KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Suppose, I have a modifying statement: cursor = conn.cursor() # some code affected_rows1 = cursor.execute(update_statement1, params1) # some code conn.commit() cursor.close() Should I wrap the block of code with a try ... except and explicitly rollback a transaction when an exception is raised, and which MySQLdb exceptions should I catch to rollback? I used to catch any StandardError in this case, but now I have a hesitation that the block of code would even need an explicit rollback at all. The following example is slightly more difficult, and I understand that it does require an explicit rollback if the first update statement succeeded. Still, which exceptions should I catch in this case: cursor = conn.cursor() # some code affected_rows1 = cursor.execute(update_statement1, params1) # some code affected_rows2 = cursor.execute(update_statement2, params2) #some code conn.commit() cursor.close()
Tags (comma-separated)
Save Edits
Cancel