Commit 66d633b8 authored by unknown's avatar unknown

Fix for bug #11557 (Error during rounding of the DEFAULT values)


mysql-test/r/type_newdecimal.result:
  test result fixed
mysql-test/t/type_newdecimal.test:
  test case added
strings/decimal.c:
  Code to check 999.9 -> 1000 case should work always
parent 2508b29e
...@@ -955,3 +955,26 @@ t1 CREATE TABLE `t1` ( ...@@ -955,3 +955,26 @@ t1 CREATE TABLE `t1` (
`sl` decimal(5,5) default NULL `sl` decimal(5,5) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1; drop table t1;
create table t1 (
f1 decimal unsigned not null default 17.49,
f2 decimal unsigned not null default 17.68,
f3 decimal unsigned not null default 99.2,
f4 decimal unsigned not null default 99.7,
f5 decimal unsigned not null default 104.49,
f6 decimal unsigned not null default 199.91,
f7 decimal unsigned not null default 999.9,
f8 decimal unsigned 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
insert into t1 (f1) values (1);
select * from t1;
f1 f2 f3 f4 f5 f6 f7 f8
1 18 99 100 104 200 1000 10000
drop table t1;
...@@ -998,3 +998,20 @@ create table t1 (sl decimal(0,30)); ...@@ -998,3 +998,20 @@ create table t1 (sl decimal(0,30));
create table t1 (sl decimal(5, 5)); create table t1 (sl decimal(5, 5));
show create table t1; show create table t1;
drop table t1; drop table t1;
#
# Bug 11557 (DEFAULT values rounded improperly
#
create table t1 (
f1 decimal unsigned not null default 17.49,
f2 decimal unsigned not null default 17.68,
f3 decimal unsigned not null default 99.2,
f4 decimal unsigned not null default 99.7,
f5 decimal unsigned not null default 104.49,
f6 decimal unsigned not null default 199.91,
f7 decimal unsigned not null default 999.9,
f8 decimal unsigned not null default 9999.99);
insert into t1 (f1) values (1);
select * from t1;
drop table t1;
...@@ -1443,6 +1443,7 @@ decimal_round(decimal_t *from, decimal_t *to, int scale, ...@@ -1443,6 +1443,7 @@ decimal_round(decimal_t *from, decimal_t *to, int scale,
intg1=ROUND_UP(from->intg + intg1=ROUND_UP(from->intg +
(((intg0 + frac0)>0) && (from->buf[0] == DIG_MAX))); (((intg0 + frac0)>0) && (from->buf[0] == DIG_MAX)));
dec1 *buf0=from->buf, *buf1=to->buf, x, y, carry=0; dec1 *buf0=from->buf, *buf1=to->buf, x, y, carry=0;
int first_dig;
sanity(to); sanity(to);
...@@ -1578,14 +1579,6 @@ decimal_round(decimal_t *from, decimal_t *to, int scale, ...@@ -1578,14 +1579,6 @@ decimal_round(decimal_t *from, decimal_t *to, int scale,
*buf1=1; *buf1=1;
to->intg++; to->intg++;
} }
else
{
/* Here we check 999.9 -> 1000 case when we need to increase intg */
int first_dig= to->intg % DIG_PER_DEC1;
/* first_dig==0 should be handled above in the 'if' */
if (first_dig && (*buf1 >= powers10[first_dig]))
to->intg++;
}
} }
else else
{ {
...@@ -1606,6 +1599,12 @@ decimal_round(decimal_t *from, decimal_t *to, int scale, ...@@ -1606,6 +1599,12 @@ decimal_round(decimal_t *from, decimal_t *to, int scale,
} }
} }
} }
/* Here we check 999.9 -> 1000 case when we need to increase intg */
first_dig= to->intg % DIG_PER_DEC1;
if (first_dig && (*buf1 >= powers10[first_dig]))
to->intg++;
if (scale<0) if (scale<0)
scale=0; scale=0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment