~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/cmpfunc.cc

  • Committer: Brian Aker
  • Date: 2009-10-15 00:22:33 UTC
  • mto: (1183.1.11 merge)
  • mto: This revision was merged to the branch mainline in revision 1198.
  • Revision ID: brian@gaz-20091015002233-fa4ao2mbc67wls91
First pass of information engine. OMG, ponies... is it so much easier to
deal with creating and engine.

The list table iterator though... its ass, needs to go. We should also
abstract out share. Very few engines need a custom one. Just say'in

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
   You should have received a copy of the GNU General Public License
13
13
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
 
17
17
/**
21
21
  This file defines all compare functions
22
22
*/
23
23
 
24
 
#include "config.h"
 
24
#include "drizzled/server_includes.h"
25
25
#include "drizzled/sql_select.h"
26
26
#include "drizzled/error.h"
27
27
#include "drizzled/temporal.h"
30
30
#include "drizzled/item/cache_int.h"
31
31
#include "drizzled/item/int_with_ref.h"
32
32
#include "drizzled/check_stack_overrun.h"
33
 
#include "drizzled/time_functions.h"
34
 
#include "drizzled/internal/my_sys.h"
35
 
#include <math.h>
 
33
 
36
34
#include <algorithm>
37
35
 
38
36
using namespace std;
39
37
 
40
 
namespace drizzled
41
 
