Skip to content

Commit 2913f61

Browse files
committed
MDEV-8949: COLUMN_CREATE unicode name breakage
Use utf-mb4 if it is possible.
1 parent c0e10f3 commit 2913f61

File tree

7 files changed

+70
-16
lines changed

7 files changed

+70
-16
lines changed

include/ma_dyncol.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ typedef struct st_mysql_lex_string LEX_STRING;
6363
/* NO and OK is the same used just to show semantics */
6464
#define ER_DYNCOL_NO ER_DYNCOL_OK
6565

66+
#ifdef HAVE_CHARSET_utf8mb4
67+
#define DYNCOL_UTF (&my_charset_utf8mb4_general_ci)
68+
#else
69+
#define DYNCOL_UTF (&my_charset_utf8_general_ci)
70+
#endif
71+
6672
enum enum_dyncol_func_result
6773
{
6874
ER_DYNCOL_OK= 0,

mysql-test/r/ctype_utf8mb4.result

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3379,5 +3379,32 @@ F09F988E78
33793379
78F09F988E78
33803380
DROP TABLE t1;
33813381
#
3382+
# MDEV-8949: COLUMN_CREATE unicode name breakage
3383+
#
3384+
SET NAMES utf8mb4;
3385+
SELECT COLUMN_JSON(COLUMN_CREATE(_utf8mb4 0xF09F988E, 1));
3386+
COLUMN_JSON(COLUMN_CREATE(_utf8mb4 0xF09F988E, 1))
3387+
{"😎":1}
3388+
SELECT COLUMN_LIST(COLUMN_CREATE(_utf8mb4 0xF09F988E, 1));
3389+
COLUMN_LIST(COLUMN_CREATE(_utf8mb4 0xF09F988E, 1))
3390+
`😎`
3391+
SELECT COLUMN_GET(COLUMN_CREATE(_utf8mb4 0xF09F988E, 1), _utf8mb4 0xF09F988E
3392+
as int);
3393+
COLUMN_GET(COLUMN_CREATE(_utf8mb4 0xF09F988E, 1), _utf8mb4 0xF09F988E
3394+
as int)
3395+
1
3396+
CREATE TABLE t1 AS SELECT
3397+
COLUMN_LIST(COLUMN_CREATE('a',1)),
3398+
COLUMN_JSON(COLUMN_CREATE('b',1));
3399+
SHOW CREATE TABLE t1;
3400+
Table Create Table
3401+
t1 CREATE TABLE `t1` (
3402+
`COLUMN_LIST(COLUMN_CREATE('a',1))` longtext CHARACTER SET utf8mb4,
3403+
`COLUMN_JSON(COLUMN_CREATE('b',1))` longtext CHARACTER SET utf8mb4
3404+
) ENGINE=MyISAM DEFAULT CHARSET=latin1
3405+
DROP TABLE t1;
3406+
SET NAMES default;
3407+
# End of 10.0 tests
3408+
#
33823409
# End of tests
33833410
#

mysql-test/t/ctype_utf8mb4.test

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1876,6 +1876,26 @@ LOAD DATA INFILE '../../std_data/loaddata/mdev-11343.txt' INTO TABLE t1 CHARACTE
18761876
SELECT HEX(a) FROM t1;
18771877
DROP TABLE t1;
18781878

1879+
--echo #
1880+
--echo # MDEV-8949: COLUMN_CREATE unicode name breakage
1881+
--echo #
1882+
1883+
SET NAMES utf8mb4;
1884+
SELECT COLUMN_JSON(COLUMN_CREATE(_utf8mb4 0xF09F988E, 1));
1885+
SELECT COLUMN_LIST(COLUMN_CREATE(_utf8mb4 0xF09F988E, 1));
1886+
SELECT COLUMN_GET(COLUMN_CREATE(_utf8mb4 0xF09F988E, 1), _utf8mb4 0xF09F988E
1887+
as int);
1888+
1889+
CREATE TABLE t1 AS SELECT
1890+
COLUMN_LIST(COLUMN_CREATE('a',1)),
1891+
COLUMN_JSON(COLUMN_CREATE('b',1));
1892+
SHOW CREATE TABLE t1;
1893+
DROP TABLE t1;
1894+
1895+
SET NAMES default;
1896+
1897+
--echo # End of 10.0 tests
1898+
18791899
--echo #
18801900
--echo # End of tests
18811901
--echo #

mysys/ma_dyncol.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4184,8 +4184,7 @@ mariadb_dyncol_json_internal(DYNAMIC_COLUMN *str, DYNAMIC_STRING *json,
41844184
}
41854185
else
41864186
{
4187-
if ((rc= mariadb_dyncol_val_str(json, &val,
4188-
&my_charset_utf8_general_ci, '"')) < 0)
4187+
if ((rc= mariadb_dyncol_val_str(json, &val, DYNCOL_UTF, '"')) < 0)
41894188
goto err;
41904189
}
41914190
}

