import sqlite3

db = sqlite3.connect(':memory:') # :memory: 表示数据保存在内存中

db.execute("CREATE TABLE data (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, value INTEGER)");

db.execute("INSERT INTO data (id, name, value) VALUES (?, ?, ?)", (1, '猫了个咪', 666));

cursor = db.execute("SELECT * FROM data");
print(cursor.fetchone())
cursor.execute("SELECT * FROM data")
print(cursor.fetchone())
cursor = db.cursor();
print(cursor.fetchone())
cursor.execute("SELECT * FROM data")
print(cursor.fetchone())

db.commit() # 事务提交 (启用事务才需要使用这个命令)

标签: none

添加新评论