Solution for Calling cursor.execute() twice in a row yielding inconsistent results
is Given Below:
I am running python 3.9 with mysql.connector.
I have a file in which I try to run to cursor.execute() statements back to back, (something) like this:
mycursor.execute("DELETE FROM sales WHERE id = 10") mycursor.execute("SELECT COUNT(*) FROM items WHERE id = 11")
Directly afterwards I set a variable to mycursor.fetchone(). Sometimes this gives me 1 (as it should, since earlier in the code I insert an item with that id) and other times it gives 0. I have run it plenty of times and there seems to be no correlation between when it is 1 and when 0.
Calling time.sleep(1) fixes the issue (haven’t bothered to test different increments of times yet).
My question is simply why? Is there any problem with calling execute functions back-to-back? Does anyone know of a possible solution besides sleep?