MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:igor Date:July 7 2007 5:33pm
Subject:bk commit into 5.0 tree (igor:1.2521) BUG#29415
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of igor. When igor 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@stripped, 2007-07-07 10:33:02-07:00, igor@stripped +3 -0
  Fixed bug #29415.
  The cast operation ignored the cases when the precision and/or the scale exceeded
  the limits, 65 and 30 respectively. No errors were reported in these cases.
  For some queries this may lead to an assertion abort.
  
  Fixed by throwing errors for such cases.

  mysql-test/r/type_newdecimal.result@stripped, 2007-07-07 10:32:49-07:00, igor@stripped +20 -0
    Added a test case for bug #29415.

  mysql-test/t/type_newdecimal.test@stripped, 2007-07-07 10:32:49-07:00, igor@stripped +23 -0
    Added a test case for bug #29415.
    

  sql/item_create.cc@stripped, 2007-07-07 10:32:49-07:00, igor@stripped +12 -0
    Fixed bug #29415.
    The cast operation ignored the cases when the precision and/or the scale exceeded
    the limits, 65 and 30 respectively. No errors were reported in these cases.
    For some queries this may lead to an assertion abort.
    
    Fixed by throwing errors for such cases.

diff -Nrup a/mysql-test/r/type_newdecimal.result b/mysql-test/r/type_newdecimal.result
--- a/mysql-test/r/type_newdecimal.result	2007-05-21 10:28:19 -07:00
+++ b/mysql-test/r/type_newdecimal.result	2007-07-07 10:32:49 -07:00
@@ -1471,4 +1471,24 @@ drop table t1;
 SELECT 1.000000000000 * 99.999999999998 / 100 a,1.000000000000 * (99.999999999998 / 100) b;
 a	b
 0.9999999999999800000000000000	0.9999999999999800000000000000
+SELECT CAST(1 AS decimal(65,10));
+CAST(1 AS decimal(65,10))
+1.0000000000
+SELECT CAST(1 AS decimal(66,10));
+ERROR 42000: Too big precision 66 specified for column '1'. Maximum is 65.
+SELECT CAST(1 AS decimal(65,30));
+CAST(1 AS decimal(65,30))
+1.000000000000000000000000000000
+SELECT CAST(1 AS decimal(65,31));
+ERROR 42000: Too big scale 31 specified for column '1'. Maximum is 30.
+CREATE TABLE t1 (a int DEFAULT NULL, b int DEFAULT NULL);
+INSERT INTO t1 VALUES (3,30), (1,10), (2,10);
+SELECT a+CAST(1 AS decimal(65,30)) AS aa, SUM(b) FROM t1 GROUP BY aa;
+aa	SUM(b)
+2.000000000000000000000000000000	10
+3.000000000000000000000000000000	10
+4.000000000000000000000000000000	30
+SELECT a+CAST(1 AS decimal(65,31)) AS aa, SUM(b) FROM t1 GROUP BY aa;
+ERROR 42000: Too big scale 31 specified for column '1'. Maximum is 30.
+DROP TABLE t1;
 End of 5.0 tests
diff -Nrup a/mysql-test/t/type_newdecimal.test b/mysql-test/t/type_newdecimal.test
--- a/mysql-test/t/type_newdecimal.test	2007-05-21 10:28:45 -07:00
+++ b/mysql-test/t/type_newdecimal.test	2007-07-07 10:32:49 -07:00
@@ -1162,4 +1162,27 @@ drop table t1;
 #
 
 SELECT 1.000000000000 * 99.999999999998 / 100 a,1.000000000000 * (99.999999999998 / 100) b;
+
+#
+# Bug #29415: CAST AS DECIMAL(P,S) with too big precision/scale 
+#
+
+SELECT CAST(1 AS decimal(65,10));
+--error ER_TOO_BIG_PRECISION
+SELECT CAST(1 AS decimal(66,10));
+
+SELECT CAST(1 AS decimal(65,30));
+--error ER_TOO_BIG_SCALE
+SELECT CAST(1 AS decimal(65,31));
+
+CREATE TABLE t1 (a int DEFAULT NULL, b int DEFAULT NULL);
+INSERT INTO t1 VALUES (3,30), (1,10), (2,10);
+SELECT a+CAST(1 AS decimal(65,30)) AS aa, SUM(b) FROM t1 GROUP BY aa;
+--error ER_TOO_BIG_SCALE
+SELECT a+CAST(1 AS decimal(65,31)) AS aa, SUM(b) FROM t1 GROUP BY aa;
+
+DROP TABLE t1;
+
 --echo End of 5.0 tests
+
+
diff -Nrup a/sql/item_create.cc b/sql/item_create.cc
--- a/sql/item_create.cc	2007-06-13 11:23:22 -07:00
+++ b/sql/item_create.cc	2007-07-07 10:32:49 -07:00
@@ -471,6 +471,18 @@ Item *create_func_cast(Item *a, Cast_tar
       my_error(ER_M_BIGGER_THAN_D, MYF(0), "");
       return 0;
     }
+    if (len > DECIMAL_MAX_PRECISION)
+    {
+      my_error(ER_TOO_BIG_PRECISION, MYF(0), len, a->name,
+               DECIMAL_MAX_PRECISION);
+      return 0;
+    }
+    if (dec > DECIMAL_MAX_SCALE)
+    {
+      my_error(ER_TOO_BIG_SCALE, MYF(0), dec, a->name,
+               DECIMAL_MAX_SCALE);
+      return 0;
+    }
     res= new Item_decimal_typecast(a, len, dec);
     break;
   case ITEM_CAST_CHAR:
Thread
bk commit into 5.0 tree (igor:1.2521) BUG#29415igor7 Jul