xref: /PHP-7.4/ext/oci8/tests/imp_res_get_2.phpt (revision 26dfce7f)
1--TEST--
2Oracle Database 12c Implicit Result Sets: oci_get_implicit_resultset: similar to imp_res_get_1 but with unrolled loop
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_2_tab_1",
26    "create table imp_res_get_2_tab_1 (c1 number, c2 varchar2(10))",
27    "insert into imp_res_get_2_tab_1 values (1, 'abcde')",
28    "insert into imp_res_get_2_tab_1 values (2, 'fghij')",
29    "insert into imp_res_get_2_tab_1 values (3, 'klmno')",
30
31    "drop table imp_res_get_2_tab_2",
32    "create table imp_res_get_2_tab_2 (c3 varchar2(1))",
33    "insert into imp_res_get_2_tab_2 values ('t')",
34    "insert into imp_res_get_2_tab_2 values ('u')",
35    "insert into imp_res_get_2_tab_2 values ('v')",
36
37    "create or replace procedure imp_res_get_2_proc as
38      c1 sys_refcursor;
39    begin
40      open c1 for select * from imp_res_get_2_tab_1 order by 1;
41      dbms_sql.return_result(c1);
42
43      open c1 for select * from imp_res_get_2_tab_2 where rownum < 3 order by 1;
44      dbms_sql.return_result(c1);
45
46      open c1 for select * from dual;
47      dbms_sql.return_result (c1);
48    end;"
49);
50
51oci8_test_sql_execute($c, $stmtarray);
52
53// Run Test
54
55echo "Test 1\n";
56
57$s = oci_parse($c, "begin imp_res_get_2_proc(); end;");
58oci_execute($s);
59
60$s1 = oci_get_implicit_resultset($s);
61while (($row = oci_fetch_array($s1, OCI_ASSOC+OCI_RETURN_NULLS))) {
62    foreach ($row as $item) {
63        echo "  ".$item;
64    }
65    echo "\n";
66}
67
68$s2 = oci_get_implicit_resultset($s);
69while (($row = oci_fetch_array($s2, OCI_ASSOC+OCI_RETURN_NULLS))) {
70    foreach ($row as $item) {
71        echo "  ".$item;
72    }
73    echo "\n";
74}
75oci_free_statement($s2);
76
77$s3 = oci_get_implicit_resultset($s);
78while (($row = oci_fetch_array($s3, OCI_ASSOC+OCI_RETURN_NULLS))) {
79    foreach ($row as $item) {
80        echo "  ".$item;
81    }
82    echo "\n";
83}
84oci_free_statement($s3);
85
86// Clean up
87
88$stmtarray = array(
89    "drop procedure imp_res_get_2_proc",
90    "drop table imp_res_get_2_tab_1",
91    "drop table imp_res_get_2_tab_2"
92);
93
94oci8_test_sql_execute($c, $stmtarray);
95
96?>
97===DONE===
98<?php exit(0); ?>
99--EXPECT--
100Test 1
101  1  abcde
102  2  fghij
103  3  klmno
104  t
105  u
106  X
107===DONE===
108