~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
 *
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
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>
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)
28
29
30
class Item_func :public Item_result_field
31
{
32
protected:
33
  Item **args, *tmp_arg[2];
34
  /*
35
    Allowed numbers of columns in result (usually 1, which means scalar value)
36
    0 means get this number from first argument
37
  */
38
  uint32_t allowed_arg_cols;
39
public:
779.3.18 by Monty Taylor
Cleaned up warnings up through innodb.
40
41
  using Item::split_sum_func;
42
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)
43
  uint32_t arg_count;
44
  table_map used_tables_cache, not_null_tables_cache;
45
  bool const_item_cache;
46
  enum Functype { UNKNOWN_FUNC,EQ_FUNC,EQUAL_FUNC,NE_FUNC,LT_FUNC,LE_FUNC,
47
                  GE_FUNC,GT_FUNC,
48
                  LIKE_FUNC,ISNULL_FUNC,ISNOTNULL_FUNC,
49
                  COND_AND_FUNC, COND_OR_FUNC, COND_XOR_FUNC,
50
                  BETWEEN, IN_FUNC, MULT_EQUAL_FUNC,
51
                  INTERVAL_FUNC, ISNOTNULLTEST_FUNC,
52
                  NOT_FUNC, NOT_ALL_FUNC,
53
                  NOW_FUNC, TRIG_COND_FUNC,
54
                  SUSERVAR_FUNC, GUSERVAR_FUNC, COLLATE_FUNC,
55
                  EXTRACT_FUNC, CHAR_TYPECAST_FUNC, FUNC_SP,
56
                  NEG_FUNC };
57
  enum optimize_type { OPTIMIZE_NONE,OPTIMIZE_KEY,OPTIMIZE_OP, OPTIMIZE_NULL,
58
                       OPTIMIZE_EQUAL };
59
  enum Type type() const { return FUNC_ITEM; }
60
  virtual enum Functype functype() const   { return UNKNOWN_FUNC; }
1022.2.29 by Monty Taylor
Fixed some no-inline warnings.
61
  virtual ~Item_func() {}
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)
62
  Item_func(void):
63
    allowed_arg_cols(1), arg_count(0)
64
  {
65
    with_sum_func= 0;
66
  }
67
  Item_func(Item *a):
68
    allowed_arg_cols(1), arg_count(1)
69
  {
70
    args= tmp_arg;
71
    args[0]= a;
72
    with_sum_func= a->with_sum_func;
73
  }
74
  Item_func(Item *a,Item *b):
75
    allowed_arg_cols(1), arg_count(2)
76
  {
77
    args= tmp_arg;
78
    args[0]= a; args[1]= b;
79
    with_sum_func= a->with_sum_func || b->with_sum_func;
80
  }
81
  Item_func(Item *a,Item *b,Item *c):
82
    allowed_arg_cols(1)
83
  {
84
    arg_count= 0;
85
    if ((args= (Item**) sql_alloc(sizeof(Item*)*3)))
86
    {
87
      arg_count= 3;
88
      args[0]= a; args[1]= b; args[2]= c;
89
      with_sum_func= a->with_sum_func || b->with_sum_func || c->with_sum_func;
90
    }
91
  }
92
  Item_func(Item *a,Item *b,Item *c,Item *d):
93
    allowed_arg_cols(1)
94
  {
95
    arg_count= 0;
96
    if ((args= (Item**) sql_alloc(sizeof(Item*)*4)))
97
    {
98
      arg_count= 4;
99
      args[0]= a; args[1]= b; args[2]= c; args[3]= d;
100
      with_sum_func= a->with_sum_func || b->with_sum_func ||
101
        c->with_sum_func || d->with_sum_func;
102
    }
103
  }
104
  Item_func(Item *a,Item *b,Item *c,Item *d,Item* e):
105
    allowed_arg_cols(1)
106
  {
107
    arg_count= 5;
108
    if ((args= (Item**) sql_alloc(sizeof(Item*)*5)))
109
    {
110
      args[0]= a; args[1]= b; args[2]= c; args[3]= d; args[4]= e;
111
      with_sum_func= a->with_sum_func || b->with_sum_func ||
112
        c->with_sum_func || d->with_sum_func || e->with_sum_func ;
113
    }
114
  }
