diff options
author | gshchepa/uchum@gleb.loc <> | 2007-10-10 20:14:29 +0500 |
---|---|---|
committer | gshchepa/uchum@gleb.loc <> | 2007-10-10 20:14:29 +0500 |
commit | 356007a8a4573d5f57794e8e627a9632dc703ce0 (patch) | |
tree | a19eadf72920454b1d8a34ad78b169d71dd0600b /sql/item_cmpfunc.cc | |
parent | 20ec6605d349c3cfa5c062a9818612616bbe3baa (diff) | |
download | mariadb-git-356007a8a4573d5f57794e8e627a9632dc703ce0.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.
Diffstat (limited to 'sql/item_cmpfunc.cc')
-rw-r--r-- | sql/item_cmpfunc.cc | 18 |
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: |