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