MySQL 9.0.0
Source Code Documentation
item_xmlfunc.h
Go to the documentation of this file.
1#ifndef ITEM_XMLFUNC_INCLUDED
2#define ITEM_XMLFUNC_INCLUDED
3
4/* Copyright (c) 2000, 2024, Oracle and/or its affiliates.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License, version 2.0,
8 as published by the Free Software Foundation.
9
10 This program is designed to work with certain software (including
11 but not limited to OpenSSL) that is licensed under separate terms,
12 as designated in a particular file or component or in included license
13 documentation. The authors of MySQL hereby grant you an additional
14 permission to link the program and your derivative works with the
15 separately licensed software that they have either included with
16 the program or referenced in the documentation.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License, version 2.0, for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
26
27#include <sys/types.h> // uint
28
29#include <vector>
30
31#include "my_inttypes.h"
32#include "my_xml.h" // my_xml_node_type
33#include "sql/item.h" // Check_function_as_value_generator_parameters
34#include "sql/item_strfunc.h" // Item_str_func
35#include "sql/parse_location.h" // POS
36#include "sql_string.h"
37#include "template_utils.h" // pointer_cast
38
39class THD;
40
41/* This file defines all XML functions */
42
43/* Structure to store a parsed XML tree */
45 uint level; /* level in XML tree, 0 means root node */
46 enum my_xml_node_type type; /* node type: node, or attribute, or text */
47 uint parent; /* link to the parent */
48 const char *beg; /* beginning of the name or text */
49 const char *end; /* end of the name or text */
50 const char *tagend; /* where this tag ends */
51};
52
53using ParsedXML = std::vector<MY_XML_NODE>;
54
56 protected:
58 Item *nodeset_func{nullptr};
59 /// True if nodeset_func assigned during resolving
62
63 public:
64 Item_xml_str_func(const POS &pos, Item *a, Item *b)
65 : Item_str_func(pos, a, b), nodeset_func(nullptr) {
66 set_nullable(true);
67 }
68 Item_xml_str_func(const POS &pos, Item *a, Item *b, Item *c)
69 : Item_str_func(pos, a, b, c), nodeset_func(nullptr) {
70 set_nullable(true);
71 }
72 bool resolve_type(THD *thd) override;
73 void cleanup() override {
76 }
77 bool check_function_as_value_generator(uchar *) override { return false; }
78
79 protected:
80 /**
81 Parse the specified XPATH expression and initialize @c nodeset_func.
82
83 @note This is normally called in resolve phase since we only support
84 constant XPATH expressions, but it may be called upon execution when
85 const value is not yet known at resolve time.
86
87 @param xpath_expr XPATH expression to be parsed
88
89 @returns false on success, true on error
90 */
91 bool parse_xpath(Item *xpath_expr);
92};
93
96
97 public:
99 : Item_xml_str_func(pos, a, b) {}
100 const char *func_name() const override { return "extractvalue"; }
101 String *val_str(String *) override;
102};
103
106
107 public:
108 Item_func_xml_update(const POS &pos, Item *a, Item *b, Item *c)
109 : Item_xml_str_func(pos, a, b, c) {}
110 const char *func_name() const override { return "updatexml"; }
111 String *val_str(String *) override;
112 bool check_function_as_value_generator(uchar *checker_args) override {
113 auto *func_arg =
114 pointer_cast<Check_function_as_value_generator_parameters *>(
115 checker_args);
116 func_arg->banned_function_name = func_name();
117 return true;
118 }
119};
120
121#endif /* ITEM_XMLFUNC_INCLUDED */
Kerberos Client Authentication nullptr
Definition: auth_kerberos_client_plugin.cc:251
Definition: item_xmlfunc.h:94
String tmp_value
Definition: item_xmlfunc.h:95
const char * func_name() const override
Definition: item_xmlfunc.h:100
String * val_str(String *) override
Definition: item_xmlfunc.cc:2486
Item_func_xml_extractvalue(const POS &pos, Item *a, Item *b)
Definition: item_xmlfunc.h:98
Definition: item_xmlfunc.h:104
bool check_function_as_value_generator(uchar *checker_args) override
Check if this item is allowed for a virtual column or inside a default expression.
Definition: item_xmlfunc.h:112
Item_func_xml_update(const POS &pos, Item *a, Item *b, Item *c)
Definition: item_xmlfunc.h:108
const char * func_name() const override
Definition: item_xmlfunc.h:110
String * val_str(String *) override
Definition: item_xmlfunc.cc:2504
String tmp_value
Definition: item_xmlfunc.h:105
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item.cc:10910
Definition: item_strfunc.h:76
Definition: item_xmlfunc.h:55
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_xmlfunc.cc:2286
Item * nodeset_func
Definition: item_xmlfunc.h:58
bool check_function_as_value_generator(uchar *) override
Check if this item is allowed for a virtual column or inside a default expression.
Definition: item_xmlfunc.h:77
bool nodeset_func_permanent
True if nodeset_func assigned during resolving.
Definition: item_xmlfunc.h:60
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item_xmlfunc.h:73
Item_xml_str_func(const POS &pos, Item *a, Item *b, Item *c)
Definition: item_xmlfunc.h:68
Item_xml_str_func(const POS &pos, Item *a, Item *b)
Definition: item_xmlfunc.h:64
ParsedXML pxml
Definition: item_xmlfunc.h:57
String xpath_tmp_value
Definition: item_xmlfunc.h:61
bool parse_xpath(Item *xpath_expr)
Parse the specified XPATH expression and initialize nodeset_func.
Definition: item_xmlfunc.cc:2315
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:930
void set_nullable(bool nullable)
Definition: item.h:3670
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:167
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
std::vector< MY_XML_NODE > ParsedXML
Definition: item_xmlfunc.h:53
Some integer typedefs for easier portability.
unsigned char uchar
Definition: my_inttypes.h:52
my_xml_node_type
Definition: my_xml.h:51
Our own string classes, used pervasively throughout the executor.
Bison "location" class.
Definition: parse_location.h:43
Definition: item_xmlfunc.h:44
const char * beg
Definition: item_xmlfunc.h:48
uint level
Definition: item_xmlfunc.h:45
enum my_xml_node_type type
Definition: item_xmlfunc.h:46
const char * end
Definition: item_xmlfunc.h:49
uint parent
Definition: item_xmlfunc.h:47
const char * tagend
Definition: item_xmlfunc.h:50