~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
 
567
572
  set_cmp_func();
568
573
}
569
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
{}
570
588
 
571
589
int Arg_comparator::set_compare_func(Item_bool_func2 *item, Item_result type)
572
590
{
1979
1997
  if (Item_func_opt_neg::fix_fields(session, ref))
1980
1998
    return 1;
1981
1999
 
1982
 
  session->lex->current_select->between_count++;
 
2000
  session->getLex()->current_select->between_count++;
1983
2001
 
1984
2002
  /* not_null_tables_cache == union(T1(e),T1(e1),T1(e2)) */
1985
2003
  if (pred_level && !negated)
3199
3217
  return (unsigned char*) &tmp;
3200
3218
}
3201
3219
 
 
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
 
3202
3227
void in_datetime::set(uint32_t pos, Item *item)
3203
3228
{
3204
3229
  Item **tmp_item= &item;
3861
3886
 
3862
3887
void Item_cond::copy_andor_arguments(Session *session, Item_cond *item)
3863
3888
{
3864
 
  List_iterator_fast<Item> li(item->list);
 
3889
  List<Item>::iterator li(item->list.begin());
3865
3890
  while (Item *it= li++)
3866
3891
    list.push_back(it->copy_andor_structure(session));
3867
3892
}
3871
3896
Item_cond::fix_fields(Session *session, Item **)
3872
3897
{
3873
3898
  assert(fixed == 0);
3874
 
  List_iterator<Item> li(list);
 
3899
  List<Item>::iterator li(list.begin());
3875
3900
  Item *item;
3876
3901
  void *orig_session_marker= session->session_marker;
3877
3902
  unsigned char buff[sizeof(char*)];                    // Max local vars in function
3911
3936
           !((Item_cond*) item)->list.is_empty())
3912
3937
    {                                           // Identical function
3913
3938
      li.replace(((Item_cond*) item)->list);
3914
 
      ((Item_cond*) item)->list.empty();
 
3939
      ((Item_cond*) item)->list.clear();
3915
3940
      item= *li.ref();                          // new current item
3916
3941
    }
3917
3942
    if (abort_on_null)
3937
3962
    if (item->maybe_null)
3938
3963
      maybe_null=1;
3939
3964
  }
3940
 
  session->lex->current_select->cond_count+= list.elements;
 
3965
  session->getLex()->current_select->cond_count+= list.elements;
3941
3966
  session->session_marker= orig_session_marker;
3942
3967
  fix_length_and_dec();
3943
3968
  fixed= 1;
3947
3972
 
