基本上我试图将数据从table1复制到table2,并根据某些其他应用程序发生在table1上的更改将数据插入到table2中.
看起来我错过了一些部分.
import sqlite3conn = sqlite3.connect("/home/sID/.Skype/testmasterut/main.db")cursor = conn.cursor()createLogtablesql = """create table IF NOT EXISTS sID_log as select ID as "s_ID",author as "s_author",timestamp as "s_timestamp",edited_by as "s_editedby",edited_timestamp as "s_edited_timestamp",body_xml as "s_body_xml" from Messages"""cursor.execute(createLogtablesql)conn.commit()print "table to save the old messages has been created"selectLog = """ select * from sID_log """original_table = cursor.execute(selectLog)cursor2 = conn.cursor()cursor3 = conn.cursor()cursor4 = conn.cursor()InsertTest = """ insert or ignore into sID_log (s_ID,s_author,s_timestamp,s_editedby,s_edited_timestamp,s_body_xml)select ID,author,timestamp,edited_by,edited_timestamp,body_xml from Messages where ID not in (select s_ID from sID_log where s_ID = ID) and edited_by is NulL and edited_timestamp is NulL"""EditedTest = """ select * from Messages where ID in (select s_ID from sID_log where s_ID = ID) and edited_by is not NulL and edited_timestamp is not NulL"""conn.close()while True: conn2 = sqlite3.connect("/home/sID/.Skype/testmasterut/main.db",timeout=3) conn2.execute(InsertTest) print "Total number of rows changed:",conn.total_changes EditedTest2 = """ select * from Messages where ID in (select s_ID from sID_log where s_ID = ID) and edited_by is not NulL and edited_timestamp is not NulL""" edited_List = conn2.execute(EditedTest2) conn2.commit() conn2.close() # for row in edited_List: # queryString = "SELECT * FROM sID_log WHERE s_ID IN (%s)" % str(row[0]) # original_message = conn.execute(queryString) # for org_row in original_message: # print "Message edited from",org_row[5],"to",row[5]
编辑
以下是追溯
Traceback (most recent call last): file "try2.py",line 28,in <module> conn2.execute(InsertTest)sqlite3.OperationalError: database is locked我不确定这是否会对任何人有所帮助,但我找到了解决我自己的锁定数据库问题的方法.
我使用PyCharm,发现我正在处理的脚本的几个实例都在运行.这通常是由于我正在测试的代码中的错误,但它保持活动状态(因此与db的连接仍处于活动状态).关闭那些(停止所有过程)并再试一次 – 它每次都适合我!
如果有人知道一段时间后让它超时的方法,请评论此解决方案.我尝试了cur.execute(“PRAGMA busy_timeout = 30000”)(从类似问题的另一个线程中找到)但它似乎没有做任何事情.
总结以上是内存溢出为你收集整理的Sqlite python sqlite3.OperationalError:数据库被锁定全部内容,希望文章能够帮你解决Sqlite python sqlite3.OperationalError:数据库被锁定所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)