mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Refactored run_sanity_checks to check_connection(conn), refs #674
This commit is contained in:
parent
f1442a8151
commit
d3f2fade88
4 changed files with 60 additions and 21 deletions
|
|
@ -790,3 +790,28 @@ class RequestParameters(dict):
|
|||
def getlist(self, name, default=None):
|
||||
"Return full list"
|
||||
return super().get(name, default)
|
||||
|
||||
|
||||
class ConnectionProblem(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class SpatialiteConnectionProblem(ConnectionProblem):
|
||||
pass
|
||||
|
||||
|
||||
def check_connection(conn):
|
||||
tables = [
|
||||
r[0]
|
||||
for r in conn.execute(
|
||||
"select name from sqlite_master where type='table'"
|
||||
).fetchall()
|
||||
]
|
||||
for table in tables:
|
||||
try:
|
||||
conn.execute("PRAGMA table_info({});".format(escape_sqlite(table)),)
|
||||
except sqlite3.OperationalError as e:
|
||||
if e.args[0] == "no such module: VirtualSpatialIndex":
|
||||
raise SpatialiteConnectionProblem(e)
|
||||
else:
|
||||
raise ConnectionProblem(e)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue