Skip to content

Commit

Permalink
Correct handling of long Python integers that cannot fit inside a 64-…
Browse files Browse the repository at this point in the history
…bit C

integer (#18).
  • Loading branch information
anthony-tuininga committed May 3, 2017
1 parent 2e04505 commit 53f8902
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion odpi
Submodule odpi updated 1 files
+6 −4 src/dpiVar.c
7 changes: 4 additions & 3 deletions src/Variable.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,9 @@ static udt_VariableType *VarType_FromQueryInfo(dpiQueryInfo *info)
case DPI_ORACLE_TYPE_NATIVE_DOUBLE:
return &vt_NativeFloat;
case DPI_ORACLE_TYPE_NUMBER:
if (info->scale == 0 && info->precision > 0) {
if (info->precision <= DPI_MAX_INT64_PRECISION)
if (info->scale == 0) {
if (info->precision > 0 &&
info->precision <= DPI_MAX_INT64_PRECISION)
return &vt_NumberAsInteger;
return &vt_NumberAsLongInteger;
}
Expand Down Expand Up @@ -460,7 +461,7 @@ static udt_VariableType *Variable_TypeByValue(PyObject* value, uint32_t* size,
}
#endif
if (PyLong_Check(value))
return &vt_NumberAsInteger;
return &vt_NumberAsLongInteger;
if (PyFloat_Check(value))
return &vt_NumberAsFloat;
if (cxBinary_Check(value)) {
Expand Down
11 changes: 9 additions & 2 deletions test/NumberVar.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ def testBindSmallLong(self):
value = long(3))
self.assertEqual(self.cursor.fetchall(), [self.dataByKey[3]])

def testBindLargeLong(self):
"test binding in a large long integer"
def testBindLargeLongAsOracleNumber(self):
"test binding in a large long integer as Oracle number"
valueVar = self.cursor.var(cx_Oracle.NUMBER)
valueVar.setvalue(0, 6088343244)
self.cursor.execute("""
Expand All @@ -81,6 +81,13 @@ def testBindLargeLong(self):
value = valueVar.getvalue()
self.assertEqual(value, 6088343249)

def testBindLargeLongAsInteger(self):
"test binding in a large long integer as Python integer"
longValue = -9999999999999999999
self.cursor.execute("select :value from dual", value = longValue)
result, = self.cursor.fetchone()
self.assertEqual(result, longValue)

def testBindIntegerAfterString(self):
"test binding in an number after setting input sizes to a string"
self.cursor.setinputsizes(value = 15)
Expand Down

0 comments on commit 53f8902

Please sign in to comment.