Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
f54485ea
Commit
f54485ea
authored
Sep 13, 2018
by
Alexey Botchkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MDEV-17001 JSON_MERGE returns nullwhen merging empty array.
Don't add the comma if nothing appended to the array.
parent
2b46dca5
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
20 deletions
+24
-20
mysql-test/r/func_json.result
mysql-test/r/func_json.result
+6
-0
mysql-test/t/func_json.test
mysql-test/t/func_json.test
+5
-0
sql/item_jsonfunc.cc
sql/item_jsonfunc.cc
+13
-16
strings/json_lib.c
strings/json_lib.c
+0
-4
No files found.
mysql-test/r/func_json.result
View file @
f54485ea
...
...
@@ -804,3 +804,9 @@ SELECT JSON_SEARCH(@`json`, 'one', @`value`);
JSON_SEARCH(@`json`, 'one', @`value`)
"$[2].C"
SET @`json` := NULL, @`value` := NULL;
#
# MDEV-17001 JSON_MERGE returns nullwhen merging empty array.
#
SELECT JSON_MERGE('[1]', '[]');
JSON_MERGE('[1]', '[]')
[1]
mysql-test/t/func_json.test
View file @
f54485ea
...
...
@@ -463,3 +463,8 @@ SET @`json` := '["A", [{"B": "1"}], {"C": "AB"}, {"D": "BC"}]', @`value` := 'AB'
SELECT
JSON_SEARCH
(
@
`json`
,
'one'
,
@
`value`
);
SET
@
`json`
:=
NULL
,
@
`value`
:=
NULL
;
--
echo
#
--
echo
# MDEV-17001 JSON_MERGE returns nullwhen merging empty array.
--
echo
#
SELECT
JSON_MERGE
(
'[1]'
,
'[]'
);
sql/item_jsonfunc.cc
View file @
f54485ea
...
...
@@ -2020,23 +2020,14 @@ static int do_merge(String *str, json_engine_t *je1, json_engine_t *je2)
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 @@ static int do_merge(String *str, json_engine_t *je1, json_engine_t *je2)
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 @@ static int do_merge(String *str, json_engine_t *je1, json_engine_t *je2)
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
&&
...
...
strings/json_lib.c
View file @
f54485ea
...
...
@@ -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.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment