You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
FEAT: Streaming support in fetchone, fetchmany, fetchall for varbinarymax data type. (#232)
### 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#33395](https://sqlclientdrivers.visualstudio.com/c6d89619-62de-46a0-8b46-70b92a84d85e/_workitems/edit/33395)
<!-- External contributors: GitHub Issue -->
> GitHub Issue: #<ISSUE_NUMBER>
-------------------------------------------------------------------
### Summary
<!-- Insert your summary of changes below. Minimum 10 characters
required. -->
This pull request significantly improves support for streaming and
fetching large binary (VARBINARY(MAX)) and large text columns in the
MSSQL Python driver. The main changes include robust chunked retrieval
of large objects (LOBs), correct handling of edge cases (such as empty
or null values), and enhanced test coverage for these scenarios.
**LOB Streaming and Fetching Enhancements:**
* Added a new helper function `FetchLobColumnData` to efficiently stream
and assemble large binary/text columns (LOBs) from the database,
handling chunking, null/empty values, and correct type conversion for
both binary and (wide/narrow) string columns.
* Updated the logic in `SQLGetData_wrap`, `FetchBatchData`,
`FetchMany_wrap`, and `FetchAll_wrap` to detect LOB columns and use the
new streaming path for fetching them, including proper fallback to
row-by-row fetching when LOBs are present.
[[1]](diffhunk://#diff-dde2297345718ec449a14e7dff91b7bb2342b008ecc071f562233646d71144a1L2062-R2184)
[[2]](diffhunk://#diff-dde2297345718ec449a14e7dff91b7bb2342b008ecc071f562233646d71144a1L2542-R2631)
[[3]](diffhunk://#diff-dde2297345718ec449a14e7dff91b7bb2342b008ecc071f562233646d71144a1R2760-R2788)
[[4]](diffhunk://#diff-dde2297345718ec449a14e7dff91b7bb2342b008ecc071f562233646d71144a1L2699-R2803)
[[5]](diffhunk://#diff-dde2297345718ec449a14e7dff91b7bb2342b008ecc071f562233646d71144a1R2882-R2910)
[[6]](diffhunk://#diff-dde2297345718ec449a14e7dff91b7bb2342b008ecc071f562233646d71144a1L2792-R2925)
* Modified the batch fetch function signatures and logic to propagate
LOB column information and ensure correct handling during bulk fetches.
**Testing Improvements:**
* Replaced and expanded the test for large binary data with a new,
comprehensive test (`test_varbinarymax_insert_fetch`) that verifies
insertion and retrieval of empty, small, and large VARBINARY(MAX) values
(including edge cases around the 8000-byte threshold) using `fetchone`,
`fetchall`, and `fetchmany`.
These changes ensure that the driver can reliably handle large binary
and text columns in all fetch scenarios, improving correctness and
robustness for users working with LOB data.
<!--
### 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
-->
0 commit comments