1
by brian
clean slate |
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'); |
|
9 |
||
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,'/*/*/*'); |
|
24 |
||
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::*'); |
|
34 |
||
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'); |
|
38 |
||
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'); |
|
44 |
||
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]'); |
|
50 |
||
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]'); |
|
55 |
||
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]'); |
|
59 |
||
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]'); |
|
65 |
||
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)]'); |
|
70 |
||
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]'); |
|
85 |
||
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"]'); |
|
89 |
||
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"]'); |
|
93 |
||
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"]'); |
|
105 |
||
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()]'); |
|
118 |
||
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"]'); |
|
127 |
||
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)]'); |
|
135 |
||
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)]'); |
|
142 |
||
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]'); |
|
149 |
||
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(@*)]'); |
|
153 |
||
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]'); |
|
158 |
||
159 |
SELECT extractValue('<a><b>b</b><c>c</c></a>', '/a/b | /a/c'); |
|
160 |
||
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]'); |
|
170 |
||
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]'); |
|
174 |
||
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())]'); |
|
179 |
||
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")]'); |
|
184 |
||
185 |
select extractValue('<a b="1">ab</a>','/a[concat(@b,"2")="12"]'); |
|
186 |
||
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"]'); |
|
194 |
||
195 |
# |
|
196 |
# Bug#16319: XML: extractvalue() returns syntax errors for some functions |
|
197 |
# |
|
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()]'); |
|
205 |
--error 1105 |
|
206 |
SELECT extractValue(@xml, 'string-length()'); |
|
207 |
SELECT extractValue(@xml, 'string-length("x")'); |
|
208 |
||
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]'); |
|
214 |
||
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/>'); |
|
219 |
||
220 |
SET @xml='<a><b>bb</b></a>'; |
|
221 |
select UpdateXML(@xml, '/a/b', '<b>ccc</b>'); |
|
222 |
||
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"'); |
|
233 |
||
234 |
# |
|
235 |
# Bug#27898 UPDATEXML Crashes the Server! |
|
236 |
# |
|
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; |
|
240 |
||
241 |
# |
|
242 |
# Bug#16234 XML: Crash if ExtractValue() |
|
243 |
# |
|
244 |
SET @xml= '<order><clerk>lesser wombat</clerk></order>'; |
|
245 |
select extractvalue(@xml,'order/clerk'); |
|
246 |
select extractvalue(@xml,'/order/clerk'); |
|
247 |
||
248 |
# |
|
249 |
# Bug#16314 XML: extractvalue() crash if vertical bar |
|
250 |
# |
|
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'); |
|
256 |
||
257 |
# |
|
258 |
# Bug#16312 XML: extractvalue() crash if angle brackets |
|
259 |
# |
|
260 |
--error 1105 |
|
261 |
select extractvalue('<a>A</a>','/<a>'); |
|
262 |
||
263 |
# |
|
264 |
# Bug#16313 XML: extractvalue() ignores '!' in names |
|
265 |
# |
|
266 |
--error 1105 |
|
267 |
select extractvalue('<a><b>b</b><b!>b!</b!></a>','//b!'); |
|
268 |
||
269 |
# |
|
270 |
# Bug #16315 XML: extractvalue() handles self badly |
|
271 |
# |
|
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 |
|
276 |
# |
|
277 |
select extractvalue('<A_B>A</A_B>','/A_B'); |
|
278 |
||
279 |
# |
|
280 |
# Bug#16318: XML: extractvalue() incorrectly returns last() = 1 |
|
281 |
# |
|
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()]'); |
|
294 |
# |
|
295 |
# Bug#16316: XML: extractvalue() is case-sensitive with contains() |
|
296 |
# |
|
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")]'); |
|
301 |
||
302 |
# |
|
303 |
# Bug#18285: ExtractValue not returning character |
|
304 |
# data within <![CDATA[]]> as expected
|
|
305 |
# |
|
306 |
select ExtractValue('<tag1><![CDATA[test]]></tag1>','/tag1'); |
|
307 |
||
308 |
# |
|
309 |
# Bug#18201: XML: ExtractValue works even if the xml fragment |
|
310 |
# is not well-formed xml |
|
311 |
# |
|
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'); |
|
318 |
||
319 |
# |
|
320 |
# Bug #18171 XML: ExtractValue: the XPath position() |
|
321 |
# function crashes the server! |
|
322 |
# |
|
323 |
--error 1105 |
|
324 |
select extractValue('<e>1</e>','position()'); |
|
325 |
--error 1105 |
|
326 |
select extractValue('<e>1</e>','last()'); |
|
327 |
||
328 |
||
329 |
# |
|
330 |
# Bug #18172 XML: Extractvalue() accepts mallformed |
|
331 |
# XPath without a XPath syntax error |
|
332 |
# |
|
333 |
--error 1105 |
|
334 |
select extractValue('<e><a>1</a></e>','/e/'); |
|
335 |
||
336 |
# |
|
337 |
# Bug#16233: XML: ExtractValue() fails with special characters |
|
338 |
# |
|
339 |
set names utf8; |
|
340 |
select extractValue('<Ñ><r>r</r></Ñ>','/Ñ/r'); |
|
341 |
select extractValue('<r><Ñ>Ñ</Ñ></r>','/r/Ñ'); |
|
342 |
select extractValue('<Ñ r="r"/>','/Ñ/@r'); |
|
343 |
select extractValue('<r Ñ="Ñ"/>','/r/@Ñ'); |
|
344 |
--disable_warnings |
|
345 |
DROP PROCEDURE IF EXISTS p2; |
|
346 |
--enable_warnings |
|
347 |
DELIMITER //; |
|
348 |
CREATE PROCEDURE p2 () |
|
349 |
BEGIN |
|
350 |
DECLARE p LONGTEXT CHARACTER SET UTF8 DEFAULT '<Ñ><r>A</r></Ñ>'; |
|
351 |
SELECT EXTRACTVALUE(p,'/Ñ/r'); |
|
352 |
END// |
|
353 |
DELIMITER ;// |
|
354 |
CALL p2(); |
|
355 |
DROP PROCEDURE p2; |
|
356 |
||
357 |
# |
|
358 |
# Bug#18170: XML: ExtractValue(): |
|
359 |
# XPath expression can't use QNames (colon in names) |
|
360 |
# |
|
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'); |
|
364 |
||
365 |
# |
|
366 |
# Bug#20795 extractvalue() won't accept names containing a dot (.) |
|
367 |
# |
|
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'); |
|
370 |
||
371 |
# |
|
372 |
# Bug#20854 XML functions: wrong result in ExtractValue |
|
373 |
# |
|
374 |
--error 1105 |
|
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.-_:>','//*'); |
|
386 |
||
387 |
# |
|
388 |
# Bug#22823 gt and lt operators appear to be |
|
389 |
# reversed in ExtractValue() command |
|
390 |
# |
|
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"); |
|
416 |
||
417 |
#
|
|
418 |
# Bug#24747 XPath error with the node name "Text" |
|
419 |
#
|
|
420 |
#
|
|
421 |
# Test nodetypes in node name context |
|
422 |
#
|
|
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'); |
|
427 |
# |
|
428 |
# Test keywords in node name contexts |
|
429 |
# |
|
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'); |
|
438 |
# |
|
439 |
# Test axis names in node name context |
|
440 |
# |
|
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'); |
|
454 |
||
455 |
# |
|
456 |
# Bug#26518 XPath and variables problem |
|
457 |
# Check with user defined variables |
|
458 |
# |
|
459 |
set @i=1; |
|
460 |
select ExtractValue('<a><b>b1</b><b>b2</b></a>','/a/b[$@i]'); |
|
461 |
set @i=2; |
|
462 |
select ExtractValue('<a><b>b1</b><b>b2</b></a>','/a/b[$@i]'); |
|
463 |
set @i=NULL; |
|
464 |
select ExtractValue('<a><b>b1</b><b>b2</b></a>','/a/b[$@i]'); |
|
465 |
||
466 |
# |
|
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. |
|
469 |
# |
|
470 |
DELIMITER |; |
|
471 |
CREATE PROCEDURE spxml(xml VARCHAR(128)) |
|
472 |
BEGIN |
|
473 |
DECLARE c INT; |
|
474 |
DECLARE i INT DEFAULT 1; |
|
475 |
SET c= ExtractValue(xml,'count(/a/b)'); |
|
476 |
SET @i= c; |
|
477 |
WHILE i <= c DO
|
|
478 |
BEGIN |
|
479 |
SELECT i, @i, ExtractValue(xml,'/a/b[$i]'), ExtractValue(xml,'/a/b[$@i]'); |
|
480 |
SET i= i + 1; |
|
481 |
SET @i= @i - 1; |
|
482 |
END; |
|
483 |
END WHILE; |
|
484 |
END| |
|
485 |
DELIMITER ;| |
|
486 |
||
487 |
call spxml('<a><b>b1</b><b>b2</b><b>b3</b></a>'); |
|
488 |
drop procedure spxml; |
|
489 |
||
490 |
# |
|
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'); |
|
494 |
--echo No matches |
|
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 |
|
505 |
SET @i='1'; |
|
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]'); |
|
511 |
SET @i='string'; |
|
512 |
SELECT ExtractValue('<a><b>b1</b><b>b2</b></a>','/a/b[$@i]'); |
|
513 |
||
514 |
--echo String-to-number conversion with a CHAR SP variable |
|
515 |
DELIMITER |; |
|
516 |
CREATE PROCEDURE spxml(xml VARCHAR(128), i CHAR(16)) |
|
517 |
BEGIN |
|
518 |
SELECT ExtractValue(xml,'/a/b[$i]'); |
|
519 |
END| |
|
520 |
DELIMITER ;| |
|
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; |
|
526 |
||
527 |
# |
|
528 |
# Bug#28558 UpdateXML called with garbage crashes server |
|
529 |
# |
|
530 |
--error 1105 |
|
531 |
select UpdateXML('<a>a</a>',repeat('a b ',1000),''); |
|
532 |
--error 1105 |
|
533 |
select ExtractValue('<a>a</a>', '/a[@x=@y0123456789_0123456789_0123456789_0123456789]'); |
|
534 |
--error 1105 |
|
535 |
select ExtractValue('<a>a</a>', '/a[@x=$y0123456789_0123456789_0123456789_0123456789]'); |
|
536 |
||
537 |
# |
|
538 |
# Bug #31438: updatexml still crashes |
|
539 |
# |
|
540 |
||
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); |
|
545 |
||
546 |
# |
|
547 |
# Bug #32557: order by updatexml causes assertion in filesort |
|
548 |
# |
|
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')); |
|
552 |
DROP TABLE t1; |
|
553 |
||
554 |
--echo End of 5.1 tests |