1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems, Inc.
4
* Copyright (C) 2008 Sun Microsystems
6
6
* This program is free software; you can redistribute it and/or modify
7
7
* it under the terms of the GNU General Public License as published by
27
27
#include "drizzled/item/sum.h"
28
28
#include "drizzled/item/int.h"
29
29
#include "drizzled/item/float.h"
30
#include "drizzled/item/string.h"
31
30
#include "drizzled/item/decimal.h"
32
31
#include "drizzled/function/math/int.h"
33
32
#include "drizzled/function/numhybrid.h"
33
#include "drizzled/session.h"
34
34
#include "drizzled/common.h"
35
35
#include "drizzled/qsort_cmp.h"
36
#include "drizzled/item/function/boolean.h"
41
40
extern Item_result item_cmp_type(Item_result a,Item_result b);
43
41
class Item_bool_func2;
44
42
class Arg_comparator;
45
43
class Item_sum_hybrid;
49
46
typedef int (Arg_comparator::*arg_cmp_func)();
51
48
typedef int (*Item_field_cmpfunc)(Item_field *f1, Item_field *f2, void *arg);
53
int64_t get_datetime_value(Session *session,
50
uint64_t get_datetime_value(Session *session,
59
56
class Arg_comparator: public memory::SqlAlloc
70
67
bool is_nulls_eq; // TRUE <=> compare for the EQUAL_FUNC
71
68
enum enum_date_cmp_type { CMP_DATE_DFLT= 0, CMP_DATE_WITH_DATE,
72
69
CMP_DATE_WITH_STR, CMP_STR_WITH_DATE };
73
int64_t (*get_value_func)(Session *session, Item ***item_arg, Item **cache_arg,
74
Item *warn_item, bool *is_null);
70
uint64_t (*get_value_func)(Session *session, Item ***item_arg, Item **cache_arg,
71
Item *warn_item, bool *is_null);
76
73
DTCollation cmp_collation;
79
session(current_session),
84
Arg_comparator(Item **a1, Item **a2):
87
session(current_session),
75
Arg_comparator(): session(0), a_cache(0), b_cache(0) {};
76
Arg_comparator(Item **a1, Item **a2): a(a1), b(a2), session(0),
77
a_cache(0), b_cache(0) {};
92
79
int set_compare_func(Item_bool_func2 *owner, Item_result type);
93
80
inline int set_compare_func(Item_bool_func2 *owner_arg)
129
116
int compare_datetime(); // compare args[0] & args[1] as DATETIMEs
131
118
static enum enum_date_cmp_type can_compare_as_dates(Item *a, Item *b,
132
int64_t *const_val_arg);
119
uint64_t *const_val_arg);
134
121
void set_datetime_cmp_func(Item **a1, Item **b1);
135
122
static arg_cmp_func comparator_matrix [5][2];
137
124
friend class Item_func;
127
class Item_bool_func :public Item_int_func
130
Item_bool_func() :Item_int_func() {}
131
Item_bool_func(Item *a) :Item_int_func(a) {}
132
Item_bool_func(Item *a,Item *b) :Item_int_func(a,b) {}
133
Item_bool_func(Session *session, Item_bool_func *item) :Item_int_func(session, item) {}
134
bool is_bool_func() { return 1; }
135
void fix_length_and_dec() { decimals=0; max_length=1; }
136
uint32_t decimal_precision() const { return 1; }
142
141
Abstract Item class, to represent <code>X IS [NOT] (TRUE | FALSE)</code>
143
142
boolean predicates.
146
class Item_func_truth : public item::function::Boolean
145
class Item_func_truth : public Item_bool_func
149
148
virtual bool val_bool();
155
154
Item_func_truth(Item *a, bool a_value, bool a_affirmative)
156
: item::function::Boolean(a), value(a_value), affirmative(a_affirmative)
155
: Item_bool_func(a), value(a_value), affirmative(a_affirmative)
159
158
~Item_func_truth()
256
255
bool result_for_null_param;
258
257
Item_in_optimizer(Item *a, Item_in_subselect *b):
259
item::function::Boolean(a, reinterpret_cast<Item *>(b)), cache(0),
258
Item_bool_func(a, reinterpret_cast<Item *>(b)), cache(0),
260
259
save_cache(0), result_for_null_param(UNKNOWN)
261
260
{ with_subselect= true; }
262
261
bool fix_fields(Session *, Item **);
391
class Item_func_not :public item::function::Boolean
390
class Item_func_not :public Item_bool_func
394
Item_func_not(Item *a) :item::function::Boolean(a) {}
393
Item_func_not(Item *a) :Item_bool_func(a) {}
395
394
int64_t val_int();
396
395
enum Functype functype() const { return NOT_FUNC; }
397
396
const char *func_name() const { return "not"; }
430
429
- To wrap condition that is pushed down into subquery
433
class Item_func_trig_cond: public item::function::Boolean
432
class Item_func_trig_cond: public Item_bool_func
437
Item_func_trig_cond(Item *a, bool *f) : item::function::Boolean(a) { trig_var= f; }
436
Item_func_trig_cond(Item *a, bool *f) : Item_bool_func(a) { trig_var= f; }
438
437
int64_t val_int() { return *trig_var ? args[0]->val_int() : 1; }
439
438
enum Functype functype() const { return TRIG_COND_FUNC; };
440
439
const char *func_name() const { return "trigcond"; };
682
681
double real_op();
683
682
int64_t int_op();
684
683
String *str_op(String *);
685
type::Decimal *decimal_op(type::Decimal *);
684
my_decimal *decimal_op(my_decimal *);
686
685
void fix_length_and_dec();
687
686
void find_num_type() {}
688
687
enum Item_result result_type () const { return hybrid_type; }
701
700
double real_op();
702
701
int64_t int_op();
703
702
String *str_op(String *str);
704
type::Decimal *decimal_op(type::Decimal *);
703
my_decimal *decimal_op(my_decimal *);
705
704
enum_field_types field_type() const;
706
705
void fix_length_and_dec();
707
706
const char *func_name() const { return "ifnull"; }
725
724
double val_real();
726
725
int64_t val_int();
727
726
String *val_str(String *str);
728
type::Decimal *val_decimal(type::Decimal *);
727
my_decimal *val_decimal(my_decimal *);
729
728
enum Item_result result_type () const { return cached_result_type; }
730
729
enum_field_types field_type() const { return cached_field_type; }
731
730
bool fix_fields(Session *, Item **);
745
744
double val_real();
746
745
int64_t val_int();
747
746
String *val_str(String *str);
748
type::Decimal *val_decimal(type::Decimal *);
747
my_decimal *val_decimal(my_decimal *);
749
748
enum Item_result result_type () const { return cached_result_type; }
750
749
void fix_length_and_dec();
751
750
uint32_t decimal_precision() const { return args[0]->decimal_precision(); }
932
931
void value_to_item(uint32_t pos, Item *item)
934
type::Decimal *dec= ((type::Decimal *)base) + pos;
933
my_decimal *dec= ((my_decimal *)base) + pos;
935
934
Item_decimal *item_dec= (Item_decimal*)item;
936
935
item_dec->set_decimal_value(dec);
950
949
const CHARSET_INFO *cmp_charset;
954
cmp_charset= &my_charset_bin;
950
cmp_item() { cmp_charset= &my_charset_bin; }
957
951
virtual ~cmp_item() {}
958
952
virtual void store_value(Item *item)= 0;
959
953
virtual int cmp(Item *item)= 0;
1156
1149
Item_result cmp_type;
1157
1150
DTCollation cmp_collation;
1158
1151
enum_field_types cached_field_type;
1159
cmp_item *cmp_items[DECIMAL_RESULT+1]; /* For all result types */
1152
cmp_item *cmp_items[5]; /* For all result types */
1160
1153
cmp_item *case_item;
1162
1155
Item_func_case(List<Item> &list, Item *first_expr_arg, Item *else_expr_arg)
1180
1173
double val_real();
1181
1174
int64_t val_int();
1182
1175
String *val_str(String *);
1183
type::Decimal *val_decimal(type::Decimal *);
1176
my_decimal *val_decimal(my_decimal *);
1184
1177
bool fix_fields(Session *session, Item **ref);
1185
1178
void fix_length_and_dec();
1186
1179
uint32_t decimal_precision() const;
1293
1287
/* Functions used by where clause */
1295
class Item_func_isnull :public item::function::Boolean
1289
class Item_func_isnull :public Item_bool_func
1298
1292
int64_t cached_value;
1300
Item_func_isnull(Item *a) :item::function::Boolean(a) {}
1294
Item_func_isnull(Item *a) :Item_bool_func(a) {}
1301
1295
int64_t val_int();
1302
1296
enum Functype functype() const { return ISNULL_FUNC; }
1303
1297
void fix_length_and_dec()
1362
class Item_func_isnotnull :public item::function::Boolean
1356
class Item_func_isnotnull :public Item_bool_func
1364
1358
bool abort_on_null;
1366
Item_func_isnotnull(Item *a) :item::function::Boolean(a), abort_on_null(0) {}
1360
Item_func_isnotnull(Item *a) :Item_bool_func(a), abort_on_null(0) {}
1367
1361
int64_t val_int();
1368
1362
enum Functype functype() const { return ISNOTNULL_FUNC; }
1369
1363
void fix_length_and_dec()
1435
1429
using Item::split_sum_func;
1437
1431
/* Item_cond() is only used to create top level items */
1438
Item_cond(): item::function::Boolean(), abort_on_null(1)
1432
Item_cond(): Item_bool_func(), abort_on_null(1)
1439
1433
{ const_item_cache=0; }
1440
1434
Item_cond(Item *i1,Item *i2)
1441
:item::function::Boolean(), abort_on_null(0)
1435
:Item_bool_func(), abort_on_null(0)
1443
1437
list.push_back(i1);
1444
1438
list.push_back(i2);
1446
1440
Item_cond(Session *session, Item_cond *item);
1447
1441
Item_cond(List<Item> &nlist)
1448
:item::function::Boolean(), list(nlist), abort_on_null(0) {}
1442
:Item_bool_func(), list(nlist), abort_on_null(0) {}
1449
1443
bool add(Item *item) { return list.push_back(item); }
1450
1444
bool add_at_head(Item *item) { return list.push_front(item); }
1451
1445
void add_at_head(List<Item> *nlist) { list.prepand(nlist); }
1549
1543
object represents f1=f2= ...=fn to the projection of known fields fi1=...=fik.
1552
class Item_equal: public item::function::Boolean
1546
class Item_equal: public Item_bool_func
1554
1548
List<Item_field> fields; /* list of equal field items */
1555
1549
Item *const_item; /* optional constant item equal to fields items */
1556
1550
cmp_item *eval_item;
1557
1551
bool cond_false;
1560
inline Item_equal() :
1561
item::function::Boolean(),
1554
: Item_bool_func(), const_item(0), eval_item(0), cond_false(0)
1555
{ const_item_cache=0 ;}
1569
1556
Item_equal(Item_field *f1, Item_field *f2);
1570
1557
Item_equal(Item *c, Item_field *f);
1571
1558
Item_equal(Item_equal *item_equal);