Skip to content

Commit d96e5db

Browse files
committed
Fix some LOB BIND_INOUT issues with nulls and empty strings
1 parent 284296c commit d96e5db

File tree

3 files changed

+47
-53
lines changed

3 files changed

+47
-53
lines changed

src/njs/src/njsConnection.cpp

Lines changed: 39 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2215,7 +2215,6 @@ void Connection::LOB2StringOrBuffer ( eBaton* executeBaton, unsigned int index,
22152215
*/
22162216
void Connection::String2CLOB ( eBaton* executeBaton, unsigned int index )
22172217
{
2218-
executeBaton->binds[index]->type = DpiClob;
22192218
StringOrBuffer2LOB ( executeBaton, index, OCI_TEMP_CLOB );
22202219
}
22212220

@@ -2235,7 +2234,6 @@ void Connection::String2CLOB ( eBaton* executeBaton, unsigned int index )
22352234
*/
22362235
void Connection::Buffer2BLOB ( eBaton* executeBaton, unsigned int index )
22372236
{
2238-
executeBaton->binds[index]->type = DpiBlob;
22392237
StringOrBuffer2LOB ( executeBaton, index, OCI_TEMP_BLOB );
22402238
}
22412239

@@ -2272,10 +2270,14 @@ void Connection::StringOrBuffer2LOB ( eBaton* executeBaton, unsigned int index,
22722270
executeBaton->dpiconn->getErrh (),
22732271
lobLocator, lobType );
22742272

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+
}
22792281

22802282
// Free the memory allocated to store js input string/buffer and
22812283
// re-allocate to store lobLocator
@@ -2383,60 +2385,52 @@ void Connection::ConvertStringOrBuffer2LOB ( eBaton* executeBaton,
23832385
unsigned int index )
23842386
{
23852387
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+
}
23862405

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 )
23942407
{
2395-
// This block is only for BIND_IN case
23962408
ExtBind* extBind = new ExtBind ( NJS_EXTBIND_LOB );
23972409
if ( !extBind )
23982410
{
23992411
executeBaton->error = NJSMessages::getErrorMsg
24002412
( errInsufficientMemory );
24012413
goto exitConvertStringOrBuffer2LOB;
24022414
}
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;
24082416

2409-
if ( bind->type == DpiVarChar )
2417+
// Convert the input data into Temp LOB for IN and INOUT binds
2418+
if ( !bind->isOut || bind->isInOut )
24102419
{
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;
24272425

2428-
if ( !extBind )
2429-
{
2430-
executeBaton->error = NJSMessages::getErrorMsg
2431-
( errInsufficientMemory );
2432-
goto exitConvertStringOrBuffer2LOB;
2426+
case DpiRaw:
2427+
Buffer2BLOB ( executeBaton, index );
2428+
break;
2429+
}
24332430
}
24342431

2435-
extBind->fields.extLob.maxSize = bind->maxSize;
2436-
24372432
// 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
24402434
extBind->fields.extLob.isStringBuffer2LOB = true;
24412435
executeBaton->extBinds[index] = extBind;
24422436

test/clobPlsqlBindAsString_bindinout.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ describe('76.clobPlsqlBindAsString_bindinout.js', function() {
313313
], done);
314314
}); // 76.1.2
315315

316-
it.skip('76.1.3 works with EMPTY_CLOB and maxSize set to (64K - 1)', function(done) {
316+
it('76.1.3 works with EMPTY_CLOB and maxSize set to (64K - 1)', function(done) {
317317
var sequence = getID();
318318
var bindVar = {
319319
i: { val: sequence, dir: oracledb.BIND_IN, type: oracledb.NUMBER },
@@ -353,7 +353,7 @@ describe('76.clobPlsqlBindAsString_bindinout.js', function() {
353353
plsqlBindInOut(sqlRun, bindVar, null, null, false, client11gPlus, done);
354354
}); // 76.1.5
355355

356-
it.skip('76.1.6 works with null and maxSize set to (64K - 1)', function(done) {
356+
it('76.1.6 works with null and maxSize set to (64K - 1)', function(done) {
357357
var sequence = getID();
358358
var bindVar = {
359359
i: { val: sequence, dir: oracledb.BIND_IN, type: oracledb.NUMBER },
@@ -383,7 +383,7 @@ describe('76.clobPlsqlBindAsString_bindinout.js', function() {
383383
plsqlBindInOut(sqlRun, bindVar, "", null, false, client11gPlus, done);
384384
}); // 76.1.8
385385

386-
it.skip('76.1.9 works with empty string and maxSize set to (64K - 1)', function(done) {
386+
it('76.1.9 works with empty string and maxSize set to (64K - 1)', function(done) {
387387
var sequence = getID();
388388
var bindVar = {
389389
i: { val: sequence, dir: oracledb.BIND_IN, type: oracledb.NUMBER },
@@ -413,7 +413,7 @@ describe('76.clobPlsqlBindAsString_bindinout.js', function() {
413413
plsqlBindInOut(sqlRun, bindVar, undefined, null, false, client11gPlus, done);
414414
}); // 76.1.11
415415

416-
it.skip('76.1.12 works with undefined and maxSize set to (64K - 1)', function(done) {
416+
it('76.1.12 works with undefined and maxSize set to (64K - 1)', function(done) {
417417
var sequence = getID();
418418
var bindVar = {
419419
i: { val: sequence, dir: oracledb.BIND_IN, type: oracledb.NUMBER },

test/list.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,16 +1180,16 @@ Overview of node-oracledb functional tests
11801180
76.1 CLOB, PLSQL, BIND_INOUT
11811181
76.1.1 works with EMPTY_CLOB
11821182
76.1.2 works with EMPTY_CLOB and maxSize set to 1
1183-
- 76.1.3 works with EMPTY_CLOB and maxSize set to (64K - 1)
1183+
76.1.3 works with EMPTY_CLOB and maxSize set to (64K - 1)
11841184
76.1.4 works with null
11851185
76.1.5 works with null and maxSize set to 1
1186-
- 76.1.6 works with null and maxSize set to (64K - 1)
1186+
76.1.6 works with null and maxSize set to (64K - 1)
11871187
76.1.7 works with empty string
11881188
76.1.8 works with empty string and maxSize set to 1
1189-
- 76.1.9 works with empty string and maxSize set to (64K - 1)
1189+
76.1.9 works with empty string and maxSize set to (64K - 1)
11901190
76.1.10 works with undefined
11911191
76.1.11 works with undefined and maxSize set to 1
1192-
- 76.1.12 works with undefined and maxSize set to (64K - 1)
1192+
76.1.12 works with undefined and maxSize set to (64K - 1)
11931193
76.1.13 works with NaN
11941194
76.1.14 works with 0
11951195
76.1.15 works with String length 32K

0 commit comments

Comments
 (0)