From c8bb43a9385cdb7a27f0702742a8d1e08a85befd Mon Sep 17 00:00:00 2001 From: Alexey Botchkov Date: Tue, 11 Sep 2018 14:37:45 +0400 Subject: MDEV-17121 JSON_ARRAY_APPEND. Extra comma added to the result when an json array is empty. --- strings/json_lib.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'strings/json_lib.c') diff --git a/strings/json_lib.c b/strings/json_lib.c index f6b4f15732d..1c0ff4b5345 100644 --- a/strings/json_lib.c +++ b/strings/json_lib.c @@ -1197,6 +1197,31 @@ int json_skip_to_level(json_engine_t *j, int level) } +#define json_skip_level(json_engine) \ + json_skip_to_level((json_engine), (json_engine)->stack_p) + + +/* + works as json_skip_level() but also counts items on the current + level skipped. +*/ +int json_skip_level_and_count(json_engine_t *j, int *n_items_skipped) +{ + int level= j->stack_p; + + *n_items_skipped= 0; + while (json_scan_next(j) == 0) + { + if (j->stack_p < level) + return 0; + if (j->stack_p == level && j->state == JST_VALUE) + (*n_items_skipped)++; + } + + return 1; +} + + int json_skip_key(json_engine_t *j) { if (json_read_value(j)) -- cgit v1.2.1 From f54485eadbab7fa1c6a388408cf908daf488284c Mon Sep 17 00:00:00 2001 From: Alexey Botchkov Date: Thu, 13 Sep 2018 13:42:09 +0400 Subject: MDEV-17001 JSON_MERGE returns nullwhen merging empty array. Don't add the comma if nothing appended to the array. --- strings/json_lib.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'strings/json_lib.c') diff --git a/strings/json_lib.c b/strings/json_lib.c index 1c0ff4b5345..4f12cbb82b5 100644 --- a/strings/json_lib.c +++ b/strings/json_lib.c @@ -1197,10 +1197,6 @@ int json_skip_to_level(json_engine_t *j, int level) } -#define json_skip_level(json_engine) \ - json_skip_to_level((json_engine), (json_engine)->stack_p) - - /* works as json_skip_level() but also counts items on the current level skipped. -- cgit v1.2.1