Skip to content

Commit 2c1eeb5

Browse files
Docs: improve sqlite3 placeholders example (GH-101092)
(cherry picked from commit b84be8d) Co-authored-by: Erlend E. Aasland <[email protected]>
1 parent 9407631 commit 2c1eeb5

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

Doc/library/sqlite3.rst

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,19 +1455,18 @@ Here's an example of both styles:
14551455
con = sqlite3.connect(":memory:")
14561456
cur = con.execute("CREATE TABLE lang(name, first_appeared)")
14571457

1458-
# This is the qmark style:
1459-
cur.execute("INSERT INTO lang VALUES(?, ?)", ("C", 1972))
1460-
1461-
# The qmark style used with executemany():
1462-
lang_list = [
1463-
("Fortran", 1957),
1464-
("Python", 1991),
1465-
("Go", 2009),
1466-
]
1467-
cur.executemany("INSERT INTO lang VALUES(?, ?)", lang_list)
1468-
1469-
# And this is the named style:
1470-
cur.execute("SELECT * FROM lang WHERE first_appeared = :year", {"year": 1972})
1458+
# This is the named style used with executemany():
1459+
data = (
1460+
{"name": "C", "year": 1972},
1461+
{"name": "Fortran", "year": 1957},
1462+
{"name": "Python", "year": 1991},
1463+
{"name": "Go", "year": 2009},
1464+
)
1465+
cur.executemany("INSERT INTO lang VALUES(:name, :year)", data)
1466+
1467+
# This is the qmark style used in a SELECT query:
1468+
params = (1972,)
1469+
cur.execute("SELECT * FROM lang WHERE first_appeared = ?", params)
14711470
print(cur.fetchall())
14721471

14731472
.. testoutput::

0 commit comments

Comments
 (0)