DECIMAL truncation is warning, not error
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Drizzle |
Fix Released
|
High
|
Padraig O'Sullivan |
Bug Description
create table t1 (
f1 decimal not null default 17.49,
f2 decimal not null default 17.68,
f3 decimal not null default 99.2,
f4 decimal not null default 99.7,
f5 decimal not null default 104.49,
f6 decimal not null default 199.91,
f7 decimal not null default 999.9,
f8 decimal not null default 9999.99);
Warnings:
Note 1265 Data truncated for column 'f1' at row 1
Note 1265 Data truncated for column 'f2' at row 1
Note 1265 Data truncated for column 'f3' at row 1
Note 1265 Data truncated for column 'f4' at row 1
Note 1265 Data truncated for column 'f5' at row 1
Note 1265 Data truncated for column 'f6' at row 1
Note 1265 Data truncated for column 'f7' at row 1
Note 1265 Data truncated for column 'f8' at row 1
and not an error.
Related branches
- Jay Pipes (community): Approve
- Diff: None lines
Changed in drizzle: | |
importance: | Undecided → High |
milestone: | none → cirrus |
Changed in drizzle: | |
status: | In Progress → Fix Committed |
Changed in drizzle: | |
status: | Fix Committed → Fix Released |
Confirmed on trunk:
drizzle> use test
Database changed
drizzle> create table t1 (
-> f1 decimal not null default 17.49,
-> f2 decimal not null default 17.68,
-> f3 decimal not null default 99.2,
-> f4 decimal not null default 99.7,
-> f5 decimal not null default 104.49,
-> f6 decimal not null default 199.91,
-> f7 decimal not null default 999.9,
-> f8 decimal not null default 9999.99);
Query OK, 0 rows affected, 8 warnings (0.01 sec)
drizzle> show warnings; -+----- -+----- ------- ------- ------- ------- ------- -+ -+----- -+----- ------- ------- ------- ------- ------- -+ -+----- -+----- ------- ------- ------- ------- ------- -+
+------
| Level | Code | Message |
+------
| Note | 1265 | Data truncated for column 'f1' at row 1 |
| Note | 1265 | Data truncated for column 'f2' at row 1 |
| Note | 1265 | Data truncated for column 'f3' at row 1 |
| Note | 1265 | Data truncated for column 'f4' at row 1 |
| Note | 1265 | Data truncated for column 'f5' at row 1 |
| Note | 1265 | Data truncated for column 'f6' at row 1 |
| Note | 1265 | Data truncated for column 'f7' at row 1 |
| Note | 1265 | Data truncated for column 'f8' at row 1 |
+------
8 rows in set (0.00 sec)
drizzle>
Just looking at the relevant code for this in drizzled/ field/decimal. cc at the Field_new_ decimal: :store( ) method, it seems that only warnings are ever issued with these types - an error is never printed. The relevant code is:
switch (err) { DRIZZLE_ ERROR:: WARN_LEVEL_ NOTE, ER_WARN_ DATA_TRUNCATED, 1); DRIZZLE_ ERROR:: WARN_LEVEL_ WARN, ER_WARN_ DATA_OUT_ OF_RANGE, 1); on_overflow( &decimal_ value, decimal_ value.sign( )); as_str. copy(from, length, &my_charset_bin);
case E_DEC_TRUNCATED:
set_warning(
break;
case E_DEC_OVERFLOW:
set_warning(
set_value_
break;
case E_DEC_BAD_NUM:
{
/* Because "from" is not NUL-terminated and we use %s in the ER() */
String from_as_str;
from_
push_ warning_ printf( table-> in_use, DRIZZLE_ ERROR:: WARN_LEVEL_ WARN,
ER_TRUNCATED_ WRONG_VALUE_ FOR_FIELD,
ER(ER_ TRUNCATED_ WRONG_VALUE_ FOR_FIELD) ,
"decimal" , from_as_ str.c_ptr( ), field_name,
(uint32_ t) table-> in_use- >row_count) ; set_zero( &decimal_ value);
my_decimal_
break;
}
Should overflow also be an error here?