1
- // Copyright (c) 2019, 2023 , Oracle and/or its affiliates.
1
+ // Copyright (c) 2019, 2025 , Oracle and/or its affiliates.
2
2
3
3
//-----------------------------------------------------------------------------
4
4
//
@@ -204,8 +204,14 @@ NJS_NAPI_METHOD_IMPL_SYNC(njsDbObject_getAttrValue, 1, &njsClassDefDbObject)
204
204
njsDbObject * obj = (njsDbObject * ) callingInstance ;
205
205
njsDbObjectAttr * attr ;
206
206
dpiData data ;
207
+ char numberAsString [200 ];
207
208
208
209
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
+ }
209
215
if (dpiObject_getAttributeValue (obj -> handle , attr -> handle ,
210
216
attr -> typeInfo .nativeTypeNum , & data ) < 0 )
211
217
return njsUtils_throwErrorDPI (env , globals );
@@ -223,8 +229,14 @@ NJS_NAPI_METHOD_IMPL_SYNC(njsDbObject_getElement, 1, &njsClassDefDbObject)
223
229
njsDbObject * obj = (njsDbObject * ) callingInstance ;
224
230
int32_t index ;
225
231
dpiData data ;
232
+ char numberAsString [200 ];
226
233
227
234
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
+ }
228
240
if (dpiObject_getElementValueByIndex (obj -> handle , index ,
229
241
obj -> type -> elementTypeInfo .nativeTypeNum , & data ) < 0 )
230
242
return njsUtils_throwErrorDPI (env , globals );
@@ -459,6 +471,7 @@ NJS_NAPI_METHOD_IMPL_SYNC(njsDbObject_getValues, 0, &njsClassDefDbObject)
459
471
uint32_t arrayPos ;
460
472
napi_value temp ;
461
473
dpiData data ;
474
+ char numberAsString [200 ];
462
475
463
476
// determine the size of the collection and create an array of that length
464
477
if (dpiObject_getSize (obj -> handle , & size ) < 0 )
@@ -471,6 +484,11 @@ NJS_NAPI_METHOD_IMPL_SYNC(njsDbObject_getValues, 0, &njsClassDefDbObject)
471
484
if (dpiObject_getFirstIndex (obj -> handle , & index , & exists ) < 0 )
472
485
return njsUtils_throwErrorDPI (env , globals );
473
486
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
+ }
474
492
if (dpiObject_getElementValueByIndex (obj -> handle , index ,
475
493
obj -> type -> elementTypeInfo .nativeTypeNum , & data ) < 0 )
476
494
return njsUtils_throwErrorDPI (env , globals );
@@ -627,6 +645,7 @@ static bool njsDbObject_transformFromOracle(njsDbObject *obj, napi_env env,
627
645
case DPI_ORACLE_TYPE_NCHAR :
628
646
case DPI_ORACLE_TYPE_VARCHAR :
629
647
case DPI_ORACLE_TYPE_NVARCHAR :
648
+ case DPI_ORACLE_TYPE_NUMBER :
630
649
NJS_CHECK_NAPI (env , napi_create_string_utf8 (env ,
631
650
data -> value .asBytes .ptr , data -> value .asBytes .length ,
632
651
value ))
@@ -636,15 +655,6 @@ static bool njsDbObject_transformFromOracle(njsDbObject *obj, napi_env env,
636
655
data -> value .asBytes .length , data -> value .asBytes .ptr , NULL ,
637
656
value ))
638
657
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;
648
658
case DPI_ORACLE_TYPE_NATIVE_INT :
649
659
NJS_CHECK_NAPI (env , napi_create_int64 (env , data -> value .asInt64 ,
650
660
value ))
@@ -712,6 +722,7 @@ static bool njsDbObject_transformToOracle(njsDbObject *obj, napi_env env,
712
722
njsDbObjectAttr * attr , njsModuleGlobals * globals )
713
723
{
714
724
napi_value constructor , getComponentsFn ;
725
+ napi_value numStr ;
715
726
napi_valuetype valueType ;
716
727
njsDbObject * valueObj ;
717
728
bool check , tempBool ;
@@ -738,8 +749,19 @@ static bool njsDbObject_transformToOracle(njsDbObject *obj, napi_env env,
738
749
dpiData_setBytes (data , * strBuffer , (uint32_t ) length );
739
750
return true;
740
751
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.
742
754
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
+ }
743
765
NJS_CHECK_NAPI (env , napi_get_value_double (env , value ,
744
766
& data -> value .asDouble ));
745
767
* nativeTypeNum = DPI_NATIVE_TYPE_DOUBLE ;
@@ -1033,7 +1055,13 @@ static bool njsDbObjectType_populateTypeInfo(njsDataTypeInfo *info,
1033
1055
napi_value temp ;
1034
1056
1035
1057
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
+ }
1037
1065
info -> precision = sourceInfo -> precision ;
1038
1066
info -> scale = sourceInfo -> scale ;
1039
1067
info -> dbSizeInBytes = sourceInfo -> dbSizeInBytes ;
0 commit comments