2007-08-15 14:28:22 +00:00
|
|
|
import sqlite3
|
|
|
|
|
|
2012-02-15 22:17:21 +02:00
|
|
|
con = sqlite3.connect(":memory:")
|
2007-08-15 14:28:22 +00:00
|
|
|
cur = con.cursor()
|
2021-05-19 09:41:19 +02:00
|
|
|
cur.execute("create table lang (name, first_appeared)")
|
2007-08-15 14:28:22 +00:00
|
|
|
|
2012-02-15 22:17:21 +02:00
|
|
|
# This is the qmark style:
|
2021-05-19 09:41:19 +02:00
|
|
|
cur.execute("insert into lang values (?, ?)", ("C", 1972))
|
2012-02-15 22:17:21 +02:00
|
|
|
|
2021-04-14 14:28:55 +02:00
|
|
|
# The qmark style used with executemany():
|
|
|
|
|
lang_list = [
|
2021-05-19 09:41:19 +02:00
|
|
|
("Fortran", 1957),
|
|
|
|
|
("Python", 1991),
|
|
|
|
|
("Go", 2009),
|
2021-04-14 14:28:55 +02:00
|
|
|
]
|
|
|
|
|
cur.executemany("insert into lang values (?, ?)", lang_list)
|
2012-02-15 22:17:21 +02:00
|
|
|
|
2021-04-14 14:28:55 +02:00
|
|
|
# And this is the named style:
|
2021-05-19 09:41:19 +02:00
|
|
|
cur.execute("select * from lang where first_appeared=:year", {"year": 1972})
|
2021-04-14 14:28:55 +02:00
|
|
|
print(cur.fetchall())
|
2019-05-20 03:22:20 +05:30
|
|
|
|
|
|
|
|
con.close()
|