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