Skip to content

Commit 7ad9fc0

Browse files
committed
[=] Move all assoc array param data from value_t to a new struct
1 parent d77988a commit 7ad9fc0

File tree

3 files changed

+35
-27
lines changed

3 files changed

+35
-27
lines changed

src/connection.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ int Connection::SetValuesOnStatement(oracle::occi::Statement* stmt, ExecuteBaton
205205
uint32_t index = 1;
206206
int outputParam = -1;
207207
OutParam * outParam = NULL;
208+
arrayParam_t* arrParam;
208209
for (vector<value_t*>::iterator iterator = values.begin(), end = values.end(); iterator != end; ++iterator, index++) {
209210
value_t* val = *iterator;
210211
int outParamType;
@@ -224,7 +225,8 @@ int Connection::SetValuesOnStatement(oracle::occi::Statement* stmt, ExecuteBaton
224225
break;
225226
case VALUE_TYPE_ARRAY:
226227
stmt->setDatabaseNCHARParam(index, true);
227-
stmt->setDataBufferArray(index, val->value, val->elemetnsType, val->collectionLength, &val->collectionLength, val->elementsSize, val->elementLength, NULL, NULL);
228+
arrParam = (arrayParam_t*)val->value;
229+
stmt->setDataBufferArray(index, arrParam->value, arrParam->elemetnsType, arrParam->collectionLength, &arrParam->collectionLength, arrParam->elementsSize, arrParam->elementLength, NULL, NULL);
228230
break;
229231
case VALUE_TYPE_OUTPUT:
230232
outParam = static_cast<OutParam*>(val->value);

src/executeBaton.cpp

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,16 @@ void ExecuteBaton::ResetValues() {
4646
delete (oracle::occi::Timestamp*)val->value;
4747
break;
4848
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;
49+
arrayParam_t* arrParam = (arrayParam_t*)val->value;
50+
if (arrParam->value != NULL && arrParam->elemetnsType == oracle::occi::OCCI_SQLT_STR)
51+
delete (char*)arrParam->value;
52+
else if (arrParam->value != NULL && arrParam->elemetnsType == oracle::occi::OCCI_SQLT_NUM)
53+
delete (char*)arrParam->value;
5354

54-
if (val->elementLength != NULL)
55-
delete val->elementLength;
55+
if (arrParam->elementLength != NULL)
56+
delete arrParam->elementLength;
5657

58+
delete (arrayParam_t*)val->value;
5759
break;
5860
}
5961
delete val;
@@ -150,7 +152,8 @@ void ExecuteBaton::CopyValuesToBaton(ExecuteBaton* baton, v8::Local<v8::Array>*
150152
else if (val->IsArray()) {
151153
value->type = VALUE_TYPE_ARRAY;
152154
Local<Array> arr = Local<Array>::Cast(val);
153-
GetVectorParam(baton, value, arr);
155+
value->value = new arrayParam_t();
156+
GetVectorParam(baton, (arrayParam_t*)value->value, arr);
154157
baton->values.push_back(value);
155158
}
156159

@@ -182,14 +185,14 @@ void ExecuteBaton::CopyValuesToBaton(ExecuteBaton* baton, v8::Local<v8::Array>*
182185
}
183186
}
184187

185-
void ExecuteBaton::GetVectorParam(ExecuteBaton* baton, value_t *value, Local<Array> arr) {
188+
void ExecuteBaton::GetVectorParam(ExecuteBaton* baton, arrayParam_t* arrParam, Local<Array> arr) {
186189
// In case the array is empty just initialize the fields as we would need something in Connection::SetValuesOnStatement
187190
if (arr->Length() < 1) {
188-
value->value = new int[0];
189-
value->collectionLength = 0;
190-
value->elementsSize = 0;
191-
value->elementLength = new ub2[0];
192-
value->elemetnsType = oracle::occi::OCCIINT;
191+
arrParam->value = new int[0];
192+
arrParam->collectionLength = 0;
193+
arrParam->elementsSize = 0;
194+
arrParam->elementLength = new ub2[0];
195+
arrParam->elemetnsType = oracle::occi::OCCIINT;
193196
return;
194197
}
195198

@@ -199,7 +202,7 @@ void ExecuteBaton::GetVectorParam(ExecuteBaton* baton, value_t *value, Local<Arr
199202

200203
// String array
201204
if (val->IsString()) {
202-
value->elemetnsType = oracle::occi::OCCI_SQLT_STR;
205+
arrParam->elemetnsType = oracle::occi::OCCI_SQLT_STR;
203206

204207
// Find the longest string, this is necessary in order to create a buffer later.
205208
int longestString = 0;
@@ -215,7 +218,7 @@ void ExecuteBaton::GetVectorParam(ExecuteBaton* baton, value_t *value, Local<Arr
215218
// Create a long char* that will hold the entire array, it is important to create a FIXED SIZE array,
216219
// meaning all strings have the same allocated length.
217220
char* strArr = new char[arr->Length() * longestString];
218-
value->elementLength = new ub2[arr->Length()];
221+
arrParam->elementLength = new ub2[arr->Length()];
219222

220223
// loop thru the arr and copy the strings into the strArr
221224
int bytesWritten = 0;
@@ -236,21 +239,21 @@ void ExecuteBaton::GetVectorParam(ExecuteBaton* baton, value_t *value, Local<Arr
236239
bytesWritten += longestString;
237240

238241
// Set the length of this element, add +1 for the '\0'
239-
value->elementLength[i] = utfStr.length() + 1;
242+
arrParam->elementLength[i] = utfStr.length() + 1;
240243
}
241244

242-
value->value = strArr;
243-
value->collectionLength = arr->Length();
244-
value->elementsSize = longestString;
245+
arrParam->value = strArr;
246+
arrParam->collectionLength = arr->Length();
247+
arrParam->elementsSize = longestString;
245248
}
246249

247250
// Integer array.
248251
else if (val->IsNumber()) {
249-
value->elemetnsType = oracle::occi::OCCI_SQLT_NUM;
252+
arrParam->elemetnsType = oracle::occi::OCCI_SQLT_NUM;
250253

251254
// Allocate memory for the numbers array, Number in Oracle is 21 bytes
252255
unsigned char* numArr = new unsigned char[arr->Length() * 21];
253-
value->elementLength = new ub2[arr->Length()];
256+
arrParam->elementLength = new ub2[arr->Length()];
254257

255258
for(unsigned int i = 0; i < arr->Length(); i++) {
256259
Local<Value> currVal = arr->Get(i);
@@ -273,13 +276,13 @@ void ExecuteBaton::GetVectorParam(ExecuteBaton* baton, value_t *value, Local<Arr
273276
// Convert the JS number into Oracle Number and get its bytes representation
274277
oracle::occi::Number n = d;
275278
oracle::occi::Bytes b = n.toBytes();
276-
value->elementLength[i] = b.length ();
279+
arrParam->elementLength[i] = b.length ();
277280
b.getBytes(&numArr[i*21], b.length());
278281
}
279282

280-
value->value = numArr;
281-
value->collectionLength = arr->Length();
282-
value->elementsSize = 21;
283+
arrParam->value = numArr;
284+
arrParam->collectionLength = arr->Length();
285+
arrParam->elementsSize = 21;
283286
}
284287

285288
// Unsupported type

src/executeBaton.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,11 @@ struct row_t {
4040
struct value_t {
4141
int type;
4242
void* value;
43+
};
4344

45+
struct arrayParam_t {
4446
// This will hold the info needed for binding vectors values
47+
void* value;
4548
ub4 collectionLength;
4649
sb4 elementsSize; // The size of each element in the array
4750
ub2* elementLength; // An array that holds the actual length of each element in the array (in case of strings)
@@ -84,7 +87,7 @@ class ExecuteBaton {
8487
int updateCount;
8588

8689
static void CopyValuesToBaton(ExecuteBaton* baton, v8::Local<v8::Array>* values);
87-
static void GetVectorParam(ExecuteBaton* baton, value_t *value, v8::Local<v8::Array> arr);
90+
static void GetVectorParam(ExecuteBaton* baton, arrayParam_t *value, v8::Local<v8::Array> arr);
8891
};
8992

9093
#endif

0 commit comments

Comments
 (0)