diff options
author | unknown <bar@mysql.com> | 2005-12-21 17:13:52 +0400 |
---|---|---|
committer | unknown <bar@mysql.com> | 2005-12-21 17:13:52 +0400 |
commit | 5e4c3ce6822cac4313cd457136ea8827fce37a77 (patch) | |
tree | f1892af36f586e6b88e05253d3a7310eb806f577 /mysql-test/t/xml.test | |
parent | f78594c028dbb33b740c7bb3d9b310568b64508e (diff) | |
download | mariadb-git-5e4c3ce6822cac4313cd457136ea8827fce37a77.tar.gz |
Adding XPath support: ExtractValue and UpdateXML functions.
libmysqld/Makefile.am:
sql/Makefile.am:
Adding new source files.
Adding new file into build process.
include/my_xml.h:
strings/xml.c:
Adding new XML parse flags to skip text normalization and
to use relative tag names. Adding enum for XML token types.
sql/lex.h:
Making parser aware of new SQL functions.
sqll/item_create.h, sql/item_create.cc:
Adding creators for ExtractValue and UpdateXML.
sql/item.h:
Adding new Item types: nodeset and nodeset comparator.
sql/item_xmlfunc.h
sql/item_xmlfunc.cc
Adding new classes implementing XPath functions.
mysql-test/t/xml.test, mysql-test/r/xml.result:
New files: adding test case
include/my_xml.h:
Adding ExtractValue and UpdateXML functions.
Adding XML parser flags and enum for XML token types.
sql/Makefile.am:
Adding new source files.
sql/item.h:
Adding new Item types: nodeset and nodeset comparator.
sql/item_create.cc:
Adding creators for ExtractValue and UpdateXML.
sql/item_create.h:
Adding creators for ExtractValue and UpdateXML.
sql/lex.h:
Make parse aware of new SQL functions.
strings/xml.c:
Adding new flags to skip text normalization and
to use relative tag names.
libmysqld/Makefile.am:
Adding new file into build process.
Diffstat (limited to 'mysql-test/t/xml.test')
-rw-r--r-- | mysql-test/t/xml.test | 217 |
1 files changed, 217 insertions, 0 deletions
diff --git a/mysql-test/t/xml.test b/mysql-test/t/xml.test new file mode 100644 index 00000000000..472f6d49300 --- /dev/null +++ b/mysql-test/t/xml.test @@ -0,0 +1,217 @@ +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/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"]'); + +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"'); |