Skip to content

Commit 8015b9a

Browse files
committed
Clarify PEP-249 compliance
1 parent cb36419 commit 8015b9a

File tree

1 file changed

+48
-44
lines changed

1 file changed

+48
-44
lines changed

Doc/library/sqlite3.rst

Lines changed: 48 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ Connection objects
654654
If :attr:`autocommit` is ``False``, this method implicitly rolls back
655655
any open transaction before closing.
656656
If :attr:`!autocommit` is ``True`` or :data:`LEGACY_TRANSACTION_CONTROL`,
657-
this method does not execute any implicit transaction control.
657+
this method does not perform any implicit transaction control.
658658
Make sure to :meth:`commit` before closing
659659
to avoid losing pending changes.
660660

@@ -1257,17 +1257,16 @@ Connection objects
12571257
This attribute controls :pep:`249`-compliant transaction behaviour.
12581258
:attr:`!autocommit` has three allowed values:
12591259

1260-
* ``False``: Select :pep:`249`-compliant transaction behaviour,
1261-
implying that :mod:`!sqlite3` ensures a transaction is always open.
1260+
* ``False``: :pep:`249`-compliant manual commit mode.
12621261
Use :meth:`commit` and :meth:`rollback` to close transactions.
12631262

12641263
This is the recommended value of :attr:`!autocommit`.
12651264

1266-
* ``True``: Use SQLite's `autocommit mode`_.
1265+
* ``True``: :pep:`249`-compliant autocommit mode.
12671266
:meth:`commit` and :meth:`rollback` have no effect in this mode.
12681267

12691268
* :data:`LEGACY_TRANSACTION_CONTROL`:
1270-
Pre-Python 3.12 (non-:pep:`249`-compliant) transaction control.
1269+
Non-:pep:`249`-compliant (pre-Python 3.12) transaction control.
12711270
See :attr:`isolation_level` for more details.
12721271

12731272
This is currently the default value of :attr:`!autocommit`.
@@ -1286,7 +1285,7 @@ Connection objects
12861285

12871286
.. attribute:: in_transaction
12881287

1289-
This read-only attribute corresponds to the low-level SQLite
1288+
This read-only attribute corresponds to the low-level SQLite's
12901289
`autocommit mode`_.
12911290

12921291
``True`` if a transaction is active (there are uncommitted changes),
@@ -2385,30 +2384,35 @@ the :attr:`Connection.autocommit` attribute,
23852384
which should preferrably be set using the *autocommit* parameter
23862385
of :func:`connect`.
23872386

2388-
It is suggested to set *autocommit* to ``False``,
2389-
which implies :pep:`249`-compliant transaction control.
2387+
It is suggested to set *autocommit* to ``False`` to enable the
2388+
:pep:`249`-compliant manual commit mode.
23902389
This means:
23912390

2392-
* :mod:`!sqlite3` ensures that a transaction is always open,
2393-
so :meth:`Connection.commit` and :meth:`Connection.rollback`
2394-
will implicitly open a new transaction immediately after closing
2395-
the open one.
2396-
:mod:`!sqlite3` uses ``BEGIN DEFERRED`` statements when opening transactions.
2397-
* Transactions should be committed explicitly using :meth:`!commit`.
2398-
* Transactions should be rolled back explicitly using :meth:`!rollback`.
2399-
* An implicit rollback is performed if the database is
2400-
:meth:`~Connection.close`-ed with pending changes.
2401-
2402-
Set *autocommit* to ``True`` to enable SQLite's `autocommit mode`_.
2403-
In this mode, :meth:`Connection.commit` and :meth:`Connection.rollback`
2404-
have no effect.
2391+
* :meth:`Connection.connect`, :meth:`Connection.commit`,
2392+
and :meth:`Connection.rollback` implicitly open a new transaction to ensure
2393+
that a transaction is always open.
2394+
Those methods use a ``BEGIN DEFERRED`` statement when opening a transaction.
2395+
* Transactions should be explicitly committed using :meth:`!commit`.
2396+
* Transactions should be explicitly rolled back using :meth:`!rollback`.
2397+
* :meth:`Connection.close` implicitly rolls back any open transaction.
2398+
2399+
Set *autocommit* to ``True`` to enable the :pep:`249`-compliant autocommit mode.
2400+
This means:
2401+
2402+
* No implicit transaction control is performed.
2403+
This leaves SQLite in `autocommit mode`_,
2404+
but also allows the user to perform their own transaction control
2405+
using explicit SQL-transaction statements.
2406+
* :meth:`Connection.commit` and :meth:`Connection.rollback` have no effect.
2407+
24052408
Note that SQLite's autocommit mode is distinct from
24062409
the :pep:`249`-compliant :attr:`Connection.autocommit` attribute;
2407-
use :attr:`Connection.in_transaction` to query
2408-
the low-level SQLite autocommit mode.
2410+
SQLite's autocommit mode can be queried using the
2411+
:attr:`Connection.in_transaction` attribute.
24092412

