prevent exceptions when invalid utf-8 in db

This commit is contained in:
Damien Elmes 2018-01-20 11:23:49 +10:00
parent 6113785b2f
commit 6077611646

View file

@ -12,6 +12,7 @@ DBError = sqlite.Error
class DB:
def __init__(self, path, timeout=0):
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
@ -102,3 +103,7 @@ class DB:
self._db.isolation_level = None
else:
self._db.isolation_level = ''
# strip out invalid utf-8 when reading from db
def _textFactory(self, data):
return str(data, errors="ignore")