Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python SQLite 3数据库未更新_Python_Sqlite - Fatal编程技术网

Python SQLite 3数据库未更新

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"

我在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","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')
。试试这些想法,我看不出你的代码中有任何错误,但我只是建议最好的做法。

只有当他在事务模式下操作,并且根据“如果我没记错的话”,对数据库事务的支持是可选的。
隔离级别默认情况下不在自动提交模式下。不管怎样,我只是遵循了手册中的示例:)