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