Skip to content

Commit 155013f

Browse files
Correctly setup and format example doctest code
1 parent 5ef2d72 commit 155013f

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

Doc/library/sqlite3.rst

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2450,12 +2450,18 @@ ensure that there is no open transaction:
24502450
using the :attr:`!autocommit` attribute
24512451
before executing the ``PRAGMA`` statement:
24522452

2453-
.. testcode::
2453+
.. testcode::
2454+
:hide:
2455+
2456+
con = sqlite3.connect(":memory:", autocommit=False)
2457+
2458+
.. testcode::
24542459

2455-
saved = con.autocommit
2456-
con.autocommit = True # Disable implicit transaction control.
2457-
cur.execute("PRAGMA foreign_keys=ON")
2458-
con.autocommit = saved # Restore the previous setting.
2460+
cur = con.cursor()
2461+
saved = con.autocommit
2462+
con.autocommit = True # Disable implicit transaction control.
2463+
cur.execute("PRAGMA foreign_keys=ON")
2464+
con.autocommit = saved # Restore the previous setting.
24592465

24602466

24612467
.. _sqlite3-uri-tricks:

0 commit comments

Comments
 (0)