Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
11 changes: 7 additions & 4 deletions Doc/library/sqlite3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1434,10 +1434,13 @@ case-insensitively by name:
Using the connection as a context manager
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Connection objects can be used as context managers
that automatically commit or rollback transactions. In the event of an
exception, the transaction is rolled back; otherwise, the transaction is
committed:
With an open transaction, connection objects can be used as context managers
that automatically commit or rollback transactions.
If the body of the ``with`` statement finishes without exceptions,
the transaction is committed.
If an exception is raised and not caught, the transaction is rolled back.

If there is no open transaction, the context manager is a no-op.

.. literalinclude:: ../includes/sqlite3/ctx_manager.py

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Clarify :mod:`sqlite3` connection context manager behaviour.