FEAT: Complex Data Type Support - DATETIMEOFFSET#243
Merged
gargsaumya merged 8 commits intomainfrom Sep 24, 2025
Merged
Conversation
Contributor
There was a problem hiding this comment.
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
DateTimeOffsetstruct and constants for handling SQL ServerDATETIMEOFFSETtype - 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.
sumitmsft
reviewed
Sep 19, 2025
sumitmsft
reviewed
Sep 19, 2025
sumitmsft
requested changes
Sep 19, 2025
Contributor
sumitmsft
left a comment
There was a problem hiding this comment.
Added a couple of comments
sumitmsft
previously approved these changes
Sep 23, 2025
bewithgaurav
requested changes
Sep 24, 2025
Collaborator
bewithgaurav
left a comment
There was a problem hiding this comment.
minor formatting changes under tests
bewithgaurav
approved these changes
Sep 24, 2025
sumitmsft
approved these changes
Sep 24, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Work Item / Issue Reference
Summary
This pull request adds comprehensive support for the SQL Server
DATETIMEOFFSETtype in the driver, including full round-trip handling of timezone-aware Pythondatetimeobjects. The changes span the C++ bindings, Python type mapping, and test coverage to ensure correct reading and writing ofDATETIMEOFFSETvalues, as well as validation for timezone information.DATETIMEOFFSET support in C++ bindings:
DateTimeOffsetstruct inddbc_bindings.cppto represent and handle the SQL ServerDATETIMEOFFSETtype and its C type mapping (SQL_SS_TIMESTAMPOFFSET,SQL_C_SS_TIMESTAMPOFFSET). [1] [2]datetimeobjects into theDateTimeOffsetstruct, including extracting and validating timezone offsets. Naive datetimes are rejected for this type.DATETIMEOFFSETvalues from the database and convert them back into Pythondatetimeobjects with the correct timezone information.Python type mapping and constants:
SQL_DATETIMEOFFSETandSQL_C_SS_TIMESTAMPOFFSETto the driver's constants inconstants.py.DATETIMEOFFSETfor timezone-awaredatetimeobjects, andTIMESTAMPfor naive ones.Testing improvements:
test_datetimeoffset_read_write, which verifies correct round-trip handling ofDATETIMEOFFSETvalues, including various timezone offsets and microsecond precision, and ensures that naive datetimes are rejected.These changes ensure that the driver now robustly supports SQL Server's
DATETIMEOFFSETtype, providing accurate and safe handling of timezone-aware datetimes between Python and the database.