Update testsuite

This commit is contained in:
Christopher Jones 2017-07-08 12:43:45 +10:00
parent e3a6159f77
commit a1e0a67395
8 changed files with 452 additions and 13 deletions

View File

@ -48,7 +48,7 @@ describe('4. binding.js', function() {
var connection = null;
before(function(done) {
oracledb.getConnection(dbConfig, function(err, conn) {
if(err) { console.error(err.message); return; }
should.not.exist(err);
connection = conn;
done();
});
@ -56,7 +56,7 @@ describe('4. binding.js', function() {
after(function(done) {
connection.release( function(err) {
if(err) { console.error(err.message); return; }
should.not.exist(err);
done();
});
});
@ -587,7 +587,7 @@ describe('4. binding.js', function() {
before(function(done) {
oracledb.getConnection(dbConfig, function(err, conn) {
if(err) { console.error(err.message); return; }
should.not.exist(err);
connection = conn;
done();
});
@ -595,7 +595,7 @@ describe('4. binding.js', function() {
after(function(done) {
connection.release( function(err) {
if(err) { console.error(err.message); return; }
should.not.exist(err);
done();
});
});

187
test/blobDMLReturning.js Normal file
View File

@ -0,0 +1,187 @@
/* Copyright (c) 2017, 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
* 136. blobDMLReturning.js
*
* DESCRIPTION
* Testing BLOB dml returning multiple rows.
*
* 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');
var random = require('./random.js');
var sql = require('./sql.js');
var assist = require('./dataTypeAssist.js');
describe('136. blobDMLReturning.js', function() {
var connection = null;
var tableName = "nodb_dml_blob_136";
var node6plus = false; // assume node runtime version is lower than 6
var blob_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" +
" blob BLOB \n" +
" ) \n" +
" '); \n" +
"END; ";
var blob_table_drop = "DROP TABLE " + tableName + " PURGE";
before(function(done) {
oracledb.getConnection(dbConfig, function(err, conn) {
should.not.exist(err);
connection = conn;
if ( process.versions["node"].substring (0, 1) >= "6")
node6plus = true;
done();
});
});
after(function(done) {
connection.release(function(err) {
should.not.exist(err);
done();
});
});
describe('136.1 BLOB, UPDATE', function() {
before(function(done) {
async.series([
function(cb) {
sql.executeSql(connection, blob_table_create, {}, {}, cb);
},
function(cb) {
insertData();
cb();
}
], done);
});
after(function(done) {
sql.executeSql(connection, blob_table_drop, {}, {}, done);
});
it.skip('136.1.1 works with stream', function(done) {
updateReturning_stream(done);
}); // 136.1.1
it('136.1.2 fetch as string', function(done) {
updateReturning_buffer(done);
}); // 136.1.1
}); // 136.1
var insertData = function() {
for(var i=0; i<10; i++) {
var str = random.getRandomLengthString(i+10);
var blob = node6plus ? Buffer.from(str, "utf-8") : new Buffer(str, "utf-8");
connection.execute(
"insert into " + tableName + " values (:id, :b)",
{
id: {val: i, dir: oracledb.BIND_IN, type: oracledb.NUMBER},
b: {val: blob, dir: oracledb.BIND_IN, type: oracledb.BUFFER}
},
function(err, result) {
should.not.exist(err);
(result.rowsAffected).should.be.exactly(1);
}
);
}
};
var updateReturning_stream = function(callback) {
var sql_update = "UPDATE " + tableName + " set id = id+10 RETURNING id, blob into :num, :lobou";
connection.execute(
sql_update,
{
num: { type: oracledb.NUMBER, dir: oracledb.BIND_OUT },
lobou: { type: oracledb.BLOB, dir: oracledb.BIND_OUT }
},
function(err, result) {
console.log(sql_update);
should.not.exist(err);
var numLobs = result.outBinds.lobou.length;
should.strictEqual(numLobs, 10);
for (var index = 0; index < result.outBinds.lobou.length; index++) {
var lob = result.outBinds.lobou[index];
var id = result.outBinds.num[index];
should.exist(lob);
var blobData = 0;
var totalLength = 0;
blobData = node6plus ? Buffer.alloc(0) : new Buffer(0);
lob.on('data', function(chunk) {
totalLength = totalLength + chunk.length;
blobData = Buffer.concat([blobData, chunk], totalLength);
});
lob.on('error', function(err) {
should.not.exist(err, "lob.on 'error' event.");
});
lob.on('end', function(err) {
should.not.exist(err);
var expected = node6plus ? Buffer.from(String(id), "utf-8") : new Buffer(String(id-10), "utf-8");
should.strictEqual(assist.compare2Buffers(blobData, expected), true);
});
}
callback();
}
);
};
var updateReturning_buffer = function(callback) {
var sql_update = "UPDATE " + tableName + " set id = id+10 RETURNING id, blob into :num, :lobou";
connection.execute(
sql_update,
{
num: { type: oracledb.NUMBER, dir: oracledb.BIND_OUT },
lobou: { type: oracledb.BUFFER, dir: oracledb.BIND_OUT }
},
function(err) {
should.exist(err);
should.strictEqual((err.message), "NJS-028: raw database type is not supported with DML Returning statements");
callback();
}
);
};
});

View File

@ -19,7 +19,7 @@
* See LICENSE.md for relevant licenses.
*
* NAME
* 79. blobPlsqlBindAsBuffer_inout.js
* 79. blobPlsqlBindAsBuffer_bindinout.js
*
* DESCRIPTION
* Testing BLOB binding inout as Buffer.
@ -41,7 +41,7 @@ var dbConfig = require('./dbconfig.js');
var random = require('./random.js');
var assist = require('./dataTypeAssist.js');
describe('79. blobPlsqlBindAsBuffer_inout.js', function() {
describe('79. blobPlsqlBindAsBuffer_bindinout.js', function() {
this.timeout(100000);
var connection = null;
var node6plus = false; // assume node runtime version is lower than 6

168
test/clobDMLReturning.js Normal file
View File

@ -0,0 +1,168 @@
/* Copyright (c) 2017, 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
* 135. clobDMLReturning.js
*
* DESCRIPTION
* Testing CLOB dml returning multiple rows.
*
* 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 dbConfig = require('./dbconfig.js');
var sql = require('./sql.js');
describe('135. clobDMLReturning.js', function() {
var connection = null;
var tableName = "nodb_dml_clob_135";
var clob_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" +
" clob CLOB \n" +
" ) \n" +
" '); \n" +
" FOR i IN 1..10 LOOP \n" +
" EXECUTE IMMEDIATE ( \n" +
" 'insert into " + tableName + " values (' || \n" +
" to_char(i) || ', ' || to_char(i) || ')'); \n" +
" END LOOP; \n" +
" commit; \n" +
"END; ";
var clob_table_drop = "DROP TABLE " + tableName + " PURGE";
before(function(done) {
oracledb.getConnection(dbConfig, function(err, conn) {
should.not.exist(err);
connection = conn;
done();
});
});
after(function(done) {
connection.release(function(err) {
should.not.exist(err);
done();
});
});
describe('135.1 CLOB, UPDATE', function() {
before(function(done) {
sql.executeSql(connection, clob_table_create, {}, {}, done);
});
after(function(done) {
sql.executeSql(connection, clob_table_drop, {}, {}, done);
});
it.skip('135.1.1 works with stream', function(done) {
updateReturning_stream(done);
}); // 135.1.1
it('135.1.2 fetch as string', function(done) {
updateReturning_string(done);
}); // 135.1.1
}); // 135.1
var updateReturning_stream = function(callback) {
var sql_update = "UPDATE " + tableName + " set id = id+10 RETURNING id, clob into :num, :lobou";
connection.execute(
sql_update,
{
num: { type: oracledb.NUMBER, dir: oracledb.BIND_OUT },
lobou: { type: oracledb.CLOB, dir: oracledb.BIND_OUT }
},
function(err, result) {
should.not.exist(err);
var numLobs = result.outBinds.lobou.length;
should.strictEqual(numLobs, 10);
for (var index = 0; index < result.outBinds.lobou.length; index++) {
var lob = result.outBinds.lobou[index];
var id = result.outBinds.num[index];
should.exist(lob);
lob.setEncoding('utf8');
var clobData = '';
lob.on('data', function(chunk) {
clobData += chunk;
});
lob.on('error', function(err) {
should.not.exist(err);
});
lob.on('end', function(err) {
should.not.exist(err);
should.strictEqual(clobData, (id-10));
});
lob.on('close', function(err) {
should.not.exist(err);
});
}
callback();
}
);
};
var updateReturning_string = function(callback) {
var sql_update = "UPDATE " + tableName + " set id = id+10 RETURNING id, clob into :num, :lobou";
connection.execute(
sql_update,
{
num: { type: oracledb.NUMBER, dir: oracledb.BIND_OUT },
lobou: { type: oracledb.STRING, dir: oracledb.BIND_OUT }
},
function(err, result) {
should.not.exist(err);
var numLobs = result.outBinds.lobou.length;
should.strictEqual(numLobs, 10);
for (var index = 0; index < result.outBinds.lobou.length; index++) {
var lob = result.outBinds.lobou[index];
var id = result.outBinds.num[index];
should.strictEqual(lob, String(id-10));
if(id === 20) {
callback();
}
}
}
);
};
});

View File

@ -93,7 +93,7 @@ describe('86. fetchClobAsString3.js', function() {
);
};
describe('86.1 fetch multiple CLOBs', function() {
describe('86.1 fetch multiple CLOBs and result set', function() {
before('create Table and populate', function(done) {
connection.execute(
proc_create_table2,
@ -231,6 +231,75 @@ describe('86. fetchClobAsString3.js', function() {
}); // 86.1.2
it('86.1.3 works with Restult Set', function(done) {
var id = insertID++;
var specialStr_1 = '86.1.3';
var contentLength_1 = 387;
var content_1 = random.getRandomString(contentLength_1, specialStr_1);
async.series([
function(cb) {
var sql = "insert into nodb_clob2(id, c1) values (:i, :c)";
connection.execute(
sql,
{
i: id,
c: content_1
},
function(err) {
should.not.exist(err);
cb();
}
);
},
function(cb) {
connection.execute(
"select c1 from nodb_clob2 where id = :1",
[id],
{ resultSet: true },
function(err, result) {
should.not.exist(err);
fetchOneRowFromRS(result.resultSet, cb);
}
);
}
], done);
var fetchOneRowFromRS = function(rs, callback) {
rs.getRow(
function(err, row) {
if (err) {
should.not.exist(err);
doClose(rs, callback);
} else if (!row) {
doClose(rs, callback);
} else {
var specialStrLen_1 = specialStr_1.length;
var resultLen_1 = row[0].length;
should.equal(row[0].length, contentLength_1);
should.strictEqual(
row[0].substring(0, specialStrLen_1),
specialStr_1
);
should.strictEqual(
row[0].substring(resultLen_1 - specialStrLen_1, resultLen_1),
specialStr_1
);
fetchOneRowFromRS(rs, callback);
}
}
);
};
var doClose = function(rs, callback) {
rs.close(function(err) {
should.not.exist(err);
callback();
});
};
}); // 86.1.3
}); // 86.1
describe('86.2 types support for fetchAsString property', function() {

View File

@ -1514,7 +1514,7 @@ Overview of node-oracledb functional tests
78.3.2 PLSQL, BIND_OUT, bind a JPG file and a Buffer
78.3.3 bind two buffer, one > (64K - 1)
79. blobPlsqlBindAsBuffer_inout.js
79. blobPlsqlBindAsBuffer_bindinout.js
79.1 BLOB, PLSQL, BIND_INOUT
79.1.1 works with EMPTY_BLOB
79.1.2 works with EMPTY_BLOB and maxSize set to 1
@ -1831,6 +1831,7 @@ Overview of node-oracledb functional tests
86.1 fetch multiple CLOBs
86.1.1 fetch multiple CLOB columns as String
86.1.2 fetch two CLOB columns, one as string, another streamed
86.1.3 works with Restult Set
86.2 types support for fetchAsString property
86.2.1 String not supported in fetchAsString
86.2.2 BLOB not supported in fetchAsString
@ -3525,3 +3526,13 @@ Overview of node-oracledb functional tests
134.2.5 works with data size 32760
134.2.6 set maxSize to size (32K - 1)
134.2.7 set maxSize to size 1GB
135. clobDMLReturning.js
135.1 CLOB, UPDATE
- 135.1.1 works with stream
135.1.2 fetch as string
136. blobDMLReturning.js
136.1 BLOB, UPDATE
- 136.1.1 works with stream
136.1.2 fetch as string

View File

@ -142,3 +142,6 @@ test/longProcedureBind_in.js
test/longrawProcedureBind_in.js
test/longrawProcedureBind_inout.js
test/longrawProcedureBind_out.js
test/clobDMLReturning.js
test/blobDMLReturning.js

View File

@ -248,7 +248,7 @@ describe('115. urowidDMLBindAsString_indexed.js', function() {
});
describe.skip('115.7 queryStream() and oracledb.maxRows < actual rows', function() {
describe('115.7 queryStream() and oracledb.maxRows < actual rows', function() {
it('115.7.1 urowid length > 200', function(done) {
var strLength = 200;
@ -783,10 +783,10 @@ describe('115. urowidDMLBindAsString_indexed.js', function() {
},
function(cb) {
var counter = 0;
var sql_select = "select c1, c2, ROWID from " + tableName_indexed + " where ROWID = :c1 or ROWID = :c2 order by c1";
var sql_select = "select c1, c2, ROWID from " + tableName_indexed + " where ROWID = :i1 or ROWID = :i2 order by c1";
var bindVar = {
c1: { val : urowid_1, dir : oracledb.BIND_IN, type : oracledb.STRING },
c2: { val : urowid_2, dir : oracledb.BIND_IN, type : oracledb.STRING }
i1: { val : urowid_1, dir : oracledb.BIND_IN, type : oracledb.STRING },
i2: { val : urowid_2, dir : oracledb.BIND_IN, type : oracledb.STRING }
};
var stream = connection.queryStream(sql_select, bindVar);
stream.on('error', function (error) {
@ -796,7 +796,8 @@ describe('115. urowidDMLBindAsString_indexed.js', function() {
stream.on('data', function(data) {
should.exist(data);
counter++;
if(counter == 1) {
var result_id = data[0];
if(result_id === id_1) {
(data).should.deepEqual([ id_1, str, urowid_1 ]);
} else {
(data).should.deepEqual([ id_2, str, urowid_2 ]);