~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item_cmpfunc.cc

  • Committer: Stewart Smith
  • Date: 2008-09-15 07:13:59 UTC
  • mfrom: (383.1.21 drizzle)
  • mto: This revision was merged to the branch mainline in revision 408.
  • Revision ID: stewart@flamingspork.com-20080915071359-f8bznznyaiqrtqxa
merged

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
 
#ifdef USE_PRAGMA_IMPLEMENTATION
25
 
#pragma implementation                          // gcc: Class implementation
26
 
#endif
27
 
 
28
 
#include "mysql_priv.h"
29
 
#include "sql_select.h"
 
24
#include <drizzled/server_includes.h>
 
25
#include <drizzled/sql_select.h>
30
26
 
31
27
static bool convert_constant_item(THD *, Item_field *, Item **);
32
28
 
33
29
static Item_result item_store_type(Item_result a, Item *item,
34
 
                                   my_bool unsigned_flag)
 
30
                                   bool unsigned_flag)
35
31
{
36
32
  Item_result b= item->result_type();
37
33
 
49
45
static void agg_result_type(Item_result *type, Item **items, uint nitems)
50
46
{
51
47
  Item **item, **item_end;
52
 
  my_bool unsigned_flag= 0;
 
48
  bool unsigned_flag= 0;
53
49
 
54
50
  *type= STRING_RESULT;
55
51
  /* Skip beginning NULL items */
390
386
 
391
387
  if (!(*item)->with_subselect && (*item)->const_item())
392
388
  {
393
 
    TABLE *table= field->table;
394
389
    ulong orig_sql_mode= thd->variables.sql_mode;
395
390
    enum_check_fields orig_count_cuted_fields= thd->count_cuted_fields;
396
 
    my_bitmap_map *old_write_map;
397
 
    my_bitmap_map *old_read_map;
398
391
    uint64_t orig_field_val= 0; /* original field value if valid */
399
392
 
400
 
    if (table)
401
 
    {
402
 
      old_write_map= dbug_tmp_use_all_columns(table, table->write_set);
403
 
      old_read_map= dbug_tmp_use_all_columns(table, table->read_set);
404
 
    }
405
393
    /* For comparison purposes allow invalid dates like 2000-01-32 */
406
394
    thd->variables.sql_mode= (orig_sql_mode & ~MODE_NO_ZERO_DATE) | 
407
395
                             MODE_INVALID_DATES;
430
418
    }
431
419
    thd->variables.sql_mode= orig_sql_mode;
432
420
    thd->count_cuted_fields= orig_count_cuted_fields;
433
 
    if (table)
434
 
    {
435
 
      dbug_tmp_restore_column_map(table->write_set, old_write_map);
436
 
      dbug_tmp_restore_column_map(table->read_set, old_read_map);
437
 
    }
438
421
  }
439
422
  return result;
440
423
}
655
638
 
656
639
  ret= str_to_datetime(str->ptr(), str->length(), &l_time,
657
640
                       (TIME_FUZZY_DATE | MODE_INVALID_DATES |
658
 
                        (thd->variables.sql_mode &
659
 
                         (MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE))),
 
641
                        (thd->variables.sql_mode & MODE_NO_ZERO_DATE)),
660
642
                       &error);
661
643
 
662
644
  if (ret == DRIZZLE_TIMESTAMP_DATETIME || ret == DRIZZLE_TIMESTAMP_DATE)
675
657
  }
676
658
 
677
659
  if (error > 0)
678
 
    make_truncated_value_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
 
660
    make_truncated_value_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
679
661
                                 str->ptr(), str->length(),
680
662
                                 warn_type, warn_name);
681
663
 
