Decode SQL Server VARCHAR using column collation/codepage instead of UTF-8

Open
#1 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
52/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
rust, sql
Domain
database

Research direction

Start in src/value.rs at the MssqlType::VarChar branch and trace what collation or type metadata is available through value.type_info. Reproduce the shown VARCHAR query with non-ASCII text, then verify that the value no longer becomes a decode error or that callers receive enough raw information for a fallback.

Written by the indexing model from the issue text.

Description

sqlx-sqlserver 0.0.3 currently decodes MssqlType::VarChar with std::str::from_utf8(bytes). That works for ASCII, but SQL Server VARCHAR bytes are encoded according to the column/database collation code page, not necessarily UTF-8.\n\nRepro shape observed while migrating SQLPage to sqlx-sqlserver:\n\nsql\nselect 'Tu gères '';'' et ''"'' ?' as msg;\n\n\nAgainst SQL Server this returns a VARCHAR value. Decoding it as String fails with an invalid UTF-8 sequence for the non-ASCII byte, so SQLPage sees the value as a decode error/null. The same text works when the query uses an NVARCHAR literal:\n\nsql\nselect N'Tu gères '';'' et ''"'' ?' as msg;\n\n\nThe relevant code appears to be in src/value.rs:\n\nrust\nif matches!(value.type_info.kind(), MssqlType::VarChar) {\n return Ok(std::str::from_utf8(bytes)?.to_owned());\n}\n\n\nExpected behavior: VARCHAR should be decoded according to the SQL Server codepage/collation metadata, or the crate should expose enough raw value information for callers to perform that fallback themselves.\n\nSQLPage can work around tests by using NVARCHAR literals where Unicode is required, but user queries returning existing VARCHAR columns with non-ASCII text will still hit this.

Dominant language
Rust
Stars
4
Forks
0
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.