xref: /PHP-8.3/ext/oci8/tests/imp_res_cursor.phpt (revision a53e5617)
1--TEST--
2Oracle Database 12c Implicit Result Sets: nested cursor
3--EXTENSIONS--
4oci8
5--SKIPIF--
6<?php
7require_once 'skipifconnectfailure.inc';
8$target_dbs = array('oracledb' => true, 'timesten' => false);  // test runs on these DBs
9require __DIR__.'/skipif.inc';
10preg_match('/.*Release ([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)*/', oci_server_version($c), $matches);
11if (!(isset($matches[0]) && $matches[1] >= 12)) {
12    die("skip expected output only valid when using Oracle Database 12c or greater");
13}
14preg_match('/^[[:digit:]]+/', oci_client_version(), $matches);
15if (!(isset($matches[0]) && $matches[0] >= 12)) {
16    die("skip works only with Oracle 12c or greater version of Oracle client libraries");
17}
18?>
19--FILE--
20<?php
21
22require __DIR__.'/connect.inc';
23
24// Initialization
25
26$stmtarray = array(
27    "drop table imp_res_cursor_tab_1",
28    "create table imp_res_cursor_tab_1 (c1 number, c2 varchar2(10))",
29    "insert into imp_res_cursor_tab_1 values (1, 'abcde')",
30    "insert into imp_res_cursor_tab_1 values (2, 'fghij')",
31    "insert into imp_res_cursor_tab_1 values (3, 'klmno')",
32
33    "drop table imp_res_cursor_tab_2",
34    "create table imp_res_cursor_tab_2 (c3 varchar2(1))",
35    "insert into imp_res_cursor_tab_2 values ('t')",
36    "insert into imp_res_cursor_tab_2 values ('u')",
37    "insert into imp_res_cursor_tab_2 values ('v')",
38
39    "create or replace procedure imp_res_cursor_proc as
40      c1 sys_refcursor;
41    begin
42      open c1 for select * from dual;
43      dbms_sql.return_result (c1);
44
45      open c1 for select cursor(select c1, c2 from imp_res_cursor_tab_1 order by 1) as curs from dual;
46      dbms_sql.return_result(c1);
47
48      open c1 for select * from imp_res_cursor_tab_2 where rownum < 3 order by 1;
49      dbms_sql.return_result(c1);
50    end;"
51);
52
53oci8_test_sql_execute($c, $stmtarray);
54
55function do_fetch($s)
56{
57    while (($row = oci_fetch_assoc($s)) != false) {
58        foreach ($row as $item) {
59            if (is_resource($item)) {  // Nested cursor
60                oci_execute($item);
61                do_fetch($item);
62            } else {
63                echo "  ".$item;
64            }
65        }
66        echo "\n";
67    }
68}
69
70// Run Test
71
72echo "Test 1\n";
73
74$s = oci_parse($c, "begin imp_res_cursor_proc(); end;");
75oci_execute($s);
76
77do_fetch($s);
78
79// Clean up
80
81$stmtarray = array(
82    "drop procedure imp_res_cursor_proc",
83    "drop table imp_res_cursor_tab_1",
84    "drop table imp_res_cursor_tab_2"
85);
86
87oci8_test_sql_execute($c, $stmtarray);
88
89?>
90--EXPECT--
91Test 1
92  X
93  1  abcde
94  2  fghij
95  3  klmno
96
97  t
98  u
99