~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/function/func.h

  • Committer: Mark Atwood
  • Date: 2008-10-03 01:39:40 UTC
  • mto: This revision was merged to the branch mainline in revision 437.
  • Revision ID: mark@fallenpegasus.com-20081003013940-mvefjo725dltz41h
rename logging_noop to logging_query

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
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
 
#ifndef DRIZZLED_FUNCTION_FUNC_H
21
 
#define DRIZZLED_FUNCTION_FUNC_H
22
 
 
23
 
/// TODO: Rename this file - func.h is stupid.
24
 
 
25
 
#include <drizzled/item.h>
26
 
#include <drizzled/sql_list.h>
27
 
#include <drizzled/item/bin_string.h>
28
 
#include "drizzled/current_session.h"
29
 
 
30
 
namespace drizzled
31
 
{
32
 
 
33
 
class Item_func :public Item_result_field
34
 
{
35
 
  Session &_session;
36
 
 
37
 
protected:
38
 
  Item **args, *tmp_arg[2];
39
 
  /*
40
 
    Allowed numbers of columns in result (usually 1, which means scalar value)
41
 
    0 means get this number from first argument
42
 
  */
43
 
  uint32_t allowed_arg_cols;
44
 
public:
45
 
 
46
 
  using Item::split_sum_func;
47
 
 
48
 
  uint32_t arg_count;
49
 
  table_map used_tables_cache, not_null_tables_cache;
50
 
  bool const_item_cache;
51
 
  enum Functype { UNKNOWN_FUNC,EQ_FUNC,EQUAL_FUNC,NE_FUNC,LT_FUNC,LE_FUNC,
52
 
                  GE_FUNC,GT_FUNC,
53
 
                  LIKE_FUNC,ISNULL_FUNC,ISNOTNULL_FUNC,
54
 
                  COND_AND_FUNC, COND_OR_FUNC, COND_XOR_FUNC,
55
 
                  BETWEEN, IN_FUNC, MULT_EQUAL_FUNC,
56
 
                  INTERVAL_FUNC, ISNOTNULLTEST_FUNC,
57
 
                  NOT_FUNC, NOT_ALL_FUNC,
58
 
                  NOW_FUNC, TRIG_COND_FUNC,
59
 
                  SUSERVAR_FUNC, GUSERVAR_FUNC, COLLATE_FUNC,
60
 
                  EXTRACT_FUNC, CHAR_TYPECAST_FUNC, FUNC_SP,
61
 
                  NEG_FUNC };
62
 
  enum optimize_type { OPTIMIZE_NONE,OPTIMIZE_KEY,OPTIMIZE_OP, OPTIMIZE_NULL,
63
 
                       OPTIMIZE_EQUAL };
64
 
  enum Type type() const { return FUNC_ITEM; }
65
 
  virtual enum Functype functype() const   { return UNKNOWN_FUNC; }
66
 
  virtual ~Item_func() {}
67
 
 
68
 
  Item_func(void):
69
 
    _session(*current_session),
70
 
    allowed_arg_cols(1), arg_count(0)
71
 
  {
72
 
    with_sum_func= 0;
73
 
    collation.set(DERIVATION_SYSCONST);
74
 
  }
75
 
 
76
 
  Item_func(Item *a):
77
 
    _session(*current_session),
78
 
    allowed_arg_cols(1), arg_count(1)
79
 
  {
80
 
    args= tmp_arg;
81
 
    args[0]= a;
82
 
    with_sum_func= a->with_sum_func;
83
 
    collation.set(DERIVATION_SYSCONST);
84
 
  }
85
 
  
86
 
  Item_func(Item *a,Item *b):
87
 
    _session(*current_session),
88
 
    allowed_arg_cols(1), arg_count(2)
89
 
  {
90
 
    args= tmp_arg;
91
 
    args[0]= a; args[1]= b;
92
 
    with_sum_func= a->with_sum_func || b->with_sum_func;
93
 
    collation.set(DERIVATION_SYSCONST);
94
 
  }
95
 
  
96
 
  Item_func(Item *a,Item *b,Item *c):
97
 
    _session(*current_session),
98
 
    allowed_arg_cols(1)
99
 
  {
100
 
    arg_count= 0;
101
 
    if ((args= (Item**) memory::sql_alloc(sizeof(Item*)*3)))
102
 
    {
103
 
      arg_count= 3;
104
 
      args[0]= a; args[1]= b; args[2]= c;
105
 
      with_sum_func= a->with_sum_func || b->with_sum_func || c->with_sum_func;
106
 
    }
107
 
    collation.set(DERIVATION_SYSCONST);
108
 
  }
109
 
  
110
 
  Item_func(Item *a,Item *b,Item *c,Item *d):
111
 
    _session(*current_session),
112
 
    allowed_arg_cols(1)
113
 
  {
114
 
    arg_count= 0;
115
 
    if ((args= (Item**) memory::sql_alloc(sizeof(Item*)*4)))
116
 
    {
117
 
      arg_count= 4;
118
 
      args[0]= a; args[1]= b; args[2]= c; args[3]= d;
119
 
      with_sum_func= a->with_sum_func || b->with_sum_func ||
120
 
        c->with_sum_func || d->with_sum_func;
121
 
    }
122
 
    collation.set(DERIVATION_SYSCONST);
123
 
  }
124
 
  
125
 
  Item_func(Item *a,Item *b,Item *c,Item *d,Item* e):
126
 
    _session(*current_session),
127
 
    allowed_arg_cols(1)
128
 
  {
129
 
    arg_count= 5;
130
 
    if ((args= (Item**) memory::sql_alloc(sizeof(Item*)*5)))
131
 
    {
132
 
      args[0]= a; args[1]= b; args[2]= c; args[3]= d; args[4]= e;
133
 
      with_sum_func= a->with_sum_func || b->with_sum_func ||
134
 
        c->with_sum_func || d->with_sum_func || e->with_sum_func ;
135
 
    }
136
 
    collation.set(DERIVATION_SYSCONST);
137
 
  }
138
 
  
139
 
  Item_func(List<Item> &list);
140
 
  
141
 
  // 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);
146
 
  table_map used_tables() const;
147
 
  table_map not_null_tables() const;
148
 
  void update_used_tables();
149
 
  bool eq(const Item *item, bool binary_cmp) const;
150
 
  virtual optimize_type select_optimize() const { return OPTIMIZE_NONE; }
151
 
  virtual bool have_rev_func() const { return 0; }
152
 
  virtual Item *key_item() const { return args[0]; }
153
 
  /*
154
 
    This method is used for debug purposes to print the name of an
155
 
    item to the debug log. The second use of this method is as
156
 
    a helper function of print(), where it is applicable.
157
 
    To suit both goals it should return a meaningful,
158
 
    distinguishable and sintactically correct string.  This method
159
 
    should not be used for runtime type identification, use enum
160
 
    {Sum}Functype and Item_func::functype()/Item_sum::sum_func()
161
 
    instead.
162
 
  */
163
 
  virtual const char *func_name() const { return NULL; }
164
 
  virtual bool const_item() const { return const_item_cache; }
165
 
  Item **arguments() const { return args; }
166
 
  void set_arguments(List<Item> &list);
167
 
  uint32_t argument_count() const { return arg_count; }
168
 
  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
 
 
178
 
  virtual void print(String *str, enum_query_type query_type);
179
 
  void print_op(String *str, enum_query_type query_type);
180
 
  void print_args(String *str, uint32_t from, enum_query_type query_type);
181
 
  virtual void fix_num_length_and_dec();
182
 
  void count_only_length();
183
 
  void count_real_length();
184
 
  void count_decimal_length();
185
 
 
186
 
  bool get_arg0_date(DRIZZLE_TIME *ltime, uint32_t fuzzy_date);
187
 
  bool get_arg0_time(DRIZZLE_TIME *ltime);
188
 
 
189
 
  bool is_null();
190
 
 
191
 
  void signal_divide_by_null();
192
 
 
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);
197
 
 
198
 
  my_decimal *val_decimal(my_decimal *);
199
 
 
200
 
  bool agg_arg_collations(DTCollation &c, Item **items, uint32_t nitems,
201
 
                          uint32_t flags);
202
 
  bool agg_arg_collations_for_comparison(DTCollation &c,
203
 
                                         Item **items, uint32_t nitems,
204
 
                                         uint32_t flags);
205
 
  bool agg_arg_charsets(DTCollation &c, Item **items, uint32_t nitems,
206
 
                        uint32_t flags, int item_sep);
207
 
  bool walk(Item_processor processor, bool walk_subquery, unsigned char *arg);
208
 
  Item *transform(Item_transformer transformer, unsigned char *arg);
209
 
  Item* compile(Item_analyzer analyzer, unsigned char **arg_p,
210
 
                Item_transformer transformer, unsigned char *arg_t);
211
 
  void traverse_cond(Cond_traverser traverser,
212
 
                     void * arg, traverse_order order);
213
 
  double fix_result(double value);
214
 
 
215
 
  Session &getSession()
216
 
  {
217
 
    return _session;
218
 
  }
219
 
 
220
 
  Session *getSessionPtr()
221
 
  {
222
 
    return &_session;
223
 
  }
224
 
 
225
 
};
226
 
 
227
 
} /* namespace drizzled */
228
 
 
229
 
 
230
 
#endif /* DRIZZLED_FUNCTION_FUNC_H */