1887
1869
    {
1888
1870
      uint mid= (start + end + 1) / 2;
1889
1871
      interval_range *range= intervals + mid;
1890
 
      my_bool cmp_result;
 
1872
      bool cmp_result;
1891
1873
      /*
1892
1874
        The values in the range intervall may have different types,
1893
1875
        Only do a decimal comparision of the first argument is a decimal
2230
2212
  return cached_field_type;
2231
2213
}
2232
2214
 
2233
 
Field *Item_func_ifnull::tmp_table_field(TABLE *table)
 
2215
Field *Item_func_ifnull::tmp_table_field(Table *table)
2234
2216
{
2235
2217
  return tmp_table_field_from_field_type(table, 0);
2236
2218
}
3090
3072
  return (int) ((*compare)(collation, base+start*size, result) == 0);
3091
3073
}
3092
3074
 
3093
 
in_string::in_string(uint elements,qsort2_cmp cmp_func, CHARSET_INFO *cs)
 
3075
in_string::in_string(uint elements,qsort2_cmp cmp_func, const CHARSET_INFO * const cs)
3094
3076
  :in_vector(elements, sizeof(String), cmp_func, cs),
3095
3077
   tmp(buff, sizeof(buff), &my_charset_bin)
3096
3078
{}
3120
3102
  }
3121
3103
  if (!str->charset())
3122
3104
  {
3123
 
    CHARSET_INFO *cs;
 
3105
    const CHARSET_INFO *cs;
3124
3106
    if (!(cs= item->collation.collation))
3125
3107
      cs= &my_charset_bin;              // Should never happen for STR items
3126
3108
    str->set_charset(cs);
3254
3236
 
3255
3237
 
3256
3238
cmp_item* cmp_item::get_comparator(Item_result type,
3257
 
                                   CHARSET_INFO *cs)
 
3239
                                   const CHARSET_INFO * const cs)
3258
3240
{
3259
3241
  switch (type) {
3260
3242
  case STRING_RESULT:
3523
3505
}
3524
3506
 
3525
3507
 
3526
 
static int srtcmp_in(CHARSET_INFO *cs, const String *x,const String *y)
 
3508
static int srtcmp_in(const CHARSET_INFO * const cs, const String *x,const String *y)
3527
3509
{
3528
3510
  return cs->coll->strnncollsp(cs,
3529
3511
                               (uchar *) x->ptr(),x->length(),
4436
4418
    String *escape_str= escape_item->val_str(&tmp_value1);
4437
4419
    if (escape_str)
4438
4420
    {
4439
 
      if (escape_used_in_parsing && (
4440
 
             (((thd->variables.sql_mode & MODE_NO_BACKSLASH_ESCAPES) &&
4441
 
                escape_str->numchars() != 1) ||
4442
 
               escape_str->numchars() > 1)))
 
4421
      if (escape_used_in_parsing && escape_str->numchars() > 1)
4443
4422
      {
4444
4423
        my_error(ER_WRONG_ARGUMENTS,MYF(0),"ESCAPE");
4445
4424
        return true;
4447
4426
 
4448
4427
      if (use_mb(cmp.cmp_collation.collation))
4449
4428
      {
4450
 
        CHARSET_INFO *cs= escape_str->charset();
 
4429
        const CHARSET_INFO * const cs= escape_str->charset();
4451
4430
        my_wc_t wc;
4452
4431
        int rc= cs->cset->mb_wc(cs, &wc,
4453
4432
                                (const uchar*) escape_str->ptr(),
4462
4441
          code instead of Unicode code as "escape" argument.
4463
4442
          Convert to "cs" if charset of escape differs.
4464
4443
        */
4465
 
        CHARSET_INFO *cs= cmp.cmp_collation.collation;
 
4444
        const CHARSET_INFO * const cs= cmp.cmp_collation.collation;
4466
4445
        uint32_t unused;
4467
4446
        if (escape_str->needs_conversion(escape_str->length(),
4468
4447
                                         escape_str->charset(), cs, &unused))
4485
4464
      We could also do boyer-more for non-const items, but as we would have to
4486
4465
      recompute the tables for each row it's not worth it.
4487
4466
    */
4488
 
    if (args[1]->const_item() && !use_strnxfrm(collation.collation) &&
4489
 
       !(specialflag & SPECIAL_NO_NEW_FUNC))
 
4467
    if (args[1]->const_item() && !use_strnxfrm(collation.collation)) 
4490
4468
    {
4491
4469
      String* res2 = args[1]->val_str(&tmp_value2);
4492
4470
      if (!res2)
4548
4526
  int            f = 0;
4549
4527
  int            g = plm1;
4550
4528
  int *const splm1 = suff + plm1;
4551
 
  CHARSET_INFO  *cs= cmp.cmp_collation.collation;
 
4529
  const CHARSET_INFO * const cs= cmp.cmp_collation.collation;
4552
4530
 
4553
4531
  *splm1 = pattern_len;
4554
4532
 
4648
4626
  int *end = bmBc + alphabet_size;
4649
4627
  int j;
4650
4628
  const int plm1 = pattern_len - 1;
4651
 
  CHARSET_INFO  *cs= cmp.cmp_collation.collation;
 
4629
  const CHARSET_INFO *const cs= cmp.cmp_collation.collation;
4652
4630
 
4653
4631
  for (i = bmBc; i < end; i++)
4654
4632
    *i = pattern_len;
4680
4658
  int shift = pattern_len;
4681
4659
  int j     = 0;
4682
4660
  int u     = 0;
4683
 
  CHARSET_INFO  *cs= cmp.cmp_collation.collation;
 
4661
  const CHARSET_INFO * const cs= cmp.cmp_collation.collation;
4684
4662
 
4685
4663
  const int plm1=  pattern_len - 1;
4686
4664
  const int tlmpl= text_len - pattern_len;
4703
4681
      register const int v = plm1 - i;
4704
4682
      turboShift = u - v;
4705
4683
      bcShift    = bmBc[(uint) (uchar) text[i + j]] - plm1 + i;
4706
 
      shift      = max(turboShift, bcShift);
4707
 
      shift      = max(shift, bmGs[i]);
 
4684
      shift      = (turboShift > bcShift) ? turboShift : bcShift;
 
4685
      shift      = (shift > bmGs[i]) ? shift : bmGs[i];
4708
4686
      if (shift == bmGs[i])
4709
 
        u = min(pattern_len - shift, v);
 
4687
        u = (pattern_len - shift < v) ? pattern_len - shift : v;
4710
4688
      else
4711
4689
      {
4712
4690
        if (turboShift < bcShift)
4734
4712
      register const int v = plm1 - i;
4735
4713
      turboShift = u - v;
4736
4714
      bcShift    = bmBc[(uint) likeconv(cs, text[i + j])] - plm1 + i;
4737
 
      shift      = max(turboShift, bcShift);
 
4715
      shift      = (turboShift > bcShift) ? turboShift : bcShift;
4738
4716
      shift      = max(shift, bmGs[i]);
4739
4717
      if (shift == bmGs[i])
4740
 
        u = min(pattern_len - shift, v);
 
4718
        u = (pattern_len - shift < v) ? pattern_len - shift : v;
4741
4719
      else
4742
4720
      {
4743
4721
        if (turboShift < bcShift)