我在获取 python 脚本更新 sqlite 数据库时遇到问题。
第一部分似乎工作正常:
conn = sqlite3.connect('/Users/test/Desktop/my-accounts.db')
currentAccount = None
for row in conn.execute('SELECT email FROM accounts WHERE active=0'):
currentAccount = row[0]
print "Checking out: ",currentAccount
break
if currentAccount is None:
print "No available accounts"
然后,在下一部分中,我想获取变量 currentAccount 并更新数据库中该值所在的行。
else:
conn.execute('UPDATE accounts SET active=1 WHERE email=?', [currentAccount,])
conn.close()
我在控制台中没有收到任何错误,但数据库没有更新。电子邮件列是 VARCHAR,事件列是 INT。
谢谢。
解决方案是添加
conn.commit()
在execute()之后
最佳答案
尝试在conn.execute("XXX")
之后添加conn.commit()
。有时 sqlite3 不会自动提交执行。
关于python - 使用 python 的 SQL 更新命令不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15716161/