sql/item_cmpfunc.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6642,7 +6642,7 @@ longlong Item_func_dyncol_exists::val_int()
66426642
null_value= 1;
66436643
return 1;
66446644
}
6645-
if (my_charset_same(nm->charset(), &my_charset_utf8_general_ci))
6645+
if (my_charset_same(nm->charset(), DYNCOL_UTF))
66466646
{
66476647
buf.str= (char *) nm->ptr();
66486648
buf.length= nm->length();
@@ -6652,11 +6652,11 @@ longlong Item_func_dyncol_exists::val_int()
66526652
uint strlen;
66536653
uint dummy_errors;
66546654
buf.str= (char *)sql_alloc((strlen= nm->length() *
6655-
my_charset_utf8_general_ci.mbmaxlen + 1));
6655+
DYNCOL_UTF->mbmaxlen + 1));
66566656
if (buf.str)
66576657
{
66586658
buf.length=
6659-
copy_and_convert(buf.str, strlen, &my_charset_utf8_general_ci,
6659+
copy_and_convert(buf.str, strlen, DYNCOL_UTF,
66606660
nm->ptr(), nm->length(), nm->charset(),
66616661
&dummy_errors);
66626662
}

sql/item_strfunc.cc

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4444,7 +4444,7 @@ bool Item_func_dyncol_create::prepare_arguments(bool force_names_arg)
44444444
if (res)
44454445
{
44464446
// guaranty UTF-8 string for names
4447-
if (my_charset_same(res->charset(), &my_charset_utf8_general_ci))
4447+
if (my_charset_same(res->charset(), DYNCOL_UTF))
44484448
{
44494449
keys_str[i].length= res->length();
44504450
keys_str[i].str= sql_strmake(res->ptr(), res->length());
@@ -4455,11 +4455,11 @@ bool Item_func_dyncol_create::prepare_arguments(bool force_names_arg)
44554455
uint dummy_errors;
44564456
char *str=
44574457
(char *)sql_alloc((strlen= res->length() *
4458-
my_charset_utf8_general_ci.mbmaxlen + 1));
4458+
DYNCOL_UTF->mbmaxlen + 1));
44594459
if (str)
44604460
{
44614461
keys_str[i].length=
4462-
copy_and_convert(str, strlen, &my_charset_utf8_general_ci,
4462+
copy_and_convert(str, strlen, DYNCOL_UTF,
44634463
res->ptr(), res->length(), res->charset(),
44644464
&dummy_errors);
44654465
keys_str[i].str= str;
@@ -4680,9 +4680,10 @@ String *Item_func_dyncol_json::val_str(String *str)
46804680
size_t length, alloc_length;
46814681
dynstr_reassociate(&json, &ptr, &length, &alloc_length);
46824682
str->reassociate(ptr, (uint32) length, (uint32) alloc_length,
4683-
&my_charset_utf8_general_ci);
4683+
DYNCOL_UTF);
46844684
null_value= FALSE;
46854685
}
4686+
str->set_charset(DYNCOL_UTF);
46864687
return str;
46874688

46884689
null:
@@ -4781,7 +4782,7 @@ bool Item_dyncol_get::get_dyn_value(DYNAMIC_COLUMN_VALUE *val, String *tmp)
47814782
return 1;
47824783
}
47834784

4784-
if (my_charset_same(nm->charset(), &my_charset_utf8_general_ci))
4785+
if (my_charset_same(nm->charset(), DYNCOL_UTF))
47854786
{
47864787
buf.str= (char *) nm->ptr();
47874788
buf.length= nm->length();
@@ -4791,11 +4792,11 @@ bool Item_dyncol_get::get_dyn_value(DYNAMIC_COLUMN_VALUE *val, String *tmp)
47914792
uint strlen;
47924793
uint dummy_errors;
47934794
buf.str= (char *)sql_alloc((strlen= nm->length() *
4794-
my_charset_utf8_general_ci.mbmaxlen + 1));
4795+
DYNCOL_UTF->mbmaxlen + 1));
47954796
if (buf.str)
47964797
{
47974798
buf.length=
4798-
copy_and_convert(buf.str, strlen, &my_charset_utf8_general_ci,
4799+
copy_and_convert(buf.str, strlen, DYNCOL_UTF,
47994800
nm->ptr(), nm->length(), nm->charset(),
48004801
&dummy_errors);
48014802
}
@@ -5229,7 +5230,6 @@ String *Item_func_dyncol_list::val_str(String *str)
52295230
goto null;
52305231

52315232
str->length(0);
5232-
str->set_charset(&my_charset_utf8_general_ci);
52335233
for (i= 0; i < count; i++)
52345234
{
52355235
append_identifier(current_thd, str, names[i].str, names[i].length);
@@ -5239,6 +5239,7 @@ String *Item_func_dyncol_list::val_str(String *str)
52395239
null_value= FALSE;
52405240
if (names)
52415241
my_free(names);
5242+
str->set_charset(DYNCOL_UTF);
52425243
return str;
52435244

52445245
null:

sql/item_strfunc.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,14 +1177,14 @@ class Item_func_dyncol_add: public Item_func_dyncol_create
11771177
class Item_func_dyncol_json: public Item_str_func
11781178
{
11791179
public:
1180-
Item_func_dyncol_json(Item *str) :Item_str_func(str) {}
1180+
Item_func_dyncol_json(Item *str) :Item_str_func(str)
1181+
{collation.set(DYNCOL_UTF);}
11811182
const char *func_name() const{ return "column_json"; }
11821183
String *val_str(String *);
11831184
void fix_length_and_dec()
11841185
{
11851186
max_length= MAX_BLOB_WIDTH;
11861187
maybe_null= 1;
1187-
collation.set(&my_charset_bin);
11881188
decimals= 0;
11891189
}
11901190
};
@@ -1218,7 +1218,8 @@ class Item_dyncol_get: public Item_str_func
12181218
class Item_func_dyncol_list: public Item_str_func
12191219
{
12201220
public:
1221-
Item_func_dyncol_list(Item *str) :Item_str_func(str) {};
1221+
Item_func_dyncol_list(Item *str) :Item_str_func(str)
1222+
{collation.set(DYNCOL_UTF);};
12221223
void fix_length_and_dec() { maybe_null= 1; max_length= MAX_BLOB_WIDTH; };
12231224
const char *func_name() const{ return "column_list"; }
12241225
String *val_str(String *);

0 commit comments

Comments
 (0)