summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorunknown <gshchepa/uchum@gleb.loc>2007-10-10 20:14:29 +0500
committerunknown <gshchepa/uchum@gleb.loc>2007-10-10 20:14:29 +0500
commitc866f8015fcfd56c42f52865c0e89a50c055f6f8 (patch)
treea19eadf72920454b1d8a34ad78b169d71dd0600b /sql
parent6146c0c75d013b15ea2c6656ee0d774498734fd2 (diff)
downloadmariadb-git-c866f8015fcfd56c42f52865c0e89a50c055f6f8.tar.gz
Fixed bug #31471: decimal_bin_size: Assertion `scale >= 0 &&
precision > 0 && scale <= precision'. A sign of a resulting item of the IFNULL function was not updated and the maximal length of this result was calculated improperly. Correct algorithm was copy&pasted from the IF function implementation. sql/item_cmpfunc.cc: Fixed bug #31471. The Item_func_ifnull::fix_length_and_dec method has been modified to update the Item_func_ifnull::unsigned_flag field and to take this field into account when calculating the Item_func_ifnull::max_length value. (See Item_func_if::fix_length_and_dec for reference). mysql-test/t/null.test: Added test case for bug #31471. mysql-test/r/null.result: Added test case for bug #31471. mysql-test/r/create.result: Update test case after the bugfix of bug #31471.
Diffstat (limited to 'sql')
-rw-r--r--sql/item_cmpfunc.cc18
1 files changed, 14 insertions, 4 deletions
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc
index 1599bcc1571..789b0f7edc0 100644
--- a/sql/item_cmpfunc.cc
+++ b/sql/item_cmpfunc.cc
@@ -2020,10 +2020,20 @@ Item_func_ifnull::fix_length_and_dec()
agg_result_type(&hybrid_type, args, 2);
maybe_null=args[1]->maybe_null;
decimals= max(args[0]->decimals, args[1]->decimals);
- max_length= (hybrid_type == DECIMAL_RESULT || hybrid_type == INT_RESULT) ?
- (max(args[0]->max_length - args[0]->decimals,
- args[1]->max_length - args[1]->decimals) + decimals) :
- max(args[0]->max_length, args[1]->max_length);
+ unsigned_flag= args[0]->unsigned_flag && args[1]->unsigned_flag;
+
+ if (hybrid_type == DECIMAL_RESULT || hybrid_type == INT_RESULT)
+ {
+ int len0= args[0]->max_length - args[0]->decimals
+ - (args[0]->unsigned_flag ? 0 : 1);
+
+ int len1= args[1]->max_length - args[1]->decimals
+ - (args[1]->unsigned_flag ? 0 : 1);
+
+ max_length= max(len0, len1) + decimals + (unsigned_flag ? 0 : 1);
+ }
+ else
+ max_length= max(args[0]->max_length, args[1]->max_length);
switch (hybrid_type) {
case STRING_RESULT: