1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

MDEV-17001 JSON_MERGE returns nullwhen merging empty array.

Don't add the comma if nothing appended to the array.
This commit is contained in:
Alexey Botchkov
2018-09-13 13:42:09 +04:00
parent 2b46dca5d7
commit f54485eadb
4 changed files with 24 additions and 20 deletions

View File

@ -2020,23 +2020,14 @@ continue_j2:
else
{
const uchar *end1, *beg1, *end2, *beg2;
int empty_array= 0;
int n_items1=1, n_items2= 1;
beg1= je1->value_begin;
/* Merge as a single array. */
if (je1->value_type == JSON_VALUE_ARRAY)
{
int cur_level= je1->stack_p;
empty_array= 1;
while (json_scan_next(je1) == 0)
{
if (je1->stack_p < cur_level)
break;
empty_array= 0;
}
if (je1->s.error)
if (json_skip_level_and_count(je1, &n_items1))
return 1;
end1= je1->s.c_str - je1->sav_c_len;
@ -2055,8 +2046,7 @@ continue_j2:
end1= je1->value_end;
}
if (str->append((const char*) beg1, end1 - beg1) ||
(!empty_array && str->append(", ", 2)))
if (str->append((const char*) beg1, end1 - beg1))
return 3;
if (json_value_scalar(je2))
@ -2067,15 +2057,22 @@ continue_j2:
else
{
if (je2->value_type == JSON_VALUE_OBJECT)
{
beg2= je2->value_begin;
if (json_skip_level(je2))
return 2;
}
else
{
beg2= je2->s.c_str;
if (json_skip_level(je2))
return 2;
if (json_skip_level_and_count(je2, &n_items2))
return 2;
}
end2= je2->s.c_str;
}
if (str->append((const char*) beg2, end2 - beg2))
if ((n_items1 && n_items2 && str->append(", ", 2)) ||
str->append((const char*) beg2, end2 - beg2))
return 3;
if (je2->value_type != JSON_VALUE_ARRAY &&