summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <hf@deer.(none)>2005-07-12 16:02:35 +0500
committerunknown <hf@deer.(none)>2005-07-12 16:02:35 +0500
commit8115f6df53570260bef834ff7a4bff284f021785 (patch)
treecc794555f26d77dd23e7ded05ce4388a7ee9fea2
parent358b6930e1a08747eca7ae3273956884cbf0380d (diff)
parent66d633b8b3a1d2fc83f1a99e75051011bb70b5e9 (diff)
downloadmariadb-git-8115f6df53570260bef834ff7a4bff284f021785.tar.gz
Merge bk@192.168.21.1:/usr/home/bk/mysql-5.0
into deer.(none):/home/hf/work/mysql-5.0.clean
-rw-r--r--mysql-test/r/type_newdecimal.result23
-rw-r--r--mysql-test/t/type_newdecimal.test17
-rw-r--r--strings/decimal.c15
3 files changed, 47 insertions, 8 deletions
diff --git a/mysql-test/r/type_newdecimal.result b/mysql-test/r/type_newdecimal.result
index 964a69ffb12..aed2a478c0e 100644
--- a/mysql-test/r/type_newdecimal.result
+++ b/mysql-test/r/type_newdecimal.result
@@ -955,3 +955,26 @@ t1 CREATE TABLE `t1` (
`sl` decimal(5,5) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
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;
diff --git a/mysql-test/t/type_newdecimal.test b/mysql-test/t/type_newdecimal.test
index 55d004b361f..f54c8d80f09 100644
--- a/mysql-test/t/type_newdecimal.test
+++ b/mysql-test/t/type_newdecimal.test
@@ -998,3 +998,20 @@ create table t1 (sl decimal(0,30));
create table t1 (sl decimal(5, 5));
show create 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;
+
diff --git a/strings/decimal.c b/strings/decimal.c
index 76e62080ba0..1d75502f0da 100644
--- a/strings/decimal.c
+++ b/strings/decimal.c
@@ -1443,6 +1443,7 @@ decimal_round(decimal_t *from, decimal_t *to, int scale,
intg1=ROUND_UP(from->intg +
(((intg0 + frac0)>0) && (from->buf[0] == DIG_MAX)));
dec1 *buf0=from->buf, *buf1=to->buf, x, y, carry=0;
+ int first_dig;
sanity(to);
@@ -1578,14 +1579,6 @@ decimal_round(decimal_t *from, decimal_t *to, int scale,
*buf1=1;
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
{
@@ -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)
scale=0;