{
42
 
 
43
 
extern const double log_10[309];
44
38
 
45
39
static Eq_creator eq_creator;
46
40
static Ne_creator ne_creator;
209
203
    collect_cmp_types()
210
204
      items             Array of items to collect types from
211
205
      nitems            Number of items in the array
212
 
      skip_nulls        Don't collect types of NULL items if TRUE
213
206
 
214
207
  DESCRIPTION
215
208
    This function collects different result types for comparison of the first
220
213
    Bitmap of collected types - otherwise
221
214
*/
222
215
 
223
 
static uint32_t collect_cmp_types(Item **items, uint32_t nitems, bool skip_nulls= false)
 
216
static uint32_t collect_cmp_types(Item **items, uint32_t nitems)
224
217
{
225
218
  uint32_t i;
226
219
  uint32_t found_types;
229
222
  found_types= 0;
230
223
  for (i= 1; i < nitems ; i++)
231
224
  {
232
 
    if (skip_nulls && items[i]->type() == Item::NULL_ITEM)
233
 
      continue; // Skip NULL constant items
234
225
    if ((left_result == ROW_RESULT ||
235
226
         items[i]->result_type() == ROW_RESULT) &&
236
227
        cmp_row_type(items[0], items[i]))
238
229
    found_types|= 1<< (uint32_t)item_cmp_type(left_result,
239
230
                                           items[i]->result_type());
240
231
  }
241
 
  /*
242
 
   Even if all right-hand items are NULLs and we are skipping them all, we need
243
 
   at least one type bit in the found_type bitmask.
244
 
  */
245
 
  if (skip_nulls && !found_types)
246
 
    found_types= 1 << (uint)left_result;
247
232
  return found_types;
248
233
}
249
234
 
570
555
{
571
556
  owner= item;
572
557
  func= comparator_matrix[type]
573
 
    [test(owner->functype() == Item_func::EQUAL_FUNC)];
574
 
 
 
558
                         [test(owner->functype() == Item_func::EQUAL_FUNC)];
575
559
  switch (type) {
576
560
  case ROW_RESULT:
577
 
    {
578
 
      uint32_t n= (*a)->cols();
579
 
      if (n != (*b)->cols())
580
 
      {
581
 
        my_error(ER_OPERAND_COLUMNS, MYF(0), n);
582
 
        comparators= 0;
583
 
        return 1;
584
 
      }
585
 
      if (!(comparators= new Arg_comparator[n]))
586
 
        return 1;
587
 
      for (uint32_t i=0; i < n; i++)
588
 
      {
589
 
        if ((*a)->element_index(i)->cols() != (*b)->element_index(i)->cols())
590
 
        {
591
 
          my_error(ER_OPERAND_COLUMNS, MYF(0), (*a)->element_index(i)->cols());
592
 
          return 1;
593
 
        }
594
 
        comparators[i].set_cmp_func(owner, (*a)->addr(i), (*b)->addr(i));
595
 
      }
596
 
      break;
597
 
    }
598
 
 
 
561
  {
 
562
    uint32_t n= (*a)->cols();
 
563
    if (n != (*b)->cols())
 
564
    {
 
565
      my_error(ER_OPERAND_COLUMNS, MYF(0), n);
 
566
      comparators= 0;
 
567
      return 1;
 
568
    }
 
569
    if (!(comparators= new Arg_comparator[n]))
 
570
      return 1;
 
571
    for (uint32_t i=0; i < n; i++)
 
572
    {
 
573
      if ((*a)->element_index(i)->cols() != (*b)->element_index(i)->cols())
 
574
      {
 
575
        my_error(ER_OPERAND_COLUMNS, MYF(0), (*a)->element_index(i)->cols());
 
576
        return 1;
 
577
      }
 
578
      comparators[i].set_cmp_func(owner, (*a)->addr(i), (*b)->addr(i));
 
579
    }
 
580
    break;
 
581
  }
599
582
  case STRING_RESULT:
 
583
  {
 
584
    /*
 
585
      We must set cmp_charset here as we may be called from for an automatic
 
586
      generated item, like in natural join
 
587
    */
 
588
    if (cmp_collation.set((*a)->collation, (*b)->collation) ||
 
589
        cmp_collation.derivation == DERIVATION_NONE)
 
590
    {
 
591
      my_coll_agg_error((*a)->collation, (*b)->collation, owner->func_name());
 
592
      return 1;
 
593
    }
 
594
    if (cmp_collation.collation == &my_charset_bin)
600
595
    {
601
596
      /*
602
 
        We must set cmp_charset here as we may be called from for an automatic
603
 
        generated item, like in natural join
 
597
        We are using BLOB/BINARY/VARBINARY, change to compare byte by byte,
 
598
        without removing end space
604
599
      */
605
 
      if (cmp_collation.set((*a)->collation, (*b)->collation) ||
606
 
          cmp_collation.derivation == DERIVATION_NONE)
607
 
      {
608
 
        my_coll_agg_error((*a)->collation, (*b)->collation, owner->func_name());
609
 
        return 1;
610
 
      }
611
 
      if (cmp_collation.collation == &my_charset_bin)
612
 
      {
613
 
        /*
614
 
          We are using BLOB/BINARY/VARBINARY, change to compare byte by byte,
615
 
          without removing end space
616
 
        */
617
 
        if (func == &Arg_comparator::compare_string)
618
 
          func= &Arg_comparator::compare_binary_string;
619
 
        else if (func == &Arg_comparator::compare_e_string)
620
 
          func= &Arg_comparator::compare_e_binary_string;
 
600
      if (func == &Arg_comparator::compare_string)
 
601
        func= &Arg_comparator::compare_binary_string;
 
602
      else if (func == &Arg_comparator::compare_e_string)
 
603
        func= &Arg_comparator::compare_e_binary_string;
621
604
 
622
 
        /*
623
 
          As this is binary compassion, mark all fields that they can't be
624
 
          transformed. Otherwise we would get into trouble with comparisons
625
 
like:
626
 
WHERE col= 'j' AND col LIKE BINARY 'j'
627
 
which would be transformed to:
628
 
WHERE col= 'j'
 
605
      /*
 
606
        As this is binary compassion, mark all fields that they can't be
 
607
        transformed. Otherwise we would get into trouble with comparisons
 
608
        like:
 
609
        WHERE col= 'j' AND col LIKE BINARY 'j'
 
610
        which would be transformed to:
 
611
        WHERE col= 'j'
629
612
      */
630
 
        (*a)->walk(&Item::set_no_const_sub, false, (unsigned char*) 0);
631
 
        (*b)->walk(&Item::set_no_const_sub, false, (unsigned char*) 0);
632
 
      }
633
 
      break;
 
613
      (*a)->walk(&Item::set_no_const_sub, false, (unsigned char*) 0);
 
614
      (*b)->walk(&Item::set_no_const_sub, false, (unsigned char*) 0);
634
615
    }
 
616
    break;
 
617
  }
635
618
  case INT_RESULT:
636
 
    {
637
 
      if (func == &Arg_comparator::compare_int_signed)
638
 
      {
639
 
        if ((*a)->unsigned_flag)
640
 
          func= (((*b)->unsigned_flag)?
641
 
                 &Arg_comparator::compare_int_unsigned :
642
 
                 &Arg_comparator::compare_int_unsigned_signed);
643
 
        else if ((*b)->unsigned_flag)
644
 
          func= &Arg_comparator::compare_int_signed_unsigned;
645
 
      }
646
 
      else if (func== &Arg_comparator::compare_e_int)
647
 
      {
648
 
        if ((*a)->unsigned_flag ^ (*b)->unsigned_flag)
649
 
          func= &Arg_comparator::compare_e_int_diff_signedness;
650
 
      }
651
 
      break;
652
 
    }
 
619
  {
 
620
    if (func == &Arg_comparator::compare_int_signed)
 
621
    {
 
622
      if ((*a)->unsigned_flag)
 
623
        func= (((*b)->unsigned_flag)?
 
624
               &Arg_comparator::compare_int_unsigned :
 
625
               &Arg_comparator::compare_int_unsigned_signed);
 
626
      else if ((*b)->unsigned_flag)
 
627
        func= &Arg_comparator::compare_int_signed_unsigned;
 
628
    }
 
629
    else if (func== &Arg_comparator::compare_e_int)
 
630
    {
 
631
      if ((*a)->unsigned_flag ^ (*b)->unsigned_flag)
 
632
        func= &Arg_comparator::compare_e_int_diff_signedness;
 
633
    }
 
634
    break;
 
635
  }
653
636
  case DECIMAL_RESULT:
654
637
    break;
655
638
  case REAL_RESULT:
 
639
  {
 
640
    if ((*a)->decimals < NOT_FIXED_DEC && (*b)->decimals < NOT_FIXED_DEC)
656
641
    {
657
 
      if ((*a)->decimals < NOT_FIXED_DEC && (*b)->decimals < NOT_FIXED_DEC)
658
 
      {
659
 
        precision= 5 / log_10[max((*a)->decimals, (*b)->decimals) + 1];
660
 
        if (func == &Arg_comparator::compare_real)
661
 
          func= &Arg_comparator::compare_real_fixed;
662
 
        else if (func == &Arg_comparator::compare_e_real)
663
 
          func= &Arg_comparator::compare_e_real_fixed;
664
 
      }
665
 
      break;
 
642
      precision= 5 / log_10[max((*a)->decimals, (*b)->decimals) + 1];
 
643
      if (func == &Arg_comparator::compare_real)
 
644
        func= &Arg_comparator::compare_real_fixed;
 
645
      else if (func == &Arg_comparator::compare_e_real)
 
646
        func= &Arg_comparator::compare_e_real_fixed;
666
647
    }
667
 
  }
668
 
 
 
648
    break;
 
649
  }
 
650
  default:
 
651
    assert(0);
 
652
  }
669
653
  return 0;
670
654
}
671
655
 
