MySQL 8.3.0
Source Code Documentation
mysql_status_variable_reader.h
Go to the documentation of this file.
1/* Copyright (c) 2022, 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_STATUS_VARIABLE_READER_H
24#define MYSQL_STATUS_VARIABLE_READER_H
25
29
30/**
31 @file
32 Read status variable values service(s)
33*/
34
35/**
36 @ingroup group_components_services_inventory
37
38 Service to read the value of a status variable as a string.
39
40 Used approximately as follows:
41
42 @code
43 my_h_string value = nullptr;
44 bool get_global = true; // or false
45 MYSQL_THD thd = nullptr; // use a temp thd
46 const char *name = "gizmo";
47 char buffer[1024];
48 const char *charset= "utf8mb4";
49
50 // try to get the current thd if there is one
51 if (!get_global && mysql_service_mysql_current_thread_reader->get(&thd)) {
52 // failed to get the current THD
53 *is_null = 1;
54 *error = 1;
55 return nullptr;
56 }
57 if (!mysql_service_mysql_status_variable_string->get(thd, name, get_global,
58 &str) && str && !mysql_service_mysql_string_converter->convert_to_buffer( str,
59 buffer, sizeof(buffer) - 1, charset)) {
60 mysql_service_mysql_string_factory->destroy(str);
61 // the value is in buffer
62 }
63
64 // wasn't able to get the value. do cleanup
65 if (str) mysql_service_mysql_string_factory->destroy(str);
66 @endcode
67
68 @sa mysql_status_variable_reader_imp
69*/
70BEGIN_SERVICE_DEFINITION(mysql_status_variable_string)
71
72/**
73 Gets the string value of a status variable
74
75 Will read the value of the status variable supplied, convert to a string
76 as needed and store into the out_string parameter as a @ref my_h_string.
77
78 @note No status variable values aggregation will be done from the threads
79 to the globals. Will keep the status variable lock while extracting the value.
80
81 @warning The function will return an error if you do not supply a session
82 and request the session value.
83
84 @param thd The THD to operate on or a nullptr to create a temp THD
85 @param name The name of the status variable to access. US ASCII
86 @param get_global true if the global value of the status variable is
87 required, false if the session one.
88 @param [out] out_string a place to store the value
89 @return Status of the operation
90 @retval false success
91 @retval true failure
92
93 @sa mysql_status_variable_reader_imp::get
94*/
95DECLARE_BOOL_METHOD(get, (MYSQL_THD thd, const char *name, bool get_global,
96 my_h_string *out_string));
97
98END_SERVICE_DEFINITION(mysql_status_variable_string)
99
100#endif /* MYSQL_STATUS_VARIABLE_READER_H */
#define MYSQL_THD
Definition: backup_page_tracker.h:37
void get(PSI_field *, PSI_longlong *) noexcept
Definition: pfs_plugin_column_bigint_v1_all_empty.cc:31
#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
case opt name
Definition: sslopt-case.h:32
Definition: mysql_string_service.cc:59