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