~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item_func.h

MergedĀ fromĀ lee.

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
#include <drizzled/functions/connection_id.h>
36
36
#include <drizzled/functions/decimal_typecast.h>
37
37
#include <drizzled/functions/divide.h>
 
38
#include <drizzled/functions/get_system_var.h>
38
39
#include <drizzled/functions/int.h>
 
40
#include <drizzled/functions/bit.h>
 
41
#include <drizzled/functions/bit_count.h>
 
42
#include <drizzled/functions/bit_length.h>
 
43
#include <drizzled/functions/find_in_set.h>
39
44
#include <drizzled/functions/int_divide.h>
40
45
#include <drizzled/functions/length.h>
41
46
#include <drizzled/functions/min_max.h>
49
54
#include <drizzled/functions/abs.h>
50
55
#include <drizzled/functions/plus.h>
51
56
#include <drizzled/functions/real.h>
 
57
#include <drizzled/functions/rollup_const.h>
52
58
#include <drizzled/functions/dec.h>
53
59
#include <drizzled/functions/int_val.h>
54
60
#include <drizzled/functions/acos.h>
 
61
#include <drizzled/functions/ascii.h>
55
62
#include <drizzled/functions/asin.h>
56
63
#include <drizzled/functions/atan.h>
 
64
#include <drizzled/functions/benchmark.h>
 
65
#include <drizzled/functions/char_length.h>
57
66
#include <drizzled/functions/ceiling.h>
58
67
#include <drizzled/functions/cos.h>
59
68
#include <drizzled/functions/exp.h>
60
69
#include <drizzled/functions/floor.h>
 
70
#include <drizzled/functions/last_insert.h>
61
71
#include <drizzled/functions/ln.h>
62
72
#include <drizzled/functions/log.h>
 
73
#include <drizzled/functions/units.h>
 
74
#include <drizzled/functions/ord.h>
63
75
#include <drizzled/functions/pow.h>
64
76
#include <drizzled/functions/rand.h>
65
77
#include <drizzled/functions/round.h>
77
89
  void fix_length_and_dec();
78
90
};
79
91
 
80
 
class Item_func_units :public Item_real_func
81
 
{
82
 
  char *name;
83
 
  double mul,add;
84
 
public:
85
 
  Item_func_units(char *name_arg,Item *a,double mul_arg,double add_arg)
86
 
    :Item_real_func(a),name(name_arg),mul(mul_arg),add(add_arg) {}
87
 
  double val_real();
88
 
  const char *func_name() const { return name; }
89
 
  void fix_length_and_dec()
90
 
  { decimals= NOT_FIXED_DEC; max_length= float_length(decimals); }
91
 
};
92
 
 
93
 
 
94
 
/* 
95
 
  Objects of this class are used for ROLLUP queries to wrap up 
96
 
  each constant item referred to in GROUP BY list. 
97
 
*/
98
 
 
99
 
class Item_func_rollup_const :public Item_func
100
 
{
101
 
public:
102
 
  Item_func_rollup_const(Item *a) :Item_func(a)
103
 
  {
104
 
    name= a->name;
105
 
    name_length= a->name_length;
106
 
  }
107
 
  double val_real() { return args[0]->val_real(); }
108
 
  int64_t val_int() { return args[0]->val_int(); }
109
 
  String *val_str(String *str) { return args[0]->val_str(str); }
110
 
  my_decimal *val_decimal(my_decimal *dec) { return args[0]->val_decimal(dec); }
111
 
  const char *func_name() const { return "rollup_const"; }
112
 
  bool const_item() const { return 0; }
113
 
  Item_result result_type() const { return args[0]->result_type(); }
114
 
  void fix_length_and_dec()
115
 
  {
116
 
    collation= args[0]->collation;
117
 
    max_length= args[0]->max_length;
118
 
    decimals=args[0]->decimals; 
119
 
    /* The item could be a NULL constant. */
120
 
    null_value= args[0]->is_null();
121
 
  }
122
 
};
123
 
 
124
 
class Item_func_bit_length :public Item_func_length
125
 
{
126
 
public:
127
 
  Item_func_bit_length(Item *a) :Item_func_length(a) {}
128
 
  int64_t val_int()
129
 
    { assert(fixed == 1); return Item_func_length::val_int()*8; }
130
 
  const char *func_name() const { return "bit_length"; }
131
 
};
132
 
 
133
 
class Item_func_char_length :public Item_int_func
134
 
