Menu

#25 Setting autocommit = False does not BeginTrans

v1.0_(example)
open
nobody
5
2016-10-26
2016-10-26
Max Slimmer
No

Setting autocommit = False on a connection instance does not begin a new transaction. This results in subsequent commit() calls raising an exception.

Something like the following on the Connection class seems to fix:

def setattr(self, name, value):
if name == 'autocommit': # extension: allow user to turn autocommit on or off
if self.supportsTransactions:
object.setattr(self, '_autocommit', bool(value))
try: self._rollback() # must clear any outstanding transactions
except: pass
if (not self._autocommit
and self.supportsTransactions
and self.transaction_level == 0):
self.transaction_level = self.connector.BeginTrans()

Discussion


Log in to post a comment.