Advertisement
Guest User

MultiThread

a guest
Nov 26th, 2014
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.16 KB | None | 0 0
  1. import sqlite3
  2.  
  3. # conn = sqlite3.connect("/home/herles1/Desktop/main.db")
  4. # conn2 = sqlite3.connect("/home/herles1/Desktop/my.db")
  5. conn = sqlite3.connect("/home/sid/.Skype/testmasterut/main.db")
  6. conn2 = sqlite3.connect("/home/sid/skp/main.db")
  7.  
  8. createLogTableSql = """
  9.     CREATE TABLE IF NOT EXISTS sid_log(s_id INTEGER PRIMARY KEY,
  10.         s_author TEXT,s_timestamp INTEGER,
  11.         s_editedby TEXT,s_edited_timestamp INTEGER,s_body_xml TEXT)
  12.     """
  13.  
  14. conn2.execute(createLogTableSql)
  15. conn2.commit()
  16.  
  17. selectLog = """ select id,author,timestamp,edited_by,edited_timestamp,body_xml from Messages """
  18. skype_table = conn.execute(selectLog)
  19.  
  20. insertToLogTable = """
  21.     INSERT INTO sid_log(s_id,s_author,s_timestamp,s_editedby,s_edited_timestamp,s_body_xml) VALUES(?,?,?,?,?,?)
  22.     """
  23. for row in skype_table:
  24.     conn2.execute(insertToLogTable, (row[0],row[1],row[2],row[3],row[4],row[5]))
  25. conn2.commit()
  26.  
  27. print "Table to save the old messages has been created"
  28.  
  29. selectLogID = """ select s_id from sid_log """
  30.  
  31. while True:
  32.     original_table_ids = conn2.execute(selectLogID)
  33.     id_list = []
  34.     for row in original_table_ids:
  35.         id_list.append(row[0])
  36.  
  37.     newMessages = "SELECT id,author,timestamp,edited_by,edited_timestamp,body_xml FROM Messages WHERE id NOT IN ({}) AND edited_by IS NULL AND edited_timestamp IS NULL".format(','.join(['?']*len(id_list)))
  38.     newMessagesRows = conn.execute(newMessages, id_list)
  39.     for row in newMessagesRows:
  40.         conn2.execute(insertToLogTable, row[0],row[1],row[2],row[3],row[4],row[5])
  41.     conn2.commit()
  42.  
  43.     original_table_ids = conn2.execute(selectLogID)
  44.     id_list = []
  45.     for row in original_table_ids:
  46.         id_list.append(row[0])
  47.  
  48.     editedMessages = "SELECT id,author,timestamp,edited_by,edited_timestamp,body_xml FROM Messages WHERE id IN ({}) AND edited_by IS NOT NULL AND edited_timestamp IS NOT NULL".format(','.join(['?']*len(id_list)))
  49.     editedMessagesRows = conn.execute(editedMessages, id_list)
  50.     for row in editedMessagesRows:
  51.         queryString = "SELECT * FROM sid_log WHERE s_id IN (%d)" % org_row[0]
  52.         original_message = conn2.execute(queryString)
  53.         for org_row in original_message:
  54.             print "Message edited from", org_row[5], "to", row[5]
  55. conn.close()
  56. conn2.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement