Commit 467acc21 authored by Alexey Botchkov's avatar Alexey Botchkov

MDEV-13324 JSON_SET returns NULL instead of object.

        Superfluous ',' was added to the JSON_SET result so it became
        invalid.
parent 49878be3
...@@ -680,3 +680,6 @@ JSON_OBJECT('foo', '`') ...@@ -680,3 +680,6 @@ JSON_OBJECT('foo', '`')
SELECT JSON_OBJECT("foo", "bar`bar"); SELECT JSON_OBJECT("foo", "bar`bar");
JSON_OBJECT("foo", "bar`bar") JSON_OBJECT("foo", "bar`bar")
{"foo": "bar`bar"} {"foo": "bar`bar"}
SELECT JSON_SET('{}', '$.age', 87);
JSON_SET('{}', '$.age', 87)
{"age": 87}
...@@ -328,3 +328,8 @@ select JSON_EXTRACT('{"foo": "bar" foobar foo invalid ', '$.foo'); ...@@ -328,3 +328,8 @@ select JSON_EXTRACT('{"foo": "bar" foobar foo invalid ', '$.foo');
SELECT JSON_OBJECT('foo', '`'); SELECT JSON_OBJECT('foo', '`');
SELECT JSON_OBJECT("foo", "bar`bar"); SELECT JSON_OBJECT("foo", "bar`bar");
#
# MDEV-13324 JSON_SET returns NULL instead of object.
#
SELECT JSON_SET('{}', '$.age', 87);
...@@ -2450,6 +2450,8 @@ String *Item_func_json_insert::val_str(String *str) ...@@ -2450,6 +2450,8 @@ String *Item_func_json_insert::val_str(String *str)
} }
else /*JSON_PATH_KEY*/ else /*JSON_PATH_KEY*/
{ {
uint n_key= 0;
if (je.value_type != JSON_VALUE_OBJECT) if (je.value_type != JSON_VALUE_OBJECT)
continue; continue;
...@@ -2461,6 +2463,7 @@ String *Item_func_json_insert::val_str(String *str) ...@@ -2461,6 +2463,7 @@ String *Item_func_json_insert::val_str(String *str)
json_string_set_str(&key_name, lp->key, lp->key_end); json_string_set_str(&key_name, lp->key, lp->key_end);
if (json_key_matches(&je, &key_name)) if (json_key_matches(&je, &key_name))
goto v_found; goto v_found;
n_key++;
if (json_skip_key(&je)) if (json_skip_key(&je))
goto js_error; goto js_error;
break; break;
...@@ -2478,7 +2481,8 @@ String *Item_func_json_insert::val_str(String *str) ...@@ -2478,7 +2481,8 @@ String *Item_func_json_insert::val_str(String *str)
v_to= (const char *) (je.s.c_str - je.sav_c_len); v_to= (const char *) (je.s.c_str - je.sav_c_len);
str->length(0); str->length(0);
if (append_simple(str, js->ptr(), v_to - js->ptr()) || if (append_simple(str, js->ptr(), v_to - js->ptr()) ||
str->append(", \"", 3) || (n_key > 0 && str->append(", ", 2)) ||
str->append("\"", 1) ||
append_simple(str, lp->key, lp->key_end - lp->key) || append_simple(str, lp->key, lp->key_end - lp->key) ||
str->append("\":", 2) || str->append("\":", 2) ||
append_json_value(str, args[n_arg+1], &tmp_val) || append_json_value(str, args[n_arg+1], &tmp_val) ||
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment