[英]Python isn't posting to Sqlite3 Db
I'm hoping someone can point a mistake I've made.... I can manually post to the db file through the terminal, but when I run the python script no data posts to the table. 我希望有人可以指出我犯的一个错误。...我可以通过终端手动将其发布到db文件,但是当我运行python脚本时,没有数据发布到表中。
def logDoors(door):
conn = sqlite3.connect('doorlog_db')
c = conn.cursor()
c.execute('CREATE TABLE IF NOT EXISTS history (date REAL, door TEXT)')
date = format(datetime.datetime.now())
c.execute("INSERT INTO history (date, door) VALUES (?, ?)",
(date, door))
conn.commit()
conn.close()
Looks like you're connecting to a file with no extension. 看起来您正在连接到没有扩展名的文件。 Did you try this?
你有尝试过吗?
conn = sqlite3.connect('doorlog_db.sqlite')
Problem solved, it was actually an issue with the db reading program I was using. 问题解决了,这实际上是我使用的数据库读取程序的问题。 The two db's had been created with differential extensions.
这两个数据库已创建为具有不同的扩展名。 The db reader didn't recognize the file with the _db as a file it could open even though it could.
数据库读取器无法识别带有_db的文件,即使该文件可以打开也可以将其打开。 Therefore I was opening the .db file which wasn't being wrote to.
因此,我正在打开未写入的.db文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.