- Notifications
You must be signed in to change notification settings - Fork 27
FEAT: Complex Data Type Support - DATETIMEOFFSET #243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this 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
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.
There was a problem hiding this 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
There was a problem hiding this 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
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.