~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/functions/func.h

Tags: innodb-plugin-1.0.3
InnoDB Plugin 1.0.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#ifndef DRIZZLED_FUNCTION_FUNC_H
21
 
#define DRIZZLED_FUNCTION_FUNC_H
 
20
#ifndef drizzled_functions_func_h
 
21
#define drizzled_functions_func_h
22
22
 
23
23
/// TODO: Rename this file - func.h is stupid.
24
24
 
25
25
#include <drizzled/item.h>
26
26
#include <drizzled/sql_list.h>
27
 
#include <drizzled/item/bin_string.h>
28
 
#include "drizzled/current_session.h"
29
27
 
30
 
namespace drizzled
31
 
{
32
28
 
33
29
class Item_func :public Item_result_field
34
30
{
35
 
  Session &_session;
36
 
 
37
31
protected:
38
32
  Item **args, *tmp_arg[2];
39
33
  /*
42
36
  */
43
37
  uint32_t allowed_arg_cols;
44
38
public:
45
 
 
46
 
  using Item::split_sum_func;
47
 
 
48
39
  uint32_t arg_count;
49
40
  table_map used_tables_cache, not_null_tables_cache;
50
41
  bool const_item_cache;
63
54
                       OPTIMIZE_EQUAL };
64
55
  enum Type type() const { return FUNC_ITEM; }
65
56
  virtual enum Functype functype() const   { return UNKNOWN_FUNC; }
66
 
  virtual ~Item_func() {}
67
 
 
68
57
  Item_func(void):
69
 
    _session(*current_session),
70
58
    allowed_arg_cols(1), arg_count(0)
71
59
  {
72
60
    with_sum_func= 0;
73
 
    collation.set(DERIVATION_SYSCONST);
74
61
  }
75
 
 
76
62
  Item_func(Item *a):
77
 
    _session(*current_session),
78
63
    allowed_arg_cols(1), arg_count(1)
79
64
  {
80
65
    args= tmp_arg;
81
66
    args[0]= a;
82
67
    with_sum_func= a->with_sum_func;
83
 
    collation.set(DERIVATION_SYSCONST);
84
68
  }
85
 
  
86
69
  Item_func(Item *a,Item *b):
87
 
    _session(*current_session),
88
70
    allowed_arg_cols(1), arg_count(2)
89
71
  {
90
72
    args= tmp_arg;
91
73
    args[0]= a; args[1]= b;
92
74
    with_sum_func= a->with_sum_func || b->with_sum_func;
93
 
    collation.set(DERIVATION_SYSCONST);
94
75
  }
95
 
  
96
76
  Item_func(Item *a,Item *b,Item *c):
97
 
    _session(*current_session),
98
77
    allowed_arg_cols(1)
99
78
  {
100
79
    arg_count= 0;
101
 
    if ((args= (Item**) memory::sql_alloc(sizeof(Item*)*3)))
 
80
    if ((args= (Item**) sql_alloc(sizeof(Item*)*3)))
102
81
    {
103
82
      arg_count= 3;
104
83
      args[0]= a; args[1]= b; args[2]= c;
105
84
      with_sum_func= a->with_sum_func || b->with_sum_func || c->with_sum_func;
106
85
    }
107
 
    collation.set(DERIVATION_SYSCONST);
108
86
  }
109
 
  
110
87
  Item_func(Item *a,Item *b,Item *c,Item *d):
111
 
    _session(*current_session),
112
88
    allowed_arg_cols(1)
113
89
  {
114
90
    arg_count= 0;
115
 
    if ((args= (Item**) memory::sql_alloc(sizeof(Item*)*4)))
 
91
    if ((args= (Item**) sql_alloc(sizeof(Item*)*4)))
116
92
    {
117
93
      arg_count= 4;
118
94
      args[0]= a; args[1]= b; args[2]= c; args[3]= d;
119
95
      with_sum_func= a->with_sum_func || b->with_sum_func ||
120
96
        c->with_sum_func || d->with_sum_func;
121
97
    }
122
 
    collation.set(DERIVATION_SYSCONST);
123
98
  }
124
 
  
125
99
  Item_func(Item *a,Item *b,Item *c,Item *d,Item* e):
126
 
    _session(*current_session),
127
100
    allowed_arg_cols(1)
128
101
  {
129
102
    arg_count= 5;
130
 
    if ((args= (Item**) memory::sql_alloc(sizeof(Item*)*5)))
 
103
    if ((args= (Item**) sql_alloc(sizeof(Item*)*5)))
131
104
    {
132
105
      args[0]= a; args[1]= b; args[2]= c; args[3]= d; args[4]= e;
133
106
      with_sum_func= a->with_sum_func || b->with_sum_func ||
134
107
        c->with_sum_func || d->with_sum_func || e->with_sum_func ;
135
108
    }
136
 
    collation.set(DERIVATION_SYSCONST);
137
109
  }
138
 
  
139
110
  Item_func(List<Item> &list);
140
 
  
141
111
  // Constructor used for Item_cond_and/or (see Item comment)
142
112
  Item_func(Session *session, Item_func *item);
143
 
  
144
113
  bool fix_fields(Session *, Item **ref);
145
 
  void fix_after_pullout(Select_Lex *new_parent, Item **ref);
 
114
  void fix_after_pullout(st_select_lex *new_parent, Item **ref);
146
115
  table_map used_tables() const;
147
116
  table_map not_null_tables() const;
148
117
  void update_used_tables();
160
129
    {Sum}Functype and Item_func::functype()/Item_sum::sum_func()
161
130
    instead.
162
131
  */
163
 
  virtual const char *func_name() const { return NULL; }
 
132
  virtual const char *func_name() const { return NULL; };
164
133
  virtual bool const_item() const { return const_item_cache; }
165
134
  Item **arguments() const { return args; }
166
135
  void set_arguments(List<Item> &list);
167
136
  uint32_t argument_count() const { return arg_count; }
168
137
  void remove_arguments() { arg_count=0; }
169
 
 
170
 
  /**
171
 
   * Check if the UDF supports the number of arguments passed in
172
 
   * @param number of args
173
 
   */
174
 
  virtual bool check_argument_count(int) { return true ; }
175
 
  virtual void split_sum_func(Session *session, Item **ref_pointer_array,
176
 
                              List<Item> &fields);
177
 
 
 
138
  void split_sum_func(Session *session, Item **ref_pointer_array, List<Item> &fields);
178
139
  virtual void print(String *str, enum_query_type query_type);
179
140
  void print_op(String *str, enum_query_type query_type);
180
141
  void print_args(String *str, uint32_t from, enum_query_type query_type);
190
151
 
191
152
  void signal_divide_by_null();
192
153
 
193
 
  virtual Field *tmp_table_field() { return result_field; }
194
 
  virtual Field *tmp_table_field(Table *t_arg);
195
 
 
 
154
  Field *tmp_table_field() { return result_field; }
 
155
  Field *tmp_table_field(Table *t_arg);
196
156
  Item *get_tmp_table_item(Session *session);
197
157
 
198
158
  my_decimal *val_decimal(my_decimal *);
212
172
                     void * arg, traverse_order order);
213
173
  double fix_result(double value);
214
174
 
215
 
  Session &getSession()
216
 
  {
217
 
    return _session;
218
 
  }
219
 
 
220
 
  Session *getSessionPtr()
221
 
  {
222
 
    return &_session;
223
 
  }
224
 
 
225
175
};
226
176
 
227
 
} /* namespace drizzled */
228
 
 
229
 
 
230
 
#endif /* DRIZZLED_FUNCTION_FUNC_H */
 
177
 
 
178
#endif