MySQL 8.0.39
Source Code Documentation
Set_variables_helper Class Reference

A helper class to fascilitate executing SET on system variables. More...

#include <set_variables_helper.h>

Public Member Functions

 Set_variables_helper (THD *existing_thd)
 Initializes the helper and switches to the canned temp LEX. More...
 
 ~Set_variables_helper ()
 
bool add_variable (const char *prefix, size_t prefix_length, const char *suffix, size_t suffix_length, Item *variable_value, enum_var_type var_type)
 Adds setting one variable instruction. More...
 
bool execute ()
 Executes the SET command for all variables added. More...
 
THDget_thd ()
 
bool is_auto_thd ()
 
bool check_variable_update_type (const char *prefix, size_t prefix_length, const char *suffix, size_t suffix_length, Item *variable_value)
 Checks the update type for the system variable and throws error if any found. More...
 

Private Attributes

List< set_var_basem_sysvar_list
 
THDm_thd
 
LEXm_lex_save
 
LEX m_lex_tmp
 
Storing_auto_THDm_thd_auto
 

Detailed Description

A helper class to fascilitate executing SET on system variables.

Runs in the current THD, but in a temp LEX to avoid polluting the THD::lex with the changes.

Useful for service implementations looking to set values to system variables.

Should be used in a single THD.

A proper usage is something of the sort:

THD *curr_thd = ...; Item *value1 = Item_int(20), *val2= Item_int(30);

Set_variables_helper hlp(curr_thd);

if (hlp.add_variable(nullptr, 0, "foo", 3, enum_var_type::PERSIST_ONLY, value1)) return true;

if (hlp.add_variable("bar", 3, "baz", 3, enum_var_type::PERSIST, val2)) return true;

...

if (hlp->execute()) return true;

The above executes the following command SET PERSIST_ONLY foo = 20, PERSIST bar.baz = 30;

See also
sql_set_variables

Constructor & Destructor Documentation

◆ Set_variables_helper()

Set_variables_helper::Set_variables_helper ( THD existing_thd)

Initializes the helper and switches to the canned temp LEX.

Parameters
existing_thdthe THD to execute on.

◆ ~Set_variables_helper()

Set_variables_helper::~Set_variables_helper ( )

Member Function Documentation

◆ add_variable()

bool Set_variables_helper::add_variable ( const char *  prefix,
size_t  prefix_length,
const char *  suffix,
size_t  suffix_length,
Item variable_value,
enum_var_type  var_type 
)

Adds setting one variable instruction.

Adds a:

<var_type> [prefix.]suffix = variable_value

to the SET command being constructed.

Parameters
prefixthe prefix for the variable name or nullptr if none
prefix_lengthlength of prefix, 0 if empty
suffixthe name of the variable to set. Must be nonnull
suffix_lengththe length of suffix
variable_valuethe value to set
var_typehow to set: PERSIST, PERSIST_ONLY etc
Return values
truefailure
falsesuccess

◆ check_variable_update_type()

bool Set_variables_helper::check_variable_update_type ( const char *  prefix,
size_t  prefix_length,
const char *  suffix,
size_t  suffix_length,
Item variable_value 
)

Checks the update type for the system variable and throws error if any found.

Parameters
prefixthe prefix for the variable name or nullptr if none
prefix_lengthlength of prefix, 0 if empty
suffixthe name of the variable to set. Must be nonnull
suffix_lengththe length of suffix
variable_valuethe value to set
Return values
truefailure
falsesuccess

◆ execute()

bool Set_variables_helper::execute ( )

Executes the SET command for all variables added.

Return values
truefailure
falsesuccess

◆ get_thd()

THD * Set_variables_helper::get_thd ( )
inline

◆ is_auto_thd()

bool Set_variables_helper::is_auto_thd ( )
inline

Member Data Documentation

◆ m_lex_save

LEX* Set_variables_helper::m_lex_save
private

◆ m_lex_tmp

LEX Set_variables_helper::m_lex_tmp
private

◆ m_sysvar_list

List<set_var_base> Set_variables_helper::m_sysvar_list
private

◆ m_thd

THD* Set_variables_helper::m_thd
private

◆ m_thd_auto

Storing_auto_THD* Set_variables_helper::m_thd_auto
private

The documentation for this class was generated from the following files: