summaryrefslogtreecommitdiff
path: root/mysql-test/t/xml.test
blob: c20c4cbccc1ede67e8618be10fcf574e3eecc9a2 (plain)
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
SET @xml='<a aa1="aa1" aa2="aa2">a1<b ba1="ba1">b1<c>c1</c>b2</b>a2</a>';
SELECT extractValue(@xml,'/a');
SELECT extractValue(@xml,'/a/b');
SELECT extractValue(@xml,'/a/b/c');
SELECT extractValue(@xml,'/a/@aa1');
SELECT extractValue(@xml,'/a/@aa2');
SELECT extractValue(@xml,'/a/@*');
SELECT extractValue(@xml,'//@ba1');

SELECT extractValue(@xml,'//a');
SELECT extractValue(@xml,'//b');
SELECT extractValue(@xml,'//c');
SELECT extractValue(@xml,'/a//b');
SELECT extractValue(@xml,'/a//c');
SELECT extractValue(@xml,'//*');
SELECT extractValue(@xml,'/a//*');
SELECT extractValue(@xml,'/./a');
SELECT extractValue(@xml,'/a/b/.');
SELECT extractValue(@xml,'/a/b/..');
SELECT extractValue(@xml,'/a/b/../@aa1');
SELECT extractValue(@xml,'/*');
SELECT extractValue(@xml,'/*/*');
SELECT extractValue(@xml,'/*/*/*');

SELECT extractValue(@xml,'/a/child::*');
SELECT extractValue(@xml,'/a/self::*');
SELECT extractValue(@xml,'/a/descendant::*');
SELECT extractValue(@xml,'/a/descendant-or-self::*');
SELECT extractValue(@xml,'/a/attribute::*');
SELECT extractValue(@xml,'/a/b/c/parent::*');
SELECT extractValue(@xml,'/a/b/c/ancestor::*');
SELECT extractValue(@xml,'/a/b/c/ancestor-or-self::*');
SELECT extractValue(@xml,'/descendant-or-self::*');

SET @xml='<a>a11<b ba="ba11" ba="ba12">b11</b><b ba="ba21" ba="ba22">b21<c>c1</c>b22</b>a12</a>';
SELECT extractValue(@xml,'/a/b/c/ancestor-or-self::*');
SELECT extractValue(@xml,'//@ba');

SET @xml='<a><b>b</b><c>c</c></a>';
SELECT extractValue(@xml,'/a/b');
SELECT extractValue(@xml,'/a/c');
SELECT extractValue(@xml,'/a/child::b');
SELECT extractValue(@xml,'/a/child::c');

SET @xml='<a><b>b1</b><c>c1</c><b>b2</b><c>c2</c></a>';
SELECT extractValue(@xml,'/a/b[1]');
SELECT extractValue(@xml,'/a/b[2]');
SELECT extractValue(@xml,'/a/c[1]');
SELECT extractValue(@xml,'/a/c[2]');

SET @xml='<a><b x="xb1" x="xb2"/><c x="xc1" x="xc2"/></a>';
SELECT extractValue(@xml,'/a//@x');
SELECT extractValue(@xml,'/a//@x[1]');
SELECT extractValue(@xml,'/a//@x[2]');

SET @xml='<a><b>b1</b><b>b2</b><c><b>c1b1</b><b>c1b2</b></c><c><b>c2b1</c></b></a>';
SELECT extractValue(@xml,'//b[1]');
SELECT extractValue(@xml,'/descendant::b[1]');

SET @xml='<a><b>b1</b><b>b2</b></a>';
SELECT extractValue(@xml,'/a/b[1+0]');
SELECT extractValue(@xml,'/a/b[1*1]');
SELECT extractValue(@xml,'/a/b[--1]');
SELECT extractValue(@xml,'/a/b[2*1-1]');

