node-oracledb/test/longrawProcedureBind_in.js

294 lines
10 KiB
JavaScript
Raw Normal View History

2023-02-21 12:04:16 +08:00
/* Copyright (c) 2017, 2023, Oracle and/or its affiliates. */
2017-06-29 14:17:44 +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.
2017-06-29 14:17:44 +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.
2017-06-29 14:17:44 +08:00
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
2017-06-29 14:17:44 +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.
2017-06-29 14:17:44 +08:00
* See the License for the specific language governing permissions and
* limitations under the License.
*
* NAME
* 132. longrawProcedureBind_in.js
*
* DESCRIPTION
* Test LONG RAW type PLSQL procedure support.
* https://docs.oracle.com/cloud/latest/db121/LNPLS/datatypes.htm#LNPLS346
*
*****************************************************************************/
'use strict';
var oracledb = require('oracledb');
var should = require('should');
var async = require('async');
var dbConfig = require('./dbconfig.js');
var random = require('./random.js');
var sql = require('./sql.js');
var assist = require('./dataTypeAssist.js');
describe('132. longrawProcedureBind_in.js', function() {
2017-06-29 14:17:44 +08:00
var connection = null;
2023-02-21 12:04:16 +08:00
const tableName = "nodb_longraw_132";
2017-06-29 14:17:44 +08:00
var insertID = 0;
2023-02-21 12:04:16 +08:00
// The NOCOMPRESS option for CREATE TABLE ensures that Hybrid Columnar Compression (HCC) is disabled for tables with LONG and LONG RAW Columns
// in all types of Oracle Databases. (Note: HCC is enabled in Oracle ADB-S and ADB-D by default)
// When HCC is enabled, Tables with LONG and LONG RAW columns cannot be created.
2017-06-29 14:17:44 +08:00
var table_create = "BEGIN \n" +
" DECLARE \n" +
" e_table_missing EXCEPTION; \n" +
" PRAGMA EXCEPTION_INIT(e_table_missing, -00942); \n" +
" BEGIN \n" +
" EXECUTE IMMEDIATE('DROP TABLE " + tableName + " PURGE'); \n" +
" EXCEPTION \n" +
" WHEN e_table_missing \n" +
" THEN NULL; \n" +
" END; \n" +
" EXECUTE IMMEDIATE (' \n" +
" CREATE TABLE " + tableName + " ( \n" +
" id NUMBER, \n" +
" content LONG RAW \n" +
2023-02-21 12:04:16 +08:00
" ) NOCOMPRESS \n" +
2017-06-29 14:17:44 +08:00
" '); \n" +
"END; ";
var table_drop = "DROP TABLE " + tableName + " PURGE";
before(function(done) {
async.series([
function(cb) {
oracledb.getConnection(dbConfig, function(err, conn) {
should.not.exist(err);
connection = conn;
cb();
});
},
function(cb) {
sql.executeSql(connection, table_create, {}, {}, cb);
}
], done);
}); // before
after(function(done) {
async.series([
function(cb) {
sql.executeSql(connection, table_drop, {}, {}, cb);
},
function(cb) {
connection.release(function(err) {
should.not.exist(err);
cb();
});
}
], done);
}); // after
beforeEach(function(done) {
insertID++;
done();
});
describe('132.1 PLSQL PROCEDURE BIND IN AS LONG RAW', function() {
var proc_bindin_name = "nodb_longraw_bindin_proc_1";
var proc_bindin_create = "CREATE OR REPLACE PROCEDURE " + proc_bindin_name + " (NUM IN NUMBER, C IN LONG RAW) \n" +
"AS \n" +
"BEGIN \n" +
" insert into " + tableName + " values (NUM, C); \n" +
"END " + proc_bindin_name + ";";
var proc_bindin_exec = "BEGIN " + proc_bindin_name + " (:i, :c); END;";
var proc_bindin_drop = "DROP PROCEDURE " + proc_bindin_name;
before(function(done) {
sql.executeSql(connection, proc_bindin_create, {}, {}, done);
});
after(function(done) {
sql.executeSql(connection, proc_bindin_drop, {}, {}, done);
});
it('132.1.1 works with NULL', function(done) {
var insertedStr = null;
longraw_bindin(insertedStr, proc_bindin_exec, done);
});
it('132.1.2 works with undefined', function(done) {
var insertedStr = undefined;
longraw_bindin(insertedStr, proc_bindin_exec, done);
});
it('132.1.3 works with empty buffer', function(done) {
var insertedBuf = Buffer.from("");
2017-06-29 14:17:44 +08:00
longraw_bindin(insertedBuf, proc_bindin_exec, done);
});
it('132.1.4 works with data size 2000', function(done) {
var insertedStr = random.getRandomLengthString(2000);
longraw_bindin(insertedStr, proc_bindin_exec, done);
});
it('132.1.5 works with data size (32K - 1)', function(done) {
var insertedStr = random.getRandomLengthString(32767);
longraw_bindin(insertedStr, proc_bindin_exec, done);
});
it('132.1.6 set maxSize to size (32K - 1)', function(done) {
var insertedStr = random.getRandomLengthString(100);
longraw_bindin_maxSize(insertedStr, proc_bindin_exec, 32767, done);
});
it('132.1.7 set maxSize to size 1GB', function(done) {
var insertedStr = random.getRandomLengthString(100);
var maxsize = 1 * 1024 * 1024 * 1024;
longraw_bindin_maxSize(insertedStr, proc_bindin_exec, maxsize, done);
});
}); // 132.1
describe('132.2 PLSQL PROCEDURE BIND IN AS RAW', function() {
var proc_bindin_name = "nodb_longraw_bindin_proc_2";
var proc_bindin_create = "CREATE OR REPLACE PROCEDURE " + proc_bindin_name + " (NUM IN NUMBER, C IN RAW) \n" +
"AS \n" +
"BEGIN \n" +
" insert into " + tableName + " values (NUM, C); \n" +
"END " + proc_bindin_name + ";";
var proc_bindin_exec = "BEGIN " + proc_bindin_name + " (:i, :c); END;";
var proc_bindin_drop = "DROP PROCEDURE " + proc_bindin_name;
before(function(done) {
sql.executeSql(connection, proc_bindin_create, {}, {}, done);
});
after(function(done) {
sql.executeSql(connection, proc_bindin_drop, {}, {}, done);
});
it('132.2.1 works with NULL', function(done) {
var insertedStr = null;
longraw_bindin(insertedStr, proc_bindin_exec, done);
});
it('132.2.2 works with undefined', function(done) {
var insertedStr = undefined;
longraw_bindin(insertedStr, proc_bindin_exec, done);
});
it('132.2.3 works with empty buffer', function(done) {
var insertedStr = Buffer.from("");
2017-06-29 14:17:44 +08:00
longraw_bindin(insertedStr, proc_bindin_exec, done);
});
it('132.2.4 works with data size 2000', function(done) {
var insertedStr = random.getRandomLengthString(2000);
longraw_bindin(insertedStr, proc_bindin_exec, done);
});
it('132.2.5 works with data size 32767', function(done) {
var insertedStr = random.getRandomLengthString(32767);
longraw_bindin(insertedStr, proc_bindin_exec, done);
});
it('132.2.6 set maxSize to size (32K - 1)', function(done) {
var insertedStr = random.getRandomLengthString(100);
longraw_bindin_maxSize(insertedStr, proc_bindin_exec, 32767, done);
});
it('132.2.7 set maxSize to size 1GB', function(done) {
var insertedStr = random.getRandomLengthString(100);
var maxsize = 1 * 1024 * 1024 * 1024;
longraw_bindin_maxSize(insertedStr, proc_bindin_exec, maxsize, done);
});
}); // 132.2
var longraw_bindin = function(insertContent, proc_bindin_exec, callback) {
var insertBuf, expectedBuf;
2021-04-01 12:48:37 +08:00
if (insertContent == null || insertContent == undefined || insertContent.length == 0) {
2017-06-29 14:17:44 +08:00
insertBuf = insertContent;
expectedBuf = null;
} else {
insertBuf = Buffer.from(insertContent);
2017-06-29 14:17:44 +08:00
expectedBuf = insertBuf;
}
async.series([
function(cb) {
var bind_in_var = {
i: { val: insertID, dir: oracledb.BIND_IN, type: oracledb.NUMBER },
c: { val: insertBuf, dir: oracledb.BIND_IN, type: oracledb.BUFFER }
};
connection.execute(
proc_bindin_exec,
bind_in_var,
function(err) {
should.not.exist(err);
cb();
}
);
},
function(cb) {
checkResult(expectedBuf, cb);
}
], callback);
};
var longraw_bindin_maxSize = function(insertContent, proc_bindin_exec, maxsize, callback) {
var insertBuf, expectedBuf;
2021-04-01 12:48:37 +08:00
if (insertContent == null || insertContent == undefined) {
2017-06-29 14:17:44 +08:00
insertBuf = insertContent;
expectedBuf = null;
} else {
insertBuf = Buffer.from(insertContent);
2017-06-29 14:17:44 +08:00
expectedBuf = insertBuf;
}
async.series([
function(cb) {
var bind_in_var = {
i: { val: insertID, dir: oracledb.BIND_IN, type: oracledb.NUMBER },
c: { val: insertBuf, dir: oracledb.BIND_IN, type: oracledb.BUFFER, maxSize: maxsize }
};
connection.execute(
proc_bindin_exec,
bind_in_var,
function(err) {
should.not.exist(err);
cb();
}
);
},
function(cb) {
checkResult(expectedBuf, cb);
}
], callback);
};
var checkResult = function(expected, callback) {
connection.execute(
"select * from " + tableName + " where id = " + insertID,
function(err, result) {
should.not.exist(err);
should.strictEqual(result.rows[0][0], insertID);
2021-04-01 12:48:37 +08:00
if (expected == null) {
2017-06-29 14:17:44 +08:00
should.strictEqual(result.rows[0][1], expected);
} else {
assist.compare2Buffers(result.rows[0][1], expected);
}
callback();
}
);
};
});