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
### 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#42905](https://sqlclientdrivers.visualstudio.com/c6d89619-62de-46a0-8b46-70b92a84d85e/_workitems/edit/42905)
<!-- External contributors: GitHub Issue -->
> GitHub Issue: #447
-------------------------------------------------------------------
### Summary
This pull request introduces support for native UUID handling in the
`mssql_python` package, allowing users to control whether SQL Server
`UNIQUEIDENTIFIER` columns are returned as `uuid.UUID` objects or as
strings. The feature is configurable at both the module and
per-connection levels, enabling incremental adoption and backward
compatibility with pyodbc-style string UUIDs. The implementation ensures
efficient conversion with minimal runtime overhead and updates the
public API, documentation, and type hints accordingly.
**Native UUID Handling**
* Added a new `native_uuid` setting to the global settings (`Settings`
class in `helpers.py`) and exposed it as a property on the module,
allowing users to control UUID handling globally.
(`mssql_python/helpers.py`, `mssql_python/__init__.py`)
* Extended the `Connection` and `connect` API to accept a `native_uuid`
parameter, enabling per-connection overrides of the global setting.
Updated docstrings and type hints to document this parameter.
(`mssql_python/connection.py`, `mssql_python/db_connection.py`,
`mssql_python/mssql_python.pyi`)
**Cursor and Row Conversion Logic**
* Updated the `Cursor` class to determine the effective `native_uuid`
setting and efficiently precompute which columns require conversion to
string, minimizing per-row overhead. (`mssql_python/cursor.py`)
* Modified the `Row` class to accept a list of UUID column indices and
convert those columns to uppercase strings only when
`native_uuid=False`, preserving pyodbc compatibility and allowing
seamless migration. (`mssql_python/row.py`,
`mssql_python/mssql_python.pyi`)
**Testing and Minor Updates**
* Updated test imports to include the new `native_uuid` symbol.
(`tests/test_001_globals.py`)
* Minor formatting and docstring updates for clarity and consistency.
(`tests/test_001_globals.py`)
These changes provide a robust and flexible way for users to opt in to
native UUID support, with clear migration paths and minimal performance
impact.
0 commit comments