Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This pull request enhances Unicode string handling in the SQL type mapping logic to properly support emojis and special characters. The key improvement addresses the incorrect sizing calculation for Unicode strings by using UTF-16 code unit length instead of Python string length.
- Updated
_map_sql_typemethod to calculate UTF-16 code unit length for Unicode parameters - Added comprehensive test coverage for emoji and special character round-trip operations
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| mssql_python/cursor.py | Fixed Unicode string length calculation by using UTF-16 encoding length instead of Python string length |
| tests/test_004_cursor.py | Added comprehensive test for emoji and special character round-trip database operations |
353dad1 to
6ef29c1
Compare
bewithgaurav
previously approved these changes
Aug 6, 2025
bewithgaurav
previously approved these changes
Aug 6, 2025
sumitmsft
reviewed
Aug 7, 2025
sumitmsft
reviewed
Aug 7, 2025
sumitmsft
reviewed
Aug 7, 2025
sumitmsft
reviewed
Aug 7, 2025
sumitmsft
reviewed
Aug 7, 2025
sumitmsft
requested changes
Aug 28, 2025
8c34858 to
056c810
Compare
sumitmsft
approved these changes
Aug 28, 2025
bewithgaurav
approved these changes
Aug 28, 2025
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.
Work Item / Issue Reference
Summary
This pull request improves Unicode string handling in the SQL type mapping logic and adds comprehensive tests for round-tripping emoji and special characters in the database. The main focus is on ensuring that Unicode strings, including those with emojis and special characters, are correctly mapped and stored in SQL Server.
Unicode string mapping improvements:
_map_sql_typemethod incursor.pyto use the UTF-16 code unit length for Unicode string parameters instead of the Python string length, ensuring correct sizing for both long and short Unicode strings. [1] [2]Testing enhancements:
test_emoji_round_tripintest_004_cursor.pyto verify that various emoji, accented, and non-Latin characters can be inserted and retrieved accurately from the database, improving coverage for Unicode edge cases.