summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOleksandr Byelkin <sanja@mariadb.com>2015-12-10 16:17:20 +0100
committerOleksandr Byelkin <sanja@mariadb.com>2015-12-10 16:18:15 +0100
commit537c750e328cd080365e465acd4f0383bf0febf3 (patch)
tree583a096c5bf18d0b1285f1e87cba9406e71a0b46
parent311f0308d04f3a55ad18470ca39e9d44479c4782 (diff)
downloadmariadb-git-537c750e328cd080365e465acd4f0383bf0febf3.tar.gz
MDEV-8521 Drastic loss of precision in COLUMN_JSON() on DOUBLEs
fixed conversion
-rw-r--r--mysql-test/r/dyncol.result18
-rw-r--r--mysql-test/t/dyncol.test7
-rw-r--r--mysys/ma_dyncol.c4
3 files changed, 25 insertions, 4 deletions
diff --git a/mysql-test/r/dyncol.result b/mysql-test/r/dyncol.result
index fe66e8ac91f..af7c3b7337c 100644
--- a/mysql-test/r/dyncol.result
+++ b/mysql-test/r/dyncol.result
@@ -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
#
diff --git a/mysql-test/t/dyncol.test b/mysql-test/t/dyncol.test
index ceebeb2e49f..0f4058d4eef 100644
--- a/mysql-test/t/dyncol.test
+++ b/mysql-test/t/dyncol.test
@@ -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
diff --git a/mysys/ma_dyncol.c b/mysys/ma_dyncol.c
index 7dfaf29a1a7..06820a0c3c5 100644
--- a/mysys/ma_dyncol.c
+++ b/mysys/ma_dyncol.c
@@ -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);