summaryrefslogtreecommitdiff
path: root/sql/set_var.cc
diff options
context:
space:
mode:
authorSergei Golubchik <sergii@pisem.net>2013-04-09 23:27:19 +0200
committerSergei Golubchik <sergii@pisem.net>2013-04-09 23:27:19 +0200
commit7d3288129f6e5b52c7377ff68295f51606c7f002 (patch)
tree9f844bb427f6f945e97d54d3e4fb9f44bd181186 /sql/set_var.cc
parenteda4c51241b647094b727643e1aad4153c45d647 (diff)
downloadmariadb-git-7d3288129f6e5b52c7377ff68295f51606c7f002.tar.gz
create sys_var::val_str(), sys_var::val_int(), sys_var::val_real().
Change Item_func_get_system_var::val_xxx functions to use that. mysql-test/t/variables.test: @@GLOBAL.INIT_CONNECT is never NULL anymore. Nor it ever was. It was a bug that empty string system variables appeared as NULL in the *integer context* (but not in a string, real, or decimal context!)
Diffstat (limited to 'sql/set_var.cc')
-rw-r--r--sql/set_var.cc111
1 files changed, 109 insertions, 2 deletions
diff --git a/sql/set_var.cc b/sql/set_var.cc
index 2d3e0b7fec4..48f7cc7a054 100644
--- a/sql/set_var.cc
+++ b/sql/set_var.cc
@@ -257,8 +257,7 @@ uchar *sys_var::value_ptr(THD *thd, enum_var_type type, LEX_STRING *base)
bool sys_var::set_default(THD *thd, enum_var_type type)
{
- LEX_STRING empty={0,0};
- set_var var(type, this, &empty, 0);
+ set_var var(type, this, &null_lex_str, 0);
if (type == OPT_GLOBAL || scope() == GLOBAL)
global_save_default(thd, &var);
@@ -268,6 +267,114 @@ bool sys_var::set_default(THD *thd, enum_var_type type)
return check(thd, &var) || update(thd, &var);
}
+
+#define do_num_val(T,CMD) \
+do { \
+ mysql_mutex_lock(&LOCK_global_system_variables); \
+ T val= *(T*) value_ptr(thd, type, base); \
+ mysql_mutex_unlock(&LOCK_global_system_variables); \
+ CMD; \
+} while (0)
+
+#define case_for_integers(CMD) \
+ case SHOW_SINT: do_num_val (int,CMD); \
+ case SHOW_SLONG: do_num_val (long,CMD); \
+ case SHOW_SLONGLONG:do_num_val (longlong,CMD); \
+ case SHOW_UINT: do_num_val (uint,CMD); \
+ case SHOW_ULONG: do_num_val (ulong,CMD); \
+ case SHOW_ULONGLONG:do_num_val (ulonglong,CMD); \
+ case SHOW_HA_ROWS: do_num_val (ha_rows,CMD); \
+ case SHOW_BOOL: do_num_val (bool,CMD); \
+ case SHOW_MY_BOOL: do_num_val (my_bool,CMD)
+
+#define case_for_double(CMD) \
+ case SHOW_DOUBLE: do_num_val (double,CMD)
+
+#define case_get_string_as_lex_string \
+ case SHOW_CHAR: \
+ mysql_mutex_lock(&LOCK_global_system_variables); \
+ sval.str= (char*) value_ptr(thd, type, base); \
+ sval.length= sval.str ? strlen(sval.str) : 0; \
+ break; \
+ case SHOW_CHAR_PTR: \
+ mysql_mutex_lock(&LOCK_global_system_variables); \
+ sval.str= *(char**) value_ptr(thd, type, base); \
+ sval.length= sval.str ? strlen(sval.str) : 0; \
+ break; \
+ case SHOW_LEX_STRING: \
+ mysql_mutex_lock(&LOCK_global_system_variables); \
+ sval= *(LEX_STRING *) value_ptr(thd, type, base); \
+ break
+
+longlong sys_var::val_int(bool *is_null,
+ THD *thd, enum_var_type type, LEX_STRING *base)
+{
+ LEX_STRING sval;
+ *is_null= false;
+ switch (show_type())
+ {
+ case_get_string_as_lex_string;
+ case_for_integers(return val);
+ case_for_double(return val);
+ default:
+ my_error(ER_VAR_CANT_BE_READ, MYF(0), name.str);
+ return 0;
+ }
+
+ longlong ret= 0;
+ if (!(*is_null= !sval.str))
+ ret= longlong_from_string_with_check(system_charset_info,
+ sval.str, sval.str + sval.length);
+ mysql_mutex_unlock(&LOCK_global_system_variables);
+ return ret;
+}
+
+
+String *sys_var::val_str(String *str,
+ THD *thd, enum_var_type type, LEX_STRING *base)
+{
+ LEX_STRING sval;
+ switch (show_type())
+ {
+ case_get_string_as_lex_string;
+ case_for_integers(return str->set((ulonglong)val, system_charset_info) ? 0 : str);
+ case_for_double(return str->set_real(val, 6, system_charset_info) ? 0 : str);
+ default:
+ my_error(ER_VAR_CANT_BE_READ, MYF(0), name.str);
+ return 0;
+ }
+
+ if (!sval.str || str->copy(sval.str, sval.length, system_charset_info))
+ str= NULL;
+ mysql_mutex_unlock(&LOCK_global_system_variables);
+ return str;
+}
+
+
+double sys_var::val_real(bool *is_null,
+ THD *thd, enum_var_type type, LEX_STRING *base)
+{
+ LEX_STRING sval;
+ *is_null= false;
+ switch (show_type())
+ {
+ case_get_string_as_lex_string;
+ case_for_integers(return val);
+ case_for_double(return val);
+ default:
+ my_error(ER_VAR_CANT_BE_READ, MYF(0), name.str);
+ return 0;
+ }
+
+ double ret= 0;
+ if (!(*is_null= !sval.str))
+ ret= double_from_string_with_check(system_charset_info,
+ sval.str, sval.str + sval.length);
+ mysql_mutex_unlock(&LOCK_global_system_variables);
+ return ret;
+}
+
+
void sys_var::do_deprecated_warning(THD *thd)
{
if (deprecation_substitute != NULL)