722
706
  }
723
707
 
724
708
  if (error > 0)
725
 
  {
726
709
    make_truncated_value_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
727
710
                                 str->ptr(), str->length(),
728
711
                                 warn_type, warn_name);
729
 
  }
730
712
 
731
713
  return value;
732
714
}
765
747
*/
766
748
 
767
749
enum Arg_comparator::enum_date_cmp_type
768
 
Arg_comparator::can_compare_as_dates(Item *in_a, Item *in_b,
769
 
                                     uint64_t *const_value)
 
750
Arg_comparator::can_compare_as_dates(Item *a, Item *b, uint64_t *const_value)
770
751
{
771
752
  enum enum_date_cmp_type cmp_type= CMP_DATE_DFLT;
772
753
  Item *str_arg= 0, *date_arg= 0;
773
754
 
774
 
  if (in_a->type() == Item::ROW_ITEM || in_b->type() == Item::ROW_ITEM)
 
755
  if (a->type() == Item::ROW_ITEM || b->type() == Item::ROW_ITEM)
775
756
    return CMP_DATE_DFLT;
776
757
 
777
 
  if (in_a->is_datetime())
 
758
  if (a->is_datetime())
778
759
  {
779
 
    if (in_b->is_datetime())
 
760
    if (b->is_datetime())
780
761
      cmp_type= CMP_DATE_WITH_DATE;
781
 
    else if (in_b->result_type() == STRING_RESULT)
 
762
    else if (b->result_type() == STRING_RESULT)
782
763
    {
783
764
      cmp_type= CMP_DATE_WITH_STR;
784
 
      date_arg= in_a;
785
 
      str_arg= in_b;
 
765
      date_arg= a;
 
766
      str_arg= b;
786
767
    }
787
768
  }
788
 
  else if (in_b->is_datetime() && in_a->result_type() == STRING_RESULT)
 
769
  else if (b->is_datetime() && a->result_type() == STRING_RESULT)
789
770
  {
790
771
    cmp_type= CMP_STR_WITH_DATE;
791
 
    date_arg= in_b;
792
 
    str_arg= in_a;
 
772
    date_arg= b;
 
773
    str_arg= a;
793
774
  }
794
775
 
795
776
  if (cmp_type != CMP_DATE_DFLT)
823
804
      String *str_val;
824
805
      String tmp;
825
806
      /* DateTime used to pick up as many string conversion possibilities as possible. */
826
 
      DateTime temporal;
 
807
      drizzled::DateTime temporal;
827
808
 
828
809
      str_val= str_arg->val_str(&tmp);
829
810
      if (! str_val)
1066
1047
  /* Compare values. */
1067
1048
  if (is_nulls_eq)
1068
1049
    return (a_value == b_value);
1069
 
  return (a_value < b_value) ? -1 : ((a_value > b_value) ? 1 : 0);
 
1050
  return a_value < b_value ? -1 : (a_value > b_value ? 1 : 0);
1070
1051
}
1071
1052
 
