~ubuntu-branches/ubuntu/saucy/drizzle/saucy-proposed

« back to all changes in this revision

Viewing changes to drizzled/item/cmpfunc.cc

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2012-06-19 10:46:49 UTC
  • mfrom: (1.1.6)
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20120619104649-e2l0ggd4oz3um0f4
Tags: upstream-7.1.36-stable
ImportĀ upstreamĀ versionĀ 7.1.36-stable

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
#include <drizzled/item/int_with_ref.h>
34
34
#include <drizzled/item/subselect.h>
35
35
#include <drizzled/session.h>
 
36
#include <drizzled/sql_lex.h>
36
37
#include <drizzled/sql_select.h>
 
38
#include <drizzled/system_variables.h>
37
39
#include <drizzled/temporal.h>
38
40
#include <drizzled/time_functions.h>
39
 
#include <drizzled/sql_lex.h>
40
41
 
41
42
#include <math.h>
42
43
#include <algorithm>
43
44
 
44
45
using namespace std;
45
46
 
46
 
namespace drizzled
47
 
{
 
47
namespace drizzled {
48
48
 
49
49
extern const double log_10[309];
50
50
 
94
94
  for (; item < item_end; item++)
95
95
  {
96
96
    if ((*item)->type() != Item::NULL_ITEM)
 
97
    {
97
98
      *type= item_store_type(*type, *item, unsigned_flag);
 
99
    }
98
100
  }
99
101
}
100
102
 
603
605
        comparators= 0;
604
606
        return 1;
605
607
      }
606
 
      if (!(comparators= new Arg_comparator[n]))
607
 
        return 1;
 
608
      comparators= new Arg_comparator[n];
608
609
      for (uint32_t i=0; i < n; i++)
609
610
      {
610
611
        if ((*a)->element_index(i)->cols() != (*b)->element_index(i)->cols())
714
715
*/
715
716
 
716
717
static int64_t
717
 
get_date_from_str(Session *session, String *str, type::timestamp_t warn_type,
718
 
                  char *warn_name, bool *error_arg)
 
718
get_date_from_str(Session *session, String *str, type::timestamp_t warn_type, const char *warn_name, bool *error_arg)
719
719
{
720
720
  int64_t value= 0;
721
721
  type::cut_t error= type::VALID;
743
743
 
744
744
  if (error != type::VALID)
745
745
  {
746
 
    make_truncated_value_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
747
 
                                 str->ptr(), str->length(),
748
 
                                 warn_type, warn_name);
 
746
    make_truncated_value_warning(*session, DRIZZLE_ERROR::WARN_LEVEL_WARN, *str, warn_type, warn_name);
749
747
  }
750
748
 
751
749
  return value;
789
787
                                     int64_t *const_value)
790
788
{
791
789
  enum enum_date_cmp_type cmp_type= CMP_DATE_DFLT;
792
 
  Item *str_arg= 0, *date_arg= 0;
 
790
  Item *str_arg= 0;
793
791
 
794
792
  if (in_a->type() == Item::ROW_ITEM || in_b->type() == Item::ROW_ITEM)
795
793
    return CMP_DATE_DFLT;
803
801
    else if (in_b->result_type() == STRING_RESULT)
804
802
    {
805
803
      cmp_type= CMP_DATE_WITH_STR;
806
 
      date_arg= in_a;
807
804
      str_arg= in_b;
808
805
    }
809
806
  }
810
807
  else if (in_b->is_datetime() && in_a->result_type() == STRING_RESULT)
811
808
  {
812
809
    cmp_type= CMP_STR_WITH_DATE;
813
 
    date_arg= in_b;
814
810
    str_arg= in_a;
815
811
  }
816
812
 
2375
2371
}
2376
2372
 
2377
2373
 
2378
 
void
2379
 
Item_func_if::fix_length_and_dec()
 
2374
void Item_func_if::fix_length_and_dec()
2380
2375
{
2381
2376
  maybe_null= args[1]->maybe_null || args[2]->maybe_null;
2382
2377
  decimals= max(args[1]->decimals, args[2]->decimals);
2401
2396
  }
