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