xref: /PHP-8.3/ext/oci8/tests/imp_res_get_4.phpt (revision a53e5617)
1--TEST--
2Oracle Database 12c Implicit Result Sets: oci_get_implicit_resultset: interleaved fetches
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_get_4_tab_1",
28    "create table imp_res_get_4_tab_1 (c1 number, c2 varchar2(10))",
29    "insert into imp_res_get_4_tab_1 values (1, 'abcde')",
30    "insert into imp_res_get_4_tab_1 values (2, 'fghij')",
31    "insert into imp_res_get_4_tab_1 values (3, 'klmno')",
32
33    "drop table imp_res_get_4_tab_2",
34    "create table imp_res_get_4_tab_2 (c3 varchar2(1))",
35    "insert into imp_res_get_4_tab_2 values ('t')",
36    "insert into imp_res_get_4_tab_2 values ('u')",
37    "insert into imp_res_get_4_tab_2 values ('v')",
38
39    "create or replace procedure imp_res_get_4_proc as
40      c1 sys_refcursor;
41    begin
42      open c1 for select * from imp_res_get_4_tab_1 order by 1;
43      dbms_sql.return_result(c1);
44
45      open c1 for select * from imp_res_get_4_tab_2 order by 1;
46      dbms_sql.return_result(c1);
47    end;"
48);
49
50oci8_test_sql_execute($c, $stmtarray);
51
52function print_row($row)
53{
54    if ($row === false) {
55      print "Return is false\n";
56      return;
57    }
58    foreach ($row as $item) {
59        echo "  ".$item;
60    }
61    echo "\n";
62}
63
64// Run Test
65
66echo "Test 1\n";
67
68$s = oci_parse($c, "begin imp_res_get_4_proc(); end;");
69oci_execute($s);
70$s1 = oci_get_implicit_resultset($s);
71$s2 = oci_get_implicit_resultset($s);
72$row = oci_fetch_array($s1, OCI_ASSOC+OCI_RETURN_NULLS);
73print_row($row);
74$row = oci_fetch_array($s2, OCI_ASSOC+OCI_RETURN_NULLS);
75print_row($row);
76$row = oci_fetch_array($s1, OCI_ASSOC+OCI_RETURN_NULLS);
77print_row($row);
78$row = oci_fetch_array($s2, OCI_ASSOC+OCI_RETURN_NULLS);
79print_row($row);
80$row = oci_fetch_array($s1, OCI_ASSOC+OCI_RETURN_NULLS);
81print_row($row);
82$row = oci_fetch_array($s2, OCI_ASSOC+OCI_RETURN_NULLS);
83print_row($row);
84
85echo "Test 2 - too many fetches\n";
86
87$s = oci_parse($c, "begin imp_res_get_4_proc(); end;");
88oci_execute($s);
89$s1 = oci_get_implicit_resultset($s);
90$s2 = oci_get_implicit_resultset($s);
91$row = oci_fetch_array($s1, OCI_ASSOC+OCI_RETURN_NULLS);
92print_row($row);
93$row = oci_fetch_array($s2, OCI_ASSOC+OCI_RETURN_NULLS);
94print_row($row);
95$row = oci_fetch_array($s1, OCI_ASSOC+OCI_RETURN_NULLS);
96print_row($row);
97$row = oci_fetch_array($s2, OCI_ASSOC+OCI_RETURN_NULLS);
98print_row($row);
99$row = oci_fetch_array($s1, OCI_ASSOC+OCI_RETURN_NULLS);
100print_row($row);
101$row = oci_fetch_array($s2, OCI_ASSOC+OCI_RETURN_NULLS);
102print_row($row);
103$row = oci_fetch_array($s1, OCI_ASSOC+OCI_RETURN_NULLS);
104print_row($row);
105$row = oci_fetch_array($s2, OCI_ASSOC+OCI_RETURN_NULLS);
106print_row($row);
107$row = oci_fetch_array($s1, OCI_ASSOC+OCI_RETURN_NULLS);
108print_row($row);
109$row = oci_fetch_array($s2, OCI_ASSOC+OCI_RETURN_NULLS);
110print_row($row);
111
112// Clean up
113
114$stmtarray = array(
115    "drop procedure imp_res_get_4_proc",
116    "drop table imp_res_get_4_tab_1",
117    "drop table imp_res_get_4_tab_2"
118);
119
120oci8_test_sql_execute($c, $stmtarray);
121
122?>
123--EXPECTF--
124Test 1
125  1  abcde
126  t
127  2  fghij
128  u
129  3  klmno
130  v
131Test 2 - too many fetches
132  1  abcde
133  t
134  2  fghij
135  u
136  3  klmno
137  v
138Return is false
139Return is false
140
141Warning: oci_fetch_array(): ORA-01002: %s in %simp_res_get_4.php on line %d
142Return is false
143
144Warning: oci_fetch_array(): ORA-01002: %s in %simp_res_get_4.php on line %d
145Return is false
146