summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOleksandr Byelkin <sanja@mariadb.com>2017-11-13 16:30:02 +0100
committerOleksandr Byelkin <sanja@mariadb.com>2017-11-14 10:49:46 +0100
commit2913f615f050f356f7be178e5d91650b86b33e4e (patch)
tree216193d0dabedf52c35966d6bd60b9bea3c81995
parentc0e10f375ad619d825ef7c21232cf5946bdf5be7 (diff)
downloadmariadb-git-2913f615f050f356f7be178e5d91650b86b33e4e.tar.gz
MDEV-8949: COLUMN_CREATE unicode name breakage
Use utf-mb4 if it is possible.
-rw-r--r--include/ma_dyncol.h6
-rw-r--r--mysql-test/r/ctype_utf8mb4.result27
-rw-r--r--mysql-test/t/ctype_utf8mb4.test20
-rw-r--r--mysys/ma_dyncol.c3
-rw-r--r--sql/item_cmpfunc.cc6
-rw-r--r--sql/item_strfunc.cc17
-rw-r--r--sql/item_strfunc.h7
7 files changed, 70 insertions, 16 deletions
diff --git a/include/ma_dyncol.h b/include/ma_dyncol.h
index cb03ccb5382..300474e061e 100644
--- a/include/ma_dyncol.h
+++ b/include/ma_dyncol.h
@@ -63,6 +63,12 @@ typedef struct st_mysql_lex_string LEX_STRING;
/* NO and OK is the same used just to show semantics */
#define ER_DYNCOL_NO ER_DYNCOL_OK
+#ifdef HAVE_CHARSET_utf8mb4
+#define DYNCOL_UTF (&my_charset_utf8mb4_general_ci)
+#else
+#define DYNCOL_UTF (&my_charset_utf8_general_ci)
+#endif
+
enum enum_dyncol_func_result
{
ER_DYNCOL_OK= 0,
diff --git a/mysql-test/r/ctype_utf8mb4.result b/mysql-test/r/ctype_utf8mb4.result
index 50382b5d5ca..ff9c155e445 100644
--- a/mysql-test/r/ctype_utf8mb4.result
+++ b/mysql-test/r/ctype_utf8mb4.result
@@ -3379,5 +3379,32 @@ F09F988E78
78F09F988E78
DROP TABLE t1;
#
+# MDEV-8949: COLUMN_CREATE unicode name breakage
+#
+SET NAMES utf8mb4;
+SELECT COLUMN_JSON(COLUMN_CREATE(_utf8mb4 0xF09F988E, 1));
+COLUMN_JSON(COLUMN_CREATE(_utf8mb4 0xF09F988E, 1))
+{"😎":1}
+SELECT COLUMN_LIST(COLUMN_CREATE(_utf8mb4 0xF09F988E, 1));
+COLUMN_LIST(COLUMN_CREATE(_utf8mb4 0xF09F988E, 1))
+`😎`
+SELECT COLUMN_GET(COLUMN_CREATE(_utf8mb4 0xF09F988E, 1), _utf8mb4 0xF09F988E
+as int);
+COLUMN_GET(COLUMN_CREATE(_utf8mb4 0xF09F988E, 1), _utf8mb4 0xF09F988E
+as int)
+1
+CREATE TABLE t1 AS SELECT
+COLUMN_LIST(COLUMN_CREATE('a',1)),
+COLUMN_JSON(COLUMN_CREATE('b',1));
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `COLUMN_LIST(COLUMN_CREATE('a',1))` longtext CHARACTER SET utf8mb4,
+ `COLUMN_JSON(COLUMN_CREATE('b',1))` longtext CHARACTER SET utf8mb4
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+DROP TABLE t1;
+SET NAMES default;
+# End of 10.0 tests
+#
# End of tests
#
diff --git a/mysql-test/t/ctype_utf8mb4.test b/mysql-test/t/ctype_utf8mb4.test
index cf1c103137e..10786183ad0 100644
--- a/mysql-test/t/ctype_utf8mb4.test
+++ b/mysql-test/t/ctype_utf8mb4.test
@@ -1877,5 +1877,25 @@ SELECT HEX(a) FROM t1;
DROP TABLE t1;
--echo #
+--echo # MDEV-8949: COLUMN_CREATE unicode name breakage
+--echo #
+
+SET NAMES utf8mb4;
+SELECT COLUMN_JSON(COLUMN_CREATE(_utf8mb4 0xF09F988E, 1));
+SELECT COLUMN_LIST(COLUMN_CREATE(_utf8mb4 0xF09F988E, 1));
+SELECT COLUMN_GET(COLUMN_CREATE(_utf8mb4 0xF09F988E, 1), _utf8mb4 0xF09F988E
+as int);
+
+CREATE TABLE t1 AS SELECT
+ COLUMN_LIST(COLUMN_CREATE('a',1)),
+ COLUMN_JSON(COLUMN_CREATE('b',1));
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+SET NAMES default;
+
+--echo # End of 10.0 tests
+
+--echo #
--echo # End of tests
--echo #
diff --git a/mysys/ma_dyncol.c b/mysys/ma_dyncol.c
index d0d6254d11c..9f6df107316 100644
--- a/mysys/ma_dyncol.c
+++ b/mysys/ma_dyncol.c
@@ -4184,8 +4184,7 @@ mariadb_dyncol_json_internal(DYNAMIC_COLUMN *str, DYNAMIC_STRING *json,
}
else
{
- if ((rc= mariadb_dyncol_val_str(json, &val,
- &my_charset_utf8_general_ci, '"')) < 0)
+ if ((rc= mariadb_dyncol_val_str(json, &val, DYNCOL_UTF, '"')) < 0)
goto err;
}
}
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc
index b086b084f97..807ce828131 100644
--- a/sql/item_cmpfunc.cc
+++ b/sql/item_cmpfunc.cc
@@ -6642,7 +6642,7 @@ longlong Item_func_dyncol_exists::val_int()
null_value= 1;
return 1;
}
- if (my_charset_same(nm->charset(), &my_charset_utf8_general_ci))
+ if (my_charset_same(nm->charset(), DYNCOL_UTF))
{
buf.str= (char *) nm->ptr();
buf.length= nm->length();
@@ -6652,11 +6652,11 @@ longlong Item_func_dyncol_exists::val_int()
uint strlen;
uint dummy_errors;
buf.str= (char *)sql_alloc((strlen= nm->length() *
- my_charset_utf8_general_ci.mbmaxlen + 1));
+ DYNCOL_UTF->mbmaxlen + 1));
if (buf.str)
{
buf.length=
- copy_and_convert(buf.str, strlen, &my_charset_utf8_general_ci,
+ copy_and_convert(buf.str, strlen, DYNCOL_UTF,
nm->ptr(), nm->length(), nm->charset(),
&dummy_errors);
}
diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc
index c3043adac47..c1bca3e12eb 100644
--- a/sql/item_strfunc.cc
+++ b/sql/item_strfunc.cc
@@ -4444,7 +4444,7 @@ bool Item_func_dyncol_create::prepare_arguments(bool force_names_arg)
if (res)
{
// guaranty UTF-8 string for names
- if (my_charset_same(res->charset(), &my_charset_utf8_general_ci))
+ if (my_charset_same(res->charset(), DYNCOL_UTF))
{
keys_str[i].length= res->length();
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)
uint dummy_errors;
char *str=
(char *)sql_alloc((strlen= res->length() *
- my_charset_utf8_general_ci.mbmaxlen + 1));
+ DYNCOL_UTF->mbmaxlen + 1));
if (str)
{
keys_str[i].length=
- copy_and_convert(str, strlen, &my_charset_utf8_general_ci,
+ copy_and_convert(str, strlen, DYNCOL_UTF,
res->ptr(), res->length(), res->charset(),
&dummy_errors);
keys_str[i].str= str;
@@ -4680,9 +4680,10 @@ String *Item_func_dyncol_json::val_str(String *str)
size_t length, alloc_length;
dynstr_reassociate(&json, &ptr, &length, &alloc_length);
str->reassociate(ptr, (uint32) length, (uint32) alloc_length,
- &my_charset_utf8_general_ci);
+ DYNCOL_UTF);
null_value= FALSE;
}
+ str->set_charset(DYNCOL_UTF);
return str;
null:
@@ -4781,7 +4782,7 @@ bool Item_dyncol_get::get_dyn_value(DYNAMIC_COLUMN_VALUE *val, String *tmp)
return 1;
}
- if (my_charset_same(nm->charset(), &my_charset_utf8_general_ci))
+ if (my_charset_same(nm->charset(), DYNCOL_UTF))
{
buf.str= (char *) nm->ptr();
buf.length= nm->length();
@@ -4791,11 +4792,11 @@ bool Item_dyncol_get::get_dyn_value(DYNAMIC_COLUMN_VALUE *val, String *tmp)
uint strlen;
uint dummy_errors;
buf.str= (char *)sql_alloc((strlen= nm->length() *
- my_charset_utf8_general_ci.mbmaxlen + 1));
+ DYNCOL_UTF->mbmaxlen + 1));
if (buf.str)
{
buf.length=
- copy_and_convert(buf.str, strlen, &my_charset_utf8_general_ci,
+ copy_and_convert(buf.str, strlen, DYNCOL_UTF,
nm->ptr(), nm->length(), nm->charset(),
&dummy_errors);
}
@@ -5229,7 +5230,6 @@ String *Item_func_dyncol_list::val_str(String *str)
goto null;
str->length(0);
- str->set_charset(&my_charset_utf8_general_ci);
for (i= 0; i < count; i++)
{
append_identifier(current_thd, str, names[i].str, names[i].length);
@@ -5239,6 +5239,7 @@ String *Item_func_dyncol_list::val_str(String *str)
null_value= FALSE;
if (names)
my_free(names);
+ str->set_charset(DYNCOL_UTF);
return str;
null:
diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h
index 1b133d1d885..6520591145b 100644
--- a/sql/item_strfunc.h
+++ b/sql/item_strfunc.h
@@ -1177,14 +1177,14 @@ public:
class Item_func_dyncol_json: public Item_str_func
{
public:
- Item_func_dyncol_json(Item *str) :Item_str_func(str) {}
+ Item_func_dyncol_json(Item *str) :Item_str_func(str)
+ {collation.set(DYNCOL_UTF);}
const char *func_name() const{ return "column_json"; }
String *val_str(String *);
void fix_length_and_dec()
{
max_length= MAX_BLOB_WIDTH;
maybe_null= 1;
- collation.set(&my_charset_bin);
decimals= 0;
}
};
@@ -1218,7 +1218,8 @@ public:
class Item_func_dyncol_list: public Item_str_func
{
public:
- Item_func_dyncol_list(Item *str) :Item_str_func(str) {};
+ Item_func_dyncol_list(Item *str) :Item_str_func(str)
+ {collation.set(DYNCOL_UTF);};
void fix_length_and_dec() { maybe_null= 1; max_length= MAX_BLOB_WIDTH; };
const char *func_name() const{ return "column_list"; }
String *val_str(String *);