xref: /PHP-8.1/ext/oci8/tests/imp_res_lob.phpt (revision 72f47c0c)
1--TEST--
2Oracle Database 12c Implicit Result Sets: LOBs
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_lob_tab",
27    "create table imp_res_lob_tab (c1 number, c2 clob, c3 varchar2(10))",
28    "insert into imp_res_lob_tab values (1, 'aaaaa', 'a')",
29    "insert into imp_res_lob_tab values (2, 'bbbbb', 'b')",
30    "insert into imp_res_lob_tab values (3, 'ccccc', 'c')",
31    "insert into imp_res_lob_tab values (4, 'ddddd', 'd')",
32
33    "create or replace procedure imp_res_lob_proc as
34      c1 sys_refcursor;
35    begin
36      open c1 for select * from imp_res_lob_tab order by 1;
37      dbms_sql.return_result(c1);
38      open c1 for select * from dual;
39      dbms_sql.return_result(c1);
40      open c1 for select c2 from imp_res_lob_tab order by c1;
41      dbms_sql.return_result(c1);
42   end;"
43);
44
45oci8_test_sql_execute($c, $stmtarray);
46
47// Run Test
48
49echo "Test 1\n";
50$s = oci_parse($c, "begin imp_res_lob_proc(); end;");
51oci_execute($s);
52while (($row = oci_fetch_row($s)) != false) {
53    foreach ($row as $item) {
54        if (is_object($item)) {
55            echo " " . $item->load();
56        } else {
57            echo " " . $item;
58        }
59    }
60    echo "\n";
61}
62
63echo "\nTest 2 - don't fetch all rows\n";
64$s = oci_parse($c, "begin imp_res_lob_proc(); end;");
65oci_execute($s);
66$row = oci_fetch_row($s);
67foreach ($row as $item) {
68    if (is_object($item)) {
69        echo " " . $item->load();
70    } else {
71        echo " " . $item;
72    }
73}
74echo "\n";
75
76// Clean up
77
78$stmtarray = array(
79    "drop procedure imp_res_lob_proc",
80    "drop table imp_res_lob_tab",
81);
82
83oci8_test_sql_execute($c, $stmtarray);
84
85?>
86--EXPECT--
87Test 1
88 1 aaaaa a
89 2 bbbbb b
90 3 ccccc c
91 4 ddddd d
92 X
93 aaaaa
94 bbbbb
95 ccccc
96 ddddd
97
98Test 2 - don't fetch all rows
99 1 aaaaa a
100