The adodbapi documentation and code implies that with autocommit = False I should only have to call commit (and possibly rollback) and if using the connection as a context manager not even those are required. If autocommit = False is passed on the initial connect the __init__ of the connector handles BeginTrans and subsequent commit and rollbacks also leave me with an open trans. But if I do this:
conn = adodbapi.connect(conn_args, autocommit=True) conn.autocommit = False with conn: cur = conn.cursor() cur.execute("insert into table1 (col1) values (?)", ('row5', )) print 'inserted a row' I get an exception that there is not an existing transaction to commit. I created a quick subclass of the Connect class that handles the __setattr__ for 'autocommit' by calling self.BeginTrans() if autocommit = False class MyConnection(adodbapi.Connection): """""" def __setattr__(self, name, value): super(self.__class__, self).__setattr__(name, value) if name == 'autocommit': if (not self._autocommit and self.supportsTransactions and self.transaction_level == 0): self.transaction_level = self.connector.BeginTrans() But of course I also had to re-implement the adodbapi.connect to use my Connection class (is there a better way?). I think what I'm getting at is that allowing the caller to change the autocommit attribute to False on the instance but not beginning a trans (as would happen if the autocommit = False was passed in connect()) seems inconsistent. On Mon, Oct 24, 2016 at 9:00 AM, <python-win32-requ...@python.org> wrote: > Send python-win32 mailing list submissions to > python-win32@python.org > > To subscribe or unsubscribe via the World Wide Web, visit > https://mail.python.org/mailman/listinfo/python-win32 > or, via email, send a message with subject or body 'help' to > python-win32-requ...@python.org > > You can reach the person managing the list at > python-win32-ow...@python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of python-win32 digest..." > > Today's Topics: > > 1. Re: adodbapi changing autocommit (Tim Roberts) > > > ---------- Forwarded message ---------- > From: Tim Roberts <t...@probo.com> > To: "python-win32@python.org" <python-win32@python.org> > Cc: > Date: Sun, 23 Oct 2016 14:59:27 -0700 > Subject: Re: [python-win32] adodbapi changing autocommit > On Oct 22, 2016, at 9:42 PM, Max Slimmer III <maxslim...@gmail.com> wrote: > > > > Setting connection.autocommit = False does not cause a > > connection.connector.BeginTrans() and so any subsequent > > connection.commit() raises an exception that there is no open > > transaction. Is this by design and I'm supposed to explicitly call > > BeginTrans() when switching autocommit off? > > Yes, that's exactly the tradeoff. If you have auto commit on, ADO will > wrap each operation in a transaction. If you have auto commit off, then > you have to insert the transaction markers yourself. > — > Tim Roberts, t...@probo.com > Providenza & Boekelheide, Inc. > > > _______________________________________________ > python-win32 mailing list > python-win32@python.org > https://mail.python.org/mailman/listinfo/python-win32 > > -- --Max III
_______________________________________________ python-win32 mailing list python-win32@python.org https://mail.python.org/mailman/listinfo/python-win32