Skip to content

Commit 287b84d

Browse files
tirkarthiberkerpeksag
authored andcommitted
bpo-34580: Update sqlite3 examples to call close() explicitly (GH-9079)
The sqlit3.Connection object doesn't call its close() method when it's used as a context manager.
1 parent 5c08ce9 commit 287b84d

26 files changed

+52
-19
lines changed

Doc/includes/sqlite3/adapter_datetime.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ def adapt_datetime(ts):
1313
now = datetime.datetime.now()
1414
cur.execute("select ?", (now,))
1515
print(cur.fetchone()[0])
16+
17+
con.close()

Doc/includes/sqlite3/adapter_point_1.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ def __conform__(self, protocol):
1414
p = Point(4.0, -3.2)
1515
cur.execute("select ?", (p,))
1616
print(cur.fetchone()[0])
17+
18+
con.close()

Doc/includes/sqlite3/adapter_point_2.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ def adapt_point(point):
1515
p = Point(4.0, -3.2)
1616
cur.execute("select ?", (p,))
1717
print(cur.fetchone()[0])
18+
19+
con.close()

Doc/includes/sqlite3/connect_db_1.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

Doc/includes/sqlite3/connect_db_2.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

Doc/includes/sqlite3/countcursors.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ def cursor(self, *args, **kwargs):
1313
cur1 = con.cursor()
1414
cur2 = con.cursor()
1515
print(con.numcursors)
16+
17+
con.close()

Doc/includes/sqlite3/ctx_manager.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@
1414
con.execute("insert into person(firstname) values (?)", ("Joe",))
1515
except sqlite3.IntegrityError:
1616
print("couldn't add Joe twice")
17+
18+
# Connection object used as context manager only commits or rollbacks transactions,
19+
# so the connection object should be closed manually
20+
con.close()

Doc/includes/sqlite3/execsql_fetchonerow.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@
1515
cur.execute(SELECT)
1616
for row in cur:
1717
print('%s is %d years old.' % (row[0], row[1]))
18+
19+
con.close()

Doc/includes/sqlite3/execsql_printall_1.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@
1111

1212
# Retrieve all rows as a sequence and print that sequence:
1313
print(cur.fetchall())
14+
15+
con.close()

Doc/includes/sqlite3/execute_1.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@
1414
cur.execute("select * from people where name_last=:who and age=:age", {"who": who, "age": age})
1515

1616
print(cur.fetchone())
17+
18+
con.close()

0 commit comments

Comments
 (0)