Prevent use of NaN with Oracle numbers since it produces corrupt data

(https://github.com/oracle/python-cx_Oracle/issues/91).
This commit is contained in:
Anthony Tuininga 2017-11-15 11:48:17 -07:00
parent 9311ab9c4e
commit c5fab177f9
2 changed files with 14 additions and 0 deletions

View File

@ -248,6 +248,12 @@ static int PythonFloatToOracleNumber(
sword status;
doubleValue = PyFloat_AS_DOUBLE(pythonValue);
if (isnan(doubleValue)) {
PyErr_SetString(g_DatabaseErrorException,
"value is not a number (NaN) and cannot be used in Oracle "
"numbers");
return -1;
}
status = OCINumberFromReal(environment->errorHandle, &doubleValue,
sizeof(double), oracleValue);
return Environment_CheckForError(environment, status,

View File

@ -18,10 +18,18 @@
#include <datetime.h>
#include <structmember.h>
#include <time.h>
#include <math.h>
#include <oci.h>
#include <orid.h>
#include <xa.h>
// define isnan for older versions of Visual Studio which only define _isnan
#ifdef _WIN32
#ifndef isnan
#define isnan _isnan
#endif
#endif
// validate OCI library
#if !defined(OCI_MAJOR_VERSION) || (OCI_MAJOR_VERSION < 11) || \
((OCI_MAJOR_VERSION == 11) && (OCI_MINOR_VERSION < 2))