Skip to content

Commit 8bbf669

Browse files
committed
MDEV-24784 JSON_ARRAYAGG charset issue
set the proper charset for a temporary result
1 parent 9a545eb commit 8bbf669

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

mysql-test/main/func_json.result

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,5 +1646,16 @@ SELECT JSON_OBJECTAGG('\\', 1);
16461646
JSON_OBJECTAGG('\\', 1)
16471647
{"\\":1}
16481648
#
1649+
# MDEV-24784 JSON_ARRAYAGG charset issue
1650+
#
1651+
set names utf8;
1652+
select json_arrayagg('ä'), json_objectagg(1, 'ä');
1653+
json_arrayagg('ä') json_objectagg(1, 'ä')
1654+
["ä"] {"1":"ä"}
1655+
set names latin1;
1656+
select json_arrayagg('ä'), json_objectagg(1, 'ä');
1657+
json_arrayagg('ä') json_objectagg(1, 'ä')
1658+
["ä"] {"1":"ä"}
1659+
#
16491660
# End of 10.5 tests
16501661
#

mysql-test/main/func_json.test

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1109,6 +1109,15 @@ SELECT JSON_OBJECTAGG('\"', 1);
11091109
SELECT JSON_OBJECTAGG('\\', 1);
11101110

11111111
--echo #
1112-
--echo # End of 10.5 tests
1112+
--echo # MDEV-24784 JSON_ARRAYAGG charset issue
11131113
--echo #
1114+
--disable_service_connection
1115+
set names utf8;
1116+
select json_arrayagg('ä'), json_objectagg(1, 'ä');
1117+
set names latin1;
1118+
select json_arrayagg('ä'), json_objectagg(1, 'ä');
1119+
--enable_service_connection
11141120

1121+
--echo #
1122+
--echo # End of 10.5 tests
1123+
--echo #

sql/item_jsonfunc.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3907,6 +3907,13 @@ int Arg_comparator::compare_e_json_str_basic(Item *j, Item *s)
39073907
return MY_TEST(sortcmp(res1, res2, compare_collation()) == 0);
39083908
}
39093909

3910+
bool Item_func_json_arrayagg::fix_fields(THD *thd, Item **ref)
3911+
{
3912+
bool res= Item_func_group_concat::fix_fields(thd, ref);
3913+
m_tmp_json.set_charset(collation.collation);
3914+
return res;
3915+
}
3916+
39103917

39113918
String *Item_func_json_arrayagg::get_str_from_item(Item *i, String *tmp)
39123919
{

sql/item_jsonfunc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,7 @@ class Item_func_json_arrayagg : public Item_func_group_concat
570570
}
571571

572572
const char *func_name() const override { return "json_arrayagg("; }
573+
bool fix_fields(THD *thd, Item **ref) override;
573574
enum Sumfunctype sum_func() const override { return JSON_ARRAYAGG_FUNC; }
574575

575576
String* val_str(String *str) override;

0 commit comments

Comments
 (0)