@@ -104,23 +104,18 @@ static const cxoTransform cxoAllTransforms[] = {
104104 {
105105 CXO_TRANSFORM_FLOAT ,
106106 DPI_ORACLE_TYPE_NUMBER ,
107- DPI_NATIVE_TYPE_DOUBLE
107+ DPI_NATIVE_TYPE_BYTES
108108 },
109109 {
110110 CXO_TRANSFORM_INT ,
111111 DPI_ORACLE_TYPE_NUMBER ,
112- DPI_NATIVE_TYPE_INT64
112+ DPI_NATIVE_TYPE_BYTES
113113 },
114114 {
115115 CXO_TRANSFORM_LONG_BINARY ,
116116 DPI_ORACLE_TYPE_LONG_RAW ,
117117 DPI_NATIVE_TYPE_BYTES
118118 },
119- {
120- CXO_TRANSFORM_LONG_INT ,
121- DPI_ORACLE_TYPE_NUMBER ,
122- DPI_NATIVE_TYPE_BYTES
123- },
124119 {
125120 CXO_TRANSFORM_LONG_STRING ,
126121 DPI_ORACLE_TYPE_LONG_VARCHAR ,
@@ -252,7 +247,6 @@ int cxoTransform_fromPython(cxoTransformNum transformNum, PyObject *pyValue,
252247 buffer -> size );
253248 Py_END_ALLOW_THREADS
254249 return status ;
255- case CXO_TRANSFORM_INT :
256250 case CXO_TRANSFORM_NATIVE_INT :
257251#if PY_MAJOR_VERSION < 3
258252 if (PyInt_Check (pyValue )) {
@@ -268,8 +262,18 @@ int cxoTransform_fromPython(cxoTransformNum transformNum, PyObject *pyValue,
268262 if (PyErr_Occurred ())
269263 return -1 ;
270264 return 0 ;
265+ case CXO_TRANSFORM_INT :
271266 case CXO_TRANSFORM_DECIMAL :
272- case CXO_TRANSFORM_LONG_INT :
267+ case CXO_TRANSFORM_FLOAT :
268+ if (!PyFloat_Check (pyValue ) &&
269+ #if PY_MAJOR_VERSION < 3
270+ !PyInt_Check (pyValue ) &&
271+ #endif
272+ !PyLong_Check (pyValue ) &&
273+ !PyObject_TypeCheck (pyValue , cxoPyTypeDecimal )) {
274+ PyErr_SetString (PyExc_TypeError , "expecting number" );
275+ return -1 ;
276+ }
273277 textValue = PyObject_Str (pyValue );
274278 if (!textValue )
275279 return -1 ;
@@ -280,19 +284,6 @@ int cxoTransform_fromPython(cxoTransformNum transformNum, PyObject *pyValue,
280284 dbValue -> asBytes .ptr = (char * ) buffer -> ptr ;
281285 dbValue -> asBytes .length = buffer -> size ;
282286 return 0 ;
283- case CXO_TRANSFORM_FLOAT :
284- if (!PyFloat_Check (pyValue ) &&
285- #if PY_MAJOR_VERSION < 3
286- !PyInt_Check (pyValue ) &&
287- #endif
288- !PyLong_Check (pyValue )) {
289- PyErr_SetString (PyExc_TypeError , "expecting float" );
290- return -1 ;
291- }
292- dbValue -> asDouble = PyFloat_AsDouble (pyValue );
293- if (PyErr_Occurred ())
294- return -1 ;
295- return 0 ;
296287 case CXO_TRANSFORM_NATIVE_DOUBLE :
297288 case CXO_TRANSFORM_NATIVE_FLOAT :
298289 if (!PyFloat_Check (pyValue ) &&
@@ -380,10 +371,6 @@ int cxoTransform_fromPython(cxoTransformNum transformNum, PyObject *pyValue,
380371//-----------------------------------------------------------------------------
381372cxoTransformNum cxoTransform_getNumFromDataTypeInfo (dpiDataTypeInfo * info )
382373{
383- #if PY_MAJOR_VERSION < 3
384- static int maxLongSafeDigits = sizeof (long ) >= 8 ? 18 : 9 ;
385- #endif
386-
387374 switch (info -> oracleTypeNum ) {
388375 case DPI_ORACLE_TYPE_VARCHAR :
389376 return CXO_TRANSFORM_STRING ;
@@ -403,14 +390,8 @@ cxoTransformNum cxoTransform_getNumFromDataTypeInfo(dpiDataTypeInfo *info)
403390 return CXO_TRANSFORM_NATIVE_FLOAT ;
404391 case DPI_ORACLE_TYPE_NUMBER :
405392 if (info -> scale == 0 ||
406- (info -> scale == -127 && info -> precision == 0 )) {
407- #if PY_MAJOR_VERSION < 3
408- if (info -> precision > 0 &&
409- info -> precision <= maxLongSafeDigits )
410- return CXO_TRANSFORM_INT ;
411- #endif
412- return CXO_TRANSFORM_LONG_INT ;
413- }
393+ (info -> scale == -127 && info -> precision == 0 ))
394+ return CXO_TRANSFORM_INT ;
414395 return CXO_TRANSFORM_FLOAT ;
415396 case DPI_ORACLE_TYPE_NATIVE_INT :
416397 return CXO_TRANSFORM_NATIVE_INT ;
@@ -479,7 +460,7 @@ cxoTransformNum cxoTransform_getNumFromType(PyTypeObject *type)
479460 if (type == & PyFloat_Type )
480461 return CXO_TRANSFORM_FLOAT ;
481462 if (type == & PyLong_Type )
482- return CXO_TRANSFORM_LONG_INT ;
463+ return CXO_TRANSFORM_INT ;
483464 if (type == cxoPyTypeDecimal )
484465 return CXO_TRANSFORM_DECIMAL ;
485466 if (type == & cxoPyTypeNumberVar )
@@ -558,7 +539,7 @@ cxoTransformNum cxoTransform_getNumFromValue(PyObject *value, int plsql)
558539 return CXO_TRANSFORM_INT ;
559540#endif
560541 if (PyLong_Check (value ))
561- return CXO_TRANSFORM_LONG_INT ;
542+ return CXO_TRANSFORM_INT ;
562543 if (PyFloat_Check (value ))
563544 return CXO_TRANSFORM_FLOAT ;
564545 if (PyDateTime_Check (value ))
@@ -703,44 +684,42 @@ PyObject *cxoTransform_toPython(cxoTransformNum transformNum,
703684 timestamp -> month , timestamp -> day , timestamp -> hour ,
704685 timestamp -> minute , timestamp -> second ,
705686 timestamp -> fsecond / 1000 );
706- case CXO_TRANSFORM_DECIMAL :
707- bytes = & dbValue -> asBytes ;
708- stringObj = cxoPyString_fromEncodedString (bytes -> ptr ,
709- bytes -> length , bytes -> encoding , encodingErrors );
710- if (!stringObj )
711- return NULL ;
712- result = PyObject_CallFunctionObjArgs (
713- (PyObject * ) cxoPyTypeDecimal , stringObj , NULL );
714- Py_DECREF (stringObj );
715- return result ;
716687 case CXO_TRANSFORM_FIXED_NCHAR :
717688 case CXO_TRANSFORM_NSTRING :
718689 bytes = & dbValue -> asBytes ;
719690 return PyUnicode_Decode (bytes -> ptr , bytes -> length , bytes -> encoding ,
720691 encodingErrors );
721- case CXO_TRANSFORM_FLOAT :
722692 case CXO_TRANSFORM_NATIVE_DOUBLE :
723693 return PyFloat_FromDouble (dbValue -> asDouble );
724694 case CXO_TRANSFORM_NATIVE_FLOAT :
725695 return PyFloat_FromDouble (dbValue -> asFloat );
726- case CXO_TRANSFORM_INT :
727696 case CXO_TRANSFORM_NATIVE_INT :
728697 return PyInt_FromLong ((long ) dbValue -> asInt64 );
729- case CXO_TRANSFORM_LONG_INT :
698+ case CXO_TRANSFORM_DECIMAL :
699+ case CXO_TRANSFORM_INT :
700+ case CXO_TRANSFORM_FLOAT :
730701 bytes = & dbValue -> asBytes ;
731702 stringObj = cxoPyString_fromEncodedString (bytes -> ptr ,
732- bytes -> length , NULL , NULL );
703+ bytes -> length , bytes -> encoding , encodingErrors );
733704 if (!stringObj )
734705 return NULL ;
706+ if (transformNum == CXO_TRANSFORM_INT &&
707+ memchr (bytes -> ptr , '.' , bytes -> length ) == NULL ) {
735708#if PY_MAJOR_VERSION >= 3
736- result = PyNumber_Long (stringObj );
709+ result = PyNumber_Long (stringObj );
737710#else
738- result = PyNumber_Int (stringObj );
711+ result = PyNumber_Int (stringObj );
739712#endif
740- if (!result && PyErr_ExceptionMatches (PyExc_ValueError )) {
741- PyErr_Clear ();
713+ Py_DECREF (stringObj );
714+ return result ;
715+ } else if (transformNum != CXO_TRANSFORM_DECIMAL &&
716+ bytes -> length <= 15 ) {
742717 result = PyNumber_Float (stringObj );
718+ Py_DECREF (stringObj );
719+ return result ;
743720 }
721+ result = PyObject_CallFunctionObjArgs (
722+ (PyObject * ) cxoPyTypeDecimal , stringObj , NULL );
744723 Py_DECREF (stringObj );
745724 return result ;
746725 case CXO_TRANSFORM_OBJECT :
0 commit comments