00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #pragma once
00023
00025
00026 #include <drizzled/charset.h>
00027 #include <drizzled/item.h>
00028 #include <drizzled/item/bin_string.h>
00029 #include <drizzled/lex_string.h>
00030 #include <drizzled/sql_list.h>
00031 #include <drizzled/type/decimal.h>
00032
00033 #include <drizzled/visibility.h>
00034
00035 namespace drizzled {
00036
00037 class DRIZZLED_API Item_func : public Item_result_field
00038 {
00039 protected:
00040 Item **args, *tmp_arg[2];
00041
00042
00043
00044
00045 uint32_t allowed_arg_cols;
00046
00047 public:
00048
00049 using Item::split_sum_func;
00050
00051 uint32_t arg_count;
00052 table_map used_tables_cache, not_null_tables_cache;
00053 bool const_item_cache;
00054 enum Functype { UNKNOWN_FUNC,EQ_FUNC,EQUAL_FUNC,NE_FUNC,LT_FUNC,LE_FUNC,
00055 GE_FUNC,GT_FUNC,
00056 LIKE_FUNC,ISNULL_FUNC,ISNOTNULL_FUNC,
00057 COND_AND_FUNC, COND_OR_FUNC, COND_XOR_FUNC,
00058 BETWEEN, IN_FUNC, MULT_EQUAL_FUNC,
00059 INTERVAL_FUNC, ISNOTNULLTEST_FUNC,
00060 NOT_FUNC, NOT_ALL_FUNC,
00061 NOW_FUNC, TRIG_COND_FUNC,
00062 SUSERVAR_FUNC, GUSERVAR_FUNC, COLLATE_FUNC,
00063 EXTRACT_FUNC, CHAR_TYPECAST_FUNC, FUNC_SP,
00064 NEG_FUNC };
00065 enum optimize_type { OPTIMIZE_NONE,OPTIMIZE_KEY,OPTIMIZE_OP, OPTIMIZE_NULL,
00066 OPTIMIZE_EQUAL };
00067 enum Type type() const { return FUNC_ITEM; }
00068 virtual enum Functype functype() const { return UNKNOWN_FUNC; }
00069 virtual ~Item_func() {}
00070
00071 Item_func(void);
00072
00073 Item_func(Item *a);
00074
00075 Item_func(Item *a,Item *b);
00076
00077 Item_func(Item *a,Item *b,Item *c);
00078
00079 Item_func(Item *a,Item *b,Item *c,Item *d);
00080
00081 Item_func(Item *a,Item *b,Item *c,Item *d,Item* e);
00082
00083 Item_func(List<Item> &list);
00084
00085
00086 Item_func(Session *session, Item_func *item);
00087
00088 bool fix_fields(Session *, Item **ref);
00089 void fix_after_pullout(Select_Lex *new_parent, Item **ref);
00090 table_map used_tables() const;
00091 table_map not_null_tables() const;
00092 void update_used_tables();
00093 bool eq(const Item *item, bool binary_cmp) const;
00094 virtual optimize_type select_optimize() const { return OPTIMIZE_NONE; }
00095 virtual bool have_rev_func() const { return 0; }
00096 virtual Item *key_item() const { return args[0]; }
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107 virtual const char *func_name() const { return NULL; }
00108 virtual bool const_item() const { return const_item_cache; }
00109 Item **arguments() const { return args; }
00110 void set_arguments(List<Item> &list);
00111 uint32_t argument_count() const { return arg_count; }
00112 void remove_arguments() { arg_count=0; }
00113
00118 virtual bool check_argument_count(int) { return true ; }
00119 virtual void split_sum_func(Session *session, Item **ref_pointer_array,
00120 List<Item> &fields);
00121
00122 virtual void print(String *str);
00123 void print_op(String *str);
00124 void print_args(String *str, uint32_t from);
00125 virtual void fix_num_length_and_dec();
00126 void count_only_length();
00127 void count_real_length();
00128 void count_decimal_length();
00129
00130 bool get_arg0_date(type::Time <ime, uint32_t fuzzy_date);
00131 bool get_arg0_time(type::Time <ime);
00132
00133 bool is_null();
00134
00135 virtual bool deterministic() const
00136 {
00137 return false;
00138 }
00139
00140 void signal_divide_by_null();
00141
00142 virtual Field *tmp_table_field() { return result_field; }
00143 virtual Field *tmp_table_field(Table *t_arg);
00144
00145 Item *get_tmp_table_item(Session *session);
00146
00147 type::Decimal *val_decimal(type::Decimal *);
00148
00149 bool agg_arg_collations(DTCollation &c, Item **items, uint32_t nitems,
00150 uint32_t flags);
00151 bool agg_arg_collations_for_comparison(DTCollation &c,
00152 Item **items, uint32_t nitems,
00153 uint32_t flags);
00154 bool agg_arg_charsets(DTCollation &c, Item **items, uint32_t nitems,
00155 uint32_t flags, int item_sep);
00156 bool walk(Item_processor processor, bool walk_subquery, unsigned char *arg);
00157 Item *transform(Item_transformer transformer, unsigned char *arg);
00158 Item* compile(Item_analyzer analyzer, unsigned char **arg_p,
00159 Item_transformer transformer, unsigned char *arg_t);
00160 void traverse_cond(Cond_traverser traverser,
00161 void * arg, traverse_order order);
00162 double fix_result(double value);
00163 };
00164
00165 }
00166
00167