1
SET @xml='<a aa1="aa1" aa2="aa2">a1<b ba1="ba1">b1<c>c1</c>b2</b>a2</a>';
2
SELECT extractValue(@xml,'/a');
3
SELECT extractValue(@xml,'/a/b');
4
SELECT extractValue(@xml,'/a/b/c');
5
SELECT extractValue(@xml,'/a/@aa1');
6
SELECT extractValue(@xml,'/a/@aa2');
7
SELECT extractValue(@xml,'/a/@*');
8
SELECT extractValue(@xml,'//@ba1');
10
SELECT extractValue(@xml,'//a');
11
SELECT extractValue(@xml,'//b');
12
SELECT extractValue(@xml,'//c');
13
SELECT extractValue(@xml,'/a//b');
14
SELECT extractValue(@xml,'/a//c');
15
SELECT extractValue(@xml,'//*');
16
SELECT extractValue(@xml,'/a//*');
17
SELECT extractValue(@xml,'/./a');
18
SELECT extractValue(@xml,'/a/b/.');
19
SELECT extractValue(@xml,'/a/b/..');
20
SELECT extractValue(@xml,'/a/b/../@aa1');
21
SELECT extractValue(@xml,'/*');
22
SELECT extractValue(@xml,'/*/*');
23
SELECT extractValue(@xml,'/*/*/*');
25
SELECT extractValue(@xml,'/a/child::*');
26
SELECT extractValue(@xml,'/a/self::*');
27
SELECT extractValue(@xml,'/a/descendant::*');
28
SELECT extractValue(@xml,'/a/descendant-or-self::*');
29
SELECT extractValue(@xml,'/a/attribute::*');
30
SELECT extractValue(@xml,'/a/b/c/parent::*');
31
SELECT extractValue(@xml,'/a/b/c/ancestor::*');
32
SELECT extractValue(@xml,'/a/b/c/ancestor-or-self::*');
33
SELECT extractValue(@xml,'/descendant-or-self::*');
35
SET @xml='<a>a11<b ba="ba11" ba="ba12">b11</b><b ba="ba21" ba="ba22">b21<c>c1</c>b22</b>a12</a>';
36
SELECT extractValue(@xml,'/a/b/c/ancestor-or-self::*');
37
SELECT extractValue(@xml,'//@ba');
39
SET @xml='<a><b>b</b><c>c</c></a>';
40
SELECT extractValue(@xml,'/a/b');
41
SELECT extractValue(@xml,'/a/c');
42
SELECT extractValue(@xml,'/a/child::b');
43
SELECT extractValue(@xml,'/a/child::c');
45
SET @xml='<a><b>b1</b><c>c1</c><b>b2</b><c>c2</c></a>';
46
SELECT extractValue(@xml,'/a/b[1]');
47
SELECT extractValue(@xml,'/a/b[2]');
48
SELECT extractValue(@xml,'/a/c[1]');
49
SELECT extractValue(@xml,'/a/c[2]');
51
SET @xml='<a><b x="xb1" x="xb2"/><c x="xc1" x="xc2"/></a>';
52
SELECT extractValue(@xml,'/a//@x');
53
SELECT extractValue(@xml,'/a//@x[1]');
54
SELECT extractValue(@xml,'/a//@x[2]');
56
SET @xml='<a><b>b1</b><b>b2</b><c><b>c1b1</b><b>c1b2</b></c><c><b>c2b1</c></b></a>';
57
SELECT extractValue(@xml,'//b[1]');
58
SELECT extractValue(@xml,'/descendant::b[1]');
60
SET @xml='<a><b>b1</b><b>b2</b></a>';
61
SELECT extractValue(@xml,'/a/b[1+0]');
62
SELECT extractValue(@xml,'/a/b[1*1]');
63
SELECT extractValue(@xml,'/a/b[--1]');
64
SELECT extractValue(@xml,'/a/b[2*1-1]');
66
SELECT extractValue(@xml,'/a/b[1+1]');
67
SELECT extractValue(@xml,'/a/b[1*2]');
68
SELECT extractValue(@xml,'/a/b[--2]');
69
SELECT extractValue(@xml,'/a/b[1*(3-1)]');
71
SELECT extractValue(@xml,'//*[1=1]');
72
SELECT extractValue(@xml,'//*[1!=1]');
73
SELECT extractValue(@xml,'//*[1>1]');
74
SELECT extractValue(@xml,'//*[2>1]');
75
SELECT extractValue(@xml,'//*[1>2]');
76
SELECT extractValue(@xml,'//*[1>=1]');
77
SELECT extractValue(@xml,'//*[2>=1]');
78
SELECT extractValue(@xml,'//*[1>=2]');
79
SELECT extractValue(@xml,'//*[1<1]');
80
SELECT extractValue(@xml,'//*[2<1]');
81
SELECT extractValue(@xml,'//*[1<2]');
82
SELECT extractValue(@xml,'//*[1<=1]');
83
SELECT extractValue(@xml,'//*[2<=1]');
84
SELECT extractValue(@xml,'//*[1<=2]');
86
SET @xml='<a><b>b11<c>c11</c></b><b>b21<c>c21</c></b></a>';
87
SELECT extractValue(@xml,'/a/b[c="c11"]');
88
SELECT extractValue(@xml,'/a/b[c="c21"]');
90
SET @xml='<a><b c="c11">b11</b><b c="c21">b21</b></a>';
91
SELECT extractValue(@xml,'/a/b[@c="c11"]');
92
SELECT extractValue(@xml,'/a/b[@c="c21"]');
94
SET @xml='<a>a1<b c="c11">b11<d>d11</d></b><b c="c21">b21<d>d21</d></b></a>';
95
SELECT extractValue(@xml, '/a/b[@c="c11"]/d');
96
SELECT extractValue(@xml, '/a/b[@c="c21"]/d');
97
SELECT extractValue(@xml, '/a/b[d="d11"]/@c');
98
SELECT extractValue(@xml, '/a/b[d="d21"]/@c');
99
SELECT extractValue(@xml, '/a[b="b11"]');
100
SELECT extractValue(@xml, '/a[b/@c="c11"]');
101
SELECT extractValue(@xml, '/a[b/d="d11"]');
102
SELECT extractValue(@xml, '/a[/a/b="b11"]');
103
SELECT extractValue(@xml, '/a[/a/b/@c="c11"]');
104
SELECT extractValue(@xml, '/a[/a/b/d="d11"]');
106
SELECT extractValue('<a>a</a>', '/a[false()]');
107
SELECT extractValue('<a>a</a>', '/a[true()]');
108
SELECT extractValue('<a>a</a>', '/a[not(false())]');
109
SELECT extractValue('<a>a</a>', '/a[not(true())]');
110
SELECT extractValue('<a>a</a>', '/a[true() and true()]');
111
SELECT extractValue('<a>a</a>', '/a[true() and false()]');
112
SELECT extractValue('<a>a</a>', '/a[false()and false()]');
113
SELECT extractValue('<a>a</a>', '/a[false()and true()]');
114
SELECT extractValue('<a>a</a>', '/a[true() or true()]');
115
SELECT extractValue('<a>a</a>', '/a[true() or false()]');
116
SELECT extractValue('<a>a</a>', '/a[false()or false()]');
117
SELECT extractValue('<a>a</a>', '/a[false()or true()]');
119
SET @xml='<a>ab<b c="c" c="e">b1</b><b c="d">b2</b><b c="f" c="e">b3</b></a>';
120
select extractValue(@xml,'/a/b[@c="c"]');
121
select extractValue(@xml,'/a/b[@c="d"]');
122
select extractValue(@xml,'/a/b[@c="e"]');
123
select extractValue(@xml,'/a/b[not(@c="e")]');
124
select extractValue(@xml,'/a/b[@c!="e"]');
125
select extractValue(@xml,'/a/b[@c="c" or @c="d"]');
126
select extractValue(@xml,'/a/b[@c="c" and @c="e"]');
128
SET @xml='<a><b c="c" d="d">b1</b><b d="d" e="e">b2</b></a>';
129
select extractValue(@xml,'/a/b[@c]');
130
select extractValue(@xml,'/a/b[@d]');
131
select extractValue(@xml,'/a/b[@e]');
132
select extractValue(@xml,'/a/b[not(@c)]');
133
select extractValue(@xml,'/a/b[not(@d)]');
134
select extractValue(@xml,'/a/b[not(@e)]');
136
select extractValue(@xml, '/a/b[boolean(@c) or boolean(@d)]');
137
select extractValue(@xml, '/a/b[boolean(@c) or boolean(@e)]');
138
select extractValue(@xml, '/a/b[boolean(@d) or boolean(@e)]');
139
select extractValue(@xml, '/a/b[boolean(@c) and boolean(@d)]');
140
select extractValue(@xml, '/a/b[boolean(@c) and boolean(@e)]');
141
select extractValue(@xml, '/a/b[boolean(@d) and boolean(@e)]');
143
select extractValue(@xml, '/a/b[@c or @d]');
144
select extractValue(@xml, '/a/b[@c or @e]');
145
select extractValue(@xml, '/a/b[@d or @e]');
146
select extractValue(@xml, '/a/b[@c and @d]');
147
select extractValue(@xml, '/a/b[@c and @e]');
148
select extractValue(@xml, '/a/b[@d and @e]');
150
SET @xml='<a><b c="c">b1</b><b>b2</b></a>';
151
SELECT extractValue(@xml,'/a/b[@*]');
152
SELECT extractValue(@xml,'/a/b[not(@*)]');
154
SELECT extractValue('<a>a</a>', '/a[ceiling(3.1)=4]');
155
SELECT extractValue('<a>a</a>', '/a[floor(3.1)=3]');
156
SELECT extractValue('<a>a</a>', '/a[round(3.1)=3]');
157
SELECT extractValue('<a>a</a>', '/a[round(3.8)=4]');
159
SELECT extractValue('<a><b>b</b><c>c</c></a>', '/a/b | /a/c');
161
select extractValue('<a b="b1" b="b2" b="b3"/>','/a/@b[position()=1]');
162
select extractValue('<a b="b1" b="b2" b="b3"/>','/a/@b[position()=2]');
163
select extractValue('<a b="b1" b="b2" b="b3"/>','/a/@b[position()=3]');
164
select extractValue('<a b="b1" b="b2" b="b3"/>','/a/@b[1=position()]');
165
select extractValue('<a b="b1" b="b2" b="b3"/>','/a/@b[2=position()]');
166
select extractValue('<a b="b1" b="b2" b="b3"/>','/a/@b[3=position()]');
167
select extractValue('<a b="b1" b="b2" b="b3"/>','/a/@b[2>=position()]');
168
select extractValue('<a b="b1" b="b2" b="b3"/>','/a/@b[2<=position()]');
169
select extractValue('<a b="b1" b="b2" b="b3"/>','/a/@b[position()=3 or position()=2]');
171
SELECT extractValue('<a>a<b>a1<c>c1</c></b><b>a2</b></a>','/a/b[count(c)=0]');
172
SELECT extractValue('<a>a<b>a1<c>c1</c></b><b>a2</b></a>','/a/b[count(c)=1]');
173
select extractValue('<a>a1<b ba="1" ba="2">b1</b><b>b2</b>4</a>','/a/b[sum(@ba)=3]');
175
select extractValue('<a><b>b1</b><b>b2</b></a>','/a/b[1]');
176
select extractValue('<a><b>b1</b><b>b2</b></a>','/a/b[boolean(1)]');
177
select extractValue('<a><b>b1</b><b>b2</b></a>','/a/b[true()]');
178
select extractValue('<a><b>b1</b><b>b2</b></a>','/a/b[number(true())]');
180
select extractValue('<a>ab</a>','/a[contains("abc","b")]');
181
select extractValue('<a>ab</a>','/a[contains(.,"a")]');
182
select extractValue('<a>ab</a>','/a[contains(.,"b")]');
183
select extractValue('<a>ab</a>','/a[contains(.,"c")]');
185
select extractValue('<a b="1">ab</a>','/a[concat(@b,"2")="12"]');
187
SET @xml='<a b="11" b="12" b="21" b="22">ab</a>';
188
select extractValue(@xml, '/a/@b[substring(.,2)="1"]');
189
select extractValue(@xml, '/a/@b[substring(.,2)="2"]');
190
select extractValue(@xml, '/a/@b[substring(.,1,1)="1"]');
191
select extractValue(@xml, '/a/@b[substring(.,1,1)="2"]');
192
select extractValue(@xml, '/a/@b[substring(.,2,1)="1"]');
193
select extractValue(@xml, '/a/@b[substring(.,2,1)="2"]');
196
# Bug#16319: XML: extractvalue() returns syntax errors for some functions
198
SET @xml='<a><b>b1</b><b>b2</b></a>';
199
SELECT extractValue(@xml, '/a/b[string-length("x")=1]');
200
SELECT extractValue(@xml, '/a/b[string-length("xx")=2]');
201
SELECT extractValue(@xml, '/a/b[string-length("xxx")=2]');
202
SELECT extractValue(@xml, '/a/b[string-length("x")]');
203
SELECT extractValue(@xml, '/a/b[string-length("xx")]');
204
SELECT extractValue(@xml, '/a/b[string-length()]');
206
SELECT extractValue(@xml, 'string-length()');
207
SELECT extractValue(@xml, 'string-length("x")');
209
SET @xml='<a b="b11" b="b12" b="b21" b="22"/>';
210
select extractValue(@xml,'/a/@b');
211
select extractValue(@xml,'/a/@b[contains(.,"1")]');
212
select extractValue(@xml,'/a/@b[contains(.,"1")][contains(.,"2")]');
213
select extractValue(@xml,'/a/@b[contains(.,"1")][contains(.,"2")][2]');
215
SET @xml='<a>a1<b>b1<c>c1</c>b2</b>a2</a>';
216
select UpdateXML('<a>a1<b>b1<c>c1</c>b2</b>a2</a>','/a/b/c','+++++++++');
217
select UpdateXML('<a>a1<b>b1<c>c1</c>b2</b>a2</a>','/a/b/c','<c1>+++++++++</c1>');
218
select UpdateXML('<a>a1<b>b1<c>c1</c>b2</b>a2</a>','/a/b/c','<c1/>');
220
SET @xml='<a><b>bb</b></a>';
221
select UpdateXML(@xml, '/a/b', '<b>ccc</b>');
223
SET @xml='<a aa1="aa1" aa2="aa2"><b bb1="bb1" bb2="bb2">bb</b></a>';
224
select UpdateXML(@xml, '/a/b', '<b>ccc</b>');
225
select UpdateXML(@xml, '/a/@aa1', '');
226
select UpdateXML(@xml, '/a/@aa1', 'aa3="aa3"');
227
select UpdateXML(@xml, '/a/@aa2', '');
228
select UpdateXML(@xml, '/a/@aa2', 'aa3="aa3"');
229
select UpdateXML(@xml, '/a/b/@bb1', '');
230
select UpdateXML(@xml, '/a/b/@bb1', 'bb3="bb3"');
231
select UpdateXML(@xml, '/a/b/@bb2', '');
232
select UpdateXML(@xml, '/a/b/@bb2', 'bb3="bb3"');
235
# Bug#27898 UPDATEXML Crashes the Server!
237
select updatexml('<div><div><span>1</span><span>2</span></div></div>',
238
'/','<tr><td>1</td><td>2</td></tr>') as upd1;
239
select updatexml('', '/', '') as upd2;
242
# Bug#16234 XML: Crash if ExtractValue()
244
SET @xml= '<order><clerk>lesser wombat</clerk></order>';
245
select extractvalue(@xml,'order/clerk');
246
select extractvalue(@xml,'/order/clerk');
249
# Bug#16314 XML: extractvalue() crash if vertical bar
251
select extractvalue('<a><b>B</b></a>','/a|/b');
252
select extractvalue('<a><b>B</b></a>','/a|b');
253
select extractvalue('<a>a<b>B</b></a>','/a|/b');
254
select extractvalue('<a>a<b>B</b></a>','/a|b');
255
select extractvalue('<a>a<b>B</b></a>','a|/b');
258
# Bug#16312 XML: extractvalue() crash if angle brackets
261
select extractvalue('<a>A</a>','/<a>');
264
# Bug#16313 XML: extractvalue() ignores '!' in names
267
select extractvalue('<a><b>b</b><b!>b!</b!></a>','//b!');
270
# Bug #16315 XML: extractvalue() handles self badly
272
select extractvalue('<a>A<b>B<c>C</c></b></a>','/a/descendant::*');
273
select extractvalue('<a>A<b>B<c>C</c></b></a>','/a/self::*');
274
select extractvalue('<a>A<b>B<c>C</c></b></a>','/a/descendant-or-self::*');
275
# Bug #16320 XML: extractvalue() won't accept names containing underscores
277
select extractvalue('<A_B>A</A_B>','/A_B');
280
# Bug#16318: XML: extractvalue() incorrectly returns last() = 1
282
select extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[position()]');
283
select extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[count(.)=last()]');
284
select extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[last()]');
285
select extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[last()-1]');
286
select extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[last()=1]');
287
select extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[last()=2]');
288
select extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[last()=position()]');
289
select extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[count(.)]');
290
select extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[count(.)-1]');
291
select extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[count(.)=1]');
292
select extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[count(.)=2]');
293
select extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[count(.)=position()]');
295
# Bug#16316: XML: extractvalue() is case-sensitive with contains()
297
select extractvalue('<a>Jack</a>','/a[contains(../a,"J")]');
298
select extractvalue('<a>Jack</a>','/a[contains(../a,"j")]');
299
select extractvalue('<a>Jack</a>','/a[contains(../a,"j")]' collate latin1_bin);
300
select extractvalue('<a>Jack</a>' collate latin1_bin,'/a[contains(../a,"j")]');
303
# Bug#18285: ExtractValue not returning character
304
# data within <![CDATA[]]> as expected
306
select ExtractValue('<tag1><![CDATA[test]]></tag1>','/tag1');
309
# Bug#18201: XML: ExtractValue works even if the xml fragment
310
# is not well-formed xml
312
select extractValue('<a>a','/a');
313
select extractValue('<a>a<','/a');
314
select extractValue('<a>a</','/a');
315
select extractValue('<a>a</a','/a');
316
select extractValue('<a>a</a></b>','/a');
317
select extractValue('<a b=>a</a>','/a');
320
# Bug #18171 XML: ExtractValue: the XPath position()
321
# function crashes the server!
324
select extractValue('<e>1</e>','position()');
326
select extractValue('<e>1</e>','last()');
330
# Bug #18172 XML: Extractvalue() accepts mallformed
331
# XPath without a XPath syntax error
334
select extractValue('<e><a>1</a></e>','/e/');
337
# Bug#16233: XML: ExtractValue() fails with special characters
340
select extractValue('<Ñ><r>r</r></Ñ>','/Ñ/r');
341
select extractValue('<r><Ñ>Ñ</Ñ></r>','/r/Ñ');
342
select extractValue('<Ñ r="r"/>','/Ñ/@r');
343
select extractValue('<r Ñ="Ñ"/>','/r/@Ñ');
345
DROP PROCEDURE IF EXISTS p2;
348
CREATE PROCEDURE p2 ()
350
DECLARE p LONGTEXT CHARACTER SET UTF8 DEFAULT '<Ñ><r>A</r></Ñ>';
351
SELECT EXTRACTVALUE(p,'/Ñ/r');
358
# Bug#18170: XML: ExtractValue():
359
# XPath expression can't use QNames (colon in names)
361
select extractValue('<ns:element xmlns:ns="myns"/>','count(ns:element)');
362
select extractValue('<ns:element xmlns:ns="myns">a</ns:element>','/ns:element');
363
select extractValue('<ns:element xmlns:ns="myns">a</ns:element>','/ns:element/@xmlns:ns');
366
# Bug#20795 extractvalue() won't accept names containing a dot (.)
368
select extractValue('<foo><foo.bar>Data</foo.bar><something>Otherdata</something></foo>','/foo/foo.bar');
369
select extractValue('<foo><foo.bar>Data</foo.bar><something>Otherdata</something></foo>','/foo/something');
372
# Bug#20854 XML functions: wrong result in ExtractValue
375
select extractValue('<zot><tim0><01>10:39:15</01><02>140</02></tim0></zot>','/zot/tim0/02');
376
select extractValue('<zot><tim0><01>10:39:15</01><02>140</02></tim0></zot>','//*');
377
# dot and dash are bad identtifier start character
378
select extractValue('<.>test</.>','//*');
379
select extractValue('<->test</->','//*');
380
# semicolon is good identifier start character
381
select extractValue('<:>test</:>','//*');
382
# underscore is good identifier start character
383
select extractValue('<_>test</_>','//*');
384
# dot, dash, underscore and semicolon are good identifier middle characters
385
select extractValue('<x.-_:>test</x.-_:>','//*');
388
# Bug#22823 gt and lt operators appear to be
389
# reversed in ExtractValue() command
391
set @xml= "<entry><id>pt10</id><pt>10</pt></entry><entry><id>pt50</id><pt>50</pt></entry>";
392
select ExtractValue(@xml, "/entry[(pt=10)]/id");
393
select ExtractValue(@xml, "/entry[(pt!=10)]/id");
394
select ExtractValue(@xml, "/entry[(pt<10)]/id");
395
select ExtractValue(@xml, "/entry[(pt<=10)]/id");
396
select ExtractValue(@xml, "/entry[(pt>10)]/id");
397
select ExtractValue(@xml, "/entry[(pt>=10)]/id");
398
select ExtractValue(@xml, "/entry[(pt=50)]/id");
399
select ExtractValue(@xml, "/entry[(pt!=50)]/id");
400
select ExtractValue(@xml, "/entry[(pt<50)]/id");
401
select ExtractValue(@xml, "/entry[(pt<=50)]/id");
402
select ExtractValue(@xml, "/entry[(pt>50)]/id");
403
select ExtractValue(@xml, "/entry[(pt>=50)]/id");
404
select ExtractValue(@xml, "/entry[(10=pt)]/id");
405
select ExtractValue(@xml, "/entry[(10!=pt)]/id");
406
select ExtractValue(@xml, "/entry[(10>pt)]/id");
407
select ExtractValue(@xml, "/entry[(10>=pt)]/id");
408
select ExtractValue(@xml, "/entry[(10<pt)]/id");
409
select ExtractValue(@xml, "/entry[(10<=pt)]/id");
410
select ExtractValue(@xml, "/entry[(50=pt)]/id");
411
select ExtractValue(@xml, "/entry[(50!=pt)]/id");
412
select ExtractValue(@xml, "/entry[(50>pt)]/id");
413
select ExtractValue(@xml, "/entry[(50>=pt)]/id");
414
select ExtractValue(@xml, "/entry[(50<pt)]/id");
415
select ExtractValue(@xml, "/entry[(50<=pt)]/id");
418
# Bug#24747 XPath error with the node name "Text"
421
# Test nodetypes in node name context
423
select ExtractValue('<a><b><Text>test</Text></b></a>','/a/b/Text');
424
select ExtractValue('<a><b><comment>test</comment></b></a>','/a/b/comment');
425
select ExtractValue('<a><b><node>test</node></b></a>','/a/b/node');
426
select ExtractValue('<a><b><processing-instruction>test</processing-instruction></b></a>','/a/b/processing-instruction');
428
# Test keywords in node name contexts
430
select ExtractValue('<a><and>test</and></a>', '/a/and');
431
select ExtractValue('<a><or>test</or></a>', '/a/or');
432
select ExtractValue('<a><mod>test</mod></a>', '/a/mod');
433
select ExtractValue('<a><div>test</div></a>', '/a/div');
434
select ExtractValue('<a><and:and>test</and:and></a>', '/a/and:and');
435
select ExtractValue('<a><or:or>test</or:or></a>', '/a/or:or');
436
select ExtractValue('<a><mod:mod>test</mod:mod></a>', '/a/mod:mod');
437
select ExtractValue('<a><div:div>test</div:div></a>', '/a/div:div');
439
# Test axis names in node name context
441
select ExtractValue('<a><ancestor>test</ancestor></a>', '/a/ancestor');
442
select ExtractValue('<a><ancestor-or-self>test</ancestor-or-self></a>', '/a/ancestor-or-self');
443
select ExtractValue('<a><attribute>test</attribute></a>', '/a/attribute');
444
select ExtractValue('<a><child>test</child></a>', '/a/child');
445
select ExtractValue('<a><descendant>test</descendant></a>', '/a/descendant');
446
select ExtractValue('<a><descendant-or-self>test</descendant-or-self></a>', '/a/descendant-or-self');
447
select ExtractValue('<a><following>test</following></a>', '/a/following');
448
select ExtractValue('<a><following-sibling>test</following-sibling></a>', '/a/following-sibling');
449
select ExtractValue('<a><namespace>test</namespace></a>', '/a/namespace');
450
select ExtractValue('<a><parent>test</parent></a>', '/a/parent');
451
select ExtractValue('<a><preceding>test</preceding></a>', '/a/preceding');
452
select ExtractValue('<a><preceding-sibling>test</preceding-sibling></a>', '/a/preceding-sibling');
453
select ExtractValue('<a><self>test</self></a>', '/a/self');
456
# Bug#26518 XPath and variables problem
457
# Check with user defined variables
460
select ExtractValue('<a><b>b1</b><b>b2</b></a>','/a/b[$@i]');
462
select ExtractValue('<a><b>b1</b><b>b2</b></a>','/a/b[$@i]');
464
select ExtractValue('<a><b>b1</b><b>b2</b></a>','/a/b[$@i]');
467
# Check variables in a stored procedure - both local and user variables
468
# Make sure that SP and local variables with the same name work together.
471
CREATE PROCEDURE spxml(xml VARCHAR(128))
474
DECLARE i INT DEFAULT 1;
475
SET c= ExtractValue(xml,'count(/a/b)');
479
SELECT i, @i, ExtractValue(xml,'/a/b[$i]'), ExtractValue(xml,'/a/b[$@i]');
487
call spxml('<a><b>b1</b><b>b2</b><b>b3</b></a>');
488
drop procedure spxml;
491
# Additional tests for bug#26518
492
--echo Multiple matches, but no index specification
493
SELECT ExtractValue('<a><b>b1</b><b>b2</b></a>','/a/b');
495
SELECT ExtractValue('<a><b>b1</b><b>b2</b></a>','/a/c');
496
--echo Index out of range
497
SELECT ExtractValue('<a><b>b1</b><b>b2</b></a>','/a/b[-1]');
498
SELECT ExtractValue('<a><b>b1</b><b>b2</b></a>','/a/b[10]');
499
--echo With string-to-number conversion
500
SELECT ExtractValue('<a><b>b1</b><b>b2</b></a>','/a/b["1"]');
501
SELECT ExtractValue('<a><b>b1</b><b>b2</b></a>','/a/b["1 and string"]');
502
SELECT ExtractValue('<a><b>b1</b><b>b2</b></a>','/a/b["string and 1"]');
503
SELECT ExtractValue('<a><b>b1</b><b>b2</b></a>','/a/b["string"]');
504
--echo String-to-number conversion from a user variable
506
SELECT ExtractValue('<a><b>b1</b><b>b2</b></a>','/a/b[$@i]');
507
SET @i='1 and string';
508
SELECT ExtractValue('<a><b>b1</b><b>b2</b></a>','/a/b[$@i]');
509
SET @i='string and 1';
510
SELECT ExtractValue('<a><b>b1</b><b>b2</b></a>','/a/b[$@i]');
512
SELECT ExtractValue('<a><b>b1</b><b>b2</b></a>','/a/b[$@i]');
514
--echo String-to-number conversion with a CHAR SP variable
516
CREATE PROCEDURE spxml(xml VARCHAR(128), i CHAR(16))
518
SELECT ExtractValue(xml,'/a/b[$i]');
521
CALL spxml('<a><b>b1</b><b>b2</b></a>', '1');
522
CALL spxml('<a><b>b1</b><b>b2</b></a>', '1 and string');
523
CALL spxml('<a><b>b1</b><b>b2</b></a>', 'string and 1');
524
CALL spxml('<a><b>b1</b><b>b2</b></a>', 'string');
525
DROP PROCEDURE spxml;
528
# Bug#28558 UpdateXML called with garbage crashes server
531
select UpdateXML('<a>a</a>',repeat('a b ',1000),'');
533
select ExtractValue('<a>a</a>', '/a[@x=@y0123456789_0123456789_0123456789_0123456789]');
535
select ExtractValue('<a>a</a>', '/a[@x=$y0123456789_0123456789_0123456789_0123456789]');
538
# Bug #31438: updatexml still crashes
541
select updatexml(NULL, 1, 1), updatexml(1, NULL, 1), updatexml(1, 1, NULL);
542
select updatexml(NULL, NULL, 1), updatexml(1, NULL, NULL),
543
updatexml(NULL, 1, NULL);
544
select updatexml(NULL, NULL, NULL);
547
# Bug #32557: order by updatexml causes assertion in filesort
549
CREATE TABLE t1(a INT NOT NULL);
550
INSERT INTO t1 VALUES (0), (0);
551
SELECT 1 FROM t1 ORDER BY(UPDATEXML(a, '1', '1'));
554
--echo End of 5.1 tests