~drizzle-trunk/drizzle/development

489.1.8 by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one)
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
489.1.8 by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one)
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
670.1.20 by Monty Taylor
Renamed functions to function... everything else is singular.
20
#ifndef DRIZZLED_FUNCTION_FUNC_H
21
#define DRIZZLED_FUNCTION_FUNC_H
489.1.8 by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one)
22
23
/// TODO: Rename this file - func.h is stupid.
24
25
#include <drizzled/item.h>
26
#include <drizzled/sql_list.h>
642.1.62 by Lee
more header file cleanup
27
#include <drizzled/item/bin_string.h>
1633.4.7 by Brian Aker
Put a copy of the Session in the root of function to make use of.
28
#include "drizzled/current_session.h"
489.1.8 by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one)
29
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
30
namespace drizzled
31
{
489.1.8 by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one)
32
33
class Item_func :public Item_result_field
34
{
1633.4.7 by Brian Aker
Put a copy of the Session in the root of function to make use of.
35
  Session &_session;
36
489.1.8 by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one)
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:
779.3.18 by Monty Taylor
Cleaned up warnings up through innodb.
45
46
  using Item::split_sum_func;
47
489.1.8 by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one)
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; }
1022.2.29 by Monty Taylor
Fixed some no-inline warnings.
66
  virtual ~Item_func() {}
1633.4.7 by Brian Aker
Put a copy of the Session in the root of function to make use of.
67
489.1.8 by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one)
68
  Item_func(void):
1633.4.7 by Brian Aker
Put a copy of the Session in the root of function to make use of.
69
    _session(*current_session),
2060 by Brian Aker
Added native functions into the function table.
70
    allowed_arg_cols(1), arg_count(0),
71
    const_item_cache(false)
489.1.8 by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one)
72
  {
73
    with_sum_func= 0;
1717.1.2 by LinuxJedi
Set string functions to use DERIVATION_SYSCONST.
74
    collation.set(DERIVATION_SYSCONST);
489.1.8 by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one)
75
  }
1633.4.7 by Brian Aker
Put a copy of the Session in the root of function to make use of.
76
489.1.8 by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one)
77
  Item_func(Item *a):
1633.4.7 by Brian Aker
Put a copy of the Session in the root of function to make use of.
78
    _session(*current_session),
2060 by Brian Aker
Added native functions into the function table.
79
    allowed_arg_cols(1), arg_count(1),
80
    const_item_cache(false)
489.1.8 by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one)
81
  {
82
    args= tmp_arg;
83
    args[0]= a;
84
    with_sum_func= a->with_sum_func;
1717.1.2 by LinuxJedi
Set string functions to use DERIVATION_SYSCONST.
85
    collation.set(DERIVATION_SYSCONST);
489.1.8 by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one)
86
  }
1633.4.7 by Brian Aker
Put a copy of the Session in the root of function to make use of.
87
  
489.1.8 by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one)
88
  Item_func(Item *a,Item *b):
1633.4.7 by Brian Aker
Put a copy of the Session in the root of function to make use of.
89
    _session(*current_session),
2060 by Brian Aker
Added native functions into the function table.
90
    allowed_arg_cols(1), arg_count(2),
91
    const_item_cache(false)
489.1.8 by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one)
92
  {
93
    args= tmp_arg;
94
    args[0]= a; args[1]= b;
95
    with_sum_func= a->with_sum_func || b->with_sum_func;
1717.1.2 by LinuxJedi
Set string functions to use DERIVATION_SYSCONST.
96
    collation.set(DERIVATION_SYSCONST);
489.1.8 by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one)
97
  }
1633.4.7 by Brian Aker
Put a copy of the Session in the root of function to make use of.
98
  
489.1.8 by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one)
99
  Item_func(Item *a,Item *b,Item *c):
1633.4.7 by Brian Aker
Put a copy of the Session in the root of function to make use of.
100
    _session(*current_session),
2060 by Brian Aker
Added native functions into the function table.
101
    allowed_arg_cols(1),
102
    const_item_cache(false)