{
135
 
  String value;
136
 
public:
137
 
  Item_func_char_length(Item *a) :Item_int_func(a) {}
138
 
  int64_t val_int();
139
 
  const char *func_name() const { return "char_length"; }
140
 
  void fix_length_and_dec() { max_length=10; }
141
 
};
142
 
 
143
 
class Item_func_coercibility :public Item_int_func
144
 
{
145
 
public:
146
 
  Item_func_coercibility(Item *a) :Item_int_func(a) {}
147
 
  int64_t val_int();
148
 
  const char *func_name() const { return "coercibility"; }
149
 
  void fix_length_and_dec() { max_length=10; maybe_null= 0; }
150
 
  table_map not_null_tables() const { return 0; }
151
 
};
152
 
 
153
 
class Item_func_locate :public Item_int_func
154
 
{
155
 
  String value1,value2;
156
 
  DTCollation cmp_collation;
157
 
public:
158
 
  Item_func_locate(Item *a,Item *b) :Item_int_func(a,b) {}
159
 
  Item_func_locate(Item *a,Item *b,Item *c) :Item_int_func(a,b,c) {}
160
 
  const char *func_name() const { return "locate"; }
161
 
  int64_t val_int();
162
 
  void fix_length_and_dec();
163
 
  virtual void print(String *str, enum_query_type query_type);
164
 
};
165
 
 
166
 
 
167
92
class Item_func_field :public Item_int_func
168
93
{
169
94
  String value,tmp;
176
101
  void fix_length_and_dec();
177
102
};
178
103
 
179
 
 
180
 
class Item_func_ascii :public Item_int_func
181
 
{
182
 
  String value;
183
 
public:
184
 
  Item_func_ascii(Item *a) :Item_int_func(a) {}
185
 
  int64_t val_int();
186
 
  const char *func_name() const { return "ascii"; }
187
 
  void fix_length_and_dec() { max_length=3; }
188
 
};
189
 
 
190
 
class Item_func_ord :public Item_int_func
191
 
{
192
 
  String value;
193
 
public:
194
 
  Item_func_ord(Item *a) :Item_int_func(a) {}
195
 
  int64_t val_int();
196
 
  const char *func_name() const { return "ord"; }
197
 
};
198
 
 
199
 
class Item_func_find_in_set :public Item_int_func
200
 
{
201
 
  String value,value2;
202
 
  uint32_t enum_value;
203
 
  uint64_t enum_bit;
204
 
  DTCollation cmp_collation;
205
 
public:
206
 
  Item_func_find_in_set(Item *a,Item *b) :Item_int_func(a,b),enum_value(0) {}
207
 
  int64_t val_int();
208
 
  const char *func_name() const { return "find_in_set"; }
209
 
  void fix_length_and_dec();
210
 
};
211
 
 
212
 
/* Base class for all bit functions: '~', '|', '^', '&', '>>', '<<' */
213
 
 
214
 
class Item_func_bit: public Item_int_func
215
 
{
216
 
public:
217
 
  Item_func_bit(Item *a, Item *b) :Item_int_func(a, b) {}
218
 
  Item_func_bit(Item *a) :Item_int_func(a) {}
219
 
  void fix_length_and_dec() { unsigned_flag= 1; }
220
 
 
221
 
  virtual inline void print(String *str, enum_query_type query_type)
222
 
  {
223
 
    print_op(str, query_type);
224
 
  }
225
 
};
226
 
 
227
 
class Item_func_bit_or :public Item_func_bit
228
 
{
229
 
public:
230
 
  Item_func_bit_or(Item *a, Item *b) :Item_func_bit(a, b) {}
231
 
  int64_t val_int();
232
 
  const char *func_name() const { return "|"; }
233
 
};
234
 
 
235
 
class Item_func_bit_and :public Item_func_bit
236
 
{
237
 
public:
238
 
  Item_func_bit_and(Item *a, Item *b) :Item_func_bit(a, b) {}
239
 
  int64_t val_int();
240
 
  const char *func_name() const { return "&"; }
241
 
};
242
 
 
243
 
class Item_func_bit_count :public Item_int_func
244
 
{
245
 
public:
246
 
  Item_func_bit_count(Item *a) :Item_int_func(a) {}
247
 
  int64_t val_int();
248
 
  const char *func_name() const { return "bit_count"; }
249
 
  void fix_length_and_dec() { max_length=2; }
250
 
};
251
 
 
252
 
class Item_func_shift_left :public Item_func_bit
253
 
