commit 8bd66b17f61a51bb1833ad826611b006fb7ac3ba Author: yuxianjiang Date: Sun Dec 13 08:59:18 2020 -0500 [bugfix]issue#329 bind param update skip strict sql_mode checking Problem: ======== After prepareing update statement ”update tsm4 set f1=f1+1 where f1=?;“, bind parameter like '1abc'. Execution of this statement will succeed. While in the same strict mode, execution of SQL "update tsm4 set f1=f1+1 where f1='1abc' " will return error. And more, the succeeded SQL will be written to binlog in binlog-format of statement or mix. This query event will cause slave broken. Solution: ========= Convert parameter string to numberic value with sql_mode checking. diff --git a/mysql-test/r/bug_bind_param_update_skip_sql_mode_check.result b/mysql-test/r/bug_bind_param_update_skip_sql_mode_check.result new file mode 100644 index 000000000..32c1567e9 --- /dev/null +++ b/mysql-test/r/bug_bind_param_update_skip_sql_mode_check.result @@ -0,0 +1,10 @@ +CREATE TABLE `tsm4` ( +`f1` int(11) DEFAULT NULL, +`f2` varchar(10) DEFAULT NULL +); +insert into tsm4 values (1, 'abc'); +set @f1='1abc'; +prepare stmt1 from 'update tsm4 set f1=f1+1 where f1=?;'; +execute stmt1 using @f1; +ERROR 22007: Truncated incorrect DOUBLE value: '1abc' +drop table tsm4; diff --git a/mysql-test/suite/opt_trace/r/general_ps_prot_all.result b/mysql-test/suite/opt_trace/r/general_ps_prot_all.result index fe585f8fb..a142ecab1 100644 --- a/mysql-test/suite/opt_trace/r/general_ps_prot_all.result +++ b/mysql-test/suite/opt_trace/r/general_ps_prot_all.result @@ -10737,6 +10737,8 @@ set optimizer_trace_offset=0, optimizer_trace_limit=100; execute stmt using @param; count(*) 0 +Warnings: +Warning 1292 Truncated incorrect DOUBLE value: 'c' select count(*) from information_schema.OPTIMIZER_TRACE; count(*) 1 @@ -10869,6 +10871,8 @@ set optimizer_trace_offset=0, optimizer_trace_limit=100; execute stmt using @param; count(*) 0 +Warnings: +Warning 1292 Truncated incorrect DOUBLE value: 'c' select count(*) from information_schema.OPTIMIZER_TRACE; count(*) 1 diff --git a/mysql-test/suite/opt_trace/r/general_ps_prot_none.result b/mysql-test/suite/opt_trace/r/general_ps_prot_none.result index 9acca49bc..31dca1336 100644 --- a/mysql-test/suite/opt_trace/r/general_ps_prot_none.result +++ b/mysql-test/suite/opt_trace/r/general_ps_prot_none.result @@ -9971,6 +9971,8 @@ set optimizer_trace_offset=0, optimizer_trace_limit=100; execute stmt using @param; count(*) 0 +Warnings: +Warning 1292 Truncated incorrect DOUBLE value: 'c' select count(*) from information_schema.OPTIMIZER_TRACE; count(*) 1 @@ -10103,6 +10105,8 @@ set optimizer_trace_offset=0, optimizer_trace_limit=100; execute stmt using @param; count(*) 0 +Warnings: +Warning 1292 Truncated incorrect DOUBLE value: 'c' select count(*) from information_schema.OPTIMIZER_TRACE; count(*) 1 diff --git a/mysql-test/t/bug_bind_param_update_skip_sql_mode_check.test b/mysql-test/t/bug_bind_param_update_skip_sql_mode_check.test new file mode 100644 index 000000000..f02a6e6d9 --- /dev/null +++ b/mysql-test/t/bug_bind_param_update_skip_sql_mode_check.test @@ -0,0 +1,16 @@ +-- source include/not_embedded.inc +-- source include/have_log_bin.inc + +CREATE TABLE `tsm4` ( + `f1` int(11) DEFAULT NULL, + `f2` varchar(10) DEFAULT NULL +); + +insert into tsm4 values (1, 'abc'); + +set @f1='1abc'; +prepare stmt1 from 'update tsm4 set f1=f1+1 where f1=?;'; +--error ER_TRUNCATED_WRONG_VALUE +execute stmt1 using @f1; + +drop table tsm4; diff --git a/sql/item.cc b/sql/item.cc index 8155a447c..ab6d56a81 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -4122,10 +4122,8 @@ double Item_param::val_real() case STRING_VALUE: case LONG_DATA_VALUE: { - int dummy_err; - char *end_not_used; - return my_strntod(str_value.charset(), (char*) str_value.ptr(), - str_value.length(), &end_not_used, &dummy_err); + return double_from_string_with_check (str_value.charset(), str_value.ptr(), + (char *) str_value.ptr() + str_value.length()); } case TIME_VALUE: /*