Skip to content

Commit e9ede7e

Browse files
committed
Change number arrays to be of type OCCI_SQLT_NUM
1 parent ecc8b39 commit e9ede7e

File tree

2 files changed

+32
-28
lines changed

2 files changed

+32
-28
lines changed

src/connection.cpp

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -283,22 +283,6 @@ int Connection::SetValuesOnStatement(oracle::occi::Statement* stmt, ExecuteBaton
283283
case OutParam::OCCIBLOB:
284284
stmt->registerOutParam(index, oracle::occi::OCCIBLOB);
285285
break;
286-
case OutParam::OCCIVECTOR:
287-
// OCCIVECTOR is supported only as an IN param.
288-
if(!outParam->_inOut.hasInParam) {
289-
ostringstream oss;
290-
oss << "SetValuesOnStatement: Unknown OutParam type: " << outParamType;
291-
baton->error = new std::string(oss.str());
292-
return -2;
293-
}
294-
295-
//if (outParam->_inOut.collectionValues == NULL)
296-
//throw NodeOracleException("OutParam::OCCIVECTOR has empty collection");
297-
298-
stmt->setDatabaseNCHARParam(index, true);
299-
stmt->setDataBufferArray(index, outParam->_inOut.collectionValues, outParam->_inOut.elemetnsType, outParam->_inOut.collectionLength,
300-
&outParam->_inOut.collectionLength, outParam->_inOut.elementsSize, outParam->_inOut.elementLength, NULL, NULL);
301-
break;
302286
default:
303287
{
304288
ostringstream oss;
@@ -527,8 +511,6 @@ void Connection::ExecuteStatement(ExecuteBaton* baton, oracle::occi::Statement*
527511
break;
528512
case OutParam::OCCINUMBER:
529513
output->numberVal = stmt->getNumber(output->index);
530-
break;
531-
case OutParam::OCCIVECTOR:
532514
break;
533515
default:
534516
{
@@ -863,10 +845,6 @@ void Connection::handleResult(ExecuteBaton* baton, Handle<Value> (&argv)[2]) {
863845
case OutParam::OCCINUMBER:
864846
obj->Set(String::New(returnParam.c_str()), Number::New(output->numberVal));
865847
break;
866-
case OutParam::OCCIVECTOR:
867-
//in vector
868-
obj->Set(String::New(returnParam.c_str()), String::New("in OCCIVECTOR was here"));
869-
break;
870848
default:
871849
{
872850
ostringstream oss;

src/executeBaton.cpp

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)