SELECT extractValue(@xml,'/a/b[1+1]');
SELECT extractValue(@xml,'/a/b[1*2]');
SELECT extractValue(@xml,'/a/b[--2]');
SELECT extractValue(@xml,'/a/b[1*(3-1)]');

SELECT extractValue(@xml,'//*[1=1]');
SELECT extractValue(@xml,'//*[1!=1]');
SELECT extractValue(@xml,'//*[1>1]');
SELECT extractValue(@xml,'//*[2>1]');
SELECT extractValue(@xml,'//*[1>2]');
SELECT extractValue(@xml,'//*[1>=1]');
SELECT extractValue(@xml,'//*[2>=1]');
SELECT extractValue(@xml,'//*[1>=2]');
SELECT extractValue(@xml,'//*[1<1]');
SELECT extractValue(@xml,'//*[2<1]');
SELECT extractValue(@xml,'//*[1<2]');
SELECT extractValue(@xml,'//*[1<=1]');
SELECT extractValue(@xml,'//*[2<=1]');
SELECT extractValue(@xml,'//*[1<=2]');

SET @xml='<a><b>b11<c>c11</c></b><b>b21<c>c21</c></b></a>';
SELECT extractValue(@xml,'/a/b[c="c11"]');
SELECT extractValue(@xml,'/a/b[c="c21"]');

SET @xml='<a><b c="c11">b11</b><b c="c21">b21</b></a>';
SELECT extractValue(@xml,'/a/b[@c="c11"]');
SELECT extractValue(@xml,'/a/b[@c="c21"]');

SET @xml='<a>a1<b c="c11">b11<d>d11</d></b><b c="c21">b21<d>d21</d></b></a>';
SELECT extractValue(@xml, '/a/b[@c="c11"]/d');
SELECT extractValue(@xml, '/a/b[@c="c21"]/d');
SELECT extractValue(@xml, '/a/b[d="d11"]/@c');
SELECT extractValue(@xml, '/a/b[d="d21"]/@c');
SELECT extractValue(@xml, '/a[b="b11"]');
SELECT extractValue(@xml, '/a[b/@c="c11"]');
SELECT extractValue(@xml, '/a[b/d="d11"]');
SELECT extractValue(@xml, '/a[/a/b="b11"]');
SELECT extractValue(@xml, '/a[/a/b/@c="c11"]');
SELECT extractValue(@xml, '/a[/a/b/d="d11"]');

SELECT extractValue('<a>a</a>', '/a[false()]');
SELECT extractValue('<a>a</a>', '/a[true()]');
SELECT extractValue('<a>a</a>', '/a[not(false())]');
SELECT extractValue('<a>a</a>', '/a[not(true())]');
SELECT extractValue('<a>a</a>', '/a[true() and true()]');
SELECT extractValue('<a>a</a>', '/a[true() and false()]');
SELECT extractValue('<a>a</a>', '/a[false()and false()]');
SELECT extractValue('<a>a</a>', '/a[false()and true()]');
SELECT extractValue('<a>a</a>', '/a[true() or true()]');
SELECT extractValue('<a>a</a>', '/a[true() or false()]');
SELECT extractValue('<a>a</a>', '/a[false()or false()]');
SELECT extractValue('<a>a</a>', '/a[false()or true()]');

SET @xml='<a>ab<b c="c" c="e">b1</b><b c="d">b2</b><b c="f" c="e">b3</b></a>';
select extractValue(@xml,'/a/b[@c="c"]');
select extractValue(@xml,'/a/b[@c="d"]');
select extractValue(@xml,'/a/b[@c="e"]');
select extractValue(@xml,'/a/b[not(@c="e")]');
select extractValue(@xml,'/a/b[@c!="e"]');
select extractValue(@xml,'/a/b[@c="c" or @c="d"]');
select extractValue(@xml,'/a/b[@c="c" and @c="e"]');

