~xnox/ubuntu/saucy/drizzle/merge

« back to all changes in this revision

Viewing changes to drizzled/item/cmpfunc.cc

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2011-01-01 13:55:03 UTC
  • Revision ID: james.westby@ubuntu.com-20110101135503-x2ub1akxoisgwi6z
Tags: 2010.12.06-0ubuntu4
* Fixed missing build depends.
* Added Lee to uploaders.

Show diffs side-by-side

added added

removed removed

Lines of Context:
463
463
      the call to save_in_field below overrides that value.
464
464
    */
465
465
    if (field_item->depended_from)
 
466
    {
466
467
      orig_field_val= field->val_int();
 
468
    }
 
469
 
467
470
    if (!(*item)->is_null() && !(*item)->save_in_field(field, 1))
468
471
    {
469
472
      Item *tmp= new Item_int_with_ref(field->val_int(), *item,
472
475
        session->change_item_tree(item, tmp);
473
476
      result= 1;                                        // Item was replaced
474
477
    }
 
478
 
475
479
    /* Restore the original field value. */
476
480
    if (field_item->depended_from)
477
481
    {
478
 
      result= field->store(orig_field_val, true);
 
482
      result= field->store(orig_field_val, field->isUnsigned());
479
483
      /* orig_field_val must be a valid value that can be restored back. */
480
484
      assert(!result);
481
485
    }
698
702
{
699
703
  uint64_t value= 0;
700
704
  int error;
701
 
  DRIZZLE_TIME l_time;
 
705
  type::Time l_time;
702
706
  enum enum_drizzle_timestamp_type ret;
703
707
 
704
708
  ret= str_to_datetime(str->ptr(), str->length(), &l_time,
1169
1173
 
1170
1174
int Arg_comparator::compare_decimal()
1171
1175
{
1172
 
  my_decimal value1;
1173
 
  my_decimal *val1= (*a)->val_decimal(&value1);
 
1176
  type::Decimal value1;
 
1177
  type::Decimal *val1= (*a)->val_decimal(&value1);
1174
1178
  if (!(*a)->null_value)
1175
1179
  {
1176
 
    my_decimal value2;
1177
 
    my_decimal *val2= (*b)->val_decimal(&value2);
 
1180
    type::Decimal value2;
 
1181
    type::Decimal *val2= (*b)->val_decimal(&value2);
1178
1182
    if (!(*b)->null_value)
1179
1183
    {
1180
1184
      owner->null_value= 0;
1181
 
      return my_decimal_cmp(val1, val2);
 
1185
      return class_decimal_cmp(val1, val2);
1182
1186
    }
1183
1187
  }
1184
1188
  owner->null_value= 1;
1196
1200
 
1197
1201
int Arg_comparator::compare_e_decimal()
1198
1202
{
1199
 
  my_decimal value1, value2;
1200
 
  my_decimal *val1= (*a)->val_decimal(&value1);
1201
 
  my_decimal *val2= (*b)->val_decimal(&value2);
 
1203
  type::Decimal value1, value2;
 
1204
  type::Decimal *val1= (*a)->val_decimal(&value1);
 
1205
  type::Decimal *val2= (*b)->val_decimal(&value2);
1202
1206
  if ((*a)->null_value || (*b)->null_value)
1203
1207
    return test((*a)->null_value && (*b)->null_value);
1204
 
  return test(my_decimal_cmp(val1, val2) == 0);
 
1208
  return test(class_decimal_cmp(val1, val2) == 0);
1205
1209
}
1206
1210
 
1207
1211
 
1611
1615
 
1612
1616
void Item_in_optimizer::cleanup()
1613
1617
{
1614
 
  Item_bool_func::cleanup();
 
1618
  item::function::Boolean::cleanup();
1615
1619
  if (!save_cache)
1616
1620
    cache= 0;
1617
1621
  return;
1819
1823
          {
1820
1824
            range->type= DECIMAL_RESULT;
1821
1825
            range->dec.init();
1822
 
            my_decimal *dec= el->val_decimal(&range->dec);
 
1826
            type::Decimal *dec= el->val_decimal(&range->dec);
1823
1827
            if (dec != &range->dec)
1824
1828
            {
1825
1829
              range->dec= *dec;
1869
1873
{
1870
1874
  assert(fixed == 1);
1871
1875
  double value;
1872
 
  my_decimal dec_buf, *dec= NULL;
 
1876
  type::Decimal dec_buf, *dec= NULL;
1873
1877
  uint32_t i;
1874
1878
 
1875
1879
  if (use_decimal_comparison)
1877
1881
    dec= row->element_index(0)->val_decimal(&dec_buf);
1878
1882
    if (row->element_index(0)->null_value)
1879
1883
      return -1;
1880
 
    my_decimal2double(E_DEC_FATAL_ERROR, dec, &value);
 
1884
    class_decimal2double(E_DEC_FATAL_ERROR, dec, &value);
1881
1885
  }
1882
1886
  else
1883
1887
  {
1902
1906
        and we are comparing against a decimal
1903
1907
      */
1904
1908
      if (dec && range->type == DECIMAL_RESULT)
1905
 
        cmp_result= my_decimal_cmp(&range->dec, dec) <= 0;
 
1909
        cmp_result= class_decimal_cmp(&range->dec, dec) <= 0;
1906
1910
      else
1907
1911
        cmp_result= (range->dbl <= value);
1908
1912
      if (cmp_result)
1912
1916
    }
1913
1917
    interval_range *range= intervals+start;
1914
1918
    return ((dec && range->type == DECIMAL_RESULT) ?
1915
 
            my_decimal_cmp(dec, &range->dec) < 0 :
 
1919
            class_decimal_cmp(dec, &range->dec) < 0 :
1916
1920
            value < range->dbl) ? 0 : start + 1;
1917
1921
  }
1918
1922
 
1923
1927
        ((el->result_type() == DECIMAL_RESULT) ||
1924
1928
         (el->result_type() == INT_RESULT)))
1925
1929
    {
1926
 
      my_decimal e_dec_buf, *e_dec= el->val_decimal(&e_dec_buf);
 
1930
      type::Decimal e_dec_buf, *e_dec= el->val_decimal(&e_dec_buf);
1927
1931
      /* Skip NULL ranges. */
1928
1932
      if (el->null_value)
1929
1933
        continue;
1930
 
      if (my_decimal_cmp(e_dec, dec) > 0)
 
1934
      if (class_decimal_cmp(e_dec, dec) > 0)
1931
1935
        return i - 1;
1932
1936
    }
1933
1937
    else
2124
2128
  }
2125
2129
  else if (cmp_type == DECIMAL_RESULT)
2126
2130
  {
2127
 
    my_decimal dec_buf, *dec= args[0]->val_decimal(&dec_buf),
 
2131
    type::Decimal dec_buf, *dec= args[0]->val_decimal(&dec_buf),
2128
2132
               a_buf, *a_dec, b_buf, *b_dec;
2129
2133
    if ((null_value=args[0]->null_value))
2130
2134
      return 0;
2131
2135
    a_dec= args[1]->val_decimal(&a_buf);
2132
2136
    b_dec= args[2]->val_decimal(&b_buf);
2133
2137
    if (!args[1]->null_value && !args[2]->null_value)
2134
 
      return (int64_t) ((my_decimal_cmp(dec, a_dec) >= 0 &&
2135
 
                          my_decimal_cmp(dec, b_dec) <= 0) != negated);
 
2138
      return (int64_t) ((class_decimal_cmp(dec, a_dec) >= 0 &&
 
2139
                          class_decimal_cmp(dec, b_dec) <= 0) != negated);
2136
2140
    if (args[1]->null_value && args[2]->null_value)
2137
2141
      null_value=1;
2138
2142
    else if (args[1]->null_value)
2139
 
      null_value= (my_decimal_cmp(dec, b_dec) <= 0);
 
2143
      null_value= (class_decimal_cmp(dec, b_dec) <= 0);
2140
2144
    else
2141
 
      null_value= (my_decimal_cmp(dec, a_dec) >= 0);
 
2145
      null_value= (class_decimal_cmp(dec, a_dec) >= 0);
2142
2146
  }
2143
2147
  else
2144
2148
  {
2272
2276
}
2273
2277
 
2274
2278
 
2275
 
my_decimal *Item_func_ifnull::decimal_op(my_decimal *decimal_value)
 
2279
type::Decimal *Item_func_ifnull::decimal_op(type::Decimal *decimal_value)
2276
2280
{
2277
2281
  assert(fixed == 1);
2278
 
  my_decimal *value= args[0]->val_decimal(decimal_value);
 
2282
  type::Decimal *value= args[0]->val_decimal(decimal_value);
2279
2283
  if (!args[0]->null_value)
2280
2284
  {
2281
2285
    null_value= 0;
2445
2449
}
2446
2450
 
2447
2451
 
2448
 
my_decimal *
2449
 
Item_func_if::val_decimal(my_decimal *decimal_value)
 
2452
type::Decimal *
 
2453
Item_func_if::val_decimal(type::Decimal *decimal_value)
2450
2454
{
2451
2455
  assert(fixed == 1);
2452
2456
  Item *arg= args[0]->val_bool() ? args[1] : args[2];
2453
 
  my_decimal *value= arg->val_decimal(decimal_value);
 
2457
  type::Decimal *value= arg->val_decimal(decimal_value);
2454
2458
  null_value= arg->null_value;
2455
2459
  return value;
2456
2460
}
2530
2534
}
2531
2535
 
2532
2536
 
2533
 
my_decimal *
2534
 
Item_func_nullif::val_decimal(my_decimal * decimal_value)
 
2537
type::Decimal *
 
2538
Item_func_nullif::val_decimal(type::Decimal * decimal_value)
2535
2539
{
2536
2540
  assert(fixed == 1);
2537
 
  my_decimal *res;
 
2541
  type::Decimal *res;
2538
2542
  if (!cmp.compare())
2539
2543
  {
2540
2544
    null_value=1;
2667
2671
}
2668
2672
 
2669
2673
 
2670
 
my_decimal *Item_func_case::val_decimal(my_decimal *decimal_value)
 
2674
type::Decimal *Item_func_case::val_decimal(type::Decimal *decimal_value)
2671
2675
{
2672
2676
  assert(fixed == 1);
2673
2677
  char buff[MAX_FIELD_WIDTH];
2674
2678
  String dummy_str(buff, sizeof(buff), default_charset());
2675
2679
  Item *item= find_item(&dummy_str);
2676
 
  my_decimal *res;
 
2680
  type::Decimal *res;
2677
2681
 
2678
2682
  if (!item)
2679
2683
  {
2716
2720
 
2717
2721
void Item_func_case::agg_num_lengths(Item *arg)
2718
2722
{
2719
 
  uint32_t len= my_decimal_length_to_precision(arg->max_length, arg->decimals,
 
2723
  uint32_t len= class_decimal_length_to_precision(arg->max_length, arg->decimals,
2720
2724
                                           arg->unsigned_flag) - arg->decimals;
2721
2725
  set_if_bigger(max_length, len);
2722
2726
  set_if_bigger(decimals, arg->decimals);
2799
2803
      agg_num_lengths(args[i + 1]);
2800
2804
    if (else_expr_num != -1)
2801
2805
      agg_num_lengths(args[else_expr_num]);
2802
 
    max_length= my_decimal_precision_to_length(max_length + decimals, decimals,
 
2806
    max_length= class_decimal_precision_to_length(max_length + decimals, decimals,
2803
2807
                                               unsigned_flag);
2804
2808
  }
2805
2809
}
2906
2910
}
2907
2911
 
2908
2912
 
2909
 
my_decimal *Item_func_coalesce::decimal_op(my_decimal *decimal_value)
 
2913
type::Decimal *Item_func_coalesce::decimal_op(type::Decimal *decimal_value)
2910
2914
{
2911
2915
  assert(fixed == 1);
2912
2916
  null_value= 0;
2913
2917
  for (uint32_t i= 0; i < arg_count; i++)
2914
2918
  {
2915
 
    my_decimal *res= args[i]->val_decimal(decimal_value);
 
2919
    type::Decimal *res= args[i]->val_decimal(decimal_value);
2916
2920
    if (!args[i]->null_value)
2917
2921
      return res;
2918
2922
  }
3061
3065
}
3062
3066
 
3063
3067
 
3064
 
static int cmp_decimal(void *, my_decimal *a, my_decimal *b)
 
3068
static int cmp_decimal(void *, type::Decimal *a, type::Decimal *b)
3065
3069
{
3066
3070
  /*
3067
3071
    We need call of fixing buffer pointer, because fast sort just copy
3069
3073
  */
3070
3074
  a->fix_buffer_pointer();
3071
3075
  b->fix_buffer_pointer();
3072
 
  return my_decimal_cmp(a, b);
 
3076
  return class_decimal_cmp(a, b);
3073
3077
}
3074
3078
 
3075
3079
 
3238
3242
 
3239
3243
 
3240
3244
in_decimal::in_decimal(uint32_t elements)
3241
 
  :in_vector(elements, sizeof(my_decimal),(qsort2_cmp) cmp_decimal, 0)
 
3245
  :in_vector(elements, sizeof(type::Decimal),(qsort2_cmp) cmp_decimal, 0)
3242
3246
{}
3243
3247
 
3244
3248
 
3245
3249
void in_decimal::set(uint32_t pos, Item *item)
3246
3250
{
3247
 
  /* as far as 'item' is constant, we can store reference on my_decimal */
3248
 
  my_decimal *dec= ((my_decimal *)base) + pos;
 
3251
  /* as far as 'item' is constant, we can store reference on type::Decimal */
 
3252
  type::Decimal *dec= ((type::Decimal *)base) + pos;
3249
3253
  dec->len= DECIMAL_BUFF_LENGTH;
3250
3254
  dec->fix_buffer_pointer();
3251
 
  my_decimal *res= item->val_decimal(dec);
 
3255
  type::Decimal *res= item->val_decimal(dec);
3252
3256
  /* if item->val_decimal() is evaluated to NULL then res == 0 */
3253
3257
  if (!item->null_value && res != dec)
3254
 
    my_decimal2decimal(res, dec);
 
3258
    class_decimal2decimal(res, dec);
3255
3259
}
3256
3260
 
3257
3261
 
3258
3262
unsigned char *in_decimal::get_value(Item *item)
3259
3263
{
3260
 
  my_decimal *result= item->val_decimal(&val);
 
3264
  type::Decimal *result= item->val_decimal(&val);
3261
3265
  if (item->null_value)
3262
3266
    return 0;
3263
3267
  return (unsigned char *)result;
3416
3420
 
3417
3421
void cmp_item_decimal::store_value(Item *item)
3418
3422
{
3419
 
  my_decimal *val= item->val_decimal(&value);
 
3423
  type::Decimal *val= item->val_decimal(&value);
3420
3424
  /* val may be zero if item is nnull */
3421
3425
  if (val && val != &value)
3422
 
    my_decimal2decimal(val, &value);
 
3426
    class_decimal2decimal(val, &value);
3423
3427
}
3424
3428
 
3425
3429
 
3426
3430
int cmp_item_decimal::cmp(Item *arg)
3427
3431
{
3428
 
  my_decimal tmp_buf, *tmp= arg->val_decimal(&tmp_buf);
 
3432
  type::Decimal tmp_buf, *tmp= arg->val_decimal(&tmp_buf);
3429
3433
  if (arg->null_value)
3430
3434
    return 1;
3431
 
  return my_decimal_cmp(&value, tmp);
 
3435
  return class_decimal_cmp(&value, tmp);
3432
3436
}
3433
3437
 
3434
3438
 
3435
3439
int cmp_item_decimal::compare(cmp_item *arg)
3436
3440
{
3437
3441
  cmp_item_decimal *l_cmp= (cmp_item_decimal*) arg;
3438
 
  return my_decimal_cmp(&value, &l_cmp->value);
 
3442
  return class_decimal_cmp(&value, &l_cmp->value);
3439
3443
}
3440
3444
 
3441
3445
 
3849
3853
 
3850
3854
 
3851
3855
Item_cond::Item_cond(Session *session, Item_cond *item)
3852
 
  :Item_bool_func(session, item),
 
3856
  :item::function::Boolean(session, item),
3853
3857
   abort_on_null(item->abort_on_null),
3854
3858
   and_tables_cache(item->and_tables_cache)
3855
3859
{
4882
4886
}
4883
4887
 
4884
4888
Item_equal::Item_equal(Item_field *f1, Item_field *f2)
4885
 
  : Item_bool_func(), const_item(0), eval_item(0), cond_false(0)
 
4889
  : item::function::Boolean(), const_item(0), eval_item(0), cond_false(0)
4886
4890
{
4887
4891
  const_item_cache= 0;
4888
4892
  fields.push_back(f1);
4890
4894
}
4891
4895
 
4892
4896
Item_equal::Item_equal(Item *c, Item_field *f)
4893
 
  : Item_bool_func(), eval_item(0), cond_false(0)
 
4897
  : item::function::Boolean(), eval_item(0), cond_false(0)
4894
4898
{
4895
4899
  const_item_cache= 0;
4896
4900
  fields.push_back(f);
4899
4903
 
4900
4904
 
4901
4905
Item_equal::Item_equal(Item_equal *item_equal)
4902
 
  : Item_bool_func(), eval_item(0), cond_false(0)
 
4906
  : item::function::Boolean(), eval_item(0), cond_false(0)
4903
4907
{
4904
4908
  const_item_cache= 0;
4905
4909
  List_iterator_fast<Item_field> li(item_equal->fields);