mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
MDEV-34295 CAST(char_col AS DOUBLE) prints redundant spaces in a warning
Field_string::val_int(), Field_string::val_real(), Field_string::val_decimal() passed the whole buffer of field_length bytes to data type conversion routines. This made conversion routines to print redundant trailing spaces in case of warnings. Adding a method Field_string::to_lex_cstring() and using it inside val_int(), val_real(), val_decimal(), val_str(). After this change conversion routines get the same value with what val_str() returns, and no redundant trailing spaces are displayed.
This commit is contained in:
@ -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
|
||||
|
40
mysql-test/main/type_char.result
Normal file
40
mysql-test/main/type_char.result
Normal file
@ -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
|
||||
#
|
19
mysql-test/main/type_char.test
Normal file
19
mysql-test/main/type_char.test
Normal file
@ -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 #
|
@ -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
|
||||
|
@ -991,20 +991,20 @@ CALL spxml('<a><b>b1</b><b>b2</b></a>', '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('<a><b>b1</b><b>b2</b></a>', '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('<a><b>b1</b><b>b2</b></a>', '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>a</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...'
|
||||
|
@ -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;
|
||||
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
||||
|
40
sql/field.cc
40
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;
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
|
Reference in New Issue
Block a user