diff options
Diffstat (limited to 'sql/item_cmpfunc.cc')
-rw-r--r-- | sql/item_cmpfunc.cc | 55 |
1 files changed, 32 insertions, 23 deletions
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index 85565b735d4..8c0f22b0947 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -2374,6 +2374,7 @@ void Item_func_between::print(String *str, enum_query_type query_type) void Item_func_ifnull::fix_length_and_dec() { + uint32 char_length; agg_result_type(&hybrid_type, args, 2); maybe_null=args[1]->maybe_null; decimals= max(args[0]->decimals, args[1]->decimals); @@ -2381,20 +2382,21 @@ Item_func_ifnull::fix_length_and_dec() if (hybrid_type == DECIMAL_RESULT || hybrid_type == INT_RESULT) { - int len0= args[0]->max_length - args[0]->decimals + int len0= args[0]->max_char_length() - args[0]->decimals - (args[0]->unsigned_flag ? 0 : 1); - int len1= args[1]->max_length - args[1]->decimals + int len1= args[1]->max_char_length() - args[1]->decimals - (args[1]->unsigned_flag ? 0 : 1); - max_length= max(len0, len1) + decimals + (unsigned_flag ? 0 : 1); + char_length= max(len0, len1) + decimals + (unsigned_flag ? 0 : 1); } else - max_length= max(args[0]->max_length, args[1]->max_length); + char_length= max(args[0]->max_char_length(), args[1]->max_char_length()); switch (hybrid_type) { case STRING_RESULT: - agg_arg_charsets_for_comparison(collation, args, arg_count); + if (agg_arg_charsets_for_comparison(collation, args, arg_count)) + return; break; case DECIMAL_RESULT: case REAL_RESULT: @@ -2406,6 +2408,7 @@ Item_func_ifnull::fix_length_and_dec() default: DBUG_ASSERT(0); } + fix_char_length(char_length); cached_field_type= agg_field_type(args, 2); } @@ -2557,28 +2560,32 @@ Item_func_if::fix_length_and_dec() cached_result_type= arg2_type; collation.set(args[2]->collation.collation); cached_field_type= args[2]->field_type(); + max_length= args[2]->max_length; + return; } - else if (null2) + + if (null2) { cached_result_type= arg1_type; collation.set(args[1]->collation.collation); cached_field_type= args[1]->field_type(); + max_length= args[1]->max_length; + return; + } + + agg_result_type(&cached_result_type, args + 1, 2); + if (cached_result_type == STRING_RESULT) + { + if (agg_arg_charsets_for_string_result(collation, args + 1, 2)) + return; } else { - agg_result_type(&cached_result_type, args+1, 2); - if (cached_result_type == STRING_RESULT) - { - if (agg_arg_charsets_for_string_result(collation, args + 1, 2)) - return; - } - else - { - collation.set_numeric(); // Number - } - cached_field_type= agg_field_type(args + 1, 2); + collation.set_numeric(); // Number } + cached_field_type= agg_field_type(args + 1, 2); + uint32 char_length; if ((cached_result_type == DECIMAL_RESULT ) || (cached_result_type == INT_RESULT)) { @@ -2588,10 +2595,11 @@ Item_func_if::fix_length_and_dec() int len2= args[2]->max_length - args[2]->decimals - (args[2]->unsigned_flag ? 0 : 1); - max_length=max(len1, len2) + decimals + (unsigned_flag ? 0 : 1); + char_length= max(len1, len2) + decimals + (unsigned_flag ? 0 : 1); } else - max_length= max(args[1]->max_length, args[2]->max_length); + char_length= max(args[1]->max_char_length(), args[2]->max_char_length()); + fix_char_length(char_length); } @@ -2901,7 +2909,7 @@ bool Item_func_case::fix_fields(THD *thd, Item **ref) void Item_func_case::agg_str_lengths(Item* arg) { - set_if_bigger(max_length, arg->max_length); + fix_char_length(max(max_char_length(), arg->max_char_length())); set_if_bigger(decimals, arg->decimals); unsigned_flag= unsigned_flag && arg->unsigned_flag; } @@ -3129,9 +3137,10 @@ void Item_func_coalesce::fix_length_and_dec() agg_result_type(&hybrid_type, args, arg_count); switch (hybrid_type) { case STRING_RESULT: - count_only_length(); decimals= NOT_FIXED_DEC; - agg_arg_charsets_for_string_result(collation, args, arg_count); + if (agg_arg_charsets_for_string_result(collation, args, arg_count)) + return; + count_only_length(); break; case DECIMAL_RESULT: count_decimal_length(); @@ -4617,7 +4626,7 @@ bool Item_func_like::fix_fields(THD *thd, Item **ref) return TRUE; } - if (escape_item->const_item()) + if (escape_item->const_item() && !thd->lex->view_prepare_mode) { /* If we are on execution stage */ String *escape_str= escape_item->val_str(&cmp.value1); |