From c112af35cb6f7f2540391b5e04fc9c9175c5adda Mon Sep 17 00:00:00 2001 From: Anthony Tuininga Date: Tue, 12 Mar 2019 09:31:38 -0600 Subject: [PATCH] Revert changes to return decimal numbers when the numeric precision was too great to be returned accurately as a floating point number. This change had too great an impact on existing functionality and an output type handler can be used to return decimal numbers where that is desirable (https://github.com/oracle/python-cx_Oracle/issues/279). --- src/cxoTransform.c | 10 ++++------ test/NumberVar.py | 6 +++--- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/cxoTransform.c b/src/cxoTransform.c index f04aa0f..bdd8ad7 100644 --- a/src/cxoTransform.c +++ b/src/cxoTransform.c @@ -717,14 +717,12 @@ PyObject *cxoTransform_toPython(cxoTransformNum transformNum, #endif Py_DECREF(stringObj); return result; - } else if (transformNum != CXO_TRANSFORM_DECIMAL && - bytes->length <= 15) { + } else if (transformNum == CXO_TRANSFORM_DECIMAL) { + result = PyObject_CallFunctionObjArgs( + (PyObject*) cxoPyTypeDecimal, stringObj, NULL); + } else { result = PyNumber_Float(stringObj); - Py_DECREF(stringObj); - return result; } - result = PyObject_CallFunctionObjArgs( - (PyObject*) cxoPyTypeDecimal, stringObj, NULL); Py_DECREF(stringObj); return result; case CXO_TRANSFORM_OBJECT: diff --git a/test/NumberVar.py b/test/NumberVar.py index 7a60884..31de4ca 100644 --- a/test/NumberVar.py +++ b/test/NumberVar.py @@ -321,7 +321,7 @@ class TestCase(TestEnv.BaseTestCase): decimal.Decimal("-9.99999999999999e+125"), 0.0, 1e-130, -1e-130] outValues = [int("9" * 15 + "0" * 111), -int("9" * 15 + "0" * 111), - 0, decimal.Decimal("1e-130"), decimal.Decimal("-1e-130")] + 0, 1e-130, -1e-130] for inValue, outValue in zip(inValues, outValues): self.cursor.execute("select :1 from dual", (inValue,)) result, = self.cursor.fetchone() @@ -351,8 +351,8 @@ class TestCase(TestEnv.BaseTestCase): from TestNumbers where IntCol = 1""") result, = self.cursor.fetchone() - self.assertAlmostEqual(result, - decimal.Decimal("1") / decimal.Decimal("7")) + self.assertEqual(result, 1.0 / 7.0) + self.assertTrue(isinstance(result, float), "float not returned") def testStringFormat(self): "test that string format is returned properly"