Skip to content

Commit

Permalink
MDEV-8472 BINARY, VARBINARY and BLOB return different warnings on CAS…
Browse files Browse the repository at this point in the history
…T to DECIMAL
  • Loading branch information
Alexander Barkov committed Jul 16, 2015
1 parent 94bc506 commit 12da27d
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 32 deletions.
34 changes: 34 additions & 0 deletions mysql-test/r/type_binary.result
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
8 changes: 4 additions & 4 deletions mysql-test/suite/funcs_1/r/innodb_func_view.result
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;


Expand Down Expand Up @@ -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
Expand All @@ -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;


Expand Down
8 changes: 4 additions & 4 deletions mysql-test/suite/funcs_1/r/memory_func_view.result
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;


Expand Down Expand Up @@ -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
Expand All @@ -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;


Expand Down
8 changes: 4 additions & 4 deletions mysql-test/suite/funcs_1/r/myisam_func_view.result
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;


Expand Down Expand Up @@ -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
Expand All @@ -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;


Expand Down
26 changes: 26 additions & 0 deletions mysql-test/t/type_binary.test
Original file line number Diff line number Diff line change
Expand Up @@ -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 #

38 changes: 18 additions & 20 deletions sql/field.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down Expand Up @@ -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);
}


Expand Down Expand Up @@ -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);
}


Expand Down
3 changes: 3 additions & 0 deletions sql/field.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 12da27d

Please sign in to comment.