[openpgp] Use Gajim's sqlite adapter/converter
This commit is contained in:
@@ -18,13 +18,11 @@ import sqlite3
|
|||||||
import logging
|
import logging
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
from nbxmpp import JID
|
|
||||||
|
|
||||||
log = logging.getLogger('gajim.p.openpgp.sql')
|
log = logging.getLogger('gajim.p.openpgp.sql')
|
||||||
|
|
||||||
TABLE_LAYOUT = '''
|
TABLE_LAYOUT = '''
|
||||||
CREATE TABLE contacts (
|
CREATE TABLE contacts (
|
||||||
jid JID,
|
jid TEXT,
|
||||||
fingerprint TEXT,
|
fingerprint TEXT,
|
||||||
active BOOLEAN,
|
active BOOLEAN,
|
||||||
trust INTEGER,
|
trust INTEGER,
|
||||||
@@ -34,19 +32,10 @@ TABLE_LAYOUT = '''
|
|||||||
CREATE UNIQUE INDEX jid_fingerprint ON contacts (jid, fingerprint);'''
|
CREATE UNIQUE INDEX jid_fingerprint ON contacts (jid, fingerprint);'''
|
||||||
|
|
||||||
|
|
||||||
def _jid_adapter(jid):
|
|
||||||
return str(jid)
|
|
||||||
|
|
||||||
|
|
||||||
sqlite3.register_adapter(JID, _jid_adapter)
|
|
||||||
|
|
||||||
|
|
||||||
class Storage:
|
class Storage:
|
||||||
def __init__(self, folder_path):
|
def __init__(self, folder_path):
|
||||||
self._con = sqlite3.connect(str(folder_path / 'contacts.db'),
|
self._con = sqlite3.connect(str(folder_path / 'contacts.db'),
|
||||||
detect_types=sqlite3.PARSE_DECLTYPES)
|
detect_types=sqlite3.PARSE_COLNAMES)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
self._con.row_factory = self._namedtuple_factory
|
self._con.row_factory = self._namedtuple_factory
|
||||||
self._create_database()
|
self._create_database()
|
||||||
@@ -82,7 +71,15 @@ class Storage:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def load_contacts(self):
|
def load_contacts(self):
|
||||||
return self._con.execute('SELECT * from contacts').fetchall()
|
sql = '''SELECT jid as "jid [jid]",
|
||||||
|
fingerprint,
|
||||||
|
active,
|
||||||
|
trust,
|
||||||
|
timestamp,
|
||||||
|
comment
|
||||||
|
FROM contacts'''
|
||||||
|
|
||||||
|
return self._con.execute(sql).fetchall()
|
||||||
|
|
||||||
def save_contact(self, db_values):
|
def save_contact(self, db_values):
|
||||||
sql = '''REPLACE INTO
|
sql = '''REPLACE INTO
|
||||||
|
|||||||
Reference in New Issue
Block a user