regression in numeric precision behavior in 6.0 · Issue #68 · oracle/python-cx_Oracle · GitHub
Skip to content

regression in numeric precision behavior in 6.0 #68

Description

@zzzeek

Using cx_Oracle.NUMERIC with setinputsizes is now causing truncation under cx_Oracle 6.0.

import cx_Oracle
import decimal

conn = cx_Oracle.connect(
    user="scott",
    password="tiger",
    dsn=cx_Oracle.makedsn(
        "192.168.1.185", 1521, sid="xe",
    )
)

cursor = conn.cursor()


def output_type_handler(cursor, name, defaultType,
                        size, precision, scale):
    if defaultType == cx_Oracle.NUMBER:
        return cursor.var(
            cx_Oracle.STRING,
            255,
            outconverter=decimal.Decimal,
            arraysize=cursor.arraysize)

cursor.outputtypehandler = output_type_handler

cursor.execute("""
CREATE TABLE t (
    x NUMERIC(38, 12)
)
""")
try:
    value = decimal.Decimal("319438950232418390.273596")
    cursor.setinputsizes(x=cx_Oracle.NUMBER)
    cursor.execute(
        "INSERT INTO t (x) VALUES (:x)",
        x=value
    )

    cursor.execute("SELECT x FROM t")
    row = cursor.fetchone()
    received = row[0]

    print "cx_Oracle version: %r" % cx_Oracle.__version__
    print "Sent: %r   Received: %r" % (value, received)

    assert received == value, "%r != %r" % (received, value)


finally:
    cursor.execute("DROP TABLE t")


output under 5.2:

cx_Oracle version: '5.2'
Sent: Decimal('319438950232418390.273596')   Received: Decimal('319438950232418390.273596')

output under 6.0:

cx_Oracle version: '6.0'
Sent: Decimal('319438950232418390.273596')   Received: Decimal('319438950232418000')
Traceback (most recent call last):
  File "test.py", line 46, in <module>
    assert received == value, "%r != %r" % (received, value)
AssertionError: Decimal('319438950232418000') != Decimal('319438950232418390.273596')

if I remove the call to setinputsizes(), it works.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions