23
23
/* compare and test functions */
25
#include "drizzled/comp_creator.h"
26
#include "drizzled/item/row.h"
27
#include "drizzled/item/sum.h"
28
#include "drizzled/item/int.h"
29
#include "drizzled/item/float.h"
30
#include "drizzled/item/string.h"
31
#include "drizzled/item/decimal.h"
32
#include "drizzled/function/math/int.h"
33
#include "drizzled/function/numhybrid.h"
34
#include "drizzled/session.h"
35
#include "drizzled/common.h"
36
#include "drizzled/qsort_cmp.h"
25
#include <drizzled/common.h>
26
#include <drizzled/comp_creator.h>
27
#include <drizzled/function/math/int.h>
28
#include <drizzled/function/numhybrid.h>
29
#include <drizzled/item/decimal.h>
30
#include <drizzled/item/float.h>
31
#include <drizzled/item/function/boolean.h>
32
#include <drizzled/item/int.h>
33
#include <drizzled/item/row.h>
34
#include <drizzled/item/string.h>
35
#include <drizzled/item/sum.h>
36
#include <drizzled/qsort_cmp.h>
41
41
extern Item_result item_cmp_type(Item_result a,Item_result b);
42
43
class Item_bool_func2;
43
44
class Arg_comparator;
44
45
class Item_sum_hybrid;
47
49
typedef int (Arg_comparator::*arg_cmp_func)();
49
51
typedef int (*Item_field_cmpfunc)(Item_field *f1, Item_field *f2, void *arg);
51
uint64_t get_datetime_value(Session *session,
53
int64_t get_datetime_value(Session *session,
57
59
class Arg_comparator: public memory::SqlAlloc
68
70
bool is_nulls_eq; // TRUE <=> compare for the EQUAL_FUNC
69
71
enum enum_date_cmp_type { CMP_DATE_DFLT= 0, CMP_DATE_WITH_DATE,
70
72
CMP_DATE_WITH_STR, CMP_STR_WITH_DATE };
71
uint64_t (*get_value_func)(Session *session, Item ***item_arg, Item **cache_arg,
72
Item *warn_item, bool *is_null);
73
int64_t (*get_value_func)(Session *session, Item ***item_arg, Item **cache_arg,
74
Item *warn_item, bool *is_null);
74
76
DTCollation cmp_collation;
76
Arg_comparator(): session(0), a_cache(0), b_cache(0) {};
77
Arg_comparator(Item **a1, Item **a2): a(a1), b(a2), session(0),
78
a_cache(0), b_cache(0) {};
80
Arg_comparator(Item **a1, Item **a2);
80
82
int set_compare_func(Item_bool_func2 *owner, Item_result type);
81
83
inline int set_compare_func(Item_bool_func2 *owner_arg)
117
119
int compare_datetime(); // compare args[0] & args[1] as DATETIMEs
119
121
static enum enum_date_cmp_type can_compare_as_dates(Item *a, Item *b,
120
uint64_t *const_val_arg);
122
int64_t *const_val_arg);
122
124
void set_datetime_cmp_func(Item **a1, Item **b1);
123
125
static arg_cmp_func comparator_matrix [5][2];
125
127
friend class Item_func;
128
class Item_bool_func :public Item_int_func
131
Item_bool_func() :Item_int_func() {}
132
Item_bool_func(Item *a) :Item_int_func(a) {}
133
Item_bool_func(Item *a,Item *b) :Item_int_func(a,b) {}
134
Item_bool_func(Session *session, Item_bool_func *item) :Item_int_func(session, item) {}
135
bool is_bool_func() { return 1; }
136
void fix_length_and_dec() { decimals=0; max_length=1; }
137
uint32_t decimal_precision() const { return 1; }
142
132
Abstract Item class, to represent <code>X IS [NOT] (TRUE | FALSE)</code>
143
133
boolean predicates.
146
class Item_func_truth : public Item_bool_func
136
class Item_func_truth : public item::function::Boolean
149
139
virtual bool val_bool();
155
145
Item_func_truth(Item *a, bool a_value, bool a_affirmative)
156
: Item_bool_func(a), value(a_value), affirmative(a_affirmative)
146
: item::function::Boolean(a), value(a_value), affirmative(a_affirmative)
159
149
~Item_func_truth()
256
246
bool result_for_null_param;
258
248
Item_in_optimizer(Item *a, Item_in_subselect *b):
259
Item_bool_func(a, reinterpret_cast<Item *>(b)), cache(0),
249
item::function::Boolean(a, reinterpret_cast<Item *>(b)), cache(0),
260
250
save_cache(0), result_for_null_param(UNKNOWN)
261
251
{ with_subselect= true; }
262
252
bool fix_fields(Session *, Item **);
391
class Item_func_not :public Item_bool_func
381
class Item_func_not :public item::function::Boolean
394
Item_func_not(Item *a) :Item_bool_func(a) {}
384
Item_func_not(Item *a) :item::function::Boolean(a) {}
395
385
int64_t val_int();
396
386
enum Functype functype() const { return NOT_FUNC; }
397
387
const char *func_name() const { return "not"; }
430
420
- To wrap condition that is pushed down into subquery
433
class Item_func_trig_cond: public Item_bool_func
423
class Item_func_trig_cond: public item::function::Boolean
437
Item_func_trig_cond(Item *a, bool *f) : Item_bool_func(a) { trig_var= f; }
427
Item_func_trig_cond(Item *a, bool *f) : item::function::Boolean(a) { trig_var= f; }
438
428
int64_t val_int() { return *trig_var ? args[0]->val_int() : 1; }
439
429
enum Functype functype() const { return TRIG_COND_FUNC; };
440
430
const char *func_name() const { return "trigcond"; };
682
672
double real_op();
683
673
int64_t int_op();
684
674
String *str_op(String *);
685
my_decimal *decimal_op(my_decimal *);
675
type::Decimal *decimal_op(type::Decimal *);
686
676
void fix_length_and_dec();
687
677
void find_num_type() {}
688
678
enum Item_result result_type () const { return hybrid_type; }
701
691
double real_op();
702
692
int64_t int_op();
703
693
String *str_op(String *str);
704
my_decimal *decimal_op(my_decimal *);
694
type::Decimal *decimal_op(type::Decimal *);
705
695
enum_field_types field_type() const;
706
696
void fix_length_and_dec();
707
697
const char *func_name() const { return "ifnull"; }
725
715
double val_real();
726
716
int64_t val_int();
727
717
String *val_str(String *str);
728
my_decimal *val_decimal(my_decimal *);
718
type::Decimal *val_decimal(type::Decimal *);
729
719
enum Item_result result_type () const { return cached_result_type; }
730
720
enum_field_types field_type() const { return cached_field_type; }
731
721
bool fix_fields(Session *, Item **);
745
735
double val_real();
746
736
int64_t val_int();
747
737
String *val_str(String *str);
748
my_decimal *val_decimal(my_decimal *);
738
type::Decimal *val_decimal(type::Decimal *);
749
739
enum Item_result result_type () const { return cached_result_type; }
750
740
void fix_length_and_dec();
751
741
uint32_t decimal_precision() const { return args[0]->decimal_precision(); }
890
880
/* Cache for the left item. */
891
881
Item *lval_cache;
893
in_datetime(Item *warn_item_arg, uint32_t elements)
894
:in_int64_t(elements), session(current_session), warn_item(warn_item_arg),
883
in_datetime(Item *warn_item_arg, uint32_t elements);
896
885
void set(uint32_t pos,Item *item);
897
886
unsigned char *get_value(Item *item);
898
887
friend int cmp_int64_t(void *cmp_arg, packed_int64_t *a,packed_int64_t *b);
932
921
void value_to_item(uint32_t pos, Item *item)
934
my_decimal *dec= ((my_decimal *)base) + pos;
923
type::Decimal *dec= ((type::Decimal *)base) + pos;
935
924
Item_decimal *item_dec= (Item_decimal*)item;
936
925
item_dec->set_decimal_value(dec);
950
939
const CHARSET_INFO *cmp_charset;
951
cmp_item() { cmp_charset= &my_charset_bin; }
943
cmp_charset= &my_charset_bin;
952
946
virtual ~cmp_item() {}
953
947
virtual void store_value(Item *item)= 0;
954
948
virtual int cmp(Item *item)= 0;
1047
1042
/* Cache for the left item. */
1048
1043
Item *lval_cache;
1050
cmp_item_datetime(Item *warn_item_arg)
1051
:session(current_session), warn_item(warn_item_arg), lval_cache(0) {}
1045
cmp_item_datetime(Item *warn_item_arg);
1052
1047
void store_value(Item *item);
1053
1048
int cmp(Item *arg);
1054
1049
int compare(cmp_item *ci);
1174
1169
double val_real();
1175
1170
int64_t val_int();
1176
1171
String *val_str(String *);
1177
my_decimal *val_decimal(my_decimal *);
1172
type::Decimal *val_decimal(type::Decimal *);
1178
1173
bool fix_fields(Session *session, Item **ref);
1179
1174
void fix_length_and_dec();
1180
1175
uint32_t decimal_precision() const;
1287
1282
/* Functions used by where clause */
1289
class Item_func_isnull :public Item_bool_func
1284
class Item_func_isnull :public item::function::Boolean
1292
1287
int64_t cached_value;
1294
Item_func_isnull(Item *a) :Item_bool_func(a) {}
1289
Item_func_isnull(Item *a) :item::function::Boolean(a) {}
1295
1290
int64_t val_int();
1296
1291
enum Functype functype() const { return ISNULL_FUNC; }
1297
1292
void fix_length_and_dec()
1356
class Item_func_isnotnull :public Item_bool_func
1351
class Item_func_isnotnull :public item::function::Boolean
1358
1353
bool abort_on_null;
1360
Item_func_isnotnull(Item *a) :Item_bool_func(a), abort_on_null(0) {}
1355
Item_func_isnotnull(Item *a) :item::function::Boolean(a), abort_on_null(0) {}
1361
1356
int64_t val_int();
1362
1357
enum Functype functype() const { return ISNOTNULL_FUNC; }
1363
1358
void fix_length_and_dec()
1429
1424
using Item::split_sum_func;
1431
1426
/* Item_cond() is only used to create top level items */
1432
Item_cond(): Item_bool_func(), abort_on_null(1)
1427
Item_cond(): item::function::Boolean(), abort_on_null(1)
1433
1428
{ const_item_cache=0; }
1434
1429
Item_cond(Item *i1,Item *i2)
1435
:Item_bool_func(), abort_on_null(0)
1430
:item::function::Boolean(), abort_on_null(0)
1437
1432
list.push_back(i1);
1438
1433
list.push_back(i2);
1440
1435
Item_cond(Session *session, Item_cond *item);
1441
1436
Item_cond(List<Item> &nlist)
1442
:Item_bool_func(), list(nlist), abort_on_null(0) {}
1437
:item::function::Boolean(), list(nlist), abort_on_null(0) {}
1443
1438
bool add(Item *item) { return list.push_back(item); }
1444
1439
bool add_at_head(Item *item) { return list.push_front(item); }
1445
1440
void add_at_head(List<Item> *nlist) { list.prepand(nlist); }
1543
1538
object represents f1=f2= ...=fn to the projection of known fields fi1=...=fik.
1546
class Item_equal: public Item_bool_func
1541
class Item_equal: public item::function::Boolean
1548
1543
List<Item_field> fields; /* list of equal field items */
1549
1544
Item *const_item; /* optional constant item equal to fields items */
1550
1545
cmp_item *eval_item;
1551
1546
bool cond_false;
1554
: Item_bool_func(), const_item(0), eval_item(0), cond_false(0)
1555
{ const_item_cache=0 ;}
1549
inline Item_equal() :
1550
item::function::Boolean(),
1556
1558
Item_equal(Item_field *f1, Item_field *f2);
1557
1559
Item_equal(Item *c, Item_field *f);
1558
1560
Item_equal(Item_equal *item_equal);