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
95228dc8
Commit
95228dc8
authored
Dec 20, 2016
by
Alexey Botchkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MDEV-11570 JSON_MERGE returns incorrect result.
JSON merging fixed.
parent
83dbb2d4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
10 deletions
+36
-10
mysql-test/r/func_json.result
mysql-test/r/func_json.result
+3
-0
mysql-test/t/func_json.test
mysql-test/t/func_json.test
+1
-0
sql/item_jsonfunc.cc
sql/item_jsonfunc.cc
+32
-10
No files found.
mysql-test/r/func_json.result
View file @
95228dc8
...
...
@@ -315,6 +315,9 @@ Warning 4038 Syntax error in JSON text in argument 1 to function 'json_merge' at
select json_merge('{"a":"b"}','{"c":"d"}');
json_merge('{"a":"b"}','{"c":"d"}')
{"a":"b", "c":"d"}
SELECT JSON_MERGE('[1, 2]', '{"id": 47}');
JSON_MERGE('[1, 2]', '{"id": 47}')
[1, 2, {"id": 47}]
select json_type('{"k1":123, "k2":345}');
json_type('{"k1":123, "k2":345}')
OBJECT
...
...
mysql-test/t/func_json.test
View file @
95228dc8
...
...
@@ -123,6 +123,7 @@ select json_merge('{"1": 2}', '{"true": false}', '{"3": 4}');
select
json_merge
(
NULL
,
json_object
(
'foo'
,
1
));
select
json_merge
(
'a'
,
'b'
);
select
json_merge
(
'{"a":"b"}'
,
'{"c":"d"}'
);
SELECT
JSON_MERGE
(
'[1, 2]'
,
'{"id": 47}'
);
select
json_type
(
'{"k1":123, "k2":345}'
);
select
json_type
(
'[123, "k2", 345]'
);
...
...
sql/item_jsonfunc.cc
View file @
95228dc8
...
...
@@ -1522,12 +1522,10 @@ String *Item_func_json_merge::val_str(String *str)
goto
error_return
;
str
->
length
(
0
);
if
((
je1
.
value_type
==
JSON_VALUE_ARRAY
&&
je2
.
value_type
==
JSON_VALUE_ARRAY
)
||
(
je1
.
value_type
==
JSON_VALUE_OBJECT
&&
je2
.
value_type
==
JSON_VALUE_OBJECT
))
if
(
je1
.
value_type
==
JSON_VALUE_OBJECT
&&
je2
.
value_type
==
JSON_VALUE_OBJECT
)
{
/*
Merge the adjancent arrays or
objects. */
/*
Wrap as a single
objects. */
if
(
json_skip_level
(
&
je1
))
goto
error_return
;
if
(
str
->
append
(
js1
->
ptr
(),
...
...
@@ -1539,11 +1537,35 @@ String *Item_func_json_merge::val_str(String *str)
}
else
{
/* Wrap as an array. */
if
(
str
->
append
(
"["
,
1
)
||
str
->
append
(
js1
->
ptr
(),
js1
->
length
())
||
str
->
append
(
", "
,
2
)
||
str
->
append
(
js2
->
ptr
(),
js2
->
length
())
||
const
char
*
end1
,
*
beg2
;
/* Merge as a single array. */
if
(
je1
.
value_type
==
JSON_VALUE_ARRAY
)
{
if
(
json_skip_level
(
&
je1
))
goto
error_return
;
end1
=
(
const
char
*
)
(
je1
.
s
.
c_str
-
je1
.
sav_c_len
);
}
else
{
if
(
str
->
append
(
"["
,
1
))
goto
error_return
;
end1
=
js1
->
end
();
}
if
(
str
->
append
(
js1
->
ptr
(),
end1
-
js1
->
ptr
()),
str
->
append
(
", "
,
2
))
goto
error_return
;
if
(
je2
.
value_type
==
JSON_VALUE_ARRAY
)
beg2
=
(
const
char
*
)
je2
.
s
.
c_str
;
else
beg2
=
js2
->
ptr
();
if
(
str
->
append
(
beg2
,
js2
->
end
()
-
beg2
))
goto
error_return
;
if
(
je2
.
value_type
!=
JSON_VALUE_ARRAY
&&
str
->
append
(
"]"
,
1
))
goto
error_return
;
}
...
...
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