SET @xml='<a><b c="c" d="d">b1</b><b d="d" e="e">b2</b></a>';
select extractValue(@xml,'/a/b[@c]');
select extractValue(@xml,'/a/b[@d]');
select extractValue(@xml,'/a/b[@e]');
select extractValue(@xml,'/a/b[not(@c)]');
select extractValue(@xml,'/a/b[not(@d)]');
select extractValue(@xml,'/a/b[not(@e)]');

select extractValue(@xml, '/a/b[boolean(@c) or boolean(@d)]');
select extractValue(@xml, '/a/b[boolean(@c) or boolean(@e)]');
select extractValue(@xml, '/a/b[boolean(@d) or boolean(@e)]');
select extractValue(@xml, '/a/b[boolean(@c) and boolean(@d)]');
select extractValue(@xml, '/a/b[boolean(@c) and boolean(@e)]');
select extractValue(@xml, '/a/b[boolean(@d) and boolean(@e)]');

select extractValue(@xml, '/a/b[@c or @d]');
select extractValue(@xml, '/a/b[@c or @e]');
select extractValue(@xml, '/a/b[@d or @e]');
select extractValue(@xml, '/a/b[@c and @d]');
select extractValue(@xml, '/a/b[@c and @e]');
select extractValue(@xml, '/a/b[@d and @e]');

SET @xml='<a><b c="c">b1</b><b>b2</b></a>';
SELECT extractValue(@xml,'/a/b[@*]');
SELECT extractValue(@xml,'/a/b[not(@*)]');

SELECT extractValue('<a>a</a>', '/a[ceiling(3.1)=4]');
SELECT extractValue('<a>a</a>', '/a[floor(3.1)=3]');
SELECT extractValue('<a>a</a>', '/a[round(3.1)=3]');
SELECT extractValue('<a>a</a>', '/a[round(3.8)=4]');

SELECT extractValue('<a><b>b</b><c>c</c></a>', '/a/b | /a/c');

select extractValue('<a b="b1" b="b2" b="b3"/>','/a/@b[position()=1]');
select extractValue('<a b="b1" b="b2" b="b3"/>','/a/@b[position()=2]');
select extractValue('<a b="b1" b="b2" b="b3"/>','/a/@b[position()=3]');
select extractValue('<a b="b1" b="b2" b="b3"/>','/a/@b[1=position()]');
select extractValue('<a b="b1" b="b2" b="b3"/>','/a/@b[2=position()]');
select extractValue('<a b="b1" b="b2" b="b3"/>','/a/@b[3=position()]');
select extractValue('<a b="b1" b="b2" b="b3"/>','/a/@b[2>=position()]');
select extractValue('<a b="b1" b="b2" b="b3"/>','/a/@b[2<=position()]');
select extractValue('<a b="b1" b="b2" b="b3"/>','/a/@b[position()=3 or position()=2]');

SELECT extractValue('<a>a<b>a1<c>c1</c></b><b>a2</b></a>','/a/b[count(c)=0]');
SELECT extractValue('<a>a<b>a1<c>c1</c></b><b>a2</b></a>','/a/b[count(c)=1]');
select extractValue('<a>a1<b ba="1" ba="2">b1</b><b>b2</b>4</a>','/a/b[sum(@ba)=3]');

select extractValue('<a><b>b1</b><b>b2</b></a>','/a/b[1]');
select extractValue('<a><b>b1</b><b>b2</b></a>','/a/b[boolean(1)]');
select extractValue('<a><b>b1</b><b>b2</b></a>','/a/b[true()]');
select extractValue('<a><b>b1</b><b>b2</b></a>','/a/b[number(true())]');

select extractValue('<a>ab</a>','/a[contains("abc","b")]');
select extractValue('<a>ab</a>','/a[contains(.,"a")]');
select extractValue('<a>ab</a>','/a[contains(.,"b")]');
select extractValue('<a>ab</a>','/a[contains(.,"c")]');

