From 2b01461629ea520c263eccc962a18b5a7ae7962f Mon Sep 17 00:00:00 2001 From: Alexey Botchkov Date: Mon, 5 Dec 2016 08:59:55 +0400 Subject: MDEV-11465 JSON_LENGTH returns incorrect length. Item_func_json_length::val_int fixed. --- mysql-test/r/func_json.result | 9 +++++++++ mysql-test/t/func_json.test | 3 +++ sql/item_jsonfunc.cc | 3 +-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/func_json.result b/mysql-test/r/func_json.result index cf9e67793ab..e69e1f138c3 100644 --- a/mysql-test/r/func_json.result +++ b/mysql-test/r/func_json.result @@ -292,3 +292,12 @@ json_depth('[[], {}]') select json_depth('[[[1,2,3],"s"], {}, []]'); json_depth('[[[1,2,3],"s"], {}, []]') 4 +select json_length(''); +json_length('') +NULL +select json_length('{}'); +json_length('{}') +0 +select json_length('[1, 2, {"a": 3}]'); +json_length('[1, 2, {"a": 3}]') +3 diff --git a/mysql-test/t/func_json.test b/mysql-test/t/func_json.test index 60dbfa720fe..2a3d1cc81d2 100644 --- a/mysql-test/t/func_json.test +++ b/mysql-test/t/func_json.test @@ -129,3 +129,6 @@ select json_depth(cast(NULL as JSON)); select json_depth('[[], {}]'); select json_depth('[[[1,2,3],"s"], {}, []]'); +select json_length(''); +select json_length('{}'); +select json_length('[1, 2, {"a": 3}]'); diff --git a/sql/item_jsonfunc.cc b/sql/item_jsonfunc.cc index 375426c672e..5361f0143d3 100644 --- a/sql/item_jsonfunc.cc +++ b/sql/item_jsonfunc.cc @@ -1271,8 +1271,7 @@ longlong Item_func_json_length::val_int() return 0; } - return length; - + return length - 1; } -- cgit v1.2.1