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--EXPECT--
85Test 1 - prefetch 0
86bool(true)
87array(2) {
88  [0]=>
89  string(1) "1"
90  [1]=>
91  string(5) "abcde"
92}
93array(2) {
94  [0]=>
95  string(1) "2"
96  [1]=>
97  string(5) "fghij"
98}
99array(2) {
100  [0]=>
101  string(1) "3"
102  [1]=>
103  string(5) "klmno"
104}
105array(1) {
106  [0]=>
107  string(1) "t"
108}
109array(1) {
110  [0]=>
111  string(1) "u"
112}
113array(1) {
114  [0]=>
115  string(1) "v"
116}
117
118Test 1 - prefetch 1
119bool(true)
120array(2) {
121  [0]=>
122  string(1) "1"
123  [1]=>
124  string(5) "abcde"
125}
126array(2) {
127  [0]=>
128  string(1) "2"
129  [1]=>
130  string(5) "fghij"
131}
132array(2) {
133  [0]=>
134  string(1) "3"
135  [1]=>
136  string(5) "klmno"
137}
138array(1) {
139  [0]=>
140  string(1) "t"
141}
142array(1) {
143  [0]=>
144  string(1) "u"
145}
146array(1) {
147  [0]=>
148  string(1) "v"
149}
150
151Test 1 - prefetch 2
152bool(true)
153array(2) {
154  [0]=>
155  string(1) "1"
156  [1]=>
157  string(5) "abcde"
158}
159array(2) {
160  [0]=>
161  string(1) "2"
162  [1]=>
163  string(5) "fghij"
164}
165array(2) {
166  [0]=>
167  string(1) "3"
168  [1]=>
169  string(5) "klmno"
170}
171array(1) {
172  [0]=>
173  string(1) "t"
174}
175array(1) {
176  [0]=>
177  string(1) "u"
178}
179array(1) {
180  [0]=>
181  string(1) "v"
182}
183