Skip to content

Commit 9f3670b

Browse files
committed
ODPI sample updates to use thick driver.
Updated the ODPI samples programs and related files to work with python-oracledb instead of cx-oracle and node-oracledb using the thick driver.
1 parent 45e06f4 commit 9f3670b

File tree

13 files changed

+208
-1452
lines changed

13 files changed

+208
-1452
lines changed

languages/THIRD_PARTY_LICENSES.txt

+164-1,414
Large diffs are not rendered by default.

languages/nodejs/README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2019, 2020 Oracle and/or its affiliates. All rights reserved.
1+
Copyright (c) 2019, 2024 Oracle and/or its affiliates. All rights reserved.
22

33
# TimesTen Node.js Samples
44

@@ -9,9 +9,9 @@ The following table describes the tested operating systems, node-oracledb driver
99

1010
OS | Node.js Version | node-oracledb Driver Version | TimesTen Client Driver | TimesTen Direct Driver
1111
------------- | ------- | ------------- | ------------ | ------
12-
Linux 64-bit | 12.7.0 |4.0.1+ | 18.1.4.1.0+ | 18.1.4.1.0+
13-
macOS | 12.7.0 |4.0.1+ | 18.1.4.1.0+ | N/A
14-
MS Windows 64-bit | 12.7.0 | 4.0.1+ | 18.1.4.1.0+ | N/A
12+
Linux 64-bit | 14+ |6.0+ | 22.1.1.25.0+ | 22.1.1.25.0+
13+
macOS | 14+ |6.0+ | 22.1.1.25.0+ | N/A
14+
MS Windows 64-bit | 14+ | 6.0+ | 22.1.1.25.0+ | N/A
1515

