Skip to content

fix: quote table and column identifiers in mssql, mysql, sqlite and libsql queries - #77

Open
xavpain wants to merge 2 commits into
frectonz:mainfrom
xavpain:fix/mssql-quote-identifiers
Open

fix: quote table and column identifiers in mssql, mysql, sqlite and libsql queries#77
xavpain wants to merge 2 commits into
frectonz:mainfrom
xavpain:fix/mssql-quote-identifiers

Conversation

@xavpain

@xavpain xavpain commented Aug 25, 2026

Copy link
Copy Markdown

Fixes #76

Problem

Table and column names were interpolated raw into the count(*) and paging queries. Any table named after a reserved word (User, Order, Group, ...) broke the overview, tables list, table page and table data endpoints:

error while getting database overview: Token error: 'Incorrect syntax near the keyword 'User'.' ...

Change

  • mssql: add quote_ident (bracket quoting, ] doubled) and use it at all four interpolation sites (overview count, tables count, table count, table data FROM + ORDER BY).
  • mysql: same, with backtick quoting (` doubled).
  • sqlite / libsql: the table name was already quoted, but ORDER BY {first_column} was not. Quote it with "...".

postgres, duckdb, parquet, csv and clickhouse already quote identifiers, no change there.

Tested

  • mssql against a SQL Server 2019 ERP database with a User table (190 tables): /api/, /api/tables, /api/tables/User, /api/tables/User/data?page=1 all return 200 (previously 500 on the overview).
  • sqlite and libsql with a table "order" whose columns are "group" and "select": table data page returns rows sorted by "group".
  • mysql not tested against a live server (no instance at hand), same code shape as mssql.

🤖 Generated with Claude Code

https://claude.ai/code/session_014KHtEx6XUzzfa8QHsEUP9p

xpain and others added 2 commits August 25, 2026 10:36
Table and column names were interpolated raw into count and paging
queries. A table named after a T-SQL reserved word (User, Order,
Group, ...) broke the overview, tables list, table page and table
data endpoints with 'Incorrect syntax near the keyword'.

Add quote_ident that wraps identifiers in [] and escapes ] and use it
at every interpolation site in the mssql module.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014KHtEx6XUzzfa8QHsEUP9p
Same class of bug as the mssql fix: mysql interpolated table names raw
into count(*) and SELECT * queries, and sqlite/libsql left the ORDER BY
column unquoted. A table or first column named after a reserved word
(order, group, key, ...) broke those pages.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014KHtEx6XUzzfa8QHsEUP9p
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.

MSSQL: a table named after a reserved word (e.g. User) breaks the overview, tables list and table pages

1 participant