0

i need some help with python an mysql.

I have the following code, which is executing in infinite loop:

db = MySQLdb.connect("127.0.0.1","user","password","dbname" )
while True:
    cursor = db.cursor()
    cursor.execute("SELECT * FROM requests WHERE status <> 'Finished'")
    all_pending_requests = cursor.fetchall()
    cursor.close()

And that works fine the first time i run it. But when i go to a tool like mysql workbench or i type it myself in in terminal, i update some rows and set their status to something that is not "Finished". So by doing that the next time the loop executes i should get those rows as a result but i get nothing. Do you guys now why this is happening maybe?

Thanks for help.

1
  • Does MySQL need to be committed? Commented Nov 26, 2014 at 18:14

1 Answer 1

1

I am not certain but would assume that you are using InnoDB storage engine in MySQL and MySQLdb version >=1.2.0. You need to commit before the changes are being reflected. As of version 1.2.0, MySQLdb disables auto-commit by default. Confirmation of the same is here. Try adding db.commit() as the last line in the loop.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.