1616
**NOTE**: Access to TimesTen Databases on any supported TimesTen server platforms can be achieved using the TimesTen client driver from any of the platforms listed above. For more information on supported TimesTen platforms, see [TimesTen Release Notes](https://docs.oracle.com/en/database/other-databases/timesten/22.1/release-notes/toc.htm).
1717

languages/nodejs/lobs.js

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
33
*
44
* Licensed under the Universal Permissive License v 1.0 as shown
55
* at http://oss.oracle.com/licenses/upl
@@ -12,6 +12,8 @@
1212
var fs = require('fs');
1313
var oracledb = require('oracledb');
1414
var accessControl = require('./AccessControl');
15+
oracledb.initOracleClient();
16+
oracledb.fetchAsString = [oracledb.CLOB];
1517

1618
// Execute the sample
1719
run(lobSample);
@@ -39,17 +41,16 @@ async function lobSample(conn) {
3941
// Get the LOB for reading
4042
console.log("> Querying CLOB column");
4143
result = await conn.execute("SELECT text FROM clobs where id=1");
42-
let outClob = result.rows[0][0];
44+
// let outClob = result.rows[0][0];
4345

4446
console.log("> Reading CLOB");
45-
await new Promise( (resolve, reject) => {
46-
outClob.on("data", chunk => console.log(chunk.toString()));
47-
outClob.on("error", error => reject(error));
48-
outClob.on("end", () => {
49-
console.log("> Finished reading CLOB");
50-
resolve();
51-
});
52-
} );
47+
if (result.rows.length == 0)
48+
console.error ("No results");
49+
else {
50+
const outClob = result.rows[0][0];
51+
console.log(outClob);
52+
}
53+
console.log("> Finished reading CLOB");
5354
}
5455

5556

languages/nodejs/queriesAndPlsql.js

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
'use strict';
1717
var oracledb = require('oracledb');
1818
var accessControl = require('./AccessControl');
19+
oracledb.initOracleClient();
1920

2021
const NUM_RECORDS = 100; // Number of records to insert
2122

languages/nodejs/simple.js

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
var oracledb = require('oracledb');
1212
var accessControl = require('./AccessControl');
1313

14+
oracledb.initOracleClient();
1415
async function run() {
1516

1617
let connection;

languages/nodejs/sql.js

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
'use strict';
1717
var oracledb = require('oracledb');
1818
var accessControl = require('./AccessControl');
19+
oracledb.initOracleClient();
1920

2021
const NUM_RECORDS = 100; // Number of records to insert. (Must have an exact square root)
2122
const READ_PERCENTAGE = 80; // Percentage of records to perform SELECTS.

languages/python/README.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ Copyright (c) 2019, 2020 Oracle and/or its affiliates. All rights reserved.
22

33
# TimesTen Python Samples
44

5-
This folder contains Python samples that illustrate database connection and operations using the cx_Oracle driver against the TimesTen database.
5+
This folder contains Python samples that illustrate database connection and operations using the python-oracledb driver against the TimesTen database.
66

77
## Software & Platform Support
8-
The following table describes the tested operating systems, cx_Oracle driver and TimesTen software versions.
8+
The following table describes the tested operating systems, python_oracledb driver and TimesTen software versions.
99

10-
OS | Python Version | cx_Oracle Driver Version | TimesTen Client Driver | TimesTen Direct Driver
10+
OS | Python Version | python-oracledb Driver Version | TimesTen Client Driver | TimesTen Direct Driver
1111
------------- | --------- | --------- | ------------| ------
12-
Linux 64-bit | 3.7.5 | 7.2.2+ | 18.1.4.1.0+ | 18.1.4.1.0+
13-
macOS | 3.7.5 |7.2.2+ | 18.1.4.1.0+ | N/A
14-
MS Windows 64-bit | 3.7.5 |7.2.2+ | 18.1.4.1.0+| N/A
12+
Linux 64-bit | 3.7+ | 7.2.2+ | 22.1.1.25.0+ | 22.1.1.25.0+
13+
macOS | 3.7+ |7.2.2+ | 22.1.1.25.0+ | N/A
14+
MS Windows 64-bit | 3.7+ |7.2.2+ | 22.1.1.25.0+| N/A
1515

1616
**NOTE**: Access to TimesTen Databases on any supported TimesTen server platforms can be achieved using the TimesTen client driver from any of the platforms listed above. For more information on supported TimesTen platforms, see [TimesTen Release Notes](https://docs.oracle.com/en/database/other-databases/timesten/22.1/release-notes/toc.htm).
1717

@@ -22,9 +22,9 @@ MS Windows 64-bit | 3.7.5 |7.2.2+ | 18.1.4.1.0+| N/A
2222
## PRE-REQUISITES
2323

2424
1. Python language is installed.
25-
2. The cx_Oracle driver for Python is installed.
25+
2. The python_oracledb for Python is installed.
2626
3. A TimesTen database is created and data source is setup to access that database.
27-
4. Environment to access Python, cx_Oracle driver and TimesTen data source are set up (i.e. the TimesTen environment script ttenv.sh/ttenv.csh has been executed)
27+
4. Environment to access Python, python_oracledb driver and TimesTen data source are set up (i.e. the TimesTen environment script ttenv.sh/ttenv.csh has been executed)
2828

2929
For more information on setup, see [TimesTen In-Memory Database Open Source Languages Support Guide](https://docs.oracle.com/en/database/other-databases/timesten/22.1/open-source-languages/index.html).
3030

@@ -182,4 +182,4 @@ Aliquam erat volutpat. Maecenas porttitor vel sapien non viverra. Sed dignissim
182182

183183

184184
## Documentation
185-
You can find the online documentation for Oracle TimesTen In-Memory Database in the [Documentation Library](https://docs.oracle.com/en/database/other-databases/timesten/). Online documenation for the cx_Oracle driver can be found [here](https://cx-oracle.readthedocs.io/en/latest/).
185+
You can find the online documentation for Oracle TimesTen In-Memory Database in the [Documentation Library](https://docs.oracle.com/en/database/other-databases/timesten/). Online documenation for the python-oracledb driver can be found [here](https://cx-oracle.readthedocs.io/en/latest/).

languages/python/lobs.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
# reading its content.
1010
#
1111

12-
import cx_Oracle
12+
import oracledb
1313
import AccessControl
1414
import os
1515

16+
oracledb.defaults.fetch_lobs = False
1617
def lobSample(cursor):
1718

1819
print("> Creating table with CLOB column")
@@ -34,30 +35,30 @@ def lobSample(cursor):
3435
outClob, = cursor.fetchone()
3536

3637
print("> Reading CLOB")
37-
print(outClob.read())
38+
print(outClob)
3839
print("> Finished reading CLOB")
3940

4041

4142
def run():
4243
try:
4344
print("> Connecting")
4445
credentials = AccessControl.getCredentials("lobs.py")
45-
connection = cx_Oracle.connect(credentials.user, credentials.password, credentials.connstr)
46+
connection = oracledb.connect(user=credentials.user, password=credentials.password, dsn=credentials.connstr)
4647
connection.autocommit = True
4748
cursor = connection.cursor()
4849

4950
lobSample(cursor)
5051

5152
except Exception as e:
52-
print("An error ocurred", str(e))
53+
print("An error occurred", str(e))
5354
finally:
5455
if(connection):
5556
try:
5657
cursor.close()
5758
connection.close()
5859
print("> Connection released")
5960
except Exception as e:
60-
print("An error ocurred", str(e))
61+
print("An error occurred", str(e))
6162

6263
# Execute sample
6364
run()

languages/python/queriesAndPlsql.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# - Calls a PL/SQL anonymous block to delete a row
1414
# - Drops the table
1515
#
16-
import cx_Oracle
16+
import oracledb
1717
import AccessControl
1818

1919
NUM_RECORDS = 100 # Number of records to insert.
@@ -68,7 +68,7 @@
6868
# Get connection and cursor.
6969
def connect():
7070
credentials = AccessControl.getCredentials("queriesAndPlsql.py")
71-
connection = cx_Oracle.connect(credentials.user, credentials.password, credentials.connstr)
71+
connection = oracledb.connect(user=credentials.user, password=credentials.password, dsn=credentials.connstr)
7272
connection.autocommit = True
7373
return connection.cursor()
7474

languages/python/simple.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99
#
1010

1111
from __future__ import print_function
12-
import cx_Oracle
12+
import oracledb
1313
import AccessControl
1414

1515
def run():
1616
try:
17+
oracledb.init_oracle_client();
1718
credentials = AccessControl.getCredentials("simple.py")
18-
connection = cx_Oracle.connect(credentials.user, credentials.password, credentials.connstr)
19+
connection = oracledb.connect(user=credentials.user, password=credentials.password, dsn=credentials.connstr)
1920

2021
cursor = connection.cursor()
2122
cursor.execute("""
@@ -36,7 +37,7 @@ def run():
3637

3738
except Exception as e:
3839
# Something went wrong
39-
print("An error ocurred", str(e))
40+
print("An error occurred", str(e))
4041

4142
run()
4243

languages/python/sql.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# - Deletes a number of records (based on 'UPDATE_PERCENTAGE')
1414
# - Drops the table
1515
#
16-
import cx_Oracle
16+
import oracledb
1717
import math
1818
import AccessControl
1919

@@ -52,7 +52,7 @@
5252
# Get connection and cursor.
5353
def connect():
5454
credentials = AccessControl.getCredentials("sql.py")
55-
connection = cx_Oracle.connect(credentials.user, credentials.password, credentials.connstr)
55+
connection = oracledb.connect(user=credentials.user, password=credentials.password, dsn=credentials.connstr)
5656
# Set autocommit to true.
5757
connection.autocommit = True
5858
return connection.cursor()

quickstart/classic/sample_code/odbc/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,15 @@ For the full syntax, use "wiscbm -help".
191191

192192
**updatelob**
193193

194-
This program queries against a Large Binary Object(LOB) and then update the selected LOB field with new value of the same row. PRINT_MEDIA table needs to be provisioned before executing this program.
194+
This program queries against a Large Binary Object(LOB) field and then update the selected LOB field with new value of the same row. PRINT_MEDIA table needs to be provisioned before executing this program.
195195

196196
Example usage:
197197

198198
Default connection string
199199

200200
`updatelob`
201201

202-
For the full syntac, use "updatelob -help".
202+
For the full syntax, use "updatelob -help".
203203

204204

205205
**xlaSimple**

quickstart/classic/sample_code/ttclasses/makefiles/Makefile.linux8664.proto

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ clean:
106106
$(PLAT_SPECIFIC_CLEAN)
107107
108108
$(OBJ_DIR):
109-
$(MD) obj
109+
$(MD) obj
110110
111111
# -----------------------------------------------------------------------------
112112
# build targets

0 commit comments

Comments
 (0)