~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/cmpfunc.h

  • Committer: Patrick Crews
  • Date: 2011-01-29 14:17:35 UTC
  • mto: (2126.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 2127.
  • Revision ID: gleebix@gmail.com-20110129141735-3y2658vt5ur0a33o
Fixes to make test-dbqp

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
 
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
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
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"
30
31
#include "drizzled/item/decimal.h"
31
32
#include "drizzled/function/math/int.h"
32
33
#include "drizzled/function/numhybrid.h"
33
34
#include "drizzled/session.h"
34
35
#include "drizzled/common.h"
35
36
#include "drizzled/qsort_cmp.h"
 
37
#include "drizzled/item/function/boolean.h"
36
38
 
37
39
namespace drizzled
38
40
{
47
49
 
48
50
typedef int (*Item_field_cmpfunc)(Item_field *f1, Item_field *f2, void *arg);
49
51
 
50
 
uint64_t get_datetime_value(Session *session, 
51
 
                            Item ***item_arg, 
52
 
                            Item **cache_arg,
53
 
                            Item *warn_item, 
54
 
                            bool *is_null);
 
52
int64_t get_datetime_value(Session *session, 
 
53
                           Item ***item_arg, 
 
54
                           Item **cache_arg,
 
55
                           Item *warn_item, 
 
56
                           bool *is_null);
55
57
 
56
58
class Arg_comparator: public memory::SqlAlloc
57
59
{
67
69
  bool is_nulls_eq;                // TRUE <=> compare for the EQUAL_FUNC
68
70
  enum enum_date_cmp_type { CMP_DATE_DFLT= 0, CMP_DATE_WITH_DATE,
69
71
                            CMP_DATE_WITH_STR, CMP_STR_WITH_DATE };
70
 
  uint64_t (*get_value_func)(Session *session, Item ***item_arg, Item **cache_arg,
71
 
                              Item *warn_item, bool *is_null);
 
72
  int64_t (*get_value_func)(Session *session, Item ***item_arg, Item **cache_arg,
 
73
                            Item *warn_item, bool *is_null);
72
74
public:
73
75
  DTCollation cmp_collation;
74
76
 
116
118
  int compare_datetime();        // compare args[0] & args[1] as DATETIMEs
117
119
 
118
120
  static enum enum_date_cmp_type can_compare_as_dates(Item *a, Item *b,
119
 
                                                      uint64_t *const_val_arg);
 
121
                                                      int64_t *const_val_arg);
120
122
 
121
123
  void set_datetime_cmp_func(Item **a1, Item **b1);
122
124
  static arg_cmp_func comparator_matrix [5][2];
124
126
  friend class Item_func;
125
127
};
126
128
 
127
 
class Item_bool_func :public Item_int_func
128
 
{
129
 
public:
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; }
137
 
};
138
 
 
139
129
 
140
130
/**
141
131
  Abstract Item class, to represent <code>X IS [NOT] (TRUE | FALSE)</code>
142
132
  boolean predicates.
143
133
*/
144
134
 
145
 
class Item_func_truth : public Item_bool_func
 
