node-oracledb/test/dataTypeTimestamp4.js

144 lines
4.3 KiB
JavaScript
Raw Normal View History

2015-07-20 12:42:12 +08:00
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
/******************************************************************************
*
* 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.
*
* The node-oracledb test suite uses 'mocha', 'should' and 'async'.
* See LICENSE.md for relevant licenses.
*
* NAME
* 36. dataTypeTimestamp4.js
*
* DESCRIPTION
* Testing Oracle data type support - TIMESTAMP (2) WITH TIME ZONE.
*
* NOTE
* TIMESTAMP support is still under enhancement request. This test is suspended.
*
* 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
* 51 - are for other tests
*
*****************************************************************************/
2015-09-02 20:33:00 +08:00
"use strict";
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('36. dataTypeTimestamp4.js', function() {
if(dbConfig.externalAuth){
var credential = { externalAuth: true, connectString: dbConfig.connectString };
} else {
var credential = dbConfig;
}
var connection = false;
var tableName = "oracledb_datatype_timestamp";
var sqlCreate =
"BEGIN " +
" 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 +" ( " +
" num NUMBER, " +
" content TIMESTAMP(2) WITH TIME ZONE " +
" )" +
" '); " +
"END; ";
var sqlDrop = "DROP table " + tableName;
before( function(done){
oracledb.getConnection(credential, function(err, conn){
if(err) { console.error(err.message); return; }
connection = conn;
connection.execute(
sqlCreate,
function(err) {
if(err) { console.error(err.message); return; }
done();
}
);
});
})
after( function(done){
connection.execute(
sqlDrop,
function(err) {
if(err) { console.error(err.message); return; }
connection.release( function(err) {
if(err) { console.error(err.message); return; }
done();
});
}
);
})
2015-08-17 14:19:36 +08:00
it('supports TIMESTAMP WITH TIME ZONE data type', function(done) {
2015-07-20 12:42:12 +08:00
connection.should.be.ok;
var timestamps = [
new Date(-100000000),
new Date(0),
new Date(10000000000),
new Date(100000000000)
];
var sqlInsert = "INSERT INTO " + tableName + " VALUES(:no, :bindValue)";
async.forEach(timestamps, function(timestamp, callback) {
connection.execute(
sqlInsert,
{ no: timestamps.indexOf(timestamp), bindValue: timestamp },
function(err) {
should.not.exist(err);
callback();
}
);
}, function(err) {
should.not.exist(err);
connection.execute(
"SELECT * FROM " + tableName,
[],
{ outFormat: oracledb.OBJECT },
function(err, result) {
2015-08-17 14:19:36 +08:00
should.exist(err);
err.message.should.startWith('NJS-010:'); // unsupported data type in select list
/*
console.log(result);
2015-07-20 12:42:12 +08:00
for(var j = 0; j < timestamps.length; j++)
result.rows[j].CONTENT.toUTCString().should.eql(timestamps[result.rows[j].NUM].toUTCString());
2015-08-17 14:19:36 +08:00
*/
done();
2015-07-20 12:42:12 +08:00
}
);
});
})
})