mirror of
				https://github.com/MariaDB/server.git
				synced 2025-11-03 14:33:32 +03:00 
			
		
		
		
	Fixed bug #28980: the result of ROUND(<decimal expr>,<int column>)
was erroneously converted to double, while the result of ROUND(<decimal expr>, <int literal>) was preserved as decimal. As a result of such a conversion the value of ROUND(D,A) could differ from the value of ROUND(D,val(A)) if D was a decimal expression. Now the result of the ROUND function is never converted to double if the first argument is decimal. mysql-test/r/type_decimal.result: Added a test case for bug #28980. mysql-test/t/type_decimal.test: Added a test case for bug #28980.
This commit is contained in:
		@@ -790,3 +790,12 @@ Warning	1292	Truncated incorrect datetime value: '0000-00-00'
 | 
				
			|||||||
Warning	1292	Truncated incorrect datetime value: '0000-00-00'
 | 
					Warning	1292	Truncated incorrect datetime value: '0000-00-00'
 | 
				
			||||||
Warning	1292	Truncated incorrect datetime value: '0000-00-00'
 | 
					Warning	1292	Truncated incorrect datetime value: '0000-00-00'
 | 
				
			||||||
drop table t1;
 | 
					drop table t1;
 | 
				
			||||||
 | 
					CREATE TABLE t1 (
 | 
				
			||||||
 | 
					qty decimal(16,6) default NULL, 
 | 
				
			||||||
 | 
					dps tinyint(3) unsigned default NULL 
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
 | 
					INSERT INTO t1 VALUES (1.1325,3);
 | 
				
			||||||
 | 
					SELECT ROUND(qty,3), dps, ROUND(qty,dps) FROM t1;
 | 
				
			||||||
 | 
					ROUND(qty,3)	dps	ROUND(qty,dps)
 | 
				
			||||||
 | 
					1.133	3	1.133
 | 
				
			||||||
 | 
					DROP TABLE t1;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -394,3 +394,17 @@ create table t1 as
 | 
				
			|||||||
 from (select 1 as s,'t' as t union select null, null ) as sub1;
 | 
					 from (select 1 as s,'t' as t union select null, null ) as sub1;
 | 
				
			||||||
select group_concat(t) from t1 group by week(date)/10;
 | 
					select group_concat(t) from t1 group by week(date)/10;
 | 
				
			||||||
drop table t1;
 | 
					drop table t1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# Bug#28980: ROUND(<dec expr>, <int col>) returned double values
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CREATE TABLE t1 (
 | 
				
			||||||
 | 
					  qty decimal(16,6) default NULL, 
 | 
				
			||||||
 | 
					  dps tinyint(3) unsigned default NULL 
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
 | 
					INSERT INTO t1 VALUES (1.1325,3);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					SELECT ROUND(qty,3), dps, ROUND(qty,dps) FROM t1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DROP TABLE t1;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1957,7 +1957,13 @@ void Item_func_round::fix_length_and_dec()
 | 
				
			|||||||
  {
 | 
					  {
 | 
				
			||||||
    max_length= args[0]->max_length;
 | 
					    max_length= args[0]->max_length;
 | 
				
			||||||
    decimals= args[0]->decimals;
 | 
					    decimals= args[0]->decimals;
 | 
				
			||||||
    hybrid_type= REAL_RESULT;
 | 
					    if (args[0]->result_type() == DECIMAL_RESULT)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      max_length++;
 | 
				
			||||||
 | 
					      hybrid_type= DECIMAL_RESULT;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					      hybrid_type= REAL_RESULT;
 | 
				
			||||||
    return;
 | 
					    return;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user