Browse Source

MDEV-11436 CREATE TABLE .. AS SELECT JSON_OBJECT truncates data.

fix_length_and_dec() didn't calculate the length of the result
        properly.
pull/274/head
Alexey Botchkov 9 years ago
parent
commit
b4cbaf0b7c
  1. 10
      mysql-test/r/func_json.result
  2. 4
      mysql-test/t/func_json.test
  3. 4
      sql/item_jsonfunc.cc

10
mysql-test/r/func_json.result

@ -165,6 +165,16 @@ json_object()
select json_object("ki", 1, "mi", "ya");
json_object("ki", 1, "mi", "ya")
{"ki": 1, "mi": "ya"}
create table t1 as select json_object('id', 87, 'name', 'carrot') as f;
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`f` varchar(32) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
select * from t1;
f
{"id": 87, "name": "carrot"}
drop table t1;
select json_exists('{"key1":"xxxx", "key2":[1, 2, 3]}', "$.key2");
json_exists('{"key1":"xxxx", "key2":[1, 2, 3]}', "$.key2")
1

4
mysql-test/t/func_json.test

@ -68,6 +68,10 @@ select json_remove(@j, '$.a');
select json_object();
select json_object("ki", 1, "mi", "ya");
create table t1 as select json_object('id', 87, 'name', 'carrot') as f;
show create table t1;
select * from t1;
drop table t1;
select json_exists('{"key1":"xxxx", "key2":[1, 2, 3]}', "$.key2");
select json_exists('{"key1":"xxxx", "key2":[1, 2, 3]}', "$.key2[1]");

4
sql/item_jsonfunc.cc

@ -874,7 +874,7 @@ append_null:
void Item_func_json_array::fix_length_and_dec()
{
ulonglong char_length= 4;
ulonglong char_length= 2;
uint n_arg;
if (arg_count == 0)
@ -889,7 +889,7 @@ void Item_func_json_array::fix_length_and_dec()
return;
for (n_arg=0 ; n_arg < arg_count ; n_arg++)
char_length+= args[n_arg]->max_char_length() + 2;
char_length+= args[n_arg]->max_char_length() + 4;
fix_char_length_ulonglong(char_length);
tmp_val.set_charset(collation.collation);

Loading…
Cancel
Save