環境:python2.7
python
在處理微信朋友圈數據的過程當中,須要對sqlite進行一些處理,只處理增量數據。已經處理過的,再也不處理。sql
在sqlite中有64位的 ROWID,ROWID默認是自增的。咱們用這個特性,來處理咱們的增量數據。微信
建立一個sqlite記錄數據python2.7
# coding=utf-8 import sqlite3 conn0 = sqlite3.connect('local_info.db') # 獲取表名列表 tables = conn0.execute("SELECT tbl_name FROM sqlite_master WHERE type='table'") # 若是表不存在,則建立表 if ('device_rowid_table',) not in list(tables): conn0.execute('''CREATE TABLE device_rowid_table ( # 設備列表 device CHAR(20) NOT NULL, # 此前處理過的最大rowid max_rowid INT NOT NULL ); ''') # 插入一條數據:假設,咱們已經處理了3fa5684f7d53設備中的前10條數據 conn0.execute('INSERT INTO device_rowid_table (device, max_rowid) VALUES ("3fa5684f7d53", 40)') conn0.commit() device_id = '3fa5684f7d53' max_rowid = 0 for device, rowid in conn0.execute('select * from device_rowid_table'): if device==device_id: max_rowid = rowid print max_rowid conn1 = sqlite3.connect('3fa5684f7d53_1479459121.18.db') row_num = conn1.execute('select count(*) from SnsInfo') print list(row_num) conn1.execute('DELETE FROM SnsInfo WHERE ROWID<{}'.format(max_rowid)) conn1.commit() row_num = conn1.execute('select count(*) from SnsInfo') print list(row_num)