Skip to content

Commit 3c36bad

Browse files
committed
Improve PL/SQL Index-by array bind messages, based on PR #470 (Hariprasad Kulkarni)
1 parent f9f08a8 commit 3c36bad

File tree

5 files changed

+81
-16
lines changed

5 files changed

+81
-16
lines changed

src/njs/src/njsConnection.cpp

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,6 +1367,7 @@ void Connection::GetInBindParamsScalar(Local<Value> v8val, Bind* bind,
13671367
;
13681368
}
13691369

1370+
13701371
/*****************************************************************************/
13711372
/*
13721373
DESCRIPTION
@@ -1431,8 +1432,20 @@ void Connection::GetInBindParamsArray(Local<Array> va8vals, Bind *bind,
14311432
case NJS_DATATYPE_STR:
14321433
if (vtype != NJS_VALUETYPE_NULL && vtype != NJS_VALUETYPE_STRING)
14331434
{
1434-
executeBaton->error = NJSMessages::getErrorMsg(
1435-
errIncompatibleTypeArrayBind);
1435+
if ( !bind->key.empty () )
1436+
{
1437+
executeBaton->error = NJSMessages::getErrorMsg (
1438+
errIncompatibleTypeArrayBind,
1439+
index,
1440+
bind->key.c_str () );
1441+
}
1442+
else
1443+
{
1444+
executeBaton->error = NJSMessages::getErrorMsg (
1445+
errIncompatibleTypeArrayIndexBind,
1446+
index,
1447+
executeBaton->binds.size() );
1448+
}
14361449
goto exitGetInBindParamsArray;
14371450
}
14381451
else
@@ -1450,8 +1463,21 @@ void Connection::GetInBindParamsArray(Local<Array> va8vals, Bind *bind,
14501463
if (vtype != NJS_VALUETYPE_NULL && vtype != NJS_VALUETYPE_INTEGER &&
14511464
vtype != NJS_VALUETYPE_UINTEGER && vtype != NJS_VALUETYPE_NUMBER)
14521465
{
1453-
executeBaton->error = NJSMessages::getErrorMsg(
1454-
errIncompatibleTypeArrayBind);
1466+
if ( !bind->key.empty () )
1467+
{
1468+
executeBaton->error = NJSMessages::getErrorMsg (
1469+
errIncompatibleTypeArrayBind,
1470+
index,
1471+
bind->key.c_str () );
1472+
}
1473+
else
1474+
{
1475+
executeBaton->error = NJSMessages::getErrorMsg (
1476+
errIncompatibleTypeArrayIndexBind,
1477+
index,
1478+
executeBaton->binds.size ());
1479+
1480+
}
14551481
goto exitGetInBindParamsArray;
14561482
}
14571483
break;

src/njs/src/njsMessages.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static const char *errMsg[] =
7373
"NJS-034: data type is unsupported for array bind", // errInvalidTypeForArrayBind
7474
"NJS-035: maxArraySize is required for IN OUT array bind", // errReqdMaxArraySize
7575
"NJS-036: given array is of size greater than maxArraySize", // errInvalidArraySize
76-
"NJS-037: incompatible type of value provided", // errIncompatibleTypeArrayBind
76+
"NJS-037: invalid data type at array index %d for bind \"%s\"", // errIncompatibleTypeArrayBind
7777
"NJS-038: maxArraySize value should be greater than zero", // errInvalidValueArrayBind
7878
"NJS-039: empty array is not allowed for IN bind", // errEmptyArray
7979
"NJS-040: connection request timeout", // errConnRequestTimeout
@@ -88,6 +88,7 @@ static const char *errMsg[] =
8888
"NJS-049: Temporary LOBs were open when the connection was closed", // errBusyConnTEMPLOB
8989
"NJS-050: data must be shorter than %d", // errBindValueTooLarge
9090
"NJS-051: \"%s\" must be less than %d", // errMaxValueTooLarge
91+
"NJS-052: invalid data type at array index %d for bind position %d", // errIncompatibleTypeArrayIndexBind
9192
};
9293

9394
string NJSMessages::getErrorMsg ( NJSErrorType err, ... )

src/njs/src/njsMessages.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ typedef enum
8787
errBusyConnTEMPLOB,
8888
errBindValueTooLarge,
8989
errMaxValueTooLarge,
90+
errIncompatibleTypeArrayIndexBind,
9091

9192
// New ones should be added here
9293

test/list.txt

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -617,19 +617,22 @@ Overview of node-oracledb functional tests
617617
42.4 in PL/SQL, the maximum size is 32767
618618
- 42.4.1 when data length is 200
619619

620-
43. plsqlBindIndexedTable1.js.js
620+
43. plsqlBindIndexedTable1.js
621621
43.1 binding PL/SQL indexed table
622-
43.1.1 binding PL/SQL indexed table IN
623-
43.1.2 binding PL/SQL indexed table IN OUT
624-
43.1.3 binding PL/SQL indexed table OUT
622+
43.1.1 binding PL/SQL indexed table IN by name
623+
43.1.2 binding PL/SQL indexed table IN by position
624+
43.1.3 binding PL/SQL indexed table IN OUT
625+
43.1.4 binding PL/SQL indexed table OUT
625626
43.2 test exceptions when using PL/SQL indexed table bindings
626627
43.2.1 maxArraySize is ignored when specifying BIND_IN
627628
43.2.2 maxArraySize is mandatory for BIND_INOUT
628-
42.2.3 maxArraySize cannot smaller than the number of array elements
629-
43.2.4 DATE type has not been supported yet
630-
43.2.5 negative case (string): incorrect type of array element
629+
43.2.3 maxArraySize cannot smaller than the number of array elements
630+
43.2.4 DATE type indexed table has not been supported yet
631+
43.2.5 negative case (string): incorrect type of array elements
631632
43.2.6 negative case (number): incorrect type of array element
632633
43.2.7 supports binding by position
634+
43.2.8 negative case: incorrect type of array elements - bind by pos1
635+
43.2.9 negative case: incorrect type of array elements - bind by pos2
633636
43.3 binding PL/SQL scalar
634637
43.3.1 binding PL/SQL scalar IN
635638
43.3.2 binding PL/SQL scalar IN/OUT
@@ -643,7 +646,7 @@ Overview of node-oracledb functional tests
643646
- 43.4.5 negative case: large value
644647
43.4.6 negative case: < 0
645648
43.4.7 negative case: = 0
646-
43.4.8 negative case: assigning a string to it
649+
43.4.8 negative case: assign a string to it
647650
43.4.9 negative case: NaN
648651

649652
44. plsqlBindIndexedTable2.js.js

test/plsqlBindIndexedTable1.js

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ describe('43. plsqlBindIndexedTable1.js', function() {
508508
function(err, result) {
509509
should.exist(err);
510510
(err.message).should.startWith('NJS-037:');
511-
// NJS-037: incompatible type of value provided.
511+
// NJS-037: invalid data type at array index %d for bind \"%s\"
512512
should.not.exist(result);
513513
done();
514514
}
@@ -525,7 +525,7 @@ describe('43. plsqlBindIndexedTable1.js', function() {
525525
function(err, result) {
526526
should.exist(err);
527527
(err.message).should.startWith('NJS-037:');
528-
// NJS-037: incompatible type of value provided.
528+
// NJS-037: NJS-037: invalid data type at array index %d for bind \"%s\"
529529
should.not.exist(result);
530530
done();
531531
}
@@ -547,6 +547,40 @@ describe('43. plsqlBindIndexedTable1.js', function() {
547547
);
548548
});
549549

550+
it('43.2.8 negative case: incorrect type of array elements - bind by pos1',
551+
function (done ){
552+
var bindvars = [ { type : oracledb.STRING, dir: oracledb.BIND_IN, val : ['hello', 1] } ];
553+
connection.execute (
554+
"BEGIN nodb_plsqlbindpack21.test4 ( :1 ); END;",
555+
bindvars,
556+
function ( err, result ) {
557+
should.exist ( err ) ;
558+
(err.message).should.startWith ( 'NJS-052:');
559+
// NJS-052: invalid data type at array index %d for bind position %d
560+
should.not.exist ( result );
561+
done ();
562+
}
563+
);
564+
}
565+
);
566+
567+
it('43.2.9 negative case: incorrect type of array elements - bind by pos2',
568+
function ( done ) {
569+
var bindvars = [ { type : oracledb.NUMBER, dir : oracledb.BIND_IN, val : [ 1, 'hello' ] }];
570+
connection.execute (
571+
"BEGIN nodb_plsqlbindpack21.test1 ( :p ) ; END;",
572+
bindvars,
573+
function ( err, result ) {
574+
should.exist ( err ) ;
575+
(err.message).should.startWith ( 'NJS-052:');
576+
// NJS-052: NJS-037: invalid data type at array index %d for bind \"%s\"
577+
should.not.exist ( result ) ;
578+
done();
579+
}
580+
);
581+
}
582+
);
583+
550584
}); // 43.2
551585

552586
describe('43.3 binding PL/SQL scalar', function() {
@@ -718,7 +752,7 @@ describe('43. plsqlBindIndexedTable1.js', function() {
718752
], done);
719753
});
720754

721-
it('43.3.4 binding PL/SQL scalar OUT by postion', function(done) {
755+
it('43.3.4 binding PL/SQL scalar OUT by position', function(done) {
722756
async.series([
723757
function(callback) {
724758
var proc = "CREATE OR REPLACE\n" +

0 commit comments

Comments
 (0)