mirror of
https://github.com/python/cpython.git
synced 2025-11-01 06:01:29 +00:00
bpo-20364: Improve sqlite3 placeholder docs (GH-25003)
This commit is contained in:
parent
c1ae741997
commit
3386ca0b36
3 changed files with 48 additions and 48 deletions
|
|
@ -2,17 +2,22 @@
|
|||
|
||||
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))
|
||||
|
||||
# The qmark style used with executemany():
|
||||
lang_list = [
|
||||
("Fortran", 64),
|
||||
("Python", 30),
|
||||
("Go", 11),
|
||||
]
|
||||
cur.executemany("insert into lang values (?, ?)", lang_list)
|
||||
|
||||
# And this is the named style:
|
||||
cur.execute("select * from people where name_last=:who and age=:age", {"who": who, "age": age})
|
||||
|
||||
print(cur.fetchone())
|
||||
cur.execute("select * from lang where lang_name=:name and lang_age=:age",
|
||||
{"name": "C", "age": 49})
|
||||
print(cur.fetchall())
|
||||
|
||||
con.close()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue