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.
This commit is contained in:
parent
f78594c028
commit
5e4c3ce682
@ -26,8 +26,31 @@ extern "C" {
|
||||
#define MY_XML_OK 0
|
||||
#define MY_XML_ERROR 1
|
||||
|
||||
/*
|
||||
A flag whether to use absolute tag names in call-back functions,
|
||||
like "a", "a.b" and "a.b.c" (used in character set file parser),
|
||||
or relative names like "a", "b" and "c".
|
||||
*/
|
||||
#define MY_XML_FLAG_RELATIVE_NAMES 1
|
||||
|
||||
/*
|
||||
A flag whether to skip normilization of text values before calling
|
||||
call-back functions: i.e. skip leading/trailing spaces,
|
||||
\r, \n, \t characters.
|
||||
*/
|
||||
#define MY_XML_FLAG_SKIP_TEXT_NORMALIZATION 2
|
||||
|
||||
enum my_xml_node_type
|
||||
{
|
||||
MY_XML_NODE_TAG, /* can have TAG, ATTR and TEXT children */
|
||||
MY_XML_NODE_ATTR, /* can have TEXT children */
|
||||
MY_XML_NODE_TEXT /* cannot have children */
|
||||
};
|
||||
|
||||
typedef struct xml_stack_st
|
||||
{
|
||||
int flags;
|
||||
enum my_xml_node_type current_node_type;
|
||||
char errstr[128];
|
||||
char attr[128];
|
||||
char *attrend;
|
||||
|
@ -48,6 +48,7 @@ sqlsources = derror.cc field.cc field_conv.cc strfunc.cc filesort.cc \
|
||||
item.cc item_buff.cc item_cmpfunc.cc item_create.cc \
|
||||
item_func.cc item_strfunc.cc item_sum.cc item_timefunc.cc \
|
||||
item_geofunc.cc item_uniq.cc item_subselect.cc item_row.cc\
|
||||
item_xmlfunc.cc \
|
||||
key.cc lock.cc log.cc log_event.cc sql_state.c \
|
||||
protocol.cc net_serv.cc opt_range.cc \
|
||||
opt_sum.cc procedure.cc records.cc sql_acl.cc \
|
||||
|
522
mysql-test/r/xml.result
Normal file
522
mysql-test/r/xml.result
Normal file
@ -0,0 +1,522 @@
|
||||
SET @xml='<a aa1="aa1" aa2="aa2">a1<b ba1="ba1">b1<c>c1</c>b2</b>a2</a>';
|
||||
SELECT extractValue(@xml,'/a');
|
||||
extractValue(@xml,'/a')
|
||||
a1 a2
|
||||
SELECT extractValue(@xml,'/a/b');
|
||||
extractValue(@xml,'/a/b')
|
||||
b1 b2
|
||||
SELECT extractValue(@xml,'/a/b/c');
|
||||
extractValue(@xml,'/a/b/c')
|
||||
c1
|
||||
SELECT extractValue(@xml,'/a/@aa1');
|
||||
extractValue(@xml,'/a/@aa1')
|
||||
aa1
|
||||
SELECT extractValue(@xml,'/a/@aa2');
|
||||
extractValue(@xml,'/a/@aa2')
|
||||
aa2
|
||||
SELECT extractValue(@xml,'/a/@*');
|
||||
extractValue(@xml,'/a/@*')
|
||||
aa1 aa2
|
||||
SELECT extractValue(@xml,'//@ba1');
|
||||
extractValue(@xml,'//@ba1')
|
||||
ba1
|
||||
SELECT extractValue(@xml,'//a');
|
||||
extractValue(@xml,'//a')
|
||||
a1 a2
|
||||
SELECT extractValue(@xml,'//b');
|
||||
extractValue(@xml,'//b')
|
||||
b1 b2
|
||||
SELECT extractValue(@xml,'//c');
|
||||
extractValue(@xml,'//c')
|
||||
c1
|
||||
SELECT extractValue(@xml,'/a//b');
|
||||
extractValue(@xml,'/a//b')
|
||||
b1 b2
|
||||
SELECT extractValue(@xml,'/a//c');
|
||||
extractValue(@xml,'/a//c')
|
||||
c1
|
||||
SELECT extractValue(@xml,'//*');
|
||||
extractValue(@xml,'//*')
|
||||
a1 b1 c1 b2 a2
|
||||
SELECT extractValue(@xml,'/a//*');
|
||||
extractValue(@xml,'/a//*')
|
||||
b1 c1 b2
|
||||
SELECT extractValue(@xml,'/./a');
|
||||
extractValue(@xml,'/./a')
|
||||
a1 a2
|
||||
SELECT extractValue(@xml,'/a/b/.');
|
||||
extractValue(@xml,'/a/b/.')
|
||||
b1 b2
|
||||
SELECT extractValue(@xml,'/a/b/..');
|
||||
extractValue(@xml,'/a/b/..')
|
||||
a1 a2
|
||||
SELECT extractValue(@xml,'/a/b/../@aa1');
|
||||
extractValue(@xml,'/a/b/../@aa1')
|
||||
aa1
|
||||
SELECT extractValue(@xml,'/*');
|
||||
extractValue(@xml,'/*')
|
||||
a1 a2
|
||||
SELECT extractValue(@xml,'/*/*');
|
||||
extractValue(@xml,'/*/*')
|
||||
b1 b2
|
||||
SELECT extractValue(@xml,'/*/*/*');
|
||||
extractValue(@xml,'/*/*/*')
|
||||
c1
|
||||
SELECT extractValue(@xml,'/a/child::*');
|
||||
extractValue(@xml,'/a/child::*')
|
||||
b1 b2
|
||||
SELECT extractValue(@xml,'/a/descendant::*');
|
||||
extractValue(@xml,'/a/descendant::*')
|
||||
b1 c1 b2
|
||||
SELECT extractValue(@xml,'/a/descendant-or-self::*');
|
||||
extractValue(@xml,'/a/descendant-or-self::*')
|
||||
a1 b1 c1 b2 a2
|
||||
SELECT extractValue(@xml,'/a/attribute::*');
|
||||
extractValue(@xml,'/a/attribute::*')
|
||||
aa1 aa2
|
||||
SELECT extractValue(@xml,'/a/b/c/parent::*');
|
||||
extractValue(@xml,'/a/b/c/parent::*')
|
||||
b1 b2
|
||||
SELECT extractValue(@xml,'/a/b/c/ancestor::*');
|
||||
extractValue(@xml,'/a/b/c/ancestor::*')
|
||||
a1 b1 b2 a2
|
||||
SELECT extractValue(@xml,'/a/b/c/ancestor-or-self::*');
|
||||
extractValue(@xml,'/a/b/c/ancestor-or-self::*')
|
||||
a1 b1 c1 b2 a2
|
||||
SELECT extractValue(@xml,'/descendant-or-self::*');
|
||||
extractValue(@xml,'/descendant-or-self::*')
|
||||
a1 b1 c1 b2 a2
|
||||
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::*');
|
||||
extractValue(@xml,'/a/b/c/ancestor-or-self::*')
|
||||
a11 b21 c1 b22 a12
|
||||
SELECT extractValue(@xml,'//@ba');
|
||||
extractValue(@xml,'//@ba')
|
||||
ba11 ba12 ba21 ba22
|
||||
SET @xml='<a><b>b</b><c>c</c></a>';
|
||||
SELECT extractValue(@xml,'/a/b');
|
||||
extractValue(@xml,'/a/b')
|
||||
b
|
||||
SELECT extractValue(@xml,'/a/c');
|
||||
extractValue(@xml,'/a/c')
|
||||
c
|
||||
SELECT extractValue(@xml,'/a/child::b');
|
||||
extractValue(@xml,'/a/child::b')
|
||||
b
|
||||
SELECT extractValue(@xml,'/a/child::c');
|
||||
extractValue(@xml,'/a/child::c')
|
||||
c
|
||||
SET @xml='<a><b>b1</b><c>c1</c><b>b2</b><c>c2</c></a>';
|
||||
SELECT extractValue(@xml,'/a/b[1]');
|
||||
extractValue(@xml,'/a/b[1]')
|
||||
b1
|
||||
SELECT extractValue(@xml,'/a/b[2]');
|
||||
extractValue(@xml,'/a/b[2]')
|
||||
b2
|
||||
SELECT extractValue(@xml,'/a/c[1]');
|
||||
extractValue(@xml,'/a/c[1]')
|
||||
c1
|
||||
SELECT extractValue(@xml,'/a/c[2]');
|
||||
extractValue(@xml,'/a/c[2]')
|
||||
c2
|
||||
SET @xml='<a><b x="xb1" x="xb2"/><c x="xc1" x="xc2"/></a>';
|
||||
SELECT extractValue(@xml,'/a//@x');
|
||||
extractValue(@xml,'/a//@x')
|
||||
xb1 xb2 xc1 xc2
|
||||
SELECT extractValue(@xml,'/a//@x[1]');
|
||||
extractValue(@xml,'/a//@x[1]')
|
||||
xb1 xc1
|
||||
SELECT extractValue(@xml,'/a//@x[2]');
|
||||
extractValue(@xml,'/a//@x[2]')
|
||||
xb2 xc2
|
||||
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]');
|
||||
extractValue(@xml,'//b[1]')
|
||||
b1 c1b1 c2b1
|
||||
SELECT extractValue(@xml,'/descendant::b[1]');
|
||||
extractValue(@xml,'/descendant::b[1]')
|
||||
b1
|
||||
SET @xml='<a><b>b1</b><b>b2</b></a>';
|
||||
SELECT extractValue(@xml,'/a/b[1+0]');
|
||||
extractValue(@xml,'/a/b[1+0]')
|
||||
b1
|
||||
SELECT extractValue(@xml,'/a/b[1*1]');
|
||||
extractValue(@xml,'/a/b[1*1]')
|
||||
b1
|
||||
SELECT extractValue(@xml,'/a/b[--1]');
|
||||
extractValue(@xml,'/a/b[--1]')
|
||||
b1
|
||||
SELECT extractValue(@xml,'/a/b[2*1-1]');
|
||||
extractValue(@xml,'/a/b[2*1-1]')
|
||||
b1
|
||||
SELECT extractValue(@xml,'/a/b[1+1]');
|
||||
extractValue(@xml,'/a/b[1+1]')
|
||||
b2
|
||||
SELECT extractValue(@xml,'/a/b[1*2]');
|
||||
extractValue(@xml,'/a/b[1*2]')
|
||||
b2
|
||||
SELECT extractValue(@xml,'/a/b[--2]');
|
||||
extractValue(@xml,'/a/b[--2]')
|
||||
b2
|
||||
SELECT extractValue(@xml,'/a/b[1*(3-1)]');
|
||||
extractValue(@xml,'/a/b[1*(3-1)]')
|
||||
b2
|
||||
SELECT extractValue(@xml,'//*[1=1]');
|
||||
extractValue(@xml,'//*[1=1]')
|
||||
b1 b2
|
||||
SELECT extractValue(@xml,'//*[1!=1]');
|
||||
extractValue(@xml,'//*[1!=1]')
|
||||
|
||||
SELECT extractValue(@xml,'//*[1>1]');
|
||||
extractValue(@xml,'//*[1>1]')
|
||||
|
||||
SELECT extractValue(@xml,'//*[2>1]');
|
||||
extractValue(@xml,'//*[2>1]')
|
||||
b1 b2
|
||||
SELECT extractValue(@xml,'//*[1>2]');
|
||||
extractValue(@xml,'//*[1>2]')
|
||||
|
||||
SELECT extractValue(@xml,'//*[1>=1]');
|
||||
extractValue(@xml,'//*[1>=1]')
|
||||
b1 b2
|
||||
SELECT extractValue(@xml,'//*[2>=1]');
|
||||
extractValue(@xml,'//*[2>=1]')
|
||||
b1 b2
|
||||
SELECT extractValue(@xml,'//*[1>=2]');
|
||||
extractValue(@xml,'//*[1>=2]')
|
||||
|
||||
SELECT extractValue(@xml,'//*[1<1]');
|
||||
extractValue(@xml,'//*[1<1]')
|
||||
|
||||
SELECT extractValue(@xml,'//*[2<1]');
|
||||
extractValue(@xml,'//*[2<1]')
|
||||
|
||||
SELECT extractValue(@xml,'//*[1<2]');
|
||||
extractValue(@xml,'//*[1<2]')
|
||||
b1 b2
|
||||
SELECT extractValue(@xml,'//*[1<=1]');
|
||||
extractValue(@xml,'//*[1<=1]')
|
||||
b1 b2
|
||||
SELECT extractValue(@xml,'//*[2<=1]');
|
||||
extractValue(@xml,'//*[2<=1]')
|
||||
|
||||
SELECT extractValue(@xml,'//*[1<=2]');
|
||||
extractValue(@xml,'//*[1<=2]')
|
||||
b1 b2
|
||||
SET @xml='<a><b>b11<c>c11</c></b><b>b21<c>c21</c></b></a>';
|
||||
SELECT extractValue(@xml,'/a/b[c="c11"]');
|
||||
extractValue(@xml,'/a/b[c="c11"]')
|
||||
b11
|
||||
SELECT extractValue(@xml,'/a/b[c="c21"]');
|
||||
extractValue(@xml,'/a/b[c="c21"]')
|
||||
b21
|
||||
SET @xml='<a><b c="c11">b11</b><b c="c21">b21</b></a>';
|
||||
SELECT extractValue(@xml,'/a/b[@c="c11"]');
|
||||
extractValue(@xml,'/a/b[@c="c11"]')
|
||||
b11
|
||||
SELECT extractValue(@xml,'/a/b[@c="c21"]');
|
||||
extractValue(@xml,'/a/b[@c="c21"]')
|
||||
b21
|
||||
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');
|
||||
extractValue(@xml, '/a/b[@c="c11"]/d')
|
||||
d11
|
||||
SELECT extractValue(@xml, '/a/b[@c="c21"]/d');
|
||||
extractValue(@xml, '/a/b[@c="c21"]/d')
|
||||
d21
|
||||
SELECT extractValue(@xml, '/a/b[d="d11"]/@c');
|
||||
extractValue(@xml, '/a/b[d="d11"]/@c')
|
||||
c11
|
||||
SELECT extractValue(@xml, '/a/b[d="d21"]/@c');
|
||||
extractValue(@xml, '/a/b[d="d21"]/@c')
|
||||
c21
|
||||
SELECT extractValue(@xml, '/a[b="b11"]');
|
||||
extractValue(@xml, '/a[b="b11"]')
|
||||
a1
|
||||
SELECT extractValue(@xml, '/a[b/@c="c11"]');
|
||||
extractValue(@xml, '/a[b/@c="c11"]')
|
||||
a1
|
||||
SELECT extractValue(@xml, '/a[b/d="d11"]');
|
||||
extractValue(@xml, '/a[b/d="d11"]')
|
||||
a1
|
||||
SELECT extractValue(@xml, '/a[/a/b="b11"]');
|
||||
extractValue(@xml, '/a[/a/b="b11"]')
|
||||
a1
|
||||
SELECT extractValue(@xml, '/a[/a/b/@c="c11"]');
|
||||
extractValue(@xml, '/a[/a/b/@c="c11"]')
|
||||
a1
|
||||
SELECT extractValue(@xml, '/a[/a/b/d="d11"]');
|
||||
extractValue(@xml, '/a[/a/b/d="d11"]')
|
||||
a1
|
||||
SELECT extractValue('<a>a</a>', '/a[false()]');
|
||||
extractValue('<a>a</a>', '/a[false()]')
|
||||
|
||||
SELECT extractValue('<a>a</a>', '/a[true()]');
|
||||
extractValue('<a>a</a>', '/a[true()]')
|
||||
a
|
||||
SELECT extractValue('<a>a</a>', '/a[not(false())]');
|
||||
extractValue('<a>a</a>', '/a[not(false())]')
|
||||
a
|
||||
SELECT extractValue('<a>a</a>', '/a[not(true())]');
|
||||
extractValue('<a>a</a>', '/a[not(true())]')
|
||||
|
||||
SELECT extractValue('<a>a</a>', '/a[true() and true()]');
|
||||
extractValue('<a>a</a>', '/a[true() and true()]')
|
||||
a
|
||||
SELECT extractValue('<a>a</a>', '/a[true() and false()]');
|
||||
extractValue('<a>a</a>', '/a[true() and false()]')
|
||||
|
||||
SELECT extractValue('<a>a</a>', '/a[false()and false()]');
|
||||
extractValue('<a>a</a>', '/a[false()and false()]')
|
||||
|
||||
SELECT extractValue('<a>a</a>', '/a[false()and true()]');
|
||||
extractValue('<a>a</a>', '/a[false()and true()]')
|
||||
|
||||
SELECT extractValue('<a>a</a>', '/a[true() or true()]');
|
||||
extractValue('<a>a</a>', '/a[true() or true()]')
|
||||
a
|
||||
SELECT extractValue('<a>a</a>', '/a[true() or false()]');
|
||||
extractValue('<a>a</a>', '/a[true() or false()]')
|
||||
a
|
||||
SELECT extractValue('<a>a</a>', '/a[false()or false()]');
|
||||
extractValue('<a>a</a>', '/a[false()or false()]')
|
||||
|
||||
SELECT extractValue('<a>a</a>', '/a[false()or true()]');
|
||||
extractValue('<a>a</a>', '/a[false()or true()]')
|
||||
a
|
||||
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"]');
|
||||
extractValue(@xml,'/a/b[@c="c"]')
|
||||
b1
|
||||
select extractValue(@xml,'/a/b[@c="d"]');
|
||||
extractValue(@xml,'/a/b[@c="d"]')
|
||||
b2
|
||||
select extractValue(@xml,'/a/b[@c="e"]');
|
||||
extractValue(@xml,'/a/b[@c="e"]')
|
||||
b1 b3
|
||||
select extractValue(@xml,'/a/b[not(@c="e")]');
|
||||
extractValue(@xml,'/a/b[not(@c="e")]')
|
||||
b2
|
||||
select extractValue(@xml,'/a/b[@c!="e"]');
|
||||
extractValue(@xml,'/a/b[@c!="e"]')
|
||||
b1 b2 b3
|
||||
select extractValue(@xml,'/a/b[@c="c" or @c="d"]');
|
||||
extractValue(@xml,'/a/b[@c="c" or @c="d"]')
|
||||
b1 b2
|
||||
select extractValue(@xml,'/a/b[@c="c" and @c="e"]');
|
||||
extractValue(@xml,'/a/b[@c="c" and @c="e"]')
|
||||
b1
|
||||
SET @xml='<a><b c="c" d="d">b1</b><b d="d" e="e">b2</b></a>';
|
||||
select extractValue(@xml,'/a/b[@c]');
|
||||
extractValue(@xml,'/a/b[@c]')
|
||||
b1
|
||||
select extractValue(@xml,'/a/b[@d]');
|
||||
extractValue(@xml,'/a/b[@d]')
|
||||
b1 b2
|
||||
select extractValue(@xml,'/a/b[@e]');
|
||||
extractValue(@xml,'/a/b[@e]')
|
||||
b2
|
||||
select extractValue(@xml,'/a/b[not(@c)]');
|
||||
extractValue(@xml,'/a/b[not(@c)]')
|
||||
b2
|
||||
select extractValue(@xml,'/a/b[not(@d)]');
|
||||
extractValue(@xml,'/a/b[not(@d)]')
|
||||
|
||||
select extractValue(@xml,'/a/b[not(@e)]');
|
||||
extractValue(@xml,'/a/b[not(@e)]')
|
||||
b1
|
||||
select extractValue(@xml, '/a/b[boolean(@c) or boolean(@d)]');
|
||||
extractValue(@xml, '/a/b[boolean(@c) or boolean(@d)]')
|
||||
b1 b2
|
||||
select extractValue(@xml, '/a/b[boolean(@c) or boolean(@e)]');
|
||||
extractValue(@xml, '/a/b[boolean(@c) or boolean(@e)]')
|
||||
b1 b2
|
||||
select extractValue(@xml, '/a/b[boolean(@d) or boolean(@e)]');
|
||||
extractValue(@xml, '/a/b[boolean(@d) or boolean(@e)]')
|
||||
b1 b2
|
||||
select extractValue(@xml, '/a/b[boolean(@c) and boolean(@d)]');
|
||||
extractValue(@xml, '/a/b[boolean(@c) and boolean(@d)]')
|
||||
b1
|
||||
select extractValue(@xml, '/a/b[boolean(@c) and boolean(@e)]');
|
||||
extractValue(@xml, '/a/b[boolean(@c) and boolean(@e)]')
|
||||
|
||||
select extractValue(@xml, '/a/b[boolean(@d) and boolean(@e)]');
|
||||
extractValue(@xml, '/a/b[boolean(@d) and boolean(@e)]')
|
||||
b2
|
||||
select extractValue(@xml, '/a/b[@c or @d]');
|
||||
extractValue(@xml, '/a/b[@c or @d]')
|
||||
b1 b2
|
||||
select extractValue(@xml, '/a/b[@c or @e]');
|
||||
extractValue(@xml, '/a/b[@c or @e]')
|
||||
b1 b2
|
||||
select extractValue(@xml, '/a/b[@d or @e]');
|
||||
extractValue(@xml, '/a/b[@d or @e]')
|
||||
b1 b2
|
||||
select extractValue(@xml, '/a/b[@c and @d]');
|
||||
extractValue(@xml, '/a/b[@c and @d]')
|
||||
b1
|
||||
select extractValue(@xml, '/a/b[@c and @e]');
|
||||
extractValue(@xml, '/a/b[@c and @e]')
|
||||
|
||||
select extractValue(@xml, '/a/b[@d and @e]');
|
||||
extractValue(@xml, '/a/b[@d and @e]')
|
||||
b2
|
||||
SET @xml='<a><b c="c">b1</b><b>b2</b></a>';
|
||||
SELECT extractValue(@xml,'/a/b[@*]');
|
||||
extractValue(@xml,'/a/b[@*]')
|
||||
b1
|
||||
SELECT extractValue(@xml,'/a/b[not(@*)]');
|
||||
extractValue(@xml,'/a/b[not(@*)]')
|
||||
b2
|
||||
SELECT extractValue('<a>a</a>', '/a[ceiling(3.1)=4]');
|
||||
extractValue('<a>a</a>', '/a[ceiling(3.1)=4]')
|
||||
a
|
||||
SELECT extractValue('<a>a</a>', '/a[floor(3.1)=3]');
|
||||
extractValue('<a>a</a>', '/a[floor(3.1)=3]')
|
||||
a
|
||||
SELECT extractValue('<a>a</a>', '/a[round(3.1)=3]');
|
||||
extractValue('<a>a</a>', '/a[round(3.1)=3]')
|
||||
a
|
||||
SELECT extractValue('<a>a</a>', '/a[round(3.8)=4]');
|
||||
extractValue('<a>a</a>', '/a[round(3.8)=4]')
|
||||
a
|
||||
SELECT extractValue('<a><b>b</b><c>c</c></a>', '/a/b | /a/c');
|
||||
extractValue('<a><b>b</b><c>c</c></a>', '/a/b | /a/c')
|
||||
b c
|
||||
select extractValue('<a b="b1" b="b2" b="b3"/>','/a/@b[position()=1]');
|
||||
extractValue('<a b="b1" b="b2" b="b3"/>','/a/@b[position()=1]')
|
||||
b1
|
||||
select extractValue('<a b="b1" b="b2" b="b3"/>','/a/@b[position()=2]');
|
||||
extractValue('<a b="b1" b="b2" b="b3"/>','/a/@b[position()=2]')
|
||||
b2
|
||||
select extractValue('<a b="b1" b="b2" b="b3"/>','/a/@b[position()=3]');
|
||||
extractValue('<a b="b1" b="b2" b="b3"/>','/a/@b[position()=3]')
|
||||
b3
|
||||
select extractValue('<a b="b1" b="b2" b="b3"/>','/a/@b[1=position()]');
|
||||
extractValue('<a b="b1" b="b2" b="b3"/>','/a/@b[1=position()]')
|
||||
b1
|
||||
select extractValue('<a b="b1" b="b2" b="b3"/>','/a/@b[2=position()]');
|
||||
extractValue('<a b="b1" b="b2" b="b3"/>','/a/@b[2=position()]')
|
||||
b2
|
||||
select extractValue('<a b="b1" b="b2" b="b3"/>','/a/@b[3=position()]');
|
||||
extractValue('<a b="b1" b="b2" b="b3"/>','/a/@b[3=position()]')
|
||||
b3
|
||||
select extractValue('<a b="b1" b="b2" b="b3"/>','/a/@b[2>=position()]');
|
||||
extractValue('<a b="b1" b="b2" b="b3"/>','/a/@b[2>=position()]')
|
||||
b1 b2
|
||||
select extractValue('<a b="b1" b="b2" b="b3"/>','/a/@b[2<=position()]');
|
||||
extractValue('<a b="b1" b="b2" b="b3"/>','/a/@b[2<=position()]')
|
||||
b2 b3
|
||||
select extractValue('<a b="b1" b="b2" b="b3"/>','/a/@b[position()=3 or position()=2]');
|
||||
extractValue('<a b="b1" b="b2" b="b3"/>','/a/@b[position()=3 or position()=2]')
|
||||
b2 b3
|
||||
SELECT extractValue('<a>a<b>a1<c>c1</c></b><b>a2</b></a>','/a/b[count(c)=0]');
|
||||
extractValue('<a>a<b>a1<c>c1</c></b><b>a2</b></a>','/a/b[count(c)=0]')
|
||||
a2
|
||||
SELECT extractValue('<a>a<b>a1<c>c1</c></b><b>a2</b></a>','/a/b[count(c)=1]');
|
||||
extractValue('<a>a<b>a1<c>c1</c></b><b>a2</b></a>','/a/b[count(c)=1]')
|
||||
a1
|
||||
select extractValue('<a>a1<b ba="1" ba="2">b1</b><b>b2</b>4</a>','/a/b[sum(@ba)=3]');
|
||||
extractValue('<a>a1<b ba="1" ba="2">b1</b><b>b2</b>4</a>','/a/b[sum(@ba)=3]')
|
||||
b1
|
||||
select extractValue('<a><b>b1</b><b>b2</b></a>','/a/b[1]');
|
||||
extractValue('<a><b>b1</b><b>b2</b></a>','/a/b[1]')
|
||||
b1
|
||||
select extractValue('<a><b>b1</b><b>b2</b></a>','/a/b[boolean(1)]');
|
||||
extractValue('<a><b>b1</b><b>b2</b></a>','/a/b[boolean(1)]')
|
||||
b1 b2
|
||||
select extractValue('<a><b>b1</b><b>b2</b></a>','/a/b[true()]');
|
||||
extractValue('<a><b>b1</b><b>b2</b></a>','/a/b[true()]')
|
||||
b1 b2
|
||||
select extractValue('<a><b>b1</b><b>b2</b></a>','/a/b[number(true())]');
|
||||
extractValue('<a><b>b1</b><b>b2</b></a>','/a/b[number(true())]')
|
||||
b1
|
||||
select extractValue('<a>ab</a>','/a[contains("abc","b")]');
|
||||
extractValue('<a>ab</a>','/a[contains("abc","b")]')
|
||||
ab
|
||||
select extractValue('<a>ab</a>','/a[contains(.,"a")]');
|
||||
extractValue('<a>ab</a>','/a[contains(.,"a")]')
|
||||
ab
|
||||
select extractValue('<a>ab</a>','/a[contains(.,"b")]');
|
||||
extractValue('<a>ab</a>','/a[contains(.,"b")]')
|
||||
ab
|
||||
select extractValue('<a>ab</a>','/a[contains(.,"c")]');
|
||||
extractValue('<a>ab</a>','/a[contains(.,"c")]')
|
||||
|
||||
select extractValue('<a b="1">ab</a>','/a[concat(@b,"2")="12"]');
|
||||
extractValue('<a b="1">ab</a>','/a[concat(@b,"2")="12"]')
|
||||
ab
|
||||
SET @xml='<a b="11" b="12" b="21" b="22">ab</a>';
|
||||
select extractValue(@xml, '/a/@b[substring(.,2)="1"]');
|
||||
extractValue(@xml, '/a/@b[substring(.,2)="1"]')
|
||||
11 21
|
||||
select extractValue(@xml, '/a/@b[substring(.,2)="2"]');
|
||||
extractValue(@xml, '/a/@b[substring(.,2)="2"]')
|
||||
12 22
|
||||
select extractValue(@xml, '/a/@b[substring(.,1,1)="1"]');
|
||||
extractValue(@xml, '/a/@b[substring(.,1,1)="1"]')
|
||||
11 12
|
||||
select extractValue(@xml, '/a/@b[substring(.,1,1)="2"]');
|
||||
extractValue(@xml, '/a/@b[substring(.,1,1)="2"]')
|
||||
21 22
|
||||
select extractValue(@xml, '/a/@b[substring(.,2,1)="1"]');
|
||||
extractValue(@xml, '/a/@b[substring(.,2,1)="1"]')
|
||||
11 21
|
||||
select extractValue(@xml, '/a/@b[substring(.,2,1)="2"]');
|
||||
extractValue(@xml, '/a/@b[substring(.,2,1)="2"]')
|
||||
12 22
|
||||
SET @xml='<a b="b11" b="b12" b="b21" b="22"/>';
|
||||
select extractValue(@xml,'/a/@b');
|
||||
extractValue(@xml,'/a/@b')
|
||||
b11 b12 b21 22
|
||||
select extractValue(@xml,'/a/@b[contains(.,"1")]');
|
||||
extractValue(@xml,'/a/@b[contains(.,"1")]')
|
||||
b11 b12 b21
|
||||
select extractValue(@xml,'/a/@b[contains(.,"1")][contains(.,"2")]');
|
||||
extractValue(@xml,'/a/@b[contains(.,"1")][contains(.,"2")]')
|
||||
b12 b21
|
||||
select extractValue(@xml,'/a/@b[contains(.,"1")][contains(.,"2")][2]');
|
||||
extractValue(@xml,'/a/@b[contains(.,"1")][contains(.,"2")][2]')
|
||||
b21
|
||||
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','+++++++++');
|
||||
UpdateXML('<a>a1<b>b1<c>c1</c>b2</b>a2</a>','/a/b/c','+++++++++')
|
||||
<a>a1<b>b1+++++++++b2</b>a2</a>
|
||||
select UpdateXML('<a>a1<b>b1<c>c1</c>b2</b>a2</a>','/a/b/c','<c1>+++++++++</c1>');
|
||||
UpdateXML('<a>a1<b>b1<c>c1</c>b2</b>a2</a>','/a/b/c','<c1>+++++++++</c1>')
|
||||
<a>a1<b>b1<c1>+++++++++</c1>b2</b>a2</a>
|
||||
select UpdateXML('<a>a1<b>b1<c>c1</c>b2</b>a2</a>','/a/b/c','<c1/>');
|
||||
UpdateXML('<a>a1<b>b1<c>c1</c>b2</b>a2</a>','/a/b/c','<c1/>')
|
||||
<a>a1<b>b1<c1/>b2</b>a2</a>
|
||||
SET @xml='<a><b>bb</b></a>';
|
||||
select UpdateXML(@xml, '/a/b', '<b>ccc</b>');
|
||||
UpdateXML(@xml, '/a/b', '<b>ccc</b>')
|
||||
<a><b>ccc</b></a>
|
||||
SET @xml='<a aa1="aa1" aa2="aa2"><b bb1="bb1" bb2="bb2">bb</b></a>';
|
||||
select UpdateXML(@xml, '/a/b', '<b>ccc</b>');
|
||||
UpdateXML(@xml, '/a/b', '<b>ccc</b>')
|
||||
<a aa1="aa1" aa2="aa2"><b>ccc</b></a>
|
||||
select UpdateXML(@xml, '/a/@aa1', '');
|
||||
UpdateXML(@xml, '/a/@aa1', '')
|
||||
<a aa2="aa2"><b bb1="bb1" bb2="bb2">bb</b></a>
|
||||
select UpdateXML(@xml, '/a/@aa1', 'aa3="aa3"');
|
||||
UpdateXML(@xml, '/a/@aa1', 'aa3="aa3"')
|
||||
<a aa3="aa3" aa2="aa2"><b bb1="bb1" bb2="bb2">bb</b></a>
|
||||
select UpdateXML(@xml, '/a/@aa2', '');
|
||||
UpdateXML(@xml, '/a/@aa2', '')
|
||||
<a aa1="aa1" ><b bb1="bb1" bb2="bb2">bb</b></a>
|
||||
select UpdateXML(@xml, '/a/@aa2', 'aa3="aa3"');
|
||||
UpdateXML(@xml, '/a/@aa2', 'aa3="aa3"')
|
||||
<a aa1="aa1" aa3="aa3"><b bb1="bb1" bb2="bb2">bb</b></a>
|
||||
select UpdateXML(@xml, '/a/b/@bb1', '');
|
||||
UpdateXML(@xml, '/a/b/@bb1', '')
|
||||
<a aa1="aa1" aa2="aa2"><b bb2="bb2">bb</b></a>
|
||||
select UpdateXML(@xml, '/a/b/@bb1', 'bb3="bb3"');
|
||||
UpdateXML(@xml, '/a/b/@bb1', 'bb3="bb3"')
|
||||
<a aa1="aa1" aa2="aa2"><b bb3="bb3" bb2="bb2">bb</b></a>
|
||||
select UpdateXML(@xml, '/a/b/@bb2', '');
|
||||
UpdateXML(@xml, '/a/b/@bb2', '')
|
||||
<a aa1="aa1" aa2="aa2"><b bb1="bb1" >bb</b></a>
|
||||
select UpdateXML(@xml, '/a/b/@bb2', 'bb3="bb3"');
|
||||
UpdateXML(@xml, '/a/b/@bb2', 'bb3="bb3"')
|
||||
<a aa1="aa1" aa2="aa2"><b bb1="bb1" bb3="bb3">bb</b></a>
|
217
mysql-test/t/xml.test
Normal file
217
mysql-test/t/xml.test
Normal file
@ -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"');
|
@ -46,6 +46,7 @@ mysqld_LDADD = @MYSQLD_EXTRA_LDFLAGS@ \
|
||||
@yassl_libs@ @openssl_libs@
|
||||
noinst_HEADERS = item.h item_func.h item_sum.h item_cmpfunc.h \
|
||||
item_strfunc.h item_timefunc.h item_uniq.h \
|
||||
item_xmlfunc.h \
|
||||
item_create.h item_subselect.h item_row.h \
|
||||
mysql_priv.h item_geofunc.h sql_bitmap.h \
|
||||
procedure.h sql_class.h sql_lex.h sql_list.h \
|
||||
@ -67,7 +68,7 @@ mysqld_SOURCES = sql_lex.cc sql_handler.cc sql_partition.cc \
|
||||
item.cc item_sum.cc item_buff.cc item_func.cc \
|
||||
item_cmpfunc.cc item_strfunc.cc item_timefunc.cc \
|
||||
thr_malloc.cc item_create.cc item_subselect.cc \
|
||||
item_row.cc item_geofunc.cc \
|
||||
item_row.cc item_geofunc.cc item_xmlfunc.cc \
|
||||
field.cc strfunc.cc key.cc sql_class.cc sql_list.cc \
|
||||
net_serv.cc protocol.cc sql_state.c \
|
||||
lock.cc my_lock.c \
|
||||
|
@ -393,6 +393,7 @@ public:
|
||||
FIELD_VARIANCE_ITEM, INSERT_VALUE_ITEM,
|
||||
SUBSELECT_ITEM, ROW_ITEM, CACHE_ITEM, TYPE_HOLDER,
|
||||
PARAM_ITEM, TRIGGER_FIELD_ITEM, DECIMAL_ITEM,
|
||||
XPATH_NODESET, XPATH_NODESET_CMP,
|
||||
VIEW_FIXER_ITEM};
|
||||
|
||||
enum cond_result { COND_UNDEF,COND_OK,COND_TRUE,COND_FALSE };
|
||||
@ -555,6 +556,7 @@ public:
|
||||
TRUE value is true (not equal to 0)
|
||||
*/
|
||||
virtual bool val_bool();
|
||||
virtual String *val_nodeset(String*) { return 0; }
|
||||
/* Helper functions, see item_sum.cc */
|
||||
String *val_string_from_real(String *str);
|
||||
String *val_string_from_int(String *str);
|
||||
@ -1911,6 +1913,7 @@ public:
|
||||
#include "item_timefunc.h"
|
||||
#include "item_uniq.h"
|
||||
#include "item_subselect.h"
|
||||
#include "item_xmlfunc.h"
|
||||
|
||||
class Item_copy_string :public Item
|
||||
{
|
||||
|
@ -502,6 +502,16 @@ Item *create_func_quote(Item* a)
|
||||
return new Item_func_quote(a);
|
||||
}
|
||||
|
||||
Item *create_func_xml_extractvalue(Item *a, Item *b)
|
||||
{
|
||||
return new Item_func_xml_extractvalue(a, b);
|
||||
}
|
||||
|
||||
Item *create_func_xml_update(Item *a, Item *b, Item *c)
|
||||
{
|
||||
return new Item_func_xml_update(a, b, c);
|
||||
}
|
||||
|
||||
#ifdef HAVE_SPATIAL
|
||||
Item *create_func_as_wkt(Item *a)
|
||||
{
|
||||
|
@ -102,7 +102,8 @@ Item *create_load_file(Item* a);
|
||||
Item *create_func_is_free_lock(Item* a);
|
||||
Item *create_func_is_used_lock(Item* a);
|
||||
Item *create_func_quote(Item* a);
|
||||
|
||||
Item *create_func_xml_extractvalue(Item *a, Item *b);
|
||||
Item *create_func_xml_update(Item *a, Item *b, Item *c);
|
||||
#ifdef HAVE_SPATIAL
|
||||
|
||||
Item *create_func_geometry_from_text(Item *a);
|
||||
|
2572
sql/item_xmlfunc.cc
Normal file
2572
sql/item_xmlfunc.cc
Normal file
File diff suppressed because it is too large
Load Diff
56
sql/item_xmlfunc.h
Normal file
56
sql/item_xmlfunc.h
Normal file
@ -0,0 +1,56 @@
|
||||
/* Copyright (C) 2000-2005 MySQL AB
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
||||
|
||||
|
||||
/* This file defines all XML functions */
|
||||
|
||||
|
||||
#ifdef __GNUC__
|
||||
#pragma interface /* gcc class implementation */
|
||||
#endif
|
||||
|
||||
|
||||
class Item_xml_str_func: public Item_str_func
|
||||
{
|
||||
protected:
|
||||
String tmp_value, pxml;
|
||||
Item *nodeset_func;
|
||||
public:
|
||||
Item_xml_str_func(Item *a, Item *b): Item_str_func(a,b) {}
|
||||
Item_xml_str_func(Item *a, Item *b, Item *c): Item_str_func(a,b,c) {}
|
||||
void fix_length_and_dec();
|
||||
String *parse_xml(String *raw_xml, String *parsed_xml_buf);
|
||||
};
|
||||
|
||||
|
||||
class Item_func_xml_extractvalue: public Item_xml_str_func
|
||||
{
|
||||
public:
|
||||
Item_func_xml_extractvalue(Item *a,Item *b) :Item_xml_str_func(a,b) {}
|
||||
const char *func_name() const { return "extractvalue"; }
|
||||
String *val_str(String *);
|
||||
};
|
||||
|
||||
|
||||
class Item_func_xml_update: public Item_xml_str_func
|
||||
{
|
||||
String tmp_value2, tmp_value3;
|
||||
public:
|
||||
Item_func_xml_update(Item *a,Item *b,Item *c) :Item_xml_str_func(a,b,c) {}
|
||||
const char *func_name() const { return "updatexml"; }
|
||||
String *val_str(String *);
|
||||
};
|
||||
|
@ -631,6 +631,7 @@ static SYMBOL sql_functions[] = {
|
||||
{ "EQUALS", F_SYM(FUNC_ARG2),0,CREATE_FUNC_GEOM(create_func_equals)},
|
||||
{ "EXTERIORRING", F_SYM(FUNC_ARG1),0,CREATE_FUNC_GEOM(create_func_exteriorring)},
|
||||
{ "EXTRACT", SYM(EXTRACT_SYM)},
|
||||
{ "EXTRACTVALUE", F_SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_xml_extractvalue)},
|
||||
{ "EXP", F_SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_exp)},
|
||||
{ "EXPORT_SET", SYM(EXPORT_SET)},
|
||||
{ "FIELD", SYM(FIELD_FUNC)}, /* For compability */
|
||||
@ -785,6 +786,7 @@ static SYMBOL sql_functions[] = {
|
||||
{ "UNHEX", F_SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_unhex)},
|
||||
{ "UNIQUE_USERS", SYM(UNIQUE_USERS)},
|
||||
{ "UNIX_TIMESTAMP", SYM(UNIX_TIMESTAMP)},
|
||||
{ "UPDATEXML", F_SYM(FUNC_ARG3),0,CREATE_FUNC(create_func_xml_update)},
|
||||
{ "UPPER", F_SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_ucase)},
|
||||
{ "UUID", F_SYM(FUNC_ARG0),0,CREATE_FUNC(create_func_uuid)},
|
||||
{ "VARIANCE", SYM(VARIANCE_SYM)},
|
||||
|
@ -104,7 +104,8 @@ static int my_xml_scan(MY_XML_PARSER *p,MY_XML_ATTR *a)
|
||||
a->end=p->cur;
|
||||
if (a->beg[0] == p->cur[0])p->cur++;
|
||||
a->beg++;
|
||||
my_xml_norm_text(a);
|
||||
if (!(p->flags & MY_XML_FLAG_SKIP_TEXT_NORMALIZATION))
|
||||
my_xml_norm_text(a);
|
||||
lex=MY_XML_STRING;
|
||||
}
|
||||
else
|
||||
@ -148,7 +149,10 @@ static int my_xml_enter(MY_XML_PARSER *st, const char *str, uint len)
|
||||
memcpy(st->attrend,str,len);
|
||||
st->attrend+=len;
|
||||
st->attrend[0]='\0';
|
||||
return st->enter ? st->enter(st,st->attr,st->attrend-st->attr) : MY_XML_OK;
|
||||
if (st->flags & MY_XML_FLAG_RELATIVE_NAMES)
|
||||
return st->enter ? st->enter(st, str, len) : MY_XML_OK;
|
||||
else
|
||||
return st->enter ? st->enter(st,st->attr,st->attrend-st->attr) : MY_XML_OK;
|
||||
}
|
||||
|
||||
|
||||
@ -167,7 +171,7 @@ static int my_xml_leave(MY_XML_PARSER *p, const char *str, uint slen)
|
||||
char s[32];
|
||||
char g[32];
|
||||
int rc;
|
||||
|
||||
|
||||
/* Find previous '.' or beginning */
|
||||
for( e=p->attrend; (e>p->attr) && (e[0] != '.') ; e--);
|
||||
glen = (uint) ((e[0] == '.') ? (p->attrend-e-1) : p->attrend-e);
|
||||
@ -180,7 +184,10 @@ static int my_xml_leave(MY_XML_PARSER *p, const char *str, uint slen)
|
||||
return MY_XML_ERROR;
|
||||
}
|
||||
|
||||
rc = p->leave_xml ? p->leave_xml(p,p->attr,p->attrend-p->attr) : MY_XML_OK;
|
||||
if (p->flags & MY_XML_FLAG_RELATIVE_NAMES)
|
||||
rc= p->leave_xml ? p->leave_xml(p, str, slen) : MY_XML_OK;
|
||||
else
|
||||
rc = p->leave_xml ? p->leave_xml(p,p->attr,p->attrend-p->attr) : MY_XML_OK;
|
||||
|
||||
*e='\0';
|
||||
p->attrend=e;
|
||||
@ -240,6 +247,7 @@ int my_xml_parse(MY_XML_PARSER *p,const char *str, uint len)
|
||||
|
||||
if (MY_XML_IDENT == lex)
|
||||
{
|
||||
p->current_node_type= MY_XML_NODE_TAG;
|
||||
if (MY_XML_OK != my_xml_enter(p,a.beg,(uint) (a.end-a.beg)))
|
||||
return MY_XML_ERROR;
|
||||
}
|
||||
@ -259,6 +267,7 @@ int my_xml_parse(MY_XML_PARSER *p,const char *str, uint len)
|
||||
lex=my_xml_scan(p,&b);
|
||||
if ( (lex == MY_XML_IDENT) || (lex == MY_XML_STRING) )
|
||||
{
|
||||
p->current_node_type= MY_XML_NODE_ATTR;
|
||||
if ((MY_XML_OK != my_xml_enter(p,a.beg,(uint) (a.end-a.beg))) ||
|
||||
(MY_XML_OK != my_xml_value(p,b.beg,(uint) (b.end-b.beg))) ||
|
||||
(MY_XML_OK != my_xml_leave(p,a.beg,(uint) (a.end-a.beg))))
|
||||
@ -273,6 +282,7 @@ int my_xml_parse(MY_XML_PARSER *p,const char *str, uint len)
|
||||
}
|
||||
else if ((MY_XML_STRING == lex) || (MY_XML_IDENT == lex))
|
||||
{
|
||||
p->current_node_type= MY_XML_NODE_ATTR;
|
||||
if ((MY_XML_OK != my_xml_enter(p,a.beg,(uint) (a.end-a.beg))) ||
|
||||
(MY_XML_OK != my_xml_leave(p,a.beg,(uint) (a.end-a.beg))))
|
||||
return MY_XML_ERROR;
|
||||
@ -319,7 +329,8 @@ gt:
|
||||
for ( ; (p->cur < p->end) && (p->cur[0] != '<') ; p->cur++);
|
||||
a.end=p->cur;
|
||||
|
||||
my_xml_norm_text(&a);
|
||||
if (!(p->flags & MY_XML_FLAG_SKIP_TEXT_NORMALIZATION))
|
||||
my_xml_norm_text(&a);
|
||||
if (a.beg != a.end)
|
||||
{
|
||||
my_xml_value(p,a.beg,(uint) (a.end-a.beg));
|
||||
|
Loading…
x
Reference in New Issue
Block a user