select extractValue('<a b="1">ab</a>','/a[concat(@b,"2")="12"]');

SET @xml='<a b="11" b="12" b="21" b="22">ab</a>';
select extractValue(@xml, '/a/@b[substring(.,2)="1"]');
select extractValue(@xml, '/a/@b[substring(.,2)="2"]');
select extractValue(@xml, '/a/@b[substring(.,1,1)="1"]');
select extractValue(@xml, '/a/@b[substring(.,1,1)="2"]');
select extractValue(@xml, '/a/@b[substring(.,2,1)="1"]');
select extractValue(@xml, '/a/@b[substring(.,2,1)="2"]');

#
# Bug#16319: XML: extractvalue() returns syntax errors for some functions
#
SET @xml='<a><b>b1</b><b>b2</b></a>';
SELECT extractValue(@xml, '/a/b[string-length("x")=1]');
SELECT extractValue(@xml, '/a/b[string-length("xx")=2]');
SELECT extractValue(@xml, '/a/b[string-length("xxx")=2]');
SELECT extractValue(@xml, '/a/b[string-length("x")]');
SELECT extractValue(@xml, '/a/b[string-length("xx")]');
SELECT extractValue(@xml, '/a/b[string-length()]');
--error 1105
SELECT extractValue(@xml, 'string-length()');
SELECT extractValue(@xml, 'string-length("x")');

SET @xml='<a b="b11" b="b12" b="b21" b="22"/>';
select extractValue(@xml,'/a/@b');
select extractValue(@xml,'/a/@b[contains(.,"1")]');
select extractValue(@xml,'/a/@b[contains(.,"1")][contains(.,"2")]');
select extractValue(@xml,'/a/@b[contains(.,"1")][contains(.,"2")][2]');

SET @xml='<a>a1<b>b1<c>c1</c>b2</b>a2</a>';
select UpdateXML('<a>a1<b>b1<c>c1</c>b2</b>a2</a>','/a/b/c','+++++++++');
select UpdateXML('<a>a1<b>b1<c>c1</c>b2</b>a2</a>','/a/b/c','<c1>+++++++++</c1>');
select UpdateXML('<a>a1<b>b1<c>c1</c>b2</b>a2</a>','/a/b/c','<c1/>');

SET @xml='<a><b>bb</b></a>';
select UpdateXML(@xml, '/a/b', '<b>ccc</b>');

SET @xml='<a aa1="aa1" aa2="aa2"><b bb1="bb1" bb2="bb2">bb</b></a>';
select UpdateXML(@xml, '/a/b', '<b>ccc</b>');
select UpdateXML(@xml, '/a/@aa1', '');
select UpdateXML(@xml, '/a/@aa1', 'aa3="aa3"');
select UpdateXML(@xml, '/a/@aa2', '');
select UpdateXML(@xml, '/a/@aa2', 'aa3="aa3"');
select UpdateXML(@xml, '/a/b/@bb1', '');
select UpdateXML(@xml, '/a/b/@bb1', 'bb3="bb3"');
select UpdateXML(@xml, '/a/b/@bb2', '');
select UpdateXML(@xml, '/a/b/@bb2', 'bb3="bb3"');

#
#  Bug#16234 XML: Crash if ExtractValue()
#
SET @xml= '<order><clerk>lesser wombat</clerk></order>';
select extractvalue(@xml,'order/clerk');
select extractvalue(@xml,'/order/clerk');

#
# Bug#16314 XML: extractvalue() crash if vertical bar
#
select extractvalue('<a><b>B</b></a>','/a|/b');
select extractvalue('<a><b>B</b></a>','/a|b');
select extractvalue('<a>a<b>B</b></a>','/a|/b');
select extractvalue('<a>a<b>B</b></a>','/a|b');
select extractvalue('<a>a<b>B</b></a>','a|/b');

#
# Bug#16312 XML: extractvalue() crash if angle brackets
#
--error 1105
select extractvalue('<a>A</a>','/<a>');

