Skip to content

Commit

Permalink
Correct support for PLS_INTEGER and BINARY_INTEGER types when used in…
Browse files Browse the repository at this point in the history
… PL/SQL

records (#112).
  • Loading branch information
anthony-tuininga committed Aug 27, 2019
1 parent 2c24d3d commit 4e80a81
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/dpiImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,7 @@ typedef union {
char *asBytes;
float *asFloat;
double *asDouble;
int32_t *asInt32;
int64_t *asInt64;
uint64_t *asUint64;
dpiOciNumber *asNumber;
Expand All @@ -868,6 +869,7 @@ typedef union {
// buffers to Oracle when values are being transferred to or from the Oracle
// database
typedef union {
int32_t asInt32;
int64_t asInt64;
uint64_t asUint64;
float asFloat;
Expand Down
13 changes: 10 additions & 3 deletions src/dpiObject.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,10 @@ static int dpiObject__fromOracleValue(dpiObject *obj, dpiError *error,
}
break;
case DPI_ORACLE_TYPE_NATIVE_INT:
if (nativeTypeNum == DPI_NATIVE_TYPE_INT64)
return dpiDataBuffer__fromOracleNumberAsInteger(&data->value,
error, value->asNumber);
if (nativeTypeNum == DPI_NATIVE_TYPE_INT64) {
data->value.asInt64 = *value->asInt32;
return DPI_SUCCESS;
}
break;
case DPI_ORACLE_TYPE_NATIVE_FLOAT:
if (nativeTypeNum == DPI_NATIVE_TYPE_FLOAT) {
Expand Down Expand Up @@ -440,6 +441,12 @@ static int dpiObject__toOracleValue(dpiObject *obj, dpiError *error,
}
break;
case DPI_ORACLE_TYPE_NATIVE_INT:
if (nativeTypeNum == DPI_NATIVE_TYPE_INT64) {
buffer->asInt32 = (int32_t) data->value.asInt64;
*ociValue = &buffer->asInt32;
return DPI_SUCCESS;
}
break;
case DPI_ORACLE_TYPE_NUMBER:
*ociValue = &buffer->asNumber;
if (nativeTypeNum == DPI_NATIVE_TYPE_INT64)
Expand Down
6 changes: 3 additions & 3 deletions src/dpiOracleType.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ static const dpiOracleType
DPI_NATIVE_TYPE_INT64, // default native type
DPI_SQLT_INT, // internal Oracle type
DPI_SQLCS_IMPLICIT, // charset form
sizeof(int64_t), // buffer size
sizeof(int32_t), // buffer size
0, // is character data
1, // can be in array
0 // requires pre-fetch
Expand Down Expand Up @@ -298,12 +298,14 @@ static dpiOracleTypeNum dpiOracleType__convertFromOracle(uint16_t typeCode,
if (charsetForm == DPI_SQLCS_NCHAR)
return DPI_ORACLE_TYPE_NVARCHAR;
return DPI_ORACLE_TYPE_VARCHAR;
case DPI_SQLT_INT:
case DPI_SQLT_FLT:
case DPI_SQLT_NUM:
case DPI_SQLT_PDN:
case DPI_SQLT_VNU:
case DPI_SQLT_BFLOAT:
case DPI_SQLT_BDOUBLE:
case DPI_OCI_TYPECODE_SMALLINT:
return DPI_ORACLE_TYPE_NUMBER;
case DPI_SQLT_DAT:
case DPI_SQLT_ODT:
Expand All @@ -315,8 +317,6 @@ static dpiOracleTypeNum dpiOracleType__convertFromOracle(uint16_t typeCode,
if (charsetForm == DPI_SQLCS_NCHAR)
return DPI_ORACLE_TYPE_NCHAR;
return DPI_ORACLE_TYPE_CHAR;
case DPI_SQLT_INT:
case DPI_OCI_TYPECODE_SMALLINT:
case DPI_OCI_TYPECODE_BINARY_INTEGER:
case DPI_OCI_TYPECODE_PLS_INTEGER:
return DPI_ORACLE_TYPE_NATIVE_INT;
Expand Down
2 changes: 1 addition & 1 deletion test/TestDataTypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1293,7 +1293,7 @@ int dpiTest_1205_verifyObjectAttributes(dpiTestCase *testCase,
dpiData_getDouble(&attrValues[12]), 13.25) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTestCase_expectDoubleEqual(testCase,
dpiData_getInt64(&attrValues[13]), 123) < 0)
dpiData_getDouble(&attrValues[13]), 123) < 0)
return dpiTestCase_setFailedFromError(testCase);

// cleanup
Expand Down

0 comments on commit 4e80a81

Please sign in to comment.