From 1a28416e1095f2b8015195db7f8273b6f7953ab6 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Sun, 21 Jun 2026 15:54:19 -0700 Subject: [PATCH] Fix for detect_fts failing on [], refs #694 --- sqlite_utils/db.py | 2 +- tests/test_fts.py | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/sqlite_utils/db.py b/sqlite_utils/db.py index 677a1f8..d447cd2 100644 --- a/sqlite_utils/db.py +++ b/sqlite_utils/db.py @@ -2776,7 +2776,7 @@ class Table(Queryable): ) """).strip() args = { - "like": '%VIRTUAL TABLE%USING FTS%content="{}"%'.format(self.name), + "like": "%VIRTUAL TABLE%USING FTS%content=[{}]%".format(self.name), "like2": '%VIRTUAL TABLE%USING FTS%content="{}"%'.format(self.name), "table": self.name, } diff --git a/tests/test_fts.py b/tests/test_fts.py index 9c635ff..ba4b32c 100644 --- a/tests/test_fts.py +++ b/tests/test_fts.py @@ -420,6 +420,29 @@ def test_enable_fts_replace_does_nothing_if_args_the_same(): assert all(q[0].startswith("select ") for q in queries) +def test_enable_fts_replace_handles_legacy_bracket_quoted_content_table(): + db = Database(memory=True) + db["books"].insert( + { + "id": 1, + "title": "Habits of Australian Marsupials", + "author": "Marlee Hawkins", + }, + pk="id", + ) + db.executescript(""" + CREATE VIRTUAL TABLE [books_fts] USING FTS5 ( + [title], + content=[books] + ); + """) + + db["books"].enable_fts(["title", "author"], replace=True) + + assert db["books_fts"].columns_dict.keys() == {"title", "author"} + assert 'content="books"' in db["books_fts"].schema + + def test_enable_fts_error_message_on_views(): db = Database(memory=True) db.create_view("hello", "select 1 + 1")