You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
FEAT: Add support for decimal value in scientific notation (#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. #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
-->
0 commit comments