Skip to content

Commit 1473e94

Browse files
Last rewrite, I promise
1 parent a530b3e commit 1473e94

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

Doc/library/sqlite3.rst

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -406,13 +406,15 @@ Connection Objects
406406

407407
.. attribute:: isolation_level
408408

409-
Get or set the isolation level.
410-
Set to :const:`None` to disable implicit transaction handling,
411-
or to one of the ``"DEFERRED"``, ``"IMMEDIATE"``, or ``"EXCLUSIVE"``
412-
transaction handling modes.
409+
This attribute controls the :ref:`transaction handling
410+
<sqlite3-controlling-transactions>` performed by ``sqlite3``.
411+
If set to :const:`None`, transactions are never implicitly opened.
412+
If set to one of ``"DEFERRED"``, ``"IMMEDIATE"``, or ``"EXCLUSIVE"``,
413+
the strings representing the underlying SQLite `transaction behaviour`_,
414+
transactions are implicitly opened before some DML statements.
415+
413416
If not overridden by the *isolation_level* parameter of :func:`connect`,
414417
the default is ``""``, which is an alias for ``"DEFERRED"``.
415-
See :ref:`sqlite3-controlling-transactions` for more details.
416418

417419
.. attribute:: in_transaction
418420

@@ -1441,34 +1443,37 @@ Controlling Transactions
14411443

14421444
The ``sqlite3`` module does not adhere to the transaction handling recommended
14431445
by :pep:`249`.
1446+
14441447
If the connection attribute :attr:`~Connection.isolation_level`
14451448
is not :const:`None`,
14461449
new transactions are implicitly opened before
14471450
:meth:`~Cursor.execute` and :meth:`~Cursor.executemany` executes
14481451
``INSERT``, ``UPDATE``, ``DELETE``, or ``REPLACE`` statements.
1449-
1450-
The :meth:`~Cursor.executescript` method implicitly commits
1451-
any pending transaction before execution of the given SQL script.
1452-
No other implicit transaction handling is performed.
14531452
Use the :meth:`~Connection.commit` and :meth:`~Connection.rollback` methods
14541453
to respectively commit and roll back pending transactions.
1454+
You can chose the underlying SQLite `transaction behaviour`_,
1455+
that is the kind of ``BEGIN`` statements ``sqlite3`` implicitly executes,
1456+
via the :attr:`~Connection.isolation_level` attribute.
14551457

1456-
You can control which kind of ``BEGIN`` statements ``sqlite3`` implicitly
1457-
executes via the :attr:`~Connection.isolation_level` attribute.
1458-
1459-
The ``sqlite3`` module lets the user bypass its transaction handling by
1460-
setting :attr:`~Connection.isolation_level` to :const:`None`.
1458+
If :attr:`~Connection.isolation_level` is set to :const:`None`,
1459+
no transactions are implicitly opened at all.
14611460
This leaves the underlying SQLite library in `autocommit mode`_,
14621461
but also allows the user to perform their own transaction handling
14631462
using explicit SQL statements.
14641463
The underlying SQLite library autocommit mode can be queried using the
14651464
:attr:`~Connection.in_transaction` attribute.
14661465

1466+
The :meth:`~Cursor.executescript` method implicitly commits
1467+
any pending transaction before execution of the given SQL script,
1468+
regardless of the value of :attr:`~Connection.isolation_level`,
1469+
14671470
.. versionchanged:: 3.6
14681471
:mod:`sqlite3` used to implicitly commit an open transaction before DDL
14691472
statements. This is no longer the case.
14701473

1471-
.. _autocommit mode: https://sqlite.org/lang_transaction.html
1474+
.. _autocommit mode: https://www.sqlite.org/lang_transaction.html#implicit_versus_explicit_transactions
1475+
1476+
.. _transaction behaviour: https://www.sqlite.org/lang_transaction.html#deferred_immediate_and_exclusive_transactions
14721477

14731478

14741479
Using :mod:`sqlite3` efficiently

0 commit comments

Comments
 (0)