python database is locked_Sqlite python sqlite3.OperationalError: database is locked

2014-11-27 00:03:20

2

I have written the following code, which is showing the sqlite3.OperationalError: database is locked error. Any help to debug would be much appreciated.

Basically I am trying to copy data from table1 to table2 and inserting data to table2 based on changes happening to table1 by some other application.

Looks like I am missing some part.

import sqlite3

conn = 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]

Edit

Below is the traceback

Traceback (most recent call last):

File "try2.py", line 28, in

conn2.execute(InsertTest)

sqlite3.OperationalError: database is locked

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值