Skip to content

Commit 3fb231b

Browse files
Update tutorial.
1 parent 6b86d9b commit 3fb231b

39 files changed

+2610
-902
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ repos:
1414
rev: v0.0.291
1515
hooks:
1616
- id: ruff
17+
exclude: ^samples/

samples/tutorial/Python-and-Oracle-Database-The-New-Wave-of-Scripting.html

Lines changed: 1926 additions & 831 deletions
Large diffs are not rendered by default.

samples/tutorial/aq.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# -----------------------------------------------------------------------------
44

55
# -----------------------------------------------------------------------------
6-
# Copyright (c) 2017, 2023, Oracle and/or its affiliates.
6+
# Copyright (c) 2017, 2025, Oracle and/or its affiliates.
77
#
88
# This software is dual-licensed to you under the Universal Permissive License
99
# (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
@@ -28,7 +28,7 @@
2828

2929
import oracledb
3030
import decimal
31-
import db_config_thick as db_config
31+
import db_config
3232

3333
con = oracledb.connect(
3434
user=db_config.user, password=db_config.pw, dsn=db_config.dsn

samples/tutorial/async_gather.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# -----------------------------------------------------------------------------
2+
# async_gather.py (Section 17.1)
3+
# -----------------------------------------------------------------------------
4+
5+
# -----------------------------------------------------------------------------
6+
# Copyright (c) 2025, Oracle and/or its affiliates.
7+
#
8+
# This software is dual-licensed to you under the Universal Permissive License
9+
# (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
10+
# 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose
11+
# either license.
12+
#
13+
# If you elect to accept the software under the Apache License, Version 2.0,
14+
# the following applies:
15+
#
16+
# Licensed under the Apache License, Version 2.0 (the "License");
17+
# you may not use this file except in compliance with the License.
18+
# You may obtain a copy of the License at
19+
#
20+
# https://www.apache.org/licenses/LICENSE-2.0
21+
#
22+
# Unless required by applicable law or agreed to in writing, software
23+
# distributed under the License is distributed on an "AS IS" BASIS,
24+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25+
# See the License for the specific language governing permissions and
26+
# limitations under the License.
27+
# -----------------------------------------------------------------------------
28+
29+
import asyncio
30+
import oracledb
31+
import db_config
32+
33+
# Number of coroutines to run
34+
CONCURRENCY = 5
35+
36+
# Maximum connection pool size
37+
POOLSIZE = 5
38+
39+
# Query the unique session identifier/serial number combination of a connection
40+
SQL = """select unique current_timestamp as ct, sid||'-'||serial# as sidser
41+
from v$session_connect_info
42+
where sid = sys_context('userenv', 'sid')"""
43+
44+
45+
# Show the unique session identifier/serial number of each connection that the
46+
# pool opens
47+
async def init_session(connection, requested_tag):
48+
res = await connection.fetchone(SQL)
49+
print(res[0].strftime("%H:%M:%S.%f"), "- init_session SID-SERIAL#", res[1])
50+
51+
52+
# The coroutine simply shows the session identifier/serial number of the
53+
# connection returned by the pool.acquire() call
54+
async def query(pool):
55+
async with pool.acquire() as connection:
56+
await connection.callproc("dbms_session.sleep", [1])
57+
res = await connection.fetchone(SQL)
58+
print(res[0].strftime("%H:%M:%S.%f"), "- query SID-SERIAL#", res[1])
59+
60+
61+
async def main():
62+
63+
pool = oracledb.create_pool_async(
64+
user=db_config.user,
65+
password=db_config.pw,
66+
dsn=db_config.dsn,
67+
min=1,
68+
max=POOLSIZE,
69+
session_callback=init_session,
70+
)
71+
72+
coroutines = [query(pool) for i in range(CONCURRENCY)]
73+
74+
await asyncio.gather(*coroutines)
75+
76+
await pool.close()
77+
78+
79+
asyncio.run(main())

samples/tutorial/bind_sdo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# -----------------------------------------------------------------------------
44

55
# -----------------------------------------------------------------------------
6-
# Copyright (c) 2017, 2023, Oracle and/or its affiliates.
6+
# Copyright (c) 2017, 2025, Oracle and/or its affiliates.
77
#
88
# This software is dual-licensed to you under the Universal Permissive License
99
# (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
@@ -27,7 +27,7 @@
2727
# -----------------------------------------------------------------------------
2828

2929
import oracledb
30-
import db_config_thick as db_config
30+
import db_config
3131

3232
con = oracledb.connect(
3333
user=db_config.user, password=db_config.pw, dsn=db_config.dsn

samples/tutorial/connect_params2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# -----------------------------------------------------------------------------
44

55
# -----------------------------------------------------------------------------
6-
# Copyright (c) 2017, 2023, Oracle and/or its affiliates.
6+
# Copyright (c) 2017, 2025, Oracle and/or its affiliates.
77
#
88
# This software is dual-licensed to you under the Universal Permissive License
99
# (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
@@ -30,7 +30,7 @@
3030
import db_config
3131

3232
params = oracledb.ConnectParams(
33-
host="localhost", port=1521, service_name="orclpdb"
33+
host="localhost", port=1521, service_name="freepdb1"
3434
)
3535
con = oracledb.connect(
3636
user=db_config.user, password=db_config.pw, params=params

samples/tutorial/create_user.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# -----------------------------------------------------------------------------
44

55
# -----------------------------------------------------------------------------
6-
# Copyright (c) 2022, 2023, Oracle and/or its affiliates.
6+
# Copyright (c) 2022, 2025, Oracle and/or its affiliates.
77
#
88
# This software is dual-licensed to you under the Universal Permissive License
99
# (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
@@ -34,8 +34,8 @@
3434

3535
# default values
3636
PYTHON_USER = "pythondemo"
37-
PYTHON_CONNECT_STRING = "localhost/orclpdb"
38-
PYTHON_DRCP_CONNECT_STRING = "localhost/orclpdb:pooled"
37+
PYTHON_CONNECT_STRING = "localhost/freepdb1"
38+
PYTHON_DRCP_CONNECT_STRING = "localhost/freepdb1:pooled"
3939

4040
# dictionary containing all parameters; these are acquired as needed by the
4141
# methods below (which should be used instead of consulting this dictionary

samples/tutorial/db_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -----------------------------------------------------------------------------
2-
# Copyright (c) 2022, 2023, Oracle and/or its affiliates.
2+
# Copyright (c) 2022, 2025, Oracle and/or its affiliates.
33
#
44
# This software is dual-licensed to you under the Universal Permissive License
55
# (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
@@ -32,7 +32,7 @@
3232

3333
user = os.environ.get("PYTHON_USER", "pythondemo")
3434

35-
dsn = os.environ.get("PYTHON_CONNECT_STRING", "localhost/orclpdb")
35+
dsn = os.environ.get("PYTHON_CONNECT_STRING", "localhost/freepdb1")
3636

3737
pw = os.environ.get("PYTHON_PASSWORD")
3838
if pw is None:

samples/tutorial/db_config_sys.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -----------------------------------------------------------------------------
2-
# Copyright (c) 2022, 2023, Oracle and/or its affiliates.
2+
# Copyright (c) 2022, 2025, Oracle and/or its affiliates.
33
#
44
# This software is dual-licensed to you under the Universal Permissive License
55
# (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
@@ -32,7 +32,7 @@
3232

3333
sysuser = os.environ.get("PYTHON_SYSUSER", "SYSTEM")
3434

35-
dsn = os.environ.get("PYTHON_CONNECT_STRING", "localhost/orclpdb")
35+
dsn = os.environ.get("PYTHON_CONNECT_STRING", "localhost/freepdb1")
3636

3737
syspw = os.environ.get("PYTHON_SYSPASSWORD")
3838
if syspw is None:

samples/tutorial/db_config_thick.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -----------------------------------------------------------------------------
2-
# Copyright (c) 2022, 2023, Oracle and/or its affiliates.
2+
# Copyright (c) 2022, 2025, Oracle and/or its affiliates.
33
#
44
# This software is dual-licensed to you under the Universal Permissive License
55
# (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
@@ -42,7 +42,7 @@
4242
# Client directory. Note the use of the raw string r"..." so backslashes can
4343
# be used as directory separators.
4444
if platform.system() == "Windows":
45-
instant_client_dir = r"C:\Oracle\instantclient_19_14"
45+
instant_client_dir = r"C:\Oracle\instantclient_23_7"
4646

4747
# On macOS set the directory to your Instant Client directory
4848
if platform.system() == "Darwin":
@@ -62,7 +62,7 @@
6262

6363
user = os.environ.get("PYTHON_USER", "pythondemo")
6464

65-
dsn = os.environ.get("PYTHON_CONNECT_STRING", "localhost/orclpdb")
65+
dsn = os.environ.get("PYTHON_CONNECT_STRING", "localhost/freepdb1")
6666

6767
pw = os.environ.get("PYTHON_PASSWORD")
6868
if pw is None:

0 commit comments

Comments
 (0)