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
3a177279
Commit
3a177279
authored
Dec 24, 2016
by
Alexey Botchkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MDEV-11573 JSON_LENGTH returns incorrect results.
Item_func_json_length fixed.
parent
4d10273b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
77 additions
and
11 deletions
+77
-11
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
+2
-0
sql/item_jsonfunc.cc
sql/item_jsonfunc.cc
+61
-5
sql/item_jsonfunc.h
sql/item_jsonfunc.h
+8
-6
No files found.
mysql-test/r/func_json.result
View file @
3a177279
...
...
@@ -425,6 +425,12 @@ json_length('{}')
select json_length('[1, 2, {"a": 3}]');
json_length('[1, 2, {"a": 3}]')
3
select json_length('{"a": 1, "b": {"c": 30}}', '$.b');
json_length('{"a": 1, "b": {"c": 30}}', '$.b')
1
select json_length('{"a": 1, "b": {"c": 30}}');
json_length('{"a": 1, "b": {"c": 30}}')
2
create table json (j INT);
show create table json;
Table Create Table
...
...
mysql-test/t/func_json.test
View file @
3a177279
...
...
@@ -170,6 +170,8 @@ select json_depth('[10, {"a": 20}]');
select
json_length
(
''
);
select
json_length
(
'{}'
);
select
json_length
(
'[1, 2, {"a": 3}]'
);
select
json_length
(
'{"a": 1, "b": {"c": 30}}'
,
'$.b'
);
select
json_length
(
'{"a": 1, "b": {"c": 30}}'
);
create
table
json
(
j
INT
);
show
create
table
json
;
...
...
sql/item_jsonfunc.cc
View file @
3a177279
...
...
@@ -1599,29 +1599,85 @@ String *Item_func_json_merge::val_str(String *str)
}
void
Item_func_json_length
::
fix_length_and_dec
()
{
if
(
arg_count
>
1
)
path
.
set_constant_flag
(
args
[
1
]
->
const_item
());
}
longlong
Item_func_json_length
::
val_int
()
{
String
*
js
=
args
[
0
]
->
val_str
(
&
tmp_js
);
json_engine_t
je
;
uint
length
=
0
;
uint
array_counters
[
JSON_DEPTH_LIMIT
];
if
((
null_value
=
args
[
0
]
->
null_value
))
return
0
;
json_scan_start
(
&
je
,
js
->
charset
(),(
const
uchar
*
)
js
->
ptr
(),
(
const
uchar
*
)
js
->
ptr
()
+
js
->
length
());
do
if
(
arg_count
>
1
)
{
if
(
je
.
state
==
JST_VALUE
)
/* Path specified - let's apply it. */
if
(
!
path
.
parsed
)
{
String
*
s_p
=
args
[
1
]
->
val_str
(
&
tmp_path
);
if
(
s_p
&&
json_path_setup
(
&
path
.
p
,
s_p
->
charset
(),
(
const
uchar
*
)
s_p
->
ptr
(),
(
const
uchar
*
)
s_p
->
ptr
()
+
s_p
->
length
()))
{
report_path_error
(
s_p
,
&
path
.
p
,
2
);
goto
null_return
;
}
path
.
parsed
=
path
.
constant
;
}
if
(
args
[
1
]
->
null_value
)
goto
null_return
;
path
.
cur_step
=
path
.
p
.
steps
;
if
(
json_find_path
(
&
je
,
&
path
.
p
,
&
path
.
cur_step
,
array_counters
))
{
if
(
je
.
s
.
error
)
goto
err_return
;
goto
null_return
;
}
}
if
(
json_read_value
(
&
je
))
goto
err_return
;
if
(
json_value_scalar
(
&
je
))
return
1
;
while
(
json_scan_next
(
&
je
)
==
0
&&
je
.
state
!=
JST_OBJ_END
&&
je
.
state
!=
JST_ARRAY_END
)
{
switch
(
je
.
state
)
{
case
JST_VALUE
:
case
JST_KEY
:
length
++
;
}
while
(
json_scan_next
(
&
je
)
==
0
);
break
;
case
JST_OBJ_START
:
case
JST_ARRAY_START
:
if
(
json_skip_level
(
&
je
))
goto
err_return
;
break
;
default:
break
;
};
}
if
(
!
je
.
s
.
error
)
return
length
-
1
;
return
length
;
err_return:
report_json_error
(
js
,
&
je
,
0
);
null_return:
null_value
=
1
;
return
0
;
}
...
...
sql/item_jsonfunc.h
View file @
3a177279
...
...
@@ -67,8 +67,8 @@ class Item_func_json_exists: public Item_int_func
String
tmp_js
,
tmp_path
;
public:
Item_func_json_exists
(
THD
*
thd
,
Item
*
js
,
Item
*
path
)
:
Item_int_func
(
thd
,
js
,
path
)
{}
Item_func_json_exists
(
THD
*
thd
,
Item
*
js
,
Item
*
i_
path
)
:
Item_int_func
(
thd
,
js
,
i_
path
)
{}
const
char
*
func_name
()
const
{
return
"json_exists"
;
}
bool
is_bool_type
()
{
return
true
;
}
void
fix_length_and_dec
();
...
...
@@ -85,8 +85,8 @@ class Item_func_json_value: public Item_str_func
String
tmp_js
,
tmp_path
;
public:
Item_func_json_value
(
THD
*
thd
,
Item
*
js
,
Item
*
path
)
:
Item_str_func
(
thd
,
js
,
path
)
{}
Item_func_json_value
(
THD
*
thd
,
Item
*
js
,
Item
*
i_
path
)
:
Item_str_func
(
thd
,
js
,
i_
path
)
{}
const
char
*
func_name
()
const
{
return
"json_value"
;
}
void
fix_length_and_dec
();
String
*
val_str
(
String
*
);
...
...
@@ -99,8 +99,8 @@ class Item_func_json_value: public Item_str_func
class
Item_func_json_query
:
public
Item_func_json_value
{
public:
Item_func_json_query
(
THD
*
thd
,
Item
*
js
,
Item
*
path
)
:
Item_func_json_value
(
thd
,
js
,
path
)
{}
Item_func_json_query
(
THD
*
thd
,
Item
*
js
,
Item
*
i_
path
)
:
Item_func_json_value
(
thd
,
js
,
i_
path
)
{}
const
char
*
func_name
()
const
{
return
"json_query"
;
}
bool
check_and_get_value
(
json_engine_t
*
je
,
String
*
res
,
int
*
error
);
Item
*
get_copy
(
THD
*
thd
,
MEM_ROOT
*
mem_root
)
...
...
@@ -291,12 +291,14 @@ class Item_func_json_merge: public Item_func_json_array
class
Item_func_json_length
:
public
Item_int_func
{
protected:
json_path_with_flags
path
;
String
tmp_js
;
String
tmp_path
;
public:
Item_func_json_length
(
THD
*
thd
,
List
<
Item
>
&
list
)
:
Item_int_func
(
thd
,
list
)
{}
const
char
*
func_name
()
const
{
return
"json_length"
;
}
void
fix_length_and_dec
();
longlong
val_int
();
Item
*
get_copy
(
THD
*
thd
,
MEM_ROOT
*
mem_root
)
{
return
get_item_copy
<
Item_func_json_length
>
(
thd
,
mem_root
,
this
);
}
...
...
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