cpython/Doc/includes/sqlite3/execute_1.py

19 lines
399 B
Python
Raw Normal View History

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