diff options
author | Sergei Golubchik <serg@mariadb.org> | 2021-10-09 16:00:13 +0200 |
---|---|---|
committer | Sergei Golubchik <serg@mariadb.org> | 2021-10-12 11:24:51 +0200 |
commit | 5ac8cdc183282883eebaf6cb1ebe039aee0557ea (patch) | |
tree | 0f57091cc9f8a0170526ada210d99a1c075ff99f | |
parent | 752122701bbed0488e0830df6061b2a2b058386b (diff) | |
download | mariadb-git-preview-10.7-MDEV-25015-sformat.tar.gz |
MDEV-26646 SFORMAT Does not allow @variable usepreview-10.7-MDEV-25015-sformat
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.
-rw-r--r-- | mysql-test/main/func_sformat.result | 13 | ||||
-rw-r--r-- | mysql-test/main/func_sformat.test | 15 | ||||
-rw-r--r-- | sql/item_strfunc.cc | 10 |
3 files changed, 33 insertions, 5 deletions
diff --git a/mysql-test/main/func_sformat.result b/mysql-test/main/func_sformat.result index d6b30ac6f36..b3a494d48a7 100644 --- a/mysql-test/main/func_sformat.result +++ b/mysql-test/main/func_sformat.result @@ -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 # @@ -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 +# diff --git a/mysql-test/main/func_sformat.test b/mysql-test/main/func_sformat.test index 36b755acae5..7c850fc2644 100644 --- a/mysql-test/main/func_sformat.test +++ b/mysql-test/main/func_sformat.test @@ -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; @@ -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 #; diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index a9decdbdf04..1a210f79ce5 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -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; |