Correctly truncate integers inserted into field and double columns
with a number of decimals specified. (Bug #7361)
This commit is contained in:
parent
77bc68f99d
commit
c2eb3bf9f6
@ -143,3 +143,39 @@ drop table t1;
|
|||||||
create table t1 (f float(54));
|
create table t1 (f float(54));
|
||||||
ERROR 42000: Incorrect column specifier for column 'f'
|
ERROR 42000: Incorrect column specifier for column 'f'
|
||||||
drop table if exists t1;
|
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;
|
||||||
|
@ -143,3 +143,39 @@ drop table t1;
|
|||||||
create table t1 (f float(54));
|
create table t1 (f float(54));
|
||||||
ERROR 42000: Incorrect column specifier for column 'f'
|
ERROR 42000: Incorrect column specifier for column 'f'
|
||||||
drop table if exists t1;
|
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;
|
||||||
|
@ -93,3 +93,13 @@ create table t1 (f float(54)); # Should give an error
|
|||||||
drop table if exists t1;
|
drop table if exists t1;
|
||||||
--enable_warnings
|
--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;
|
||||||
|
36
sql/field.cc
36
sql/field.cc
@ -2395,23 +2395,7 @@ int Field_float::store(double nr)
|
|||||||
|
|
||||||
int Field_float::store(longlong nr)
|
int Field_float::store(longlong nr)
|
||||||
{
|
{
|
||||||
int error= 0;
|
return store((double)nr);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -2690,23 +2674,7 @@ int Field_double::store(double nr)
|
|||||||
|
|
||||||
int Field_double::store(longlong nr)
|
int Field_double::store(longlong nr)
|
||||||
{
|
{
|
||||||
double j= (double) nr;
|
return store((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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user