Commit 6ec0949
### Work Item / Issue Reference
<!--
IMPORTANT: Please follow the PR template guidelines below.
For mssql-python maintainers: Insert your ADO Work Item ID below
For external contributors: Insert Github Issue number below
Only one reference is required - either GitHub issue OR ADO Work Item.
-->
<!-- mssql-python maintainers: ADO Work Item -->
>
[AB#43177](https://sqlclientdrivers.visualstudio.com/c6d89619-62de-46a0-8b46-70b92a84d85e/_workitems/edit/43177)
<!-- External contributors: GitHub Issue -->
> GitHub Issue: #468
-------------------------------------------------------------------
### Summary
<!-- Insert your summary of changes below. Minimum 10 characters
required. -->
This pull request updates the default handling of SQL `CHAR`/`VARCHAR`
columns to use UTF-16 (wide character) encoding instead of UTF-8,
primarily to address encoding mismatches on Windows and ensure
consistent Unicode decoding. The changes span the connection, cursor,
and C++ binding layers, and update related tests to reflect the new
default behavior.
**Default Encoding and Decoding Changes:**
* The default decoding for SQL `CHAR` columns is now set to use
`"utf-16le"` encoding and the `SQL_WCHAR` ctype, replacing the previous
`"utf-8"`/`SQL_CHAR` defaults. This avoids issues where Windows ODBC
drivers return raw bytes in the server's native code page, which may not
decode as UTF-8. (`mssql_python/connection.py`,
[mssql_python/connection.pyR264-R271](diffhunk://#diff-29bb94de45aae51c23a6426d40133c28e4161e68769e08d046059c7186264e90R264-R271))
* All cursor fetch methods (`fetchone`, `fetchmany`, `fetchall`) are
updated to request UTF-16 decoding and pass the correct ctype when
fetching `CHAR` data, ensuring consistent behavior across platforms.
(`mssql_python/cursor.py`,
[[1]](diffhunk://#diff-deceea46ae01082ce8400e14fa02f4b7585afb7b5ed9885338b66494f5f38280L2371-R2373)
[[2]](diffhunk://#diff-deceea46ae01082ce8400e14fa02f4b7585afb7b5ed9885338b66494f5f38280L2437-R2440)
[[3]](diffhunk://#diff-deceea46ae01082ce8400e14fa02f4b7585afb7b5ed9885338b66494f5f38280L2495-R2499)
**C++ Binding and Processing Updates:**
* The `ColumnInfoExt` struct now tracks whether wide character (UTF-16)
fetching is used for a column, and the `ProcessChar` function is updated
to handle both wide and narrow character paths, decoding appropriately
based on the new setting. (`mssql_python/pybind/ddbc_bindings.h`,
[[1]](diffhunk://#diff-85167a2d59779df18704284ab7ce46220c3619408fbf22c631ffdf29f794d635R671)
[[2]](diffhunk://#diff-85167a2d59779df18704284ab7ce46220c3619408fbf22c631ffdf29f794d635R795-R798)
[[3]](diffhunk://#diff-85167a2d59779df18704284ab7ce46220c3619408fbf22c631ffdf29f794d635R816-R846)
**Test Adjustments:**
* Tests are updated to expect `"utf-16le"` and `SQL_WCHAR` as the
default decoding settings for `SQL_CHAR` columns, and to validate the
new default behavior. (`tests/test_013_encoding_decoding.py`,
[[1]](diffhunk://#diff-97f01c2139fb5a0dc283aacb2982e014f2f3cd8bb88079451eba91362e2fb3f1L607-R614)
[[2]](diffhunk://#diff-97f01c2139fb5a0dc283aacb2982e014f2f3cd8bb88079451eba91362e2fb3f1L4924-R4927)
[[3]](diffhunk://#diff-97f01c2139fb5a0dc283aacb2982e014f2f3cd8bb88079451eba91362e2fb3f1L5651-R5656)
<!--
### PR Title Guide
> For feature requests
FEAT: (short-description)
> For non-feature requests like test case updates, config updates ,
dependency updates etc
CHORE: (short-description)
> For Fix requests
FIX: (short-description)
> For doc update requests
DOC: (short-description)
> For Formatting, indentation, or styling update
STYLE: (short-description)
> For Refactor, without any feature changes
REFACTOR: (short-description)
> For release related changes, without any feature changes
RELEASE: #<RELEASE_VERSION> (short-description)
### Contribution Guidelines
External contributors:
- Create a GitHub issue first:
https://github.com/microsoft/mssql-python/issues/new
- Link the GitHub issue in the "GitHub Issue" section above
- Follow the PR title format and provide a meaningful summary
mssql-python maintainers:
- Create an ADO Work Item following internal processes
- Link the ADO Work Item in the "ADO Work Item" section above
- Follow the PR title format and provide a meaningful summary
-->
---------
Co-authored-by: gargsaumya <saumyagarg.100@gmail.com>
1 parent 6209889 commit 6ec0949
5 files changed
Lines changed: 1227 additions & 350 deletions
File tree
- mssql_python
- pybind
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
261 | 261 | | |
262 | 262 | | |
263 | 263 | | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
264 | 268 | | |
265 | 269 | | |
266 | | - | |
267 | | - | |
| 270 | + | |
| 271 | + | |
268 | 272 | | |
269 | 273 | | |
270 | 274 | | |
| |||
643 | 647 | | |
644 | 648 | | |
645 | 649 | | |
646 | | - | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
647 | 654 | | |
648 | | - | |
| 655 | + | |
| 656 | + | |
649 | 657 | | |
650 | 658 | | |
651 | 659 | | |
| |||
655 | 663 | | |
656 | 664 | | |
657 | 665 | | |
658 | | - | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
659 | 670 | | |
660 | 671 | | |
661 | 672 | | |
| |||
691 | 702 | | |
692 | 703 | | |
693 | 704 | | |
694 | | - | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
695 | 712 | | |
696 | | - | |
697 | | - | |
698 | | - | |
699 | | - | |
| 713 | + | |
700 | 714 | | |
701 | 715 | | |
702 | 716 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2462 | 2462 | | |
2463 | 2463 | | |
2464 | 2464 | | |
2465 | | - | |
| 2465 | + | |
2466 | 2466 | | |
| 2467 | + | |
2467 | 2468 | | |
2468 | 2469 | | |
2469 | 2470 | | |
| |||
2528 | 2529 | | |
2529 | 2530 | | |
2530 | 2531 | | |
2531 | | - | |
| 2532 | + | |
2532 | 2533 | | |
| 2534 | + | |
2533 | 2535 | | |
2534 | 2536 | | |
2535 | 2537 | | |
| |||
2586 | 2588 | | |
2587 | 2589 | | |
2588 | 2590 | | |
2589 | | - | |
| 2591 | + | |
2590 | 2592 | | |
| 2593 | + | |
2591 | 2594 | | |
2592 | 2595 | | |
2593 | 2596 | | |
| |||
0 commit comments