mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Don't crash on weird character encodings
Expecting SQLite columns to all be valid utf8 doesn't work, because we are deailing with all kinds of databases. Instead, we now use the 'replace' encoding mode to replace any non-UTF8 characters with a [X] character.
This commit is contained in:
parent
c371f06fde
commit
4c7379a898
1 changed files with 2 additions and 1 deletions
3
app.py
3
app.py
|
|
@ -34,6 +34,7 @@ def get_conn(name):
|
|||
uri=True
|
||||
)
|
||||
conns[name].row_factory = sqlite3.Row
|
||||
conns[name].text_factory = lambda x: str(x, 'utf-8', 'replace')
|
||||
return conns[name]
|
||||
|
||||
|
||||
|
|
@ -279,7 +280,7 @@ def pks_for_table(conn, table):
|
|||
if row[-1]
|
||||
]
|
||||
rows.sort(key=lambda row: row[-1])
|
||||
return [r[1] for r in rows]
|
||||
return [str(r[1]) for r in rows]
|
||||
|
||||
|
||||
def path_from_row_pks(row, pks):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue