#include <item_cmpfunc.h>
Inheritance diagram for Item_func_case:


Public Member Functions | |
| Item_func_case (List< Item > &list, Item *first_expr_arg, Item *else_expr_arg) | |
| double | val_real () |
| longlong | val_int () |
| String * | val_str (String *) |
| my_decimal * | val_decimal (my_decimal *) |
| bool | fix_fields (THD *thd, Item **ref) |
| void | fix_length_and_dec () |
| uint | decimal_precision () const |
| table_map | not_null_tables () const |
| enum Item_result | result_type () const |
| const char * | func_name () const |
| void | print (String *str) |
| Item * | find_item (String *str) |
| CHARSET_INFO * | compare_collation () |
| bool | check_partition_func_processor (byte *bool_arg) |
Private Attributes | |
| int | first_expr_num |
| int | else_expr_num |
| enum Item_result | cached_result_type |
| String | tmp_value |
| uint | ncases |
| Item_result | cmp_type |
| DTCollation | cmp_collation |
Definition at line 591 of file item_cmpfunc.h.
| Item_func_case::Item_func_case | ( | List< Item > & | list, | |
| Item * | first_expr_arg, | |||
| Item * | else_expr_arg | |||
| ) | [inline] |
Definition at line 600 of file item_cmpfunc.h.
References else_expr_num, first_expr_num, list(), ncases, and Item_func::set_arguments().
00601 :Item_func(), first_expr_num(-1), else_expr_num(-1), 00602 cached_result_type(INT_RESULT) 00603 { 00604 ncases= list.elements; 00605 if (first_expr_arg) 00606 { 00607 first_expr_num= list.elements; 00608 list.push_back(first_expr_arg); 00609 } 00610 if (else_expr_arg) 00611 { 00612 else_expr_num= list.elements; 00613 list.push_back(else_expr_arg); 00614 } 00615 set_arguments(list); 00616 }
Here is the call graph for this function:

| CHARSET_INFO* Item_func_case::compare_collation | ( | ) | [inline, virtual] |
Reimplemented from Item.
Definition at line 629 of file item_cmpfunc.h.
References cmp_collation, and DTCollation::collation.
00629 { return cmp_collation.collation; }
| uint Item_func_case::decimal_precision | ( | ) | const [virtual] |
Reimplemented from Item.
Definition at line 1932 of file item_cmpfunc.cc.
References Item_func::args, Item::decimal_int_part(), DECIMAL_MAX_PRECISION, Item::decimals, else_expr_num, min, ncases, and set_if_bigger.
01933 { 01934 int max_int_part=0; 01935 for (uint i=0 ; i < ncases ; i+=2) 01936 set_if_bigger(max_int_part, args[i+1]->decimal_int_part()); 01937 01938 if (else_expr_num != -1) 01939 set_if_bigger(max_int_part, args[else_expr_num]->decimal_int_part()); 01940 return min(max_int_part + decimals, DECIMAL_MAX_PRECISION); 01941 }
Here is the call graph for this function:

