diff options
author | Alexey Botchkov <holyfoot@askmonty.org> | 2016-12-05 09:34:28 +0400 |
---|---|---|
committer | Alexey Botchkov <holyfoot@askmonty.org> | 2016-12-05 09:34:28 +0400 |
commit | 1da0865058cca5e92e39f5c876c220ebca1ffa66 (patch) | |
tree | 04c3530977ec756e2813719b015a84931e7a640f /sql/item_jsonfunc.cc | |
parent | 2b01461629ea520c263eccc962a18b5a7ae7962f (diff) | |
download | mariadb-git-1da0865058cca5e92e39f5c876c220ebca1ffa66.tar.gz |
MDEV-11467 JSON_EXTRACT returns incorrect results.
Item_func_json_extract::val_str fixed.
Diffstat (limited to 'sql/item_jsonfunc.cc')
-rw-r--r-- | sql/item_jsonfunc.cc | 74 |
1 files changed, 37 insertions, 37 deletions
diff --git a/sql/item_jsonfunc.cc b/sql/item_jsonfunc.cc index 5361f0143d3..cb1c174d08d 100644 --- a/sql/item_jsonfunc.cc +++ b/sql/item_jsonfunc.cc @@ -461,52 +461,52 @@ String *Item_func_json_extract::val_str(String *str) c_path->cur_step= c_path->p.steps; - if (json_find_path(&je, &c_path->p, &c_path->cur_step, array_counters)) + while (!json_find_path(&je, &c_path->p, &c_path->cur_step, array_counters)) { - /* Path wasn't found. */ - if (je.s.error) + if (json_read_value(&je)) goto error; - continue; - } - - if (json_read_value(&je)) - goto error; + value= je.value_begin; + if (json_value_scalar(&je)) + v_len= je.value_end - value; + else + { + if (json_skip_level(&je)) + goto error; + v_len= je.s.c_str - value; + } - value= je.value_begin; - if (json_value_scalar(&je)) - v_len= je.value_end - value; - else - { - if (json_skip_level(&je)) + if (json_scan_next(&je) && je.s.error) goto error; - v_len= je.s.c_str - value; - } - if (!multiple_values_found) - { - if (first_value == NULL) - { - /* - Just remember the first value as we don't know yet - if we need to create an array out of it or not. - */ - first_value= (const char *) value; - first_len= v_len; - continue; - } - else + if (!multiple_values_found) { - multiple_values_found= TRUE; /* We have to make an JSON array. */ - if (str->append("[", 1) || - str->append(first_value, first_len)) - goto error; /* Out of memory. */ - } + if (first_value == NULL) + { + /* + Just remember the first value as we don't know yet + if we need to create an array out of it or not. + */ + first_value= (const char *) value; + first_len= v_len; + continue; + } + else + { + multiple_values_found= TRUE; /* We have to make an JSON array. */ + if (str->append("[", 1) || + str->append(first_value, first_len)) + goto error; /* Out of memory. */ + } + } + if (str->append(", ", 2) || + str->append((const char *) value, v_len)) + goto error; /* Out of memory. */ } - if (str->append(", ", 2) || - str->append((const char *) value, v_len)) - goto error; /* Out of memory. */ + + if (je.s.error) + goto error; } if (first_value == NULL) |