1- // Copyright (c) 2019, 2023 , Oracle and/or its affiliates.
1+ // Copyright (c) 2019, 2025 , Oracle and/or its affiliates.
22
33//-----------------------------------------------------------------------------
44//
@@ -204,8 +204,14 @@ NJS_NAPI_METHOD_IMPL_SYNC(njsDbObject_getAttrValue, 1, &njsClassDefDbObject)
204204 njsDbObject * obj = (njsDbObject * ) callingInstance ;
205205 njsDbObjectAttr * attr ;
206206 dpiData data ;
207+ char numberAsString [200 ];
207208
208209 NJS_CHECK_NAPI (env , napi_unwrap (env , args [0 ], (void * * ) & attr ))
210+ if (attr -> typeInfo .oracleTypeNum == DPI_ORACLE_TYPE_NUMBER ) {
211+ data .value .asBytes .ptr = numberAsString ;
212+ data .value .asBytes .length = sizeof (numberAsString );
213+ data .value .asBytes .encoding = NULL ;
214+ }
209215 if (dpiObject_getAttributeValue (obj -> handle , attr -> handle ,
210216 attr -> typeInfo .nativeTypeNum , & data ) < 0 )
211217 return njsUtils_throwErrorDPI (env , globals );
@@ -223,8 +229,14 @@ NJS_NAPI_METHOD_IMPL_SYNC(njsDbObject_getElement, 1, &njsClassDefDbObject)
223229 njsDbObject * obj = (njsDbObject * ) callingInstance ;
224230 int32_t index ;
225231 dpiData data ;
232+ char numberAsString [200 ];
226233
227234 NJS_CHECK_NAPI (env , napi_get_value_int32 (env , args [0 ], & index ))
235+ if (obj -> type -> elementTypeInfo .oracleTypeNum == DPI_ORACLE_TYPE_NUMBER ) {
236+ data .value .asBytes .ptr = numberAsString ;
237+ data .value .asBytes .length = sizeof (numberAsString );
238+ data .value .asBytes .encoding = NULL ;
239+ }
228240 if (dpiObject_getElementValueByIndex (obj -> handle , index ,
229241 obj -> type -> elementTypeInfo .nativeTypeNum , & data ) < 0 )
230242 return njsUtils_throwErrorDPI (env , globals );
@@ -459,6 +471,7 @@ NJS_NAPI_METHOD_IMPL_SYNC(njsDbObject_getValues, 0, &njsClassDefDbObject)
459471 uint32_t arrayPos ;
460472 napi_value temp ;
461473 dpiData data ;
474+ char numberAsString [200 ];
462475
463476 // determine the size of the collection and create an array of that length
464477 if (dpiObject_getSize (obj -> handle , & size ) < 0 )
@@ -471,6 +484,11 @@ NJS_NAPI_METHOD_IMPL_SYNC(njsDbObject_getValues, 0, &njsClassDefDbObject)
471484 if (dpiObject_getFirstIndex (obj -> handle , & index , & exists ) < 0 )
472485 return njsUtils_throwErrorDPI (env , globals );
473486 while (exists ) {
487+ if (obj -> type -> elementTypeInfo .oracleTypeNum == DPI_ORACLE_TYPE_NUMBER ) {
488+ data .value .asBytes .ptr = numberAsString ;
489+ data .value .asBytes .length = sizeof (numberAsString );
490+ data .value .asBytes .encoding = NULL ;
491+ }
474492 if (dpiObject_getElementValueByIndex (obj -> handle , index ,
475493 obj -> type -> elementTypeInfo .nativeTypeNum , & data ) < 0 )
476494 return njsUtils_throwErrorDPI (env , globals );
@@ -627,6 +645,7 @@ static bool njsDbObject_transformFromOracle(njsDbObject *obj, napi_env env,
627645 case DPI_ORACLE_TYPE_NCHAR :
628646 case DPI_ORACLE_TYPE_VARCHAR :
629647 case DPI_ORACLE_TYPE_NVARCHAR :
648+ case DPI_ORACLE_TYPE_NUMBER :
630649 NJS_CHECK_NAPI (env , napi_create_string_utf8 (env ,
631650 data -> value .asBytes .ptr , data -> value .asBytes .length ,
632651 value ))
@@ -636,15 +655,6 @@ static bool njsDbObject_transformFromOracle(njsDbObject *obj, napi_env env,
636655 data -> value .asBytes .length , data -> value .asBytes .ptr , NULL ,
637656 value ))
638657 return true;
639- case DPI_ORACLE_TYPE_NUMBER :
640- if (typeInfo -> nativeTypeNum == DPI_NATIVE_TYPE_INT64 ) {
641- NJS_CHECK_NAPI (env , napi_create_int64 (env , data -> value .asInt64 ,
642- value ))
643- } else {
644- NJS_CHECK_NAPI (env , napi_create_double (env ,
645- data -> value .asDouble , value ))
646- }
647- return true;
648658 case DPI_ORACLE_TYPE_NATIVE_INT :
649659 NJS_CHECK_NAPI (env , napi_create_int64 (env , data -> value .asInt64 ,
650660 value ))
@@ -712,6 +722,7 @@ static bool njsDbObject_transformToOracle(njsDbObject *obj, napi_env env,
712722 njsDbObjectAttr * attr , njsModuleGlobals * globals )
713723{
714724 napi_value constructor , getComponentsFn ;
725+ napi_value numStr ;
715726 napi_valuetype valueType ;
716727 njsDbObject * valueObj ;
717728 bool check , tempBool ;
@@ -738,8 +749,19 @@ static bool njsDbObject_transformToOracle(njsDbObject *obj, napi_env env,
738749 dpiData_setBytes (data , * strBuffer , (uint32_t ) length );
739750 return true;
740751
741- // numbers are handled as doubles in JavaScript
752+ // numbers are handled as doubles in JavaScript.
753+ // If property type is NUMBER, we write string.
742754 case napi_number :
755+ case napi_bigint :
756+ if (oracleTypeNum == DPI_ORACLE_TYPE_NUMBER ) {
757+ // Write to NUMBER/ INTEGER properties astring.
758+ NJS_CHECK_NAPI (env , napi_coerce_to_string (env , value , & numStr ))
759+ if (!njsUtils_copyStringFromJS (env , numStr , strBuffer , & length ))
760+ return false;
761+ * nativeTypeNum = DPI_NATIVE_TYPE_BYTES ;
762+ dpiData_setBytes (data , * strBuffer , (uint32_t )length );
763+ return true;
764+ }
743765 NJS_CHECK_NAPI (env , napi_get_value_double (env , value ,
744766 & data -> value .asDouble ));
745767 * nativeTypeNum = DPI_NATIVE_TYPE_DOUBLE ;
@@ -1033,7 +1055,13 @@ static bool njsDbObjectType_populateTypeInfo(njsDataTypeInfo *info,
10331055 napi_value temp ;
10341056
10351057 info -> oracleTypeNum = sourceInfo -> oracleTypeNum ;
1036- info -> nativeTypeNum = sourceInfo -> defaultNativeTypeNum ;
1058+ if (sourceInfo -> oracleTypeNum == DPI_ORACLE_TYPE_NUMBER ) {
1059+ // For NUMBER property, we want to retrieve always as
1060+ // DPI_NATIVE_TYPE_BYTES not DPI_NATIVE_TYPE_DOUBLE.
1061+ info -> nativeTypeNum = DPI_NATIVE_TYPE_BYTES ;
1062+ } else {
1063+ info -> nativeTypeNum = sourceInfo -> defaultNativeTypeNum ;
1064+ }
10371065 info -> precision = sourceInfo -> precision ;
10381066 info -> scale = sourceInfo -> scale ;
10391067 info -> dbSizeInBytes = sourceInfo -> dbSizeInBytes ;
0 commit comments