pypyodbc
pypyodbc copied to clipboard
Decimal_cvt fails if the value has decimals
If i try to fetch data with the datatype number(5,2) i got error:
File "C:\Program Files (x86)\Python37-32\lib\site-packages\pypyodbc.py", line 608, in Decimal_cvt
return Decimal(x)
decimal.InvalidOperation: [<class 'decimal.ConversionSyntax'>]
This error happens only if the value has decimals, for example 1.23, if the value has no decimals like 1.00 there is no error.
Database is oracle 12 (dont know if other databases produce this error too) Reproducable with
def foo():
sql = """
select cast(1.23 as number(5,2))
from dual;
"""
cs = "Driver={Oracle in OraClient12Home1_32bit};Dbq=xxx;Uid=xxx;Pwd=xxx;app=pypyodbc"
conn = pypyodbc.connect(cs)
cur = conn.cursor()
cur.execute(sql)
d = cur.fetchall()
Tried to workaround with cast(1.23 as float) but it brings error to if the value has decimals:
File "C:\Program Files (x86)\Python37-32\lib\site-packages\pypyodbc.py", line 1911, in fetchone
value_list.append(buf_cvt_func(alloc_buffer.value))
ValueError: could not convert string to float: b'1,23'
I have no usable workaround.
I take a closer look at the code, and if iam right the Decimal_cvt uses Lib/decimal.py, so i guess the problem comes from different decimal separators . or ,
If the database uses and delivers , has separator pypyodbc fails to convert cause other separators than . not usable!?