~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/cmpfunc.cc

  • Committer: Brian Aker
  • Date: 2011-02-22 06:12:02 UTC
  • mfrom: (2190.1.6 drizzle-build)
  • Revision ID: brian@tangent.org-20110222061202-k03czxykqy4x9hjs
List update, header fixes, multiple symbols, and David deletes some code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
  This file defines all compare functions
22
22
*/
23
23
 
24
 
#include "config.h"
25
 
#include "drizzled/sql_select.h"
26
 
#include "drizzled/error.h"
27
 
#include "drizzled/temporal.h"
28
 
#include "drizzled/item/cmpfunc.h"
29
 
#include "drizzled/cached_item.h"
30
 
#include "drizzled/item/cache_int.h"
31
 
#include "drizzled/item/int_with_ref.h"
32
 
#include "drizzled/check_stack_overrun.h"
33
 
#include "drizzled/time_functions.h"
34
 
#include "drizzled/internal/my_sys.h"
 
24
#include <config.h>
 
25
 
 
26
#include <drizzled/cached_item.h>
 
27
#include <drizzled/check_stack_overrun.h>
 
28
#include <drizzled/current_session.h>
 
29
#include <drizzled/error.h>
 
30
#include <drizzled/internal/my_sys.h>
 
31
#include <drizzled/item/cache_int.h>
 
32
#include <drizzled/item/cmpfunc.h>
 
33
#include <drizzled/item/int_with_ref.h>
 
34
#include <drizzled/item/subselect.h>
 
35
#include <drizzled/session.h>
 
36
#include <drizzled/sql_select.h>
 
37
#include <drizzled/temporal.h>
 
38
#include <drizzled/time_functions.h>
 
39
 
35
40
#include <math.h>
36
41
#include <algorithm>
37
42
 
