File tree Expand file tree Collapse file tree 1 file changed +17
-4
lines changed Expand file tree Collapse file tree 1 file changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -1553,14 +1553,27 @@ case-insensitively by name:
1553
1553
1554
1554
.. literalinclude :: ../includes/sqlite3/rowclass.py
1555
1555
1556
+ .. _sqlite3-connection-context-manager :
1556
1557
1557
1558
Using the connection as a context manager
1558
1559
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1559
1560
1560
- Connection objects can be used as context managers
1561
- that automatically commit or rollback transactions. In the event of an
1562
- exception, the transaction is rolled back; otherwise, the transaction is
1563
- committed:
1561
+ A :class: `Connection ` object can be used as a context manager that
1562
+ automatically commits or rolls back open transactions when leaving the body of the
1563
+ context manager.
1564
+ If the body of the :keyword: `with ` statement finishes without exceptions,
1565
+ the transaction is committed.
1566
+ If this commit fails,
1567
+ or if the body of the ``with `` statement raises an uncaught exception,
1568
+ the transaction is rolled back.
1569
+
1570
+ If there is no open transaction upon leaving the body of the ``with `` statement,
1571
+ the context manager is a no-op.
1572
+
1573
+ .. note ::
1574
+
1575
+ The context manager does not implicitly open a new transaction
1576
+ or close the connection.
1564
1577
1565
1578
.. literalinclude :: ../includes/sqlite3/ctx_manager.py
1566
1579
You can’t perform that action at this time.
0 commit comments