|
20 | 20 | from __future__ import print_function |
21 | 21 |
|
22 | 22 | import cx_Oracle |
| 23 | +import SampleEnv |
23 | 24 |
|
24 | | -# define constants used throughout the script; adjust as desired |
25 | | -USER_NAME = "CX_ORACLE_TESTEDITIONS" |
26 | | -PASSWORD = "dev" |
27 | | -DBA_USER_NAME = "system" |
28 | | -DBA_PASSWORD = "" |
29 | | -DSN = "" |
30 | | -EDITION_NAME = "CX_ORACLE_E1" |
31 | | - |
32 | | -# create user dropping it first, if necessary |
33 | | -connection = cx_Oracle.Connection(DBA_USER_NAME, DBA_PASSWORD, DSN) |
34 | | -cursor = connection.cursor() |
35 | | -cursor.execute(""" |
36 | | - select username |
37 | | - from dba_users |
38 | | - where username = :name""", |
39 | | - name = USER_NAME) |
40 | | -names = [n for n, in cursor] |
41 | | -for name in names: |
42 | | - print("Dropping user", name) |
43 | | - cursor.execute("drop user %s cascade" % name) |
44 | | -print("Creating user", USER_NAME) |
45 | | -cursor.execute("create user %s identified by %s" % (USER_NAME, PASSWORD)) |
46 | | -cursor.execute("grant create session, create procedure to %s" % USER_NAME) |
47 | | -cursor.execute("alter user %s enable editions" % USER_NAME) |
48 | | - |
49 | | -# create edition, dropping it first, if necessary |
50 | | -cursor.execute(""" |
51 | | - select edition_name |
52 | | - from dba_editions |
53 | | - where edition_name = :name""", |
54 | | - name = EDITION_NAME) |
55 | | -names = [n for n, in cursor] |
56 | | -for name in names: |
57 | | - print("Dropping edition", name) |
58 | | - cursor.execute("drop edition %s" % name) |
59 | | -print("Creating edition", EDITION_NAME) |
60 | | -cursor.execute("create edition %s" % EDITION_NAME) |
61 | | -cursor.execute("grant use on edition %s to %s" % (EDITION_NAME, USER_NAME)) |
62 | | - |
63 | | -# now connect to the newly created user and create a procedure |
64 | | -connection = cx_Oracle.Connection(USER_NAME, PASSWORD, DSN) |
| 25 | +# connect to the editions user and create a procedure |
| 26 | +connection = cx_Oracle.Connection(SampleEnv.EDITION_CONNECT_STRING) |
65 | 27 | print("Edition should be None at this point, actual value is", |
66 | 28 | connection.edition) |
67 | 29 | cursor = connection.cursor() |
|
74 | 36 | print("Function call should return Base Edition, actually returns", result) |
75 | 37 |
|
76 | 38 | # next, change the edition and recreate the procedure in the new edition |
77 | | -cursor.execute("alter session set edition = %s" % EDITION_NAME) |
78 | | -print("Edition should be %s at this point, actual value is" % EDITION_NAME, |
79 | | - connection.edition) |
| 39 | +cursor.execute("alter session set edition = %s" % SampleEnv.EDITION_NAME) |
| 40 | +print("Edition should be %s at this point, actual value is" % \ |
| 41 | + SampleEnv.EDITION_NAME.upper(), connection.edition) |
80 | 42 | cursor.execute(""" |
81 | 43 | create or replace function TestEditions return varchar2 as |
82 | 44 | begin |
|
92 | 54 | print("Function call should return Base Edition, actually returns", result) |
93 | 55 |
|
94 | 56 | # the edition can be set upon connection |
95 | | -connection = cx_Oracle.Connection(USER_NAME, PASSWORD, DSN, |
96 | | - edition = EDITION_NAME) |
| 57 | +connection = cx_Oracle.Connection(SampleEnv.EDITION_CONNECT_STRING, |
| 58 | + edition = SampleEnv.EDITION_NAME.upper()) |
97 | 59 | cursor = connection.cursor() |
98 | 60 | result = cursor.callfunc("TestEditions", str) |
99 | 61 | print("Function call should return Edition 1, actually returns", result) |
100 | 62 |
|
101 | 63 | # it can also be set via the environment variable ORA_EDITION |
102 | | -os.environ["ORA_EDITION"] = EDITION_NAME |
103 | | -connection = cx_Oracle.Connection(USER_NAME, PASSWORD, DSN) |
104 | | -print("Edition should be %s at this point, actual value is" % EDITION_NAME, |
105 | | - connection.edition) |
| 64 | +os.environ["ORA_EDITION"] = SampleEnv.EDITION_NAME.upper() |
| 65 | +connection = cx_Oracle.Connection(SampleEnv.EDITION_CONNECT_STRING) |
| 66 | +print("Edition should be %s at this point, actual value is" % \ |
| 67 | + SampleEnv.EDITION_NAME.upper(), connection.edition) |
106 | 68 | cursor = connection.cursor() |
107 | 69 | result = cursor.callfunc("TestEditions", str) |
108 | 70 | print("Function call should return Edition 1, actually returns", result) |
|
0 commit comments