115
  Item_func(List<Item> &list);
116
  // Constructor used for Item_cond_and/or (see Item comment)
520.1.22 by Brian Aker
Second pass of thd cleanup
117
  Item_func(Session *session, Item_func *item);
520.1.21 by Brian Aker
THD -> Session rename
118
  bool fix_fields(Session *, Item **ref);
846 by Brian Aker
Removing on typedeffed class.
119
  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)
120
  table_map used_tables() const;
121
  table_map not_null_tables() const;
122
  void update_used_tables();
123
  bool eq(const Item *item, bool binary_cmp) const;
124
  virtual optimize_type select_optimize() const { return OPTIMIZE_NONE; }
125
  virtual bool have_rev_func() const { return 0; }
126
  virtual Item *key_item() const { return args[0]; }
127
  /*
128
    This method is used for debug purposes to print the name of an
129
    item to the debug log. The second use of this method is as
130
    a helper function of print(), where it is applicable.
131
    To suit both goals it should return a meaningful,
132
    distinguishable and sintactically correct string.  This method
133
    should not be used for runtime type identification, use enum
134
    {Sum}Functype and Item_func::functype()/Item_sum::sum_func()
135
    instead.
136
  */
137
  virtual const char *func_name() const { return NULL; };
138
  virtual bool const_item() const { return const_item_cache; }
139
  Item **arguments() const { return args; }
140
  void set_arguments(List<Item> &list);
141
  uint32_t argument_count() const { return arg_count; }
142
  void remove_arguments() { arg_count=0; }
1005.1.2 by Monty Taylor
Merged Stewart from lp:~stewart-flamingspork/drizzle/fix-function-arguments
143
144
  /**
145
   * Check if the UDF supports the number of arguments passed in
146
   * @param number of args
147
   */
148
  virtual bool check_argument_count(int) { return true ; }
779.3.16 by Monty Taylor
Some Sun warning fixes.
149
  virtual void split_sum_func(Session *session, Item **ref_pointer_array,
150
                              List<Item> &fields);
151
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
  virtual void print(String *str, enum_query_type query_type);
153
  void print_op(String *str, enum_query_type query_type);
154
  void print_args(String *str, uint32_t from, enum_query_type query_type);
155
  virtual void fix_num_length_and_dec();
156
  void count_only_length();
157
  void count_real_length();
158
  void count_decimal_length();
159
160
  bool get_arg0_date(DRIZZLE_TIME *ltime, uint32_t fuzzy_date);
161
  bool get_arg0_time(DRIZZLE_TIME *ltime);
162
163
  bool is_null();
164
165
  void signal_divide_by_null();
166
779.3.16 by Monty Taylor
Some Sun warning fixes.
167
  virtual Field *tmp_table_field() { return result_field; }
168
  virtual Field *tmp_table_field(Table *t_arg);
169
520.1.22 by Brian Aker
Second pass of thd cleanup
170
  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)
171
172
  my_decimal *val_decimal(my_decimal *);
173
174
  bool agg_arg_collations(DTCollation &c, Item **items, uint32_t nitems,
175
                          uint32_t flags);
176
  bool agg_arg_collations_for_comparison(DTCollation &c,
177
                                         Item **items, uint32_t nitems,
178
                                         uint32_t flags);
179
  bool agg_arg_charsets(DTCollation &c, Item **items, uint32_t nitems,
180
                        uint32_t flags, int item_sep);
181
  bool walk(Item_processor processor, bool walk_subquery, unsigned char *arg);
182
  Item *transform(Item_transformer transformer, unsigned char *arg);
183
  Item* compile(Item_analyzer analyzer, unsigned char **arg_p,
184
                Item_transformer transformer, unsigned char *arg_t);
185
  void traverse_cond(Cond_traverser traverser,
186
                     void * arg, traverse_order order);
187
  double fix_result(double value);
188
189
};
190
191
670.1.20 by Monty Taylor
Renamed functions to function... everything else is singular.
192
#endif /* DRIZZLED_FUNCTION_FUNC_H */