Skip to content

Commit a9374f0

Browse files
committed
Re-allow unamed objects containing "val" for IN binds (broken in 35594e7)
1 parent e0e344e commit a9374f0

File tree

2 files changed

+155
-7
lines changed

2 files changed

+155
-7
lines changed

src/njs/src/njsConnection.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -724,14 +724,17 @@ void Connection::GetBindUnit (Local<Value> val, Bind* bind, bool array,
724724

725725
if ( array )
726726
{
727-
// In case of array binds, JSON objects are expected to be unnamed.
728-
// Named json object gets confused as we look for "dir", "type",
729-
// "maxSize" key words, but "name" will not match.
730-
// Array binds syntax
727+
// In case of bind-by-position, JSON objects are expected to be unnamed.
728+
// If JSON object is provided, we look for "dir", "type", "maxSize",
729+
// "val" key names. If not found report error
730+
// values provided as in Array syntax - working case.
731731
// [ id, name, {type : oracledb.STRING, dir : oracledb.BIND_OUT}]
732-
// the 3rd parameter is unnamed JSON object.
732+
// In this example the 3rd parameter is unnamed JSON object.
733+
//
733734
// [ id, n, { a: { type : oracledb.STRING, dir : oracledb.BIND_OUT} }]
734-
// will fail now.
735+
// will fail now. In this example the third parameter JSON object has
736+
// a key with name "a" and value as another JSON. Incorrect syntax
737+
//
735738
Local<Array> keys = bind_unit->GetOwnPropertyNames ();
736739
if ( keys->Length () > 0 )
737740
{
@@ -747,7 +750,8 @@ void Connection::GetBindUnit (Local<Value> val, Bind* bind, bool array,
747750

748751
if ( ( key.compare ( "dir" ) == 0 ) ||
749752
( key.compare ( "type" ) == 0 ) ||
750-
( key.compare ( "maxSize" ) == 0 ) )
753+
( key.compare ( "maxSize" ) == 0 ) ||
754+
( key.compare ( "val" ) == 0 ) )
751755
{
752756
valid = true;
753757
}

test/binding.js

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,4 +777,148 @@ describe('4. binding.js', function() {
777777

778778
})
779779
})
780+
781+
// Test cases involving JSON value as input
782+
describe ('4.7 Value as JSON named/unamed test cases', function () {
783+
it ( '4.7.1 valid case when numeric values are passed as it is',
784+
function (done ) {
785+
var sql = "SELECT SYSDATE FROM DUAL WHERE :b = 1 and :c = 456 ";
786+
var binds = [ 1, 456 ];
787+
788+
oracledb.getConnection (
789+
dbConfig,
790+
function (err, connection ){
791+
792+
should.not.exist ( err ) ;
793+
connection.execute (
794+
sql,
795+
binds,
796+
function ( err, result ) {
797+
should.not.exist ( err );
798+
done ();
799+
}
800+
);
801+
});
802+
});
803+
804+
it ( '4.7.2 Valid values when one of the value is passed as JSON ',
805+
function (done ) {
806+
var sql = "SELECT SYSDATE FROM DUAL WHERE :b = 1 and :c = 456 ";
807+
var binds = [ 1, { val : 456 } ];
808+
809+
oracledb.getConnection (
810+
dbConfig,
811+
function (err, connection ){
812+
813+
should.not.exist ( err ) ;
814+
connection.execute (
815+
sql,
816+
binds,
817+
function ( err, result ) {
818+
should.not.exist ( err );
819+
done ();
820+
} );
821+
});
822+
});
823+
824+
it ( '4.7.3 Valid test case when one of the value is passed as JSON ',
825+
function (done ) {
826+
var sql = "SELECT SYSDATE FROM DUAL WHERE :b = 1 and :c = 456 ";
827+
var binds = [ {val : 1}, 456 ];
828+
829+
oracledb.getConnection (
830+
dbConfig,
831+
function (err, connection ){
832+
833+
should.not.exist ( err ) ;
834+
connection.execute (
835+
sql,
836+
binds,
837+
function ( err, result ) {
838+
should.not.exist ( err );
839+
done ();
840+
} );
841+
});
842+
});
843+
844+
it ( '4.7.4 Valid Test case when both values are passed as JSON',
845+
function (done ) {
846+
var sql = "SELECT SYSDATE FROM DUAL WHERE :b = 1 and :c = 456 ";
847+
var binds = [ {val : 1}, {val : 456 } ];
848+
849+
oracledb.getConnection (
850+
dbConfig,
851+
function (err, connection ){
852+
853+
should.not.exist ( err ) ;
854+
connection.execute (
855+
sql,
856+
binds,
857+
function ( err, result ) {
858+
should.not.exist ( err );
859+
done ();
860+
} );
861+
});
862+
});
863+
864+
it ( '4.7.5 Invalid Test case when value is passed as named JSON',
865+
function (done ) {
866+
var sql = "SELECT SYSDATE FROM DUAL WHERE :b = 1 and :c = 456 ";
867+
var binds = [ {val : 1}, { c: {val : 456 } } ];
868+
869+
oracledb.getConnection (
870+
dbConfig,
871+
function (err, connection ){
872+
should.not.exist ( err ) ;
873+
connection.execute (
874+
sql,
875+
binds,
876+
function ( err, result ) {
877+
should.exist ( err );
878+
(err.message).should.startWith ( 'NJS-044');
879+
done ();
880+
} );
881+
});
882+
});
883+
884+
it ( '4.7.6 Invalid Test case when other-value is passed as named JSON',
885+
function (done ) {
886+
var sql = "SELECT SYSDATE FROM DUAL WHERE :b = 1 and :c = 456 ";
887+
var binds = [ { b: {val : 1} }, {val : 456 } ];
888+
889+
oracledb.getConnection (
890+
dbConfig,
891+
function (err, connection ){
892+
should.not.exist ( err ) ;
893+
connection.execute (
894+
sql,
895+
binds,
896+
function ( err, result ) {
897+
should.exist ( err );
898+
(err.message).should.startWith ( 'NJS-044');
899+
done ();
900+
} );
901+
});
902+
});
903+
904+
it ( '4.7.7 Invalid Test case when all values is passed as named JSON',
905+
function (done ) {
906+
var sql = "SELECT SYSDATE FROM DUAL WHERE :b = 1 and :c = 456 ";
907+
var binds = [ { b: {val : 1} }, { c: {val : 456 } } ];
908+
909+
oracledb.getConnection (
910+
dbConfig,
911+
function (err, connection ){
912+
should.not.exist ( err ) ;
913+
connection.execute (
914+
sql,
915+
binds,
916+
function ( err, result ) {
917+
should.exist ( err );
918+
(err.message).should.startWith ( 'NJS-044');
919+
done ();
920+
} );
921+
});
922+
});
923+
});
780924
})

0 commit comments

Comments
 (0)