Commit 2b7f886
authored
FEAT: Adding getDecimalSeperator and setDecimalSeperator as global functions (#188)
### Work Item / Issue Reference
<!--
IMPORTANT: Please follow the PR template guidelines below.
For mssql-python maintainers: Insert your ADO Work Item ID below (e.g.
AB#37452)
For external contributors: Insert Github Issue number below (e.g. #149)
Only one reference is required - either GitHub issue OR ADO Work Item.
-->
<!-- mssql-python maintainers: ADO Work Item -->
>
[AB#34907](https://sqlclientdrivers.visualstudio.com/c6d89619-62de-46a0-8b46-70b92a84d85e/_workitems/edit/34907)
>
[AB#34908](https://sqlclientdrivers.visualstudio.com/c6d89619-62de-46a0-8b46-70b92a84d85e/_workitems/edit/34908)
-------------------------------------------------------------------
### Summary
This pull request adds support for configuring the decimal separator
used when parsing and displaying NUMERIC/DECIMAL values in the
`mssql_python` package. It introduces new Python and C++ APIs to control
the decimal separator, ensures the separator is respected in string
representations, and includes comprehensive tests to verify the new
functionality.
**Decimal separator configuration and propagation:**
- Added `setDecimalSeparator` and `getDecimalSeparator` functions in
`mssql_python/__init__.py` to allow users to set and retrieve the
decimal separator character, with input validation and propagation to
the C++ layer (`DDBCSetDecimalSeparator`).
- Introduced a global `g_decimalSeparator` variable and the
`DDBCSetDecimalSeparator` function in C++ (`ddbc_bindings.cpp` and
`ddbc_bindings.h`) to store and update the separator, and exposed this
setter to Python via pybind11.
**Integration with data handling and display:**
- Updated the C++ data fetching logic to use the configured decimal
separator when converting NUMERIC/DECIMAL database values to Python
`Decimal` objects, ensuring correct parsing and formatting.
- Modified the Python `Row.__str__` method to use the current decimal
separator when displaying decimal values, so string representations
reflect user configuration.
**Testing:**
- Added and expanded tests in `tests/test_001_globals.py` and
`tests/test_004_cursor.py` to cover the new decimal separator
functionality, including validation, database operations, string
formatting, and ensuring calculations are unaffected by the separator
setting.
These changes make the decimal separator fully configurable and ensure
consistent behavior across both parsing and display of decimal values.
---------
Co-authored-by: Jahnvi Thakkar <jathakkar@microsoft.com>1 parent 5fe06f5 commit 2b7f886
File tree
7 files changed
+858
-29
lines changed- mssql_python
- pybind
- tests
7 files changed
+858
-29
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
7 | 9 | | |
8 | 10 | | |
9 | 11 | | |
| |||
13 | 15 | | |
14 | 16 | | |
15 | 17 | | |
16 | | - | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
17 | 28 | | |
18 | | - | |
19 | 29 | | |
20 | 30 | | |
21 | 31 | | |
| 32 | + | |
| 33 | + | |
22 | 34 | | |
23 | | - | |
| 35 | + | |
24 | 36 | | |
| 37 | + | |
25 | 38 | | |
26 | | - | |
27 | 39 | | |
28 | 40 | | |
29 | 41 | | |
30 | 42 | | |
31 | 43 | | |
32 | 44 | | |
33 | | - | |
34 | | - | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
35 | 102 | | |
36 | 103 | | |
37 | 104 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2037 | 2037 | | |
2038 | 2038 | | |
2039 | 2039 | | |
2040 | | - | |
2041 | | - | |
2042 | | - | |
2043 | | - | |
2044 | | - | |
2045 | | - | |
2046 | | - | |
2047 | | - | |
2048 | | - | |
2049 | | - | |
| 2040 | + | |
| 2041 | + | |
| 2042 | + | |
| 2043 | + | |
| 2044 | + | |
| 2045 | + | |
| 2046 | + | |
| 2047 | + | |
| 2048 | + | |
| 2049 | + | |
| 2050 | + | |
| 2051 | + | |
| 2052 | + | |
| 2053 | + | |
| 2054 | + | |
| 2055 | + | |
| 2056 | + | |
| 2057 | + | |
| 2058 | + | |
| 2059 | + | |
| 2060 | + | |
| 2061 | + | |
| 2062 | + | |
2050 | 2063 | | |
| 2064 | + | |
| 2065 | + | |
| 2066 | + | |
| 2067 | + | |
| 2068 | + | |
| 2069 | + | |
| 2070 | + | |
| 2071 | + | |
| 2072 | + | |
| 2073 | + | |
| 2074 | + | |
| 2075 | + | |
| 2076 | + | |
2051 | 2077 | | |
2052 | | - | |
2053 | | - | |
| 2078 | + | |
| 2079 | + | |
| 2080 | + | |
| 2081 | + | |
2054 | 2082 | | |
2055 | 2083 | | |
2056 | 2084 | | |
| |||
2560 | 2588 | | |
2561 | 2589 | | |
2562 | 2590 | | |
2563 | | - | |
2564 | | - | |
2565 | | - | |
2566 | | - | |
2567 | | - | |
| 2591 | + | |
| 2592 | + | |
| 2593 | + | |
| 2594 | + | |
| 2595 | + | |
| 2596 | + | |
| 2597 | + | |
| 2598 | + | |
| 2599 | + | |
| 2600 | + | |
| 2601 | + | |
| 2602 | + | |
| 2603 | + | |
| 2604 | + | |
| 2605 | + | |
| 2606 | + | |
| 2607 | + | |
| 2608 | + | |
2568 | 2609 | | |
2569 | 2610 | | |
2570 | 2611 | | |
| |||
3016 | 3057 | | |
3017 | 3058 | | |
3018 | 3059 | | |
| 3060 | + | |
| 3061 | + | |
| 3062 | + | |
| 3063 | + | |
| 3064 | + | |
| 3065 | + | |
| 3066 | + | |
3019 | 3067 | | |
3020 | 3068 | | |
3021 | 3069 | | |
| |||
3102 | 3150 | | |
3103 | 3151 | | |
3104 | 3152 | | |
| 3153 | + | |
| 3154 | + | |
3105 | 3155 | | |
3106 | 3156 | | |
3107 | 3157 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
413 | 413 | | |
414 | 414 | | |
415 | 415 | | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
94 | | - | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
95 | 113 | | |
96 | 114 | | |
97 | 115 | | |
| |||
0 commit comments