drop echo and text factory
This commit is contained in:
parent
c1252d68f0
commit
8ef28f8571
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user