Skip to content

Commit a933630

Browse files
author
Alexey Botchkov
committed
MDEV-17018 JSON_SEARCH and User-Defined Variables.
Item_func_json_search needs a member to store the path.
1 parent c312417 commit a933630

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

mysql-test/r/func_json.result

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,3 +796,11 @@ JSON_SET('{}', '$.a', _utf8 X'C3B6', '$.x', 1, '$.b', _utf8 X'C3B6')
796796
select json_array_append('[ ]', '$', 'aue');
797797
json_array_append('[ ]', '$', 'aue')
798798
["aue"]
799+
#
800+
# MDEV-17018 JSON_SEARCH and User-Defined Variables.
801+
#
802+
SET @`json` := '["A", [{"B": "1"}], {"C": "AB"}, {"D": "BC"}]', @`value` := 'AB';
803+
SELECT JSON_SEARCH(@`json`, 'one', @`value`);
804+
JSON_SEARCH(@`json`, 'one', @`value`)
805+
"$[2].C"
806+
SET @`json` := NULL, @`value` := NULL;

mysql-test/t/func_json.test

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,3 +455,11 @@ SELECT JSON_SET('{}', '$.a', _utf8 X'C3B6', '$.x', 1, '$.b', _utf8 X'C3B6');
455455

456456
select json_array_append('[ ]', '$', 'aue');
457457

458+
--echo #
459+
--echo # MDEV-17018 JSON_SEARCH and User-Defined Variables.
460+
--echo #
461+
462+
SET @`json` := '["A", [{"B": "1"}], {"C": "AB"}, {"D": "BC"}]', @`value` := 'AB';
463+
SELECT JSON_SEARCH(@`json`, 'one', @`value`);
464+
SET @`json` := NULL, @`value` := NULL;
465+

sql/item_jsonfunc.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3056,7 +3056,7 @@ static int append_json_path(String *str, const json_path_t *p)
30563056
String *Item_func_json_search::val_str(String *str)
30573057
{
30583058
String *js= args[0]->val_json(&tmp_js);
3059-
String *s_str= args[2]->val_str(&tmp_js);
3059+
String *s_str= args[2]->val_str(&tmp_path);
30603060
json_engine_t je;
30613061
json_path_t p, sav_path;
30623062
uint n_arg;

sql/item_jsonfunc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ class Item_func_json_keys: public Item_str_func
400400
class Item_func_json_search: public Item_json_str_multipath
401401
{
402402
protected:
403-
String tmp_js, esc_value;
403+
String tmp_js, tmp_path, esc_value;
404404
bool mode_one;
405405
bool ooa_constant, ooa_parsed;
406406
int escape;

0 commit comments

Comments
 (0)