Skip to content

Commit aa596a1

Browse files
Merge pull request oracle-samples#153 from cjbj/scriptingexamples
Updated Python & Node.js examples for cx_Oracle 8.2 and node-oracledb 5.2
2 parents c47743c + 62a2060 commit aa596a1

File tree

128 files changed

+2207
-1047
lines changed

Some content is hidden

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

128 files changed

+2207
-1047
lines changed

javascript/node-oracledb/README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
# Node-oracledb Examples
22

3-
This directory contains [node-oracledb](https://www.npmjs.com/package/oracledb) examples.
3+
This directory contains [node-oracledb](https://www.npmjs.com/package/oracledb)
4+
examples. Documentation is [here
5+
](https://oracle.github.io/node-oracledb/doc/api.html).
46

57
To run the examples:
68

79
- [Install node-oracledb](https://oracle.github.io/node-oracledb/INSTALL.html#quickstart).
810

9-
10-
- Edit `dbconfig.js` and set your username, password and the database
11-
connection string, for example:
11+
- Edit `dbconfig.js` and set your username and the database connection string,
12+
for example:
1213

1314
```
1415
module.exports = {
@@ -19,9 +20,8 @@ connection string, for example:
1920
2021
```
2122

22-
This reads the password from the environment variable
23-
`NODE_ORACLEDB_PASSWORD`, which you must set before running
24-
examples.
23+
- In a terminal window, set the environment variable `NODE_ORACLEDB_PASSWORD` to
24+
the value of your database password.
2525

2626
- Review the samples and then run them like:
2727

@@ -58,8 +58,7 @@ File Name | Description
5858
[`dbmsoutputpipe.js`](dbmsoutputpipe.js) | Show fetching DBMS_OUTPUT by using a pipelined table
5959
[`demodrop.js`](demodrop.js) | Drops the schema objects created by the examples
6060
[`demosetup.js`](demosetup.js) | Used to create common schema objects for the examples
61-
[`dmlrupd1.js`](dmlrupd1.js) | Example of DML RETURNING with a single row match
62-
[`dmlrupd2.js`](dmlrupd2.js) | Example of DML RETURNING where multiple rows are matched
61+
[`dmlrupd.js`](dmlrupd.js) | Example of DML RETURNING where multiple rows are matched
6362
[`em_batcherrors.js`](em_batcherrors.js) | `executeMany()` example showing handling data errors
6463
[`em_dmlreturn1.js`](em_dmlreturn1.js) | `executeMany()` example of DML RETURNING that returns single values
6564
[`em_dmlreturn2.js`](em_dmlreturn2.js) | `executeMany()` example of DML RETURNING that returns multiple values
@@ -73,6 +72,7 @@ File Name | Description
7372
[`impres.js`](impres.js) | Shows PL/SQL 'Implict Results' returning multiple query results from PL/SQL code.
7473
[`insert1.js`](insert1.js) | Basic example creating a table and inserting data. Shows DDL and DML
7574
[`insert2.js`](insert2.js) | Basic example showing auto commit behavior
75+
[`lastinsertid.js`](lastinsertid.js) | Shows inserting a row and getting its ROWID.
7676
[`lobbinds.js`](lobbinds.js) | Demonstrates how to bind and query LOBs
7777
[`lobinsert1.js`](lobinsert1.js) | Shows inserting a file into a CLOB column
7878
[`lobinsert2.js`](lobinsert2.js) | Inserts text into a CLOB column using the RETURNING INTO method.
@@ -97,7 +97,7 @@ File Name | Description
9797
[`select1.js`](select1.js) | Executes a basic query without using a connection pool or ResultSet
9898
[`select2.js`](select2.js) | Executes queries to show array and object output formats
9999
[`selectgeometry.js`](selectgeometry.js) | Insert and query Oracle Spatial geometries
100-
[`selectjson.js`](selectjson.js) | Shows some JSON features of Oracle Database
100+
[`selectjson.js`](selectjson.js) | Shows some JSON features of Oracle Database 21c
101101
[`selectjsonblob.js`](selectjsonblob.js) | Shows how to use a BLOB as a JSON column store
102102
[`selectobject.js`](selectobject.js) | Insert and query a named Oracle database object
103103
[`selectnestedcursor.js`](selectnestedcursor.js) | Shows selecting from a nested cursor
@@ -108,4 +108,4 @@ File Name | Description
108108
[`sessiontagging2.js`](sessiontagging2.js) | More complex example of pooled connection tagging for setting session state
109109
[`soda1.js`](soda1.js) | Basic Simple Oracle Document Access (SODA) example
110110
[`version.js`](version.js) | Shows the node-oracledb version attributes
111-
[`webappawait.js`](webappawait.js) | A simple web application using a connection pool
111+
[`webapp.js`](webapp.js) | A simple web application using a connection pool

javascript/node-oracledb/aqmulti.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. */
1+
/* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved. */
22

33
/******************************************************************************
44
*
@@ -33,6 +33,17 @@
3333
const oracledb = require('oracledb');
3434
const dbConfig = require('./dbconfig.js');
3535

36+
// On Windows and macOS, you can specify the directory containing the Oracle
37+
// Client Libraries at runtime, or before Node.js starts. On other platforms
38+
// the system library search path must always be set before Node.js is started.
39+
// See the node-oracledb installation documentation.
40+
// If the search path is not correct, you will get a DPI-1047 error.
41+
if (process.platform === 'win32') { // Windows
42+
oracledb.initOracleClient({ libDir: 'C:\\oracle\\instantclient_19_11' });
43+
} else if (process.platform === 'darwin') { // macOS
44+
oracledb.initOracleClient({ libDir: process.env.HOME + '/Downloads/instantclient_19_8' });
45+
}
46+
3647
const queueName = "DEMO_RAW_QUEUE";
3748

3849
async function enq() {

javascript/node-oracledb/aqobject.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. */
1+
/* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved. */
22

33
/******************************************************************************
44
*
@@ -34,6 +34,17 @@
3434
const oracledb = require('oracledb');
3535
const dbConfig = require('./dbconfig.js');
3636

37+
// On Windows and macOS, you can specify the directory containing the Oracle
38+
// Client Libraries at runtime, or before Node.js starts. On other platforms
39+
// the system library search path must always be set before Node.js is started.
40+
// See the node-oracledb installation documentation.
41+
// If the search path is not correct, you will get a DPI-1047 error.
42+
if (process.platform === 'win32') { // Windows
43+
oracledb.initOracleClient({ libDir: 'C:\\oracle\\instantclient_19_11' });
44+
} else if (process.platform === 'darwin') { // macOS
45+
oracledb.initOracleClient({ libDir: process.env.HOME + '/Downloads/instantclient_19_8' });
46+
}
47+
3748
const queueName = "ADDR_QUEUE";
3849

3950
async function enq() {

javascript/node-oracledb/aqoptions.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. */
1+
/* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved. */
22

33
/******************************************************************************
44
*
@@ -33,6 +33,17 @@
3333
const oracledb = require('oracledb');
3434
const dbConfig = require('./dbconfig.js');
3535

36+
// On Windows and macOS, you can specify the directory containing the Oracle
37+
// Client Libraries at runtime, or before Node.js starts. On other platforms
38+
// the system library search path must always be set before Node.js is started.
39+
// See the node-oracledb installation documentation.
40+
// If the search path is not correct, you will get a DPI-1047 error.
41+
if (process.platform === 'win32') { // Windows
42+
oracledb.initOracleClient({ libDir: 'C:\\oracle\\instantclient_19_11' });
43+
} else if (process.platform === 'darwin') { // macOS
44+
oracledb.initOracleClient({ libDir: process.env.HOME + '/Downloads/instantclient_19_8' });
45+
}
46+
3647
const queueName = "DEMO_RAW_QUEUE";
3748

3849
async function enq() {

javascript/node-oracledb/aqraw.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. */
1+
/* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved. */
22

33
/******************************************************************************
44
*
@@ -33,6 +33,17 @@
3333
const oracledb = require('oracledb');
3434
const dbConfig = require('./dbconfig.js');
3535

36+
// On Windows and macOS, you can specify the directory containing the Oracle
37+
// Client Libraries at runtime, or before Node.js starts. On other platforms
38+
// the system library search path must always be set before Node.js is started.
39+
// See the node-oracledb installation documentation.
40+
// If the search path is not correct, you will get a DPI-1047 error.
41+
if (process.platform === 'win32') { // Windows
42+
oracledb.initOracleClient({ libDir: 'C:\\oracle\\instantclient_19_11' });
43+
} else if (process.platform === 'darwin') { // macOS
44+
oracledb.initOracleClient({ libDir: process.env.HOME + '/Downloads/instantclient_19_8' });
45+
}
46+
3647
const queueName = "DEMO_RAW_QUEUE";
3748

3849
async function enq() {

javascript/node-oracledb/blobhttp.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved. */
1+
/* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved. */
22

33
/******************************************************************************
44
*
@@ -35,6 +35,17 @@ const oracledb = require('oracledb');
3535
const dbConfig = require('./dbconfig.js');
3636
const demoSetup = require('./demosetup.js');
3737

38+
// On Windows and macOS, you can specify the directory containing the Oracle
39+
// Client Libraries at runtime, or before Node.js starts. On other platforms
40+
// the system library search path must always be set before Node.js is started.
41+
// See the node-oracledb installation documentation.
42+
// If the search path is not correct, you will get a DPI-1047 error.
43+
if (process.platform === 'win32') { // Windows
44+
oracledb.initOracleClient({ libDir: 'C:\\oracle\\instantclient_19_11' });
45+
} else if (process.platform === 'darwin') { // macOS
46+
oracledb.initOracleClient({ libDir: process.env.HOME + '/Downloads/instantclient_19_8' });
47+
}
48+
3849
const httpPort = 7000;
3950

4051
// Main entry point. Creates a connection pool which becomes the
@@ -140,7 +151,7 @@ async function closePoolAndExit() {
140151
await oracledb.getPool().close(2);
141152
console.log('Pool closed');
142153
process.exit(0);
143-
} catch(err) {
154+
} catch (err) {
144155
console.error(err.message);
145156
process.exit(1);
146157
}

javascript/node-oracledb/calltimeout.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. */
1+
/* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved. */
22

33
/******************************************************************************
44
*
@@ -32,6 +32,17 @@
3232
const oracledb = require("oracledb");
3333
const dbConfig = require('./dbconfig.js');
3434

35+
// On Windows and macOS, you can specify the directory containing the Oracle
36+
// Client Libraries at runtime, or before Node.js starts. On other platforms
37+
// the system library search path must always be set before Node.js is started.
38+
// See the node-oracledb installation documentation.
39+
// If the search path is not correct, you will get a DPI-1047 error.
40+
if (process.platform === 'win32') { // Windows
41+
oracledb.initOracleClient({ libDir: 'C:\\oracle\\instantclient_19_11' });
42+
} else if (process.platform === 'darwin') { // macOS
43+
oracledb.initOracleClient({ libDir: process.env.HOME + '/Downloads/instantclient_19_8' });
44+
}
45+
3546
const dboptime = 4; // seconds the simulated database operation will take
3647
const timeout = 2; // seconds the application will wait for the database operation
3748

javascript/node-oracledb/connect.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. */
1+
/* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved. */
22

33
/******************************************************************************
44
*
@@ -33,6 +33,17 @@
3333
const oracledb = require('oracledb');
3434
const dbConfig = require('./dbconfig.js');
3535

36+
// On Windows and macOS, you can specify the directory containing the Oracle
37+
// Client Libraries at runtime, or before Node.js starts. On other platforms
38+
// the system library search path must always be set before Node.js is started.
39+
// See the node-oracledb installation documentation.
40+
// If the search path is not correct, you will get a DPI-1047 error.
41+
if (process.platform === 'win32') { // Windows
42+
oracledb.initOracleClient({ libDir: 'C:\\oracle\\instantclient_19_11' });
43+
} else if (process.platform === 'darwin') { // macOS
44+
oracledb.initOracleClient({ libDir: process.env.HOME + '/Downloads/instantclient_19_8' });
45+
}
46+
3647
async function run() {
3748

3849
let connection;

javascript/node-oracledb/connectionpool.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved. */
1+
/* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved. */
22

33
/******************************************************************************
44
*
@@ -22,7 +22,7 @@
2222
* Shows connection pool usage. Connection pools are recommended
2323
* for applications that use a lot of connections for short periods.
2424
*
25-
* Other connection pool examples are in sessionfixup.js and webappawait.js.
25+
* Other connection pool examples are in sessionfixup.js and webapp.js.
2626
* For a standalone connection example, see connect.js
2727
*
2828
* In some networks forced pool termination may hang unless you have
@@ -38,11 +38,24 @@
3838
// If you increase poolMax, you must increase UV_THREADPOOL_SIZE before Node.js
3939
// starts its thread pool. If you set UV_THREADPOOL_SIZE too late, the value is
4040
// ignored and the default size of 4 is used.
41+
// Note on Windows you must set the UV_THREADPOOL_SIZE environment variable before
42+
// running your application.
4143
// process.env.UV_THREADPOOL_SIZE = 4;
4244

4345
const oracledb = require('oracledb');
4446
const dbConfig = require('./dbconfig.js');
4547

48+
// On Windows and macOS, you can specify the directory containing the Oracle
49+
// Client Libraries at runtime, or before Node.js starts. On other platforms
50+
// the system library search path must always be set before Node.js is started.
51+
// See the node-oracledb installation documentation.
52+
// If the search path is not correct, you will get a DPI-1047 error.
53+
if (process.platform === 'win32') { // Windows
54+
oracledb.initOracleClient({ libDir: 'C:\\oracle\\instantclient_19_11' });
55+
} else if (process.platform === 'darwin') { // macOS
56+
oracledb.initOracleClient({ libDir: process.env.HOME + '/Downloads/instantclient_19_8' });
57+
}
58+
4659
async function init() {
4760
try {
4861
// Create a connection pool which will later be accessed via the
@@ -64,8 +77,9 @@ async function init() {
6477
// queueMax: 500, // don't allow more than 500 unsatisfied getConnection() calls in the pool queue
6578
// queueTimeout: 60000, // terminate getConnection() calls queued for longer than 60000 milliseconds
6679
// sessionCallback: myFunction, // function invoked for brand new connections or by a connection tag mismatch
80+
// sodaMetaDataCache: false, // Set true to improve SODA collection access performance
6781
// stmtCacheSize: 30, // number of statements that are cached in the statement cache of each connection
68-
// _enableStats: false // record pool usage statistics that can be output with pool._logStats()
82+
// enableStatistics: false // record pool usage for oracledb.getPool().getStatistics() and logStatistics()
6983
});
7084
console.log('Connection pool started');
7185

@@ -89,7 +103,7 @@ async function dostuff() {
89103
const options = { outFormat: oracledb.OUT_FORMAT_OBJECT };
90104
const result = await connection.execute(sql, binds, options);
91105
console.log(result);
92-
// oracledb.getPool()._logStats(); // show pool statistics. _enableStats must be true
106+
// oracledb.getPool().logStatistics(); // show pool statistics. pool.enableStatistics must be true
93107
} catch (err) {
94108
console.error(err);
95109
} finally {
@@ -115,7 +129,7 @@ async function closePoolAndExit() {
115129
await oracledb.getPool().close(10);
116130
console.log('Pool closed');
117131
process.exit(0);
118-
} catch(err) {
132+
} catch (err) {
119133
console.error(err.message);
120134
process.exit(1);
121135
}

javascript/node-oracledb/cqn1.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. */
1+
/* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved. */
22

33
/******************************************************************************
44
*
@@ -39,14 +39,24 @@
3939
const oracledb = require("oracledb");
4040
const dbConfig = require('./dbconfig.js');
4141

42+
// On Windows and macOS, you can specify the directory containing the Oracle
43+
// Client Libraries at runtime, or before Node.js starts. On other platforms
44+
// the system library search path must always be set before Node.js is started.
45+
// See the node-oracledb installation documentation.
46+
// If the search path is not correct, you will get a DPI-1047 error.
47+
if (process.platform === 'win32') { // Windows
48+
oracledb.initOracleClient({ libDir: 'C:\\oracle\\instantclient_19_11' });
49+
} else if (process.platform === 'darwin') { // macOS
50+
oracledb.initOracleClient({ libDir: process.env.HOME + '/Downloads/instantclient_19_8' });
51+
}
52+
4253
dbConfig.events = true; // CQN needs events mode
4354

4455
const interval = setInterval(function() {
4556
console.log("waiting...");
4657
}, 5000);
4758

48-
function myCallback(message)
49-
{
59+
function myCallback(message) {
5060
// message.type is one of the oracledb.SUBSCR_EVENT_TYPE_* values
5161
console.log("Message type:", message.type);
5262
if (message.type == oracledb.SUBSCR_EVENT_TYPE_DEREG) {
@@ -100,7 +110,7 @@ async function setup(connection) {
100110
for (const s of stmts) {
101111
try {
102112
await connection.execute(s);
103-
} catch(e) {
113+
} catch (e) {
104114
if (e.errorNum != 942)
105115
console.error(e);
106116
}

0 commit comments

Comments
 (0)