~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/functions/func.h

  • Committer: Brian Aker
  • Date: 2008-11-04 15:39:09 UTC
  • mfrom: (575.1.2 devel)
  • Revision ID: brian@tangent.org-20081104153909-c72hn65udxs1ccal
Merge of Monty's work

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_functions_func_h
 
21
#define drizzled_functions_func_h
 
22
 
 
23
/// TODO: Rename this file - func.h is stupid.
 
24
 
 
25
#include <drizzled/item.h>
 
26
#include <drizzled/item_func.h>
 
27
#include <drizzled/sql_list.h>
 
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:
 
40
  uint32_t arg_count;
 
41
  table_map used_tables_cache, not_null_tables_cache;
 
42
  bool const_item_cache;
 
43
  enum Functype { UNKNOWN_FUNC,EQ_FUNC,EQUAL_FUNC,NE_FUNC,LT_FUNC,LE_FUNC,
 
44
                  GE_FUNC,GT_FUNC,
 
45
                  LIKE_FUNC,ISNULL_FUNC,ISNOTNULL_FUNC,
 
46
                  COND_AND_FUNC, COND_OR_FUNC, COND_XOR_FUNC,
 
47
                  BETWEEN, IN_FUNC, MULT_EQUAL_FUNC,
 
48
                  INTERVAL_FUNC, ISNOTNULLTEST_FUNC,
 
49
                  NOT_FUNC, NOT_ALL_FUNC,
 
50
                  NOW_FUNC, TRIG_COND_FUNC,
 
51
                  SUSERVAR_FUNC, GUSERVAR_FUNC, COLLATE_FUNC,
 
52
                  EXTRACT_FUNC, CHAR_TYPECAST_FUNC, FUNC_SP,
 
53
                  NEG_FUNC };
 
54
  enum optimize_type { OPTIMIZE_NONE,OPTIMIZE_KEY,OPTIMIZE_OP, OPTIMIZE_NULL,
 
55
                       OPTIMIZE_EQUAL };
 
56
  enum Type type() const { return FUNC_ITEM; }
 
57
  virtual enum Functype functype() const   { return UNKNOWN_FUNC; }
 
58
  Item_func(void):
 
59
    allowed_arg_cols(1), arg_count(0)
 
60
  {
 
61
    with_sum_func= 0;
 
62
  }
 
63
  Item_func(Item *a):
 
64
    allowed_arg_cols(1), arg_count(1)
 
65
  {
 
66
    args= tmp_arg;
 
67
    args[0]= a;
 
68
    with_sum_func= a->with_sum_func;
 
69
  }
 
70
  Item_func(Item *a,Item *b):
 
71
    allowed_arg_cols(1), arg_count(2)
 
72
  {
 
73
    args= tmp_arg;
 
74
    args[0]= a; args[1]= b;
 
75
    with_sum_func= a->with_sum_func || b->with_sum_func;
 
76
  }
 
77
  Item_func(Item *a,Item *b,Item *c):
 
78
    allowed_arg_cols(1)
 
79
  {
 
80
    arg_count= 0;
 
81
    if ((args= (Item**) sql_alloc(sizeof(Item*)*3)))
 
82
    {
 
83
      arg_count= 3;
 
84
      args[0]= a; args[1]= b; args[2]= c;
 
85
      with_sum_func= a->with_sum_func || b->with_sum_func || c->with_sum_func;
 
86
    }
 
87
  }
 
88
  Item_func(Item *a,Item *b,Item *c,Item *d):
 
89
    allowed_arg_cols(1)
 
90
  {
 
91
    arg_count= 0;
 
92
    if ((args= (Item**) sql_alloc(sizeof(Item*)*4)))
 
93
    {
 
94
      arg_count= 4;
 
95
      args[0]= a; args[1]= b; args[2]= c; args[3]= d;
 
96
      with_sum_func= a->with_sum_func || b->with_sum_func ||
 
97
        c->with_sum_func || d->with_sum_func;
 
98
    }
 
99
  }
 
100
  Item_func(Item *a,Item *b,Item *c,Item *d,Item* e):
 
101
    allowed_arg_cols(1)
 
