diff options
author | unknown <holyfoot@hf-ibm.(none)> | 2005-06-08 15:49:36 +0500 |
---|---|---|
committer | unknown <holyfoot@hf-ibm.(none)> | 2005-06-08 15:49:36 +0500 |
commit | 4408350b51278b085533050f4ad5ef59955baccd (patch) | |
tree | 934ffa52aa1df1de3b1ab029692103e5cee518a1 /sql | |
parent | b5755ae60b2fac28f450edd64b1e98249d8660d8 (diff) | |
download | mariadb-git-4408350b51278b085533050f4ad5ef59955baccd.tar.gz |
Fix for bug #8429 (FORMAT returns incorrect result)
mysql-test/r/func_math.result:
test result ixed
mysql-test/t/func_math.test:
test case added
sql/item_strfunc.cc:
Item_func_format::val_str now handles 'decimal' and 'double' values in
different way
Diffstat (limited to 'sql')
-rw-r--r-- | sql/item_strfunc.cc | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index d3327a0e41f..539bed58e66 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -1668,22 +1668,36 @@ Item_func_format::Item_func_format(Item *org,int dec) :Item_str_func(org) String *Item_func_format::val_str(String *str) { - DBUG_ASSERT(fixed == 1); - double nr= args[0]->val_real(); - uint32 length,str_length,dec; + uint32 length, str_length ,dec; int diff; - if ((null_value=args[0]->null_value)) - return 0; /* purecov: inspected */ - nr= my_double_round(nr, decimals, FALSE); + DBUG_ASSERT(fixed == 1); dec= decimals ? decimals+1 : 0; - /* Here default_charset() is right as this is not an automatic conversion */ - str->set(nr,decimals, default_charset()); - if (isnan(nr)) - return str; - str_length=str->length(); - if (nr < 0) - str_length--; // Don't count sign + if (args[0]->result_type() == DECIMAL_RESULT || + args[0]->result_type() == INT_RESULT) + { + my_decimal dec_val, rnd_dec, *res; + res= args[0]->val_decimal(&dec_val); + 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(); + if (rnd_dec.sign()) + str_length--; + } + else + { + double nr= args[0]->val_real(); + if ((null_value=args[0]->null_value)) + return 0; /* purecov: inspected */ + nr= my_double_round(nr, decimals, FALSE); + /* Here default_charset() is right as this is not an automatic conversion */ + str->set(nr,decimals, default_charset()); + if (isnan(nr)) + return str; + str_length=str->length(); + if (nr < 0) + str_length--; // Don't count sign + } /* We need this test to handle 'nan' values */ if (str_length >= dec+4) { |