From 12da27da853f4e3e69778beb2b8df4406685494f Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Thu, 16 Jul 2015 16:28:06 +0400 Subject: [PATCH] MDEV-8472 BINARY, VARBINARY and BLOB return different warnings on CAST to DECIMAL --- mysql-test/r/type_binary.result | 34 +++++++++++++++++ .../suite/funcs_1/r/innodb_func_view.result | 8 ++-- .../suite/funcs_1/r/memory_func_view.result | 8 ++-- .../suite/funcs_1/r/myisam_func_view.result | 8 ++-- mysql-test/t/type_binary.test | 26 +++++++++++++ sql/field.cc | 38 +++++++++---------- sql/field.h | 3 ++ 7 files changed, 93 insertions(+), 32 deletions(-) diff --git a/mysql-test/r/type_binary.result b/mysql-test/r/type_binary.result index b00d1585b2927..9d44d718a0297 100644 --- a/mysql-test/r/type_binary.result +++ b/mysql-test/r/type_binary.result @@ -146,3 +146,37 @@ hex(f2) hex(f3) 0000 drop table t1; End of 5.0 tests +# +# Start of 10.0 tests +# +# +# MDEV-8472 BINARY, VARBINARY and BLOB return different warnings on CAST to DECIMAL +# +SET NAMES utf8; +CREATE TABLE t1 (a BINARY(30)); +INSERT INTO t1 VALUES ('1äÖüß@µ*$'); +SELECT CAST(a AS DECIMAL) FROM t1; +CAST(a AS DECIMAL) +1 +Warnings: +Warning 1292 Truncated incorrect DECIMAL value: '1\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' +DROP TABLE t1; +CREATE TABLE t1 (a VARBINARY(30)); +INSERT INTO t1 VALUES ('1äÖüß@µ*$'); +SELECT CAST(a AS DECIMAL) FROM t1; +CAST(a AS DECIMAL) +1 +Warnings: +Warning 1292 Truncated incorrect DECIMAL value: '1\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$' +DROP TABLE t1; +CREATE TABLE t1 (a BLOB); +INSERT INTO t1 VALUES ('1äÖüß@µ*$'); +SELECT CAST(a AS DECIMAL) FROM t1; +CAST(a AS DECIMAL) +1 +Warnings: +Warning 1292 Truncated incorrect DECIMAL value: '1\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$' +DROP TABLE t1; +# +# End of 10.0 tests +# diff --git a/mysql-test/suite/funcs_1/r/innodb_func_view.result b/mysql-test/suite/funcs_1/r/innodb_func_view.result index ae9440859df8a..f4cbc188e691b 100644 --- a/mysql-test/suite/funcs_1/r/innodb_func_view.result +++ b/mysql-test/suite/funcs_1/r/innodb_func_view.result @@ -3404,7 +3404,7 @@ Warning 1292 Truncated incorrect DECIMAL value: '' Warning 1918 Encountered illegal value '' when converting to DECIMAL Warning 1292 Truncated incorrect DECIMAL value: '<---------1000 characters-------------------------------------------------------------------------------------------------------' Warning 1918 Encountered illegal value '' when converting to DECIMAL -Warning 1292 Truncated incorrect DECIMAL value: ' ---äÖüß@µ*$-- ' +Warning 1292 Truncated incorrect DECIMAL value: ' ---\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$-- ' SHOW CREATE VIEW v1; View Create View character_set_client collation_connection v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select cast(`t1_values`.`my_varbinary_1000` as decimal(37,2)) AS `CAST(my_varbinary_1000 AS DECIMAL(37,2))`,`t1_values`.`my_varbinary_1000` AS `my_varbinary_1000`,`t1_values`.`id` AS `id` from `t1_values` latin1 latin1_swedish_ci @@ -3424,7 +3424,7 @@ Warning 1292 Truncated incorrect DECIMAL value: '' Warning 1918 Encountered illegal value '' when converting to DECIMAL Warning 1292 Truncated incorrect DECIMAL value: '<---------1000 characters-------------------------------------------------------------------------------------------------------' Warning 1918 Encountered illegal value '' when converting to DECIMAL -Warning 1292 Truncated incorrect DECIMAL value: ' ---äÖüß@µ*$-- ' +Warning 1292 Truncated incorrect DECIMAL value: ' ---\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$-- ' DROP VIEW v1; @@ -3492,7 +3492,7 @@ Warning 1292 Truncated incorrect DECIMAL value: '' Warning 1918 Encountered illegal value '' when converting to DECIMAL Warning 1292 Truncated incorrect DECIMAL value: '<---------1000 characters-------------------------------------------------------------------------------------------------------' Warning 1918 Encountered illegal value '' when converting to DECIMAL -Warning 1292 Truncated incorrect DECIMAL value: ' ---äÖüß@µ*$-- ' +Warning 1292 Truncated incorrect DECIMAL value: ' ---äÖüß@µ*$-- ' SHOW CREATE VIEW v1; View Create View character_set_client collation_connection v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select cast(`t1_values`.`my_varchar_1000` as decimal(37,2)) AS `CAST(my_varchar_1000 AS DECIMAL(37,2))`,`t1_values`.`my_varchar_1000` AS `my_varchar_1000`,`t1_values`.`id` AS `id` from `t1_values` latin1 latin1_swedish_ci @@ -3512,7 +3512,7 @@ Warning 1292 Truncated incorrect DECIMAL value: '' Warning 1918 Encountered illegal value '' when converting to DECIMAL Warning 1292 Truncated incorrect DECIMAL value: '<---------1000 characters-------------------------------------------------------------------------------------------------------' Warning 1918 Encountered illegal value '' when converting to DECIMAL -Warning 1292 Truncated incorrect DECIMAL value: ' ---äÖüß@µ*$-- ' +Warning 1292 Truncated incorrect DECIMAL value: ' ---äÖüß@µ*$-- ' DROP VIEW v1; diff --git a/mysql-test/suite/funcs_1/r/memory_func_view.result b/mysql-test/suite/funcs_1/r/memory_func_view.result index 81f7a0584d307..623fb38ef508b 100644 --- a/mysql-test/suite/funcs_1/r/memory_func_view.result +++ b/mysql-test/suite/funcs_1/r/memory_func_view.result @@ -3405,7 +3405,7 @@ Warning 1292 Truncated incorrect DECIMAL value: '' Warning 1918 Encountered illegal value '' when converting to DECIMAL Warning 1292 Truncated incorrect DECIMAL value: '<---------1000 characters-------------------------------------------------------------------------------------------------------' Warning 1918 Encountered illegal value '' when converting to DECIMAL -Warning 1292 Truncated incorrect DECIMAL value: ' ---äÖüß@µ*$-- ' +Warning 1292 Truncated incorrect DECIMAL value: ' ---\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$-- ' SHOW CREATE VIEW v1; View Create View character_set_client collation_connection v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select cast(`t1_values`.`my_varbinary_1000` as decimal(37,2)) AS `CAST(my_varbinary_1000 AS DECIMAL(37,2))`,`t1_values`.`my_varbinary_1000` AS `my_varbinary_1000`,`t1_values`.`id` AS `id` from `t1_values` latin1 latin1_swedish_ci @@ -3425,7 +3425,7 @@ Warning 1292 Truncated incorrect DECIMAL value: '' Warning 1918 Encountered illegal value '' when converting to DECIMAL Warning 1292 Truncated incorrect DECIMAL value: '<---------1000 characters-------------------------------------------------------------------------------------------------------' Warning 1918 Encountered illegal value '' when converting to DECIMAL -Warning 1292 Truncated incorrect DECIMAL value: ' ---äÖüß@µ*$-- ' +Warning 1292 Truncated incorrect DECIMAL value: ' ---\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$-- ' DROP VIEW v1; @@ -3493,7 +3493,7 @@ Warning 1292 Truncated incorrect DECIMAL value: '' Warning 1918 Encountered illegal value '' when converting to DECIMAL Warning 1292 Truncated incorrect DECIMAL value: '<---------1000 characters-------------------------------------------------------------------------------------------------------' Warning 1918 Encountered illegal value '' when converting to DECIMAL -Warning 1292 Truncated incorrect DECIMAL value: ' ---äÖüß@µ*$-- ' +Warning 1292 Truncated incorrect DECIMAL value: ' ---äÖüß@µ*$-- ' SHOW CREATE VIEW v1; View Create View character_set_client collation_connection v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select cast(`t1_values`.`my_varchar_1000` as decimal(37,2)) AS `CAST(my_varchar_1000 AS DECIMAL(37,2))`,`t1_values`.`my_varchar_1000` AS `my_varchar_1000`,`t1_values`.`id` AS `id` from `t1_values` latin1 latin1_swedish_ci @@ -3513,7 +3513,7 @@ Warning 1292 Truncated incorrect DECIMAL value: '' Warning 1918 Encountered illegal value '' when converting to DECIMAL Warning 1292 Truncated incorrect DECIMAL value: '<---------1000 characters-------------------------------------------------------------------------------------------------------' Warning 1918 Encountered illegal value '' when converting to DECIMAL -Warning 1292 Truncated incorrect DECIMAL value: ' ---äÖüß@µ*$-- ' +Warning 1292 Truncated incorrect DECIMAL value: ' ---äÖüß@µ*$-- ' DROP VIEW v1; diff --git a/mysql-test/suite/funcs_1/r/myisam_func_view.result b/mysql-test/suite/funcs_1/r/myisam_func_view.result index 81f7a0584d307..623fb38ef508b 100644 --- a/mysql-test/suite/funcs_1/r/myisam_func_view.result +++ b/mysql-test/suite/funcs_1/r/myisam_func_view.result @@ -3405,7 +3405,7 @@ Warning 1292 Truncated incorrect DECIMAL value: '' Warning 1918 Encountered illegal value '' when converting to DECIMAL Warning 1292 Truncated incorrect DECIMAL value: '<---------1000 characters-------------------------------------------------------------------------------------------------------' Warning 1918 Encountered illegal value '' when converting to DECIMAL -Warning 1292 Truncated incorrect DECIMAL value: ' ---äÖüß@µ*$-- ' +Warning 1292 Truncated incorrect DECIMAL value: ' ---\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$-- ' SHOW CREATE VIEW v1; View Create View character_set_client collation_connection v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select cast(`t1_values`.`my_varbinary_1000` as decimal(37,2)) AS `CAST(my_varbinary_1000 AS DECIMAL(37,2))`,`t1_values`.`my_varbinary_1000` AS `my_varbinary_1000`,`t1_values`.`id` AS `id` from `t1_values` latin1 latin1_swedish_ci @@ -3425,7 +3425,7 @@ Warning 1292 Truncated incorrect DECIMAL value: '' Warning 1918 Encountered illegal value '' when converting to DECIMAL Warning 1292 Truncated incorrect DECIMAL value: '<---------1000 characters-------------------------------------------------------------------------------------------------------' Warning 1918 Encountered illegal value '' when converting to DECIMAL -Warning 1292 Truncated incorrect DECIMAL value: ' ---äÖüß@µ*$-- ' +Warning 1292 Truncated incorrect DECIMAL value: ' ---\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$-- ' DROP VIEW v1; @@ -3493,7 +3493,7 @@ Warning 1292 Truncated incorrect DECIMAL value: '' Warning 1918 Encountered illegal value '' when converting to DECIMAL Warning 1292 Truncated incorrect DECIMAL value: '<---------1000 characters-------------------------------------------------------------------------------------------------------' Warning 1918 Encountered illegal value '' when converting to DECIMAL -Warning 1292 Truncated incorrect DECIMAL value: ' ---äÖüß@µ*$-- ' +Warning 1292 Truncated incorrect DECIMAL value: ' ---äÖüß@µ*$-- ' SHOW CREATE VIEW v1; View Create View character_set_client collation_connection v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select cast(`t1_values`.`my_varchar_1000` as decimal(37,2)) AS `CAST(my_varchar_1000 AS DECIMAL(37,2))`,`t1_values`.`my_varchar_1000` AS `my_varchar_1000`,`t1_values`.`id` AS `id` from `t1_values` latin1 latin1_swedish_ci @@ -3513,7 +3513,7 @@ Warning 1292 Truncated incorrect DECIMAL value: '' Warning 1918 Encountered illegal value '' when converting to DECIMAL Warning 1292 Truncated incorrect DECIMAL value: '<---------1000 characters-------------------------------------------------------------------------------------------------------' Warning 1918 Encountered illegal value '' when converting to DECIMAL -Warning 1292 Truncated incorrect DECIMAL value: ' ---äÖüß@µ*$-- ' +Warning 1292 Truncated incorrect DECIMAL value: ' ---äÖüß@µ*$-- ' DROP VIEW v1; diff --git a/mysql-test/t/type_binary.test b/mysql-test/t/type_binary.test index 4d5a53124725d..b583e257aa9a4 100644 --- a/mysql-test/t/type_binary.test +++ b/mysql-test/t/type_binary.test @@ -100,3 +100,29 @@ select hex(f2), hex(f3) from t1; drop table t1; --echo End of 5.0 tests + +--echo # +--echo # Start of 10.0 tests +--echo # + +--echo # +--echo # MDEV-8472 BINARY, VARBINARY and BLOB return different warnings on CAST to DECIMAL +--echo # +SET NAMES utf8; +CREATE TABLE t1 (a BINARY(30)); +INSERT INTO t1 VALUES ('1äÖüß@µ*$'); +SELECT CAST(a AS DECIMAL) FROM t1; +DROP TABLE t1; +CREATE TABLE t1 (a VARBINARY(30)); +INSERT INTO t1 VALUES ('1äÖüß@µ*$'); +SELECT CAST(a AS DECIMAL) FROM t1; +DROP TABLE t1; +CREATE TABLE t1 (a BLOB); +INSERT INTO t1 VALUES ('1äÖüß@µ*$'); +SELECT CAST(a AS DECIMAL) FROM t1; +DROP TABLE t1; + +--echo # +--echo # End of 10.0 tests +--echo # + diff --git a/sql/field.cc b/sql/field.cc index c5319ae0b72cb..582926cb563f8 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -6500,24 +6500,32 @@ String *Field_string::val_str(String *val_buffer __attribute__((unused)), } -my_decimal *Field_string::val_decimal(my_decimal *decimal_value) +my_decimal *Field_longstr::val_decimal_from_str(const char *str, + uint length, + CHARSET_INFO *cs, + my_decimal *decimal_value) { - ASSERT_COLUMN_MARKED_FOR_READ; - int err= str2my_decimal(E_DEC_FATAL_ERROR, (char*) ptr, field_length, - charset(), decimal_value); + int err= str2my_decimal(E_DEC_FATAL_ERROR, str, length, cs, decimal_value); if (!get_thd()->no_errors && err) { - ErrConvString errmsg((char*) ptr, field_length, charset()); + ErrConvString errmsg(str, length, cs); push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, ER_TRUNCATED_WRONG_VALUE, ER(ER_TRUNCATED_WRONG_VALUE), "DECIMAL", errmsg.ptr()); } - return decimal_value; } +my_decimal *Field_string::val_decimal(my_decimal *decimal_value) +{ + ASSERT_COLUMN_MARKED_FOR_READ; + return val_decimal_from_str((const char *) ptr, field_length, + Field_string::charset(), decimal_value); +} + + struct Check_field_param { Field *field; }; @@ -6942,18 +6950,9 @@ String *Field_varstring::val_str(String *val_buffer __attribute__((unused)), my_decimal *Field_varstring::val_decimal(my_decimal *decimal_value) { ASSERT_COLUMN_MARKED_FOR_READ; - CHARSET_INFO *cs= charset(); uint length= length_bytes == 1 ? (uint) *ptr : uint2korr(ptr); - int error= str2my_decimal(E_DEC_FATAL_ERROR, (char*) ptr+length_bytes, length, - cs, decimal_value); - - if (!get_thd()->no_errors && error) - { - push_numerical_conversion_warning(current_thd, (char*)ptr+length_bytes, - length, cs, "DECIMAL", - ER_TRUNCATED_WRONG_VALUE); - } - return decimal_value; + return val_decimal_from_str((const char *) ptr + length_bytes, length, + Field_varstring::charset(), decimal_value); } @@ -7474,9 +7473,8 @@ my_decimal *Field_blob::val_decimal(my_decimal *decimal_value) else length= get_length(ptr); - str2my_decimal(E_DEC_FATAL_ERROR, blob, length, charset(), - decimal_value); - return decimal_value; + return val_decimal_from_str(blob, length, + Field_blob::charset(), decimal_value); } diff --git a/sql/field.h b/sql/field.h index a40e2ef991368..4e3a9f4c7b10b 100644 --- a/sql/field.h +++ b/sql/field.h @@ -1161,6 +1161,9 @@ class Field_longstr :public Field_str const char *cannot_convert_error_pos, const char *end, CHARSET_INFO *cs); + my_decimal *val_decimal_from_str(const char *str, uint length, + CHARSET_INFO *cs, + my_decimal *decimal_value); public: Field_longstr(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, uchar null_bit_arg, utype unireg_check_arg,