|
2 | 2 | # Editioning.py |
3 | 3 | # This script demonstrates the use of editioning, available in Oracle |
4 | 4 | # 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. |
8 | 7 | #------------------------------------------------------------------------------ |
9 | 8 |
|
10 | 9 | from __future__ import print_function |
|
14 | 13 | # define constants used throughout the script; adjust as desired |
15 | 14 | USER_NAME = "CX_ORACLE_TESTEDITIONS" |
16 | 15 | PASSWORD = "dev" |
| 16 | +DBA_USER_NAME = "system" |
| 17 | +DBA_PASSWORD = "" |
| 18 | +DSN = "" |
17 | 19 | EDITION_NAME = "CX_ORACLE_E1" |
18 | 20 |
|
19 | 21 | # 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) |
21 | 23 | cursor = connection.cursor() |
22 | 24 | cursor.execute(""" |
23 | 25 | select username |
|
48 | 50 | cursor.execute("grant use on edition %s to %s" % (EDITION_NAME, USER_NAME)) |
49 | 51 |
|
50 | 52 | # 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) |
53 | 54 | print("Edition should be None at this point, actual value is", |
54 | 55 | connection.edition) |
55 | 56 | cursor = connection.cursor() |
|
80 | 81 | print("Function call should return Base Edition, actually returns", result) |
81 | 82 |
|
82 | 83 | # 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) |
84 | 86 | cursor = connection.cursor() |
85 | 87 | result = cursor.callfunc("TestEditions", str) |
86 | 88 | print("Function call should return Edition 1, actually returns", result) |
87 | 89 |
|
88 | 90 | # it can also be set via the environment variable ORA_EDITION |
89 | 91 | os.environ["ORA_EDITION"] = EDITION_NAME |
90 | | -connection = cx_Oracle.Connection(connectString) |
| 92 | +connection = cx_Oracle.Connection(USER_NAME, PASSWORD, DSN) |
91 | 93 | print("Edition should be %s at this point, actual value is" % EDITION_NAME, |
92 | 94 | connection.edition) |
93 | 95 | cursor = connection.cursor() |
|
0 commit comments