summaryrefslogtreecommitdiff
path: root/sql/item_jsonfunc.cc
diff options
context:
space:
mode:
authorAlexey Botchkov <holyfoot@askmonty.org>2017-01-26 16:35:05 +0400
committerAlexey Botchkov <holyfoot@askmonty.org>2017-01-26 16:35:05 +0400
commitd96ee168a1f87c090421fb593930515ae8db3d7f (patch)
tree7eb78889644c1bc4eb32ab4274a0840a1622cfd4 /sql/item_jsonfunc.cc
parent71495a1748784a887f42888a2a7b8cac5e088ff6 (diff)
downloadmariadb-git-d96ee168a1f87c090421fb593930515ae8db3d7f.tar.gz
MDEV-11557 port MySQL-5.7 JSON tests to MariaDB.
paths ending on [0]..[0] should be handled in conforming manner.
Diffstat (limited to 'sql/item_jsonfunc.cc')
-rw-r--r--sql/item_jsonfunc.cc24
1 files changed, 17 insertions, 7 deletions
diff --git a/sql/item_jsonfunc.cc b/sql/item_jsonfunc.cc
index fc146427bc1..4731bada6ab 100644
--- a/sql/item_jsonfunc.cc
+++ b/sql/item_jsonfunc.cc
@@ -1983,13 +1983,22 @@ String *Item_func_json_insert::val_str(String *str)
if (je.value_type != JSON_VALUE_ARRAY)
{
const uchar *v_from= je.value_begin;
- if (!mode_insert)
- continue;
+ int do_array_autowrap;
+
+ if (mode_insert)
+ do_array_autowrap= !mode_replace || lp->n_item;
+ else
+ {
+ if (lp->n_item)
+ continue;
+ do_array_autowrap= 0;
+ }
+
str->length(0);
/* Wrap the value as an array. */
if (append_simple(str, js->ptr(), (const char *) v_from - js->ptr()) ||
- str->append("[", 1))
+ (do_array_autowrap && str->append("[", 1)))
goto js_error; /* Out of memory. */
if (je.value_type == JSON_VALUE_OBJECT)
@@ -1998,10 +2007,11 @@ String *Item_func_json_insert::val_str(String *str)
goto js_error;
}
- if (append_simple(str, v_from, je.s.c_str - v_from) ||
- str->append(", ", 2) ||
+ if ((do_array_autowrap &&
+ (append_simple(str, v_from, je.s.c_str - v_from) ||
+ str->append(", ", 2))) ||
append_json_value(str, args[n_arg+1], &tmp_val) ||
- str->append("]", 1) ||
+ (do_array_autowrap && str->append("]", 1)) ||
append_simple(str, je.s.c_str, js->end()-(const char *) je.s.c_str))
goto js_error; /* Out of memory. */
@@ -2033,7 +2043,7 @@ String *Item_func_json_insert::val_str(String *str)
v_to= (const char *) (je.s.c_str - je.sav_c_len);
str->length(0);
if (append_simple(str, js->ptr(), v_to - js->ptr()) ||
- str->append(", ", 2) ||
+ (n_item > 0 && str->append(", ", 2)) ||
append_json_value(str, args[n_arg+1], &tmp_val) ||
append_simple(str, v_to, js->end() - v_to))
goto js_error; /* Out of memory. */