MySQL  8.0.15
Source Code Documentation
user_var_entry Class Reference

#include <item_func.h>

Public Member Functions

 user_var_entry ()
 
bool store (const void *ptr, size_t length, Item_result type, const CHARSET_INFO *cs, Derivation dv, bool unsigned_arg)
 Store a value of the given type and attributes (collation, sign) into a user_var_entry instance. More...
 
void set_type (Item_result type)
 Set type of to the given value. More...
 
void set_null_value (Item_result type)
 Set value to NULL. More...
 
void destroy ()
 Free all memory used by a user_var_entry instance previously created by create(). More...
 
void lock ()
 
void unlock ()
 
const char * ptr () const
 
size_t length () const
 
Item_result type () const
 
double val_real (bool *null_value) const
 Get the value of a variable as a double. More...
 
longlong val_int (bool *null_value) const
 Get the value of a variable as an integer. More...
 
Stringval_str (bool *null_value, String *str, uint decimals) const
 Get the value of a variable as a string. More...
 
my_decimalval_decimal (bool *null_value, my_decimal *result) const
 Get the value of a variable as a decimal. More...
 

Static Public Member Functions

static user_var_entrycreate (THD *thd, const Name_string &name, const CHARSET_INFO *cs)
 Allocates and initializes a user variable instance. More...
 

Public Attributes

Simple_cstring entry_name
 
DTCollation collation
 
query_id_t update_query_id
 
query_id_t used_query_id
 
bool unsigned_flag
 

Private Member Functions

void reset_value ()
 
void set_value (char *value, size_t length)
 
char * internal_buffer_ptr () const
 Position inside a user_var_entry where small values are stored: double values, longlong values and string values with length up to extra_size (should be 8 bytes on all platforms). More...
 
char * name_ptr () const
 Position inside a user_var_entry where a null-terminates array of characters representing the variable name is stored. More...
 
bool mem_realloc (size_t length)
 Initialize m_ptr to the internal buffer (if the value is small enough), or allocate a separate buffer. More...
 
bool alloced ()
 Check if m_ptr point to an external buffer previously alloced by realloc(). More...
 
void free_value ()
 Free the external value buffer, if it's allocated. More...
 
void copy_name (const Simple_cstring &name)
 Copy the array of characters from the given name into the internal name buffer and initialize entry_name to point to it. More...
 
void init (THD *thd, const Simple_cstring &name, const CHARSET_INFO *cs)
 Initialize all members. More...
 
bool store (const void *from, size_t length, Item_result type)
 Store a value of the given type into a user_var_entry instance. More...
 
void assert_locked () const
 Assert the user variable is locked. More...
 

Private Attributes

char * m_ptr
 
size_t m_length
 
Item_result m_type
 
THDm_owner
 

Static Private Attributes

static const size_t extra_size = sizeof(double)
 

Constructor & Destructor Documentation

◆ user_var_entry()

user_var_entry::user_var_entry ( )
inline

Member Function Documentation

◆ alloced()

bool user_var_entry::alloced ( )
inlineprivate

Check if m_ptr point to an external buffer previously alloced by realloc().

Return values
true- an external buffer is alloced.
false- m_ptr is null, or points to the internal buffer.

◆ assert_locked()

void user_var_entry::assert_locked ( ) const
private

Assert the user variable is locked.

This is debug code only. The thread LOCK_thd_data mutex protects:

  • the thd->user_vars hash itself
  • the values in the user variable itself. The protection is required for monitoring, as a different thread can inspect this session user variables, on a live session.

◆ copy_name()

void user_var_entry::copy_name ( const Simple_cstring name)
inlineprivate

Copy the array of characters from the given name into the internal name buffer and initialize entry_name to point to it.

◆ create()

user_var_entry * user_var_entry::create ( THD thd,
const Name_string name,
const CHARSET_INFO cs 
)
static

Allocates and initializes a user variable instance.

Parameters
thdCurrent session.
nameName of the variable.
csCharset of the variable.
Returns
Address of the allocated and initialized user_var_entry instance.
Return values
NULLOn allocation error.

◆ destroy()

void user_var_entry::destroy ( )
inline

Free all memory used by a user_var_entry instance previously created by create().

◆ free_value()

void user_var_entry::free_value ( )
inlineprivate

Free the external value buffer, if it's allocated.

