Commit 57bf8c1f authored by Sergei Golubchik's avatar Sergei Golubchik

MDEV-26646 SFORMAT Does not allow @variable use

If charset aggregation decides to convert arguments to some specific
charset and some arguments are numbers, they'll be wrapped into a
Item_func_conv_charset(), that changes result_type() to STRING_RESULT.

Fix: don't convert numbers, sformat needs their numerical value only.
parent 6a7c10de
...@@ -437,6 +437,7 @@ t1 CREATE TABLE `t1` ( ...@@ -437,6 +437,7 @@ t1 CREATE TABLE `t1` (
`x` varchar(8) CHARACTER SET ucs2 DEFAULT NULL `x` varchar(8) CHARACTER SET ucs2 DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1; drop table t1;
set names latin1;
# #
# ps parameters # ps parameters
# #
...@@ -455,3 +456,15 @@ Warning 4183 SFORMAT error: invalid type specifier ...@@ -455,3 +456,15 @@ Warning 4183 SFORMAT error: invalid type specifier
select sformat('{}', cast(1.1 as float)); select sformat('{}', cast(1.1 as float));
sformat('{}', cast(1.1 as float)) sformat('{}', cast(1.1 as float))
1.1 1.1
#
# MDEV-26646 SFORMAT Does not allow @variable use
#
set names utf8;
set @a=3.14;
select sformat('{:f}', @a);
sformat('{:f}', @a)
3.140000
set names latin1;
#
# End of 10.7 tests
#
...@@ -199,7 +199,7 @@ select hex(sformat(_ucs2 x'003D007B007D003D', _ucs2 x'0442043504410442')); ...@@ -199,7 +199,7 @@ select hex(sformat(_ucs2 x'003D007B007D003D', _ucs2 x'0442043504410442'));
create table t1 as select sformat(_ucs2 x'003D007B007D003D', _ucs2 x'0442043504410442') as x; create table t1 as select sformat(_ucs2 x'003D007B007D003D', _ucs2 x'0442043504410442') as x;
show create table t1; show create table t1;
drop table t1; drop table t1;
set names latin1;
echo #; echo #;
echo # ps parameters; echo # ps parameters;
...@@ -213,3 +213,16 @@ echo # MDEV-26691 SFORMAT: Pass down FLOAT as FLOAT, without upcast to DOUBLE; ...@@ -213,3 +213,16 @@ echo # MDEV-26691 SFORMAT: Pass down FLOAT as FLOAT, without upcast to DOUBLE;
echo #; echo #;
select sformat('{}', cast(1.1 as float)); select sformat('{}', cast(1.1 as float));
echo #;
echo # MDEV-26646 SFORMAT Does not allow @variable use;
echo #;
set names utf8;
set @a=3.14;
select sformat('{:f}', @a);
set names latin1;
echo #;
echo # End of 10.7 tests;
echo #;
...@@ -1336,12 +1336,14 @@ bool Item_func_sformat::fix_length_and_dec() ...@@ -1336,12 +1336,14 @@ bool Item_func_sformat::fix_length_and_dec()
if (c.collation->mbminlen > 1) if (c.collation->mbminlen > 1)
c.collation= &my_charset_utf8mb4_bin; c.collation= &my_charset_utf8mb4_bin;
if (Type_std_attributes::agg_item_set_converter(c, func_name_cstring(), args,
arg_count, flags, 1))
return TRUE;
for (uint i=0 ; i < arg_count ; i++) for (uint i=0 ; i < arg_count ; i++)
{
char_length+= args[i]->max_char_length(); char_length+= args[i]->max_char_length();
if (args[i]->result_type() == STRING_RESULT &&
Type_std_attributes::agg_item_set_converter(c, func_name_cstring(),
args+i, 1, flags, 1))
return TRUE;
}
fix_char_length_ulonglong(char_length); fix_char_length_ulonglong(char_length);
return FALSE; return FALSE;
......
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