Commit 3c1658ac authored by unknown's avatar unknown

bug#3612 - Item_func_div set decimals incorrectly

parent b0ecad8e
......@@ -67,6 +67,21 @@ select min(a) from t1;
min(a)
-0.010
drop table t1;
create table t1 (c1 double, c2 varchar(20));
insert t1 values (121,"16");
select c1 + c1 * (c2 / 100) as col from t1;
col
140.36
create table t2 select c1 + c1 * (c2 / 100) as col from t1;
select * from t2;
col
140.36
show create table t2;
Table Create Table
t2 CREATE TABLE `t2` (
`col` double default NULL
) TYPE=MyISAM
drop table t1,t2;
create table t1 (f float, f2 float(24), f3 float(6,2), d double, d2 float(53), d3 double(10,3), de decimal, de2 decimal(6), de3 decimal(5,2), n numeric, n2 numeric(8), n3 numeric(5,6));
show full columns from t1;
Field Type Null Key Default Extra Privileges
......
......@@ -28,6 +28,14 @@ select a from t1 order by a;
select min(a) from t1;
drop table t1;
create table t1 (c1 double, c2 varchar(20));
insert t1 values (121,"16");
select c1 + c1 * (c2 / 100) as col from t1;
create table t2 select c1 + c1 * (c2 / 100) as col from t1;
select * from t2;
show create table t2;
drop table t1,t2;
#
# FLOAT/DOUBLE/DECIMAL handling
#
......
......@@ -402,6 +402,7 @@ longlong Item_func_div::val_int()
void Item_func_div::fix_length_and_dec()
{
decimals=max(args[0]->decimals,args[1]->decimals)+2;
set_if_smaller(decimals, NOT_FIXED_DEC);
max_length=args[0]->max_length - args[0]->decimals + decimals;
uint tmp=float_length(decimals);
set_if_smaller(max_length,tmp);
......
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