Python DB API - commit() v. execute("commit transaction")?

Jon Ribbens jon+usenet at unequivocal.eu
Fri Jun 2 06:46:46 EDT 2017


On 2017-06-02, Frank Millman <frank at chagford.com> wrote:
> "Frank Millman"  wrote in message news:ogr3ff$sg1$1 at blaine.gmane.org...
>
>> By default, psycopg2 uses 'autocommit', which means that even a SELECT is
>> preceded by a 'BEGIN' statement internally. I never changed the default, so
>> all of the following assumes that autocommit is on.
>
> Oops - by default it does *not* use autocommit, so the following assumes 
> that it is off.

Indeed, the DB-API spec says that auto-commmit must be initially off.
This led to an extremely irritating situation whereby Python-MySQLdb
changed incompatibly between versions, it used to have auto-commit on
but was changed to bring it in line with the spec - and they didn't
even add any way of achieving the old backwards-compatible behaviour!

(You can call Connection.autocommit() but this has to happen after the
connection has already been established, and results in every new
connection starting with two completely pointless "SET autocommit 0"
"SET autocommit 1" commands.)



More information about the Python-list mailing list