Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Object raw attributes #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/dpiImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ extern unsigned long dpiDebugLevel;
#define DPI_SQLT_BIN 23
#define DPI_SQLT_LBI 24
#define DPI_SQLT_UIN 68
#define DPI_SQLT_LVB 95
#define DPI_SQLT_AFC 96
#define DPI_SQLT_IBFLOAT 100
#define DPI_SQLT_IBDOUBLE 101
Expand Down Expand Up @@ -777,6 +778,7 @@ typedef union {
void **asInterval;
void **asLobLocator;
void **asString;
void **asOciraw;
void **asStmt;
void **asRowid;
int *asBoolean;
Expand Down
27 changes: 27 additions & 0 deletions src/dpiObject.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ static void dpiObject__clearOracleValue(dpiObject *obj, dpiError *error,
dpiOci__stringResize(obj->env->handle, &buffer->asString, 0,
error);
break;
case DPI_ORACLE_TYPE_RAW:
if (buffer->asRaw)
dpiOci__rawResize(obj->env->handle, &buffer->asRaw, 0,
error);
break;
case DPI_ORACLE_TYPE_TIMESTAMP:
if (buffer->asTimestamp)
dpiOci__descriptorFree(buffer->asTimestamp,
Expand Down Expand Up @@ -243,6 +248,17 @@ static int dpiObject__fromOracleValue(dpiObject *obj, dpiError *error,
return DPI_SUCCESS;
}
break;
case DPI_ORACLE_TYPE_RAW:
if (nativeTypeNum == DPI_NATIVE_TYPE_BYTES) {
asBytes = &data->value.asBytes;
dpiOci__rawPtr(obj->env->handle, *value->asOciraw,
(void **)&asBytes->ptr);
dpiOci__rawSize(obj->env->handle, *value->asOciraw,
&asBytes->length);
asBytes->encoding = NULL;
return DPI_SUCCESS;
}
break;
case DPI_ORACLE_TYPE_NATIVE_INT:
if (nativeTypeNum == DPI_NATIVE_TYPE_INT64)
return dpiDataBuffer__fromOracleNumberAsInteger(&data->value,
Expand Down Expand Up @@ -385,6 +401,17 @@ static int dpiObject__toOracleValue(dpiObject *obj, dpiError *error,
return DPI_SUCCESS;
}
break;
case DPI_ORACLE_TYPE_RAW:
buffer->asRaw = NULL;
if (nativeTypeNum == DPI_NATIVE_TYPE_BYTES) {
bytes = &data->value.asBytes;
if (dpiOci__rawAssignBytes(obj->env->handle, bytes->ptr,
bytes->length, &buffer->asRaw, error) < 0)
return DPI_FAILURE;
*ociValue = buffer->asRaw;
return DPI_SUCCESS;
}
break;
case DPI_ORACLE_TYPE_NATIVE_INT:
case DPI_ORACLE_TYPE_NUMBER:
*ociValue = &buffer->asNumber;
Expand Down
1 change: 1 addition & 0 deletions src/dpiOracleType.c
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ static dpiOracleTypeNum dpiOracleType__convertFromOracle(uint16_t typeCode,
case DPI_SQLT_ODT:
return DPI_ORACLE_TYPE_DATE;
case DPI_SQLT_BIN:
case DPI_SQLT_LVB:
return DPI_ORACLE_TYPE_RAW;
case DPI_SQLT_AFC:
if (charsetForm == DPI_SQLCS_NCHAR)
Expand Down
17 changes: 14 additions & 3 deletions test/TestDataTypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1086,11 +1086,11 @@ int dpiTest_1205_verifyObjectAttributes(dpiTestCase *testCase,
const char *insertSql = "insert into TestObjectDataTypes values (:1)";
const char *selectSql = "select ObjectCol from TestObjectDataTypes";
const char *objectName = "UDT_OBJECTDATATYPES";
dpiData data, *objColValue, attrValues[13];
uint32_t i, bufferRowIndex, numAttrs = 13;
dpiData data, *objColValue, attrValues[14];
uint32_t i, bufferRowIndex, numAttrs = 14;
dpiNativeTypeNum nativeTypeNum;
dpiObjectAttrInfo attrInfo;
dpiObjectAttr *attrs[13];
dpiObjectAttr *attrs[14];
dpiQueryInfo queryInfo;
dpiObjectType *objType;
dpiObject *obj;
Expand Down Expand Up @@ -1162,6 +1162,10 @@ int dpiTest_1205_verifyObjectAttributes(dpiTestCase *testCase,
if (dpiObject_setAttributeValue(obj, attrs[12], DPI_NATIVE_TYPE_INT64,
&data) < 0)
return dpiTestCase_setFailedFromError(testCase);
dpiData_setBytes(&data, "RawData", strlen("RawData"));
if (dpiObject_setAttributeValue(obj, attrs[13], DPI_NATIVE_TYPE_BYTES,
&data) < 0)
return dpiTestCase_setFailedFromError(testCase);

// insert data
if (dpiConn_prepareStmt(conn, 0, insertSql, strlen(insertSql), NULL, 0,
Expand Down Expand Up @@ -1246,6 +1250,8 @@ int dpiTest_1205_verifyObjectAttributes(dpiTestCase *testCase,
if (dpiTest__compareTimestamps(testCase, dpiData_getTimestamp(&data),
dpiData_getTimestamp(&attrValues[8])) < 0)
return DPI_FAILURE;
//work with german dbtimzone here
dpiData_setTimestamp(&data, 2017, 6, 1, 4, 2, 1, 0, 0, 0);
if (dpiTest__compareTimestamps(testCase, dpiData_getTimestamp(&data),
dpiData_getTimestamp(&attrValues[9])) < 0)
return DPI_FAILURE;
Expand All @@ -1258,6 +1264,11 @@ int dpiTest_1205_verifyObjectAttributes(dpiTestCase *testCase,
if (dpiTestCase_expectDoubleEqual(testCase,
dpiData_getInt64(&attrValues[12]), 123) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTestCase_expectStringEqual(testCase,
dpiData_getBytes(&attrValues[13])->ptr,
dpiData_getBytes(&attrValues[13])->length, "RawData",
strlen("RawData")) < 0)
return dpiTestCase_setFailedFromError(testCase);

// cleanup
for (i = 0; i < numAttrs; i++) {
Expand Down
3 changes: 2 additions & 1 deletion test/sql/SetupTest.sql
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ create type &main_user..udt_ObjectDataTypes as object (
TimestampLTZCol timestamp with local time zone,
BinaryFltCol binary_float,
BinaryDoubleCol binary_double,
SignedIntCol integer
SignedIntCol integer,
RawCol raw(16)
);
/

Expand Down