Skip to content

Conversation

@gargsaumya
Copy link
Contributor

@gargsaumya gargsaumya commented Sep 15, 2025

Work Item / Issue Reference

AB#34945

GitHub Issue: #241


Summary

This pull request adds comprehensive support for Python's uuid.UUID type when interacting with SQL Server UNIQUEIDENTIFIER columns. It updates both the parameter binding and result retrieval logic to handle UUIDs as native Python objects, ensuring correct type mapping, byte order, and conversion in both directions. Additionally, new tests are introduced to verify correct insertion and retrieval of UUID values, including edge cases with None.

UUID/UNIQUEIDENTIFIER Support Improvements:

  • Added logic in mssql_python/cursor.py to map Python uuid.UUID objects to the correct SQL types and convert them to raw bytes before sending to SQL Server. [1] [2]
  • Updated the C++ binding layer (mssql_python/pybind/ddbc_bindings.cpp) to correctly marshal UUIDs between Python and SQL Server, including proper byte order conversion and error handling for incorrect UUID sizes.
  • Enhanced result fetching in the C++ layer to convert SQL Server UNIQUEIDENTIFIER columns back into Python uuid.UUID objects, both for single-row and batch fetches, and to handle NULL values gracefully. [1] [2]

Testing Enhancements:

  • Added new tests in tests/test_004_cursor.py to verify correct insertion, retrieval, and handling of None values in UUID columns, as well as round-trip integrity for multiple UUIDs. [1] [2]

Copilot AI review requested due to automatic review settings September 15, 2025 10:04
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds comprehensive support for Python's uuid.UUID type when working with SQL Server UNIQUEIDENTIFIER columns. It enables native UUID handling for both parameter binding and result retrieval.

  • Added parameter mapping for UUID objects to SQL_GUID type in cursor.py
  • Implemented UUID byte conversion and marshaling in the C++ binding layer
  • Enhanced result fetching to return Python UUID objects instead of raw bytes
  • Added comprehensive test coverage for UUID operations including NULL handling

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
mssql_python/cursor.py Maps UUID parameters to SQL_GUID type and converts UUID objects to bytes
mssql_python/pybind/ddbc_bindings.cpp Implements UUID parameter binding and result conversion with proper byte order handling
tests/test_004_cursor.py Adds test cases for UUID insertion, retrieval, and NULL value handling

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@github-actions github-actions bot added the pr-size: medium Moderate update size label Sep 15, 2025
@github-actions github-actions bot added pr-size: medium Moderate update size and removed pr-size: medium Moderate update size labels Sep 15, 2025
@github-actions github-actions bot added pr-size: medium Moderate update size and removed pr-size: medium Moderate update size labels Sep 19, 2025
@github-actions github-actions bot added pr-size: medium Moderate update size and removed pr-size: medium Moderate update size labels Sep 19, 2025
Copy link
Contributor

@sumitmsft sumitmsft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few comments

@github-actions github-actions bot added pr-size: medium Moderate update size and removed pr-size: medium Moderate update size labels Sep 22, 2025
@gargsaumya gargsaumya merged commit c1debd6 into main Sep 24, 2025
18 checks passed
@github-actions github-actions bot added pr-size: medium Moderate update size and removed pr-size: medium Moderate update size labels Oct 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-size: medium Moderate update size

Projects

None yet

Development

Successfully merging this pull request may close these issues.

coercion of UNIQUEIDENTIFIER / uuid values from binary to string only works with fetchone(), not fetchall() or fetchmany()

4 participants