@@ -275,76 +275,91 @@ NAN_METHOD(njsResultSet::GetRows)
275
275
276
276
277
277
// -----------------------------------------------------------------------------
278
- // njsResultSet::Async_GetRows()
279
- // Worker function for njsResultSet::GetRowsCommon() method.
278
+ // njsResultSet::GetRowsHelper()
279
+ // Get rows from the result set and return a boolean indicating if the
280
+ // fetch was successful or not.
280
281
// -----------------------------------------------------------------------------
281
- void njsResultSet::Async_GetRows (njsBaton *baton)
282
+ bool njsResultSet::GetRowsHelper (njsBaton *baton, int *moreRows )
282
283
{
283
- njsResultSet *resultSet = (njsResultSet*) baton->callingObj ;
284
284
uint32_t i, numRowsToFetch;
285
285
njsVariable *var;
286
- int moreRows;
287
286
288
287
// determine how many rows to fetch; use fetchArraySize unless it is less
289
288
// than maxRows (no need to waste memory!)
290
289
numRowsToFetch = baton->fetchArraySize ;
291
- if (resultSet ->maxRows > 0 && resultSet ->maxRows < numRowsToFetch)
292
- numRowsToFetch = resultSet ->maxRows ;
290
+ if (this ->maxRows > 0 && this ->maxRows < numRowsToFetch)
291
+ numRowsToFetch = this ->maxRows ;
293
292
294
293
// create ODPI-C variables and define them, if necessary
295
- for (i = 0 ; i < resultSet ->numQueryVars ; i++) {
296
- var = &resultSet ->queryVars [i];
294
+ for (i = 0 ; i < this ->numQueryVars ; i++) {
295
+ var = &this ->queryVars [i];
297
296
if (var->dpiVarHandle && var->maxArraySize >= numRowsToFetch)
298
297
continue ;
299
298
if (var->dpiVarHandle ) {
300
299
if (dpiVar_release (var->dpiVarHandle ) < 0 ) {
301
300
baton->GetDPIError ();
302
- return ;
301
+ return false ;
303
302
}
304
303
var->dpiVarHandle = NULL ;
305
304
}
306
- if (dpiConn_newVar (resultSet ->dpiConnHandle , var->varTypeNum ,
305
+ if (dpiConn_newVar (this ->dpiConnHandle , var->varTypeNum ,
307
306
var->nativeTypeNum , numRowsToFetch, var->maxSize , 1 , 0 , NULL ,
308
307
&var->dpiVarHandle , &var->dpiVarData ) < 0 ) {
309
308
baton->GetDPIError ();
310
- return ;
309
+ return false ;
311
310
}
312
311
var->maxArraySize = numRowsToFetch;
313
- if (dpiStmt_define (resultSet ->dpiStmtHandle , i + 1 ,
312
+ if (dpiStmt_define (this ->dpiStmtHandle , i + 1 ,
314
313
var->dpiVarHandle ) < 0 ) {
315
314
baton->GetDPIError ();
316
- return ;
315
+ return false ;
317
316
}
318
317
}
319
318
320
319
// set fetch array size as requested
321
- if (dpiStmt_setFetchArraySize (resultSet ->dpiStmtHandle ,
320
+ if (dpiStmt_setFetchArraySize (this ->dpiStmtHandle ,
322
321
numRowsToFetch) < 0 ) {
323
322
baton->GetDPIError ();
324
- return ;
323
+ return false ;
325
324
}
326
325
327
326
// perform fetch
328
- if (dpiStmt_fetchRows (resultSet ->dpiStmtHandle , numRowsToFetch,
329
- &baton->bufferRowIndex , &baton->rowsFetched , & moreRows) < 0 ) {
327
+ if (dpiStmt_fetchRows (this ->dpiStmtHandle , numRowsToFetch,
328
+ &baton->bufferRowIndex , &baton->rowsFetched , moreRows) < 0 ) {
330
329
baton->GetDPIError ();
331
- return ;
330
+ return false ;
332
331
}
333
332
334
333
// result sets that should be auto closed are closed if the result set
335
334
// is exhaused or the maximum number of rows has been fetched
336
- if (moreRows && resultSet ->maxRows > 0 ) {
337
- if (baton->rowsFetched == resultSet ->maxRows )
338
- moreRows = 0 ;
339
- else resultSet ->maxRows -= baton->rowsFetched ;
335
+ if (* moreRows && this ->maxRows > 0 ) {
336
+ if (baton->rowsFetched == this ->maxRows )
337
+ * moreRows = 0 ;
338
+ else this ->maxRows -= baton->rowsFetched ;
340
339
}
341
- if (!moreRows && resultSet->autoClose ) {
340
+ return njsConnection::ProcessVars (baton, this ->queryVars ,
341
+ this ->numQueryVars , baton->rowsFetched );
342
+ }
343
+
344
+
345
+ // -----------------------------------------------------------------------------
346
+ // njsResultSet::Async_GetRows()
347
+ // Worker function for njsResultSet::GetRows() method.
348
+ // -----------------------------------------------------------------------------
349
+ void njsResultSet::Async_GetRows (njsBaton *baton)
350
+ {
351
+ njsResultSet *resultSet = (njsResultSet*) baton->callingObj ;
352
+ int moreRows;
353
+ bool success;
354
+
355
+ // result sets that should be auto closed are closed if the result set
356
+ // is exhaused or the maximum number of rows has been fetched or an error
357
+ // has taken place
358
+ success = resultSet->GetRowsHelper (baton, &moreRows);
359
+ if ((!success || !moreRows) && resultSet->autoClose ) {
342
360
dpiStmt_release (resultSet->dpiStmtHandle );
343
361
resultSet->dpiStmtHandle = NULL ;
344
362
}
345
-
346
- njsConnection::ProcessVars (baton, resultSet->queryVars ,
347
- resultSet->numQueryVars , baton->rowsFetched );
348
363
}
349
364
350
365
0 commit comments