From 012fc7c5cd3e9160c9a4c19cc964253e97fb054a Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Tue, 20 Mar 2018 18:26:04 -0700 Subject: [PATCH] Fix for FTS virtual table counting error --- datasette/app.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/datasette/app.py b/datasette/app.py index e7a5ce48..e07cb2ef 100644 --- a/datasette/app.py +++ b/datasette/app.py @@ -929,9 +929,14 @@ class Datasette: ] views = [v[0] for v in conn.execute('select name from sqlite_master where type = "view"')] for table in table_names: - count = conn.execute( - 'select count(*) from {}'.format(escape_sqlite_table_name(table)) - ).fetchone()[0] + try: + count = conn.execute( + 'select count(*) from {}'.format(escape_sqlite_table_name(table)) + ).fetchone()[0] + except sqlite3.OperationalError: + # This can happen when running against a FTS virtual tables + # e.g. "select count(*) from some_fts;" + count = 0 label_column = None # If table has two columns, one of which is ID, then label_column is the other one column_names = [r[1] for r in conn.execute(