Skip to content

Commit 3a9c0d9

Browse files
committed
Add DB Support objects and Pipelined Table tests
1 parent 4c2336e commit 3a9c0d9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1660
-208
lines changed

examples/plsqlrecord.js

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,26 @@ Error.stackTraceLimit = 50;
3737
const oracledb = require('oracledb');
3838
const dbConfig = require('./dbconfig.js');
3939

40-
// This example requires node-oracledb Thick mode.
40+
// This example runs in both node-oracledb Thin and Thick modes.
4141
//
42-
// Thick mode requires Oracle Client or Oracle Instant Client libraries. On
43-
// Windows and macOS Intel you can specify the directory containing the
44-
// libraries at runtime or before Node.js starts. On other platforms (where
45-
// Oracle libraries are available) the system library search path must always
46-
// include the Oracle library path before Node.js starts. If the search path
47-
// is not correct, you will get a DPI-1047 error. See the node-oracledb
48-
// installation documentation.
49-
let clientOpts = {};
50-
if (process.platform === 'win32') { // Windows
51-
clientOpts = { libDir: 'C:\\oracle\\instantclient_19_17' };
52-
} else if (process.platform === 'darwin' && process.arch === 'x64') { // macOS Intel
53-
clientOpts = { libDir: process.env.HOME + '/Downloads/instantclient_19_8' };
42+
// Optionally run in node-oracledb Thick mode
43+
if (process.env.NODE_ORACLEDB_DRIVER_MODE === 'thick') {
44+
45+
// Thick mode requires Oracle Client or Oracle Instant Client libraries.
46+
// On Windows and macOS Intel you can specify the directory containing the
47+
// libraries at runtime or before Node.js starts. On other platforms (where
48+
// Oracle libraries are available) the system library search path must always
49+
// include the Oracle library path before Node.js starts. If the search path
50+
// is not correct, you will get a DPI-1047 error. See the node-oracledb
51+
// installation documentation.
52+
let clientOpts = {};
53+
if (process.platform === 'win32') { // Windows
54+
clientOpts = { libDir: 'C:\\oracle\\instantclient_19_17' };
55+
} else if (process.platform === 'darwin' && process.arch === 'x64') { // macOS Intel
56+
clientOpts = { libDir: process.env.HOME + '/Downloads/instantclient_19_8' };
57+
}
58+
oracledb.initOracleClient(clientOpts); // enable node-oracledb Thick mode
5459
}
55-
oracledb.initOracleClient(clientOpts); // enable node-oracledb Thick mode
5660

5761
async function run() {
5862
let connection, binds, options, result, obj;

examples/plsqlvarrayrecord.js

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,26 @@ Error.stackTraceLimit = 50;
3737
const oracledb = require('oracledb');
3838
const dbConfig = require('./dbconfig.js');
3939

40-
// This example requires node-oracledb Thick mode.
40+
// This example runs in both node-oracledb Thin and Thick modes.
4141
//
42-
// Thick mode requires Oracle Client or Oracle Instant Client libraries. On
43-
// Windows and macOS Intel you can specify the directory containing the
44-
// libraries at runtime or before Node.js starts. On other platforms (where
45-
// Oracle libraries are available) the system library search path must always
46-
// include the Oracle library path before Node.js starts. If the search path
47-
// is not correct, you will get a DPI-1047 error. See the node-oracledb
48-
// installation documentation.
49-
let clientOpts = {};
50-
if (process.platform === 'win32') { // Windows
51-
clientOpts = { libDir: 'C:\\oracle\\instantclient_19_17' };
52-
} else if (process.platform === 'darwin' && process.arch === 'x64') { // macOS Intel
53-
clientOpts = { libDir: process.env.HOME + '/Downloads/instantclient_19_8' };
42+
// Optionally run in node-oracledb Thick mode
43+
if (process.env.NODE_ORACLEDB_DRIVER_MODE === 'thick') {
44+
45+
// Thick mode requires Oracle Client or Oracle Instant Client libraries.
46+
// On Windows and macOS Intel you can specify the directory containing the
47+
// libraries at runtime or before Node.js starts. On other platforms (where
48+
// Oracle libraries are available) the system library search path must always
49+
// include the Oracle library path before Node.js starts. If the search path
50+
// is not correct, you will get a DPI-1047 error. See the node-oracledb
51+
// installation documentation.
52+
let clientOpts = {};
53+
if (process.platform === 'win32') { // Windows
54+
clientOpts = { libDir: 'C:\\oracle\\instantclient_19_17' };
55+
} else if (process.platform === 'darwin' && process.arch === 'x64') { // macOS Intel
56+
clientOpts = { libDir: process.env.HOME + '/Downloads/instantclient_19_8' };
57+
}
58+
oracledb.initOracleClient(clientOpts); // enable node-oracledb Thick mode
5459
}
55-
oracledb.initOracleClient(clientOpts); // enable node-oracledb Thick mode
5660

5761
async function run() {
5862
let connection;

examples/selectgeometry.js

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,26 @@ Error.stackTraceLimit = 50;
3737
const oracledb = require('oracledb');
3838
const dbConfig = require('./dbconfig.js');
3939

40-
// This example requires node-oracledb Thick mode.
40+
// This example runs in both node-oracledb Thin and Thick modes.
4141
//
42-
// On Windows and macOS Intel, you can specify the directory containing the
43-
// Oracle Client Libraries at runtime, or before Node.js starts. On other
44-
// platforms the system library search path must always be set before Node.js
45-
// is started. See the node-oracledb installation documentation. If the
46-
// search path is not correct, you will get a DPI-1047 error.
47-
let clientOpts = {};
48-
if (process.platform === 'win32') { // Windows
49-
clientOpts = { libDir: 'C:\\oracle\\instantclient_19_17' };
50-
} else if (process.platform === 'darwin' && process.arch === 'x64') { // macOS Intel
51-
clientOpts = { libDir: process.env.HOME + '/Downloads/instantclient_19_8' };
42+
// Optionally run in node-oracledb Thick mode
43+
if (process.env.NODE_ORACLEDB_DRIVER_MODE === 'thick') {
44+
45+
// Thick mode requires Oracle Client or Oracle Instant Client libraries.
46+
// On Windows and macOS Intel you can specify the directory containing the
47+
// libraries at runtime or before Node.js starts. On other platforms (where
48+
// Oracle libraries are available) the system library search path must always
49+
// include the Oracle library path before Node.js starts. If the search path
50+
// is not correct, you will get a DPI-1047 error. See the node-oracledb
51+
// installation documentation.
52+
let clientOpts = {};
53+
if (process.platform === 'win32') { // Windows
54+
clientOpts = { libDir: 'C:\\oracle\\instantclient_19_17' };
55+
} else if (process.platform === 'darwin' && process.arch === 'x64') { // macOS Intel
56+
clientOpts = { libDir: process.env.HOME + '/Downloads/instantclient_19_8' };
57+
}
58+
oracledb.initOracleClient(clientOpts); // enable node-oracledb Thick mode
5259
}
53-
oracledb.initOracleClient(clientOpts);
5460

5561
// If each object's attributes are accessed multiple times, it may be more
5662
// efficient to fetch as simple JavaScriptobjects.

examples/selectobject.js

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,26 @@ Error.stackTraceLimit = 50;
3838
const oracledb = require('oracledb');
3939
const dbConfig = require('./dbconfig.js');
4040

41-
// This example requires node-oracledb Thick mode.
41+
// This example runs in both node-oracledb Thin and Thick modes.
4242
//
43-
// Thick mode requires Oracle Client or Oracle Instant Client libraries. On
44-
// Windows and macOS Intel you can specify the directory containing the
45-
// libraries at runtime or before Node.js starts. On other platforms (where
46-
// Oracle libraries are available) the system library search path must always
47-
// include the Oracle library path before Node.js starts. If the search path
48-
// is not correct, you will get a DPI-1047 error. See the node-oracledb
49-
// installation documentation.
50-
let clientOpts = {};
51-
if (process.platform === 'win32') { // Windows
52-
clientOpts = { libDir: 'C:\\oracle\\instantclient_19_17' };
53-
} else if (process.platform === 'darwin' && process.arch === 'x64') { // macOS Intel
54-
clientOpts = { libDir: process.env.HOME + '/Downloads/instantclient_19_8' };
43+
// Optionally run in node-oracledb Thick mode
44+
if (process.env.NODE_ORACLEDB_DRIVER_MODE === 'thick') {
45+
46+
// Thick mode requires Oracle Client or Oracle Instant Client libraries.
47+
// On Windows and macOS Intel you can specify the directory containing the
48+
// libraries at runtime or before Node.js starts. On other platforms (where
49+
// Oracle libraries are available) the system library search path must always
50+
// include the Oracle library path before Node.js starts. If the search path
51+
// is not correct, you will get a DPI-1047 error. See the node-oracledb
52+
// installation documentation.
53+
let clientOpts = {};
54+
if (process.platform === 'win32') { // Windows
55+
clientOpts = { libDir: 'C:\\oracle\\instantclient_19_17' };
56+
} else if (process.platform === 'darwin' && process.arch === 'x64') { // macOS Intel
57+
clientOpts = { libDir: process.env.HOME + '/Downloads/instantclient_19_8' };
58+
}
59+
oracledb.initOracleClient(clientOpts); // enable node-oracledb Thick mode
5560
}
56-
oracledb.initOracleClient(clientOpts); // enable node-oracledb Thick mode
5761

5862
// If each object's attributes are accessed multiple times, it may be more
5963
// efficient to fetch as simple JavaScriptobjects.

examples/selectvarray.js

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,26 @@ Error.stackTraceLimit = 50;
3737
const oracledb = require('oracledb');
3838
const dbConfig = require('./dbconfig.js');
3939

40-
// This example requires node-oracledb Thick mode.
40+
// This example runs in both node-oracledb Thin and Thick modes.
4141
//
42-
// Thick mode requires Oracle Client or Oracle Instant Client libraries. On
43-
// Windows and macOS Intel you can specify the directory containing the
44-
// libraries at runtime or before Node.js starts. On other platforms (where
45-
// Oracle libraries are available) the system library search path must always
46-
// include the Oracle library path before Node.js starts. If the search path
47-
// is not correct, you will get a DPI-1047 error. See the node-oracledb
48-
// installation documentation.
49-
let clientOpts = {};
50-
if (process.platform === 'win32') { // Windows
51-
clientOpts = { libDir: 'C:\\oracle\\instantclient_19_17' };
52-
} else if (process.platform === 'darwin' && process.arch === 'x64') { // macOS Intel
53-
clientOpts = { libDir: process.env.HOME + '/Downloads/instantclient_19_8' };
42+
// Optionally run in node-oracledb Thick mode
43+
if (process.env.NODE_ORACLEDB_DRIVER_MODE === 'thick') {
44+
45+
// Thick mode requires Oracle Client or Oracle Instant Client libraries.
46+
// On Windows and macOS Intel you can specify the directory containing the
47+
// libraries at runtime or before Node.js starts. On other platforms (where
48+
// Oracle libraries are available) the system library search path must always
49+
// include the Oracle library path before Node.js starts. If the search path
50+
// is not correct, you will get a DPI-1047 error. See the node-oracledb
51+
// installation documentation.
52+
let clientOpts = {};
53+
if (process.platform === 'win32') { // Windows
54+
clientOpts = { libDir: 'C:\\oracle\\instantclient_19_17' };
55+
} else if (process.platform === 'darwin' && process.arch === 'x64') { // macOS Intel
56+
clientOpts = { libDir: process.env.HOME + '/Downloads/instantclient_19_8' };
57+
}
58+
oracledb.initOracleClient(clientOpts); // enable node-oracledb Thick mode
5459
}
55-
oracledb.initOracleClient(clientOpts); // enable node-oracledb Thick mode
5660

5761
async function run() {
5862
let connection;

lib/connection.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ class Connection extends EventEmitter {
8282
//---------------------------------------------------------------------------
8383
_buildDbObjectClass(objType) {
8484
const DbObject = function(initialValue) {
85-
this._impl = new impl.DbObjectImpl();
86-
this._impl._objType = objType;
85+
this._impl = new impl.DbObjectImpl(objType);
8786
if (this.isCollection) {
8887
const proxy = new Proxy(this, BaseDbObject._collectionProxyHandler);
8988
if (initialValue !== undefined) {
@@ -169,6 +168,8 @@ class Connection extends EventEmitter {
169168
// object class has already been built.
170169
//---------------------------------------------------------------------------
171170
_getDbObjectClass(objType) {
171+
if (objType.prototype instanceof BaseDbObject)
172+
return objType;
172173
let cls = this._dbObjectClasses.get(objType);
173174
if (!cls) {
174175
cls = this._buildDbObjectClass(objType);

lib/dbObject.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class BaseDbObject {
140140
//---------------------------------------------------------------------------
141141
get attributes() {
142142
if (!this._attributes) {
143-
const implAttrs = this._objType.attributes;
143+
const implAttrs = this._objType.attributes || [];
144144
const attrs = {};
145145
for (let i = 0; i < implAttrs.length; i++) {
146146
const implAttr = implAttrs[i];

lib/errors.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ const ERR_CALL_TIMEOUT_EXCEEDED = 123;
126126
const ERR_EMPTY_CONNECTION_STRING = 125;
127127
const ERR_OSON_VERSION_NOT_SUPPORTED = 126;
128128
const ERR_UNKOWN_SERVER_SIDE_PIGGYBACK = 127;
129+
const ERR_UNKNOWN_COLUMN_TYPE_NAME = 128;
130+
const ERR_INVALID_OBJECT_TYPE_NAME = 129;
131+
const ERR_TDS_TYPE_NOT_SUPPORTED = 130;
132+
const ERR_INVALID_COLL_INDEX_SET = 131;
133+
const ERR_INVALID_COLL_INDEX_GET = 132;
134+
const ERR_DELETE_ELEMENTS_OF_VARRAY = 133;
129135

130136
// Oracle Net layer errors start from 500
131137
const ERR_CONNECTION_CLOSED = 500;
@@ -153,12 +159,16 @@ const ERR_CONNECTION_EOF = 521;
153159
// define mapping for ODPI-C errors that need to be wrapped with NJS errors
154160
const adjustErrorXref = new Map();
155161
adjustErrorXref.set("DPI-1010", ERR_CONNECTION_CLOSED);
162+
adjustErrorXref.set("DPI-1024", [ERR_INVALID_COLL_INDEX_GET, 'at index ([0-9]+) does']);
156163
adjustErrorXref.set("DPI-1040", ERR_LOB_CLOSED);
157164
adjustErrorXref.set("DPI-1044", ERR_ORACLE_NUMBER_NO_REPR);
158165
adjustErrorXref.set("DPI-1055", ERR_NAN_VALUE);
159166
adjustErrorXref.set("DPI-1063", ERR_EXEC_MODE_ONLY_FOR_DML);
160167
adjustErrorXref.set("DPI-1067", [ERR_CALL_TIMEOUT_EXCEEDED, "call timeout of ([0-9]+) ms"]);
161168
adjustErrorXref.set("DPI-1080", ERR_CONNECTION_CLOSED);
169+
adjustErrorXref.set("OCI-22303", [ERR_INVALID_OBJECT_TYPE_NAME, 'type "([^"]*"."[^"]*)"']);
170+
adjustErrorXref.set("OCI-22164", ERR_DELETE_ELEMENTS_OF_VARRAY);
171+
adjustErrorXref.set("OCI-22165", [ERR_INVALID_COLL_INDEX_SET, /index \[([0-9]+)\] must be in the range of \[([0-9]+)\] to \[([0-9]+)\]/]);
162172
adjustErrorXref.set("ORA-00028", ERR_CONNECTION_CLOSED);
163173
adjustErrorXref.set("ORA-00600", ERR_CONNECTION_CLOSED);
164174
adjustErrorXref.set("ORA-24338", ERR_INVALID_REF_CURSOR);
@@ -359,6 +369,18 @@ messages.set(ERR_OSON_VERSION_NOT_SUPPORTED, // NJS-126
359369
'OSON version %s is not supported');
360370
messages.set(ERR_UNKOWN_SERVER_SIDE_PIGGYBACK, // NJS-127
361371
'internal error: unknown server side piggyback opcode %s');
372+
messages.set(ERR_UNKNOWN_COLUMN_TYPE_NAME, // NJS-128
373+
'internal error: unknown column type name "%s"');
374+
messages.set(ERR_INVALID_OBJECT_TYPE_NAME, // NJS-129
375+
'invalid object type name: "%s"');
376+
messages.set(ERR_TDS_TYPE_NOT_SUPPORTED, // NJS-130
377+
'Oracle TDS data type %d is not supported');
378+
messages.set(ERR_INVALID_COLL_INDEX_SET, // NJS-131
379+
'given index %d must be in the range of %d to %d');
380+
messages.set(ERR_INVALID_COLL_INDEX_GET, // NJS-132
381+
'element at index %d does not exist');
382+
messages.set(ERR_DELETE_ELEMENTS_OF_VARRAY, // NJS-133
383+
'cannot delete elements of a VARRAY');
362384

363385
// Oracle Net layer errors
364386

@@ -719,6 +741,12 @@ module.exports = {
719741
ERR_CALL_TIMEOUT_EXCEEDED,
720742
ERR_EMPTY_CONNECTION_STRING,
721743
ERR_UNKOWN_SERVER_SIDE_PIGGYBACK,
744+
ERR_UNKNOWN_COLUMN_TYPE_NAME,
745+
ERR_INVALID_OBJECT_TYPE_NAME,
746+
ERR_TDS_TYPE_NOT_SUPPORTED,
747+
ERR_INVALID_COLL_INDEX_SET,
748+
ERR_INVALID_COLL_INDEX_GET,
749+
ERR_DELETE_ELEMENTS_OF_VARRAY,
722750
ERR_CONNECTION_CLOSED_CODE: `${ERR_PREFIX}-${ERR_CONNECTION_CLOSED}`,
723751
assert,
724752
assertArgCount,

lib/impl/connection.js

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,34 @@ class ConnectionImpl {
7272
// _getDbObjectType()
7373
//
7474
// Return the object identifying the object type. These are cached by fully
75-
// qualified name.
76-
// ---------------------------------------------------------------------------
77-
_getDbObjectType(schema, name) {
78-
const fqn = `${schema}.${name}`;
79-
let dbObjectType = this._dbObjectTypes.get(fqn);
75+
// qualified name and by OID (thin mode only).
76+
//---------------------------------------------------------------------------
77+
_getDbObjectType(schema, name, packageName, oid) {
78+
let dbObjectType;
79+
if (oid) {
80+
dbObjectType = this._dbObjectTypes.get(oid);
81+
if (dbObjectType)
82+
return dbObjectType;
83+
}
84+
const fqn = (packageName) ? `${schema}.${packageName}.${name}` :
85+
`${schema}.${name}`;
86+
dbObjectType = this._dbObjectTypes.get(fqn);
8087
if (!dbObjectType) {
81-
dbObjectType = {schema: schema, name: name, fqn: fqn};
88+
dbObjectType = {
89+
oid: oid,
90+
fqn: fqn,
91+
schema: schema,
92+
name: name,
93+
packageName: packageName,
94+
partial: true,
95+
isXmlType: (schema === 'SYS' && name === 'XMLTYPE')
96+
};
8297
this._dbObjectTypes.set(fqn, dbObjectType);
8398
}
99+
if (oid && !dbObjectType.oid) {
100+
dbObjectType.oid = oid;
101+
this._dbObjectTypes.set(oid, dbObjectType);
102+
}
84103
return dbObjectType;
85104
}
86105

lib/impl/dbObject.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ const errors = require('../errors.js');
3333
// instantiated; a cache of these classes are maintained on each connection
3434
class DbObjectImpl {
3535

36+
constructor(objType) {
37+
this._objType = objType;
38+
}
39+
3640
//---------------------------------------------------------------------------
3741
// append()
3842
//

0 commit comments

Comments
 (0)