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
12897a5b
Commit
12897a5b
authored
Dec 04, 2016
by
Alexey Botchkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MDEV-11437 JSON_QUOTE function does not quote and uses wrong character set.
json_quote fixed.
parent
b4cbaf0b
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
6 deletions
+23
-6
mysql-test/r/func_json.result
mysql-test/r/func_json.result
+11
-1
mysql-test/t/func_json.test
mysql-test/t/func_json.test
+4
-0
sql/item_jsonfunc.cc
sql/item_jsonfunc.cc
+8
-5
No files found.
mysql-test/r/func_json.result
View file @
12897a5b
...
...
@@ -186,7 +186,17 @@ json_exists('{"key1":"xxxx", "key2":[1, 2, 3]}', "$.key2[10]")
0
select json_quote('"string"');
json_quote('"string"')
\"string\"
"\"string\""
create table t1 as select json_quote('foo');
select * from t1;
json_quote('foo')
"foo"
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`json_quote('foo')` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
select json_merge('string', 123);
json_merge('string', 123)
["string", 123]
...
...
mysql-test/t/func_json.test
View file @
12897a5b
...
...
@@ -78,6 +78,10 @@ select json_exists('{"key1":"xxxx", "key2":[1, 2, 3]}', "$.key2[1]");
select
json_exists
(
'{"key1":"xxxx", "key2":[1, 2, 3]}'
,
"$.key2[10]"
);
select
json_quote
(
'"string"'
);
create
table
t1
as
select
json_quote
(
'foo'
);
select
*
from
t1
;
show
create
table
t1
;
drop
table
t1
;
select
json_merge
(
'string'
,
123
);
...
...
sql/item_jsonfunc.cc
View file @
12897a5b
...
...
@@ -287,12 +287,12 @@ bool Item_func_json_query::check_and_get_value(json_engine_t *je, String *res,
void
Item_func_json_quote
::
fix_length_and_dec
()
{
collation
.
set
(
args
[
0
]
->
collatio
n
);
collation
.
set
(
&
my_charset_utf8mb4_bi
n
);
/*
Odd but realistic worst case is when all characters
of the argument turn into '\uXXXX\uXXXX', which is 12.
*/
max_length
=
args
[
0
]
->
max_length
*
12
;
max_length
=
args
[
0
]
->
max_length
*
12
+
2
;
}
...
...
@@ -300,13 +300,16 @@ String *Item_func_json_quote::val_str(String *str)
{
String
*
s
=
args
[
0
]
->
val_str
(
&
tmp_s
);
if
((
null_value
=
args
[
0
]
->
null_value
))
if
((
null_value
=
(
args
[
0
]
->
null_value
||
args
[
0
]
->
result_type
()
!=
STRING_RESULT
)))
return
NULL
;
str
->
length
(
0
);
str
->
set_charset
(
s
->
charset
()
);
str
->
set_charset
(
&
my_charset_utf8mb4_bin
);
if
(
st_append_escaped
(
str
,
s
))
if
(
str
->
append
(
"
\"
"
,
1
)
||
st_append_escaped
(
str
,
s
)
||
str
->
append
(
"
\"
"
,
1
))
{
/* Report an error. */
null_value
=
1
;
...
...
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