What happens
Connecting to a SQL Server database that has a table called User (or Order, Group, Key, ... any T-SQL reserved word) makes the UI unusable. The connection itself succeeds, but the home page immediately fails:
INFO sql_studio::mssql: found 190 tables in Server=...;Database=erp;...
ERROR sql_studio::handlers: error while getting database overview: Token error: 'Incorrect syntax near the keyword 'User'.' on server ... executing on line 1 (code: 156, state: 1, class: 15)
The tables list and the individual table page fail the same way. Only the query editor still works.
Why
In mod mssql table names are interpolated into SQL without quoting:
let sql = format!("SELECT count(*) AS count FROM {}", count.name);
SELECT count(*) FROM User is a syntax error in T-SQL. The paged row fetch also does ORDER BY {first_column} unquoted, so a column named Key, Order, etc. breaks table data too.
Same problem elsewhere
- mysql: same pattern,
FROM {} and ORDER BY {first_column} unquoted. A table called order or group breaks it the same way.
- sqlite / libsql: table name is quoted but
ORDER BY {first_column} is not, so a first column named order, group, key... breaks the table data page.
- postgres, duckdb, parquet, csv and clickhouse already quote identifiers and are fine.
Fix
Quote identifiers at every interpolation site: [name] for mssql, `name` for mysql, "name" for sqlite/libsql, the same way the ClickHouse module already does with its quote_ident helper. PR ready.
Repro
Any SQL Server database with:
CREATE TABLE [User] (ID int);
then sql-studio mssql "<connection string>" and open the home page.
Version
sql-studio 0.1.52
What happens
Connecting to a SQL Server database that has a table called
User(orOrder,Group,Key, ... any T-SQL reserved word) makes the UI unusable. The connection itself succeeds, but the home page immediately fails:The tables list and the individual table page fail the same way. Only the query editor still works.
Why
In
mod mssqltable names are interpolated into SQL without quoting:SELECT count(*) FROM Useris a syntax error in T-SQL. The paged row fetch also doesORDER BY {first_column}unquoted, so a column namedKey,Order, etc. breaks table data too.Same problem elsewhere
FROM {}andORDER BY {first_column}unquoted. A table calledorderorgroupbreaks it the same way.ORDER BY {first_column}is not, so a first column namedorder,group,key... breaks the table data page.Fix
Quote identifiers at every interpolation site:
[name]for mssql,`name`for mysql,"name"for sqlite/libsql, the same way the ClickHouse module already does with itsquote_identhelper. PR ready.Repro
Any SQL Server database with:
CREATE TABLE [User] (ID int);then
sql-studio mssql "<connection string>"and open the home page.Version
sql-studio 0.1.52