I am trying to run following code:
with open('file.sql') as sqlFile:
sql = sqlFile.read()
cursor.execute(sql)
file.sql contains some SQL queries that initialize a DB.
However this code finishes working before all queries are proceed. They will be proceed in a few seconds after this script finish working.
How can I wait until all queries are proceed?
That's already the case.
execute() command already waits for the command to be completely executed before passing to the next line of code in your script.
That means your code won't continue before the cursor.execute() finishes execution.
Your assumptions are wrong. I assume you're getting an error in your sql execution, and that's what causes the sql to be skipped.
For one, cursor.execute() usually can't run multiple SQL statements, so you probably have to split the file into multiple statements and call cursor.execute() multiple times, one for each statement.
Please remove all try/except clauses that might be hiding errors with the code above, and provide the full error traceback you're getting, if that's not the case.
I experienced the same problem.
I solved it by call mydb.commit() after mycursor.execute
Then, it worked.
But I am not sure if it is the lege artis construction.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With