489.1.8 by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one)
103
  {
104
    arg_count= 0;
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
105
    if ((args= (Item**) memory::sql_alloc(sizeof(Item*)*3)))
489.1.8 by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one)
106
    {
107
      arg_count= 3;
108
      args[0]= a; args[1]= b; args[2]= c;
109
      with_sum_func= a->with_sum_func || b->with_sum_func || c->with_sum_func;
110
    }
1717.1.2 by LinuxJedi
Set string functions to use DERIVATION_SYSCONST.
111
    collation.set(DERIVATION_SYSCONST);
489.1.8 by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one)
112
  }
1633.4.7 by Brian Aker
Put a copy of the Session in the root of function to make use of.
113
  
489.1.8 by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one)
114
  Item_func(Item *a,Item *b,Item *c,Item *d):
1633.4.7 by Brian Aker
Put a copy of the Session in the root of function to make use of.
115
    _session(*current_session),
2060 by Brian Aker
Added native functions into the function table.
116
    allowed_arg_cols(1),
117
    const_item_cache(false)
489.1.8 by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one)
118
  {
119
    arg_count= 0;
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
120
    if ((args= (Item**) memory::sql_alloc(sizeof(Item*)*4)))
489.1.8 by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one)
121
    {
122
      arg_count= 4;
123
      args[0]= a; args[1]= b; args[2]= c; args[3]= d;
124
      with_sum_func= a->with_sum_func || b->with_sum_func ||
125
        c->with_sum_func || d->with_sum_func;
126
    }
1717.1.2 by LinuxJedi
Set string functions to use DERIVATION_SYSCONST.
127
    collation.set(DERIVATION_SYSCONST);
489.1.8 by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one)
128
  }
1633.4.7 by Brian Aker
Put a copy of the Session in the root of function to make use of.
129
  
489.1.8 by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one)
130
  Item_func(Item *a,Item *b,Item *c,Item *d,Item* e):
1633.4.7 by Brian Aker
Put a copy of the Session in the root of function to make use of.
131
    _session(*current_session),
2060 by Brian Aker
Added native functions into the function table.
132
    allowed_arg_cols(1),
133
    const_item_cache(false)
489.1.8 by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one)
134
  {
135
    arg_count= 5;
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
136
    if ((args= (Item**) memory::sql_alloc(sizeof(Item*)*5)))
489.1.8 by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one)
137
    {
138
      args[0]= a; args[1]= b; args[2]= c; args[3]= d; args[4]= e;
139
      with_sum_func= a->with_sum_func || b->with_sum_func ||
140
        c->with_sum_func || d->with_sum_func || e->with_sum_func ;
141
    }
1717.1.2 by LinuxJedi
Set string functions to use DERIVATION_SYSCONST.
142
    collation.set(DERIVATION_SYSCONST);
489.1.8 by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one)
143
  }
1633.4.7 by Brian Aker
Put a copy of the Session in the root of function to make use of.
144
  
489.1.8 by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one)
145
  Item_func(List<Item> &list);
1633.4.7 by Brian Aker
Put a copy of the Session in the root of function to make use of.
146
  
489.1.8 by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one)
147
  // Constructor used for Item_cond_and/or (see Item comment)
520.1.22 by Brian Aker
Second pass of thd cleanup
148
  Item_func(Session *session, Item_func *item);
1633.4.7 by Brian Aker
Put a copy of the Session in the root of function to make use of.
149
  
520.1.21 by Brian Aker
THD -> Session rename
150
  bool fix_fields(Session *, Item **ref);
846 by Brian Aker
Removing on typedeffed class.
151
  void fix_after_pullout(Select_Lex *new_parent, Item **ref);
489.1.8 by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one)
152
  table_map used_tables() const;
153
  table_map not_null_tables() const;
154
  void update_used_tables();
155
  bool eq(const Item *item, bool binary_cmp) const;
156
  virtual optimize_type select_optimize() const { return OPTIMIZE_NONE; }
157
  virtual bool have_rev_func() const { return 0; }
158
  virtual Item *key_item() const { return args[0]; }
