~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/cmpfunc.cc

  • Committer: Monty Taylor
  • Date: 2010-12-27 19:41:48 UTC
  • mfrom: (2035 staging)
  • mto: This revision was merged to the branch mainline in revision 2038.
  • Revision ID: mordred@inaugust.com-20101227194148-nqd86au4o76pdltw
Merged trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
702
702
{
703
703
  uint64_t value= 0;
704
704
  int error;
705
 
  DRIZZLE_TIME l_time;
 
705
  type::Time l_time;
706
706
  enum enum_drizzle_timestamp_type ret;
707
707
 
708
708
  ret= str_to_datetime(str->ptr(), str->length(), &l_time,
1173
1173
 
1174
1174
int Arg_comparator::compare_decimal()
1175
1175
{
1176
 
  my_decimal value1;
1177
 
  my_decimal *val1= (*a)->val_decimal(&value1);
 
1176
  type::Decimal value1;
 
1177
  type::Decimal *val1= (*a)->val_decimal(&value1);
1178
1178
  if (!(*a)->null_value)
1179
1179
  {
1180
 
    my_decimal value2;
1181
 
    my_decimal *val2= (*b)->val_decimal(&value2);
 
1180
    type::Decimal value2;
 
1181
    type::Decimal *val2= (*b)->val_decimal(&value2);
1182
1182
    if (!(*b)->null_value)
1183
1183
    {
1184
1184
      owner->null_value= 0;
1185
 
      return my_decimal_cmp(val1, val2);
 
1185
      return class_decimal_cmp(val1, val2);
1186
1186
    }
1187
1187
  }
1188
1188
  owner->null_value= 1;
1200
1200
 
1201
1201
int Arg_comparator::compare_e_decimal()
1202
1202
{
1203
 
  my_decimal value1, value2;
1204
 
  my_decimal *val1= (*a)->val_decimal(&value1);
1205
 
  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);
1206
1206
  if ((*a)->null_value || (*b)->null_value)
1207
1207
    return test((*a)->null_value && (*b)->null_value);
1208
 
  return test(my_decimal_cmp(val1, val2) == 0);
 
1208
  return test(class_decimal_cmp(val1, val2) == 0);
1209
1209
}
1210
1210
 
1211
1211
 
1823
1823
          {
1824
1824
            range->type= DECIMAL_RESULT;
1825
1825
            range->dec.init();
1826
 
            my_decimal *dec= el->val_decimal(&range->dec);
 
1826
            type::Decimal *dec= el->val_decimal(&range->dec);
1827
1827
            if (dec != &range->dec)
1828
1828
            {
1829
1829
              range->dec= *dec;
1873
1873
{
1874
1874
  assert(fixed == 1);
1875
1875
  double value;
1876
 
  my_decimal dec_buf, *dec= NULL;
 
1876
  type::Decimal dec_buf, *dec= NULL;
1877
1877
  uint32_t i;
1878
1878
 
1879
1879
  if (use_decimal_comparison)
1881
1881
    dec= row->element_index(0)->val_decimal(&dec_buf);
1882
1882
    if (row->element_index(0)->null_value)
1883
1883
      return -1;
1884
 
    my_decimal2double(E_DEC_FATAL_ERROR, dec, &value);
 
1884
    class_decimal2double(E_DEC_FATAL_ERROR, dec, &value);
1885
1885
  }
1886
1886
  else
1887
1887
  {
1906
1906
        and we are comparing against a decimal
1907
1907
      */
1908
1908
      if (dec && range->type == DECIMAL_RESULT)
1909
 
        cmp_result= my_decimal_cmp(&range->dec, dec) <= 0;
 
1909
        cmp_result= class_decimal_cmp(&range->dec, dec) <= 0;
1910
1910
      else
1911
1911
        cmp_result= (range->dbl <= value);
1912
1912
      if (cmp_result)
1916
1916
    }
1917
1917
    interval_range *range= intervals+start;
1918
1918
    return ((dec && range->type == DECIMAL_RESULT) ?
1919
 
            my_decimal_cmp(dec, &range->dec) < 0 :
 
1919
            class_decimal_cmp(dec, &range->dec) < 0 :
1920
1920
            value < range->dbl) ? 0 : start + 1;
1921
1921
  }
1922
1922
 
1927
1927
        ((el->result_type() == DECIMAL_RESULT) ||
1928
1928
         (el->result_type() == INT_RESULT)))
1929
1929
    {
1930
 
      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);
1931
1931
      /* Skip NULL ranges. */
1932
1932
      if (el->null_value)
1933
1933
        continue;
1934
 
      if (my_decimal_cmp(e_dec, dec) > 0)
 
1934
      if (class_decimal_cmp(e_dec, dec) > 0)
1935
1935
        return i - 1;
1936
1936
    }
1937
1937
    else
2128
2128
  }
2129
2129
  else if (cmp_type == DECIMAL_RESULT)
2130
2130
  {
2131
 
    my_decimal dec_buf, *dec= args[0]->val_decimal(&dec_buf),
 
2131
    type::Decimal dec_buf, *dec= args[0]->val_decimal(&dec_buf),
2132
2132
               a_buf, *a_dec, b_buf, *b_dec;
2133
2133
    if ((null_value=args[0]->null_value))
2134
2134
      return 0;
2135
2135
    a_dec= args[1]->val_decimal(&a_buf);
2136
2136
    b_dec= args[2]->val_decimal(&b_buf);
2137
2137
    if (!args[1]->null_value && !args[2]->null_value)
2138
 
      return (int64_t) ((my_decimal_cmp(dec, a_dec) >= 0 &&
2139
 
                          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);
2140
2140
    if (args[1]->null_value && args[2]->null_value)
2141
2141
      null_value=1;
2142
2142
    else if (args[1]->null_value)
2143
 
      null_value= (my_decimal_cmp(dec, b_dec) <= 0);
 
2143
      null_value= (class_decimal_cmp(dec, b_dec) <= 0);
2144
2144
    else
2145
 
      null_value= (my_decimal_cmp(dec, a_dec) >= 0);
 
2145
      null_value= (class_decimal_cmp(dec, a_dec) >= 0);
2146
2146
  }
2147
2147
  else
2148
2148
  {
2276
2276
}
2277
2277
 
2278
2278
 
2279
 
my_decimal *Item_func_ifnull::decimal_op(my_decimal *decimal_value)
 
2279
type::Decimal *Item_func_ifnull::decimal_op(type::Decimal *decimal_value)
2280
2280
{
2281
2281
  assert(fixed == 1);
2282
 
  my_decimal *value= args[0]->val_decimal(decimal_value);
 
2282
  type::Decimal *value= args[0]->val_decimal(decimal_value);
2283
2283
  if (!args[0]->null_value)
2284
2284
  {
2285
2285
    null_value= 0;
2449
2449
}
2450
2450
 
2451
2451
 
2452
 
my_decimal *
2453
 
Item_func_if::val_decimal(my_decimal *decimal_value)
 
2452
type::Decimal *
 
2453
Item_func_if::val_decimal(type::Decimal *decimal_value)
2454
2454
{
2455
2455
  assert(fixed == 1);
2456
2456
  Item *arg= args[0]->val_bool() ? args[1] : args[2];
2457
 
  my_decimal *value= arg->val_decimal(decimal_value);
 
2457
  type::Decimal *value= arg->val_decimal(decimal_value);
2458
2458
  null_value= arg->null_value;
2459
2459
  return value;
2460
2460
}
2534
2534
}
2535
2535
 
2536
2536
 
2537
 
my_decimal *
2538
 
Item_func_nullif::val_decimal(my_decimal * decimal_value)
 
2537
type::Decimal *
 
2538
Item_func_nullif::val_decimal(type::Decimal * decimal_value)
2539
2539
{
2540
2540
  assert(fixed == 1);
2541
 
  my_decimal *res;
 
2541
  type::Decimal *res;
2542
2542
  if (!cmp.compare())
2543
2543
  {
2544
2544
    null_value=1;
2671
2671
}
2672
2672
 
2673
2673
 
2674
 
my_decimal *Item_func_case::val_decimal(my_decimal *decimal_value)
 
2674
type::Decimal *Item_func_case::val_decimal(type::Decimal *decimal_value)
2675
2675
{
2676
2676
  assert(fixed == 1);
2677
2677
  char buff[MAX_FIELD_WIDTH];
2678
2678
  String dummy_str(buff, sizeof(buff), default_charset());
2679
2679
  Item *item= find_item(&dummy_str);
2680
 
  my_decimal *res;
 
2680
  type::Decimal *res;
2681
2681
 
2682
2682
  if (!item)
2683
2683
  {
2720
2720
 
2721
2721
void Item_func_case::agg_num_lengths(Item *arg)
2722
2722
{
2723
 
  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,
2724
2724
                                           arg->unsigned_flag) - arg->decimals;
2725
2725
  set_if_bigger(max_length, len);
2726
2726
  set_if_bigger(decimals, arg->decimals);
2803
2803
      agg_num_lengths(args[i + 1]);
2804
2804
    if (else_expr_num != -1)
2805
2805
      agg_num_lengths(args[else_expr_num]);
2806
 
    max_length= my_decimal_precision_to_length(max_length + decimals, decimals,
 
2806
    max_length= class_decimal_precision_to_length(max_length + decimals, decimals,
2807
2807
                                               unsigned_flag);
2808
2808
  }
2809
2809
}
2910
2910
}
2911
2911
 
2912
2912
 
2913
 
my_decimal *Item_func_coalesce::decimal_op(my_decimal *decimal_value)
 
2913
type::Decimal *Item_func_coalesce::decimal_op(type::Decimal *decimal_value)
2914
2914
{
2915
2915
  assert(fixed == 1);
2916
2916
  null_value= 0;
2917
2917
  for (uint32_t i= 0; i < arg_count; i++)
2918
2918
  {
2919
 
    my_decimal *res= args[i]->val_decimal(decimal_value);
 
2919
    type::Decimal *res= args[i]->val_decimal(decimal_value);
2920
2920
    if (!args[i]->null_value)
2921
2921
      return res;
2922
2922
  }
3065
3065
}
3066
3066
 
3067
3067
 
3068
 
static int cmp_decimal(void *, my_decimal *a, my_decimal *b)
 
3068
static int cmp_decimal(void *, type::Decimal *a, type::Decimal *b)
3069
3069
{
3070
3070
  /*
3071
3071
    We need call of fixing buffer pointer, because fast sort just copy
3073
3073
  */
3074
3074
  a->fix_buffer_pointer();
3075
3075
  b->fix_buffer_pointer();
3076
 
  return my_decimal_cmp(a, b);
 
3076
  return class_decimal_cmp(a, b);
3077
3077
}
3078
3078
 
3079
3079
 
3242
3242
 
3243
3243
 
3244
3244
in_decimal::in_decimal(uint32_t elements)
3245
 
  :in_vector(elements, sizeof(my_decimal),(qsort2_cmp) cmp_decimal, 0)
 
3245
  :in_vector(elements, sizeof(type::Decimal),(qsort2_cmp) cmp_decimal, 0)
3246
3246
{}
3247
3247
 
3248
3248
 
3249
3249
void in_decimal::set(uint32_t pos, Item *item)
3250
3250
{
3251
 
  /* as far as 'item' is constant, we can store reference on my_decimal */
3252
 
  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;
3253
3253
  dec->len= DECIMAL_BUFF_LENGTH;
3254
3254
  dec->fix_buffer_pointer();
3255
 
  my_decimal *res= item->val_decimal(dec);
 
3255
  type::Decimal *res= item->val_decimal(dec);
3256
3256
  /* if item->val_decimal() is evaluated to NULL then res == 0 */
3257
3257
  if (!item->null_value && res != dec)
3258
 
    my_decimal2decimal(res, dec);
 
3258
    class_decimal2decimal(res, dec);
3259
3259
}
3260
3260
 
3261
3261
 
3262
3262
unsigned char *in_decimal::get_value(Item *item)
3263
3263
{
3264
 
  my_decimal *result= item->val_decimal(&val);
 
3264
  type::Decimal *result= item->val_decimal(&val);
3265
3265
  if (item->null_value)
3266
3266
    return 0;
3267
3267
  return (unsigned char *)result;
3420
3420
 
3421
3421
void cmp_item_decimal::store_value(Item *item)
3422
3422
{
3423
 
  my_decimal *val= item->val_decimal(&value);
 
3423
  type::Decimal *val= item->val_decimal(&value);
3424
3424
  /* val may be zero if item is nnull */
3425
3425
  if (val && val != &value)
3426
 
    my_decimal2decimal(val, &value);
 
3426
    class_decimal2decimal(val, &value);
3427
3427
}
3428
3428
 
3429
3429
 
3430
3430
int cmp_item_decimal::cmp(Item *arg)
3431
3431
{
3432
 
  my_decimal tmp_buf, *tmp= arg->val_decimal(&tmp_buf);
 
3432
  type::Decimal tmp_buf, *tmp= arg->val_decimal(&tmp_buf);
3433
3433
  if (arg->null_value)
3434
3434
    return 1;
3435
 
  return my_decimal_cmp(&value, tmp);
 
3435
  return class_decimal_cmp(&value, tmp);
3436
3436
}
3437
3437
 
3438
3438
 
3439
3439
int cmp_item_decimal::compare(cmp_item *arg)
3440
3440
{
3441
3441
  cmp_item_decimal *l_cmp= (cmp_item_decimal*) arg;
3442
 
  return my_decimal_cmp(&value, &l_cmp->value);
 
3442
  return class_decimal_cmp(&value, &l_cmp->value);
3443
3443
}
3444
3444
 
3445
3445