@@ -777,10 +777,61 @@ describe('4. binding.js', function() {
777777 await connection . execute ( sql ) ;
778778 } ,
779779 //ORA-01008: not all variables bound
780- //NJS-098: 1 positional bind values are required but 0 were provided
780+ //NJS-098: 1 bind placeholders were used in the SQL statement but 0 bind values were provided
781781 / O R A - 0 1 0 0 8 : | N J S - 0 9 8 : /
782782 ) ;
783783 } ) ;
784+
785+ it ( '4.9.4 not using a bind name in execute statement - repeated bind placeholders' , async function ( ) {
786+ const sql = 'select :val, bind(:val) from dual' ;
787+ await assert . rejects (
788+ async ( ) => {
789+ await connection . execute ( sql ) ;
790+ } ,
791+ //ORA-01008: not all variables bound
792+ //NJS-098: 2 bind placeholders were used in the SQL statement but 0 bind values were provided
793+ / O R A - 0 1 0 0 8 : | N J S - 0 9 8 : /
794+ ) ;
795+ } ) ;
796+
797+ it ( '4.9.5 mismatch of named binds - lower number of bind values' , async function ( ) {
798+ const sql = 'select :val1, :val2 from dual' ;
799+ const binds = { val1 : 1 } ;
800+ await assert . rejects (
801+ async ( ) => {
802+ await connection . execute ( sql , binds ) ;
803+ } ,
804+ //ORA-01008: not all variables bound
805+ //NJS-098: 2 bind placeholders were used in the SQL statement but 1 bind values were provided
806+ / O R A - 0 1 0 0 8 : | N J S - 0 9 8 : /
807+ ) ;
808+ } ) ;
809+
810+ it ( '4.9.6 mismatch of named repeated binds - lower number of bind values' , async function ( ) {
811+ const sql = 'select :val1, bind(:val1), :val2 from dual' ;
812+ const binds = { val1 : 1 } ;
813+ await assert . rejects (
814+ async ( ) => {
815+ await connection . execute ( sql , binds ) ;
816+ } ,
817+ //ORA-01008: not all variables bound
818+ //NJS-098: 3 bind placeholders were used in the SQL statement but 1 bind values were provided
819+ / O R A - 0 1 0 0 8 : | N J S - 0 9 8 : /
820+ ) ;
821+ } ) ;
822+
823+ it ( '4.9.7 mismatch of named binds - higher number of bind values' , async function ( ) {
824+ const sql = 'select :val1 from dual' ;
825+ const binds = { val1 : 1 , val2 : 2 } ;
826+ await assert . rejects (
827+ async ( ) => {
828+ await connection . execute ( sql , binds ) ;
829+ } ,
830+ //ORA-01036: illegal variable name/number
831+ //NJS-098: 1 bind placeholders were used in the SQL statement but 2 bind values were provided
832+ / O R A - 0 1 0 3 6 : | N J S - 0 9 8 : /
833+ ) ;
834+ } ) ;
784835 } ) ; // 4.9
785836
786837 describe ( '4.10 various quoted binds' , function ( ) {
@@ -1187,4 +1238,48 @@ describe('4. binding.js', function() {
11871238 assert ( newOpenCount - openCount < 4 ) ;
11881239 } ) ;
11891240 } ) ;
1241+
1242+ describe ( '4.16 positional binding' , function ( ) {
1243+ let connection = null ;
1244+ before ( async function ( ) {
1245+ connection = await oracledb . getConnection ( dbConfig ) ;
1246+ } ) ;
1247+
1248+ after ( async function ( ) {
1249+ await connection . close ( ) ;
1250+ } ) ;
1251+
1252+ it ( '4.16.1 Matching bind values' , async function ( ) {
1253+ const sql = 'select :1, :2, :3 from dual' ;
1254+ const binds = [ 1 , 2 , 3 ] ;
1255+ const result = await connection . execute ( sql , binds ) ;
1256+ assert . strictEqual ( result . rows [ 0 ] [ 0 ] , 1 ) ;
1257+ assert . strictEqual ( result . rows [ 0 ] [ 2 ] , 3 ) ;
1258+ } ) ;
1259+
1260+ it ( '4.16.2 Negative - bind mismatch of zero bind values' , async function ( ) {
1261+ const sql = 'select :1, dump(:2) from dual' ;
1262+ await assert . rejects (
1263+ async ( ) => {
1264+ await connection . execute ( sql ) ;
1265+ } ,
1266+ //ORA-01008: not all variables bound
1267+ //NJS-098: 2 bind placeholders were used in the SQL statement but 0 bind values were provided
1268+ / O R A - 0 1 0 0 8 : | N J S - 0 9 8 : /
1269+ ) ;
1270+ } ) ;
1271+
1272+ it ( '4.16.3 Negative - bind mismatch of non-zero bind values' , async function ( ) {
1273+ const sql = 'select :1, dump(:2), :3 from dual' ;
1274+ const binds = [ 1 ] ;
1275+ await assert . rejects (
1276+ async ( ) => {
1277+ await connection . execute ( sql , binds ) ;
1278+ } ,
1279+ //ORA-01008: not all variables bound
1280+ //NJS-098: 3 bind placeholders were used in the SQL statement but 1 bind values were provided
1281+ / O R A - 0 1 0 0 8 : | N J S - 0 9 8 : /
1282+ ) ;
1283+ } ) ;
1284+ } ) ;
11901285} ) ;
0 commit comments