Commit 7e03c67a authored by Alexey Botchkov's avatar Alexey Botchkov

MDEV-11474 JSON_DEPTH returns incorrect results.

        Item_func_json_depth::val_int fixed.
parent 78dc7c3a
...@@ -277,3 +277,9 @@ NULL ...@@ -277,3 +277,9 @@ NULL
select json_depth(cast(NULL as JSON)); select json_depth(cast(NULL as JSON));
json_depth(cast(NULL as JSON)) json_depth(cast(NULL as JSON))
NULL NULL
select json_depth('[[], {}]');
json_depth('[[], {}]')
2
select json_depth('[[[1,2,3],"s"], {}, []]');
json_depth('[[[1,2,3],"s"], {}, []]')
4
...@@ -123,4 +123,6 @@ select json_object("a", cast('{"b": "abcd"}' as json)); ...@@ -123,4 +123,6 @@ select json_object("a", cast('{"b": "abcd"}' as json));
select cast(NULL AS JSON); select cast(NULL AS JSON);
select json_depth(cast(NULL as JSON)); select json_depth(cast(NULL as JSON));
select json_depth('[[], {}]');
select json_depth('[[[1,2,3],"s"], {}, []]');
...@@ -1235,7 +1235,7 @@ longlong Item_func_json_depth::val_int() ...@@ -1235,7 +1235,7 @@ longlong Item_func_json_depth::val_int()
{ {
String *js= args[0]->val_str(&tmp_js); String *js= args[0]->val_str(&tmp_js);
json_engine_t je; json_engine_t je;
uint depth= 0; uint depth= 0, c_depth= 0;
bool inc_depth= TRUE; bool inc_depth= TRUE;
if ((null_value= args[0]->null_value)) if ((null_value= args[0]->null_value))
...@@ -1252,14 +1252,22 @@ longlong Item_func_json_depth::val_int() ...@@ -1252,14 +1252,22 @@ longlong Item_func_json_depth::val_int()
case JST_VALUE: case JST_VALUE:
if (inc_depth) if (inc_depth)
{ {
depth++; c_depth++;
inc_depth= FALSE; inc_depth= FALSE;
if (c_depth > depth)
depth= c_depth;
} }
break; break;
case JST_OBJ_START: case JST_OBJ_START:
case JST_ARRAY_START: case JST_ARRAY_START:
inc_depth= TRUE; inc_depth= TRUE;
break; break;
case JST_OBJ_END:
case JST_ARRAY_END:
if (!inc_depth)
c_depth--;
inc_depth= FALSE;
break;
default: default:
break; break;
} }
......
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