2009-09-23 23:32:31 +02:00
|
|
|
#ifndef ITEM_XMLFUNC_INCLUDED
|
|
|
|
#define ITEM_XMLFUNC_INCLUDED
|
|
|
|
|
2019-03-07 14:08:19 +01:00
|
|
|
/* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
|
2019-09-26 09:06:54 +02:00
|
|
|
Copyright (c) 2009, 2019, MariaDB
|
2005-12-21 14:13:52 +01:00
|
|
|
|
|
|
|
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
|
2006-12-27 02:23:51 +01:00
|
|
|
the Free Software Foundation; version 2 of the License.
|
2005-12-21 14:13:52 +01:00
|
|
|
|
|
|
|
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
|
2019-05-11 20:29:06 +02:00
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */
|
2005-12-21 14:13:52 +01:00
|
|
|
|
|
|
|
|
|
|
|
/* This file defines all XML functions */
|
|
|
|
|
|
|
|
|
2014-03-23 12:15:07 +01:00
|
|
|
typedef struct my_xml_node_st MY_XML_NODE;
|
|
|
|
|
|
|
|
|
2019-09-26 09:06:54 +02:00
|
|
|
/* Structure to store nodeset elements */
|
|
|
|
class MY_XPATH_FLT
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
uint num; // Absolute position in MY_XML_NODE array
|
|
|
|
uint pos; // Relative position in context
|
|
|
|
uint size; // Context size
|
|
|
|
public:
|
|
|
|
MY_XPATH_FLT(uint32 num_arg, uint32 pos_arg)
|
|
|
|
:num(num_arg), pos(pos_arg), size(0)
|
|
|
|
{ }
|
|
|
|
MY_XPATH_FLT(uint32 num_arg, uint32 pos_arg, uint32 size_arg)
|
|
|
|
:num(num_arg), pos(pos_arg), size(size_arg)
|
|
|
|
{ }
|
|
|
|
bool append_to(Native *to) const
|
|
|
|
{
|
|
|
|
return to->append((const char*) this, (uint32) sizeof(*this));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class NativeNodesetBuffer: public NativeBuffer<16*sizeof(MY_XPATH_FLT)>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
const MY_XPATH_FLT &element(uint i) const
|
|
|
|
{
|
|
|
|
const MY_XPATH_FLT *p= (MY_XPATH_FLT*) (ptr() + i * sizeof(MY_XPATH_FLT));
|
|
|
|
return *p;
|
|
|
|
}
|
|
|
|
uint32 elements() const
|
|
|
|
{
|
|
|
|
return length() / sizeof(MY_XPATH_FLT);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-12-21 14:13:52 +01:00
|
|
|
class Item_xml_str_func: public Item_str_func
|
|
|
|
{
|
|
|
|
protected:
|
2014-03-23 12:15:07 +01:00
|
|
|
/*
|
|
|
|
A helper class to store raw and parsed XML.
|
|
|
|
*/
|
|
|
|
class XML
|
|
|
|
{
|
|
|
|
bool m_cached;
|
|
|
|
String *m_raw_ptr; // Pointer to text representation
|
|
|
|
String m_raw_buf; // Cached text representation
|
|
|
|
String m_parsed_buf; // Array of MY_XML_NODEs, pointing to raw_buffer
|
|
|
|
bool parse();
|
|
|
|
void reset()
|
|
|
|
{
|
|
|
|
m_cached= false;
|
|
|
|
m_raw_ptr= (String *) 0;
|
|
|
|
}
|
|
|
|
public:
|
|
|
|
XML() { reset(); }
|
|
|
|
void set_charset(CHARSET_INFO *cs) { m_parsed_buf.set_charset(cs); }
|
|
|
|
String *raw() { return m_raw_ptr; }
|
|
|
|
String *parsed() { return &m_parsed_buf; }
|
|
|
|
const MY_XML_NODE *node(uint idx);
|
|
|
|
bool cached() { return m_cached; }
|
|
|
|
bool parse(String *raw, bool cache);
|
|
|
|
bool parse(Item *item, bool cache)
|
|
|
|
{
|
|
|
|
String *res;
|
|
|
|
if (!(res= item->val_str(&m_raw_buf)))
|
|
|
|
{
|
|
|
|
m_raw_ptr= (String *) 0;
|
|
|
|
m_cached= cache;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return parse(res, cache);
|
|
|
|
}
|
|
|
|
};
|
2018-01-30 08:07:35 +01:00
|
|
|
String m_xpath_query; // XPath query text
|
2005-12-21 14:13:52 +01:00
|
|
|
Item *nodeset_func;
|
2014-03-23 12:15:07 +01:00
|
|
|
XML xml;
|
2015-07-06 19:24:14 +02:00
|
|
|
bool get_xml(XML *xml_arg, bool cache= false)
|
2014-03-23 12:15:07 +01:00
|
|
|
{
|
2015-07-06 19:24:14 +02:00
|
|
|
if (!cache && xml_arg->cached())
|
|
|
|
return xml_arg->raw() == 0;
|
|
|
|
return xml_arg->parse(args[0], cache);
|
2014-03-23 12:15:07 +01:00
|
|
|
}
|
2005-12-21 14:13:52 +01:00
|
|
|
public:
|
2015-08-11 09:18:38 +02:00
|
|
|
Item_xml_str_func(THD *thd, Item *a, Item *b): Item_str_func(thd, a, b)
|
2013-09-25 14:30:13 +02:00
|
|
|
{
|
|
|
|
maybe_null= TRUE;
|
|
|
|
}
|
2015-08-11 09:18:38 +02:00
|
|
|
Item_xml_str_func(THD *thd, Item *a, Item *b, Item *c):
|
|
|
|
Item_str_func(thd, a, b, c)
|
2013-09-25 14:30:13 +02:00
|
|
|
{
|
|
|
|
maybe_null= TRUE;
|
|
|
|
}
|
2014-03-23 12:15:07 +01:00
|
|
|
bool fix_fields(THD *thd, Item **ref);
|
2018-05-08 15:26:26 +02:00
|
|
|
bool fix_length_and_dec();
|
2014-03-23 12:15:07 +01:00
|
|
|
bool const_item() const
|
|
|
|
{
|
|
|
|
return const_item_cache && (!nodeset_func || nodeset_func->const_item());
|
|
|
|
}
|
2005-12-21 14:13:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Item_func_xml_extractvalue: public Item_xml_str_func
|
|
|
|
{
|
|
|
|
public:
|
2015-08-11 09:18:38 +02:00
|
|
|
Item_func_xml_extractvalue(THD *thd, Item *a, Item *b):
|
|
|
|
Item_xml_str_func(thd, a, b) {}
|
2005-12-21 14:13:52 +01:00
|
|
|
const char *func_name() const { return "extractvalue"; }
|
|
|
|
String *val_str(String *);
|
2017-11-22 07:01:07 +01:00
|
|
|
Item *get_copy(THD *thd)
|
|
|
|
{ return get_item_copy<Item_func_xml_extractvalue>(thd, this); }
|
2005-12-21 14:13:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Item_func_xml_update: public Item_xml_str_func
|
|
|
|
{
|
2019-09-26 09:06:54 +02:00
|
|
|
NativeNodesetBuffer tmp_native_value2;
|
|
|
|
String tmp_value3;
|
2014-03-23 12:15:07 +01:00
|
|
|
bool collect_result(String *str,
|
|
|
|
const MY_XML_NODE *cut,
|
|
|
|
const String *replace);
|
2005-12-21 14:13:52 +01:00
|
|
|
public:
|
2015-08-11 09:18:38 +02:00
|
|
|
Item_func_xml_update(THD *thd, Item *a, Item *b, Item *c):
|
|
|
|
Item_xml_str_func(thd, a, b, c) {}
|
2005-12-21 14:13:52 +01:00
|
|
|
const char *func_name() const { return "updatexml"; }
|
|
|
|
String *val_str(String *);
|
2017-11-22 07:01:07 +01:00
|
|
|
Item *get_copy(THD *thd)
|
|
|
|
{ return get_item_copy<Item_func_xml_update>(thd, this); }
|
2005-12-21 14:13:52 +01:00
|
|
|
};
|
|
|
|
|
2009-09-23 23:32:31 +02:00
|
|
|
#endif /* ITEM_XMLFUNC_INCLUDED */
|