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).
This commit is contained in:
parent
8789c6d2a0
commit
c112af35cb
@ -717,14 +717,12 @@ PyObject *cxoTransform_toPython(cxoTransformNum transformNum,
|
|||||||
#endif
|
#endif
|
||||||
Py_DECREF(stringObj);
|
Py_DECREF(stringObj);
|
||||||
return result;
|
return result;
|
||||||
} else if (transformNum != CXO_TRANSFORM_DECIMAL &&
|
} else if (transformNum == CXO_TRANSFORM_DECIMAL) {
|
||||||
bytes->length <= 15) {
|
result = PyObject_CallFunctionObjArgs(
|
||||||
|
(PyObject*) cxoPyTypeDecimal, stringObj, NULL);
|
||||||
|
} else {
|
||||||
result = PyNumber_Float(stringObj);
|
result = PyNumber_Float(stringObj);
|
||||||
Py_DECREF(stringObj);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
result = PyObject_CallFunctionObjArgs(
|
|
||||||
(PyObject*) cxoPyTypeDecimal, stringObj, NULL);
|
|
||||||
Py_DECREF(stringObj);
|
Py_DECREF(stringObj);
|
||||||
return result;
|
return result;
|
||||||
case CXO_TRANSFORM_OBJECT:
|
case CXO_TRANSFORM_OBJECT:
|
||||||
|
|||||||
@ -321,7 +321,7 @@ class TestCase(TestEnv.BaseTestCase):
|
|||||||
decimal.Decimal("-9.99999999999999e+125"), 0.0, 1e-130,
|
decimal.Decimal("-9.99999999999999e+125"), 0.0, 1e-130,
|
||||||
-1e-130]
|
-1e-130]
|
||||||
outValues = [int("9" * 15 + "0" * 111), -int("9" * 15 + "0" * 111),
|
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):
|
for inValue, outValue in zip(inValues, outValues):
|
||||||
self.cursor.execute("select :1 from dual", (inValue,))
|
self.cursor.execute("select :1 from dual", (inValue,))
|
||||||
result, = self.cursor.fetchone()
|
result, = self.cursor.fetchone()
|
||||||
@ -351,8 +351,8 @@ class TestCase(TestEnv.BaseTestCase):
|
|||||||
from TestNumbers
|
from TestNumbers
|
||||||
where IntCol = 1""")
|
where IntCol = 1""")
|
||||||
result, = self.cursor.fetchone()
|
result, = self.cursor.fetchone()
|
||||||
self.assertAlmostEqual(result,
|
self.assertEqual(result, 1.0 / 7.0)
|
||||||
decimal.Decimal("1") / decimal.Decimal("7"))
|
self.assertTrue(isinstance(result, float), "float not returned")
|
||||||
|
|
||||||
def testStringFormat(self):
|
def testStringFormat(self):
|
||||||
"test that string format is returned properly"
|
"test that string format is returned properly"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user