node-oracledb/test/dataTypeTimestamp6.js

157 lines
4.7 KiB
JavaScript
Raw Normal View History

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
/******************************************************************************
*
* 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
*
2015-07-20 12:42:12 +08:00
* NAME
* 38. dataTypeTimestamp6.js
*
* DESCRIPTION
* Testing Oracle data type support - TIMESTAMP (9) WITH LOCAL TIME ZONE.
*
* NOTE
* TIMESTAMP support is still under enhancement request. This test is suspended.
*
*****************************************************************************/
'use strict';
2015-09-02 20:33:00 +08:00
2015-07-20 12:42:12 +08:00
var oracledb = require('oracledb');
var should = require('should');
var async = require('async');
var assist = require('./dataTypeAssist.js');
var dbConfig = require('./dbconfig.js');
2015-07-20 12:42:12 +08:00
describe('38. dataTypeTimestamp6.js', function() {
2016-03-24 14:09:53 +08:00
2016-05-16 07:57:53 +08:00
var connection = null;
var tableName = "nodb_timestamp6";
2015-09-02 19:08:19 +08:00
before('get one connection', 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;
done();
}
);
});
2015-09-02 19:08:19 +08:00
after('release connection', function(done) {
2021-04-01 12:48:37 +08:00
connection.release(function(err) {
2015-09-02 19:08:19 +08:00
should.not.exist(err);
done();
});
2017-06-14 09:54:15 +08:00
});
2015-09-02 19:08:19 +08:00
describe('38.1 Testing JavaScript Date with database TIMESTAMP(9) WITH LOCAL TIME ZONE', function() {
var dates = assist.data.dates;
2021-04-01 12:48:37 +08:00
before('create table, insert data', function(done) {
2015-09-02 19:08:19 +08:00
assist.setUp(connection, tableName, dates, done);
2017-06-14 09:54:15 +08:00
});
2015-09-02 19:08:19 +08:00
after(function(done) {
2017-11-17 19:59:41 +08:00
oracledb.fetchAsString = [];
2015-09-02 19:08:19 +08:00
connection.execute(
2017-06-14 09:54:15 +08:00
"DROP table " + tableName + " PURGE",
2015-09-02 19:08:19 +08:00
function(err) {
should.not.exist(err);
done();
}
);
2017-06-14 09:54:15 +08:00
});
2015-09-02 19:08:19 +08:00
it('38.1.1 works well with SELECT query', function(done) {
assist.dataTypeSupport(connection, tableName, dates, done);
2017-06-14 09:54:15 +08:00
});
2015-09-02 19:08:19 +08:00
it('38.1.2 works well with result set', function(done) {
assist.verifyResultSet(connection, tableName, dates, done);
2017-06-14 09:54:15 +08:00
});
2016-03-24 14:09:53 +08:00
2015-09-02 20:33:00 +08:00
it('38.1.3 works well with REF Cursor', function(done) {
2015-09-02 19:08:19 +08:00
assist.verifyRefCursor(connection, tableName, dates, done);
2017-06-14 09:54:15 +08:00
});
2016-03-24 14:09:53 +08:00
2017-11-17 19:59:41 +08:00
it('38.1.4 columns fetched from REF CURSORS can be mapped by fetchInfo settings', function(done) {
assist.verifyRefCursorWithFetchInfo(connection, tableName, dates, done);
});
it('38.1.5 columns fetched from REF CURSORS can be mapped by oracledb.fetchAsString', function(done) {
oracledb.fetchAsString = [ oracledb.DATE ];
assist.verifyRefCursorWithFetchAsString(connection, tableName, dates, done);
});
2017-06-14 09:54:15 +08:00
}); // end of 37.1 suite
2016-03-24 14:09:53 +08:00
2015-09-02 19:08:19 +08:00
describe('38.2 stores null value correctly', function() {
it('38.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 19:08:19 +08:00
describe('38.3 testing TIMESTAMP WITH LOCAL TIME ZONE', function() {
2017-06-14 09:54:15 +08:00
var timestamps = assist.TIMESTAMP_TZ_STRINGS_2;
2015-09-02 19:08:19 +08:00
before(function(done) {
assist.setUp4sql(connection, tableName, timestamps, done);
2017-06-14 09:54:15 +08:00
});
2015-09-02 19:08:19 +08:00
after(function(done) {
connection.execute(
2017-06-14 09:54:15 +08:00
"DROP table " + tableName + " PURGE",
2015-09-02 19:08:19 +08:00
function(err) {
should.not.exist(err);
done();
}
);
2017-06-14 09:54:15 +08:00
}); // after
2015-09-02 19:08:19 +08:00
it('38.3.1 SELECT query - original data', function(done) {
assist.selectOriginalData(connection, tableName, timestamps, done);
2017-06-14 09:54:15 +08:00
});
2015-09-02 19:08:19 +08:00
it('38.3.2 SELECT query - formatted data for comparison', function(done) {
2016-03-24 14:09:53 +08:00
var sql = "SELECT num, TO_CHAR(content AT TIME ZONE '-8:00', 'DD-MM-YYYY HH24:MI:SS.FF TZR') AS TS_DATA FROM "
2015-09-02 20:33:00 +08:00
+ tableName + " WHERE num = :no";
async.eachSeries(timestamps, function(timestamp, cb) {
2015-09-02 19:08:19 +08:00
var bv = timestamps.indexOf(timestamp);
connection.execute(
2015-09-02 20:33:00 +08:00
sql,
2015-09-02 19:08:19 +08:00
{ no: bv },
2016-03-24 14:09:53 +08:00
{
outFormat: oracledb.OUT_FORMAT_OBJECT
2015-09-02 20:33:00 +08:00
},
2015-09-02 19:08:19 +08:00
function(err, result) {
should.not.exist(err);
// console.log(result.rows);
(result.rows[0].TS_DATA).should.equal(assist.content.timestamps6[bv]);
cb();
2016-03-24 14:09:53 +08:00
}
2015-09-02 19:08:19 +08:00
);
}, function(err) {
2017-06-14 09:54:15 +08:00
should.not.exist(err);
done();
2015-09-02 19:08:19 +08:00
});
2017-06-14 09:54:15 +08:00
});
}); // end of 38.3 suite
});