mirror of
https://github.com/python/cpython.git
synced 2025-08-03 00:23:06 +00:00
bpo-44106: Improve sqlite3 example database contents (GH-26027)
(cherry picked from commit 92d1064727
)
Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@innova.no>
This commit is contained in:
parent
1f483c0c1b
commit
3185bc9d3f
9 changed files with 37 additions and 42 deletions
|
@ -2,22 +2,21 @@ import sqlite3
|
|||
|
||||
con = sqlite3.connect(":memory:")
|
||||
cur = con.cursor()
|
||||
cur.execute("create table lang (lang_name, lang_age)")
|
||||
cur.execute("create table lang (name, first_appeared)")
|
||||
|
||||
# This is the qmark style:
|
||||
cur.execute("insert into lang values (?, ?)", ("C", 49))
|
||||
cur.execute("insert into lang values (?, ?)", ("C", 1972))
|
||||
|
||||
# The qmark style used with executemany():
|
||||
lang_list = [
|
||||
("Fortran", 64),
|
||||
("Python", 30),
|
||||
("Go", 11),
|
||||
("Fortran", 1957),
|
||||
("Python", 1991),
|
||||
("Go", 2009),
|
||||
]
|
||||
cur.executemany("insert into lang values (?, ?)", lang_list)
|
||||
|
||||
# And this is the named style:
|
||||
cur.execute("select * from lang where lang_name=:name and lang_age=:age",
|
||||
{"name": "C", "age": 49})
|
||||
cur.execute("select * from lang where first_appeared=:year", {"year": 1972})
|
||||
print(cur.fetchall())
|
||||
|
||||
con.close()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue