execute_1.py 386 Bytes
Newer Older
1 2
import sqlite3

3
con = sqlite3.connect(":memory:")
4
cur = con.cursor()
5
cur.execute("create table people (name_last, age)")
6 7 8 9

who = "Yeltsin"
age = 72

10 11 12 13 14 15
# This is the qmark style:
cur.execute("insert into people values (?, ?)", (who, age))

# And this is the named style:
cur.execute("select * from people where name_last=:who and age=:age", {"who": who, "age": age})

16
print(cur.fetchone())