2402
2397
  else
2403
2398
  {
2404
 
    agg_result_type(&cached_result_type, args+1, 2);
 
2399
    agg_result_type(&cached_result_type, args +1, 2);
2405
2400
    if (cached_result_type == STRING_RESULT)
2406
2401
    {
2407
 
      if (agg_arg_charsets(collation, args+1, 2, MY_COLL_ALLOW_CONV, 1))
 
2402
      if (agg_arg_charsets(collation, args +1, 2, MY_COLL_ALLOW_CONV, 1))
2408
2403
        return;
2409
2404
    }
2410
2405
    else
2411
2406
    {
2412
2407
      collation.set(&my_charset_bin);   // Number
2413
2408
    }
2414
 
    cached_field_type= agg_field_type(args + 1, 2);
 
2409
    cached_field_type= agg_field_type(args +1, 2);
2415
2410
  }
2416
2411
 
2417
 
  if ((cached_result_type == DECIMAL_RESULT )
2418
 
      || (cached_result_type == INT_RESULT))
 
2412
  switch (cached_result_type)
2419
2413
  {
2420
 
    int len1= args[1]->max_length - args[1]->decimals
2421
 
      - (args[1]->unsigned_flag ? 0 : 1);
2422
 
 
2423
 
    int len2= args[2]->max_length - args[2]->decimals
2424
 
      - (args[2]->unsigned_flag ? 0 : 1);
2425
 
 
2426
 
    max_length= max(len1, len2) + decimals + (unsigned_flag ? 0 : 1);
2427
 
  }
2428
 
  else
 
2414
  case DECIMAL_RESULT: 
 
2415
  case INT_RESULT:
 
2416
    {
 
2417
      int len1= args[1]->max_length -args[1]->decimals -(args[1]->unsigned_flag ? 0 : 1);
 
2418
      int len2= args[2]->max_length -args[2]->decimals -(args[2]->unsigned_flag ? 0 : 1);
 
2419
      max_length= max(len1, len2) + decimals + (unsigned_flag ? 0 : 1);
 
2420
    }
 
2421
    break;
 
2422
  case REAL_RESULT:
 
2423
  case STRING_RESULT:
2429
2424
    max_length= max(args[1]->max_length, args[2]->max_length);
 
2425
    break;
 
2426
 
 
2427
  case ROW_RESULT:
 
2428
    assert(0);
 
2429
    break;
 
2430
  }
2430
2431
}
2431
2432
 
2432
2433
 
2453
2454
{
2454
2455
  assert(fixed == 1);
2455
2456
  Item *arg= args[0]->val_bool() ? args[1] : args[2];
2456
 
  int64_t value=arg->val_int();
2457
 
  null_value=arg->null_value;
 
2457
  int64_t value= arg->val_int();
 
2458
  null_value= arg->null_value;
2458
2459
  return value;
2459
2460
}
2460
2461
 
2463
2464
{
2464
2465
  assert(fixed == 1);
2465
2466
  Item *arg= args[0]->val_bool() ? args[1] : args[2];
2466
 
  String *res=arg->val_str(str);
 
2467
  String *res= arg->val_str(str);
2467
2468
  if (res)
 
2469
  {
2468
2470
    res->set_charset(collation.collation);
2469
 
  null_value=arg->null_value;
 
2471
  }
 
2472
  null_value= arg->null_value;
2470
2473
  return res;
2471
2474
}
2472
2475
 
3127
3130
  return (int) ((*compare)(collation, base+start*size, result) == 0);
3128
3131
}
3129
3132
 
3130
 
in_string::in_string(uint32_t elements,qsort2_cmp cmp_func, const CHARSET_INFO * const cs)
 
3133
in_string::in_string(uint32_t elements,qsort2_cmp cmp_func, const charset_info_st * const cs)
3131
3134
  :in_vector(elements, sizeof(String), cmp_func, cs),
3132
3135
   tmp(buff, sizeof(buff), &my_charset_bin)
3133
3136
{}
3157
3160
  }
