Skip to content

Decimal_cvt fails if the value has decimals #97

@iconberg

Description

@iconberg

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions