Commit 537c750e authored by Oleksandr Byelkin's avatar Oleksandr Byelkin

MDEV-8521 Drastic loss of precision in COLUMN_JSON() on DOUBLEs

fixed conversion
parent 311f0308
......@@ -1693,10 +1693,10 @@ ERROR 22007: Illegal value used as argument of dynamic column function
#
select column_json(column_create("int", -1212 as int, "uint", 12334 as unsigned int, "decimal", "23.344" as decimal, "double", 1.23444e50 as double, "string", 'gdgd\\dhdjh"dhdhd' as char, "time", "0:45:49.000001" AS time, "datetime", "2011-04-05 0:45:49.000001" AS datetime, "date", "2011-04-05" AS date));
column_json(column_create("int", -1212 as int, "uint", 12334 as unsigned int, "decimal", "23.344" as decimal, "double", 1.23444e50 as double, "string", 'gdgd\\dhdjh"dhdhd' as char, "time", "0:45:49.000001" AS time, "datetime", "2011-04-05 0:45:49.000001"
{"int":-1212,"date":"2011-04-05","time":"00:45:49.000001","uint":12334,"double":1.2e50,"string":"gdgd\\dhdjh\"dhdhd","decimal":23.344,"datetime":"2011-04-05 00:45:49.000001"}
{"int":-1212,"date":"2011-04-05","time":"00:45:49.000001","uint":12334,"double":1.23444e50,"string":"gdgd\\dhdjh\"dhdhd","decimal":23.344,"datetime":"2011-04-05 00:45:49.000001"}
select column_json(column_create(1, -1212 as int, 2, 12334 as unsigned int, 3, "23.344" as decimal, 4, 1.23444e50 as double, 5, 'gdgd\\dhdjh"dhdhd' as char, 6, "0:45:49.000001" AS time, 7, "2011-04-05 0:45:49.000001" AS datetime, 8, "2011-04-05" AS date));
column_json(column_create(1, -1212 as int, 2, 12334 as unsigned int, 3, "23.344" as decimal, 4, 1.23444e50 as double, 5, 'gdgd\\dhdjh"dhdhd' as char, 6, "0:45:49.000001" AS time, 7, "2011-04-05 0:45:49.000001" AS datetime, 8, "2011-04-05" AS date))
{"1":-1212,"2":12334,"3":23.344,"4":1.2e50,"5":"gdgd\\dhdjh\"dhdhd","6":"00:45:49.000001","7":"2011-04-05 00:45:49.000001","8":"2011-04-05"}
{"1":-1212,"2":12334,"3":23.344,"4":1.23444e50,"5":"gdgd\\dhdjh\"dhdhd","6":"00:45:49.000001","7":"2011-04-05 00:45:49.000001","8":"2011-04-05"}
#
# CHECK test
#
......@@ -1834,7 +1834,19 @@ COLUMN_CREATE(
'two', 123.456 as DOUBLE
)
)
{"one":123.456,"two":123.46}
{"one":123.456,"two":123.456}
#
# MDEV-8521: Drastic loss of precision in COLUMN_JSON() on DOUBLEs
#
select column_get(column_create('float', 1.23456789012345E+100 as double), 'float' as double);
column_get(column_create('float', 1.23456789012345E+100 as double), 'float' as double)
1.23456789012345e100
select column_json(column_create('float', 1.23456789012345E+100 as double));
column_json(column_create('float', 1.23456789012345E+100 as double))
{"float":1.23456789012345e100}
select column_json(column_create('float', 1.23456789012345E+10 as double));
column_json(column_create('float', 1.23456789012345E+10 as double))
{"float":12345678901.2345}
#
# end of 10.0 tests
#
......@@ -893,6 +893,13 @@ SELECT COLUMN_JSON(
)
);
--echo #
--echo # MDEV-8521: Drastic loss of precision in COLUMN_JSON() on DOUBLEs
--echo #
select column_get(column_create('float', 1.23456789012345E+100 as double), 'float' as double);
select column_json(column_create('float', 1.23456789012345E+100 as double));
select column_json(column_create('float', 1.23456789012345E+10 as double));
--echo #
--echo # end of 10.0 tests
......
......@@ -3837,7 +3837,9 @@ mariadb_dyncol_val_str(DYNAMIC_STRING *str, DYNAMIC_COLUMN_VALUE *val,
return ER_DYNCOL_RESOURCE;
break;
case DYN_COL_DOUBLE:
len= my_snprintf(buff, sizeof(buff), "%g", val->x.double_value);
len= my_gcvt(val->x.double_value, MY_GCVT_ARG_DOUBLE,
sizeof(buff) - 1, buff, NULL);
if (dynstr_realloc(str, len + (quote ? 2 : 0)))
return ER_DYNCOL_RESOURCE;
dynstr_append_mem(str, buff, 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