00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <config.h>
00021
00022 #include "elt.h"
00023
00024 namespace drizzled
00025 {
00026
00027 void Item_func_elt::fix_length_and_dec()
00028 {
00029 max_length=0;
00030 decimals=0;
00031
00032 if (agg_arg_charsets(collation, args+1, arg_count-1, MY_COLL_ALLOW_CONV, 1))
00033 return;
00034
00035 for (uint32_t i= 1 ; i < arg_count ; i++)
00036 {
00037 set_if_bigger(max_length,args[i]->max_length);
00038 set_if_bigger(decimals,args[i]->decimals);
00039 }
00040 maybe_null=1;
00041 }
00042
00043
00044 double Item_func_elt::val_real()
00045 {
00046 assert(fixed == 1);
00047 uint32_t tmp;
00048 null_value=1;
00049 if ((tmp=(uint) args[0]->val_int()) == 0 || tmp >= arg_count)
00050 return 0.0;
00051 double result= args[tmp]->val_real();
00052 null_value= args[tmp]->null_value;
00053 return result;
00054 }
00055
00056 int64_t Item_func_elt::val_int()
00057 {
00058 assert(fixed == 1);
00059 uint32_t tmp;
00060 null_value=1;
00061 if ((tmp=(uint) args[0]->val_int()) == 0 || tmp >= arg_count)
00062 return 0;
00063
00064 int64_t result= args[tmp]->val_int();
00065 null_value= args[tmp]->null_value;
00066 return result;
00067 }
00068
00069
00070 String *Item_func_elt::val_str(String *str)
00071 {
00072 assert(fixed == 1);
00073 uint32_t tmp;
00074 null_value=1;
00075 if ((tmp=(uint) args[0]->val_int()) == 0 || tmp >= arg_count)
00076 return NULL;
00077
00078 String *result= args[tmp]->val_str(str);
00079 if (result)
00080 result->set_charset(collation.collation);
00081 null_value= args[tmp]->null_value;
00082 return result;
00083 }
00084
00085 }