Repository navigation
fix(mssql): find edited rows by text outside code page 1252 - #824
Merged
Merged
Conversation
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
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Closed
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related issue: #762
What and why
On SQL Server, an edit that found its row by the text of a
charorvarcharcolumn comparedcol COLLATE Latin1_General_100_BIN2 = N'…'. Applying that collation to avarcharvalueconverts it to code page 1252 first, so every character outside 1252 turned into
?and no rowmatched: 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 (
_UTF8collations, Korean 949,Japanese 932, Cyrillic 1251 and the others).
I now compare
charandvarchartext as Unicode first:char,varchar[col] COLLATE … = N'…'(converted to 1252)CAST([col] AS nvarchar(max)) COLLATE … = N'…'nchar,nvarchar,sysname[col] COLLATE … = N'…'char/varchar[col] = N'…'onlychar/varcharnchar/nvarchar[col] = N'…'onlynchar/nvarchartext,ntextNULLis still found withIS NULL. The other engines are not touched: the MySQL writeralready converts to
utf8mb4before its binary collation, PostgreSQL and SQLite have no codepages.
A type of the user's (an alias type,
CREATE TYPE … FROM varchar(20)) now compares as the typeit 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 newtext_of_a_code_page_is_compared_as_unicodeandtext_and_bytes_are_compared_exactlyfail(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
varcharcolumn.Live test
a_row_is_found_by_text_outside_code_page_1252(edits_mssql.rs, SQL Server2022): stored tables with a
_UTF8, a Korean (949) and a Cyrillic (1251)varcharcolumnand a Korean
char(4)column, found by values, and a table found by a Koreanvarcharprimary key. A row holding literal
?values sits next to the rows with characters outside1252, with the same other values. Each edited row is counted once, updated or deleted, and
the rows read back are exactly the expected ones.
left: 0, right: 1, on[utf8] COLLATE Latin1_General_100_BIN2 = N'…'(no row found).test a_row_is_found_by_text_outside_code_page_1252 ... ok.edits_mssqltarget: 16 passed, 0 failed.zz_objects left on the server after the runs, and the dev databases' checksums arethe same before and after.
cargo fmt --all --check: passcargo clippy --workspace --all-targets --locked -- -D warnings: passpython3 scripts/text-style.py,scripts/changes.sh check changes/*/*.md: passThis change was discussed and assigned in its issue (or is a small fix such as a typo)
A page of
docs/site/srcdescribes what users see change (orno doc change: …)A fragment
changes/<kind>/<slug>.mdfor a change tocrates/(orno 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