{
254
 
public:
255
 
  Item_func_shift_left(Item *a, Item *b) :Item_func_bit(a, b) {}
256
 
  int64_t val_int();
257
 
  const char *func_name() const { return "<<"; }
258
 
};
259
 
 
260
 
class Item_func_shift_right :public Item_func_bit
261
 
{
262
 
public:
263
 
  Item_func_shift_right(Item *a, Item *b) :Item_func_bit(a, b) {}
264
 
  int64_t val_int();
265
 
  const char *func_name() const { return ">>"; }
266
 
};
267
 
 
268
 
class Item_func_bit_neg :public Item_func_bit
269
 
{
270
 
public:
271
 
  Item_func_bit_neg(Item *a) :Item_func_bit(a) {}
272
 
  int64_t val_int();
273
 
  const char *func_name() const { return "~"; }
274
 
 
275
 
  virtual inline void print(String *str, enum_query_type query_type)
276
 
  {
277
 
    Item_func::print(str, query_type);
278
 
  }
279
 
};
280
 
 
281
 
 
282
 
class Item_func_last_insert_id :public Item_int_func
283
 
{
284
 
public:
285
 
  Item_func_last_insert_id() :Item_int_func() {}
286
 
  Item_func_last_insert_id(Item *a) :Item_int_func(a) {}
287
 
  int64_t val_int();
288
 
  const char *func_name() const { return "last_insert_id"; }
289
 
  void fix_length_and_dec()
290
 
  {
291
 
    if (arg_count)
292
 
      max_length= args[0]->max_length;
293
 
  }
294
 
  bool fix_fields(Session *session, Item **ref);
295
 
  bool check_vcol_func_processor(unsigned char *int_arg __attribute__((unused)))
296
 
  { return true; }
297
 
};
298
 
 
299
 
 
300
 
class Item_func_benchmark :public Item_int_func
301
 
{
302
 
public:
303
 
  Item_func_benchmark(Item *count_expr, Item *expr)
304
 
    :Item_int_func(count_expr, expr)
305
 
  {}
306
 
  int64_t val_int();
307
 
  const char *func_name() const { return "benchmark"; }
308
 
  void fix_length_and_dec() { max_length=1; maybe_null=0; }
309
 
  virtual void print(String *str, enum_query_type query_type);
310
 
  bool check_vcol_func_processor(unsigned char *int_arg __attribute__((unused)))
311
 
  { return true; }
312
 
};
313
 
 
314
104
/* replication functions */
315
105
 
316
106
class Item_master_pos_wait :public Item_int_func
444
234
};
445
235
 
446
236
 
447
 
/* A system variable */
448
 
 
449
 
class Item_func_get_system_var :public Item_func
450
 
{
451
 
  sys_var *var;
452
 
  enum_var_type var_type;
453
 
  LEX_STRING component;
454
 
public:
455
 
  Item_func_get_system_var(sys_var *var_arg, enum_var_type var_type_arg,
456
 
                           LEX_STRING *component_arg, const char *name_arg,
457
 
                           size_t name_len_arg);
458
 
  bool fix_fields(Session *session, Item **ref);
459
 
  /*
460
 
    Stubs for pure virtual methods. Should never be called: this
461
 
    item is always substituted with a constant in fix_fields().
462
 
  */
463
 
  double val_real()         { assert(0); return 0.0; }
464
 
  int64_t val_int()        { assert(0); return 0; }
465
 
  String* val_str(String*)  { assert(0); return 0; }
466
 
  void fix_length_and_dec() { assert(0); }
467
 
  /* TODO: fix to support views */
468
 
  const char *func_name() const { return "get_system_var"; }
469
 
  /**
470
 
    Indicates whether this system variable is written to the binlog or not.
471
 
 
472
 
    Variables are written to the binlog as part of "status_vars" in
473
 
    Query_log_event, as an Intvar_log_event, or a Rand_log_event.
474
 
 
475
 
    @return true if the variable is written to the binlog, false otherwise.
476
 
  */
477
 
  bool is_written_to_binlog();
478
 
};
479
 
 
480
 
class Item_func_bit_xor : public Item_func_bit
481
 
{
482
 
public:
483
 
  Item_func_bit_xor(Item *a, Item *b) :Item_func_bit(a, b) {}
484
 
  int64_t val_int();
485
 
  const char *func_name() const { return "^"; }
486
 
};
487
 
 
488
237
class Item_func_is_free_lock :public Item_int_func
489
238
{
490
239
  String value;