Skip to content

Commit 234540e

Browse files
committed
Correct handling of collection values that are dates
1 parent 623939f commit 234540e

File tree

1 file changed

+33
-22
lines changed

1 file changed

+33
-22
lines changed

src/njsDbObject.c

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ static bool njsDbObject_validateArgs(napi_env env, napi_callback_info info,
101101
static bool njsDbObjectType_populate(njsDbObjectType *objType,
102102
dpiObjectType *objectTypeHandle, napi_env env, napi_value jsObjectType,
103103
dpiObjectTypeInfo *info, njsBaton *baton);
104+
static bool njsDbObjectType_populateTypeInfo(njsDataTypeInfo *info,
105+
njsBaton *baton, napi_env env, dpiDataTypeInfo *sourceInfo);
104106
static bool njsDbObject_wrap(napi_env env, napi_value value,
105107
njsDbObject **obj);
106108

@@ -1194,13 +1196,8 @@ static bool njsDbObjectType_populate(njsDbObjectType *objType,
11941196

11951197
// process collections object types
11961198
if (info->isCollection) {
1197-
objType->elementTypeInfo.oracleTypeNum =
1198-
info->elementTypeInfo.oracleTypeNum;
1199-
objType->elementTypeInfo.nativeTypeNum =
1200-
info->elementTypeInfo.defaultNativeTypeNum;
1201-
if (info->elementTypeInfo.objectType && !njsDbObject_getSubClass(baton,
1202-
info->elementTypeInfo.objectType, env, &temp,
1203-
&objType->elementTypeInfo.objectType))
1199+
if (!njsDbObjectType_populateTypeInfo(&objType->elementTypeInfo,
1200+
baton, env, &info->elementTypeInfo))
12041201
return false;
12051202
if (!njsUtils_addTypeProperties(env, jsObjectType, "elementType",
12061203
info->elementTypeInfo.oracleTypeNum,
@@ -1219,24 +1216,12 @@ static bool njsDbObjectType_populate(njsDbObjectType *objType,
12191216
if (dpiObjectAttr_getInfo(attr->handle, &attrInfo) < 0)
12201217
return njsBaton_setErrorDPI(baton);
12211218
attr->oracleDb = baton->oracleDb;
1222-
attr->typeInfo.oracleTypeNum = attrInfo.typeInfo.oracleTypeNum;
1223-
attr->typeInfo.nativeTypeNum =
1224-
attrInfo.typeInfo.defaultNativeTypeNum;
1219+
if (!njsDbObjectType_populateTypeInfo(&attr->typeInfo,
1220+
baton, env, &attrInfo.typeInfo))
1221+
return false;
12251222
attr->name = attrInfo.name;
12261223
attr->nameLength = attrInfo.nameLength;
1227-
if (attrInfo.typeInfo.oracleTypeNum == DPI_ORACLE_TYPE_TIMESTAMP ||
1228-
attrInfo.typeInfo.oracleTypeNum == DPI_ORACLE_TYPE_DATE ||
1229-
attrInfo.typeInfo.oracleTypeNum ==
1230-
DPI_ORACLE_TYPE_TIMESTAMP_TZ ||
1231-
attrInfo.typeInfo.oracleTypeNum ==
1232-
DPI_ORACLE_TYPE_TIMESTAMP_LTZ) {
1233-
attr->typeInfo.nativeTypeNum = DPI_NATIVE_TYPE_DOUBLE;
1234-
}
12351224
NJS_CHECK_NAPI(env, napi_create_object(env, &element))
1236-
if (attrInfo.typeInfo.objectType && !njsDbObject_getSubClass(baton,
1237-
attrInfo.typeInfo.objectType, env, &temp,
1238-
&attr->typeInfo.objectType))
1239-
return false;
12401225
if (!njsUtils_addTypeProperties(env, element, "type",
12411226
attrInfo.typeInfo.oracleTypeNum,
12421227
attr->typeInfo.objectType))
@@ -1279,3 +1264,29 @@ static bool njsDbObjectType_populate(njsDbObjectType *objType,
12791264

12801265
return true;
12811266
}
1267+
1268+
1269+
//-----------------------------------------------------------------------------
1270+
// njsDbObjectType_populateTypeInfo()
1271+
// Populates type information. Acquires the object type, if needed. Modifies
1272+
// the native type to double for all dates.
1273+
//-----------------------------------------------------------------------------
1274+
static bool njsDbObjectType_populateTypeInfo(njsDataTypeInfo *info,
1275+
njsBaton *baton, napi_env env, dpiDataTypeInfo *sourceInfo)
1276+
{
1277+
napi_value temp;
1278+
1279+
info->oracleTypeNum = sourceInfo->oracleTypeNum;
1280+
info->nativeTypeNum = sourceInfo->defaultNativeTypeNum;
1281+
if (info->oracleTypeNum == DPI_ORACLE_TYPE_DATE ||
1282+
info->oracleTypeNum == DPI_ORACLE_TYPE_TIMESTAMP ||
1283+
info->oracleTypeNum == DPI_ORACLE_TYPE_TIMESTAMP_TZ ||
1284+
info->oracleTypeNum == DPI_ORACLE_TYPE_TIMESTAMP_LTZ) {
1285+
info->nativeTypeNum = DPI_NATIVE_TYPE_DOUBLE;
1286+
}
1287+
if (sourceInfo->objectType) {
1288+
return njsDbObject_getSubClass(baton, sourceInfo->objectType, env,
1289+
&temp, &info->objectType);
1290+
}
1291+
return true;
1292+
}

0 commit comments

Comments
 (0)