From a93363022ccdb66846f2fc87b630ebdf4184b45d Mon Sep 17 00:00:00 2001 From: Alexey Botchkov Date: Wed, 12 Sep 2018 21:57:28 +0400 Subject: [PATCH] MDEV-17018 JSON_SEARCH and User-Defined Variables. Item_func_json_search needs a member to store the path. --- mysql-test/r/func_json.result | 8 ++++++++ mysql-test/t/func_json.test | 8 ++++++++ sql/item_jsonfunc.cc | 2 +- sql/item_jsonfunc.h | 2 +- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/func_json.result b/mysql-test/r/func_json.result index 9c7a10625e3..6ba4ed753ea 100644 --- a/mysql-test/r/func_json.result +++ b/mysql-test/r/func_json.result @@ -796,3 +796,11 @@ JSON_SET('{}', '$.a', _utf8 X'C3B6', '$.x', 1, '$.b', _utf8 X'C3B6') select json_array_append('[ ]', '$', 'aue'); json_array_append('[ ]', '$', 'aue') ["aue"] +# +# MDEV-17018 JSON_SEARCH and User-Defined Variables. +# +SET @`json` := '["A", [{"B": "1"}], {"C": "AB"}, {"D": "BC"}]', @`value` := 'AB'; +SELECT JSON_SEARCH(@`json`, 'one', @`value`); +JSON_SEARCH(@`json`, 'one', @`value`) +"$[2].C" +SET @`json` := NULL, @`value` := NULL; diff --git a/mysql-test/t/func_json.test b/mysql-test/t/func_json.test index e27128a3f4a..0790ea2ffba 100644 --- a/mysql-test/t/func_json.test +++ b/mysql-test/t/func_json.test @@ -455,3 +455,11 @@ SELECT JSON_SET('{}', '$.a', _utf8 X'C3B6', '$.x', 1, '$.b', _utf8 X'C3B6'); select json_array_append('[ ]', '$', 'aue'); +--echo # +--echo # MDEV-17018 JSON_SEARCH and User-Defined Variables. +--echo # + +SET @`json` := '["A", [{"B": "1"}], {"C": "AB"}, {"D": "BC"}]', @`value` := 'AB'; +SELECT JSON_SEARCH(@`json`, 'one', @`value`); +SET @`json` := NULL, @`value` := NULL; + diff --git a/sql/item_jsonfunc.cc b/sql/item_jsonfunc.cc index 1da53935441..4cb79749903 100644 --- a/sql/item_jsonfunc.cc +++ b/sql/item_jsonfunc.cc @@ -3056,7 +3056,7 @@ static int append_json_path(String *str, const json_path_t *p) String *Item_func_json_search::val_str(String *str) { String *js= args[0]->val_json(&tmp_js); - String *s_str= args[2]->val_str(&tmp_js); + String *s_str= args[2]->val_str(&tmp_path); json_engine_t je; json_path_t p, sav_path; uint n_arg; diff --git a/sql/item_jsonfunc.h b/sql/item_jsonfunc.h index f331ee3b582..f2358168080 100644 --- a/sql/item_jsonfunc.h +++ b/sql/item_jsonfunc.h @@ -400,7 +400,7 @@ public: class Item_func_json_search: public Item_json_str_multipath { protected: - String tmp_js, esc_value; + String tmp_js, tmp_path, esc_value; bool mode_one; bool ooa_constant, ooa_parsed; int escape;