summaryrefslogtreecommitdiff
path: root/Doc
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2019-05-19 15:36:32 -0700
committerBerker Peksag <berker.peksag@gmail.com>2019-05-20 01:36:32 +0300
commit205c1f0e36e00e6e7cb7fbabaab4f52732859f9e (patch)
tree18a634c9d26ed3182b6d377f6dbe91b978148414 /Doc
parentf393e8eb463d60ce559982613429568c518ab8d9 (diff)
downloadcpython-git-205c1f0e36e00e6e7cb7fbabaab4f52732859f9e.tar.gz
bpo-34580: Update sqlite3 examples to call close() explicitly (GH-9079)
The sqlite3.Connection object doesn't call its close() method when it's used as a context manager. (cherry picked from commit 287b84de939db47aa8c6f30734ceb8aba9d1db29) Co-authored-by: Xtreak <tir.karthi@gmail.com>
Diffstat (limited to 'Doc')
-rw-r--r--Doc/includes/sqlite3/adapter_datetime.py2
-rw-r--r--Doc/includes/sqlite3/adapter_point_1.py2
-rw-r--r--Doc/includes/sqlite3/adapter_point_2.py2
-rw-r--r--Doc/includes/sqlite3/connect_db_1.py3
-rw-r--r--Doc/includes/sqlite3/connect_db_2.py3
-rw-r--r--Doc/includes/sqlite3/countcursors.py2
-rw-r--r--Doc/includes/sqlite3/ctx_manager.py4
-rw-r--r--Doc/includes/sqlite3/execsql_fetchonerow.py2
-rw-r--r--Doc/includes/sqlite3/execsql_printall_1.py2
-rw-r--r--Doc/includes/sqlite3/execute_1.py2
-rw-r--r--Doc/includes/sqlite3/execute_3.py12
-rw-r--r--Doc/includes/sqlite3/executemany_1.py2
-rw-r--r--Doc/includes/sqlite3/executemany_2.py2
-rw-r--r--Doc/includes/sqlite3/executescript.py1
-rw-r--r--Doc/includes/sqlite3/insert_more_people.py2
-rw-r--r--Doc/includes/sqlite3/load_extension.py2
-rw-r--r--Doc/includes/sqlite3/md5func.py2
-rw-r--r--Doc/includes/sqlite3/mysumaggr.py2
-rw-r--r--Doc/includes/sqlite3/parse_colnames.py2
-rw-r--r--Doc/includes/sqlite3/pysqlite_datetime.py2
-rw-r--r--Doc/includes/sqlite3/row_factory.py2
-rw-r--r--Doc/includes/sqlite3/rowclass.py2
-rw-r--r--Doc/includes/sqlite3/shortcut_methods.py4
-rw-r--r--Doc/includes/sqlite3/simple_tableprinter.py2
-rw-r--r--Doc/includes/sqlite3/text_factory.py2
-rw-r--r--Doc/library/sqlite3.rst6
26 files changed, 52 insertions, 19 deletions
diff --git a/Doc/includes/sqlite3/adapter_datetime.py b/Doc/includes/sqlite3/adapter_datetime.py
index be33395100..d5221d80c3 100644
--- a/Doc/includes/sqlite3/adapter_datetime.py
+++ b/Doc/includes/sqlite3/adapter_datetime.py
@@ -13,3 +13,5 @@ cur = con.cursor()
now = datetime.datetime.now()
cur.execute("select ?", (now,))
print(cur.fetchone()[0])
+
+con.close()
diff --git a/Doc/includes/sqlite3/adapter_point_1.py b/Doc/includes/sqlite3/adapter_point_1.py
index 6b1af84156..77daf8f16d 100644
--- a/Doc/includes/sqlite3/adapter_point_1.py
+++ b/Doc/includes/sqlite3/adapter_point_1.py
@@ -14,3 +14,5 @@ cur = con.cursor()
p = Point(4.0, -3.2)
cur.execute("select ?", (p,))
print(cur.fetchone()[0])
+
+con.close()
diff --git a/Doc/includes/sqlite3/adapter_point_2.py b/Doc/includes/sqlite3/adapter_point_2.py
index d670700f04..cb86331692 100644
--- a/Doc/includes/sqlite3/adapter_point_2.py
+++ b/Doc/includes/sqlite3/adapter_point_2.py
@@ -15,3 +15,5 @@ cur = con.cursor()
p = Point(4.0, -3.2)
cur.execute("select ?", (p,))
print(cur.fetchone()[0])
+
+con.close()
diff --git a/Doc/includes/sqlite3/connect_db_1.py b/Doc/includes/sqlite3/connect_db_1.py
deleted file mode 100644
index 1b97523286..0000000000
--- a/Doc/includes/sqlite3/connect_db_1.py
+++ /dev/null
@@ -1,3 +0,0 @@
-import sqlite3
-
-con = sqlite3.connect("mydb")
diff --git a/Doc/includes/sqlite3/connect_db_2.py b/Doc/includes/sqlite3/connect_db_2.py
deleted file mode 100644
index f9728b3613..0000000000
--- a/Doc/includes/sqlite3/connect_db_2.py
+++ /dev/null
@@ -1,3 +0,0 @@
-import sqlite3
-
-con = sqlite3.connect(":memory:")
diff --git a/Doc/includes/sqlite3/countcursors.py b/Doc/includes/sqlite3/countcursors.py
index ef3e70a2a9..112f47703a 100644
--- a/Doc/includes/sqlite3/countcursors.py
+++ b/Doc/includes/sqlite3/countcursors.py
@@ -13,3 +13,5 @@ con = sqlite3.connect(":memory:", factory=CountCursorsConnection)
cur1 = con.cursor()
cur2 = con.cursor()
print(con.numcursors)
+
+con.close()
diff --git a/Doc/includes/sqlite3/ctx_manager.py b/Doc/includes/sqlite3/ctx_manager.py
index 7af4ad1ecf..6db77d4504 100644
--- a/Doc/includes/sqlite3/ctx_manager.py
+++ b/Doc/includes/sqlite3/ctx_manager.py
@@ -14,3 +14,7 @@ try:
con.execute("insert into person(firstname) values (?)", ("Joe",))
except sqlite3.IntegrityError:
print("couldn't add Joe twice")
+
+# Connection object used as context manager only commits or rollbacks transactions,
+# so the connection object should be closed manually
+con.close()
diff --git a/Doc/includes/sqlite3/execsql_fetchonerow.py b/Doc/includes/sqlite3/execsql_fetchonerow.py
index 078873bfc9..115bcb50c7 100644
--- a/Doc/includes/sqlite3/execsql_fetchonerow.py
+++ b/Doc/includes/sqlite3/execsql_fetchonerow.py
@@ -15,3 +15,5 @@ for (name_last, age) in cur:
cur.execute(SELECT)
for row in cur:
print('%s is %d years old.' % (row[0], row[1]))
+
+con.close()
diff --git a/Doc/includes/sqlite3/execsql_printall_1.py b/Doc/includes/sqlite3/execsql_printall_1.py
index a4ce5c5281..19306e6e3c 100644
--- a/Doc/includes/sqlite3/execsql_printall_1.py
+++ b/Doc/includes/sqlite3/execsql_printall_1.py
@@ -11,3 +11,5 @@ cur.execute("select * from people order by age")
# Retrieve all rows as a sequence and print that sequence:
print(cur.fetchall())
+
+con.close()
diff --git a/Doc/includes/sqlite3/execute_1.py b/Doc/includes/sqlite3/execute_1.py
index f864a8984e..3466b1265a 100644
--- a/Doc/includes/sqlite3/execute_1.py
+++ b/Doc/includes/sqlite3/execute_1.py
@@ -14,3 +14,5 @@ cur.execute("insert into people values (?, ?)", (who, age))
cur.execute("select * from people where name_last=:who and age=:age", {"who": who, "age": age})
print(cur.fetchone())
+
+con.close()
diff --git a/Doc/includes/sqlite3/execute_3.py b/Doc/includes/sqlite3/execute_3.py
deleted file mode 100644
index 0353683fc7..0000000000
--- a/Doc/includes/sqlite3/execute_3.py
+++ /dev/null
@@ -1,12 +0,0 @@
-import sqlite3
-
-con = sqlite3.connect("mydb")
-
-cur = con.cursor()
-
-who = "Yeltsin"
-age = 72
-
-cur.execute("select name_last, age from people where name_last=:who and age=:age",
- locals())
-print(cur.fetchone())
diff --git a/Doc/includes/sqlite3/executemany_1.py b/Doc/includes/sqlite3/executemany_1.py
index efae10637c..edf6f8b7eb 100644
--- a/Doc/includes/sqlite3/executemany_1.py
+++ b/Doc/includes/sqlite3/executemany_1.py
@@ -22,3 +22,5 @@ cur.executemany("insert into characters(c) values (?)", theIter)
cur.execute("select c from characters")
print(cur.fetchall())
+
+con.close()
diff --git a/Doc/includes/sqlite3/executemany_2.py b/Doc/includes/sqlite3/executemany_2.py
index 527358ebc2..02a594c861 100644
--- a/Doc/includes/sqlite3/executemany_2.py
+++ b/Doc/includes/sqlite3/executemany_2.py
@@ -13,3 +13,5 @@ cur.executemany("insert into characters(c) values (?)", char_generator())
cur.execute("select c from characters")
print(cur.fetchall())
+
+con.close()
diff --git a/Doc/includes/sqlite3/executescript.py b/Doc/includes/sqlite3/executescript.py
index 7e5358178d..aea8943fbe 100644
--- a/Doc/includes/sqlite3/executescript.py
+++ b/Doc/includes/sqlite3/executescript.py
@@ -22,3 +22,4 @@ cur.executescript("""
1987
);
""")
+con.close()
diff --git a/Doc/includes/sqlite3/insert_more_people.py b/Doc/includes/sqlite3/insert_more_people.py
index edbc79e7e5..10cf937243 100644
--- a/Doc/includes/sqlite3/insert_more_people.py
+++ b/Doc/includes/sqlite3/insert_more_people.py
@@ -14,3 +14,5 @@ for person in newPeople:
# The changes will not be saved unless the transaction is committed explicitly:
con.commit()
+
+con.close()
diff --git a/Doc/includes/sqlite3/load_extension.py b/Doc/includes/sqlite3/load_extension.py
index b997c70668..624cfe262f 100644
--- a/Doc/includes/sqlite3/load_extension.py
+++ b/Doc/includes/sqlite3/load_extension.py
@@ -24,3 +24,5 @@ con.executescript("""
""")
for row in con.execute("select rowid, name, ingredients from recipe where name match 'pie'"):
print(row)
+
+con.close()
diff --git a/Doc/includes/sqlite3/md5func.py b/Doc/includes/sqlite3/md5func.py
index 0056b2d6ce..16dc348bf0 100644
--- a/Doc/includes/sqlite3/md5func.py
+++ b/Doc/includes/sqlite3/md5func.py
@@ -9,3 +9,5 @@ con.create_function("md5", 1, md5sum)
cur = con.cursor()
cur.execute("select md5(?)", (b"foo",))
print(cur.fetchone()[0])
+
+con.close()
diff --git a/Doc/includes/sqlite3/mysumaggr.py b/Doc/includes/sqlite3/mysumaggr.py
index d2dfd2c0b9..11f96395b6 100644
--- a/Doc/includes/sqlite3/mysumaggr.py
+++ b/Doc/includes/sqlite3/mysumaggr.py
@@ -18,3 +18,5 @@ cur.execute("insert into test(i) values (1)")
cur.execute("insert into test(i) values (2)")
cur.execute("select mysum(i) from test")
print(cur.fetchone()[0])
+
+con.close()
diff --git a/Doc/includes/sqlite3/parse_colnames.py b/Doc/includes/sqlite3/parse_colnames.py
index cc68c76459..5f01dbfe1c 100644
--- a/Doc/includes/sqlite3/parse_colnames.py
+++ b/Doc/includes/sqlite3/parse_colnames.py
@@ -6,3 +6,5 @@ cur = con.cursor()
cur.execute('select ? as "x [timestamp]"', (datetime.datetime.now(),))
dt = cur.fetchone()[0]
print(dt, type(dt))
+
+con.close()
diff --git a/Doc/includes/sqlite3/pysqlite_datetime.py b/Doc/includes/sqlite3/pysqlite_datetime.py
index 68d49358a5..5d843f906b 100644
--- a/Doc/includes/sqlite3/pysqlite_datetime.py
+++ b/Doc/includes/sqlite3/pysqlite_datetime.py
@@ -18,3 +18,5 @@ cur.execute('select current_date as "d [date]", current_timestamp as "ts [timest
row = cur.fetchone()
print("current_date", row[0], type(row[0]))
print("current_timestamp", row[1], type(row[1]))
+
+con.close()
diff --git a/Doc/includes/sqlite3/row_factory.py b/Doc/includes/sqlite3/row_factory.py
index e436ffc6c8..9de6e7b1b9 100644
--- a/Doc/includes/sqlite3/row_factory.py
+++ b/Doc/includes/sqlite3/row_factory.py
@@ -11,3 +11,5 @@ con.row_factory = dict_factory
cur = con.cursor()
cur.execute("select 1 as a")
print(cur.fetchone()["a"])
+
+con.close()
diff --git a/Doc/includes/sqlite3/rowclass.py b/Doc/includes/sqlite3/rowclass.py
index 92b5ad60cb..fc60287069 100644
--- a/Doc/includes/sqlite3/rowclass.py
+++ b/Doc/includes/sqlite3/rowclass.py
@@ -10,3 +10,5 @@ for row in cur:
assert row["name"] == row["nAmE"]
assert row[1] == row["age"]
assert row[1] == row["AgE"]
+
+con.close()
diff --git a/Doc/includes/sqlite3/shortcut_methods.py b/Doc/includes/sqlite3/shortcut_methods.py
index 71600d4f60..98a3941149 100644
--- a/Doc/includes/sqlite3/shortcut_methods.py
+++ b/Doc/includes/sqlite3/shortcut_methods.py
@@ -18,3 +18,7 @@ for row in con.execute("select firstname, lastname from person"):
print(row)
print("I just deleted", con.execute("delete from person").rowcount, "rows")
+
+# close is not a shortcut method and it's not called automatically,
+# so the connection object should be closed manually
+con.close()
diff --git a/Doc/includes/sqlite3/simple_tableprinter.py b/Doc/includes/sqlite3/simple_tableprinter.py
index 231d8726cd..148a1707f9 100644
--- a/Doc/includes/sqlite3/simple_tableprinter.py
+++ b/Doc/includes/sqlite3/simple_tableprinter.py
@@ -24,3 +24,5 @@ for row in cur:
print(fieldValue.ljust(FIELD_MAX_WIDTH), end=' ')
print() # Finish the row with a newline.
+
+con.close()
diff --git a/Doc/includes/sqlite3/text_factory.py b/Doc/includes/sqlite3/text_factory.py
index 5f96cdb58d..a857a155cd 100644
--- a/Doc/includes/sqlite3/text_factory.py
+++ b/Doc/includes/sqlite3/text_factory.py
@@ -25,3 +25,5 @@ con.text_factory = lambda x: x.decode("utf-8") + "foo"
cur.execute("select ?", ("bar",))
row = cur.fetchone()
assert row[0] == "barfoo"
+
+con.close()
diff --git a/Doc/library/sqlite3.rst b/Doc/library/sqlite3.rst
index 569bfced38..e20b4b3db3 100644
--- a/Doc/library/sqlite3.rst
+++ b/Doc/library/sqlite3.rst
@@ -530,6 +530,7 @@ Connection Objects
with open('dump.sql', 'w') as f:
for line in con.iterdump():
f.write('%s\n' % line)
+ con.close()
.. method:: backup(target, *, pages=0, progress=None, name="main", sleep=0.250)
@@ -566,8 +567,11 @@ Connection Objects
print(f'Copied {total-remaining} of {total} pages...')
con = sqlite3.connect('existing_db.db')
- with sqlite3.connect('backup.db') as bck:
+ bck = sqlite3.connect('backup.db')
+ with bck:
con.backup(bck, pages=1, progress=progress)
+ bck.close()
+ con.close()
Example 2, copy an existing database into a transient copy::