18
18
* This file uses NAN:
19
19
*
20
20
* Copyright (c) 2015 NAN contributors
21
- *
21
+ *
22
22
* NAN contributors listed at https://github.com/rvagg/nan#contributors
23
- *
23
+ *
24
24
* Permission is hereby granted, free of charge, to any person obtaining
25
25
* a copy of this software and associated documentation files (the
26
26
* "Software"), to deal in the Software without restriction, including
27
27
* without limitation the rights to use, copy, modify, merge, publish,
28
28
* distribute, sublicense, and/or sell copies of the Software, and to
29
29
* permit persons to whom the Software is furnished to do so, subject to
30
30
* the following conditions:
31
- *
31
+ *
32
32
* The above copyright notice and this permission notice shall be
33
33
* included in all copies or substantial portions of the Software.
34
- *
34
+ *
35
35
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
36
36
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
37
37
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
38
38
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
39
39
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
40
40
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
41
41
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
42
- *
42
+ *
43
43
* NAME
44
44
* njsResultSet.cpp
45
45
*
@@ -88,13 +88,13 @@ void ResultSet::setResultSet ( dpi::Stmt *stmt, dpi::Env *env,
88
88
*/
89
89
void ResultSet::Init (Handle<Object> target)
90
90
{
91
- NanScope ();
91
+ NanScope ();
92
92
Local<FunctionTemplate> temp = NanNew<FunctionTemplate>(New);
93
93
temp->InstanceTemplate ()->SetInternalFieldCount (1 );
94
94
temp->SetClassName (NanNew<v8::String>(" ResultSet" ));
95
95
96
96
NODE_SET_PROTOTYPE_METHOD (temp, " close" , Close);
97
- NODE_SET_PROTOTYPE_METHOD (temp, " getRow" , GetRows );
97
+ NODE_SET_PROTOTYPE_METHOD (temp, " getRow" , GetRow );
98
98
NODE_SET_PROTOTYPE_METHOD (temp, " getRows" , GetRows);
99
99
100
100
temp->InstanceTemplate ()->SetAccessor (
@@ -145,8 +145,8 @@ NAN_PROPERTY_GETTER(ResultSet::GetMetaData)
145
145
NanReturnUndefined ();
146
146
}
147
147
std::string *columnNames = new std::string[njsResultSet->numCols_ ];
148
- Connection::CopyMetaData ( columnNames, njsResultSet->meta_ ,
149
- njsResultSet->numCols_ );
148
+ Connection::CopyMetaData ( columnNames, njsResultSet->meta_ ,
149
+ njsResultSet->numCols_ );
150
150
Handle<Value> meta;
151
151
meta = Connection::GetMetaData ( columnNames,
152
152
njsResultSet->numCols_ );
@@ -173,13 +173,42 @@ NAN_SETTER(ResultSet::SetMetaData)
173
173
NJS_SET_EXCEPTION (msg.c_str (), (int ) msg.length ());
174
174
}
175
175
176
+ /* ****************************************************************************/
177
+ /*
178
+ DESCRIPTION
179
+ Get Row method on Result Set class.
180
+
181
+ PARAMETERS:
182
+ Arguments - callback
183
+ */
184
+ NAN_METHOD (ResultSet::GetRow)
185
+ {
186
+ NanScope ();
187
+
188
+ Local<Function> callback;
189
+ NJS_GET_CALLBACK ( callback, args );
190
+
191
+ ResultSet *njsResultSet = ObjectWrap::Unwrap<ResultSet>(args.This ());
192
+ rsBaton *getRowsBaton = new rsBaton ();
193
+ NanAssignPersistent (getRowsBaton->cb , callback );
194
+
195
+ NJS_CHECK_NUMBER_OF_ARGS ( getRowsBaton->error , args, 1 , 1 , exitGetRow );
196
+
197
+ getRowsBaton->numRows = 1 ;
198
+ getRowsBaton->njsRS = njsResultSet;
199
+
200
+ exitGetRow:
201
+ ResultSet::GetRowsCommon (getRowsBaton);
202
+ NanReturnUndefined ();
203
+ }
204
+
176
205
/* ****************************************************************************/
177
206
/*
178
207
DESCRIPTION
179
208
Get Rows method on Result Set class.
180
209
181
210
PARAMETERS:
182
- Arguments - Callback
211
+ Arguments - numRows, callback
183
212
*/
184
213
NAN_METHOD (ResultSet::GetRows)
185
214
{
@@ -189,55 +218,69 @@ NAN_METHOD(ResultSet::GetRows)
189
218
NJS_GET_CALLBACK ( callback, args );
190
219
191
220
ResultSet *njsResultSet = ObjectWrap::Unwrap<ResultSet>(args.This ());
192
- rsBaton *getRowsBaton = new rsBaton ();
221
+ rsBaton *getRowsBaton = new rsBaton ();
193
222
NanAssignPersistent (getRowsBaton->cb , callback );
194
223
195
- NJS_CHECK_NUMBER_OF_ARGS ( getRowsBaton->error , args, 1 , 2 , exitGetRows );
196
- if (args.Length () == 2 )
197
- {
198
- NJS_GET_ARG_V8UINT ( getRowsBaton->numRows , getRowsBaton->error ,
199
- args, 0 , exitGetRows );
200
- getRowsBaton->fetchMultiple = true ;
201
- }
202
- else
203
- {
204
- getRowsBaton->numRows = 1 ;
205
- }
224
+ NJS_CHECK_NUMBER_OF_ARGS ( getRowsBaton->error , args, 2 , 2 , exitGetRows );
225
+ NJS_GET_ARG_V8UINT ( getRowsBaton->numRows , getRowsBaton->error ,
226
+ args, 0 , exitGetRows );
227
+
228
+ getRowsBaton->fetchMultiple = true ;
229
+ getRowsBaton->njsRS = njsResultSet;
230
+ exitGetRows:
231
+ ResultSet::GetRowsCommon (getRowsBaton);
232
+ NanReturnUndefined ();
233
+ }
206
234
207
- getRowsBaton->njsRS = njsResultSet;
208
- getRowsBaton->ebaton = new eBaton;
235
+ /* ****************************************************************************/
236
+ /*
237
+ DESCRIPTION
238
+ Common method for GetRow and GetRows method
209
239
210
- if (!njsResultSet->njsconn_ ->isValid ())
240
+ PARAMETERS:
241
+ Arguments - resultset baton
242
+ */
243
+ void ResultSet::GetRowsCommon (rsBaton *getRowsBaton)
244
+ {
245
+ ResultSet *njsRS;
246
+ eBaton *ebaton;
247
+
248
+ if (!(getRowsBaton->error ).empty ()) goto exitGetRowsCommon;
249
+
250
+ if (!getRowsBaton->njsRS ->njsconn_ ->isValid ())
211
251
{
212
252
getRowsBaton->error = NJSMessages::getErrorMsg ( errInvalidConnection );
213
- goto exitGetRows ;
253
+ goto exitGetRowsCommon ;
214
254
}
215
- if (njsResultSet ->state_ == INVALID)
255
+ if (getRowsBaton-> njsRS ->state_ == INVALID)
216
256
{
217
257
getRowsBaton->error = NJSMessages::getErrorMsg ( errInvalidResultSet );
218
- goto exitGetRows ;
258
+ goto exitGetRowsCommon ;
219
259
}
220
- else if (njsResultSet ->state_ == ACTIVE)
260
+ else if (getRowsBaton-> njsRS ->state_ == ACTIVE)
221
261
{
222
262
getRowsBaton->error = NJSMessages::getErrorMsg ( errBusyResultSet );
223
- goto exitGetRows ;
263
+ goto exitGetRowsCommon ;
224
264
}
225
265
226
- njsResultSet->state_ = ACTIVE;
227
- getRowsBaton->ebaton ->columnNames = new std::string[njsResultSet->numCols_ ];
228
- getRowsBaton->ebaton ->maxRows = getRowsBaton->numRows ;
229
- getRowsBaton->ebaton ->dpistmt = njsResultSet->dpistmt_ ;
230
- getRowsBaton->ebaton ->dpienv = njsResultSet->dpienv_ ;
231
- getRowsBaton->ebaton ->getRS = true ;
232
- getRowsBaton->ebaton ->outFormat = njsResultSet->outFormat_ ;
266
+ getRowsBaton->ebaton = new eBaton;
267
+ ebaton = getRowsBaton->ebaton ;
268
+ njsRS = getRowsBaton->njsRS ;
233
269
234
- exitGetRows:
235
- getRowsBaton->req .data = (void *)getRowsBaton;
270
+ njsRS->state_ = ACTIVE;
271
+ ebaton->columnNames = new std::string[njsRS->numCols_ ];
272
+ ebaton->maxRows = getRowsBaton->numRows ;
273
+ ebaton->dpistmt = njsRS->dpistmt_ ;
274
+ ebaton->dpienv = njsRS->dpienv_ ;
275
+ ebaton->getRS = true ;
276
+ ebaton->outFormat = njsRS->outFormat_ ;
277
+
278
+ exitGetRowsCommon:
279
+ getRowsBaton->req .data = (void *)getRowsBaton;
236
280
237
281
uv_queue_work (uv_default_loop (), &getRowsBaton->req , Async_GetRows,
238
282
(uv_after_work_cb)Async_AfterGetRows);
239
283
240
- NanReturnUndefined ();
241
284
}
242
285
243
286
/* ****************************************************************************/
@@ -261,16 +304,16 @@ void ResultSet::Async_GetRows(uv_work_t *req)
261
304
262
305
if (njsRS->rsEmpty_ )
263
306
{
264
- ebaton->rowsFetched = 0 ;
307
+ ebaton->rowsFetched = 0 ;
265
308
goto exitAsyncGetRows;
266
309
}
267
310
268
311
try
269
312
{
270
- Connection::CopyMetaData ( ebaton->columnNames , njsRS->meta_ ,
313
+ Connection::CopyMetaData ( ebaton->columnNames , njsRS->meta_ ,
271
314
njsRS->numCols_ );
272
315
ebaton->numCols = njsRS->numCols_ ;
273
- if ( !njsRS->defineBuffers_ ||
316
+ if ( !njsRS->defineBuffers_ ||
274
317
njsRS->fetchRowCount_ < getRowsBaton->numRows )
275
318
{
276
319
if ( njsRS->defineBuffers_ )
@@ -284,7 +327,7 @@ void ResultSet::Async_GetRows(uv_work_t *req)
284
327
}
285
328
ebaton->defines = njsRS->defineBuffers_ ;
286
329
Connection::DoFetch (ebaton);
287
-
330
+
288
331
if (ebaton->rowsFetched != getRowsBaton->numRows )
289
332
njsRS->rsEmpty_ = true ;
290
333
}
@@ -324,11 +367,11 @@ void ResultSet::Async_AfterGetRows(uv_work_t *req)
324
367
getRowsBaton->njsRS ->state_ = INACTIVE;
325
368
eBaton* ebaton = getRowsBaton->ebaton ;
326
369
ebaton->outFormat = getRowsBaton->njsRS ->outFormat_ ;
327
- Handle<Value> rowsArray = NanNew<v8::Array>(0 ),
370
+ Handle<Value> rowsArray = NanNew<v8::Array>(0 ),
328
371
rowsArrayValue = NanNew (NanNull ());
329
372
330
373
if (ebaton->rowsFetched )
331
- {
374
+ {
332
375
rowsArray = Connection::GetRows (ebaton);
333
376
if (!(ebaton->error ).empty ())
334
377
{
@@ -338,7 +381,7 @@ void ResultSet::Async_AfterGetRows(uv_work_t *req)
338
381
}
339
382
rowsArrayValue = Handle<Array>::Cast (rowsArray)->Get (0 );
340
383
}
341
- argv[1 ] = (getRowsBaton->fetchMultiple ) ? rowsArray : rowsArrayValue;
384
+ argv[1 ] = (getRowsBaton->fetchMultiple ) ? rowsArray : rowsArrayValue;
342
385
}
343
386
344
387
exitAsyncAfterGetRows:
@@ -423,9 +466,11 @@ void ResultSet::Async_Close(uv_work_t *req)
423
466
424
467
Define* defineBuffers = closeBaton-> njsRS-> defineBuffers_;
425
468
unsigned int numCols = closeBaton-> njsRS-> numCols_;
426
-
427
- ResultSet::clearFetchBuffer (defineBuffers, numCols);
428
- closeBaton-> njsRS-> defineBuffers_ = NULL ;
469
+ if (defineBuffers)
470
+ {
471
+ ResultSet::clearFetchBuffer (defineBuffers, numCols);
472
+ closeBaton-> njsRS-> defineBuffers_ = NULL ;
473
+ }
429
474
}
430
475
catch (dpi::Exception& e)
431
476
{
@@ -474,24 +519,24 @@ void ResultSet::Async_AfterClose(uv_work_t *req)
474
519
/* ****************************************************************************/
475
520
/*
476
521
DESCRIPTION
477
- Free FetchBuffers
522
+ Free FetchBuffers
478
523
479
524
PARAMETERS:
480
- Fetch Buffer, numCols
525
+ Fetch Buffer, numCols
481
526
*/
482
527
void ResultSet::clearFetchBuffer ( Define* defineBuffers, unsigned int numCols)
483
528
{
484
529
for ( unsigned int i=0 ; i<numCols; i++ )
485
- {
530
+ {
486
531
if ( defineBuffers[i].dttmarr )
487
- {
488
- defineBuffers[i].dttmarr ->release ();
532
+ {
533
+ defineBuffers[i].dttmarr ->release ();
489
534
defineBuffers[i].extbuf = NULL ;
490
- }
535
+ }
491
536
free (defineBuffers[i].buf );
492
537
free (defineBuffers[i].len );
493
538
free (defineBuffers[i].ind );
494
- }
539
+ }
495
540
delete [] defineBuffers;
496
541
defineBuffers = NULL ;
497
542
}
0 commit comments