Emit N prefix for xml string literals in SQL Server#38460
Closed
Copilot wants to merge 2 commits into
Closed
Conversation
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix missing N prefix for xml constants in queries
Emit N prefix for xml string literals in SQL Server
Jun 18, 2026
ErikEJ
reviewed
Jun 18, 2026
| _isUtf16 = parameters.Unicode && parameters.StoreType.StartsWith("n", StringComparison.OrdinalIgnoreCase); | ||
| _isUtf16 = parameters.Unicode | ||
| && (parameters.StoreType.StartsWith("n", StringComparison.OrdinalIgnoreCase) | ||
| || parameters.StoreType.StartsWith("xml", StringComparison.OrdinalIgnoreCase)); |
Contributor
There was a problem hiding this comment.
Equals("xml", StringComparison.OrdinalIgnoreCase)) ?
Member
|
Superseded by #38462 |
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.
String constants mapped to the SQL Server
xmlstore type were generated without theNprefix, so they were treated as non-Unicodevarchar. The database collation's codepage was then applied, silently corrupting characters outside it (e.g. emoji in XML attribute values).Changes
SqlServerStringTypeMapping: extend the_isUtf16detection to also recognize thexmlstore type. Thexmlmapping is created withunicode: truebut a store type of"xml", which the existingStartsWith("n")guard excluded.StartsWith("n")guard (rather than reverting to plainparameters.Unicode) to preserve its original intent: a property mapped as Unicode but with an explicit non-Unicode store type (e.g.varchar) must not get anNprefix.xmlis genuinely a Unicode store type, so it is added alongsiden*.This also propagates to the related literal pieces (
nchar(10/13)andCAST(... AS nvarchar(max))insideCONCAT).Tests
GenerateProviderValueSqlLiteral_works_xmlcovering plain, escaped-apostrophe, emoji, and line-feed/CONCATcases to confirm xml literals now emitN'...',nchar, andnvarchar(max).