2022-04-19 08:06:36 +08:00
|
|
|
/* Copyright (c) 2015, 2022, Oracle and/or its affiliates. */
|
2015-12-21 19:50:55 +08:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
*
|
2023-02-21 09:43:43 +08:00
|
|
|
* This software is dual-licensed to you under the Universal Permissive License
|
|
|
|
* (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
|
|
|
|
* 2.0 as shown at https://www.apache.org/licenses/LICENSE-2.0. You may choose
|
|
|
|
* either license.
|
2015-12-21 19:50:55 +08:00
|
|
|
*
|
2023-02-21 09:43:43 +08:00
|
|
|
* If you elect to accept the software under the Apache License, Version 2.0,
|
|
|
|
* the following applies:
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
2015-12-21 19:50:55 +08:00
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
2023-02-21 09:43:43 +08:00
|
|
|
* https://www.apache.org/licenses/LICENSE-2.0
|
2015-12-21 19:50:55 +08:00
|
|
|
*
|
2023-02-21 09:43:43 +08:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
2015-12-21 19:50:55 +08:00
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2016-03-24 14:09:53 +08:00
|
|
|
*
|
2015-12-21 19:50:55 +08:00
|
|
|
* NAME
|
|
|
|
* 63. autoCommit4nestedExecutes.js
|
|
|
|
*
|
|
|
|
* DESCRIPTION
|
2016-03-24 14:09:53 +08:00
|
|
|
* Nested executes where the 2nd execute fails used to cause an unexpected
|
|
|
|
* commit, even though the autoCommit:false setting is enabled at the
|
|
|
|
* execute() and/or oracledb level. This is github issue 269. It has
|
2015-12-21 19:50:55 +08:00
|
|
|
* been fixed in 1.4.
|
2016-03-24 14:09:53 +08:00
|
|
|
*
|
2015-12-21 19:50:55 +08:00
|
|
|
* https://github.com/oracle/node-oracledb/issues/269
|
2016-03-24 14:09:53 +08:00
|
|
|
*
|
2015-12-21 19:50:55 +08:00
|
|
|
*****************************************************************************/
|
2016-03-24 14:09:53 +08:00
|
|
|
'use strict';
|
2015-12-21 19:50:55 +08:00
|
|
|
|
2022-09-08 14:27:17 +08:00
|
|
|
const oracledb = require('oracledb');
|
|
|
|
const assert = require('assert');
|
|
|
|
const dbConfig = require('./dbconfig.js');
|
2015-12-21 19:50:55 +08:00
|
|
|
|
|
|
|
describe('63. autoCommit4nestedExecutes.js', function() {
|
2016-03-24 14:09:53 +08:00
|
|
|
|
2022-09-08 14:27:17 +08:00
|
|
|
let tableName = "nodb_issue269tab";
|
|
|
|
let procName = "issue269proc";
|
|
|
|
let connection = null;
|
2015-12-21 19:50:55 +08:00
|
|
|
|
2022-09-08 14:27:17 +08:00
|
|
|
before('prepare table and procedure', async function() {
|
2015-12-21 19:50:55 +08:00
|
|
|
|
2022-09-08 14:27:17 +08:00
|
|
|
let sqlCreateTab =
|
2016-03-24 14:09:53 +08:00
|
|
|
" BEGIN "
|
|
|
|
+ " DECLARE "
|
2016-07-08 15:05:31 +08:00
|
|
|
+ " e_table_missing EXCEPTION; "
|
|
|
|
+ " PRAGMA EXCEPTION_INIT(e_table_missing, -00942); "
|
2016-03-24 14:09:53 +08:00
|
|
|
+ " BEGIN "
|
2016-12-01 19:28:49 +08:00
|
|
|
+ " EXECUTE IMMEDIATE ('DROP TABLE " + tableName + " PURGE'); "
|
2015-12-21 19:50:55 +08:00
|
|
|
+ " EXCEPTION "
|
2016-07-08 15:05:31 +08:00
|
|
|
+ " WHEN e_table_missing "
|
2015-12-21 19:50:55 +08:00
|
|
|
+ " THEN NULL; "
|
|
|
|
+ " END; "
|
|
|
|
+ " EXECUTE IMMEDIATE (' "
|
|
|
|
+ " CREATE TABLE " + tableName + " ( "
|
|
|
|
+ " myts timestamp, p_iname VARCHAR2(40), "
|
2016-03-24 14:09:53 +08:00
|
|
|
+ " p_short_name VARCHAR2(40), p_comments VARCHAR2(40) "
|
|
|
|
+ " ) "
|
|
|
|
+ " '); "
|
|
|
|
+ " END; ";
|
2015-12-21 19:50:55 +08:00
|
|
|
|
2022-09-08 14:27:17 +08:00
|
|
|
let sqlCreateProc =
|
2015-12-21 19:50:55 +08:00
|
|
|
" CREATE OR REPLACE PROCEDURE " + procName + "(p_iname IN VARCHAR2, "
|
2016-03-24 14:09:53 +08:00
|
|
|
+ " p_short_name IN VARCHAR2, p_comments IN VARCHAR2, p_new_id OUT NUMBER, p_status OUT NUMBER, "
|
2015-12-21 19:50:55 +08:00
|
|
|
+ " p_description OUT VARCHAR2) "
|
|
|
|
+ " AS "
|
|
|
|
+ " BEGIN "
|
2016-03-24 14:09:53 +08:00
|
|
|
+ " p_description := p_iname || ' ' || p_short_name || ' ' || p_comments; "
|
2015-12-21 19:50:55 +08:00
|
|
|
+ " p_new_id := 1; "
|
|
|
|
+ " p_status := 2; "
|
|
|
|
+ " insert into " + tableName + " values (systimestamp, p_iname, p_short_name, p_comments); "
|
|
|
|
+ " END; ";
|
2016-03-24 14:09:53 +08:00
|
|
|
|
2022-09-08 14:27:17 +08:00
|
|
|
connection = await oracledb.getConnection(dbConfig);
|
|
|
|
await connection.execute(sqlCreateTab);
|
|
|
|
|
|
|
|
await connection.execute(sqlCreateProc);
|
2016-12-01 19:10:30 +08:00
|
|
|
}); // before
|
2015-12-21 19:50:55 +08:00
|
|
|
|
2022-09-08 14:27:17 +08:00
|
|
|
after('drop table and procedure', async function() {
|
|
|
|
await connection.execute("DROP PROCEDURE " + procName);
|
|
|
|
await connection.execute("DROP TABLE " + tableName + " PURGE");
|
2016-12-01 19:10:30 +08:00
|
|
|
}); // after
|
2015-12-21 19:50:55 +08:00
|
|
|
|
2022-09-08 14:27:17 +08:00
|
|
|
it('63.1 nested execute() functions', async function() {
|
2016-03-24 14:09:53 +08:00
|
|
|
|
2022-09-08 14:27:17 +08:00
|
|
|
let pool = null,
|
2016-12-01 19:10:30 +08:00
|
|
|
conn = null;
|
2022-09-08 14:27:17 +08:00
|
|
|
let result = null;
|
|
|
|
|
2016-03-24 14:09:53 +08:00
|
|
|
// sql will be the same for both execute calls
|
2022-09-08 14:27:17 +08:00
|
|
|
let procSql = "BEGIN " + procName + "(p_iname=>:p_iname, p_short_name=>:p_short_name, "
|
2015-12-21 19:50:55 +08:00
|
|
|
+ " p_comments=>:p_comments, p_new_id=>:p_new_id, p_status=>:p_status, "
|
2016-03-24 14:09:53 +08:00
|
|
|
+ " p_description=>:p_description); END;";
|
|
|
|
|
2022-09-08 14:27:17 +08:00
|
|
|
pool = await oracledb.createPool(dbConfig);
|
|
|
|
conn = await pool.getConnection();
|
|
|
|
|
|
|
|
await conn.execute(
|
|
|
|
procSql,
|
|
|
|
{
|
|
|
|
p_iname: "Test iname",
|
|
|
|
p_short_name: "TST",
|
|
|
|
p_comments: "Test comments",
|
|
|
|
p_new_id: {
|
|
|
|
type: oracledb.NUMBER,
|
|
|
|
dir: oracledb.BIND_OUT
|
|
|
|
},
|
|
|
|
p_status: {
|
|
|
|
type: oracledb.NUMBER,
|
|
|
|
dir: oracledb.BIND_OUT
|
|
|
|
},
|
|
|
|
p_description: {
|
|
|
|
type: oracledb.STRING,
|
|
|
|
dir: oracledb.BIND_OUT
|
|
|
|
}
|
2015-12-21 19:50:55 +08:00
|
|
|
},
|
2022-09-08 14:27:17 +08:00
|
|
|
{ autoCommit: false });
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
result = await conn.execute(
|
|
|
|
procSql,
|
|
|
|
{
|
|
|
|
p_iname123: "Test iname", // specify wrong bind parameter name to cause an error
|
|
|
|
p_short_name: "TST",
|
|
|
|
p_comments: "Test comments",
|
|
|
|
p_new_id: {
|
|
|
|
type: oracledb.NUMBER,
|
|
|
|
dir: oracledb.BIND_OUT
|
2015-12-21 19:50:55 +08:00
|
|
|
},
|
2022-09-08 14:27:17 +08:00
|
|
|
p_status: {
|
|
|
|
type: oracledb.NUMBER,
|
|
|
|
dir: oracledb.BIND_OUT
|
2015-12-21 19:50:55 +08:00
|
|
|
},
|
2022-09-08 14:27:17 +08:00
|
|
|
p_description: {
|
|
|
|
type: oracledb.STRING,
|
|
|
|
dir: oracledb.BIND_OUT
|
2015-12-21 19:50:55 +08:00
|
|
|
}
|
2022-09-08 14:27:17 +08:00
|
|
|
},
|
|
|
|
{ autoCommit: false });
|
|
|
|
} catch (err) {
|
|
|
|
assert(err);
|
2023-02-21 11:50:24 +08:00
|
|
|
// NJS-097: illegal variable name/number
|
|
|
|
assert.equal(err.message.substring(0, err.message.indexOf(':')), `NJS-097`);
|
2022-09-08 14:27:17 +08:00
|
|
|
}
|
2015-12-21 19:50:55 +08:00
|
|
|
|
2022-09-08 14:27:17 +08:00
|
|
|
await conn.release();
|
|
|
|
await pool.terminate();
|
|
|
|
|
|
|
|
result = await connection.execute(
|
|
|
|
"SELECT count(*) as amount FROM " + tableName,
|
|
|
|
[],
|
|
|
|
{ outFormat: oracledb.OUT_FORMAT_OBJECT });
|
|
|
|
assert.strictEqual(result.rows[0].AMOUNT, 0);
|
|
|
|
});
|
2016-12-01 19:10:30 +08:00
|
|
|
});
|