1--TEST--
2Oracle Database 12c Implicit Result Sets: basic test
3--SKIPIF--
4<?php
5if (!extension_loaded('oci8')) die ("skip no oci8 extension");
6$target_dbs = array('oracledb' => true, 'timesten' => false);  // test runs on these DBs
7require(__DIR__.'/skipif.inc');
8preg_match('/.*Release ([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)*/', oci_server_version($c), $matches);
9if (!(isset($matches[0]) && $matches[1] >= 12)) {
10    die("skip expected output only valid when using Oracle Database 12c or greater");
11}
12preg_match('/^[[:digit:]]+/', oci_client_version(), $matches);
13if (!(isset($matches[0]) && $matches[0] >= 12)) {
14    die("skip works only with Oracle 12c or greater version of Oracle client libraries");
15}
16?>
17--FILE--
18<?php
19
20require(__DIR__.'/connect.inc');
21
22// Initialization
23
24$stmtarray = array(
25    "drop table imp_res_prefetch_tab_1",
26    "create table imp_res_prefetch_tab_1 (c1 number, c2 varchar2(10))",
27    "insert into imp_res_prefetch_tab_1 values (1, 'abcde')",
28    "insert into imp_res_prefetch_tab_1 values (2, 'fghij')",
29    "insert into imp_res_prefetch_tab_1 values (3, 'klmno')",
30
31    "drop table imp_res_prefetch_tab_2",
32    "create table imp_res_prefetch_tab_2 (c3 varchar2(1))",
33    "insert into imp_res_prefetch_tab_2 values ('t')",
34    "insert into imp_res_prefetch_tab_2 values ('u')",
35    "insert into imp_res_prefetch_tab_2 values ('v')",
36
37    "create or replace procedure imp_res_prefetch_proc as
38      c1 sys_refcursor;
39    begin
40      open c1 for select * from imp_res_prefetch_tab_1 order by 1;
41      dbms_sql.return_result(c1);
42
43      open c1 for select * from imp_res_prefetch_tab_2 order by 1;
44      dbms_sql.return_result(c1);
45    end;"
46);
47
48oci8_test_sql_execute($c, $stmtarray);
49
50// Run Test
51
52echo "Test 1 - prefetch 0\n";
53$s = oci_parse($c, "begin imp_res_prefetch_proc(); end;");
54oci_execute($s);
55var_dump(oci_set_prefetch($s, 0));
56while (($row = oci_fetch_row($s)) != false)
57    var_dump($row);
58
59echo "\nTest 1 - prefetch 1\n";
60$s = oci_parse($c, "begin imp_res_prefetch_proc(); end;");
61oci_execute($s);
62var_dump(oci_set_prefetch($s, 1));
63while (($row = oci_fetch_row($s)) != false)
64    var_dump($row);
65
66echo "\nTest 1 - prefetch 2\n";
67$s = oci_parse($c, "begin imp_res_prefetch_proc(); end;");
68oci_execute($s);
69var_dump(oci_set_prefetch($s, 2));
70while (($row = oci_fetch_row($s)) != false)
71    var_dump($row);
72
73// Clean up
74
75$stmtarray = array(
76    "drop procedure imp_res_prefetch_proc",
77    "drop table imp_res_prefetch_tab_1",
78    "drop table imp_res_prefetch_tab_2"
79);
80
81oci8_test_sql_execute($c, $stmtarray);
82
83?>
84===DONE===
85<?php exit(0); ?>
86--EXPECT--
87Test 1 - prefetch 0
88bool(true)
89array(2) {
90  [0]=>
91  string(1) "1"
92  [1]=>
93  string(5) "abcde"
94}
95array(2) {
96  [0]=>
97  string(1) "2"
98  [1]=>
99  string(5) "fghij"
100}
101array(2) {
102  [0]=>
103  string(1) "3"
104  [1]=>
105  string(5) "klmno"
106}
107array(1) {
108  [0]=>
109  string(1) "t"
110}
111array(1) {
112  [0]=>
113  string(1) "u"
114}
115array(1) {
116  [0]=>
117  string(1) "v"
118}
119
120Test 1 - prefetch 1
121bool(true)
122array(2) {
123  [0]=>
124  string(1) "1"
125  [1]=>
126  string(5) "abcde"
127}
128array(2) {
129  [0]=>
130  string(1) "2"
131  [1]=>
132  string(5) "fghij"
133}
134array(2) {
135  [0]=>
136  string(1) "3"
137  [1]=>
138  string(5) "klmno"
139}
140array(1) {
141  [0]=>
142  string(1) "t"
143}
144array(1) {
145  [0]=>
146  string(1) "u"
147}
148array(1) {
149  [0]=>
150  string(1) "v"
151}
152
153Test 1 - prefetch 2
154bool(true)
155array(2) {
156  [0]=>
157  string(1) "1"
158  [1]=>
159  string(5) "abcde"
160}
161array(2) {
162  [0]=>
163  string(1) "2"
164  [1]=>
165  string(5) "fghij"
166}
167array(2) {
168  [0]=>
169  string(1) "3"
170  [1]=>
171  string(5) "klmno"
172}
173array(1) {
174  [0]=>
175  string(1) "t"
176}
177array(1) {
178  [0]=>
179  string(1) "u"
180}
181array(1) {
182  [0]=>
183  string(1) "v"
184}
185===DONE===
186