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: uniqueidentifier support in executemany() (#245)
### 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#34945](https://sqlclientdrivers.visualstudio.com/c6d89619-62de-46a0-8b46-70b92a84d85e/_workitems/edit/34945)
<!-- External contributors: GitHub Issue -->
> GitHub Issue: #<ISSUE_NUMBER>
-------------------------------------------------------------------
### Summary
<!-- Insert your summary of changes below. Minimum 10 characters
required. -->
This pull request adds full support for handling Python `uuid.UUID`
objects with SQL Server's `UNIQUEIDENTIFIER` type in the `mssql_python`
driver. It introduces robust conversion between Python UUIDs and SQL
GUIDs for both single and batch operations, ensures correct retrieval as
Python `uuid.UUID` objects, and adds comprehensive tests for these
scenarios.
**UUID/GUID Support Improvements:**
* Added mapping for Python `uuid.UUID` to SQL `GUID` types in
`_map_sql_type`, enabling seamless parameter binding for UUIDs.
* Implemented correct binding and conversion logic for UUIDs in both
single (`BindParameters`) and batch (`BindParameterArray`) parameter
bindings, including validation of binary length and error handling.
[[1]](diffhunk://#diff-dde2297345718ec449a14e7dff91b7bb2342b008ecc071f562233646d71144a1L507-R534)
[[2]](diffhunk://#diff-dde2297345718ec449a14e7dff91b7bb2342b008ecc071f562233646d71144a1R1911-R1948)
* Enhanced data retrieval to return UUID columns as Python `uuid.UUID`
objects instead of strings or raw bytes, in both single-row
(`SQLGetData_wrap`) and batch (`FetchBatchData`) fetches.
[[1]](diffhunk://#diff-dde2297345718ec449a14e7dff91b7bb2342b008ecc071f562233646d71144a1L2556-R2641)
[[2]](diffhunk://#diff-dde2297345718ec449a14e7dff91b7bb2342b008ecc071f562233646d71144a1L2960-R3041)
**Testing Enhancements:**
* Added comprehensive tests for inserting, selecting, and batch
operations involving UUIDs, including cases with `None` (NULL) values
and mixed UUID/NULL batches.
* Updated test imports to include the `uuid` module for use in new test
cases.
<!--
### 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