From ca084e0f729ac7a1d53671df2f17f3df1fb252b1 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 25 Aug 2005 19:21:47 +0500 Subject: [PATCH 1/2] Fix for bug #12694 (float(1,2) field error) mysql-test/t/type_float.test: test case sql/sql_parse.cc: length & dec checks added --- mysql-test/t/type_float.test | 9 +++++++++ sql/sql_parse.cc | 16 ++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/mysql-test/t/type_float.test b/mysql-test/t/type_float.test index c0f1854d5b2..cf2a2676ab0 100644 --- a/mysql-test/t/type_float.test +++ b/mysql-test/t/type_float.test @@ -147,3 +147,12 @@ select * from t1 where reckey=1.09E2; drop table t1; # End of 4.1 tests + +# +# bug #12694 (float(m,d) specifications) +# + +--error 1427 +create table t1 (s1 float(0,2)); +--error 1427 +create table t1 (s1 float(1,2)); diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 70920b07a97..65169f2af10 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -5752,19 +5752,31 @@ new_create_field(THD *thd, char *field_name, enum_field_types type, new_field->decimals= NOT_FIXED_DEC; break; } - if (!length) + if (!length && !decimals) { new_field->length = FLT_DIG+6; new_field->decimals= NOT_FIXED_DEC; } + if (new_field->length < new_field->decimals && + new_field->decimals != NOT_FIXED_DEC) + { + my_error(ER_SCALE_BIGGER_THAN_PRECISION, MYF(0), field_name); + DBUG_RETURN(NULL); + } break; case FIELD_TYPE_DOUBLE: allowed_type_modifier= AUTO_INCREMENT_FLAG; - if (!length) + if (!length && !decimals) { new_field->length = DBL_DIG+7; new_field->decimals=NOT_FIXED_DEC; } + if (new_field->length < new_field->decimals && + new_field->decimals != NOT_FIXED_DEC) + { + my_error(ER_SCALE_BIGGER_THAN_PRECISION, MYF(0), field_name); + DBUG_RETURN(NULL); + } break; case FIELD_TYPE_TIMESTAMP: if (!length) From eaba3ed347999af4c31c4419b6bf89e40c041caa Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 4 Sep 2005 17:45:02 +0500 Subject: [PATCH 2/2] Error message changed for buf #12694 as PeterG suggested mysql-test/r/type_float.result: result fixed mysql-test/t/type_float.test: errno fixed sql/share/errmsg.txt: error message added sql/sql_parse.cc: error message changed --- mysql-test/r/type_float.result | 4 ++++ mysql-test/t/type_float.test | 4 ++-- sql/share/errmsg.txt | 2 ++ sql/sql_parse.cc | 4 ++-- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/mysql-test/r/type_float.result b/mysql-test/r/type_float.result index d243985332e..fc7e4c5f346 100644 --- a/mysql-test/r/type_float.result +++ b/mysql-test/r/type_float.result @@ -225,3 +225,7 @@ select * from t1 where reckey=1.09E2; reckey recdesc 109 Has 109 as key drop table t1; +create table t1 (s1 float(0,2)); +ERROR 42000: For float(M,D) or double(M,D), M must be >= D (column 's1'). +create table t1 (s1 float(1,2)); +ERROR 42000: For float(M,D) or double(M,D), M must be >= D (column 's1'). diff --git a/mysql-test/t/type_float.test b/mysql-test/t/type_float.test index cf2a2676ab0..bb7bd37039b 100644 --- a/mysql-test/t/type_float.test +++ b/mysql-test/t/type_float.test @@ -152,7 +152,7 @@ drop table t1; # bug #12694 (float(m,d) specifications) # ---error 1427 +--error 1443 create table t1 (s1 float(0,2)); ---error 1427 +--error 1443 create table t1 (s1 float(1,2)); diff --git a/sql/share/errmsg.txt b/sql/share/errmsg.txt index b49b7248021..1535cc95367 100644 --- a/sql/share/errmsg.txt +++ b/sql/share/errmsg.txt @@ -5399,3 +5399,5 @@ ER_DATETIME_FUNCTION_OVERFLOW 22008 eng "Datetime function: %-.32s field overflow" ER_CANT_UPDATE_USED_TABLE_IN_SF_OR_TRG eng "Can't update table '%-.64s' in stored function/trigger because it is already used by statement which invoked this stored function/trigger." +ER_M_BIGGER_THAN_D 42000 S1009 + eng "For float(M,D) or double(M,D), M must be >= D (column '%-.64s')." diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 65169f2af10..27ab3fc0579 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -5760,7 +5760,7 @@ new_create_field(THD *thd, char *field_name, enum_field_types type, if (new_field->length < new_field->decimals && new_field->decimals != NOT_FIXED_DEC) { - my_error(ER_SCALE_BIGGER_THAN_PRECISION, MYF(0), field_name); + my_error(ER_M_BIGGER_THAN_D, MYF(0), field_name); DBUG_RETURN(NULL); } break; @@ -5774,7 +5774,7 @@ new_create_field(THD *thd, char *field_name, enum_field_types type, if (new_field->length < new_field->decimals && new_field->decimals != NOT_FIXED_DEC) { - my_error(ER_SCALE_BIGGER_THAN_PRECISION, MYF(0), field_name); + my_error(ER_M_BIGGER_THAN_D, MYF(0), field_name); DBUG_RETURN(NULL); } break;