~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/function/func.h

  • Committer: Monty Taylor
  • Date: 2008-09-16 00:00:48 UTC
  • mto: This revision was merged to the branch mainline in revision 391.
  • Revision ID: monty@inaugust.com-20080916000048-3rvrv3gv9l0ad3gs
Fixed copyright headers in drizzled/

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; version 2 of the License.
9
 
 *
10
 
 *  This program is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with this program; if not, write to the Free Software
17
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 
 */
19
 
 
20
 
 
21
 
 
22
 
#ifndef DRIZZLED_FUNCTION_FUNC_H
23
 
#define DRIZZLED_FUNCTION_FUNC_H
24
 
 
25
 
/// TODO: Rename this file - func.h is stupid.
26
 
 
27
 
#include <drizzled/charset_info.h>
28
 
#include <drizzled/current_session.h>
29
 
#include <drizzled/item.h>
30
 
#include <drizzled/item/bin_string.h>
31
 
#include <drizzled/lex_string.h>
32
 
#include <drizzled/sql_list.h>
33
 
#include <drizzled/type/decimal.h>
34
 
 
35
 
#include "drizzled/visibility.h"
36
 
 
37
 
namespace drizzled
38
 
{
39
 
 
40
 
class DRIZZLED_API Item_func :
41
 
  public Item_result_field
42
 
{
43
 
  Session &_session;
44
 
 
45
 
protected:
46
 
  Item **args, *tmp_arg[2];
47
 
  /*
48
 
    Allowed numbers of columns in result (usually 1, which means scalar value)
49
 
    0 means get this number from first argument
50
 
  */
51
 
  uint32_t allowed_arg_cols;
52
 
public:
53
 
 
54
 
  using Item::split_sum_func;
55
 
 
56
 
  uint32_t arg_count;
57
 
  table_map used_tables_cache, not_null_tables_cache;
58
 
  bool const_item_cache;
59
 
  enum Functype { UNKNOWN_FUNC,EQ_FUNC,EQUAL_FUNC,NE_FUNC,LT_FUNC,LE_FUNC,
60
 
                  GE_FUNC,GT_FUNC,
61
 
                  LIKE_FUNC,ISNULL_FUNC,ISNOTNULL_FUNC,
62
 
                  COND_AND_FUNC, COND_OR_FUNC, COND_XOR_FUNC,
63
 
                  BETWEEN, IN_FUNC, MULT_EQUAL_FUNC,
64
 
                  INTERVAL_FUNC, ISNOTNULLTEST_FUNC,
65
 
                  NOT_FUNC, NOT_ALL_FUNC,
66
 
                  NOW_FUNC, TRIG_COND_FUNC,
67
 
                  SUSERVAR_FUNC, GUSERVAR_FUNC, COLLATE_FUNC,
68
 
                  EXTRACT_FUNC, CHAR_TYPECAST_FUNC, FUNC_SP,
69
 
                  NEG_FUNC };
70
 
  enum optimize_type { OPTIMIZE_NONE,OPTIMIZE_KEY,OPTIMIZE_OP, OPTIMIZE_NULL,
71
 
                       OPTIMIZE_EQUAL };
72
 
  enum Type type() const { return FUNC_ITEM; }
73
 
  virtual enum Functype functype() const   { return UNKNOWN_FUNC; }
74
 
  virtual ~Item_func() {}
75
 
 
76
 
  Item_func(void):
77
 
    _session(*current_session),
78
 
    allowed_arg_cols(1), arg_count(0),
79
 
    const_item_cache(false)
80
 
  {
81
 
    with_sum_func= 0;
82
 
    collation.set(DERIVATION_SYSCONST);
83
 
  }
84
 
 
85
 
  Item_func(Item *a):
86
 
    _session(*current_session),
87
 
    allowed_arg_cols(1), arg_count(1),
88
 
    const_item_cache(false)
89
 
  {
90
 
    args= tmp_arg;
91
 
    args[0]= a;
92
 
    with_sum_func= a->with_sum_func;
93
 
    collation.set(DERIVATION_SYSCONST);
94
 
  }
95
 
  
96
 
  Item_func(Item *a,Item *b):
97
 
    _session(*current_session),
98
 
    allowed_arg_cols(1), arg_count(2),
99
 
    const_item_cache(false)
100
 
  {
101
 
    args= tmp_arg;
102
 
    args[0]= a; args[1]= b;
103
 
    with_sum_func= a->with_sum_func || b->with_sum_func;
104
 
    collation.set(DERIVATION_SYSCONST);
105
 
  }
106
 
  
107
 
  Item_func(Item *a,Item *b,Item *c):
108
 
    _session(*current_session),
109
 
    allowed_arg_cols(1),
110
 
    const_item_cache(false)
111
 
  {
112
 
    arg_count= 0;
113
 
    if ((args= (Item**) memory::sql_alloc(sizeof(Item*)*3)))
114
 
    {
115
 
      arg_count= 3;
116
 
      args[0]= a; args[1]= b; args[2]= c;
117
 
      with_sum_func= a->with_sum_func || b->with_sum_func || c->with_sum_func;
118
 
    }
119
 
    collation.set(DERIVATION_SYSCONST);
120
 
  }
121
 
  
122
 
  Item_func(Item *a,Item *b,Item *c,Item *d):
123
 
    _session(*current_session),
124
 
    allowed_arg_cols(1),
125
 
    const_item_cache(false)
126
 
  {
127
 
    arg_count= 0;
128
 
    if ((args= (Item**) memory::sql_alloc(sizeof(Item*)*4)))
129
 
    {
130
 
      arg_count= 4;
131
 
      args[0]= a; args[1]= b; args[2]= c; args[3]= d;
132
 
      with_sum_func= a->with_sum_func || b->with_sum_func ||
133
 
        c->with_sum_func || d->with_sum_func;
134
 
    }
135
 
    collation.set(DERIVATION_SYSCONST);
136
 
  }
137
 
  
138
 
  Item_func(Item *a,Item *b,Item *c,Item *d,Item* e):
139
 
    _session(*current_session),
140
 
    allowed_arg_cols(1),
141
 
    const_item_cache(false)
142
 
  {
143
 
    arg_count= 5;
144
 
    if ((args= (Item**) memory::sql_alloc(sizeof(Item*)*5)))
145
 
    {
146
 
      args[0]= a; args[1]= b; args[2]= c; args[3]= d; args[4]= e;
147
 
      with_sum_func= a->with_sum_func || b->with_sum_func ||
148
 
        c->with_sum_func || d->with_sum_func || e->with_sum_func ;
149
 
    }
150
 
    collation.set(DERIVATION_SYSCONST);
151
 
  }
152
 
  
153
 
  Item_func(List<Item> &list);
154
 
  
155
 
  // Constructor used for Item_cond_and/or (see Item comment)
156
 
  Item_func(Session *session, Item_func *item);
157
 
  
158
 
  bool fix_fields(Session *, Item **ref);
159
 
  void fix_after_pullout(Select_Lex *new_parent, Item **ref);
160
 
  table_map used_tables() const;
161
 
  table_map not_null_tables() const;
162
 
  void update_used_tables();
163
 
  bool eq(const Item *item, bool binary_cmp) const;
164
 
  virtual optimize_type select_optimize() const { return OPTIMIZE_NONE; }
165
 
  virtual bool have_rev_func() const { return 0; }
166
 
  virtual Item *key_item() const { return args[0]; }
167
 
  /*
168
 
    This method is used for debug purposes to print the name of an
169
 
    item to the debug log. The second use of this method is as
170
 
    a helper function of print(), where it is applicable.
171
 
    To suit both goals it should return a meaningful,
172
 
    distinguishable and sintactically correct string.  This method
173
 
    should not be used for runtime type identification, use enum
174
 
    {Sum}Functype and Item_func::functype()/Item_sum::sum_func()
175
 
    instead.
176
 
  */
177
 
  virtual const char *func_name() const { return NULL; }
178
 
  virtual bool const_item() const { return const_item_cache; }
179
 
  Item **arguments() const { return args; }
180
 
  void set_arguments(List<Item> &list);
181
 
  uint32_t argument_count() const { return arg_count; }
182
 
  void remove_arguments() { arg_count=0; }
183
 
 
184
 
  /**
185
 
   * Check if the UDF supports the number of arguments passed in
186
 
   * @param number of args
187
 
   */
188
 
  virtual bool check_argument_count(int) { return true ; }
189
 
  virtual void split_sum_func(Session *session, Item **ref_pointer_array,
190
 
                              List<Item> &fields);
191
 
 
192
 
  virtual void print(String *str, enum_query_type query_type);
193
 
  void print_op(String *str, enum_query_type query_type);
194
 
  void print_args(String *str, uint32_t from, enum_query_type query_type);
195
 
  virtual void fix_num_length_and_dec();
196
 
  void count_only_length();
197
 
  void count_real_length();
198
 
  void count_decimal_length();
199
 
 
200
 
  bool get_arg0_date(type::Time &ltime, uint32_t fuzzy_date);
201
 
  bool get_arg0_time(type::Time &ltime);
202
 
 
203
 
  bool is_null();
204
 
 
205
 
  virtual bool deterministic() const
206
 
  {
207
 
    return false;
208
 
  }
209
 
 
210
 
  void signal_divide_by_null();
211
 
 
212
 
  virtual Field *tmp_table_field() { return result_field; }
213
 
  virtual Field *tmp_table_field(Table *t_arg);
214
 
 
215
 
  Item *get_tmp_table_item(Session *session);
216
 
 
217
 
  type::Decimal *val_decimal(type::Decimal *);
218
 
 
219
 
  bool agg_arg_collations(DTCollation &c, Item **items, uint32_t nitems,
220
 
                          uint32_t flags);
221
 
  bool agg_arg_collations_for_comparison(DTCollation &c,
222
 
                                         Item **items, uint32_t nitems,
223
 
                                         uint32_t flags);
224
 
  bool agg_arg_charsets(DTCollation &c, Item **items, uint32_t nitems,
225
 
                        uint32_t flags, int item_sep);
226
 
  bool walk(Item_processor processor, bool walk_subquery, unsigned char *arg);
227
 
  Item *transform(Item_transformer transformer, unsigned char *arg);
228
 
  Item* compile(Item_analyzer analyzer, unsigned char **arg_p,
229
 
                Item_transformer transformer, unsigned char *arg_t);
230
 
  void traverse_cond(Cond_traverser traverser,
231
 
                     void * arg, traverse_order order);
232
 
  double fix_result(double value);
233
 
 
234
 
  Session &getSession()
235
 
  {
236
 
    return _session;
237
 
  }
238
 
 
239
 
  Session *getSessionPtr()
240
 
  {
241
 
    return &_session;
242
 
  }
243
 
 
244
 
};
245
 
 
246
 
} /* namespace drizzled */
247
 
 
248
 
 
249
 
#endif /* DRIZZLED_FUNCTION_FUNC_H */