diff --git a/mysql-test/r/flagset_option_with_unrecognized_flag.result b/mysql-test/r/flagset_option_with_unrecognized_flag.result index 6ceacdb93ac..db2dd81e8e9 100644 --- a/mysql-test/r/flagset_option_with_unrecognized_flag.result +++ b/mysql-test/r/flagset_option_with_unrecognized_flag.result @@ -22,4 +22,6 @@ Warnings: Warning 6424 Adjusted incorrect optimizer_switch value: 'ab=c=-d=123-,', discarding 'ab=c=-d=123-'. SET optimizer_switch='mrr=on'; SET optimizer_switch=''; +SET optimizer_switch='index'; +ERROR 42000: Variable 'optimizer_switch' can't be set to the value of 'index' # restart: diff --git a/mysql-test/t/flagset_option_with_unrecognized_flag.test b/mysql-test/t/flagset_option_with_unrecognized_flag.test index 786f05ca07a..f85f14cc8fa 100644 --- a/mysql-test/t/flagset_option_with_unrecognized_flag.test +++ b/mysql-test/t/flagset_option_with_unrecognized_flag.test @@ -24,6 +24,9 @@ SET optimizer_switch='mrr=on,ab=c=-d=123-,derived_merge=off'; SET optimizer_switch='ab=c=-d=123-,'; SET optimizer_switch='mrr=on'; SET optimizer_switch=''; +# Coverage test for any true error which are not adjusted. +--error ER_WRONG_VALUE_FOR_VAR +SET optimizer_switch='index'; let $restart_parameters = "restart:"; --source include/restart_mysqld.inc diff --git a/mysys/my_getopt.cc b/mysys/my_getopt.cc index b5bbb9831fb..3f372108748 100644 --- a/mysys/my_getopt.cc +++ b/mysys/my_getopt.cc @@ -956,17 +956,17 @@ static int setval(const struct my_option *opts, void *value, strlen(argument), &flag_error, &error_len, abuf, sizeof(abuf), ebuf, sizeof(ebuf)); + if (flag_error) { + res = EXIT_ARGUMENT_INVALID; + goto ret; + }; + if (ebuf[0] != '\0') { my_getopt_error_reporter( WARNING_LEVEL, EE_ADJUSTED_FLAGSET_VALUE_FOR_OPTION, opts->name, argument, abuf, ebuf); assert(!flag_error); } - - if (flag_error) { - res = EXIT_ARGUMENT_INVALID; - goto ret; - }; } break; case GET_NO_ARG: /* get_one_option has taken care of the value already */ default: /* dummy default to avoid compiler warnings */ diff --git a/mysys/typelib.cc b/mysys/typelib.cc index 981d33e308e..659fdd45331 100644 --- a/mysys/typelib.cc +++ b/mysys/typelib.cc @@ -296,7 +296,8 @@ inline void append_flag(char *buf, uint size, char **pp, const char *start, @param err_len OUT If error, set to the length of wrong set string @param abuf OUT String buffer to collect recognized flags @param asize Size of abuf - @param ebuf OUT String buffer to collect unrecognized flags + @param ebuf OUT String buffer to collect unrecognized flags (they are + not errors, thus should be checked on success) @param esize Size of ebuf @details diff --git a/sql/set_var.cc b/sql/set_var.cc index fbb32228673..4e7817afb5b 100644 --- a/sql/set_var.cc +++ b/sql/set_var.cc @@ -591,10 +591,10 @@ bool throw_bounds_warning(THD *thd, const char *name, bool fixed, double v) { } bool throw_bounds_warning(THD *thd, const char *name, bool fixed, - const char *v, const char *err, const char *eb) { + const char *v, const char *eb) { if (fixed) { if (thd->variables.sql_mode & MODE_STRICT_ALL_TABLES) { - my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, err); + my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, eb); return true; } push_warning_printf(thd, Sql_condition::SL_WARNING, diff --git a/sql/sys_vars.h b/sql/sys_vars.h index 01d9b3f881b..c8f828287ae 100644 --- a/sql/sys_vars.h +++ b/sql/sys_vars.h @@ -1567,16 +1567,17 @@ class Sys_var_flagset : public Sys_var_typelib { &typelib, typelib.count, current_value, default_value, res->ptr(), static_cast(res->length()), &error, &error_len, abuf, sizeof(abuf), ebuf, sizeof(ebuf)); - if (!error) { - error = ebuf; - error_len = strlen(ebuf); - } - const ErrConvString err(error, error_len, res->charset()); - const ErrConvString eb(ebuf, strlen(ebuf), res->charset()); + if (error) { + const ErrConvString err(error, error_len, res->charset()); + my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name.str, err.ptr()); + return true; + } + const ErrConvString eb(ebuf, strlen(ebuf), res->charset()); bool fixed = ebuf[0] != '\0'; - return throw_bounds_warning(current_thd, name.str, fixed, res->ptr(), - err.ptr(), eb.ptr()); + if (throw_bounds_warning(current_thd, name.str, fixed, res->ptr(), + eb.ptr())) + return true; } } else { const longlong tmp = var->value->val_int(); diff --git a/sql/sys_vars_shared.h b/sql/sys_vars_shared.h index 56f91fcfd5f..2743bc502ff 100644 --- a/sql/sys_vars_shared.h +++ b/sql/sys_vars_shared.h @@ -45,8 +45,7 @@ extern bool throw_bounds_warning(THD *thd, const char *name, bool fixed, extern bool throw_bounds_warning(THD *thd, const char *name, bool fixed, double v); extern bool throw_bounds_warning(THD *thd, const char *name, bool fixed, - const char *v, const char *err, - const char *eb); + const char *v, const char *eb); extern sys_var *find_static_system_variable(const std::string &name); extern sys_var *find_dynamic_system_variable(const std::string &name); extern sys_var *intern_find_sys_var(const char *str, size_t length);