xref: /PHP-8.2/ext/oci8/tests/edition_2.phpt (revision 93e509fd)
1--TEST--
2Set and check Oracle 11gR2 "edition" attribute
3--EXTENSIONS--
4oci8
5--SKIPIF--
6<?php
7if (getenv('SKIP_REPEAT')) die('skip fails with repeat');
8require(__DIR__."/connect.inc");
9if (strcasecmp($user, "system") && strcasecmp($user, "sys"))
10    die("skip needs to be run as a DBA user");
11if ($test_drcp)
12    die("skip as Output might vary with DRCP");
13preg_match('/.*Release ([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)*/', oci_server_version($c), $matches);
14if (!(isset($matches[0]) &&
15      (($matches[1] == 11 && $matches[2] >= 2) ||
16       ($matches[1] >= 12)
17       ))) {
18        die("skip expected output only valid when using Oracle 11gR2 or greater database server");
19}
20preg_match('/^([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)/', oci_client_version(), $matches);
21if (!(isset($matches[0]) &&
22    (($matches[1] == 11 && $matches[2] >= 2) ||
23     ($matches[1] >= 12)
24     ))) {
25    die("skip test expected to work only with Oracle 11gR2 or greater version of client");
26}
27
28?>
29--FILE--
30<?php
31
32error_reporting(E_ALL ^ E_DEPRECATED);
33
34/* In 11.2, there can only be one child edition.  So this test will
35 * fail to create the necessary editions if a child edition exists
36 * already
37 */
38
39$testuser     = 'testuser_ed_2';  // Used in conn_attr.inc
40$testpassword = 'testuser';
41
42require(__DIR__."/conn_attr.inc");
43
44echo"**Test 1.1 - Default value for  the attribute **************\n";
45get_edit_attr($c);
46
47echo"\n\n**Test 1.2 - Set a value and get the same with different connections *********\n";
48set_edit_attr('MYEDITION');
49
50// With oci_connect, oci_pconnect, oci_new_connect
51$conn1 = get_conn(1);
52get_edit_attr($conn1);
53
54//pconnect
55$conn2 = get_conn(2);
56get_edit_attr($conn2);
57
58//new_connect
59$conn3 = get_conn(3);
60get_edit_attr($conn3);
61
62oci_close($conn1);
63
64// With a oci_pconnect with a different charset.
65$pc1 = oci_pconnect($testuser,$testpassword,$dbase,"utf8");
66get_edit_attr($pc1);
67oci_close($pc1);
68
69
70echo"\n\n**Test 1.3 change the value and verify with existing connections.*********\n";
71set_edit_attr('MYEDITION1');
72get_edit_attr($conn2);
73get_edit_attr($conn3); // Old value
74oci_close($conn2);
75oci_close($conn3);
76
77//open a new connection and get the edition value . This will have the updated value.
78$c3 = get_conn(3); //oci_new_connect()
79get_edit_attr($c3);
80
81$c4 = get_conn(2); //oci_pconnect()
82get_edit_attr($c4);
83
84$c5 = get_conn(1); //oci_connect()
85get_edit_attr($c5);
86
87oci_close($c3);
88oci_close($c4);
89oci_close($c5);
90
91echo "\n\n**Test 1.4 - with different type of values *********\n";
92$values_array = array(123,NULL,'NO EDITION','edition name which has more than thirty chars!!!edition name which has more than thirty chars!!!');
93foreach ($values_array as $val ) {
94    set_edit_attr($val);
95    $c1 = get_conn(1); //oci_connect()
96    if ($c1) {
97        get_edit_attr($c1);
98        oci_close($c1);
99    }
100}
101
102echo "\n\n**Test 1.5 - Negative case with an invalid string value. *********\n";
103$c1 = get_conn(3);
104$r = set_edit_attr($c1);
105
106echo"\n\n**Test 1.6 - Set Multiple times.*****\n";
107set_edit_attr('MYEDITION');
108set_edit_attr('MYEDITION1');
109$c1 = get_conn(1);
110get_edit_attr($c1);
111oci_close($c1);
112
113echo "\n\n**Test 1.7 - Test with ALTER SESSION statement to change the edition *******\n";
114// Set the edition value to MYEDITION. open a conn .get the value.
115// execute the alter system set edition ='MYEDITION' .get the value .
116// set it back to MYEDITION using oci_set_edition. and get the value.
117
118set_edit_attr('MYEDITION');
119$c1 = get_conn(3);
120echo "get the value set to MYEDITION with oci_set_edition\n";
121get_edit_attr($c1);
122
123$alter_stmt = "alter session set edition = MYEDITION1";
124$s = oci_parse($c1,$alter_stmt);
125oci_execute($s);
126oci_commit($c1);
127echo "Get the value set to MYEDITION1 with alter session\n";
128get_edit_attr($c1);
129
130echo " Get the value with a new connection\n";
131$c2 = get_conn(1);
132get_edit_attr($c2);
133
134echo " Set the value back using oci-set_edition\n";
135set_edit_attr('MYEDITION');
136get_edit_attr($c2);
137
138echo " Get the value with a new connection\n";
139$c3 = get_conn(1);
140get_edit_attr($c3);
141
142oci_close($c1);
143oci_close($c2);
144oci_close($c3);
145
146
147echo "\n\n**Test 1.8 - Test setting the attribute with scope ends*******\n";
148set_scope();
149get_scope();
150
151clean_up($c);
152echo "Done\n";
153
154
155function set_scope() {
156    $r = set_edit_attr('MYEDITION1');
157}
158
159function get_scope() {
160    $sc1 = oci_connect($GLOBALS['testuser'],$GLOBALS['testpassword'],$GLOBALS['dbase']);
161    if ($sc1 === false) {
162        $m = oci_error();
163        die("Error:" . $m['message']);
164    }
165    get_edit_attr($sc1);
166    oci_close($sc1);
167}
168?>
169--EXPECTF--
170**Test 1.1 - Default value for  the attribute **************
171The value of current EDITION is ORA$BASE
172
173
174**Test 1.2 - Set a value and get the same with different connections *********
175 The value of edition has been successfully set
176Testing with oci_connect()
177The value of current EDITION is MYEDITION
178Testing with oci_pconnect()
179The value of current EDITION is MYEDITION
180Testing with oci_new_connect()
181The value of current EDITION is MYEDITION
182The value of current EDITION is MYEDITION
183
184
185**Test 1.3 change the value and verify with existing connections.*********
186 The value of edition has been successfully set
187The value of current EDITION is MYEDITION
188The value of current EDITION is MYEDITION
189Testing with oci_new_connect()
190The value of current EDITION is MYEDITION1
191Testing with oci_pconnect()
192The value of current EDITION is MYEDITION1
193Testing with oci_connect()
194The value of current EDITION is MYEDITION1
195
196
197**Test 1.4 - with different type of values *********
198 The value of edition has been successfully set
199Testing with oci_connect()
200
201Warning: oci_connect(): ORA-38801: %s ORA_EDITION in %s on line %d
202 The value of edition has been successfully set
203Testing with oci_connect()
204The value of current EDITION is ORA$BASE
205 The value of edition has been successfully set
206Testing with oci_connect()
207
208Warning: oci_connect(): ORA-38801: %s ORA_EDITION in %s on line %d
209 The value of edition has been successfully set
210Testing with oci_connect()
211
212Warning: oci_connect(): ORA-38801: %s ORA_EDITION in %s on line %d
213
214
215**Test 1.5 - Negative case with an invalid string value. *********
216Testing with oci_new_connect()
217
218Warning: oci_new_connect(): ORA-38801: %s ORA_EDITION in %s on line %d
219 The value of edition has been successfully set
220
221
222**Test 1.6 - Set Multiple times.*****
223 The value of edition has been successfully set
224 The value of edition has been successfully set
225Testing with oci_connect()
226The value of current EDITION is MYEDITION1
227
228
229**Test 1.7 - Test with ALTER SESSION statement to change the edition *******
230 The value of edition has been successfully set
231Testing with oci_new_connect()
232get the value set to MYEDITION with oci_set_edition
233The value of current EDITION is MYEDITION
234Get the value set to MYEDITION1 with alter session
235The value of current EDITION is MYEDITION1
236 Get the value with a new connection
237Testing with oci_connect()
238The value of current EDITION is MYEDITION
239 Set the value back using oci-set_edition
240 The value of edition has been successfully set
241The value of current EDITION is MYEDITION
242 Get the value with a new connection
243Testing with oci_connect()
244The value of current EDITION is MYEDITION
245
246
247**Test 1.8 - Test setting the attribute with scope ends*******
248 The value of edition has been successfully set
249The value of current EDITION is MYEDITION1
250Done
251