atomic transactions

32 views
Skip to first unread message

Kevin Geohagan

unread,
Sep 10, 2012, 1:14:48 PM9/10/12
to pyo...@googlegroups.com
I'm having trouble figuring out the proper way to do atomic commits.  My intuition is that (for autocommit=False), everything passed to the execute() method between calls to commit() (on a single given Cursor) gets batched into a single atomic transaction.  Is that right, or should I be trying to execute() everything in a big SQL statement?  Thanks.

K.

Michael Kleehammer

unread,
Sep 10, 2012, 3:52:08 PM9/10/12
to pyo...@googlegroups.com
You are correct - by default connections have autocommit set to False, so everything you do is batched up, so to speak, until you call Connection.commit (or Cursor.commit in recent source builds).

This makes coding very handy since you put the commit at the bottom of a function.  If an exception occurs and the connection is closed (which happens automatically if you don't keep references to it), the transaction is rolled back.

Kevin Geohagan

unread,
Sep 11, 2012, 12:09:27 PM9/11/12
to pyo...@googlegroups.com
Great, thanks for the help.
Reply all
Reply to author
Forward
0 new messages