~ubuntu-branches/ubuntu/lucid/php5/lucid

« back to all changes in this revision

Viewing changes to ext/oci8/tests/xmltype_02.phpt

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2010-03-16 09:09:50 UTC
  • mfrom: (1.1.18 upstream) (0.3.10 sid)
  • Revision ID: james.westby@ubuntu.com-20100316090950-e36m0pzranoixifd
Tags: 5.3.2-1ubuntu1
* Merge from debian unstable: 
  - debian/control:
    * Dropped firebird2.1-dev, libc-client-dev, libmcrypt-dev as it is in universe.
    * Dropped libmysqlclient15-dev, build against mysql 5.1.
    * Dropped libcurl-dev not in the archive.
    * Suggest php5-suhosin rather than recommends.
    * Dropped php5-imap, php5-interbase, php5-mcrypt since we have versions already in
      universe.
    * Dropped libonig-dev and libqgdbm since its in universe. (will be re-added in lucid+1)
    * Dropped locales-all.
  - modulelist: Drop imap, interbase, and mcrypt.
  - debian/rules:
    * Dropped building of mcrypt, imap, and interbase.
    * Install apport hook for php5.
  - Dropped debian/patches/libedit_is_editline.patch.

Show diffs side-by-side

added added

removed removed

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