3948
3973
void Item_cond::fix_after_pullout(Select_Lex *new_parent, Item **)
3949
3974
{
3950
 
  List_iterator<Item> li(list);
 
3975
  List<Item>::iterator li(list.begin());
3951
3976
  Item *item;
3952
3977
 
3953
3978
  used_tables_cache=0;
3979
4004
 
3980
4005
bool Item_cond::walk(Item_processor processor, bool walk_subquery, unsigned char *arg)
3981
4006
{
3982
 
  List_iterator_fast<Item> li(list);
 
4007
  List<Item>::iterator li(list.begin());
3983
4008
  Item *item;
3984
4009
  while ((item= li++))
3985
4010
    if (item->walk(processor, walk_subquery, arg))
4008
4033
 
4009
4034
Item *Item_cond::transform(Item_transformer transformer, unsigned char *arg)
4010
4035
{
4011
 
  List_iterator<Item> li(list);
 
4036
  List<Item>::iterator li(list.begin());
4012
4037
  Item *item;
4013
4038
  while ((item= li++))
4014
4039
  {
4059
4084
  if (!(this->*analyzer)(arg_p))
4060
4085
    return 0;
4061
4086
 
4062
 
  List_iterator<Item> li(list);
 
4087
  List<Item>::iterator li(list.begin());
4063
4088
  Item *item;
4064
4089
  while ((item= li++))
4065
4090
  {
4078
4103
void Item_cond::traverse_cond(Cond_traverser traverser,
4079
4104
                              void *arg, traverse_order order)
4080
4105
{
4081
 
  List_iterator<Item> li(list);
 
4106
  List<Item>::iterator li(list.begin());
4082
4107
  Item *item;
4083
4108
 
4084
4109
  switch (order) {
4119
4144
void Item_cond::split_sum_func(Session *session, Item **ref_pointer_array,
4120
4145
                               List<Item> &fields)
4121
4146
{
4122
 
  List_iterator<Item> li(list);
 
4147
  List<Item>::iterator li(list.begin());
4123
4148
  Item *item;
4124
4149
  while ((item= li++))
4125
4150
    item->split_sum_func(session, ref_pointer_array,
4136
4161
 
4137
4162
void Item_cond::update_used_tables()
4138
4163
{
4139
 
  List_iterator_fast<Item> li(list);
 
4164
  List<Item>::iterator li(list.begin());
4140
4165
  Item *item;
4141
4166
 
4142
4167
  used_tables_cache=0;
4153
4178
void Item_cond::print(String *str, enum_query_type query_type)
4154
4179
{
4155
4180
  str->append('(');
4156
 
  List_iterator_fast<Item> li(list);
 
4181
  List<Item>::iterator li(list.begin());
4157
4182
  Item *item;
4158
4183
  if ((item=li++))
4159
4184
    item->print(str, query_type);
4170
4195
 
4171
4196
void Item_cond::neg_arguments(Session *session)
4172
4197
{
4173
 
  List_iterator<Item> li(list);
 
4198
  List<Item>::iterator li(list.begin());
4174
4199
  Item *item;
4175
4200
  while ((item= li++))          /* Apply not transformation to the arguments */
4176
4201
  {
4208
4233
int64_t Item_cond_and::val_int()
4209
4234
{
4210
4235
  assert(fixed == 1);
4211
 
  List_iterator_fast<Item> li(list);
 
4236
  List<Item>::iterator li(list.begin());
4212
4237
  Item *item;
4213
4238
  null_value= 0;
4214
4239
  while ((item=li++))
4226
4251
int64_t Item_cond_or::val_int()
4227
4252
{
4228
4253
  assert(fixed == 1);
4229
 
  List_iterator_fast<Item> li(list);
 
4254
  List<Item>::iterator li(list.begin());
4230
4255
  Item *item;
4231
4256
  null_value=0;
4232
4257
  while ((item=li++))
4626
4651
 
4627
4652
bool Item_func_like::turboBM_matches(const char* text, int text_len) const
4628
4653
{
4629
 
  register int bcShift;
4630
 
  register int turboShift;
 
4654
  int bcShift;
 
4655
  int turboShift;
4631
4656
  int shift = pattern_len;
4632
4657
  int j     = 0;
4633
4658
  int u     = 0;
4641
4666
  {
4642
4667
    while (j <= tlmpl)
4643
4668
    {
4644
 
      register int i= plm1;
 
4669
      int i= plm1;
4645
4670
      while (i >= 0 && pattern[i] == text[i + j])
4646
4671
      {
4647
4672
        i--;
4651
4676
      if (i < 0)
4652
4677
        return 1;
4653
4678
 
4654
 
      register const int v = plm1 - i;
 
4679
      const int v = plm1 - i;
4655
4680
      turboShift = u - v;
4656
4681
      bcShift    = bmBc[(uint32_t) (unsigned char) text[i + j]] - plm1 + i;
4657
4682
      shift      = (turboShift > bcShift) ? turboShift : bcShift;
4672
4697
  {
4673
4698
    while (j <= tlmpl)
4674
4699
    {
4675
 
      register int i = plm1;
 
4700
      int i = plm1;
4676
4701
      while (i >= 0 && likeconv(cs,pattern[i]) == likeconv(cs,text[i + j]))
4677
4702
      {
4678
4703
        i--;
4683
4708
      if (i < 0)
4684
4709
        return 1;
4685
4710
 
4686
 
      register const int v= plm1 - i;
 
4711
      const int v= plm1 - i;
4687
4712
      turboShift= u - v;
4688
4713
      bcShift= bmBc[(uint32_t) likeconv(cs, text[i + j])] - plm1 + i;
4689
4714
      shift= (turboShift > bcShift) ? turboShift : bcShift;
4724
4749
int64_t Item_cond_xor::val_int()
4725
4750
{
4726
4751
  assert(fixed == 1);
4727
 
  List_iterator<Item> li(list);
 
4752
  List<Item>::iterator li(list.begin());
4728
4753
  Item *item;
4729
4754
  int result=0;
4730
4755
  null_value=0;
4904
4929
  : item::function::Boolean(), eval_item(0), cond_false(0)
4905
4930
{
4906
4931
  const_item_cache= false;
4907
 
  List_iterator_fast<Item_field> li(item_equal->fields);
 
4932
  List<Item_field>::iterator li(item_equal->fields.begin());
4908
4933
  Item_field *item;
4909
4934
  while ((item= li++))
4910
4935
  {
4956
4981
 
4957
4982
bool Item_equal::contains(Field *field)
4958
4983
{
4959
 
  List_iterator_fast<Item_field> it(fields);
 
4984
  List<Item_field>::iterator it(fields.begin());
4960
4985
  Item_field *item;
4961
4986
  while ((item= it++))
4962
4987
  {
5015
5040
void Item_equal::sort(Item_field_cmpfunc cmp, void *arg)
5016
5041
{
5017
5042
  bool swap;
5018
 
  List_iterator<Item_field> it(fields);
 
5043
  List<Item_field>::iterator it(fields.begin());
5019
5044
  do
5020
5045
  {
5021
5046
    Item_field *item1= it++;
5039
5064
        ref1= ref2;
5040
5065
      }
5041
5066
    }
5042
 
    it.rewind();
 
5067
    it= fields.begin();
5043
5068
  } while (swap);
5044
5069
}
5045
5070
 
5056
5081
 
5057
5082
void Item_equal::update_const()
5058
5083
{
5059
 
  List_iterator<Item_field> it(fields);
 
5084
  List<Item_field>::iterator it(fields.begin());
5060
5085
  Item *item;
5061
5086
  while ((item= it++))
5062
5087
  {
5070
5095
 
5071
5096
bool Item_equal::fix_fields(Session *, Item **)
5072
5097
{
5073
 
  List_iterator_fast<Item_field> li(fields);
 
5098
  List<Item_field>::iterator li(fields.begin());
5074
5099
  Item *item;
5075
5100
  not_null_tables_cache= used_tables_cache= 0;
5076
5101
  const_item_cache= false;
5090
5115
 
5091
5116
void Item_equal::update_used_tables()
5092
5117
{
5093
 
  List_iterator_fast<Item_field> li(fields);
 
5118
  List<Item_field>::iterator li(fields.begin());
5094
5119
  Item *item;
5095
5120
  not_null_tables_cache= used_tables_cache= 0;
5096
5121
  if ((const_item_cache= cond_false))
5108
5133
  Item_field *item_field;
5109
5134
  if (cond_false)
5110
5135
    return 0;
5111
 
  List_iterator_fast<Item_field> it(fields);
 
5136
  List<Item_field>::iterator it(fields.begin());
5112
5137
  Item *item= const_item ? const_item : it++;
5113
5138
  eval_item->store_value(item);
5114
5139
  if ((null_value= item->null_value))
5134
5159
 
5135
5160
bool Item_equal::walk(Item_processor processor, bool walk_subquery, unsigned char *arg)
5136
5161
{
5137
 
  List_iterator_fast<Item_field> it(fields);
 
5162
  List<Item_field>::iterator it(fields.begin());
5138
5163
  Item *item;
5139
5164
  while ((item= it++))
5140
5165
  {
5146
5171
 
5147
5172
Item *Item_equal::transform(Item_transformer transformer, unsigned char *arg)
5148
5173
{
5149
 
  List_iterator<Item_field> it(fields);
 
5174
  List<Item_field>::iterator it(fields.begin());
5150
5175
  Item *item;
5151
5176
  while ((item= it++))
5152
5177
  {
5170
5195
{
5171
5196
  str->append(func_name());
5172
5197
  str->append('(');
5173
 
  List_iterator_fast<Item_field> it(fields);
 
5198
  List<Item_field>::iterator it(fields.begin());
5174
5199
  Item *item;
5175
5200
  if (const_item)
5176
5201
    const_item->print(str, query_type);
5188
5213
  str->append(')');
5189
5214
}
5190
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
 
5191
5222
} /* namespace drizzled */