Skip to content

fix(mssql): find edited rows by text outside code page 1252 - #824

Merged
DokaDev merged 1 commit into
mainfrom
fix/mssql-edit-find-non-1252
Dec 6, 2026
Merged

DokaDev merged 1 commit into
mainfrom
fix/mssql-edit-find-non-1252

Conversation

@DokaDev

@DokaDev DokaDev commented Dec 6, 2026

Copy link
Copy Markdown
Owner

Related issue: #762

What and why

On SQL Server, an edit that found its row by the text of a char or varchar column compared
col COLLATE Latin1_General_100_BIN2 = N'…'. Applying that collation to a varchar value
converts it to code page 1252 first, so every character outside 1252 turned into ? and no row
matched: updating such a cell, deleting such a row or finding a row by its values was refused.
Nothing was written to a wrong row. It hit every non-1252 page (_UTF8 collations, Korean 949,
Japanese 932, Cyrillic 1251 and the others).

I now compare char and varchar text as Unicode first:

[col] = N'…' AND CAST([col] AS nvarchar(max)) COLLATE Latin1_General_100_BIN2 = N'…'
    AND DATALENGTH(CAST([col] AS nvarchar(max))) = DATALENGTH(N'…')
Column type Before After
char, varchar [col] COLLATE … = N'…' (converted to 1252) CAST([col] AS nvarchar(max)) COLLATE … = N'…'
nchar, nvarchar, sysname [col] COLLATE … = N'…' unchanged
a type of the user's over char/varchar [col] = N'…' only as char/varchar
a type of the user's over nchar/nvarchar [col] = N'…' only as nchar/nvarchar
text, ntext never used to find a row (they do not compare exactly) unchanged
other types unchanged unchanged

NULL is still found with IS NULL. The other engines are not touched: the MySQL writer
already converts to utf8mb4 before its binary collation, PostgreSQL and SQLite have no code
pages.

A type of the user's (an alias type, CREATE TYPE … FROM varchar(20)) now compares as the type
it is over, which the structure already names. Such a type can only be part of a key here (it
does not count as exact for a row found by its values), where the extra conditions only narrow
a match the key already makes unique.

Checks

  • Unit tests (edit::sql::mssql): with the fix removed, the new
    text_of_a_code_page_is_compared_as_unicode and text_and_bytes_are_compared_exactly fail
    (2 failed, 6 passed); with the fix and the recorded statements (golden/writer_mssql.txt)
    re-recorded, 8 passed. The recorded statements change only for the varchar column.

  • Live test a_row_is_found_by_text_outside_code_page_1252 (edits_mssql.rs, SQL Server
    2022): stored tables with a _UTF8, a Korean (949) and a Cyrillic (1251) varchar column
    and a Korean char(4) column, found by values, and a table found by a Korean varchar
    primary key. A row holding literal ? values sits next to the rows with characters outside
    1252, with the same other values. Each edited row is counted once, updated or deleted, and
    the rows read back are exactly the expected ones.

    • On main: fails at the count of the first row, left: 0, right: 1, on
      [utf8] COLLATE Latin1_General_100_BIN2 = N'…' (no row found).
    • With the fix: test a_row_is_found_by_text_outside_code_page_1252 ... ok.
    • The whole edits_mssql target: 16 passed, 0 failed.
    • No zz_ objects left on the server after the runs, and the dev databases' checksums are
      the same before and after.
  • cargo fmt --all --check: pass

  • cargo clippy --workspace --all-targets --locked -- -D warnings: pass

  • python3 scripts/text-style.py, scripts/changes.sh check changes/*/*.md: pass

  • This change was discussed and assigned in its issue (or is a small fix such as a typo)

  • A page of docs/site/src describes what users see change (or no doc change: …)

  • A fragment changes/<kind>/<slug>.md for a change to crates/ (or
    no changelog: …)

  • Generated docs regenerated with DATARIG_BLESS=1 cargo test -p datarig-tui --test <test>
    (keybindings_doc, themes_doc, config_doc, cli_doc, book_screens): not needed

An edit that found its row by the text of a char or varchar column
compared it with COLLATE Latin1_General_100_BIN2. Applying that
collation to a varchar value converts it to code page 1252 first, so
every character outside 1252 became '?' and no row matched: updating
such a cell, deleting such a row or finding a row by its values was
refused.

Compare char and varchar text as nvarchar before the binary
collation. nchar and nvarchar stay as they were, and a type of the
user's now compares as the type it is over.

Part of #762
@DokaDev DokaDev added this to the 0.48.0 milestone Dec 6, 2026
@DokaDev DokaDev added the bug Something isn't working label Dec 6, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 6, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-06T13:34:27.366072Z c764f87 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@DokaDev
DokaDev merged commit 873f504 into main Dec 6, 2026
21 checks passed
@DokaDev
DokaDev deleted the fix/mssql-edit-find-non-1252 branch December 6, 2026 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant