Python SQLite 3数据库未更新
我在Windows 8 x64上运行以下代码:Python SQLite 3数据库未更新,python,sqlite,Python,Sqlite,我在Windows 8 x64上运行以下代码: import sqlite3 as db conn = db.connect('test.db') cursor = conn.cursor() cursor.execute("create table films(title text, year text, director text)") print("table created") cursor.execute('insert into films values("Annie Hall"
import sqlite3 as db
conn = db.connect('test.db')
cursor = conn.cursor()
cursor.execute("create table films(title text, year text, director text)")
print("table created")
cursor.execute('insert into films values("Annie Hall","1977","Woody Allen")')
cursor.execute('insert into films values("The Godfather","1972","Francis Ford Coppola")')
conn.close()
检查创建的SQLite文件(test.db)(用于测试通过代码创建的表中是否有条目)不会显示任何内容。有什么帮助吗?您必须在
连接关闭()之前调用连接提交()
如果您想要自动提交模式,您必须将isolation\u level=None
作为db.connect()
调用的参数。说明光标可以是只读的,或者您的数据库可能处于事务模式。我也不清楚为什么在未在准备好的语句中指定参数的情况下使用,如cursor.execute('insert-into-films values(?,?)','Annie Hall','1977','Woody Allen')
。试试这些想法,我看不出你的代码中有任何错误,但我只是建议最好的做法。只有当他在事务模式下操作,并且根据“如果我没记错的话”,对数据库事务的支持是可选的。隔离级别默认情况下不在自动提交模式下。不管怎样,我只是遵循了手册中的示例:)