8000 Docs: improve sqlite3 placeholders example · python/cpython@1a93802 · GitHub
[go: up one dir, main page]

Skip to content 8000

Commit 1a93802

Browse files
Docs: improve sqlite3 placeholders example
Use named style for executemany() example.
1 parent 1de4395 commit 1a93802

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

Doc/library/sqlite3.rst

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1961,16 +1961,16 @@ Here's an example of both styles:
19611961
# This is the qmark style:
19621962
cur.execute("INSERT INTO lang VALUES(?, ?)", ("C", 1972))
19631963

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})
1964+
# The named style used with executemany():
1965+
lang_list = (
1966+
{"name": "Fortran", "year": 1957},
1967+
{"name": "Python", "year": 1991},
1968+
{"name": "Go", "year": 2009},
1969+
)
1970+
cur.executemany("INSERT INTO lang VALUES(:name, :year)", lang_list)
1971+
1972+
# This is the qmark style used in a query:
1973+
cur.execute("SELECT * FROM lang WHERE first_appeared = ?", (1972,))
19741974
print(cur.fetchall())
19751975

19761976
.. testoutput::

0 commit comments

Comments
 (0)
0