1
- /* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. */
1
+ /* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. */
2
2
3
3
/******************************************************************************
4
4
*
31
31
*****************************************************************************/
32
32
'use strict' ;
33
33
34
- var oracledb = require ( 'oracledb' ) ;
35
- var should = require ( 'should' ) ;
36
- var dbconfig = require ( './dbconfig.js' ) ;
34
+ const oracledb = require ( 'oracledb' ) ;
35
+ const should = require ( 'should' ) ;
36
+ const dbconfig = require ( './dbconfig.js' ) ;
37
+ const sodaUtil = require ( './sodaUtil.js' ) ;
37
38
38
39
describe ( '172. executeMany2.js' , function ( ) {
39
40
40
- before ( function ( ) {
41
- if ( ! dbconfig . test . DBA_PRIVILEGE ) this . skip ( ) ;
42
- } ) ;
43
-
44
- // Currently skipped for
45
- // Segmentation fault: 11
46
- it . skip ( '172.1 Negative - incorrect parameters' , async ( ) => {
41
+ it ( '172.1 Negative - incorrect parameters' , async ( ) => {
47
42
48
43
let conn ;
44
+ let schema = dbconfig . user . toUpperCase ( ) ;
45
+
49
46
try {
50
- const connectionDetails = {
51
- user : dbconfig . test . DBA_user ,
52
- password : dbconfig . test . DBA_password ,
53
- connectString : dbconfig . connectString ,
54
- privilege : oracledb . SYSDBA
55
- } ;
56
- const schema = 'T_APPDEV4DB' ;
57
- const password = 'oracle' ;
47
+ conn = await oracledb . getConnection ( dbconfig ) ;
48
+ await conn . execute (
49
+ `BEGIN EXECUTE IMMEDIATE 'DROP TABLE "${ schema } "."NODB_TAB_SALES"'; EXCEPTION WHEN OTHERS THEN IF SQLCODE <> -942 THEN RAISE; END IF; END; `
50
+ ) ;
51
+ await conn . execute (
52
+ `create table "${ schema } "."NODB_TAB_SALES" ("AMOUNT_SOLD" NUMBER(10,2))`
53
+ ) ;
54
+
55
+ } catch ( err ) {
56
+ should . not . exist ( err ) ;
57
+ }
58
58
59
- conn = await oracledb . getConnection ( connectionDetails ) ;
59
+ await sodaUtil . assertThrowsAsync (
60
+ async ( ) => {
61
+ await conn . executeMany (
62
+ `insert into "${ schema } "."NODB_TAB_SALES" ("AMOUNT_SOLD") values (:1)` ,
63
+ [ 48 , 33 , 3 , 999 , 1 , 13.13 ]
64
+ ) ;
65
+ } ,
66
+ / N J S - 0 0 5 : /
67
+ ) ;
68
+ // NJS-005: invalid value for parameter %d
60
69
70
+ try {
61
71
await conn . execute (
62
- `DROP USER ${ schema } CASCADE `
72
+ `BEGIN EXECUTE IMMEDIATE ' DROP TABLE " ${ schema } "."NODB_TAB_SALES"'; EXCEPTION WHEN OTHERS THEN IF SQLCODE <> -942 THEN RAISE; END IF; END; `
63
73
) ;
74
+ await conn . close ( ) ;
75
+ } catch ( err ) {
76
+ should . not . exist ( err ) ;
77
+ }
78
+ } ) ; // 172.1
79
+
80
+ it ( '172.2 binding by position and by name cannot be mixed' , async ( ) => {
81
+ let conn ;
82
+ try {
83
+ conn = await oracledb . getConnection ( dbconfig ) ;
84
+
64
85
await conn . execute (
65
- `GRANT CONNECT, RESOURCE, UNLIMITED TABLESPACE TO ${ schema } identified by ${ password } `
86
+ `BEGIN EXECUTE IMMEDIATE 'DROP TABLE nodb_tab_emp'; EXCEPTION WHEN OTHERS THEN IF SQLCODE <> -942 THEN RAISE; END IF; END; `
66
87
) ;
67
88
await conn . execute (
68
- `create table " ${ schema } "."SALES" ("AMOUNT_SOLD" NUMBER(10,2 ))`
89
+ `create table nodb_tab_emp (id NUMBER, name VARCHAR2(100 ))`
69
90
) ;
70
-
71
- await conn . executeMany (
72
- `insert into "${ schema } "."SALES" ("AMOUNT_SOLD") values (:1)` ,
73
- [ 48 , 33 , 3 , 999 , 1 , 13.13 ]
91
+
92
+ } catch ( err ) {
93
+ should . not . exist ( err ) ;
94
+ }
95
+
96
+ try {
97
+ const bindVars = [
98
+ [ 1 , "John Smith" ] ,
99
+ { a : 2 , b : "Changjie" } ,
100
+ ] ;
101
+ await sodaUtil . assertThrowsAsync (
102
+ async ( ) => {
103
+ await conn . executeMany (
104
+ `insert into nodb_tab_emp values (:a, :b)` ,
105
+ bindVars
106
+ ) ;
107
+ } ,
108
+ / N J S - 0 5 5 : /
74
109
) ;
110
+ // NJS-055: binding by position and name cannot be mixed
111
+ } catch ( err ) {
112
+ should . not . exist ( err ) ;
113
+ }
75
114
115
+ try {
116
+ await conn . execute (
117
+ `BEGIN EXECUTE IMMEDIATE 'DROP TABLE nodb_tab_emp'; EXCEPTION WHEN OTHERS THEN IF SQLCODE <> -942 THEN RAISE; END IF; END; `
118
+ ) ;
119
+ await conn . commit ( ) ;
120
+ await conn . close ( ) ;
76
121
} catch ( err ) {
77
122
should . not . exist ( err ) ;
78
- } finally {
79
- if ( conn ) {
80
- try {
81
- await conn . close ( ) ;
82
- } catch ( err ) {
83
- should . not . exist ( err ) ;
84
- }
85
- }
86
123
}
87
- } ) ; // 172.1
88
- } ) ;
124
+ } ) ; // 172.2
125
+ } ) ;
0 commit comments