830
unsigned char *sys_var_session_bool::value_ptr(Session *session,
832
const lex_string_t *)
821
unsigned char *sys_var_session_bool::value_ptr(Session *session, sql_var_t type)
834
if (type == OPT_GLOBAL)
835
return (unsigned char*) &(global_system_variables.*offset);
836
return (unsigned char*) &(session->variables.*offset);
823
return type == OPT_GLOBAL
824
? (unsigned char*) &(global_system_variables.*offset)
825
: (unsigned char*) &(session->variables.*offset);
840
bool sys_var::check_enum(Session *,
841
set_var *var, const TYPELIB *enum_names)
829
bool sys_var::check_enum(Session *, set_var *var, const TYPELIB *enum_names)
843
831
char buff[STRING_BUFFER_USUAL_SIZE];
844
832
const char *value;
888
876
If type is not given, return local value if exists, else global.
891
Item *sys_var::item(Session *session, sql_var_t var_type, const lex_string_t *base)
879
Item *sys_var::item(Session *session, sql_var_t var_type)
893
881
if (check_type(var_type))
895
883
if (var_type != OPT_DEFAULT)
897
my_error(ER_INCORRECT_GLOBAL_LOCAL_VAR, MYF(0),
898
name.c_str(), var_type == OPT_GLOBAL ? "SESSION" : "GLOBAL");
885
my_error(ER_INCORRECT_GLOBAL_LOCAL_VAR, MYF(0), name.c_str(), var_type == OPT_GLOBAL ? "SESSION" : "GLOBAL");
901
888
/* As there was no local variable, return the global value */
902
889
var_type= OPT_GLOBAL;
904
switch (show_type()) {
891
boost::mutex::scoped_lock lock(session->catalog().systemVariableLock());
909
boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
910
value= *(uint*) value_ptr(session, var_type, base);
897
uint32_t value= *(uint*) value_ptr(session, var_type);
912
898
return new Item_uint((uint64_t) value);
914
900
case SHOW_LONGLONG:
917
boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
918
value= *(int64_t*) value_ptr(session, var_type, base);
902
int64_t value= *(int64_t*) value_ptr(session, var_type);
920
903
return new Item_int(value);
922
905
case SHOW_DOUBLE:
926
boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
927
value= *(double*) value_ptr(session, var_type, base);
907
double value= *(double*) value_ptr(session, var_type);
930
908
/* 6, as this is for now only used with microseconds */
931
909
return new Item_float(value, 6);
933
911
case SHOW_HA_ROWS:
936
boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
937
value= *(ha_rows*) value_ptr(session, var_type, base);
913
ha_rows value= *(ha_rows*) value_ptr(session, var_type);
939
914
return new Item_int((uint64_t) value);
944
boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
945
value= *(size_t*) value_ptr(session, var_type, base);
918
size_t value= *(size_t*) value_ptr(session, var_type);
947
919
return new Item_int((uint64_t) value);
949
921
case SHOW_MY_BOOL:
952
boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
953
value= *(bool*) value_ptr(session, var_type, base);
954
return new Item_int(value,1);
923
int32_t value= *(bool*) value_ptr(session, var_type);
924
return new Item_int(value, 1);
956
926
case SHOW_CHAR_PTR:
959
boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
960
char *str= *(char**) value_ptr(session, var_type, base);
928
if (const char *str= *(char**) value_ptr(session, var_type))
963
930
uint32_t length= strlen(str);
964
tmp= new Item_string(session->mem.strdup(str, length), length, system_charset_info, DERIVATION_SYSCONST);
968
tmp= new Item_null();
969
tmp->collation.set(system_charset_info, DERIVATION_SYSCONST);
931
return new Item_string(session->mem.strdup(str, length), length, system_charset_info, DERIVATION_SYSCONST);
933
Item* tmp= new Item_null();
934
tmp->collation.set(system_charset_info, DERIVATION_SYSCONST);
976
boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
977
if (const char* str= (char*) value_ptr(session, var_type, base))
939
if (const char* str= (char*) value_ptr(session, var_type))
978
940
return new Item_string(str_ref(str), system_charset_info, DERIVATION_SYSCONST);
979
941
Item* tmp= new Item_null();
980
942
tmp->collation.set(system_charset_info, DERIVATION_SYSCONST);
1009
unsigned char *sys_var_session_enum::value_ptr(Session *session,
1011
const lex_string_t *)
971
unsigned char *sys_var_session_enum::value_ptr(Session *session, sql_var_t type)
1013
uint32_t tmp= ((type == OPT_GLOBAL) ?
1014
global_system_variables.*offset :
1015
session->variables.*offset);
973
uint32_t tmp= type == OPT_GLOBAL ? global_system_variables.*offset : session->variables.*offset;
1016
974
return (unsigned char*) enum_names->type_names[tmp];
1019
977
bool sys_var_session_bit::check(Session *session, set_var *var)
1021
return (check_enum(session, var, &bool_typelib) ||
1022
(check_func && (*check_func)(session, var)));
979
return check_enum(session, var, &bool_typelib) || (check_func && (*check_func)(session, var));
1025
982
bool sys_var_session_bit::update(Session *session, set_var *var)
1027
int res= (*update_func)(session, var);
984
return (*update_func)(session, var);
1032
unsigned char *sys_var_session_bit::value_ptr(Session *session, sql_var_t,
1033
const lex_string_t *)
988
unsigned char *sys_var_session_bit::value_ptr(Session *session, sql_var_t)
1036
991
If reverse is 0 (default) return 1 if bit is set.
1037
992
If reverse is 1, return 0 if bit is set
1039
session->sys_var_tmp.bool_value= ((session->options & bit_flag) ?
1040
!reverse : reverse);
994
session->sys_var_tmp.bool_value= (session->options & bit_flag) ? !reverse : reverse;
1041
995
return (unsigned char*) &session->sys_var_tmp.bool_value;
1560
1502
Functions to handle table_type
1561
1503
****************************************************************************/
1563
unsigned char *sys_var_session_storage_engine::value_ptr(Session *session,
1565
const lex_string_t *)
1505
unsigned char *sys_var_session_storage_engine::value_ptr(Session *session, sql_var_t type)
1567
plugin::StorageEngine *engine= session->variables.*offset;
1568
if (type == OPT_GLOBAL)
1569
engine= global_system_variables.*offset;
1570
string engine_name= engine->getName();
1571
return (unsigned char *) session->mem.strdup(engine_name);
1507
plugin::StorageEngine *engine= type == OPT_GLOBAL
1508
? global_system_variables.*offset
1509
: session->variables.*offset;
1510
return (unsigned char *) session->mem.strdup(engine->getName());