Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-61162: Clarify sqlite3 connection context manager docs #93890

Merged
merged 16 commits into from
Jun 19, 2022
Merged
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
erlend-aasland marked this conversation as resolved.
Show resolved Hide resolved
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Connection objects can be used as context managers
that automatically commit or rollback transactions. In the event of an
erlend-aasland marked this conversation as resolved.
Show resolved Hide resolved
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,
erlend-aasland marked this conversation as resolved.
Show resolved Hide resolved
the transaction is committed.
erlend-aasland marked this conversation as resolved.
Show resolved Hide resolved
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.
erlend-aasland marked this conversation as resolved.
Show resolved Hide resolved

.. 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.
erlend-aasland marked this conversation as resolved.
Show resolved Hide resolved