Skip to content

Commit

Permalink
MDEV-9516 type error when setting session variable
Browse files Browse the repository at this point in the history
Allowing assigning of DECIMAL(N,0) values to INT-alike system variables.
  • Loading branch information
Alexander Barkov committed Mar 21, 2016
1 parent e8af217 commit 537fc57
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ ERROR 42000: Incorrect argument type to variable 'innodb_thread_sleep_delay'
set global innodb_thread_sleep_delay="foo";
ERROR 42000: Incorrect argument type to variable 'innodb_thread_sleep_delay'
set global innodb_thread_sleep_delay=18446744073709551616;
ERROR 42000: Incorrect argument type to variable 'innodb_thread_sleep_delay'
Warnings:
Warning 1916 Got overflow when converting '18446744073709551616' to INT. Value truncated.
Warning 1292 Truncated incorrect innodb_thread_sleep_delay value: '9223372036854775807'
set global innodb_thread_sleep_delay=-7;
Warnings:
Warning 1292 Truncated incorrect innodb_thread_sleep_delay value: '-7'
Expand Down
12 changes: 12 additions & 0 deletions mysql-test/suite/sys_vars/r/wait_timeout_basic.result
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,17 @@ SELECT session.wait_timeout;
ERROR 42S02: Unknown table 'session' in field list
SELECT wait_timeout = @@session.wait_timeout;
ERROR 42S22: Unknown column 'wait_timeout' in 'field list'
#
# MDEV-9516 type error when setting session variable
#
SET SESSION wait_timeout= 28000;
SET SESSION wait_timeout= GREATEST(28000, @@wait_timeout);
SET SESSION wait_timeout= COALESCE(28000, @@wait_timeout);
SET SESSION wait_timeout= IFNULL(28000, @@wait_timeout);
SET SESSION wait_timeout= CASE WHEN TRUE THEN 28000 ELSE @@wait_timeout END;
SET SESSION wait_timeout= 28000.0;
ERROR 42000: Incorrect argument type to variable 'wait_timeout'
SET SESSION wait_timeout= 28000.1;
ERROR 42000: Incorrect argument type to variable 'wait_timeout'
SET @@global.wait_timeout = @start_global_value;
SET @@session.wait_timeout = @start_session_value;
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ set global innodb_thread_sleep_delay=1.1;
set global innodb_thread_sleep_delay=1e1;
--error ER_WRONG_TYPE_FOR_VAR
set global innodb_thread_sleep_delay="foo";
--error ER_WRONG_TYPE_FOR_VAR

set global innodb_thread_sleep_delay=18446744073709551616;

set global innodb_thread_sleep_delay=-7;
Expand Down
14 changes: 14 additions & 0 deletions mysql-test/suite/sys_vars/t/wait_timeout_basic.test
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,20 @@ SELECT session.wait_timeout;
--Error ER_BAD_FIELD_ERROR
SELECT wait_timeout = @@session.wait_timeout;

--echo #
--echo # MDEV-9516 type error when setting session variable
--echo #

SET SESSION wait_timeout= 28000;
SET SESSION wait_timeout= GREATEST(28000, @@wait_timeout);
SET SESSION wait_timeout= COALESCE(28000, @@wait_timeout);
SET SESSION wait_timeout= IFNULL(28000, @@wait_timeout);
SET SESSION wait_timeout= CASE WHEN TRUE THEN 28000 ELSE @@wait_timeout END;

--error ER_WRONG_TYPE_FOR_VAR
SET SESSION wait_timeout= 28000.0;
--error ER_WRONG_TYPE_FOR_VAR
SET SESSION wait_timeout= 28000.1;

####################################
# Restore initial value #
Expand Down
2 changes: 1 addition & 1 deletion sql/set_var.cc
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ int set_var::check(THD *thd)
if ((!value->fixed &&
value->fix_fields(thd, &value)) || value->check_cols(1))
return -1;
if (var->check_update_type(value->result_type()))
if (var->check_update_type(value))
{
my_error(ER_WRONG_TYPE_FOR_VAR, MYF(0), var->name.str);
return -1;
Expand Down
6 changes: 4 additions & 2 deletions sql/set_var.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,18 @@ class sys_var: protected Value_source // for double_from_string_with_check
bool is_set_stmt_ok() const { return !(flags & NO_SET_STATEMENT); }
bool is_written_to_binlog(enum_var_type type)
{ return type != OPT_GLOBAL && binlog_status == SESSION_VARIABLE_IN_BINLOG; }
bool check_update_type(Item_result type)
bool check_update_type(const Item *item)
{
Item_result type= item->result_type();
switch (option.var_type & GET_TYPE_MASK) {
case GET_INT:
case GET_UINT:
case GET_LONG:
case GET_ULONG:
case GET_LL:
case GET_ULL:
return type != INT_RESULT;
return type != INT_RESULT &&
(type != DECIMAL_RESULT || item->decimals != 0);
case GET_STR:
case GET_STR_ALLOC:
return type != STRING_RESULT;
Expand Down

0 comments on commit 537fc57

Please sign in to comment.