Merged
Conversation
… bewithgaurav/fix_blank_columns
… bewithgaurav/fix_executemany
…icrosoft/mssql-python into bewithgaurav/fix_executemany
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes binary data handling in the mssql-python library, specifically addressing issues with empty strings and binary data that previously caused assertion failures. The fix improves UTF-16 conversion on Unix platforms and ensures proper handling of zero-length data.
- Fixes assertion failures when handling empty strings and binary data
- Improves UTF-16 string conversion for Unix platforms (Linux/macOS)
- Updates SQL type mapping to use VARBINARY instead of BINARY for better compatibility
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| tests/test_004_cursor.py | Adds comprehensive test cases for empty string/binary handling and fixes existing test expectations |
| mssql_python/pybind/ddbc_bindings.cpp | Fixes core data handling logic for empty strings/binary and improves UTF-16 conversion |
| mssql_python/cursor.py | Updates SQL type mapping to use VARBINARY and ensures minimum column sizes |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
sumitmsft
approved these changes
Sep 8, 2025
jahnvi480
approved these changes
Sep 8, 2025
gargsaumya
approved these changes
Sep 8, 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 how binary data (Python
bytesandbytearray) is handled in the MSSQL Python driver, especially for edge cases like empty values, mixed types, and large binaries. It also significantly expands the test suite to cover these scenarios and documents current driver limitations regarding parameter and fetch buffer sizes.Binary Data Handling Improvements
_map_sql_typeincursor.pyto always useVARBINARYfor Pythonbytes/bytearray, avoiding storage waste and ensuring correct handling of variable-length data. This removes previous logic that sometimes used fixed-lengthBINARYand simplifies type mapping._select_best_sample_valueto correctly handle columns that contain only binary types (bytesorbytearray).Test Suite Enhancements for Binary Data
test_longvarbinarytest to expect the correct number of rows and removed assumptions about zero-padding in returned binary data.bytes.bytesandbytearraytypes in the same column, confirming consistent storage and retrieval asbytes.