2022-04-19 08:06:36 +08:00
|
|
|
/* Copyright (c) 2015, 2022, Oracle and/or its affiliates. */
|
2015-07-20 12:42:12 +08:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
*
|
2023-02-21 09:43:43 +08:00
|
|
|
* This software is dual-licensed to you under the Universal Permissive License
|
|
|
|
* (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
|
|
|
|
* 2.0 as shown at https://www.apache.org/licenses/LICENSE-2.0. You may choose
|
|
|
|
* either license.
|
2015-07-20 12:42:12 +08:00
|
|
|
*
|
2023-02-21 09:43:43 +08:00
|
|
|
* If you elect to accept the software under the Apache License, Version 2.0,
|
|
|
|
* the following applies:
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
2015-07-20 12:42:12 +08:00
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
2023-02-21 09:43:43 +08:00
|
|
|
* https://www.apache.org/licenses/LICENSE-2.0
|
2015-07-20 12:42:12 +08:00
|
|
|
*
|
2023-02-21 09:43:43 +08:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
2015-07-20 12:42:12 +08:00
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2016-03-24 14:09:53 +08:00
|
|
|
*
|
2015-07-20 12:42:12 +08:00
|
|
|
* NAME
|
|
|
|
* 27. dataTypeNumber2.js
|
|
|
|
*
|
|
|
|
* DESCRIPTION
|
|
|
|
* Testing Oracle data type support - NUMBER(p, s).
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2016-03-24 14:31:19 +08:00
|
|
|
'use strict';
|
2016-03-24 14:09:53 +08:00
|
|
|
|
2015-07-20 12:42:12 +08:00
|
|
|
var oracledb = require('oracledb');
|
2016-03-24 14:31:19 +08:00
|
|
|
var should = require('should');
|
|
|
|
var assist = require('./dataTypeAssist.js');
|
2016-02-29 10:19:26 +08:00
|
|
|
var dbConfig = require('./dbconfig.js');
|
2015-07-20 12:42:12 +08:00
|
|
|
|
|
|
|
describe('27. dataTypeNumber2.js', function() {
|
2016-03-24 14:09:53 +08:00
|
|
|
|
2015-09-02 20:33:00 +08:00
|
|
|
var connection = null;
|
2016-03-24 14:31:19 +08:00
|
|
|
var tableName = "nodb_number2";
|
2015-09-02 20:33:00 +08:00
|
|
|
var numbers = assist.data.numbers;
|
|
|
|
|
|
|
|
before('get one connection', function(done) {
|
2023-02-21 12:04:16 +08:00
|
|
|
oracledb.getConnection(dbConfig,
|
2017-06-14 09:54:15 +08:00
|
|
|
function(err, conn) {
|
|
|
|
should.not.exist(err);
|
|
|
|
connection = conn;
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
2016-03-24 14:09:53 +08:00
|
|
|
|
2015-09-02 20:33:00 +08:00
|
|
|
after('release connection', function(done) {
|
2021-04-01 12:48:37 +08:00
|
|
|
connection.release(function(err) {
|
2015-09-02 20:33:00 +08:00
|
|
|
should.not.exist(err);
|
|
|
|
done();
|
|
|
|
});
|
2017-06-14 09:54:15 +08:00
|
|
|
});
|
2015-09-02 20:33:00 +08:00
|
|
|
|
|
|
|
describe('27.1 testing NUMBER(p, s) data', function() {
|
|
|
|
|
2021-04-01 12:48:37 +08:00
|
|
|
before('create table, insert data', function(done) {
|
2015-09-02 20:33:00 +08:00
|
|
|
assist.setUp(connection, tableName, numbers, done);
|
2017-06-14 09:54:15 +08:00
|
|
|
});
|
2015-09-02 20:33:00 +08:00
|
|
|
|
|
|
|
after(function(done) {
|
|
|
|
connection.execute(
|
2017-06-14 09:54:15 +08:00
|
|
|
"DROP table " + tableName + " PURGE",
|
2015-09-02 20:33:00 +08:00
|
|
|
function(err) {
|
|
|
|
should.not.exist(err);
|
|
|
|
done();
|
2015-07-20 12:42:12 +08:00
|
|
|
}
|
2015-09-02 20:33:00 +08:00
|
|
|
);
|
2017-06-14 09:54:15 +08:00
|
|
|
});
|
2015-09-02 20:33:00 +08:00
|
|
|
|
|
|
|
it('27.1.1 SELECT query', function(done) {
|
2017-06-14 09:54:15 +08:00
|
|
|
connection.should.be.ok();
|
2015-09-02 20:33:00 +08:00
|
|
|
connection.execute(
|
|
|
|
"SELECT * FROM " + tableName,
|
|
|
|
[],
|
2019-06-15 12:51:36 +08:00
|
|
|
{ outFormat: oracledb.OUT_FORMAT_OBJECT },
|
2015-09-02 20:33:00 +08:00
|
|
|
function(err, result) {
|
|
|
|
should.not.exist(err);
|
|
|
|
// console.log(result);
|
2021-04-01 12:48:37 +08:00
|
|
|
for (var j = 0; j < numbers.length; j++) {
|
|
|
|
if (Math.abs(numbers[result.rows[j].NUM]) == 0.00000123)
|
2015-09-02 20:33:00 +08:00
|
|
|
result.rows[j].CONTENT.should.be.exactly(0);
|
2016-03-24 14:09:53 +08:00
|
|
|
else
|
2015-09-02 20:33:00 +08:00
|
|
|
result.rows[j].CONTENT.should.be.exactly(numbers[result.rows[j].NUM]);
|
2015-07-20 12:42:12 +08:00
|
|
|
}
|
2015-07-20 15:56:29 +08:00
|
|
|
done();
|
2015-07-20 12:42:12 +08:00
|
|
|
}
|
2015-09-02 20:33:00 +08:00
|
|
|
);
|
2017-06-14 09:54:15 +08:00
|
|
|
}); // 27.1.1
|
2015-09-02 20:33:00 +08:00
|
|
|
|
|
|
|
it('27.1.2 resultSet stores NUMBER(p, s) data correctly', function(done) {
|
2017-06-14 09:54:15 +08:00
|
|
|
connection.should.be.ok();
|
2015-09-02 20:33:00 +08:00
|
|
|
var numRows = 3; // number of rows to return from each call to getRows()
|
|
|
|
connection.execute(
|
|
|
|
"SELECT * FROM " + tableName,
|
|
|
|
[],
|
2019-06-15 12:51:36 +08:00
|
|
|
{ resultSet: true, outFormat: oracledb.OUT_FORMAT_OBJECT },
|
2015-09-02 20:33:00 +08:00
|
|
|
function(err, result) {
|
|
|
|
should.not.exist(err);
|
|
|
|
(result.resultSet.metaData[0]).name.should.eql('NUM');
|
|
|
|
(result.resultSet.metaData[1]).name.should.eql('CONTENT');
|
|
|
|
fetchRowsFromRS(result.resultSet);
|
|
|
|
}
|
|
|
|
);
|
2016-03-24 14:09:53 +08:00
|
|
|
|
2015-09-02 20:33:00 +08:00
|
|
|
function fetchRowsFromRS(rs) {
|
|
|
|
rs.getRows(numRows, function(err, rows) {
|
|
|
|
should.not.exist(err);
|
2021-04-01 12:48:37 +08:00
|
|
|
if (rows.length > 0) {
|
|
|
|
for (var i = 0; i < rows.length; i++) {
|
|
|
|
if (Math.abs(numbers[rows[i].NUM]) == 0.00000123)
|
2015-09-02 20:33:00 +08:00
|
|
|
rows[i].CONTENT.should.be.exactly(0);
|
2017-06-14 09:54:15 +08:00
|
|
|
else
|
2017-06-17 07:40:09 +08:00
|
|
|
rows[i].CONTENT.should.be.exactly(numbers[rows[i].NUM]);
|
2015-09-02 20:33:00 +08:00
|
|
|
}
|
|
|
|
return fetchRowsFromRS(rs);
|
2021-04-01 12:48:37 +08:00
|
|
|
} else if (rows.length == 0) {
|
2015-09-02 20:33:00 +08:00
|
|
|
rs.close(function(err) {
|
|
|
|
should.not.exist(err);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
var lengthLessThanZero = true;
|
|
|
|
should.not.exist(lengthLessThanZero);
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
});
|
2016-03-24 14:09:53 +08:00
|
|
|
}
|
2017-06-14 09:54:15 +08:00
|
|
|
});
|
2015-09-02 20:33:00 +08:00
|
|
|
|
2017-06-14 09:54:15 +08:00
|
|
|
}); // 27.1
|
2016-03-24 14:09:53 +08:00
|
|
|
|
2015-09-02 20:33:00 +08:00
|
|
|
describe('27.2 stores null value correctly', function() {
|
|
|
|
it('27.2.1 testing Null, Empty string and Undefined', function(done) {
|
|
|
|
assist.verifyNullValues(connection, tableName, done);
|
2017-06-14 09:54:15 +08:00
|
|
|
});
|
|
|
|
});
|
2015-09-02 20:33:00 +08:00
|
|
|
|
2017-06-14 09:54:15 +08:00
|
|
|
});
|