Skip to content

Commit a7b2c95

Browse files
committed
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
1 parent b969a69 commit a7b2c95

File tree

4 files changed

+25
-15
lines changed

4 files changed

+25
-15
lines changed

mysql-test/r/ctype_cp1250_ch.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ a
351351
DROP TABLE t1;
352352
set global LC_MESSAGES=convert((@@global.log_bin_trust_function_creators)
353353
using cp1250);
354-
ERROR HY000: Unknown locale: '1'
354+
ERROR HY000: Unknown locale: 'ON'
355355
#
356356
# Start of 5.6 tests
357357
#

sql/set_var.cc

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,7 @@ do { \
274274
case SHOW_UINT: do_num_val (uint,CMD); \
275275
case SHOW_ULONG: do_num_val (ulong,CMD); \
276276
case SHOW_ULONGLONG:do_num_val (ulonglong,CMD); \
277-
case SHOW_HA_ROWS: do_num_val (ha_rows,CMD); \
278-
case SHOW_BOOL: do_num_val (bool,CMD); \
279-
case SHOW_MY_BOOL: do_num_val (my_bool,CMD)
277+
case SHOW_HA_ROWS: do_num_val (ha_rows,CMD);
280278

281279
#define case_for_double(CMD) \
282280
case SHOW_DOUBLE: do_num_val (double,CMD)
@@ -307,33 +305,43 @@ longlong sys_var::val_int(bool *is_null,
307305
case_get_string_as_lex_string;
308306
case_for_integers(return val);
309307
case_for_double(return (longlong) val);
308+
case SHOW_MY_BOOL: return *(my_bool*)value;
310309
default:
311310
my_error(ER_VAR_CANT_BE_READ, MYF(0), name.str);
312311
return 0;
313312
}
314313

315314
longlong ret= 0;
316315
if (!(*is_null= !sval.str))
317-
ret= longlong_from_string_with_check(system_charset_info,
316+
ret= longlong_from_string_with_check(charset(thd),
318317
sval.str, sval.str + sval.length);
319318
return ret;
320319
}
321320

322321

323322
String *sys_var::val_str_nolock(String *str, THD *thd, const uchar *value)
324323
{
324+
static LEX_STRING bools[]=
325+
{
326+
{ C_STRING_WITH_LEN("OFF") },
327+
{ C_STRING_WITH_LEN("ON") }
328+
};
329+
325330
LEX_STRING sval;
326331
switch (show_type())
327332
{
328333
case_get_string_as_lex_string;
329-
case_for_integers(return str->set((ulonglong)val, system_charset_info) ? 0 : str);
334+
case_for_integers(return str->set(val, system_charset_info) ? 0 : str);
330335
case_for_double(return str->set_real(val, 6, system_charset_info) ? 0 : str);
336+
case SHOW_MY_BOOL:
337+
sval= bools[(int)*(my_bool*)value];
338+
break;
331339
default:
332340
my_error(ER_VAR_CANT_BE_READ, MYF(0), name.str);
333341
return 0;
334342
}
335343

336-
if (!sval.str || str->copy(sval.str, sval.length, system_charset_info))
344+
if (!sval.str || str->copy(sval.str, sval.length, charset(thd)))
337345
str= NULL;
338346
return str;
339347
}
@@ -361,16 +369,16 @@ double sys_var::val_real(bool *is_null,
361369
case_get_string_as_lex_string;
362370
case_for_integers(return val);
363371
case_for_double(return val);
372+
case SHOW_MY_BOOL: return *(my_bool*)value;
364373
default:
365374
my_error(ER_VAR_CANT_BE_READ, MYF(0), name.str);
366375
return 0;
367376
}
368377

369378
double ret= 0;
370379
if (!(*is_null= !sval.str))
371-
ret= double_from_string_with_check(system_charset_info,
380+
ret= double_from_string_with_check(charset(thd),
372381
sval.str, sval.str + sval.length);
373-
mysql_mutex_unlock(&LOCK_global_system_variables);
374382
return ret;
375383
}
376384

sql/set_var.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,8 @@ class sys_var
206206
protected:
207207
/**
208208
A pointer to a value of the variable for SHOW.
209-
It must be of show_val_type type (bool for SHOW_BOOL, int for SHOW_INT,
210-
longlong for SHOW_LONGLONG, etc).
209+
It must be of show_val_type type (my_bool for SHOW_MY_BOOL,
210+
int for SHOW_INT, longlong for SHOW_LONGLONG, etc).
211211
*/
212212
virtual uchar *session_value_ptr(THD *thd, const LEX_STRING *base);
213213
virtual uchar *global_value_ptr(THD *thd, const LEX_STRING *base);

sql/sql_string.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,12 @@ class String
211211
str_charset=cs;
212212
}
213213
bool set_int(longlong num, bool unsigned_flag, CHARSET_INFO *cs);
214-
bool set(longlong num, CHARSET_INFO *cs)
215-
{ return set_int(num, false, cs); }
216-
bool set(ulonglong num, CHARSET_INFO *cs)
217-
{ return set_int((longlong)num, true, cs); }
214+
bool set(int num, CHARSET_INFO *cs) { return set_int(num, false, cs); }
215+
bool set(uint num, CHARSET_INFO *cs) { return set_int(num, true, cs); }
216+
bool set(long num, CHARSET_INFO *cs) { return set_int(num, false, cs); }
217+
bool set(ulong num, CHARSET_INFO *cs) { return set_int(num, true, cs); }
218+
bool set(longlong num, CHARSET_INFO *cs) { return set_int(num, false, cs); }
219+
bool set(ulonglong num, CHARSET_INFO *cs) { return set_int((longlong)num, true, cs); }
218220
bool set_real(double num,uint decimals, CHARSET_INFO *cs);
219221

220222
/* Move handling of buffer from some other object to String */

0 commit comments

Comments
 (0)