@@ -2215,7 +2215,6 @@ void Connection::LOB2StringOrBuffer ( eBaton* executeBaton, unsigned int index,
2215
2215
*/
2216
2216
void Connection::String2CLOB ( eBaton* executeBaton, unsigned int index )
2217
2217
{
2218
- executeBaton->binds [index]->type = DpiClob;
2219
2218
StringOrBuffer2LOB ( executeBaton, index, OCI_TEMP_CLOB );
2220
2219
}
2221
2220
@@ -2235,7 +2234,6 @@ void Connection::String2CLOB ( eBaton* executeBaton, unsigned int index )
2235
2234
*/
2236
2235
void Connection::Buffer2BLOB ( eBaton* executeBaton, unsigned int index )
2237
2236
{
2238
- executeBaton->binds [index]->type = DpiBlob;
2239
2237
StringOrBuffer2LOB ( executeBaton, index, OCI_TEMP_BLOB );
2240
2238
}
2241
2239
@@ -2272,10 +2270,14 @@ void Connection::StringOrBuffer2LOB ( eBaton* executeBaton, unsigned int index,
2272
2270
executeBaton->dpiconn ->getErrh (),
2273
2271
lobLocator, lobType );
2274
2272
2275
- Lob::write ( ( DpiHandle * ) executeBaton->dpiconn ->getSvch (),
2276
- ( DpiHandle * ) executeBaton->dpiconn ->getErrh (),
2277
- ( Descriptor * ) lobLocator, byteAmount, charAmount, offset,
2278
- bind->value , bufLen );
2273
+ if ( byteAmount || charAmount )
2274
+ {
2275
+ // Write into Temp LOB only in case of non-empty inputs
2276
+ Lob::write ( ( DpiHandle * ) executeBaton->dpiconn ->getSvch (),
2277
+ ( DpiHandle * ) executeBaton->dpiconn ->getErrh (),
2278
+ ( Descriptor * ) lobLocator, byteAmount, charAmount, offset,
2279
+ bind->value , bufLen );
2280
+ }
2279
2281
2280
2282
// Free the memory allocated to store js input string/buffer and
2281
2283
// re-allocate to store lobLocator
@@ -2383,60 +2385,52 @@ void Connection::ConvertStringOrBuffer2LOB ( eBaton* executeBaton,
2383
2385
unsigned int index )
2384
2386
{
2385
2387
Bind *bind = executeBaton->binds [index];
2388
+ DPI_SZ_TYPE size = 0 ;
2389
+
2390
+ if ( !bind->isOut && !bind->isInOut )
2391
+ {
2392
+ // Case for BIND_IN
2393
+ size = *bind->len ;
2394
+ }
2395
+ else if ( bind->isInOut )
2396
+ {
2397
+ // Case for BIND_INOUT
2398
+ size = ( bind->maxSize >= *( bind->len ) ) ? bind->maxSize : *( bind->len );
2399
+ }
2400
+ else if ( bind->isOut && !bind->isInOut )
2401
+ {
2402
+ // Case for BIND_OUT
2403
+ size = bind->maxSize ;
2404
+ }
2386
2405
2387
- // In case of IN or INOUT bind convert string/buffer to LOB if input data
2388
- // is not NULL and input data size more than 32k for strict IN binds or
2389
- // maxSize more than 32k for INOUT binds
2390
- if ( ( ( !bind->isOut || bind->isInOut ) && *bind->ind != -1 ) &&
2391
- ( ( !bind->isOut && *bind->len > NJS_THRESHOLD_SIZE_PLSQL_STRING_ARG ) ||
2392
- ( bind->isInOut && bind->maxSize > NJS_THRESHOLD_SIZE_PLSQL_STRING_ARG
2393
- ) ) )
2406
+ if ( size > NJS_THRESHOLD_SIZE_PLSQL_STRING_ARG )
2394
2407
{
2395
- // This block is only for BIND_IN case
2396
2408
ExtBind* extBind = new ExtBind ( NJS_EXTBIND_LOB );
2397
2409
if ( !extBind )
2398
2410
{
2399
2411
executeBaton->error = NJSMessages::getErrorMsg
2400
2412
( errInsufficientMemory );
2401
2413
goto exitConvertStringOrBuffer2LOB;
2402
2414
}
2403
- // Set a flag to know that type conversion happened
2404
- // This helps in later steps to clean LOB resources
2405
- extBind->fields .extLob .isStringBuffer2LOB = true ;
2406
- executeBaton->extBinds [index] = extBind;
2407
- extBind->fields .extLob .maxSize = bind->maxSize ;
2415
+ extBind->fields .extLob .maxSize = bind->maxSize ;
2408
2416
2409
- if ( bind->type == DpiVarChar )
2417
+ // Convert the input data into Temp LOB for IN and INOUT binds
2418
+ if ( !bind->isOut || bind->isInOut )
2410
2419
{
2411
- String2CLOB ( executeBaton, index );
2412
- }
2413
- else
2414
- {
2415
- Buffer2BLOB ( executeBaton, index );
2416
- }
2417
- // Set a flag to know that type conversion happened
2418
- // This helps in later steps to clean LOB resources
2419
- extBind->fields .extLob .isStringBuffer2LOB = true ;
2420
- executeBaton->extBinds [index] = extBind;
2421
- }
2422
- else if ( ( bind->isOut || bind->isInOut ) &&
2423
- bind->maxSize > NJS_THRESHOLD_SIZE_PLSQL_STRING_ARG )
2424
- {
2425
- // This block is only for BIND_OUT case
2426
- ExtBind* extBind = new ExtBind ( NJS_EXTBIND_LOB );
2420
+ switch ( bind->type )
2421
+ {
2422
+ case DpiVarChar:
2423
+ String2CLOB ( executeBaton, index );
2424
+ break ;
2427
2425
2428
- if ( !extBind )
2429
- {
2430
- executeBaton->error = NJSMessages::getErrorMsg
2431
- ( errInsufficientMemory );
2432
- goto exitConvertStringOrBuffer2LOB;
2426
+ case DpiRaw:
2427
+ Buffer2BLOB ( executeBaton, index );
2428
+ break ;
2429
+ }
2433
2430
}
2434
2431
2435
- extBind->fields .extLob .maxSize = bind->maxSize ;
2436
-
2437
2432
// Set a flag to know that type conversion happened
2438
- // This helps in later steps for converting LOB to String/Buffer and
2439
- // clean LOB resources
2433
+ // This helps in later steps to clean LOB resources
2440
2434
extBind->fields .extLob .isStringBuffer2LOB = true ;
2441
2435
executeBaton->extBinds [index] = extBind;
2442
2436
0 commit comments