MySQL 8.0.31
Source Code Documentation
item_inetfunc.h
Go to the documentation of this file.
1#ifndef ITEM_INETFUNC_INCLUDED
2#define ITEM_INETFUNC_INCLUDED
3
4/* Copyright (c) 2011, 2022, 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 also distributed 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 included with MySQL.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License, version 2.0, for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
25
26#include "m_ctype.h"
27#include "my_inttypes.h"
28#include "sql/item_cmpfunc.h" // Item_bool_func
29#include "sql/item_func.h"
30#include "sql/item_strfunc.h" // Item_str_func
31#include "sql/parse_location.h" // POS
32
33class Item;
34class String;
35class THD;
36
37/*************************************************************************
38 Item_func_inet_aton implements INET_ATON() SQL-function.
39*************************************************************************/
40
42 public:
43 inline Item_func_inet_aton(const POS &pos, Item *arg)
44 : Item_int_func(pos, arg) {}
45
46 public:
47 longlong val_int() override;
48
49 const char *func_name() const override { return "inet_aton"; }
50
51 bool resolve_type(THD *thd) override {
52 if (param_type_is_default(thd, 0, 1)) return true;
53 set_nullable(true);
54 unsigned_flag = true;
55 return false;
56 }
57};
58
59/*************************************************************************
60 Item_func_inet_ntoa implements INET_NTOA() SQL-function.
61*************************************************************************/
62
64 public:
65 inline Item_func_inet_ntoa(const POS &pos, Item *arg)
66 : Item_str_func(pos, arg) {}
67
68 public:
69 String *val_str(String *str) override;
70
71 const char *func_name() const override { return "inet_ntoa"; }
72
73 bool resolve_type(THD *thd) override {
74 if (param_type_is_default(thd, 0, 1, MYSQL_TYPE_LONGLONG)) return true;
76 set_nullable(true);
77 return false;
78 }
79};
80
81/*************************************************************************
82 Item_func_inet_bool_base implements common code for INET6/IP-related
83 functions returning boolean value.
84*************************************************************************/
85
87 public:
89 : Item_bool_func(pos, ip_addr) {
90 null_value = false;
91 }
92
93 public:
94 longlong val_int() override;
95
96 protected:
97 virtual bool calc_value(const String *arg) const = 0;
98};
99
100/*************************************************************************
101 Item_func_inet_str_base implements common code for INET6/IP-related
102 functions returning string value.
103*************************************************************************/
104
106 public:
108 : Item_str_ascii_func(pos, arg) {}
109
110 public:
111 String *val_str_ascii(String *buffer) override;
112
113 protected:
114 virtual bool calc_value(String *arg, String *buffer) = 0;
115};
116
117/*************************************************************************
118 Item_func_inet6_aton implements INET6_ATON() SQL-function.
119*************************************************************************/
120
122 public:
124 : Item_func_inet_str_base(pos, ip_addr) {}
125
126 public:
127 const char *func_name() const override { return "inet6_aton"; }
128
129 bool resolve_type(THD *thd) override {
130 if (param_type_is_default(thd, 0, 1)) return true;
132 set_nullable(true);
133 return false;
134 }
135
136 protected:
137 bool calc_value(String *arg, String *buffer) override;
138};
139
140/*************************************************************************
141 Item_func_inet6_ntoa implements INET6_NTOA() SQL-function.
142*************************************************************************/
143
145 public:
147 : Item_func_inet_str_base(pos, ip_addr) {}
148
149 public:
150 const char *func_name() const override { return "inet6_ntoa"; }
151
152 bool resolve_type(THD *thd) override {
153 if (param_type_is_default(thd, 0, 1)) return true;
154 // max length: IPv6-address -- 16 bytes
155 // 16 bytes / 2 bytes per group == 8 groups => 7 delimiter
156 // 4 symbols per group
158
159 set_nullable(true);
160 return false;
161 }
162
163 protected:
164 bool calc_value(String *arg, String *buffer) override;
165};
166
167/*************************************************************************
168 Item_func_is_ipv4 implements IS_IPV4() SQL-function.
169*************************************************************************/
170
172 public:
173 Item_func_is_ipv4(const POS &pos, Item *ip_addr)
174 : Item_func_inet_bool_base(pos, ip_addr) {}
175
176 public:
177 const char *func_name() const override { return "is_ipv4"; }
178
179 protected:
180 bool calc_value(const String *arg) const override;
181};
182
183/*************************************************************************
184 Item_func_is_ipv6 implements IS_IPV6() SQL-function.
185*************************************************************************/
186
188 public:
189 Item_func_is_ipv6(const POS &pos, Item *ip_addr)
190 : Item_func_inet_bool_base(pos, ip_addr) {}
191
192 public:
193 const char *func_name() const override { return "is_ipv6"; }
194
195 protected:
196 bool calc_value(const String *arg) const override;
197};
198
199/*************************************************************************
200 Item_func_is_ipv4_compat implements IS_IPV4_COMPAT() SQL-function.
201*************************************************************************/
202
204 public:
206 : Item_func_inet_bool_base(pos, ip_addr) {}
207
208 public:
209 const char *func_name() const override { return "is_ipv4_compat"; }
210
211 protected:
212 bool calc_value(const String *arg) const override;
213};
214
215/*************************************************************************
216 Item_func_is_ipv4_mapped implements IS_IPV4_MAPPED() SQL-function.
217*************************************************************************/
218
220 public:
222 : Item_func_inet_bool_base(pos, ip_addr) {}
223
224 public:
225 const char *func_name() const override { return "is_ipv4_mapped"; }
226
227 protected:
228 bool calc_value(const String *arg) const override;
229};
230
231#endif // ITEM_INETFUNC_INCLUDED
Definition: item_cmpfunc.h:292
Definition: item_inetfunc.h:121
const char * func_name() const override
Definition: item_inetfunc.h:127
Item_func_inet6_aton(const POS &pos, Item *ip_addr)
Definition: item_inetfunc.h:123
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_inetfunc.h:129
bool calc_value(String *arg, String *buffer) override
Converts IP-address-string to IP-address-data.
Definition: item_inetfunc.cc:693
Definition: item_inetfunc.h:144
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_inetfunc.h:152
bool calc_value(String *arg, String *buffer) override
Converts IP-address-data to IP-address-string.
Definition: item_inetfunc.cc:730
Item_func_inet6_ntoa(const POS &pos, Item *ip_addr)
Definition: item_inetfunc.h:146
const char * func_name() const override
Definition: item_inetfunc.h:150
Definition: item_inetfunc.h:41
const char * func_name() const override
Definition: item_inetfunc.h:49
Item_func_inet_aton(const POS &pos, Item *arg)
Definition: item_inetfunc.h:43
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_inetfunc.h:51
longlong val_int() override
Definition: item_inetfunc.cc:57
Definition: item_inetfunc.h:86
longlong val_int() override
Check the function argument, handle errors properly.
Definition: item_inetfunc.cc:193
virtual bool calc_value(const String *arg) const =0
Item_func_inet_bool_base(const POS &pos, Item *ip_addr)
Definition: item_inetfunc.h:88
Definition: item_inetfunc.h:63
Item_func_inet_ntoa(const POS &pos, Item *arg)
Definition: item_inetfunc.h:65
String * val_str(String *str) override
Definition: item_inetfunc.cc:129
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_inetfunc.h:73
const char * func_name() const override
Definition: item_inetfunc.h:71
Definition: item_inetfunc.h:105
virtual bool calc_value(String *arg, String *buffer)=0
String * val_str_ascii(String *buffer) override
Check the function argument, handle errors properly.
Definition: item_inetfunc.cc:222
Item_func_inet_str_base(const POS &pos, Item *arg)
Definition: item_inetfunc.h:107
Definition: item_inetfunc.h:203
Item_func_is_ipv4_compat(const POS &pos, Item *ip_addr)
Definition: item_inetfunc.h:205
const char * func_name() const override
Definition: item_inetfunc.h:209
bool calc_value(const String *arg) const override
Checks if the passed IPv6-address is an IPv4-compat IPv6-address.
Definition: item_inetfunc.cc:805
Definition: item_inetfunc.h:219
bool calc_value(const String *arg) const override
Checks if the passed IPv6-address is an IPv4-mapped IPv6-address.
Definition: item_inetfunc.cc:826
Item_func_is_ipv4_mapped(const POS &pos, Item *ip_addr)
Definition: item_inetfunc.h:221
const char * func_name() const override
Definition: item_inetfunc.h:225
Definition: item_inetfunc.h:171
Item_func_is_ipv4(const POS &pos, Item *ip_addr)
Definition: item_inetfunc.h:173
bool calc_value(const String *arg) const override
Checks if the passed string represents an IPv4-address.
Definition: item_inetfunc.cc:769
const char * func_name() const override
Definition: item_inetfunc.h:177
Definition: item_inetfunc.h:187
Item_func_is_ipv6(const POS &pos, Item *ip_addr)
Definition: item_inetfunc.h:189
const char * func_name() const override
Definition: item_inetfunc.h:193
bool calc_value(const String *arg) const override
Checks if the passed string represents an IPv6-address.
Definition: item_inetfunc.cc:787
bool param_type_is_default(THD *thd, uint start, uint end, uint step, enum_field_types def)
For arguments of this Item_func ("args" array), in range [start, start+step, start+2*step,...
Definition: item_func.cc:516
Definition: item_func.h:924
Definition: item_strfunc.h:143
Definition: item_strfunc.h:75
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:802
void set_nullable(bool nullable)
Definition: item.h:3334
static const CHARSET_INFO * default_charset()
Definition: item.cc:1620
bool null_value
True if item is null.
Definition: item.h:3359
bool unsigned_flag
Definition: item.h:3360
void set_data_type_string(uint32 max_l)
Set the Item to be variable length string.
Definition: item.h:1387
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:166
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:922
char * pos
Definition: do_ctype.cc:76
@ MYSQL_TYPE_LONGLONG
Definition: field_types.h:61
A better implementation of the UNIX ctype(3) library.
MYSQL_PLUGIN_IMPORT CHARSET_INFO my_charset_bin
Definition: ctype-bin.cc:510
Some integer typedefs for easier portability.
long long int longlong
Definition: my_inttypes.h:54
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1063
mutable_buffer buffer(void *p, size_t n) noexcept
Definition: buffer.h:418
Bison "location" class.
Definition: parse_location.h:42