Commit 90d6195f authored by jimw@mysql.com's avatar jimw@mysql.com

Fix handling of NULL values in decimal fields in FORMAT(). (Bug #13361)

parent 306dcf06
......@@ -1011,3 +1011,9 @@ t
1000000
1
drop table t1;
create table t1 (d decimal default null);
insert into t1 values (null);
select format(d, 2) from t1;
format(d, 2)
NULL
drop table t1;
......@@ -665,3 +665,13 @@ select rpad(i, 7, ' ') as t from t1;
drop table t1;
# End of 4.1 tests
#
# Bug #13361: SELECT FORMAT(<decimal field with null>, 2) crashes
#
create table t1 (d decimal default null);
insert into t1 values (null);
select format(d, 2) from t1;
drop table t1;
# End of 5.0 tests
......@@ -1733,6 +1733,8 @@ String *Item_func_format::val_str(String *str)
{
my_decimal dec_val, rnd_dec, *res;
res= args[0]->val_decimal(&dec_val);
if ((null_value=args[0]->null_value))
return 0; /* purecov: inspected */
my_decimal_round(E_DEC_FATAL_ERROR, res, decimals, false, &rnd_dec);
my_decimal2string(E_DEC_FATAL_ERROR, &rnd_dec, 0, 0, 0, str);
str_length= str->length();
......
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