summaryrefslogtreecommitdiff
path: root/sql/item.cc
diff options
context:
space:
mode:
authorunknown <hf@deer.(none)>2005-09-27 15:11:39 +0500
committerunknown <hf@deer.(none)>2005-09-27 15:11:39 +0500
commit087f7cc82adf16138f701cede7d295778db06681 (patch)
tree3a2825c14b94739213cdacde3f03625e8237036c /sql/item.cc
parentab7ec7ee8f4ac8c751c6f0d84d8314154146bf10 (diff)
downloadmariadb-git-087f7cc82adf16138f701cede7d295778db06681.tar.gz
Fix for bug #13372 (decimal union)
mysql-test/r/type_decimal.result: test result fixed mysql-test/r/type_float.result: test result fixed mysql-test/t/type_decimal.test: test case added mysql-test/t/type_float.test: test case added sql/item.cc: Fixed counting of the max_length for the REAL_RESULT
Diffstat (limited to 'sql/item.cc')
-rw-r--r--sql/item.cc24
1 files changed, 22 insertions, 2 deletions
diff --git a/sql/item.cc b/sql/item.cc
index 010189c321c..ec83cc1f511 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -3205,9 +3205,14 @@ enum_field_types Item_type_holder::get_real_type(Item *item)
bool Item_type_holder::join_types(THD *thd, Item *item)
{
+ uint max_length_orig= max_length;
+ uint decimals_orig= decimals;
max_length= max(max_length, display_length(item));
+ decimals= max(decimals, item->decimals);
fld_type= Field::field_type_merge(fld_type, get_real_type(item));
- if (Field::result_merge_type(fld_type) == STRING_RESULT)
+ switch (Field::result_merge_type(fld_type))
+ {
+ case STRING_RESULT:
{
const char *old_cs, *old_derivation;
old_cs= collation.collation->name;
@@ -3221,8 +3226,23 @@ bool Item_type_holder::join_types(THD *thd, Item *item)
"UNION");
return TRUE;
}
+ break;
}
- decimals= max(decimals, item->decimals);
+ case REAL_RESULT:
+ {
+ decimals= max(decimals, item->decimals);
+ if (decimals != NOT_FIXED_DEC)
+ {
+ int delta1= max_length_orig - decimals_orig;
+ int delta2= item->max_length - item->decimals;
+ max_length= max(delta1, delta2) + decimals;
+ }
+ else
+ max_length= (fld_type == MYSQL_TYPE_FLOAT) ? FLT_DIG+6 : DBL_DIG+7;
+ break;
+ }
+ default:;
+ };
maybe_null|= item->maybe_null;
get_full_info(item);
return FALSE;