Skip to content

Conversation

@gargsaumya
Copy link
Contributor

@gargsaumya gargsaumya commented Sep 18, 2025

Work Item / Issue Reference

AB#34944

GitHub Issue: #<ISSUE_NUMBER>


Summary

This pull request adds comprehensive support for the SQL Server DATETIMEOFFSET type in the driver, including full round-trip handling of timezone-aware Python datetime objects. The changes span the C++ bindings, Python type mapping, and test coverage to ensure correct reading and writing of DATETIMEOFFSET values, as well as validation for timezone information.

DATETIMEOFFSET support in C++ bindings:

  • Defined new constants and a DateTimeOffset struct in ddbc_bindings.cpp to represent and handle the SQL Server DATETIMEOFFSET type and its C type mapping (SQL_SS_TIMESTAMPOFFSET, SQL_C_SS_TIMESTAMPOFFSET). [1] [2]
  • Implemented logic in parameter binding to convert Python timezone-aware datetime objects into the DateTimeOffset struct, including extracting and validating timezone offsets. Naive datetimes are rejected for this type.
  • Added logic to fetch DATETIMEOFFSET values from the database and convert them back into Python datetime objects with the correct timezone information.

Python type mapping and constants:

  • Added SQL_DATETIMEOFFSET and SQL_C_SS_TIMESTAMPOFFSET to the driver's constants in constants.py.
  • Updated the cursor's type mapping logic to use DATETIMEOFFSET for timezone-aware datetime objects, and TIMESTAMP for naive ones.

Testing improvements:

  • Introduced a new test, test_datetimeoffset_read_write, which verifies correct round-trip handling of DATETIMEOFFSET values, including various timezone offsets and microsecond precision, and ensures that naive datetimes are rejected.
  • Added necessary imports for timezone handling in the test module.

These changes ensure that the driver now robustly supports SQL Server's DATETIMEOFFSET type, providing accurate and safe handling of timezone-aware datetimes between Python and the database.

Copilot AI review requested due to automatic review settings September 18, 2025 14:52
@github-actions github-actions bot added the pr-size: medium Moderate update size label Sep 18, 2025
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 SQL Server's DATETIMEOFFSET type in the Python driver, enabling proper handling of timezone-aware datetime objects. The implementation includes C++ bindings, Python type mapping, and comprehensive test coverage.

  • Adds DateTimeOffset struct and constants for handling SQL Server DATETIMEOFFSET type
  • Implements parameter binding and data retrieval logic for timezone-aware datetime objects
  • Updates cursor type mapping to distinguish between timezone-aware and naive datetime objects

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
ddbc_bindings.cpp Implements C++ binding logic for DATETIMEOFFSET including struct definition, parameter binding, and data retrieval
cursor.py Updates type mapping to use DATETIMEOFFSET for timezone-aware datetime objects
constants.py Adds SQL_DATETIMEOFFSET and SQL_C_SS_TIMESTAMPOFFSET constants
test_004_cursor.py Adds comprehensive test coverage for DATETIMEOFFSET round-trip functionality

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

@gargsaumya gargsaumya changed the title FEAT: Complex Data Type Support for DATETIMEOFFSET FEAT: Complex Data Type Support - DATETIMEOFFSET 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.

Added a couple of 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
@github-actions github-actions bot added pr-size: medium Moderate update size and removed pr-size: medium Moderate update size labels Sep 22, 2025
sumitmsft
sumitmsft previously approved these changes Sep 23, 2025
Copy link
Collaborator

@bewithgaurav bewithgaurav left a comment

Choose a reason for hiding this comment

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

minor formatting changes under tests

@github-actions github-actions bot added pr-size: medium Moderate update size and removed pr-size: medium Moderate update size labels Sep 24, 2025
@github-actions github-actions bot added pr-size: medium Moderate update size and removed pr-size: medium Moderate update size labels Sep 24, 2025
@gargsaumya gargsaumya merged commit fba0e63 into main Sep 24, 2025
18 checks passed
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

4 participants