Skip to content

Detect full-text indexes for table names containing double quotes - #985

Open
khushalx wants to merge 2 commits into
simonw:mainfrom
khushalx:codex/quoted-fts-table-detection
Open

khushalx wants to merge 2 commits into
simonw:mainfrom
khushalx:codex/quoted-fts-table-detection

Conversation

@khushalx

@khushalx khushalx commented Dec 2, 2026 •

Copy link
Copy Markdown

Fixes #984.

Use quote_identifier() to match SQLite’s doubled quotes in detect_fts(). Exclude matches where the apparent closing quote is part of an escaped quote, so a cannot select the index for a"b, whether a has its own index or none. Keep legacy bracket quoting and LIKE wildcard escaping.

Regression tests cover FTS4 and FTS5, quoted names, %, _, backslashes, search and index removal. The 24 additional cases from review fail on the preceding PR head and pass with the fix. They verify that disable_fts() preserves the neighboring table’s index and triggers. Update the existing tracer test’s expected SQL.

Validation on Python 3.12.16 / SQLite 3.53.1: 1,662 passed and 17 skipped in each of the normal and --sqlite-autocommit runs. Black, flake8, mypy, Pyright, ty, Cog, codespell and git diff --check pass.

AI assistance: OpenAI Codex helped investigate, implement and test this change.


📚 Documentation preview 📚: https://sqlite-utils--985.org.readthedocs.build/en/985/

@atishay-kasliwal atishay-kasliwal left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With FTS4 and FTS5, detect_fts() now finds the index for a"b, "lead, x%"y and u_"v (master: None). docs, trail" and br]k are unchanged.

Comment thread sqlite_utils/db.py Outdated
args = {
"like": f"%VIRTUAL TABLE%USING FTS%content=[{escaped_name}]%",
"like2": f'%VIRTUAL TABLE%USING FTS%content="{escaped_name}"%',
"like2": f"%VIRTUAL TABLE%USING FTS%content={quote_identifier(escaped_name)}%",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other direction still matches because of the trailing %. A table a with no FTS, next to a"b with FTS, returns a"b_fts from a.detect_fts(), since content="a"% matches content="a""b". Same for docs next to docs". That happens here and on master, with FTS4 and FTS5. An extra AND sql NOT LIKE '%content="a""%', or comparing the parsed content= value in Python, would close it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Full-text index detection mishandles double quotes in table names

2 participants