~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/cmpfunc.h

  • Committer: Brian Aker
  • Date: 2009-02-21 00:18:15 UTC
  • Revision ID: brian@tangent.org-20090221001815-x20e8h71e984lvs1
Completion (?) of uint conversion.

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
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"
31
30
#include "drizzled/item/decimal.h"
32
31
#include "drizzled/function/math/int.h"
33
32
#include "drizzled/function/numhybrid.h"
34
 
#include "drizzled/common.h"
35
 
#include "drizzled/qsort_cmp.h"
36
 
#include "drizzled/item/function/boolean.h"
37
 
 
38
 
namespace drizzled
39
 
{
 
33
#include "drizzled/session.h"
40
34
 
41
35
extern Item_result item_cmp_type(Item_result a,Item_result b);
42
 
 
43
36
class Item_bool_func2;
44
37
class Arg_comparator;
45
38
class Item_sum_hybrid;
46
39
class Item_row;
47
 
class Session;
48
40
 
49
41
typedef int (Arg_comparator::*arg_cmp_func)();
50
42
 
51
43
typedef int (*Item_field_cmpfunc)(Item_field *f1, Item_field *f2, void *arg);
52
44
 
53
 
int64_t get_datetime_value(Session *session, 
54
 
                           Item ***item_arg, 
55
 
                           Item **cache_arg,
56
 
                           Item *warn_item, 
57
 
                           bool *is_null);
58
 
 
59
 
class Arg_comparator: public memory::SqlAlloc
 
45
class Arg_comparator: public Sql_alloc
60
46
{
61
47
  Item **a, **b;
62
48
  arg_cmp_func func;
70
56
  bool is_nulls_eq;                // TRUE <=> compare for the EQUAL_FUNC
71
57
  enum enum_date_cmp_type { CMP_DATE_DFLT= 0, CMP_DATE_WITH_DATE,
72
58
                            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);
 
59
  uint64_t (*get_value_func)(Session *session, Item ***item_arg, Item **cache_arg,
 
60
                              Item *warn_item, bool *is_null);
75
61
public:
76
62
  DTCollation cmp_collation;
77
63
 
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
 
  {};
 
64
  Arg_comparator(): session(0), a_cache(0), b_cache(0) {};
 
65
  Arg_comparator(Item **a1, Item **a2): a(a1), b(a2), session(0),
 
66
    a_cache(0), b_cache(0) {};
91
67
 
92
68
  int set_compare_func(Item_bool_func2 *owner, Item_result type);
93
69
  inline int set_compare_func(Item_bool_func2 *owner_arg)
129
105
  int compare_datetime();        // compare args[0] & args[1] as DATETIMEs
130
106
 
131
107
  static enum enum_date_cmp_type can_compare_as_dates(Item *a, Item *b,
132
 
                                                      int64_t *const_val_arg);
 
108
                                                      uint64_t *const_val_arg);
133
109
 
134
110
  void set_datetime_cmp_func(Item **a1, Item **b1);
135
111
  static arg_cmp_func comparator_matrix [5][2];
137
113
  friend class Item_func;
138
114
};
139
115
 
 
116
class Item_bool_func :public Item_int_func
 
117
{
 
118
public:
 
119
  Item_bool_func() :Item_int_func() {}
 
120
  Item_bool_func(Item *a) :Item_int_func(a) {}
 
121
  Item_bool_func(Item *a,Item *b) :Item_int_func(a,b) {}
 
122
  Item_bool_func(Session *session, Item_bool_func *item) :Item_int_func(session, item) {}
 
123
  bool is_bool_func() { return 1; }
 
124
  void fix_length_and_dec() { decimals=0; max_length=1; }
 
125
  uint32_t decimal_precision() const { return 1; }
 
126
};
 
127
 
140
128
 
141
129
/**
142
130
  Abstract Item class, to represent <code>X IS [NOT] (TRUE | FALSE)</code>
143
131
  boolean predicates.
144
132
*/
145
133
 
146
 
class Item_func_truth : public item::function::Boolean
 
