17
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
#ifndef DRIZZLED_FUNCTION_FUNC_H
21
#define DRIZZLED_FUNCTION_FUNC_H
20
#ifndef drizzled_functions_func_h
21
#define drizzled_functions_func_h
23
23
/// TODO: Rename this file - func.h is stupid.
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"
31
extern "C" /* Bug in BSDI include file */
33
37
class Item_func :public Item_result_field
38
40
Item **args, *tmp_arg[2];
64
63
enum Type type() const { return FUNC_ITEM; }
65
64
virtual enum Functype functype() const { return UNKNOWN_FUNC; }
66
virtual ~Item_func() {}
69
_session(*current_session),
70
66
allowed_arg_cols(1), arg_count(0)
73
collation.set(DERIVATION_SYSCONST);
76
70
Item_func(Item *a):
77
_session(*current_session),
78
71
allowed_arg_cols(1), arg_count(1)
82
75
with_sum_func= a->with_sum_func;
83
collation.set(DERIVATION_SYSCONST);
86
77
Item_func(Item *a,Item *b):
87
_session(*current_session),
88
78
allowed_arg_cols(1), arg_count(2)
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);
96
84
Item_func(Item *a,Item *b,Item *c):
97
_session(*current_session),
98
85
allowed_arg_cols(1)
101
if ((args= (Item**) memory::sql_alloc(sizeof(Item*)*3)))
88
if ((args= (Item**) sql_alloc(sizeof(Item*)*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;
107
collation.set(DERIVATION_SYSCONST);
110
95
Item_func(Item *a,Item *b,Item *c,Item *d):
111
_session(*current_session),
112
96
allowed_arg_cols(1)
115
if ((args= (Item**) memory::sql_alloc(sizeof(Item*)*4)))
99
if ((args= (Item**) sql_alloc(sizeof(Item*)*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;
122
collation.set(DERIVATION_SYSCONST);
125
107
Item_func(Item *a,Item *b,Item *c,Item *d,Item* e):
126
_session(*current_session),
127
108
allowed_arg_cols(1)
130
if ((args= (Item**) memory::sql_alloc(sizeof(Item*)*5)))
111
if ((args= (Item**) sql_alloc(sizeof(Item*)*5)))
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 ;
136
collation.set(DERIVATION_SYSCONST);
139
118
Item_func(List<Item> &list);
141
119
// Constructor used for Item_cond_and/or (see Item comment)
142
Item_func(Session *session, Item_func *item);
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()
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; }
171
* Check if the UDF supports the number of arguments passed in
172
* @param number of args
174
virtual bool check_argument_count(int) { return true ; }
175
virtual void split_sum_func(Session *session, Item **ref_pointer_array,
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);