Skip to content

Commit 8150f52

Browse files
committed
support charsets with mbminlen > 1
1 parent fe65ca0 commit 8150f52

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

mysql-test/main/func_sformat.result

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,3 +417,23 @@ sformat('{:p}', '50')
417417
NULL
418418
Warnings:
419419
Warning 4183 SFORMAT error: invalid type specifier
420+
#
421+
# ucs2 test
422+
#
423+
select sformat('={}=', _ucs2 x'006100620063');
424+
sformat('={}=', _ucs2 x'006100620063')
425+
=abc=
426+
set names utf8;
427+
select sformat(_ucs2 x'003D007B007D003D', _ucs2 x'0442043504410442');
428+
sformat(_ucs2 x'003D007B007D003D', _ucs2 x'0442043504410442')
429+
=тест=
430+
select hex(sformat(_ucs2 x'003D007B007D003D', _ucs2 x'0442043504410442'));
431+
hex(sformat(_ucs2 x'003D007B007D003D', _ucs2 x'0442043504410442'))
432+
003D0442043504410442003D
433+
create table t1 as select sformat(_ucs2 x'003D007B007D003D', _ucs2 x'0442043504410442') as x;
434+
show create table t1;
435+
Table Create Table
436+
t1 CREATE TABLE `t1` (
437+
`x` varchar(8) CHARACTER SET ucs2 DEFAULT NULL
438+
) ENGINE=MyISAM DEFAULT CHARSET=latin1
439+
drop table t1;

mysql-test/main/func_sformat.test

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,14 @@ echo #;
188188
echo # Unsupported/disabled features;
189189
echo #;
190190
select sformat('{:p}', '50');
191+
192+
echo #;
193+
echo # ucs2 test;
194+
echo #;
195+
select sformat('={}=', _ucs2 x'006100620063');
196+
set names utf8;
197+
select sformat(_ucs2 x'003D007B007D003D', _ucs2 x'0442043504410442');
198+
select hex(sformat(_ucs2 x'003D007B007D003D', _ucs2 x'0442043504410442'));
199+
create table t1 as select sformat(_ucs2 x'003D007B007D003D', _ucs2 x'0442043504410442') as x;
200+
show create table t1;
201+
drop table t1;

sql/item_strfunc.cc

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,7 +1311,20 @@ bool Item_func_sformat::fix_length_and_dec()
13111311
{
13121312
ulonglong char_length= 0;
13131313

1314-
if (agg_arg_charsets_for_string_result(collation, args, arg_count))
1314+
uint flags= MY_COLL_ALLOW_SUPERSET_CONV |
1315+
MY_COLL_ALLOW_COERCIBLE_CONV |
1316+
MY_COLL_ALLOW_NUMERIC_CONV;
1317+
1318+
if (Type_std_attributes::agg_item_collations(collation, func_name_cstring(),
1319+
args, arg_count, flags, 1))
1320+
return TRUE;
1321+
1322+
DTCollation c= collation;
1323+
if (c.collation->mbminlen > 1)
1324+
c.collation= &my_charset_utf8mb4_bin;
1325+
1326+
if (Type_std_attributes::agg_item_set_converter(c, func_name_cstring(), args,
1327+
arg_count, flags, 1))
13151328
return TRUE;
13161329

13171330
for (uint i=0 ; i < arg_count ; i++)
@@ -1406,7 +1419,7 @@ String *Item_func_sformat::val_str(String *res)
14061419
fmt::format_args(vargs, arg_count-1));
14071420
res->length(0);
14081421
res->set_charset(collation.collation);
1409-
res->append(text.c_str(), text.size());
1422+
res->append(text.c_str(), text.size(), fmt_arg->charset());
14101423
}
14111424
catch (const fmt::format_error &ex)
14121425
{

0 commit comments

Comments
 (0)