1072
1053
 
1806
1787
 
1807
1788
    if (not_null_consts &&
1808
1789
        (intervals=
1809
 
          (interval_range*) memory::sql_alloc(sizeof(interval_range) * (rows - 1))))
 
1790
          (interval_range*) sql_alloc(sizeof(interval_range) * (rows - 1))))
1810
1791
    {
1811
1792
      if (use_decimal_comparison)
1812
1793
      {
2036
2017
    ge_cmp.set_datetime_cmp_func(args, args + 1);
2037
2018
    le_cmp.set_datetime_cmp_func(args, args + 2);
2038
2019
  }
2039
 
  else if (args[0]->real_item()->type() == FIELD_ITEM)
 
2020
  else if (args[0]->real_item()->type() == FIELD_ITEM &&
 
2021
           session->lex->sql_command != SQLCOM_SHOW_CREATE)
2040
2022
  {
2041
2023
    Item_field *field_item= (Item_field*) (args[0]->real_item());
2042
2024
    if (field_item->field->can_be_compared_as_int64_t())
2196
2178
    max_length= max(len0, len1) + decimals + (unsigned_flag ? 0 : 1);
2197
2179
  }
2198
2180
  else
2199
 
  {
2200
2181
    max_length= max(args[0]->max_length, args[1]->max_length);
2201
 
  }
2202
2182
 
2203
2183
  switch (hybrid_type)
2204
2184
  {
2205
2185
  case STRING_RESULT:
2206
2186
    agg_arg_charsets(collation, args, arg_count, MY_COLL_CMP_CONV, 1);
2207
2187
    break;
2208
 
 
2209
2188
  case DECIMAL_RESULT:
2210
2189
  case REAL_RESULT:
2211
2190
    break;
2212
 
 
2213
2191
  case INT_RESULT:
2214
2192
    decimals= 0;
2215
2193
    break;
2216
 
 
2217
2194
  case ROW_RESULT:
 
2195
  default:
2218
2196
    assert(0);
2219
2197
  }
2220
 
 
2221
2198
  cached_field_type= agg_field_type(args, 2);
2222
2199
}
2223
2200
 
