Commit 95a1f18
authored
FIX: Executemany String corruption on Unix systems + tests (#217)
### Work Item / Issue Reference
<!--
IMPORTANT: Please follow the PR template guidelines below.
For mssql-python maintainers: Insert your ADO Work Item ID below (e.g.
AB#37452)
For external contributors: Insert Github Issue number below (e.g. #149)
Only one reference is required - either GitHub issue OR ADO Work Item.
-->
<!-- mssql-python maintainers: ADO Work Item -->
>
[AB#38479](https://sqlclientdrivers.visualstudio.com/c6d89619-62de-46a0-8b46-70b92a84d85e/_workitems/edit/38479)
<!-- External contributors: GitHub Issue -->
> GitHub Issue: #<ISSUE_NUMBER>
-------------------------------------------------------------------
### Summary
<!-- Insert your summary of changes below. Minimum 10 characters
required. -->
## Fix string handling in executemany batch operations on Unix systems
**Issue:**
`executemany` was corrupting string data on Unix/macOS due to encoding
mismatch in batch parameter binding. Strings were either truncated or
returned garbage data.
**Root Cause:**
In `BindParameterArray` function, `std::wstring` (UTF-32 on Unix) was
directly copied to `SQLWCHAR` buffers (UTF-16) without proper encoding
conversion, while single parameter binding in `execute` correctly used
`WStringToSQLWCHAR()`.
**Fix:**
- Added platform-specific string conversion in `BindParameterArray` for
`SQL_C_WCHAR` case
- Unix: Use `WStringToSQLWCHAR()` for proper UTF-32 → UTF-16 conversion
- Windows: Keep existing direct copy (both are UTF-16)
**Impact:**
- All string data (including empty strings) now correctly preserved in
executemany
- Eliminates data corruption and truncation on Unix platforms
- Maintains existing Windows behavior
- Consistent string handling between `execute` and `executemany`
<!--
### 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
- 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
-->1 parent 1da4fa9 commit 95a1f18
File tree
2 files changed
+529
-0
lines changed- mssql_python/pybind
- tests
2 files changed
+529
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1352 | 1352 | | |
1353 | 1353 | | |
1354 | 1354 | | |
| 1355 | + | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
| 1363 | + | |
| 1364 | + | |
| 1365 | + | |
| 1366 | + | |
| 1367 | + | |
1355 | 1368 | | |
1356 | 1369 | | |
1357 | 1370 | | |
1358 | 1371 | | |
1359 | 1372 | | |
| 1373 | + | |
1360 | 1374 | | |
1361 | 1375 | | |
1362 | 1376 | | |
| |||
0 commit comments