Conversation
…f/Replace translations
SqlServerStringMethodTranslator applied CharTypeMapping to char arguments of
string.IndexOf(char) and string.Replace(char, char). CharTypeMapping's literal has
no N prefix, so a constant such as 'ş' or '中' was emitted as a non-Unicode literal
and best-fit mapped to the database code page before the comparison: on the
default collation `CHARINDEX('ş', N'aşb')` returns 0 while `CHARINDEX('ş', N'asb')`
returns 2, and `REPLACE(N'Şişlis', 'ş', 'x')` replaces the trailing 's'. Passing the
same char as a parameter (sent as nvarchar) gave the right answer, and an
ExecuteUpdate with an inline char could silently corrupt data.
Emit char constants as string constants with the string argument's type mapping
(N'ş' for nvarchar columns) and keep CharTypeMapping only for non-constant char
expressions. Existing baselines change from 'e' to N'e' accordingly; a varchar
column still gets a non-Unicode literal.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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.
…f/Replace translations
SqlServerStringMethodTranslator applied CharTypeMapping to char arguments of string.IndexOf(char) and string.Replace(char, char). CharTypeMapping's literal has no N prefix, so a constant such as 'ş' or '中' was emitted as a non-Unicode literal and best-fit mapped to the database code page before the comparison: on the default collation
CHARINDEX('ş', N'aşb')returns 0 whileCHARINDEX('ş', N'asb')returns 2, andREPLACE(N'Şişlis', 'ş', 'x')replaces the trailing 's'. Passing the same char as a parameter (sent as nvarchar) gave the right answer, and an ExecuteUpdate with an inline char could silently corrupt data.Emit char constants as string constants with the string argument's type mapping (N'ş' for nvarchar columns) and keep CharTypeMapping only for non-constant char expressions. Existing baselines change from 'e' to N'e' accordingly; a varchar column still gets a non-Unicode literal.