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

Neil Cerutti neilc at norwich.edu
Fri Jun 2 08:07:45 EDT 2017


On 2017-06-02, Frank Millman <frank at chagford.com> wrote:
> As I said, I cannot prove this, but the theory fits the
> observed behaviour perfectly, so I have proceeded on the
> assumption that it is true. Therefore I now always run every
> SQL command or block of commands within a context manager,
> which always calls conn.commit() or conn.rollback() on exit,
> and I have not had any more problems. I use exactly the same
> code for sqlite3 and for Sql Server/pyodbc, and it has not
> caused any problems there either.

You're probably not expected to interleave transaction control
commands from different levels of abstraction, e.g., only call
'commit' directly if you called 'begin' directly.

-- 
Neil Cerutti




More information about the Python-list mailing list