Fix for detect_fts failing on [], refs #694

This commit is contained in:
Simon Willison 2026-06-21 15:54:19 -07:00
commit 1a28416e10
2 changed files with 24 additions and 1 deletions

View file

@ -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,
}

View file

@ -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")