xref: /PHP-8.3/ext/oci8/tests/imp_res_lob.phpt (revision a53e5617)
1--TEST--
2Oracle Database 12c Implicit Result Sets: LOBs
3--EXTENSIONS--
4oci8
5--SKIPIF--
6<?php
7require_once 'skipifconnectfailure.inc';
8$target_dbs = array('oracledb' => true, 'timesten' => false);  // test runs on these DBs
9require __DIR__.'/skipif.inc';
10preg_match('/.*Release ([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)*/', oci_server_version($c), $matches);
11if (!(isset($matches[0]) && $matches[1] >= 12)) {
12    die("skip expected output only valid when using Oracle Database 12c or greater");
13}
14preg_match('/^[[:digit:]]+/', oci_client_version(), $matches);
15if (!(isset($matches[0]) && $matches[0] >= 12)) {
16    die("skip works only with Oracle 12c or greater version of Oracle client libraries");
17}
18?>
19--FILE--
20<?php
21
22require __DIR__.'/connect.inc';
23
24// Initialization
25
26$stmtarray = array(
27    "drop table imp_res_lob_tab",
28    "create table imp_res_lob_tab (c1 number, c2 clob, c3 varchar2(10))",
29    "insert into imp_res_lob_tab values (1, 'aaaaa', 'a')",
30    "insert into imp_res_lob_tab values (2, 'bbbbb', 'b')",
31    "insert into imp_res_lob_tab values (3, 'ccccc', 'c')",
32    "insert into imp_res_lob_tab values (4, 'ddddd', 'd')",
33
34    "create or replace procedure imp_res_lob_proc as
35      c1 sys_refcursor;
36    begin
37      open c1 for select * from imp_res_lob_tab order by 1;
38      dbms_sql.return_result(c1);
39      open c1 for select * from dual;
40      dbms_sql.return_result(c1);
41      open c1 for select c2 from imp_res_lob_tab order by c1;
42      dbms_sql.return_result(c1);
43   end;"
44);
45
46oci8_test_sql_execute($c, $stmtarray);
47
48// Run Test
49
50echo "Test 1\n";
51$s = oci_parse($c, "begin imp_res_lob_proc(); end;");
52oci_execute($s);
53while (($row = oci_fetch_row($s)) != false) {
54    foreach ($row as $item) {
55        if (is_object($item)) {
56            echo " " . $item->load();
57        } else {
58            echo " " . $item;
59        }
60    }
61    echo "\n";
62}
63
64echo "\nTest 2 - don't fetch all rows\n";
65$s = oci_parse($c, "begin imp_res_lob_proc(); end;");
66oci_execute($s);
67$row = oci_fetch_row($s);
68foreach ($row as $item) {
69    if (is_object($item)) {
70        echo " " . $item->load();
71    } else {
72        echo " " . $item;
73    }
74}
75echo "\n";
76
77// Clean up
78
79$stmtarray = array(
80    "drop procedure imp_res_lob_proc",
81    "drop table imp_res_lob_tab",
82);
83
84oci8_test_sql_execute($c, $stmtarray);
85
86?>
87--EXPECT--
88Test 1
89 1 aaaaa a
90 2 bbbbb b
91 3 ccccc c
92 4 ddddd d
93 X
94 aaaaa
95 bbbbb
96 ccccc
97 ddddd
98
99Test 2 - don't fetch all rows
100 1 aaaaa a
101