Skip to content

fix-spaces: allow queries on column names with spaces - #387

Open
polina-alekseeva-rogii wants to merge 7 commits into
tiberius-rs:mainfrom
polina-alekseeva-rogii:fix-spaces
Open

fix-spaces: allow queries on column names with spaces#387
polina-alekseeva-rogii wants to merge 7 commits into
tiberius-rs:mainfrom
polina-alekseeva-rogii:fix-spaces

Conversation

@polina-alekseeva-rogii

Copy link
Copy Markdown

Changed the code to support spaces in column names in bulk insert.

joelparkerhenderson added a commit to mssql-rust/mssql-rust that referenced this pull request Aug 29, 2026
Combines tiberius-rs/tiberius#387 (correct escaping) and #388 (test
coverage) -- neither alone was complete: #387 escapes an embedded `]`
but ships no test, #388 has a test but doesn't escape `]`. Also
resolves the same underlying bug reported separately in #296/#398.

A column named after a reserved word or containing a space (e.g.
`[End]`) broke bulk_insert, since the INSERT BULK/SELECT TOP 0
statement text that MetaDataColumn::Display generates from the
server's own reported column metadata didn't quote the name at all.
Now brackets it, doubling any literal `]` per SQL Server's own escaping
rule for quoted identifiers (`]` -> `]]`), so a column that itself
contains `]` can't break out of the quoted identifier into the
surrounding statement text.

Added regression tests in both tests/bulk.rs (a bulk_insert into an
`[End] INT` column) and tests/query.rs (manually-bracket-quoted
execute/query against the same), ported from #388. Confirmed the
bulk.rs test fails without this fix ("Incorrect syntax near the
keyword 'End'") and passes with it.

Note: Client::bulk_insert_columns's caller-supplied column list (added
this session, #359) is a related but separate gap -- it isn't
bracket-quoted either, and fixing that needs to special-case the "*"
wildcard so it isn't itself quoted. Left out of scope here to avoid
touching that just-shipped, already-tested feature; worth a follow-up.

Verified live against a real SQL Server (Azure SQL Edge via rustls):
292 tests total (202 in tests/query.rs, 90 in tests/bulk.rs). Also
verified: cargo check across all 6 CI feature combinations, cargo
clippy --all-targets, cargo fmt --check, and cargo test --lib (153
passing).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0156Di1tRRLsJK8ctU1AmAJr
joelparkerhenderson added a commit to mssql-rust/mssql-rust that referenced this pull request Aug 30, 2026
Combines tiberius-rs/tiberius#387 (correct escaping) and #388 (test
coverage) -- neither alone was complete: #387 escapes an embedded `]`
but ships no test, #388 has a test but doesn't escape `]`. Also
resolves the same underlying bug reported separately in #296/#398.

A column named after a reserved word or containing a space (e.g.
`[End]`) broke bulk_insert, since the INSERT BULK/SELECT TOP 0
statement text that MetaDataColumn::Display generates from the
server's own reported column metadata didn't quote the name at all.
Now brackets it, doubling any literal `]` per SQL Server's own escaping
rule for quoted identifiers (`]` -> `]]`), so a column that itself
contains `]` can't break out of the quoted identifier into the
surrounding statement text.

Added regression tests in both tests/bulk.rs (a bulk_insert into an
`[End] INT` column) and tests/query.rs (manually-bracket-quoted
execute/query against the same), ported from #388. Confirmed the
bulk.rs test fails without this fix ("Incorrect syntax near the
keyword 'End'") and passes with it.

Note: Client::bulk_insert_columns's caller-supplied column list (added
this session, #359) is a related but separate gap -- it isn't
bracket-quoted either, and fixing that needs to special-case the "*"
wildcard so it isn't itself quoted. Left out of scope here to avoid
touching that just-shipped, already-tested feature; worth a follow-up.

Verified live against a real SQL Server (Azure SQL Edge via rustls):
292 tests total (202 in tests/query.rs, 90 in tests/bulk.rs). Also
verified: cargo check across all 6 CI feature combinations, cargo
clippy --all-targets, cargo fmt --check, and cargo test --lib (153
passing).

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

2 participants