◆ init()

void user_var_entry::init ( THD thd,
const Simple_cstring name,
const CHARSET_INFO cs 
)
private

Initialize all members.

Parameters
thdCurrent session.
nameName of the user_var_entry instance.
cscharset information of the user_var_entry instance.

◆ internal_buffer_ptr()

char* user_var_entry::internal_buffer_ptr ( ) const
inlineprivate

Position inside a user_var_entry where small values are stored: double values, longlong values and string values with length up to extra_size (should be 8 bytes on all platforms).

String values with length longer than 8 are stored in a separate memory buffer, which is allocated when needed using the method realloc().

◆ length()

size_t user_var_entry::length ( ) const
inline

◆ lock()

void user_var_entry::lock ( )

◆ mem_realloc()

bool user_var_entry::mem_realloc ( size_t  length)
private

Initialize m_ptr to the internal buffer (if the value is small enough), or allocate a separate buffer.

Parameters
length- length of the value to be stored.

◆ name_ptr()

char* user_var_entry::name_ptr ( ) const
inlineprivate

Position inside a user_var_entry where a null-terminates array of characters representing the variable name is stored.

◆ ptr()

const char* user_var_entry::ptr ( ) const
inline

◆ reset_value()

void user_var_entry::reset_value ( )
inlineprivate

◆ set_null_value()

void user_var_entry::set_null_value ( Item_result  type)
inline

Set value to NULL.

Parameters
typeData type.

◆ set_type()

void user_var_entry::set_type ( Item_result  type)
inline

Set type of to the given value.

Parameters
typeData type.

◆ set_value()

void user_var_entry::set_value ( char *  value,
size_t  length 
)
inlineprivate

◆ store() [1/2]

bool user_var_entry::store ( const void *  from,
size_t  length,
Item_result  type 
)
private

Store a value of the given type into a user_var_entry instance.

Set value to user variable.

Parameters
fromValue
lengthSize of the value
typetype
Returns
Return values
falseon success
trueon memory allocation error
Parameters
frompointer to buffer with new value
lengthlength of new value
typetype of new value
Return values
falseon success
trueon allocation error

◆ store() [2/2]

bool user_var_entry::store ( const void *  ptr,
size_t  length,
Item_result  type,
const CHARSET_INFO cs,
Derivation  dv,
bool  unsigned_arg 
)

Store a value of the given type and attributes (collation, sign) into a user_var_entry instance.

Set value to user variable.

Parameters
ptrValue
lengthSize of the value
typetype
csCharacter set and collation of the value
dvCollation derivation of the value
unsigned_argSigness of the value
Returns
Return values
falseon success
trueon memory allocation error
Parameters
ptrpointer to buffer with new value
lengthlength of new value
typetype of new value
cscharset info for new value
dvderivation for new value
unsigned_argindiates if a value of type INT_RESULT is unsigned
Note
Sets error and fatal error if allocation fails.
Return values
falsesuccess
truefailure

◆ type()

Item_result user_var_entry::type ( ) const
inline

◆ unlock()

void user_var_entry::unlock ( )

◆ val_decimal()

my_decimal * user_var_entry::val_decimal ( bool null_value,
my_decimal val 
) const

Get the value of a variable as a decimal.

◆ val_int()

longlong user_var_entry::val_int ( bool null_value) const

Get the value of a variable as an integer.

◆ val_real()

double user_var_entry::val_real ( bool null_value) const

Get the value of a variable as a double.

◆ val_str()

String * user_var_entry::val_str ( bool null_value,
String str,
uint  decimals 
) const

Get the value of a variable as a string.

Member Data Documentation

◆ collation

DTCollation user_var_entry::collation

◆ entry_name

Simple_cstring user_var_entry::entry_name

◆ extra_size

const size_t user_var_entry::extra_size = sizeof(double)
staticprivate

◆ m_length

size_t user_var_entry::m_length
private

◆ m_owner

THD* user_var_entry::m_owner
private

◆ m_ptr

char* user_var_entry::m_ptr
private

◆ m_type

Item_result user_var_entry::m_type
private

◆ unsigned_flag

bool user_var_entry::unsigned_flag

◆ update_query_id

query_id_t user_var_entry::update_query_id

◆ used_query_id

query_id_t user_var_entry::used_query_id

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