1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-01 03:47:19 +03:00

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

mysql-test/r/func_str.result:
  Add new results
mysql-test/t/func_str.test:
  Add new regression test
sql/item_strfunc.cc:
  Handle NULL decimal fields in FORMAT().
This commit is contained in:
unknown
2005-09-22 11:40:22 -07:00
parent d2fc3bd424
commit 0f0f72c74f
3 changed files with 18 additions and 0 deletions

View File

@ -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;

View File

@ -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

View File

@ -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();