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