159
  /*
160
    This method is used for debug purposes to print the name of an
161
    item to the debug log. The second use of this method is as
162
    a helper function of print(), where it is applicable.
163
    To suit both goals it should return a meaningful,
164
    distinguishable and sintactically correct string.  This method
165
    should not be used for runtime type identification, use enum
166
    {Sum}Functype and Item_func::functype()/Item_sum::sum_func()
167
    instead.
168
  */
1891.2.1 by Monty Taylor
Fixed things to make things compile with clang
169
  virtual const char *func_name() const { return NULL; }
489.1.8 by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one)
170
  virtual bool const_item() const { return const_item_cache; }
171
  Item **arguments() const { return args; }
172
  void set_arguments(List<Item> &list);
173
  uint32_t argument_count() const { return arg_count; }
174
  void remove_arguments() { arg_count=0; }
1005.1.2 by Monty Taylor
Merged Stewart from lp:~stewart-flamingspork/drizzle/fix-function-arguments
175
176
  /**
177
   * Check if the UDF supports the number of arguments passed in
178
   * @param number of args
179
   */
180
  virtual bool check_argument_count(int) { return true ; }
779.3.16 by Monty Taylor
Some Sun warning fixes.
181
  virtual void split_sum_func(Session *session, Item **ref_pointer_array,
182
                              List<Item> &fields);
183
489.1.8 by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one)
184
  virtual void print(String *str, enum_query_type query_type);
185
  void print_op(String *str, enum_query_type query_type);
186
  void print_args(String *str, uint32_t from, enum_query_type query_type);
187
  virtual void fix_num_length_and_dec();
188
  void count_only_length();
189
  void count_real_length();
190
  void count_decimal_length();
191
2030.1.5 by Brian Aker
Update for moving DRIZZLE_TIME to type::Time
192
  bool get_arg0_date(type::Time *ltime, uint32_t fuzzy_date);
193
  bool get_arg0_time(type::Time *ltime);
489.1.8 by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one)
194
195
  bool is_null();
196
2060 by Brian Aker
Added native functions into the function table.
197
  virtual bool deterministic() const
198
  {
199
    return false;
200
  }
201
489.1.8 by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one)
202
  void signal_divide_by_null();
203
779.3.16 by Monty Taylor
Some Sun warning fixes.
204
  virtual Field *tmp_table_field() { return result_field; }
205
  virtual Field *tmp_table_field(Table *t_arg);
206
520.1.22 by Brian Aker
Second pass of thd cleanup
207
  Item *get_tmp_table_item(Session *session);
489.1.8 by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one)
208
2030.1.4 by Brian Aker
Change my_decimal to Decimal
209
  type::Decimal *val_decimal(type::Decimal *);
489.1.8 by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one)
210
211
  bool agg_arg_collations(DTCollation &c, Item **items, uint32_t nitems,
212
                          uint32_t flags);
213
  bool agg_arg_collations_for_comparison(DTCollation &c,
214
                                         Item **items, uint32_t nitems,
215
                                         uint32_t flags);
216
  bool agg_arg_charsets(DTCollation &c, Item **items, uint32_t nitems,
217
                        uint32_t flags, int item_sep);
218
  bool walk(Item_processor processor, bool walk_subquery, unsigned char *arg);
219
  Item *transform(Item_transformer transformer, unsigned char *arg);
220
  Item* compile(Item_analyzer analyzer, unsigned char **arg_p,
221
                Item_transformer transformer, unsigned char *arg_t);
222
  void traverse_cond(Cond_traverser traverser,
223
                     void * arg, traverse_order order);
224
  double fix_result(double value);
225
1633.4.7 by Brian Aker
Put a copy of the Session in the root of function to make use of.
226
  Session &getSession()
227
  {
228
    return _session;
229
  }
230
231
  Session *getSessionPtr()
232
  {
233
    return &_session;
234
  }
235
489.1.8 by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one)
236
};
237
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
238
} /* namespace drizzled */
239
489.1.8 by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one)
240
670.1.20 by Monty Taylor
Renamed functions to function... everything else is singular.
241
#endif /* DRIZZLED_FUNCTION_FUNC_H */