2410-
Set *autocommit* to :data:`LEGACY_TRANSACTION_CONTROL`
2411-
to leave transaction control behaviour to the
2413+
Set *autocommit* to :data:`LEGACY_TRANSACTION_CONTROL` to enable
2414+
non-:pep:`249`-compliant (pre-Python 3.12) transaction control.
2415+
This means transaction control behaviour is left to the
24122416
:attr:`Connection.isolation_level` attribute.
24132417
See :ref:`sqlite3-transaction-control-isolation-level` for more information.
24142418

@@ -2430,29 +2434,29 @@ transaction behaviour is controlled using
24302434
the :attr:`Connection.isolation_level` attribute.
24312435
Otherwise, :attr:`!isolation_level` has no effect.
24322436

2433-
If the connection attribute :attr:`~Connection.isolation_level`
2434-
is not ``None``,
2435-
new transactions are implicitly opened before
2436-
:meth:`~Cursor.execute` and :meth:`~Cursor.executemany` executes
2437-
``INSERT``, ``UPDATE``, ``DELETE``, or ``REPLACE`` statements;
2438-
for other statements, no implicit transaction handling is performed.
2439-
Use the :meth:`~Connection.commit` and :meth:`~Connection.rollback` methods
2440-
to respectively commit and roll back open transactions.
2441-
You can choose the underlying `SQLite transaction behaviour`_ —
2442-
that is, whether and what type of ``BEGIN`` statements :mod:`!sqlite3`
2443-
implicitly executes –
2444-
via the :attr:`~Connection.isolation_level` attribute.
2437+
If :attr:`~Connection.isolation_level` is not ``None``:
2438+
2439+
* :meth:`~Cursor.execute` and :meth:`~Cursor.executemany`
2440+
implicitly open new a transaction before executing an
2441+
``INSERT``, ``UPDATE``, ``DELETE``, or ``REPLACE`` statement;
2442+
for other statements, no implicit transaction control is performed.
2443+
The type of ``BEGIN`` statement that those methods use for the underlying
2444+
`SQLite transaction behaviour`_ can be chosen via the
2445+
:attr:`~Connection.isolation_level` attribute.
2446+
* Transactions should be explicitly committed using :meth:`!commit`.
2447+
* Transactions should be explicitly rolled back using :meth:`!rollback`.
24452448

24462449
If :attr:`~Connection.isolation_level` is set to ``None``,
2447-
no transactions are implicitly opened at all.
2448-
This leaves the underlying SQLite library in `autocommit mode`_,
2449-
but also allows the user to perform their own transaction handling
2450-
using explicit SQL statements.
2451-
The underlying SQLite library autocommit mode can be queried using the
2450+
no implicit transaction control is performed.
2451+
This leaves SQLite in `autocommit mode`_,
2452+
but also allows the user to perform their own transaction control
2453+
using explicit SQL-transaction statements.
2454+
2455+
SQLite's autocommit mode can be queried using the
24522456
:attr:`~Connection.in_transaction` attribute.
24532457

2454-
The :meth:`~Cursor.executescript` method implicitly commits
2455-
any open transaction before execution of the given SQL script,
2458+
:meth:`~Cursor.executescript` implicitly commits
2459+
any open transaction before executing the given SQL script,
24562460
regardless of the value of :attr:`~Connection.isolation_level`.
24572461

24582462
.. versionchanged:: 3.6

0 commit comments

Comments
 (0)