8000 Docs: improve sqlite3 placeholders example (#101092) · python/cpython@b84be8d · GitHub
[go: up one dir, main page]

Skip to content

Commit b84be8d

Browse files
Docs: improve sqlite3 placeholders example (#101092)
1 parent 48ec678 commit b84be8d

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
@@ -1958,19 +1958,18 @@ Here's an example of both styles:
19581958
con = sqlite3.connect(":memory:")
19591959
cur = con.execute("CREATE TABLE lang(name, first_appeared)")
19601960

1961-
# This is the qmark style:
1962-
cur.execute("INSERT INTO lang VALUES(?, ?)", ("C", 1972))
1963-
1964-
# The qmark style used with executemany():
1965-
lang_list = [
1966-
("Fortran", 1957),
1967-
("Python", 1991),
1968-
("Go", 2009),
1969-
]
1970-
cur.executemany("INSERT INTO lang VALUES(?, ?)", lang_list)
1971-
1972-
# And this is the named style:
1973-
cur.execute("SELECT * FROM lang WHERE first_appeared = :year", {"year": 1972})
1961+
# This is the named style used with executemany():
1962+
data = (
1963+
{"name": "C", "year": 1972},
1964+
{"name": "Fortran", "year": 1957},
1965+
{"name": "Python", "year": 1991},
1966+
{"name": "Go", "year": 2009},
1967+
)
1968+
cur.executemany("INSERT INTO lang VALUES(:name, :year)", data)
1969+
1970+
# This is the qmark style used in a SELECT query:
1971+
params = (1972,)
1972+
cur.execute("SELECT * FROM lang WHERE first_appeared = ?", params)
19741973
print(cur.fetchall())
19751974

19761975
.. testoutput::

0 commit comments

Comments
 (0)
0