42#include <drizzled/vc_version.h>
43#include <drizzled/option.h>
44#include <drizzled/error.h>
45#include <drizzled/gettext.h>
46#include <drizzled/data_home.h>
47#include <drizzled/set_var.h>
48#include <drizzled/session.h>
49#include <drizzled/session/times.h>
50#include <drizzled/sql_base.h>
51#include <drizzled/lock.h>
52#include <drizzled/item/uint.h>
53#include <drizzled/item/null.h>
54#include <drizzled/item/float.h>
55#include <drizzled/item/string.h>
56#include <drizzled/plugin.h>
57#include <drizzled/version.h>
58#include <drizzled/internal/m_string.h>
59#include <drizzled/pthread_globals.h>
60#include <drizzled/charset.h>
61#include <drizzled/transaction_services.h>
62#include <drizzled/constrained_value.h>
64#include <drizzled/typelib.h>
65#include <drizzled/plugin/storage_engine.h>
66#include <drizzled/system_variables.h>
67#include <drizzled/catalog/instance.h>
80extern struct option my_long_options[];
82extern size_t my_thread_stack_size;
84typedef map<string, sys_var *> SystemVariableMap;
85static SystemVariableMap system_variable_map;
86extern char *opt_drizzle_tmpdir;
88extern TYPELIB tx_isolation_typelib;
92 static size_t revno= DRIZZLE_VC_REVNO;
93 static size_t release_id= DRIZZLE_VERSION_ID;
96const char *bool_type_names[]= {
"OFF",
"ON", NULL };
99 array_elements(bool_type_names)-1,
"", bool_type_names, NULL
106static void fix_tx_isolation(
Session*, sql_var_t);
109static void fix_session_mem_root(
Session*, sql_var_t);
110void throw_bounds_warning(
Session*,
bool fixed,
bool unsignd,
const std::string &name, int64_t);
111static unsigned char *get_error_count(
Session*);
112static unsigned char *get_warning_count(
Session*);
125sys_auto_increment_increment(
"auto_increment_increment", &drizzle_system_variables::auto_increment_increment);
127sys_auto_increment_offset(
"auto_increment_offset", &drizzle_system_variables::auto_increment_offset);
133static sys_var_size_t_ptr sys_thread_stack_size(
"thread_stack", &my_thread_stack_size);
136static sys_var_session_uint64_t sys_bulk_insert_buff_size(
"bulk_insert_buffer_size", &drizzle_system_variables::bulk_insert_buff_size);
137static sys_var_session_uint32_t sys_completion_type(
"completion_type", &drizzle_system_variables::completion_type, check_completion_type);
139sys_collation_server(
"collation_server", &drizzle_system_variables::collation_server, &default_charset_info);
143static sys_var_session_uint32_t sys_max_allowed_packet(
"max_allowed_packet", &drizzle_system_variables::max_allowed_packet);
145static sys_var_session_uint64_t sys_max_heap_table_size(
"max_heap_table_size", &drizzle_system_variables::max_heap_table_size);
146static sys_var_session_uint64_t sys_pseudo_thread_id(
"pseudo_thread_id", &drizzle_system_variables::pseudo_thread_id, 0, check_pseudo_thread_id);
148static sys_var_session_uint64_t sys_max_seeks_for_key(
"max_seeks_for_key", &drizzle_system_variables::max_seeks_for_key);
149static sys_var_session_uint64_t sys_max_length_for_sort_data(
"max_length_for_sort_data", &drizzle_system_variables::max_length_for_sort_data);
150static sys_var_session_size_t sys_max_sort_length(
"max_sort_length", &drizzle_system_variables::max_sort_length);
151static sys_var_uint64_t_ptr sys_max_write_lock_count(
"max_write_lock_count", &max_write_lock_count);
152static sys_var_session_uint64_t sys_min_examined_row_limit(
"min_examined_row_limit", &drizzle_system_variables::min_examined_row_limit);
154static sys_var_session_bool sys_optimizer_prune_level(
"optimizer_prune_level", &drizzle_system_variables::optimizer_prune_level);
155static sys_var_session_uint32_t sys_optimizer_search_depth(
"optimizer_search_depth", &drizzle_system_variables::optimizer_search_depth);
157static sys_var_session_uint64_t sys_preload_buff_size(
"preload_buffer_size", &drizzle_system_variables::preload_buff_size);
159static sys_var_session_uint32_t sys_read_rnd_buff_size(
"read_rnd_buffer_size", &drizzle_system_variables::read_rnd_buff_size);
160static sys_var_session_uint32_t sys_div_precincrement(
"div_precision_increment", &drizzle_system_variables::div_precincrement);
162static sys_var_session_size_t sys_range_alloc_block_size(
"range_alloc_block_size", &drizzle_system_variables::range_alloc_block_size);
164static sys_var_session_bool sys_replicate_query(
"replicate_query", &drizzle_system_variables::replicate_query);
166static sys_var_session_uint32_t sys_query_alloc_block_size(
"query_alloc_block_size", &drizzle_system_variables::query_alloc_block_size, NULL, fix_session_mem_root);
167static sys_var_session_uint32_t sys_query_prealloc_size(
"query_prealloc_size", &drizzle_system_variables::query_prealloc_size, NULL, fix_session_mem_root);
170static sys_var_fs_path sys_secure_file_priv(
"secure_file_priv", secure_file_priv);
177static sys_var_session_size_t sys_sort_buffer(
"sort_buffer_size", &drizzle_system_variables::sortbuff_size);
179static sys_var_size_t_ptr_readonly sys_transaction_message_threshold(
"transaction_message_threshold", &transaction_message_threshold);
182static sys_var_size_t_ptr sys_table_def_size(
"table_definition_cache", &table_def_size);
184static sys_var_uint64_t_ptr sys_table_lock_wait_timeout(
"table_lock_wait_timeout", &table_lock_wait_timeout);
186 &drizzle_system_variables::tx_isolation,
187 &tx_isolation_typelib,
191 &drizzle_system_variables::tmp_table_size);
194static sys_var_const_str sys_version_comment(
"version_comment", COMPILATION_COMMENT);
195static sys_var_const_str sys_version_compile_machine(
"version_compile_machine", HOST_CPU);
197static sys_var_const_str sys_version_compile_vendor(
"version_compile_vendor", HOST_VENDOR);
201sys_var_session_bit sys_autocommit(
"autocommit", 0, set_option_autocommit, OPTION_NOT_AUTOCOMMIT, 1);
202static sys_var_session_bit sys_big_selects(
"sql_big_selects", 0, set_option_bit, OPTION_BIG_SELECTS);
203static sys_var_session_bit sys_sql_warnings(
"sql_warnings", 0, set_option_bit, OPTION_WARNINGS);
205static sys_var_session_bit sys_buffer_results(
"sql_buffer_result", 0, set_option_bit, OPTION_BUFFER_RESULT);
206static sys_var_session_bit sys_foreign_key_checks(
"foreign_key_checks", 0, set_option_bit, OPTION_NO_FOREIGN_KEY_CHECKS, 1);
207static sys_var_session_bit sys_unique_checks(
"unique_checks", 0, set_option_bit, OPTION_RELAXED_UNIQUE_CHECKS, 1);
213sys_last_insert_id(
"last_insert_id");
234static sys_var_readonly sys_error_count(
"error_count", OPT_SESSION, SHOW_INT, get_error_count);
235static sys_var_readonly sys_warning_count(
"warning_count", OPT_SESSION, SHOW_INT, get_warning_count);
237sys_var_session_uint64_t sys_group_concat_max_len(
"group_concat_max_len", &drizzle_system_variables::group_concat_max_len);
251 int res= (*check_func)(session, var);
253 my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0),
getName().c_str(), var->value->str_value.ptr());
265 int res= (*check_func)(session, var);
267 my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0),
getName().c_str(), var->value->str_value.ptr());
276 if ((*check_func)(session, var))
278 my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0),
getName().c_str(), var->value->str_value.ptr());
295 if (
type != OPT_GLOBAL)
297 if (session->variables.max_join_size == HA_POS_ERROR)
298 session->options|= OPTION_BIG_SELECTS;
300 session->options&= ~OPTION_BIG_SELECTS;
311 if (
var->type == OPT_DEFAULT && (session->server_status & SERVER_STATUS_IN_TRANS))
313 my_error(ER_CANT_CHANGE_TX_ISOLATION, MYF(0));
323static void fix_tx_isolation(Session *session, sql_var_t type)
325 if (type == OPT_SESSION)
326 session->session_tx_isolation= (enum_tx_isolation) session->variables.tx_isolation;
331 int64_t val=
var->value->val_int();
332 if (val < 0 || val > 2)
335 my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0),
var->var->getName().c_str(), internal::llstr(val, buf));
342static void fix_session_mem_root(
Session *session, sql_var_t
type)
344 if (
type != OPT_GLOBAL)
345 session->mem.reset_defaults(session->variables.query_alloc_block_size, session->variables.query_prealloc_size);
349void throw_bounds_warning(
Session *session,
bool fixed,
bool unsignd,
const std::string &name, int64_t val)
353 char buf[DECIMAL_LONGLONG_DIGITS];
356 internal::ullstr((uint64_t) val, buf);
358 internal::llstr(val, buf);
360 push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
361 ER_TRUNCATED_WRONG_VALUE, ER(ER_TRUNCATED_WRONG_VALUE), name.c_str(), buf);
364uint64_t fix_unsigned(
Session *session, uint64_t num,
const option& option_limits)
367 uint64_t out= getopt_ull_limit_value(num, option_limits, &fixed);
369 throw_bounds_warning(session, fixed,
true, option_limits.name, (int64_t) num);
374static size_t fix_size_t(
Session *session,
size_t num,
const option& option_limits)
377 size_t out= (size_t)getopt_ull_limit_value(num, option_limits, &fixed);
379 throw_bounds_warning(session, fixed,
true, option_limits.name, (int64_t) num);
391 uint64_t tmp= var->getInteger();
392 boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
396 uint32_t newvalue= (uint32_t) fix_unsigned(session, tmp, *
option_limits);
397 if (
static_cast<uint64_t
>(newvalue) == tmp)
402 *value=
static_cast<uint32_t
>(tmp);
409void sys_var_uint32_t_ptr::set_default(
Session *session, sql_var_t)
412 boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
419 uint64_t tmp= var->getInteger();
420 boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
424 uint64_t newvalue= fix_unsigned(session, tmp, *
option_limits);
437void sys_var_uint64_t_ptr::set_default(
Session *session, sql_var_t)
439 if (have_default_value)
441 *value= default_value;
446 boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
454 size_t tmp= size_t(var->getInteger());
456 boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
467void sys_var_size_t_ptr::set_default(
Session *session, sql_var_t)
470 boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
476 return check_enum(session, var, &bool_typelib);
481 *value= bool(var->getInteger());
486void sys_var_bool_ptr::set_default(
Session *, sql_var_t)
488 *value= default_value;
498 return (check_func && (*check_func)(session, var));
503 uint64_t tmp= var->getInteger();
506 if ((uint32_t) tmp > max_system_variables.*offset)
508 throw_bounds_warning(session,
true,
true,
getName(), (int64_t) tmp);
509 tmp= max_system_variables.*offset;
514 else if (tmp > UINT32_MAX)
517 throw_bounds_warning(session,
true,
true,
getName(), int64_t(var->getInteger()));
520 if (var->type == OPT_GLOBAL)
521 global_system_variables.*offset= (uint32_t) tmp;
523 session->variables.*offset= (uint32_t) tmp;
529 void sys_var_session_uint32_t::set_default(
Session *session, sql_var_t
type)
531 if (type == OPT_GLOBAL)
535 global_system_variables.*offset=
539 session->variables.*offset= global_system_variables.*offset;
543unsigned char *sys_var_session_uint32_t::value_ptr(
Session *session, sql_var_t
type)
545 return type == OPT_GLOBAL
546 ? (
unsigned char*) &(global_system_variables.*offset)
547 : (unsigned char*) &(session->variables.*offset);
553 uint64_t tmp= var->getInteger();
556 if ((ha_rows) tmp > max_system_variables.*offset)
557 tmp= max_system_variables.*offset;
561 if (var->type == OPT_GLOBAL)
564 boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
565 global_system_variables.*offset= (ha_rows) tmp;
569 session->variables.*offset= (ha_rows) tmp;
576void sys_var_session_ha_rows::set_default(
Session *session, sql_var_t
type)
578 if (type == OPT_GLOBAL)
582 boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
583 global_system_variables.*offset=
588 session->variables.*offset= global_system_variables.*offset;
593unsigned char *sys_var_session_ha_rows::value_ptr(
Session *session, sql_var_t
type)
595 return type == OPT_GLOBAL
596 ? (
unsigned char*) &(global_system_variables.*offset)
597 : (unsigned char*) &(session->variables.*offset);
603 return (check_func && (*check_func)(session, var));
608 uint64_t tmp= var->getInteger();
610 if (tmp > max_system_variables.*offset)
612 throw_bounds_warning(session,
true,
true,
getName(), (int64_t) tmp);
613 tmp= max_system_variables.*offset;
618 if (var->type == OPT_GLOBAL)
621 boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
622 global_system_variables.*offset= (uint64_t) tmp;
626 session->variables.*offset= (uint64_t) tmp;
633void sys_var_session_uint64_t::set_default(
Session *session, sql_var_t
type)
635 if (type == OPT_GLOBAL)
638 boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
639 global_system_variables.*offset=
644 session->variables.*offset= global_system_variables.*offset;
649unsigned char *sys_var_session_uint64_t::value_ptr(
Session *session, sql_var_t
type)
651 return type == OPT_GLOBAL
652 ? (
unsigned char*) &(global_system_variables.*offset)
653 : (unsigned char*) &(session->variables.*offset);
659 return (check_func && (*check_func)(session, var));
664 size_t tmp= size_t(var->getInteger());
666 if (tmp > max_system_variables.*offset)
667 tmp= max_system_variables.*offset;
671 if (var->type == OPT_GLOBAL)
674 boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
675 global_system_variables.*offset= tmp;
679 session->variables.*offset= tmp;
686void sys_var_session_size_t::set_default(
Session *session, sql_var_t
type)
688 if (type == OPT_GLOBAL)
691 boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
692 global_system_variables.*offset=
697 session->variables.*offset= global_system_variables.*offset;
702unsigned char *sys_var_session_size_t::value_ptr(
Session *session, sql_var_t
type)
704 return type == OPT_GLOBAL
705 ? (
unsigned char*) &(global_system_variables.*offset)
706 : (unsigned char*) &(session->variables.*offset);
711 return check_enum(session, var, &bool_typelib);
716 if (var->type == OPT_GLOBAL)
717 global_system_variables.*offset= bool(var->getInteger());
719 session->variables.*offset= bool(var->getInteger());
725void sys_var_session_bool::set_default(
Session *session, sql_var_t
type)
727 if (type == OPT_GLOBAL)
728 global_system_variables.*offset= (bool)
option_limits->def_value;
730 session->variables.*offset= global_system_variables.*offset;
734unsigned char *sys_var_session_bool::value_ptr(
Session *session, sql_var_t
type)
736 return type == OPT_GLOBAL
737 ? (
unsigned char*) &(global_system_variables.*offset)
738 : (unsigned char*) &(session->variables.*offset);
744 char buff[STRING_BUFFER_USUAL_SIZE];
746 String str(buff,
sizeof(buff), system_charset_info), *res;
748 if (var->value->result_type() == STRING_RESULT)
750 res= var->value->val_str(&str);
757 uint64_t tmp_val= enum_names->find_type(res->ptr(), res->length(),
true);
763 var->setValue(tmp_val-1);
767 uint64_t tmp= var->value->val_int();
768 if (tmp >= enum_names->count)
770 internal::llstr(tmp,buff);
779 my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0),
name.c_str(), value);
794 if (check_type(var_type))
796 if (var_type != OPT_DEFAULT)
798 my_error(ER_INCORRECT_GLOBAL_LOCAL_VAR, MYF(0),
name.c_str(), var_type == OPT_GLOBAL ?
"SESSION" :
"GLOBAL");
802 var_type= OPT_GLOBAL;
804 boost::mutex::scoped_lock lock(session->catalog().systemVariableLock());
810 uint32_t value= *(uint*) value_ptr(session, var_type);
815 int64_t value= *(int64_t*) value_ptr(session, var_type);
820 double value= *(
double*) value_ptr(session, var_type);
826 ha_rows value= *(ha_rows*) value_ptr(session, var_type);
827 return new Item_int((uint64_t) value);
831 size_t value= *(
size_t*) value_ptr(session, var_type);
832 return new Item_int((uint64_t) value);
836 int32_t value= *(
bool*) value_ptr(session, var_type);
841 if (
const char *str= *(
char**) value_ptr(session, var_type))
843 uint32_t length= strlen(str);
844 return new Item_string(session->mem.strdup(str, length), length, system_charset_info, DERIVATION_SYSCONST);
847 tmp->collation.set(system_charset_info, DERIVATION_SYSCONST);
852 if (
const char* str= (
char*) value_ptr(session, var_type))
853 return new Item_string(str_ref(str), system_charset_info, DERIVATION_SYSCONST);
855 tmp->collation.set(system_charset_info, DERIVATION_SYSCONST);
859 my_error(ER_VAR_CANT_BE_READ, MYF(0),
name.c_str());
867 if (
var->type == OPT_GLOBAL)
868 global_system_variables.*offset=
var->getInteger();
870 session->variables.*offset=
var->getInteger();
875void sys_var_session_enum::set_default(Session *session, sql_var_t type)
877 if (type == OPT_GLOBAL)
878 global_system_variables.*offset= (uint32_t)
option_limits->def_value;
880 session->variables.*offset= global_system_variables.*offset;
884unsigned char *sys_var_session_enum::value_ptr(
Session *session, sql_var_t
type)
886 uint32_t tmp= type == OPT_GLOBAL ? global_system_variables.*offset : session->variables.*offset;
887 return (
unsigned char*) enum_names->type_names[tmp];
892 return check_enum(session, var, &bool_typelib) || (check_func && (*check_func)(session, var));
897 return (*update_func)(session, var);
901unsigned char *sys_var_session_bit::value_ptr(
Session *session, sql_var_t)
907 session->sys_var_tmp.bool_value= (session->options & bit_flag) ? !reverse : reverse;
908 return (
unsigned char*) &session->sys_var_tmp.bool_value;
914 const charset_info_st *tmp;
916 if (var->value->result_type() == STRING_RESULT)
918 char buff[STRING_BUFFER_USUAL_SIZE];
919 String str(buff,
sizeof(buff), system_charset_info), *res;
920 if (!(res=var->value->val_str(&str)))
922 boost::throw_exception(invalid_option_value(var->var->getName()) << invalid_value(std::string(
"NULL")));
925 if (!(tmp=get_charset_by_name(res->c_ptr())))
927 my_error(ER_UNKNOWN_COLLATION, MYF(0), res->c_ptr());
928 boost::throw_exception(invalid_option_value(var->var->getName()) << invalid_value(std::string(res->c_ptr())));
934 if (!(tmp=get_charset((
int) var->value->val_int())))
937 internal::int10_to_str((
int) var->value->val_int(), buf, -10);
938 my_error(ER_UNKNOWN_COLLATION, MYF(0), buf);
939 boost::throw_exception(invalid_option_value(var->var->getName()) << invalid_value(boost::lexical_cast<std::string>(var->value->val_int())));
943 if (var->type == OPT_GLOBAL)
944 global_system_variables.*offset= tmp;
947 session->variables.*offset= tmp;
953void sys_var_collation_sv::set_default(
Session *session, sql_var_t
type)
955 if (type == OPT_GLOBAL)
956 global_system_variables.*offset= *global_default;
959 session->variables.*offset= global_system_variables.*offset;
964unsigned char *sys_var_collation_sv::value_ptr(
Session *session, sql_var_t
type)
966 const charset_info_st *cs= type == OPT_GLOBAL ? global_system_variables.*offset : session->variables.*offset;
967 return cs ? (
unsigned char*) cs->name : (unsigned char*)
"NULL";
974 session->times.set_time(time_t(var->getInteger()));
979void sys_var_timestamp::set_default(
Session *session, sql_var_t)
981 session->times.resetUserTime();
985unsigned char *sys_var_timestamp::value_ptr(
Session *session, sql_var_t)
987 session->sys_var_tmp.int32_t_value= (int32_t) session->times.getCurrentTimestampEpoch();
988 return (
unsigned char*) &session->sys_var_tmp.int32_t_value;
994 session->first_successful_insert_id_in_prev_stmt= var->getInteger();
999unsigned char *sys_var_last_insert_id::value_ptr(
Session *session, sql_var_t)
1005 session->sys_var_tmp.uint64_t_value=
1006 session->read_first_successful_insert_id_in_prev_stmt();
1007 return (
unsigned char*) &session->sys_var_tmp.uint64_t_value;
1012 MY_LOCALE *locale_match;
1014 if (var->value->result_type() == INT_RESULT)
1016 if (!(locale_match= my_locale_by_number((uint32_t) var->value->val_int())))
1018 char buf[DECIMAL_LONGLONG_DIGITS];
1019 internal::int10_to_str((
int) var->value->val_int(), buf, -10);
1020 my_printf_error(ER_UNKNOWN_ERROR,
"Unknown locale: '%s'", MYF(0), buf);
1027 String str(buff,
sizeof(buff), &my_charset_utf8_general_ci), *res;
1028 if (!(res=var->value->val_str(&str)))
1030 my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0),
name.c_str(),
"NULL");
1033 const char *locale_str= res->c_ptr();
1034 if (!(locale_match= my_locale_by_name(locale_str)))
1036 my_printf_error(ER_UNKNOWN_ERROR,
1037 "Unknown locale: '%s'", MYF(0), locale_str);
1042 if (var->type == OPT_GLOBAL)
1043 global_system_variables.lc_time_names= locale_match;
1045 session->variables.lc_time_names= locale_match;
1050unsigned char *sys_var_session_lc_time_names::value_ptr(
Session *session, sql_var_t
type)
1052 return type == OPT_GLOBAL
1053 ? (
unsigned char *) global_system_variables.lc_time_names->name
1054 : (unsigned char *) session->variables.lc_time_names->
name;
1058void sys_var_session_lc_time_names::set_default(
Session *session, sql_var_t
type)
1060 if (type == OPT_GLOBAL)
1061 global_system_variables.lc_time_names= my_default_lc_time_names;
1063 session->variables.lc_time_names= global_system_variables.lc_time_names;
1077 double num= var->value->val_real();
1078 int64_t microseconds;
1083 microseconds= (int64_t) (num * 1000000.0 + 0.5);
1084 if (var->type == OPT_GLOBAL)
1086 boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
1087 (global_system_variables.*offset)= microseconds;
1090 session->variables.*offset= microseconds;
1095void sys_var_microseconds::set_default(
Session *session, sql_var_t
type)
1097 int64_t microseconds= (int64_t) (
option_limits->def_value * 1000000.0);
1098 if (type == OPT_GLOBAL)
1100 boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
1101 global_system_variables.*offset= microseconds;
1104 session->variables.*offset= microseconds;
1114 if ((
var->getInteger() != 0) ==
sys_var->reverse)
1115 session->options&=
~sys_var->bit_flag;
1117 session->options|=
sys_var->bit_flag;
1127 uint64_t org_options= session->options;
1128 uint64_t new_options= session->options;
1130 if (
var->getInteger() != 0)
1135 if ((org_options ^ new_options) & OPTION_NOT_AUTOCOMMIT)
1137 if ((org_options & OPTION_NOT_AUTOCOMMIT))
1139 success= session->endActiveTransaction();
1141 session->options&= ~(uint64_t) (OPTION_BEGIN);
1142 session->server_status|= SERVER_STATUS_AUTOCOMMIT;
1146 session->server_status&= ~SERVER_STATUS_AUTOCOMMIT;
1150 if (
var->getInteger() != 0)
1164static unsigned char *get_warning_count(
Session *session)
1166 session->sys_var_tmp.uint32_t_value=
1167 (session->warn_count[(uint32_t) DRIZZLE_ERROR::WARN_LEVEL_NOTE] +
1168 session->warn_count[(uint32_t) DRIZZLE_ERROR::WARN_LEVEL_ERROR] +
1169 session->warn_count[(uint32_t) DRIZZLE_ERROR::WARN_LEVEL_WARN]);
1170 return (
unsigned char*) &session->sys_var_tmp.uint32_t_value;
1173static unsigned char *get_error_count(
Session *session)
1175 session->sys_var_tmp.uint32_t_value=
1176 session->warn_count[(uint32_t) DRIZZLE_ERROR::WARN_LEVEL_ERROR];
1177 return (
unsigned char*) &session->sys_var_tmp.uint32_t_value;
1197 assert(drizzle_tmpdir.size());
1198 return (
unsigned char*)drizzle_tmpdir.c_str();
1223 uint32_t length= strlen(name);
1224 for (; opt->name; opt++)
1226 if (not getopt_compare_strings(opt->name, name, length) and not opt->name[length])
1232 return opt->value ? opt : NULL;
1254drizzle_show_var* enumerate_sys_vars(Session *session)
1256 drizzle_show_var *result=
new (session->mem) drizzle_show_var[system_variable_map.size() + 1];
1257 drizzle_show_var *show= result;
1258 for (SystemVariableMap::const_reference iter : system_variable_map)
1260 sys_var *var= iter.second;
1261 show->name= var->getName().c_str();
1262 show->value= (
char*) var;
1263 show->type= SHOW_SYS;
1274 string lower_name(
var->getName());
1275 boost::to_lower(lower_name);
1278 if (system_variable_map.count(lower_name))
1280 errmsg_printf(error::ERROR, _(
"Variable named %s already exists!\n"),
var->getName().c_str());
1284 pair<SystemVariableMap::iterator, bool> ret= system_variable_map.insert(make_pair(lower_name,
var));
1285 if (ret.second ==
false)
1287 errmsg_printf(error::ERROR, _(
"Could not add Variable: %s\n"),
var->getName().c_str());
1294 add_sys_var_to_list(
var);
1313 add_sys_var_to_list(&sys_auto_increment_increment, my_long_options);
1314 add_sys_var_to_list(&sys_auto_increment_offset, my_long_options);
1315 add_sys_var_to_list(&sys_autocommit, my_long_options);
1316 add_sys_var_to_list(&sys_back_log, my_long_options);
1317 add_sys_var_to_list(&sys_basedir, my_long_options);
1318 add_sys_var_to_list(&sys_big_selects, my_long_options);
1319 add_sys_var_to_list(&sys_branch, my_long_options);
1320 add_sys_var_to_list(&sys_buffer_results, my_long_options);
1321 add_sys_var_to_list(&sys_bulk_insert_buff_size, my_long_options);
1322 add_sys_var_to_list(&sys_collation_server, my_long_options);
1323 add_sys_var_to_list(&sys_completion_type, my_long_options);
1324 add_sys_var_to_list(&sys_datadir, my_long_options);
1325 add_sys_var_to_list(&sys_div_precincrement, my_long_options);
1326 add_sys_var_to_list(&sys_error_count, my_long_options);
1327 add_sys_var_to_list(&sys_foreign_key_checks, my_long_options);
1328 add_sys_var_to_list(&sys_group_concat_max_len, my_long_options);
1329 add_sys_var_to_list(&sys_hostname, my_long_options);
1330 add_sys_var_to_list(&sys_identity, my_long_options);
1331 add_sys_var_to_list(&sys_join_buffer_size, my_long_options);
1332 add_sys_var_to_list(&sys_last_insert_id, my_long_options);
1333 add_sys_var_to_list(&sys_lc_time_names, my_long_options);
1334 add_sys_var_to_list(&sys_max_allowed_packet, my_long_options);
1335 add_sys_var_to_list(&sys_max_error_count, my_long_options);
1336 add_sys_var_to_list(&sys_max_heap_table_size, my_long_options);
1337 add_sys_var_to_list(&sys_max_join_size, my_long_options);
1338 add_sys_var_to_list(&sys_max_length_for_sort_data, my_long_options);
1339 add_sys_var_to_list(&sys_max_seeks_for_key, my_long_options);
1340 add_sys_var_to_list(&sys_max_sort_length, my_long_options);
1341 add_sys_var_to_list(&sys_max_write_lock_count, my_long_options);
1342 add_sys_var_to_list(&sys_min_examined_row_limit, my_long_options);
1343 add_sys_var_to_list(&sys_optimizer_prune_level, my_long_options);
1344 add_sys_var_to_list(&sys_optimizer_search_depth, my_long_options);
1345 add_sys_var_to_list(&sys_pid_file, my_long_options);
1346 add_sys_var_to_list(&sys_plugin_dir, my_long_options);
1347 add_sys_var_to_list(&sys_preload_buff_size, my_long_options);
1348 add_sys_var_to_list(&sys_pseudo_thread_id, my_long_options);
1349 add_sys_var_to_list(&sys_query_alloc_block_size, my_long_options);
1350 add_sys_var_to_list(&sys_query_prealloc_size, my_long_options);
1351 add_sys_var_to_list(&sys_range_alloc_block_size, my_long_options);
1352 add_sys_var_to_list(&sys_read_buff_size, my_long_options);
1353 add_sys_var_to_list(&sys_read_rnd_buff_size, my_long_options);
1354 add_sys_var_to_list(&sys_release_id, my_long_options);
1355 add_sys_var_to_list(&sys_replicate_query, my_long_options);
1356 add_sys_var_to_list(&sys_revid, my_long_options);
1357 add_sys_var_to_list(&sys_revno, my_long_options);
1358 add_sys_var_to_list(&sys_scheduler, my_long_options);
1359 add_sys_var_to_list(&sys_secure_file_priv, my_long_options);
1360 add_sys_var_to_list(&sys_select_limit, my_long_options);
1361 add_sys_var_to_list(&sys_server_id, my_long_options);
1362 add_sys_var_to_list(&sys_server_uuid, my_long_options);
1363 add_sys_var_to_list(&sys_sort_buffer, my_long_options);
1364 add_sys_var_to_list(&sys_sql_notes, my_long_options);
1365 add_sys_var_to_list(&sys_sql_warnings, my_long_options);
1366 add_sys_var_to_list(&sys_storage_engine, my_long_options);
1367 add_sys_var_to_list(&sys_table_cache_size, my_long_options);
1368 add_sys_var_to_list(&sys_table_def_size, my_long_options);
1369 add_sys_var_to_list(&sys_table_lock_wait_timeout, my_long_options);
1370 add_sys_var_to_list(&sys_thread_stack_size, my_long_options);
1371 add_sys_var_to_list(&sys_timestamp, my_long_options);
1372 add_sys_var_to_list(&sys_tmp_table_size, my_long_options);
1373 add_sys_var_to_list(&sys_tmpdir, my_long_options);
1374 add_sys_var_to_list(&sys_transaction_message_threshold, my_long_options);
1375 add_sys_var_to_list(&sys_tx_isolation, my_long_options);
1376 add_sys_var_to_list(&sys_unique_checks, my_long_options);
1377 add_sys_var_to_list(&sys_version, my_long_options);
1378 add_sys_var_to_list(&sys_version_comment, my_long_options);
1379 add_sys_var_to_list(&sys_version_compile_machine, my_long_options);
1380 add_sys_var_to_list(&sys_version_compile_os, my_long_options);
1381 add_sys_var_to_list(&sys_version_compile_vendor, my_long_options);
1382 add_sys_var_to_list(&sys_warning_count, my_long_options);
1384 catch (std::exception&)
1386 errmsg_printf(error::ERROR, _(
"Failed to initialize system variables"));
1406 if (
sys_var* ptr= find_ptr2(system_variable_map, boost::to_lower_copy(name)))
1408 my_error(ER_UNKNOWN_SYSTEM_VARIABLE, MYF(0), name.c_str());
1417unsigned char *sys_var_session_storage_engine::value_ptr(Session *session, sql_var_t type)
1419 plugin::StorageEngine *engine= type == OPT_GLOBAL
1420 ? global_system_variables.*offset
1421 : session->variables.*offset;
1422 return (
unsigned char *) session->mem.strdup(engine->getName());
1426void sys_var_session_storage_engine::set_default(
Session *session, sql_var_t
type)
1428 plugin::StorageEngine *new_value, **value;
1429 if (type == OPT_GLOBAL)
1431 value= &(global_system_variables.*offset);
1432 new_value= myisam_engine;
1436 value= &(session->variables.*offset);
1437 new_value= global_system_variables.*offset;
1446 char buff[STRING_BUFFER_USUAL_SIZE];
1447 const char *name_value;
1448 String str(buff,
sizeof(buff), &my_charset_utf8_general_ci), *res;
1450 plugin::StorageEngine *tmp= NULL;
1451 plugin::StorageEngine **value= NULL;
1453 if (var->value->result_type() == STRING_RESULT)
1455 res= var->value->val_str(&str);
1456 if (res == NULL || res->ptr() == NULL)
1463 const std::string engine_name(res->ptr());
1464 tmp= plugin::StorageEngine::findByName(*session, engine_name);
1467 name_value= res->c_ptr();
1474 name_value=
"unknown";
1477 value= &(global_system_variables.*offset);
1478 if (var->type != OPT_GLOBAL)
1479 value= &(session->variables.*offset);
1486 my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), name_value);
struct option * option_limits
const std::string & getName() const
Item * item(Session *, sql_var_t)
Convert from decimal to binary representation.
TODO: Rename this file - func.h is stupid.
static int check_tx_isolation(Session *, set_var *)
static option * find_option(struct option *opt, const char *name)
static unsigned char * get_tmpdir(Session *)
static void fix_max_join_size(Session *, sql_var_t)
sys_var * find_sys_var(const std::string &name)
Visibility Control Macros.