Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

oracledb

Package Overview
Dependencies
Maintainers
2
Versions
59
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

oracledb - npm Package Compare versions

Comparing version 0.7.0 to 1.0.0

src/dpi/include/dpiCommon.h

34

CHANGELOG.md
# Change Log
## node-oracledb v1.0.0 (17 Aug 2015)
- Implemented the Stream interface for CLOB and BLOB types, adding support for LOB queries, inserts, and PL/SQL LOB bind variables.
- Added `fetchAsString` and `execute()` option `fetchInfo` properties to allow numbers, dates and ROWIDs to be fetched as strings.
- Added support for binding DATE, TIMESTAMP and TIMESTAMP WITH LOCAL TIME ZONE as `DATE` to DML RETURNING (aka RETURNING INTO) `type`.
- The internal Oracle client character set is now always set to AL32UTF8.
- The test suite and example scripts database credentials can now be set via environment variables.
- Fixed issues with database-to-client character set conversion by allocating extra memory to allow for character expansion.
- Fixed a crash with `ResultSet` and unsupported column data types.
- Fixed a crash allocating memory for large `maxRows` values.
- Fixed a bug preventing closing of a `ResultSet` when `getRow()` or `getRows()` returned an error.
- Fixed date precision issues affecting insert and query.
- Fixed `BIND_OUT` bind `type` not defaulting to `STRING`.
- Fixed INSERT of a date when the SQL has a RETURNING INTO clause and the bind style is array format.
- Improved RETURNING INTO handling of unsupported types and sizes.
- Correctly throw an error when array and named bind syntaxes are mixed together.
## node-oracledb v0.7.0 (20 Jul 2015)

@@ -17,3 +47,3 @@

- Renumbered the values used by the Oracledb Constants
- Renumbered the values used by the Oracledb Constants.

@@ -32,3 +62,3 @@ ## node-oracledb v0.6.0 (26 May 2015)

- Fixed outBinds array counting to not give empty array entries for IN binds.
- Fixed `outBinds` array counting to not give empty array entries for IN binds.

@@ -35,0 +65,0 @@ - Added support for DML RETURNING bind variables.

@@ -30,18 +30,100 @@ /* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */

}
}
}
var Duplex = require('stream').Duplex;
var util = require('util');
util.inherits(Lob, Duplex);
function Lob(iLob, opt)
{
Duplex.call(this, opt);
this.iLob = iLob;
this.once('finish', this.close);
Object.defineProperties(
this,
{
"chunkSize": {value: iLob.chunkSize,
writable: false },
"length": {get: function() {return iLob.length}},
"pieceSize": {get: function() {return iLob.pieceSize;},
set: function(newPieceSize) {iLob.pieceSize = newPieceSize;}},
});
}
Lob.prototype._read = function()
{
var self = this;
self.iLob.read(
function(err, str)
{
if (err) {
self.close();
self.emit('error', err);
return;
}
if (!str) {
self.close();
}
self.push(str);
});
}
Lob.prototype._write = function(data, encoding, cb)
{
var self = this;
self.iLob.write(
data,
function(err)
{
if (err) {
self.close();
return cb(err);
}
cb();
});
}
Lob.prototype.close = function(cb)
{
var self = this;
if (cb) {
this.once('close', cb);
}
if (self.iLob != null) {
self.iLob.release();
self.iLob = null;
}
self.emit('close');
}
oracledb.Oracledb.prototype.newLob = function(iLob)
{
return new Lob(iLob, null);
}
var oracledb_ins = new oracledb.Oracledb();
oracledb_ins.STRING = 2001;
oracledb_ins.NUMBER = 2002;
oracledb_ins.DATE = 2003;
oracledb_ins.CURSOR = 2004;
oracledb_ins.DEFAULT = 0;
oracledb_ins.STRING = 2001;
oracledb_ins.NUMBER = 2002;
oracledb_ins.DATE = 2003;
oracledb_ins.CURSOR = 2004;
oracledb_ins.BUFFER = 2005;
oracledb_ins.CLOB = 2006;
oracledb_ins.BLOB = 2007;
oracledb_ins.BIND_IN = 3001;
oracledb_ins.BIND_INOUT = 3002;
oracledb_ins.BIND_OUT = 3003;
oracledb_ins.BIND_IN = 3001;
oracledb_ins.BIND_INOUT = 3002;
oracledb_ins.BIND_OUT = 3003;
oracledb_ins.ARRAY = 4001;
oracledb_ins.OBJECT = 4002;
oracledb_ins.ARRAY = 4001;
oracledb_ins.OBJECT = 4002;
module.exports = oracledb_ins;

2

