-
Notifications
You must be signed in to change notification settings - Fork 27
FEAT: Add support for decimal value in scientific notation #313
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 fixes Decimal to VARCHAR conversion issues by preventing scientific notation from being passed to SQL Server. The driver now converts Decimal values to fixed-point notation using format(param, 'f') instead of str(param), which previously preserved scientific notation and caused SQL Server conversion errors.
Key changes:
- Modified Decimal to VARCHAR conversion to use fixed-point notation format
- Removed error-handling workarounds from tests that are no longer needed
- Added comprehensive test coverage for Decimal scientific notation scenarios
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| mssql_python/cursor.py | Changed Decimal to VARCHAR conversion from str() to format(param, 'f') for MONEY/SMALLMONEY and other VARCHAR-bound decimals to prevent scientific notation |
| tests/test_004_cursor.py | Removed obsolete exception handlers, added new test for Decimal scientific notation to VARCHAR conversion, minor whitespace fix |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
📊 Code Coverage Report
Diff CoverageDiff: main...HEAD, staged and unstaged changes
Summary
📋 Files Needing Attention📉 Files with overall lowest coverage (click to expand)mssql_python.pybind.ddbc_bindings.cpp: 70.9%
mssql_python.pybind.connection.connection_pool.cpp: 78.9%
mssql_python.ddbc_bindings.py: 79.6%
mssql_python.pybind.connection.connection.cpp: 81.2%
mssql_python.connection.py: 82.9%
mssql_python.auth.py: 87.1%
mssql_python.pooling.py: 87.7%
mssql_python.helpers.py: 88.9%
mssql_python.__init__.py: 90.7%
mssql_python.exceptions.py: 92.1%🔗 Quick Links
|
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.
Left few comments
|
As discussed offline, I’ve created a work item (40169) for correct handling of Decimal types (Numeric, Money, and SmallMoney) based on proper precision and scale. |
Work Item / Issue Reference
Summary
This pull request improves the handling of decimal values, especially those in scientific notation, when converting to SQL
VARCHARtypes. 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:
_map_sql_typeinmssql_python/cursor.pyto useformat(param, 'f')instead ofstr(param)forMONEYandSMALLMONEYtypes, ensuring decimals are always converted to fixed-point strings. [1] [2]executemanyinmssql_python/cursor.pyto format decimal values as fixed-point strings before insertion when mapped toSQL_VARCHAR.Test suite enhancements:
test_decimal_scientific_notation_to_varcharintests/test_004_cursor.pyto verify that decimals (including those with scientific notation) are correctly converted and stored asVARCHARwithout causing conversion errors.Test cleanup and simplification:
test_numeric_leading_zeros_precision_lossandtest_numeric_extreme_exponents_precision_lossthat previously skipped tests on conversion errors, as these errors should no longer occur with the improved formatting. [1] [2]