~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/functions/func.h

  • Committer: Monty Taylor
  • Date: 2008-10-14 16:33:44 UTC
  • mfrom: (512 drizzle)
  • mto: (511.1.5 codestyle)
  • mto: This revision was merged to the branch mainline in revision 515.
  • Revision ID: monty@inaugust.com-20081014163344-9xprk712n9hmbrzr
MergedĀ fromĀ trunk.

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
#include <drizzled/item_func.h>
26
27
#include <drizzled/sql_list.h>
27
 
#include <drizzled/item/bin_string.h>
28
 
#include "drizzled/current_session.h"
29
 
 
30
 
namespace drizzled
 
28
 
 
29
 
 
30
#ifdef HAVE_IEEEFP_H
 
31
extern "C"        /* Bug in BSDI include file */
31
32
{
 
33
#include <ieeefp.h>
 
34
}
 
35
#endif
32
36
 
33
37
class Item_func :public Item_result_field
34
38
{
35
 
  Session &_session;
36
 
 
37
39
protected:
38
40
  Item **args, *tmp_arg[2];
39
41
  /*
42
44
  */
43
45
  uint32_t allowed_arg_cols;
44
46
public:
45
 
 
46
 
  using Item::split_sum_func;
47
 
 
48
47
  uint32_t arg_count;
49
48
  table_map used_tables_cache, not_null_tables_cache;
50
49
  bool const_item_cache;
63
62
                       OPTIMIZE_EQUAL };
64
63
  enum Type type() const { return FUNC_ITEM; }
65
64
  virtual enum Functype functype() const   { return UNKNOWN_FUNC; }
66
 
  virtual ~Item_func() {}
67
 
 
68
65
  Item_func(void):
69
 
    _session(*current_session),
70
66
    allowed_arg_cols(1), arg_count(0)
71
67
  {
72
68
    with_sum_func= 0;
73
 
    collation.set(DERIVATION_SYSCONST);
74
69
  }
75
 
 
76
70
  Item_func(Item *a):
77
 
    _session(*current_session),
78
71
    allowed_arg_cols(1), arg_count(1)
79
72
  {
80
73
    args= tmp_arg;
81
74
    args[0]= a;
82
75
    with_sum_func= a->with_sum_func;
83
 
    collation.set(DERIVATION_SYSCONST);
84
76
  }
85
 
  
86
77
  Item_func(Item *a,Item *b):
87
 
    _session(*current_session),
88
78
    allowed_arg_cols(1), arg_count(2)
89
79
  {
90
80
    args= tmp_arg;
91
81
    args[0]= a; args[1]= b;
92
82
    with_sum_func= a->with_sum_func || b->with_sum_func;
93
 
    collation.set(DERIVATION_SYSCONST);
94
83
  }
95
 
  
96
84
  Item_func(Item *a,Item *b,Item *c):
97
 
    _session(*current_session),
98
85
    allowed_arg_cols(1)
99
86
  {
100
87
    arg_count= 0;
101
 
    if ((args= (Item**) memory::sql_alloc(sizeof(Item*)*3)))
 
88
    if ((args= (Item**) sql_alloc(sizeof(Item*)*3)))
102
89
    {
103
90
      arg_count= 3;
104
91
      args[0]= a; args[1]= b; args[2]= c;
105
92
      with_sum_func= a->with_sum_func || b->with_sum_func || c->with_sum_func;
106
93
    }
107
 
    collation.set(DERIVATION_SYSCONST);
108
94
  }
109
 
  
110
95
  Item_func(Item *a,Item *b,Item *c,Item *d):
111
 
    _session(*current_session),
112
96
    allowed_arg_cols(1)
113
97
  {
114
98
    arg_count= 0;
115
 
    if ((args= (Item**) memory::sql_alloc(sizeof(Item*)*4)))
 
99
    if ((args= (Item**) sql_alloc(sizeof(Item*)*4)))
116
100
    {
117
101
      arg_count= 4;
118
102
      args[0]= a; args[1]= b; args[2]= c; args[3]= d;
119
103
      with_sum_func= a->with_sum_func || b->with_sum_func ||
120
104
        c->with_sum_func || d->with_sum_func;
121
105
    }
122
 
    collation.set(DERIVATION_SYSCONST);
123
106
  }
124
 
  
125
107
  Item_func(Item *a,Item *b,Item *c,Item *d,Item* e):
126
 
    _session(*current_session),
127
108
    allowed_arg_cols(1)
128
109
  {
129
110
    arg_count= 5;
130
 
    if ((args= (Item**) memory::sql_alloc(sizeof(Item*)*5)))
 
111
    if ((args= (Item**) sql_alloc(sizeof(Item*)*5)))
131
112
    {
132
113
      args[0]= a; args[1]= b; args[2]= c; args[3]= d; args[4]= e;
133
114
      with_sum_func= a->with_sum_func || b->with_sum_func ||
134
115
        c->with_sum_func || d->with_sum_func || e->with_sum_func ;
135
116
    }
136
 
    collation.set(DERIVATION_SYSCONST);
137
117
  }
138
 
  
139
118
  Item_func(List<Item> &list);
140
 
  
141
119
  // Constructor used for Item_cond_and/or (see Item comment)
142
 
  Item_func(Session *session, Item_func *item);
143
 
  
144
 
  bool fix_fields(Session *, Item **ref);
145
 
  void fix_after_pullout(Select_Lex *new_parent, Item **ref);
 
120
  Item_func(THD *thd, Item_func *item);
 
121
  bool fix_fields(THD *, Item **ref);
 
122
  void fix_after_pullout(st_select_lex *new_parent, Item **ref);
146
123
  table_map used_tables() const;
147
124
  table_map not_null_tables() const;
148
125
  void update_used_tables();
160
137
    {Sum}Functype and Item_func::functype()/Item_sum::sum_func()
161
138
    instead.
162
139
  */
163
 
  virtual const char *func_name() const { return NULL; }
 
140
  virtual const char *func_name() const { return NULL; };
164
141
  virtual bool const_item() const { return const_item_cache; }
165
142
  Item **arguments() const { return args; }
166
143
  void set_arguments(List<Item> &list);
167
144
  uint32_t argument_count() const { return arg_count; }
168
145
  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
 
 
 
146
  void split_sum_func(THD *thd, Item **ref_pointer_array, List<Item> &fields);
178
147
  virtual void print(String *str, enum_query_type query_type);
179
148
  void print_op(String *str, enum_query_type query_type);
180
149
  void print_args(String *str, uint32_t from, enum_query_type query_type);
190
159
 
191
160
  void signal_divide_by_null();
192
161
 
193
 
  virtual Field *tmp_table_field() { return result_field; }
194
 
  virtual Field *tmp_table_field(Table *t_arg);
195
 
 
196
 
  Item *get_tmp_table_item(Session *session);
 
162
  Field *tmp_table_field() { return result_field; }
 
163
  Field *tmp_table_field(Table *t_arg);
 
164
  Item *get_tmp_table_item(THD *thd);
197
165
 
198
166
  my_decimal *val_decimal(my_decimal *);
199
167
 
212
180
                     void * arg, traverse_order order);
213
181
  double fix_result(double value);
214
182
 
215
 
  Session &getSession()
216
 
  {
217
 
    return _session;
218
 
  }
219
 
 
220
 
  Session *getSessionPtr()
221
 
  {
222
 
    return &_session;
223
 
  }
224
 
 
225
183
};
226
184
 
227
 
} /* namespace drizzled */
228
 
 
229
 
 
230
 
#endif /* DRIZZLED_FUNCTION_FUNC_H */
 
185
 
 
186
#endif