From 76bc67711723bfa0eeda33798c706d9e333bbb30 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 11 May 2004 12:19:37 +0200 Subject: bug#3612 - Item_func_div set decimals incorrectly --- mysql-test/r/type_float.result | 15 +++++++++++++++ mysql-test/t/type_float.test | 8 ++++++++ sql/item_func.cc | 1 + 3 files changed, 24 insertions(+) diff --git a/mysql-test/r/type_float.result b/mysql-test/r/type_float.result index e85bced353a..c9996e9c9f3 100644 --- a/mysql-test/r/type_float.result +++ b/mysql-test/r/type_float.result @@ -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 diff --git a/mysql-test/t/type_float.test b/mysql-test/t/type_float.test index 23941ad2913..65d594387b9 100644 --- a/mysql-test/t/type_float.test +++ b/mysql-test/t/type_float.test @@ -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 # diff --git a/sql/item_func.cc b/sql/item_func.cc index 9d1f784fc25..368c14cc8df 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -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); -- cgit v1.2.1