diff --git a/mysql-test/main/sp-vars.result b/mysql-test/main/sp-vars.result index f0931ca48ff..e8e7b66b3ab 100644 --- a/mysql-test/main/sp-vars.result +++ b/mysql-test/main/sp-vars.result @@ -1171,7 +1171,7 @@ SET j= 1 + i; END| CALL ctest(); Warnings: -Warning 1292 Truncated incorrect DOUBLE value: 'string ' +Warning 1292 Truncated incorrect DOUBLE value: 'string' DROP PROCEDURE ctest; CREATE PROCEDURE vctest() BEGIN diff --git a/mysql-test/main/type_char.result b/mysql-test/main/type_char.result new file mode 100644 index 00000000000..07dfe7cdc29 --- /dev/null +++ b/mysql-test/main/type_char.result @@ -0,0 +1,40 @@ +# +# Start of 10.5 tests +# +# +# MDEV-34295 CAST(char_col AS DOUBLE) prints redundant spaces in a warning +# +CREATE TABLE t1 (a CHAR(5) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci); +INSERT INTO t1 VALUES ('1x'), ('x'); +SELECT a, CAST(a AS DOUBLE) FROM t1 ORDER BY a; +a CAST(a AS DOUBLE) +1x 1 +x 0 +Warnings: +Warning 1292 Truncated incorrect DOUBLE value: '1x' +Warning 1292 Truncated incorrect DOUBLE value: 'x' +SELECT a, CAST(a AS DECIMAL(20,2)) FROM t1 ORDER BY a; +a CAST(a AS DECIMAL(20,2)) +1x 1.00 +x 0.00 +Warnings: +Warning 1292 Truncated incorrect DECIMAL value: '1x' +Warning 1292 Truncated incorrect DECIMAL value: 'x' +SELECT a, CAST(a AS SIGNED) FROM t1 ORDER BY a; +a CAST(a AS SIGNED) +1x 1 +x 0 +Warnings: +Warning 1292 Truncated incorrect INTEGER value: '1x' +Warning 1292 Truncated incorrect INTEGER value: 'x' +SELECT a, CAST(a AS UNSIGNED) FROM t1 ORDER BY a; +a CAST(a AS UNSIGNED) +1x 1 +x 0 +Warnings: +Warning 1292 Truncated incorrect INTEGER value: '1x' +Warning 1292 Truncated incorrect INTEGER value: 'x' +DROP TABLE t1; +# +# End of 10.5 tests +# diff --git a/mysql-test/main/type_char.test b/mysql-test/main/type_char.test new file mode 100644 index 00000000000..053613c5dad --- /dev/null +++ b/mysql-test/main/type_char.test @@ -0,0 +1,19 @@ +--echo # +--echo # Start of 10.5 tests +--echo # + +--echo # +--echo # MDEV-34295 CAST(char_col AS DOUBLE) prints redundant spaces in a warning +--echo # + +CREATE TABLE t1 (a CHAR(5) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci); +INSERT INTO t1 VALUES ('1x'), ('x'); +SELECT a, CAST(a AS DOUBLE) FROM t1 ORDER BY a; +SELECT a, CAST(a AS DECIMAL(20,2)) FROM t1 ORDER BY a; +SELECT a, CAST(a AS SIGNED) FROM t1 ORDER BY a; +SELECT a, CAST(a AS UNSIGNED) FROM t1 ORDER BY a; +DROP TABLE t1; + +--echo # +--echo # End of 10.5 tests +--echo # diff --git a/mysql-test/main/type_varchar.result b/mysql-test/main/type_varchar.result index d00531018a4..6c6e95e3721 100644 --- a/mysql-test/main/type_varchar.result +++ b/mysql-test/main/type_varchar.result @@ -465,7 +465,7 @@ a (a + 0) t 0 Warnings: Warning 1292 Truncated incorrect DOUBLE value: '1a' -Warning 1292 Truncated incorrect DOUBLE value: 't ' +Warning 1292 Truncated incorrect DOUBLE value: 't' SELECT a,(a DIV 2) FROM t1 ORDER BY a; a (a DIV 2) 10 5 @@ -476,7 +476,7 @@ a (a DIV 2) t 0 Warnings: Warning 1292 Truncated incorrect DECIMAL value: '1a' -Warning 1292 Truncated incorrect DECIMAL value: 't ' +Warning 1292 Truncated incorrect DECIMAL value: 't' SELECT a,CAST(a AS SIGNED) FROM t1 ORDER BY a; a CAST(a AS SIGNED) 10 10 @@ -508,8 +508,8 @@ SELECT 5 = a FROM t1; 0 0 Warnings: -Warning 1292 Truncated incorrect DECIMAL value: 's ' -Warning 1292 Truncated incorrect DECIMAL value: ' ' +Warning 1292 Truncated incorrect DECIMAL value: 's' +Warning 1292 Truncated incorrect DECIMAL value: '' DROP TABLE t1; # # MDEV-13530 VARBINARY doesn't convert to to BLOB for sizes 65533, 65534 and 65535 diff --git a/mysql-test/main/xml.result b/mysql-test/main/xml.result index efaca961b4a..d0acb0debf3 100644 --- a/mysql-test/main/xml.result +++ b/mysql-test/main/xml.result @@ -991,20 +991,20 @@ CALL spxml('b1b2', '1 and string'); ExtractValue(xml,'/a/b[$i]') b1 Warnings: -Warning 1292 Truncated incorrect INTEGER value: '1 and string ' -Warning 1292 Truncated incorrect INTEGER value: '1 and string ' +Warning 1292 Truncated incorrect INTEGER value: '1 and string' +Warning 1292 Truncated incorrect INTEGER value: '1 and string' CALL spxml('b1b2', 'string and 1'); ExtractValue(xml,'/a/b[$i]') Warnings: -Warning 1292 Truncated incorrect INTEGER value: 'string and 1 ' -Warning 1292 Truncated incorrect INTEGER value: 'string and 1 ' +Warning 1292 Truncated incorrect INTEGER value: 'string and 1' +Warning 1292 Truncated incorrect INTEGER value: 'string and 1' CALL spxml('b1b2', 'string'); ExtractValue(xml,'/a/b[$i]') Warnings: -Warning 1292 Truncated incorrect INTEGER value: 'string ' -Warning 1292 Truncated incorrect INTEGER value: 'string ' +Warning 1292 Truncated incorrect INTEGER value: 'string' +Warning 1292 Truncated incorrect INTEGER value: 'string' DROP PROCEDURE spxml; select UpdateXML('a',repeat('a b ',1000),''); ERROR HY000: XPATH syntax error: 'b a b a b a b a b a b a b a b...' 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 e9fa172c321..90f2f3d3dc0 100644 --- a/mysql-test/suite/funcs_1/r/innodb_func_view.result +++ b/mysql-test/suite/funcs_1/r/innodb_func_view.result @@ -2202,9 +2202,9 @@ IS NOT TRUE <--------30 characters-------> 3 IS NOT TRUE ---äÖüß@µ*$-- 4 IS TRUE -1 5 Warnings: -Warning 1292 Truncated incorrect DOUBLE value: ' ' +Warning 1292 Truncated incorrect DOUBLE value: '' Warning 1292 Truncated incorrect DOUBLE value: '<--------30 characters------->' -Warning 1292 Truncated incorrect DOUBLE value: ' ---äÖüß@µ*$-- ' +Warning 1292 Truncated incorrect DOUBLE 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 if(`t1_values`.`my_char_30`,'IS TRUE','IS NOT TRUE') AS `IF(my_char_30, 'IS TRUE', 'IS NOT TRUE')`,`t1_values`.`my_char_30` AS `my_char_30`,`t1_values`.`id` AS `id` from `t1_values` latin1 latin1_swedish_ci @@ -2218,9 +2218,9 @@ IS NOT TRUE <--------30 characters-------> 3 IS NOT TRUE ---äÖüß@µ*$-- 4 IS TRUE -1 5 Warnings: -Warning 1292 Truncated incorrect DOUBLE value: ' ' +Warning 1292 Truncated incorrect DOUBLE value: '' Warning 1292 Truncated incorrect DOUBLE value: '<--------30 characters------->' -Warning 1292 Truncated incorrect DOUBLE value: ' ---äÖüß@µ*$-- ' +Warning 1292 Truncated incorrect DOUBLE value: ' ---äÖüß@µ*$--' DROP VIEW v1; @@ -3523,9 +3523,9 @@ NULL NULL 1 -1.00 -1 5 -3333.33 -3333.3333 26 Warnings: -Warning 1292 Truncated incorrect DECIMAL value: ' ' +Warning 1292 Truncated incorrect DECIMAL value: '' Warning 1292 Truncated incorrect DECIMAL value: '<--------30 characters------->' -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_char_30` as decimal(37,2)) AS `CAST(my_char_30 AS DECIMAL(37,2))`,`t1_values`.`my_char_30` AS `my_char_30`,`t1_values`.`id` AS `id` from `t1_values` latin1 latin1_swedish_ci @@ -3540,9 +3540,9 @@ NULL NULL 1 -1.00 -1 5 -3333.33 -3333.3333 26 Warnings: -Warning 1292 Truncated incorrect DECIMAL value: ' ' +Warning 1292 Truncated incorrect DECIMAL value: '' Warning 1292 Truncated incorrect DECIMAL value: '<--------30 characters------->' -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 744166bb849..74b6206959a 100644 --- a/mysql-test/suite/funcs_1/r/memory_func_view.result +++ b/mysql-test/suite/funcs_1/r/memory_func_view.result @@ -2203,9 +2203,9 @@ IS NOT TRUE <--------30 characters-------> 3 IS NOT TRUE ---äÖüß@µ*$-- 4 IS TRUE -1 5 Warnings: -Warning 1292 Truncated incorrect DOUBLE value: ' ' +Warning 1292 Truncated incorrect DOUBLE value: '' Warning 1292 Truncated incorrect DOUBLE value: '<--------30 characters------->' -Warning 1292 Truncated incorrect DOUBLE value: ' ---äÖüß@µ*$-- ' +Warning 1292 Truncated incorrect DOUBLE 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 if(`t1_values`.`my_char_30`,'IS TRUE','IS NOT TRUE') AS `IF(my_char_30, 'IS TRUE', 'IS NOT TRUE')`,`t1_values`.`my_char_30` AS `my_char_30`,`t1_values`.`id` AS `id` from `t1_values` latin1 latin1_swedish_ci @@ -2219,9 +2219,9 @@ IS NOT TRUE <--------30 characters-------> 3 IS NOT TRUE ---äÖüß@µ*$-- 4 IS TRUE -1 5 Warnings: -Warning 1292 Truncated incorrect DOUBLE value: ' ' +Warning 1292 Truncated incorrect DOUBLE value: '' Warning 1292 Truncated incorrect DOUBLE value: '<--------30 characters------->' -Warning 1292 Truncated incorrect DOUBLE value: ' ---äÖüß@µ*$-- ' +Warning 1292 Truncated incorrect DOUBLE value: ' ---äÖüß@µ*$--' DROP VIEW v1; @@ -3524,9 +3524,9 @@ NULL NULL 1 -1.00 -1 5 -3333.33 -3333.3333 26 Warnings: -Warning 1292 Truncated incorrect DECIMAL value: ' ' +Warning 1292 Truncated incorrect DECIMAL value: '' Warning 1292 Truncated incorrect DECIMAL value: '<--------30 characters------->' -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_char_30` as decimal(37,2)) AS `CAST(my_char_30 AS DECIMAL(37,2))`,`t1_values`.`my_char_30` AS `my_char_30`,`t1_values`.`id` AS `id` from `t1_values` latin1 latin1_swedish_ci @@ -3541,9 +3541,9 @@ NULL NULL 1 -1.00 -1 5 -3333.33 -3333.3333 26 Warnings: -Warning 1292 Truncated incorrect DECIMAL value: ' ' +Warning 1292 Truncated incorrect DECIMAL value: '' Warning 1292 Truncated incorrect DECIMAL value: '<--------30 characters------->' -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 744166bb849..74b6206959a 100644 --- a/mysql-test/suite/funcs_1/r/myisam_func_view.result +++ b/mysql-test/suite/funcs_1/r/myisam_func_view.result @@ -2203,9 +2203,9 @@ IS NOT TRUE <--------30 characters-------> 3 IS NOT TRUE ---äÖüß@µ*$-- 4 IS TRUE -1 5 Warnings: -Warning 1292 Truncated incorrect DOUBLE value: ' ' +Warning 1292 Truncated incorrect DOUBLE value: '' Warning 1292 Truncated incorrect DOUBLE value: '<--------30 characters------->' -Warning 1292 Truncated incorrect DOUBLE value: ' ---äÖüß@µ*$-- ' +Warning 1292 Truncated incorrect DOUBLE 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 if(`t1_values`.`my_char_30`,'IS TRUE','IS NOT TRUE') AS `IF(my_char_30, 'IS TRUE', 'IS NOT TRUE')`,`t1_values`.`my_char_30` AS `my_char_30`,`t1_values`.`id` AS `id` from `t1_values` latin1 latin1_swedish_ci @@ -2219,9 +2219,9 @@ IS NOT TRUE <--------30 characters-------> 3 IS NOT TRUE ---äÖüß@µ*$-- 4 IS TRUE -1 5 Warnings: -Warning 1292 Truncated incorrect DOUBLE value: ' ' +Warning 1292 Truncated incorrect DOUBLE value: '' Warning 1292 Truncated incorrect DOUBLE value: '<--------30 characters------->' -Warning 1292 Truncated incorrect DOUBLE value: ' ---äÖüß@µ*$-- ' +Warning 1292 Truncated incorrect DOUBLE value: ' ---äÖüß@µ*$--' DROP VIEW v1; @@ -3524,9 +3524,9 @@ NULL NULL 1 -1.00 -1 5 -3333.33 -3333.3333 26 Warnings: -Warning 1292 Truncated incorrect DECIMAL value: ' ' +Warning 1292 Truncated incorrect DECIMAL value: '' Warning 1292 Truncated incorrect DECIMAL value: '<--------30 characters------->' -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_char_30` as decimal(37,2)) AS `CAST(my_char_30 AS DECIMAL(37,2))`,`t1_values`.`my_char_30` AS `my_char_30`,`t1_values`.`id` AS `id` from `t1_values` latin1 latin1_swedish_ci @@ -3541,9 +3541,9 @@ NULL NULL 1 -1.00 -1 5 -3333.33 -3333.3333 26 Warnings: -Warning 1292 Truncated incorrect DECIMAL value: ' ' +Warning 1292 Truncated incorrect DECIMAL value: '' Warning 1292 Truncated incorrect DECIMAL value: '<--------30 characters------->' -Warning 1292 Truncated incorrect DECIMAL value: ' ---äÖüß@µ*$-- ' +Warning 1292 Truncated incorrect DECIMAL value: ' ---äÖüß@µ*$--' DROP VIEW v1; diff --git a/sql/field.cc b/sql/field.cc index f03135a63bc..a423fdd0fa3 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -7485,11 +7485,11 @@ double Field_string::val_real(void) { DBUG_ASSERT(marked_for_read()); THD *thd= get_thd(); - return Converter_strntod_with_warn(get_thd(), + const LEX_CSTRING str= to_lex_cstring(); + return Converter_strntod_with_warn(thd, Warn_filter_string(thd, this), Field_string::charset(), - (const char *) ptr, - field_length).result(); + str.str, str.length).result(); } @@ -7497,10 +7497,10 @@ longlong Field_string::val_int(void) { DBUG_ASSERT(marked_for_read()); THD *thd= get_thd(); + const LEX_CSTRING str= to_lex_cstring(); return Converter_strntoll_with_warn(thd, Warn_filter_string(thd, this), Field_string::charset(), - (const char *) ptr, - field_length).result(); + str.str, str.length).result(); } @@ -7516,20 +7516,26 @@ sql_mode_t Field_string::can_handle_sql_mode_dependency_on_store() const } -String *Field_string::val_str(String *val_buffer __attribute__((unused)), - String *val_ptr) +LEX_CSTRING Field_string::to_lex_cstring() const { DBUG_ASSERT(marked_for_read()); /* See the comment for Field_long::store(long long) */ DBUG_ASSERT(!table || table->in_use == current_thd); - size_t length; - if (get_thd()->variables.sql_mode & - MODE_PAD_CHAR_TO_FULL_LENGTH) - length= field_charset()->charpos(ptr, ptr + field_length, - Field_string::char_length()); - else - length= field_charset()->lengthsp((const char*) ptr, field_length); - val_ptr->set((const char*) ptr, length, field_charset()); + if (get_thd()->variables.sql_mode & MODE_PAD_CHAR_TO_FULL_LENGTH) + return Lex_cstring((const char*) ptr, + field_charset()->charpos(ptr, ptr + field_length, + Field_string::char_length())); + return Lex_cstring((const char *) ptr, + field_charset()->lengthsp((const char*) ptr, field_length)); +} + + +String *Field_string::val_str(String *val_buffer __attribute__((unused)), + String *val_ptr) +{ + DBUG_ASSERT(marked_for_read()); + const LEX_CSTRING str= to_lex_cstring(); + val_ptr->set(str.str, str.length, field_charset()); return val_ptr; } @@ -7538,12 +7544,12 @@ my_decimal *Field_string::val_decimal(my_decimal *decimal_value) { DBUG_ASSERT(marked_for_read()); THD *thd= get_thd(); + const LEX_CSTRING str= to_lex_cstring(); Converter_str2my_decimal_with_warn(thd, Warn_filter_string(thd, this), E_DEC_FATAL_ERROR & ~E_DEC_BAD_NUM, Field_string::charset(), - (const char *) ptr, - field_length, decimal_value); + str.str, str.length, decimal_value); return decimal_value; } diff --git a/sql/field.h b/sql/field.h index 3da30453e1b..2eafb471d4b 100644 --- a/sql/field.h +++ b/sql/field.h @@ -4013,6 +4013,7 @@ class Field_string final :public Field_longstr { field_length >= 4 && orig_table->s->frm_version < FRM_VER_TRUE_VARCHAR; } + LEX_CSTRING to_lex_cstring() const; public: bool can_alter_field_type; Field_string(uchar *ptr_arg, uint32 len_arg,uchar *null_ptr_arg,