2018-02-09 16:51:13 +08:00
|
|
|
/* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. */
|
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
|
|
|
*
|
|
|
|
* The node-oracledb test suite uses 'mocha', 'should' and 'async'.
|
2015-07-20 12:42:12 +08:00
|
|
|
* See LICENSE.md for relevant licenses.
|
|
|
|
*
|
|
|
|
* NAME
|
|
|
|
* 22. dataTypeChar.js
|
|
|
|
*
|
|
|
|
* DESCRIPTION
|
|
|
|
* Testing Oracle data type support - CHAR.
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2016-03-24 14:31:19 +08:00
|
|
|
'use strict';
|
2015-07-20 12:42:12 +08:00
|
|
|
|
|
|
|
var oracledb = require('oracledb');
|
2016-01-30 19:31:33 +08:00
|
|
|
var should = require('should');
|
|
|
|
var assist = require('./dataTypeAssist.js');
|
2016-02-29 10:19:26 +08:00
|
|
|
var dbConfig = require('./dbconfig.js');
|
2016-01-30 19:31:33 +08:00
|
|
|
var async = require('async');
|
2015-07-20 12:42:12 +08:00
|
|
|
|
|
|
|
describe('22. dataTypeChar.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_char";
|
2015-07-20 15:56:29 +08:00
|
|
|
|
|
|
|
var strLen = [100, 1000, 2000]; // char string length
|
2016-03-24 14:09:53 +08:00
|
|
|
var strs =
|
2017-06-14 09:54:15 +08:00
|
|
|
[
|
|
|
|
assist.createCharString(strLen[0]),
|
|
|
|
assist.createCharString(strLen[1]),
|
|
|
|
assist.createCharString(strLen[2]),
|
|
|
|
];
|
2015-09-02 20:33:00 +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();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
2016-03-24 14:09:53 +08:00
|
|
|
|
2015-09-02 20:33:00 +08:00
|
|
|
after('release connection', function(done) {
|
|
|
|
connection.release( function(err) {
|
|
|
|
should.not.exist(err);
|
|
|
|
done();
|
|
|
|
});
|
2017-06-14 09:54:15 +08:00
|
|
|
});
|
2015-09-02 20:33:00 +08:00
|
|
|
|
|
|
|
describe('22.1 testing CHAR data in various lengths', function() {
|
2016-03-24 14:09:53 +08:00
|
|
|
|
2015-09-02 20:33:00 +08:00
|
|
|
before('create table, insert data',function(done) {
|
|
|
|
assist.setUp(connection, tableName, strs, done);
|
2017-06-14 09:54:15 +08:00
|
|
|
});
|
2015-09-02 20:33:00 +08:00
|
|
|
|
|
|
|
after(function(done) {
|
2017-11-17 19:59:41 +08:00
|
|
|
oracledb.fetchAsString = [];
|
2015-09-02 20:33:00 +08:00
|
|
|
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);
|
2015-07-20 15:56:29 +08:00
|
|
|
done();
|
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('22.1.1 works well with SELECT query', function(done) {
|
|
|
|
assist.dataTypeSupport(connection, tableName, strs, done);
|
2017-06-14 09:54:15 +08:00
|
|
|
});
|
2015-09-02 20:33:00 +08:00
|
|
|
|
|
|
|
it('22.1.2 works well with result set', function(done) {
|
|
|
|
assist.verifyResultSet(connection, tableName, strs, done);
|
2017-06-14 09:54:15 +08:00
|
|
|
});
|
2015-09-02 20:33:00 +08:00
|
|
|
|
|
|
|
it('22.1.3 works well with REF Cursor', function(done) {
|
|
|
|
assist.verifyRefCursor(connection, tableName, strs, done);
|
2017-06-14 09:54:15 +08:00
|
|
|
});
|
2017-11-17 19:59:41 +08:00
|
|
|
|
|
|
|
it('22.1.4 columns fetched from REF CURSORS can be mapped by fetchInfo settings', function(done) {
|
|
|
|
assist.verifyRefCursorWithFetchInfo(connection, tableName, strs, done);
|
|
|
|
});
|
|
|
|
|
2017-06-14 09:54:15 +08:00
|
|
|
});
|
2015-09-02 20:33:00 +08:00
|
|
|
|
|
|
|
describe('22.2 stores null value correctly', function() {
|
|
|
|
it('22.2.1 testing Null, Empty string and Undefined', function(done) {
|
|
|
|
assist.verifyNullValues(connection, tableName, done);
|
2017-06-14 09:54:15 +08:00
|
|
|
});
|
|
|
|
});
|
2016-01-30 19:31:33 +08:00
|
|
|
|
|
|
|
describe('22.3 PL/SQL binding scalar', function() {
|
|
|
|
|
|
|
|
it('22.3.1 PL/SQL binding scalar values IN', function(done) {
|
|
|
|
async.series([
|
|
|
|
function(callback) {
|
|
|
|
var proc = "CREATE OR REPLACE\n" +
|
|
|
|
"FUNCTION testchar(stringValue IN CHAR) RETURN CHAR\n" +
|
|
|
|
"IS\n" +
|
|
|
|
"BEGIN\n" +
|
|
|
|
" RETURN 'Hello ' || stringValue || ' world!';\n" +
|
|
|
|
"END testchar;";
|
2017-06-14 09:54:15 +08:00
|
|
|
connection.should.be.ok();
|
2016-01-30 19:31:33 +08:00
|
|
|
connection.execute(
|
|
|
|
proc,
|
|
|
|
function(err) {
|
|
|
|
should.not.exist(err);
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
function(callback) {
|
|
|
|
var bindvars = {
|
|
|
|
result: {type: oracledb.STRING, dir: oracledb.BIND_OUT},
|
|
|
|
stringValue: {type: oracledb.STRING, dir: oracledb.BIND_IN, val: 'Node.js'}
|
|
|
|
};
|
|
|
|
connection.execute(
|
|
|
|
"BEGIN :result := testchar(:stringValue); END;",
|
|
|
|
bindvars,
|
2017-06-14 09:54:15 +08:00
|
|
|
function(err) {
|
2016-01-30 19:31:33 +08:00
|
|
|
should.not.exist(err);
|
|
|
|
// console.log(result);
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
function(callback) {
|
|
|
|
connection.execute(
|
|
|
|
"DROP FUNCTION testchar",
|
|
|
|
function(err) {
|
|
|
|
should.not.exist(err);
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2016-03-24 14:09:53 +08:00
|
|
|
], done);
|
2017-06-14 09:54:15 +08:00
|
|
|
}); // 22.3.1
|
2016-01-30 19:31:33 +08:00
|
|
|
|
|
|
|
it('22.3.2 bind scalar values INOUT', function(done) {
|
|
|
|
async.series([
|
|
|
|
function(callback) {
|
|
|
|
var proc = "CREATE OR REPLACE\n" +
|
2016-05-16 07:43:20 +08:00
|
|
|
"PROCEDURE nodb_testproc(stringValue IN OUT NOCOPY CHAR)\n" +
|
2016-01-30 19:31:33 +08:00
|
|
|
"IS\n" +
|
|
|
|
"BEGIN\n" +
|
|
|
|
" stringValue := '(' || stringValue || ')';\n" +
|
2016-05-16 07:43:20 +08:00
|
|
|
"END nodb_testproc;\n";
|
2016-01-30 19:31:33 +08:00
|
|
|
connection.execute(
|
|
|
|
proc,
|
|
|
|
function(err) {
|
|
|
|
should.not.exist(err);
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
);
|
2016-03-24 14:09:53 +08:00
|
|
|
},
|
2016-01-30 19:31:33 +08:00
|
|
|
function(callback) {
|
|
|
|
var bindvars = { stringValue: {type: oracledb.STRING, dir: oracledb.BIND_INOUT, val: 'Node.js'} };
|
|
|
|
connection.execute(
|
2016-05-16 07:43:20 +08:00
|
|
|
"BEGIN nodb_testproc(:stringValue); END;",
|
2016-01-30 19:31:33 +08:00
|
|
|
bindvars,
|
|
|
|
function(err, result) {
|
|
|
|
should.exist(err);
|
|
|
|
// Error: ORA-06502: PL/SQL: numeric or value error: character string buffer too small
|
|
|
|
// For SQL*PLUS driver, the behavior is the same
|
2017-06-14 09:54:15 +08:00
|
|
|
|
|
|
|
should.not.exist(result);
|
2016-01-30 19:31:33 +08:00
|
|
|
callback();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
function(callback) {
|
|
|
|
connection.execute(
|
2016-05-16 07:43:20 +08:00
|
|
|
"DROP PROCEDURE nodb_testproc",
|
2016-01-30 19:31:33 +08:00
|
|
|
function(err) {
|
|
|
|
should.not.exist(err);
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
], done);
|
2017-06-14 09:54:15 +08:00
|
|
|
}); // 22.3.2
|
2016-01-30 19:31:33 +08:00
|
|
|
|
|
|
|
it('22.3.3 bind scalar values OUT', function(done) {
|
|
|
|
async.series([
|
|
|
|
function(callback) {
|
|
|
|
var proc = "CREATE OR REPLACE\n" +
|
2016-05-16 07:43:20 +08:00
|
|
|
"PROCEDURE nodb_testproc(stringValue OUT NOCOPY CHAR)\n" +
|
2016-01-30 19:31:33 +08:00
|
|
|
"IS\n" +
|
|
|
|
"BEGIN\n" +
|
|
|
|
" stringValue := 'Hello Node.js World!';\n" +
|
2016-05-16 07:43:20 +08:00
|
|
|
"END nodb_testproc;\n";
|
2016-01-30 19:31:33 +08:00
|
|
|
connection.execute(
|
|
|
|
proc,
|
|
|
|
function(err) {
|
|
|
|
should.not.exist(err);
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
);
|
2016-03-24 14:09:53 +08:00
|
|
|
},
|
2016-01-30 19:31:33 +08:00
|
|
|
function(callback) {
|
|
|
|
var bindvars = { stringValue: {type: oracledb.STRING, dir: oracledb.BIND_OUT, maxSize:200} };
|
|
|
|
connection.execute(
|
2016-05-16 07:43:20 +08:00
|
|
|
"BEGIN nodb_testproc(:stringValue); END;",
|
2016-01-30 19:31:33 +08:00
|
|
|
bindvars,
|
|
|
|
function(err, result) {
|
|
|
|
should.not.exist(err);
|
2016-03-24 14:09:53 +08:00
|
|
|
// There are trailing spaces with the outBind value as CHAR is a kind of
|
2016-01-30 19:31:33 +08:00
|
|
|
// fix-size data type. So the case uses trim() function.
|
|
|
|
(result.outBinds.stringValue.trim()).should.be.exactly('Hello Node.js World!');
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
function(callback) {
|
|
|
|
connection.execute(
|
2016-05-16 07:43:20 +08:00
|
|
|
"DROP PROCEDURE nodb_testproc",
|
2016-01-30 19:31:33 +08:00
|
|
|
function(err) {
|
|
|
|
should.not.exist(err);
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
], done);
|
2017-06-14 09:54:15 +08:00
|
|
|
}); // 22.3.3
|
|
|
|
}); // 22.3
|
2016-01-30 19:31:33 +08:00
|
|
|
|
|
|
|
describe('22.4 PL/SQL binding indexed tables', function() {
|
2016-03-24 14:09:53 +08:00
|
|
|
|
2016-01-30 19:31:33 +08:00
|
|
|
it.skip('22.4.1 bind indexed table IN', function(done) {
|
|
|
|
async.series([
|
|
|
|
function(callback) {
|
|
|
|
var proc = "CREATE OR REPLACE PACKAGE\n" +
|
2016-03-24 14:31:19 +08:00
|
|
|
"nodb_testpack\n" +
|
2016-01-30 19:31:33 +08:00
|
|
|
"IS\n" +
|
|
|
|
" TYPE stringsType IS TABLE OF CHAR(30) INDEX BY BINARY_INTEGER;\n" +
|
|
|
|
" FUNCTION test(strings IN stringsType) RETURN CHAR;\n" +
|
|
|
|
"END;";
|
2017-06-14 09:54:15 +08:00
|
|
|
connection.should.be.ok();
|
2016-01-30 19:31:33 +08:00
|
|
|
connection.execute(
|
|
|
|
proc,
|
|
|
|
function(err) {
|
|
|
|
should.not.exist(err);
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
function(callback) {
|
|
|
|
var proc = "CREATE OR REPLACE PACKAGE BODY\n" +
|
2016-03-24 14:31:19 +08:00
|
|
|
"nodb_testpack\n" +
|
2016-01-30 19:31:33 +08:00
|
|
|
"IS\n" +
|
2016-05-16 07:43:20 +08:00
|
|
|
" FUNCTION nodb_testfunc(strings IN stringsType) RETURN CHAR\n" +
|
2016-01-30 19:31:33 +08:00
|
|
|
" IS\n" +
|
|
|
|
" s CHAR(2000) := '';\n" +
|
|
|
|
" BEGIN\n" +
|
|
|
|
" FOR i IN 1 .. strings.COUNT LOOP\n" +
|
|
|
|
" s := s || strings(i);\n" +
|
|
|
|
" END LOOP;\n" +
|
|
|
|
" RETURN s;\n" +
|
|
|
|
" END;\n" +
|
|
|
|
"END;";
|
|
|
|
connection.execute(
|
|
|
|
proc,
|
|
|
|
function(err) {
|
|
|
|
should.not.exist(err);
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
function(callback) {
|
|
|
|
var bindvars = {
|
|
|
|
result: {type: oracledb.STRING, dir: oracledb.BIND_OUT, maxSize: 2000},
|
|
|
|
strings: {type: oracledb.STRING, dir: oracledb.BIND_IN, val: ['John', 'Doe']}
|
|
|
|
};
|
|
|
|
connection.execute(
|
2016-05-16 07:43:20 +08:00
|
|
|
"BEGIN :result := nodb_testpack.nodb_testfunc(:strings); END;",
|
2016-01-30 19:31:33 +08:00
|
|
|
bindvars,
|
|
|
|
function(err, result) {
|
|
|
|
should.not.exist(err);
|
|
|
|
console.log(result);
|
|
|
|
//result.outBinds.result.should.be.exactly('JohnDoe');
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
function(callback) {
|
|
|
|
connection.execute(
|
2016-03-24 14:31:19 +08:00
|
|
|
"DROP PACKAGE nodb_testpack",
|
2016-01-30 19:31:33 +08:00
|
|
|
function(err) {
|
|
|
|
should.not.exist(err);
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
], done);
|
2017-06-14 09:54:15 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|