While discussing with Erlend about the semantics of
Connection.autocommit, I was a bit surprised to find that we had
obviously not added this as a DB-API 2.0 standard extension yet:

https://discuss.python.org/t/introducing-a-pep-249-compliant-transaction-behaviour-to-sqlite3/16516

I'd like to change that, so here's a draft wording:

"""
Connection.autocommit

  Attribute to query and set the autocommit mode of the connection.

  Returns True if the connection is operating in autocommit (non-
  transactional) mode. Returns False is the connection is operating in
  manual commit (transactional) mode.

  Setting the attribute to True or False adjusts the connection’s mode
  accordingly.
"""

The above is what quite a few database modules already implement,
so there shouldn't much to discuss.

Something that's not immediately clear, though, is how to handle
semantics when switching from one to the other.

A. Things are clear for changing from True to False (disabling
autocommit): the database leaves autocommit mode and starts a new
transaction.

B. Things are less clear when changing from False to True (enabling
autocommit).

The case for an empty transaction is straight forward:
since there's nothing to commit or rollback, the database enters
autocommit mode without any other effects.

If there is a pending transaction, though, there are three approaches
we could take:

1. The database module raises an exception, to force an explicit
   .commit() or .rollback() by the programmer.

2. The module automatically commits the pending transaction,
   since that's what autocommit is all about.

3. We leave these semantics open and up to the database module
   to determine.

My preference would be option 2, since this makes things clear for
everyone and is intuitive (well, at least for me :-)).

Thoughts ?

--
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Experts (#1, Oct 28 2022)
>>> Python Projects, Coaching and Support ...    https://www.egenix.com/
>>> Python Product Development ...        https://consulting.egenix.com/
________________________________________________________________________

::: We implement business ideas - efficiently in both time and costs :::

   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611
               https://www.egenix.com/company/contact/
                     https://www.malemburg.com/

_______________________________________________
DB-SIG maillist  -  DB-SIG@python.org
https://mail.python.org/mailman/listinfo/db-sig

Reply via email to