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