1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
|
SET NAMES utf8;
#
# Testing tag values
#
CREATE TABLE t1
(
AUTHOR CHAR(50),
TITLE CHAR(32),
TRANSLATOR CHAR(40),
PUBLISHER CHAR(40),
DATEPUB INT(4)
) ENGINE=CONNECT TABLE_TYPE=XML FILE_NAME='xsample.xml'
OPTION_LIST='xmlsup=domdoc';
SELECT * FROM t1;
AUTHOR Jean-Christophe Bernadac
TITLE Construire une application XML
TRANSLATOR NULL
PUBLISHER Eyrolles Paris
DATEPUB 1999
AUTHOR William J. Pardi
TITLE XML en Action
TRANSLATOR James Guerin
PUBLISHER Microsoft Press Paris
DATEPUB 1999
DROP TABLE t1;
#
# Testing that tag names are case sensitive
#
CREATE TABLE t1
(
author CHAR(50),
TITLE CHAR(32),
TRANSLATOR CHAR(40),
PUBLISHER CHAR(40),
DATEPUB INT(4)
) ENGINE=CONNECT TABLE_TYPE=XML FILE_NAME='xsample.xml'
OPTION_LIST='xmlsup=domdoc';
SELECT * FROM t1;
author NULL
TITLE Construire une application XML
TRANSLATOR NULL
PUBLISHER Eyrolles Paris
DATEPUB 1999
author NULL
TITLE XML en Action
TRANSLATOR James Guerin
PUBLISHER Microsoft Press Paris
DATEPUB 1999
DROP TABLE t1;
#
# Testing attribute values
#
CREATE TABLE t1 (
ISBN CHAR(15),
LANG CHAR(2),
SUBJECT CHAR(32)
) ENGINE=CONNECT TABLE_TYPE=XML FILE_NAME='xsample.xml'
OPTION_LIST='Coltype=@,xmlsup=domdoc';
SELECT * FROM t1;
ISBN 9782212090819
LANG fr
SUBJECT applications
ISBN 9782840825685
LANG fr
SUBJECT applications
DROP TABLE t1;
#
# Testing that attribute names are case sensitive
#
CREATE TABLE t1 (
isbn CHAR(15),
LANG CHAR(2),
SUBJECT CHAR(32)
) ENGINE=CONNECT TABLE_TYPE=XML FILE_NAME='xsample.xml'
OPTION_LIST='Coltype=@,xmlsup=domdoc';
SELECT * FROM t1;
isbn NULL
LANG fr
SUBJECT applications
isbn NULL
LANG fr
SUBJECT applications
DROP TABLE t1;
#
# Testing mixed tag and attribute values
#
CREATE TABLE t1 (
ISBN CHAR(15) FIELD_FORMAT='@',
LANG CHAR(2) FIELD_FORMAT='@',
SUBJECT CHAR(32) FIELD_FORMAT='@',
AUTHOR CHAR(50),
TITLE CHAR(32),
TRANSLATOR CHAR(40),
PUBLISHER CHAR(40),
DATEPUB INT(4)
) ENGINE=CONNECT TABLE_TYPE=XML FILE_NAME='xsample.xml'
TABNAME='BIBLIO' OPTION_LIST='rownode=BOOK'
OPTION_LIST='xmlsup=domdoc';
SELECT * FROM t1;
ISBN 9782212090819
LANG fr
SUBJECT applications
AUTHOR Jean-Christophe Bernadac
TITLE Construire une application XML
TRANSLATOR NULL
PUBLISHER Eyrolles Paris
DATEPUB 1999
ISBN 9782840825685
LANG fr
SUBJECT applications
AUTHOR William J. Pardi
TITLE XML en Action
TRANSLATOR James Guerin
PUBLISHER Microsoft Press Paris
DATEPUB 1999
DROP TABLE t1;
#
# Testing INSERT on mixed tag and attribute values
#
CREATE TABLE t1 (
ISBN CHAR(15) FIELD_FORMAT='@',
LANG CHAR(2) FIELD_FORMAT='@',
SUBJECT CHAR(32) FIELD_FORMAT='@',
AUTHOR CHAR(50),
TITLE CHAR(32),
TRANSLATOR CHAR(40),
PUBLISHER CHAR(40),
DATEPUB INT(4)
) ENGINE=CONNECT TABLE_TYPE=XML FILE_NAME='xsample2.xml'
TABNAME='BIBLIO'
OPTION_LIST='rownode=BOOK,xmlsup=domdoc';
INSERT INTO t1 (ISBN, LANG, SUBJECT, AUTHOR, TITLE, PUBLISHEr, DATEPUB)
VALUES('9782212090529','fr','général','Alain Michard',
'XML, Langage et Applications','Eyrolles Paris',1998);
SELECT * FROM t1;
ISBN 9782212090819
LANG fr
SUBJECT applications
AUTHOR Jean-Christophe Bernadac
TITLE Construire une application XML
TRANSLATOR NULL
PUBLISHER Eyrolles Paris
DATEPUB 1999
ISBN 9782840825685
LANG fr
SUBJECT applications
AUTHOR William J. Pardi
TITLE XML en Action
TRANSLATOR James Guerin
PUBLISHER Microsoft Press Paris
DATEPUB 1999
ISBN 9782212090529
LANG fr
SUBJECT général
AUTHOR Alain Michard
TITLE XML, Langage et Applications
TRANSLATOR NULL
PUBLISHER Eyrolles Paris
DATEPUB 1998
SELECT LOAD_FILE('MYSQLD_DATADIR/test/xsample2.xml') AS xml;
xml <?xml version="1.0" encoding="UTF-8"?>
<BIBLIO SUBJECT="XML">
<BOOK ISBN="9782212090819" LANG="fr" SUBJECT="applications">
<AUTHOR>
<FIRSTNAME>Jean-Christophe</FIRSTNAME>
<LASTNAME>Bernadac</LASTNAME>
</AUTHOR>
<AUTHOR>
<FIRSTNAME>François</FIRSTNAME>
<LASTNAME>Knab</LASTNAME>
</AUTHOR>
<TITLE>Construire une application XML</TITLE>
<PUBLISHER>
<NAME>Eyrolles</NAME>
<PLACE>Paris</PLACE>
</PUBLISHER>
<DATEPUB>1999</DATEPUB>
</BOOK>
<BOOK ISBN="9782840825685" LANG="fr" SUBJECT="applications">
<AUTHOR>
<FIRSTNAME>William J.</FIRSTNAME>
<LASTNAME>Pardi</LASTNAME>
</AUTHOR>
<TRANSLATOR PREFIX="adapté de l'anglais par">
<FIRSTNAME>James</FIRSTNAME>
<LASTNAME>Guerin</LASTNAME>
</TRANSLATOR>
<TITLE>XML en Action</TITLE>
<PUBLISHER>
<NAME>Microsoft Press</NAME>
<PLACE>Paris</PLACE>
</PUBLISHER>
<DATEPUB>1999</DATEPUB>
</BOOK>
<BOOK ISBN="9782212090529" LANG="fr" SUBJECT="général">
<AUTHOR>Alain Michard</AUTHOR>
<TITLE>XML, Langage et Applications</TITLE>
<PUBLISHER>Eyrolles Paris</PUBLISHER>
<DATEPUB>1998</DATEPUB>
</BOOK>
</BIBLIO>
DROP TABLE t1;
#
# Testing XPath
#
CREATE TABLE t1 (
isbn CHAR(15) FIELD_FORMAT='@ISBN',
language CHAR(2) FIELD_FORMAT='@LANG',
subject CHAR(32) FIELD_FORMAT='@SUBJECT',
authorfn CHAR(20) FIELD_FORMAT='AUTHOR/FIRSTNAME',
authorln CHAR(20) FIELD_FORMAT='AUTHOR/LASTNAME',
title CHAR(32) FIELD_FORMAT='TITLE',
translated CHAR(32) FIELD_FORMAT='TRANSLATOR/@PREFIX',
tranfn CHAR(20) FIELD_FORMAT='TRANSLATOR/FIRSTNAME',
tranln CHAR(20) FIELD_FORMAT='TRANSLATOR/LASTNAME',
publisher CHAR(20) FIELD_FORMAT='PUBLISHER/NAME',
location CHAR(20) FIELD_FORMAT='PUBLISHER/PLACE',
year INT(4) FIELD_FORMAT='DATEPUB'
) ENGINE=CONNECT TABLE_TYPE=XML FILE_NAME='xsample.xml'
TABNAME='BIBLIO' OPTION_LIST='rownode=BOOK,skipnull=1,xmlsup=domdoc';
SELECT * FROM t1;
isbn 9782212090819
language fr
subject applications
authorfn Jean-Christophe
authorln Bernadac
title Construire une application XML
translated NULL
tranfn NULL
tranln NULL
publisher Eyrolles
location Paris
year 1999
isbn 9782840825685
language fr
subject applications
authorfn William J.
authorln Pardi
title XML en Action
translated adapté de l'anglais par
tranfn James
tranln Guerin
publisher Microsoft Press
location Paris
year 1999
SELECT isbn, title, translated, tranfn, tranln, location FROM t1
WHERE translated <> '';
isbn 9782840825685
title XML en Action
translated adapté de l'anglais par
tranfn James
tranln Guerin
location Paris
DROP TABLE t1;
#
# Testing that XPath is case sensitive
#
CREATE TABLE t1
(
isbn CHAR(15) FIELD_FORMAT='@isbn'
) ENGINE=CONNECT TABLE_TYPE=XML FILE_NAME='xsample.xml'
TABNAME='BIBLIO' OPTION_LIST='rownode=BOOK,skipnull=1,xmlsup=domdoc';
SELECT * FROM t1;
isbn NULL
isbn NULL
DROP TABLE t1;
#
# Testing character sets
#
CREATE TABLE t1
(
c CHAR(16)
) ENGINE=CONNECT TABLE_TYPE=XML FILE_NAME='latin1.xml'
OPTION_LIST='xmlsup=domdoc'
DATA_CHARSET=latin1;
ERROR HY000: DATA_CHARSET='latin1' is not supported for TABLE_TYPE=XML
CREATE TABLE t1
(
c CHAR(16)
) ENGINE=CONNECT TABLE_TYPE=XML FILE_NAME='latin1.xml'
OPTION_LIST='xmlsup=domdoc'
DATA_CHARSET=utf8;
SHOW CREATE TABLE t1;
Table t1
Create Table CREATE TABLE `t1` (
`c` char(16) DEFAULT NULL
) ENGINE=CONNECT DEFAULT CHARSET=latin1 `TABLE_TYPE`=XML `FILE_NAME`='latin1.xml' `OPTION_LIST`='xmlsup=domdoc' `DATA_CHARSET`=utf8
SELECT c, HEX(c) FROM t1;
c ÁÂÃÄÅÆÇ
HEX(c) C1C2C3C4C5C6C7
DROP TABLE t1;
CREATE TABLE t1
(
c CHAR(16)
) ENGINE=CONNECT TABLE_TYPE=XML FILE_NAME='latin1.xml'
OPTION_LIST='xmlsup=domdoc';
SELECT c, HEX(c) FROM t1;
c ÁÂÃÄÅÆÇ
HEX(c) C1C2C3C4C5C6C7
DROP TABLE t1;
CREATE TABLE t1
(
c CHAR(16) CHARACTER SET utf8
) ENGINE=CONNECT TABLE_TYPE=XML FILE_NAME='latin1.xml'
OPTION_LIST='xmlsup=domdoc';
SELECT c, HEX(c) FROM t1;
c ÁÂÃÄÅÆÇ
HEX(c) C381C382C383C384C385C386C387
DROP TABLE t1;
#
# Conversion from latin1 to cp1251 produces a warning.
# Question marks are returned.
#
CREATE TABLE t1
(
c CHAR(16) CHARACTER SET cp1251
) ENGINE=CONNECT TABLE_TYPE=XML FILE_NAME='latin1.xml'
OPTION_LIST='xmlsup=domdoc';
SELECT c, HEX(c) FROM t1;
c ???????
HEX(c) 3F3F3F3F3F3F3F
Warnings:
Level Warning
Code 1366
Message Incorrect string value: '\xC3\x81\xC3\x82\xC3\x83...' for column `test`.`t1`.`c` at row 1
Level Warning
Code 1105
Message Out of range value ÁÂÃÄÅÆÇ for column 'c' at row 1
DROP TABLE t1;
#
# Testing Cyrillic
#
#
# Testing that the underlying file is created with a proper Encoding
#
CREATE TABLE t1 (node VARCHAR(50))
CHARACTER SET latin1
ENGINE=connect TABLE_TYPE=xml FILE_NAME='t1.xml'
OPTION_LIST='xmlsup=domdoc,rownode=line,encoding=utf-8';
INSERT INTO t1 VALUES (_latin1 0xC0C1C2C3);
SELECT node, hex(node) FROM t1;
node ÀÁÂÃ
hex(node) C0C1C2C3
DROP TABLE t1;
SET @a=LOAD_FILE('MYSQLD_DATADIR/test/t1.xml');
SELECT LEFT(@a,38);
LEFT(@a,38) <?xml version="1.0" encoding="utf-8"?>
SELECT HEX(EXTRACTVALUE(@a,'/t1/line/node'));
HEX(EXTRACTVALUE(@a,'/t1/line/node')) C380C381C382C383
CREATE TABLE t1 (node VARCHAR(50))
CHARACTER SET latin1
ENGINE=connect TABLE_TYPE=xml FILE_NAME='t1.xml'
OPTION_LIST='xmlsup=domdoc,rownode=line,encoding=iso-8859-1';
INSERT INTO t1 VALUES (_latin1 0xC0C1C2C3);
SELECT node, hex(node) FROM t1;
node ÀÁÂÃ
hex(node) C0C1C2C3
DROP TABLE t1;
SET @a=LOAD_FILE('MYSQLD_DATADIR/test/t1.xml');
SELECT LEFT(@a,43);
LEFT(@a,43) <?xml version="1.0" encoding="iso-8859-1"?>
SELECT HEX(EXTRACTVALUE(@a,'/t1/line/node'));
HEX(EXTRACTVALUE(@a,'/t1/line/node')) C0C1C2C3
#
# Testing XML entities
#
CREATE TABLE t1 (node VARCHAR(50))
CHARACTER SET utf8
ENGINE=connect TABLE_TYPE=xml FILE_NAME='t1.xml'
OPTION_LIST='xmlsup=domdoc,rownode=line,encoding=iso-8859-1';
INSERT INTO t1 VALUES (_latin1 0xC0C1C2C3);
INSERT INTO t1 VALUES (_cp1251 0xC0C1C2C3);
Warnings:
Level Warning
Code 1105
Message warning about characters outside of iso-8859-1
INSERT INTO t1 VALUES ('&<>"\'');
SELECT node, hex(node) FROM t1;
node &<>"'
hex(node) 263C3E2227
DROP TABLE t1;
SET @a=LOAD_FILE('MYSQLD_DATADIR/test/t1.xml');
SELECT CAST(@a AS CHAR CHARACTER SET latin1);
CAST(@a AS CHAR CHARACTER SET latin1) <?xml version="1.0" encoding="iso-8859-1"?>
<!-- Created by the MariaDB CONNECT Storage Engine-->
<t1>
<line>
<node>&<>"'</node>
</line>
</t1>
|