3158
3161
  if (!str->charset())
3159
3162
  {
3160
 
    const CHARSET_INFO *cs;
 
3163
    const charset_info_st *cs;
3161
3164
    if (!(cs= item->collation.collation))
3162
3165
      cs= &my_charset_bin;              // Should never happen for STR items
3163
3166
    str->set_charset(cs);
3185
3188
 
3186
3189
in_row::~in_row()
3187
3190
{
3188
 
  if (base)
3189
 
    delete [] (cmp_item_row*) base;
 
3191
  delete[] (cmp_item_row*) base;
3190
3192
}
3191
3193
 
3192
3194
unsigned char *in_row::get_value(Item *item)
3298
3300
 
3299
3301
 
3300
3302
cmp_item* cmp_item::get_comparator(Item_result type,
3301
 
                                   const CHARSET_INFO * const cs)
 
3303
                                   const charset_info_st * const cs)
3302
3304
{
3303
3305
  switch (type) {
3304
3306
  case STRING_RESULT:
3359
3361
void cmp_item_row::alloc_comparators()
3360
3362
{
3361
3363
  if (!comparators)
3362
 
    comparators= (cmp_item **) current_session->calloc(sizeof(cmp_item *)*n);
 
3364
    comparators= (cmp_item **) current_session->mem.calloc(sizeof(cmp_item *)*n);
3363
3365
}
3364
3366
 
3365
3367
 
3569
3571
}
3570
3572
 
3571
3573
 
3572
 
static int srtcmp_in(const CHARSET_INFO * const cs, const String *x,const String *y)
 
3574
static int srtcmp_in(const charset_info_st * const cs, const String *x,const String *y)
3573
3575
{
3574
3576
  return cs->coll->strnncollsp(cs,
3575
3577
                               (unsigned char *) x->ptr(),x->length(),
3632
3634
      }
3633
3635
      else
3634
3636
      {
3635
 
        if (!(cmp= new cmp_item_row))
3636
 
          return;
 
3637
        cmp= new cmp_item_row;
3637
3638
        cmp_items[ROW_RESULT]= cmp;
3638
3639
      }
3639
3640
      cmp->n= args[0]->cols();
4182
4183
  while ((item=li++))
4183
4184
  {
4184
4185
    str->append(' ');
4185
 
    str->append(func_name());
 
4186
    str->append(func_name(), strlen(func_name()));
4186
4187
    str->append(' ');
4187
4188
    item->print(str);
4188
4189
  }
4198
4199
  {
4199
4200
    Item *new_item= item->neg_transformer(session);
4200
4201
    if (!new_item)
4201
 
    {
4202
 
      if (!(new_item= new Item_func_not(item)))
4203
 
        return;                                 // Fatal OEM error
4204
 
    }
 
4202
      new_item= new Item_func_not(item);
4205
4203
    li.replace(new_item);
4206
4204
  }
4207
4205
}
4291
4289
  if (a == *org_item)
4292
4290
  {
4293
4291
    Item_cond *res;
4294
 
    if ((res= new Item_cond_and(a, (Item*) b)))
4295
 
    {
4296
 
      res->used_tables_cache= a->used_tables() | b->used_tables();
4297
 
      res->not_null_tables_cache= a->not_null_tables() | b->not_null_tables();
4298
 
    }
 
4292
    res= new Item_cond_and(a, (Item*) b);
 
4293
    res->used_tables_cache= a->used_tables() | b->used_tables();
 
4294
    res->not_null_tables_cache= a->not_null_tables() | b->not_null_tables();
4299
4295
    return res;
4300
4296
  }
4301
 
  if (((Item_cond_and*) a)->add((Item*) b))
4302
 
    return 0;
 
4297
  ((Item_cond_and*) a)->add((Item*) b);
4303
4298
  ((Item_cond_and*) a)->used_tables_cache|= b->used_tables();
4304
4299
  ((Item_cond_and*) a)->not_null_tables_cache|= b->not_null_tables();
4305
4300
  return a;
4329
4324
  if (args[0]->is_null())
4330
4325
  {
4331
4326
    owner->was_null|= 1;
4332
 
    return(0);
 
4327
    return 0;
4333
4328
  }
4334
4329
  else
4335
 
    return(1);
 
4330
    return 1;
4336
4331
}
4337
4332
 
