Commit 622f95b
authored
FEAT: Add support for decimal value in scientific notation (microsoft#313)
### 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. microsoft#149)
Only one reference is required - either GitHub issue OR ADO Work Item.
-->
<!-- mssql-python maintainers: ADO Work Item -->
>
[AB#40022](https://sqlclientdrivers.visualstudio.com/c6d89619-62de-46a0-8b46-70b92a84d85e/_workitems/edit/40022)
<!-- External contributors: GitHub Issue -->
> GitHub Issue: #<ISSUE_NUMBER>
-------------------------------------------------------------------
### Summary
<!-- Insert your summary of changes below. Minimum 10 characters
required. -->
This pull request improves the handling of decimal values, especially
those in scientific notation, when converting to SQL `VARCHAR` types.
The changes ensure that decimals are consistently formatted as
fixed-point strings rather than potentially problematic scientific
notation, preventing SQL Server conversion errors. Additionally, new
tests have been added to verify correct behavior for a variety of
decimal values.
**Decimal formatting and conversion improvements:**
* Updated `_map_sql_type` in `mssql_python/cursor.py` to use
`format(param, 'f')` instead of `str(param)` for `MONEY` and
`SMALLMONEY` types, ensuring decimals are always converted to
fixed-point strings.
[[1]](diffhunk://#diff-deceea46ae01082ce8400e14fa02f4b7585afb7b5ed9885338b66494f5f38280L402-R402)
[[2]](diffhunk://#diff-deceea46ae01082ce8400e14fa02f4b7585afb7b5ed9885338b66494f5f38280L412-R411)
* Modified `executemany` in `mssql_python/cursor.py` to format decimal
values as fixed-point strings before insertion when mapped to
`SQL_VARCHAR`.
**Test suite enhancements:**
* Added `test_decimal_scientific_notation_to_varchar` in
`tests/test_004_cursor.py` to verify that decimals (including those with
scientific notation) are correctly converted and stored as `VARCHAR`
without causing conversion errors.
**Test cleanup and simplification:**
* Removed exception handling logic in
`test_numeric_leading_zeros_precision_loss` and
`test_numeric_extreme_exponents_precision_loss` that previously skipped
tests on conversion errors, as these errors should no longer occur with
the improved formatting.
[[1]](diffhunk://#diff-82594712308ff34afa8b067af67db231e9a1372ef474da3db121e14e4d418f69L13944-L13957)
[[2]](diffhunk://#diff-82594712308ff34afa8b067af67db231e9a1372ef474da3db121e14e4d418f69L14005-L14030)
<!--
### PR Title Guide
> For feature requests
FEAT: (short-description)
> For non-feature requests like test case updates, config updates ,
dependency updates etc
CHORE: (short-description)
> For Fix requests
FIX: (short-description)
> For doc update requests
DOC: (short-description)
> For Formatting, indentation, or styling update
STYLE: (short-description)
> For Refactor, without any feature changes
REFACTOR: (short-description)
> For release related changes, without any feature changes
RELEASE: #<RELEASE_VERSION> (short-description)
### Contribution Guidelines
External contributors:
- Create a GitHub issue first:
https://github.com/microsoft/mssql-python/issues/new
- Link the GitHub issue in the "GitHub Issue" section above
- Follow the PR title format and provide a meaningful summary
mssql-python maintainers:
- Create an ADO Work Item following internal processes
- Link the ADO Work Item in the "ADO Work Item" section above
- Follow the PR title format and provide a meaningful summary
-->1 parent 0a5d1f2 commit 622f95b
2 files changed
+70
-40
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
395 | 395 | | |
396 | 396 | | |
397 | 397 | | |
398 | | - | |
399 | | - | |
| 398 | + | |
400 | 399 | | |
401 | 400 | | |
402 | 401 | | |
| |||
405 | 404 | | |
406 | 405 | | |
407 | 406 | | |
408 | | - | |
409 | | - | |
| 407 | + | |
410 | 408 | | |
411 | 409 | | |
412 | 410 | | |
| |||
1916 | 1914 | | |
1917 | 1915 | | |
1918 | 1916 | | |
1919 | | - | |
1920 | 1917 | | |
1921 | 1918 | | |
1922 | 1919 | | |
1923 | 1920 | | |
1924 | 1921 | | |
1925 | | - | |
| 1922 | + | |
1926 | 1923 | | |
1927 | 1924 | | |
1928 | 1925 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13477 | 13477 | | |
13478 | 13478 | | |
13479 | 13479 | | |
13480 | | - | |
13481 | | - | |
13482 | | - | |
13483 | | - | |
13484 | | - | |
13485 | | - | |
13486 | | - | |
13487 | | - | |
13488 | | - | |
13489 | | - | |
13490 | | - | |
13491 | | - | |
13492 | | - | |
13493 | | - | |
13494 | 13480 | | |
13495 | 13481 | | |
13496 | 13482 | | |
| |||
13538 | 13524 | | |
13539 | 13525 | | |
13540 | 13526 | | |
13541 | | - | |
13542 | | - | |
13543 | | - | |
13544 | | - | |
13545 | | - | |
13546 | | - | |
13547 | | - | |
13548 | | - | |
13549 | | - | |
13550 | | - | |
13551 | | - | |
13552 | | - | |
13553 | | - | |
13554 | | - | |
13555 | | - | |
13556 | | - | |
13557 | | - | |
13558 | | - | |
13559 | 13527 | | |
13560 | 13528 | | |
13561 | 13529 | | |
13562 | 13530 | | |
13563 | 13531 | | |
13564 | 13532 | | |
13565 | 13533 | | |
13566 | | - | |
13567 | 13534 | | |
13568 | 13535 | | |
13569 | 13536 | | |
| |||
13659 | 13626 | | |
13660 | 13627 | | |
13661 | 13628 | | |
| 13629 | + | |
| 13630 | + | |
| 13631 | + | |
| 13632 | + | |
| 13633 | + | |
| 13634 | + | |
| 13635 | + | |
| 13636 | + | |
| 13637 | + | |
| 13638 | + | |
| 13639 | + | |
| 13640 | + | |
| 13641 | + | |
| 13642 | + | |
| 13643 | + | |
| 13644 | + | |
| 13645 | + | |
| 13646 | + | |
| 13647 | + | |
| 13648 | + | |
| 13649 | + | |
| 13650 | + | |
| 13651 | + | |
| 13652 | + | |
| 13653 | + | |
| 13654 | + | |
| 13655 | + | |
| 13656 | + | |
| 13657 | + | |
| 13658 | + | |
| 13659 | + | |
| 13660 | + | |
| 13661 | + | |
| 13662 | + | |
| 13663 | + | |
| 13664 | + | |
| 13665 | + | |
| 13666 | + | |
| 13667 | + | |
| 13668 | + | |
| 13669 | + | |
| 13670 | + | |
| 13671 | + | |
| 13672 | + | |
| 13673 | + | |
| 13674 | + | |
| 13675 | + | |
| 13676 | + | |
| 13677 | + | |
| 13678 | + | |
| 13679 | + | |
| 13680 | + | |
| 13681 | + | |
| 13682 | + | |
| 13683 | + | |
| 13684 | + | |
| 13685 | + | |
| 13686 | + | |
| 13687 | + | |
| 13688 | + | |
| 13689 | + | |
| 13690 | + | |
| 13691 | + | |
| 13692 | + | |
| 13693 | + | |
| 13694 | + | |
13662 | 13695 | | |
13663 | 13696 | | |
13664 | 13697 | | |
| |||
14400 | 14433 | | |
14401 | 14434 | | |
14402 | 14435 | | |
14403 | | - | |
| 14436 | + | |
0 commit comments