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
fe6d0a07
Commit
fe6d0a07
authored
Dec 05, 2016
by
Alexey Botchkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MDEV-11471 JSON_ARRAY_APPEND returns incorrect results.
Item_func_json_array_append::val_str fixed.
parent
abb80d25
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
93 additions
and
28 deletions
+93
-28
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
+89
-28
No files found.
mysql-test/r/func_json.result
View file @
fe6d0a07
...
...
@@ -55,6 +55,9 @@ json_array_append('["a", "b"]', '$', FALSE)
select json_array_append('{"k1":1, "k2":["a", "b"]}', '$.k2', 2);
json_array_append('{"k1":1, "k2":["a", "b"]}', '$.k2', 2)
{"k1":1, "k2":["a", "b", 2]}
select json_array_append('["a", ["b", "c"], "d"]', '$[0]', 2);
json_array_append('["a", ["b", "c"], "d"]', '$[0]', 2)
[["a", 2], ["b", "c"], "d"]
select json_array_insert('["a", {"b": [1, 2]}, [3, 4]]', '$[1]', 'x');
json_array_insert('["a", {"b": [1, 2]}, [3, 4]]', '$[1]', 'x')
["a", "x", {"b": [1, 2]}, [3, 4]]
...
...
mysql-test/t/func_json.test
View file @
fe6d0a07
...
...
@@ -21,6 +21,7 @@ select json_array(1, "text", false, null);
select
json_array_append
(
'["a", "b"]'
,
'$'
,
FALSE
);
select
json_array_append
(
'{"k1":1, "k2":["a", "b"]}'
,
'$.k2'
,
2
);
select
json_array_append
(
'["a", ["b", "c"], "d"]'
,
'$[0]'
,
2
);
select
json_array_insert
(
'["a", {"b": [1, 2]}, [3, 4]]'
,
'$[1]'
,
'x'
);
select
json_array_insert
(
'["a", {"b": [1, 2]}, [3, 4]]'
,
'$[2]'
,
'x'
);
...
...
sql/item_jsonfunc.cc
View file @
fe6d0a07
...
...
@@ -994,32 +994,69 @@ String *Item_func_json_array_append::val_str(String *str)
if
(
json_read_value
(
&
je
))
goto
error
;
if
(
je
.
value_type
!=
JSON_VALUE_ARRAY
)
{
/* Must be an array. */
goto
error
;
}
if
(
json_skip_level
(
&
je
))
goto
error
;
str
->
length
(
0
);
str
->
set_charset
(
js
->
charset
());
if
(
str
->
reserve
(
js
->
length
()
+
8
,
1024
))
goto
error
;
/* Out of memory. */
ar_end
=
je
.
s
.
c_str
-
je
.
sav_c_len
;
str_rest_len
=
js
->
length
()
-
(
ar_end
-
(
const
uchar
*
)
js
->
ptr
());
str
->
q_append
(
js
->
ptr
(),
ar_end
-
(
const
uchar
*
)
js
->
ptr
());
str
->
append
(
", "
,
2
);
if
(
append_json_value
(
str
,
args
[
n_arg
+
1
],
&
tmp_val
))
goto
error
;
/* Out of memory. */
if
(
str
->
reserve
(
str_rest_len
,
1024
))
goto
error
;
/* Out of memory. */
str
->
q_append
((
const
char
*
)
ar_end
,
str_rest_len
);
if
(
je
.
value_type
==
JSON_VALUE_ARRAY
)
{
if
(
json_skip_level
(
&
je
))
goto
error
;
ar_end
=
je
.
s
.
c_str
-
je
.
sav_c_len
;
str_rest_len
=
js
->
length
()
-
(
ar_end
-
(
const
uchar
*
)
js
->
ptr
());
str
->
q_append
(
js
->
ptr
(),
ar_end
-
(
const
uchar
*
)
js
->
ptr
());
str
->
append
(
", "
,
2
);
if
(
append_json_value
(
str
,
args
[
n_arg
+
1
],
&
tmp_val
))
goto
error
;
/* Out of memory. */
if
(
str
->
reserve
(
str_rest_len
,
1024
))
goto
error
;
/* Out of memory. */
str
->
q_append
((
const
char
*
)
ar_end
,
str_rest_len
);
}
else
{
const
uchar
*
c_from
,
*
c_to
;
/* Wrap as an array. */
str
->
q_append
(
js
->
ptr
(),
(
const
char
*
)
je
.
value_begin
-
js
->
ptr
());
c_from
=
je
.
value_begin
;
if
(
je
.
value_type
==
JSON_VALUE_OBJECT
)
{
if
(
json_skip_level
(
&
je
))
goto
error
;
c_to
=
je
.
s
.
c_str
;
}
else
c_to
=
je
.
value_end
;
if
(
str
->
append
(
"["
,
1
)
||
str
->
append
((
const
char
*
)
c_from
,
c_to
-
c_from
)
||
str
->
append
(
", "
,
2
)
||
append_json_value
(
str
,
args
[
n_arg
+
1
],
&
tmp_val
)
||
str
->
append
(
"]"
,
1
)
||
str
->
append
((
const
char
*
)
je
.
s
.
c_str
,
js
->
end
()
-
(
const
char
*
)
je
.
s
.
c_str
))
goto
error
;
}
{
/* Swap str and js. */
if
(
str
==
&
tmp_js
)
{
str
=
js
;
js
=
&
tmp_js
;
}
else
{
js
=
str
;
str
=
&
tmp_js
;
}
}
}
return
str
;
return
js
;
error:
null_value
=
1
;
...
...
@@ -1123,9 +1160,17 @@ String *Item_func_json_array_insert::val_str(String *str)
goto
error
;
/* Out of memory. */
{
String
*
tmp_str
=
str
;
str
=
&
tmp_js
;
js
=
tmp_str
;
/* Swap str and js. */
if
(
str
==
&
tmp_js
)
{
str
=
js
;
js
=
&
tmp_js
;
}
else
{
js
=
str
;
str
=
&
tmp_js
;
}
}
}
...
...
@@ -1539,9 +1584,17 @@ String *Item_func_json_insert::val_str(String *str)
goto
error
;
/* Out of memory. */
continue_point:
{
String
*
tmp
=
str
;
str
=
&
tmp_js
;
js
=
tmp
;
/* Swap str and js. */
if
(
str
==
&
tmp_js
)
{
str
=
js
;
js
=
&
tmp_js
;
}
else
{
js
=
str
;
str
=
&
tmp_js
;
}
}
}
...
...
@@ -1701,9 +1754,17 @@ String *Item_func_json_remove::val_str(String *str)
goto
error
;
/* Out of memory. */
{
String
*
tmp
=
str
;
str
=
&
tmp_js
;
js
=
tmp
;
/* Swap str and js. */
if
(
str
==
&
tmp_js
)
{
str
=
js
;
js
=
&
tmp_js
;
}
else
{
js
=
str
;
str
=
&
tmp_js
;
}
}
}
...
...
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