Name

rollback( )

Signature

rollback(  )

Synopsis

Rolls back any uncommitted statements. This works only if MySQL is set up for transactional processing in this context.

Example

connection = MySQLdb.connect(host='carthage', user='test', 
                              passwd='test', db='test');
connection._transactional = 1;
cursor = connection.cursor(  );
cursor.execute("UPDATE TNAME SET COL = 1 WHERE PK = 2045");
try:
    cursor.execute("UPDATE TNAME SET COL = 1 WHERE PK = 3200");
    connection.commit(  );
except:
    connection.rollback(  );
connection.close(  );

Get Managing & Using MySQL, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.