493
498
void Item_bool_func2::fix_length_and_dec()
494
499
{
495
500
  max_length= 1;                                     // Function returns 0 or 1
496
 
  Session *session;
497
501
 
498
502
  /*
499
503
    As some compare functions are generated after sql_yacc,
531
535
    return;
532
536
  }
533
537
 
534
 
  session= current_session;
535
538
  Item_field *field_item= NULL;
536
539
 
537
540
  if (args[0]->real_item()->type() == FIELD_ITEM)
540
543
    if (field_item->field->can_be_compared_as_int64_t() &&
541
544
        !(field_item->is_datetime() && args[1]->result_type() == STRING_RESULT))
542
545
    {
543
 
      if (convert_constant_item(session, field_item, &args[1]))
 
546
      if (convert_constant_item(&getSession(), field_item, &args[1]))
544
547
      {
545
548
        cmp.set_cmp_func(this, tmp_arg, tmp_arg+1,
546
549
                         INT_RESULT);           // Works for all types.
556
559
          !(field_item->is_datetime() &&
557
560
            args[0]->result_type() == STRING_RESULT))
558
561
      {
559
 
        if (convert_constant_item(session, field_item, &args[0]))
 
562
        if (convert_constant_item(&getSession(), field_item, &args[0]))
560
563
        {
561
564
          cmp.set_cmp_func(this, tmp_arg, tmp_arg+1,
562
565
                           INT_RESULT); // Works for all types.
569
572
  set_cmp_func();
570
573
}
571
574
 
 
575
Arg_comparator::Arg_comparator():
 
576
  session(current_session),
 
577
  a_cache(0),
 
578
  b_cache(0)
 
579
{}
 
580
 
 
581
Arg_comparator::Arg_comparator(Item **a1, Item **a2):
 
582
  a(a1),
 
583
  b(a2),
 
584
  session(current_session),
 
585
  a_cache(0),
 
586
  b_cache(0)
 
587
{}
572
588
 
573
589
int Arg_comparator::set_compare_func(Item_bool_func2 *item, Item_result type)
574
590
{
696
712
    converted value. 0 on error and on zero-dates -- check 'failure'
697
713
*/
698
714
 
699
 
static uint64_t
700
 
get_date_from_str(Session *session, String *str, enum enum_drizzle_timestamp_type warn_type,
 
715
static int64_t
 
716
get_date_from_str(Session *session, String *str, type::timestamp_t warn_type,
701
717
                  char *warn_name, bool *error_arg)
702
718
{
703
 
  uint64_t value= 0;
704
 
  int error;
705
 
  DRIZZLE_TIME l_time;
706
 
  enum enum_drizzle_timestamp_type ret;
707
 
 
708
 
  ret= str_to_datetime(str->ptr(), str->length(), &l_time,
709
 
                       (TIME_FUZZY_DATE | MODE_INVALID_DATES |
710
 
                        (session->variables.sql_mode & MODE_NO_ZERO_DATE)),
711
 
                       &error);
712
 
 
713
 
  if (ret == DRIZZLE_TIMESTAMP_DATETIME || ret == DRIZZLE_TIMESTAMP_DATE)
 
719
  int64_t value= 0;
 
720
  type::cut_t error= type::VALID;
 
721
  type::Time l_time;
 
722
  type::timestamp_t ret;
 
723
 
 
724
  ret= l_time.store(str->ptr(), str->length(),
 
725
                    (TIME_FUZZY_DATE | MODE_INVALID_DATES | (session->variables.sql_mode & MODE_NO_ZERO_DATE)),
 
726
                    error);
 
727
 
 
728
  if (ret == type::DRIZZLE_TIMESTAMP_DATETIME || ret == type::DRIZZLE_TIMESTAMP_DATE)
714
729
  {
715
730
    /*
716
731
      Do not return yet, we may still want to throw a "trailing garbage"
717
732
      warning.
718
733
    */
719
734
    *error_arg= false;
720
 
    value= TIME_to_uint64_t_datetime(&l_time);
 
735
    l_time.convert(value);
721
736
  }
722
737
  else
723
738
  {
724
739
    *error_arg= true;
725
 
    error= 1;                                   /* force warning */
 
740
    error= type::CUT;                                   /* force warning */
726
741
  }
727
742
 
728
 
  if (error > 0)
 
743
  if (error != type::VALID)
729
744
  {
730
745
    make_truncated_value_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
731
746
                                 str->ptr(), str->length(),
770
785
 
771
786
enum Arg_comparator::enum_date_cmp_type
772
787
Arg_comparator::can_compare_as_dates(Item *in_a, Item *in_b,
773
 
                                     uint64_t *const_value)
 
788
                                     int64_t *const_value)
774
789
{
775
790
  enum enum_date_cmp_type cmp_type= CMP_DATE_DFLT;
776
791
  Item *str_arg= 0, *date_arg= 0;
781
796
  if (in_a->is_datetime())
782
797
  {
783
798
    if (in_b->is_datetime())
 
799
    {
784
800
      cmp_type= CMP_DATE_WITH_DATE;
 
801
    }
785
802
    else if (in_b->result_type() == STRING_RESULT)
786
803
    {
787
804
      cmp_type= CMP_DATE_WITH_STR;
823
840
       * Does a uint64_t conversion really have to happen here?  Fields return int64_t
824
841
       * from val_int(), not uint64_t...
825
842
       */
826
 
      uint64_t value;
 
843
      int64_t value;
827
844
      String *str_val;
828
845
      String tmp;
829
846
      /* DateTime used to pick up as many string conversion possibilities as possible. */
849
866
      }
850
867
 
851
868
      /* String conversion was good.  Convert to an integer for comparison purposes. */
852
 
      int64_t int_value;
853
 
      temporal.to_int64_t(&int_value);
854
 
      value= (uint64_t) int_value;
 
869
      temporal.to_int64_t(&value);
855
870
 
856
871
      if (const_value)
857
872
        *const_value= value;
865
880
                                        Item **a1, Item **a2,
866
881
                                        Item_result type)
867
882
{
868
 
  enum enum_date_cmp_type cmp_type;
869
 
  uint64_t const_value= (uint64_t)-1;
 
883
  enum_date_cmp_type cmp_type;
 
884
  int64_t const_value= -1;
870
885
  a= a1;
871
886
  b= a2;
872
887
 
873
888
  if ((cmp_type= can_compare_as_dates(*a, *b, &const_value)))
874
889
  {
875
 
    session= current_session;
876
890
    owner= owner_arg;
877
891
    a_type= (*a)->field_type();
878
892
    b_type= (*b)->field_type();
879
893
    a_cache= 0;
880
894
    b_cache= 0;
881
895
 
882
 
    if (const_value != (uint64_t)-1)
 
896
    if (const_value != -1)
883
897
    {
884
898
      Item_cache_int *cache= new Item_cache_int();
885
899
      /* Mark the cache as non-const to prevent re-caching. */
900
914
    is_nulls_eq= test(owner && owner->functype() == Item_func::EQUAL_FUNC);
901
915
    func= &Arg_comparator::compare_datetime;
902
916
    get_value_func= &get_datetime_value;
 
917
 
903
918
    return 0;
904
919
  }
905
920
 
909
924
 
910
925
void Arg_comparator::set_datetime_cmp_func(Item **a1, Item **b1)
911
926
{
912
 
  session= current_session;
913
927
  /* A caller will handle null values by itself. */
914
928
  owner= NULL;
915
929
  a= a1;
953
967
    obtained value
954
968
*/
955
969
 
956
 
uint64_t
 
970
int64_t
957
971
get_datetime_value(Session *session, Item ***item_arg, Item **cache_arg,
958
972
                   Item *warn_item, bool *is_null)
959
973
{
960
 
  uint64_t value= 0;
 
974
  int64_t value= 0;
961
975
  String buf, *str= 0;
962
976
  Item *item= **item_arg;
963
977
 
981
995
    str= item->val_str(&buf);
982
996
    *is_null= item->null_value;
983
997
  }
 
998
 
984
999
  if (*is_null)
985
1000
    return ~(uint64_t) 0;
 
1001
 
986
1002
  /*
987
1003
    Convert strings to the integer DATE/DATETIME representation.
988
1004
    Even if both dates provided in strings we can't compare them directly as
993
1009
  {
994
1010
    bool error;
995
1011
    enum_field_types f_type= warn_item->field_type();
996
 
    enum enum_drizzle_timestamp_type t_type= f_type ==
997
 
      DRIZZLE_TYPE_DATE ? DRIZZLE_TIMESTAMP_DATE : DRIZZLE_TIMESTAMP_DATETIME;
 
1012
    type::timestamp_t t_type= f_type == DRIZZLE_TYPE_DATE ? type::DRIZZLE_TIMESTAMP_DATE : type::DRIZZLE_TIMESTAMP_DATETIME;
998
1013
    value= get_date_from_str(session, str, t_type, warn_item->name, &error);
999
1014
    /*
1000
1015
      If str did not contain a valid date according to the current
1017
1032
    *cache_arg= cache;
1018
1033
    *item_arg= cache_arg;
1019
1034
  }
 
1035
 
1020
1036
  return value;
1021
1037
}
1022
1038
 
1173
1189
 
1174
1190
int Arg_comparator::compare_decimal()
1175
1191
{
1176
 
  my_decimal value1;
1177
 
  my_decimal *val1= (*a)->val_decimal(&value1);
 
1192
  type::Decimal value1;
 
1193
  type::Decimal *val1= (*a)->val_decimal(&value1);
1178
1194
  if (!(*a)->null_value)
1179
1195
  {
1180
 
    my_decimal value2;
1181
 
    my_decimal *val2= (*b)->val_decimal(&value2);
 
1196
    type::Decimal value2;
 
1197
    type::Decimal *val2= (*b)->val_decimal(&value2);
1182
1198
    if (!(*b)->null_value)
1183
1199
    {
1184
1200
      owner->null_value= 0;
1185
 
      return my_decimal_cmp(val1, val2);
 
1201
      return class_decimal_cmp(val1, val2);
1186
1202
    }
1187
1203
  }
1188
1204
  owner->null_value= 1;
1200
1216
 
1201
1217
int Arg_comparator::compare_e_decimal()
1202
1218
{
1203
 
  my_decimal value1, value2;
1204
 
  my_decimal *val1= (*a)->val_decimal(&value1);
1205
 
  my_decimal *val2= (*b)->val_decimal(&value2);
 
1219
  type::Decimal value1, value2;
 
1220
  type::Decimal *val1= (*a)->val_decimal(&value1);
 
1221
  type::Decimal *val2= (*b)->val_decimal(&value2);
1206
1222
  if ((*a)->null_value || (*b)->null_value)
1207
1223
    return test((*a)->null_value && (*b)->null_value);
1208
 
  return test(my_decimal_cmp(val1, val2) == 0);
 
1224
  return test(class_decimal_cmp(val1, val2) == 0);
1209
1225
}
1210
1226
 
1211
1227
 
1615
1631
 
1616
1632
void Item_in_optimizer::cleanup()
1617
1633
{
1618
 
  Item_bool_func::cleanup();
 
1634
  item::function::Boolean::cleanup();
1619
1635
  if (!save_cache)
1620
1636
    cache= 0;
1621
1637
  return;
1668
1684
    change records at each execution.
1669
1685
  */
1670
1686
  if ((*args) != new_item)
1671
 
    current_session->change_item_tree(args, new_item);
 
1687
    getSession().change_item_tree(args, new_item);
1672
1688
 
1673
1689
  /*
1674
1690
    Transform the right IN operand which should be an Item_in_subselect or a
1823
1839
          {
1824
1840
            range->type= DECIMAL_RESULT;
1825
1841
            range->dec.init();
1826
 
            my_decimal *dec= el->val_decimal(&range->dec);
 
1842
            type::Decimal *dec= el->val_decimal(&range->dec);
1827
1843
            if (dec != &range->dec)
1828
1844
            {
1829
1845
              range->dec= *dec;
1873
1889
{
1874
1890
  assert(fixed == 1);
1875
1891
  double value;
1876
 
  my_decimal dec_buf, *dec= NULL;
 
1892
  type::Decimal dec_buf, *dec= NULL;
1877
1893
  uint32_t i;
1878
1894
 
1879
1895
  if (use_decimal_comparison)
1881
1897
    dec= row->element_index(0)->val_decimal(&dec_buf);
1882
1898
    if (row->element_index(0)->null_value)
1883
1899
      return -1;
1884
 
    my_decimal2double(E_DEC_FATAL_ERROR, dec, &value);
 
1900
    class_decimal2double(E_DEC_FATAL_ERROR, dec, &value);
1885
1901
  }
1886
1902
  else
1887
1903
  {
1906
1922
        and we are comparing against a decimal
1907
1923
      */
1908
1924
      if (dec && range->type == DECIMAL_RESULT)
1909
 
        cmp_result= my_decimal_cmp(&range->dec, dec) <= 0;
 
1925
        cmp_result= class_decimal_cmp(&range->dec, dec) <= 0;
1910
1926
      else
1911
1927
        cmp_result= (range->dbl <= value);
1912
1928
      if (cmp_result)
1916
1932
    }
1917
1933
    interval_range *range= intervals+start;
1918
1934
    return ((dec && range->type == DECIMAL_RESULT) ?
1919
 
            my_decimal_cmp(dec, &range->dec) < 0 :
 
1935
            class_decimal_cmp(dec, &range->dec) < 0 :
1920
1936
            value < range->dbl) ? 0 : start + 1;
1921
1937
  }
1922
1938
 
1927
1943
        ((el->result_type() == DECIMAL_RESULT) ||
1928
1944
         (el->result_type() == INT_RESULT)))
1929
1945
    {
1930
 
      my_decimal e_dec_buf, *e_dec= el->val_decimal(&e_dec_buf);
 
1946
      type::Decimal e_dec_buf, *e_dec= el->val_decimal(&e_dec_buf);
1931
1947
      /* Skip NULL ranges. */
1932
1948
      if (el->null_value)
1933
1949
        continue;
1934
 
      if (my_decimal_cmp(e_dec, dec) > 0)
 
1950
      if (class_decimal_cmp(e_dec, dec) > 0)
1935
1951
        return i - 1;
1936
1952
    }
1937
1953
    else
1981
1997
  if (Item_func_opt_neg::fix_fields(session, ref))
1982
1998
    return 1;
1983
1999
 
1984
 
  session->lex->current_select->between_count++;
 
2000
  session->getLex()->current_select->between_count++;
1985
2001
 
1986
2002
  /* not_null_tables_cache == union(T1(e),T1(e1),T1(e2)) */
1987
2003
  if (pred_level && !negated)
2002
2018
  int i;
2003
2019
  bool datetime_found= false;
2004
2020
  compare_as_dates= true;
2005
 
  Session *session= current_session;
2006
2021
 
2007
2022
  /*
2008
2023
    As some compare functions are generated after sql_yacc,
2049
2064
        The following can't be recoded with || as convert_constant_item
2050
2065
        changes the argument
2051
2066
      */
2052
 
      if (convert_constant_item(session, field_item, &args[1]))
 
2067
      if (convert_constant_item(&getSession(), field_item, &args[1]))
2053
2068
        cmp_type=INT_RESULT;                    // Works for all types.
2054
 
      if (convert_constant_item(session, field_item, &args[2]))
 
2069
      if (convert_constant_item(&getSession(), field_item, &args[2]))
2055
2070
        cmp_type=INT_RESULT;                    // Works for all types.
2056
2071
    }
2057
2072
  }
2128
2143
  }
2129
2144
  else if (cmp_type == DECIMAL_RESULT)
2130
2145
  {
2131
 
    my_decimal dec_buf, *dec= args[0]->val_decimal(&dec_buf),
 
2146
    type::Decimal dec_buf, *dec= args[0]->val_decimal(&dec_buf),
2132
2147
               a_buf, *a_dec, b_buf, *b_dec;
2133
2148
    if ((null_value=args[0]->null_value))
2134
2149
      return 0;
2135
2150
    a_dec= args[1]->val_decimal(&a_buf);
2136
2151
    b_dec= args[2]->val_decimal(&b_buf);
2137
2152
    if (!args[1]->null_value && !args[2]->null_value)
2138
 
      return (int64_t) ((my_decimal_cmp(dec, a_dec) >= 0 &&
2139
 
                          my_decimal_cmp(dec, b_dec) <= 0) != negated);
 
2153
      return (int64_t) ((class_decimal_cmp(dec, a_dec) >= 0 &&
 
2154
                          class_decimal_cmp(dec, b_dec) <= 0) != negated);
2140
2155
    if (args[1]->null_value && args[2]->null_value)
2141
2156
      null_value=1;
2142
2157
    else if (args[1]->null_value)
2143
 
      null_value= (my_decimal_cmp(dec, b_dec) <= 0);
 
2158
      null_value= (class_decimal_cmp(dec, b_dec) <= 0);
2144
2159
    else
2145
 
      null_value= (my_decimal_cmp(dec, a_dec) >= 0);
 
2160
      null_value= (class_decimal_cmp(dec, a_dec) >= 0);
2146
2161
  }
2147
2162
  else
2148
2163
  {
2276
2291
}
2277
2292
 
2278
2293
 
2279
 
my_decimal *Item_func_ifnull::decimal_op(my_decimal *decimal_value)
 
2294
type::Decimal *Item_func_ifnull::decimal_op(type::Decimal *decimal_value)
2280
2295
{
2281
2296
  assert(fixed == 1);
2282
 
  my_decimal *value= args[0]->val_decimal(decimal_value);
 
2297
  type::Decimal *value= args[0]->val_decimal(decimal_value);
2283
2298
  if (!args[0]->null_value)
2284
2299
  {
2285
2300
    null_value= 0;
2449
2464
}
2450
2465
 
2451
2466
 
2452
 
my_decimal *
2453
 
Item_func_if::val_decimal(my_decimal *decimal_value)
 
2467
type::Decimal *
 
2468
Item_func_if::val_decimal(type::Decimal *decimal_value)
2454
2469
{
2455
2470
  assert(fixed == 1);
2456
2471
  Item *arg= args[0]->val_bool() ? args[1] : args[2];
2457
 
  my_decimal *value= arg->val_decimal(decimal_value);
 
2472
  type::Decimal *value= arg->val_decimal(decimal_value);
2458
2473
  null_value= arg->null_value;
2459
2474
  return value;
2460
2475
}
2534
2549
}
2535
2550
 
2536
2551
 
2537
 
my_decimal *
2538
 
Item_func_nullif::val_decimal(my_decimal * decimal_value)
 
2552
type::Decimal *
 
2553
Item_func_nullif::val_decimal(type::Decimal * decimal_value)
2539
2554
{
2540
2555
  assert(fixed == 1);
2541
 
  my_decimal *res;
 
2556
  type::Decimal *res;
2542
2557
  if (!cmp.compare())
2543
2558
  {
2544
2559
    null_value=1;
2671
2686
}
2672
2687
 
2673
2688
 
2674
 
my_decimal *Item_func_case::val_decimal(my_decimal *decimal_value)
 
2689
type::Decimal *Item_func_case::val_decimal(type::Decimal *decimal_value)
2675
2690
{
2676
2691
  assert(fixed == 1);
2677
2692
  char buff[MAX_FIELD_WIDTH];
2678
2693
  String dummy_str(buff, sizeof(buff), default_charset());
2679
2694
  Item *item= find_item(&dummy_str);
2680
 
  my_decimal *res;
 
2695
  type::Decimal *res;
2681
2696
 
2682
2697
  if (!item)
2683
2698
  {
2720
2735
 
2721
2736
void Item_func_case::agg_num_lengths(Item *arg)
2722
2737
{
2723
 
  uint32_t len= my_decimal_length_to_precision(arg->max_length, arg->decimals,
 
2738
  uint32_t len= class_decimal_length_to_precision(arg->max_length, arg->decimals,
2724
2739
                                           arg->unsigned_flag) - arg->decimals;
2725
2740
  set_if_bigger(max_length, len);
2726
2741
  set_if_bigger(decimals, arg->decimals);
2803
2818
      agg_num_lengths(args[i + 1]);
2804
2819
    if (else_expr_num != -1)
2805
2820
      agg_num_lengths(args[else_expr_num]);
2806
 
    max_length= my_decimal_precision_to_length(max_length + decimals, decimals,
 
2821
    max_length= class_decimal_precision_to_length(max_length + decimals, decimals,
2807
2822
                                               unsigned_flag);
2808
2823
  }
2809
2824
}
2910
2925
}
2911
2926
 
2912
2927
 
2913
 
my_decimal *Item_func_coalesce::decimal_op(my_decimal *decimal_value)
 
2928
type::Decimal *Item_func_coalesce::decimal_op(type::Decimal *decimal_value)
2914
2929
{
2915
2930
  assert(fixed == 1);
2916
2931
  null_value= 0;
2917
2932
  for (uint32_t i= 0; i < arg_count; i++)
2918
2933
  {
2919
 
    my_decimal *res= args[i]->val_decimal(decimal_value);
 
2934
    type::Decimal *res= args[i]->val_decimal(decimal_value);
2920
2935
    if (!args[i]->null_value)
2921
2936
      return res;
2922
2937
  }
3065
3080
}
3066
3081
 
3067
3082
 
3068
 
static int cmp_decimal(void *, my_decimal *a, my_decimal *b)
 
3083
static int cmp_decimal(void *, type::Decimal *a, type::Decimal *b)
3069
3084
{
3070
3085
  /*
3071
3086
    We need call of fixing buffer pointer, because fast sort just copy
3073
3088
  */
3074
3089
  a->fix_buffer_pointer();
3075
3090
  b->fix_buffer_pointer();
3076
 
  return my_decimal_cmp(a, b);
 
3091
  return class_decimal_cmp(a, b);
3077
3092
}
3078
3093
 
3079
3094
 
3181
3196
  return;
3182
3197
}
3183
3198
 
3184
 
in_int64_t::in_int64_t(uint32_t elements)
3185
 
  :in_vector(elements,sizeof(packed_int64_t),(qsort2_cmp) cmp_int64_t, 0)
 
3199
in_int64_t::in_int64_t(uint32_t elements) :
 
3200
  in_vector(elements, sizeof(packed_int64_t),(qsort2_cmp) cmp_int64_t, 0)
3186
3201
{}
3187
3202
 
3188
3203
void in_int64_t::set(uint32_t pos,Item *item)
3202
3217
  return (unsigned char*) &tmp;
3203
3218
}
3204
3219
 
3205
 
void in_datetime::set(uint32_t pos,Item *item)
 
3220
in_datetime::in_datetime(Item *warn_item_arg, uint32_t elements) :
 
3221
  in_int64_t(elements),
 
3222
  session(current_session),
 
3223
  warn_item(warn_item_arg),
 
3224
  lval_cache(0)
 
3225
{}
 
3226
 
 
3227
void in_datetime::set(uint32_t pos, Item *item)
3206
3228
{
3207
3229
  Item **tmp_item= &item;
3208
3230
  bool is_null;
3242
3264
 
3243
3265
 
3244
3266
in_decimal::in_decimal(uint32_t elements)
3245
 
  :in_vector(elements, sizeof(my_decimal),(qsort2_cmp) cmp_decimal, 0)
 
3267
  :in_vector(elements, sizeof(type::Decimal),(qsort2_cmp) cmp_decimal, 0)
3246
3268
{}
3247
3269
 
3248
3270
 
3249
3271
void in_decimal::set(uint32_t pos, Item *item)
3250
3272
{
3251
 
  /* as far as 'item' is constant, we can store reference on my_decimal */
3252
 
  my_decimal *dec= ((my_decimal *)base) + pos;
 
3273
  /* as far as 'item' is constant, we can store reference on type::Decimal */
 
3274
  type::Decimal *dec= ((type::Decimal *)base) + pos;
3253
3275
  dec->len= DECIMAL_BUFF_LENGTH;
3254
3276
  dec->fix_buffer_pointer();
3255
 
  my_decimal *res= item->val_decimal(dec);
 
3277
  type::Decimal *res= item->val_decimal(dec);
3256
3278
  /* if item->val_decimal() is evaluated to NULL then res == 0 */
3257
3279
  if (!item->null_value && res != dec)
3258
 
    my_decimal2decimal(res, dec);
 
3280
    class_decimal2decimal(res, dec);
3259
3281
}
3260
3282
 
3261
3283
 
3262
3284
unsigned char *in_decimal::get_value(Item *item)
3263
3285
{
3264
 
  my_decimal *result= item->val_decimal(&val);
 
3286
  type::Decimal *result= item->val_decimal(&val);
3265
3287
  if (item->null_value)
3266
3288
    return 0;
3267
3289
  return (unsigned char *)result;
3420
3442
 
3421
3443
void cmp_item_decimal::store_value(Item *item)
3422
3444
{
3423
 
  my_decimal *val= item->val_decimal(&value);
 
3445
  type::Decimal *val= item->val_decimal(&value);
3424
3446
  /* val may be zero if item is nnull */
3425
3447
  if (val && val != &value)
3426
 
    my_decimal2decimal(val, &value);
 
3448
    class_decimal2decimal(val, &value);
3427
3449
}
3428
3450
 
3429
3451
 
3430
3452
int cmp_item_decimal::cmp(Item *arg)
3431
3453
{
3432
 
  my_decimal tmp_buf, *tmp= arg->val_decimal(&tmp_buf);
 
3454
  type::Decimal tmp_buf, *tmp= arg->val_decimal(&tmp_buf);
3433
3455
  if (arg->null_value)
3434
3456
    return 1;
3435
 
  return my_decimal_cmp(&value, tmp);
 
3457
  return class_decimal_cmp(&value, tmp);
3436
3458
}
3437
3459
 
3438
3460
 
3439
3461
int cmp_item_decimal::compare(cmp_item *arg)
3440
3462
{
3441
3463
  cmp_item_decimal *l_cmp= (cmp_item_decimal*) arg;
3442
 
  return my_decimal_cmp(&value, &l_cmp->value);
 
3464
  return class_decimal_cmp(&value, &l_cmp->value);
3443
3465
}
3444
3466
 
3445
3467
 
3552
3574
{
3553
3575
  Item **arg, **arg_end;
3554
3576
  bool const_itm= 1;
3555
 
  Session *session= current_session;
3556
3577
  bool datetime_found= false;
3557
3578
  /* true <=> arguments values will be compared as DATETIMEs. */
3558
3579
  bool compare_as_datetime= false;
3700
3721
          bool all_converted= true;
3701
3722
          for (arg=args+1, arg_end=args+arg_count; arg != arg_end ; arg++)
3702
3723
          {
3703
 
            if (!convert_constant_item (session, field_item, &arg[0]))
 
3724
            if (!convert_constant_item (&getSession(), field_item, &arg[0]))
3704
3725
              all_converted= false;
3705
3726
          }
3706
3727
          if (all_converted)
3737
3758
      }
3738
3759
    }
3739
3760
 
3740
 
    if (array && !(session->is_fatal_error))            // If not EOM
 
3761
    if (array && !(getSession().is_fatal_error))                // If not EOM
3741
3762
    {
3742
3763
      uint32_t j=0;
3743
3764
      for (uint32_t arg_num=1 ; arg_num < arg_count ; arg_num++)
3853
3874
 
3854
3875
 
3855
3876
Item_cond::Item_cond(Session *session, Item_cond *item)
3856
 
  :Item_bool_func(session, item),
 
3877
  :item::function::Boolean(session, item),
3857
3878
   abort_on_null(item->abort_on_null),
3858
3879
   and_tables_cache(item->and_tables_cache)
3859
3880
{
3865
3886
 
3866
3887
void Item_cond::copy_andor_arguments(Session *session, Item_cond *item)
3867
3888
{
3868
 
  List_iterator_fast<Item> li(item->list);
 
3889
  List<Item>::iterator li(item->list.begin());
3869
3890
  while (Item *it= li++)
3870
3891
    list.push_back(it->copy_andor_structure(session));
3871
3892
}
3875
3896
Item_cond::fix_fields(Session *session, Item **)
3876
3897
{
3877
3898
  assert(fixed == 0);
3878
 
  List_iterator<Item> li(list);
 
3899
  List<Item>::iterator li(list.begin());
3879
3900
  Item *item;
3880
3901
  void *orig_session_marker= session->session_marker;
3881
3902
  unsigned char buff[sizeof(char*)];                    // Max local vars in function
3882
3903
  not_null_tables_cache= used_tables_cache= 0;
3883
 
  const_item_cache= 1;
 
3904
  const_item_cache= true;
3884
3905
 
3885
3906
  if (functype() == COND_OR_FUNC)
3886
3907
    session->session_marker= 0;
3915
3936
           !((Item_cond*) item)->list.is_empty())
3916
3937
    {                                           // Identical function
3917
3938
      li.replace(((Item_cond*) item)->list);
3918
 
      ((Item_cond*) item)->list.empty();
 
3939
      ((Item_cond*) item)->list.clear();
3919
3940
      item= *li.ref();                          // new current item
3920
3941
    }
3921
3942
    if (abort_on_null)
3941
3962
    if (item->maybe_null)
3942
3963
      maybe_null=1;
3943
3964
  }
3944
 
  session->lex->current_select->cond_count+= list.elements;
 
3965
  session->getLex()->current_select->cond_count+= list.elements;
3945
3966
  session->session_marker= orig_session_marker;
3946
3967
  fix_length_and_dec();
3947
3968
  fixed= 1;
3951
3972
 
3952
3973
void Item_cond::fix_after_pullout(Select_Lex *new_parent, Item **)
3953
3974
{
3954
 
  List_iterator<Item> li(list);
 
3975
  List<Item>::iterator li(list.begin());
3955
3976
  Item *item;
3956
3977
 
3957
3978
  used_tables_cache=0;
3958
 
  const_item_cache=1;
 
3979
  const_item_cache= true;
3959
3980
 
3960
3981
  and_tables_cache= ~(table_map) 0; // Here and below we do as fix_fields does
3961
3982
  not_null_tables_cache= 0;
3983
4004
 
3984
4005
bool Item_cond::walk(Item_processor processor, bool walk_subquery, unsigned char *arg)
3985
4006
{
3986
 
  List_iterator_fast<Item> li(list);
 
4007
  List<Item>::iterator li(list.begin());
3987
4008
  Item *item;
3988
4009
  while ((item= li++))
3989
4010
    if (item->walk(processor, walk_subquery, arg))
4012
4033
 
4013
4034
Item *Item_cond::transform(Item_transformer transformer, unsigned char *arg)
4014
4035
{
4015
 
  List_iterator<Item> li(list);
 
4036
  List<Item>::iterator li(list.begin());
4016
4037
  Item *item;
4017
4038
  while ((item= li++))
4018
4039
  {
4027
4048
      change records at each execution.
4028
4049
    */
4029
4050
    if (new_item != item)
4030
 
      current_session->change_item_tree(li.ref(), new_item);
 
4051
      getSession().change_item_tree(li.ref(), new_item);
4031
4052
  }
4032
4053
  return Item_func::transform(transformer, arg);
4033
4054
}
4063
4084
  if (!(this->*analyzer)(arg_p))
4064
4085
    return 0;
4065
4086
 
4066
 
  List_iterator<Item> li(list);
 
4087
  List<Item>::iterator li(list.begin());
4067
4088
  Item *item;
4068
4089
  while ((item= li++))
4069
4090
  {
4082
4103
void Item_cond::traverse_cond(Cond_traverser traverser,
4083
4104
                              void *arg, traverse_order order)
4084
4105
{
4085
 
  List_iterator<Item> li(list);
 
4106
  List<Item>::iterator li(list.begin());
4086
4107
  Item *item;
4087
4108
 
4088
4109
  switch (order) {
4123
4144
void Item_cond::split_sum_func(Session *session, Item **ref_pointer_array,
4124
4145
                               List<Item> &fields)
4125
4146
{
4126
 
  List_iterator<Item> li(list);
 
4147
  List<Item>::iterator li(list.begin());
4127
4148
  Item *item;
4128
4149
  while ((item= li++))
4129
4150
    item->split_sum_func(session, ref_pointer_array,
4140
4161
 
4141
4162
void Item_cond::update_used_tables()
4142
4163
{
4143
 
  List_iterator_fast<Item> li(list);
 
4164
  List<Item>::iterator li(list.begin());
4144
4165
  Item *item;
4145
4166
 
4146
4167
  used_tables_cache=0;
4147
 
  const_item_cache=1;
 
4168
  const_item_cache= true;
4148
4169
  while ((item=li++))
4149
4170
  {
4150
4171
    item->update_used_tables();
4157
4178
void Item_cond::print(String *str, enum_query_type query_type)
4158
4179
{
4159
4180
  str->append('(');
4160
 
  List_iterator_fast<Item> li(list);
 
4181
  List<Item>::iterator li(list.begin());
4161
4182
  Item *item;
4162
4183
  if ((item=li++))
4163
4184
    item->print(str, query_type);
4174
4195
 
4175
4196
void Item_cond::neg_arguments(Session *session)
4176
4197
{
4177
 
  List_iterator<Item> li(list);
 
4198
  List<Item>::iterator li(list.begin());
4178
4199
  Item *item;
4179
4200
  while ((item= li++))          /* Apply not transformation to the arguments */
4180
4201
  {
4212
4233
int64_t Item_cond_and::val_int()
4213
4234
{
4214
4235
  assert(fixed == 1);
4215
 
  List_iterator_fast<Item> li(list);
 
4236
  List<Item>::iterator li(list.begin());
4216
4237
  Item *item;
4217
4238
  null_value= 0;
4218
4239
  while ((item=li++))
4230
4251
int64_t Item_cond_or::val_int()
4231
4252
{
4232
4253
  assert(fixed == 1);
4233
 
  List_iterator_fast<Item> li(list);
 
4254
  List<Item>::iterator li(list.begin());
4234
4255
  Item *item;
4235
4256
  null_value=0;
4236
4257
  while ((item=li++))
4467
4488
      {
4468
4489
        pattern     = first + 1;
4469
4490
        pattern_len = (int) len - 2;
4470
 
        int *suff = (int*) session->alloc((int) (sizeof(int)*
4471
 
                                      ((pattern_len + 1)*2+
4472
 
                                      alphabet_size)));
 
4491
        int *suff = (int*) session->getMemRoot()->allocate((int) (sizeof(int)*
 
4492
                                                                  ((pattern_len + 1)*2+
 
4493
                                                                   alphabet_size)));
4473
4494
        bmGs      = suff + pattern_len + 1;
4474
4495
        bmBc      = bmGs + pattern_len + 1;
4475
4496
        turboBM_compute_good_suffix_shifts(suff);
4486
4507
  Item_bool_func2::cleanup();
4487
4508
}
4488
4509
 
 
4510
static unsigned char likeconv(const CHARSET_INFO *cs, unsigned char a)
 
4511
{
4489
4512
#ifdef LIKE_CMP_TOUPPER
4490
 
#define likeconv(cs,A) (unsigned char) (cs)->toupper(A)
 
4513
  return cs->toupper(a);
4491
4514
#else
4492
 
#define likeconv(cs,A) (unsigned char) (cs)->sort_order[(unsigned char) (A)]
 
4515
  return cs->sort_order[a];
4493
4516
#endif
4494
 
 
 
4517
}
4495
4518
 
4496
4519
/**
4497
4520
  Precomputation dependent only on pattern_len.
4628
4651
 
4629
4652
bool Item_func_like::turboBM_matches(const char* text, int text_len) const
4630
4653
{
4631
 
  register int bcShift;
4632
 
  register int turboShift;
 
4654
  int bcShift;
 
4655
  int turboShift;
4633
4656
  int shift = pattern_len;
4634
4657
  int j     = 0;
4635
4658
  int u     = 0;
4643
4666
  {
4644
4667
    while (j <= tlmpl)
4645
4668
    {
4646
 
      register int i= plm1;
 
4669
      int i= plm1;
4647
4670
      while (i >= 0 && pattern[i] == text[i + j])
4648
4671
      {
4649
4672
        i--;
4653
4676
      if (i < 0)
4654
4677
        return 1;
4655
4678
 
4656
 
      register const int v = plm1 - i;
 
4679
      const int v = plm1 - i;
4657
4680
      turboShift = u - v;
4658
4681
      bcShift    = bmBc[(uint32_t) (unsigned char) text[i + j]] - plm1 + i;
4659
4682
      shift      = (turboShift > bcShift) ? turboShift : bcShift;
4674
4697
  {
4675
4698
    while (j <= tlmpl)
4676
4699
    {
4677
 
      register int i = plm1;
 
4700
      int i = plm1;
4678
4701
      while (i >= 0 && likeconv(cs,pattern[i]) == likeconv(cs,text[i + j]))
4679
4702
      {
4680
4703
        i--;
4685
4708
      if (i < 0)
4686
4709
        return 1;
4687
4710
 
4688
 
      register const int v= plm1 - i;
 
4711
      const int v= plm1 - i;
4689
4712
      turboShift= u - v;
4690
4713
      bcShift= bmBc[(uint32_t) likeconv(cs, text[i + j])] - plm1 + i;
4691
4714
      shift= (turboShift > bcShift) ? turboShift : bcShift;
4726
4749
int64_t Item_cond_xor::val_int()
4727
4750
{
4728
4751
  assert(fixed == 1);
4729
 
  List_iterator<Item> li(list);
 
4752
  List<Item>::iterator li(list.begin());
4730
4753
  Item *item;
4731
4754
  int result=0;
4732
4755
  null_value=0;
4886
4909
}
4887
4910
 
4888
4911
Item_equal::Item_equal(Item_field *f1, Item_field *f2)
4889
 
  : Item_bool_func(), const_item(0), eval_item(0), cond_false(0)
 
4912
  : item::function::Boolean(), const_item(0), eval_item(0), cond_false(0)
4890
4913
{
4891
 
  const_item_cache= 0;
 
4914
  const_item_cache= false;
4892
4915
  fields.push_back(f1);
4893
4916
  fields.push_back(f2);
4894
4917
}
4895
4918
 
4896
4919
Item_equal::Item_equal(Item *c, Item_field *f)
4897
 
  : Item_bool_func(), eval_item(0), cond_false(0)
 
4920
  : item::function::Boolean(), eval_item(0), cond_false(0)
4898
4921
{
4899
 
  const_item_cache= 0;
 
4922
  const_item_cache= false;
4900
4923
  fields.push_back(f);
4901
4924
  const_item= c;
4902
4925
}
4903
4926
 
4904
4927
 
4905
4928
Item_equal::Item_equal(Item_equal *item_equal)
4906
 
  : Item_bool_func(), eval_item(0), cond_false(0)
 
4929
  : item::function::Boolean(), eval_item(0), cond_false(0)
4907
4930
{
4908
 
  const_item_cache= 0;
4909
 
  List_iterator_fast<Item_field> li(item_equal->fields);
 
4931
  const_item_cache= false;
 
4932
  List<Item_field>::iterator li(item_equal->fields.begin());
4910
4933
  Item_field *item;
4911
4934
  while ((item= li++))
4912
4935
  {
4929
4952
  func->set_cmp_func();
4930
4953
  func->quick_fix_field();
4931
4954
  if ((cond_false= !func->val_int()))
4932
 
    const_item_cache= 1;
 
4955
    const_item_cache= true;
4933
4956
}
4934
4957
 
4935
4958
void Item_equal::add(Item_field *f)
4958
4981
 
4959
4982
bool Item_equal::contains(Field *field)
4960
4983
{
4961
 
  List_iterator_fast<Item_field> it(fields);
 
4984
  List<Item_field>::iterator it(fields.begin());
4962
4985
  Item_field *item;
4963
4986
  while ((item= it++))
4964
4987
  {
5017
5040
void Item_equal::sort(Item_field_cmpfunc cmp, void *arg)
5018
5041
{
5019
5042
  bool swap;
5020
 
  List_iterator<Item_field> it(fields);
 
5043
  List<Item_field>::iterator it(fields.begin());
5021
5044
  do
5022
5045
  {
5023
5046
    Item_field *item1= it++;
5041
5064
        ref1= ref2;
5042
5065
      }
5043
5066
    }
5044
 
    it.rewind();
 
5067
    it= fields.begin();
5045
5068
  } while (swap);
5046
5069
}
5047
5070
 
5058
5081
 
5059
5082
void Item_equal::update_const()
5060
5083
{
5061
 
  List_iterator<Item_field> it(fields);
 
5084
  List<Item_field>::iterator it(fields.begin());
5062
5085
  Item *item;
5063
5086
  while ((item= it++))
5064
5087
  {
5072
5095
 
5073
5096
bool Item_equal::fix_fields(Session *, Item **)
5074
5097
{
5075
 
  List_iterator_fast<Item_field> li(fields);
 
5098
  List<Item_field>::iterator li(fields.begin());
5076
5099
  Item *item;
5077
5100
  not_null_tables_cache= used_tables_cache= 0;
5078
 
  const_item_cache= 0;
 
5101
  const_item_cache= false;
5079
5102
  while ((item= li++))
5080
5103
  {
5081
5104
    table_map tmp_table_map;
5092
5115
 
5093
5116
void Item_equal::update_used_tables()
5094
5117
{
5095
 
  List_iterator_fast<Item_field> li(fields);
 
5118
  List<Item_field>::iterator li(fields.begin());
5096
5119
  Item *item;
5097
5120
  not_null_tables_cache= used_tables_cache= 0;
5098
5121
  if ((const_item_cache= cond_false))
5110
5133
  Item_field *item_field;
5111
5134
  if (cond_false)
5112
5135
    return 0;
5113
 
  List_iterator_fast<Item_field> it(fields);
 
5136
  List<Item_field>::iterator it(fields.begin());
5114
5137
  Item *item= const_item ? const_item : it++;
 
5138
  eval_item->store_value(item);
5115
5139
  if ((null_value= item->null_value))
5116
5140
    return 0;
5117
 
  eval_item->store_value(item);
5118
5141
  while ((item_field= it++))
5119
5142
  {
5120
5143
    /* Skip fields of non-const tables. They haven't been read yet */
5121
5144
    if (item_field->field->getTable()->const_table)
5122
5145
    {
5123
 
      if ((null_value= item_field->null_value) || eval_item->cmp(item_field))
 
5146
      if (eval_item->cmp(item_field) || (null_value= item_field->null_value))
5124
5147
        return 0;
5125
5148
    }
5126
5149
  }
5136
5159
 
5137
5160
bool Item_equal::walk(Item_processor processor, bool walk_subquery, unsigned char *arg)
5138
5161
{
5139
 
  List_iterator_fast<Item_field> it(fields);
 
5162
  List<Item_field>::iterator it(fields.begin());
5140
5163
  Item *item;
5141
5164
  while ((item= it++))
5142
5165
  {
5148
5171
 
5149
5172
Item *Item_equal::transform(Item_transformer transformer, unsigned char *arg)
5150
5173
{
5151
 
  List_iterator<Item_field> it(fields);
 
5174
  List<Item_field>::iterator it(fields.begin());
5152
5175
  Item *item;
5153
5176
  while ((item= it++))
5154
5177
  {
5163
5186
      change records at each execution.
5164
5187
    */
5165
5188
    if (new_item != item)
5166
 
      current_session->change_item_tree((Item **) it.ref(), new_item);
 
5189
      getSession().change_item_tree((Item **) it.ref(), new_item);
5167
5190
  }
5168
5191
  return Item_func::transform(transformer, arg);
5169
5192
}
5172
5195
{
5173
5196
  str->append(func_name());
5174
5197
  str->append('(');
5175
 
  List_iterator_fast<Item_field> it(fields);
 
5198
  List<Item_field>::iterator it(fields.begin());
5176
5199
  Item *item;
5177
5200
  if (const_item)
5178
5201
    const_item->print(str, query_type);
5190
5213
  str->append(')');
5191
5214
}
5192
5215
 
 
5216
cmp_item_datetime::cmp_item_datetime(Item *warn_item_arg) :
 
5217
  session(current_session),
 
5218
  warn_item(warn_item_arg),
 
5219
  lval_cache(0)
 
5220
{}
 
5221
 
5193
5222
} /* namespace drizzled */