134
class Item_func_truth : public Item_bool_func
147
135
{
148
136
public:
149
137
  virtual bool val_bool();
153
141
 
154
142
protected:
155
143
  Item_func_truth(Item *a, bool a_value, bool a_affirmative)
156
 
  : item::function::Boolean(a), value(a_value), affirmative(a_affirmative)
 
144
  : Item_bool_func(a), value(a_value), affirmative(a_affirmative)
157
145
  {}
158
146
 
159
147
  ~Item_func_truth()
242
230
    placed into a separate class called 'Item_in_optimizer'.
243
231
*/
244
232
 
245
 
class Item_in_optimizer: public item::function::Boolean
 
233
class Item_in_optimizer: public Item_bool_func
246
234
{
247
235
protected:
248
236
  Item_cache *cache;
256
244
  bool result_for_null_param;
257
245
public:
258
246
  Item_in_optimizer(Item *a, Item_in_subselect *b):
259
 
    item::function::Boolean(a, reinterpret_cast<Item *>(b)), cache(0),
 
247
    Item_bool_func(a, reinterpret_cast<Item *>(b)), cache(0),
260
248
    save_cache(0), result_for_null_param(UNKNOWN)
261
249
  { with_subselect= true; }
262
250
  bool fix_fields(Session *, Item **);
388
376
  { return true; }
389
377
};
390
378
 
391
 
class Item_func_not :public item::function::Boolean
 
379
class Item_func_not :public Item_bool_func
392
380
{
393
381
public:
394
 
  Item_func_not(Item *a) :item::function::Boolean(a) {}
 
382
  Item_func_not(Item *a) :Item_bool_func(a) {}
395
383
  int64_t val_int();
396
384
  enum Functype functype() const { return NOT_FUNC; }
397
385
  const char *func_name() const { return "not"; }
430
418
   - To wrap condition that is pushed down into subquery
431
419
*/
432
420
 
433
 
class Item_func_trig_cond: public item::function::Boolean
 
421
class Item_func_trig_cond: public Item_bool_func
434
422
{
435
423
  bool *trig_var;
436
424
public:
437
 
  Item_func_trig_cond(Item *a, bool *f) : item::function::Boolean(a) { trig_var= f; }
 
425
  Item_func_trig_cond(Item *a, bool *f) : Item_bool_func(a) { trig_var= f; }
438
426
  int64_t val_int() { return *trig_var ? args[0]->val_int() : 1; }
439
427
  enum Functype functype() const { return TRIG_COND_FUNC; };
440
428
  const char *func_name() const { return "trigcond"; };
651
639
{
652
640
  Item_result type;
653
641
  double dbl;
654
 
  type::Decimal dec;
 
642
  my_decimal dec;
655
643
};
656
644
 
657
645
class Item_func_interval :public Item_int_func
682
670
  double real_op();
683
671
  int64_t int_op();
684
672
  String *str_op(String *);
685
 
  type::Decimal *decimal_op(type::Decimal *);
 
673
  my_decimal *decimal_op(my_decimal *);
686
674
  void fix_length_and_dec();
687
675
  void find_num_type() {}
688
676
  enum Item_result result_type () const { return hybrid_type; }
701
689
  double real_op();
702
690
  int64_t int_op();
703
691
  String *str_op(String *str);
704
 
  type::Decimal *decimal_op(type::Decimal *);
 
692
  my_decimal *decimal_op(my_decimal *);
705
693
  enum_field_types field_type() const;
706
694
  void fix_length_and_dec();
707
695
  const char *func_name() const { return "ifnull"; }
725
713
  double val_real();
726
714
  int64_t val_int();
727
715
  String *val_str(String *str);
728
 
  type::Decimal *val_decimal(type::Decimal *);
 
716
  my_decimal *val_decimal(my_decimal *);
729
717
  enum Item_result result_type () const { return cached_result_type; }
730
718
  enum_field_types field_type() const { return cached_field_type; }
731
719
  bool fix_fields(Session *, Item **);
745
733
  double val_real();
746
734
  int64_t val_int();
747
735
  String *val_str(String *str);
748
 
  type::Decimal *val_decimal(type::Decimal *);
 
736
  my_decimal *val_decimal(my_decimal *);
749
737
  enum Item_result result_type () const { return cached_result_type; }
750
738
  void fix_length_and_dec();
751
739
  uint32_t decimal_precision() const { return args[0]->decimal_precision(); }
766
754
 
767
755
/* A vector of values of some type  */
768
756
 
769
 
class in_vector :public memory::SqlAlloc
 
757
class in_vector :public Sql_alloc
770
758
{
771
759
public:
772
760
  char *base;
778
766
  in_vector() {}
779
767
  in_vector(uint32_t elements,uint32_t element_length,qsort2_cmp cmp_func,
780
768
            const CHARSET_INFO * const cmp_coll)
781
 
    :base((char*) memory::sql_calloc(elements*element_length)),
 
769
    :base((char*) sql_calloc(elements*element_length)),
782
770
     size(element_length), compare(cmp_func), collation(cmp_coll),
783
771
     count(elements), used_count(elements) {}
784
772
  virtual ~in_vector() {}
785
773
  virtual void set(uint32_t pos,Item *item)=0;
786
774
  virtual unsigned char *get_value(Item *item)=0;
787
 
  void sort();
 
775
  void sort()
 
776
  {
 
777
    my_qsort2(base,used_count,size,compare, (void *) collation);
 
778
  }
788
779
  int find(Item *item);
789
780
 
790
781
  /*
920
911
 
921
912
class in_decimal :public in_vector
922
913
{
923
 
  type::Decimal val;
 
914
  my_decimal val;
924
915
public:
925
916
  in_decimal(uint32_t elements);
926
917
  void set(uint32_t pos, Item *item);
931
922
  }
932
923
  void value_to_item(uint32_t pos, Item *item)
933
924
  {
934
 
    type::Decimal *dec= ((type::Decimal *)base) + pos;
 
925
    my_decimal *dec= ((my_decimal *)base) + pos;
935
926
    Item_decimal *item_dec= (Item_decimal*)item;
936
927
    item_dec->set_decimal_value(dec);
937
928
  }
944
935
** Classes for easy comparing of non const items
945
936
*/
946
937
 
947
 
class cmp_item :public memory::SqlAlloc
 
938
class cmp_item :public Sql_alloc
948
939
{
949
940
public:
950
941
  const CHARSET_INFO *cmp_charset;
951
 
 
952
 
  cmp_item()
953
 
  {
954
 
    cmp_charset= &my_charset_bin;
955
 
  }
956
 
 
 
942
  cmp_item() { cmp_charset= &my_charset_bin; }
957
943
  virtual ~cmp_item() {}
958
944
  virtual void store_value(Item *item)= 0;
959
945
  virtual int cmp(Item *item)= 0;
1044
1030
*/
1045
1031
class cmp_item_datetime :public cmp_item
1046
1032
{
1047
 
  int64_t value;
1048
 
 
 
1033
  uint64_t value;
1049
1034
public:
1050
1035
  Session *session;
1051
1036
  /* Item used for issuing warnings. */
1085
1070
 
1086
1071
class cmp_item_decimal :public cmp_item
1087
1072
{
1088
 
  type::Decimal value;
 
1073
  my_decimal value;
1089
1074
public:
1090
1075
  cmp_item_decimal() {}                       /* Remove gcc warning */
1091
1076
  void store_value(Item *item);
1156
1141
  Item_result cmp_type;
1157
1142
  DTCollation cmp_collation;
1158
1143
  enum_field_types cached_field_type;
1159
 
  cmp_item *cmp_items[DECIMAL_RESULT+1]; /* For all result types */
 
1144
  cmp_item *cmp_items[5]; /* For all result types */
1160
1145
  cmp_item *case_item;
1161
1146
public:
1162
1147
  Item_func_case(List<Item> &list, Item *first_expr_arg, Item *else_expr_arg)
1180
1165
  double val_real();
1181
1166
  int64_t val_int();
1182
1167
  String *val_str(String *);
1183
 
  type::Decimal *val_decimal(type::Decimal *);
 
1168
  my_decimal *val_decimal(my_decimal *);
1184
1169
  bool fix_fields(Session *session, Item **ref);
1185
1170
  void fix_length_and_dec();
1186
1171
  uint32_t decimal_precision() const;
1241
1226
  uint32_t decimal_precision() const { return 1; }
1242
1227
  void cleanup()
1243
1228
  {
 
1229
    uint32_t i;
1244
1230
    Item_int_func::cleanup();
1245
1231
    delete array;
1246
1232
    array= 0;
1247
 
    for (int i= STRING_RESULT; i <= DECIMAL_RESULT; i++)
 
1233
    for (i= 0; i <= (uint32_t)DECIMAL_RESULT + 1; i++)
1248
1234
    {
1249
1235
      delete cmp_items[i];
1250
1236
      cmp_items[i]= 0;
1292
1278
 
1293
1279
/* Functions used by where clause */
1294
1280
 
1295
 
class Item_func_isnull :public item::function::Boolean
 
1281
class Item_func_isnull :public Item_bool_func
1296
1282
{
1297
1283
protected:
1298
1284
  int64_t cached_value;
1299
1285
public:
1300
 
  Item_func_isnull(Item *a) :item::function::Boolean(a) {}
 
1286
  Item_func_isnull(Item *a) :Item_bool_func(a) {}
1301
1287
  int64_t val_int();
1302
1288
  enum Functype functype() const { return ISNULL_FUNC; }
1303
1289
  void fix_length_and_dec()
1359
1345
};
1360
1346
 
1361
1347
 
1362
 
class Item_func_isnotnull :public item::function::Boolean
 
1348
class Item_func_isnotnull :public Item_bool_func
1363
1349
{
1364
1350
  bool abort_on_null;
1365
1351
public:
1366
 
  Item_func_isnotnull(Item *a) :item::function::Boolean(a), abort_on_null(0) {}
 
1352
  Item_func_isnotnull(Item *a) :Item_bool_func(a), abort_on_null(0) {}
1367
1353
  int64_t val_int();
1368
1354
  enum Functype functype() const { return ISNOTNULL_FUNC; }
1369
1355
  void fix_length_and_dec()
1402
1388
 
1403
1389
  bool escape_used_in_parsing;
1404
1390
 
1405
 
 
1406
1391
public:
1407
 
 
1408
 
  char *escape;
 
1392
  int escape;
1409
1393
 
1410
1394
  Item_func_like(Item *a,Item *b, Item *escape_arg, bool escape_used)
1411
1395
    :Item_bool_func2(a,b), canDoTurboBM(false), pattern(0), pattern_len(0),
1412
1396
     bmGs(0), bmBc(0), escape_item(escape_arg),
1413
 
     escape_used_in_parsing(escape_used), escape(NULL) {}
 
1397
     escape_used_in_parsing(escape_used) {}
1414
1398
  int64_t val_int();
1415
1399
  enum Functype functype() const { return LIKE_FUNC; }
1416
1400
  optimize_type select_optimize() const;
1423
1407
 
1424
1408
typedef class Item COND;
1425
1409
 
1426
 
class Item_cond :public item::function::Boolean
 
1410
class Item_cond :public Item_bool_func
1427
1411
{
1428
1412
protected:
1429
1413
  List<Item> list;
1435
1419
  using Item::split_sum_func;
1436
1420
 
1437
1421
  /* Item_cond() is only used to create top level items */
1438
 
  Item_cond(): item::function::Boolean(), abort_on_null(1)
 
1422
  Item_cond(): Item_bool_func(), abort_on_null(1)
1439
1423
  { const_item_cache=0; }
1440
1424
  Item_cond(Item *i1,Item *i2)
1441
 
    :item::function::Boolean(), abort_on_null(0)
 
1425
    :Item_bool_func(), abort_on_null(0)
1442
1426
  {
1443
1427
    list.push_back(i1);
1444
1428
    list.push_back(i2);
1445
1429
  }
1446
1430
  Item_cond(Session *session, Item_cond *item);
1447
1431
  Item_cond(List<Item> &nlist)
1448
 
    :item::function::Boolean(), list(nlist), abort_on_null(0) {}
 
1432
    :Item_bool_func(), list(nlist), abort_on_null(0) {}
1449
1433
  bool add(Item *item) { return list.push_back(item); }
1450
1434
  bool add_at_head(Item *item) { return list.push_front(item); }
1451
1435
  void add_at_head(List<Item> *nlist) { list.prepand(nlist); }
1549
1533
  object represents f1=f2= ...=fn to the projection of known fields fi1=...=fik.
1550
1534
*/
1551
1535
 
1552
 
class Item_equal: public item::function::Boolean
 
1536
class Item_equal: public Item_bool_func
1553
1537
{
1554
1538
  List<Item_field> fields; /* list of equal field items                    */
1555
1539
  Item *const_item;        /* optional constant item equal to fields items */
1556
1540
  cmp_item *eval_item;
1557
1541
  bool cond_false;
1558
 
 
1559
1542
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
 
 
 
1543
  inline Item_equal()
 
1544
    : Item_bool_func(), const_item(0), eval_item(0), cond_false(0)
 
1545
  { const_item_cache=0 ;}
1569
1546
  Item_equal(Item_field *f1, Item_field *f2);
1570
1547
  Item_equal(Item *c, Item_field *f);
1571
1548
  Item_equal(Item_equal *item_equal);
1593
1570
  { return fields.head()->collation.collation; }
1594
1571
};
1595
1572
 
1596
 
class COND_EQUAL: public memory::SqlAlloc
 
1573
class COND_EQUAL: public Sql_alloc
1597
1574
{
1598
1575
public:
1599
1576
  uint32_t max_members;               /* max number of members the current level
1707
1684
  void top_level_item() {}
1708
1685
};
1709
1686
 
1710
 
enum_field_types agg_field_type(Item **items, uint32_t nitems);
1711
 
 
1712
1687
 
1713
1688
/* Some useful inline functions */
1714
1689
 
1721
1696
 
1722
1697
Item *and_expressions(Item *a, Item *b, Item **org_item);
1723
1698
 
1724
 
} /* namespace drizzled */
1725
 
 
1726
1699
#endif /* DRIZZLED_ITEM_CMPFUNC_H */