Commit 1da4fa9
authored
FIX: Handle empty data + tests (#212)
### 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#<WORK_ITEM_ID>
<!-- External contributors: GitHub Issue -->
> GitHub Issue: #205
-------------------------------------------------------------------
### Summary
<!-- Insert your summary of changes below. Minimum 10 characters
required. -->
This pull request improves the handling of empty string and binary
values in the MSSQL Python bindings, ensuring that empty data is
correctly distinguished from NULL values and does not cause assertion
failures. It also adds comprehensive tests to verify correct behavior
for these edge cases.
**Improvements to empty value handling:**
* Updated `SQLGetData_wrap` in `ddbc_bindings.cpp` to append an empty
string (`""`) or empty bytes (`b""`) when the returned data length is
zero, instead of causing assertion failures or misinterpreting the value
as NULL. This change applies to both string and binary column types.
[[1]](diffhunk://#diff-dde2297345718ec449a14e7dff91b7bb2342b008ecc071f562233646d71144a1R1703-R1705)
[[2]](diffhunk://#diff-dde2297345718ec449a14e7dff91b7bb2342b008ecc071f562233646d71144a1R1762-R1764)
[[3]](diffhunk://#diff-dde2297345718ec449a14e7dff91b7bb2342b008ecc071f562233646d71144a1R1961-R1963)
* Changed assertions in `FetchBatchData` to allow zero-length data,
ensuring that empty values are handled gracefully instead of triggering
errors.
**Testing improvements:**
* Added new tests in `tests/test_004_cursor.py` to verify correct
handling of empty strings and binary data, including distinguishing
empty values from NULLs, batch fetching, and various edge cases for
empty strings. These tests ensure that the fixes work as intended and
prevent regressions.
**Minor code cleanup:**
* Minor formatting and comment improvements in `ddbc_bindings.cpp` for
better code clarity.
<!--
### 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
-->1 parent 4b42f8c commit 1da4fa9
File tree
2 files changed
+454
-15
lines changed- mssql_python/pybind
- tests
2 files changed
+454
-15
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1778 | 1778 | | |
1779 | 1779 | | |
1780 | 1780 | | |
1781 | | - | |
1782 | | - | |
| 1781 | + | |
| 1782 | + | |
| 1783 | + | |
| 1784 | + | |
| 1785 | + | |
1783 | 1786 | | |
1784 | | - | |
1785 | | - | |
| 1787 | + | |
| 1788 | + | |
| 1789 | + | |
| 1790 | + | |
| 1791 | + | |
| 1792 | + | |
| 1793 | + | |
1786 | 1794 | | |
1787 | 1795 | | |
1788 | 1796 | | |
| |||
1834 | 1842 | | |
1835 | 1843 | | |
1836 | 1844 | | |
1837 | | - | |
1838 | | - | |
1839 | | - | |
1840 | | - | |
1841 | | - | |
| 1845 | + | |
| 1846 | + | |
| 1847 | + | |
| 1848 | + | |
| 1849 | + | |
| 1850 | + | |
| 1851 | + | |
| 1852 | + | |
| 1853 | + | |
1842 | 1854 | | |
1843 | 1855 | | |
1844 | 1856 | | |
| |||
2030 | 2042 | | |
2031 | 2043 | | |
2032 | 2044 | | |
2033 | | - | |
2034 | | - | |
2035 | | - | |
2036 | | - | |
2037 | | - | |
| 2045 | + | |
| 2046 | + | |
| 2047 | + | |
| 2048 | + | |
| 2049 | + | |
| 2050 | + | |
| 2051 | + | |
| 2052 | + | |
| 2053 | + | |
2038 | 2054 | | |
2039 | 2055 | | |
2040 | 2056 | | |
| |||
2317 | 2333 | | |
2318 | 2334 | | |
2319 | 2335 | | |
| 2336 | + | |
| 2337 | + | |
| 2338 | + | |
| 2339 | + | |
| 2340 | + | |
| 2341 | + | |
| 2342 | + | |
| 2343 | + | |
| 2344 | + | |
| 2345 | + | |
| 2346 | + | |
| 2347 | + | |
| 2348 | + | |
| 2349 | + | |
| 2350 | + | |
| 2351 | + | |
| 2352 | + | |
| 2353 | + | |
| 2354 | + | |
| 2355 | + | |
| 2356 | + | |
| 2357 | + | |
2320 | 2358 | | |
2321 | | - | |
| 2359 | + | |
2322 | 2360 | | |
2323 | 2361 | | |
2324 | 2362 | | |
| |||
0 commit comments