From b4bf19d9d5e6d910b3a42a4315ec1f754fefa3f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Mon, 18 Feb 2019 19:43:03 +0100 Subject: [PATCH] [omemo] Sqlite use text factory bytes Sqlite/Pythons detection what to convert to a string seems not reliable, so always return bytes and convert all TEXT columns --- omemo/backend/liteaxolotlstore.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/omemo/backend/liteaxolotlstore.py b/omemo/backend/liteaxolotlstore.py index 7ae01e8..bc8b1f8 100644 --- a/omemo/backend/liteaxolotlstore.py +++ b/omemo/backend/liteaxolotlstore.py @@ -39,9 +39,18 @@ from omemo.backend.util import DEFAULT_PREKEY_AMOUNT log = logging.getLogger('gajim.plugin_system.omemo') +def _convert_to_string(text): + return text.decode() + + +sqlite3.register_converter('TEXT', _convert_to_string) + + class LiteAxolotlStore(AxolotlStore): def __init__(self, db_path): - self._con = sqlite3.connect(db_path, check_same_thread=False) + self._con = sqlite3.connect(db_path, + detect_types=sqlite3.PARSE_DECLTYPES) + self._con.text_factory = bytes self._con.row_factory = self._namedtuple_factory self.createDb() self.migrateDb()