मैंने निम्नलिखित कोड लिखा है, जो sqlite3.OperationalError: database is locked
त्रुटि दिखा रहा है। डीबग करने में कोई मदद की सराहना की जाएगी।स्क्लाइट पायथन sqlite3.OperationalError: डेटाबेस लॉक किया गया है
मूल रूप से मैं तालिका 1 से तालिका 2 में डेटा कॉपी करने और किसी अन्य एप्लिकेशन द्वारा तालिका 1 में होने वाले परिवर्तनों के आधार पर तालिका 2 में डेटा डालने का प्रयास कर रहा हूं।
ऐसा लगता है कि मुझे कुछ हिस्सा याद आ रहा है।
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]
संपादित नीचे ट्रैस बैक
Traceback (most recent call last):
File "try2.py", line 28, in <module>
conn2.execute(InsertTest)
sqlite3.OperationalError: database is locked
कृपया हमें दिखाने बनाओ वापस ट्रेस करें। यह अपवाद के बिना कि कौन सी लाइन इस अपवाद को उठाती है, समस्या को डीबग करना बहुत मुश्किल है। – abarnert
स्क्लाइट समेकन अच्छी तरह से संभाल नहीं करता है ... –
@ जोरनबेस्ले: यह इसे _efficiently_ को संभाल नहीं करता है, लेकिन [यह इसे सही तरीके से संभालता है] (http://www.sqlite.org/faq.html#q5)। इसके अलावा, यदि ओपी वास्तव में एक ही फाइल में एक ही समय में एक कनेक्शन है, तो इससे कोई फर्क नहीं पड़ता। – abarnert