summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey Botchkov <holyfoot@askmonty.org>2019-03-12 01:09:55 +0400
committerAlexey Botchkov <holyfoot@askmonty.org>2019-03-12 01:09:55 +0400
commitacb4a872049e0ac23a1fdf7a1aaf12ed2bf858a2 (patch)
tree0cf4e5095972b076c71619bbdffd88a11502e635
parent28e713dc12881e7f50207d0c642523ca3e630114 (diff)
downloadmariadb-git-acb4a872049e0ac23a1fdf7a1aaf12ed2bf858a2.tar.gz
MDEV-18886 JSON_ARRAY() does not recognise JSON argument.
JSON_ARRAY and JSON_OBJECT functions with no arguments now get the connection charset. Item_func_convert_charset returns the correct is_json() flag.
-rw-r--r--mysql-test/r/func_json.result12
-rw-r--r--mysql-test/t/func_json.test7
-rw-r--r--sql/item_jsonfunc.cc5
-rw-r--r--sql/item_strfunc.h1
4 files changed, 23 insertions, 2 deletions
diff --git a/mysql-test/r/func_json.result b/mysql-test/r/func_json.result
index 74798b13e3a..e74d6292476 100644
--- a/mysql-test/r/func_json.result
+++ b/mysql-test/r/func_json.result
@@ -830,3 +830,15 @@ SET sql_mode=default;
select JSON_VALID( '{"a":1]' );
JSON_VALID( '{"a":1]' )
0
+#
+# MDEV-18886 JSON_ARRAY() does not recognise JSON argument.
+#
+SELECT JSON_ARRAY(_UTF8 'str', JSON_OBJECT(_LATIN1 'plugin', _LATIN1'unix_socket'));
+JSON_ARRAY(_UTF8 'str', JSON_OBJECT(_LATIN1 'plugin', _LATIN1'unix_socket'))
+["str", {"plugin": "unix_socket"}]
+SELECT CHARSET(JSON_ARRAY());
+CHARSET(JSON_ARRAY())
+latin1
+SELECT CHARSET(JSON_OBJECT());
+CHARSET(JSON_OBJECT())
+latin1
diff --git a/mysql-test/t/func_json.test b/mysql-test/t/func_json.test
index 43bd19801d5..ef3fdc685fe 100644
--- a/mysql-test/t/func_json.test
+++ b/mysql-test/t/func_json.test
@@ -487,3 +487,10 @@ SET sql_mode=default;
select JSON_VALID( '{"a":1]' );
+--echo #
+--echo # MDEV-18886 JSON_ARRAY() does not recognise JSON argument.
+--echo #
+SELECT JSON_ARRAY(_UTF8 'str', JSON_OBJECT(_LATIN1 'plugin', _LATIN1'unix_socket'));
+SELECT CHARSET(JSON_ARRAY());
+SELECT CHARSET(JSON_OBJECT());
+
diff --git a/sql/item_jsonfunc.cc b/sql/item_jsonfunc.cc
index 27bc97f4c5e..78eb58506ff 100644
--- a/sql/item_jsonfunc.cc
+++ b/sql/item_jsonfunc.cc
@@ -1488,9 +1488,10 @@ bool Item_func_json_array::fix_length_and_dec()
if (arg_count == 0)
{
- collation.set(&my_charset_utf8_general_ci,
+ THD* thd= current_thd;
+ collation.set(thd->variables.collation_connection,
DERIVATION_COERCIBLE, MY_REPERTOIRE_ASCII);
- tmp_val.set_charset(&my_charset_utf8_general_ci);
+ tmp_val.set_charset(thd->variables.collation_connection);
max_length= 2;
return FALSE;
}
diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h
index a908aba2d2f..b3baae99c15 100644
--- a/sql/item_strfunc.h
+++ b/sql/item_strfunc.h
@@ -1192,6 +1192,7 @@ public:
(cs->state & MY_CS_UNICODE));
}
}
+ bool is_json_type() { return args[0]->is_json_type(); }
String *val_str(String *);
longlong val_int()
{