mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
MDEV-17042: prepared statement does not return error with SQL_MODE STRICT_TRANS_TABLES.
Use for parameters value conversion functions which issue warnings.
This commit is contained in:
@ -4334,4 +4334,67 @@ LINE1 1
|
||||
LINE2 2
|
||||
LINE3 3
|
||||
drop table t1;
|
||||
#
|
||||
# MDEV-17042: prepared statement does not return error with
|
||||
# SQL_MODE STRICT_TRANS_TABLES. (Part 1)
|
||||
#
|
||||
set @save_sql_mode=@@sql_mode;
|
||||
set sql_mode='STRICT_ALL_TABLES';
|
||||
CREATE TABLE t1 (id int, count int);
|
||||
insert into t1 values (1,1),(0,2);
|
||||
update t1 set count = count + 1 where id = '1bad';
|
||||
ERROR 22007: Truncated incorrect DOUBLE value: '1bad'
|
||||
prepare stmt from "update t1 set count = count + 1 where id = '1bad'";
|
||||
execute stmt;
|
||||
ERROR 22007: Truncated incorrect DOUBLE value: '1bad'
|
||||
deallocate prepare stmt;
|
||||
prepare stmt from 'update t1 set count = count + 1 where id = ?';
|
||||
set @a = '1bad';
|
||||
execute stmt using @a;
|
||||
ERROR 22007: Truncated incorrect DOUBLE value: '1bad'
|
||||
deallocate prepare stmt;
|
||||
drop table t1;
|
||||
CREATE TABLE t1 (id decimal(10,5), count int);
|
||||
insert into t1 values (1,1),(0,2);
|
||||
update t1 set count = count + 1 where id = '1bad';
|
||||
ERROR 22007: Truncated incorrect DOUBLE value: '1bad'
|
||||
prepare stmt from "update t1 set count = count + 1 where id = '1bad'";
|
||||
execute stmt;
|
||||
ERROR 22007: Truncated incorrect DOUBLE value: '1bad'
|
||||
deallocate prepare stmt;
|
||||
prepare stmt from 'update t1 set count = count + 1 where id = ?';
|
||||
set @a = '1bad';
|
||||
execute stmt using @a;
|
||||
ERROR 22007: Truncated incorrect DOUBLE value: '1bad'
|
||||
deallocate prepare stmt;
|
||||
drop table t1;
|
||||
CREATE TABLE t1 (id double, count int);
|
||||
insert into t1 values (1,1),(0,2);
|
||||
update t1 set count = count + 1 where id = '1bad';
|
||||
ERROR 22007: Truncated incorrect DOUBLE value: '1bad'
|
||||
prepare stmt from "update t1 set count = count + 1 where id = '1bad'";
|
||||
execute stmt;
|
||||
ERROR 22007: Truncated incorrect DOUBLE value: '1bad'
|
||||
deallocate prepare stmt;
|
||||
prepare stmt from 'update t1 set count = count + 1 where id = ?';
|
||||
set @a = '1bad';
|
||||
execute stmt using @a;
|
||||
ERROR 22007: Truncated incorrect DOUBLE value: '1bad'
|
||||
deallocate prepare stmt;
|
||||
drop table t1;
|
||||
CREATE TABLE t1 (id date, count int);
|
||||
insert into t1 values ("2019-06-11",1),("2019-06-12",2);
|
||||
update t1 set count = count + 1 where id = '1bad';
|
||||
ERROR 22007: Incorrect datetime value: '1bad'
|
||||
prepare stmt from "update t1 set count = count + 1 where id = '1bad'";
|
||||
execute stmt;
|
||||
ERROR 22007: Incorrect datetime value: '1bad'
|
||||
deallocate prepare stmt;
|
||||
prepare stmt from 'update t1 set count = count + 1 where id = ?';
|
||||
set @a = '1bad';
|
||||
execute stmt using @a;
|
||||
ERROR 22007: Incorrect datetime value: '1bad'
|
||||
deallocate prepare stmt;
|
||||
drop table t1;
|
||||
set sql_mode=@save_sql_mode;
|
||||
# End of 5.5 tests
|
||||
|
64
mysql-test/r/ps_innodb.result
Normal file
64
mysql-test/r/ps_innodb.result
Normal file
@ -0,0 +1,64 @@
|
||||
#
|
||||
# MDEV-17042: prepared statement does not return error with
|
||||
# SQL_MODE STRICT_TRANS_TABLES. (Part 2)
|
||||
#
|
||||
set @save_sql_mode=@@sql_mode;
|
||||
set sql_mode='STRICT_TRANS_TABLES';
|
||||
CREATE TABLE t1 (id int, count int) engine=innodb;
|
||||
insert into t1 values (1,1),(0,2);
|
||||
update t1 set count = count + 1 where id = '1bad';
|
||||
ERROR 22007: Truncated incorrect DOUBLE value: '1bad'
|
||||
prepare stmt from "update t1 set count = count + 1 where id = '1bad'";
|
||||
execute stmt;
|
||||
ERROR 22007: Truncated incorrect DOUBLE value: '1bad'
|
||||
deallocate prepare stmt;
|
||||
prepare stmt from 'update t1 set count = count + 1 where id = ?';
|
||||
set @a = '1bad';
|
||||
execute stmt using @a;
|
||||
ERROR 22007: Truncated incorrect DOUBLE value: '1bad'
|
||||
deallocate prepare stmt;
|
||||
drop table t1;
|
||||
CREATE TABLE t1 (id decimal(10,5), count int) engine=innodb;
|
||||
insert into t1 values (1,1),(0,2);
|
||||
update t1 set count = count + 1 where id = '1bad';
|
||||
ERROR 22007: Truncated incorrect DOUBLE value: '1bad'
|
||||
prepare stmt from "update t1 set count = count + 1 where id = '1bad'";
|
||||
execute stmt;
|
||||
ERROR 22007: Truncated incorrect DOUBLE value: '1bad'
|
||||
deallocate prepare stmt;
|
||||
prepare stmt from 'update t1 set count = count + 1 where id = ?';
|
||||
set @a = '1bad';
|
||||
execute stmt using @a;
|
||||
ERROR 22007: Truncated incorrect DOUBLE value: '1bad'
|
||||
deallocate prepare stmt;
|
||||
drop table t1;
|
||||
CREATE TABLE t1 (id double, count int) engine=innodb;
|
||||
insert into t1 values (1,1),(0,2);
|
||||
update t1 set count = count + 1 where id = '1bad';
|
||||
ERROR 22007: Truncated incorrect DOUBLE value: '1bad'
|
||||
prepare stmt from "update t1 set count = count + 1 where id = '1bad'";
|
||||
execute stmt;
|
||||
ERROR 22007: Truncated incorrect DOUBLE value: '1bad'
|
||||
deallocate prepare stmt;
|
||||
prepare stmt from 'update t1 set count = count + 1 where id = ?';
|
||||
set @a = '1bad';
|
||||
execute stmt using @a;
|
||||
ERROR 22007: Truncated incorrect DOUBLE value: '1bad'
|
||||
deallocate prepare stmt;
|
||||
drop table t1;
|
||||
CREATE TABLE t1 (id date, count int) engine=innodb;
|
||||
insert into t1 values ("2019-06-11",1),("2019-06-12",2);
|
||||
update t1 set count = count + 1 where id = '1bad';
|
||||
ERROR 22007: Incorrect datetime value: '1bad'
|
||||
prepare stmt from "update t1 set count = count + 1 where id = '1bad'";
|
||||
execute stmt;
|
||||
ERROR 22007: Incorrect datetime value: '1bad'
|
||||
deallocate prepare stmt;
|
||||
prepare stmt from 'update t1 set count = count + 1 where id = ?';
|
||||
set @a = '1bad';
|
||||
execute stmt using @a;
|
||||
ERROR 22007: Incorrect datetime value: '1bad'
|
||||
deallocate prepare stmt;
|
||||
drop table t1;
|
||||
set sql_mode=@save_sql_mode;
|
||||
# End of 5.5 tests
|
@ -3858,4 +3858,81 @@ FROM
|
||||
FROM t1 A, (SELECT @cnt := 0) C) T
|
||||
) X;
|
||||
drop table t1;
|
||||
|
||||
--echo #
|
||||
--echo # MDEV-17042: prepared statement does not return error with
|
||||
--echo # SQL_MODE STRICT_TRANS_TABLES. (Part 1)
|
||||
--echo #
|
||||
|
||||
set @save_sql_mode=@@sql_mode;
|
||||
set sql_mode='STRICT_ALL_TABLES';
|
||||
|
||||
CREATE TABLE t1 (id int, count int);
|
||||
insert into t1 values (1,1),(0,2);
|
||||
--error ER_TRUNCATED_WRONG_VALUE
|
||||
update t1 set count = count + 1 where id = '1bad';
|
||||
|
||||
prepare stmt from "update t1 set count = count + 1 where id = '1bad'";
|
||||
--error ER_TRUNCATED_WRONG_VALUE
|
||||
execute stmt;
|
||||
deallocate prepare stmt;
|
||||
|
||||
prepare stmt from 'update t1 set count = count + 1 where id = ?';
|
||||
set @a = '1bad';
|
||||
--error ER_TRUNCATED_WRONG_VALUE
|
||||
execute stmt using @a;
|
||||
deallocate prepare stmt;
|
||||
drop table t1;
|
||||
|
||||
CREATE TABLE t1 (id decimal(10,5), count int);
|
||||
insert into t1 values (1,1),(0,2);
|
||||
--error ER_TRUNCATED_WRONG_VALUE
|
||||
update t1 set count = count + 1 where id = '1bad';
|
||||
|
||||
prepare stmt from "update t1 set count = count + 1 where id = '1bad'";
|
||||
--error ER_TRUNCATED_WRONG_VALUE
|
||||
execute stmt;
|
||||
deallocate prepare stmt;
|
||||
|
||||
prepare stmt from 'update t1 set count = count + 1 where id = ?';
|
||||
set @a = '1bad';
|
||||
--error ER_TRUNCATED_WRONG_VALUE
|
||||
execute stmt using @a;
|
||||
deallocate prepare stmt;
|
||||
drop table t1;
|
||||
|
||||
CREATE TABLE t1 (id double, count int);
|
||||
insert into t1 values (1,1),(0,2);
|
||||
--error ER_TRUNCATED_WRONG_VALUE
|
||||
update t1 set count = count + 1 where id = '1bad';
|
||||
|
||||
prepare stmt from "update t1 set count = count + 1 where id = '1bad'";
|
||||
--error ER_TRUNCATED_WRONG_VALUE
|
||||
execute stmt;
|
||||
deallocate prepare stmt;
|
||||
|
||||
prepare stmt from 'update t1 set count = count + 1 where id = ?';
|
||||
set @a = '1bad';
|
||||
--error ER_TRUNCATED_WRONG_VALUE
|
||||
execute stmt using @a;
|
||||
deallocate prepare stmt;
|
||||
drop table t1;
|
||||
|
||||
CREATE TABLE t1 (id date, count int);
|
||||
insert into t1 values ("2019-06-11",1),("2019-06-12",2);
|
||||
--error ER_TRUNCATED_WRONG_VALUE
|
||||
update t1 set count = count + 1 where id = '1bad';
|
||||
|
||||
prepare stmt from "update t1 set count = count + 1 where id = '1bad'";
|
||||
--error ER_TRUNCATED_WRONG_VALUE
|
||||
execute stmt;
|
||||
deallocate prepare stmt;
|
||||
|
||||
prepare stmt from 'update t1 set count = count + 1 where id = ?';
|
||||
set @a = '1bad';
|
||||
--error ER_TRUNCATED_WRONG_VALUE
|
||||
execute stmt using @a;
|
||||
deallocate prepare stmt;
|
||||
drop table t1;
|
||||
set sql_mode=@save_sql_mode;
|
||||
--echo # End of 5.5 tests
|
||||
|
80
mysql-test/t/ps_innodb.test
Normal file
80
mysql-test/t/ps_innodb.test
Normal file
@ -0,0 +1,80 @@
|
||||
--source include/have_innodb.inc
|
||||
|
||||
--echo #
|
||||
--echo # MDEV-17042: prepared statement does not return error with
|
||||
--echo # SQL_MODE STRICT_TRANS_TABLES. (Part 2)
|
||||
--echo #
|
||||
|
||||
set @save_sql_mode=@@sql_mode;
|
||||
set sql_mode='STRICT_TRANS_TABLES';
|
||||
|
||||
CREATE TABLE t1 (id int, count int) engine=innodb;
|
||||
insert into t1 values (1,1),(0,2);
|
||||
--error ER_TRUNCATED_WRONG_VALUE
|
||||
update t1 set count = count + 1 where id = '1bad';
|
||||
|
||||
prepare stmt from "update t1 set count = count + 1 where id = '1bad'";
|
||||
--error ER_TRUNCATED_WRONG_VALUE
|
||||
execute stmt;
|
||||
deallocate prepare stmt;
|
||||
|
||||
prepare stmt from 'update t1 set count = count + 1 where id = ?';
|
||||
set @a = '1bad';
|
||||
--error ER_TRUNCATED_WRONG_VALUE
|
||||
execute stmt using @a;
|
||||
deallocate prepare stmt;
|
||||
drop table t1;
|
||||
|
||||
CREATE TABLE t1 (id decimal(10,5), count int) engine=innodb;
|
||||
insert into t1 values (1,1),(0,2);
|
||||
--error ER_TRUNCATED_WRONG_VALUE
|
||||
update t1 set count = count + 1 where id = '1bad';
|
||||
|
||||
prepare stmt from "update t1 set count = count + 1 where id = '1bad'";
|
||||
--error ER_TRUNCATED_WRONG_VALUE
|
||||
execute stmt;
|
||||
deallocate prepare stmt;
|
||||
|
||||
prepare stmt from 'update t1 set count = count + 1 where id = ?';
|
||||
set @a = '1bad';
|
||||
--error ER_TRUNCATED_WRONG_VALUE
|
||||
execute stmt using @a;
|
||||
deallocate prepare stmt;
|
||||
drop table t1;
|
||||
|
||||
CREATE TABLE t1 (id double, count int) engine=innodb;
|
||||
insert into t1 values (1,1),(0,2);
|
||||
--error ER_TRUNCATED_WRONG_VALUE
|
||||
update t1 set count = count + 1 where id = '1bad';
|
||||
|
||||
prepare stmt from "update t1 set count = count + 1 where id = '1bad'";
|
||||
--error ER_TRUNCATED_WRONG_VALUE
|
||||
execute stmt;
|
||||
deallocate prepare stmt;
|
||||
|
||||
prepare stmt from 'update t1 set count = count + 1 where id = ?';
|
||||
set @a = '1bad';
|
||||
--error ER_TRUNCATED_WRONG_VALUE
|
||||
execute stmt using @a;
|
||||
deallocate prepare stmt;
|
||||
drop table t1;
|
||||
|
||||
CREATE TABLE t1 (id date, count int) engine=innodb;
|
||||
insert into t1 values ("2019-06-11",1),("2019-06-12",2);
|
||||
--error ER_TRUNCATED_WRONG_VALUE
|
||||
update t1 set count = count + 1 where id = '1bad';
|
||||
|
||||
prepare stmt from "update t1 set count = count + 1 where id = '1bad'";
|
||||
--error ER_TRUNCATED_WRONG_VALUE
|
||||
execute stmt;
|
||||
deallocate prepare stmt;
|
||||
|
||||
prepare stmt from 'update t1 set count = count + 1 where id = ?';
|
||||
set @a = '1bad';
|
||||
--error ER_TRUNCATED_WRONG_VALUE
|
||||
execute stmt using @a;
|
||||
deallocate prepare stmt;
|
||||
drop table t1;
|
||||
set sql_mode=@save_sql_mode;
|
||||
|
||||
--echo # End of 5.5 tests
|
20
sql/item.cc
20
sql/item.cc
@ -3668,10 +3668,10 @@ 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(),
|
||||
str_value.ptr() +
|
||||
str_value.length());
|
||||
}
|
||||
case TIME_VALUE:
|
||||
/*
|
||||
@ -3706,11 +3706,10 @@ longlong Item_param::val_int()
|
||||
}
|
||||
case STRING_VALUE:
|
||||
case LONG_DATA_VALUE:
|
||||
{
|
||||
int dummy_err;
|
||||
return my_strntoll(str_value.charset(), str_value.ptr(),
|
||||
str_value.length(), 10, (char**) 0, &dummy_err);
|
||||
}
|
||||
return longlong_from_string_with_check(str_value.charset(),
|
||||
str_value.ptr(),
|
||||
str_value.ptr() +
|
||||
str_value.length());
|
||||
case TIME_VALUE:
|
||||
return (longlong) TIME_to_ulonglong(&value.time);
|
||||
case NULL_VALUE:
|
||||
@ -3735,8 +3734,7 @@ my_decimal *Item_param::val_decimal(my_decimal *dec)
|
||||
return dec;
|
||||
case STRING_VALUE:
|
||||
case LONG_DATA_VALUE:
|
||||
string2my_decimal(E_DEC_FATAL_ERROR, &str_value, dec);
|
||||
return dec;
|
||||
return val_decimal_from_string(dec);
|
||||
case TIME_VALUE:
|
||||
{
|
||||
longlong i= (longlong) TIME_to_ulonglong(&value.time);
|
||||
|
Reference in New Issue
Block a user