~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/cmpfunc.h

  • Committer: Patrick Crews
  • Date: 2010-12-07 20:02:50 UTC
  • Revision ID: gleebix@gmail.com-20101207200250-6a27jgqalgw5bsb5
Added disabled.def file to disable drizzleslap due to Bug#684269.  Need to skip for tarball release this round

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
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"
37
37
 
38
38
namespace drizzled
39
39
{
40
40
 
41
41
extern Item_result item_cmp_type(Item_result a,Item_result b);
42
 
 
43
42
class Item_bool_func2;
44
43
class Arg_comparator;
45
44
class Item_sum_hybrid;
46
45
class Item_row;
47
 
class Session;
48
46
 
49
47
typedef int (Arg_comparator::*arg_cmp_func)();
50
48
 
51
49
typedef int (*Item_field_cmpfunc)(Item_field *f1, Item_field *f2, void *arg);
52
50
 
53
 
int64_t get_datetime_value(Session *session, 
54
 
                           Item ***item_arg, 
55
 
                           Item **cache_arg,
56
 
                           Item *warn_item, 
57
 
                           bool *is_null);
 
51
uint64_t get_datetime_value(Session *session, 
 
52
                            Item ***item_arg, 
 
53
                            Item **cache_arg,
 
54
                            Item *warn_item, 
 
55
                            bool *is_null);
58
56
 
59
57
class Arg_comparator: public memory::SqlAlloc
60
58
{
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);
75
73
public:
76
74
  DTCollation cmp_collation;
77
75
 
78
 
  Arg_comparator():
79
 
    session(current_session),
80
 
    a_cache(0),
81
 
    b_cache(0)
82
 
  {};
83
 
 
84
 
  Arg_comparator(Item **a1, Item **a2):
85
 
    a(a1),
86
 
    b(a2),
87
 
    session(current_session),
88
 
    a_cache(0),
89
 
    b_cache(0)
90
 
  {};
 
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) {};
91
79
 
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
130
118
 
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);
133
121
 
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;
138
126
};
139
127
 
 
128
class Item_bool_func :public Item_int_func
 
129
{
 
130
public:
 
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; }
 
138
};
 
139
 
140
140
 
141
141
/**
142
142
  Abstract Item class, to represent <code>X IS [NOT] (TRUE | FALSE)</code>
143
143
  boolean predicates.
144
144
*/
145
145
 
146
 
class Item_func_truth : public item::function::Boolean
 
146
class Item_func_truth : public Item_bool_func
147
147
{
148
148
public:
149
149
  virtual bool val_bool();
153
153
 
154
154
protected:
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)
157
157
  {}
158
158
 
159
159
  ~Item_func_truth()
242
242
    placed into a separate class called 'Item_in_optimizer'.
243
243
*/
244
244
 
245
 
class Item_in_optimizer: public item::function::Boolean
 
245
class Item_in_optimizer: public Item_bool_func
246
246
{
247
247
protected:
248
248
  Item_cache *cache;
256
256
  bool result_for_null_param;
257
257
public:
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 **);
388
388
  { return true; }
389
389
};
390
390
 
391
 
class Item_func_not :public item::function::Boolean
 
391
class Item_func_not :public Item_bool_func
392
392
{
393
393
public:
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
431
431
*/
432
432
 
433
 
class Item_func_trig_cond: public item::function::Boolean
 
433
class Item_func_trig_cond: public Item_bool_func
434
434
{
435
435
  bool *trig_var;
436
436
public:
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"; };
651
651
{
652
652
  Item_result type;
653
653
  double dbl;
654
 
  type::Decimal dec;
 
654
  my_decimal dec;
655
655
};
656
656
 
657
657
class Item_func_interval :public Item_int_func
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(); }
920
920
 
921
921
class in_decimal :public in_vector
922
922
{
923
 
  type::Decimal val;
 
923
  my_decimal val;
924
924
public:
925
925
  in_decimal(uint32_t elements);
926
926
  void set(uint32_t pos, Item *item);
931
931
  }
932
932
  void value_to_item(uint32_t pos, Item *item)
933
933
  {
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);
937
937
  }
948
948
{
949
949
public:
950
950
  const CHARSET_INFO *cmp_charset;
951
 
 
952
 
  cmp_item()
953
 
  {
954
 
    cmp_charset= &my_charset_bin;
955
 
  }
956
 
 
 
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;
1044
1039
*/
1045
1040
class cmp_item_datetime :public cmp_item
1046
1041
{
1047
 
  int64_t value;
1048
 
 
 
1042
  uint64_t value;
1049
1043
public:
1050
1044
  Session *session;
1051
1045
  /* Item used for issuing warnings. */
1085
1079
 
1086
1080
class cmp_item_decimal :public cmp_item
1087
1081
{
1088
 
  type::Decimal value;
 
1082
  my_decimal value;
1089
1083
public:
1090
1084
  cmp_item_decimal() {}                       /* Remove gcc warning */
1091
1085
  void store_value(Item *item);
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;
1161
1155
public:
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;
1241
1235
  uint32_t decimal_precision() const { return 1; }
1242
1236
  void cleanup()
1243
1237
  {
 
1238
    uint32_t i;
1244
1239
    Item_int_func::cleanup();
1245
1240
    delete array;
1246
1241
    array= 0;
1247
 
    for (int i= STRING_RESULT; i <= DECIMAL_RESULT; i++)
 
1242
    for (i= 0; i <= (uint32_t)DECIMAL_RESULT + 1; i++)
1248
1243
    {
1249
1244
      delete cmp_items[i];
1250
1245
      cmp_items[i]= 0;
1292
1287
 
1293
1288
/* Functions used by where clause */
1294
1289
 
1295
 
class Item_func_isnull :public item::function::Boolean
 
1290
class Item_func_isnull :public Item_bool_func
1296
1291
{
1297
1292
protected:
1298
1293
  int64_t cached_value;
1299
1294
public:
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()
1359
1354
};
1360
1355
 
1361
1356
 
1362
 
class Item_func_isnotnull :public item::function::Boolean
 
1357
class Item_func_isnotnull :public Item_bool_func
1363
1358
{
1364
1359
  bool abort_on_null;
1365
1360
public:
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()
1423
1418
 
1424
1419
typedef class Item COND;
1425
1420
 
1426
 
class Item_cond :public item::function::Boolean
 
1421
class Item_cond :public Item_bool_func
1427
1422
{
1428
1423
protected:
1429
1424
  List<Item> list;
1435
1430
  using Item::split_sum_func;
1436
1431
 
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)
1442
1437
  {
1443
1438
    list.push_back(i1);
1444
1439
    list.push_back(i2);
1445
1440
  }
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.
1550
1545
*/
1551
1546
 
1552
 
class Item_equal: public item::function::Boolean
 
1547
class Item_equal: public Item_bool_func
1553
1548
{
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;
1558
 
 
1559
1553
public:
1560
 
  inline Item_equal() :
1561
 
    item::function::Boolean(),
1562
 
    const_item(0),
1563
 
    eval_item(0),
1564
 
    cond_false(0)
1565
 
  {
1566
 
    const_item_cache=0;
1567
 
  }
1568
 
 
 
1554
  inline Item_equal()
 
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);