Commit 537fc572 authored by Alexander Barkov's avatar Alexander Barkov

MDEV-9516 type error when setting session variable

Allowing assigning of DECIMAL(N,0) values to INT-alike system variables.
parent e8af217e
......@@ -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'
......
......@@ -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;
......@@ -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;
......
......@@ -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 #
......
......@@ -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;
......
......@@ -137,8 +137,9 @@ public:
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:
......@@ -146,7 +147,8 @@ public:
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;
......
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