• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import sqlite3
2
3con = sqlite3.connect(":memory:")
4cur = con.cursor()
5cur.execute("create table lang (name, first_appeared)")
6
7# This is the qmark style:
8cur.execute("insert into lang values (?, ?)", ("C", 1972))
9
10# The qmark style used with executemany():
11lang_list = [
12    ("Fortran", 1957),
13    ("Python", 1991),
14    ("Go", 2009),
15]
16cur.executemany("insert into lang values (?, ?)", lang_list)
17
18# And this is the named style:
19cur.execute("select * from lang where first_appeared=:year", {"year": 1972})
20print(cur.fetchall())
21
22con.close()
23