~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/cmpfunc.h

  • Committer: Monty Taylor
  • Date: 2011-02-14 20:25:28 UTC
  • mto: (2168.1.3 build)
  • mto: This revision was merged to the branch mainline in revision 2169.
  • Revision ID: mordred@inaugust.com-20110214202528-wfb2a5h51ntbl5ct
Fix daemonize c++ patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
/* compare and test functions */
24
24
 
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>
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
 
42
43
class Item_bool_func2;
43
44
class Arg_comparator;
44
45
class Item_sum_hybrid;
45
46
class Item_row;
 
47
class Session;
46
48
 
47
49
typedef int (Arg_comparator::*arg_cmp_func)();
48
50
 
49
51
typedef int (*Item_field_cmpfunc)(Item_field *f1, Item_field *f2, void *arg);
50
52
 
51
 
uint64_t get_datetime_value(Session *session, 
52
 
                            Item ***item_arg, 
53
 
                            Item **cache_arg,
54
 
                            Item *warn_item, 
55
 
                            bool *is_null);
 
53
int64_t get_datetime_value(Session *session, 
 
54
                           Item ***item_arg, 
 
55
                           Item **cache_arg,
 
56
                           Item *warn_item, 
 
57
                           bool *is_null);
56
58
 
57
59
class Arg_comparator: public memory::SqlAlloc
58
60
{
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);
73
75
public:
74
76
  DTCollation cmp_collation;
75
77
 
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) {};
 
78
  Arg_comparator();
 
79
 
 
80
  Arg_comparator(Item **a1, Item **a2);
79
81
 
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
118
120
 
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);
121
123
 
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;
126
128
};
127
129
 
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
130
 
141
131
/**
142
132
  Abstract Item class, to represent <code>X IS [NOT] (TRUE | FALSE)</code>
143
133
  boolean predicates.
144
134
*/
145
135
 
146
 
class Item_func_truth : public Item_bool_func
 
136
class Item_func_truth : public item::function::Boolean
147
137
{
148
138
public:
149
139
  virtual bool val_bool();
153
143
 
154
144
protected:
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)
157
147
  {}
158
148
 
159
149
  ~Item_func_truth()
242
232
    placed into a separate class called 'Item_in_optimizer'.
243
233
*/
244
234
 
245
 
class Item_in_optimizer: public Item_bool_func
 
235
class Item_in_optimizer: public item::function::Boolean
246
236
{
247
237
protected:
248
238
  Item_cache *cache;
256
246
  bool result_for_null_param;
257
247
public:
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 **);
388
378
  { return true; }
389
379
};
390
380
 
391
 
class Item_func_not :public Item_bool_func
 
381
class Item_func_not :public item::function::Boolean
392
382
{
393
383
public:
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
431
421
*/
432
422
 
433
 
class Item_func_trig_cond: public Item_bool_func
 
423
class Item_func_trig_cond: public item::function::Boolean
434
424
{
435
425
  bool *trig_var;
436
426
public:
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"; };
651
641
{
652
642
  Item_result type;
653
643
  double dbl;
654
 
  my_decimal dec;
 
644
  type::Decimal dec;
655
645
};
656
646
 
657
647
class Item_func_interval :public Item_int_func
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;
892
882
 
893
 
  in_datetime(Item *warn_item_arg, uint32_t elements)
894
 
    :in_int64_t(elements), session(current_session), warn_item(warn_item_arg),
895
 
     lval_cache(0) {};
 
883
  in_datetime(Item *warn_item_arg, uint32_t elements);
 
884
 
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);
920
909
 
921
910
class in_decimal :public in_vector
922
911
{
923
 
  my_decimal val;
 
912
  type::Decimal val;
924
913
public:
925
914
  in_decimal(uint32_t elements);
926
915
  void set(uint32_t pos, Item *item);
931
920
  }
932
921
  void value_to_item(uint32_t pos, Item *item)
933
922
  {
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);
937
926
  }
948
937
{
949
938
public:
950
939
  const CHARSET_INFO *cmp_charset;
951
 
  cmp_item() { cmp_charset= &my_charset_bin; }
 
940
 
 
941
  cmp_item()
 
942
  {
 
943
    cmp_charset= &my_charset_bin;
 
944
  }
 
945
 
952
946
  virtual ~cmp_item() {}
953
947
  virtual void store_value(Item *item)= 0;
954
948
  virtual int cmp(Item *item)= 0;
1039
1033
*/
1040
1034
class cmp_item_datetime :public cmp_item
1041
1035
{
1042
 
  uint64_t value;
 
1036
  int64_t value;
 
1037
 
1043
1038
public:
1044
1039
  Session *session;
1045
1040
  /* Item used for issuing warnings. */
1047
1042
  /* Cache for the left item. */
1048
1043
  Item *lval_cache;
1049
1044
 
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);
 
1046
 
1052
1047
  void store_value(Item *item);
1053
1048
  int cmp(Item *arg);
1054
1049
  int compare(cmp_item *ci);
1079
1074
 
1080
1075
class cmp_item_decimal :public cmp_item
1081
1076
{
1082
 
  my_decimal value;
 
1077
  type::Decimal value;
1083
1078
public:
1084
1079
  cmp_item_decimal() {}                       /* Remove gcc warning */
1085
1080
  void store_value(Item *item);
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;
1286
1281
 
1287
1282
/* Functions used by where clause */
1288
1283
 
1289
 
class Item_func_isnull :public Item_bool_func
 
1284
class Item_func_isnull :public item::function::Boolean
1290
1285
{
1291
1286
protected:
1292
1287
  int64_t cached_value;
1293
1288
public:
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()
1353
1348
};
1354
1349
 
1355
1350
 
1356
 
class Item_func_isnotnull :public Item_bool_func
 
1351
class Item_func_isnotnull :public item::function::Boolean
1357
1352
{
1358
1353
  bool abort_on_null;
1359
1354
public:
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()
1417
1412
 
1418
1413
typedef class Item COND;
1419
1414
 
1420
 
class Item_cond :public Item_bool_func
 
1415
class Item_cond :public item::function::Boolean
1421
1416
{
1422
1417
protected:
1423
1418
  List<Item> list;
1429
1424
  using Item::split_sum_func;
1430
1425
 
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)
1436
1431
  {
1437
1432
    list.push_back(i1);
1438
1433
    list.push_back(i2);
1439
1434
  }
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.
1544
1539
*/
1545
1540
 
1546
 
class Item_equal: public Item_bool_func
 
1541
class Item_equal: public item::function::Boolean
1547
1542
{
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;
 
1547
 
1552
1548
public:
1553
 
  inline Item_equal()
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(),
 
1551
    const_item(0),
 
1552
    eval_item(0),
 
1553
    cond_false(0)
 
1554
  {
 
1555
    const_item_cache=0;
 
1556
  }
 
1557
 
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);