1--TEST--
2Oracle Database 12c Implicit Result Sets: oci_get_implicit_resultset: nested cursor
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_get_cursor_tab_1",
26    "create table imp_res_get_cursor_tab_1 (c1 number, c2 varchar2(10))",
27    "insert into imp_res_get_cursor_tab_1 values (1, 'abcde')",
28    "insert into imp_res_get_cursor_tab_1 values (2, 'fghij')",
29    "insert into imp_res_get_cursor_tab_1 values (3, 'klmno')",
30
31    "drop table imp_res_get_cursor_tab_2",
32    "create table imp_res_get_cursor_tab_2 (c3 varchar2(1))",
33    "insert into imp_res_get_cursor_tab_2 values ('t')",
34    "insert into imp_res_get_cursor_tab_2 values ('u')",
35    "insert into imp_res_get_cursor_tab_2 values ('v')",
36
37    "create or replace procedure imp_res_get_cursor_proc as
38      c1 sys_refcursor;
39    begin
40      open c1 for select cursor(select c1, c2 from imp_res_get_cursor_tab_1 order by 1) as curs from dual;
41      dbms_sql.return_result(c1);
42
43      open c1 for select * from imp_res_get_cursor_tab_2 where rownum < 3 order by 1;
44      dbms_sql.return_result(c1);
45
46      open c1 for select * from dual;
47      dbms_sql.return_result (c1);
48    end;"
49);
50
51oci8_test_sql_execute($c, $stmtarray);
52
53function do_fetch($s)
54{
55    while (($row = oci_fetch_assoc($s)) != false) {
56        foreach ($row as $item) {
57            if (is_resource($item)) {  // Nested cursor
58                oci_execute($item);
59                do_fetch($item);
60            } else {
61                echo "  ".$item;
62            }
63        }
64        echo "\n";
65    }
66}
67
68// Run Test
69
70echo "Test 1\n";
71
72$s = oci_parse($c, "begin imp_res_get_cursor_proc(); end;");
73oci_execute($s);
74
75while (($s1 = oci_get_implicit_resultset($s))) {
76    do_fetch($s1);
77}
78
79// Clean up
80
81$stmtarray = array(
82    "drop procedure imp_res_get_cursor_proc",
83    "drop table imp_res_get_cursor_tab_1",
84    "drop table imp_res_get_cursor_tab_2"
85);
86
87oci8_test_sql_execute($c, $stmtarray);
88
89?>
90===DONE===
91<?php exit(0); ?>
92--EXPECT--
93Test 1
94  1  abcde
95  2  fghij
96  3  klmno
97
98  t
99  u
100  X
101===DONE===
102