102
  {
 
103
    arg_count= 5;
 
104
    if ((args= (Item**) sql_alloc(sizeof(Item*)*5)))
 
105
    {
 
106
      args[0]= a; args[1]= b; args[2]= c; args[3]= d; args[4]= e;
 
107
      with_sum_func= a->with_sum_func || b->with_sum_func ||
 
108
        c->with_sum_func || d->with_sum_func || e->with_sum_func ;
 
109
    }
 
110
  }
 
111
  Item_func(List<Item> &list);
 
112
  // Constructor used for Item_cond_and/or (see Item comment)
 
113
  Item_func(Session *session, Item_func *item);
 
114
  bool fix_fields(Session *, Item **ref);
 
115
  void fix_after_pullout(st_select_lex *new_parent, Item **ref);
 
116
  table_map used_tables() const;
 
117
  table_map not_null_tables() const;
 
118
  void update_used_tables();
 
119
  bool eq(const Item *item, bool binary_cmp) const;
 
120
  virtual optimize_type select_optimize() const { return OPTIMIZE_NONE; }
 
121
  virtual bool have_rev_func() const { return 0; }
 
122
  virtual Item *key_item() const { return args[0]; }
 
123
  /*
 
124
    This method is used for debug purposes to print the name of an
 
125
    item to the debug log. The second use of this method is as
 
126
    a helper function of print(), where it is applicable.
 
127
    To suit both goals it should return a meaningful,
 
128
    distinguishable and sintactically correct string.  This method
 
129
    should not be used for runtime type identification, use enum
 
130
    {Sum}Functype and Item_func::functype()/Item_sum::sum_func()
 
131
    instead.
 
132
  */
 
133
  virtual const char *func_name() const { return NULL; };
 
134
  virtual bool const_item() const { return const_item_cache; }
 
135
  Item **arguments() const { return args; }
 
136
  void set_arguments(List<Item> &list);
 
137
  uint32_t argument_count() const { return arg_count; }
 
138
  void remove_arguments() { arg_count=0; }
 
139
  void split_sum_func(Session *session, Item **ref_pointer_array, List<Item> &fields);
 
140
  virtual void print(String *str, enum_query_type query_type);
 
141
  void print_op(String *str, enum_query_type query_type);
 
142
  void print_args(String *str, uint32_t from, enum_query_type query_type);
 
143
  virtual void fix_num_length_and_dec();
 
144
  void count_only_length();
 
145
  void count_real_length();
 
146
  void count_decimal_length();
 
147
 
 
148
  bool get_arg0_date(DRIZZLE_TIME *ltime, uint32_t fuzzy_date);
 
149
  bool get_arg0_time(DRIZZLE_TIME *ltime);
 
150
 
 
151
  bool is_null();
 
152
 
 
153
  void signal_divide_by_null();
 
154
 
 
155
  Field *tmp_table_field() { return result_field; }
 
156
  Field *tmp_table_field(Table *t_arg);
 
157
  Item *get_tmp_table_item(Session *session);
 
158
 
 
159
  my_decimal *val_decimal(my_decimal *);
 
160
 
 
161
  bool agg_arg_collations(DTCollation &c, Item **items, uint32_t nitems,
 
162
                          uint32_t flags);
 
163
  bool agg_arg_collations_for_comparison(DTCollation &c,
 
164
                                         Item **items, uint32_t nitems,
 
165
                                         uint32_t flags);
 
166
  bool agg_arg_charsets(DTCollation &c, Item **items, uint32_t nitems,
 
167
                        uint32_t flags, int item_sep);
 
168
  bool walk(Item_processor processor, bool walk_subquery, unsigned char *arg);
 
169
  Item *transform(Item_transformer transformer, unsigned char *arg);
 
170
  Item* compile(Item_analyzer analyzer, unsigned char **arg_p,
 
171
                Item_transformer transformer, unsigned char *arg_t);
 
172
  void traverse_cond(Cond_traverser traverser,
 
173
                     void * arg, traverse_order order);
 
174
  double fix_result(double value);
 
175
 
 
176
};
 
177
 
 
178
 
 
179
#endif