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