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