xref: /PHP-8.0/ext/oci8/tests/xmltype_01.phpt (revision b2d1736d)
1--TEST--
2Basic XMLType test
3--SKIPIF--
4<?php
5if (!extension_loaded("simplexml")) die("skip no simplexml extension");
6$target_dbs = array('oracledb' => true, 'timesten' => false);  // test runs on these DBs
7require(__DIR__.'/skipif.inc');
8?>
9--FILE--
10<?php
11
12require(__DIR__."/connect.inc");
13
14// Initialization
15
16$stmtarray = array(
17    "drop table xtt",
18    "create table xtt
19           (xt_id number, xt_spec xmltype)
20           xmltype xt_spec store as clob",
21    "insert into xtt (xt_id, xt_spec) values
22      (1,
23       xmltype('<?xml version=\"1.0\"?>
24        <Xt>
25          <XtId>1</XtId>
26          <Size>Big</Size>
27          <Area>12345</Area>
28          <Hardness>20</Hardness>
29          <Lip>Curved</Lip>
30          <Color>Red</Color>
31          <Nice>N</Nice>
32          <Compact>Tiny</Compact>
33          <Material>Steel</Material>
34        </Xt>'))"
35);
36
37oci8_test_sql_execute($c, str_replace("\r", "", $stmtarray));
38
39function do_query($c)
40{
41    $s = oci_parse($c, 'select XMLType.getClobVal(xt_spec)
42                        from xtt where xt_id = 1');
43    oci_execute($s);
44    $row = oci_fetch_row($s);
45    $data = $row[0]->load();
46    var_dump($data);
47    return($data);
48}
49
50// Check
51echo "Initial Data\n";
52$data = do_query($c);
53
54// Manipulate the data using SimpleXML
55$sx = simplexml_load_string($data);
56$sx->Hardness = $sx->Hardness - 1;
57$sx->Nice = 'Y';
58
59// Insert changes using a temporary CLOB
60$s = oci_parse($c, 'update xtt
61                    set xt_spec = XMLType(:clob)
62                    where xt_id = 1');
63$lob = oci_new_descriptor($c, OCI_D_LOB);
64oci_bind_by_name($s, ':clob', $lob, -1, OCI_B_CLOB);
65$lob->writeTemporary($sx->asXml());
66oci_execute($s);
67$lob->close();
68
69// Verify
70echo "Verify\n";
71$data = do_query($c);
72
73// Cleanup
74
75$stmtarray = array(
76    "drop table xtt",
77);
78
79oci8_test_sql_execute($c, $stmtarray);
80
81echo "Done\n";
82
83?>
84--EXPECT--
85Initial Data
86string(316) "<?xml version="1.0"?>
87        <Xt>
88          <XtId>1</XtId>
89          <Size>Big</Size>
90          <Area>12345</Area>
91          <Hardness>20</Hardness>
92          <Lip>Curved</Lip>
93          <Color>Red</Color>
94          <Nice>N</Nice>
95          <Compact>Tiny</Compact>
96          <Material>Steel</Material>
97        </Xt>"
98Verify
99string(309) "<?xml version="1.0"?>
100<Xt>
101          <XtId>1</XtId>
102          <Size>Big</Size>
103          <Area>12345</Area>
104          <Hardness>19</Hardness>
105          <Lip>Curved</Lip>
106          <Color>Red</Color>
107          <Nice>Y</Nice>
108          <Compact>Tiny</Compact>
109          <Material>Steel</Material>
110        </Xt>
111"
112Done
113