@@ -563,6 +563,13 @@ void Connection::ProcessOptions (Nan::NAN_METHOD_ARGS_TYPE args, unsigned int in
563
563
options = args[index]->ToObject ();
564
564
NJS_GET_UINT_FROM_JSON ( executeBaton->maxRows , executeBaton->error ,
565
565
options, " maxRows" , 2 , exitProcessOptions );
566
+
567
+ if ( executeBaton->maxRows <= 0 )
568
+ {
569
+ executeBaton->error = NJSMessages::getErrorMsg ( errInvalidmaxRows );
570
+ goto exitProcessOptions;
571
+ }
572
+
566
573
NJS_GET_UINT_FROM_JSON ( executeBaton->prefetchRows , executeBaton->error ,
567
574
options, " prefetchRows" , 2 , exitProcessOptions );
568
575
NJS_GET_UINT_FROM_JSON ( executeBaton->outFormat , executeBaton->error ,
@@ -1628,6 +1635,8 @@ void Connection::Async_Execute (uv_work_t *req)
1628
1635
1629
1636
Connection::CopyMetaData ( executeBaton->mInfo , executeBaton, mData ,
1630
1637
executeBaton->numCols );
1638
+ if ( !executeBaton->error .empty () )
1639
+ goto exitAsyncExecute;
1631
1640
1632
1641
if ( executeBaton->getRS )
1633
1642
{
@@ -1763,6 +1772,9 @@ void Connection::Async_Execute (uv_work_t *req)
1763
1772
}
1764
1773
Connection::CopyMetaData ( extBind->mInfo , executeBaton, mData ,
1765
1774
extBind->numCols );
1775
+ if ( !executeBaton->error .empty () )
1776
+ goto exitAsyncExecute;
1777
+
1766
1778
executeBaton->extBinds [ b ] = extBind;
1767
1779
}
1768
1780
else
@@ -1807,6 +1819,21 @@ void Connection::Async_Execute (uv_work_t *req)
1807
1819
{
1808
1820
executeBaton->dpistmt ->release ();
1809
1821
}
1822
+
1823
+ // In case of error, release the statement handles allocated (REF CURSOR)
1824
+ if ( !(executeBaton->error ).empty () )
1825
+ {
1826
+ for ( unsigned int index = 0 ;index < executeBaton->binds .size ();
1827
+ index++ )
1828
+ {
1829
+ if ( executeBaton->binds [index]->value &&
1830
+ ( executeBaton->binds [index]->type == DpiRSet ) )
1831
+ {
1832
+ ((Stmt*)executeBaton->binds [index]->value )->release ();
1833
+ executeBaton->binds [index]->value = NULL ;
1834
+ }
1835
+ }
1836
+ }
1810
1837
;
1811
1838
}
1812
1839
@@ -1961,7 +1988,9 @@ void Connection::CopyMetaData ( MetaInfo *mInfo,
1961
1988
const MetaData* mData ,
1962
1989
const unsigned int numCols )
1963
1990
{
1964
- for ( unsigned int col = 0 ; col < numCols; col++ )
1991
+ bool error = false ;
1992
+
1993
+ for ( unsigned int col = 0 ; !error && ( col < numCols ); col++ )
1965
1994
{
1966
1995
mInfo [col].name = string ( (const char *)mData [col].colName ,
1967
1996
mData [col].colNameLen );
@@ -2045,6 +2074,16 @@ void Connection::CopyMetaData ( MetaInfo *mInfo,
2045
2074
mInfo [col].dbType = NJS_DATATYPE_UNKNOWN;
2046
2075
break ;
2047
2076
}
2077
+
2078
+ if ( mInfo [col].njsFetchType == NJS_DATATYPE_UNKNOWN )
2079
+ {
2080
+ error = true ;
2081
+ }
2082
+ }
2083
+
2084
+ if ( error )
2085
+ {
2086
+ executeBaton->error = NJSMessages::getErrorMsg ( errUnsupportedDatType );
2048
2087
}
2049
2088
}
2050
2089
@@ -2270,19 +2309,17 @@ unsigned short Connection::GetTargetType ( eBaton *executeBaton,
2270
2309
*/
2271
2310
void Connection::DoDefines ( eBaton* executeBaton )
2272
2311
{
2273
- unsigned int numCols = executeBaton->numCols ;
2274
- Define *defines = executeBaton->defines = new Define[numCols];
2275
- int csratio = executeBaton->dpiconn ->getByteExpansionRatio ();
2276
-
2277
- // Check for maxRows must be greater than zero in case of non-resultSet
2278
- if ( executeBaton->maxRows == 0 )
2279
- {
2280
- executeBaton->error = NJSMessages::getErrorMsg ( errInvalidmaxRows );
2281
- return ;
2282
- }
2312
+ unsigned int numCols = executeBaton->numCols ;
2313
+ Define *defines = executeBaton->defines = new Define[numCols];
2314
+ int csratio = executeBaton->dpiconn ->getByteExpansionRatio ();
2315
+ bool error = false ;
2283
2316
2284
- for (unsigned int col = 0 ; col < numCols; col++)
2317
+ for (unsigned int col = 0 ; !error && ( col < numCols ) ; col++)
2285
2318
{
2319
+ /*
2320
+ * Only supported DB column types handled here and others would have
2321
+ * reported error while processing meta-data
2322
+ */
2286
2323
switch ( executeBaton->mInfo [col].dbType )
2287
2324
{
2288
2325
case dpi::DpiNumber :
@@ -2297,7 +2334,7 @@ void Connection::DoDefines ( eBaton* executeBaton )
2297
2334
executeBaton->maxRows ) )
2298
2335
{
2299
2336
executeBaton->error = NJSMessages::getErrorMsg ( errResultsTooLarge );
2300
- return ;
2337
+ error = true ;
2301
2338
}
2302
2339
else
2303
2340
{
@@ -2308,7 +2345,7 @@ void Connection::DoDefines ( eBaton* executeBaton )
2308
2345
{
2309
2346
executeBaton->error = NJSMessages::getErrorMsg (
2310
2347
errInsufficientMemory );
2311
- return ;
2348
+ error = true ;
2312
2349
}
2313
2350
}
2314
2351
@@ -2320,7 +2357,7 @@ void Connection::DoDefines ( eBaton* executeBaton )
2320
2357
/*
2321
2358
* the buffer size is increased to account for possible character
2322
2359
* size expansion when data is converted from the DB character set
2323
- * to AL32UTF8
2360
+ * to client character set
2324
2361
*/
2325
2362
2326
2363
if ( executeBaton->mInfo [col].byteSize != 0 )
@@ -2333,7 +2370,7 @@ void Connection::DoDefines ( eBaton* executeBaton )
2333
2370
{
2334
2371
executeBaton->error = NJSMessages::getErrorMsg (
2335
2372
errResultsTooLarge );
2336
- return ;
2373
+ error = true ;
2337
2374
}
2338
2375
else
2339
2376
{
@@ -2343,32 +2380,21 @@ void Connection::DoDefines ( eBaton* executeBaton )
2343
2380
{
2344
2381
executeBaton->error = NJSMessages::getErrorMsg (
2345
2382
errInsufficientMemory );
2346
- return ;
2383
+ error = true ;
2347
2384
}
2348
2385
}
2349
2386
}
2350
2387
/* The null scenario will have indicator as -1, so memory allocation
2351
2388
* not required.
2352
2389
*/
2353
2390
break ;
2391
+ case dpi::DpiTimestampTZ:
2392
+ // TIMESTAMPTZ WITH TIMEZONE (TZ) supported only as STRING value
2354
2393
case dpi::DpiDate :
2355
2394
case dpi::DpiTimestamp:
2356
- case dpi::DpiTimestampTZ:
2357
2395
case dpi::DpiTimestampLTZ:
2358
2396
defines[col].fetchType = executeBaton->mInfo [col].dpiFetchType ;
2359
2397
2360
- if ( ( executeBaton->mInfo [col].dbType == dpi::DpiTimestampTZ ) &&
2361
- ( defines[col].fetchType != dpi::DpiVarChar ))
2362
- {
2363
- /*
2364
- * TIMESTAMP WITH TIMEZONE (TZ) column type supported only as
2365
- * STRING value.
2366
- */
2367
- executeBaton->error = NJSMessages::getErrorMsg (
2368
- errUnsupportedDatType ) ;
2369
- return ;
2370
- }
2371
-
2372
2398
if ( defines[col].fetchType != dpi::DpiVarChar )
2373
2399
{
2374
2400
defines[col].dttmarr = executeBaton->dpienv ->getDateTimeArray (
@@ -2385,8 +2411,9 @@ void Connection::DoDefines ( eBaton* executeBaton )
2385
2411
if ( NJS_SIZE_T_OVERFLOW ( defines[col].maxSize ,
2386
2412
executeBaton->maxRows ) )
2387
2413
{
2388
- executeBaton->error = NJSMessages::getErrorMsg ( errResultsTooLarge );
2389
- return ;
2414
+ executeBaton->error =
2415
+ NJSMessages::getErrorMsg ( errResultsTooLarge );
2416
+ error = true ;
2390
2417
}
2391
2418
else
2392
2419
{
@@ -2397,7 +2424,7 @@ void Connection::DoDefines ( eBaton* executeBaton )
2397
2424
{
2398
2425
executeBaton->error = NJSMessages::getErrorMsg (
2399
2426
errInsufficientMemory);
2400
- return ;
2427
+ error = true ;
2401
2428
}
2402
2429
}
2403
2430
@@ -2412,15 +2439,18 @@ void Connection::DoDefines ( eBaton* executeBaton )
2412
2439
{
2413
2440
executeBaton->error = NJSMessages::getErrorMsg (
2414
2441
errResultsTooLarge ) ;
2415
- return ;
2442
+ error = true ;
2416
2443
}
2417
- defines[col].buf = (char *)malloc (defines[col].maxSize *
2418
- (size_t ) executeBaton->maxRows ) ;
2419
- if ( !defines[col].buf )
2444
+ else
2420
2445
{
2421
- executeBaton->error = NJSMessages::getErrorMsg (
2422
- errInsufficientMemory );
2423
- return ;
2446
+ defines[col].buf = (char *)malloc (defines[col].maxSize *
2447
+ (size_t ) executeBaton->maxRows ) ;
2448
+ if ( !defines[col].buf )
2449
+ {
2450
+ executeBaton->error = NJSMessages::getErrorMsg (
2451
+ errInsufficientMemory );
2452
+ error = true ;
2453
+ }
2424
2454
}
2425
2455
break ;
2426
2456
@@ -2434,7 +2464,7 @@ void Connection::DoDefines ( eBaton* executeBaton )
2434
2464
executeBaton->maxRows ) )
2435
2465
{
2436
2466
executeBaton->error = NJSMessages::getErrorMsg ( errResultsTooLarge );
2437
- return ;
2467
+ error = true ;
2438
2468
}
2439
2469
else
2440
2470
{
@@ -2443,34 +2473,33 @@ void Connection::DoDefines ( eBaton* executeBaton )
2443
2473
2444
2474
if ( !defines[col].buf )
2445
2475
{
2446
- executeBaton->error = NJSMessages::getErrorMsg ( errInsufficientMemory );
2447
- return ;
2476
+ executeBaton->error =
2477
+ NJSMessages::getErrorMsg ( errInsufficientMemory );
2478
+ error = true ;
2448
2479
}
2449
2480
}
2450
2481
2451
- for ( unsigned int j = 0 ; j < executeBaton-> maxRows ; j++ )
2482
+ if ( !error )
2452
2483
{
2453
- ((Descriptor **)(defines[col].buf ))[j] =
2454
- executeBaton->dpienv ->allocDescriptor (LobDescriptorType);
2484
+ for (unsigned int j = 0 ; j < executeBaton->maxRows ; j++)
2485
+ {
2486
+ ((Descriptor **)(defines[col].buf ))[j] =
2487
+ executeBaton->dpienv ->allocDescriptor (LobDescriptorType);
2488
+ }
2455
2489
}
2456
2490
break ;
2457
2491
2458
2492
case dpi::DpiRowid:
2459
2493
defines[col].fetchType = executeBaton->mInfo [col].dpiFetchType ;
2460
2494
2461
- if ( defines[col].fetchType != dpi::DpiVarChar )
2462
- {
2463
- executeBaton->error = NJSMessages::getErrorMsg (
2464
- errUnsupportedDatType);
2465
- return ;
2466
- }
2495
+ // ROWID supported only as STRING value
2467
2496
defines[col].maxSize = NJS_MAX_FETCH_AS_STRING_SIZE;
2468
2497
2469
2498
if ( NJS_SIZE_T_OVERFLOW ( defines[col].maxSize ,
2470
2499
executeBaton->maxRows ) )
2471
2500
{
2472
2501
executeBaton->error = NJSMessages::getErrorMsg ( errResultsTooLarge );
2473
- return ;
2502
+ error = true ;
2474
2503
}
2475
2504
else
2476
2505
{
@@ -2481,36 +2510,41 @@ void Connection::DoDefines ( eBaton* executeBaton )
2481
2510
{
2482
2511
executeBaton->error = NJSMessages::getErrorMsg (
2483
2512
errInsufficientMemory);
2484
- return ;
2513
+ error = true ;
2485
2514
}
2486
2515
}
2487
2516
break ;
2488
2517
2489
2518
default :
2490
- executeBaton->error = NJSMessages::getErrorMsg (errUnsupportedDatType);
2491
- return ;
2519
+ // For unsupported column types, an error is reported earlier itself
2520
+ executeBaton->error = NJSMessages::getErrorMsg ( errInternalError,
2521
+ " default:" , " DoDefines" );
2522
+ error = true ;
2492
2523
break ;
2493
2524
}
2494
2525
2495
- defines[col].ind = (short *)malloc (sizeof (short )*(executeBaton->maxRows ));
2496
- if (!defines[col].ind )
2526
+ if ( !error )
2497
2527
{
2498
- executeBaton->error = NJSMessages::getErrorMsg ( errInsufficientMemory );
2499
- return ;
2500
- }
2501
- defines[col].len = (DPI_BUFLEN_TYPE *)malloc (sizeof (DPI_BUFLEN_TYPE)*
2502
- executeBaton->maxRows );
2503
- if (!defines[col].len )
2504
- {
2505
- executeBaton->error = NJSMessages::getErrorMsg ( errInsufficientMemory );
2506
- return ;
2507
- }
2528
+ defines[col].ind = (short *)malloc ( sizeof ( short ) *
2529
+ ( executeBaton->maxRows ) );
2530
+ if (!defines[col].ind )
2531
+ {
2532
+ executeBaton->error = NJSMessages::getErrorMsg ( errInsufficientMemory );
2533
+ error = true ;
2534
+ }
2535
+ defines[col].len = (DPI_BUFLEN_TYPE *)malloc (sizeof (DPI_BUFLEN_TYPE)*
2536
+ executeBaton->maxRows );
2537
+ if (!defines[col].len )
2538
+ {
2539
+ executeBaton->error = NJSMessages::getErrorMsg ( errInsufficientMemory );
2540
+ error = true ;
2541
+ }
2508
2542
2509
- executeBaton->dpistmt ->define (col+1 , defines[col].fetchType ,
2510
- (defines[col].buf ) ? defines[col].buf : defines[col].extbuf ,
2511
- defines[col].maxSize , defines[col].ind , defines[col].len );
2543
+ executeBaton->dpistmt ->define (col+1 , defines[col].fetchType ,
2544
+ (defines[col].buf ) ? defines[col].buf : defines[col].extbuf ,
2545
+ defines[col].maxSize , defines[col].ind , defines[col].len );
2546
+ }
2512
2547
}
2513
- executeBaton->numCols = numCols;
2514
2548
}
2515
2549
2516
2550
/* ****************************************************************************/
0 commit comments