Python、Sqlite不在文件上保存结果
我用Python编写了以下代码:Python、Sqlite不在文件上保存结果,python,database,sqlite,Python,Database,Sqlite,我用Python编写了以下代码: conn = sqlite3.connect("people.db") cursor = conn.cursor() sql = 'create table if not exists people (id integer, name VARCHAR(255))' cursor.execute(sql) conn.commit() sql = 'insert into people VALUES (3, "test")' cursor.execute(sql
conn = sqlite3.connect("people.db")
cursor = conn.cursor()
sql = 'create table if not exists people (id integer, name VARCHAR(255))'
cursor.execute(sql)
conn.commit()
sql = 'insert into people VALUES (3, "test")'
cursor.execute(sql)
conn.commit()
sql = 'insert into people VALUES (5, "test")'
cursor.execute(sql)
conn.commit()
print 'Printing all inserted'
cursor.execute("select * from people")
for row in cursor.fetchall():
print row
cursor.close()
conn.close()
但似乎从未保存到数据库,数据库上总是有相同的元素,就好像它没有保存任何东西一样
另一方面,如果我试图通过sqlite访问db文件,则会出现以下错误:
Unable to open database "people.db": file is encrypted or is not a database
我在其他一些答案中找到了使用conn.commit
而不是conn.commit()
,但没有改变结果
有什么想法吗?这对我来说似乎还不错(“在数据库中”每次运行都会增加):
你能用sqlite administrator这样的工具打开数据库吗?这将证明DB格式是正确的。 如果我搜索该错误,解决方案将指向sqlite和所使用的db驱动程序之间的版本问题。也许你可以chrck你的版本或者AKX可以发布工作组合
你好,谢谢!人!我也有同样的问题。其中一个原因很简单。我正在使用debian linux,错误是 无法打开数据库“people.db”:文件已加密或不是数据库 数据库文件与我的python脚本位于同一目录中 连接线已断开
conn=sqlite3.connect('./testcases.db')
我改变了这个
conn=sqlite3.connect('testcases.db')
!!没有点和斜线。
修正了错误。所有作品
如果有人认为这是有用的,欢迎您您在做出更改后提交,即:
myDatabase.commit()
你的代码非常适合你,代码正在运行。。。关于无法打开数据库“people.db”的错误有什么想法:文件是加密的还是不是数据库?嗨,hhz,是ubuntu服务器,所以我没有UI。谢谢你的回答!将其scp到具有ui的客户端。可能的只需让您确定.db文件本身是否有效。这是非常好的一点。始终检查您的路径,即您以cron作业等方式运行脚本。为了避免我们需要比较代码,您能解释一下您是如何修复的吗?
myDatabase.commit()