Commit 5e12d492 authored by Alexander Barkov's avatar Alexander Barkov

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.
parent 581712b9
......@@ -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
......
#
# 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
#
--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...'
......
......@@ -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,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment