zillow / ctds

Python DB-API 2.0 library for MS SQL Server
MIT License
83 stars 12 forks source link

SqlDecimal raises RuntimeError for numbers less than or equal to 1e-5 independent of the scale specified #100

Open dfox-rms opened 1 year ago

dfox-rms commented 1 year ago

Hi, I am having receiving an error when converting Python floats to SqlDecimal.

Here is a minimal example:

import ctds
afloat = 1e-4
# runs successfully
result = ctds.SqlDecimal(afloat, 38, 0)

bfloat = 1e-5
# raises "RuntimeError: failed to convert '1e-05'"
try:
    result = ctds.SqlDecimal(bfloat, 38, 0)
except RuntimeError as e:
    print(e)

cfloat = 1e-5
# raises "RuntimeError: failed to convert '1e-05'"
try:
    result = ctds.SqlDecimal(cfloat, 38, 8)
except RuntimeError as e:
    print(e)

My setup: MacOS BigSur Version 11.7 Python 3.10.9 Working in a Conda Environment Name Version Build Channel ctds 1.14.0 py310h90acd4f_3 conda-forge Result of running $ tsql -C: Compile-time settings (established with the "configure" script) Version: freetds v1.1.15 freetds.conf directory: /Users/.../miniconda3/envs/.../etc MS db-lib source compatibility: no Sybase binary compatibility: no Thread safety: yes iconv library: yes TDS version: auto iODBC: no unixodbc: yes SSPI "trusted" logins: no Kerberos: no OpenSSL: yes GnuTLS: no MARS: yes

Thanks for any assistance you can provide. CTDS has been a great help on previous projects, so thanks!