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