From f8630bb2ed11edb05efecd7b440852c01d37e2b6 Mon Sep 17 00:00:00 2001 From: Lee Miller Date: Fri, 13 Sep 2024 06:14:21 +0300 Subject: [PATCH] Set the row_factory for the sqlite3.Connection --- minode/sql.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/minode/sql.py b/minode/sql.py index 4259ce9..382f540 100644 --- a/minode/sql.py +++ b/minode/sql.py @@ -39,18 +39,17 @@ class Inventory(): cur.execute('VACUUM') cur.execute("INSERT INTO status VALUES ('lastvacuumtime', ?)", (now,)) self._db.commit() + self._db.row_factory = self.__object @staticmethod def __object(cursor, row): + if len(cursor.description) != 8: + return row vector, expires, obj_type, version, stream, tag, data, offset = row return structure.Object( expires, obj_type, version, stream, data, offset, tag=tag, vector=vector) - def __objects(self, cur): - cur.row_factory = self.__object - return cur - def cleanup(self): with shared.objects_lock: self._db.execute( @@ -74,7 +73,7 @@ class Inventory(): cur = self._db.execute( 'SELECT * FROM objects WHERE ' # nosec B608 + ' AND '.join(clauses), params) - return self.__objects(cur) + return cur def vectors_to_send(self, stream=None): cur = self._db.execute( @@ -95,8 +94,7 @@ class Inventory(): return (v for v, in cur) def values(self): - cur = self._db.execute('SELECT * FROM objects') - return self.__objects(cur) + return self._db.execute('SELECT * FROM objects') def popitem(self): if not self.rowid: