mirror of
https://github.com/MariaDB/server.git
synced 2025-08-01 03:47:19 +03:00
MDEV-11474 JSON_DEPTH returns incorrect results.
Item_func_json_depth::val_int fixed.
This commit is contained in:
@ -277,3 +277,9 @@ NULL
|
||||
select json_depth(cast(NULL as JSON));
|
||||
json_depth(cast(NULL as JSON))
|
||||
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));
|
||||
|
||||
select 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()
|
||||
{
|
||||
String *js= args[0]->val_str(&tmp_js);
|
||||
json_engine_t je;
|
||||
uint depth= 0;
|
||||
uint depth= 0, c_depth= 0;
|
||||
bool inc_depth= TRUE;
|
||||
|
||||
if ((null_value= args[0]->null_value))
|
||||
@ -1252,14 +1252,22 @@ longlong Item_func_json_depth::val_int()
|
||||
case JST_VALUE:
|
||||
if (inc_depth)
|
||||
{
|
||||
depth++;
|
||||
c_depth++;
|
||||
inc_depth= FALSE;
|
||||
if (c_depth > depth)
|
||||
depth= c_depth;
|
||||
}
|
||||
break;
|
||||
case JST_OBJ_START:
|
||||
case JST_ARRAY_START:
|
||||
inc_depth= TRUE;
|
||||
break;
|
||||
case JST_OBJ_END:
|
||||
case JST_ARRAY_END:
|
||||
if (!inc_depth)
|
||||
c_depth--;
|
||||
inc_depth= FALSE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
Reference in New Issue
Block a user