Skip to content

Commit

Permalink
Remove array support from OutParam
Browse files Browse the repository at this point in the history
  • Loading branch information
ValYouW committed Mar 1, 2014
1 parent 578e4aa commit 34f50e7
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 124 deletions.
115 changes: 0 additions & 115 deletions src/outParam.cpp
Expand Up @@ -60,12 +60,6 @@ uni::CallbackType OutParam::New(const uni::FunctionCallbackInfo& args) {
OBJ_GET_STRING(opts, "in", outParam->_inOut.stringVal);
break;
}
case OutParam::OCCIVECTOR: {
uni::CallbackType ret = OutParam::GetVectorParam(opts, outParam);
if (!ret->IsNull())
return ret;
break;
}
default:
UNI_THROW(Exception::Error(String::New("Unhandled OutPram type!")));
}
Expand All @@ -82,19 +76,6 @@ OutParam::OutParam() {
}

OutParam::~OutParam() {
if (_inOut.collectionValues != NULL) {
// This can be either a char* or int*
if (_inOut.elemetnsType == oracle::occi::OCCIINT)
delete (int*)(_inOut.collectionValues);
else if (_inOut.elemetnsType == oracle::occi::OCCI_SQLT_STR)
delete (char*)(_inOut.collectionValues);
}

if (_inOut.elementLength != 0)
delete _inOut.elementLength;

if (_inOut.stringVal != NULL)
delete _inOut.stringVal;
}

int OutParam::type() {
Expand All @@ -104,99 +85,3 @@ int OutParam::type() {
int OutParam::size() {
return _size;
}

uni::CallbackType OutParam::GetVectorParam(Local<Object> opts, OutParam* outParam) {
// Get the array
Local<Value> val = opts->Get(String::New("in"));
if (!val->IsArray())
UNI_THROW(Exception::Error(String::New("OutParam::OCCIVECTOR must include array object as 'in' property")));

Local<Array> arr = Local<Array>::Cast(val);

if (arr->Length() < 1) {
outParam->_inOut.collectionLength = arr->Length();
outParam->_inOut.collectionValues = new int[0];
outParam->_inOut.elementsSize = 0;
outParam->_inOut.elementLength = new ub2[0];
return v8::Null();
}


// Get the vector's elements type if specified, default is int.
int type;
OBJ_GET_NUMBER(opts, "type", type, OutParam::OCCIINT);

switch(type) {
// Here we create the array buffer that will be used later as the value for the param on the sp statement (Connection::SetValuesOnStatement)
case OutParam::OCCISTRING: {
outParam->_inOut.elemetnsType = oracle::occi::OCCI_SQLT_STR;

// Find the longest string, this is necessary in order to create a buffer later.
// If "size" was provided by the user we use it as the size of the "longest string".
int longestString = 0;
if (opts->Has(String::New("size"))) {
longestString = outParam->_size;
} else {
// Loop thru all strings and save the length of the longest one.
for(unsigned int i = 0; i < arr->Length(); i++) {
Local<Value> val = arr->Get(i);
if (val->ToString()->Utf8Length() > longestString)
longestString = val->ToString()->Utf8Length();
}
}

// Add 1 for '\0'
++longestString;

// Create a long char* that will hold the entire array, it is important to create a FIXED SIZE array,
// meaning all strings have the same allocated length.
char* strArr = new char[arr->Length() * longestString];
outParam->_inOut.elementLength = new ub2[arr->Length()];

// loop thru the arr and copy the strings into the strArr
int bytesWritten = 0;
for(unsigned int i = 0; i < arr->Length(); i++) {
Local<Value> val = arr->Get(i);
if(!val->IsString())
UNI_THROW(Exception::Error(String::New("OutParam::OCCIVECTOR of type OCCISTRING must include string types only")));

String::Utf8Value utfStr(val);

// Copy this string onto the strArr (we put \0 in the beginning as this is what strcat expects).
strArr[bytesWritten] = '\0';
strncat(strArr + bytesWritten, *utfStr, longestString);
bytesWritten += longestString;

// Set the length of this element, add +1 for the '\0'
outParam->_inOut.elementLength[i] = utfStr.length() + 1;
}

outParam->_inOut.collectionValues = strArr;
outParam->_inOut.collectionLength = arr->Length();
outParam->_inOut.elementsSize = longestString;
break;
}
case OutParam::OCCIINT: {
// Allocate memory and copy the ints.
int* intArr = new int[arr->Length()];
for(unsigned int i = 0; i < arr->Length(); i++) {
Local<Value> val = arr->Get(i);
if(!val->IsInt32()) {
UNI_THROW(Exception::Error(String::New("OutParam::OCCIVECTOR of type OCCIINT must include integer types only")));
}

intArr[i] = val->ToInt32()->Value();
}

outParam->_inOut.collectionValues = intArr;
outParam->_inOut.collectionLength = arr->Length();
outParam->_inOut.elementsSize = sizeof(int32_t);
outParam->_inOut.elemetnsType = oracle::occi::OCCIINT;
break;
}
default:
UNI_THROW(Exception::Error(String::New("OutParam::OCCIVECTOR unsupported `type`, only supports OCCIINT and OCCISTRING")));
}

return v8::Null();
}
9 changes: 0 additions & 9 deletions src/outParam.h
Expand Up @@ -22,13 +22,6 @@ struct inout_t {
oracle::occi::Date dateVal;
oracle::occi::Timestamp timestampVal;
oracle::occi::Number numberVal;

// This will hold the info needed for binding vectors values
void* collectionValues;
ub4 collectionLength;
sb4 elementsSize; // The size of each element in the array
ub2* elementLength; // An array that holds the actual length of each element in the array (in case of strings)
oracle::occi::Type elemetnsType;
};

class OutParam : public ObjectWrap {
Expand All @@ -54,10 +47,8 @@ class OutParam : public ObjectWrap {
static const int OCCITIMESTAMP = 7;
static const int OCCINUMBER = 8;
static const int OCCIBLOB = 9;
static const int OCCIVECTOR = 10;

private:
static uni::CallbackType GetVectorParam(Local<Object> opts, OutParam* outParam);
};

#endif

0 comments on commit 34f50e7

Please sign in to comment.