diff --git a/mysql-test/r/type_float.result b/mysql-test/r/type_float.result index 151ec4044559943575e0495808281856cfe92f38..84c931e14dab969039ccaacd7204dbb5525f10f7 100644 --- a/mysql-test/r/type_float.result +++ b/mysql-test/r/type_float.result @@ -143,3 +143,39 @@ drop table t1; create table t1 (f float(54)); ERROR 42000: Incorrect column specifier for column 'f' drop table if exists t1; +create table t1 (f float(4,3)); +insert into t1 values (-11.0),(-11),("-11"),(11.0),(11),("11"); +Warnings: +Warning 1264 Data truncated; out of range for column 'f' at row 1 +Warning 1264 Data truncated; out of range for column 'f' at row 2 +Warning 1264 Data truncated; out of range for column 'f' at row 3 +Warning 1264 Data truncated; out of range for column 'f' at row 4 +Warning 1264 Data truncated; out of range for column 'f' at row 5 +Warning 1264 Data truncated; out of range for column 'f' at row 6 +select * from t1; +f +-9.999 +-9.999 +-9.999 +9.999 +9.999 +9.999 +drop table if exists t1; +create table t1 (f double(4,3)); +insert into t1 values (-11.0),(-11),("-11"),(11.0),(11),("11"); +Warnings: +Warning 1264 Data truncated; out of range for column 'f' at row 1 +Warning 1264 Data truncated; out of range for column 'f' at row 2 +Warning 1264 Data truncated; out of range for column 'f' at row 3 +Warning 1264 Data truncated; out of range for column 'f' at row 4 +Warning 1264 Data truncated; out of range for column 'f' at row 5 +Warning 1264 Data truncated; out of range for column 'f' at row 6 +select * from t1; +f +-9.999 +-9.999 +-9.999 +9.999 +9.999 +9.999 +drop table if exists t1; diff --git a/mysql-test/r/type_float.result.es b/mysql-test/r/type_float.result.es index 4bfe644d7fb13d4fa54db5f429796708aa9dc643..64d9be7e30fdc9af317da792b921a95d8c093fcb 100644 --- a/mysql-test/r/type_float.result.es +++ b/mysql-test/r/type_float.result.es @@ -143,3 +143,39 @@ drop table t1; create table t1 (f float(54)); ERROR 42000: Incorrect column specifier for column 'f' drop table if exists t1; +create table t1 (f float(4,3)); +insert into t1 values (-11.0),(-11),("-11"),(11.0),(11),("11"); +Warnings: +Warning 1264 Data truncated; out of range for column 'f' at row 1 +Warning 1264 Data truncated; out of range for column 'f' at row 2 +Warning 1264 Data truncated; out of range for column 'f' at row 3 +Warning 1264 Data truncated; out of range for column 'f' at row 4 +Warning 1264 Data truncated; out of range for column 'f' at row 5 +Warning 1264 Data truncated; out of range for column 'f' at row 6 +select * from t1; +f +-9.999 +-9.999 +-9.999 +9.999 +9.999 +9.999 +drop table if exists t1; +create table t1 (f double(4,3)); +insert into t1 values (-11.0),(-11),("-11"),(11.0),(11),("11"); +Warnings: +Warning 1264 Data truncated; out of range for column 'f' at row 1 +Warning 1264 Data truncated; out of range for column 'f' at row 2 +Warning 1264 Data truncated; out of range for column 'f' at row 3 +Warning 1264 Data truncated; out of range for column 'f' at row 4 +Warning 1264 Data truncated; out of range for column 'f' at row 5 +Warning 1264 Data truncated; out of range for column 'f' at row 6 +select * from t1; +f +-9.999 +-9.999 +-9.999 +9.999 +9.999 +9.999 +drop table if exists t1; diff --git a/mysql-test/t/type_float.test b/mysql-test/t/type_float.test index 26ac272c6d46bae3a50e6c36cf254777e2e65de0..3fe3afa3fac66323bb9163a1c322532d87f70a11 100644 --- a/mysql-test/t/type_float.test +++ b/mysql-test/t/type_float.test @@ -93,3 +93,13 @@ create table t1 (f float(54)); # Should give an error drop table if exists t1; --enable_warnings +# Ensure that maximum values as the result of number of decimals +# being specified in table schema are enforced (Bug #7361) +create table t1 (f float(4,3)); +insert into t1 values (-11.0),(-11),("-11"),(11.0),(11),("11"); +select * from t1; +drop table if exists t1; +create table t1 (f double(4,3)); +insert into t1 values (-11.0),(-11),("-11"),(11.0),(11),("11"); +select * from t1; +drop table if exists t1; diff --git a/sql/field.cc b/sql/field.cc index d15db92e51f4960cf46a5d06f082bce89cf4be82..8e0fddae3320ea1d8cb59673fde2aba2e6a7a8a0 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -2440,23 +2440,7 @@ int Field_float::store(double nr) int Field_float::store(longlong nr) { - int error= 0; - float j= (float) nr; - if (unsigned_flag && j < 0) - { - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); - j=0; - error= 1; - } -#ifdef WORDS_BIGENDIAN - if (table->db_low_byte_first) - { - float4store(ptr,j); - } - else -#endif - memcpy_fixed(ptr,(byte*) &j,sizeof(j)); - return error; + return store((double)nr); } @@ -2738,23 +2722,7 @@ int Field_double::store(double nr) int Field_double::store(longlong nr) { - double j= (double) nr; - int error= 0; - if (unsigned_flag && j < 0) - { - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); - error= 1; - j=0; - } -#ifdef WORDS_BIGENDIAN - if (table->db_low_byte_first) - { - float8store(ptr,j); - } - else -#endif - doublestore(ptr,j); - return error; + return store((double)nr); }