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
c8bb43a9
Commit
c8bb43a9
authored
Sep 11, 2018
by
Alexey Botchkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MDEV-17121 JSON_ARRAY_APPEND.
Extra comma added to the result when an json array is empty.
parent
4d9ec7cb
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
48 additions
and
2 deletions
+48
-2
include/json_lib.h
include/json_lib.h
+6
-0
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
+7
-0
sql/item_jsonfunc.cc
sql/item_jsonfunc.cc
+4
-2
strings/json_lib.c
strings/json_lib.c
+25
-0
No files found.
include/json_lib.h
View file @
c8bb43a9
...
...
@@ -319,6 +319,12 @@ int json_skip_to_level(json_engine_t *j, int level);
json_skip_to_level((json_engine), (json_engine)->stack_p)
/*
works as json_skip_level() but also counts items on the current
level skipped.
*/
int
json_skip_level_and_count
(
json_engine_t
*
j
,
int
*
n_items_skipped
);
#define json_skip_array_item json_skip_key
/*
...
...
mysql-test/r/func_json.result
View file @
c8bb43a9
...
...
@@ -790,3 +790,9 @@ JSON_SET('{}', '$.a', _utf8 0xC3B6, '$.b', _utf8 0xC3B6)
SELECT JSON_SET('{}', '$.a', _utf8 X'C3B6', '$.x', 1, '$.b', _utf8 X'C3B6');
JSON_SET('{}', '$.a', _utf8 X'C3B6', '$.x', 1, '$.b', _utf8 X'C3B6')
{"a": "", "x": 1, "b": ""}
#
# MDEV-17121 JSON_ARRAY_APPEND
#
select json_array_append('[ ]', '$', 'aue');
json_array_append('[ ]', '$', 'aue')
["aue"]
mysql-test/t/func_json.test
View file @
c8bb43a9
...
...
@@ -448,3 +448,10 @@ SELECT JSON_SET('{}', '$.a', _utf8 0xC3B6);
SELECT
JSON_SET
(
'{}'
,
'$.a'
,
_utf8
0xC3B6
,
'$.b'
,
_utf8
0xC3B6
);
SELECT
JSON_SET
(
'{}'
,
'$.a'
,
_utf8
X
'C3B6'
,
'$.x'
,
1
,
'$.b'
,
_utf8
X
'C3B6'
);
--
echo
#
--
echo
# MDEV-17121 JSON_ARRAY_APPEND
--
echo
#
select
json_array_append
(
'[ ]'
,
'$'
,
'aue'
);
sql/item_jsonfunc.cc
View file @
c8bb43a9
...
...
@@ -1621,13 +1621,15 @@ String *Item_func_json_array_append::val_str(String *str)
if
(
je
.
value_type
==
JSON_VALUE_ARRAY
)
{
if
(
json_skip_level
(
&
je
))
int
n_items
;
if
(
json_skip_level_and_count
(
&
je
,
&
n_items
))
goto
js_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
(
n_items
)
str
->
append
(
", "
,
2
);
if
(
append_json_value
(
str
,
args
[
n_arg
+
1
],
&
tmp_val
))
goto
return_null
;
/* Out of memory. */
...
...
strings/json_lib.c
View file @
c8bb43a9
...
...
@@ -1197,6 +1197,31 @@ 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.
*/
int
json_skip_level_and_count
(
json_engine_t
*
j
,
int
*
n_items_skipped
)
{
int
level
=
j
->
stack_p
;
*
n_items_skipped
=
0
;
while
(
json_scan_next
(
j
)
==
0
)
{
if
(
j
->
stack_p
<
level
)
return
0
;
if
(
j
->
stack_p
==
level
&&
j
->
state
==
JST_VALUE
)
(
*
n_items_skipped
)
++
;
}
return
1
;
}
int
json_skip_key
(
json_engine_t
*
j
)
{
if
(
json_read_value
(
j
))
...
...
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