Commit 352c7e0d authored by Alexey Botchkov's avatar Alexey Botchkov

MDEV-15905 select json_value('{"b":true}','$.b')=1 --> false with

"Truncated incorrect DOUBLE value: 'true'".

JSON_VALUE_TRUE and JSON_VALUE_FALSE should be handled specifically
in Item_json_value.
parent b8514c94
...@@ -739,3 +739,6 @@ drop table t1; ...@@ -739,3 +739,6 @@ drop table t1;
select json_extract('{"test":8.437e-5}','$.test'); select json_extract('{"test":8.437e-5}','$.test');
json_extract('{"test":8.437e-5}','$.test') json_extract('{"test":8.437e-5}','$.test')
8.437e-5 8.437e-5
select json_value('{"b":true}','$.b')=1;
json_value('{"b":true}','$.b')=1
1
...@@ -398,3 +398,10 @@ drop table t1; ...@@ -398,3 +398,10 @@ drop table t1;
select json_extract('{"test":8.437e-5}','$.test'); select json_extract('{"test":8.437e-5}','$.test');
#
# MDEV-15905 select json_value('{"b":true}','$.b')=1 --> false with
# "Truncated incorrect DOUBLE value: 'true'"
#
select json_value('{"b":true}','$.b')=1;
...@@ -513,6 +513,10 @@ String *Item_func_json_value::val_str(String *str) ...@@ -513,6 +513,10 @@ String *Item_func_json_value::val_str(String *str)
bool Item_func_json_value::check_and_get_value(json_engine_t *je, String *res, bool Item_func_json_value::check_and_get_value(json_engine_t *je, String *res,
int *error) int *error)
{ {
CHARSET_INFO *json_cs;
const uchar *js;
uint js_len;
if (!json_value_scalar(je)) if (!json_value_scalar(je))
{ {
/* We only look for scalar values! */ /* We only look for scalar values! */
...@@ -521,7 +525,22 @@ bool Item_func_json_value::check_and_get_value(json_engine_t *je, String *res, ...@@ -521,7 +525,22 @@ bool Item_func_json_value::check_and_get_value(json_engine_t *je, String *res,
return true; return true;
} }
return st_append_json(res, je->s.cs, je->value, je->value_len); if (je->value_type == JSON_VALUE_TRUE ||
je->value_type == JSON_VALUE_FALSE)
{
json_cs= &my_charset_utf8mb4_bin;
js= (const uchar *) ((je->value_type == JSON_VALUE_TRUE) ? "1" : "0");
js_len= 1;
}
else
{
json_cs= je->s.cs;
js= je->value;
js_len= je->value_len;
}
return st_append_json(res, json_cs, js, js_len);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment