mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 00:36:38 -04:00
prevent exceptions when invalid utf-8 in db
This commit is contained in:
parent
6113785b2f
commit
6077611646
1 changed files with 5 additions and 0 deletions
|
@ -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")
|
||||
|
|
Loading…
Reference in a new issue