Skip to content

Commit

Permalink
MDEV-26646 SFORMAT Does not allow @variable use
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vuvova committed Oct 12, 2021
1 parent 6a7c10d commit 57bf8c1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
13 changes: 13 additions & 0 deletions mysql-test/main/func_sformat.result
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ t1 CREATE TABLE `t1` (
`x` varchar(8) CHARACTER SET ucs2 DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
set names latin1;
#
# ps parameters
#
Expand All @@ -455,3 +456,15 @@ Warning 4183 SFORMAT error: invalid type specifier
select sformat('{}', cast(1.1 as float));
sformat('{}', cast(1.1 as float))
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
#
15 changes: 14 additions & 1 deletion mysql-test/main/func_sformat.test
Original file line number Diff line number Diff line change
Expand Up @@ -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;
show create table t1;
drop table t1;

set names latin1;

echo #;
echo # ps parameters;
Expand All @@ -213,3 +213,16 @@ echo # MDEV-26691 SFORMAT: Pass down FLOAT as FLOAT, without upcast to DOUBLE;
echo #;

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 #;
10 changes: 6 additions & 4 deletions sql/item_strfunc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1336,12 +1336,14 @@ bool Item_func_sformat::fix_length_and_dec()
if (c.collation->mbminlen > 1)
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++)
{
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);
return FALSE;
Expand Down

0 comments on commit 57bf8c1

Please sign in to comment.