Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
10d3a65
Add sqlite3.Connection.autocommit for PEP 249 compliant behaviour
erlend-aasland Jun 11, 2022
6ca9045
Add basic tests
erlend-aasland Jun 14, 2022
5772676
Add documentation
erlend-aasland Jun 14, 2022
06609f3
Add NEWS
erlend-aasland Jun 14, 2022
8b6b866
Add What's New
erlend-aasland Jun 14, 2022
a604a57
Document DEPRECATED_TRANSACTION_CONTROL
erlend-aasland Jun 14, 2022
cbc1041
Fix setattr behaviour
erlend-aasland Jun 14, 2022
41b898c
Suggest new behaviour starting with Python 3.14
erlend-aasland Jun 15, 2022
b11ebd2
Simplify implicit rollback test
erlend-aasland Jun 15, 2022
d3009d4
Address Alex' review
erlend-aasland Jun 15, 2022
fb98615
Reorder if condition to add emphasis to deprecated behaviour
erlend-aasland Jun 15, 2022
5e4626e
Add context manager tests
erlend-aasland Jun 15, 2022
a8e3b9e
Improve 5e4626ecf47a679ba5fa8846472af16fb325cac5
erlend-aasland Jun 15, 2022
d46e9be
Add executescript tests
erlend-aasland Jun 15, 2022
c2e2f1a
Improve docs
erlend-aasland Jun 15, 2022
3bf3ee1
Add missing versionadded
erlend-aasland Jun 16, 2022
757f70b
Try to further improve the docs
erlend-aasland Jun 16, 2022
a5ef40c
Nano-optimisation
erlend-aasland Jun 16, 2022
ae37fbb
Explicit downcast
erlend-aasland Jun 17, 2022
341e0dd
Clarify execute*, commit, rollback, and close
erlend-aasland Jun 17, 2022
77651c0
Incorporate gh-93890 changes
erlend-aasland Jun 17, 2022
0ac782c
Improve
erlend-aasland Jun 17, 2022
7743f34
Merge branch 'main' into sqlite-autocommit
erlend-aasland Jun 19, 2022
6628e30
commit/rollback wordings
erlend-aasland Jun 19, 2022
060bd3a
Fix merge
erlend-aasland Jun 19, 2022
c96adbf
Doc: reword context manager section
erlend-aasland Jun 20, 2022
a7c7c4c
Autocommit is keyword only
erlend-aasland Jun 24, 2022
f1c5843
Isolation level is not yet deprecated (soon it will be though)
erlend-aasland Jun 24, 2022
491426e
Merge remote-tracking branch 'upstream/main' into sqlite-autocommit
erlend-aasland Jun 24, 2022
05879a9
Merge branch 'main' into sqlite-autocommit
erlend-aasland Jun 27, 2022
97ad734
Use macro as C default
erlend-aasland Jun 27, 2022
bf3a857
Merge branch 'main' into sqlite-autocommit
erlend-aasland Jul 8, 2022
60f7224
Merge branch 'main' into sqlite-autocommit
erlend-aasland Jul 18, 2022
7f645ee
Pass keywords to factory function
erlend-aasland Jul 20, 2022
88fb2b9
Merge branch 'main' into sqlite-autocommit
erlend-aasland Jul 20, 2022
4deed17
Adjust commit/rollback and remove redundant info
erlend-aasland Jul 20, 2022
f3a9e37
Merge branch 'main' into sqlite-autocommit
erlend-aasland Jul 23, 2022
2981a6b
Fix docstring
erlend-aasland Jul 23, 2022
a5b7864
Revert unneeded doc changes
erlend-aasland Jul 23, 2022
fd6659a
Fix autocommit enum
erlend-aasland Jul 23, 2022
52e3736
Sync with main bco. recent doc updates
erlend-aasland Jul 26, 2022
6e92073
Merge branch 'main' into sqlite-autocommit
erlend-aasland Jul 30, 2022
59fbd29
Merge branch 'main' into sqlite-autocommit
erlend-aasland Aug 3, 2022
894fcce
Add autocommit to connect signature
erlend-aasland Aug 3, 2022
fff4307
Merge branch 'main' into sqlite-autocommit
erlend-aasland Aug 8, 2022
4ac0fa0
Address Alex's second review
erlend-aasland Aug 8, 2022
64c6482
Adjust headings
erlend-aasland Aug 8, 2022
e4947d0
Use versionadded iso. versionchanged
erlend-aasland Aug 8, 2022
5981536
Remove some no-ops
erlend-aasland Aug 8, 2022
527e6a3
Three adjustments:
erlend-aasland Aug 8, 2022
697b65a
Address Alex's last round of review
erlend-aasland Aug 15, 2022
4299874
Sync with main bco. recent Argument Clinic changes
erlend-aasland Aug 15, 2022
76122be
Regen all
erlend-aasland Aug 15, 2022
6902738
Explicit logic in set_autocommit
erlend-aasland Aug 15, 2022
c37ebb5
Tweak naming: connection_txn_stmt => connection_exec_stmt
erlend-aasland Aug 15, 2022
2e9083c
Merge branch 'main' into sqlite-autocommit
erlend-aasland Aug 18, 2022
b944a90
Address review: improve wording for connection close()
erlend-aasland Aug 18, 2022
bce921f
Sync with main
erlend-aasland Oct 28, 2022
78e04f0
Fix bad merge
erlend-aasland Oct 28, 2022
bd91e34
Remove implicit commit for cx.autocommit = False
erlend-aasland Oct 28, 2022
9d66daa
Doc: make the autocommit reference more to the point; expand in the e…
erlend-aasland Oct 28, 2022
d4c0583
Address most of CAM's review
erlend-aasland Oct 29, 2022
a3aa9aa
Better naming for the constant; don't mention deprecations (yet)
erlend-aasland Oct 29, 2022
c9b05ff
Fix default role
erlend-aasland Oct 30, 2022
d5e33f1
Make it explicit that isolation_level is ignored if autocommit is Tru…
erlend-aasland Oct 30, 2022
0cf022a
Reflow
erlend-aasland Oct 30, 2022
5009372
Address review: COMPAT_TRANSACTIONAL_CONTROL => LEGACY_TRANSACTION_CO…
erlend-aasland Oct 31, 2022
2c9b117
Address more of CAM's review
erlend-aasland Oct 31, 2022
de3bd4e
Try to address the rest of CAM's review
erlend-aasland Oct 31, 2022
fca9c56
Sync with main
erlend-aasland Nov 6, 2022
7de6bf3
Address more of CAM's remarks
erlend-aasland Nov 6, 2022
e0fa134
Prevent segfault if implicitly rolling back during interpreter shutdown
erlend-aasland Nov 6, 2022
e0bedf6
Update Doc/library/sqlite3.rst
Nov 7, 2022
e33946a
Address last batch of CAM's comments
erlend-aasland Nov 7, 2022
cd15505
Last bit
erlend-aasland Nov 8, 2022
4feefa1
Update Doc/library/sqlite3.rst
Nov 11, 2022
720ac11
Sync with main
erlend-aasland Nov 11, 2022
f7c2ae4
Update Doc/library/sqlite3.rst
Nov 11, 2022
88e1420
Sync with main
erlend-aasland Nov 12, 2022
7b87830
Address review: remove unneeded assert in test_autocommit_setget_invalid
erlend-aasland Nov 12, 2022
8322683
Address review: add test for rollback() if autocommit is True
erlend-aasland Nov 12, 2022
aca1e22
Address review: fixup context manager docs
erlend-aasland Nov 12, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Address more of CAM's remarks
  • Loading branch information
