Binary integer variables now explicitly convert values to integers (since

implicit conversion to integer has become an error in Python 3.10) and
values that are not `int`, `float` or `decimal.Decimal` are explicitly
rejected.
This commit is contained in:
Anthony Tuininga 2021-06-08 11:15:13 -06:00
parent abb666706b
commit cc067bf83e
2 changed files with 23 additions and 8 deletions

View File

@ -13,6 +13,10 @@ Version 8.3 (TBD)
#) Updated embedded ODPI-C to `version 4.3.0
<https://oracle.github.io/odpi/doc/releasenotes.html#
version-4-3-tbd>`__.
#) Binary integer variables now explicitly convert values to integers (since
implicit conversion to integer has become an error in Python 3.10) and
values that are not `int`, `float` or `decimal.Decimal` are explicitly
rejected.
Version 8.2.1 (June 2021)

View File

@ -244,7 +244,7 @@ int cxoTransform_fromPython(cxoTransformNum transformNum,
dpiIntervalDS *interval;
PyDateTime_Delta *delta;
int32_t deltaSeconds;
PyObject *textValue;
PyObject *tempValue;
cxoObject *obj;
cxoLob *lob;
int status;
@ -316,10 +316,21 @@ int cxoTransform_fromPython(cxoTransformNum transformNum,
dbValue->asInt64 = (pyValue == Py_True);
return 0;
}
dbValue->asInt64 = PyLong_AsLong(pyValue);
if (PyErr_Occurred())
if (!PyFloat_Check(pyValue) &&
!PyLong_Check(pyValue) &&
!PyObject_TypeCheck(pyValue, cxoPyTypeDecimal)) {
PyErr_SetString(PyExc_TypeError,
"expecting number or boolean");
return -1;
return 0;
}
tempValue = PyObject_CallFunctionObjArgs((PyObject*) &PyLong_Type,
pyValue, NULL);
if (!tempValue)
return -1;
dbValue->asInt64 = PyLong_AsLong(tempValue);
status = (PyErr_Occurred()) ? -1 : 0;
Py_DECREF(tempValue);
return status;
case CXO_TRANSFORM_INT:
case CXO_TRANSFORM_DECIMAL:
case CXO_TRANSFORM_FLOAT:
@ -334,11 +345,11 @@ int cxoTransform_fromPython(cxoTransformNum transformNum,
PyErr_SetString(PyExc_TypeError, "expecting number");
return -1;
}
textValue = PyObject_Str(pyValue);
if (!textValue)
tempValue = PyObject_Str(pyValue);
if (!tempValue)
return -1;
status = cxoBuffer_fromObject(buffer, textValue, encoding);
Py_DECREF(textValue);
status = cxoBuffer_fromObject(buffer, tempValue, encoding);
Py_DECREF(tempValue);
if (status < 0)
return -1;
}