node-oracledb/test/resultSet2.js

1011 lines
26 KiB
JavaScript
Raw Normal View History

/* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. */
2015-07-20 15:56:29 +08:00
/******************************************************************************
*
* You may not use the identified files except in compliance with the Apache
* License, Version 2.0 (the "License.")
*
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0.
*
* 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.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*
2016-03-24 14:09:53 +08:00
* The node-oracledb test suite uses 'mocha', 'should' and 'async'.
2015-07-20 15:56:29 +08:00
* See LICENSE.md for relevant licenses.
*
* NAME
* 55. resultSet2.js
*
* DESCRIPTION
* Testing driver resultSet feature.
*
* NUMBERING RULE
* Test numbers follow this numbering rule:
* 1 - 20 are reserved for basic functional tests
* 21 - 50 are reserved for data type supporting tests
2016-03-24 14:09:53 +08:00
* 51 onwards are for other tests
*
2015-07-20 15:56:29 +08:00
*****************************************************************************/
2017-06-17 07:40:09 +08:00
"use strict";
var oracledb = require('oracledb');
var should = require('should');
var async = require('async');
var dbConfig = require('./dbconfig.js');
describe('55. resultSet2.js', function() {
var connection = null;
var tableName = "nodb_rs2_emp";
var rowsAmount = 300;
before('get one connection', function(done) {
oracledb.getConnection(
{
user: dbConfig.user,
password: dbConfig.password,
connectString: dbConfig.connectString
},
2017-06-14 09:54:15 +08:00
function(err, conn) {
should.not.exist(err);
connection = conn;
done();
}
);
2017-06-17 07:40:09 +08:00
});
2016-03-24 14:09:53 +08:00
2017-06-17 07:40:09 +08:00
after('release connection', function(done) {
connection.release( function(err) {
should.not.exist(err);
done();
});
});
2016-03-24 14:09:53 +08:00
2017-06-17 07:40:09 +08:00
describe('55.1 query a RDBMS function', function() {
2016-03-24 14:09:53 +08:00
2017-06-17 07:40:09 +08:00
it('55.1.1 LPAD function', function(done) {
connection.should.be.ok();
connection.execute(
2015-07-20 15:56:29 +08:00
"select lpad('a',100,'x') from dual",
[],
{ resultSet: true },
function(err, result) {
should.not.exist(err);
fetchRowFromRS(result.resultSet);
}
);
2016-03-24 14:09:53 +08:00
2017-06-17 07:40:09 +08:00
function fetchRowFromRS(rs) {
rs.getRow(function(err, row) {
should.not.exist(err);
if(row) {
2015-07-20 15:56:29 +08:00
// console.log(row);
2017-06-17 07:40:09 +08:00
row[0].length.should.be.exactly(100);
return fetchRowFromRS(rs);
} else {
rs.close(function(err) {
should.not.exist(err);
done();
});
}
});
}
});
}); // 55.1
describe('55.2 binding variables', function() {
before(function(done){
setUp(connection, tableName, done);
});
after(function(done) {
clearUp(connection, tableName, done);
});
it('55.2.1 query with one binding variable', function(done) {
connection.should.be.ok();
var rowCount = 0;
connection.execute(
2017-06-14 09:54:15 +08:00
"SELECT * FROM nodb_rs2_emp WHERE employees_id > :1",
2015-07-20 15:56:29 +08:00
[200],
{ resultSet: true },
function(err, result) {
should.not.exist(err);
// console.log(result.resultSet);
fetchRowFromRS(result.resultSet);
2016-03-24 14:09:53 +08:00
}
2015-07-20 15:56:29 +08:00
);
2016-03-24 14:09:53 +08:00
2017-06-17 07:40:09 +08:00
function fetchRowFromRS(rs) {
rs.getRow(function(err, row) {
should.not.exist(err);
if(row) {
rowCount++;
return fetchRowFromRS(rs);
} else {
rs.close(function(err) {
rowCount.should.be.exactly(100);
should.not.exist(err);
done();
});
}
});
}
});
2017-06-14 09:54:15 +08:00
2017-06-17 07:40:09 +08:00
});
2017-06-14 09:54:15 +08:00
2017-06-17 07:40:09 +08:00
describe('55.3 alternating getRow() & getRows() function', function() {
before(function(done){
setUp(connection, tableName, done);
});
2017-06-14 09:54:15 +08:00
2017-06-17 07:40:09 +08:00
after(function(done) {
clearUp(connection, tableName, done);
});
2017-06-14 09:54:15 +08:00
2017-06-17 07:40:09 +08:00
it('55.3.1 result set', function(done) {
connection.should.be.ok();
var accessCount = 0;
var numRows = 4;
var flag = 1; // 1 - getRow(); 2 - getRows(); 3 - to close resultSet.
connection.execute(
2017-06-14 09:54:15 +08:00
"SELECT * FROM nodb_rs2_emp WHERE employees_id > :1",
2015-07-20 15:56:29 +08:00
[200],
{ resultSet: true },
function(err, result) {
should.not.exist(err);
// console.log(result.resultSet);
fetchRowFromRS(result.resultSet);
2016-03-24 14:09:53 +08:00
}
2015-07-20 15:56:29 +08:00
);
2016-03-24 14:09:53 +08:00
2017-06-17 07:40:09 +08:00
function fetchRowFromRS(rs) {
if(flag === 1) {
rs.getRow(function(err, row) {
should.not.exist(err);
if(row) {
flag = 2;
accessCount++;
return fetchRowFromRS(rs);
} else {
flag = 3;
return fetchRowFromRS(rs);
}
});
}
else if(flag === 2) {
rs.getRows(numRows, function(err, rows) {
should.not.exist(err);
if(rows.length > 0) {
flag = 1;
accessCount++;
return fetchRowFromRS(rs);
} else {
flag = 3;
return fetchRowFromRS(rs);
}
});
}
else if(flag === 3) {
2015-07-20 15:56:29 +08:00
// console.log("resultSet is empty!");
2017-06-17 07:40:09 +08:00
rs.close(function(err) {
should.not.exist(err);
2015-07-20 15:56:29 +08:00
// console.log("Total access count is " + accessCount);
2017-06-17 07:40:09 +08:00
accessCount.should.be.exactly((100/(numRows + 1)) * 2);
done();
});
}
}
});
2017-06-14 09:54:15 +08:00
2017-06-17 07:40:09 +08:00
it('55.3.2 REF Cursor', function(done) {
connection.should.be.ok();
var accessCount = 0;
var numRows = 4;
var flag = 1; // 1 - getRow(); 2 - getRows(); 3 - to close resultSet.
2017-06-14 09:54:15 +08:00
2017-06-17 07:40:09 +08:00
connection.execute(
2017-06-14 09:54:15 +08:00
"BEGIN nodb_rs2_get_emp(:in, :out); END;",
2017-06-17 07:40:09 +08:00
{
in: 200,
out: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
},
2015-08-17 14:19:36 +08:00
function(err, result) {
should.not.exist(err);
fetchRowFromRS(result.outBinds.out, done);
}
);
2016-03-24 14:09:53 +08:00
2017-06-17 07:40:09 +08:00
function fetchRowFromRS(rs, cb) {
if(flag === 1) {
rs.getRow(function(err, row) {
should.not.exist(err);
if(row) {
flag = 2;
accessCount++;
return fetchRowFromRS(rs, cb);
} else {
flag = 3;
return fetchRowFromRS(rs, cb);
}
});
}
else if(flag === 2) {
rs.getRows(numRows, function(err, rows) {
should.not.exist(err);
if(rows.length > 0) {
flag = 1;
accessCount++;
return fetchRowFromRS(rs, cb);
} else {
flag = 3;
return fetchRowFromRS(rs, cb);
}
});
}
else if(flag === 3) {
2015-08-17 14:19:36 +08:00
// console.log("resultSet is empty!");
2017-06-17 07:40:09 +08:00
rs.close(function(err) {
should.not.exist(err);
2015-08-17 14:19:36 +08:00
// console.log("Total access count is " + accessCount);
2017-06-17 07:40:09 +08:00
accessCount.should.be.exactly((100/(numRows + 1)) * 2);
cb();
});
}
}
});
});
describe('55.4 release connection before close resultSet', function() {
before(function(done){
setUp(connection, tableName, done);
});
after(function(done) {
clearUp(connection, tableName, done);
});
var testConn = null;
2017-06-17 07:40:09 +08:00
beforeEach(function(done) {
oracledb.getConnection(
dbConfig,
2015-09-02 20:35:01 +08:00
function(err, conn) {
should.not.exist(err);
testConn = conn;
2015-09-02 20:35:01 +08:00
done();
}
);
2017-06-17 07:40:09 +08:00
});
function fetchRowFromRS(rs, cb) {
rs.getRow(function(err, row) {
if(row) {
return fetchRowFromRS(rs, cb);
} else {
testConn.release(function(err) {
should.exist(err);
should.strictEqual(
err.message,
"DPI-1054: connection cannot be closed when open statements or LOBs exist"
);
2017-06-17 07:40:09 +08:00
rs.close(function(err) {
should.not.exist(err);
testConn.release(cb);
2017-06-17 07:40:09 +08:00
});
});
}
});
}
2017-06-14 09:54:15 +08:00
2017-06-17 07:40:09 +08:00
it('55.4.1 result set', function(done) {
testConn.should.be.ok();
testConn.execute(
2017-06-14 09:54:15 +08:00
"SELECT * FROM nodb_rs2_emp ORDER BY employees_id",
2015-07-20 15:56:29 +08:00
[],
{ resultSet: true },
function(err, result) {
should.not.exist(err);
2015-08-17 14:19:36 +08:00
fetchRowFromRS(result.resultSet, done);
2015-07-20 15:56:29 +08:00
}
);
2017-06-17 07:40:09 +08:00
});
2016-03-24 14:09:53 +08:00
2017-06-17 07:40:09 +08:00
it('55.4.2 REF Cursor', function(done) {
testConn.should.be.ok();
testConn.execute(
2017-06-14 09:54:15 +08:00
"BEGIN nodb_rs2_get_emp(:in, :out); END;",
2017-06-17 07:40:09 +08:00
{
in: 200,
out: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
},
2015-08-17 14:19:36 +08:00
function(err, result) {
2015-07-20 15:56:29 +08:00
should.not.exist(err);
2015-08-17 14:19:36 +08:00
fetchRowFromRS(result.outBinds.out, done);
}
);
2017-06-17 07:40:09 +08:00
});
});
describe('55.5 the content of resultSet should be consistent', function() {
before(function(done){
setUp(connection, tableName, done);
});
after(function(done) {
clearUp(connection, tableName, done);
});
it('55.5.1 (1) get RS (2) modify data in that table and commit (3) check RS', function(done) {
connection.should.be.ok();
var rowsCount = 0;
var rs = false;
async.series([
function(callback) {
connection.execute(
2017-06-14 09:54:15 +08:00
"SELECT * FROM nodb_rs2_emp ORDER BY employees_id",
2015-07-20 15:56:29 +08:00
[],
{ resultSet: true },
function(err, result) {
should.not.exist(err);
rs = result.resultSet;
callback();
}
);
2017-06-17 07:40:09 +08:00
},
function(callback) {
connection.execute(
2017-06-14 09:54:15 +08:00
"TRUNCATE TABLE nodb_rs2_emp",
2015-07-20 15:56:29 +08:00
[],
{ autoCommit: true },
function(err) {
should.not.exist(err);
callback();
}
);
2017-06-17 07:40:09 +08:00
},
function(callback) {
fetchRowFromRS(rs, callback);
}
], done);
2017-06-14 09:54:15 +08:00
2017-06-17 07:40:09 +08:00
function fetchRowFromRS(rset, cb) {
rset.getRow(function(err, row) {
should.not.exist(err);
if(row) {
rowsCount++;
return fetchRowFromRS(rset, cb);
} else {
rset.close(function(err) {
should.not.exist(err);
rowsCount.should.eql(rowsAmount);
cb();
});
}
});
}
2017-06-14 09:54:15 +08:00
2017-06-17 07:40:09 +08:00
});
2017-06-14 09:54:15 +08:00
2017-06-17 07:40:09 +08:00
});
2017-06-14 09:54:15 +08:00
2017-06-17 07:40:09 +08:00
describe('55.6 access resultSet simultaneously', function() {
before(function(done){
setUp(connection, tableName, done);
});
after(function(done) {
clearUp(connection, tableName, done);
});
function fetchRowsFromRS(resultset, callback) {
var numRows = 10; // number of rows to return from each call to getRows()
resultset.getRows(numRows, function(err, rows) {
if(err) {
return callback(err);
} else {
if(rows.length > 0) {
return fetchRowsFromRS(resultset, callback);
} else {
return resultset.close(callback);
2017-06-17 07:40:09 +08:00
}
}
});
2017-06-14 09:54:15 +08:00
2017-06-17 07:40:09 +08:00
}
it('55.6.1 concurrent operations on resultSet are not allowed', function(done) {
var rset;
async.series([
function(cb) {
connection.execute(
2017-06-14 09:54:15 +08:00
"SELECT * FROM nodb_rs2_emp ORDER BY employees_id",
[],
{ resultSet: true },
function(err, result) {
2015-07-20 15:56:29 +08:00
should.not.exist(err);
2017-06-14 09:54:15 +08:00
rset = result.resultSet;
2015-07-20 15:56:29 +08:00
cb();
2016-03-24 14:09:53 +08:00
}
2017-06-14 09:54:15 +08:00
);
2017-06-17 07:40:09 +08:00
},
function(cb) {
async.parallel([
function(callback) {
fetchRowsFromRS(rset, callback);
},
function(callback) {
fetchRowsFromRS(rset, callback);
}
],
2017-06-14 09:54:15 +08:00
function(err) {
should.exist(err);
(err.message).should.startWith('NJS-017:');
// NJS-017: concurrent operations on ResultSet are not allowed
2015-08-17 14:19:36 +08:00
2017-06-14 09:54:15 +08:00
cb();
2015-08-17 14:19:36 +08:00
});
2017-06-17 07:40:09 +08:00
}
], done);
2015-09-02 20:35:01 +08:00
2017-06-17 07:40:09 +08:00
});
2015-09-02 20:35:01 +08:00
2017-06-17 07:40:09 +08:00
it('55.6.2 concurrent operation on REF Cursor are not allowed', function(done) {
2016-03-24 14:09:53 +08:00
2017-06-17 07:40:09 +08:00
var rcur;
async.series([
function(cb) {
connection.execute(
2017-06-14 09:54:15 +08:00
"BEGIN nodb_rs2_get_emp(:in, :out); END;",
2017-06-17 07:40:09 +08:00
{
in: 0,
out: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
},
2017-06-14 09:54:15 +08:00
function(err, result) {
should.not.exist(err);
rcur = result.outBinds.out;
return cb();
}
);
2017-06-17 07:40:09 +08:00
},
function(cb) {
async.parallel([
function(callback) {
fetchRowsFromRS(rcur, callback);
},
function(callback) {
fetchRowsFromRS(rcur, callback);
}
],
2017-06-14 09:54:15 +08:00
function(err) {
should.exist(err);
(err.message).should.startWith('NJS-017:');
// NJS-017: concurrent operations on ResultSet are not allowed
2016-03-24 14:09:53 +08:00
2015-08-17 14:19:36 +08:00
cb();
});
2017-06-17 07:40:09 +08:00
}
], done);
2017-06-14 09:54:15 +08:00
2017-06-17 07:40:09 +08:00
});
2017-06-14 09:54:15 +08:00
2017-06-17 07:40:09 +08:00
});
2017-06-14 09:54:15 +08:00
2017-06-17 07:40:09 +08:00
describe('55.7 getting multiple resultSets', function() {
before(function(done){
setUp(connection, tableName, done);
});
2017-06-14 09:54:15 +08:00
2017-06-17 07:40:09 +08:00
after(function(done) {
clearUp(connection, tableName, done);
});
2017-06-14 09:54:15 +08:00
2017-06-17 07:40:09 +08:00
var numRows = 10; // number of rows to return from each call to getRows()
2017-06-14 09:54:15 +08:00
2017-06-17 07:40:09 +08:00
function fetchRowFromRS(rs, cb) {
rs.getRow(function(err, row) {
should.not.exist(err);
if(row) {
return fetchRowFromRS(rs, cb);
} else {
rs.close(function(err) {
should.not.exist(err);
cb();
});
}
});
}
function fetchRowsFromRS(rs, cb) {
rs.getRows(numRows, function(err, rows) {
should.not.exist(err);
if(rows.length > 0) {
return fetchRowsFromRS(rs, cb);
} else {
rs.close(function(err) {
should.not.exist(err);
cb();
});
}
});
}
it('55.7.1 can access multiple resultSet on one connection', function(done) {
connection.should.be.ok();
async.parallel([
function(callback) {
connection.execute(
2017-06-14 09:54:15 +08:00
"SELECT * FROM nodb_rs2_emp ORDER BY employees_id",
2015-07-20 15:56:29 +08:00
[],
{ resultSet: true },
function(err, result) {
should.not.exist(err);
fetchRowFromRS(result.resultSet, callback);
}
);
2017-06-17 07:40:09 +08:00
},
function(callback) {
connection.execute(
2017-06-14 09:54:15 +08:00
"SELECT * FROM nodb_rs2_emp ORDER BY employees_id",
2015-07-20 15:56:29 +08:00
[],
{ resultSet: true },
function(err, result) {
should.not.exist(err);
fetchRowsFromRS(result.resultSet, callback);
}
);
2017-06-17 07:40:09 +08:00
}
], function(err) {
should.not.exist(err);
done();
});
});
2017-06-14 09:54:15 +08:00
2017-06-17 07:40:09 +08:00
it('55.7.2 can access multiple REF Cursor', function(done) {
connection.should.be.ok();
2017-06-14 09:54:15 +08:00
2017-06-17 07:40:09 +08:00
async.parallel([
function(callback) {
connection.execute(
2017-06-14 09:54:15 +08:00
"BEGIN nodb_rs2_get_emp(:in, :out); END;",
2017-06-17 07:40:09 +08:00
{
in: 200,
out: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
},
2015-08-17 14:19:36 +08:00
function(err, result) {
should.not.exist(err);
fetchRowFromRS(result.outBinds.out, callback);
}
);
2017-06-17 07:40:09 +08:00
},
function(callback) {
connection.execute(
2017-06-14 09:54:15 +08:00
"BEGIN nodb_rs2_get_emp(:in, :out); END;",
2017-06-17 07:40:09 +08:00
{
in: 100,
out: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
},
2015-08-17 14:19:36 +08:00
function(err, result) {
should.not.exist(err);
fetchRowsFromRS(result.outBinds.out, callback);
}
);
2017-06-17 07:40:09 +08:00
}
], function(err) {
should.not.exist(err);
done();
});
});
});
describe('55.8 Negative - resultSet is only for query statement', function() {
before(function(done){
setUp(connection, tableName, done);
});
after(function(done) {
clearUp(connection, tableName, done);
});
it('55.8.1 resultSet cannot be returned for non-query statements', function(done) {
connection.should.be.ok();
connection.execute(
2017-06-14 09:54:15 +08:00
"UPDATE nodb_rs2_emp SET employees_name = 'Alan' WHERE employees_id = 100",
2015-08-17 14:19:36 +08:00
[],
{ resultSet: true },
2017-06-14 09:54:15 +08:00
function(err) {
2015-08-17 14:19:36 +08:00
should.exist(err);
// console.log(err);
err.message.should.startWith('NJS-019:');
2015-08-17 14:19:36 +08:00
done();
}
);
2016-03-24 14:09:53 +08:00
2017-06-17 07:40:09 +08:00
});
});
2016-03-24 14:09:53 +08:00
2017-06-17 07:40:09 +08:00
describe('55.9 test querying a PL/SQL function', function() {
before(function(done){
setUp(connection, tableName, done);
});
2015-09-02 20:35:01 +08:00
2017-06-17 07:40:09 +08:00
after(function(done) {
clearUp(connection, tableName, done);
});
2015-09-02 20:35:01 +08:00
2017-06-17 07:40:09 +08:00
it('55.9.1 ', function(done) {
var proc =
2017-06-14 09:54:15 +08:00
"CREATE OR REPLACE FUNCTION nodb_rs2_testfunc RETURN VARCHAR2 \
2015-08-17 14:19:36 +08:00
IS \
emp_name VARCHAR2(20); \
BEGIN \
SELECT 'Clark Kent' INTO emp_name FROM dual; \
RETURN emp_name; \
END; ";
2016-03-24 14:09:53 +08:00
2017-06-17 07:40:09 +08:00
async.series([
function(callback) {
connection.execute(
2015-08-17 14:19:36 +08:00
proc,
function(err) {
should.not.exist(err);
callback();
}
);
2017-06-17 07:40:09 +08:00
},
function(callback) {
connection.execute(
2017-06-14 09:54:15 +08:00
"SELECT nodb_rs2_testfunc FROM dual",
2015-08-17 14:19:36 +08:00
[],
{ resultSet: true },
function(err, result) {
should.not.exist(err);
2017-06-14 09:54:15 +08:00
(result.resultSet.metaData[0].name).should.eql('NODB_RS2_TESTFUNC');
2015-08-17 14:19:36 +08:00
fetchRowFromRS(result.resultSet, callback);
}
);
2017-06-17 07:40:09 +08:00
},
function(callback) {
connection.execute(
2017-06-14 09:54:15 +08:00
"DROP FUNCTION nodb_rs2_testfunc",
function(err) {
2015-08-17 14:19:36 +08:00
should.not.exist(err);
callback();
}
);
2017-06-17 07:40:09 +08:00
}
], done);
2017-06-14 09:54:15 +08:00
2017-06-17 07:40:09 +08:00
function fetchRowFromRS(rs, cb) {
rs.getRow(function(err, row) {
should.not.exist(err);
if(row) {
row[0].should.eql('Clark Kent');
return fetchRowFromRS(rs, cb);
} else {
rs.close(function(err) {
should.not.exist(err);
cb();
});
}
});
}
});
});
2017-06-14 09:54:15 +08:00
2017-06-17 07:40:09 +08:00
describe('55.10 calls getRows() once and then close RS before getting more rows', function() {
before(function(done){
setUp(connection, tableName, done);
});
after(function(done) {
clearUp(connection, tableName, done);
});
2017-06-14 09:54:15 +08:00
2017-06-17 07:40:09 +08:00
it('55.10.1 ', function(done) {
connection.should.be.ok();
var numRows = 10;
2017-06-14 09:54:15 +08:00
2017-06-17 07:40:09 +08:00
connection.execute(
2017-06-14 09:54:15 +08:00
"SELECT * FROM nodb_rs2_emp ORDER BY employees_id",
2015-07-20 15:56:29 +08:00
[],
{ resultSet: true },
function(err, result) {
2015-08-17 14:19:36 +08:00
should.not.exist(err);
result.resultSet.getRows(
2016-03-24 14:09:53 +08:00
numRows,
2017-06-14 09:54:15 +08:00
function(err) {
2016-03-24 14:09:53 +08:00
should.not.exist(err);
2015-08-17 14:19:36 +08:00
result.resultSet.close(function(err) {
should.not.exist(err);
2017-06-17 07:40:09 +08:00
fetchRowsFromRS(result.resultSet, numRows, done);
2015-08-17 14:19:36 +08:00
});
}
);
2015-07-20 15:56:29 +08:00
}
);
2017-06-17 07:40:09 +08:00
2017-06-19 18:53:49 +08:00
function fetchRowsFromRS(rs, numRows, done) {
rs.getRows(numRows, function(err) {
should.exist(err);
err.message.should.startWith('NJS-018:'); // invalid result set
done();
});
}
});
});
2016-03-24 14:09:53 +08:00
2017-06-17 07:40:09 +08:00
describe('55.11 result set with unsupported data types', function() {
it('55.11.1 INTERVAL YEAR TO MONTH data type', function(done) {
connection.execute(
2017-06-14 09:54:15 +08:00
"SELECT dummy, to_yminterval('1-3') FROM dual",
2015-08-17 14:19:36 +08:00
[],
{ resultSet: true },
function(err, result) {
should.strictEqual(
err.message,
"NJS-010: unsupported data type 2016 in column 2"
);
2017-06-14 09:54:15 +08:00
should.not.exist(result);
done();
2015-08-17 14:19:36 +08:00
}
2016-03-24 14:09:53 +08:00
);
2017-06-17 07:40:09 +08:00
});
2015-07-20 15:56:29 +08:00
2017-06-17 07:40:09 +08:00
}); // 55.11
2016-03-24 14:09:53 +08:00
2017-06-17 07:40:09 +08:00
describe('55.12 bind a cursor BIND_INOUT', function() {
2015-12-21 20:01:45 +08:00
2017-06-17 07:40:09 +08:00
before('prepare table nodb_rs2_emp', function(done) {
setUp(connection, tableName, done);
});
2015-12-21 20:01:45 +08:00
2017-06-17 07:40:09 +08:00
after('drop table', function(done) {
clearUp(connection, tableName, done);
});
2017-06-14 09:54:15 +08:00
2017-06-17 07:40:09 +08:00
it('55.12.1 has not supported binding a cursor with BIND_INOUT', function(done) {
var proc =
2017-06-14 09:54:15 +08:00
"CREATE OR REPLACE PROCEDURE nodb_rs2_get_emp_inout (p_in IN NUMBER, p_out IN OUT SYS_REFCURSOR) \
AS \
BEGIN \
OPEN p_out FOR \
2017-06-14 09:54:15 +08:00
SELECT * FROM nodb_rs2_emp \
WHERE employees_id > p_in; \
2016-03-24 14:09:53 +08:00
END; ";
2017-06-17 07:40:09 +08:00
async.series([
function(callback) {
connection.execute(
proc,
function(err) {
should.not.exist(err);
callback();
}
);
2017-06-17 07:40:09 +08:00
},
function(callback) {
connection.execute(
2017-06-14 09:54:15 +08:00
"BEGIN nodb_rs2_get_emp_inout(:in, :out); END;",
2017-06-17 07:40:09 +08:00
{
in: 200,
out: { type: oracledb.CURSOR, dir: oracledb.BIND_INOUT }
},
2017-06-14 09:54:15 +08:00
function(err) {
should.exist(err);
(err.message).should.startWith('NJS-007:');
// NJS-007: invalid value for "type" in parameter 2
callback();
}
);
2017-06-17 07:40:09 +08:00
},
function(callback) {
connection.execute(
2017-06-14 09:54:15 +08:00
"DROP PROCEDURE nodb_rs2_get_emp_inout",
function(err) {
should.not.exist(err);
callback();
}
);
2017-06-17 07:40:09 +08:00
}
], done);
});
2016-03-24 14:09:53 +08:00
2017-06-17 07:40:09 +08:00
}); // 55.12
2015-09-02 20:35:01 +08:00
2017-06-17 07:40:09 +08:00
describe('55.13 Invalid Ref Cursor', function() {
var proc =
2016-03-24 14:09:53 +08:00
"CREATE OR REPLACE PROCEDURE get_invalid_refcur ( p OUT SYS_REFCURSOR) " +
2015-09-02 20:35:01 +08:00
" AS " +
2016-03-24 14:09:53 +08:00
" BEGIN " +
" NULL; " +
2017-06-14 09:54:15 +08:00
" END;";
2017-06-17 07:40:09 +08:00
before(function(done){
async.series([
function(callback) {
setUp(connection, tableName, callback);
},
function(callback) {
connection.execute(
2015-09-02 20:35:01 +08:00
proc,
function(err) {
should.not.exist(err);
callback();
}
);
2017-06-17 07:40:09 +08:00
}
], done);
});
2017-06-14 09:54:15 +08:00
2017-06-17 07:40:09 +08:00
after(function(done) {
async.series([
function(callback) {
connection.execute(
2015-09-02 20:35:01 +08:00
"DROP PROCEDURE get_invalid_refcur",
function(err) {
should.not.exist(err);
callback();
}
);
2017-06-17 07:40:09 +08:00
},
function(callback) {
clearUp(connection, tableName, callback);
}
], done);
});
2016-03-24 14:09:53 +08:00
2017-06-17 07:40:09 +08:00
it('55.13.1 ', function (done ) {
connection.should.be.ok();
2015-09-02 20:35:01 +08:00
2017-06-17 07:40:09 +08:00
connection.execute (
2015-09-02 20:35:01 +08:00
"BEGIN get_invalid_refcur ( :p ); END; ",
2017-06-17 07:40:09 +08:00
{
p : { type : oracledb.CURSOR, dir : oracledb.BIND_OUT }
},
2017-06-14 09:54:15 +08:00
function ( err ) {
should.exist ( err );
done();
2015-09-02 20:35:01 +08:00
}
);
2017-06-17 07:40:09 +08:00
}); // 55.13.1
}); // 55.13
2015-09-02 20:35:01 +08:00
2017-06-17 07:40:09 +08:00
});
2015-09-02 20:35:01 +08:00
/********************* Helper functions *************************/
2017-06-17 07:40:09 +08:00
function setUp(connection, tableName, done)
2015-09-02 20:35:01 +08:00
{
2017-06-17 07:40:09 +08:00
async.series([
function(callback) {
createTable(connection, tableName, callback);
},
function(callback) {
insertData(connection, tableName, callback);
},
function(callback) {
createProc1(connection, tableName, callback);
}
], done);
}
function clearUp(connection, tableName, done)
2015-09-02 20:35:01 +08:00
{
2017-06-17 07:40:09 +08:00
async.series([
function(callback) {
dropProc1(connection, callback);
},
function(callback) {
dropTable(connection, tableName, callback);
}
], done);
}
function createTable(connection, tableName, done)
2015-09-02 20:35:01 +08:00
{
2017-06-17 07:40:09 +08:00
var sqlCreate =
2016-03-24 14:09:53 +08:00
"BEGIN " +
2015-09-02 20:35:01 +08:00
" DECLARE " +
2017-06-14 09:54:15 +08:00
" e_table_missing EXCEPTION; " +
" PRAGMA EXCEPTION_INIT(e_table_missing, -00942); " +
2015-09-02 20:35:01 +08:00
" BEGIN " +
2017-06-14 09:54:15 +08:00
" EXECUTE IMMEDIATE ('DROP TABLE " + tableName + " PURGE'); " +
2015-09-02 20:35:01 +08:00
" EXCEPTION " +
2017-06-14 09:54:15 +08:00
" WHEN e_table_missing " +
2015-09-02 20:35:01 +08:00
" THEN NULL; " +
" END; " +
" EXECUTE IMMEDIATE (' " +
" CREATE TABLE " + tableName +" ( " +
2016-03-24 14:09:53 +08:00
" employees_id NUMBER(10), " +
2015-09-02 20:35:01 +08:00
" employee_name VARCHAR2(20) " +
" )" +
2016-03-24 14:09:53 +08:00
" '); " +
2015-09-02 20:35:01 +08:00
"END; ";
2017-06-17 07:40:09 +08:00
connection.execute(
2015-09-02 20:35:01 +08:00
sqlCreate,
function(err) {
should.not.exist(err);
done();
}
);
2017-06-17 07:40:09 +08:00
}
2015-09-02 20:35:01 +08:00
2017-06-17 07:40:09 +08:00
function dropTable(connection, tableName, done)
2015-09-02 20:35:01 +08:00
{
2017-06-17 07:40:09 +08:00
connection.execute(
2017-06-14 09:54:15 +08:00
'DROP TABLE ' + tableName + ' PURGE',
2015-09-02 20:35:01 +08:00
function(err) {
should.not.exist(err);
done();
}
);
2017-06-17 07:40:09 +08:00
}
2015-09-02 20:35:01 +08:00
2017-06-17 07:40:09 +08:00
function insertData(connection, tableName, done)
2016-03-24 14:09:53 +08:00
{
2017-06-17 07:40:09 +08:00
var sqlInsert =
2016-03-24 14:09:53 +08:00
"DECLARE " +
" x NUMBER := 0; " +
" n VARCHAR2(20); " +
2015-09-02 20:35:01 +08:00
"BEGIN " +
" FOR i IN 1..300 LOOP " +
2016-03-24 14:09:53 +08:00
" x := x + 1; " +
" n := 'staff ' || x; " +
" INSERT INTO " + tableName + " VALUES (x, n); " +
2015-09-02 20:35:01 +08:00
" END LOOP; " +
"END; ";
2016-03-24 14:09:53 +08:00
2017-06-17 07:40:09 +08:00
connection.execute(
2015-09-02 20:35:01 +08:00
sqlInsert,
2016-03-24 14:09:53 +08:00
[],
2015-09-02 20:35:01 +08:00
{ autoCommit: true },
function(err) {
should.not.exist(err);
done();
}
);
2017-06-17 07:40:09 +08:00
}
2015-09-02 20:35:01 +08:00
2017-06-17 07:40:09 +08:00
function createProc1(connection, tableName, done)
2015-09-02 20:35:01 +08:00
{
2017-06-17 07:40:09 +08:00
var sqlProc =
2017-06-14 09:54:15 +08:00
"CREATE OR REPLACE PROCEDURE nodb_rs2_get_emp (p_in IN NUMBER, p_out OUT SYS_REFCURSOR) " +
2016-03-24 14:09:53 +08:00
" AS " +
" BEGIN " +
" OPEN p_out FOR " +
" SELECT * FROM " + tableName + " WHERE employees_id > p_in; " +
2015-09-02 20:35:01 +08:00
" END; ";
2017-06-17 07:40:09 +08:00
connection.execute(
2015-09-02 20:35:01 +08:00
sqlProc,
2016-03-24 14:09:53 +08:00
[],
2015-09-02 20:35:01 +08:00
{ autoCommit: true },
function(err) {
should.not.exist(err);
done();
}
);
2017-06-17 07:40:09 +08:00
}
2015-09-02 20:35:01 +08:00
2017-06-17 07:40:09 +08:00
function dropProc1(connection, done)
2015-09-02 20:35:01 +08:00
{
2017-06-17 07:40:09 +08:00
connection.execute(
2017-06-14 09:54:15 +08:00
'DROP PROCEDURE nodb_rs2_get_emp',
2015-09-02 20:35:01 +08:00
function(err) {
should.not.exist(err);
done();
}
);
2017-06-17 07:40:09 +08:00
}