@@ -187,51 +187,80 @@ void Connection::EIO_Execute(eio_req* req) {
187
187
}
188
188
}
189
189
190
+ Local<Object> Connection::CreateV8ObjectFromRow (ExecuteBaton* baton, row_t * currentRow) {
191
+ Local<Object> obj = Object::New ();
192
+ uint32_t colIndex = 0 ;
193
+ for (std::vector<column_t *>::iterator iterator = baton->columns .begin (), end = baton->columns .end (); iterator != end; ++iterator, colIndex++) {
194
+ column_t * col = *iterator;
195
+ void * val = currentRow->values [colIndex];
196
+ switch (col->type ) {
197
+ case VALUE_TYPE_STRING:
198
+ {
199
+ std::string* v = (std::string*)val;
200
+ obj->Set (String::New (col->name .c_str ()), String::New (v->c_str ()));
201
+ delete v;
202
+ }
203
+ break ;
204
+ case VALUE_TYPE_NUMBER:
205
+ {
206
+ oracle::occi::Number* v = (oracle::occi::Number*)val;
207
+ obj->Set (String::New (col->name .c_str ()), Number::New ((double )(*v)));
208
+ delete v;
209
+ }
210
+ break ;
211
+ default :
212
+ std::ostringstream message;
213
+ message << " Unhandled type: " << col->type ;
214
+ throw NodeOracleException (message.str ());
215
+ break ;
216
+ }
217
+ }
218
+ return obj;
219
+ }
220
+
221
+ Local<Array> Connection::CreateV8ArrayFromRows (ExecuteBaton* baton) {
222
+ size_t totalRows = baton->rows ->size ();
223
+ Local<Array> rows = Array::New (totalRows);
224
+ uint32_t index = 0 ;
225
+ for (std::vector<row_t *>::iterator iterator = baton->rows ->begin (), end = baton->rows ->end (); iterator != end; ++iterator, index++) {
226
+ row_t * currentRow = *iterator;
227
+ Local<Object> obj = CreateV8ObjectFromRow (baton, currentRow);
228
+ rows->Set (index, obj);
229
+ }
230
+ return rows;
231
+ }
232
+
190
233
int Connection::EIO_AfterExecute (eio_req* req) {
191
234
ExecuteBaton* baton = static_cast <ExecuteBaton*>(req->data );
192
235
ev_unref (EV_DEFAULT_UC);
193
236
baton->connection ->Unref ();
194
237
195
- Handle<Value> argv[2 ];
196
- if (baton->error ) {
197
- argv[0 ] = Exception::Error (String::New (baton->error ->c_str ()));
198
- argv[1 ] = Undefined ();
199
- } else {
200
- argv[0 ] = Undefined ();
201
-
202
- if (baton->rows ) {
203
- size_t totalRows = baton->rows ->size ();
204
- Local<Array> rows = Array::New (totalRows);
205
- uint32_t index = 0 ;
206
- for (std::vector<row_t *>::iterator iterator = baton->rows ->begin (), end = baton->rows ->end (); iterator != end; ++iterator, index++) {
207
- row_t * currentRow = *iterator;
238
+ try {
239
+ Handle<Value> argv[2 ];
240
+ if (baton->error ) {
241
+ argv[0 ] = Exception::Error (String::New (baton->error ->c_str ()));
242
+ argv[1 ] = Undefined ();
243
+ } else {
244
+ argv[0 ] = Undefined ();
245
+ if (baton->rows ) {
246
+ argv[1 ] = CreateV8ArrayFromRows (baton);
247
+ } else {
208
248
Local<Object> obj = Object::New ();
209
- uint32_t colIndex = 0 ;
210
- for (std::vector<column_t *>::iterator iterator = baton->columns .begin (), end = baton->columns .end (); iterator != end; ++iterator, colIndex++) {
211
- column_t * col = *iterator;
212
- void * val = currentRow->values [colIndex];
213
- switch (col->type ) {
214
- case VALUE_TYPE_STRING:
215
- std::string* v = (std::string*)val;
216
- obj->Set (String::New (col->name .c_str ()), String::New (v->c_str ()));
217
- delete v;
218
- break ;
219
- }
249
+ obj->Set (String::New (" updateCount" ), Integer::New (baton->updateCount ));
250
+ if (baton->returnParam ) {
251
+ obj->Set (String::New (" returnParam" ), Integer::New (*baton->returnParam ));
252
+ delete baton->returnParam ;
220
253
}
221
- rows->Set (index, obj);
222
- }
223
- argv[1 ] = rows;
224
- } else {
225
- Local<Object> obj = Object::New ();
226
- obj->Set (String::New (" updateCount" ), Integer::New (baton->updateCount ));
227
- if (baton->returnParam ) {
228
- obj->Set (String::New (" returnParam" ), Integer::New (*baton->returnParam ));
229
- delete baton->returnParam ;
254
+ argv[1 ] = obj;
230
255
}
231
- argv[1 ] = obj;
232
256
}
257
+ baton->callback ->Call (Context::GetCurrent ()->Global (), 2 , argv);
258
+ } catch (NodeOracleException &ex) {
259
+ Handle<Value> argv[2 ];
260
+ argv[0 ] = Exception::Error (String::New (ex.getMessage ().c_str ()));
261
+ argv[1 ] = Undefined ();
262
+ baton->callback ->Call (Context::GetCurrent ()->Global (), 2 , argv);
233
263
}
234
- baton->callback ->Call (Context::GetCurrent ()->Global (), 2 , argv);
235
264
236
265
delete baton;
237
266
return 0 ;
0 commit comments