Skip to content
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

Decimal_cvt fails if the value has decimals #97

Open
iconberg opened this issue Jun 4, 2019 · 1 comment
Open

Decimal_cvt fails if the value has decimals #97

iconberg opened this issue Jun 4, 2019 · 1 comment

Comments

@iconberg
Copy link

iconberg commented Jun 4, 2019

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.

@iconberg
Copy link
Author

iconberg commented Jun 4, 2019

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!?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant