xref: /PHP-8.0/ext/oci8/tests/imp_res_get_5.phpt (revision a555cc0b)
1--TEST--
2Oracle Database 12c Implicit Result Sets: oci_get_implicit_resultset: get from wrong statement
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
22function print_row($row)
23{
24    foreach ($row as $item) {
25        echo "  ".$item;
26    }
27    echo "\n";
28}
29
30$plsql =
31    "declare
32      c1 sys_refcursor;
33    begin
34      open c1 for select 1 from dual union all select 2 from dual;
35      dbms_sql.return_result(c1);
36      open c1 for select 3 from dual union all select 4 from dual;
37      dbms_sql.return_result(c1);
38      open c1 for select 5 from dual union all select 6 from dual;
39      dbms_sql.return_result(c1);
40    end;";
41
42// Run Test
43
44echo "Test 1\n";
45// This test effectively discards all the first IRS results
46$s = oci_parse($c, $plsql);
47oci_execute($s);
48while (($s1 = oci_get_implicit_resultset($s))) {  // $s1 is never used again so its results are lost
49    while (($row = oci_fetch_array($s, OCI_ASSOC+OCI_RETURN_NULLS)) != false) {  // use parent $s instead of $s1
50        print_row($row);
51    }
52}
53oci_free_statement($s);
54
55echo "\nTest 2 - fetch first IRS explicitly\n";
56$s = oci_parse($c, $plsql);
57oci_execute($s);
58$s1 = oci_get_implicit_resultset($s);
59while (($row = oci_fetch_row($s1)) != false) {
60    print_row($row);
61}
62while (($row = oci_fetch_row($s)) != false) {
63    print_row($row);
64}
65oci_free_statement($s);
66
67echo "\nTest 3 - fetch part of IRS explicitly\n";
68$s = oci_parse($c, $plsql);
69oci_execute($s);
70$s1 = oci_get_implicit_resultset($s);
71while (($row = oci_fetch_row($s1)) != false) {
72    print_row($row);
73}
74$row = oci_fetch_row($s);
75print_row($row);
76$s1 = oci_get_implicit_resultset($s);
77while (($row = oci_fetch_row($s1)) != false) {
78    print_row($row);
79}
80while (($row = oci_fetch_row($s)) != false) {
81    print_row($row);
82}
83oci_free_statement($s);
84
85echo "\nTest 4 - skip IRSs\n";
86$s = oci_parse($c, $plsql);
87oci_execute($s);
88$s1 = oci_get_implicit_resultset($s);
89$s1 = oci_get_implicit_resultset($s);
90while (($row = oci_fetch_row($s)) != false) { // parent
91    print_row($row);
92}
93oci_free_statement($s);
94
95?>
96--EXPECT--
97Test 1
98  3
99  4
100  5
101  6
102
103Test 2 - fetch first IRS explicitly
104  1
105  2
106  3
107  4
108  5
109  6
110
111Test 3 - fetch part of IRS explicitly
112  1
113  2
114  3
115  5
116  6
117  4
118
119Test 4 - skip IRSs
120  5
121  6
122