欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

python操作SQLite数据库的Cursor对象

程序员文章站 2022-03-13 08:37:23
...

一 代码

import sqlite3
conn=sqlite3.connect(":memory:")
cur=conn.cursor()
cur.execute("CREATE TABLE people(name_last,age)")
who = "cakin"
age = 35
cur.execute("INSERT INTO people VALUES(?,?)",(who,age))
cur.execute("SELECT * FROM people WHERE name_last=:who1 AND age = :age1",
            {"who1":who,"age1":age})
print(cur.fetchone())

 

二 运行结果
==========
('cakin', 35)