1#ifndef ITEM_XMLFUNC_INCLUDED
2#define ITEM_XMLFUNC_INCLUDED
3
4/* Copyright (c) 2000-2007 MySQL AB, 2009 Sun Microsystems, Inc.
5 Use is subject to license terms.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; version 2 of the License.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
19
20
21/* This file defines all XML functions */
22
23
24typedef struct my_xml_node_st MY_XML_NODE;
25
26
27class Item_xml_str_func: public Item_str_func
28{
29protected:
30 /*
31 A helper class to store raw and parsed XML.
32 */
33 class XML
34 {
35 bool m_cached;
36 String *m_raw_ptr; // Pointer to text representation
37 String m_raw_buf; // Cached text representation
38 String m_parsed_buf; // Array of MY_XML_NODEs, pointing to raw_buffer
39 bool parse();
40 void reset()
41 {
42 m_cached= false;
43 m_raw_ptr= (String *) 0;
44 }
45 public:
46 XML() { reset(); }
47 void set_charset(CHARSET_INFO *cs) { m_parsed_buf.set_charset(cs); }
48 String *raw() { return m_raw_ptr; }
49 String *parsed() { return &m_parsed_buf; }
50 const MY_XML_NODE *node(uint idx);
51 bool cached() { return m_cached; }
52 bool parse(String *raw, bool cache);
53 bool parse(Item *item, bool cache)
54 {
55 String *res;
56 if (!(res= item->val_str(&m_raw_buf)))
57 {
58 m_raw_ptr= (String *) 0;
59 m_cached= cache;
60 return true;
61 }
62 return parse(res, cache);
63 }
64 };
65 String m_xpath_query; // XPath query text
66 Item *nodeset_func;
67 XML xml;
68 bool get_xml(XML *xml_arg, bool cache= false)
69 {
70 if (!cache && xml_arg->cached())
71 return xml_arg->raw() == 0;
72 return xml_arg->parse(args[0], cache);
73 }
74public:
75 Item_xml_str_func(THD *thd, Item *a, Item *b): Item_str_func(thd, a, b)
76 {
77 maybe_null= TRUE;
78 }
79 Item_xml_str_func(THD *thd, Item *a, Item *b, Item *c):
80 Item_str_func(thd, a, b, c)
81 {
82 maybe_null= TRUE;
83 }
84 bool fix_fields(THD *thd, Item **ref);
85 void fix_length_and_dec();
86 bool const_item() const
87 {
88 return const_item_cache && (!nodeset_func || nodeset_func->const_item());
89 }
90};
91
92
93class Item_func_xml_extractvalue: public Item_xml_str_func
94{
95public:
96 Item_func_xml_extractvalue(THD *thd, Item *a, Item *b):
97 Item_xml_str_func(thd, a, b) {}
98 const char *func_name() const { return "extractvalue"; }
99 String *val_str(String *);
100 Item *get_copy(THD *thd)
101 { return get_item_copy<Item_func_xml_extractvalue>(thd, this); }
102};
103
104
105class Item_func_xml_update: public Item_xml_str_func
106{
107 String tmp_value2, tmp_value3;
108 bool collect_result(String *str,
109 const MY_XML_NODE *cut,
110 const String *replace);
111public:
112 Item_func_xml_update(THD *thd, Item *a, Item *b, Item *c):
113 Item_xml_str_func(thd, a, b, c) {}
114 const char *func_name() const { return "updatexml"; }
115 String *val_str(String *);
116 Item *get_copy(THD *thd)
117 { return get_item_copy<Item_func_xml_update>(thd, this); }
118};
119
120#endif /* ITEM_XMLFUNC_INCLUDED */
121