node-oracledb/test/dataTypeNumber2.js

115 lines
3.9 KiB
JavaScript
Raw Normal View History

2023-02-21 14:08:24 +08:00
/* Copyright (c) 2015, 2023, Oracle and/or its affiliates. */
2015-07-20 12:42:12 +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
*
* 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
*
* https://www.apache.org/licenses/LICENSE-2.0
2015-07-20 12:42:12 +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).
*
*****************************************************************************/
'use strict';
2016-03-24 14:09:53 +08:00
2023-02-21 14:08:24 +08:00
const oracledb = require('oracledb');
2023-02-21 14:18:59 +08:00
const assert = require('assert');
2023-02-21 14:08:24 +08:00
const assist = require('./dataTypeAssist.js');
const 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
2023-02-21 14:08:24 +08:00
let connection = null;
2023-08-17 16:11:49 +08:00
const tableName = "nodb_number2";
const numbers = assist.data.numbers;
2023-02-21 14:18:59 +08:00
before('get one connection', async function() {
connection = await oracledb.getConnection(dbConfig);
2017-06-14 09:54:15 +08:00
});
2016-03-24 14:09:53 +08:00
2023-02-21 14:18:59 +08:00
after('release connection', async function() {
await connection.close();
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() {
2023-02-21 14:18:59 +08:00
before('create table, insert data', async function() {
2023-03-14 14:33:48 +08:00
await assist.setUp(connection, tableName, numbers);
2017-06-14 09:54:15 +08:00
});
2015-09-02 20:33:00 +08:00
2023-02-21 14:18:59 +08:00
after(async function() {
await connection.execute(`DROP table ` + tableName + ` PURGE`);
2017-06-14 09:54:15 +08:00
});
2015-09-02 20:33:00 +08:00
2023-02-21 14:18:59 +08:00
it('27.1.1 SELECT query', async function() {
2023-08-17 16:11:49 +08:00
const result = await connection.execute(
2023-02-21 14:18:59 +08:00
`SELECT * FROM ` + tableName,
2015-09-02 20:33:00 +08:00
[],
2023-02-21 14:18:59 +08:00
{ outFormat: oracledb.OUT_FORMAT_OBJECT });
for (let j = 0; j < numbers.length; j++) {
if (Math.abs(numbers[result.rows[j].NUM]) == 0.00000123)
assert.strictEqual(result.rows[j].CONTENT, 0);
else
assert.strictEqual(result.rows[j].CONTENT, numbers[result.rows[j].NUM]);
}
2017-06-14 09:54:15 +08:00
}); // 27.1.1
2015-09-02 20:33:00 +08:00
2023-02-21 14:18:59 +08:00
it('27.1.2 resultSet stores NUMBER(p, s) data correctly', async function() {
2023-08-17 16:11:49 +08:00
const numRows = 3; // number of rows to return from each call to getRows()
const result = await connection.execute(
2023-02-21 14:18:59 +08:00
`SELECT * FROM ` + tableName,
2015-09-02 20:33:00 +08:00
[],
2023-02-21 14:18:59 +08:00
{ resultSet: true, outFormat: oracledb.OUT_FORMAT_OBJECT });
assert.strictEqual((result.resultSet.metaData[0]).name, 'NUM');
assert.strictEqual((result.resultSet.metaData[1]).name, 'CONTENT');
await fetchRowsFromRS(result.resultSet);
async function fetchRowsFromRS(rs) {
2023-08-17 16:11:49 +08:00
const rows = await rs.getRows(numRows);
2023-02-21 14:18:59 +08:00
if (rows.length > 0) {
for (let i = 0; i < rows.length; i++) {
if (Math.abs(numbers[rows[i].NUM]) == 0.00000123)
assert.strictEqual(rows[i].CONTENT, 0);
else
assert.strictEqual(rows[i].CONTENT, numbers[rows[i].NUM]);
2015-09-02 20:33:00 +08:00
}
2023-02-21 14:18:59 +08:00
return fetchRowsFromRS(rs);
} else if (rows.length == 0) {
await rs.close();
} else {
2023-08-17 16:11:49 +08:00
const lengthLessThanZero = true;
2023-02-21 14:18:59 +08:00
assert.ifError(lengthLessThanZero);
}
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() {
2023-02-21 14:18:59 +08:00
it('27.2.1 testing Null, Empty string and Undefined', async function() {
2023-03-14 14:33:48 +08:00
await assist.verifyNullValues(connection, tableName);
2017-06-14 09:54:15 +08:00
});
});
2015-09-02 20:33:00 +08:00
2017-06-14 09:54:15 +08:00
});