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
4bca34d8
Commit
4bca34d8
authored
Aug 08, 2017
by
Alexey Botchkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MDEV-12789 JSON_KEYS returns duplicate keys twice.
Check for duplicating keys added.
parent
01a4eb8f
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
4 deletions
+57
-4
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
+46
-4
No files found.
mysql-test/r/func_json.result
View file @
4bca34d8
...
...
@@ -356,6 +356,12 @@ json_keys('foo')
NULL
Warnings:
Warning 4038 Syntax error in JSON text in argument 1 to function 'json_keys' at position 1
select json_keys('{"a":{"c":1, "d":2}, "b":2, "c":1, "a":3, "b":1, "c":2}');
json_keys('{"a":{"c":1, "d":2}, "b":2, "c":1, "a":3, "b":1, "c":2}')
["a", "b", "c"]
select json_keys('{"c1": "value 1", "c1": "value 2"}');
json_keys('{"c1": "value 1", "c1": "value 2"}')
["c1"]
SET @j = '["abc", [{"k": "10"}, "def"], {"x":"abc"}, {"y":"bcd"}]';
select json_search(@j, 'one', 'abc');
json_search(@j, 'one', 'abc')
...
...
mysql-test/t/func_json.test
View file @
4bca34d8
...
...
@@ -138,6 +138,11 @@ select json_keys('{"a":{"c":1, "d":2}, "b":2}');
select
json_keys
(
'{"a":{"c":1, "d":2}, "b":2}'
,
"$.a"
);
select
json_keys
(
'{"a":{"c":1, "d":2}, "b":2}'
,
"$.b"
);
select
json_keys
(
'foo'
);
#
# mdev-12789 JSON_KEYS returns duplicate keys twice
#
select
json_keys
(
'{"a":{"c":1, "d":2}, "b":2, "c":1, "a":3, "b":1, "c":2}'
);
select
json_keys
(
'{"c1": "value 1", "c1": "value 2"}'
);
SET
@
j
=
'["abc", [{"k": "10"}, "def"], {"x":"abc"}, {"y":"bcd"}]'
;
select
json_search
(
@
j
,
'one'
,
'abc'
);
...
...
sql/item_jsonfunc.cc
View file @
4bca34d8
...
...
@@ -2779,6 +2779,41 @@ void Item_func_json_keys::fix_length_and_dec()
}
/*
That function is for Item_func_json_keys::val_str exclusively.
It utilizes the fact the resulting string is in specific format:
["key1", "key2"...]
*/
static
int
check_key_in_list
(
String
*
res
,
const
uchar
*
key
,
int
key_len
)
{
const
uchar
*
c
=
(
const
uchar
*
)
res
->
ptr
()
+
2
;
/* beginning '["' */
const
uchar
*
end
=
(
const
uchar
*
)
res
->
end
()
-
1
;
/* ending '"' */
while
(
c
<
end
)
{
int
n_char
;
for
(
n_char
=
0
;
c
[
n_char
]
!=
'"'
&&
n_char
<
key_len
;
n_char
++
)
{
if
(
c
[
n_char
]
!=
key
[
n_char
])
break
;
}
if
(
c
[
n_char
]
==
'"'
)
{
if
(
n_char
==
key_len
)
return
1
;
}
else
{
while
(
c
[
n_char
]
!=
'"'
)
n_char
++
;
}
c
+=
n_char
+
4
;
/* skip ', "' */
}
return
0
;
}
String
*
Item_func_json_keys
::
val_str
(
String
*
str
)
{
json_engine_t
je
;
...
...
@@ -2835,6 +2870,7 @@ String *Item_func_json_keys::val_str(String *str)
while
(
json_scan_next
(
&
je
)
==
0
&&
je
.
state
!=
JST_OBJ_END
)
{
const
uchar
*
key_start
,
*
key_end
;
int
key_len
;
switch
(
je
.
state
)
{
...
...
@@ -2844,13 +2880,19 @@ String *Item_func_json_keys::val_str(String *str)
{
key_end
=
je
.
s
.
c_str
;
}
while
(
json_read_keyname_chr
(
&
je
)
==
0
);
if
(
je
.
s
.
error
||
(
n_keys
>
0
&&
str
->
append
(
", "
,
2
))
||
if
(
je
.
s
.
error
)
goto
err_return
;
key_len
=
key_end
-
key_start
;
if
(
!
check_key_in_list
(
str
,
key_start
,
key_len
))
{
if
((
n_keys
>
0
&&
str
->
append
(
", "
,
2
))
||
str
->
append
(
"
\"
"
,
1
)
||
append_simple
(
str
,
key_start
,
key_
end
-
key_start
)
||
append_simple
(
str
,
key_start
,
key_
len
)
||
str
->
append
(
"
\"
"
,
1
))
goto
err_return
;
n_keys
++
;
}
break
;
case
JST_OBJ_START
:
case
JST_ARRAY_START
:
...
...
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