erlend-aasland committed Nov 6, 2022
commit 7de6bf38a70b52e5452100089c838672a8a6b5c7
34 changes: 10 additions & 24 deletions Doc/library/sqlite3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ Module functions
Can be ``"DEFERRED"`` (default), ``"EXCLUSIVE"`` or ``"IMMEDIATE"``;
or ``None`` to disable opening transactions implicitly.
Has no effect unless :attr:`Connection.autocommit` is set to
:data:`~sqlite3.LEGACY_TRANSACTION_CONTROL`.
:data:`~sqlite3.LEGACY_TRANSACTION_CONTROL` (the default).
:type isolation_level: str | None

:param bool check_same_thread:
Expand Down Expand Up @@ -1308,16 +1308,18 @@ Connection objects
If set to ``None``, transactions are never implicitly opened.
If set to one of ``"DEFERRED"``, ``"IMMEDIATE"``, or ``"EXCLUSIVE"``,
corresponding to the underlying `SQLite transaction behaviour`_,
implicit :ref:`transaction management
:ref:`implicit transaction management
<sqlite3-transaction-control-isolation-level>` is performed.

If not overridden by the *isolation_level* parameter of :func:`connect`,
the default is ``""``, which is an alias for ``"DEFERRED"``.

Using :attr:`autocommit` to control transaction handling is recommended
over using :attr:`!isolation_level`.
:attr:`!isolation_level` has no effect unless :attr:`autocommit` is set
to :data:`LEGACY_TRANSACTION_CONTROL`.
.. note::

Using :attr:`autocommit` to control transaction handling is
recommended over using :attr:`!isolation_level`.
:attr:`!isolation_level` has no effect unless :attr:`autocommit` is
set to :data:`LEGACY_TRANSACTION_CONTROL` (the default).

.. attribute:: row_factory

Expand Down Expand Up @@ -2389,22 +2391,6 @@ to leave transaction control behaviour to the
:attr:`Connection.isolation_level` attribute.
See :ref:`sqlite3-transaction-control-isolation-level` for more information.

.. note::

:attr:`~Connection.autocommit` and SQLite's `autocommit mode`_
are not linked.
For example, explicitly issuing a ``BEGIN`` statement when
:attr:`!autocommit` is ``True`` will not change the value of
the *autocommit* attribute.

Use :attr:`Connection.in_transaction` to query the low-level SQLite
autocommit mode.

.. note::

The :attr:`Connection.isolation_level` attribute has no effect unless
:attr:`Connection.autocommit` is :data:`LEGACY_TRANSACTION_CONTROL`.


.. _sqlite3-transaction-control-isolation-level:

Expand All @@ -2420,8 +2406,8 @@ Transaction control via the ``isolation_level`` attribute
If :attr:`Connection.autocommit` is set to
:data:`LEGACY_TRANSACTION_CONTROL`,
transaction behaviour is controlled using
the :attr:`Connection.isolation_level` attribute,
else it has no effect.
the :attr:`Connection.isolation_level` attribute.
Otherwise, :attr:`!isolation_level` has no effect.

If the connection attribute :attr:`~Connection.isolation_level`
is not ``None``,
Expand Down
6 changes: 3 additions & 3 deletions Lib/test/test_sqlite3/test_transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ def test_isolation_level_none(self):

class AutocommitAttribute(unittest.TestCase):
"""Test PEP 249-compliant autocommit behaviour."""
compat = sqlite.LEGACY_TRANSACTION_CONTROL
legacy = sqlite.LEGACY_TRANSACTION_CONTROL

@contextmanager
def check_stmt_trace(self, cx, expected, reset=True):
Expand Down Expand Up @@ -483,7 +483,7 @@ def test_autocommit_disabled_ctx_mgr(self):

def test_autocommit_compat_ctx_mgr(self):
expected = ["BEGIN ", "INSERT INTO T VALUES(1)", "COMMIT"]
with memory_database(autocommit=self.compat) as cx:
with memory_database(autocommit=self.legacy) as cx:
cx.execute("create table t(t)")
with self.check_stmt_trace(cx, expected):
with cx:
Expand Down Expand Up @@ -511,7 +511,7 @@ def test_autocommit_disabled_executescript(self):

def test_autocommit_compat_executescript(self):
expected = ["BEGIN", "COMMIT", "SELECT 1"]
with memory_database(autocommit=self.compat) as cx:
with memory_database(autocommit=self.legacy) as cx:
with self.check_stmt_trace(cx, expected):
self.assertFalse(cx.in_transaction)
cx.execute("BEGIN")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Add the :attr:`~sqlite3.Connection.autocommit` attribute
to :class:`~sqlite3.Connection`
and the *autocommit* parameter to :func:`~sqlite3.connect`
to :class:`sqlite3.Connection`
and the *autocommit* parameter to :func:`sqlite3.connect`
to control :pep:`249`-compliant
:ref:`transaction handling <sqlite3-transaction-control-autocommit>`.
Patch by Erlend E. Aasland.
6 changes: 3 additions & 3 deletions Modules/_sqlite/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ autocommit_converter(PyObject *val, enum autocommit_mode *result)
if (PyLong_Check(val) &&
PyLong_AsLong(val) == LEGACY_TRANSACTION_CONTROL)
{
*result = AUTOCOMMIT_COMPAT;
*result = AUTOCOMMIT_LEGACY;
return 1;
}

Expand Down Expand Up @@ -601,7 +601,7 @@ pysqlite_connection_commit_impl(pysqlite_Connection *self)
return NULL;
}

if (self->autocommit == AUTOCOMMIT_COMPAT) {
if (self->autocommit == AUTOCOMMIT_LEGACY) {
if (!sqlite3_get_autocommit(self->db)) {
if (connection_exec_stmt(self, "COMMIT") < 0) {
return NULL;
Expand Down Expand Up @@ -635,7 +635,7 @@ pysqlite_connection_rollback_impl(pysqlite_Connection *self)
return NULL;
}

if (self->autocommit == AUTOCOMMIT_COMPAT) {
if (self->autocommit == AUTOCOMMIT_LEGACY) {
if (!sqlite3_get_autocommit(self->db)) {
if (connection_exec_stmt(self, "ROLLBACK") < 0) {
return NULL;
Expand Down
2 changes: 1 addition & 1 deletion Modules/_sqlite/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ typedef struct _callback_context
} callback_context;

enum autocommit_mode {
AUTOCOMMIT_COMPAT = LEGACY_TRANSACTION_CONTROL,
AUTOCOMMIT_LEGACY = LEGACY_TRANSACTION_CONTROL,
AUTOCOMMIT_ENABLED = 1,
AUTOCOMMIT_DISABLED = 0,
};
Expand Down
4 changes: 2 additions & 2 deletions Modules/_sqlite/cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,7 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation

/* We start a transaction implicitly before a DML statement.
SELECT is the only exception. See #9924. */
if (self->connection->autocommit == AUTOCOMMIT_COMPAT
if (self->connection->autocommit == AUTOCOMMIT_LEGACY
&& self->connection->isolation_level
&& self->statement->is_dml
&& sqlite3_get_autocommit(self->connection->db))
Expand Down Expand Up @@ -1034,7 +1034,7 @@ pysqlite_cursor_executescript_impl(pysqlite_Cursor *self,

// Commit if needed
sqlite3 *db = self->connection->db;
if (self->connection->autocommit == AUTOCOMMIT_COMPAT
if (self->connection->autocommit == AUTOCOMMIT_LEGACY
&& !sqlite3_get_autocommit(db))
{
int rc = SQLITE_OK;
Expand Down