Open
Description
When a table name contains _ or %, detect_fts() treats those characters as SQL LIKE wildcards. It can select another table's FTS index and use its matching row IDs against the requested table.
from sqlite_utils import Database
db = Database(memory=True)
db["bookXtitles"].insert({"title": "incorrect"}).enable_fts(["title"])
db["book_titles"].insert({"title": "correct"}).enable_fts(["title"])
print(db["book_titles"].detect_fts())
print(list(db["book_titles"].search("incorrect")))Current main prints bookXtitles_fts and returns the row containing correct, even though that row does not match the search. It should detect book_titles_fts and return no rows for this query.
The same issue occurs with % in the table name. The table-name portion of the LIKE patterns needs escaping. The quote delimiters added for #434 prevent prefix matches but leave wildcard characters active.
Reproduced on Python 3.12 and SQLite 3.53.1 using current main.
Metadata
Metadata
Assignees
Labels
No labels
Activity