4338
4333
/**
4393
4388
  return my_wildcmp(cmp.cmp_collation.collation,
4394
4389
                    res->ptr(),res->ptr()+res->length(),
4395
4390
                    res2->ptr(),res2->ptr()+res2->length(),
4396
 
                    make_escape_code(cmp.cmp_collation.collation, escape),
4397
 
                    internal::wild_one,internal::wild_many) ? 0 : 1;
 
4391
                    make_escape_code(cmp.cmp_collation.collation, escape), internal::wild_one,internal::wild_many) ? 0 : 1;
4398
4392
}
4399
4393
 
4400
4394
 
4454
4448
      We could also do boyer-more for non-const items, but as we would have to
4455
4449
      recompute the tables for each row it's not worth it.
4456
4450
    */
4457
 
    if (args[1]->const_item() && !use_strnxfrm(collation.collation))
 
4451
    if (args[1]->const_item() && not collation.collation->use_strnxfrm())
4458
4452
    {
4459
4453
      String* res2 = args[1]->val_str(&tmp_value2);
4460
4454
      if (!res2)
4485
4479
      {
4486
4480
        pattern     = first + 1;
4487
4481
        pattern_len = (int) len - 2;
4488
 
        int *suff = (int*) session->getMemRoot()->allocate((int) (sizeof(int)*
4489
 
                                                                  ((pattern_len + 1)*2+
4490
 
                                                                   alphabet_size)));
 
4482
        int *suff = (int*) session->mem.alloc(sizeof(int) * ((pattern_len + 1)*2+ alphabet_size));
4491
4483
        bmGs      = suff + pattern_len + 1;
4492
4484
        bmBc      = bmGs + pattern_len + 1;
4493
4485
        turboBM_compute_good_suffix_shifts(suff);
4504
4496
  Item_bool_func2::cleanup();
4505
4497
}
4506
4498
 
4507
 
static unsigned char likeconv(const CHARSET_INFO *cs, unsigned char a)
 
4499
static unsigned char likeconv(const charset_info_st *cs, unsigned char a)
4508
4500
{
4509
4501
#ifdef LIKE_CMP_TOUPPER
4510
4502
  return cs->toupper(a);
4523
4515
  int            f = 0;
4524
4516
  int            g = plm1;
4525
4517
  int *const splm1 = suff + plm1;
4526
 
  const CHARSET_INFO * const cs= cmp.cmp_collation.collation;
 
4518
  const charset_info_st * const cs= cmp.cmp_collation.collation;
4527
4519
 
4528
4520
  *splm1 = pattern_len;
4529
4521
 
4621
4613
  int *end = bmBc + alphabet_size;
4622
4614
  int j;
4623
4615
  const int plm1 = pattern_len - 1;
4624
 
  const CHARSET_INFO *const cs= cmp.cmp_collation.collation;
 
4616
  const charset_info_st *const cs= cmp.cmp_collation.collation;
4625
4617
 
4626
4618
  for (i = bmBc; i < end; i++)
4627
4619
    *i = pattern_len;
4653
4645
  int shift = pattern_len;
4654
4646
  int j     = 0;
4655
4647
  int u     = 0;
4656
 
  const CHARSET_INFO * const cs= cmp.cmp_collation.collation;
 
4648
  const charset_info_st * const cs= cmp.cmp_collation.collation;
4657
4649
 
4658
4650
  const int plm1=  pattern_len - 1;
4659
4651
  const int tlmpl= text_len - pattern_len;
5182
5174
 
5183
5175
void Item_equal::print(String *str)
5184
5176
{
5185
 
  str->append(func_name());
 
5177
  str->append(func_name(), strlen(func_name()));
5186
5178
  str->append('(');
5187
5179
  List<Item_field>::iterator it(fields.begin());
5188
5180
  Item *item;