MySQL 8.3.0
Source Code Documentation
mysql_system_variable.h
Go to the documentation of this file.
1/* Copyright (c) 2021, 2023, Oracle and/or its affiliates.
2
3This program is free software; you can redistribute it and/or modify
4it under the terms of the GNU General Public License, version 2.0,
5as published by the Free Software Foundation.
6
7This program is also distributed with certain software (including
8but not limited to OpenSSL) that is licensed under separate terms,
9as designated in a particular file or component or in included license
10documentation. The authors of MySQL hereby grant you an additional
11permission to link the program and your derivative works with the
12separately licensed software that they have included with MySQL.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU General Public License, version 2.0, for more details.
18
19You should have received a copy of the GNU General Public License
20along with this program; if not, write to the Free Software
21Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23#ifndef MYSQL_SYSTEM_VARIABLES_H
24#define MYSQL_SYSTEM_VARIABLES_H
25
28#include <mysql/components/services/mysql_string.h> // my_h_string
29
30/**
31 @ingroup group_components_services_inventory
32
33 Service to set the value of system variables.
34 This is an example of using the service:
35
36 @code
37
38 MYSQL_THD thd = nullptr;
39
40 if (!make_new_thread &&
41 mysql_service_mysql_current_thread_reader->get(&thd)) {
42 *error = 1;
43 return 0;
44 }
45
46 const char *cs = "latin1";
47 const char *base_input = "my_component"; //nullptr if not a component variable
48 const char *name_input = "my_variable";
49 const char *value_input = "value";
50 const char *type = "GLOBAL";
51
52 my_h_string base = nullptr, name = nullptr, value = nullptr;
53 if ((base != nullptr &&
54 mysql_service_mysql_string_converter->convert_from_buffer(
55 &base, base_input, strlen(base_input), cs)) ||
56 mysql_service_mysql_string_converter->convert_from_buffer(
57 &name, name_input, strlen(name_input), cs) ||
58 mysql_service_mysql_string_converter->convert_from_buffer(
59 &value, value_input, strlen(value_input), cs) {
60 if (base) mysql_service_mysql_string_factory->destroy(base);
61 if (name) mysql_service_mysql_string_factory->destroy(name);
62 if (value) mysql_service_mysql_string_factory->destroy(value);
63 *error = 1;
64 return 0;
65 }
66
67 if (mysql_service_mysql_system_variable_update_string->set(thd, type,
68 base, name, value)) *error = 1;
69
70 if (base) mysql_service_mysql_string_factory->destroy(base);
71 if (name) mysql_service_mysql_string_factory->destroy(name);
72 if (value) mysql_service_mysql_string_factory->destroy(value);
73 @endcode
74
75
76 @sa @ref mysql_system_variable_update_imp
77*/
78BEGIN_SERVICE_DEFINITION(mysql_system_variable_update_string)
79
80/**
81 Sets the value of a system variable to a new string value.
82
83 @param thd thread session handle. if NULL a temp one will be created and then
84 removed.
85 @param set_variable_type: one of [GLOBAL, PERSIST, PERSIST_ONLY].
86 If NULL, then assumes GLOBAL.
87 @param variable_name_base: a mysql string of the variable name prefix. NULL
88 of none
89 @param variable_name: a mysql string of the variable name
90 @param variable_value: a mysql string to set as value
91 @retval FALSE: success
92 @retval TRUE: failure, see THD if supplied.
93*/
95 (MYSQL_THD thd, const char *set_variable_type,
96 my_h_string variable_name_base, my_h_string variable_name,
97 my_h_string variable_value));
98END_SERVICE_DEFINITION(mysql_system_variable_update_string)
99
100/**
101 @ingroup group_components_services_inventory
102
103 Service to set the value of integer system variables.
104
105 Passing non-NULL THD input to setter methods means that the operation will be
106 executed within the scope of existing transaction, thus any operation side
107 effects impacting transaction itself (for example it may generate an SQL error
108 that it stores into the current THD). If using existing THD, security context
109 of the thread is checked to make sure that required privileges exist. Passing
110 NULL makes a temporary THD created as a execution context (and destroyed
111 afterwards), i.e. no impacts on existing transactions. It doesn't make sense
112 to change SESSION variable on a temporary THD, so this operation will generate
113 error.
114
115 This is an example of using the service:
116
117 @code
118
119 MYSQL_THD thd = nullptr;
120
121 if (!make_new_thread &&
122 mysql_service_mysql_current_thread_reader->get(&thd)) {
123 *error = 1;
124 return 0;
125 }
126
127 const char *cs = "latin1";
128 const char *base_input = "my_component"; //nullptr if not a component variable
129 const char *name_input = "my_variable";
130 const char *type = "SESSION";
131 long long value_signed = 100000;
132 unsigned long long value_unsigned = 500000;
133
134 my_h_string base = nullptr, name = nullptr;
135 if ((base != nullptr &&
136 mysql_service_mysql_string_converter->convert_from_buffer(
137 &base, base_input, strlen(base_input), cs)) ||
138 mysql_service_mysql_string_converter->convert_from_buffer(
139 &name, name_input, strlen(name_input), cs)) {
140 if (base) mysql_service_mysql_string_factory->destroy(base);
141 if (name) mysql_service_mysql_string_factory->destroy(name);
142 *error = 1;
143 return 0;
144 }
145
146 // example call for signed integer system variable type
147 if (mysql_service_mysql_system_variable_update_integer->set_signed(
148 thd, type, base, name, value_signed))
149 *error = 1;
150
151 // alternative call for unsigned integer type
152 if (mysql_service_mysql_system_variable_update_integer->set_unsigned(
153 thd, type, base, name, value_unsigned))
154 *error = 1;
155
156 if (base) mysql_service_mysql_string_factory->destroy(base);
157 if (name) mysql_service_mysql_string_factory->destroy(name);
158 @endcode
159
160
161 @sa @ref mysql_system_variable_update_imp
162*/
163BEGIN_SERVICE_DEFINITION(mysql_system_variable_update_integer)
164
165/**
166 Sets the value of a system variable to a new signed integer value.
167
168 Uses long long type to store the data, this type size may
169 differ on a different environments (32-bit vs 64-bit builds for example).
170 This means that the user must ensure that component using this API was
171 compiled using the same environment as for the server code.
172
173 @param thd thread session handle. if NULL a temp one will be created and then
174 removed.
175 @param variable_type: One of GLOBAL, SESSION, PERSIST, PERSIST_ONLY.
176 If NULL, then assumes GLOBAL. SESSION is not supported
177 for a temporary THD.
178 @param variable_base: a mysql string of the variable name prefix. NULL if
179 none
180 @param variable_name: MySQL string of the variable name
181 @param variable_value: long long to set as value
182 @retval FALSE: success
183 @retval TRUE: failure, error set. For error info, see THD if supplied.
184*/
185DECLARE_BOOL_METHOD(set_signed,
186 (MYSQL_THD thd, const char *variable_type,
187 my_h_string variable_base, my_h_string variable_name,
188 long long variable_value));
189
190/**
191 Sets the value of a system variable to a new unsigned integer value.
192
193 Uses unsigned long long type to store the data, this type size may
194 differ on a different environments (32-bit vs 64-bit builds for example).
195 This means that the user must ensure that component using this API was
196 compiled using the same environment as for the server code.
197
198 @param thd thread session handle. if NULL a temp one will be created and then
199 removed.
200 @param variable_type: One of GLOBAL, SESSION, PERSIST, PERSIST_ONLY.
201 If NULL, then assumes GLOBAL. SESSION is not supported
202 for a temporary THD.
203 @param variable_base: a mysql string of the variable name prefix. NULL if
204 none
205 @param variable_name: MySQL string of the variable name
206 @param variable_value: unsigned long long to set as value
207 @retval FALSE: success
208 @retval TRUE: failure, error set. For error info, see THD if supplied.
209 */
211 (MYSQL_THD thd, const char *variable_type,
212 my_h_string variable_base, my_h_string variable_name,
213 unsigned long long variable_value));
214END_SERVICE_DEFINITION(mysql_system_variable_update_integer)
215
216/**
217 @ingroup group_components_services_inventory
218
219 Service to set the default value of system variables.
220 This is an example of using the service:
221
222 @code
223
224 MYSQL_THD thd = nullptr;
225
226 if (!make_new_thread &&
227 mysql_service_mysql_current_thread_reader->get(&thd)) {
228 *error = 1;
229 return 0;
230 }
231
232 const char *cs = "latin1";
233 const char *base_input = "my_component"; //nullptr if not a component variable
234 const char *name_input = "my_variable";
235 const char *type = "PERSIST";
236
237 my_h_string base = nullptr, name = nullptr;
238 if ((base != nullptr &&
239 mysql_service_mysql_string_converter->convert_from_buffer(
240 &base, base_input, strlen(base_input), cs)) ||
241 mysql_service_mysql_string_converter->convert_from_buffer(
242 &name, name_input, strlen(name_input), cs)) {
243 if (base) mysql_service_mysql_string_factory->destroy(base);
244 if (name) mysql_service_mysql_string_factory->destroy(name);
245 *error = 1;
246 return 0;
247 }
248
249 if (mysql_service_mysql_system_variable_update_default->set(
250 thd, type, base, name))
251 *error = 1;
252
253 if (base) mysql_service_mysql_string_factory->destroy(base);
254 if (name) mysql_service_mysql_string_factory->destroy(name);
255 @endcode
256
257
258 @sa @ref mysql_system_variable_update_imp
259*/
260BEGIN_SERVICE_DEFINITION(mysql_system_variable_update_default)
261
262/**
263 Sets the value of a system variable to its default value.
264
265 @sa @ref group_components_services_inventory
266
267 @param thd thread session handle. if NULL a temp one will be created and then
268 removed.
269 @param variable_type: One of GLOBAL, SESSION, PERSIST, PERSIST_ONLY.
270 If NULL, then assumes GLOBAL. SESSION is not supported
271 for a temporary THD.
272 @param variable_base: a mysql string of the variable name prefix. NULL if
273 none
274 @param variable_name: MySQL string of the variable name
275 @retval FALSE: success
276 @retval TRUE: failure, error set. For error info, see THD if supplied.
277*/
279 (MYSQL_THD thd, const char *variable_type,
280 my_h_string variable_base, my_h_string variable_name));
281END_SERVICE_DEFINITION(mysql_system_variable_update_default)
282
283#endif /* MYSQL_SYSTEM_VARIABLES_H */
#define MYSQL_THD
Definition: backup_page_tracker.h:37
void set_unsigned(PSI_field *, PSI_ulonglong) noexcept
Definition: pfs_plugin_column_bigint_v1_all_empty.cc:30
std::set< Key, Compare, ut::allocator< Key > > set
Specialization of set which uses ut_allocator.
Definition: ut0new.h:2881
#define END_SERVICE_DEFINITION(name)
A macro to end the last Service definition started with the BEGIN_SERVICE_DEFINITION macro.
Definition: service.h:90
#define BEGIN_SERVICE_DEFINITION(name)
Declares a new Service.
Definition: service.h:85
#define DECLARE_BOOL_METHOD(name, args)
Declares a method that returns bool as a part of the Service definition.
Definition: service.h:111
Definition: mysql_string_service.cc:59