summaryrefslogtreecommitdiffstats
path: root/Doc/includes
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-04-14 13:28:11 (GMT)
committerGitHub <noreply@github.com>2021-04-14 13:28:11 (GMT)
commit95e4431804587a0c9d464bb7b3d5f3057bbeaccd (patch)
treea01913f01173d7f5c7e8ae8f8522ab7331b62ac8 /Doc/includes
parent57873af35aad98c6428b1718aaee4b16a82ea3f5 (diff)
downloadcpython-95e4431804587a0c9d464bb7b3d5f3057bbeaccd.zip
cpython-95e4431804587a0c9d464bb7b3d5f3057bbeaccd.tar.gz
cpython-95e4431804587a0c9d464bb7b3d5f3057bbeaccd.tar.bz2
bpo-20364: Improve sqlite3 placeholder docs (GH-25003)
(cherry picked from commit 3386ca0b36327afeef8d7eff277b2aed1030c08d) Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@innova.no>
Diffstat (limited to 'Doc/includes')
-rw-r--r--Doc/includes/sqlite3/execute_1.py21
1 files changed, 13 insertions, 8 deletions
diff --git a/Doc/includes/sqlite3/execute_1.py b/Doc/includes/sqlite3/execute_1.py
index 3466b12..42aad4d 100644
--- a/Doc/includes/sqlite3/execute_1.py
+++ b/Doc/includes/sqlite3/execute_1.py
@@ -2,17 +2,22 @@ import sqlite3
con = sqlite3.connect(":memory:")
cur = con.cursor()
-cur.execute("create table people (name_last, age)")
-
-who = "Yeltsin"
-age = 72
+cur.execute("create table lang (lang_name, lang_age)")
# This is the qmark style:
-cur.execute("insert into people values (?, ?)", (who, age))
+cur.execute("insert into lang values (?, ?)", ("C", 49))
-# And this is the named style:
-cur.execute("select * from people where name_last=:who and age=:age", {"who": who, "age": age})
+# The qmark style used with executemany():
+lang_list = [
+ ("Fortran", 64),
+ ("Python", 30),
+ ("Go", 11),
+]
+cur.executemany("insert into lang values (?, ?)", lang_list)
-print(cur.fetchone())
+# And this is the named style:
+cur.execute("select * from lang where lang_name=:name and lang_age=:age",
+ {"name": "C", "age": 49})
+print(cur.fetchall())
con.close()