135
class Item_func_truth : public item::function::Boolean
146
136
{
147
137
public:
148
138
  virtual bool val_bool();
152
142
 
153
143
protected:
154
144
  Item_func_truth(Item *a, bool a_value, bool a_affirmative)
155
 
  : Item_bool_func(a), value(a_value), affirmative(a_affirmative)
 
145
  : item::function::Boolean(a), value(a_value), affirmative(a_affirmative)
156
146
  {}
157
147
 
158
148
  ~Item_func_truth()
241
231
    placed into a separate class called 'Item_in_optimizer'.
242
232
*/
243
233
 
244
 
class Item_in_optimizer: public Item_bool_func
 
234
class Item_in_optimizer: public item::function::Boolean
245
235
{
246
236
protected:
247
237
  Item_cache *cache;
255
245
  bool result_for_null_param;
256
246
public:
257
247
  Item_in_optimizer(Item *a, Item_in_subselect *b):
258
 
    Item_bool_func(a, reinterpret_cast<Item *>(b)), cache(0),
 
248
    item::function::Boolean(a, reinterpret_cast<Item *>(b)), cache(0),
259
249
    save_cache(0), result_for_null_param(UNKNOWN)
260
250
  { with_subselect= true; }
261
251
  bool fix_fields(Session *, Item **);
387
377
  { return true; }
388
378
};
389
379
 
390
 
class Item_func_not :public Item_bool_func
 
380
class Item_func_not :public item::function::Boolean
391
381
{
392
382
public:
393
 
  Item_func_not(Item *a) :Item_bool_func(a) {}
 
383
  Item_func_not(Item *a) :item::function::Boolean(a) {}
394
384
  int64_t val_int();
395
385
  enum Functype functype() const { return NOT_FUNC; }
396
386
  const char *func_name() const { return "not"; }
429
419
   - To wrap condition that is pushed down into subquery
430
420
*/
431
421
 
432
 
class Item_func_trig_cond: public Item_bool_func
 
422
class Item_func_trig_cond: public item::function::Boolean
433
423
{
434
424
  bool *trig_var;
435
425
public:
436
 
  Item_func_trig_cond(Item *a, bool *f) : Item_bool_func(a) { trig_var= f; }
 
426
  Item_func_trig_cond(Item *a, bool *f) : item::function::Boolean(a) { trig_var= f; }
437
427
  int64_t val_int() { return *trig_var ? args[0]->val_int() : 1; }
438
428
  enum Functype functype() const { return TRIG_COND_FUNC; };
439
429
  const char *func_name() const { return "trigcond"; };
650
640
{
651
641
  Item_result type;
652
642
  double dbl;
653
 
  my_decimal dec;
 
643
  type::Decimal dec;
654
644
};
655
645
 
656
646
class Item_func_interval :public Item_int_func
681
671
  double real_op();
682
672
  int64_t int_op();
683
673
  String *str_op(String *);
684
 
  my_decimal *decimal_op(my_decimal *);
 
674
  type::Decimal *decimal_op(type::Decimal *);
685
675
  void fix_length_and_dec();
686
676
  void find_num_type() {}
687
677
  enum Item_result result_type () const { return hybrid_type; }
700
690
  double real_op();
701
691
  int64_t int_op();
702
692
  String *str_op(String *str);
703
 
  my_decimal *decimal_op(my_decimal *);
 
693
  type::Decimal *decimal_op(type::Decimal *);
704
694
  enum_field_types field_type() const;
705
695
  void fix_length_and_dec();
706
696
  const char *func_name() const { return "ifnull"; }
724
714
  double val_real();
725
715
  int64_t val_int();
726
716
  String *val_str(String *str);
727
 
  my_decimal *val_decimal(my_decimal *);
 
717
  type::Decimal *val_decimal(type::Decimal *);
728
718
  enum Item_result result_type () const { return cached_result_type; }
729
719
  enum_field_types field_type() const { return cached_field_type; }
730
720
  bool fix_fields(Session *, Item **);
744
734
  double val_real();
745
735
  int64_t val_int();
746
736
  String *val_str(String *str);
747
 
  my_decimal *val_decimal(my_decimal *);
 
737
  type::Decimal *val_decimal(type::Decimal *);
748
738
  enum Item_result result_type () const { return cached_result_type; }
749
739
  void fix_length_and_dec();
750
740
  uint32_t decimal_precision() const { return args[0]->decimal_precision(); }
919
909
 
920
910
class in_decimal :public in_vector
921
911
{
922
 
  my_decimal val;
 
912
  type::Decimal val;
923
913
public:
924
914
  in_decimal(uint32_t elements);
925
915
  void set(uint32_t pos, Item *item);
930
920
  }
931
921
  void value_to_item(uint32_t pos, Item *item)
932
922
  {
933
 
    my_decimal *dec= ((my_decimal *)base) + pos;
 
923
    type::Decimal *dec= ((type::Decimal *)base) + pos;
934
924
    Item_decimal *item_dec= (Item_decimal*)item;
935
925
    item_dec->set_decimal_value(dec);
936
926
  }
1038
1028
*/
1039
1029
class cmp_item_datetime :public cmp_item
1040
1030
{
1041
 
  uint64_t value;
 
1031
  int64_t value;
 
1032
 
1042
1033
public:
1043
1034
  Session *session;
1044
1035
  /* Item used for issuing warnings. */
1078
1069
 
1079
1070
class cmp_item_decimal :public cmp_item
1080
1071
{
1081
 
  my_decimal value;
 
1072
  type::Decimal value;
1082
1073
public:
1083
1074
  cmp_item_decimal() {}                       /* Remove gcc warning */
1084
1075
  void store_value(Item *item);
1149
1140
  Item_result cmp_type;
1150
1141
  DTCollation cmp_collation;
1151
1142
  enum_field_types cached_field_type;
1152
 
  cmp_item *cmp_items[5]; /* For all result types */
 
1143
  cmp_item *cmp_items[DECIMAL_RESULT+1]; /* For all result types */
1153
1144
  cmp_item *case_item;
1154
1145
public:
1155
1146
  Item_func_case(List<Item> &list, Item *first_expr_arg, Item *else_expr_arg)
1173
1164
  double val_real();
1174
1165
  int64_t val_int();
1175
1166
  String *val_str(String *);
1176
 
  my_decimal *val_decimal(my_decimal *);
 
1167
  type::Decimal *val_decimal(type::Decimal *);
1177
1168
  bool fix_fields(Session *session, Item **ref);
1178
1169
  void fix_length_and_dec();
1179
1170
  uint32_t decimal_precision() const;
1234
1225
  uint32_t decimal_precision() const { return 1; }
1235
1226
  void cleanup()
1236
1227
  {
1237
 
    uint32_t i;
1238
1228
    Item_int_func::cleanup();
1239
1229
    delete array;
1240
1230
    array= 0;
1241
 
    for (i= 0; i <= (uint32_t)DECIMAL_RESULT + 1; i++)
 
1231
    for (int i= STRING_RESULT; i <= DECIMAL_RESULT; i++)
1242
1232
    {
1243
1233
      delete cmp_items[i];
1244
1234
      cmp_items[i]= 0;
1286
1276
 
1287
1277
/* Functions used by where clause */
1288
1278
 
1289
 
class Item_func_isnull :public Item_bool_func
 
1279
class Item_func_isnull :public item::function::Boolean
1290
1280
{
1291
1281
protected:
1292
1282
  int64_t cached_value;
1293
1283
public:
1294
 
  Item_func_isnull(Item *a) :Item_bool_func(a) {}
 
1284
  Item_func_isnull(Item *a) :item::function::Boolean(a) {}
1295
1285
  int64_t val_int();
1296
1286
  enum Functype functype() const { return ISNULL_FUNC; }
1297
1287
  void fix_length_and_dec()
1353
1343
};
1354
1344
 
1355
1345
 
1356
 
class Item_func_isnotnull :public Item_bool_func
 
1346
class Item_func_isnotnull :public item::function::Boolean
1357
1347
{
1358
1348
  bool abort_on_null;
1359
1349
public:
1360
 
  Item_func_isnotnull(Item *a) :Item_bool_func(a), abort_on_null(0) {}
 
1350
  Item_func_isnotnull(Item *a) :item::function::Boolean(a), abort_on_null(0) {}
1361
1351
  int64_t val_int();
1362
1352
  enum Functype functype() const { return ISNOTNULL_FUNC; }
1363
1353
  void fix_length_and_dec()
1417
1407
 
1418
1408
typedef class Item COND;
1419
1409
 
1420
 
class Item_cond :public Item_bool_func
 
1410
class Item_cond :public item::function::Boolean
1421
1411
{
1422
1412
protected:
1423
1413
  List<Item> list;
1429
1419
  using Item::split_sum_func;
1430
1420
 
1431
1421
  /* Item_cond() is only used to create top level items */
1432
 
  Item_cond(): Item_bool_func(), abort_on_null(1)
 
1422
  Item_cond(): item::function::Boolean(), abort_on_null(1)
1433
1423
  { const_item_cache=0; }
1434
1424
  Item_cond(Item *i1,Item *i2)
1435
 
    :Item_bool_func(), abort_on_null(0)
 
1425
    :item::function::Boolean(), abort_on_null(0)
1436
1426
  {
1437
1427
    list.push_back(i1);
1438
1428
    list.push_back(i2);
1439
1429
  }
1440
1430
  Item_cond(Session *session, Item_cond *item);
1441
1431
  Item_cond(List<Item> &nlist)
1442
 
    :Item_bool_func(), list(nlist), abort_on_null(0) {}
 
1432
    :item::function::Boolean(), list(nlist), abort_on_null(0) {}
1443
1433
  bool add(Item *item) { return list.push_back(item); }
1444
1434
  bool add_at_head(Item *item) { return list.push_front(item); }
1445
1435
  void add_at_head(List<Item> *nlist) { list.prepand(nlist); }
1543
1533
  object represents f1=f2= ...=fn to the projection of known fields fi1=...=fik.
1544
1534
*/
1545
1535
 
1546
 
class Item_equal: public Item_bool_func
 
1536
class Item_equal: public item::function::Boolean
1547
1537
{
1548
1538
  List<Item_field> fields; /* list of equal field items                    */
1549
1539
  Item *const_item;        /* optional constant item equal to fields items */
1550
1540
  cmp_item *eval_item;
1551
1541
  bool cond_false;
 
1542
 
1552
1543
public:
1553
 
  inline Item_equal()
1554
 
    : Item_bool_func(), const_item(0), eval_item(0), cond_false(0)
1555
 
  { const_item_cache=0 ;}
 
1544
  inline Item_equal() :
 
1545
    item::function::Boolean(),
 
1546
    const_item(0),
 
1547
    eval_item(0),
 
1548
    cond_false(0)
 
1549
  {
 
1550
    const_item_cache=0;
 
1551
  }
 
1552
 
1556
1553
  Item_equal(Item_field *f1, Item_field *f2);
1557
1554
  Item_equal(Item *c, Item_field *f);
1558
1555
  Item_equal(Item_equal *item_equal);