-
Notifications
You must be signed in to change notification settings - Fork 33
FIX: varchar columnsize does not account for utf8 conversion #392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ffelixg
wants to merge
14
commits into
microsoft:main
Choose a base branch
from
ffelixg:varchar_columnsize_small
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+206
−59
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
59fcad4
Document original behavior in test_encoding_buffersize
ffelixg c14964f
Remove trivially false isLob
ffelixg 459868a
Explain the buffer size issue in exception instead of attempting hope…
ffelixg a7e43dc
Raise exception instead of returning corrupted data for fetchone
ffelixg c211253
Actually fix the buffer size
ffelixg c6063ca
Rename test
ffelixg 11c94c4
Change multiplier to 4, add test which covers all of latin1
ffelixg 65ffc59
Merge branch 'main' into varchar_columnsize_small
gargsaumya 4446a50
Merge branch 'main' into varchar_columnsize_small
jahnvi480 bc2c767
Use recursive CTE instead of sys.objects in test
ffelixg 572516e
Remove now redundant hstmt arg from ColumnProcessors
ffelixg e634f24
Merge branch 'main' into varchar_columnsize_small
bewithgaurav 06d83a2
Windows tests assert that an exception/data corruption happens instea…
ffelixg 838af1b
Merge branch 'main' into varchar_columnsize_small
jahnvi480 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any specific reason of this number or is it random?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we are fetching varchar(x), the driver gives us x in the columnSize variable. The driver (msodbcsql18) however does not give us which collation the varchar(x) column uses. The Non-Windows drivers also convert the data to utf-8 no matter which collation is used by the column. So if it's a utf-8 collation, x equals the maximum number of bytes, so we're fine. If varchar(x) uses any other single byte collation, we must allocate the buffer large enough such that the result of a conversion to utf-8 fits. From my understanding, utf-8 tries to encode most characters of other collations with 2 bytes. Some later additions, like "€" to latin1 may require 3 bytes.
I've also verified this by iterating over all possible SQL Server collations and converting the result to utf-8. If there was a single byte collation with a character that requires more than 3 bytes, the following script would error. (posted this also in some copilot review comment)
Therefore x needs to be multiplied by 3 at least. +1 for the null terminator is fine, since the null terminator takes 1 byte no matter the encoding/collation.