xref: /PHP-7.0/ext/oci8/tests/imp_res_get_5.phpt (revision bfc3c223)
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(dirname(__FILE__).'/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(dirname(__FILE__).'/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===DONE===
97<?php exit(0); ?>
98--EXPECTF--
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===DONE===
125