MySQL 9.0.0
Source Code Documentation
s_mysql_mysql_system_variable_reader Struct Reference

Fetches the session/global/persist value of a system variable. More...

#include <mysql_system_variable.h>

Public Attributes

mysql_service_status_t(* get )(THD *hthd, const char *variable_type, const char *component_name, const char *variable_name, void **val, size_t *out_length_of_val)
 Gets the value of a system variable. More...
 

Detailed Description

Fetches the session/global/persist value of a system variable.

This is an example of using the service:

Call this to get the session/global/persist value of a variable. You can access both the component variables (SELECT ["@@"][scope "."]component_name "." variable_name; where scope ::= SESSION | LOCAL | GLOBAL) and the "legacy" system variables (SELECT ["@@"][scope "."].variable_name; where scope ::= SESSION | LOCAL | GLOBAL) that are registered by the server component. To access the latter you need to pass "mysql_server" (lowercase) as a component name.

A pointer to the value is returned into the val input/output argument. And the length of the value (as applicable) is returned into the out_length_of_val argument.

In case when the user buffer was too small to copy the value, the call fails and needed buffer size is returned by 'out_length_of_val'.

Decide on a variable storage type among one of "GLOBAL" or "SESSION"

Typical use (char * variable):

char *value, buffer_for_value[160];
size_t value_length;
const char *type = "GLOBAL";
value= &buffer_for_value[0];
value_length= sizeof(buffer_for_value) - 1;
mysql_service_mysql_system_variable_reader->get(nullptr, type, "foo", "bar",
&value, &value_length);
printf("%.*s", (int) value_length, value);
To get the "SESSION" value the "hthd" should be passed :
MYSQL_THD hthd;
if (mysql_service_mysql_current_thread_reader->get(&hthd)) {
my_error("%s\n", "mysql_current_thread_reader get() api failed");
}
mysql_service_mysql_system_variable_reader->get(
hthd, "SESSION", "foo", "bar",
&value, &value_length);
#define MYSQL_THD
Definition: backup_page_tracker.h:38
void my_error(int nr, myf MyFlags,...)
Fill in and print a previously registered error message.
Definition: my_error.cc:216
required string type
Definition: replication_group_member_actions.proto:34
mysql_service_status_t(* get)(THD *hthd, const char *variable_type, const char *component_name, const char *variable_name, void **val, size_t *out_length_of_val)
Gets the value of a system variable.
Definition: mysql_system_variable.h:177

Member Data Documentation

◆ get

mysql_service_status_t(* s_mysql_mysql_system_variable_reader::get) (THD *hthd, const char *variable_type, const char *component_name, const char *variable_name, void **val, size_t *out_length_of_val)

Gets the value of a system variable.

Parameters
hthdthread session handle. if NULL, the GLOBAL value of the variable is returned.
variable_typeone of [GLOBAL, SESSION].
component_nameName of the component or "mysql_server" for the legacy ones.
variable_nameName of the variable
[in,out]valOn input: a buffer to hold the value. On output a pointer to the value.
[in,out]out_length_of_valOn input: the buffer size. On output the length of the data copied.
Return values
truefailure
falsesuccess

The documentation for this struct was generated from the following file: