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