@@ -60,6 +60,93 @@ uni::CallbackType OutParam::New(const uni::FunctionCallbackInfo& args) {
6060 OBJ_GET_STRING (opts, " in" , outParam->_inOut .stringVal );
6161 break ;
6262 }
63+ case OutParam::OCCIVECTOR: {
64+ // Get the vector's elements type
65+ Local<Value> valType = opts->Get (String::New (" type" ));
66+ if (valType->IsUndefined () || valType->IsNull ())
67+ UNI_THROW (Exception::Error (String::New (" OutParam::OCCIVECTOR missing `type` property" )));
68+
69+ // Create the collection according to the elem type.
70+ int type = valType->ToInt32 ()->Value ();
71+ switch (type) {
72+ // Here we create the array buffer that will be used later as the value for the param on the sp statement (Connection::SetValuesOnStatement)
73+ case OutParam::OCCISTRING: {
74+ outParam->_inOut .elemetnsType = oracle::occi::OCCI_SQLT_STR;
75+
76+ // Get the array
77+ Local<Array> arr = Local<Array>::Cast (opts->Get (String::New (" in" )));
78+
79+ // Find the longest string, this is necessary in order to create a buffer later.
80+ // If "size" was provided by the user we use it as the size of the "longest string", otherwise we would look for it.
81+ int longestString = 0 ;
82+ if (opts->Has (String::New (" in" ))) {
83+ longestString = outParam->_size ;
84+ } else {
85+ for (unsigned int i = 0 ; i < arr->Length (); i++) {
86+ Local<Value> val = arr->Get (i);
87+ if (val->ToString ()->Utf8Length () > longestString)
88+ longestString = val->ToString ()->Utf8Length ();
89+ }
90+ }
91+
92+ // Add 1 for '\0'
93+ ++longestString;
94+
95+ // Create a long char* that will hold the entire array, it is important to create a FIXED SIZE array,
96+ // meaning all strings have the same allocated length.
97+ char * strArr = new char [arr->Length () * longestString];
98+ outParam->_inOut .elementLength = new ub2[arr->Length ()];
99+
100+ // loop thru the arr and copy the strings into the strArr
101+ int bytesWritten = 0 ;
102+ for (unsigned int i = 0 ; i < arr->Length (); i++) {
103+ Local<Value> val = arr->Get (i);
104+ if (!val->IsString ()) {
105+ UNI_THROW (Exception::Error (String::New (" OutParam::OCCIVECTOR of type OCCISTRING must include string types only" )));
106+ }
107+
108+ String::Utf8Value utfStr (val);
109+
110+ // Copy this string onto the strArr (we put \0 in the beginning as this is what strcat expects).
111+ strArr[bytesWritten] = ' \0 ' ;
112+ strncat (strArr + bytesWritten, *utfStr, longestString);
113+ bytesWritten += longestString;
114+
115+ // Set the length of this element, add +1 for the '\0'
116+ outParam->_inOut .elementLength [i] = utfStr.length () + 1 ;
117+ }
118+
119+ outParam->_inOut .collectionValues = strArr;
120+ outParam->_inOut .collectionLength = arr->Length ();
121+ outParam->_inOut .elementsSize = longestString;
122+ break ;
123+ }
124+ case OutParam::OCCIINT: {
125+ Local<Array> arr = Local<Array>::Cast ( opts->Get (String::New (" in" )));
126+
127+ // Allocate memory and copy the ints.
128+ int * intArr = new int [arr->Length ()];
129+ for (unsigned int i = 0 ; i < arr->Length (); i++) {
130+ Local<Value> val = arr->Get (i);
131+ if (!val->IsInt32 ()) {
132+ UNI_THROW (Exception::Error (String::New (" OutParam::OCCIVECTOR of type OCCIINT must include integer types only" )));
133+ }
134+
135+ intArr[i] = val->ToInt32 ()->Value ();
136+ }
137+
138+ outParam->_inOut .collectionValues = intArr;
139+ outParam->_inOut .collectionLength = arr->Length ();
140+ outParam->_inOut .elementsSize = sizeof (int );
141+ outParam->_inOut .elemetnsType = oracle::occi::OCCIINT;
142+ break ;
143+ }
144+ default :
145+ UNI_THROW (Exception::Error (String::New (" OutParam::OCCIVECTOR unsupported `type`, only supports OCCIINT and OCCISTRING" )));
146+ }
147+ // End case:OCCIVECTOR
148+ break ;
149+ }
63150 default :
64151 UNI_THROW (Exception::Error (String::New (" Unhandled OutPram type!" )));
65152 }
@@ -76,6 +163,19 @@ OutParam::OutParam() {
76163}
77164
78165OutParam::~OutParam () {
166+ if (_inOut.collectionValues != NULL ) {
167+ // This can be either a char* or int*
168+ if (_inOut.elemetnsType == oracle::occi::OCCIINT)
169+ delete (int *)(_inOut.collectionValues );
170+ else if (_inOut.elemetnsType == oracle::occi::OCCI_SQLT_STR)
171+ delete (char *)(_inOut.collectionValues );
172+ }
173+
174+ if (_inOut.elementLength != 0 )
175+ delete _inOut.elementLength ;
176+
177+ if (_inOut.stringVal != NULL )
178+ delete _inOut.stringVal ;
79179}
80180
81181int OutParam::type () {
0 commit comments