#
# Bug#16313 XML: extractvalue() ignores '!' in names
#
--error 1105
select extractvalue('<a><b>b</b><b!>b!</b!></a>','//b!');

#
# Bug #16315 XML: extractvalue() handles self badly
#
select extractvalue('<a>A<b>B<c>C</c></b></a>','/a/descendant::*');
select extractvalue('<a>A<b>B<c>C</c></b></a>','/a/self::*');
select extractvalue('<a>A<b>B<c>C</c></b></a>','/a/descendant-or-self::*');
# Bug #16320 XML: extractvalue() won't accept names containing underscores
#
select extractvalue('<A_B>A</A_B>','/A_B');

#
# Bug#16318: XML: extractvalue() incorrectly returns last() = 1
#
select extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[position()]');
select extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[count(.)=last()]');
select extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[last()]');
select extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[last()-1]');
select extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[last()=1]');
select extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[last()=2]');
select extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[last()=position()]');
select extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[count(.)]');
select extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[count(.)-1]');
select extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[count(.)=1]');
select extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[count(.)=2]');
select extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[count(.)=position()]');
#
# Bug#16316: XML: extractvalue() is case-sensitive with contains()
#
select extractvalue('<a>Jack</a>','/a[contains(../a,"J")]');
select extractvalue('<a>Jack</a>','/a[contains(../a,"j")]');
select extractvalue('<a>Jack</a>','/a[contains(../a,"j")]' collate latin1_bin);
select extractvalue('<a>Jack</a>' collate latin1_bin,'/a[contains(../a,"j")]');

#
# Bug#18285: ExtractValue not returning character
# data within <![CDATA[]]> as expected
#
select ExtractValue('<tag1><![CDATA[test]]></tag1>','/tag1');

#
# Bug#18201: XML: ExtractValue works even if the xml fragment
# is not well-formed xml
#
select extractValue('<a>a','/a');
select extractValue('<a>a<','/a');
select extractValue('<a>a</','/a');
select extractValue('<a>a</a','/a');
select extractValue('<a>a</a></b>','/a');
select extractValue('<a b=>a</a>','/a');

#
# Bug #18171 XML: ExtractValue: the XPath position()
# function crashes the server!
#
--error 1105
select extractValue('<e>1</e>','position()');
--error 1105
select extractValue('<e>1</e>','last()');


#
# Bug #18172 XML: Extractvalue() accepts mallformed
# XPath without a XPath syntax error
#
--error 1105
select extractValue('<e><a>1</a></e>','/e/');

#
# Bug#16233: XML: ExtractValue() fails with special characters
#
set names utf8;
select extractValue('<Ñ><r>r</r></Ñ>','/Ñ/r');
select extractValue('<r><Ñ>Ñ</Ñ></r>','/r/Ñ');
select extractValue('<Ñ r="r"/>','/Ñ/@r');
select extractValue('<r Ñ="Ñ"/>','/r/@Ñ');
--disable_warnings
DROP PROCEDURE IF EXISTS p2;
--enable_warnings
DELIMITER //;
CREATE PROCEDURE p2 ()
BEGIN
 DECLARE p LONGTEXT CHARACTER SET UTF8 DEFAULT '<Ñ><r>A</r></Ñ>';
 SELECT EXTRACTVALUE(p,'/Ñ/r');
END//
DELIMITER ;//
CALL p2();
DROP PROCEDURE p2;

#
# Bug#18170: XML: ExtractValue():
# XPath expression can't use QNames (colon in names)
#
select extractValue('<ns:element xmlns:ns="myns"/>','count(ns:element)');
select extractValue('<ns:element xmlns:ns="myns">a</ns:element>','/ns:element');
select extractValue('<ns:element xmlns:ns="myns">a</ns:element>','/ns:element/@xmlns:ns');