2729
2706
  Item **agg;
2730
2707
  uint32_t nagg;
2731
2708
  uint32_t found_types= 0;
2732
 
  if (!(agg= (Item**) memory::sql_alloc(sizeof(Item*)*(ncases+1))))
 
2709
  if (!(agg= (Item**) sql_alloc(sizeof(Item*)*(ncases+1))))
2733
2710
    return;
2734
2711
 
2735
2712
  /*
2755
2732
  */
2756
2733
  if (first_expr_num != -1)
2757
2734
  {
 
2735
    uint32_t i;
2758
2736
    agg[0]= args[first_expr_num];
2759
2737
    left_result_type= agg[0]->result_type();
2760
2738
 
2764
2742
    if (!(found_types= collect_cmp_types(agg, nagg)))
2765
2743
      return;
2766
2744
 
2767
 
    for (int i= STRING_RESULT; i <= DECIMAL_RESULT; i++)
 
2745
    for (i= 0; i <= (uint32_t)DECIMAL_RESULT; i++)
2768
2746
    {
2769
2747
      if (found_types & (1 << i) && !cmp_items[i])
2770
2748
      {
2850
2828
 
2851
2829
void Item_func_case::cleanup()
2852
2830
{
 
2831
  uint32_t i;
2853
2832
  Item_func::cleanup();
2854
 
  for (int i= STRING_RESULT; i <= DECIMAL_RESULT; i++)
 
2833
  for (i= 0; i <= (uint32_t)DECIMAL_RESULT; i++)
2855
2834
  {
2856
2835
    delete cmp_items[i];
2857
2836
    cmp_items[i]= 0;
2858
2837
  }
 
2838
  return;
2859
2839
}
2860
2840
 
2861
2841
 
2925
2905
{
2926
2906
  cached_field_type= agg_field_type(args, arg_count);
2927
2907
  agg_result_type(&hybrid_type, args, arg_count);
2928
 
 
2929
2908
  switch (hybrid_type) {
2930
2909
  case STRING_RESULT:
2931
2910
    count_only_length();
2932
2911
    decimals= NOT_FIXED_DEC;
2933
2912
    agg_arg_charsets(collation, args, arg_count, MY_COLL_ALLOW_CONV, 1);
2934
2913
    break;
2935
 
 
2936
2914
  case DECIMAL_RESULT:
2937
2915
    count_decimal_length();
2938
2916
    break;
2939
 
 
2940
2917
  case REAL_RESULT:
2941
2918
    count_real_length();
2942
2919
    break;
2943
 
 
2944
2920
  case INT_RESULT:
2945
2921
    count_only_length();
2946
2922
    decimals= 0;
2947
2923
    break;
2948
 
 
2949
2924
  case ROW_RESULT:
 
2925
  default:
2950
2926
    assert(0);
2951
2927
  }
2952
2928
}
3073
3049
}
3074
3050
 
3075
3051
 
3076
 
void in_vector::sort()
3077
 
{
3078
 
  internal::my_qsort2(base,used_count,size,compare, (void *) collation);
3079
 
}
3080
 
 
3081
 
 
3082
3052
int in_vector::find(Item *item)
3083
3053
{
3084
3054
  unsigned char *result=get_value(item);
3110
3080
{
3111
3081
  if (base)
3112
3082
  {
3113
 
    // base was allocated with help of memory::sql_alloc => following is OK
 
3083
    // base was allocated with help of sql_alloc => following is OK
3114
3084
    for (uint32_t i=0 ; i < count ; i++)
3115
3085
      ((String*) base)[i].free();
3116
3086
  }
3270
3240
  switch (type) {
3271
3241
  case STRING_RESULT:
3272
3242
    return new cmp_item_sort_string(cs);
3273
 
 
3274
3243
  case INT_RESULT:
3275
3244
    return new cmp_item_int;
3276
 
 
3277
3245
  case REAL_RESULT:
3278
3246
    return new cmp_item_real;
3279
 
 
3280
3247
  case ROW_RESULT:
3281
3248
    return new cmp_item_row;
3282
 
 
3283
3249
  case DECIMAL_RESULT:
3284
3250
    return new cmp_item_decimal;
 
3251
  default:
 
3252
    assert(0);
 
3253
    break;
3285
3254
  }
3286
 
 
3287
3255
  return 0; // to satisfy compiler :)
3288
3256
}
3289
3257
 
3362
3330
    return;
3363
3331
  }
3364
3332
  n= tmpl->n;
3365
 
  if ((comparators= (cmp_item **) memory::sql_alloc(sizeof(cmp_item *)*n)))
 
3333
  if ((comparators= (cmp_item **) sql_alloc(sizeof(cmp_item *)*n)))
3366
3334
  {
3367
3335
    item->bring_value();
3368
3336
    item->null_value= 0;
3554
3522
  bool compare_as_datetime= false;
3555
3523
  Item *date_arg= 0;
3556
3524
  uint32_t found_types= 0;
3557
 
  uint32_t type_cnt= 0;
 
3525
  uint32_t type_cnt= 0, i;
3558
3526
  Item_result cmp_type= STRING_RESULT;
3559
3527
  left_result_type= args[0]->result_type();
3560
 
  if (!(found_types= collect_cmp_types(args, arg_count, true)))
 
3528
  if (!(found_types= collect_cmp_types(args, arg_count)))
3561
3529
    return;
3562
3530
 
3563
3531
  for (arg= args + 1, arg_end= args + arg_count; arg != arg_end ; arg++)
3568
3536
      break;
3569
3537
    }
3570
3538
  }
3571
 
  for (int i= STRING_RESULT; i <= DECIMAL_RESULT; i++)
 
3539
  for (i= 0; i <= (uint32_t)DECIMAL_RESULT; i++)
3572
3540
  {
3573
3541
    if (found_types & 1 << i)
3574
3542
    {
3675
3643
  if (type_cnt == 1 && const_itm && !nulls_in_row())
3676
3644
  {
3677
3645
    if (compare_as_datetime)
3678
 
    {
3679
3646
      array= new in_datetime(date_arg, arg_count - 1);
3680
 
    }
3681
3647
    else
3682
3648
    {
3683
3649
      /*
3688
3654
        comparison type accordingly.
3689
3655
      */
3690
3656
      if (args[0]->real_item()->type() == FIELD_ITEM &&
 
3657
          session->lex->sql_command != SQLCOM_SHOW_CREATE &&
3691
3658
          cmp_type != INT_RESULT)
3692
3659
      {
3693
3660
        Item_field *field_item= (Item_field*) (args[0]->real_item());
3703
3670
            cmp_type= INT_RESULT;
3704
3671
        }
3705
3672
      }
3706
 
 
3707
3673
      switch (cmp_type) {
3708
3674
      case STRING_RESULT:
3709
3675
        array=new in_string(arg_count-1,(qsort2_cmp) srtcmp_in,
3710
3676
                            cmp_collation.collation);
3711
3677
        break;
3712
 
 
3713
3678
      case INT_RESULT:
3714
3679
        array= new in_int64_t(arg_count-1);
3715
3680
        break;
3716
 
 
3717
3681
      case REAL_RESULT:
3718
3682
        array= new in_double(arg_count-1);
3719
3683
        break;
3720
 
 
3721
3684
      case ROW_RESULT:
3722
3685
        /*
3723
3686
          The row comparator was created at the beginning but only DATETIME
3726
3689
        */
3727
3690
        ((in_row*)array)->tmp.store_value(args[0]);
3728
3691
        break;
3729
 
 
3730
3692
      case DECIMAL_RESULT:
3731
3693
        array= new in_decimal(arg_count - 1);
3732
3694
        break;
 
3695
      default:
 
3696
        assert(0);
 
3697
        return;
3733
3698
      }
3734
3699
    }
3735
 
 
3736
3700
    if (array && !(session->is_fatal_error))            // If not EOM
3737
3701
    {
3738
3702
      uint32_t j=0;
3739
3703
      for (uint32_t arg_num=1 ; arg_num < arg_count ; arg_num++)
3740
3704
      {
3741
 
        if (!args[arg_num]->null_value)                 // Skip NULL values
3742
 
        {
3743
 
          array->set(j,args[arg_num]);
3744
 
          j++;
3745
 
        }
3746
 
        else
3747
 
          have_null= 1;
 
3705
        array->set(j,args[arg_num]);
 
3706
        if (!args[arg_num]->null_value)                 // Skip NULL values
 
3707
          j++;
 
3708
        else
 
3709
          have_null= 1;
3748
3710
      }
3749
3711
      if ((array->used_count= j))
3750
 
        array->sort();
 
3712
        array->sort();
3751
3713
    }
3752
3714
  }
3753
3715
  else
3756
3718
      cmp_items[STRING_RESULT]= new cmp_item_datetime(date_arg);
3757
3719
    else
3758
3720
    {
3759
 
      for (int i= STRING_RESULT; i <= DECIMAL_RESULT; i++)
 
3721
      for (i= 0; i <= (uint32_t) DECIMAL_RESULT; i++)
3760
3722
      {
3761
3723
        if (found_types & (1 << i) && !cmp_items[i])
3762
3724
        {
4372
4334
                    res->ptr(),res->ptr()+res->length(),
4373
4335
                    res2->ptr(),res2->ptr()+res2->length(),
4374
4336
                    make_escape_code(cmp.cmp_collation.collation, escape),
4375
 
                    internal::wild_one,internal::wild_many) ? 0 : 1;
 
4337
                    wild_one,wild_many) ? 0 : 1;
4376
4338
}
4377
4339
 
4378
4340
 
4389
4351
    if (!res2)
4390
4352
      return OPTIMIZE_NONE;
4391
4353
 
4392
 
    if (*res2->ptr() != internal::wild_many)
 
4354
    if (*res2->ptr() != wild_many)
4393
4355
    {
4394
 
      if (args[0]->result_type() != STRING_RESULT || *res2->ptr() != internal::wild_one)
 
4356
      if (args[0]->result_type() != STRING_RESULT || *res2->ptr() != wild_one)
4395
4357
        return OPTIMIZE_OP;
4396
4358
    }
4397
4359
  }
4419
4381
    String *escape_str= escape_item->val_str(&tmp_value1);
4420
4382
    if (escape_str)
4421
4383
    {
4422
 
      escape= (char *)memory::sql_alloc(escape_str->length());
 
4384
      escape= (char *)sql_alloc(escape_str->length());
4423
4385
      strcpy(escape, escape_str->ptr()); 
4424
4386
    }
4425
4387
    else
4426
4388
    {
4427
 
      escape= (char *)memory::sql_alloc(1);
 
4389
      escape= (char *)sql_alloc(1);
4428
4390
      strcpy(escape, "\\");
4429
4391
    } 
4430
4392
   
4447
4409
      */
4448
4410
 
4449
4411
      if (len > MIN_TURBOBM_PATTERN_LEN + 2 &&
4450
 
          *first == internal::wild_many &&
4451
 
          *last  == internal::wild_many)
 
4412
          *first == wild_many &&
 
4413
          *last  == wild_many)
4452
4414
      {
4453
4415
        const char* tmp = first + 1;
4454
 
        for (; *tmp != internal::wild_many && *tmp != internal::wild_one; tmp++)
 
4416
        for (; *tmp != wild_many && *tmp != wild_one; tmp++)
4455
4417
        {
4456
4418
          if (escape == tmp)
4457
4419
            break;
5114
5076
  while ((item_field= it++))
5115
5077
  {
5116
5078
    /* Skip fields of non-const tables. They haven't been read yet */
5117
 
    if (item_field->field->getTable()->const_table)
 
5079
    if (item_field->field->table->const_table)
5118
5080
    {
5119
5081
      if ((null_value= item_field->null_value) || eval_item->cmp(item_field))
5120
5082
        return 0;
5186
5148
  str->append(')');
5187
5149
}
5188
5150
 
5189
 
} /* namespace drizzled */