Fixed support for integers. OCI_TYPECODE_INTEGER is stored as a OCINumber, not

as a native integer.
This commit is contained in:
Anthony Tuininga 2016-03-07 08:01:24 -07:00
parent d86cf980ba
commit 614b272e34
2 changed files with 23 additions and 7 deletions

View File

@ -290,11 +290,6 @@ static int Object_ConvertFromPython(
*ociValue = oracleValue->stringValue;
break;
case OCI_TYPECODE_INTEGER:
oracleValue->integerValue = PyInt_AsLong(pythonValue);
if (PyErr_Occurred())
return -1;
*ociValue = &oracleValue->integerValue;
break;
case OCI_TYPECODE_NUMBER:
if (PythonNumberToOracleNumber(environment,
pythonValue, &oracleValue->numberValue) < 0)
@ -388,7 +383,8 @@ static PyObject *Object_ConvertToPython(
return cxString_FromEncodedString( (char*) stringValue,
stringSize, environment->encoding);
case OCI_TYPECODE_INTEGER:
return PyInt_FromLong(* (int*) value);
return OracleNumberToPythonInteger(environment,
(OCINumber*) value);
case OCI_TYPECODE_NUMBER:
return OracleNumberToPythonFloat(environment, (OCINumber*) value);
case OCI_TYPECODE_DATE:

View File

@ -96,7 +96,7 @@ static PyObject *OracleTimestampToPythonDate(
//-----------------------------------------------------------------------------
// OracleNumberToPythonFloat()
// Return a Python date object given an Oracle date.
// Return a Python float given an Oracle number.
//-----------------------------------------------------------------------------
static PyObject *OracleNumberToPythonFloat(
udt_Environment *environment, // environment
@ -114,6 +114,26 @@ static PyObject *OracleNumberToPythonFloat(
}
//-----------------------------------------------------------------------------
// OracleNumberToPythonInteger()
// Return a Python integer given an Oracle number.
//-----------------------------------------------------------------------------
static PyObject *OracleNumberToPythonInteger(
udt_Environment *environment, // environment
OCINumber* value) // value to convert
{
long integerValue;
sword status;
status = OCINumberToInt(environment->errorHandle, value,
sizeof(long), OCI_NUMBER_SIGNED, (dvoid*) &integerValue);
if (Environment_CheckForError(environment, status,
"OracleNumberToPythonInteger()") < 0)
return NULL;
return PyInt_FromLong(integerValue);
}
#if ORACLE_VERSION_HEX >= ORACLE_VERSION(12, 1)
//-----------------------------------------------------------------------------
// PythonBooleanToOracleBoolean()