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
31
31
#include "drizzled/item/decimal.h"
32
32
#include "drizzled/function/math/int.h"
33
33
#include "drizzled/function/numhybrid.h"
34
#include "drizzled/session.h"
34
35
#include "drizzled/common.h"
35
36
#include "drizzled/qsort_cmp.h"
36
#include "drizzled/item/function/boolean.h"
41
41
extern Item_result item_cmp_type(Item_result a,Item_result b);
43
42
class Item_bool_func2;
44
43
class Arg_comparator;
45
44
class Item_sum_hybrid;
49
47
typedef int (Arg_comparator::*arg_cmp_func)();
51
49
typedef int (*Item_field_cmpfunc)(Item_field *f1, Item_field *f2, void *arg);
53
int64_t get_datetime_value(Session *session,
51
uint64_t get_datetime_value(Session *session,
59
57
class Arg_comparator: public memory::SqlAlloc
70
68
bool is_nulls_eq; // TRUE <=> compare for the EQUAL_FUNC
71
69
enum enum_date_cmp_type { CMP_DATE_DFLT= 0, CMP_DATE_WITH_DATE,
72
70
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);
71
uint64_t (*get_value_func)(Session *session, Item ***item_arg, Item **cache_arg,
72
Item *warn_item, bool *is_null);
76
74
DTCollation cmp_collation;
79
session(current_session),
84
Arg_comparator(Item **a1, Item **a2):
87
session(current_session),
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) {};
92
80
int set_compare_func(Item_bool_func2 *owner, Item_result type);
93
81
inline int set_compare_func(Item_bool_func2 *owner_arg)
129
117
int compare_datetime(); // compare args[0] & args[1] as DATETIMEs
131
119
static enum enum_date_cmp_type can_compare_as_dates(Item *a, Item *b,
132
int64_t *const_val_arg);
120
uint64_t *const_val_arg);
134
122
void set_datetime_cmp_func(Item **a1, Item **b1);
135
123
static arg_cmp_func comparator_matrix [5][2];
137
125
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
142
Abstract Item class, to represent <code>X IS [NOT] (TRUE | FALSE)</code>
143
143
boolean predicates.
146
class Item_func_truth : public item::function::Boolean
146
class Item_func_truth : public Item_bool_func
149
149
virtual bool val_bool();
155
155
Item_func_truth(Item *a, bool a_value, bool a_affirmative)
156
: item::function::Boolean(a), value(a_value), affirmative(a_affirmative)
156
: Item_bool_func(a), value(a_value), affirmative(a_affirmative)
159
159
~Item_func_truth()
256
256
bool result_for_null_param;
258
258
Item_in_optimizer(Item *a, Item_in_subselect *b):
259
item::function::Boolean(a, reinterpret_cast<Item *>(b)), cache(0),
259
Item_bool_func(a, reinterpret_cast<Item *>(b)), cache(0),
260
260
save_cache(0), result_for_null_param(UNKNOWN)
261
261
{ with_subselect= true; }
262
262
bool fix_fields(Session *, Item **);
391
class Item_func_not :public item::function::Boolean
391
class Item_func_not :public Item_bool_func
394
Item_func_not(Item *a) :item::function::Boolean(a) {}
394
Item_func_not(Item *a) :Item_bool_func(a) {}
395
395
int64_t val_int();
396
396
enum Functype functype() const { return NOT_FUNC; }
397
397
const char *func_name() const { return "not"; }
430
430
- To wrap condition that is pushed down into subquery
433
class Item_func_trig_cond: public item::function::Boolean
433
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; }
437
Item_func_trig_cond(Item *a, bool *f) : Item_bool_func(a) { trig_var= f; }
438
438
int64_t val_int() { return *trig_var ? args[0]->val_int() : 1; }
439
439
enum Functype functype() const { return TRIG_COND_FUNC; };
440
440
const char *func_name() const { return "trigcond"; };
682
682
double real_op();
683
683
int64_t int_op();
684
684
String *str_op(String *);
685
type::Decimal *decimal_op(type::Decimal *);
685
my_decimal *decimal_op(my_decimal *);
686
686
void fix_length_and_dec();
687
687
void find_num_type() {}
688
688
enum Item_result result_type () const { return hybrid_type; }
701
701
double real_op();
702
702
int64_t int_op();
703
703
String *str_op(String *str);
704
type::Decimal *decimal_op(type::Decimal *);
704
my_decimal *decimal_op(my_decimal *);
705
705
enum_field_types field_type() const;
706
706
void fix_length_and_dec();
707
707
const char *func_name() const { return "ifnull"; }
725
725
double val_real();
726
726
int64_t val_int();
727
727
String *val_str(String *str);
728
type::Decimal *val_decimal(type::Decimal *);
728
my_decimal *val_decimal(my_decimal *);
729
729
enum Item_result result_type () const { return cached_result_type; }
730
730
enum_field_types field_type() const { return cached_field_type; }
731
731
bool fix_fields(Session *, Item **);
745
745
double val_real();
746
746
int64_t val_int();
747
747
String *val_str(String *str);
748
type::Decimal *val_decimal(type::Decimal *);
748
my_decimal *val_decimal(my_decimal *);
749
749
enum Item_result result_type () const { return cached_result_type; }
750
750
void fix_length_and_dec();
751
751
uint32_t decimal_precision() const { return args[0]->decimal_precision(); }
932
932
void value_to_item(uint32_t pos, Item *item)
934
type::Decimal *dec= ((type::Decimal *)base) + pos;
934
my_decimal *dec= ((my_decimal *)base) + pos;
935
935
Item_decimal *item_dec= (Item_decimal*)item;
936
936
item_dec->set_decimal_value(dec);
950
950
const CHARSET_INFO *cmp_charset;
954
cmp_charset= &my_charset_bin;
951
cmp_item() { cmp_charset= &my_charset_bin; }
957
952
virtual ~cmp_item() {}
958
953
virtual void store_value(Item *item)= 0;
959
954
virtual int cmp(Item *item)= 0;
1156
1150
Item_result cmp_type;
1157
1151
DTCollation cmp_collation;
1158
1152
enum_field_types cached_field_type;
1159
cmp_item *cmp_items[DECIMAL_RESULT+1]; /* For all result types */
1153
cmp_item *cmp_items[5]; /* For all result types */
1160
1154
cmp_item *case_item;
1162
1156
Item_func_case(List<Item> &list, Item *first_expr_arg, Item *else_expr_arg)
1180
1174
double val_real();
1181
1175
int64_t val_int();
1182
1176
String *val_str(String *);
1183
type::Decimal *val_decimal(type::Decimal *);
1177
my_decimal *val_decimal(my_decimal *);
1184
1178
bool fix_fields(Session *session, Item **ref);
1185
1179
void fix_length_and_dec();
1186
1180
uint32_t decimal_precision() const;
1293
1288
/* Functions used by where clause */
1295
class Item_func_isnull :public item::function::Boolean
1290
class Item_func_isnull :public Item_bool_func
1298
1293
int64_t cached_value;
1300
Item_func_isnull(Item *a) :item::function::Boolean(a) {}
1295
Item_func_isnull(Item *a) :Item_bool_func(a) {}
1301
1296
int64_t val_int();
1302
1297
enum Functype functype() const { return ISNULL_FUNC; }
1303
1298
void fix_length_and_dec()
1362
class Item_func_isnotnull :public item::function::Boolean
1357
class Item_func_isnotnull :public Item_bool_func
1364
1359
bool abort_on_null;
1366
Item_func_isnotnull(Item *a) :item::function::Boolean(a), abort_on_null(0) {}
1361
Item_func_isnotnull(Item *a) :Item_bool_func(a), abort_on_null(0) {}
1367
1362
int64_t val_int();
1368
1363
enum Functype functype() const { return ISNOTNULL_FUNC; }
1369
1364
void fix_length_and_dec()
1435
1430
using Item::split_sum_func;
1437
1432
/* Item_cond() is only used to create top level items */
1438
Item_cond(): item::function::Boolean(), abort_on_null(1)
1433
Item_cond(): Item_bool_func(), abort_on_null(1)
1439
1434
{ const_item_cache=0; }
1440
1435
Item_cond(Item *i1,Item *i2)
1441
:item::function::Boolean(), abort_on_null(0)
1436
:Item_bool_func(), abort_on_null(0)
1443
1438
list.push_back(i1);
1444
1439
list.push_back(i2);
1446
1441
Item_cond(Session *session, Item_cond *item);
1447
1442
Item_cond(List<Item> &nlist)
1448
:item::function::Boolean(), list(nlist), abort_on_null(0) {}
1443
:Item_bool_func(), list(nlist), abort_on_null(0) {}
1449
1444
bool add(Item *item) { return list.push_back(item); }
1450
1445
bool add_at_head(Item *item) { return list.push_front(item); }
1451
1446
void add_at_head(List<Item> *nlist) { list.prepand(nlist); }
1549
1544
object represents f1=f2= ...=fn to the projection of known fields fi1=...=fik.
1552
class Item_equal: public item::function::Boolean
1547
class Item_equal: public Item_bool_func
1554
1549
List<Item_field> fields; /* list of equal field items */
1555
1550
Item *const_item; /* optional constant item equal to fields items */
1556
1551
cmp_item *eval_item;
1557
1552
bool cond_false;
1560
inline Item_equal() :
1561
item::function::Boolean(),
1555
: Item_bool_func(), const_item(0), eval_item(0), cond_false(0)
1556
{ const_item_cache=0 ;}
1569
1557
Item_equal(Item_field *f1, Item_field *f2);
1570
1558
Item_equal(Item *c, Item_field *f);
1571
1559
Item_equal(Item_equal *item_equal);