我有这样的代码在Python:的Python,SQLite的未保存的文件结果
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()
,但似乎永远不会保存到数据库中,总是存在于数据库相同的元素,如果它是不节能任何东西。
在另一边。如果我试图访问通过源码它的数据库文件,我得到这个错误:
Unable to open database "people.db": file is encrypted or is not a database
我发现了一些其他的答案,使用conn.commit
代替conn.commit()
但没有改变的结果。
有什么想法?
你的代码工作完美的我 – 2012-08-04 10:13:42
似乎是现在的代码工作...任何想法上的错误无法打开数据库“people.db” :文件是加密的还是不是数据库? – 2012-08-04 10:30:19