FEAT: Add support for decimal value in scientific notation by gargsaumya · Pull Request #313 · microsoft/mssql-python
Work Item / Issue Reference
GitHub Issue: #<ISSUE_NUMBER>
Summary
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_typeinmssql_python/cursor.pyto useformat(param, 'f')instead ofstr(param)forMONEYandSMALLMONEYtypes, ensuring decimals are always converted to fixed-point strings. [1] [2] - Modified
executemanyinmssql_python/cursor.pyto format decimal values as fixed-point strings before insertion when mapped toSQL_VARCHAR.
Test suite enhancements:
- Added
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: