~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item_func.h

  • Committer: Monty Taylor
  • Date: 2008-10-08 00:14:19 UTC
  • mto: This revision was merged to the branch mainline in revision 491.
  • Revision ID: monty@inaugust.com-20081008001419-tg3g62sm9e3yz9q4
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one)

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
}
34
34
#endif
35
35
 
36
 
class Item_func :public Item_result_field
37
 
{
38
 
protected:
39
 
  Item **args, *tmp_arg[2];
40
 
  /*
41
 
    Allowed numbers of columns in result (usually 1, which means scalar value)
42
 
    0 means get this number from first argument
43
 
  */
44
 
  uint32_t allowed_arg_cols;
45
 
public:
46
 
  uint32_t arg_count;
47
 
  table_map used_tables_cache, not_null_tables_cache;
48
 
  bool const_item_cache;
49
 
  enum Functype { UNKNOWN_FUNC,EQ_FUNC,EQUAL_FUNC,NE_FUNC,LT_FUNC,LE_FUNC,
50
 
                  GE_FUNC,GT_FUNC,
51
 
                  LIKE_FUNC,ISNULL_FUNC,ISNOTNULL_FUNC,
52
 
                  COND_AND_FUNC, COND_OR_FUNC, COND_XOR_FUNC,
53
 
                  BETWEEN, IN_FUNC, MULT_EQUAL_FUNC,
54
 
                  INTERVAL_FUNC, ISNOTNULLTEST_FUNC,
55
 
                  NOT_FUNC, NOT_ALL_FUNC,
56
 
                  NOW_FUNC, TRIG_COND_FUNC,
57
 
                  SUSERVAR_FUNC, GUSERVAR_FUNC, COLLATE_FUNC,
58
 
                  EXTRACT_FUNC, CHAR_TYPECAST_FUNC, FUNC_SP,
59
 
                  NEG_FUNC };
60
 
  enum optimize_type { OPTIMIZE_NONE,OPTIMIZE_KEY,OPTIMIZE_OP, OPTIMIZE_NULL,
61
 
                       OPTIMIZE_EQUAL };
62
 
  enum Type type() const { return FUNC_ITEM; }
63
 
  virtual enum Functype functype() const   { return UNKNOWN_FUNC; }
64
 
  Item_func(void):
65
 
    allowed_arg_cols(1), arg_count(0)
66
 
  {
67
 
    with_sum_func= 0;
68
 
  }
69
 
  Item_func(Item *a):
70
 
    allowed_arg_cols(1), arg_count(1)
71
 
  {
72
 
    args= tmp_arg;
73
 
    args[0]= a;
74
 
    with_sum_func= a->with_sum_func;
75
 
  }
76
 
  Item_func(Item *a,Item *b):
77
 
    allowed_arg_cols(1), arg_count(2)
78
 
  {
79
 
    args= tmp_arg;
80
 
    args[0]= a; args[1]= b;
81
 
    with_sum_func= a->with_sum_func || b->with_sum_func;
82
 
  }
83
 
  Item_func(Item *a,Item *b,Item *c):
84
 
    allowed_arg_cols(1)
85
 
  {
86
 
    arg_count= 0;
87
 
    if ((args= (Item**) sql_alloc(sizeof(Item*)*3)))
88
 
    {
89
 
      arg_count= 3;
90
 
      args[0]= a; args[1]= b; args[2]= c;
91
 
      with_sum_func= a->with_sum_func || b->with_sum_func || c->with_sum_func;
92
 
    }
93
 
  }
94
 
  Item_func(Item *a,Item *b,Item *c,Item *d):
95
 
    allowed_arg_cols(1)
96
 
  {
97
 
    arg_count= 0;
98
 
    if ((args= (Item**) sql_alloc(sizeof(Item*)*4)))
99
 
    {
100
 
      arg_count= 4;
101
 
      args[0]= a; args[1]= b; args[2]= c; args[3]= d;
102
 
      with_sum_func= a->with_sum_func || b->with_sum_func ||
103
 
        c->with_sum_func || d->with_sum_func;
104
 
    }
105
 
  }
106
 
  Item_func(Item *a,Item *b,Item *c,Item *d,Item* e):
107
 
    allowed_arg_cols(1)
108
 
  {
109
 
    arg_count= 5;
110
 
    if ((args= (Item**) sql_alloc(sizeof(Item*)*5)))
111
 
    {
112
 
      args[0]= a; args[1]= b; args[2]= c; args[3]= d; args[4]= e;
113
 
      with_sum_func= a->with_sum_func || b->with_sum_func ||
114
 
        c->with_sum_func || d->with_sum_func || e->with_sum_func ;
115
 
    }
116
 
  }
117
 
  Item_func(List<Item> &list);
118
 
  // Constructor used for Item_cond_and/or (see Item comment)
119
 
  Item_func(THD *thd, Item_func *item);
120
 
  bool fix_fields(THD *, Item **ref);
121
 
  void fix_after_pullout(st_select_lex *new_parent, Item **ref);
122
 
  table_map used_tables() const;
123
 
  table_map not_null_tables() const;
124
 
  void update_used_tables();
125
 
  bool eq(const Item *item, bool binary_cmp) const;
126
 
  virtual optimize_type select_optimize() const { return OPTIMIZE_NONE; }
127
 
  virtual bool have_rev_func() const { return 0; }
128
 
  virtual Item *key_item() const { return args[0]; }
129
 
  /*
130
 
    This method is used for debug purposes to print the name of an
131
 
    item to the debug log. The second use of this method is as
132
 
    a helper function of print(), where it is applicable.
133
 
    To suit both goals it should return a meaningful,
134
 
    distinguishable and sintactically correct string.  This method
135
 
    should not be used for runtime type identification, use enum
136
 
    {Sum}Functype and Item_func::functype()/Item_sum::sum_func()
137
 
    instead.
138
 
  */
139
 
  virtual const char *func_name() const { return NULL; };
140
 
  virtual bool const_item() const { return const_item_cache; }
141
 
  inline Item **arguments() const { return args; }
142
 
  void set_arguments(List<Item> &list);
143
 
  inline uint32_t argument_count() const { return arg_count; }
144
 
  inline void remove_arguments() { arg_count=0; }
145
 
  void split_sum_func(THD *thd, Item **ref_pointer_array, List<Item> &fields);
146
 
  virtual void print(String *str, enum_query_type query_type);
147
 
  void print_op(String *str, enum_query_type query_type);
148
 
  void print_args(String *str, uint32_t from, enum_query_type query_type);
149
 
  virtual void fix_num_length_and_dec();
150
 
  void count_only_length();
151
 
  void count_real_length();
152
 
  void count_decimal_length();
153
 
  inline bool get_arg0_date(DRIZZLE_TIME *ltime, uint32_t fuzzy_date)
154
 
  {
155
 
    return (null_value=args[0]->get_date(ltime, fuzzy_date));
156
 
  }
157
 
  inline bool get_arg0_time(DRIZZLE_TIME *ltime)
158
 
  {
159
 
    return (null_value=args[0]->get_time(ltime));
160
 
  }
161
 
  bool is_null() { 
162
 
    update_null_value();
163
 
    return null_value; 
164
 
  }
165
 
  void signal_divide_by_null();
166
 
 
167
 
  Field *tmp_table_field() { return result_field; }
168
 
  Field *tmp_table_field(Table *t_arg);
169
 
  Item *get_tmp_table_item(THD *thd);
170
 
 
171
 
  my_decimal *val_decimal(my_decimal *);
172
 
 
173
 
  bool agg_arg_collations(DTCollation &c, Item **items, uint32_t nitems,
174
 
                          uint32_t flags)
175
 
  {
176
 
    return agg_item_collations(c, func_name(), items, nitems, flags, 1);
177
 
  }
178
 
  bool agg_arg_collations_for_comparison(DTCollation &c,
179
 
                                         Item **items, uint32_t nitems,
180
 
                                         uint32_t flags)
181
 
  {
182
 
    return agg_item_collations_for_comparison(c, func_name(),
183
 
                                              items, nitems, flags);
184
 
  }
185
 
  bool agg_arg_charsets(DTCollation &c, Item **items, uint32_t nitems,
186
 
                        uint32_t flags, int item_sep)
187
 
  {
188
 
    return agg_item_charsets(c, func_name(), items, nitems, flags, item_sep);
189
 
  }
190
 
  bool walk(Item_processor processor, bool walk_subquery, unsigned char *arg);
191
 
  Item *transform(Item_transformer transformer, unsigned char *arg);
192
 
  Item* compile(Item_analyzer analyzer, unsigned char **arg_p,
193
 
                Item_transformer transformer, unsigned char *arg_t);
194
 
  void traverse_cond(Cond_traverser traverser,
195
 
                     void * arg, traverse_order order);
196
 
  inline double fix_result(double value)
197
 
  {
198
 
    if (CMATH_C99_NAMESPACE isfinite(value))
199
 
      return value;
200
 
    null_value=1;
201
 
    return 0.0;
202
 
  }
203
 
};
204
 
 
 
36
#include <drizzled/functions/func.h>
 
37
#include <drizzled/functions/int.h>
205
38
 
206
39
class Item_real_func :public Item_func
207
40
{
314
147
};
315
148
 
316
149
 
317
 
class Item_int_func :public Item_func
318
 
{
319
 
public:
320
 
  Item_int_func() :Item_func() { max_length= 21; }
321
 
  Item_int_func(Item *a) :Item_func(a) { max_length= 21; }
322
 
  Item_int_func(Item *a,Item *b) :Item_func(a,b) { max_length= 21; }
323
 
  Item_int_func(Item *a,Item *b,Item *c) :Item_func(a,b,c)
324
 
  { max_length= 21; }
325
 
  Item_int_func(List<Item> &list) :Item_func(list) { max_length= 21; }
326
 
  Item_int_func(THD *thd, Item_int_func *item) :Item_func(thd, item) {}
327
 
  double val_real();
328
 
  String *val_str(String*str);
329
 
  enum Item_result result_type () const { return INT_RESULT; }
330
 
  void fix_length_and_dec() {}
331
 
};
332
 
 
 
150
#include <drizzled/functions/int.h>
333
151
 
334
152
class Item_func_connection_id :public Item_int_func
335
153
{