From 8ef28f85716cb46d1d7d2e4578de0edd8aec4e82 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Mon, 2 Mar 2020 20:11:33 +1000 Subject: [PATCH] drop echo and text factory --- pylib/anki/dbproxy.py | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/pylib/anki/dbproxy.py b/pylib/anki/dbproxy.py index 1d11e2a03..b104ec1b0 100644 --- a/pylib/anki/dbproxy.py +++ b/pylib/anki/dbproxy.py @@ -1,6 +1,8 @@ # Copyright: Ankitects Pty Ltd and contributors # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html +# fixme: lossy utf8 handling + import os import time from sqlite3 import Cursor @@ -11,9 +13,7 @@ from typing import Any, List, Type class DBProxy: def __init__(self, path: str, timeout: int = 0) -> None: self._db = sqlite.connect(path, timeout=timeout) - self._db.text_factory = self._textFactory self._path = path - self.echo = os.environ.get("DBECHO") self.mod = False def execute(self, sql: str, *a, **ka) -> Cursor: @@ -29,32 +29,19 @@ class DBProxy: else: # execute("...where id = ?", 5) res = self._db.execute(sql, a) - if self.echo: - # print a, ka - print(sql, "%0.3fms" % ((time.time() - t) * 1000)) - if self.echo == "2": - print(a, ka) return res def executemany(self, sql: str, l: Any) -> None: self.mod = True t = time.time() self._db.executemany(sql, l) - if self.echo: - print(sql, "%0.3fms" % ((time.time() - t) * 1000)) - if self.echo == "2": - print(l) def commit(self) -> None: t = time.time() self._db.commit() - if self.echo: - print("commit %0.3fms" % ((time.time() - t) * 1000)) def executescript(self, sql: str) -> None: self.mod = True - if self.echo: - print(sql) self._db.executescript(sql) def rollback(self) -> None: @@ -104,9 +91,5 @@ class DBProxy: else: self._db.isolation_level = "" - # strip out invalid utf-8 when reading from db - def _textFactory(self, data: bytes) -> str: - return str(data, errors="ignore") - def cursor(self, factory: Type[Cursor] = Cursor) -> Cursor: return self._db.cursor(factory)