Add PL/SQL Array bind null and maxSize tests. Rename dbConfig.js to dbconfig.js.

This commit is contained in:
Christopher Jones 2016-02-29 13:19:26 +11:00
parent 4c43e67b19
commit 78e8716075
50 changed files with 548 additions and 283 deletions

View File

@ -34,7 +34,7 @@
var oracledb = require('oracledb');
var should = require('should');
var dbConfig = require('./dbConfig.js');
var dbConfig = require('./dbconfig.js');
describe('51. accessTerminatedPoolAttributes.js', function(){

View File

@ -36,7 +36,7 @@
var oracledb = require('oracledb');
var should = require('should');
var async = require('async');
var dbConfig = require('./dbConfig.js');
var dbConfig = require('./dbconfig.js');
describe('7. autoCommit.js', function() {

View File

@ -41,7 +41,7 @@
var oracledb = require('oracledb');
var should = require('should');
var async = require('async');
var dbConfig = require('./dbConfig.js');
var dbConfig = require('./dbconfig.js');
describe('63. autoCommit4nestedExecutes.js', function() {

View File

@ -35,7 +35,7 @@
var oracledb = require('oracledb');
var should = require('should');
var async = require('async');
var dbConfig = require('./dbConfig.js');
var dbConfig = require('./dbconfig.js');
describe('8. autoCommitForSelect.js', function(){

View File

@ -37,7 +37,7 @@
var oracledb = require('oracledb');
var should = require('should');
var async = require('async');
var dbConfig = require('./dbConfig.js');
var dbConfig = require('./dbconfig.js');
var assist = require('./dataTypeAssist.js');
describe('4. binding.js', function() {

View File

@ -38,7 +38,7 @@ var oracledb = require('oracledb');
var should = require('should');
var async = require('async');
var fs = require('fs');
var dbConfig = require('./dbConfig.js');
var dbConfig = require('./dbconfig.js');
var assist = require('./dataTypeAssist.js');
describe('61. checkClassesTypes.js', function() {

View File

@ -42,7 +42,7 @@ var oracledb = require('oracledb');
var async = require('async');
var should = require('should');
var stream = require('stream');
var dbConfig = require('./dbConfig.js');
var dbConfig = require('./dbconfig.js');
var assist = require('./dataTypeAssist.js');
describe('60. clobPlsqlString.js', function() {

View File

@ -35,7 +35,7 @@
var oracledb = require('oracledb');
var should = require('should');
var async = require('async');
var dbConfig = require('./dbConfig.js');
var dbConfig = require('./dbconfig.js');
describe('9. columnMetadata.js', function(){

View File

@ -35,7 +35,7 @@
var oracledb = require('oracledb');
var should = require('should');
var async = require('async');
var dbConfig = require('./dbConfig.js');
var dbConfig = require('./dbconfig.js');
describe('1. connection.js', function(){

View File

@ -41,7 +41,7 @@ var oracledb = require('oracledb');
var should = require('should');
var async = require('async');
var assist = require('./dataTypeAssist.js');
var dbConfig = require('./dbConfig.js');
var dbConfig = require('./dbconfig.js');
describe('31. dataTypeBinaryDouble.js', function() {

View File

@ -37,7 +37,7 @@ var oracledb = require('oracledb');
var should = require('should');
var async = require('async');
var assist = require('./dataTypeAssist.js');
var dbConfig = require('./dbConfig.js');
var dbConfig = require('./dbconfig.js');
describe('30. dataTypeBinaryFloat.js', function() {

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
/* Copyright (c) 2015, 2016 Oracle and/or its affiliates. All rights reserved. */
/******************************************************************************
*
@ -42,7 +42,7 @@ var oracledb = require('oracledb');
var fs = require('fs');
var async = require('async');
var should = require('should');
var dbConfig = require('./dbConfig.js');
var dbConfig = require('./dbconfig.js');
var assist = require('./dataTypeAssist.js');
var inFileName = './test/fuzzydinosaur.jpg'; // contains the image to be inserted
@ -94,9 +94,10 @@ describe('41. dataTypeBlob', function() {
connection.should.be.ok;
async.series([
function blobinsert1(callback) {
var streamEndEventFired = false;
var lobFinishEventFired = false;
setTimeout( function() {
streamEndEventFired.should.equal(true, "inStream does not call 'end' event!")
lobFinishEventFired.should.equal(true, "lob does not call 'finish' event!")
callback();
}, 2000);
@ -114,14 +115,6 @@ describe('41. dataTypeBlob', function() {
should.not.exist(err, "inStream.on 'end' event");
});
inStream.on('end', function() {
streamEndEventFired = true;
// now commit updates
connection.commit( function(err) {
should.not.exist(err);
});
});
var lob = result.outBinds.lobbv[0];
lob.on('error', function(err) {
@ -129,6 +122,15 @@ describe('41. dataTypeBlob', function() {
});
inStream.pipe(lob); // pipes the data to the BLOB
lob.on('finish', function() {
lobFinishEventFired = true;
// now commit updates
connection.commit(function(err) {
should.not.exist(err);
});
});
}
);
},

View File

@ -36,7 +36,7 @@
var oracledb = require('oracledb');
var should = require('should');
var assist = require('./dataTypeAssist.js');
var dbConfig = require('./dbConfig.js');
var dbConfig = require('./dbconfig.js');
var async = require('async');
describe('22. dataTypeChar.js', function(){

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
/* Copyright (c) 2015, 2016 Oracle and/or its affiliates. All rights reserved. */
/******************************************************************************
*
@ -43,7 +43,7 @@ var oracledb = require('oracledb');
var fs = require('fs');
var async = require('async');
var should = require('should');
var dbConfig = require('./dbConfig.js');
var dbConfig = require('./dbconfig.js');
var assist = require('./dataTypeAssist.js');
var inFileName = './test/clobexample.txt'; // the file with text to be inserted into the database
@ -95,9 +95,10 @@ describe('40. dataTypeClob.js', function() {
connection.should.be.ok;
async.series([
function clobinsert1(callback) {
var streamEndEventFired = false;
var lobFinishEventFired = false;
setTimeout( function() {
streamEndEventFired.should.equal(true, "inStream does not call 'end' event!")
lobFinishEventFired.should.equal(true, "lob does not fire 'finish' event!");
callback();
}, 2000);
@ -121,13 +122,14 @@ describe('40. dataTypeClob.js', function() {
should.not.exist(err, "inStream.on 'error' event");
});
inStream.on('end', function() {
streamEndEventFired = true;
lob.on('finish', function() {
lobFinishEventFired = true;
// now commit updates
connection.commit( function(err) {
should.not.exist(err);
});
});
inStream.pipe(lob); // copies the text to the CLOB
}
);
@ -172,7 +174,7 @@ describe('40. dataTypeClob.js', function() {
streamFinishEventFired = true;
});
});
})
});
}
);
},

View File

@ -37,7 +37,7 @@ var oracledb = require('oracledb');
var should = require('should');
var async = require('async');
var assist = require('./dataTypeAssist.js');
var dbConfig = require('./dbConfig.js');
var dbConfig = require('./dbconfig.js');
describe('32. dataTypeDate.js', function() {

View File

@ -36,7 +36,7 @@
var oracledb = require('oracledb');
var should = require('should');
var assist = require('./dataTypeAssist.js');
var dbConfig = require('./dbConfig.js');
var dbConfig = require('./dbconfig.js');
describe('28. dataTypeFloat.js', function() {

View File

@ -36,7 +36,7 @@
var oracledb = require('oracledb');
var should = require('should');
var assist = require('./dataTypeAssist.js');
var dbConfig = require('./dbConfig.js');
var dbConfig = require('./dbconfig.js');
describe('29. dataTypeFloat2.js', function() {

View File

@ -36,7 +36,7 @@
var oracledb = require('oracledb');
var should = require('should');
var assist = require('./dataTypeAssist.js');
var dbConfig = require('./dbConfig.js');
var dbConfig = require('./dbconfig.js');
describe('23. dataTypeNchar.js', function(){

View File

@ -36,7 +36,7 @@
var oracledb = require('oracledb');
var should = require('should');
var assist = require('./dataTypeAssist.js');
var dbConfig = require('./dbConfig.js');
var dbConfig = require('./dbconfig.js');
describe('26. dataTypeNumber.js', function() {

View File

@ -37,7 +37,7 @@ var oracledb = require('oracledb');
var should = require('should');
var async = require('async');
var assist = require('./dataTypeAssist.js');
var dbConfig = require('./dbConfig.js');
var dbConfig = require('./dbconfig.js');
describe('27. dataTypeNumber2.js', function() {

View File

@ -36,7 +36,7 @@
var oracledb = require('oracledb');
var should = require('should');
var assist = require('./dataTypeAssist.js');
var dbConfig = require('./dbConfig.js');
var dbConfig = require('./dbconfig.js');
describe('25. dataTypeNvarchar2.js', function() {

View File

@ -37,7 +37,7 @@ var oracledb = require('oracledb');
var should = require('should');
var async = require('async');
var assist = require('./dataTypeAssist.js');
var dbConfig = require('./dbConfig.js');
var dbConfig = require('./dbconfig.js');
describe('42. dataTypeRaw.js', function() {

View File

@ -40,7 +40,7 @@ var oracledb = require('oracledb');
var should = require('should');
var async = require('async');
var assist = require('./dataTypeAssist.js');
var dbConfig = require('./dbConfig.js');
var dbConfig = require('./dbconfig.js');
describe('39. dataTypeRowid.js', function() {

View File

@ -37,7 +37,7 @@ var oracledb = require('oracledb');
var should = require('should');
var async = require('async');
var assist = require('./dataTypeAssist.js');
var dbConfig = require('./dbConfig.js');
var dbConfig = require('./dbconfig.js');
describe('33. dataTypeTimestamp1.js', function() {

View File

@ -37,7 +37,7 @@ var oracledb = require('oracledb');
var should = require('should');
var async = require('async');
var assist = require('./dataTypeAssist.js');
var dbConfig = require('./dbConfig.js');
var dbConfig = require('./dbconfig.js');
describe('34. dataTypeTimestamp2.js', function() {

View File

@ -40,7 +40,7 @@ var oracledb = require('oracledb');
var should = require('should');
var async = require('async');
var assist = require('./dataTypeAssist.js');
var dbConfig = require('./dbConfig.js');
var dbConfig = require('./dbconfig.js');
describe('35. dataTypeTimestamp3.js', function() {

View File

@ -40,7 +40,7 @@ var oracledb = require('oracledb');
var should = require('should');
var async = require('async');
var assist = require('./dataTypeAssist.js');
var dbConfig = require('./dbConfig.js');
var dbConfig = require('./dbconfig.js');
describe('36. dataTypeTimestamp4.js', function() {

View File

@ -37,7 +37,7 @@ var oracledb = require('oracledb');
var should = require('should');
var async = require('async');
var assist = require('./dataTypeAssist.js');
var dbConfig = require('./dbConfig.js');
var dbConfig = require('./dbconfig.js');
describe('37. dataTypeTimestamp5.js', function() {

View File

@ -40,7 +40,7 @@ var oracledb = require('oracledb');
var should = require('should');
var async = require('async');
var assist = require('./dataTypeAssist.js');
var dbConfig = require('./dbConfig.js');
var dbConfig = require('./dbconfig.js');
describe('38. dataTypeTimestamp6.js', function() {

View File

@ -36,7 +36,7 @@
var oracledb = require('oracledb');
var should = require('should');
var assist = require('./dataTypeAssist.js');
var dbConfig = require('./dbConfig.js');
var dbConfig = require('./dbconfig.js');
describe('24. dataTypeVarchar2.js', function() {

View File

@ -40,7 +40,7 @@
var oracledb = require('oracledb');
var should = require('should');
var async = require('async');
var dbConfig = require('./dbConfig.js');
var dbConfig = require('./dbconfig.js');
var assist = require('./dataTypeAssist.js');
describe('6. dmlReturning.js', function(){

View File

@ -35,7 +35,7 @@
var oracledb = require('oracledb');
var should = require('should');
var async = require('async');
var dbConfig = require('./dbConfig.js');
var dbConfig = require('./dbconfig.js');
describe('3. examples.js', function(){

View File

@ -40,7 +40,7 @@
var oracledb = require('oracledb');
var should = require('should');
var dbConfig = require('./dbConfig.js');
var dbConfig = require('./dbconfig.js');
describe('5. externalAuthentication.js', function(){

View File

@ -35,7 +35,7 @@
var oracledb = require ( 'oracledb' );
var should = require ( 'should' );
var async = require('async');
var dbConfig = require ( './dbConfig.js' );
var dbConfig = require ( './dbconfig.js' );
describe('56. fetchAs.js', function() {

View File

@ -34,7 +34,7 @@
var oracledb = require('oracledb');
var should = require('should');
var dbConfig = require('./dbConfig.js');
var dbConfig = require('./dbconfig.js');
describe('52. getConnAfterPoolTerminate.js', function(){

View File

@ -408,11 +408,11 @@
42.4 in PL/SQL, the maximum size is 32767
- 42.4.1 when data length is 200
43. plsqlBinding.js
43. plsqlBinding1.js
43.1 binding PL/SQL indexed table
43.1.1 binding PL/SQL indexed table IN
43.1.2 binding PL/SQL indexed table IN OUT
43.1.3 binding PL/SQL indexed table OUT
43.1.2 binding PL/SQL indexed table IN OUT
43.1.3 binding PL/SQL indexed table OUT
43.2 test exceptions when using PL/SQL indexed table bindings
43.2.1 maxArraySize is ignored when specifying BIND_IN
43.2.2 maxArraySize is mandatory for BIND_INOUT
@ -420,8 +420,7 @@
42.2.4 DATE type has not been supported yet
42.2.5 the type of the array element should be compatible with binding type declaration
42.2.6 type compatibility
- 42.2.7 maxSize restriction
42.2.8 dose not allow array syntax of bindings
42.2.7 dose not allow array syntax of bindings
43.3 binding PL/SQL scalar
43.3.1 binding PL/SQL scalar IN
- 43.3.2 binding PL/SQL scalar IN/OUT
@ -436,8 +435,12 @@
43.4.7 negative case: = 0
43.4.8 negative case: assigning it to be a string
43.4.9 negative case: NaN
43.5 Indexed Table Null Elements
- 43.5.1 null elements work well
44. plsqlBinding2.js
44.1 example case
44.2 null elements in String and Number arrays
44.3 NJS-039: empty array is not allowed for IN bind
- 44.4 maxSize option applies to each elements of an array
51. accessTerminatedPoolAttributes.js
can not access attributes of terminated pool

View File

@ -38,7 +38,7 @@ var oracledb = require('oracledb');
var fs = require('fs');
var should = require('should');
var async = require('async');
var dbConfig = require('./dbConfig.js');
var dbConfig = require('./dbconfig.js');
describe('62. lobProperties.js', function() {

View File

@ -42,7 +42,7 @@ var fs = require('fs');
var async = require('async');
var should = require('should');
var stream = require('stream');
var dbConfig = require('./dbConfig.js');
var dbConfig = require('./dbconfig.js');
var assist = require('./dataTypeAssist.js');
var inFileName = './test/clobexample.txt';

View File

@ -36,7 +36,7 @@
var oracledb = require('oracledb');
var should = require('should');
var async = require('async');
var dbConfig = require('./dbConfig.js');
var dbConfig = require('./dbconfig.js');
describe('57. nestedCursor.js', function() {

View File

@ -35,7 +35,7 @@
var oracledb = require('oracledb');
var should = require('should');
var async = require('async');
var dbConfig = require('./dbConfig.js');
var dbConfig = require('./dbconfig.js');
describe('10. nullColumnValues.js', function() {

View File

@ -19,10 +19,10 @@
* See LICENSE.md for relevant licenses.
*
* NAME
* 43. plsqlBinding.js
* 43. plsqlBinding1.js
*
* DESCRIPTION
* Allow binding of PL/SQL indexed tables (associative arrays).
* Testing PL/SQL indexed tables (associative arrays).
*
* NUMBERING RULE
* Test numbers follow this numbering rule:
@ -34,12 +34,11 @@
'use strict';
var oracledb = require('oracledb');
var should = require('should');
var async = require('async');
var should = require('should');
var async = require('async');
var dbConfig = require('./dbconfig.js');
var dbConfig = require('./dbConfig.js');
describe('43. plsqlBinding.js', function() {
describe('43. plsqlBinding1.js', function() {
if(dbConfig.externalAuth){
var credential = { externalAuth: true, connectString: dbConfig.connectString };
@ -65,7 +64,7 @@ describe('43. plsqlBinding.js', function() {
});
})
it('43.1.1 binding PL/SQL indexed table IN by name', function(done) {
it('43.1.1 binding PL/SQL indexed table IN', function(done) {
async.series([
function(callback) {
var proc = "CREATE OR REPLACE PACKAGE\n" +
@ -139,77 +138,7 @@ describe('43. plsqlBinding.js', function() {
], done);
});
it('43.1.2 binding PL/SQL indexed table IN by position', function(done) {
async.series([
function(callback) {
var proc = "CREATE OR REPLACE PACKAGE\n" +
"oracledb_testpack\n" +
"IS\n" +
" TYPE stringsType IS TABLE OF VARCHAR2(30) INDEX BY BINARY_INTEGER;\n" +
" TYPE numbersType IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;\n" +
" PROCEDURE test(s IN stringsType, n IN numbersType);\n" +
"END;";
connection.should.be.ok;
connection.execute(
proc,
function(err) {
should.not.exist(err);
callback();
}
);
},
function(callback) {
var proc = "CREATE OR REPLACE PACKAGE BODY\n" +
"oracledb_testpack\n" +
"IS\n" +
" PROCEDURE test(s IN stringsType, n IN numbersType)\n" +
" IS\n" +
" BEGIN\n" +
" IF (s(1) IS NULL OR s(1) <> 'John') THEN\n" +
" raise_application_error(-20000, 'Invalid s(1): \"' || s(1) || '\"');\n" +
" END IF;\n" +
" IF (s(2) IS NULL OR s(2) <> 'Doe') THEN\n" +
" raise_application_error(-20000, 'Invalid s(2): \"' || s(2) || '\"');\n" +
" END IF;\n" +
" END;\n" +
"END;";
connection.should.be.ok;
connection.execute(
proc,
function(err) {
should.not.exist(err);
callback();
}
);
},
function(callback) {
var bindvars = [
{type: oracledb.STRING, dir: oracledb.BIND_IN, val: ['John', 'Doe']},
{type: oracledb.NUMBER, dir: oracledb.BIND_IN, val: [8, 11]}
];
connection.execute(
"BEGIN oracledb_testpack.test(:1, :2); END;",
bindvars,
function(err, result) {
should.not.exist(err);
// console.log(result);
callback();
}
);
},
function(callback) {
connection.execute(
"DROP PACKAGE oracledb_testpack",
function(err) {
should.not.exist(err);
callback();
}
);
}
], done);
});
it('43.1.3 binding PL/SQL indexed table IN OUT', function(done) {
it('43.1.2 binding PL/SQL indexed table IN OUT', function(done) {
async.series([
function(callback) {
var proc = "CREATE OR REPLACE PACKAGE\n" +
@ -282,7 +211,7 @@ describe('43. plsqlBinding.js', function() {
], done);
});
it('43.1.4 binding PL/SQL indexed table OUT', function(done) {
it('43.1.3 binding PL/SQL indexed table OUT', function(done) {
async.series([
function(callback) {
var proc = "CREATE OR REPLACE PACKAGE\n" +
@ -532,24 +461,7 @@ describe('43. plsqlBinding.js', function() {
);
})
it.skip('42.2.7 maxSize restriction', function(done) {
var bindvars = {
p: {type: oracledb.STRING, dir: oracledb.BIND_IN, val: ['this is a quite longs string'], maxSize: 10}
};
connection.execute(
"BEGIN oracledb_testpack.test4(:p); END;",
bindvars,
function(err, result) {
should.exist(err);
(err.message).should.startWith('NJS-039');
// NJS-039: Invalid value or size provided in Array binds.
should.not.exist(result);
done();
}
);
})
it('42.2.8 dose not allow array syntax of bindings', function(done) {
it('42.2.7 dose not allow array syntax of bindings', function(done) {
var bindvars = [
{type: oracledb.STRING, dir: oracledb.BIND_IN, val: ['hello', 'node.js']}
];
@ -557,8 +469,9 @@ describe('43. plsqlBinding.js', function() {
"BEGIN oracledb_testpack.test4(:1); END;",
bindvars,
function(err, result) {
should.not.exist(err);
should.exist(result);
should.exist(err);
(err.message).should.startWith('ORA-06550'); // this causes a PL/SQL syntax error
should.not.exist(result);
done();
}
);
@ -631,7 +544,8 @@ describe('43. plsqlBinding.js', function() {
}
], done);
});
// Date data type not support yet
it.skip('43.3.2 binding PL/SQL scalar IN/OUT', function(done) {
async.series([
function(callback) {
@ -837,7 +751,7 @@ describe('43. plsqlBinding.js', function() {
function(err, result) {
should.exist(err);
(err.message).should.startWith('NJS-036');
// NJS-036: Property maxArraySize is required for INOUT Array binds.
// NJS-036: given array is of size greater than maxArraySize
should.not.exist(result);
done();
}
@ -875,6 +789,7 @@ describe('43. plsqlBinding.js', function() {
);
})
// known bug
// The maximum safe integer in JavaScript is (2^53 - 1).
it.skip('43.4.5 negative case: large value', function(done) {
var bindvars = {
@ -955,102 +870,4 @@ describe('43. plsqlBinding.js', function() {
})
}) // 43.4
describe('43.5 Indexed Table Null Elements', function() {
var connection = null;
before(function(done) {
async.series([
function(cb) {
oracledb.getConnection(credential, function(err, conn) {
should.not.exist(err);
connection = conn;
cb();
});
},
function(cb) {
var proc = "CREATE OR REPLACE PACKAGE\n" +
"oracledb_testpack\n" +
"IS\n" +
" TYPE stringsType IS TABLE OF VARCHAR2(30) INDEX BY BINARY_INTEGER;\n" +
" TYPE numbersType IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;\n" +
" FUNCTION test(strings IN stringsType, numbers IN numbersType) RETURN VARCHAR2;\n" +
"END;";
connection.should.be.ok;
connection.execute(
proc,
function(err) {
should.not.exist(err);
cb();
}
);
},
function(cb) {
var proc = "CREATE OR REPLACE PACKAGE BODY\n" +
"oracledb_testpack\n" +
"IS\n" +
" FUNCTION test(strings IN stringsType, numbers IN numbersType) RETURN VARCHAR2\n" +
" IS\n" +
" s VARCHAR2(2000) := '';\n" +
" BEGIN\n" +
" FOR i IN 1 .. strings.COUNT LOOP\n" +
" s := s || strings(i);\n" +
" END LOOP;\n" +
" FOR i IN 1 .. numbers.COUNT LOOP\n" +
" s := s || numbers(i);\n" +
" END LOOP;\n" +
" RETURN s;\n" +
" END;\n" +
"END;";
connection.execute(
proc,
function(err) {
should.not.exist(err);
cb();
}
);
}
], done);
}) // before
after(function(done) {
async.series([
function(callback) {
connection.execute(
"DROP PACKAGE oracledb_testpack",
function(err) {
should.not.exist(err);
callback();
}
);
},
function(callback) {
connection.release(function(err) {
should.not.exist(err);
callback();
});
}
], done);
}) // after
it.skip('43.5.1 null elements work well', function(done) {
var bindvars = {
result: {type: oracledb.STRING, dir: oracledb.BIND_OUT, maxSize: 2000},
strings: {type: oracledb.STRING, dir: oracledb.BIND_IN, val: ['One', 'Two', 'Three', null, '']},
numbers: {type: oracledb.NUMBER, dir: oracledb.BIND_IN, val: [1, 2, 3, null, '']}
};
connection.execute(
"BEGIN :result := oracledb_testpack.test(:strings, :numbers); END;",
bindvars,
function(err, result) {
should.not.exist(err);
// Error: NJS-037: incompatible type of value provided
console.log(result);
result.outBinds.result.should.be.exactly('OneTwoThree123');
done();
}
);
})
}) // 43.5
})

440
test/plsqlBinding2.js Normal file
View File

@ -0,0 +1,440 @@
/* Copyright (c) 2016, 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
* 44. plsqlBinding2.js
*
* DESCRIPTION
* Testing PL/SQL indexed tables (associative arrays).
*
* 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 onwards are for other tests
*
*****************************************************************************/
'use strict';
var oracledb = require('oracledb');
var should = require('should');
var async = require('async');
var dbConfig = require('./dbconfig.js');
describe('44. plsqlBinding2.js', function() {
if(dbConfig.externalAuth){
var credential = { externalAuth: true, connectString: dbConfig.connectString };
} else {
var credential = dbConfig;
}
var connection = null;
beforeEach(function(done) {
async.series([
function(callback) {
oracledb.getConnection(credential, function(err, conn) {
should.not.exist(err);
connection = conn;
callback();
});
},
function createTab(callback) {
var proc = "BEGIN \n" +
" DECLARE \n" +
" e_table_exists EXCEPTION; \n" +
" PRAGMA EXCEPTION_INIT(e_table_exists, -00942);\n " +
" BEGIN \n" +
" EXECUTE IMMEDIATE ('DROP TABLE waveheight'); \n" +
" EXCEPTION \n" +
" WHEN e_table_exists \n" +
" THEN NULL; \n" +
" END; \n" +
" EXECUTE IMMEDIATE (' \n" +
" CREATE TABLE waveheight (beach VARCHAR2(50), depth NUMBER) \n" +
" '); \n" +
"END; ";
connection.execute(
proc,
function(err) {
should.not.exist(err);
callback();
}
);
},
function createPkg(callback) {
var proc = "CREATE OR REPLACE PACKAGE beachpkg IS\n" +
" TYPE beachType IS TABLE OF VARCHAR2(30) INDEX BY BINARY_INTEGER;\n" +
" TYPE depthType IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;\n" +
" PROCEDURE array_in(beaches IN beachType, depths IN depthType);\n" +
" PROCEDURE array_out(beaches OUT beachType, depths OUT depthType); \n" +
" PROCEDURE array_inout(beaches IN OUT beachType, depths IN OUT depthType); \n" +
"END;";
connection.execute(
proc,
function(err) {
should.not.exist(err);
callback();
}
);
},
function(callback) {
var proc = "CREATE OR REPLACE PACKAGE BODY beachpkg IS \n" +
" PROCEDURE array_in(beaches IN beachType, depths IN depthType) IS \n" +
" BEGIN \n" +
" IF beaches.COUNT <> depths.COUNT THEN \n" +
" RAISE_APPLICATION_ERROR(-20000, 'Array lengths must match for this example.'); \n" +
" END IF; \n" +
" FORALL i IN INDICES OF beaches \n" +
" INSERT INTO waveheight (beach, depth) VALUES (beaches(i), depths(i)); \n" +
" END; \n" +
" PROCEDURE array_out(beaches OUT beachType, depths OUT depthType) IS \n" +
" BEGIN \n" +
" SELECT beach, depth BULK COLLECT INTO beaches, depths FROM waveheight; \n" +
" END; \n" +
" PROCEDURE array_inout(beaches IN OUT beachType, depths IN OUT depthType) IS \n" +
" BEGIN \n" +
" IF beaches.COUNT <> depths.COUNT THEN \n" +
" RAISE_APPLICATION_ERROR(-20001, 'Array lenghts must match for this example.'); \n" +
" END IF; \n" +
" FORALL i IN INDICES OF beaches \n" +
" INSERT INTO waveheight (beach, depth) VALUES (beaches(i), depths(i)); \n" +
" SELECT beach, depth BULK COLLECT INTO beaches, depths FROM waveheight ORDER BY 1; \n" +
" END; \n " +
"END;";
connection.execute(
proc,
function(err) {
should.not.exist(err);
callback();
}
);
},
function(callback) {
connection.commit(function(err) {
should.not.exist(err);
callback();
});
}
], done);
}) // before
afterEach(function(done) {
async.series([
function(callback) {
connection.execute(
"DROP TABLE waveheight",
function(err) {
should.not.exist(err);
callback();
}
);
},
function(callback) {
connection.execute(
"DROP PACKAGE beachpkg",
function(err) {
should.not.exist(err);
callback();
}
);
},
function(callback) {
connection.release(function(err) {
should.not.exist(err);
callback();
});
},
], done);
}) // after
it('44.1 example case', function(done) {
async.series([
// Pass arrays of values to a PL/SQL procedure
function(callback) {
connection.execute(
"BEGIN beachpkg.array_in(:beach_in, :depth_in); END;",
{
beach_in: { type: oracledb.STRING,
dir: oracledb.BIND_IN,
val: ["Malibu Beach", "Bondi Beach", "Waikiki Beach"] },
depth_in: { type: oracledb.NUMBER,
dir: oracledb.BIND_IN,
val: [45, 30, 67]
}
},
function(err) {
should.not.exist(err);
callback();
}
);
},
// Fetch arrays of values from a PL/SQL procedure
function(callback) {
connection.execute(
"BEGIN beachpkg.array_out(:beach_out, :depth_out); END;",
{
beach_out: { type: oracledb.STRING,
dir: oracledb.BIND_OUT,
maxArraySize: 3 },
depth_out: { type: oracledb.NUMBER,
dir: oracledb.BIND_OUT,
maxArraySize: 3 }
},
function(err, result) {
should.not.exist(err);
// console.log(result.outBinds);
(result.outBinds.beach_out).should.eql([ 'Malibu Beach', 'Bondi Beach', 'Waikiki Beach' ]);
(result.outBinds.depth_out).should.eql([45, 30, 67]);
callback();
}
);
},
function(callback) {
connection.rollback(function(err) {
should.not.exist(err);
callback();
});
},
// Return input arrays sorted by beach name
function(callback) {
connection.execute(
"BEGIN beachpkg.array_inout(:beach_inout, :depth_inout); END;",
{
beach_inout: { type: oracledb.STRING,
dir: oracledb.BIND_INOUT,
val: ["Port Melbourne Beach", "Eighty Mile Beach", "Chesil Beach"],
maxArraySize: 3},
depth_inout: { type: oracledb.NUMBER,
dir: oracledb.BIND_INOUT,
val: [8, 3, 70],
maxArraySize: 3}
},
function(err, result) {
should.not.exist(err);
//console.log(result.outBinds);
(result.outBinds.beach_inout).should.eql([ 'Chesil Beach', 'Eighty Mile Beach', 'Port Melbourne Beach' ]);
(result.outBinds.depth_inout).should.eql([ 70, 3, 8 ]);
callback();
}
);
}
], done);
}) // 44.1
it('44.2 null elements in String and Number arrays', function(done) {
async.series([
// Pass arrays of values to a PL/SQL procedure
function(callback) {
connection.execute(
"BEGIN beachpkg.array_in(:beach_in, :depth_in); END;",
{
beach_in: { type: oracledb.STRING,
dir: oracledb.BIND_IN,
val: ["Malibu Beach", "Bondi Beach", null, "Waikiki Beach", '', null] },
depth_in: { type: oracledb.NUMBER,
dir: oracledb.BIND_IN,
val: [null, null, 45, 30, 67, null, ]
}
},
function(err) {
should.not.exist(err);
callback();
}
);
},
// Fetch arrays of values from a PL/SQL procedure
function(callback) {
connection.execute(
"BEGIN beachpkg.array_out(:beach_out, :depth_out); END;",
{
beach_out: { type: oracledb.STRING,
dir: oracledb.BIND_OUT,
maxArraySize: 10 },
depth_out: { type: oracledb.NUMBER,
dir: oracledb.BIND_OUT,
maxArraySize: 10 }
},
function(err, result) {
should.not.exist(err);
// console.log(result.outBinds);
(result.outBinds.beach_out).should.eql([ 'Malibu Beach', 'Bondi Beach', null, 'Waikiki Beach', null, null ]);
(result.outBinds.depth_out).should.eql([ null, null, 45, 30, 67, null ]);
callback();
}
);
},
function(callback) {
connection.rollback(function(err) {
should.not.exist(err);
callback();
});
},
// Return input arrays sorted by beach name
function(callback) {
connection.execute(
"BEGIN beachpkg.array_inout(:beach_inout, :depth_inout); END;",
{
beach_inout: { type: oracledb.STRING,
dir: oracledb.BIND_INOUT,
val: ["Port Melbourne Beach", "Eighty Mile Beach", '', "Chesil Beach", null, ''],
maxArraySize: 10},
depth_inout: { type: oracledb.NUMBER,
dir: oracledb.BIND_INOUT,
val: [null, 8, null, 3, null, 70],
maxArraySize: 10}
},
function(err, result) {
should.not.exist(err);
// console.log(result.outBinds);
(result.outBinds.beach_inout).should.eql([ 'Chesil Beach', 'Eighty Mile Beach', 'Port Melbourne Beach', null, null, null ]);
(result.outBinds.depth_inout).should.eql([ 3, 8, null, null, 70, null ]);
callback();
}
);
}
], done);
}) // 44.2
it('44.3 NJS-039: empty array is not allowed for IN bind', function(done) {
async.series([
// Pass arrays of values to a PL/SQL procedure
function(callback) {
connection.execute(
"BEGIN beachpkg.array_in(:beach_in, :depth_in); END;",
{
beach_in: { type: oracledb.STRING,
dir: oracledb.BIND_IN,
val: [] },
depth_in: { type: oracledb.NUMBER,
dir: oracledb.BIND_IN,
val: []
}
},
function(err) {
should.exist(err);
(err.message).should.startWith('NJS-039');
callback();
}
);
},
// Return input arrays sorted by beach name
function(callback) {
connection.execute(
"BEGIN beachpkg.array_inout(:beach_inout, :depth_inout); END;",
{
beach_inout: { type: oracledb.STRING,
dir: oracledb.BIND_INOUT,
val: [],
},
depth_inout: { type: oracledb.NUMBER,
dir: oracledb.BIND_INOUT,
val: [],
maxArraySize: 3}
},
function(err, result) {
should.exist(err);
(err.message).should.startWith('NJS-039');
callback();
}
);
}
], done);
}) // 44.3
it.skip('44.4 maxSize option applies to each elements of an array', function(done) {
async.series([
// Pass arrays of values to a PL/SQL procedure
function(callback) {
connection.execute(
"BEGIN beachpkg.array_in(:beach_in, :depth_in); END;",
{
beach_in: { type: oracledb.STRING,
dir: oracledb.BIND_IN,
val: ["Malibu", "Bondi", "Waikiki"] },
depth_in: { type: oracledb.NUMBER,
dir: oracledb.BIND_IN,
val: [45, 30, 67]
}
},
function(err) {
should.not.exist(err);
callback();
}
);
},
// Fetch arrays of values from a PL/SQL procedure
function(callback) {
connection.execute(
"BEGIN beachpkg.array_out(:beach_out, :depth_out); END;",
{
beach_out: { type: oracledb.STRING,
dir: oracledb.BIND_OUT,
maxArraySize: 3,
maxSize: 6 },
depth_out: { type: oracledb.NUMBER,
dir: oracledb.BIND_OUT,
maxArraySize: 3 }
},
function(err, result) {
should.exist(err);
(err.message).should.startWith('ORA-06502');
// ORA-06502: PL/SQL: numeric or value error: host bind array too small
callback();
}
);
},
function(callback) {
connection.rollback(function(err) {
should.not.exist(err);
callback();
});
},
// Return input arrays sorted by beach name
function(callback) {
connection.execute(
"BEGIN beachpkg.array_inout(:beach_inout, :depth_inout); END;",
{
beach_inout: { type: oracledb.STRING,
dir: oracledb.BIND_INOUT,
val: ["Port Melbourne Beach", "Eighty Mile Beach", "Chesil Beach"],
maxArraySize: 3,
maxSize : 5},
depth_inout: { type: oracledb.NUMBER,
dir: oracledb.BIND_INOUT,
val: [8, 3, 70],
maxArraySize: 3}
},
function(err, result) {
should.not.exist(err);
//console.log(result.outBinds);
(result.outBinds.beach_inout).should.eql([ 'Chesil Beach', 'Eighty Mile Beach', 'Port Melbourne Beach' ]);
(result.outBinds.depth_inout).should.eql([ 70, 3, 8 ]);
callback();
}
);
}
], done);
}) // 44.4
})

View File

@ -31,10 +31,11 @@
* 51 - are for other tests
*
*****************************************************************************/
'use strict';
var oracledb = require('oracledb');
var should = require('should');
var dbConfig = require('./dbConfig.js');
var should = require('should');
var dbConfig = require('./dbconfig.js');
describe('2. pool.js', function(){

View File

@ -33,9 +33,9 @@
*****************************************************************************/
var oracledb = require('oracledb');
var should = require('should');
var async = require('async');
var dbConfig = require('./dbConfig.js');
var should = require('should');
var async = require('async');
var dbConfig = require('./dbconfig.js');
describe('11. poolTimeout.js', function(){
this.timeout(0); // disable suite-level Time-out

View File

@ -34,7 +34,7 @@
var oracledb = require('oracledb');
var should = require('should');
var dbConfig = require('./dbConfig.js');
var dbConfig = require('./dbconfig.js');
describe('53. poolValidityAfterFailingTernimate.js', function(){

View File

@ -36,9 +36,9 @@
var oracledb = require('oracledb');
var fs = require('fs');
var should = require('should');
var async = require('async');
var dbConfig = require('./dbConfig.js');
var should = require('should');
var async = require('async');
var dbConfig = require('./dbconfig.js');
var assist = require('./dataTypeAssist.js');
describe('58. properties.js', function() {

View File

@ -34,7 +34,7 @@
var oracledb = require('oracledb');
var should = require('should');
var dbConfig = require('./dbConfig.js');
var dbConfig = require('./dbconfig.js');
describe('54. releaseAfterFailingTerminate.js', function(){

View File

@ -33,9 +33,9 @@
*****************************************************************************/
var oracledb = require('oracledb');
var should = require('should');
var async = require('async');
var dbConfig = require('./dbConfig.js');
var should = require('should');
var async = require('async');
var dbConfig = require('./dbconfig.js');
describe('12. resultSet1.js', function() {
var connection = false;

View File

@ -34,9 +34,9 @@
"use strict";
var oracledb = require('oracledb');
var should = require('should');
var async = require('async');
var dbConfig = require('./dbConfig.js');
var should = require('should');
var async = require('async');
var dbConfig = require('./dbconfig.js');
describe('55. resultSet2.js', function() {

View File

@ -37,9 +37,9 @@
var oracledb = require('oracledb');
var fs = require('fs');
var should = require('should');
var async = require('async');
var dbConfig = require('./dbConfig.js');
var should = require('should');
var async = require('async');
var dbConfig = require('./dbconfig.js');
describe('64. sqlWithWarnings.js', function() {