Commit a7b2c95a authored by Sergei Golubchik's avatar Sergei Golubchik

bugs in sys_var::val_* code

1. @@boolean_var differs from SHOW VARIABLES
2. @@str_var ignored variable charset (which is wrong
   for path variables that use filesystem charset)
3. @@signed_int_var in the string context was printed
   as unsigned
parent b969a690
......@@ -351,7 +351,7 @@ a
DROP TABLE t1;
set global LC_MESSAGES=convert((@@global.log_bin_trust_function_creators)
using cp1250);
ERROR HY000: Unknown locale: '1'
ERROR HY000: Unknown locale: 'ON'
#
# Start of 5.6 tests
#
......
......@@ -274,9 +274,7 @@ do { \
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)
case SHOW_HA_ROWS: do_num_val (ha_rows,CMD);
#define case_for_double(CMD) \
case SHOW_DOUBLE: do_num_val (double,CMD)
......@@ -307,6 +305,7 @@ longlong sys_var::val_int(bool *is_null,
case_get_string_as_lex_string;
case_for_integers(return val);
case_for_double(return (longlong) val);
case SHOW_MY_BOOL: return *(my_bool*)value;
default:
my_error(ER_VAR_CANT_BE_READ, MYF(0), name.str);
return 0;
......@@ -314,7 +313,7 @@ longlong sys_var::val_int(bool *is_null,
longlong ret= 0;
if (!(*is_null= !sval.str))
ret= longlong_from_string_with_check(system_charset_info,
ret= longlong_from_string_with_check(charset(thd),
sval.str, sval.str + sval.length);
return ret;
}
......@@ -322,18 +321,27 @@ longlong sys_var::val_int(bool *is_null,
String *sys_var::val_str_nolock(String *str, THD *thd, const uchar *value)
{
static LEX_STRING bools[]=
{
{ C_STRING_WITH_LEN("OFF") },
{ C_STRING_WITH_LEN("ON") }
};
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_integers(return str->set(val, system_charset_info) ? 0 : str);
case_for_double(return str->set_real(val, 6, system_charset_info) ? 0 : str);
case SHOW_MY_BOOL:
sval= bools[(int)*(my_bool*)value];
break;
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))
if (!sval.str || str->copy(sval.str, sval.length, charset(thd)))
str= NULL;
return str;
}
......@@ -361,6 +369,7 @@ double sys_var::val_real(bool *is_null,
case_get_string_as_lex_string;
case_for_integers(return val);
case_for_double(return val);
case SHOW_MY_BOOL: return *(my_bool*)value;
default:
my_error(ER_VAR_CANT_BE_READ, MYF(0), name.str);
return 0;
......@@ -368,9 +377,8 @@ double sys_var::val_real(bool *is_null,
double ret= 0;
if (!(*is_null= !sval.str))
ret= double_from_string_with_check(system_charset_info,
ret= double_from_string_with_check(charset(thd),
sval.str, sval.str + sval.length);
mysql_mutex_unlock(&LOCK_global_system_variables);
return ret;
}
......
......@@ -206,8 +206,8 @@ private:
protected:
/**
A pointer to a value of the variable for SHOW.
It must be of show_val_type type (bool for SHOW_BOOL, int for SHOW_INT,
longlong for SHOW_LONGLONG, etc).
It must be of show_val_type type (my_bool for SHOW_MY_BOOL,
int for SHOW_INT, longlong for SHOW_LONGLONG, etc).
*/
virtual uchar *session_value_ptr(THD *thd, const LEX_STRING *base);
virtual uchar *global_value_ptr(THD *thd, const LEX_STRING *base);
......
......@@ -211,10 +211,12 @@ public:
str_charset=cs;
}
bool set_int(longlong num, bool unsigned_flag, CHARSET_INFO *cs);
bool set(longlong num, CHARSET_INFO *cs)
{ return set_int(num, false, cs); }
bool set(ulonglong num, CHARSET_INFO *cs)
{ return set_int((longlong)num, true, cs); }
bool set(int num, CHARSET_INFO *cs) { return set_int(num, false, cs); }
bool set(uint num, CHARSET_INFO *cs) { return set_int(num, true, cs); }
bool set(long num, CHARSET_INFO *cs) { return set_int(num, false, cs); }
bool set(ulong num, CHARSET_INFO *cs) { return set_int(num, true, cs); }
bool set(longlong num, CHARSET_INFO *cs) { return set_int(num, false, cs); }
bool set(ulonglong num, CHARSET_INFO *cs) { return set_int((longlong)num, true, cs); }
bool set_real(double num,uint decimals, CHARSET_INFO *cs);
/* Move handling of buffer from some other object to String */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment