Skip to content

Commit 94972d5

Browse files
miss-islingtonberkerpeksag
authored andcommitted
bpo-8145: Improve isolation_level documentation (GH-8499)
Initial patch by R. David Murray. (cherry picked from commit a71fed0) Co-authored-by: Berker Peksag <[email protected]>
1 parent 8f6a7e1 commit 94972d5

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

Doc/library/sqlite3.rst

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ Connection Objects
274274

275275
.. attribute:: isolation_level
276276

277-
Get or set the current isolation level. :const:`None` for autocommit mode or
277+
Get or set the current default isolation level. :const:`None` for autocommit mode or
278278
one of "DEFERRED", "IMMEDIATE" or "EXCLUSIVE". See section
279279
:ref:`sqlite3-controlling-transactions` for a more detailed explanation.
280280

@@ -946,22 +946,30 @@ timestamp converter.
946946
Controlling Transactions
947947
------------------------
948948

949-
By default, the :mod:`sqlite3` module opens transactions implicitly before a
950-
Data Modification Language (DML) statement (i.e.
951-
``INSERT``/``UPDATE``/``DELETE``/``REPLACE``).
952-
953-
You can control which kind of ``BEGIN`` statements sqlite3 implicitly executes
954-
(or none at all) via the *isolation_level* parameter to the :func:`connect`
955-
call, or via the :attr:`isolation_level` property of connections.
949+
The underlying ``sqlite3`` library operates in ``autocommit`` mode by default,
950+
but the Python :mod:`sqlite3` module by default does not.
956951

957-
If you want **autocommit mode**, then set :attr:`isolation_level` to ``None``.
952+
``autocommit`` mode means that statements that modify the database take effect
953+
immediately. A ``BEGIN`` or ``SAVEPOINT`` statement disables ``autocommit``
954+
mode, and a ``COMMIT``, a ``ROLLBACK``, or a ``RELEASE`` that ends the
955+
outermost transaction, turns ``autocommit`` mode back on.
958956

959-
Otherwise leave it at its default, which will result in a plain "BEGIN"
960-
statement, or set it to one of SQLite's supported isolation levels: "DEFERRED",
961-
"IMMEDIATE" or "EXCLUSIVE".
957+
The Python :mod:`sqlite3` module by default issues a ``BEGIN`` statement
958+
implicitly before a Data Modification Language (DML) statement (i.e.
959+
``INSERT``/``UPDATE``/``DELETE``/``REPLACE``).
962960

963-
The current transaction state is exposed through the
964-
:attr:`Connection.in_transaction` attribute of the connection object.
961+
You can control which kind of ``BEGIN`` statements :mod:`sqlite3` implicitly
962+
executes via the *isolation_level* parameter to the :func:`connect`
963+
call, or via the :attr:`isolation_level` property of connections.
964+
If you specify no *isolation_level*, a plain ``BEGIN`` is used, which is
965+
equivalent to specifying ``DEFERRED``. Other possible values are ``IMMEDIATE``
966+
and ``EXCLUSIVE``.
967+
968+
You can disable the :mod:`sqlite3` module's implicit transaction management by
969+
setting :attr:`isolation_level` to ``None``. This will leave the underlying
970+
``sqlite3`` library operating in ``autocommit`` mode. You can then completely
971+
control the transaction state by explicitly issuing ``BEGIN``, ``ROLLBACK``,
972+
``SAVEPOINT``, and ``RELEASE`` statements in your code.
965973

966974
.. versionchanged:: 3.6
967975
:mod:`sqlite3` used to implicitly commit an open transaction before DDL

0 commit comments

Comments
 (0)