xref: /PHP-5.3/ext/oci8/tests/xmltype_02.phpt (revision ae1baaa5)
1--TEST--
2Basic XMLType test #2
3--SKIPIF--
4<?php
5$target_dbs = array('oracledb' => true, 'timesten' => false);  // test runs on these DBs
6require(dirname(__FILE__).'/skipif.inc');
7if (!extension_loaded("simplexml")) die ("skip no simplexml extension");
8?>
9--FILE--
10<?php
11
12require(dirname(__FILE__).'/connect.inc');
13
14// Initialization
15
16$stmtarray = array(
17	"drop table xmltype_02_tab",
18	"create table xmltype_02_tab (warehouse_id number, warehouse_spec xmltype)",
19);
20
21oci8_test_sql_execute($c, $stmtarray);
22
23// Run Test
24
25
26$id = 1;
27
28// Delete any current entry
29$s = oci_parse($c, "delete from xmltype_02_tab where warehouse_id = :id");
30oci_bind_by_name($s, ':id', $id);
31oci_execute($s);
32
33// XML data to be inserted
34$xml =<<<EOF
35<?xml version="1.0"?>
36<Warehouse>
37<WarehouseId>1</WarehouseId>
38<WarehouseName>Southlake, Texas</WarehouseName>
39<Building>Owned</Building>
40<Area>25000</Area>
41<Docks>2</Docks>
42<DockType>Rear load</DockType>
43<WaterAccess>true</WaterAccess>
44<RailAccess>N</RailAccess>
45<Parking>Street</Parking>
46<VClearance>10</VClearance>
47</Warehouse>
48EOF;
49
50echo "Test 1 Insert new XML data using a temporary CLOB\n";
51$s = oci_parse($c,
52    "insert into xmltype_02_tab (warehouse_id, warehouse_spec)
53     values (:id, XMLType(:clob))");
54oci_bind_by_name($s, ':id', $id);
55$lob = oci_new_descriptor($c, OCI_D_LOB);
56oci_bind_by_name($s, ':clob', $lob, -1, OCI_B_CLOB);
57$lob->writeTemporary($xml);
58oci_execute($s);
59$lob->close();
60
61// Query the row back
62$s = oci_parse($c, 'select xmltype.getclobval(warehouse_spec)
63                    from xmltype_02_tab where warehouse_id = :id');
64$r = oci_bind_by_name($s, ':id', $id);
65oci_execute($s);
66$row = oci_fetch_array($s, OCI_NUM);
67
68var_dump($row);
69
70echo "Test 2 Manipulate the data using SimpleXML\n";
71
72$sx = simplexml_load_string((binary)$row[0]->load());
73$row[0]->free();
74var_dump($sx);
75
76$sx->Docks -= 1;  // change the data
77
78var_dump($sx);
79
80echo "Test 3: Update changes using a temporary CLOB\n";
81
82$s = oci_parse($c, 'update xmltype_02_tab
83                    set warehouse_spec = XMLType(:clob)
84                    where warehouse_id = :id');
85oci_bind_by_name($s, ':id', $id);
86$lob = oci_new_descriptor($c, OCI_D_LOB);
87oci_bind_by_name($s, ':clob', $lob, -1, OCI_B_CLOB);
88$lob->writeTemporary($sx->asXml());
89oci_execute($s);
90$lob->close();
91
92// Query the changed row back and print it
93$s = oci_parse($c, 'select xmltype.getclobval(warehouse_spec)
94                    from xmltype_02_tab where warehouse_id = :id');
95$r = oci_bind_by_name($s, ':id', $id);
96oci_execute($s);
97$row = oci_fetch_array($s, OCI_NUM);
98var_dump($row[0]->load());
99$row[0]->free();
100
101// Clean up
102
103$stmtarray = array(
104	"drop table xmltype_02_tab"
105);
106
107oci8_test_sql_execute($c, $stmtarray);
108
109?>
110===DONE===
111<?php exit(0); ?>
112--EXPECTF--
113Test 1 Insert new XML data using a temporary CLOB
114array(1) {
115  [0]=>
116  object(OCI-Lob)#%d (1) {
117    ["descriptor"]=>
118    resource(%d) of type (oci8 descriptor)
119  }
120}
121Test 2 Manipulate the data using SimpleXML
122object(SimpleXMLElement)#%d (10) {
123  ["WarehouseId"]=>
124  string(1) "1"
125  ["WarehouseName"]=>
126  string(16) "Southlake, Texas"
127  ["Building"]=>
128  string(5) "Owned"
129  ["Area"]=>
130  string(5) "25000"
131  ["Docks"]=>
132  string(1) "2"
133  ["DockType"]=>
134  string(9) "Rear load"
135  ["WaterAccess"]=>
136  string(4) "true"
137  ["RailAccess"]=>
138  string(1) "N"
139  ["Parking"]=>
140  string(6) "Street"
141  ["VClearance"]=>
142  string(2) "10"
143}
144object(SimpleXMLElement)#%d (10) {
145  ["WarehouseId"]=>
146  string(1) "1"
147  ["WarehouseName"]=>
148  string(16) "Southlake, Texas"
149  ["Building"]=>
150  string(5) "Owned"
151  ["Area"]=>
152  string(5) "25000"
153  ["Docks"]=>
154  string(1) "1"
155  ["DockType"]=>
156  string(9) "Rear load"
157  ["WaterAccess"]=>
158  string(4) "true"
159  ["RailAccess"]=>
160  string(1) "N"
161  ["Parking"]=>
162  string(6) "Street"
163  ["VClearance"]=>
164  string(2) "10"
165}
166Test 3: Update changes using a temporary CLOB
167string(%d) "<?xml version="1.0"?>
168<Warehouse>
169%sWarehouseId>1</WarehouseId>
170%sWarehouseName>Southlake, Texas</WarehouseName>
171%sBuilding>Owned</Building>
172%sArea>25000</Area>
173%sDocks>1</Docks>
174%sDockType>Rear load</DockType>
175%sWaterAccess>true</WaterAccess>
176%sRailAccess>N</RailAccess>
177%sParking>Street</Parking>
178%sVClearance>10</VClearance>
179</Warehouse>
180"
181===DONE===