[Commits] 352c7e0: MDEV-15905 select json_value('{"b":true}', '$.b')=1 --> false with
revision-id: 352c7e0dfaa0f121c5b35e1d9fafb9ec8897e768 (mariadb-10.2.15-61-g352c7e0) parent(s): b8514c94f61f37757a24df1c6b9a7dd530b3de12 committer: Alexey Botchkov timestamp: 2018-06-17 17:15:21 +0400 message: 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. --- mysql-test/r/func_json.result | 3 +++ mysql-test/t/func_json.test | 7 +++++++ sql/item_jsonfunc.cc | 21 ++++++++++++++++++++- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/func_json.result b/mysql-test/r/func_json.result index 2ffeb83..77a4241 100644 --- a/mysql-test/r/func_json.result +++ b/mysql-test/r/func_json.result @@ -739,3 +739,6 @@ drop table t1; select json_extract('{"test":8.437e-5}','$.test'); json_extract('{"test":8.437e-5}','$.test') 8.437e-5 +select json_value('{"b":true}','$.b')=1; +json_value('{"b":true}','$.b')=1 +1 diff --git a/mysql-test/t/func_json.test b/mysql-test/t/func_json.test index a6ae934..b74915c 100644 --- a/mysql-test/t/func_json.test +++ b/mysql-test/t/func_json.test @@ -398,3 +398,10 @@ drop table t1; 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; + + diff --git a/sql/item_jsonfunc.cc b/sql/item_jsonfunc.cc index 72aeac5..c8cda66 100644 --- a/sql/item_jsonfunc.cc +++ b/sql/item_jsonfunc.cc @@ -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, int *error) { + CHARSET_INFO *json_cs; + const uchar *js; + uint js_len; + if (!json_value_scalar(je)) { /* 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, 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); }
participants (1)
-
holyfoot@askmonty.org