node-oracledb/test/resultSet1.js

1394 lines
39 KiB
JavaScript
Raw Normal View History

2018-02-09 16:51:13 +08:00
/* Copyright (c) 2015, 2018, 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
* 12. resultSet1.js
*
* DESCRIPTION
* Testing driver resultSet feature.
*
*****************************************************************************/
2016-03-24 14:09:53 +08:00
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
describe('12. resultSet1.js', function() {
2016-03-24 14:09:53 +08:00
2016-05-16 07:57:53 +08:00
var connection = null;
2016-03-24 14:09:53 +08:00
var createTable =
2015-07-20 15:56:29 +08:00
"BEGIN \
DECLARE \
2017-06-14 09:54:15 +08:00
e_table_missing EXCEPTION; \
PRAGMA EXCEPTION_INIT(e_table_missing, -00942); \
2015-07-20 15:56:29 +08:00
BEGIN \
2017-06-14 09:54:15 +08:00
EXECUTE IMMEDIATE ('DROP TABLE nodb_rs1_emp PURGE'); \
2015-07-20 15:56:29 +08:00
EXCEPTION \
2017-06-14 09:54:15 +08:00
WHEN e_table_missing \
2015-07-20 15:56:29 +08:00
THEN NULL; \
END; \
EXECUTE IMMEDIATE (' \
2017-06-14 09:54:15 +08:00
CREATE TABLE nodb_rs1_emp ( \
2015-07-20 15:56:29 +08:00
employees_id NUMBER, \
employees_name VARCHAR2(20) \
) \
'); \
END; ";
2016-03-24 14:09:53 +08:00
var insertRows =
2015-07-20 15:56:29 +08:00
"DECLARE \
x NUMBER := 0; \
n VARCHAR2(20); \
BEGIN \
FOR i IN 1..217 LOOP \
x := x + 1; \
n := 'staff ' || x; \
2017-06-14 09:54:15 +08:00
INSERT INTO nodb_rs1_emp VALUES (x, n); \
2015-07-20 15:56:29 +08:00
END LOOP; \
END; ";
var rowsAmount = 217;
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
before(function(done) {
2017-06-14 09:54:15 +08:00
oracledb.getConnection(
{
user: dbConfig.user,
password: dbConfig.password,
connectString: dbConfig.connectString
},
function(err, conn) {
should.not.exist(err);
connection = conn;
connection.execute(
createTable,
function(err) {
should.not.exist(err);
connection.execute(insertRows, function(err) {
should.not.exist(err);
done();
});
})
;
}
);
});
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
after(function(done) {
connection.execute(
2017-06-14 09:54:15 +08:00
'DROP TABLE nodb_rs1_emp PURGE',
2015-07-20 15:56:29 +08:00
function(err) {
if(err) { console.error(err.message); return; }
connection.release(function(err) {
if(err) { console.error(err.message); return; }
done();
});
}
);
2017-06-14 09:54:15 +08:00
});
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
describe('12.1 Testing resultSet option', function() {
it('12.1.1 when resultSet option = false, content of result is correct', function(done) {
2017-06-14 09:54:15 +08:00
connection.should.be.ok();
2015-07-20 15:56:29 +08:00
connection.execute(
2017-06-14 09:54:15 +08:00
"SELECT employees_name FROM nodb_rs1_emp",
2015-07-20 15:56:29 +08:00
[],
{ resultSet: false, fetchArraySize: 100, maxRows: 1000 },
2015-07-20 15:56:29 +08:00
function(err, result) {
should.not.exist(err);
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
should.exist(result.rows);
result.rows.length.should.be.exactly(rowsAmount);
// console.log(result.rows);
2016-03-24 14:09:53 +08:00
should.not.exist(result.resultSet);
2015-07-20 15:56:29 +08:00
done();
}
);
2017-06-14 09:54:15 +08:00
});
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
it('12.1.2 when resultSet option = true, content of result is correct', function(done) {
2017-06-14 09:54:15 +08:00
connection.should.be.ok();
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
connection.execute(
2017-06-14 09:54:15 +08:00
"SELECT employees_name FROM nodb_rs1_emp",
2015-07-20 15:56:29 +08:00
[],
{ resultSet: true, fetchArraySize: 100, maxRows: 1000 },
2015-07-20 15:56:29 +08:00
function(err, result) {
should.not.exist(err);
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
should.not.exist(result.rows);
2016-03-24 14:09:53 +08:00
should.exist(result.resultSet);
result.resultSet.close(done);
2015-07-20 15:56:29 +08:00
}
);
2017-06-14 09:54:15 +08:00
});
2016-03-24 14:09:53 +08:00
it('12.1.3 negative - 0', function(done) {
2017-06-14 09:54:15 +08:00
connection.should.be.ok();
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
connection.execute(
2017-06-14 09:54:15 +08:00
"SELECT employees_name FROM nodb_rs1_emp",
2015-07-20 15:56:29 +08:00
[],
{ resultSet: 0, fetchArraySize: 100, maxRows: 1000 },
2015-07-20 15:56:29 +08:00
function(err, result) {
should.not.exist(result);
should.exist(err);
should.strictEqual(err.message, "NJS-007: invalid value for \"resultSet\" in parameter 3");
2015-07-20 15:56:29 +08:00
done();
}
);
2017-06-14 09:54:15 +08:00
});
2016-03-24 14:09:53 +08:00
it('12.1.4 negative - null',function(done) {
2017-06-14 09:54:15 +08:00
connection.should.be.ok();
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
connection.execute(
2017-06-14 09:54:15 +08:00
"SELECT employees_name FROM nodb_rs1_emp",
2015-07-20 15:56:29 +08:00
[],
{ resultSet: null, fetchArraySize: 100, maxRows: 1000 },
2015-07-20 15:56:29 +08:00
function(err, result) {
should.not.exist(result);
should.exist(err);
should.strictEqual(err.message, "NJS-007: invalid value for \"resultSet\" in parameter 3");
2015-07-20 15:56:29 +08:00
done();
}
);
2017-06-14 09:54:15 +08:00
});
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
it('12.1.5 when resultSet option = undefined, it behaves like false', function(done) {
2017-06-14 09:54:15 +08:00
connection.should.be.ok();
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
connection.execute(
2017-06-14 09:54:15 +08:00
"SELECT employees_name FROM nodb_rs1_emp",
2015-07-20 15:56:29 +08:00
[],
{ resultSet: undefined, fetchArraySize: 100, maxRows: 1000 },
2015-07-20 15:56:29 +08:00
function(err, result) {
should.not.exist(err);
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
should.exist(result.rows);
result.rows.length.should.be.exactly(rowsAmount);
2016-03-24 14:09:53 +08:00
should.not.exist(result.resultSet);
2015-07-20 15:56:29 +08:00
done();
}
);
2017-06-14 09:54:15 +08:00
});
2016-03-24 14:09:53 +08:00
it('12.1.6 negative - NaN', function(done) {
2017-06-14 09:54:15 +08:00
connection.should.be.ok();
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
connection.execute(
2017-06-14 09:54:15 +08:00
"SELECT employees_name FROM nodb_rs1_emp",
2015-07-20 15:56:29 +08:00
[],
{ resultSet: NaN, fetchArraySize: 100, maxRows: 1000 },
2015-07-20 15:56:29 +08:00
function(err, result) {
should.not.exist(result);
should.exist(err);
should.strictEqual(err.message, "NJS-007: invalid value for \"resultSet\" in parameter 3");
2015-07-20 15:56:29 +08:00
done();
}
);
2017-06-14 09:54:15 +08:00
});
2016-03-24 14:09:53 +08:00
it('12.1.7 negative - 1', function(done) {
2017-06-14 09:54:15 +08:00
connection.should.be.ok();
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
connection.execute(
2017-06-14 09:54:15 +08:00
"SELECT employees_name FROM nodb_rs1_emp",
2015-07-20 15:56:29 +08:00
[],
{ resultSet: 1, fetchArraySize: 100, maxRows: 1000 },
2015-07-20 15:56:29 +08:00
function(err, result) {
should.not.exist(result);
should.exist(err);
should.strictEqual(err.message, "NJS-007: invalid value for \"resultSet\" in parameter 3");
done();
2015-07-20 15:56:29 +08:00
}
);
2017-06-14 09:54:15 +08:00
});
2016-03-24 14:09:53 +08:00
it('12.1.8 negative - (-1)', function(done) {
2017-06-14 09:54:15 +08:00
connection.should.be.ok();
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
connection.execute(
2017-06-14 09:54:15 +08:00
"SELECT employees_name FROM nodb_rs1_emp",
2015-07-20 15:56:29 +08:00
[],
{ resultSet: -1, fetchArraySize: 100, maxRows: 1000 },
2015-07-20 15:56:29 +08:00
function(err, result) {
should.not.exist(result);
should.exist(err);
should.strictEqual(err.message, "NJS-007: invalid value for \"resultSet\" in parameter 3");
done();
2015-07-20 15:56:29 +08:00
}
);
2017-06-14 09:54:15 +08:00
});
2016-03-24 14:09:53 +08:00
it('12.1.9 negative - random string', function(done) {
2017-06-14 09:54:15 +08:00
connection.should.be.ok();
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
connection.execute(
2017-06-14 09:54:15 +08:00
"SELECT employees_name FROM nodb_rs1_emp",
2015-07-20 15:56:29 +08:00
[],
{ resultSet: 'foo', fetchArraySize: 100, maxRows: 1000 },
2015-07-20 15:56:29 +08:00
function(err, result) {
should.not.exist(result);
should.exist(err);
should.strictEqual(err.message, "NJS-007: invalid value for \"resultSet\" in parameter 3");
done();
2015-07-20 15:56:29 +08:00
}
);
2017-06-14 09:54:15 +08:00
});
2016-03-24 14:09:53 +08:00
2017-06-14 09:54:15 +08:00
});
2016-03-24 14:09:53 +08:00
describe('12.2 Testing fetchArraySize option', function() {
it('12.2.1 negative - negative value', function(done) {
2017-06-14 09:54:15 +08:00
connection.should.be.ok();
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
connection.execute(
2017-06-14 09:54:15 +08:00
"SELECT employees_name FROM nodb_rs1_emp",
2015-07-20 15:56:29 +08:00
[],
{ resultSet: true, fetchArraySize: -10, maxRows: 1000 },
2017-06-14 09:54:15 +08:00
function(err) {
2015-07-20 15:56:29 +08:00
should.exist(err);
(err.message).should.startWith('NJS-007:');
// NJS-007: invalid value for "fetchArraySize"
2015-07-20 15:56:29 +08:00
done();
}
);
2017-06-14 09:54:15 +08:00
});
2016-03-24 14:09:53 +08:00
it('12.2.2 negative - random string', function(done) {
2017-06-14 09:54:15 +08:00
connection.should.be.ok();
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
connection.execute(
2017-06-14 09:54:15 +08:00
"SELECT employees_name FROM nodb_rs1_emp",
2015-07-20 15:56:29 +08:00
[],
{ resultSet: true, fetchArraySize: 'bar', maxRows: 1000 },
2017-06-14 09:54:15 +08:00
function(err) {
2015-07-20 15:56:29 +08:00
should.exist(err);
(err.message).should.startWith('NJS-007:');
// NJS-007: invalid value for "fetchArraySize"
2015-07-20 15:56:29 +08:00
done();
}
);
2017-06-14 09:54:15 +08:00
});
2016-03-24 14:09:53 +08:00
it('12.2.3 negative - NaN', function(done) {
2017-06-14 09:54:15 +08:00
connection.should.be.ok();
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
connection.execute(
2017-06-14 09:54:15 +08:00
"SELECT employees_name FROM nodb_rs1_emp",
2015-07-20 15:56:29 +08:00
[],
{ resultSet: true, fetchArraySize: NaN, maxRows: 1000 },
2017-06-14 09:54:15 +08:00
function(err) {
2015-07-20 15:56:29 +08:00
should.exist(err);
(err.message).should.startWith('NJS-007:');
// NJS-007: invalid value for "fetchArraySize"
2015-07-20 15:56:29 +08:00
done();
}
);
2017-06-14 09:54:15 +08:00
});
2016-03-24 14:09:53 +08:00
it('12.2.4 negative - null', function(done) {
2017-06-14 09:54:15 +08:00
connection.should.be.ok();
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
connection.execute(
2017-06-14 09:54:15 +08:00
"SELECT employees_name FROM nodb_rs1_emp",
2015-07-20 15:56:29 +08:00
[],
{ resultSet: true, fetchArraySize: null, maxRows: 1000 },
function(err, result) {
should.not.exist(result);
should.exist(err);
should.strictEqual(err.message, "NJS-007: invalid value for \"fetchArraySize\" in parameter 3");
done();
2015-07-20 15:56:29 +08:00
}
);
2017-06-14 09:54:15 +08:00
});
2016-03-24 14:09:53 +08:00
it('12.2.5 negative - zero value', function(done) {
2017-06-14 09:54:15 +08:00
connection.should.be.ok();
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
connection.execute(
2017-06-14 09:54:15 +08:00
"SELECT employees_name FROM nodb_rs1_emp",
2015-07-20 15:56:29 +08:00
[],
{ resultSet: true, fetchArraySize: 0, maxRows: 1000 },
function(err, result) {
should.not.exist(result);
should.exist(err);
should.strictEqual(err.message, "NJS-007: invalid value for \"fetchArraySize\" in parameter 3");
done();
2015-07-20 15:56:29 +08:00
}
);
2017-06-14 09:54:15 +08:00
});
2016-03-24 14:09:53 +08:00
2017-06-14 09:54:15 +08:00
});
2015-07-20 15:56:29 +08:00
describe('12.3 Testing function getRows()', function() {
2015-08-17 14:19:36 +08:00
it('12.3.1 retrieved set is exactly the size of result', function(done) {
2017-06-14 09:54:15 +08:00
connection.should.be.ok();
2015-07-20 15:56:29 +08:00
var nRows = rowsAmount;
var accessCount = 0;
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
connection.execute(
2017-06-14 09:54:15 +08:00
"SELECT employees_name FROM nodb_rs1_emp",
2015-07-20 15:56:29 +08:00
[],
{ resultSet: true, fetchArraySize: 100 },
2015-07-20 15:56:29 +08:00
function(err, result) {
should.not.exist(err);
fetchRowFromRS(result.resultSet, nRows);
}
);
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
function fetchRowFromRS(rs, numRows) {
rs.getRows(numRows, function(err, rows) {
should.not.exist(err);
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
if(rows.length > 0) {
accessCount++;
return fetchRowFromRS(rs, numRows);
} else {
rs.close(function(err) {
should.not.exist(err);
accessCount.should.be.exactly(1);
done();
});
2016-03-24 14:09:53 +08:00
}
2015-07-20 15:56:29 +08:00
});
}
2017-06-14 09:54:15 +08:00
});
2016-03-24 14:09:53 +08:00
2015-08-17 14:19:36 +08:00
it('12.3.2 retrieved set is greater than the size of result', function(done) {
2017-06-14 09:54:15 +08:00
connection.should.be.ok();
2015-07-20 15:56:29 +08:00
var nRows = rowsAmount * 2;
var accessCount = 0;
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
connection.execute(
2017-06-14 09:54:15 +08:00
"SELECT employees_name FROM nodb_rs1_emp",
2015-07-20 15:56:29 +08:00
[],
{ resultSet: true, fetchArraySize: 100 },
2015-07-20 15:56:29 +08:00
function(err, result) {
should.not.exist(err);
fetchRowFromRS(result.resultSet, nRows);
}
);
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
function fetchRowFromRS(rs, numRows) {
rs.getRows(numRows, function(err, rows) {
should.not.exist(err);
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
if(rows.length > 0) {
accessCount++;
return fetchRowFromRS(rs, numRows);
} else {
rs.close(function(err) {
should.not.exist(err);
accessCount.should.be.exactly(1);
done();
});
2016-03-24 14:09:53 +08:00
}
2015-07-20 15:56:29 +08:00
});
}
2017-06-14 09:54:15 +08:00
});
2015-07-20 15:56:29 +08:00
2015-08-17 14:19:36 +08:00
it('12.3.3 retrieved set is half of the size of result', function(done) {
2017-06-14 09:54:15 +08:00
connection.should.be.ok();
2015-07-20 15:56:29 +08:00
var nRows = Math.ceil(rowsAmount/2);
var accessCount = 0;
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
connection.execute(
2017-06-14 09:54:15 +08:00
"SELECT employees_name FROM nodb_rs1_emp",
2015-07-20 15:56:29 +08:00
[],
{ resultSet: true, fetchArraySize: 100 },
2015-07-20 15:56:29 +08:00
function(err, result) {
should.not.exist(err);
fetchRowFromRS(result.resultSet, nRows);
}
);
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
function fetchRowFromRS(rs, numRows) {
rs.getRows(numRows, function(err, rows) {
should.not.exist(err);
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
if(rows.length > 0) {
accessCount++;
return fetchRowFromRS(rs, numRows);
} else {
rs.close(function(err) {
should.not.exist(err);
accessCount.should.be.exactly(2);
done();
});
2016-03-24 14:09:53 +08:00
}
2015-07-20 15:56:29 +08:00
});
}
2017-06-14 09:54:15 +08:00
});
2016-03-24 14:09:53 +08:00
2015-08-17 14:19:36 +08:00
it('12.3.4 retrieved set is one tenth of the size of the result', function(done) {
2017-06-14 09:54:15 +08:00
connection.should.be.ok();
2015-07-20 15:56:29 +08:00
var nRows = Math.ceil(rowsAmount/10);
var accessCount = 0;
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
connection.execute(
2017-06-14 09:54:15 +08:00
"SELECT employees_name FROM nodb_rs1_emp",
2015-07-20 15:56:29 +08:00
[],
{ resultSet: true, fetchArraySize: 100 },
2015-07-20 15:56:29 +08:00
function(err, result) {
should.not.exist(err);
fetchRowFromRS(result.resultSet, nRows);
}
);
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
function fetchRowFromRS(rs, numRows) {
rs.getRows(numRows, function(err, rows) {
should.not.exist(err);
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
if(rows.length > 0) {
accessCount++;
return fetchRowFromRS(rs, numRows);
} else {
rs.close(function(err) {
should.not.exist(err);
accessCount.should.be.exactly(10);
done();
});
2016-03-24 14:09:53 +08:00
}
2015-07-20 15:56:29 +08:00
});
}
2017-06-14 09:54:15 +08:00
});
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
it('12.3.5 data in resultSet is array when setting outFormat ARRAY', function(done) {
2017-06-14 09:54:15 +08:00
connection.should.be.ok();
2015-07-20 15:56:29 +08:00
var nRows = Math.ceil(rowsAmount/10);
var accessCount = 0;
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
connection.execute(
2017-06-14 09:54:15 +08:00
"SELECT employees_name FROM nodb_rs1_emp",
2015-07-20 15:56:29 +08:00
[],
{ resultSet: true, fetchArraySize: 100, outFormat: oracledb.OUT_FORMAT_ARRAY },
2015-07-20 15:56:29 +08:00
function(err, result) {
should.not.exist(err);
fetchRowFromRS(result.resultSet, nRows);
}
);
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
function fetchRowFromRS(rs, numRows) {
rs.getRows(numRows, function(err, rows) {
should.not.exist(err);
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
if(rows.length > 0) {
accessCount++;
for(var i = 0; i < rows.length; i++)
2016-03-24 14:09:53 +08:00
(rows[i]).should.be.an.Array;
2015-07-20 15:56:29 +08:00
return fetchRowFromRS(rs, numRows);
} else {
rs.close(function(err) {
should.not.exist(err);
accessCount.should.be.exactly(10);
done();
});
2016-03-24 14:09:53 +08:00
}
2015-07-20 15:56:29 +08:00
});
}
2017-06-14 09:54:15 +08:00
});
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
it('12.3.6 data in resultSet is object when setting outFormat OBJECT', function(done) {
2017-06-14 09:54:15 +08:00
connection.should.be.ok();
2015-07-20 15:56:29 +08:00
var nRows = Math.ceil(rowsAmount/10);
var accessCount = 0;
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
connection.execute(
2017-06-14 09:54:15 +08:00
"SELECT employees_name FROM nodb_rs1_emp",
2015-07-20 15:56:29 +08:00
[],
{ resultSet: true, fetchArraySize: 100, outFormat: oracledb.OUT_FORMAT_OBJECT },
2015-07-20 15:56:29 +08:00
function(err, result) {
should.not.exist(err);
fetchRowFromRS(result.resultSet, nRows);
}
);
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
function fetchRowFromRS(rs, numRows) {
rs.getRows(numRows, function(err, rows) {
should.not.exist(err);
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
if(rows.length > 0) {
accessCount++;
for(var i = 0; i < rows.length; i++)
2016-03-24 14:09:53 +08:00
(rows[i]).should.be.an.Object;
2015-07-20 15:56:29 +08:00
return fetchRowFromRS(rs, numRows);
} else {
rs.close(function(err) {
should.not.exist(err);
accessCount.should.be.exactly(10);
done();
});
2016-03-24 14:09:53 +08:00
}
2015-07-20 15:56:29 +08:00
});
}
2017-06-14 09:54:15 +08:00
});
2016-03-24 14:09:53 +08:00
2015-08-17 14:19:36 +08:00
it('12.3.7 the size of retrieved set can be set to 1', function(done) {
2017-06-14 09:54:15 +08:00
connection.should.be.ok();
2015-07-20 15:56:29 +08:00
var nRows = 1;
var accessCount = 0;
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
connection.execute(
2017-06-14 09:54:15 +08:00
"SELECT employees_name FROM nodb_rs1_emp",
2015-07-20 15:56:29 +08:00
[],
{ resultSet: true, fetchArraySize: 100 },
2015-07-20 15:56:29 +08:00
function(err, result) {
should.not.exist(err);
fetchRowFromRS(result.resultSet, nRows);
}
);
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
function fetchRowFromRS(rs, numRows) {
rs.getRows(numRows, function(err, rows) {
should.not.exist(err);
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
if(rows.length > 0) {
accessCount++;
return fetchRowFromRS(rs, numRows);
} else {
rs.close(function(err) {
should.not.exist(err);
accessCount.should.be.exactly(rowsAmount);
done();
});
2016-03-24 14:09:53 +08:00
}
2015-07-20 15:56:29 +08:00
});
}
2017-06-14 09:54:15 +08:00
});
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
it('12.3.8 query 0 row', function(done) {
2017-06-14 09:54:15 +08:00
connection.should.be.ok();
2015-07-20 15:56:29 +08:00
var accessCount = 0;
2017-06-14 09:54:15 +08:00
2015-07-20 15:56:29 +08:00
connection.execute(
2017-06-14 09:54:15 +08:00
"SELECT employees_name FROM nodb_rs1_emp WHERE employees_id > 300",
2015-07-20 15:56:29 +08:00
[],
{ resultSet: true },
function(err, result) {
should.not.exist(err);
fetchRowsFromRS(result.resultSet);
}
);
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
function fetchRowsFromRS(rs, numRows) {
rs.getRow(function(err, rows) {
should.not.exist(err);
if(rows) {
accessCount++;
2017-06-14 09:54:15 +08:00
rows[0].should.eql('staff ' + accessCount);
rows.should.be.an.Array;
2015-07-20 15:56:29 +08:00
return fetchRowsFromRS(rs, numRows);
} else {
rs.close(function(err) {
should.not.exist(err);
accessCount.should.be.exactly(0);
done();
});
2016-03-24 14:09:53 +08:00
}
2015-07-20 15:56:29 +08:00
});
}
2017-06-14 09:54:15 +08:00
});
2015-07-20 15:56:29 +08:00
it('12.3.9 Negative - To omit the first parameter', function(done) {
2017-06-14 09:54:15 +08:00
connection.should.be.ok();
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
connection.execute(
2017-06-14 09:54:15 +08:00
"SELECT employees_name FROM nodb_rs1_emp",
2015-07-20 15:56:29 +08:00
[],
{ resultSet: true, fetchArraySize: 100 },
2015-07-20 15:56:29 +08:00
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) {
try {
rs.getRows(function() {});
} catch (err) {
2015-07-20 15:56:29 +08:00
should.exist(err);
(err.message).should.startWith('NJS-009:');
// NJS-009: invalid number of parameters
2015-07-20 15:56:29 +08:00
rs.close(function(err) {
should.not.exist(err);
done();
2016-03-24 14:09:53 +08:00
});
}
2015-07-20 15:56:29 +08:00
}
2017-06-14 09:54:15 +08:00
});
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
it('12.3.10 Negative - set the 1st parameter of getRows() to be 0', function(done) {
2017-06-14 09:54:15 +08:00
connection.should.be.ok();
2015-07-20 15:56:29 +08:00
var nRows = 0;
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
connection.execute(
2017-06-14 09:54:15 +08:00
"SELECT employees_name FROM nodb_rs1_emp",
2015-07-20 15:56:29 +08:00
[],
{ resultSet: true, fetchArraySize: 100 },
2015-07-20 15:56:29 +08:00
function(err, result) {
should.not.exist(err);
fetchRowFromRS(result.resultSet, nRows);
}
);
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
function fetchRowFromRS(rs, numRows) {
try {
rs.getRows(numRows, function() {});
} catch (err) {
2015-07-20 15:56:29 +08:00
should.exist(err);
(err.message).should.startWith('NJS-005:');
// NJS-005: invalid value for parameter 1
2015-07-20 15:56:29 +08:00
rs.close(function(err) {
should.not.exist(err);
done();
});
2017-06-14 09:54:15 +08:00
}
2015-07-20 15:56:29 +08:00
}
2017-06-14 09:54:15 +08:00
});
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
it('12.3.11 Negative - set the 1st parameter of getRows() to be -5', function(done) {
2017-06-14 09:54:15 +08:00
connection.should.be.ok();
2015-07-20 15:56:29 +08:00
var nRows = -5;
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
connection.execute(
2017-06-14 09:54:15 +08:00
"SELECT employees_name FROM nodb_rs1_emp",
2015-07-20 15:56:29 +08:00
[],
{ resultSet: true, fetchArraySize: 100 },
2015-07-20 15:56:29 +08:00
function(err, result) {
should.not.exist(err);
fetchRowFromRS(result.resultSet, nRows);
}
);
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
function fetchRowFromRS(rs, numRows) {
try {
rs.getRows(numRows, function() {});
} catch (err) {
2015-07-20 15:56:29 +08:00
should.exist(err);
2019-03-13 08:02:49 +08:00
(err.message).should.startWith('NJS-005:');
// NJS-005: invalid value for parameter 1
2015-07-20 15:56:29 +08:00
rs.close(function(err) {
should.not.exist(err);
done();
2016-03-24 14:09:53 +08:00
});
2017-06-14 09:54:15 +08:00
}
2015-07-20 15:56:29 +08:00
}
2017-06-14 09:54:15 +08:00
});
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
it('12.3.12 Negative - set the 1st parameter of getRows() to be null', function(done) {
2017-06-14 09:54:15 +08:00
connection.should.be.ok();
2015-07-20 15:56:29 +08:00
var nRows = null; // setting to 'undefined' is the same
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
connection.execute(
2017-06-14 09:54:15 +08:00
"SELECT employees_name FROM nodb_rs1_emp",
2015-07-20 15:56:29 +08:00
[],
{ resultSet: true, fetchArraySize: 100 },
2015-07-20 15:56:29 +08:00
function(err, result) {
should.not.exist(err);
fetchRowFromRS(result.resultSet, nRows);
}
);
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
function fetchRowFromRS(rs, numRows) {
try {
rs.getRows(numRows, function() {});
} catch (err) {
2015-07-20 15:56:29 +08:00
should.exist(err);
(err.message).should.startWith('NJS-005:');
// NJS-005: invalid value for parameter 1
2015-07-20 15:56:29 +08:00
rs.close(function(err) {
should.not.exist(err);
done();
2016-03-24 14:09:53 +08:00
});
}
2015-07-20 15:56:29 +08:00
}
2017-06-14 09:54:15 +08:00
});
});
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
describe('12.4 Testing function getRow()', function() {
it('12.4.1 works well with all correct setting', function(done) {
2017-06-14 09:54:15 +08:00
connection.should.be.ok();
2015-07-20 15:56:29 +08:00
var accessCount = 0;
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
connection.execute(
2017-06-14 09:54:15 +08:00
"SELECT employees_name FROM nodb_rs1_emp",
2015-07-20 15:56:29 +08:00
[],
{ resultSet: true, fetchArraySize: 100 },
2015-07-20 15:56:29 +08:00
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);
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
if(row) {
accessCount++;
row[0].should.eql('staff ' + accessCount);
return fetchRowFromRS(rs);
} else {
rs.close(function(err) {
should.not.exist(err);
accessCount.should.be.exactly(rowsAmount);
done();
});
2016-03-24 14:09:53 +08:00
}
2015-07-20 15:56:29 +08:00
});
}
2017-06-14 09:54:15 +08:00
});
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
it('12.4.2 data in resultSet is array when setting outFormat ARRAY', function(done) {
2017-06-14 09:54:15 +08:00
connection.should.be.ok();
2015-07-20 15:56:29 +08:00
var accessCount = 0;
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
connection.execute(
2017-06-14 09:54:15 +08:00
"SELECT employees_name FROM nodb_rs1_emp",
2015-07-20 15:56:29 +08:00
[],
{ resultSet: true, fetchArraySize: 100, outFormat: oracledb.OUT_FORMAT_ARRAY },
2015-07-20 15:56:29 +08:00
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);
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
if(row) {
accessCount++;
row[0].should.eql('staff ' + accessCount);
row.should.be.an.Array;
return fetchRowFromRS(rs);
} else {
rs.close(function(err) {
should.not.exist(err);
accessCount.should.be.exactly(rowsAmount);
done();
});
2016-03-24 14:09:53 +08:00
}
2015-07-20 15:56:29 +08:00
});
}
2017-06-14 09:54:15 +08:00
});
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
it('12.4.3 data in resultSet is object when setting outFormat OBJECT', function(done) {
2017-06-14 09:54:15 +08:00
connection.should.be.ok();
2015-07-20 15:56:29 +08:00
var accessCount = 0;
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
connection.execute(
2017-06-14 09:54:15 +08:00
"SELECT employees_name FROM nodb_rs1_emp",
2015-07-20 15:56:29 +08:00
[],
{ resultSet: true, fetchArraySize: 100, outFormat: oracledb.OUT_FORMAT_OBJECT },
2015-07-20 15:56:29 +08:00
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);
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
if(row) {
accessCount++;
row.EMPLOYEES_NAME.should.eql('staff ' + accessCount);
row.should.be.an.Object;
return fetchRowFromRS(rs);
} else {
rs.close(function(err) {
should.not.exist(err);
accessCount.should.be.exactly(rowsAmount);
done();
});
2016-03-24 14:09:53 +08:00
}
2015-07-20 15:56:29 +08:00
});
}
2017-06-14 09:54:15 +08:00
});
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
it('12.4.4 query 0 row', function(done) {
2017-06-14 09:54:15 +08:00
connection.should.be.ok();
2015-07-20 15:56:29 +08:00
var accessCount = 0;
connection.execute(
2017-06-14 09:54:15 +08:00
"SELECT employees_name FROM nodb_rs1_emp WHERE employees_id > 300",
2015-07-20 15:56:29 +08:00
[],
{ 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) {
accessCount++;
row[0].should.eql('staff ' + accessCount);
row.should.be.an.Array;
return fetchRowFromRS(rs);
} else {
rs.close(function(err) {
should.not.exist(err);
accessCount.should.be.exactly(0);
done();
});
2016-03-24 14:09:53 +08:00
}
2015-07-20 15:56:29 +08:00
});
}
2017-06-14 09:54:15 +08:00
});
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
it('12.4.5 Negative - set the first parameter like getRows()', function(done){
2017-06-14 09:54:15 +08:00
connection.should.be.ok();
2015-07-20 15:56:29 +08:00
var nRows = 2;
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
connection.execute(
2017-06-14 09:54:15 +08:00
"SELECT employees_name FROM nodb_rs1_emp",
2015-07-20 15:56:29 +08:00
[],
{ resultSet: true, fetchArraySize: 100 },
2015-07-20 15:56:29 +08:00
function(err, result) {
should.not.exist(err);
fetchRowFromRS(result.resultSet, nRows);
}
);
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
function fetchRowFromRS(rs, numRows) {
try {
rs.getRow(numRows, function() {});
} catch (err) {
2015-07-20 15:56:29 +08:00
should.exist(err);
(err.message).should.startWith('NJS-009:');
// NJS-009: invalid number of parameters
2015-07-20 15:56:29 +08:00
rs.close(function(err) {
should.not.exist(err);
done();
2016-03-24 14:09:53 +08:00
});
}
2015-07-20 15:56:29 +08:00
}
2017-06-14 09:54:15 +08:00
});
2016-03-24 14:09:53 +08:00
2017-06-14 09:54:15 +08:00
});
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
describe('12.5 Testing function close()', function() {
it('12.5.1 does not call close()', function(done) {
2017-06-14 09:54:15 +08:00
connection.should.be.ok();
2015-07-20 15:56:29 +08:00
var nRows = Math.ceil(rowsAmount/10);
var accessCount = 0;
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
connection.execute(
2017-06-14 09:54:15 +08:00
"SELECT employees_name FROM nodb_rs1_emp",
2015-07-20 15:56:29 +08:00
[],
{ resultSet: true, fetchArraySize: 100 },
2015-07-20 15:56:29 +08:00
function(err, result) {
should.not.exist(err);
fetchRowFromRS(result.resultSet, nRows);
}
);
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
function fetchRowFromRS(rs, numRows) {
rs.getRows(numRows, function(err, rows) {
should.not.exist(err);
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
if(rows.length > 0) {
accessCount++;
return fetchRowFromRS(rs, numRows);
} else {
accessCount.should.be.exactly(10);
rs.close(done);
2016-03-24 14:09:53 +08:00
}
2015-07-20 15:56:29 +08:00
});
}
2017-06-14 09:54:15 +08:00
});
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
it('12.5.2 invokes close() twice', function(done) {
2017-06-14 09:54:15 +08:00
connection.should.be.ok();
2015-07-20 15:56:29 +08:00
var nRows = Math.ceil(rowsAmount/10);
var accessCount = 0;
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
connection.execute(
2017-06-14 09:54:15 +08:00
"SELECT employees_name FROM nodb_rs1_emp",
2015-07-20 15:56:29 +08:00
[],
{ resultSet: true, fetchArraySize: 100 },
2015-07-20 15:56:29 +08:00
function(err, result) {
should.not.exist(err);
fetchRowFromRS(result.resultSet, nRows);
}
);
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
function fetchRowFromRS(rs, numRows) {
rs.getRows(numRows, function(err, rows) {
should.not.exist(err);
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
if(rows.length > 0) {
accessCount++;
return fetchRowFromRS(rs, numRows);
} else {
rs.close(function(err) {
should.not.exist(err);
accessCount.should.be.exactly(10);
2017-06-17 07:40:09 +08:00
rs.close(function(err) {
2015-07-20 15:56:29 +08:00
should.exist(err);
(err.message).should.startWith('NJS-018:');
2015-07-20 15:56:29 +08:00
done();
2017-06-17 07:40:09 +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
}
2017-06-14 09:54:15 +08:00
});
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
it('12.5.3 uses getRows after calling close()', function(done) {
2017-06-14 09:54:15 +08:00
connection.should.be.ok();
2015-07-20 15:56:29 +08:00
var nRows = Math.ceil(rowsAmount/10);
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
connection.execute(
2017-06-14 09:54:15 +08:00
"SELECT employees_name FROM nodb_rs1_emp",
2015-07-20 15:56:29 +08:00
[],
{ resultSet: true, fetchArraySize: 100 },
2015-07-20 15:56:29 +08:00
function(err, result) {
should.not.exist(err);
fetchRowFromRS(result.resultSet, nRows);
}
);
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
function fetchRowFromRS(rs, numRows) {
rs.getRows(numRows, function(err, rows) {
should.not.exist(err);
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
if(rows.length > 0) {
return fetchRowFromRS(rs, numRows);
} else {
rs.close(function(err) {
should.not.exist(err);
2017-06-17 07:40:09 +08:00
rs.getRows(numRows, function(err) {
2015-07-20 15:56:29 +08:00
should.exist(err);
(err.message).should.startWith('NJS-018:');
2015-07-20 15:56:29 +08:00
done();
2017-06-17 07:40:09 +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 09:54:15 +08:00
});
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
it('12.5.4 closes one resultSet and then open another resultSet', function(done) {
2017-06-14 09:54:15 +08:00
connection.should.be.ok();
2015-07-20 15:56:29 +08:00
var nRows = Math.ceil(rowsAmount/10);
var accessCount = 0;
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
async.series([
function(callback) {
connection.execute(
2017-06-14 09:54:15 +08:00
"SELECT employees_name FROM nodb_rs1_emp",
2015-07-20 15:56:29 +08:00
[],
{ resultSet: true, fetchArraySize: 100 },
2015-07-20 15:56:29 +08:00
function(err, result) {
should.not.exist(err);
fetchRowFromRS(result.resultSet, nRows, callback);
}
);
},
function(callback) {
accessCount = 0;
connection.execute(
2017-06-14 09:54:15 +08:00
"SELECT * FROM nodb_rs1_emp",
2015-07-20 15:56:29 +08:00
[],
{ resultSet: true, fetchArraySize: 100 },
2015-07-20 15:56:29 +08:00
function(err, result) {
should.not.exist(err);
fetchRowFromRS(result.resultSet, nRows, callback);
}
);
}
], done);
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
function fetchRowFromRS(rs, numRows, callback) {
rs.getRows(numRows, function(err, rows) {
should.not.exist(err);
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
if(rows.length > 0) {
accessCount++;
return fetchRowFromRS(rs, numRows, callback);
} else {
rs.close(function(err) {
should.not.exist(err);
accessCount.should.be.exactly(10);
callback();
});
}
});
}
2017-06-14 09:54:15 +08:00
});
2016-03-24 14:09:53 +08:00
2017-06-14 09:54:15 +08:00
});
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
describe('12.6 Testing metaData', function() {
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
it('12.6.1 the amount and value of metaData should be correct', function(done) {
2017-06-14 09:54:15 +08:00
connection.should.be.ok();
2015-07-20 15:56:29 +08:00
/* Helper functions */
var StringBuffer = function() {
this.buffer = [];
this.index = 0;
};
StringBuffer.prototype = {
append: function(s) {
this.buffer[this.index] = s;
this.index += 1;
return this;
},
toString: function() {
return this.buffer.join("");
}
};
var createTab = function(size) {
var buffer = new StringBuffer();
2018-09-30 20:20:25 +08:00
buffer.append("CREATE TABLE nodb_tab_manycolumns( ");
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
for(var i = 0; i < size-1; i++) {
buffer.append("c" + i + " NUMBER, ");
}
buffer.append("c" + (size-1) + " NUMBER");
buffer.append(" )");
return buffer.toString();
2017-06-14 09:54:15 +08:00
};
2015-07-20 15:56:29 +08:00
/*********************/
var columnsAmount = 1000;
async.series([
function(callback) {
var sql = createTab(columnsAmount);
// console.log(sql);
connection.execute(
sql,
function(err) {
should.not.exist(err);
callback();
}
);
},
function(callback){
connection.execute(
2018-09-30 20:20:25 +08:00
"SELECT * FROM nodb_tab_manycolumns",
2015-07-20 15:56:29 +08:00
[],
{ resultSet: true},
function(err, result){
should.not.exist(err);
//console.log(result.resultSet.metaData);
for(var i = 0; i < columnsAmount; i++) {
(result.resultSet.metaData[i].name).should.be.exactly('C' + i);
}
result.resultSet.close(callback);
2015-07-20 15:56:29 +08:00
}
);
},
function(callback) {
connection.execute(
2018-09-30 20:20:25 +08:00
"DROP TABLE nodb_tab_manycolumns PURGE",
2015-07-20 15:56:29 +08:00
function(err) {
should.not.exist(err);
callback();
}
);
}
], done);
2017-06-14 09:54:15 +08:00
});
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
it('12.6.2 can distinguish lower case and upper case', function(done) {
2017-06-14 09:54:15 +08:00
connection.should.be.ok();
var tableName = "nodb_uppercase";
2016-03-24 14:09:53 +08:00
var createTable =
2015-07-20 15:56:29 +08:00
" BEGIN " +
" DECLARE " +
2017-06-14 09:54:15 +08:00
" e_table_missing EXCEPTION; " +
" PRAGMA EXCEPTION_INIT(e_table_missing, -00942); " +
2015-07-20 15:56:29 +08:00
" BEGIN " +
2017-06-14 09:54:15 +08:00
" EXECUTE IMMEDIATE ('DROP TABLE " + tableName + " PURGE'); " +
2015-07-20 15:56:29 +08:00
" EXCEPTION " +
2017-06-14 09:54:15 +08:00
" WHEN e_table_missing " +
2015-07-20 15:56:29 +08:00
" THEN NULL; " +
" END; " +
" EXECUTE IMMEDIATE (' " +
2016-03-24 14:09:53 +08:00
" CREATE TABLE " + tableName + " ( " +
2015-07-20 15:56:29 +08:00
' "c" NUMBER, ' +
' "C" NUMBER ' +
" ) " +
" '); " +
" END; ";
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
async.series([
function(callback) {
connection.execute(
createTable,
function(err) {
should.not.exist(err);
callback();
}
);
},
function(callback) {
connection.execute(
"SELECT * FROM " + tableName,
[],
{ resultSet: true },
function(err, result) {
should.not.exist(err);
// console.log(result.resultSet.metaData);
(result.resultSet.metaData[0].name).should.be.exactly('c');
(result.resultSet.metaData[1].name).should.be.exactly('C');
result.resultSet.close(callback);
2015-07-20 15:56:29 +08:00
}
);
},
function(callback) {
connection.execute(
2017-06-14 09:54:15 +08:00
"DROP TABLE " + tableName + " PURGE",
2015-07-20 15:56:29 +08:00
function(err) {
should.not.exist(err);
callback();
}
);
}
], done);
2017-06-14 09:54:15 +08:00
});
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
it('12.6.3 can contain quotes', function(done) {
2017-06-14 09:54:15 +08:00
connection.should.be.ok();
var tableName = "nodb_quotes";
2016-03-24 14:09:53 +08:00
var createTable =
2015-07-20 15:56:29 +08:00
" BEGIN " +
" DECLARE " +
2017-06-14 09:54:15 +08:00
" e_table_missing EXCEPTION; " +
" PRAGMA EXCEPTION_INIT(e_table_missing, -00942); " +
2015-07-20 15:56:29 +08:00
" BEGIN " +
2017-06-14 09:54:15 +08:00
" EXECUTE IMMEDIATE ('DROP TABLE " + tableName + " PURGE'); " +
2015-07-20 15:56:29 +08:00
" EXCEPTION " +
2017-06-14 09:54:15 +08:00
" WHEN e_table_missing " +
2015-07-20 15:56:29 +08:00
" THEN NULL; " +
" END; " +
" EXECUTE IMMEDIATE (' " +
2016-03-24 14:09:53 +08:00
" CREATE TABLE " + tableName + " ( " +
' "c' + "''" + '" NUMBER, ' +
2015-07-20 15:56:29 +08:00
' "c" NUMBER ' +
" ) " +
" '); " +
" END; ";
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
async.series([
function(callback) {
connection.execute(
createTable,
function(err) {
should.not.exist(err);
callback();
}
);
},
function(callback) {
connection.execute(
"SELECT * FROM " + tableName,
[],
{ resultSet: true },
function(err, result) {
should.not.exist(err);
// console.log(result.resultSet.metaData);
(result.resultSet.metaData[0].name).should.be.exactly("c'");
(result.resultSet.metaData[1].name).should.be.exactly('c');
result.resultSet.close(callback);
2015-07-20 15:56:29 +08:00
}
);
},
function(callback) {
connection.execute(
2017-06-14 09:54:15 +08:00
"DROP TABLE " + tableName + " PURGE",
2015-07-20 15:56:29 +08:00
function(err) {
should.not.exist(err);
callback();
}
);
}
], done);
2017-06-14 09:54:15 +08:00
});
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
it('12.6.4 can contain underscore', function(done) {
2017-06-14 09:54:15 +08:00
connection.should.be.ok();
var tableName = "nodb_underscore";
2016-03-24 14:09:53 +08:00
var createTable =
2015-07-20 15:56:29 +08:00
" BEGIN " +
" DECLARE " +
2017-06-14 09:54:15 +08:00
" e_table_missing EXCEPTION; " +
" PRAGMA EXCEPTION_INIT(e_table_missing, -00942); " +
2015-07-20 15:56:29 +08:00
" BEGIN " +
2017-06-14 09:54:15 +08:00
" EXECUTE IMMEDIATE ('DROP TABLE " + tableName + " PURGE'); " +
2015-07-20 15:56:29 +08:00
" EXCEPTION " +
2017-06-14 09:54:15 +08:00
" WHEN e_table_missing " +
2015-07-20 15:56:29 +08:00
" THEN NULL; " +
" END; " +
" EXECUTE IMMEDIATE (' " +
2016-03-24 14:09:53 +08:00
" CREATE TABLE " + tableName + " ( " +
2015-07-20 15:56:29 +08:00
' "c_" NUMBER, ' +
' "c__" NUMBER ' +
" ) " +
" '); " +
2016-03-24 14:09:53 +08:00
" END; ";
2015-07-20 15:56:29 +08:00
async.series([
function(callback) {
connection.execute(
createTable,
function(err) {
should.not.exist(err);
callback();
}
);
},
function(callback) {
connection.execute(
"SELECT * FROM " + tableName,
[],
{ resultSet: true },
function(err, result) {
should.not.exist(err);
// console.log(result.resultSet.metaData);
(result.resultSet.metaData[0].name).should.be.exactly("c_");
(result.resultSet.metaData[1].name).should.be.exactly('c__');
result.resultSet.close(callback);
2015-07-20 15:56:29 +08:00
}
);
},
function(callback) {
connection.execute(
2017-06-14 09:54:15 +08:00
"DROP TABLE " + tableName + " PURGE",
2015-07-20 15:56:29 +08:00
function(err) {
should.not.exist(err);
callback();
}
);
}
], done);
2017-06-14 09:54:15 +08:00
});
});
2016-03-24 14:09:53 +08:00
2015-07-20 15:56:29 +08:00
describe('12.7 Testing maxRows', function() {
it('12.7.1 maxRows option is ignored when resultSet option is true', function(done) {
2017-06-14 09:54:15 +08:00
connection.should.be.ok();
2015-07-20 15:56:29 +08:00
var rowsLimit = 50;
2017-06-14 09:54:15 +08:00
2015-07-20 15:56:29 +08:00
connection.execute(
2017-06-14 09:54:15 +08:00
"SELECT * FROM nodb_rs1_emp ORDER BY employees_id",
2015-07-20 15:56:29 +08:00
[],
{ resultSet: true, maxRows: rowsLimit },
function(err, result) {
should.not.exist(err);
fetchRowFromRS(result.resultSet);
}
);
function fetchRowFromRS(rs) {
rs.getRow(function(err, row) {
should.not.exist(err);
if(row) {
return fetchRowFromRS(rs);
} else {
rs.close(function(err) {
should.not.exist(err);
done();
});
}
});
}
2017-06-14 09:54:15 +08:00
});
2016-03-24 14:09:53 +08:00
2015-08-17 14:19:36 +08:00
it('12.7.2 maxRows option is ignored with REF Cursor', function(done) {
2017-06-14 09:54:15 +08:00
connection.should.be.ok();
2015-08-17 14:19:36 +08:00
var rowCount = 0;
2016-03-24 14:09:53 +08:00
var queryAmount = 100;
var proc =
2017-06-14 09:54:15 +08:00
"CREATE OR REPLACE PROCEDURE get_emp_rs1_proc (p_in IN NUMBER, p_out OUT SYS_REFCURSOR) \
2015-08-17 14:19:36 +08:00
AS \
BEGIN \
OPEN p_out FOR \
2017-06-14 09:54:15 +08:00
SELECT * FROM nodb_rs1_emp \
2015-08-17 14:19:36 +08:00
WHERE employees_id <= p_in; \
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(
2017-06-14 09:54:15 +08:00
"BEGIN get_emp_rs1_proc(:in, :out); END;",
2015-08-17 14:19:36 +08:00
{
in: queryAmount,
out: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
},
{ maxRows: 10 },
function(err, result) {
should.not.exist(err);
fetchRowFromRS(result.outBinds.out, callback);
}
);
2016-03-24 14:09:53 +08:00
},
2015-08-17 14:19:36 +08:00
function(callback) {
connection.execute(
2017-06-14 09:54:15 +08:00
"DROP PROCEDURE get_emp_rs1_proc",
2015-08-17 14:19:36 +08:00
function(err) {
should.not.exist(err);
callback();
}
);
}
], done);
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) {
rowCount++;
return fetchRowFromRS(rs, cb);
} else {
rs.close( function(err) {
should.not.exist(err);
rowCount.should.eql(queryAmount);
cb();
});
}
});
}
2017-06-14 09:54:15 +08:00
});
2019-05-23 06:04:57 +08:00
}); // 12.7
2015-07-20 15:56:29 +08:00
2017-06-14 09:54:15 +08:00
});