From ee718b98b793df2a15b125cbf20816c9864bf7e9 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Thu, 26 Mar 2020 18:03:41 -0700 Subject: [PATCH] Verify SQLite DBs with check_connection --- datasette/app.py | 2 +- datasette/utils/__init__.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/datasette/app.py b/datasette/app.py index 98a31364..34300272 100644 --- a/datasette/app.py +++ b/datasette/app.py @@ -227,7 +227,7 @@ class Datasette: self.databases.pop(name) def scan_dirs(self): - # Recurse through self.dirs looking for new SQLite DBs + # Recurse through self.dirs looking for new SQLite DBs. Runs in a thread. while True: current_filepaths = { d.path for d in list(self.databases.values()) if d.path is not None diff --git a/datasette/utils/__init__.py b/datasette/utils/__init__.py index c15b7eae..f0a2cb89 100644 --- a/datasette/utils/__init__.py +++ b/datasette/utils/__init__.py @@ -603,7 +603,8 @@ def is_valid_sqlite(path): return False # Check we can run `select * from sqlite_master` try: - sqlite3.connect(str(path)).execute("select * from sqlite_master") + conn = sqlite3.connect(str(path)) + check_connection(conn) except Exception: return False return True