2007-08-15 11:28:01 -03:00
|
|
|
import sqlite3
|
|
|
|
|
2012-03-01 15:28:00 -04:00
|
|
|
con = sqlite3.connect(":memory:")
|
2007-08-15 11:28:01 -03:00
|
|
|
cur = con.cursor()
|
2012-03-01 15:28:00 -04:00
|
|
|
cur.execute("create table people (name_last, age)")
|
2007-08-15 11:28:01 -03:00
|
|
|
|
|
|
|
who = "Yeltsin"
|
|
|
|
age = 72
|
|
|
|
|
2012-03-01 15:28:00 -04:00
|
|
|
# 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})
|
|
|
|
|
2007-08-15 11:28:01 -03:00
|
|
|
print cur.fetchone()
|