Skip to content

Commit c52f1d3

Browse files
Adjust sample so that it can be run without SYSDBA and from a remote client.
1 parent cefcf25 commit c52f1d3

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

samples/Editioning.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
# Editioning.py
33
# This script demonstrates the use of editioning, available in Oracle
44
# Database 11.2 and higher. See the Oracle documentation on the subject for
5-
# additional information. This script makes use of SYSDBA but can be adjusted
6-
# to make use of any user that has the ability to create users. It creates the
7-
# user and edition noted in the constants at the top of the script.
5+
# additional information. Adjust the contants at the top of the script for
6+
# your own database as needed.
87
#------------------------------------------------------------------------------
98

109
from __future__ import print_function
@@ -14,10 +13,13 @@
1413
# define constants used throughout the script; adjust as desired
1514
USER_NAME = "CX_ORACLE_TESTEDITIONS"
1615
PASSWORD = "dev"
16+
DBA_USER_NAME = "system"
17+
DBA_PASSWORD = ""
18+
DSN = ""
1719
EDITION_NAME = "CX_ORACLE_E1"
1820

1921
# create user dropping it first, if necessary
20-
connection = cx_Oracle.Connection(mode = cx_Oracle.SYSDBA)
22+
connection = cx_Oracle.Connection(DBA_USER_NAME, DBA_PASSWORD, DSN)
2123
cursor = connection.cursor()
2224
cursor.execute("""
2325
select username
@@ -48,8 +50,7 @@
4850
cursor.execute("grant use on edition %s to %s" % (EDITION_NAME, USER_NAME))
4951

5052
# now connect to the newly created user and create a procedure
51-
connectString = "%s/%s" % (USER_NAME, PASSWORD)
52-
connection = cx_Oracle.Connection(connectString)
53+
connection = cx_Oracle.Connection(USER_NAME, PASSWORD, DSN)
5354
print("Edition should be None at this point, actual value is",
5455
connection.edition)
5556
cursor = connection.cursor()
@@ -80,14 +81,15 @@
8081
print("Function call should return Base Edition, actually returns", result)
8182

8283
# the edition can be set upon connection
83-
connection = cx_Oracle.Connection(connectString, edition = EDITION_NAME)
84+
connection = cx_Oracle.Connection(USER_NAME, PASSWORD, DSN,
85+
edition = EDITION_NAME)
8486
cursor = connection.cursor()
8587
result = cursor.callfunc("TestEditions", str)
8688
print("Function call should return Edition 1, actually returns", result)
8789

8890
# it can also be set via the environment variable ORA_EDITION
8991
os.environ["ORA_EDITION"] = EDITION_NAME
90-
connection = cx_Oracle.Connection(connectString)
92+
connection = cx_Oracle.Connection(USER_NAME, PASSWORD, DSN)
9193
print("Edition should be %s at this point, actual value is" % EDITION_NAME,
9294
connection.edition)
9395
cursor = connection.cursor()

0 commit comments

Comments
 (0)