@@ -45,6 +45,16 @@ void ExecuteBaton::ResetValues() {
4545 case VALUE_TYPE_TIMESTAMP:
4646 delete (oracle::occi::Timestamp*)val->value ;
4747 break ;
48+ case VALUE_TYPE_ARRAY:
49+ if (val->value != NULL && val->elemetnsType == oracle::occi::OCCI_SQLT_STR)
50+ delete (char *)val->value ;
51+ else if (val->value != NULL && val->elemetnsType == oracle::occi::OCCI_SQLT_NUM)
52+ delete (char *)val->value ;
53+
54+ if (val->elementLength != NULL )
55+ delete val->elementLength ;
56+
57+ break ;
4858 }
4959 delete val;
5060 }
@@ -236,8 +246,12 @@ void ExecuteBaton::GetVectorParam(ExecuteBaton* baton, value_t *value, Local<Arr
236246
237247 // Integer array.
238248 else if (val->IsNumber ()) {
239- // Allocate memory and copy the ints.
240- double * intArr = new double [arr->Length ()];
249+ value->elemetnsType = oracle::occi::OCCI_SQLT_NUM;
250+
251+ // Allocate memory for the numbers array, Number in Oracle is 21 bytes
252+ unsigned char * numArr = new unsigned char [arr->Length () * 21 ];
253+ value->elementLength = new ub2[arr->Length ()];
254+
241255 for (unsigned int i = 0 ; i < arr->Length (); i++) {
242256 Local<Value> currVal = arr->Get (i);
243257 if (!currVal->IsNumber ()) {
@@ -247,13 +261,25 @@ void ExecuteBaton::GetVectorParam(ExecuteBaton* baton, value_t *value, Local<Arr
247261 return ;
248262 }
249263
250- intArr[i] = currVal->ToNumber ()->Value ();
264+ // JS numbers can exceed oracle numbers, make sure this is not the case.
265+ double d = currVal->ToNumber ()->Value ();
266+ if (d > 9.99999999999999999999999999999999999999 *std::pow (10 , 125 ) || d < -9.99999999999999999999999999999999999999 *std::pow (10 , 125 )) {
267+ std::ostringstream message;
268+ message << " Input array has number that is out of the range of Oracle numbers, check the number at index " << i;
269+ baton->error = new std::string (message.str ());
270+ return ;
271+ }
272+
273+ // Convert the JS number into Oracle Number and get its bytes representation
274+ oracle::occi::Number n = d;
275+ oracle::occi::Bytes b = n.toBytes ();
276+ value->elementLength [i] = b.length ();
277+ b.getBytes (&numArr[i*21 ], b.length ());
251278 }
252279
253- value->value = intArr ;
280+ value->value = numArr ;
254281 value->collectionLength = arr->Length ();
255- value->elementsSize = sizeof (double );
256- value->elemetnsType = oracle::occi::OCCIFLOAT;
282+ value->elementsSize = 21 ;
257283 }
258284
259285 // Unsupported type
0 commit comments