SET @xml='a1b1c1b2a2'; 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='a11b11b21c1b22a12'; SELECT extractValue(@xml,'/a/b/c/ancestor-or-self::*'); SELECT extractValue(@xml,'//@ba'); SET @xml='bc'; SELECT extractValue(@xml,'/a/b'); SELECT extractValue(@xml,'/a/c'); SELECT extractValue(@xml,'/a/child::b'); SELECT extractValue(@xml,'/a/child::c'); SET @xml='b1c1b2c2'; 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=''; SELECT extractValue(@xml,'/a//@x'); SELECT extractValue(@xml,'/a//@x[1]'); SELECT extractValue(@xml,'/a//@x[2]'); SET @xml='b1b2c1b1c1b2c2b1'; SELECT extractValue(@xml,'//b[1]'); SELECT extractValue(@xml,'/descendant::b[1]'); SET @xml='b1b2'; 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='b11c11b21c21'; SELECT extractValue(@xml,'/a/b[c="c11"]'); SELECT extractValue(@xml,'/a/b[c="c21"]'); SET @xml='b11b21'; SELECT extractValue(@xml,'/a/b[@c="c11"]'); SELECT extractValue(@xml,'/a/b[@c="c21"]'); SET @xml='a1b11d11b21d21'; 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[false()]'); SELECT extractValue('a', '/a[true()]'); SELECT extractValue('a', '/a[not(false())]'); SELECT extractValue('a', '/a[not(true())]'); SELECT extractValue('a', '/a[true() and true()]'); SELECT extractValue('a', '/a[true() and false()]'); SELECT extractValue('a', '/a[false()and false()]'); SELECT extractValue('a', '/a[false()and true()]'); SELECT extractValue('a', '/a[true() or true()]'); SELECT extractValue('a', '/a[true() or false()]'); SELECT extractValue('a', '/a[false()or false()]'); SELECT extractValue('a', '/a[false()or true()]'); SET @xml='abb1b2b3'; 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='b1b2'; 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='b1b2'; SELECT extractValue(@xml,'/a/b[@*]'); SELECT extractValue(@xml,'/a/b[not(@*)]'); SELECT extractValue('a', '/a[ceiling(3.1)=4]'); SELECT extractValue('a', '/a[floor(3.1)=3]'); SELECT extractValue('a', '/a[round(3.1)=3]'); SELECT extractValue('a', '/a[round(3.8)=4]'); SELECT extractValue('bc', '/a/b | /a/c'); select extractValue('','/a/@b[position()=1]'); select extractValue('','/a/@b[position()=2]'); select extractValue('','/a/@b[position()=3]'); select extractValue('','/a/@b[1=position()]'); select extractValue('','/a/@b[2=position()]'); select extractValue('','/a/@b[3=position()]'); select extractValue('','/a/@b[2>=position()]'); select extractValue('','/a/@b[2<=position()]'); select extractValue('','/a/@b[position()=3 or position()=2]'); SELECT extractValue('aa1c1a2','/a/b[count(c)=0]'); SELECT extractValue('aa1c1a2','/a/b[count(c)=1]'); select extractValue('a1b1b24','/a/b[sum(@ba)=3]'); select extractValue('b1b2','/a/b[1]'); select extractValue('b1b2','/a/b[boolean(1)]'); select extractValue('b1b2','/a/b[true()]'); select extractValue('b1b2','/a/b[number(true())]'); select extractValue('ab','/a[contains("abc","b")]'); select extractValue('ab','/a[contains(.,"a")]'); select extractValue('ab','/a[contains(.,"b")]'); select extractValue('ab','/a[contains(.,"c")]'); select extractValue('ab','/a[concat(@b,"2")="12"]'); SET @xml='ab'; 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='b1b2'; 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=''; 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='a1b1c1b2a2'; select UpdateXML('a1b1c1b2a2','/a/b/c','+++++++++'); select UpdateXML('a1b1c1b2a2','/a/b/c','+++++++++'); select UpdateXML('a1b1c1b2a2','/a/b/c',''); SET @xml='bb'; select UpdateXML(@xml, '/a/b', 'ccc'); SET @xml='bb'; select UpdateXML(@xml, '/a/b', 'ccc'); 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#27898 UPDATEXML Crashes the Server! # select updatexml('
12
', '/','12') as upd1; select updatexml('', '/', '') as upd2; # # Bug#16234 XML: Crash if ExtractValue() # SET @xml= 'lesser wombat'; select extractvalue(@xml,'order/clerk'); select extractvalue(@xml,'/order/clerk'); # # Bug#16314 XML: extractvalue() crash if vertical bar # select extractvalue('B','/a|/b'); select extractvalue('B','/a|b'); select extractvalue('aB','/a|/b'); select extractvalue('aB','/a|b'); select extractvalue('aB','a|/b'); # # Bug#16312 XML: extractvalue() crash if angle brackets # --error 1105 select extractvalue('A','/'); # # Bug#16313 XML: extractvalue() ignores '!' in names # --error 1105 select extractvalue('bb!','//b!'); # # Bug #16315 XML: extractvalue() handles self badly # select extractvalue('ABC','/a/descendant::*'); select extractvalue('ABC','/a/self::*'); select extractvalue('ABC','/a/descendant-or-self::*'); # Bug #16320 XML: extractvalue() won't accept names containing underscores # select extractvalue('A','/A_B'); # # Bug#16318: XML: extractvalue() incorrectly returns last() = 1 # select extractvalue('AB1B2','/a/b[position()]'); select extractvalue('AB1B2','/a/b[count(.)=last()]'); select extractvalue('AB1B2','/a/b[last()]'); select extractvalue('AB1B2','/a/b[last()-1]'); select extractvalue('AB1B2','/a/b[last()=1]'); select extractvalue('AB1B2','/a/b[last()=2]'); select extractvalue('AB1B2','/a/b[last()=position()]'); select extractvalue('AB1B2','/a/b[count(.)]'); select extractvalue('AB1B2','/a/b[count(.)-1]'); select extractvalue('AB1B2','/a/b[count(.)=1]'); select extractvalue('AB1B2','/a/b[count(.)=2]'); select extractvalue('AB1B2','/a/b[count(.)=position()]'); # # Bug#16316: XML: extractvalue() is case-sensitive with contains() # select extractvalue('Jack','/a[contains(../a,"J")]'); select extractvalue('Jack','/a[contains(../a,"j")]'); select extractvalue('Jack','/a[contains(../a,"j")]' collate latin1_bin); select extractvalue('Jack' collate latin1_bin,'/a[contains(../a,"j")]'); # # Bug#18285: ExtractValue not returning character # data within as expected # select ExtractValue('','/tag1'); # # Bug#18201: XML: ExtractValue works even if the xml fragment # is not well-formed xml # select extractValue('a','/a'); select extractValue('a<','/a'); select extractValue('aaa
','/a'); select extractValue('a','/a'); # # Bug #18171 XML: ExtractValue: the XPath position() # function crashes the server! # --error 1105 select extractValue('1','position()'); --error 1105 select extractValue('1','last()'); # # Bug #18172 XML: Extractvalue() accepts mallformed # XPath without a XPath syntax error # --error 1105 select extractValue('1','/e/'); # # Bug#16233: XML: ExtractValue() fails with special characters # set names utf8; select extractValue('<Ñ>r','/Ñ/r'); select extractValue('<Ñ>Ñ','/r/Ñ'); select extractValue('<Ñ r="r"/>','/Ñ/@r'); select extractValue('','/r/@Ñ'); --disable_warnings DROP PROCEDURE IF EXISTS p2; --enable_warnings DELIMITER //; CREATE PROCEDURE p2 () BEGIN DECLARE p LONGTEXT CHARACTER SET UTF8 DEFAULT '<Ñ>A'; 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('','count(ns:element)'); select extractValue('a','/ns:element'); select extractValue('a','/ns:element/@xmlns:ns'); # # Bug#20795 extractvalue() won't accept names containing a dot (.) # select extractValue('DataOtherdata','/foo/foo.bar'); select extractValue('DataOtherdata','/foo/something'); # # Bug#20854 XML functions: wrong result in ExtractValue # --error 1105 select extractValue('<01>10:39:15<02>140','/zot/tim0/02'); select extractValue('<01>10:39:15<02>140','//*'); # dot and dash are bad identtifier start character select extractValue('<.>test','//*'); select extractValue('<->test','//*'); # semicolon is good identifier start character select extractValue('<:>test','//*'); # underscore is good identifier start character select extractValue('<_>test','//*'); # dot, dash, underscore and semicolon are good identifier middle characters select extractValue('test','//*'); # # Bug#22823 gt and lt operators appear to be # reversed in ExtractValue() command # set @xml= "pt1010pt5050"; select ExtractValue(@xml, "/entry[(pt=10)]/id"); select ExtractValue(@xml, "/entry[(pt!=10)]/id"); select ExtractValue(@xml, "/entry[(pt<10)]/id"); select ExtractValue(@xml, "/entry[(pt<=10)]/id"); select ExtractValue(@xml, "/entry[(pt>10)]/id"); select ExtractValue(@xml, "/entry[(pt>=10)]/id"); select ExtractValue(@xml, "/entry[(pt=50)]/id"); select ExtractValue(@xml, "/entry[(pt!=50)]/id"); select ExtractValue(@xml, "/entry[(pt<50)]/id"); select ExtractValue(@xml, "/entry[(pt<=50)]/id"); select ExtractValue(@xml, "/entry[(pt>50)]/id"); select ExtractValue(@xml, "/entry[(pt>=50)]/id"); select ExtractValue(@xml, "/entry[(10=pt)]/id"); select ExtractValue(@xml, "/entry[(10!=pt)]/id"); select ExtractValue(@xml, "/entry[(10>pt)]/id"); select ExtractValue(@xml, "/entry[(10>=pt)]/id"); select ExtractValue(@xml, "/entry[(10pt)]/id"); select ExtractValue(@xml, "/entry[(50>=pt)]/id"); select ExtractValue(@xml, "/entry[(50test','/a/b/Text'); select ExtractValue('test','/a/b/comment'); select ExtractValue('test','/a/b/node'); select ExtractValue('test','/a/b/processing-instruction'); # # Test keywords in node name contexts # select ExtractValue('test', '/a/and'); select ExtractValue('test', '/a/or'); select ExtractValue('test', '/a/mod'); select ExtractValue('
test
', '/a/div'); select ExtractValue('test', '/a/and:and'); select ExtractValue('test', '/a/or:or'); select ExtractValue('test', '/a/mod:mod'); select ExtractValue('test', '/a/div:div'); # # Test axis names in node name context # select ExtractValue('test', '/a/ancestor'); select ExtractValue('test', '/a/ancestor-or-self'); select ExtractValue('test', '/a/attribute'); select ExtractValue('test', '/a/child'); select ExtractValue('test', '/a/descendant'); select ExtractValue('test', '/a/descendant-or-self'); select ExtractValue('test', '/a/following'); select ExtractValue('test', '/a/following-sibling'); select ExtractValue('test', '/a/namespace'); select ExtractValue('test', '/a/parent'); select ExtractValue('test', '/a/preceding'); select ExtractValue('test', '/a/preceding-sibling'); select ExtractValue('test', '/a/self'); # # Bug#26518 XPath and variables problem # Check with user defined variables # set @i=1; select ExtractValue('b1b2','/a/b[$@i]'); set @i=2; select ExtractValue('b1b2','/a/b[$@i]'); set @i=NULL; select ExtractValue('b1b2','/a/b[$@i]'); # # Check variables in a stored procedure - both local and user variables # Make sure that SP and local variables with the same name work together. # DELIMITER |; CREATE PROCEDURE spxml(xml VARCHAR(128)) BEGIN DECLARE c INT; DECLARE i INT DEFAULT 1; SET c= ExtractValue(xml,'count(/a/b)'); SET @i= c; WHILE i <= c DO BEGIN SELECT i, @i, ExtractValue(xml,'/a/b[$i]'), ExtractValue(xml,'/a/b[$@i]'); SET i= i + 1; SET @i= @i - 1; END; END WHILE; END| DELIMITER ;| call spxml('b1b2b3'); drop procedure spxml; # # Additional tests for bug#26518 --echo Multiple matches, but no index specification SELECT ExtractValue('b1b2','/a/b'); --echo No matches SELECT ExtractValue('b1b2','/a/c'); --echo Index out of range SELECT ExtractValue('b1b2','/a/b[-1]'); SELECT ExtractValue('b1b2','/a/b[10]'); --echo With string-to-number conversion SELECT ExtractValue('b1b2','/a/b["1"]'); SELECT ExtractValue('b1b2','/a/b["1 and string"]'); SELECT ExtractValue('b1b2','/a/b["string and 1"]'); SELECT ExtractValue('b1b2','/a/b["string"]'); --echo String-to-number conversion from a user variable SET @i='1'; SELECT ExtractValue('b1b2','/a/b[$@i]'); SET @i='1 and string'; SELECT ExtractValue('b1b2','/a/b[$@i]'); SET @i='string and 1'; SELECT ExtractValue('b1b2','/a/b[$@i]'); SET @i='string'; SELECT ExtractValue('b1b2','/a/b[$@i]'); --echo String-to-number conversion with a CHAR SP variable DELIMITER |; CREATE PROCEDURE spxml(xml VARCHAR(128), i CHAR(16)) BEGIN SELECT ExtractValue(xml,'/a/b[$i]'); END| DELIMITER ;| CALL spxml('b1b2', '1'); CALL spxml('b1b2', '1 and string'); CALL spxml('b1b2', 'string and 1'); CALL spxml('b1b2', 'string'); DROP PROCEDURE spxml; # # Bug#28558 UpdateXML called with garbage crashes server # --error 1105 select UpdateXML('a',repeat('a b ',1000),''); --error 1105 select ExtractValue('a', '/a[@x=@y0123456789_0123456789_0123456789_0123456789]'); --error 1105 select ExtractValue('a', '/a[@x=$y0123456789_0123456789_0123456789_0123456789]'); # # Bug #31438: updatexml still crashes # select updatexml(NULL, 1, 1), updatexml(1, NULL, 1), updatexml(1, 1, NULL); select updatexml(NULL, NULL, 1), updatexml(1, NULL, NULL), updatexml(NULL, 1, NULL); select updatexml(NULL, NULL, NULL); # # Bug #32557: order by updatexml causes assertion in filesort # CREATE TABLE t1(a INT NOT NULL); INSERT INTO t1 VALUES (0), (0); SELECT 1 FROM t1 ORDER BY(UPDATEXML(a, '1', '1')); DROP TABLE t1; # # BUG#38227 EXTRACTVALUE doesn't work with DTD declarations # # Check that quoted strings work fine in DOCTYPE declaration. # SET @xml= ' Title - document with document declaration Hi, Im a webpage with document a declaration '; SELECT ExtractValue(@xml, 'html/head/title'); SELECT ExtractValue(@xml, 'html/body'); # These two documents will fail. # Quoted strings are not allowed in regular tags # SELECT ExtractValue('CharData', '/xml'); SELECT ExtractValue('CharData', '/xml'); # # Bug#42495 updatexml: Assertion failed: xpath->context, file .\item_xmlfunc.cc, line 2507 # set @x=10; --error ER_UNKNOWN_ERROR select extractvalue('','$@x/a'); --error ER_UNKNOWN_ERROR select extractvalue('','round(123.4)/a'); --error ER_UNKNOWN_ERROR select extractvalue('','1/a'); --error ER_UNKNOWN_ERROR select extractvalue('','"b"/a'); --error ER_UNKNOWN_ERROR select extractvalue('','(1)/a'); # # Bug#43183 ExctractValue() brings result list in missorder # CREATE TABLE IF NOT EXISTS t1 ( id int(10) unsigned NOT NULL AUTO_INCREMENT, xml text, PRIMARY KEY (id) ) ENGINE=MyISAM; INSERT INTO t1 (id, xml) VALUES (15, ''), (14, ''); SELECT extractvalue( xml, '/bla/@name' ), extractvalue( xml, '/bla/@name' ) FROM t1 ORDER BY t1.id; SELECT UpdateXML(xml, '/bla/@name', 'test'), UpdateXML(xml, '/bla/@name', 'test') FROM t1 ORDER BY t1.id; DROP TABLE t1; --echo # --echo # Bug#57257 Replace(ExtractValue(...)) causes MySQL crash --echo # SET NAMES utf8; SELECT REPLACE(EXTRACTVALUE('1', '/a'),'ds',''); --echo # --echo # Bug #57820 extractvalue crashes --echo # SELECT AVG(DISTINCT EXTRACTVALUE((''),('$@k'))); --echo # --echo # Bug#57279 updatexml dies with: Assertion failed: str_arg[length] == 0 --echo # --error ER_ILLEGAL_VALUE_FOR_TYPE SELECT UPDATEXML(NULL, (LPAD(0.1111E-15, '2011', 1)), 1); --error ER_ILLEGAL_VALUE_FOR_TYPE SELECT EXTRACTVALUE('', LPAD(0.1111E-15, '2011', 1)); --echo # --echo # Bug #44332 my_xml_scan reads behind the end of buffer --echo # SELECT UPDATEXML(CONVERT(_latin1'<' USING utf8),'1','1'); SELECT UPDATEXML(CONVERT(_latin1'