package.json
{
"name": "oracledb",
"version": "0.7.0",
"version": "1.0.0",
"description": "Oracle Database driver by Oracle Corp.",

@@ -5,0 +5,0 @@ "license": "Apache-2.0",

@@ -1,2 +0,2 @@

# node-oracledb version 0.7
# node-oracledb version 1.0

@@ -8,38 +8,38 @@ ## <a name="about"></a> 1. About node-oracledb

Node-oracledb 0.7 supports basic and advanced Oracle features, including:
Node-oracledb connects Node.js 0.10, Node.js 0.12, and io.js to
Oracle Database.
- SQL and PL/SQL Execution
- Fetching of large result sets
- REF CURSOR support
- Query results as JavaScript objects or array
- Binding using JavaScript objects or arrays
- Conversion between JavaScript and Oracle types
- Transaction Management
- Connection Pooling
- [Database Resident Connection Pooling](http://docs.oracle.com/database/121/ADFNS/adfns_perf_scale.htm#ADFNS228) (DRCP)
- [External Authentication](http://docs.oracle.com/database/121/DBSEG/authentication.htm#DBSEG99840)
- [Statement Caching](http://docs.oracle.com/database/121/LNOCI/oci09adv.htm#i471377)
This is an open source project maintained by Oracle Corp.
The node-oracledb home page is on the
[Oracle Technology Network](http://www.oracle.com/technetwork/database/database-technologies/node_js/index.html).
### Node-oracledb supports:
- [SQL and PL/SQL execution](https://github.com/oracle/node-oracledb/blob/master/doc/api.md#sqlexecution)
- [Fetching of large result sets](https://github.com/oracle/node-oracledb/blob/master/doc/api.md#resultsethandling)
- [REF CURSORs](https://github.com/oracle/node-oracledb/blob/master/doc/api.md#refcursors)
- [Large Objects: CLOBs and BLOBs](https://github.com/oracle/node-oracledb/blob/master/doc/api.md#lobhandling)
- [Query results as JavaScript objects or array ](https://github.com/oracle/node-oracledb/blob/master/doc/api.md#queryoutputformats)
- [Smart mapping between JavaScript and Oracle types with manual override available](https://github.com/oracle/node-oracledb/blob/master/doc/api.md#typemap)
- [Data binding using JavaScript objects or arrays](https://github.com/oracle/node-oracledb/blob/master/doc/api.md#bind)
- [Transaction Management](https://github.com/oracle/node-oracledb/blob/master/doc/api.md#transactionmgt)
- [Inbuilt Connection Pooling](https://github.com/oracle/node-oracledb/blob/master/doc/api.md#connpooling)
- [Database Resident Connection Pooling (DRCP)](https://github.com/oracle/node-oracledb/blob/master/doc/api.md#drcp)
- [External Authentication](https://github.com/oracle/node-oracledb/blob/master/doc/api.md#extauth)
- [Row Prefetching](https://github.com/oracle/node-oracledb/blob/master/doc/api.md#rowprefetching)
- [Statement Caching](https://github.com/oracle/node-oracledb/blob/master/doc/api.md#stmtcache)
- [Client Result Caching](http://docs.oracle.com/database/121/ADFNS/adfns_perf_scale.htm#ADFNS464)
- [End-to-end tracing](http://docs.oracle.com/database/121/TGSQL/tgsql_trace.htm#CHDBDGIJ)
- High Availability Features
- [Fast Application Notification](http://docs.oracle.com/database/121/ADFNS/adfns_avail.htm#ADFNS538) (FAN)
- [Runtime Load Balancing](http://docs.oracle.com/database/121/ADFNS/adfns_perf_scale.htm#ADFNS515) (RLB)
- [Transparent Application Failover](http://docs.oracle.com/database/121/ADFNS/adfns_avail.htm#ADFNS534) (TAF)
- [Fast Application Notification (FAN)](http://docs.oracle.com/database/121/ADFNS/adfns_avail.htm#ADFNS538)
- [Runtime Load Balancing (RLB)](http://docs.oracle.com/database/121/ADFNS/adfns_perf_scale.htm#ADFNS515)
- [Transparent Application Failover (TAF)](http://docs.oracle.com/database/121/ADFNS/adfns_avail.htm#ADFNS534)
Node-oracledb 0.7 is a preview release. We are actively working on
adding features such as LOB support.
We are actively working on supporting the best Oracle Database
features, and on functionality requests from
[users involved in the project](https://github.com/oracle/node-oracledb/issues).
Share your feedback at the Oracle Technology Network
[Node.js discussion forum](https://community.oracle.com/community/database/developer-tools/node_js/content)
so we can incorporate any fixes and "must-haves" into a 1.0 release
soon. Issues with node-oracledb can also be reported
[here](https://github.com/oracle/node-oracledb/issues).
### A simple query example:
The driver is maintained by Oracle Corp.
The node-oracledb home page is on the
[Oracle Technology Network](http://www.oracle.com/technetwork/database/database-technologies/node_js/index.html).
### Example: Simple SELECT statement implementation in node-oracledb
```javascript

@@ -56,17 +56,10 @@ var oracledb = require('oracledb');

{
if (err) {
console.error(err.message);
return;
}
if (err) { console.error(err.message); return; }
connection.execute(
"SELECT department_id, department_name "
+ "FROM departments "
+ "WHERE department_id = :did",
[180],
"SELECT department_id, department_name FROM departments WHERE department_id = :did",
[180], // bind value for :did
function(err, result)
{
if (err) {
console.error(err.message);
return;
}
if (err) { console.error(err.message); return; }
console.log(result.rows);

@@ -83,30 +76,36 @@ });

There are more examples in the [examples](examples) directory.
## <a name="examples"></a> 2. Examples
## <a name="installation"></a> 2. Installation
There are examples in the [examples](https://github.com/oracle/node-oracledb/tree/master/examples) directory.
## <a name="installation"></a> 3. Installation
The basic install steps are:
- Install the small, free [Oracle Instant Client](http://www.oracle.com/technetwork/database/features/instant-client/index-100365.html) libraries if your database is remote, or have a local database such as the free [Oracle XE](http://www.oracle.com/technetwork/database/database-technologies/express-edition/overview/index.html) release.
- Install the small, free [Oracle Instant Client](http://www.oracle.com/technetwork/database/features/instant-client/index-100365.html) libraries if your database is remote. Or use a locally installed database such as the free [Oracle XE](http://www.oracle.com/technetwork/database/database-technologies/express-edition/overview/index.html) release.
- Run `npm install oracledb` to install from the NPM registry.
See [INSTALL](INSTALL.md) for details.
See [INSTALL](https://github.com/oracle/node-oracledb/tree/master/INSTALL.md) for details.
## <a name="doc"></a> 3. Documentation
## <a name="doc"></a> 4. Documentation
See [Documentation for the Oracle Database Node.js Driver](doc/api.md)
See [Documentation for the Oracle Database Node.js Driver](https://github.com/oracle/node-oracledb/tree/master/doc/api.md).
## <a name="changes"></a> 4. Changes
## <a name="changes"></a> 5. Changes
See [CHANGELOG](CHANGELOG.md)
See [CHANGELOG](https://github.com/oracle/node-oracledb/tree/master/CHANGELOG.md)
*Note* there were two small, backward-compatibility breaking attribute name changes in node-oracledb 0.5.
## <a name="contrib"></a> 5. Contributing
## <a name="testing"></a> 6. Testsuite
To run the included testsuite see [test/README](https://github.com/oracle/node-oracledb/tree/master/test/README.md).
## <a name="contrib"></a> 7. Contributing
Node-oracledb is an open source project. See
[CONTRIBUTING](CONTRIBUTING.md)
[CONTRIBUTING](https://github.com/oracle/node-oracledb/tree/master/CONTRIBUTING.md)
for details.
## <a name="license"></a> 6. Licence
## <a name="license"></a> 8. License

@@ -127,13 +126,1 @@ Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.

limitations under the License.
## <a name="testing"></a> 7. Running tests
The basic steps for running tests are:
- Install the driver `npm install oracledb`
- Change directory `cd node_modules/oracledb`
- Run `npm install mocha should async` to install dependent Node.js modules required for testing.
- Set the correct credential information in `test/dbConfig.js`
- Run `npm test` to start the test suite.
See [test/README](test/README.md) for details.

@@ -34,2 +34,3 @@ /* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */

*****************************************************************************/
"use strict";

@@ -41,4 +42,4 @@ var oracledb = require('oracledb');

describe('7. autoCommit.js', function(){
describe('7. autoCommit.js', function() {
if(dbConfig.externalAuth){

@@ -48,68 +49,72 @@ var credential = { externalAuth: true, connectString: dbConfig.connectString };

var credential = dbConfig;
}
}
var connection = false;
var anotherConnection = false;
var script =
"BEGIN \
DECLARE \
e_table_exists EXCEPTION; \
PRAGMA EXCEPTION_INIT(e_table_exists, -00942); \
BEGIN \
EXECUTE IMMEDIATE ('DROP TABLE oracledb_departments'); \
EXCEPTION \
WHEN e_table_exists \
THEN NULL; \
END; \
EXECUTE IMMEDIATE (' \
CREATE TABLE oracledb_departments ( \
department_id NUMBER, \
department_name VARCHAR2(20) \
) \
'); \
END; ";
beforeEach(function(done){
oracledb.outFormat = oracledb.OBJECT;
oracledb.autoCommit = true;
var pool = null;
var connection = null;
before('create pool, get one connection, create table', function(done) {
var script =
"BEGIN \
DECLARE \
e_table_exists EXCEPTION; \
PRAGMA EXCEPTION_INIT(e_table_exists, -00942); \
BEGIN \
EXECUTE IMMEDIATE ('DROP TABLE oracledb_departments'); \
EXCEPTION \
WHEN e_table_exists \
THEN NULL; \
END; \
EXECUTE IMMEDIATE (' \
CREATE TABLE oracledb_departments ( \
department_id NUMBER, \
department_name VARCHAR2(20) \
) \
'); \
END; ";
async.series([
function(callback){
oracledb.getConnection(credential, function(err, conn){
if(err) { console.error(err.message); return; }
function(callback) {
oracledb.createPool(
{
externalAuth : credential.externalAuth,
user : credential.user,
password : credential.password,
connectString : credential.connectString,
poolMin : 3,
poolMax : 7,
poolIncrement : 1
},
function(err, connectionPool) {
should.not.exist(err);
pool = connectionPool;
callback();
}
);
},
function(callback) {
pool.getConnection( function(err, conn) {
should.not.exist(err);
connection = conn;
callback();
});
});
},
function(callback){
oracledb.getConnection(credential, function(err, conn){
if(err) { console.error(err.message); return; }
anotherConnection = conn;
callback();
});
},
function(callback){
connection.execute(script, function(err){
if(err) { console.error(err.message); return; }
connection.commit( function(err){
if(err) { console.error(err.message); return; }
function(callback) {
connection.execute(
script,
function(err) {
should.not.exist(err);
callback();
});
});
}
);
}
], done);
], done);
})
afterEach(function(done){
oracledb.outFormat = oracledb.ARRAY;
oracledb.autoCommit = false;
after('drop table, release connection, terminate pool', function(done) {
async.series([
function(callback){
function(callback) {
connection.execute(
'DROP TABLE oracledb_departments',
function(err){
if(err) { console.error(err.message); return; }
"DROP TABLE oracledb_departments",
function(err) {
should.not.exist(err);
callback();

@@ -119,11 +124,11 @@ }

},
function(callback){
connection.release( function(err){
if(err) { console.error(err.message); return; }
function(callback) {
connection.release( function(err) {
should.not.exist(err);
callback();
});
},
function(callback){
anotherConnection.release( function(err){
if(err) { console.error(err.message); return; }
function(callback) {
pool.terminate(function(err) {
should.not.exist(err);
callback();

@@ -134,9 +139,35 @@ });

})
afterEach('truncate table, reset the oracledb properties', function(done) {
oracledb.autoCommit = false; /* Restore to default value */
connection.execute(
"TRUNCATE TABLE oracledb_departments",
function(err) {
should.not.exist(err);
done();
}
);
})
it('7.1 auto commit takes effect for DML - insert', function(done){
it('7.1 autoCommit takes effect when setting oracledb.autoCommit before connecting', function(done) {
var conn1 = null;
var conn2 = null;
oracledb.autoCommit = true;
async.series([
function(callback){
connection.execute(
function(callback) {
pool.getConnection(
function(err, conn) {
should.not.exist(err);
conn1 = conn;
callback();
}
);
},
function(callback) {
conn1.execute(
"INSERT INTO oracledb_departments VALUES (82, 'Security')",
function(err){
function(err) {
should.not.exist(err);

@@ -147,9 +178,18 @@ callback();

},
function(callback){
anotherConnection.execute(
function(callback) { // get another connection
pool.getConnection(
function(err, conn) {
should.not.exist(err);
conn2 = conn;
callback();
}
);
},
function(callback) {
conn2.execute(
"SELECT department_id FROM oracledb_departments WHERE department_name = 'Security'",
function(err, result){
[],
{ outFormat: oracledb.OBJECT },
function(err, result) {
should.not.exist(err);
should.exist(result);
// console.log(result);
result.rows[0].DEPARTMENT_ID.should.eql(82).and.be.a.Number;

@@ -159,12 +199,58 @@ callback();

);
},
function(callback) {
conn1.execute(
"UPDATE oracledb_departments SET department_id = 101 WHERE department_name = 'Security'",
function(err){
should.not.exist(err);
callback();
}
);
},
function(callback) {
conn2.execute(
"SELECT department_id FROM oracledb_departments WHERE department_name = 'Security'",
[],
{ outFormat: oracledb.OBJECT },
function(err, result) {
should.not.exist(err);
result.rows[0].DEPARTMENT_ID.should.eql(101).and.be.a.Number;
callback();
}
);
},
function(callback) {
conn1.release(function(err) {
should.not.exist(err);
callback();
});
},
function(callback) {
conn2.release(function(err) {
should.not.exist(err);
callback();
});
}
], done);
})
it('7.2 auto commit takes effect for DML - update', function(done){
it('7.2 autoCommit takes effect when setting oracledb.autoCommit after connecting', function(done) {
var conn1 = null;
var conn2 = null;
async.series([
function(callback){
connection.execute(
function(callback) {
pool.getConnection(
function(err, conn) {
should.not.exist(err);
conn1 = conn;
callback();
}
);
},
function(callback) {
oracledb.autoCommit = true; // change autoCommit after connection
conn1.execute(
"INSERT INTO oracledb_departments VALUES (82, 'Security')",
function(err){
function(err) {
should.not.exist(err);

@@ -175,4 +261,25 @@ callback();

},
function(callback){
connection.execute(
function(callback) {
pool.getConnection(
function(err, conn) {
should.not.exist(err);
conn2 = conn;
callback();
}
);
},
function(callback) {
conn2.execute(
"SELECT department_id FROM oracledb_departments WHERE department_name = 'Security'",
[],
{ outFormat: oracledb.OBJECT },
function(err, result) {
should.not.exist(err);
result.rows[0].DEPARTMENT_ID.should.eql(82).and.be.a.Number;
callback();
}
);
},
function(callback) {
conn1.execute(
"UPDATE oracledb_departments SET department_id = 101 WHERE department_name = 'Security'",

@@ -185,9 +292,9 @@ function(err){

},
function(callback){
anotherConnection.execute(
function(callback) {
conn2.execute(
"SELECT department_id FROM oracledb_departments WHERE department_name = 'Security'",
function(err, result){
[],
{ outFormat: oracledb.OBJECT },
function(err, result) {
should.not.exist(err);
should.exist(result);
// console.log(result);
result.rows[0].DEPARTMENT_ID.should.eql(101).and.be.a.Number;

@@ -197,5 +304,112 @@ callback();

);
},
function(callback) {
conn1.release(function(err) {
should.not.exist(err);
callback();
});
},
function(callback) {
conn2.release(function(err) {
should.not.exist(err);
callback();
});
}
], done);
})
it('7.3 autoCommit setting does not affect previous SQL result', function(done) {
var conn1 = null;
var conn2 = null;
async.series([
function(callback) {
pool.getConnection(
function(err, conn) {
should.not.exist(err);
conn1 = conn;
callback();
}
);
},
function(callback) {
conn1.execute(
"INSERT INTO oracledb_departments VALUES (82, 'Security')",
function(err) {
should.not.exist(err);
callback();
}
);
},
function(callback) {
pool.getConnection(
function(err, conn) {
should.not.exist(err);
conn2 = conn;
callback();
}
);
},
function(callback) {
oracledb.autoCommit = true; // change autoCommit after connection
conn2.execute(
"SELECT department_id FROM oracledb_departments WHERE department_name = 'Security'",
[],
{ outFormat: oracledb.OBJECT },
function(err, result) {
should.not.exist(err);
(result.rows).should.eql([]);
callback();
}
);
},
function(callback) {
conn2.execute(
"INSERT INTO oracledb_departments VALUES (99, 'Marketing')",
function(err) {
should.not.exist(err);
callback();
}
);
},
function(callback) {
conn2.execute(
"SELECT COUNT(*) as amount FROM oracledb_departments",
[],
{ outFormat: oracledb.OBJECT },
function(err, result) {
should.not.exist(err);
result.rows[0].AMOUNT.should.eql(1);
callback();
}
);
},
function(callback) {
conn1.execute(
"SELECT COUNT(*) as amount FROM oracledb_departments",
[],
{ outFormat: oracledb.OBJECT },
function(err, result) {
should.not.exist(err);
result.rows[0].AMOUNT.should.eql(2); // autoCommit for SELECT
callback();
}
);
},
function(callback) {
conn1.release(function(err) {
should.not.exist(err);
callback();
});
},
function(callback) {
conn2.release(function(err) {
should.not.exist(err);
callback();
});
}
], done);
})
})

@@ -50,316 +50,642 @@ /* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */

var connection = false;
beforeEach(function(done) {
oracledb.getConnection(credential, function(err, conn) {
if(err) { console.error(err.message); return; }
connection = conn;
done();
});
})
describe('4.1 test STRING, NUMBER, ARRAY & JSON format', function() {
var connection = null;
before(function(done) {
oracledb.getConnection(credential, function(err, conn) {
if(err) { console.error(err.message); return; }
connection = conn;
done();
});
})
afterEach(function(done) {
connection.release( function(err) {
if(err) { console.error(err.message); return; }
done();
});
after(function(done) {
connection.release( function(err) {
if(err) { console.error(err.message); return; }
done();
});
})
it('4.1.1 VARCHAR2 binding, Object & Array formats', function(done) {
async.series([
function(callback) {
var proc = "CREATE OR REPLACE PROCEDURE oracledb_testproc (p_out OUT VARCHAR2) \
AS \
BEGIN \
p_out := 'abcdef'; \
END;";
connection.should.be.ok;
connection.execute(
proc,
function(err) {
should.not.exist(err);
callback();
}
);
},
function(callback) {
connection.execute(
"BEGIN oracledb_testproc(:o); END;",
{
o: { type: oracledb.STRING, dir: oracledb.BIND_OUT }
},
function(err, result) {
should.not.exist(err);
// console.log(result);
result.outBinds.o.should.be.exactly('abcdef');
callback();
}
);
},
function(callback) {
connection.execute(
"BEGIN oracledb_testproc(:o); END;",
[
{ type: oracledb.STRING, dir: oracledb.BIND_OUT }
],
function(err, result) {
should.not.exist(err);
// console.log(result);
result.outBinds.should.be.eql(['abcdef']);
callback();
}
);
},
function(callback) {
connection.execute(
"DROP PROCEDURE oracledb_testproc",
function(err) {
should.not.exist(err);
callback();
}
);
}
], done);
})
it('4.1.2 NUMBER binding, Object & Array formats', function(done) {
async.series([
function(callback) {
var proc = "CREATE OR REPLACE PROCEDURE oracledb_testproc (p_out OUT NUMBER) \
AS \
BEGIN \
p_out := 10010; \
END;";
connection.should.be.ok;
connection.execute(
proc,
function(err) {
should.not.exist(err);
callback();
}
);
},
function(callback) {
connection.execute(
"BEGIN oracledb_testproc(:o); END;",
{
o: { type: oracledb.NUMBER, dir: oracledb.BIND_OUT }
},
function(err, result) {
should.not.exist(err);
// console.log(result);
result.outBinds.o.should.be.exactly(10010);
callback();
}
);
},
function(callback) {
connection.execute(
"BEGIN oracledb_testproc(:o); END;",
[
{ type: oracledb.NUMBER, dir: oracledb.BIND_OUT }
],
function(err, result) {
should.not.exist(err);
// console.log(result);
result.outBinds.should.be.eql([ 10010 ]);
callback();
}
);
},
function(callback) {
connection.execute(
"DROP PROCEDURE oracledb_testproc",
function(err) {
should.not.exist(err);
callback();
}
);
}
], done);
})
it('4.1.3 Multiple binding values, Object & Array formats', function(done) {
async.series([
function(callback) {
var proc = "CREATE OR REPLACE PROCEDURE oracledb_testproc (p_in IN VARCHAR2, p_inout IN OUT VARCHAR2, p_out OUT NUMBER) \
AS \
BEGIN \
p_inout := p_in || ' ' || p_inout; \
p_out := 101; \
END; ";
connection.should.be.ok;
connection.execute(
proc,
function(err) {
should.not.exist(err);
callback();
}
);
},
function(callback) {
connection.execute(
"BEGIN oracledb_testproc(:i, :io, :o); END;",
{
i: 'Alan', // bind type is determined from the data type
io: { val: 'Turing', dir : oracledb.BIND_INOUT },
o: { type: oracledb.NUMBER, dir : oracledb.BIND_OUT }
},
function(err, result) {
should.not.exist(err);
// console.log(result);
result.outBinds.io.should.be.exactly('Alan Turing');
callback();
}
);
},
function(callback) {
connection.execute(
"BEGIN oracledb_testproc(:i, :io, :o); END;",
[
'Alan', // bind type is determined from the data type
{ val: 'Turing', dir : oracledb.BIND_INOUT },
{ type: oracledb.NUMBER, dir : oracledb.BIND_OUT }
],
function(err, result) {
should.not.exist(err);
// console.log(result);
result.outBinds.should.be.eql([ 'Alan Turing', 101 ]);
callback();
}
);
},
function(callback) {
connection.execute(
"DROP PROCEDURE oracledb_testproc",
function(err) {
should.not.exist(err);
callback();
}
);
}
], done);
})
it('4.1.4 Multiple binding values, Change binding order', function(done) {
async.series([
function(callback) {
var proc = "CREATE OR REPLACE PROCEDURE oracledb_testproc (p_inout IN OUT VARCHAR2, p_out OUT NUMBER, p_in IN VARCHAR2) \
AS \
BEGIN \
p_inout := p_in || ' ' || p_inout; \
p_out := 101; \
END; ";
connection.should.be.ok;
connection.execute(
proc,
function(err) {
should.not.exist(err);
callback();
}
);
},
function(callback) {
connection.execute(
"BEGIN oracledb_testproc(:io, :o, :i); END;",
{
i: 'Alan', // bind type is determined from the data type
io: { val: 'Turing', dir : oracledb.BIND_INOUT },
o: { type: oracledb.NUMBER, dir : oracledb.BIND_OUT }
},
function(err, result) {
should.not.exist(err);
// console.log(result);
result.outBinds.io.should.be.exactly('Alan Turing');
callback();
}
);
},
function(callback) {
connection.execute(
"BEGIN oracledb_testproc(:io, :o, :i); END;",
[
{ val: 'Turing', dir : oracledb.BIND_INOUT },
{ type: oracledb.NUMBER, dir : oracledb.BIND_OUT },
'Alan', // bind type is determined from the data type
],
function(err, result) {
should.not.exist(err);
// console.log(result);
result.outBinds.should.be.eql([ 'Alan Turing', 101 ]);
callback();
}
);
},
function(callback) {
connection.execute(
"DROP PROCEDURE oracledb_testproc",
function(err) {
should.not.exist(err);
callback();
}
);
}
], done);
})
it('4.1.5 default bind type - STRING', function(done) {
connection.should.be.ok;
var sql = "begin :n := 1001; end;";
var bindVar = { n : { dir: oracledb.BIND_OUT } };
var options = { };
connection.execute(
sql,
bindVar,
options,
function(err, result) {
should.not.exist(err);
// console.log(result);
result.outBinds.n.should.be.a.String;
result.outBinds.n.should.eql('1001');
done();
}
);
})
})
it('4.1 VARCHAR2 binding, Object & Array formats', function(done) {
async.series([
function(callback) {
var proc = "CREATE OR REPLACE PROCEDURE oracledb_testproc (p_out OUT VARCHAR2) \
AS \
BEGIN \
p_out := 'abcdef'; \
END;";
connection.should.be.ok;
connection.execute(
proc,
describe('4.2 mixing named with positional binding', function() {
var connection = null;
var createTable =
"BEGIN \
DECLARE \
e_table_exists EXCEPTION; \
PRAGMA EXCEPTION_INIT(e_table_exists, -00942); \
BEGIN \
EXECUTE IMMEDIATE ('DROP TABLE oracledb_binding'); \
EXCEPTION \
WHEN e_table_exists \
THEN NULL; \
END; \
EXECUTE IMMEDIATE (' \
CREATE TABLE oracledb_binding ( \
id NUMBER(4), \
name VARCHAR2(32) \
) \
'); \
END; ";
var insert = 'insert into oracledb_binding (id, name) values (:0, :1) returning id into :2';
var param1 = [ 1, 'changjie', { type: oracledb.NUMBER, dir: oracledb.BIND_OUT } ];
var param2 = [ 2, 'changjie', { ignored_name: { type: oracledb.NUMBER, dir: oracledb.BIND_OUT } } ];
var options = { autoCommit: true, outFormat: oracledb.OBJECT };
beforeEach(function(done) {
oracledb.getConnection(credential, function(err, conn) {
should.not.exist(err);
connection = conn;
conn.execute(
createTable,
function(err) {
should.not.exist(err);
callback();
done();
}
);
},
function(callback) {
connection.execute(
"BEGIN oracledb_testproc(:o); END;",
{
o: { type: oracledb.STRING, dir: oracledb.BIND_OUT }
},
function(err, result) {
should.not.exist(err);
// console.log(result);
result.outBinds.o.should.be.exactly('abcdef');
callback();
}
);
},
function(callback) {
connection.execute(
"BEGIN oracledb_testproc(:o); END;",
[
{ type: oracledb.STRING, dir: oracledb.BIND_OUT }
],
function(err, result) {
should.not.exist(err);
// console.log(result);
result.outBinds.should.be.eql(['abcdef']);
callback();
}
);
},
function(callback) {
connection.execute(
"DROP PROCEDURE oracledb_testproc",
function(err) {
should.not.exist(err);
callback();
}
);
}
], done);
})
});
})
it('4.2 NUMBER binding, Object & Array formats', function(done) {
async.series([
function(callback) {
var proc = "CREATE OR REPLACE PROCEDURE oracledb_testproc (p_out OUT NUMBER) \
AS \
BEGIN \
p_out := 10010; \
END;";
connection.should.be.ok;
connection.execute(
proc,
function(err) {
afterEach(function(done) {
connection.should.be.ok;
connection.execute(
"DROP TABLE oracledb_binding",
function(err) {
should.not.exist(err);
connection.release(function(err) {
should.not.exist(err);
callback();
}
);
},
function(callback) {
connection.execute(
"BEGIN oracledb_testproc(:o); END;",
{
o: { type: oracledb.NUMBER, dir: oracledb.BIND_OUT }
},
function(err, result) {
should.not.exist(err);
// console.log(result);
result.outBinds.o.should.be.exactly(10010);
callback();
}
);
},
function(callback) {
connection.execute(
"BEGIN oracledb_testproc(:o); END;",
[
{ type: oracledb.NUMBER, dir: oracledb.BIND_OUT }
],
function(err, result) {
should.not.exist(err);
// console.log(result);
result.outBinds.should.be.eql([ 10010 ]);
callback();
}
);
},
function(callback) {
connection.execute(
"DROP PROCEDURE oracledb_testproc",
function(err) {
should.not.exist(err);
callback();
}
);
}
], done);
done();
});
}
);
})
it('4.2.1 array binding is ok', function(done) {
connection.execute(
insert,
param1,
options,
function(err, result) {
should.not.exist(err);
result.rowsAffected.should.be.exactly(1);
result.outBinds[0].should.eql([1]);
// console.log(result);
connection.execute(
"SELECT * FROM oracledb_binding",
[],
options,
function(err, result) {
should.not.exist(err);
//console.log(result);
result.rows[0].ID.should.be.exactly(1);
result.rows[0].NAME.should.eql('changjie');
done();
}
);
}
);
})
it.skip('4.2.2 array binding with mixing JSON should throw an error', function(done) {
connection.execute(
insert,
param2,
options,
function(err, result) {
should.exist(err); // pending to fix
result.rowsAffected.should.be.exactly(1);
//result.outBinds[0].should.eql([1]);
//console.log(result);
connection.execute(
"SELECT * FROM oracledb_binding",
[],
options,
function(err, result) {
should.not.exist(err);
//console.log(result);
result.rows[0].ID.should.be.exactly(2);
result.rows[0].NAME.should.eql('changjie');
done();
}
);
}
);
})
})
it('4.3 Multiple binding values, Object & Array formats', function(done) {
async.series([
function(callback) {
var proc = "CREATE OR REPLACE PROCEDURE oracledb_testproc (p_in IN VARCHAR2, p_inout IN OUT VARCHAR2, p_out OUT NUMBER) \
AS \
BEGIN \
p_inout := p_in || ' ' || p_inout; \
p_out := 101; \
END; ";
connection.should.be.ok;
connection.execute(
proc,
describe('4.3 insert with DATE column and DML returning', function(done) {
var connection = null;
var createTable =
"BEGIN \
DECLARE \
e_table_exists EXCEPTION; \
PRAGMA EXCEPTION_INIT(e_table_exists, -00942); \
BEGIN \
EXECUTE IMMEDIATE ('DROP TABLE oracledb_binding'); \
EXCEPTION \
WHEN e_table_exists \
THEN NULL; \
END; \
EXECUTE IMMEDIATE (' \
CREATE TABLE oracledb_binding ( \
num NUMBER(4), \
str VARCHAR2(32), \
dt DATE \
) \
'); \
END; ";
beforeEach(function(done) {
oracledb.getConnection(credential, function(err, conn) {
should.not.exist(err);
connection = conn;
conn.execute(
createTable,
function(err) {
should.not.exist(err);
callback();
done();
}
);
},
function(callback) {
connection.execute(
"BEGIN oracledb_testproc(:i, :io, :o); END;",
{
i: 'Alan', // bind type is determined from the data type
io: { val: 'Turing', dir : oracledb.BIND_INOUT },
o: { type: oracledb.NUMBER, dir : oracledb.BIND_OUT }
},
function(err, result) {
should.not.exist(err);
// console.log(result);
result.outBinds.io.should.be.exactly('Alan Turing');
callback();
}
);
},
function(callback) {
connection.execute(
"BEGIN oracledb_testproc(:i, :io, :o); END;",
[
'Alan', // bind type is determined from the data type
{ val: 'Turing', dir : oracledb.BIND_INOUT },
{ type: oracledb.NUMBER, dir : oracledb.BIND_OUT }
],
function(err, result) {
should.not.exist(err);
// console.log(result);
result.outBinds.should.be.eql([ 'Alan Turing', 101 ]);
callback();
}
);
},
function(callback) {
connection.execute(
"DROP PROCEDURE oracledb_testproc",
function(err) {
should.not.exist(err);
callback();
}
);
}
], done);
})
});
})
it('4.4 Multiple binding values, Change binding order', function(done) {
async.series([
function(callback) {
var proc = "CREATE OR REPLACE PROCEDURE oracledb_testproc (p_inout IN OUT VARCHAR2, p_out OUT NUMBER, p_in IN VARCHAR2) \
AS \
BEGIN \
p_inout := p_in || ' ' || p_inout; \
p_out := 101; \
END; ";
connection.should.be.ok;
connection.execute(
proc,
function(err) {
afterEach(function(done) {
connection.should.be.ok;
connection.execute(
"DROP TABLE oracledb_binding",
function(err) {
should.not.exist(err);
connection.release(function(err) {
should.not.exist(err);
callback();
}
);
},
function(callback) {
connection.execute(
"BEGIN oracledb_testproc(:io, :o, :i); END;",
{
i: 'Alan', // bind type is determined from the data type
io: { val: 'Turing', dir : oracledb.BIND_INOUT },
o: { type: oracledb.NUMBER, dir : oracledb.BIND_OUT }
},
function(err, result) {
should.not.exist(err);
// console.log(result);
result.outBinds.io.should.be.exactly('Alan Turing');
callback();
}
);
},
function(callback) {
connection.execute(
"BEGIN oracledb_testproc(:io, :o, :i); END;",
[
{ val: 'Turing', dir : oracledb.BIND_INOUT },
{ type: oracledb.NUMBER, dir : oracledb.BIND_OUT },
'Alan', // bind type is determined from the data type
],
function(err, result) {
should.not.exist(err);
// console.log(result);
result.outBinds.should.be.eql([ 'Alan Turing', 101 ]);
callback();
}
);
},
function(callback) {
connection.execute(
"DROP PROCEDURE oracledb_testproc",
function(err) {
should.not.exist(err);
callback();
}
);
}
], done);
done();
});
}
);
})
var insert1 = 'insert into oracledb_binding (num, str, dt) values (:0, :1, :2)';
var insert2 = 'insert into oracledb_binding (num, str, dt) values (:0, :1, :2) returning num into :3';
var param1 = { 0: 123, 1: 'str', 2: new Date() };
var param2 = { 0: 123, 1: 'str', 2: new Date(), 3: { type: oracledb.NUMBER, dir: oracledb.BIND_OUT } };
var param3 = [ 123, 'str', new Date() ];
var param4 = [ 123, 'str', new Date(), { type: oracledb.NUMBER, dir: oracledb.BIND_OUT } ];
var options = { autoCommit: true };
it('4.3.1 passes in object syntax without returning into', function(done) {
connection.execute(
insert1,
param1,
options,
function(err, result) {
should.not.exist(err);
result.rowsAffected.should.be.exactly(1);
connection.execute(
"SELECT * FROM oracledb_binding",
[],
options,
function(err, result) {
should.not.exist(err);
// console.log(result);
done();
}
);
}
);
})
it('4.3.2 passes in object syntax with returning into', function(done) {
connection.execute(
insert2,
param2,
options,
function(err, result) {
should.not.exist(err);
result.rowsAffected.should.be.exactly(1);
//console.log(result);
result.outBinds.should.eql({ '3': [123] });
connection.execute(
"SELECT * FROM oracledb_binding",
[],
options,
function(err, result) {
should.not.exist(err);
// console.log(result);
done();
}
);
}
);
})
it('4.3.3 passes in array syntax without returning into', function(done) {
connection.execute(
insert1,
param3,
options,
function(err, result) {
should.not.exist(err);
result.rowsAffected.should.be.exactly(1);
// console.log(result);
connection.execute(
"SELECT * FROM oracledb_binding",
[],
options,
function(err, result) {
should.not.exist(err);
// console.log(result);
done();
}
);
}
);
})
it ('4.3.4 should pass but fail in array syntax with returning into', function(done) {
connection.execute(
insert2,
param4,
options,
function(err, result) {
should.not.exist(err);
result.rowsAffected.should.be.exactly(1);
// console.log(result);
result.outBinds[0].should.eql([123]);
connection.execute(
"SELECT * FROM oracledb_binding",
[],
options,
function(err, result) {
should.not.exist(err);
// console.log(result);
done();
}
);
}
);
})
})
it('4.5 outBind & maxSize restriction', function(done) {
async.series([
function(callback) {
var proc = "CREATE OR REPLACE PROCEDURE oracledb_testproc (p_out OUT VARCHAR2) \
AS \
BEGIN \
p_out := 'ABCDEF GHIJK LMNOP QRSTU'; \
END;";
connection.should.be.ok;
connection.execute(
proc,
function(err) {
should.not.exist(err);
callback();
}
);
},
function(callback) {
connection.execute(
"BEGIN oracledb_testproc(:o); END;",
{
o: { type: oracledb.STRING, dir: oracledb.BIND_OUT, maxSize:2 }
},
function(err, result) {
should.exist(err);
// console.log(err.message);
err.message.should.startWith('ORA-06502:');
// console.log(result);
callback();
}
);
},
function(callback) {
connection.execute(
"BEGIN oracledb_testproc(:o); END;",
[
{ type: oracledb.STRING, dir: oracledb.BIND_OUT, maxSize:3 }
],
function(err, result) {
should.exist(err);
// console.log(err.message);
err.message.should.startWith('ORA-06502:');
// console.log(result);
callback();
}
);
},
function(callback) {
connection.execute(
"DROP PROCEDURE oracledb_testproc",
function(err) {
should.not.exist(err);
callback();
}
);
}
], done);
})
describe('4.4 test maxSize option', function() {
var connection = null;
before(function(done) {
oracledb.getConnection(credential, function(err, conn) {
if(err) { console.error(err.message); return; }
connection = conn;
done();
});
})
after(function(done) {
connection.release( function(err) {
if(err) { console.error(err.message); return; }
done();
});
})
it('4.4.1 outBind & maxSize restriction', function(done) {
async.series([
function(callback) {
var proc = "CREATE OR REPLACE PROCEDURE oracledb_testproc (p_out OUT VARCHAR2) \
AS \
BEGIN \
p_out := 'ABCDEF GHIJK LMNOP QRSTU'; \
END;";
connection.should.be.ok;
connection.execute(
proc,
function(err) {
should.not.exist(err);
callback();
}
);
},
function(callback) {
connection.execute(
"BEGIN oracledb_testproc(:o); END;",
{
o: { type: oracledb.STRING, dir: oracledb.BIND_OUT, maxSize:2 }
},
function(err, result) {
should.exist(err);
// console.log(err.message);
err.message.should.startWith('ORA-06502:'); // ORA-06502: PL/SQL: numeric or value error: character string buffer too small
// console.log(result);
callback();
}
);
},
function(callback) {
connection.execute(
"BEGIN oracledb_testproc(:o); END;",
[
{ type: oracledb.STRING, dir: oracledb.BIND_OUT, maxSize:22 }
],
function(err, result) {
should.exist(err);
// console.log(err.message);
err.message.should.startWith('ORA-06502:');
// console.log(result);
callback();
}
);
},
function(callback) {
connection.execute(
"DROP PROCEDURE oracledb_testproc",
function(err) {
should.not.exist(err);
callback();
}
);
}
], done);
})
it.skip('4.4.2 default value is 200', function(done) {
connection.execute(
"BEGIN :o := lpad('A',201,'x'); END;",
{ o: { type: oracledb.STRING, dir : oracledb.BIND_OUT } },
function (err, result) {
should.exist(err);
err.message.should.startWith('ORA-06502:');
console.log(result.outBinds.o.length);
done();
}
);
})
it.skip('4.4.3 maximum value is 32767', function(done) {
connection.execute(
"BEGIN :o := lpad('A',32767,'x'); END;",
{ o: { type: oracledb.STRING, dir : oracledb.BIND_OUT, maxSize:50000 } },
function(err, result) {
should.exist(err);
console.log(result.outBinds.o.length);
done();
}
);
})
})
})

@@ -261,3 +261,3 @@ /* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */

it('9.8 only works for SELECT statament, does not work for INSERT', function(done){
it('9.8 only works for SELECT statement, does not work for INSERT', function(done){
connection.should.be.ok;

@@ -264,0 +264,0 @@ connection.execute(

@@ -144,3 +144,3 @@ /* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */

it('1.1.4 Negatve test - invalid outFormat value', function(done){
it('1.1.4 Negative test - invalid outFormat value', function(done){
connection.should.be.ok;

@@ -190,2 +190,3 @@ connection.execute(

END; ";
var rowsAmount = 107;

@@ -279,2 +280,15 @@ before(function(done){

})
it('1.2.5 sets maxRows to be very large value', function(done) {
connection.execute(
"SELECT * FROM oracledb_employees",
{},
{maxRows: 500000},
function(err, result){
should.not.exist(err);
(result.rows.length).should.eql(rowsAmount);
done();
}
);
})
})

@@ -315,3 +329,3 @@

it('bind parameters in various ways', function(done){
it('1.3.1 bind parameters in various ways', function(done){
var bindValues = {

@@ -336,5 +350,3 @@ i: 'Alan', // default is type STRING and direction Infinity

describe('1.4 stmtCacheSize = 0, which disable statement caching', function() {
var connection = false;
describe('1.4 statementCacheSize controls statement caching', function() {
var makeTable =

@@ -372,8 +384,8 @@ "BEGIN \

'); \
END; ";
END; ";
var connection = false;
var defaultStmtCache = oracledb.stmtCacheSize; // 30
before('get connection and prepare table', function(done) {
oracledb.stmtCacheSize = 0;
beforeEach('get connection and prepare table', function(done) {
oracledb.getConnection(credential, function(err, conn) {

@@ -392,3 +404,3 @@ if(err) { console.error(err.message); return; }

after('drop table and release connection', function(done) {
afterEach('drop table and release connection', function(done) {
oracledb.stmtCacheSize = defaultStmtCache;

@@ -406,6 +418,47 @@ connection.execute(

})
it('1.4.1 stmtCacheSize = 0, which disable statement caching', function(done) {
connection.should.be.ok;
oracledb.stmtCacheSize = 0;
async.series([
function(callback) {
connection.execute(
"INSERT INTO oracledb_employees VALUES (:num, :str)",
{ num: 1003, str: 'Robyn Sands' },
{ autoCommit: true },
function(err) {
should.not.exist(err);
callback();
}
);
},
function(callback) {
connection.execute(
"INSERT INTO oracledb_employees VALUES (:num, :str)",
{ num: 1004, str: 'Bryant Lin' },
{ autoCommit: true },
function(err) {
should.not.exist(err);
callback();
}
);
},
function(callback) {
connection.execute(
"INSERT INTO oracledb_employees VALUES (:num, :str)",
{ num: 1005, str: 'Patrick Engebresson' },
{ autoCommit: true },
function(err) {
should.not.exist(err);
callback();
}
);
}
], done);
})
it('works well when statement cache disabled', function(done) {
it('1.4.2 works well when statement cache enabled (stmtCacheSize > 0) ', function(done) {
connection.should.be.ok;
(oracledb.stmtCacheSize).should.be.exactly(0);
oracledb.stmtCacheSize = 100;

@@ -448,7 +501,6 @@ async.series([

})
})
describe('1.5 stmtCacheSize > 0', function() {
var connection = false;
describe('1.5 Testing commit() & rollback() functions', function() {
var makeTable =

@@ -474,3 +526,3 @@ "BEGIN \

VALUES \
(1001,''Chris Jones'') \
(1001,''Tom Kyte'') \
'); \

@@ -480,52 +532,74 @@ EXECUTE IMMEDIATE (' \

VALUES \
(1002,''Tom Kyte'') \
(1002, ''Karen Morton'') \
'); \
EXECUTE IMMEDIATE (' \
INSERT INTO oracledb_employees \
VALUES \
(2001, ''Karen Morton'') \
'); \
END; ";
END; ";
var defaultStmtCache = oracledb.stmtCacheSize; // 30
before('get connection and prepare table', function(done) {
oracledb.stmtCacheSize = 100;
oracledb.getConnection(credential, function(err, conn) {
if(err) { console.error(err.message); return; }
connection = conn;
conn.execute(
makeTable,
function(err){
if(err) { console.error(err.message); return; }
done();
}
);
});
var conn1 = false;
var conn2 = false;
beforeEach('get 2 connections and create the table', function(done) {
async.series([
function(callback) {
oracledb.getConnection(credential, function(err, conn) {
should.not.exist(err);
conn1 = conn;
callback();
});
},
function(callback) {
oracledb.getConnection(credential, function(err, conn) {
should.not.exist(err);
conn2 = conn;
callback();
});
},
function(callback) {
conn1.should.be.ok;
conn1.execute(
makeTable,
[],
{ autoCommit: true },
function(err) {
should.not.exist(err);
callback();
}
);
}
], done);
})
after('drop table and release connection', function(done) {
oracledb.stmtCacheSize = defaultStmtCache;
connection.execute(
"DROP TABLE oracledb_employees",
function(err){
if(err) { console.error(err.message); return; }
connection.release( function(err){
if(err) { console.error(err.message); return; }
done();
afterEach('drop table and release connections', function(done) {
conn1.should.be.ok;
conn2.should.be.ok;
async.series([
function(callback) {
conn2.execute(
"DROP TABLE oracledb_employees",
function(err) {
should.not.exist(err);
callback();
}
);
},
function(callback) {
conn1.release(function(err) {
should.not.exist(err);
callback();
});
},
function(callback) {
conn2.release(function(err) {
should.not.exist(err);
callback();
});
}
);
], done);
})
it('works well when statement cache enabled', function(done) {
connection.should.be.ok;
(oracledb.stmtCacheSize).should.be.exactly(100);
it('1.5.1 commit() function works well', function(done) {
async.series([
function(callback) {
connection.execute(
conn2.execute(
"INSERT INTO oracledb_employees VALUES (:num, :str)",
{ num: 1003, str: 'Robyn Sands' },
{ autoCommit: true },
{ num: 1003, str: 'Patrick Engebresson' },
function(err) {

@@ -538,8 +612,7 @@ should.not.exist(err);

function(callback) {
connection.execute(
"INSERT INTO oracledb_employees VALUES (:num, :str)",
{ num: 1004, str: 'Bryant Lin' },
{ autoCommit: true },
function(err) {
conn1.execute(
"SELECT COUNT(*) FROM oracledb_employees",
function(err, result) {
should.not.exist(err);
result.rows[0][0].should.be.exactly(2);
callback();

@@ -550,6 +623,37 @@ }

function(callback) {
connection.execute(
conn2.execute(
"SELECT COUNT(*) FROM oracledb_employees",
function(err, result) {
should.not.exist(err);
result.rows[0][0].should.be.exactly(3);
callback();
}
);
},
function(callback) {
conn2.commit(function(err) {
should.not.exist(err);
callback();
});
},
function(callback) {
conn1.execute(
"SELECT COUNT(*) FROM oracledb_employees",
function(err, result) {
should.not.exist(err);
result.rows[0][0].should.be.exactly(3);
callback();
}
);
},
], done);
})
it('1.5.2 rollback() function works well', function(done) {
async.series([
function(callback) {
conn2.execute(
"INSERT INTO oracledb_employees VALUES (:num, :str)",
{ num: 1005, str: 'Patrick Engebresson' },
{ autoCommit: true },
{ num: 1003, str: 'Patrick Engebresson' },
function(err) {

@@ -560,3 +664,39 @@ should.not.exist(err);

);
}
},
function(callback) {
conn1.execute(
"SELECT COUNT(*) FROM oracledb_employees",
function(err, result) {
should.not.exist(err);
result.rows[0][0].should.be.exactly(2);
callback();
}
);
},
function(callback) {
conn2.execute(
"SELECT COUNT(*) FROM oracledb_employees",
function(err, result) {
should.not.exist(err);
result.rows[0][0].should.be.exactly(3);
callback();
}
);
},
function(callback) {
conn2.rollback(function(err) {
should.not.exist(err);
callback();
});
},
function(callback) {
conn2.execute(
"SELECT COUNT(*) FROM oracledb_employees",
function(err, result) {
should.not.exist(err);
result.rows[0][0].should.be.exactly(2);
callback();
}
);
},
], done);

@@ -563,0 +703,0 @@ })

@@ -101,3 +101,3 @@ /* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */

it.skip('supports TIMESTAMP WITH TIME ZONE data type', function(done) {
it('supports TIMESTAMP WITH TIME ZONE data type', function(done) {
connection.should.be.ok;

@@ -130,8 +130,10 @@

function(err, result) {
should.not.exist(err);
// console.log(result);
should.exist(err);
err.message.should.startWith('NJS-010:'); // unsupported data type in select list
/*
console.log(result);
for(var j = 0; j < timestamps.length; j++)
result.rows[j].CONTENT.toUTCString().should.eql(timestamps[result.rows[j].NUM].toUTCString());
done();
*/
done();
}

@@ -138,0 +140,0 @@ );

@@ -101,3 +101,3 @@ /* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */

it.skip('supports TIMESTAMP WITH TIME ZONE data type', function(done) {
it('supports TIMESTAMP WITH TIME ZONE data type', function(done) {
connection.should.be.ok;

@@ -130,8 +130,10 @@

function(err, result) {
should.not.exist(err);
// console.log(result);
should.exist(err);
err.message.should.startWith('NJS-010:'); // unsupported data type in select list
/*
console.log(result);
for(var j = 0; j < timestamps.length; j++)
result.rows[j].CONTENT.toUTCString().should.eql(timestamps[result.rows[j].NUM].toUTCString());
done();
*/
done();
}

@@ -138,0 +140,0 @@ );

@@ -34,6 +34,6 @@ /* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */

module.exports = {
user : "hr",
password : "welcome",
connectString : "localhost/orcl",
externalAuth : false
user : process.env.NODE_ORACLEDB_USER || "hr",
password : process.env.NODE_ORACLEDB_PASSWORD || "welcome",
connectString : process.env.NODE_ORACLEDB_CONNECTIONSTRING || "localhost/orcl",
externalAuth : process.env.NODE_ORACLEDB_EXTERNALAUTH ? true : false
};

@@ -160,3 +160,3 @@ /* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */

should.exist(err);
err.message.should.eql('NJS-016: buffer is too small for OUT binds');
err.message.should.startWith('NJS-016'); // NJS-016: buffer is too small for OUT binds
//console.log(result);

@@ -163,0 +163,0 @@ done();

@@ -513,13 +513,3 @@ /* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */

var connection = false;
var proc = "CREATE OR REPLACE PROCEDURE testproc (p_in IN VARCHAR2, p_inout IN OUT VARCHAR2, p_out OUT NUMBER) \
AS \
BEGIN \
p_inout := p_in || p_inout; \
p_out := 101; \
END; ";
var bindVars = {
i: 'Chris', // bind type is determined from the data type
io: { val: 'Jones', dir : oracledb.BIND_INOUT },
o: { type: oracledb.NUMBER, dir : oracledb.BIND_OUT }
}
before(function(done){

@@ -541,2 +531,15 @@ oracledb.getConnection(credential, function(err, conn){

it('3.7.1 can call PL/SQL procedure and binding parameters in various ways', function(done){
var proc =
"CREATE OR REPLACE PROCEDURE testproc (p_in IN VARCHAR2, p_inout IN OUT VARCHAR2, p_out OUT NUMBER) \
AS \
BEGIN \
p_inout := p_in || p_inout; \
p_out := 101; \
END; ";
var bindVars = {
i: 'Chris', // bind type is determined from the data type
io: { val: 'Jones', dir : oracledb.BIND_INOUT },
o: { type: oracledb.NUMBER, dir : oracledb.BIND_OUT }
}
async.series([

@@ -575,2 +578,49 @@ function(callback){

})
it('3.7.2 can call PL/SQL function', function(done) {
var proc =
"CREATE OR REPLACE FUNCTION testfunc (p1_in IN VARCHAR2, p2_in IN VARCHAR2) RETURN VARCHAR2 \
AS \
BEGIN \
return p1_in || p2_in; \
END; ";
var bindVars = {
p1: 'Chris',
p2: 'Jones',
ret: { dir: oracledb.BIND_OUT, type: oracledb.STRING, maxSize: 40 }
};
async.series([
function(callback){
connection.execute(
proc,
function(err){
should.not.exist(err);
callback();
}
);
},
function(callback){
connection.execute(
"BEGIN :ret := testfunc(:p1, :p2); END;",
bindVars,
function(err, result){
should.not.exist(err);
// console.log(result);
(result.outBinds.ret).should.equal('ChrisJones');
callback();
}
);
},
function(callback){
connection.execute(
"DROP FUNCTION testfunc",
function(err, result){
should.not.exist(err);
callback();
}
);
}
], done);
})

@@ -906,6 +956,153 @@ })

})
})
describe('3.11 refcursor.js', function() {
var connection = false;
var script =
"BEGIN \
DECLARE \
e_table_exists EXCEPTION; \
PRAGMA EXCEPTION_INIT(e_table_exists, -00942); \
BEGIN \
EXECUTE IMMEDIATE ('DROP TABLE oracledb_employees'); \
EXCEPTION \
WHEN e_table_exists \
THEN NULL; \
END; \
EXECUTE IMMEDIATE (' \
CREATE TABLE oracledb_employees ( \
name VARCHAR2(40), \
salary NUMBER, \
hire_date DATE \
) \
'); \
EXECUTE IMMEDIATE (' \
INSERT INTO oracledb_employees \
(name, salary, hire_date) VALUES \
(''Steven'',24000, TO_DATE(''20030617'', ''yyyymmdd'')) \
'); \
EXECUTE IMMEDIATE (' \
INSERT INTO oracledb_employees \
(name, salary, hire_date) VALUES \
(''Neena'',17000, TO_DATE(''20050921'', ''yyyymmdd'')) \
'); \
EXECUTE IMMEDIATE (' \
INSERT INTO oracledb_employees \
(name, salary, hire_date) VALUES \
(''Lex'',17000, TO_DATE(''20010112'', ''yyyymmdd'')) \
'); \
EXECUTE IMMEDIATE (' \
INSERT INTO oracledb_employees \
(name, salary, hire_date) VALUES \
(''Nancy'',12008, TO_DATE(''20020817'', ''yyyymmdd'')) \
'); \
EXECUTE IMMEDIATE (' \
INSERT INTO oracledb_employees \
(name, salary, hire_date) VALUES \
(''Karen'',14000, TO_DATE(''20050104'', ''yyyymmdd'')) \
'); \
EXECUTE IMMEDIATE (' \
INSERT INTO oracledb_employees \
(name, salary, hire_date) VALUES \
(''Peter'',9000, TO_DATE(''20100525'', ''yyyymmdd'')) \
'); \
END; ";
var proc =
"CREATE OR REPLACE PROCEDURE get_emp_rs (p_sal IN NUMBER, p_recordset OUT SYS_REFCURSOR) \
AS \
BEGIN \
OPEN p_recordset FOR \
SELECT * FROM oracledb_employees \
WHERE salary > p_sal; \
END; ";
before(function(done){
async.series([
function(callback) {
oracledb.getConnection(
credential,
function(err, conn) {
should.not.exist(err);
connection = conn;
callback();
}
);
},
function(callback) {
connection.execute(
script,
function(err) {
should.not.exist(err);
callback();
}
);
},
function(callback) {
connection.execute(
proc,
function(err) {
should.not.exist(err);
callback();
}
);
}
], done);
})
after(function(done){
connection.execute(
'DROP TABLE oracledb_employees',
function(err){
if(err) { console.error(err.message); return; }
connection.release( function(err){
if(err) { console.error(err.message); return; }
done();
});
}
);
})
it('3.11.1 REF CURSOR', function(done) {
connection.should.be.ok;
var numRows = 100; // number of rows to return from each call to getRows()
connection.execute(
"BEGIN get_emp_rs(:sal, :cursor); END;",
{
sal: 12000,
cursor: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
},
function(err, result) {
should.not.exist(err);
result.outBinds.cursor.metaData[0].name.should.eql('NAME');
result.outBinds.cursor.metaData[1].name.should.eql('SALARY');
result.outBinds.cursor.metaData[2].name.should.eql('HIRE_DATE');
fetchRowsFromRS(result.outBinds.cursor);
}
);
function fetchRowsFromRS(resultSet) {
resultSet.getRows(
numRows,
function(err, rows) {
should.not.exist(err);
if(rows.length > 0) {
// console.log("fetchRowsFromRS(): Got " + rows.length + " rows");
// console.log(rows);
rows.length.should.be.exactly(5);
fetchRowsFromRS(resultSet);
} else {
resultSet.close( function(err) {
should.not.exist(err);
done();
});
}
}
);
}
})
})
})

@@ -61,4 +61,7 @@ # Testing node-oracledb

### 4. Edit database credentials
### 4. Database credentials
The database credentials for node-oracledb test suite are defined in dbConfig.js file. You can set the credentials via environment variables or dbConfig.js file.
Change the credentials to a user who has privileges to connect and create tables.
```

@@ -68,10 +71,8 @@ vi <some-directory>/node_modules/oracledb/test/dbConfig.js

Change the credentials to a user who has privileges to connect and create tables:
```javascript
module.exports = {
user : "hr",
password : "welcome",
connectString : "localhost/orcl",
externalAuth : false
user : process.env.NODE_ORACLEDB_USER || "hr",
password : process.env.NODE_ORACLEDB_PASSWORD || "welcome",
connectString : process.env.NODE_ORACLEDB_CONNECTIONSTRING || "localhost/orcl",
externalAuth : process.env.NODE_ORACLEDB_EXTERNALAUTH ? true : false
};

@@ -118,1 +119,5 @@ ```

- 51 onwards are for other tests
## Test List
See test/list.txt file for the list of existing tests.

@@ -349,3 +349,3 @@ /* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */

describe('12.3 Testing function getRows()', function() {
it('12.3.1 retrived set is exactly the size of result', function(done) {
it('12.3.1 retrieved set is exactly the size of result', function(done) {
connection.should.be.ok;

@@ -383,3 +383,3 @@ var nRows = rowsAmount;

it('12.3.2 retrived set is greater than the size of result', function(done) {
it('12.3.2 retrieved set is greater than the size of result', function(done) {
connection.should.be.ok;

@@ -417,3 +417,3 @@ var nRows = rowsAmount * 2;

it('12.3.3 retrived set is half of the size of result', function(done) {
it('12.3.3 retrieved set is half of the size of result', function(done) {
connection.should.be.ok;

@@ -451,3 +451,3 @@ var nRows = Math.ceil(rowsAmount/2);

it('12.3.4 retrived set is one tenth of the size of the result', function(done) {
it('12.3.4 retrieved set is one tenth of the size of the result', function(done) {
connection.should.be.ok;

@@ -557,3 +557,3 @@ var nRows = Math.ceil(rowsAmount/10);

it('12.3.7 the size of retrived set can be set to 1', function(done) {
it('12.3.7 the size of retrieved set can be set to 1', function(done) {
connection.should.be.ok;

@@ -1326,2 +1326,67 @@ var nRows = 1;

})
it('12.7.2 maxRows option is ignored with REF Cursor', function(done) {
connection.should.be.ok;
var rowCount = 0;
var queryAmount = 100;
var proc =
"CREATE OR REPLACE PROCEDURE get_emp_rs (p_in IN NUMBER, p_out OUT SYS_REFCURSOR) \
AS \
BEGIN \
OPEN p_out FOR \
SELECT * FROM oracledb_employees \
WHERE employees_id <= p_in; \
END; ";
async.series([
function(callback) {
connection.execute(
proc,
function(err) {
should.not.exist(err);
callback();
}
);
},
function(callback) {
connection.execute(
"BEGIN get_emp_rs(:in, :out); END;",
{
in: queryAmount,
out: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
},
{ maxRows: 10 },
function(err, result) {
should.not.exist(err);
fetchRowFromRS(result.outBinds.out, callback);
}
);
},
function(callback) {
connection.execute(
"DROP PROCEDURE get_emp_rs",
function(err) {
should.not.exist(err);
callback();
}
);
}
], done);
function fetchRowFromRS(rs, cb) {
rs.getRow(function(err, row) {
should.not.exist(err);
if(row) {
rowCount++;
return fetchRowFromRS(rs, cb);
} else {
rs.close( function(err) {
should.not.exist(err);
rowCount.should.eql(queryAmount);
cb();
});
}
});
}
})
})

@@ -1328,0 +1393,0 @@

@@ -34,3 +34,4 @@ /* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */

*****************************************************************************/
"use strict";
var oracledb = require('oracledb');

@@ -41,3 +42,3 @@ var should = require('should');

describe('55 resultSet2.js', function() {
describe('55. resultSet2.js', function() {

@@ -70,2 +71,3 @@ if(dbConfig.externalAuth){

var rowsAmount = 300;
var insertRows =

@@ -82,33 +84,85 @@ "DECLARE \

END; ";
var rowsAmount = 300;
var proc =
"CREATE OR REPLACE PROCEDURE get_emp_rs (p_in IN NUMBER, p_out OUT SYS_REFCURSOR) \
AS \
BEGIN \
OPEN p_out FOR \
SELECT * FROM oracledb_employees \
WHERE employees_id > p_in; \
END; ";
beforeEach(function(done) {
oracledb.getConnection(credential, function(err, conn) {
if(err) { console.error(err.message); return; }
connection = conn;
connection.execute(createTable, function(err) {
if(err) { console.error(err.message); return; }
async.series([
function(callback) {
oracledb.getConnection(
credential,
function(err, conn) {
connection = conn;
callback();
}
);
},
function(callback) {
connection.should.be.ok;
connection.execute(
insertRows,
createTable,
function(err) {
should.not.exist(err);
callback();
}
);
},
function(callback) {
connection.execute(
insertRows,
[],
{ autoCommit: true },
function(err) {
if(err) { console.error(err.message); return; }
done();
});
});
});
should.not.exist(err);
callback();
}
);
},
function(callback) {
connection.execute(
proc,
[],
{ autoCommit: true },
function(err) {
should.not.exist(err);
callback();
}
);
}
], done);
})
afterEach(function(done) {
connection.execute(
'DROP TABLE oracledb_employees',
function(err) {
if(err) { console.error(err.message); return; }
connection.release(function(err) {
if(err) { console.error(err.message); return; }
done();
async.series([
function(callback) {
connection.execute(
'DROP TABLE oracledb_employees',
function(err) {
should.not.exist(err);
callback();
}
);
},
function(callback) {
connection.execute(
'DROP PROCEDURE get_emp_rs',
function(err) {
should.not.exist(err);
callback();
}
);
},
function(callback) {
connection.release( function(err) {
should.not.exist(err);
callback();
});
}
);
], done);
})

@@ -181,4 +235,4 @@

describe('55.3 alternating getRow() & getRows() function', function(done) {
it('55.3.1', function(done) {
describe('55.3 alternating getRow() & getRows() function', function() {
it('55.3.1 result set', function(done) {
connection.should.be.ok;

@@ -237,7 +291,81 @@ var accessCount = 0;

})
it('55.3.2 REF Cursor', function(done) {
connection.should.be.ok;
var accessCount = 0;
var numRows = 4;
var flag = 1; // 1 - getRow(); 2 - getRows(); 3 - to close resultSet.
connection.execute(
"BEGIN get_emp_rs(:in, :out); END;",
{
in: 200,
out: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
},
function(err, result) {
should.not.exist(err);
fetchRowFromRS(result.outBinds.out, done);
}
);
function fetchRowFromRS(rs, cb) {
if(flag === 1) {
rs.getRow(function(err, row) {
should.not.exist(err);
if(row) {
flag = 2;
accessCount++;
return fetchRowFromRS(rs, cb);
} else {
flag = 3;
return fetchRowFromRS(rs, cb);
}
});
}
else if(flag === 2) {
rs.getRows(numRows, function(err, rows) {
should.not.exist(err);
if(rows.length > 0) {
flag = 1;
accessCount++;
return fetchRowFromRS(rs, cb);
} else {
flag = 3;
return fetchRowFromRS(rs, cb);
}
});
}
else if(flag === 3) {
// console.log("resultSet is empty!");
rs.close(function(err) {
should.not.exist(err);
// console.log("Total access count is " + accessCount);
accessCount.should.be.exactly((100/(numRows + 1)) * 2);
cb();
});
}
}
})
})
describe('55.4 release connetion before close resultSet', function() {
describe('55.4 release connection before close resultSet', function() {
var conn2 = false;
before(function(done) {
function fetchRowFromRS(rs, cb) {
rs.getRow(function(err, row) {
if(row) {
return fetchRowFromRS(rs, cb);
} else {
conn2.release(function(err) {
should.not.exist(err);
rs.close(function(err) {
should.exist(err);
err.message.should.startWith('NJS-003'); // invalid connection
cb();
});
});
}
});
}
beforeEach(function(done) {
oracledb.getConnection(

@@ -253,3 +381,3 @@ credential,

it('55.4.1 ', function(done) {
it('55.4.1 result set', function(done) {
conn2.should.be.ok;

@@ -262,24 +390,21 @@ conn2.execute(

should.not.exist(err);
fetchRowFromRS(result.resultSet);
fetchRowFromRS(result.resultSet, done);
}
);
})
it('55.4.2 REF Cursor', function(done) {
conn2.should.be.ok;
function fetchRowFromRS(rs) {
rs.getRow(function(err, row) {
conn2.execute(
"BEGIN get_emp_rs(:in, :out); END;",
{
in: 200,
out: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
},
function(err, result) {
should.not.exist(err);
if(row) {
return fetchRowFromRS(rs);
} else {
conn2.release(function(err) {
should.not.exist(err);
rs.close(function(err) {
should.exist(err);
err.message.should.startWith('NJS-003');
done();
});
});
}
});
}
fetchRowFromRS(result.outBinds.out, done);
}
);
})

@@ -323,3 +448,3 @@ })

function fetchRowFromRS(rset, cb) {
rs.getRow(function(err, row) {
rset.getRow(function(err, row) {
should.not.exist(err);

@@ -330,3 +455,3 @@ if(row) {

} else {
rs.close(function(err) {
rset.close(function(err) {
should.not.exist(err);

@@ -341,10 +466,41 @@ rowsCount.should.eql(rowsAmount);

})
})
describe('55.6 access resultSet simultaneously', function() {
var numRows = 10; // number of rows to return from each call to getRows()
function fetchRowFromRS(rs, cb) {
rs.getRow(function(err, row) {
if(err) {
cb(err);
return;
} else {
if(row) {
return fetchRowFromRS(rs, cb);
} else {
cb();
}
}
});
}
function fetchRowsFromRS(rs, cb) {
rs.getRows(numRows, function(err, rows) {
if(err) {
cb(err);
return;
} else {
if(rows.length > 0) {
return fetchRowsFromRS(rs, cb);
} else {
cb();
}
}
});
}
it('55.6.1 concurrent operations on resultSet are not allowed', function(done) {
connection.should.be.ok;
var rowCount1 = 0;
var rowCount2 = 0;
var numRows = 10; // number of rows to return from each call to getRows()
connection.execute(

@@ -378,45 +534,76 @@ "SELECT * FROM oracledb_employees",

}
);
function fetchRowFromRS(rs, cb) {
rs.getRow(function(err, row) {
if(err) {
cb(err);
return;
} else {
if(row) {
rowCount1++;
return fetchRowFromRS(rs, cb);
} else {
cb();
);
})
it('55.6.2 concurrent operation on REF Cursor are not allowed', function(done) {
connection.should.be.ok;
connection.execute(
"BEGIN get_emp_rs(:in, :out); END;",
{
in: 0,
out: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
},
function(err, result) {
should.not.exist(err);
async.parallel([
function(callback) {
fetchRowFromRS(result.outBinds.out, callback);
},
function(callback) {
fetchRowsFromRS(result.outBinds.out, callback);
}
}
});
}
function fetchRowsFromRS(rs, cb) {
rs.getRows(numRows, function(err, rows) {
//should.not.exist(err);
if(err) {
cb(err);
return;
} else {
if(rows.length > 0) {
rowCount2 += 10;
return fetchRowsFromRS(rs, cb);
], function(err) {
if(err) {
// console.log(err);
err.message.should.startWith('NJS-017');
result.outBinds.out.close(function(err) {
done();
});
} else {
cb();
}
}
});
}
result.outBinds.out.close(function(error) {
should.not.exist(error);
done();
});
}
});
}
);
})
})
describe('55.7 getting multiple resultSets', function() {
var numRows = 10; // number of rows to return from each call to getRows()
function fetchRowFromRS(rs, cb) {
rs.getRow(function(err, row) {
should.not.exist(err);
if(row) {
return fetchRowFromRS(rs, cb);
} else {
rs.close(function(err) {
should.not.exist(err);
cb();
});
}
});
}
function fetchRowsFromRS(rs, cb) {
rs.getRows(numRows, function(err, rows) {
should.not.exist(err);
if(rows.length > 0) {
return fetchRowsFromRS(rs, cb);
} else {
rs.close(function(err) {
should.not.exist(err);
cb();
});
}
});
}
it('55.7.1 can access multiple resultSet on one connection', function(done) {
connection.should.be.ok;
var rowCount1 = 0;
var rowCount2 = 0;
var numRows = 10; // number of rows to return from each call to getRows()
async.parallel([

@@ -449,3 +636,103 @@ function(callback) {

});
})
it('55.7.2 can access multiple REF Cursor', function(done) {
connection.should.be.ok;
async.parallel([
function(callback) {
connection.execute(
"BEGIN get_emp_rs(:in, :out); END;",
{
in: 200,
out: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
},
function(err, result) {
should.not.exist(err);
fetchRowFromRS(result.outBinds.out, callback);
}
);
},
function(callback) {
connection.execute(
"BEGIN get_emp_rs(:in, :out); END;",
{
in: 100,
out: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
},
function(err, result) {
should.not.exist(err);
fetchRowsFromRS(result.outBinds.out, callback);
}
);
}
], function(err) {
should.not.exist(err);
done();
});
})
})
describe('55.8 Negative - resultSet is only for query statement', function() {
it('55.8.1 resultSet cannot be returned for non-query statements', function(done) {
connection.should.be.ok;
connection.execute(
"UPDATE oracledb_employees SET employees_name = 'Alan' WHERE employees_id = 100",
[],
{ resultSet: true },
function(err, result) {
should.exist(err);
// console.log(err);
err.message.should.startWith('NJS-019');
done();
}
);
})
})
describe('55.9 test querying a PL/SQL function', function() {
it('55.9.1 ', function(done) {
var proc =
"CREATE OR REPLACE FUNCTION testfunc RETURN VARCHAR2 \
IS \
emp_name VARCHAR2(20); \
BEGIN \
SELECT 'Clark Kent' INTO emp_name FROM dual; \
RETURN emp_name; \
END; ";
async.series([
function(callback) {
connection.execute(
proc,
function(err) {
should.not.exist(err);
callback();
}
);
},
function(callback) {
connection.execute(
"SELECT testfunc FROM dual",
[],
{ resultSet: true },
function(err, result) {
should.not.exist(err);
(result.resultSet.metaData[0].name).should.eql('TESTFUNC');
fetchRowFromRS(result.resultSet, callback);
}
);
},
function(callback) {
connection.execute(
"DROP FUNCTION testfunc",
function(err, result) {
should.not.exist(err);
callback();
}
);
}
], done);
function fetchRowFromRS(rs, cb) {

@@ -455,3 +742,3 @@ rs.getRow(function(err, row) {

if(row) {
rowCount1++;
row[0].should.eql('Clark Kent');
return fetchRowFromRS(rs, cb);

@@ -466,58 +753,95 @@ } else {

}
function fetchRowsFromRS(rs, cb) {
rs.getRows(numRows, function(err, rows) {
should.not.exist(err);
if(rows.length > 0) {
rowCount2 += numRows;
return fetchRowsFromRS(rs, cb);
} else {
rs.close(function(err) {
should.not.exist(err);
cb();
});
}
});
}
})
})
describe('55.8 Negative - resultSet is only for query statement', function() {
it('55.8.1 resultSet cannot be returned for non-query statements', function(done) {
describe('55.10 calls getRows() once and then close RS before getting more rows', function() {
it('55.10.1 ', function(done) {
connection.should.be.ok;
var numRows = 10;
var closeRS = true;
connection.execute(
"UPDATE oracledb_employees SET employees_name = 'Alan' WHERE employees_id = 100",
"SELECT * FROM oracledb_employees",
[],
{ resultSet: true },
function(err, result) {
should.exist(err);
// console.log(err);
err.message.should.startWith('NJS-019');
done();
should.not.exist(err);
result.resultSet.getRows(
numRows,
function(err, rows) {
should.not.exist(err);
result.resultSet.close(function(err) {
should.not.exist(err);
fetchRowsFromRS(result.resultSet, numRows, done);
});
}
);
}
);
function fetchRowsFromRS(rs, numRows, done) {
rs.getRows(numRows, function(err, rows) {
should.exist(err);
err.message.should.startWith('NJS-018:'); // invalid result set
done();
});
}
})
})
})
describe('55.11 deals with unsupported database with result set', function() {
var sql1 = "select dummy, HEXTORAW('0123456789ABCDEF0123456789ABCDEF') from dual";
var sql2 = "SELECT dummy, rowid FROM dual";
function fetchOneRowFromRS(rs, cb) {
rs.getRow(function(err, row) {
/* Currently, even if the driver doesn't support certain data type
* the result set can still be created.
*/
// Error at accessing RS
if(err) {
// console.error("Error at accessing RS: " + err.message);
// NJS-010: unsupported data type in select list
(err.message).should.startWith('NJS-010');
rs.close( function(err) {
should.not.exist(err);
cb();
});
} else if(row) {
console.log(row);
fetchOneRowFromRS(rs, cb);
} else {
rs.close( function(err) {
should.not.exist(err);
cb();
});
}
});
}
it('55.11.1 RAW data type', function(done) {
connection.should.be.ok;
connection.execute(
sql1,
[],
{ resultSet: true },
function(err, result) {
should.not.exist(err);
fetchOneRowFromRS(result.resultSet, done);
}
);
})
it('55.11.2 ROWID date type', function(done) {
connection.execute(
sql2,
[],
{ resultSet: true },
function(err, result) {
should.not.exist(err);
fetchOneRowFromRS(result.resultSet, done);
}
);
})
})
})

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc