From 9b85f35b63c874fcc738aed1966490f397adaf0b Mon Sep 17 00:00:00 2001 From: Ross Williams Date: Mon, 16 Oct 2023 14:50:48 -0400 Subject: [PATCH] sqlite search: check SQLite version when indexing If creating the FTS5 tables fails due to a known version incompatiblity, report the required version to the user. --- archivebox/search/backends/sqlite.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/archivebox/search/backends/sqlite.py b/archivebox/search/backends/sqlite.py index b4c61efb..2fee789a 100644 --- a/archivebox/search/backends/sqlite.py +++ b/archivebox/search/backends/sqlite.py @@ -75,12 +75,23 @@ def _create_tables(): with get_connection() as cursor: # Create a contentless-delete FTS5 table that indexes # but does not store the texts of snapshots - cursor.execute( - f"CREATE VIRTUAL TABLE {table}" - f" USING fts5({column}," - f" tokenize={tokenizers}," - " content='', contentless_delete=1);" - ) + try: + cursor.execute( + f"CREATE VIRTUAL TABLE {table}" + f" USING fts5({column}," + f" tokenize={tokenizers}," + " content='', contentless_delete=1);" + ) + except Exception as e: + msg = str(e) + if 'unrecognized option: "contentlessdelete"' in msg: + sqlite_version = getattr(sqlite3, "sqlite_version", "Unknown") + raise RuntimeError( + "SQLite full-text search requires SQLite >= 3.43.0;" + f" the running version is {sqlite_version}" + ) from e + else: + raise # Create a one-to-one mapping between ArchiveBox snapshot_id # and FTS5 rowid, because the column type of rowid can't be # customized.