List:Internals« Previous MessageNext Message »
From:holyfoot Date:June 8 2005 10:49am
Subject:bk commit into 5.0 tree (holyfoot:1.1951) BUG#8429
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of hf. When hf does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet
  1.1951 05/06/08 15:49:36 holyfoot@hf-ibm.(none) +3 -0
  Fix for bug #8429 (FORMAT returns incorrect result)

  sql/item_strfunc.cc
    1.232 05/06/08 15:49:01 holyfoot@stripped +27 -13
    Item_func_format::val_str now handles 'decimal' and 'double' values in
    different way

  mysql-test/t/func_math.test
    1.17 05/06/08 15:49:00 holyfoot@stripped +12 -0
    test case added

  mysql-test/r/func_math.result
    1.25 05/06/08 15:49:00 holyfoot@stripped +13 -0
    test result ixed

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	holyfoot
# Host:	hf-ibm.(none)
# Root:	/home/hf/work/mysql-5.0.8459

--- 1.231/sql/item_strfunc.cc	Mon Jun  6 23:21:25 2005
+++ 1.232/sql/item_strfunc.cc	Wed Jun  8 15:49:01 2005
@@ -1668,22 +1668,36 @@
 
 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)
   {

--- 1.24/mysql-test/r/func_math.result	Fri May 20 01:03:59 2005
+++ 1.25/mysql-test/r/func_math.result	Wed Jun  8 15:49:00 2005
@@ -130,3 +130,16 @@
 Note	1003	select degrees(pi()) AS `degrees(pi())`,radians(360) AS `radians(360)`
 select rand(rand);
 ERROR 42S22: Unknown column 'rand' in 'field list'
+create table t1 (col1 int, col2 decimal(60,30));
+insert into t1 values(1,1234567890.12345);
+select format(col2,7) from t1;
+format(col2,7)
+1,234,567,890.1234500
+select format(col2,8) from t1;
+format(col2,8)
+1,234,567,890.12345000
+insert into t1 values(7,1234567890123456.12345);
+select format(col2,6) from t1 where col1=7;
+format(col2,6)
+1,234,567,890,123,456.123450
+drop table t1;

--- 1.16/mysql-test/t/func_math.test	Fri May 20 01:04:00 2005
+++ 1.17/mysql-test/t/func_math.test	Wed Jun  8 15:49:00 2005
@@ -67,3 +67,15 @@
 
 --error 1054
 select rand(rand);
+
+#
+# Bug #8459 (FORMAT returns incorrect result)
+#
+create table t1 (col1 int, col2 decimal(60,30));
+insert into t1 values(1,1234567890.12345);
+select format(col2,7) from t1;
+select format(col2,8) from t1;
+insert into t1 values(7,1234567890123456.12345);
+select format(col2,6) from t1 where col1=7;
+drop table t1;
+
Thread
bk commit into 5.0 tree (holyfoot:1.1951) BUG#8429holyfoot8 Jun