upd history
This commit is contained in:
parent
de1c56654c
commit
fb26b02cd2
@ -35,9 +35,9 @@ class History(object):
|
|||||||
' message_type INTEGER'
|
' message_type INTEGER'
|
||||||
')')
|
')')
|
||||||
db.commit()
|
db.commit()
|
||||||
except Exception as e:
|
except:
|
||||||
db.rollback()
|
db.rollback()
|
||||||
raise e
|
raise
|
||||||
finally:
|
finally:
|
||||||
db.close()
|
db.close()
|
||||||
|
|
||||||
@ -49,12 +49,21 @@ class History(object):
|
|||||||
cursor.execute('DELETE FROM friends WHERE tox_id=?;', (tox_id, ))
|
cursor.execute('DELETE FROM friends WHERE tox_id=?;', (tox_id, ))
|
||||||
cursor.execute('DROP TABLE id' + tox_id + ';')
|
cursor.execute('DROP TABLE id' + tox_id + ';')
|
||||||
db.commit()
|
db.commit()
|
||||||
except Exception as e:
|
except:
|
||||||
db.rollback()
|
db.rollback()
|
||||||
raise e
|
raise
|
||||||
finally:
|
finally:
|
||||||
db.close()
|
db.close()
|
||||||
|
|
||||||
|
def friend_exists_in_db(self, tox_id):
|
||||||
|
os.chdir(Settings.get_default_path())
|
||||||
|
db = sqlite3.connect(self._name + '.hstr')
|
||||||
|
cursor = db.cursor()
|
||||||
|
cursor.execute('SELECT 0 FROM friends WHERE tox_id=?', (tox_id, ))
|
||||||
|
result = cursor.fetchone()
|
||||||
|
db.close()
|
||||||
|
return result is not None
|
||||||
|
|
||||||
def save_messages_to_db(self, tox_id, messages_iter):
|
def save_messages_to_db(self, tox_id, messages_iter):
|
||||||
os.chdir(Settings.get_default_path())
|
os.chdir(Settings.get_default_path())
|
||||||
db = sqlite3.connect(self._name + '.hstr')
|
db = sqlite3.connect(self._name + '.hstr')
|
||||||
@ -63,9 +72,9 @@ class History(object):
|
|||||||
cursor.executemany('INSERT INTO id' + tox_id + '(message, owner, unix_time) '
|
cursor.executemany('INSERT INTO id' + tox_id + '(message, owner, unix_time) '
|
||||||
'VALUES (?, ?, ?);', messages_iter)
|
'VALUES (?, ?, ?);', messages_iter)
|
||||||
db.commit()
|
db.commit()
|
||||||
except Exception as e:
|
except:
|
||||||
db.rollback()
|
db.rollback()
|
||||||
raise e
|
raise
|
||||||
finally:
|
finally:
|
||||||
db.close()
|
db.close()
|
||||||
|
|
||||||
@ -96,5 +105,4 @@ class History(object):
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
h = History('test')
|
h = History('test')
|
||||||
getter = h.messages_getter('42')
|
getter = h.messages_getter('42')
|
||||||
print getter.get_all()
|
print h.friend_exists_in_db('42'), type(h.friend_exists_in_db('42'))
|
||||||
print getter.get(5)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user