Commit 9bc78ae
authored
FIX: Stored datetime.time values have the microseconds attribute set to zero (#479)
### 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#38820](https://sqlclientdrivers.visualstudio.com/c6d89619-62de-46a0-8b46-70b92a84d85e/_workitems/edit/38820)
<!-- External contributors: GitHub Issue -->
> GitHub Issue: #203
-------------------------------------------------------------------
### Summary
This pull request introduces significant improvements to how SQL
TIME/TIME2 values are handled in the MSSQL Python driver, transitioning
from native C-type bindings to text-based representations. The changes
ensure correct parsing, binding, and conversion between SQL TIME values
and Python `datetime.time` objects, addressing edge cases and improving
compatibility.
### SQL TIME/TIME2 Handling Improvements
* Changed TIME/TIME2 parameter binding in `mssql_python/cursor.py` to
use `SQL_TYPE_TIME` and text C-types (`SQL_C_CHAR`), and normalized
Python `datetime.time` values to ISO text format with microseconds.
* Updated C++ bindings in `ddbc_bindings.cpp` to bind and fetch
TIME/TIME2 columns as text buffers instead of native structs, and
introduced a robust parser (`ParseSqlTimeTextToPythonObject`) for
converting SQL time text to Python objects.
* Adjusted row size calculations and buffer allocations for TIME/TIME2
columns to use the new maximum text length constant
(`SQL_TIME_TEXT_MAX_LEN`).
### Testing and Utilities
* Exposed the time-text parser as a test helper in the Python module,
allowing for unit testing of TIME/TIME2 parsing edge cases.
### Miscellaneous
* Improved table cleanup in tests by switching to `drop_table_if_exists`
for reliability.1 parent 2398ffd commit 9bc78ae
4 files changed
Lines changed: 266 additions & 37 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
54 | 67 | | |
55 | 68 | | |
56 | 69 | | |
| |||
676 | 689 | | |
677 | 690 | | |
678 | 691 | | |
679 | | - | |
680 | | - | |
681 | | - | |
682 | | - | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
683 | 696 | | |
684 | 697 | | |
685 | 698 | | |
| |||
958 | 971 | | |
959 | 972 | | |
960 | 973 | | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
961 | 981 | | |
962 | 982 | | |
963 | 983 | | |
| |||
2277 | 2297 | | |
2278 | 2298 | | |
2279 | 2299 | | |
| 2300 | + | |
| 2301 | + | |
| 2302 | + | |
| 2303 | + | |
2280 | 2304 | | |
2281 | 2305 | | |
2282 | 2306 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| 27 | + | |
26 | 28 | | |
27 | 29 | | |
28 | 30 | | |
| |||
66 | 68 | | |
67 | 69 | | |
68 | 70 | | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
69 | 75 | | |
70 | 76 | | |
71 | 77 | | |
| |||
3076 | 3082 | | |
3077 | 3083 | | |
3078 | 3084 | | |
3079 | | - | |
| 3085 | + | |
3080 | 3086 | | |
3081 | 3087 | | |
3082 | 3088 | | |
| |||
3481 | 3487 | | |
3482 | 3488 | | |
3483 | 3489 | | |
3484 | | - | |
3485 | 3490 | | |
3486 | 3491 | | |
3487 | | - | |
3488 | | - | |
3489 | | - | |
3490 | | - | |
3491 | | - | |
3492 | | - | |
| 3492 | + | |
| 3493 | + | |
| 3494 | + | |
| 3495 | + | |
| 3496 | + | |
| 3497 | + | |
3493 | 3498 | | |
3494 | | - | |
3495 | | - | |
3496 | | - | |
| 3499 | + | |
| 3500 | + | |
| 3501 | + | |
| 3502 | + | |
| 3503 | + | |
3497 | 3504 | | |
3498 | 3505 | | |
3499 | 3506 | | |
| |||
3668 | 3675 | | |
3669 | 3676 | | |
3670 | 3677 | | |
3671 | | - | |
| 3678 | + | |
3672 | 3679 | | |
3673 | 3680 | | |
3674 | 3681 | | |
| |||
3822 | 3829 | | |
3823 | 3830 | | |
3824 | 3831 | | |
3825 | | - | |
3826 | | - | |
3827 | 3832 | | |
3828 | 3833 | | |
3829 | 3834 | | |
3830 | | - | |
3831 | | - | |
| 3835 | + | |
| 3836 | + | |
3832 | 3837 | | |
3833 | 3838 | | |
3834 | 3839 | | |
| |||
4132 | 4137 | | |
4133 | 4138 | | |
4134 | 4139 | | |
4135 | | - | |
4136 | | - | |
4137 | 4140 | | |
| 4141 | + | |
4138 | 4142 | | |
4139 | | - | |
4140 | | - | |
4141 | | - | |
| 4143 | + | |
| 4144 | + | |
4142 | 4145 | | |
4143 | 4146 | | |
4144 | 4147 | | |
| |||
4271 | 4274 | | |
4272 | 4275 | | |
4273 | 4276 | | |
4274 | | - | |
4275 | | - | |
4276 | 4277 | | |
4277 | | - | |
| 4278 | + | |
4278 | 4279 | | |
4279 | 4280 | | |
4280 | 4281 | | |
| |||
4969 | 4970 | | |
4970 | 4971 | | |
4971 | 4972 | | |
4972 | | - | |
| 4973 | + | |
4973 | 4974 | | |
4974 | | - | |
| 4975 | + | |
4975 | 4976 | | |
4976 | 4977 | | |
4977 | 4978 | | |
| |||
5228 | 5229 | | |
5229 | 5230 | | |
5230 | 5231 | | |
5231 | | - | |
5232 | | - | |
5233 | | - | |
| 5232 | + | |
5234 | 5233 | | |
5235 | 5234 | | |
5236 | 5235 | | |
| |||
5713 | 5712 | | |
5714 | 5713 | | |
5715 | 5714 | | |
| 5715 | + | |
| 5716 | + | |
5716 | 5717 | | |
5717 | 5718 | | |
5718 | 5719 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
618 | 618 | | |
619 | 619 | | |
620 | 620 | | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
621 | 629 | | |
622 | 630 | | |
623 | 631 | | |
| |||
642 | 650 | | |
643 | 651 | | |
644 | 652 | | |
645 | | - | |
| 653 | + | |
646 | 654 | | |
647 | 655 | | |
648 | 656 | | |
| |||
0 commit comments