node-oracledb/test/resultSet2.js

1058 lines
27 KiB
JavaScript
Raw Normal View History

/* Copyright (c) 2015, 2016, 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
*****************************************************************************/
2015-08-17 14:19:36 +08:00
"use strict";
2015-07-20 15:56:29 +08:00
var oracledb = require('oracledb');
var should = require('should');
var async = require('async');
var dbConfig = require('./dbconfig.js');
2015-07-20 15:56:29 +08:00
2015-08-17 14:19:36 +08:00
describe('55. resultSet2.js', function() {
2015-07-20 15:56:29 +08:00
2015-09-02 20:35:01 +08:00
var connection = null;
var tableName = "nodb_employees";
2015-09-02 20:35:01 +08:00
var rowsAmount = 300;
before('get one connection', function(done) {
2016-05-16 07:57:53 +08:00
oracledb.getConnection(dbConfig, function(err, conn) {
2015-09-02 20:35:01 +08:00
should.not.exist(err);
connection = conn;
done();
});
})
2016-03-24 14:09:53 +08:00
2015-09-02 20:35:01 +08:00
after('release connection', function(done) {
connection.release( function(err) {
should.not.exist(err);
done();
});
})
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
describe('55.1 query a RDBMS function', function() {
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
it('55.1.1 LPAD function', function(done) {
connection.should.be.ok;
connection.execute(
"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
2015-07-20 15:56:29 +08:00
function fetchRowFromRS(rs) {
rs.getRow(function(err, row) {
should.not.exist(err);
if(row) {
// console.log(row);
row[0].length.should.be.exactly(100);
return fetchRowFromRS(rs);
} else {
rs.close(function(err) {
should.not.exist(err);
done();
});
}
});
}
})
2015-09-02 20:35:01 +08:00
}) // 55.1
2016-03-24 14:09:53 +08:00
describe('55.2 binding variables', function() {
2015-09-02 20:35:01 +08:00
before(function(done){
setUp(connection, tableName, done);
})
after(function(done) {
clearUp(connection, tableName, done);
})
2015-07-20 15:56:29 +08:00
it('55.2.1 query with one binding variable', function(done) {
connection.should.be.ok;
var rowCount = 0;
connection.execute(
"SELECT * FROM nodb_employees 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
2015-07-20 15:56:29 +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();
});
}
});
}
})
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
})
2016-03-24 14:09:53 +08:00
2015-08-17 14:19:36 +08:00
describe('55.3 alternating getRow() & getRows() function', function() {
2015-09-02 20:35:01 +08:00
before(function(done){
setUp(connection, tableName, done);
})
after(function(done) {
clearUp(connection, tableName, done);
})
2015-08-17 14:19:36 +08:00
it('55.3.1 result set', function(done) {
2015-07-20 15:56:29 +08:00
connection.should.be.ok;
var accessCount = 0;
var numRows = 4;
var flag = 1; // 1 - getRow(); 2 - getRows(); 3 - to close resultSet.
connection.execute(
"SELECT * FROM nodb_employees 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
2015-07-20 15:56:29 +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) {
// console.log("resultSet is empty!");
rs.close(function(err) {
should.not.exist(err);
// console.log("Total access count is " + accessCount);
accessCount.should.be.exactly((100/(numRows + 1)) * 2);
done();
});
2016-03-24 14:09:53 +08:00
}
2015-07-20 15:56:29 +08:00
}
})
2016-03-24 14:09:53 +08:00
2015-08-17 14:19:36 +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.
2016-03-24 14:09:53 +08:00
2015-08-17 14:19:36 +08:00
connection.execute(
"BEGIN get_emp_rs(:in, :out); END;",
{
in: 200,
out: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
},
function(err, result) {
should.not.exist(err);
fetchRowFromRS(result.outBinds.out, done);
}
);
2016-03-24 14:09:53 +08:00
2015-08-17 14:19:36 +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) {
// console.log("resultSet is empty!");
rs.close(function(err) {
should.not.exist(err);
// console.log("Total access count is " + accessCount);
accessCount.should.be.exactly((100/(numRows + 1)) * 2);
cb();
});
2016-03-24 14:09:53 +08:00
}
2015-08-17 14:19:36 +08:00
}
})
2015-07-20 15:56:29 +08:00
})
2016-03-24 14:09:53 +08:00
2015-08-17 14:19:36 +08:00
describe('55.4 release connection before close resultSet', function() {
2015-09-02 20:35:01 +08:00
before(function(done){
setUp(connection, tableName, done);
})
after(function(done) {
clearUp(connection, tableName, done);
})
beforeEach(function(done) {
oracledb.getConnection(
2016-05-16 07:57:53 +08:00
dbConfig,
2015-09-02 20:35:01 +08:00
function(err, conn) {
should.not.exist(err);
conn2 = conn;
done();
}
);
})
2015-07-20 15:56:29 +08:00
var conn2 = false;
2015-08-17 14:19:36 +08:00
function fetchRowFromRS(rs, cb) {
2015-09-02 20:21:53 +08:00
2015-08-17 14:19:36 +08:00
rs.getRow(function(err, row) {
if(row) {
return fetchRowFromRS(rs, cb);
} else {
conn2.release(function(err) {
should.not.exist(err);
try {
rs.close(function() {});
} catch (err) {
2015-08-17 14:19:36 +08:00
should.exist(err);
err.message.should.startWith('NJS-018:'); // invalid result set
2015-08-17 14:19:36 +08:00
cb();
};
2015-08-17 14:19:36 +08:00
});
}
});
}
2016-03-24 14:09:53 +08:00
2015-08-17 14:19:36 +08:00
it('55.4.1 result set', function(done) {
2015-07-20 15:56:29 +08:00
conn2.should.be.ok;
conn2.execute(
"SELECT * FROM nodb_employees 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
}
);
2015-08-17 14:19:36 +08:00
})
2016-03-24 14:09:53 +08:00
2015-08-17 14:19:36 +08:00
it('55.4.2 REF Cursor', function(done) {
conn2.should.be.ok;
2016-03-24 14:09:53 +08:00
2015-08-17 14:19:36 +08:00
conn2.execute(
"BEGIN get_emp_rs(:in, :out); END;",
{
in: 200,
out: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
},
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);
}
);
2015-07-20 15:56:29 +08:00
})
})
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
describe('55.5 the content of resultSet should be consistent', function() {
2015-09-02 20:35:01 +08:00
before(function(done){
setUp(connection, tableName, done);
})
after(function(done) {
clearUp(connection, tableName, done);
})
2015-07-20 15:56:29 +08:00
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(
"SELECT * FROM nodb_employees 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();
}
);
},
function(callback) {
connection.execute(
"TRUNCATE TABLE nodb_employees",
2015-07-20 15:56:29 +08:00
[],
{ autoCommit: true },
function(err) {
should.not.exist(err);
callback();
}
);
},
function(callback) {
fetchRowFromRS(rs, callback);
2016-03-24 14:09:53 +08:00
}
2015-07-20 15:56:29 +08:00
], done);
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
function fetchRowFromRS(rset, cb) {
2015-08-17 14:19:36 +08:00
rset.getRow(function(err, row) {
2015-07-20 15:56:29 +08:00
should.not.exist(err);
if(row) {
rowsCount++;
return fetchRowFromRS(rset, cb);
} else {
2015-08-17 14:19:36 +08:00
rset.close(function(err) {
2015-07-20 15:56:29 +08:00
should.not.exist(err);
rowsCount.should.eql(rowsAmount);
cb();
});
}
});
}
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
})
2015-08-17 14:19:36 +08:00
2015-07-20 15:56:29 +08:00
})
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
describe('55.6 access resultSet simultaneously', function() {
2015-09-02 20:35:01 +08:00
before(function(done){
setUp(connection, tableName, done);
})
after(function(done) {
clearUp(connection, tableName, done);
})
2015-08-17 14:19:36 +08:00
var numRows = 10; // number of rows to return from each call to getRows()
2016-03-24 14:09:53 +08:00
2015-08-17 14:19:36 +08:00
function fetchRowFromRS(rs, cb) {
rs.getRow(function(err, row) {
if(err) {
cb(err);
return;
} else {
if(row) {
return fetchRowFromRS(rs, cb);
} else {
cb();
}
2016-03-24 14:09:53 +08:00
}
2015-08-17 14:19:36 +08:00
});
}
2016-03-24 14:09:53 +08:00
2015-08-17 14:19:36 +08:00
function fetchRowsFromRS(rs, cb) {
rs.getRows(numRows, function(err, rows) {
if(err) {
cb(err);
return;
} else {
if(rows.length > 0) {
return fetchRowsFromRS(rs, cb);
} else {
cb();
}
2016-03-24 14:09:53 +08:00
}
2015-08-17 14:19:36 +08:00
});
}
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
it('55.6.1 concurrent operations on resultSet are not allowed', function(done) {
connection.should.be.ok;
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
connection.execute(
"SELECT * FROM nodb_employees ORDER BY employees_id",
2015-07-20 15:56:29 +08:00
[],
{ resultSet: true },
function(err, result) {
should.not.exist(err);
async.parallel([
function(callback) {
fetchRowFromRS(result.resultSet, callback);
},
function(callback) {
fetchRowsFromRS(result.resultSet, callback);
}
], function(err) {
if(err) {
// console.log(err);
err.message.should.startWith('NJS-017:');
2015-07-20 15:56:29 +08:00
result.resultSet.close(function(err) {
done();
});
} else {
result.resultSet.close(function(error) {
should.not.exist(error);
done();
});
2016-03-24 14:09:53 +08:00
}
2015-07-20 15:56:29 +08:00
});
}
2016-03-24 14:09:53 +08:00
);
2015-08-17 14:19:36 +08:00
})
2016-03-24 14:09:53 +08:00
2015-08-17 14:19:36 +08:00
it('55.6.2 concurrent operation on REF Cursor are not allowed', function(done) {
connection.should.be.ok;
connection.execute(
"BEGIN get_emp_rs(:in, :out); END;",
{
in: 0,
out: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
2016-03-24 14:09:53 +08:00
},
2015-08-17 14:19:36 +08:00
function(err, result) {
should.not.exist(err);
async.parallel([
function(callback) {
fetchRowFromRS(result.outBinds.out, callback);
},
function(callback) {
fetchRowsFromRS(result.outBinds.out, callback);
2015-07-20 15:56:29 +08:00
}
2015-08-17 14:19:36 +08:00
], function(err) {
if(err) {
// console.log(err);
(err.message).should.startWith('NJS-017:');
2015-08-17 14:19:36 +08:00
result.outBinds.out.close(function(err) {
done();
});
2015-07-20 15:56:29 +08:00
} else {
2015-08-17 14:19:36 +08:00
result.outBinds.out.close(function(error) {
should.not.exist(error);
done();
});
2016-03-24 14:09:53 +08:00
}
2015-08-17 14:19:36 +08:00
});
}
);
2015-07-20 15:56:29 +08:00
})
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
})
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
describe('55.7 getting multiple resultSets', function() {
2015-09-02 20:35:01 +08:00
before(function(done){
setUp(connection, tableName, done);
})
after(function(done) {
clearUp(connection, tableName, done);
})
2015-08-17 14:19:36 +08:00
var numRows = 10; // number of rows to return from each call to getRows()
2016-03-24 14:09:53 +08:00
2015-08-17 14:19:36 +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();
});
}
});
}
2016-03-24 14:09:53 +08:00
2015-08-17 14:19:36 +08:00
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();
});
2016-03-24 14:09:53 +08:00
}
2015-08-17 14:19:36 +08:00
});
}
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
it('55.7.1 can access multiple resultSet on one connection', function(done) {
connection.should.be.ok;
async.parallel([
function(callback) {
connection.execute(
"SELECT * FROM nodb_employees 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);
}
);
},
function(callback) {
connection.execute(
"SELECT * FROM nodb_employees 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);
}
);
}
], function(err) {
should.not.exist(err);
done();
});
2015-08-17 14:19:36 +08:00
})
2016-03-24 14:09:53 +08:00
2015-08-17 14:19:36 +08:00
it('55.7.2 can access multiple REF Cursor', function(done) {
connection.should.be.ok;
2016-03-24 14:09:53 +08:00
2015-08-17 14:19:36 +08:00
async.parallel([
function(callback) {
connection.execute(
"BEGIN get_emp_rs(:in, :out); END;",
{
in: 200,
out: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
2016-03-24 14:09:53 +08:00
},
2015-08-17 14:19:36 +08:00
function(err, result) {
should.not.exist(err);
fetchRowFromRS(result.outBinds.out, callback);
}
);
},
function(callback) {
connection.execute(
"BEGIN get_emp_rs(:in, :out); END;",
{
in: 100,
out: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
2016-03-24 14:09:53 +08:00
},
2015-08-17 14:19:36 +08:00
function(err, result) {
should.not.exist(err);
fetchRowsFromRS(result.outBinds.out, callback);
}
);
}
], function(err) {
should.not.exist(err);
done();
});
})
})
2016-03-24 14:09:53 +08:00
2015-08-17 14:19:36 +08:00
describe('55.8 Negative - resultSet is only for query statement', function() {
2015-09-02 20:35:01 +08:00
before(function(done){
setUp(connection, tableName, done);
})
after(function(done) {
clearUp(connection, tableName, done);
})
2015-08-17 14:19:36 +08:00
it('55.8.1 resultSet cannot be returned for non-query statements', function(done) {
connection.should.be.ok;
connection.execute(
"UPDATE nodb_employees SET employees_name = 'Alan' WHERE employees_id = 100",
2015-08-17 14:19:36 +08:00
[],
{ resultSet: true },
function(err, result) {
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
2015-08-17 14:19:36 +08:00
})
})
2016-03-24 14:09:53 +08:00
2015-08-17 14:19:36 +08:00
describe('55.9 test querying a PL/SQL function', function() {
2015-09-02 20:35:01 +08:00
before(function(done){
setUp(connection, tableName, done);
})
after(function(done) {
clearUp(connection, tableName, done);
})
2015-08-17 14:19:36 +08:00
it('55.9.1 ', function(done) {
2016-03-24 14:09:53 +08:00
var proc =
"CREATE OR REPLACE FUNCTION nodb_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
2015-08-17 14:19:36 +08:00
async.series([
function(callback) {
connection.execute(
proc,
function(err) {
should.not.exist(err);
callback();
}
);
},
function(callback) {
connection.execute(
"SELECT nodb_testfunc FROM dual",
2015-08-17 14:19:36 +08:00
[],
{ resultSet: true },
function(err, result) {
should.not.exist(err);
(result.resultSet.metaData[0].name).should.eql('NODB_TESTFUNC');
2015-08-17 14:19:36 +08:00
fetchRowFromRS(result.resultSet, callback);
}
);
},
function(callback) {
connection.execute(
"DROP FUNCTION nodb_testfunc",
2015-08-17 14:19:36 +08:00
function(err, result) {
should.not.exist(err);
callback();
}
);
}
], done);
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
function fetchRowFromRS(rs, cb) {
rs.getRow(function(err, row) {
should.not.exist(err);
if(row) {
2015-08-17 14:19:36 +08:00
row[0].should.eql('Clark Kent');
2015-07-20 15:56:29 +08:00
return fetchRowFromRS(rs, cb);
} else {
rs.close(function(err) {
should.not.exist(err);
cb();
});
}
});
}
})
})
2016-03-24 14:09:53 +08:00
2015-08-17 14:19:36 +08:00
describe('55.10 calls getRows() once and then close RS before getting more rows', function() {
2015-09-02 20:35:01 +08:00
before(function(done){
setUp(connection, tableName, done);
})
after(function(done) {
clearUp(connection, tableName, done);
})
2015-08-17 14:19:36 +08:00
it('55.10.1 ', function(done) {
2015-07-20 15:56:29 +08:00
connection.should.be.ok;
2015-08-17 14:19:36 +08:00
var numRows = 10;
var closeRS = true;
2015-07-20 15:56:29 +08:00
connection.execute(
"SELECT * FROM nodb_employees 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,
2015-08-17 14:19:36 +08:00
function(err, rows) {
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);
try {
result.resultSet.getRows(numRows, function() {});
} catch (err) {
should.exist(err);
err.message.should.startWith('NJS-018:');
// invalid result set
done();
}
2015-08-17 14:19:36 +08:00
});
}
);
2015-07-20 15:56:29 +08:00
}
);
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
})
})
2017-06-14 06:16:22 +08:00
describe.skip('55.11 result set with unsupported data types', function() {
2016-03-24 14:09:53 +08:00
2015-08-17 14:19:36 +08:00
var sql2 = "SELECT dummy, rowid FROM dual";
2016-03-24 14:09:53 +08:00
2015-08-17 14:19:36 +08:00
function fetchOneRowFromRS(rs, cb) {
rs.getRow(function(err, row) {
2016-03-24 14:09:53 +08:00
/* Currently, even if the driver doesn't support certain data type
2015-08-17 14:19:36 +08:00
* the result set can still be created.
2016-03-24 14:09:53 +08:00
*/
2015-08-17 14:19:36 +08:00
// Error at accessing RS
2015-09-25 16:33:04 +08:00
should.exist(err);
2015-08-17 14:19:36 +08:00
if(err) {
2016-03-24 14:09:53 +08:00
// console.error("Error at accessing RS: " + err.message);
2015-08-17 14:19:36 +08:00
// NJS-010: unsupported data type in select list
(err.message).should.startWith('NJS-010:');
2015-08-17 14:19:36 +08:00
rs.close( function(err) {
should.not.exist(err);
cb();
});
} else if(row) {
console.log(row);
fetchOneRowFromRS(rs, cb);
} else {
rs.close( function(err) {
should.not.exist(err);
cb();
});
}
});
}
2015-07-20 15:56:29 +08:00
2017-06-14 06:16:22 +08:00
it('55.11.1 ROWID data type', function(done) {
2015-08-17 14:19:36 +08:00
connection.execute(
sql2,
[],
{ resultSet: true },
function(err, result) {
should.not.exist(err);
fetchOneRowFromRS(result.resultSet, done);
}
2016-03-24 14:09:53 +08:00
);
2015-08-17 14:19:36 +08:00
})
})
2015-07-20 15:56:29 +08:00
describe.skip('55.12 bind a cursor BIND_INOUT', function() {
2016-03-24 14:09:53 +08:00
before('prepare table nodb_employees', function(done) {
2015-12-21 20:01:45 +08:00
setUp(connection, tableName, done);
})
after('drop table', function(done) {
clearUp(connection, tableName, done);
})
it('55.12.1 does not work currently due to known bug', function(done) {
2016-03-24 14:09:53 +08:00
var proc =
"CREATE OR REPLACE PROCEDURE get_emp_rs_inout (p_in IN NUMBER, p_out IN OUT SYS_REFCURSOR) \
AS \
BEGIN \
OPEN p_out FOR \
SELECT * FROM nodb_employees \
WHERE employees_id > p_in; \
2016-03-24 14:09:53 +08:00
END; ";
async.series([
function(callback) {
connection.execute(
proc,
function(err) {
should.not.exist(err);
callback();
}
);
},
function(callback) {
connection.execute(
"BEGIN get_emp_rs_inout(:in, :out); END;",
{
in: 200,
out: { type: oracledb.CURSOR, dir: oracledb.BIND_INOUT }
},
function(err, result) {
should.not.exist(err);
(err.message).should.startWith('NJS-007:');
// NJS-007: invalid value for "type" in parameter 2
console.log(result);
callback();
}
);
},
function(callback) {
connection.execute(
"DROP PROCEDURE get_emp_rs_inout",
function(err) {
should.not.exist(err);
callback();
}
);
}
], done);
})
2016-03-24 14:09:53 +08:00
2015-09-02 20:35:01 +08:00
}) // 55.12
describe('55.13 Invalid Ref Cursor', function() {
2016-03-24 14:09:53 +08:00
var proc =
"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; " +
" END;"
2015-09-02 20:35:01 +08:00
before(function(done){
async.series([
function(callback) {
setUp(connection, tableName, callback);
},
function(callback) {
connection.execute(
proc,
function(err) {
should.not.exist(err);
callback();
}
);
}
], done);
})
after(function(done) {
async.series([
function(callback) {
connection.execute(
"DROP PROCEDURE get_invalid_refcur",
function(err) {
should.not.exist(err);
callback();
}
);
},
function(callback) {
clearUp(connection, tableName, done);
}
], done);
})
2016-03-24 14:09:53 +08:00
2015-09-02 20:35:01 +08:00
it('55.13.1 ', function (done ) {
connection.should.be.ok;
connection.execute (
"BEGIN get_invalid_refcur ( :p ); END; ",
{
p : { type : oracledb.CURSOR, dir : oracledb.BIND_OUT }
},
function ( err, result) {
should.exist ( err );
done();
2015-09-02 20:35:01 +08:00
}
);
function fetchRowFromRS2 (rs, cb ) {
if ( rs ) {
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();
});
}
});
} else {
cb();
}
}
}) // 55.13.1
}) // 55.13
2016-03-24 14:09:53 +08:00
})
2015-09-02 20:35:01 +08:00
/********************* Helper functions *************************/
function setUp(connection, tableName, done)
{
async.series([
function(callback) {
createTable(connection, tableName, callback);
},
function(callback) {
insertData(connection, tableName, callback);
2016-03-24 14:09:53 +08:00
},
2015-09-02 20:35:01 +08:00
function(callback) {
createProc1(connection, tableName, callback);
}
], done);
}
2016-03-24 14:09:53 +08:00
function clearUp(connection, tableName, done)
2015-09-02 20:35:01 +08:00
{
async.series([
function(callback) {
dropProc1(connection, callback);
},
function(callback) {
dropTable(connection, tableName, callback);
}
], done);
}
function createTable(connection, tableName, done)
{
2016-03-24 14:09:53 +08:00
var sqlCreate =
"BEGIN " +
2015-09-02 20:35:01 +08:00
" DECLARE " +
" e_table_exists EXCEPTION; " +
" PRAGMA EXCEPTION_INIT(e_table_exists, -00942); " +
" BEGIN " +
" EXECUTE IMMEDIATE ('DROP TABLE " + tableName + " '); " +
" EXCEPTION " +
" WHEN e_table_exists " +
" 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; ";
connection.execute(
sqlCreate,
function(err) {
should.not.exist(err);
done();
}
);
}
function dropTable(connection, tableName, done)
{
connection.execute(
'DROP TABLE ' + tableName,
function(err) {
should.not.exist(err);
done();
}
);
}
function insertData(connection, tableName, done)
2016-03-24 14:09:53 +08:00
{
var sqlInsert =
"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
2015-09-02 20:35:01 +08:00
connection.execute(
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();
}
);
}
function createProc1(connection, tableName, done)
{
2016-03-24 14:09:53 +08:00
var sqlProc =
"CREATE OR REPLACE PROCEDURE get_emp_rs (p_in IN NUMBER, p_out OUT SYS_REFCURSOR) " +
" AS " +
" BEGIN " +
" OPEN p_out FOR " +
" SELECT * FROM " + tableName + " WHERE employees_id > p_in; " +
2015-09-02 20:35:01 +08:00
" END; ";
connection.execute(
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();
}
);
}
function dropProc1(connection, done)
{
connection.execute(
'DROP PROCEDURE get_emp_rs',
function(err) {
should.not.exist(err);
done();
}
);
2016-03-24 14:09:53 +08:00
}