本文介绍了sqlite3.OperationalError:数据库被锁定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将列表的所有值插入到我的 sqlite3 数据库中.当我使用 python 交互式解释器模拟这个查询时,我能够正确地将单个值插入到数据库中.但是我的代码在使用迭代时失败了:
...连接=lite.connect(db_name)游标=connection.cursor()匹配名称:cursor.execute("""INSERT INTO video_dizi(name) VALUES (?)""",(name,))连接提交()...错误:cursor.execute("""INSERT INTO video_dizi(name) VALUES (?)""",(name,))sqlite3.OperationalError:数据库被锁定有什么办法可以解决这个问题?
解决方案
当您尝试提交失败的操作时,您的代码中是否有其他连接用于启动仍处于活动状态(未提交)的事务?
I'm trying to insert all values of a list to my sqlite3 database. When I simulate this query by using the python interactive interpreter, I am able to insert the single value to DB properly. But my code fails while using an iteration:
...
connection=lite.connect(db_name)
cursor=connection.cursor()
for name in match:
cursor.execute("""INSERT INTO video_dizi(name) VALUES (?)""",(name,))
connection.commit()
...
error:cursor.execute("""INSERT INTO video_dizi(name) VALUES (?)""",(name,))
sqlite3.OperationalError: database is locked
Any way to overcome this problem?
解决方案
Do you have another connection elsewhere in your code that you use to begin a transaction that is still active (not committed) when you try to commit the operation that fails?
这篇关于sqlite3.OperationalError:数据库被锁定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!