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
3bae5328
Commit
3bae5328
authored
Dec 06, 2016
by
Alexey Botchkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MDEV-11433 JSON_MERGE returns a non-NULL result with a NULL argument.
Item_func_json_merge fixed.
parent
486079d1
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
81 additions
and
15 deletions
+81
-15
mysql-test/r/func_json.result
mysql-test/r/func_json.result
+15
-0
mysql-test/t/func_json.test
mysql-test/t/func_json.test
+5
-0
sql/item_jsonfunc.cc
sql/item_jsonfunc.cc
+60
-14
sql/item_jsonfunc.h
sql/item_jsonfunc.h
+1
-1
No files found.
mysql-test/r/func_json.result
View file @
3bae5328
...
@@ -218,7 +218,22 @@ select json_merge('string');
...
@@ -218,7 +218,22 @@ select json_merge('string');
ERROR 42000: Incorrect parameter count in the call to native function 'json_merge'
ERROR 42000: Incorrect parameter count in the call to native function 'json_merge'
select json_merge('string', 123);
select json_merge('string', 123);
json_merge('string', 123)
json_merge('string', 123)
NULL
select json_merge('"string"', 123);
json_merge('"string"', 123)
["string", 123]
["string", 123]
select json_merge('[1, 2]', '[true, false]');
json_merge('[1, 2]', '[true, false]')
[1, 2, true, false]
select json_merge('{"1": 2}', '{"true": false}');
json_merge('{"1": 2}', '{"true": false}')
{"1": 2, "true": false}
select json_merge('{"1": 2}', '{"true": false}', '{"3": 4}');
json_merge('{"1": 2}', '{"true": false}', '{"3": 4}')
{"1": 2, "true": false, "3": 4}
select json_merge(NULL,json_object('foo', 1));
json_merge(NULL,json_object('foo', 1))
NULL
select json_type('{"k1":123, "k2":345}');
select json_type('{"k1":123, "k2":345}');
json_type('{"k1":123, "k2":345}')
json_type('{"k1":123, "k2":345}')
OBJECT
OBJECT
...
...
mysql-test/t/func_json.test
View file @
3bae5328
...
@@ -93,6 +93,11 @@ drop table t1;
...
@@ -93,6 +93,11 @@ drop table t1;
--
error
ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT
--
error
ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT
select
json_merge
(
'string'
);
select
json_merge
(
'string'
);
select
json_merge
(
'string'
,
123
);
select
json_merge
(
'string'
,
123
);
select
json_merge
(
'"string"'
,
123
);
select
json_merge
(
'[1, 2]'
,
'[true, false]'
);
select
json_merge
(
'{"1": 2}'
,
'{"true": false}'
);
select
json_merge
(
'{"1": 2}'
,
'{"true": false}'
,
'{"3": 4}'
);
select
json_merge
(
NULL
,
json_object
(
'foo'
,
1
));
select
json_type
(
'{"k1":123, "k2":345}'
);
select
json_type
(
'{"k1":123, "k2":345}'
);
select
json_type
(
'[123, "k2", 345]'
);
select
json_type
(
'[123, "k2", 345]'
);
...
...
sql/item_jsonfunc.cc
View file @
3bae5328
...
@@ -1219,28 +1219,74 @@ String *Item_func_json_object::val_str(String *str)
...
@@ -1219,28 +1219,74 @@ String *Item_func_json_object::val_str(String *str)
String
*
Item_func_json_merge
::
val_str
(
String
*
str
)
String
*
Item_func_json_merge
::
val_str
(
String
*
str
)
{
{
DBUG_ASSERT
(
fixed
==
1
);
DBUG_ASSERT
(
fixed
==
1
);
json_engine_t
je1
,
je2
;
String
*
js1
=
args
[
0
]
->
val_str
(
&
tmp_js1
);
uint
n_arg
;
uint
n_arg
;
str
->
length
(
0
);
if
(
args
[
0
]
->
null_value
)
goto
error_return
;
if
(
str
->
append
(
"["
,
1
)
||
((
arg_count
>
0
)
&&
append_json_value
(
str
,
args
[
0
],
&
tmp_val
)))
goto
err_return
;
for
(
n_arg
=
1
;
n_arg
<
arg_count
;
n_arg
++
)
for
(
n_arg
=
1
;
n_arg
<
arg_count
;
n_arg
++
)
{
{
if
(
str
->
append
(
", "
,
2
)
||
String
*
js2
=
args
[
n_arg
]
->
val_str
(
&
tmp_js2
);
append_json_value
(
str
,
args
[
n_arg
],
&
tmp_val
))
if
(
args
[
n_arg
]
->
null_value
)
goto
err_return
;
goto
error_return
;
}
if
(
str
->
append
(
"]"
,
1
))
json_scan_start
(
&
je1
,
js1
->
charset
(),(
const
uchar
*
)
js1
->
ptr
(),
goto
err_return
;
(
const
uchar
*
)
js1
->
ptr
()
+
js1
->
length
())
;
return
str
;
json_scan_start
(
&
je2
,
js2
->
charset
(),(
const
uchar
*
)
js2
->
ptr
(),
(
const
uchar
*
)
js2
->
ptr
()
+
js2
->
length
());
err_return:
if
(
json_read_value
(
&
je1
)
||
json_read_value
(
&
je2
))
/*TODO: Launch out of memory error. */
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
))
{
/* Merge the adjancent arrays or objects. */
if
(
json_skip_level
(
&
je1
))
goto
error_return
;
if
(
str
->
append
(
js1
->
ptr
(),
((
const
char
*
)
je1
.
s
.
c_str
-
js1
->
ptr
())
-
je1
.
sav_c_len
)
||
str
->
append
(
", "
,
2
)
||
str
->
append
((
const
char
*
)
je2
.
s
.
c_str
,
js2
->
length
()
-
((
const
char
*
)
je2
.
s
.
c_str
-
js2
->
ptr
())))
goto
error_return
;
}
else
{
/* Wrap as an array. */
if
(
str
->
append
(
"["
,
1
)
||
str
->
append
(
js1
->
ptr
(),
js1
->
length
())
||
str
->
append
(
", "
,
2
)
||
str
->
append
(
js2
->
ptr
(),
js2
->
length
())
||
str
->
append
(
"]"
,
1
))
goto
error_return
;
}
{
/* Swap str and js1. */
if
(
str
==
&
tmp_js1
)
{
str
=
js1
;
js1
=
&
tmp_js1
;
}
else
{
js1
=
str
;
str
=
&
tmp_js1
;
}
}
}
null_value
=
0
;
return
js1
;
error_return:
null_value
=
1
;
null_value
=
1
;
return
NULL
;
return
NULL
;
}
}
...
...
sql/item_jsonfunc.h
View file @
3bae5328
...
@@ -278,7 +278,7 @@ class Item_func_json_object: public Item_func_json_array
...
@@ -278,7 +278,7 @@ class Item_func_json_object: public Item_func_json_array
class
Item_func_json_merge
:
public
Item_func_json_array
class
Item_func_json_merge
:
public
Item_func_json_array
{
{
protected:
protected:
String
tmp_
val
;
String
tmp_
js1
,
tmp_js2
;
public:
public:
Item_func_json_merge
(
THD
*
thd
,
List
<
Item
>
&
list
)
:
Item_func_json_merge
(
THD
*
thd
,
List
<
Item
>
&
list
)
:
Item_func_json_array
(
thd
,
list
)
{}
Item_func_json_array
(
thd
,
list
)
{}
...
...
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