xref: /PHP-8.2/ext/oci8/tests/imp_res_get_4.phpt (revision 72f47c0c)
1--TEST--
2Oracle Database 12c Implicit Result Sets: oci_get_implicit_resultset: interleaved fetches
3--EXTENSIONS--
4oci8
5--SKIPIF--
6<?php
7$target_dbs = array('oracledb' => true, 'timesten' => false);  // test runs on these DBs
8require(__DIR__.'/skipif.inc');
9preg_match('/.*Release ([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)*/', oci_server_version($c), $matches);
10if (!(isset($matches[0]) && $matches[1] >= 12)) {
11    die("skip expected output only valid when using Oracle Database 12c or greater");
12}
13preg_match('/^[[:digit:]]+/', oci_client_version(), $matches);
14if (!(isset($matches[0]) && $matches[0] >= 12)) {
15    die("skip works only with Oracle 12c or greater version of Oracle client libraries");
16}
17?>
18--FILE--
19<?php
20
21require(__DIR__.'/connect.inc');
22
23// Initialization
24
25$stmtarray = array(
26    "drop table imp_res_get_4_tab_1",
27    "create table imp_res_get_4_tab_1 (c1 number, c2 varchar2(10))",
28    "insert into imp_res_get_4_tab_1 values (1, 'abcde')",
29    "insert into imp_res_get_4_tab_1 values (2, 'fghij')",
30    "insert into imp_res_get_4_tab_1 values (3, 'klmno')",
31
32    "drop table imp_res_get_4_tab_2",
33    "create table imp_res_get_4_tab_2 (c3 varchar2(1))",
34    "insert into imp_res_get_4_tab_2 values ('t')",
35    "insert into imp_res_get_4_tab_2 values ('u')",
36    "insert into imp_res_get_4_tab_2 values ('v')",
37
38    "create or replace procedure imp_res_get_4_proc as
39      c1 sys_refcursor;
40    begin
41      open c1 for select * from imp_res_get_4_tab_1 order by 1;
42      dbms_sql.return_result(c1);
43
44      open c1 for select * from imp_res_get_4_tab_2 order by 1;
45      dbms_sql.return_result(c1);
46    end;"
47);
48
49oci8_test_sql_execute($c, $stmtarray);
50
51function print_row($row)
52{
53    if ($row === false) {
54      print "Return is false\n";
55      return;
56    }
57    foreach ($row as $item) {
58        echo "  ".$item;
59    }
60    echo "\n";
61}
62
63// Run Test
64
65echo "Test 1\n";
66
67$s = oci_parse($c, "begin imp_res_get_4_proc(); end;");
68oci_execute($s);
69$s1 = oci_get_implicit_resultset($s);
70$s2 = oci_get_implicit_resultset($s);
71$row = oci_fetch_array($s1, OCI_ASSOC+OCI_RETURN_NULLS);
72print_row($row);
73$row = oci_fetch_array($s2, OCI_ASSOC+OCI_RETURN_NULLS);
74print_row($row);
75$row = oci_fetch_array($s1, OCI_ASSOC+OCI_RETURN_NULLS);
76print_row($row);
77$row = oci_fetch_array($s2, OCI_ASSOC+OCI_RETURN_NULLS);
78print_row($row);
79$row = oci_fetch_array($s1, OCI_ASSOC+OCI_RETURN_NULLS);
80print_row($row);
81$row = oci_fetch_array($s2, OCI_ASSOC+OCI_RETURN_NULLS);
82print_row($row);
83
84echo "Test 2 - too many fetches\n";
85
86$s = oci_parse($c, "begin imp_res_get_4_proc(); end;");
87oci_execute($s);
88$s1 = oci_get_implicit_resultset($s);
89$s2 = oci_get_implicit_resultset($s);
90$row = oci_fetch_array($s1, OCI_ASSOC+OCI_RETURN_NULLS);
91print_row($row);
92$row = oci_fetch_array($s2, OCI_ASSOC+OCI_RETURN_NULLS);
93print_row($row);
94$row = oci_fetch_array($s1, OCI_ASSOC+OCI_RETURN_NULLS);
95print_row($row);
96$row = oci_fetch_array($s2, OCI_ASSOC+OCI_RETURN_NULLS);
97print_row($row);
98$row = oci_fetch_array($s1, OCI_ASSOC+OCI_RETURN_NULLS);
99print_row($row);
100$row = oci_fetch_array($s2, OCI_ASSOC+OCI_RETURN_NULLS);
101print_row($row);
102$row = oci_fetch_array($s1, OCI_ASSOC+OCI_RETURN_NULLS);
103print_row($row);
104$row = oci_fetch_array($s2, OCI_ASSOC+OCI_RETURN_NULLS);
105print_row($row);
106$row = oci_fetch_array($s1, OCI_ASSOC+OCI_RETURN_NULLS);
107print_row($row);
108$row = oci_fetch_array($s2, OCI_ASSOC+OCI_RETURN_NULLS);
109print_row($row);
110
111// Clean up
112
113$stmtarray = array(
114    "drop procedure imp_res_get_4_proc",
115    "drop table imp_res_get_4_tab_1",
116    "drop table imp_res_get_4_tab_2"
117);
118
119oci8_test_sql_execute($c, $stmtarray);
120
121?>
122--EXPECTF--
123Test 1
124  1  abcde
125  t
126  2  fghij
127  u
128  3  klmno
129  v
130Test 2 - too many fetches
131  1  abcde
132  t
133  2  fghij
134  u
135  3  klmno
136  v
137Return is false
138Return is false
139
140Warning: oci_fetch_array(): ORA-01002: %s in %simp_res_get_4.php on line %d
141Return is false
142
143Warning: oci_fetch_array(): ORA-01002: %s in %simp_res_get_4.php on line %d
144Return is false
145