How would I know if the following update executed successfully, right now the statement executes but the table doesn’t reflect that.
cursor = mysql.cursor()
cursor.execute("""UPDATE foo SET key1 = %s WHERE id = %s""", (val1, id2))
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
As far as I know, you need to call
for your changes to take effect.
This makes sure that your database operations (you can have multiple) are executed in one so called transaction. If something goes wrong, you can revert the whole changes.
In one transaction you put stuff that belong together, like adding a new person and setting a reference to that person in another table.
See also the chapter Insert Operation on this page (where they use
rollbackin case of an exception): http://www.tutorialspoint.com/python/python_database_access.htm