2628
void Item_func_if::cache_type_info(Item *source)
2630
collation.set(source->collation);
2631
cached_field_type= source->field_type();
2632
cached_result_type= source->result_type();
2633
decimals= source->decimals;
2634
max_length= source->max_length;
2635
maybe_null= source->maybe_null;
2636
unsigned_flag= source->unsigned_flag;
2629
2641
Item_func_if::fix_length_and_dec()
2631
maybe_null=args[1]->maybe_null || args[2]->maybe_null;
2643
// Let IF(cond, expr, NULL) and IF(cond, NULL, expr) inherit type from expr.
2644
if (args[1]->type() == NULL_ITEM)
2646
cache_type_info(args[2]);
2648
// If both arguments are NULL, make resulting type BINARY(0).
2649
if (args[2]->type() == NULL_ITEM)
2650
cached_field_type= MYSQL_TYPE_STRING;
2653
if (args[2]->type() == NULL_ITEM)
2655
cache_type_info(args[1]);
2660
agg_result_type(&cached_result_type, args + 1, 2);
2661
maybe_null= args[1]->maybe_null || args[2]->maybe_null;
2632
2662
decimals= max(args[1]->decimals, args[2]->decimals);
2633
2663
unsigned_flag=args[1]->unsigned_flag && args[2]->unsigned_flag;
2635
enum Item_result arg1_type=args[1]->result_type();
2636
enum Item_result arg2_type=args[2]->result_type();
2637
bool null1=args[1]->const_item() && args[1]->null_value;
2638
bool null2=args[2]->const_item() && args[2]->null_value;
2642
cached_result_type= arg2_type;
2643
collation.set(args[2]->collation);
2644
cached_field_type= args[2]->field_type();
2645
max_length= args[2]->max_length;
2651
cached_result_type= arg1_type;
2652
collation.set(args[1]->collation);
2653
cached_field_type= args[1]->field_type();
2654
max_length= args[1]->max_length;
2658
agg_result_type(&cached_result_type, args + 1, 2);
2659
2665
if (cached_result_type == STRING_RESULT)
2661
2667
if (agg_arg_charsets_for_string_result(collation, args + 1, 2))