MDEV-11452 JSON_CONTAINS accepts wrong number of arguments.

Create_func_json_contains::create_native fixed.
This commit is contained in:
Alexey Botchkov 2016-12-05 00:15:08 +04:00
commit 5454500562
3 changed files with 7 additions and 3 deletions

View file

@ -76,6 +76,8 @@ json_contains('"you"', '"you"')
select json_contains('"youth"', '"you"');
json_contains('"youth"', '"you"')
0
select json_contains('[1]', '[1]', '$', '$[0]');
ERROR 42000: Incorrect parameter count in the call to native function 'json_contains'
select json_contains_path('{"key1":1, "key2":[2,3]}', "oNE", "$.key2[1]");
json_contains_path('{"key1":1, "key2":[2,3]}', "oNE", "$.key2[1]")
1

View file

@ -30,6 +30,8 @@ SELECT JSON_ARRAY_INSERT('["a", {"b": [1, 2]}, [3, 4]]', '$[4]', 'x');
select json_contains('{"k1":123, "k2":345}', '123', '$.k1');
select json_contains('"you"', '"you"');
select json_contains('"youth"', '"you"');
--error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT
select json_contains('[1]', '[1]', '$', '$[0]');
select json_contains_path('{"key1":1, "key2":[2,3]}', "oNE", "$.key2[1]");
select json_contains_path('{"key1":1, "key2":[2,3]}', "oNE", "$.key2[10]");

View file

@ -5218,13 +5218,13 @@ Create_func_json_contains::create_native(THD *thd, LEX_STRING name,
if (item_list != NULL)
arg_count= item_list->elements;
if (arg_count < 2 /* json_doc, val, [path]...*/)
if (arg_count == 2 || arg_count == 3/* json_doc, val, [path] */)
{
my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
func= new (thd->mem_root) Item_func_json_contains(thd, *item_list);
}
else
{
func= new (thd->mem_root) Item_func_json_contains(thd, *item_list);
my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
}
return func;