Skip to content

Commit 8443b18

Browse files
committed
Add testcases for autocommit
1 parent 39e7e7d commit 8443b18

File tree

2 files changed

+276
-0
lines changed

2 files changed

+276
-0
lines changed

test/autoCommit4nestedExecutes.js

Lines changed: 273 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,273 @@
1+
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
2+
3+
/******************************************************************************
4+
*
5+
* You may not use the identified files except in compliance with the Apache
6+
* License, Version 2.0 (the "License.")
7+
*
8+
* You may obtain a copy of the License at
9+
* http://www.apache.org/licenses/LICENSE-2.0.
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
*
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* The node-oracledb test suite uses 'mocha', 'should' and 'async'.
19+
* See LICENSE.md for relevant licenses.
20+
*
21+
* NAME
22+
* 63. autoCommit4nestedExecutes.js
23+
*
24+
* DESCRIPTION
25+
* Nested executes where the 2nd execute fails used to cause an unexpected
26+
* commit, even though the autoCommit:false setting is enabled at the
27+
* execute() and/or oracledb level. This is github issue 269. It has
28+
* been fixed in 1.4.
29+
*
30+
* https://github.com/oracle/node-oracledb/issues/269
31+
*
32+
* NUMBERING RULE
33+
* Test numbers follow this numbering rule:
34+
* 1 - 20 are reserved for basic functional tests
35+
* 21 - 50 are reserved for data type supporting tests
36+
* 51 onwards are for other tests
37+
*
38+
*****************************************************************************/
39+
'use strict';
40+
41+
var oracledb = require('oracledb');
42+
var should = require('should');
43+
var async = require('async');
44+
var dbConfig = require('./dbConfig.js');
45+
46+
describe('63. autoCommit4nestedExecutes.js', function() {
47+
48+
if(dbConfig.externalAuth){
49+
var credential = { externalAuth: true, connectString: dbConfig.connectString };
50+
} else {
51+
var credential = dbConfig;
52+
}
53+
54+
var tableName = "oracledb_issue269tab";
55+
var procName = "issue269proc";
56+
var connection = null;
57+
58+
before('prepare table and procedure', function(done) {
59+
60+
var sqlCreateTab =
61+
" BEGIN "
62+
+ " DECLARE "
63+
+ " e_table_exists EXCEPTION; "
64+
+ " PRAGMA EXCEPTION_INIT(e_table_exists, -00942); "
65+
+ " BEGIN "
66+
+ " EXECUTE IMMEDIATE ('DROP TABLE " + tableName + " '); "
67+
+ " EXCEPTION "
68+
+ " WHEN e_table_exists "
69+
+ " THEN NULL; "
70+
+ " END; "
71+
+ " EXECUTE IMMEDIATE (' "
72+
+ " CREATE TABLE " + tableName + " ( "
73+
+ " myts timestamp, p_iname VARCHAR2(40), "
74+
+ " p_short_name VARCHAR2(40), p_comments VARCHAR2(40) "
75+
+ " ) "
76+
+ " '); "
77+
+ " END; ";
78+
79+
var sqlCreateProc =
80+
" CREATE OR REPLACE PROCEDURE " + procName + "(p_iname IN VARCHAR2, "
81+
+ " p_short_name IN VARCHAR2, p_comments IN VARCHAR2, p_new_id OUT NUMBER, p_status OUT NUMBER, "
82+
+ " p_description OUT VARCHAR2) "
83+
+ " AS "
84+
+ " BEGIN "
85+
+ " p_description := p_iname || ' ' || p_short_name || ' ' || p_comments; "
86+
+ " p_new_id := 1; "
87+
+ " p_status := 2; "
88+
+ " insert into " + tableName + " values (systimestamp, p_iname, p_short_name, p_comments); "
89+
+ " END; ";
90+
91+
async.series([
92+
function(cb) {
93+
oracledb.getConnection(credential, function(err, conn) {
94+
should.not.exist(err);
95+
connection = conn;
96+
cb();
97+
});
98+
},
99+
function(cb) {
100+
connection.execute(
101+
sqlCreateTab,
102+
function(err) {
103+
should.not.exist(err);
104+
cb();
105+
}
106+
);
107+
},
108+
function(cb) {
109+
connection.execute(
110+
sqlCreateProc,
111+
function(err) {
112+
should.not.exist(err);
113+
cb();
114+
}
115+
);
116+
}
117+
], done);
118+
}) // before
119+
120+
after('drop table and procedure', function(done) {
121+
async.series([
122+
function(cb) {
123+
connection.execute(
124+
"DROP PROCEDURE " + procName,
125+
function(err) {
126+
should.not.exist(err);
127+
cb();
128+
}
129+
);
130+
},
131+
function(cb) {
132+
connection.execute(
133+
"DROP TABLE " + tableName,
134+
function(err) {
135+
should.not.exist(err);
136+
cb();
137+
}
138+
);
139+
}
140+
], done);
141+
}) // after
142+
143+
it('63.1 nested execute() functions', function(done) {
144+
145+
var pool = null,
146+
conn = null;
147+
// sql will be the same for both execute calls
148+
var procSql = "BEGIN " + procName + "(p_iname=>:p_iname, p_short_name=>:p_short_name, "
149+
+ " p_comments=>:p_comments, p_new_id=>:p_new_id, p_status=>:p_status, "
150+
+ " p_description=>:p_description); END;";
151+
152+
// Two execute() uses the same bindVar which conflicts occur
153+
var bindVar =
154+
{
155+
p_iname: "Test iname",
156+
p_short_name: "TST",
157+
p_comments: "Test comments",
158+
p_new_id: {
159+
type: oracledb.NUMBER,
160+
dir: oracledb.BIND_OUT
161+
},
162+
p_status: {
163+
type: oracledb.NUMBER,
164+
dir: oracledb.BIND_OUT
165+
},
166+
p_description: {
167+
type: oracledb.STRING,
168+
dir: oracledb.BIND_OUT
169+
}
170+
};
171+
172+
async.series([
173+
function getPool(cb) {
174+
oracledb.createPool(
175+
credential,
176+
function(err, pooling) {
177+
should.not.exist(err);
178+
pool = pooling;
179+
cb();
180+
}
181+
);
182+
},
183+
function getConn(cb) {
184+
pool.getConnection( function(err, connecting) {
185+
should.not.exist(err);
186+
conn = connecting;
187+
cb();
188+
});
189+
},
190+
function excute1(cb) {
191+
conn.execute(
192+
procSql,
193+
{
194+
p_iname: "Test iname",
195+
p_short_name: "TST",
196+
p_comments: "Test comments",
197+
p_new_id: {
198+
type: oracledb.NUMBER,
199+
dir: oracledb.BIND_OUT
200+
},
201+
p_status: {
202+
type: oracledb.NUMBER,
203+
dir: oracledb.BIND_OUT
204+
},
205+
p_description: {
206+
type: oracledb.STRING,
207+
dir: oracledb.BIND_OUT
208+
}
209+
},
210+
{ autoCommit: false },
211+
function(err, result) {
212+
should.not.exist(err);
213+
cb();
214+
}
215+
);
216+
},
217+
function execute2(cb) {
218+
conn.execute(
219+
procSql,
220+
{
221+
p_iname123: "Test iname", // specify wrong bind parameter name to cause an error
222+
p_short_name: "TST",
223+
p_comments: "Test comments",
224+
p_new_id: {
225+
type: oracledb.NUMBER,
226+
dir: oracledb.BIND_OUT
227+
},
228+
p_status: {
229+
type: oracledb.NUMBER,
230+
dir: oracledb.BIND_OUT
231+
},
232+
p_description: {
233+
type: oracledb.STRING,
234+
dir: oracledb.BIND_OUT
235+
}
236+
},
237+
{ autoCommit: false },
238+
function(err, result) {
239+
should.exist(err);
240+
// ORA-01036: illegal variable name/number
241+
(err.message).should.startWith('ORA-01036');
242+
cb();
243+
}
244+
);
245+
},
246+
function(cb) {
247+
conn.release(function(err) {
248+
should.not.exist(err);
249+
cb();
250+
});
251+
},
252+
function(cb) {
253+
pool.terminate(function(err) {
254+
should.not.exist(err);
255+
cb();
256+
});
257+
},
258+
function verifyTabContent(cb) {
259+
connection.execute(
260+
"SELECT count(*) as amount FROM " + tableName,
261+
[],
262+
{ outFormat: oracledb.OBJECT },
263+
function(err, result) {
264+
should.not.exist(err);
265+
(result.rows[0].AMOUNT).should.be.exactly(0);
266+
cb();
267+
}
268+
);
269+
}
270+
], done);
271+
})
272+
273+
})

test/list.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,3 +517,6 @@
517517
62.8 pieceSize - cannot be null
518518
62.9 pieceSize - must be a number
519519
62.10 type (read-only)
520+
521+
63. autoCommit4nestedExecutes.js
522+
63.1 nested execute() functions

0 commit comments

Comments
 (0)