Comparing dlevy-msft-sql:main...microsoft:main · dlevy-msft-sql/mssql-python
Commits on Mar 12, 2026
-
FIX: False positive qmark detection for ? inside bracketed identifier…
…s, string literals and comments (microsoft#465) ### 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#42937](https://sqlclientdrivers.visualstudio.com/c6d89619-62de-46a0-8b46-70b92a84d85e/_workitems/edit/42937) <!-- External contributors: GitHub Issue --> > GitHub Issue: microsoft#464 ------------------------------------------------------------------- ### Summary This pull request introduces a robust fix for detecting real parameter placeholders in SQL statements, specifically addressing false positives caused by question marks inside bracketed identifiers, string literals, quoted identifiers, and comments. The changes add context-aware scanning logic and comprehensive tests, ensuring that only actual parameter placeholders are flagged and handled. This resolves a bug where SQL containing `?` inside brackets (e.g., `[q?marks]`) would incorrectly trigger parameter mismatch errors. ### Core logic improvements * Added `_skip_quoted_context` helper in `parameter_helper.py` to accurately skip over single-line comments, multi-line comments, single-quoted string literals (with escaped quotes), double-quoted identifiers, and bracketed identifiers when scanning SQL for placeholders. * Added `_has_unquoted_question_marks` function to detect real `?` placeholders only outside quoted contexts, using the new context-skipping logic. * Updated `detect_and_convert_parameters` to use `_has_unquoted_question_marks` for parameter style mismatch detection, preventing false positives when `?` appears inside bracketed identifiers or other quoted contexts. ### Testing improvements * Added extensive unit tests for `_skip_quoted_context` and `_has_unquoted_question_marks`, covering all relevant SQL quoting and commenting scenarios, including edge cases like unclosed quotes/brackets. * Added integration tests verifying that SQL with `?` inside bracketed identifiers, string literals, and comments does not trigger parameter style mismatch errors, and that real placeholders are still detected correctly. ### Test harness updates * Imported the new helper functions in the test module to facilitate direct testing.
-
FEAT: add native_uuid support (microsoft#463)
### 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: microsoft#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.
-
FEAT: Export Row class and refactor __init__.py (microsoft#270) (micr…
…osoft#474) ### 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#43062](https://sqlclientdrivers.visualstudio.com/c6d89619-62de-46a0-8b46-70b92a84d85e/_workitems/edit/43062) <!-- External contributors: GitHub Issue --> > GitHub Issue: microsoft#270 ------------------------------------------------------------------- ### Summary This pull request refactors how module-level constants and decimal separator configuration are handled in the `mssql_python` package. Constants are now dynamically exported from the `constants` module, and decimal separator functions are moved to a dedicated module for improved maintainability and clarity. The changes also add new exports for row objects and simplify imports. **Module-level constant export and API improvements:** * Constants such as SQL types and GetInfo constants are now dynamically exported from the `constants` module, allowing direct import from `mssql_python` and reducing manual duplication. The `get_info_constants` function is also moved and exported from `constants.py`. * All manual constant exports and the `get_info_constants` function implementation are removed from `__init__.py` in favor of wildcard imports from `constants.py`. **Decimal separator configuration refactor:** * The decimal separator getter/setter logic is moved to a new module `decimal_config.py`, which encapsulates validation and C++ binding logic. A factory function now creates bound getter/setter functions for use in `__init__.py`. * The previous implementation of decimal separator functions in `__init__.py` is removed and replaced with the new factory-based approach. **API and import enhancements:** * The `Row` object is now exported at the top level for easier access. * Import statements are clarified and simplified, including the settings import and constant exports. These changes improve the maintainability, clarity, and usability of the package's public API and configuration options.
Commits on Mar 24, 2026
-
FIX: NULL parameter type mapping for VARBINARY columns (microsoft#458) (
microsoft#466) ### 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#42894](https://sqlclientdrivers.visualstudio.com/c6d89619-62de-46a0-8b46-70b92a84d85e/_workitems/edit/42894) <!-- External contributors: GitHub Issue --> > GitHub Issue: microsoft#458 ------------------------------------------------------------------- ### Summary <!-- Insert your summary of changes below. Minimum 10 characters required. --> This pull request makes a targeted fix to the parameter type mapping logic for NULL values in the `mssql_python/cursor.py` file. The change improves compatibility and prevents implicit conversion errors when executing queries with NULL parameters. Parameter mapping improvement: * Changed the mapping for NULL parameters in the `_map_sql_type` function to use `SQL_UNKNOWN_TYPE` instead of `SQL_VARCHAR`, allowing the driver to correctly determine the column type and avoid conversion errors. <!-- ### 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 --> --------- Co-authored-by: Jahnvi Thakkar <61936179+jahnvi480@users.noreply.github.com>
Commits on Mar 25, 2026
-
FEAT: Support for Complex Data Type- sql_variant (microsoft#446)
### 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#42724](https://sqlclientdrivers.visualstudio.com/c6d89619-62de-46a0-8b46-70b92a84d85e/_workitems/edit/42724) <!-- External contributors: GitHub Issue --> > GitHub Issue: #<ISSUE_NUMBER> ------------------------------------------------------------------- ### Summary <!-- Insert your summary of changes below. Minimum 10 characters required. --> This pull request adds support for the `sql_variant` SQL Server type to the Python MSSQL driver, ensuring that `sql_variant` columns are fetched and mapped correctly to their underlying types. The changes introduce new constants, update type mappings, and enhance the fetch logic to detect and process `sql_variant` columns using their native types, improving compatibility and correctness when handling complex data. **Support for sql_variant type** * Added the `SQL_SS_VARIANT` constant and related attribute constants in both `mssql_python/constants.py` and the C++ binding layer to enable recognition and handling of the `sql_variant` type. [[1]](diffhunk://#diff-e6d80f1000af6fd5afca05f435b11fd82df7f5c3e75ecf5763f85d3aacdbe758R120) [[2]](diffhunk://#diff-dde2297345718ec449a14e7dff91b7bb2342b008ecc071f562233646d71144a1R30-R34) * Included `SQL_SS_VARIANT` in the set of valid types for type validation logic. **Type mapping and fetch logic** * Updated the C type mapping in `cursor.py` so that `SQL_SS_VARIANT` is mapped to `SQL_C_BINARY`, allowing binary transfer of the variant data. * Implemented a helper function in the C++ layer to map a `sql_variant`'s underlying C type to the appropriate SQL data type, enabling the fetch logic to reuse existing code for each possible underlying type. * Enhanced the fetch routines (`SQLGetData_wrap`, `FetchMany_wrap`, and `FetchAll_wrap`) to detect `sql_variant` columns, determine their true data types at runtime, and handle them with the correct logic. This includes always using the streaming fetch path for `sql_variant` columns to preserve native type fidelity. [[1]](diffhunk://#diff-dde2297345718ec449a14e7dff91b7bb2342b008ecc071f562233646d71144a1L2932-R3020) [[2]](diffhunk://#diff-dde2297345718ec449a14e7dff91b7bb2342b008ecc071f562233646d71144a1L4044-R4144) [[3]](diffhunk://#diff-dde2297345718ec449a14e7dff91b7bb2342b008ecc071f562233646d71144a1R4229-R4274) **Other improvements** * Improved error logging and debug output for easier troubleshooting and visibility into how `sql_variant` columns are processed. [[1]](diffhunk://#diff-dde2297345718ec449a14e7dff91b7bb2342b008ecc071f562233646d71144a1L1156-R1162) [[2]](diffhunk://#diff-dde2297345718ec449a14e7dff91b7bb2342b008ecc071f562233646d71144a1L2932-R3020) [[3]](diffhunk://#diff-dde2297345718ec449a14e7dff91b7bb2342b008ecc071f562233646d71144a1L4044-R4144) [[4]](diffhunk://#diff-dde2297345718ec449a14e7dff91b7bb2342b008ecc071f562233646d71144a1R4229-R4274) These changes collectively ensure that the driver can now fully support reading `sql_variant` columns, mapping them to their actual types, and handling them efficiently. <!-- ### 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 -->