xref: /PHP-8.1/ext/oci8/tests/edition_1.phpt (revision 74859783)
1--TEST--
2Basic test for setting Oracle 11gR2 "edition" attribute
3--EXTENSIONS--
4oci8
5--SKIPIF--
6<?php
7require(__DIR__."/connect.inc");
8if (strcasecmp($user, "system") && strcasecmp($user, "sys")) {
9    die("skip needs to be run as a DBA user");
10}
11if ($test_drcp) {
12    die("skip as Output might vary with DRCP");
13}
14preg_match('/.*Release ([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)*/', oci_server_version($c), $matches);
15if (!(isset($matches[0]) &&
16      (($matches[1] == 11 && $matches[2] >= 2) ||
17       ($matches[1] >= 12)
18       ))) {
19        die("skip expected output only valid when using Oracle 11gR2 or greater database server");
20}
21preg_match('/^([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)/', oci_client_version(), $matches);
22if (!(isset($matches[0]) &&
23    (($matches[1] == 11 && $matches[2] >= 2) ||
24     ($matches[1] >= 12)
25     ))) {
26    die("skip test expected to work only with Oracle 11gR2 or greater version of client");
27}
28?>
29--FILE--
30<?php
31
32/* In 11.2, there can only be one child edition.  So this test will
33 * fail to create the necessary editions if a child edition exists
34 * already
35 */
36
37$testuser     = 'testuser_attr_1';  // Used in conn_attr.inc
38$testpassword = 'testuser';
39
40require(__DIR__."/conn_attr.inc");
41
42function select_fn($conn) {
43    $s = oci_parse($conn,"select * from view_ed");
44    oci_execute($s);
45    while ($row = oci_fetch_row($s)) {
46        var_dump($row);
47    }
48}
49/* Create a editon MYEDITION
50   create a view view_ed in MYEDITION1.
51   create the same view 'view_ed' with a different definition in MYEDITION.
52   select from both the editions and verify the contents. */
53
54set_edit_attr('MYEDITION');
55$conn = oci_connect($testuser,$testpassword,$dbase);
56if ($conn === false) {
57    $m = oci_error();
58    die("Error:" . $m['message']);
59}
60
61$stmtarray = array(
62    "drop table edit_tab",
63    "create table edit_tab (name varchar2(10),age number,job varchar2(50), salary number)",
64    "insert into edit_tab values('mike',30,'Senior engineer',200)",
65    "insert into edit_tab values('juan',25,'engineer',100)",
66    "create or replace editioning view view_ed as select name,age,job from edit_tab",
67);
68
69oci8_test_sql_execute($conn, $stmtarray);
70
71// Check the current edition of the DB and the contents of view_ed.
72get_edit_attr($conn);
73select_fn($conn);
74
75// Create a different version of view_ed in MYEDITION1.
76set_edit_attr('MYEDITION1');
77$conn2 = oci_new_connect($testuser,$testpassword,$dbase);
78$stmt = "create or replace editioning view view_ed as select name,age,job,salary from edit_tab";
79$s = oci_parse($conn2, $stmt);
80oci_execute($s);
81
82// Check the current edition of the DB and the contents of view_ed.
83get_edit_attr($conn2);
84select_fn($conn2);
85
86// Verify the contents in MYEDITION EDITION.
87echo "version of view_ed in MYEDITION\n";
88get_edit_attr($conn);
89select_fn($conn);
90
91clean_up($c);
92
93oci_close($conn);
94oci_close($conn2);
95echo "Done\n";
96
97?>
98--EXPECTF--
99The value of edition has been successfully set
100The value of current EDITION is MYEDITION
101array(3) {
102  [0]=>
103  string(%d) "mike"
104  [1]=>
105  string(%d) "30"
106  [2]=>
107  string(%d) "Senior engineer"
108}
109array(3) {
110  [0]=>
111  string(%d) "juan"
112  [1]=>
113  string(%d) "25"
114  [2]=>
115  string(%d) "engineer"
116}
117 The value of edition has been successfully set
118The value of current EDITION is MYEDITION1
119array(4) {
120  [0]=>
121  string(%d) "mike"
122  [1]=>
123  string(%d) "30"
124  [2]=>
125  string(%d) "Senior engineer"
126  [3]=>
127  string(%d) "200"
128}
129array(4) {
130  [0]=>
131  string(%d) "juan"
132  [1]=>
133  string(%d) "25"
134  [2]=>
135  string(%d) "engineer"
136  [3]=>
137  string(%d) "100"
138}
139version of view_ed in MYEDITION
140The value of current EDITION is MYEDITION
141array(3) {
142  [0]=>
143  string(%d) "mike"
144  [1]=>
145  string(%d) "30"
146  [2]=>
147  string(%d) "Senior engineer"
148}
149array(3) {
150  [0]=>
151  string(%d) "juan"
152  [1]=>
153  string(%d) "25"
154  [2]=>
155  string(%d) "engineer"
156}
157Done
158