Definition at line 1688 of file item_cmpfunc.cc.
References Item_func::args, cmp_collation, cmp_type, DTCollation::collation, DBUG_ASSERT, DECIMAL_RESULT, Item::default_charset(), else_expr_num, first_expr_num, INT_RESULT, LINT_INIT, MAX_FIELD_WIDTH, my_decimal_cmp(), ncases, Item::null_value, REAL_RESULT, ROW_RESULT, sortcmp(), STRING_RESULT, Item::val_bool(), val_decimal(), Item::val_decimal(), val_int(), Item::val_int(), val_real(), Item::val_real(), val_str(), and value.
Referenced by val_decimal(), val_int(), val_real(), and val_str().
01689 { 01690 String *first_expr_str, *tmp; 01691 my_decimal *first_expr_dec, first_expr_dec_val; 01692 longlong first_expr_int; 01693 double first_expr_real; 01694 char buff[MAX_FIELD_WIDTH]; 01695 String buff_str(buff,sizeof(buff),default_charset()); 01696 01697 /* These will be initialized later */ 01698 LINT_INIT(first_expr_str); 01699 LINT_INIT(first_expr_int); 01700 LINT_INIT(first_expr_real); 01701 LINT_INIT(first_expr_dec); 01702 01703 if (first_expr_num != -1) 01704 { 01705 switch (cmp_type) 01706 { 01707 case STRING_RESULT: 01708 // We can't use 'str' here as this may be overwritten 01709 if (!(first_expr_str= args[first_expr_num]->val_str(&buff_str))) 01710 return else_expr_num != -1 ? args[else_expr_num] : 0; // Impossible 01711 break; 01712 case INT_RESULT: 01713 first_expr_int= args[first_expr_num]->val_int(); 01714 if (args[first_expr_num]->null_value) 01715 return else_expr_num != -1 ? args[else_expr_num] : 0; 01716 break; 01717 case REAL_RESULT: 01718 first_expr_real= args[first_expr_num]->val_real(); 01719 if (args[first_expr_num]->null_value) 01720 return else_expr_num != -1 ? args[else_expr_num] : 0; 01721 break; 01722 case DECIMAL_RESULT: 01723 first_expr_dec= args[first_expr_num]->val_decimal(&first_expr_dec_val); 01724 if (args[first_expr_num]->null_value) 01725 return else_expr_num != -1 ? args[else_expr_num] : 0; 01726 break; 01727 case ROW_RESULT: 01728 default: 01729 // This case should never be chosen 01730 DBUG_ASSERT(0); 01731 break; 01732 } 01733 } 01734 01735 // Compare every WHEN argument with it and return the first match 01736 for (uint i=0 ; i < ncases ; i+=2) 01737 { 01738 if (first_expr_num == -1) 01739 { 01740 // No expression between CASE and the first WHEN 01741 if (args[i]->val_bool()) 01742 return args[i+1]; 01743 continue; 01744 } 01745 switch (cmp_type) { 01746 case STRING_RESULT: 01747 if ((tmp=args[i]->val_str(str))) // If not null 01748 if (sortcmp(tmp,first_expr_str,cmp_collation.collation)==0) 01749 return args[i+1]; 01750 break; 01751 case INT_RESULT: 01752 if (args[i]->val_int()==first_expr_int && !args[i]->null_value) 01753 return args[i+1]; 01754 break; 01755 case REAL_RESULT: 01756 if (args[i]->val_real() == first_expr_real && !args[i]->null_value) 01757 return args[i+1]; 01758 break; 01759 case DECIMAL_RESULT: 01760 { 01761 my_decimal value; 01762 if (my_decimal_cmp(args[i]->val_decimal(&value), first_expr_dec) == 0) 01763 return args[i+1]; 01764 break; 01765 } 01766 case ROW_RESULT: 01767 default: 01768 // This case should never be chosen 01769 DBUG_ASSERT(0); 01770 break; 01771 } 01772 } 01773 // No, WHEN clauses all missed, return ELSE expression 01774 return else_expr_num != -1 ? args[else_expr_num] : 0; 01775 }
Here is the call graph for this function:

Here is the caller graph for this function:

Reimplemented from Item_func.
Definition at line 1853 of file item_cmpfunc.cc.
References check_stack_overrun(), Item_func::fix_fields(), MAX_FIELD_WIDTH, STACK_MIN_SIZE, and TRUE.
01854 { 01855 /* 01856 buff should match stack usage from 01857 Item_func_case::val_int() -> Item_func_case::find_item() 01858 */ 01859 char buff[MAX_FIELD_WIDTH*2+sizeof(String)*2+sizeof(String*)*2+sizeof(double)*2+sizeof(longlong)*2]; 01860 bool res= Item_func::fix_fields(thd, ref); 01861 /* 01862 Call check_stack_overrun after fix_fields to be sure that stack variable 01863 is not optimized away 01864 */ 01865 if (check_stack_overrun(thd, STACK_MIN_SIZE, buff)) 01866 return TRUE; // Fatal error flag is set! 01867 return res; 01868 }
Here is the call graph for this function:

| void Item_func_case::fix_length_and_dec | ( | ) | [virtual] |
Implements Item_result_field.
Definition at line 1872 of file item_cmpfunc.cc.
References Item_func::agg_arg_charsets(), agg_cmp_type(), agg_result_type(), Item_func::args, cached_result_type, cmp_collation, cmp_type, Item::collation, current_thd, Item::decimals, else_expr_num, first_expr_num, Item::max_length, Item::maybe_null, MY_COLL_ALLOW_CONV, MY_COLL_CMP_CONV, ncases, set_if_bigger, sql_alloc(), and STRING_RESULT.
01873 { 01874 Item **agg; 01875 uint nagg; 01876 THD *thd= current_thd; 01877 01878 if (!(agg= (Item**) sql_alloc(sizeof(Item*)*(ncases+1)))) 01879 return; 01880 01881 /* 01882 Aggregate all THEN and ELSE expression types 01883 and collations when string result 01884 */ 01885 01886 for (nagg= 0 ; nagg < ncases/2 ; nagg++) 01887 agg[nagg]= args[nagg*2+1]; 01888 01889 if (else_expr_num != -1) 01890 agg[nagg++]= args[else_expr_num]; 01891 01892 agg_result_type(&cached_result_type, agg, nagg); 01893 if ((cached_result_type == STRING_RESULT) && 01894 agg_arg_charsets(collation, agg, nagg, MY_COLL_ALLOW_CONV, 1)) 01895 return; 01896 01897 01898 /* 01899 Aggregate first expression and all THEN expression types 01900 and collations when string comparison 01901 */ 01902 if (first_expr_num != -1) 01903 { 01904 agg[0]= args[first_expr_num]; 01905 for (nagg= 0; nagg < ncases/2 ; nagg++) 01906 agg[nagg+1]= args[nagg*2]; 01907 nagg++; 01908 agg_cmp_type(thd, &cmp_type, agg, nagg); 01909 if ((cmp_type == STRING_RESULT) && 01910 agg_arg_charsets(cmp_collation, agg, nagg, MY_COLL_CMP_CONV, 1)) 01911 return; 01912 } 01913 01914 if (else_expr_num == -1 || args[else_expr_num]->maybe_null) 01915 maybe_null=1; 01916 01917 max_length=0; 01918 decimals=0; 01919 for (uint i=0 ; i < ncases ; i+=2) 01920 { 01921 set_if_bigger(max_length,args[i+1]->max_length); 01922 set_if_bigger(decimals,args[i+1]->decimals); 01923 } 01924 if (else_expr_num != -1) 01925 { 01926 set_if_bigger(max_length,args[else_expr_num]->max_length); 01927 set_if_bigger(decimals,args[else_expr_num]->decimals); 01928 } 01929 }
Here is the call graph for this function:

| const char* Item_func_case::func_name | ( | ) | const [inline, virtual] |
| table_map Item_func_case::not_null_tables | ( | ) | const [inline, virtual] |
| void Item_func_case::print | ( | String * | str | ) | [virtual] |
Reimplemented from Item_func.
Definition at line 1946 of file item_cmpfunc.cc.
References String::append(), Item_func::args, else_expr_num, first_expr_num, ncases, Item::print(), and STRING_WITH_LEN.
01947 { 01948 str->append(STRING_WITH_LEN("(case ")); 01949 if (first_expr_num != -1) 01950 { 01951 args[first_expr_num]->print(str); 01952 str->append(' '); 01953 } 01954 for (uint i=0 ; i < ncases ; i+=2) 01955 { 01956 str->append(STRING_WITH_LEN("when ")); 01957 args[i]->print(str); 01958 str->append(STRING_WITH_LEN(" then ")); 01959 args[i+1]->print(str); 01960 str->append(' '); 01961 } 01962 if (else_expr_num != -1) 01963 { 01964 str->append(STRING_WITH_LEN("else ")); 01965 args[else_expr_num]->print(str); 01966 str->append(' '); 01967 } 01968 str->append(STRING_WITH_LEN("end)")); 01969 }
Here is the call graph for this function:

| enum Item_result Item_func_case::result_type | ( | ) | const [inline, virtual] |
Reimplemented from Item.
Definition at line 625 of file item_cmpfunc.h.
References cached_result_type.
00625 { return cached_result_type; }
| my_decimal * Item_func_case::val_decimal | ( | my_decimal * | ) | [virtual] |
Reimplemented from Item_func.
Definition at line 1833 of file item_cmpfunc.cc.
References DBUG_ASSERT, Item::default_charset(), find_item(), Item::fixed, MAX_FIELD_WIDTH, Item::null_value, and Item::val_decimal().
Referenced by find_item().
01834 { 01835 DBUG_ASSERT(fixed == 1); 01836 char buff[MAX_FIELD_WIDTH]; 01837 String dummy_str(buff, sizeof(buff), default_charset()); 01838 Item *item= find_item(&dummy_str); 01839 my_decimal *res; 01840 01841 if (!item) 01842 { 01843 null_value=1; 01844 return 0; 01845 } 01846 01847 res= item->val_decimal(decimal_value); 01848 null_value= item->null_value; 01849 return res; 01850 }
Here is the call graph for this function:

Here is the caller graph for this function:

| longlong Item_func_case::val_int | ( | ) | [virtual] |
Implements Item.
Definition at line 1796 of file item_cmpfunc.cc.
References DBUG_ASSERT, Item::default_charset(), find_item(), Item::fixed, MAX_FIELD_WIDTH, Item::null_value, and Item::val_int().
Referenced by find_item().
01797 { 01798 DBUG_ASSERT(fixed == 1); 01799 char buff[MAX_FIELD_WIDTH]; 01800 String dummy_str(buff,sizeof(buff),default_charset()); 01801 Item *item=find_item(&dummy_str); 01802 longlong res; 01803 01804 if (!item) 01805 { 01806 null_value=1; 01807 return 0; 01808 } 01809 res=item->val_int(); 01810 null_value=item->null_value; 01811 return res; 01812 }
Here is the call graph for this function:

Here is the caller graph for this function:

| double Item_func_case::val_real | ( | ) | [virtual] |
Implements Item.
Definition at line 1814 of file item_cmpfunc.cc.
References DBUG_ASSERT, Item::default_charset(), find_item(), Item::fixed, MAX_FIELD_WIDTH, Item::null_value, and Item::val_real().
Referenced by find_item().
01815 { 01816 DBUG_ASSERT(fixed == 1); 01817 char buff[MAX_FIELD_WIDTH]; 01818 String dummy_str(buff,sizeof(buff),default_charset()); 01819 Item *item=find_item(&dummy_str); 01820 double res; 01821 01822 if (!item) 01823 { 01824 null_value=1; 01825 return 0; 01826 } 01827 res= item->val_real(); 01828 null_value=item->null_value; 01829 return res; 01830 }
Here is the call graph for this function:

Here is the caller graph for this function:

Implements Item.
Definition at line 1778 of file item_cmpfunc.cc.
References DBUG_ASSERT, find_item(), Item::fixed, Item::null_value, and Item::val_str().
Referenced by find_item().
01779 { 01780 DBUG_ASSERT(fixed == 1); 01781 String *res; 01782 Item *item=find_item(str); 01783 01784 if (!item) 01785 { 01786 null_value=1; 01787 return 0; 01788 } 01789 null_value= 0; 01790 if (!(res=item->val_str(str))) 01791 null_value= 1; 01792 return res; 01793 }
Here is the call graph for this function:

Here is the caller graph for this function:

enum Item_result Item_func_case::cached_result_type [private] |
Definition at line 594 of file item_cmpfunc.h.
Referenced by fix_length_and_dec(), and result_type().
DTCollation Item_func_case::cmp_collation [private] |
Definition at line 598 of file item_cmpfunc.h.
Referenced by compare_collation(), find_item(), and fix_length_and_dec().
Item_result Item_func_case::cmp_type [private] |
int Item_func_case::else_expr_num [private] |
Definition at line 593 of file item_cmpfunc.h.
Referenced by decimal_precision(), find_item(), fix_length_and_dec(), Item_func_case(), and print().
int Item_func_case::first_expr_num [private] |
Definition at line 593 of file item_cmpfunc.h.
Referenced by find_item(), fix_length_and_dec(), Item_func_case(), and print().
uint Item_func_case::ncases [private] |
Definition at line 596 of file item_cmpfunc.h.
Referenced by decimal_precision(), find_item(), fix_length_and_dec(), Item_func_case(), and print().
String Item_func_case::tmp_value [private] |
Definition at line 595 of file item_cmpfunc.h.
1.4.7

