~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item_func.cc

  • Committer: Brian Aker
  • Date: 2008-10-06 06:47:29 UTC
  • Revision ID: brian@tangent.org-20081006064729-2i9mhjkzyvow9xsm
RemoveĀ uint.

Show diffs side-by-side

added added

removed removed

Lines of Context:
359
359
{
360
360
  used_tables_cache=0;
361
361
  const_item_cache=1;
362
 
  for (uint i=0 ; i < arg_count ; i++)
 
362
  for (uint32_t i=0 ; i < arg_count ; i++)
363
363
  {
364
364
    args[i]->update_used_tables();
365
365
    used_tables_cache|=args[i]->used_tables();
389
389
}
390
390
 
391
391
 
392
 
void Item_func::print_args(String *str, uint from, enum_query_type query_type)
 
392
void Item_func::print_args(String *str, uint32_t from, enum_query_type query_type)
393
393
{
394
 
  for (uint i=from ; i < arg_count ; i++)
 
394
  for (uint32_t i=from ; i < arg_count ; i++)
395
395
  {
396
396
    if (i != from)
397
397
      str->append(',');
403
403
void Item_func::print_op(String *str, enum_query_type query_type)
404
404
{
405
405
  str->append('(');
406
 
  for (uint i=0 ; i < arg_count-1 ; i++)
 
406
  for (uint32_t i=0 ; i < arg_count-1 ; i++)
407
407
  {
408
408
    args[i]->print(str, query_type);
409
409
    str->append(' ');
431
431
      (func_type == Item_func::FUNC_SP &&
432
432
       my_strcasecmp(system_charset_info, func_name(), item_func->func_name())))
433
433
    return 0;
434
 
  for (uint i=0; i < arg_count ; i++)
 
434
  for (uint32_t i=0; i < arg_count ; i++)
435
435
    if (!args[i]->eq(item_func->args[i], binary_cmp))
436
436
      return 0;
437
437
  return 1;
506
506
 
507
507
void Item_func::fix_num_length_and_dec()
508
508
{
509
 
  uint fl_length= 0;
 
509
  uint32_t fl_length= 0;
510
510
  decimals=0;
511
 
  for (uint i=0 ; i < arg_count ; i++)
 
511
  for (uint32_t i=0 ; i < arg_count ; i++)
512
512
  {
513
513
    set_if_bigger(decimals,args[i]->decimals);
514
514
    set_if_bigger(fl_length, args[i]->max_length);
536
536
  int max_int_part= 0;
537
537
  decimals= 0;
538
538
  unsigned_flag= 1;
539
 
  for (uint i=0 ; i < arg_count ; i++)
 
539
  for (uint32_t i=0 ; i < arg_count ; i++)
540
540
  {
541
541
    set_if_bigger(decimals, args[i]->decimals);
542
542
    set_if_bigger(max_int_part, args[i]->decimal_int_part());
556
556
{
557
557
  max_length= 0;
558
558
  unsigned_flag= 0;
559
 
  for (uint i=0 ; i < arg_count ; i++)
 
559
  for (uint32_t i=0 ; i < arg_count ; i++)
560
560
  {
561
561
    set_if_bigger(max_length, args[i]->max_length);
562
562
    set_if_bigger(unsigned_flag, args[i]->unsigned_flag);
574
574
  uint32_t length= 0;
575
575
  decimals= 0;
576
576
  max_length= 0;
577
 
  for (uint i=0 ; i < arg_count ; i++)
 
577
  for (uint32_t i=0 ; i < arg_count ; i++)
578
578
  {
579
579
    if (decimals != NOT_FIXED_DEC)
580
580
    {
1014
1014
{
1015
1015
  my_decimal tmp_buf, *tmp= args[0]->val_decimal(&tmp_buf);
1016
1016
  bool sign;
1017
 
  uint precision;
 
1017
  uint32_t precision;
1018
1018
 
1019
1019
  if ((null_value= args[0]->null_value))
1020
1020
    return NULL;
1052
1052
  char len_buf[20*3 + 1];
1053
1053
  char *end;
1054
1054
 
1055
 
  uint precision= my_decimal_length_to_precision(max_length, decimals,
 
1055
  uint32_t precision= my_decimal_length_to_precision(max_length, decimals,
1056
1056
                                                 unsigned_flag);
1057
1057
  str->append(STRING_WITH_LEN("cast("));
1058
1058
  args[0]->print(str, query_type);
1281
1281
 
1282
1282
void Item_func_div::result_precision()
1283
1283
{
1284
 
  uint precision=cmin(args[0]->decimal_precision() + prec_increment,
 
1284
  uint32_t precision=cmin(args[0]->decimal_precision() + prec_increment,
1285
1285
                     (unsigned int)DECIMAL_MAX_PRECISION);
1286
1286
  /* Integer operations keep unsigned_flag if one of arguments is unsigned */
1287
1287
  if (result_type() == INT_RESULT)
1304
1304
    decimals=cmax(args[0]->decimals,args[1]->decimals)+prec_increment;
1305
1305
    set_if_smaller(decimals, NOT_FIXED_DEC);
1306
1306
    max_length=args[0]->max_length - args[0]->decimals + decimals;
1307
 
    uint tmp=float_length(decimals);
 
1307
    uint32_t tmp=float_length(decimals);
1308
1308
    set_if_smaller(max_length,tmp);
1309
1309
    break;
1310
1310
  }
1715
1715
int64_t Item_func_shift_left::val_int()
1716
1716
{
1717
1717
  assert(fixed == 1);
1718
 
  uint shift;
 
1718
  uint32_t shift;
1719
1719
  uint64_t res= ((uint64_t) args[0]->val_int() <<
1720
1720
                  (shift=(uint) args[1]->val_int()));
1721
1721
  if (args[0]->null_value || args[1]->null_value)
1730
1730
int64_t Item_func_shift_right::val_int()
1731
1731
{
1732
1732
  assert(fixed == 1);
1733
 
  uint shift;
 
1733
  uint32_t shift;
1734
1734
  uint64_t res= (uint64_t) args[0]->val_int() >>
1735
1735
    (shift=(uint) args[1]->val_int());
1736
1736
  if (args[0]->null_value || args[1]->null_value)
1758
1758
void Item_func_integer::fix_length_and_dec()
1759
1759
{
1760
1760
  max_length=args[0]->max_length - args[0]->decimals+1;
1761
 
  uint tmp=float_length(decimals);
 
1761
  uint32_t tmp=float_length(decimals);
1762
1762
  set_if_smaller(max_length,tmp);
1763
1763
  decimals=0;
1764
1764
}
1768
1768
  max_length= args[0]->max_length - (args[0]->decimals ?
1769
1769
                                     args[0]->decimals + 1 :
1770
1770
                                     0) + 2;
1771
 
  uint tmp= float_length(decimals);
 
1771
  uint32_t tmp= float_length(decimals);
1772
1772
  set_if_smaller(max_length,tmp);
1773
1773
  decimals= 0;
1774
1774
}
2170
2170
  maybe_null=0;
2171
2171
  cmp_type=args[0]->result_type();
2172
2172
 
2173
 
  for (uint i=0 ; i < arg_count ; i++)
 
2173
  for (uint32_t i=0 ; i < arg_count ; i++)
2174
2174
  {
2175
2175
    set_if_bigger(max_length, args[i]->max_length);
2176
2176
    set_if_bigger(decimals, args[i]->decimals);
2219
2219
   #    index of the least/greatest argument
2220
2220
*/
2221
2221
 
2222
 
uint Item_func_min_max::cmp_datetimes(uint64_t *value)
 
2222
uint32_t Item_func_min_max::cmp_datetimes(uint64_t *value)
2223
2223
{
2224
2224
  uint64_t min_max= 0;
2225
 
  uint min_max_idx= 0;
 
2225
  uint32_t min_max_idx= 0;
2226
2226
 
2227
 
  for (uint i=0; i < arg_count ; i++)
 
2227
  for (uint32_t i=0; i < arg_count ; i++)
2228
2228
  {
2229
2229
    Item **arg= args + i;
2230
2230
    bool is_null;
2253
2253
  if (compare_as_dates)
2254
2254
  {
2255
2255
    String *str_res;
2256
 
    uint min_max_idx= cmp_datetimes(NULL);
 
2256
    uint32_t min_max_idx= cmp_datetimes(NULL);
2257
2257
    if (null_value)
2258
2258
      return 0;
2259
2259
    str_res= args[min_max_idx]->val_str(str);
2289
2289
  {
2290
2290
    String *res= NULL;
2291
2291
 
2292
 
    for (uint i=0; i < arg_count ; i++)
 
2292
    for (uint32_t i=0; i < arg_count ; i++)
2293
2293
    {
2294
2294
      if (i == 0)
2295
2295
        res=args[i]->val_str(str);
2330
2330
    (void)cmp_datetimes(&result);
2331
2331
    return (double)result;
2332
2332
  }
2333
 
  for (uint i=0; i < arg_count ; i++)
 
2333
  for (uint32_t i=0; i < arg_count ; i++)
2334
2334
  {
2335
2335
    if (i == 0)
2336
2336
      value= args[i]->val_real();
2357
2357
    (void)cmp_datetimes(&result);
2358
2358
    return (int64_t)result;
2359
2359
  }
2360
 
  for (uint i=0; i < arg_count ; i++)
 
2360
  for (uint32_t i=0; i < arg_count ; i++)
2361
2361
  {
2362
2362
    if (i == 0)
2363
2363
      value=args[i]->val_int();
2386
2386
    uint64_t2decimal(value, dec);
2387
2387
    return dec;
2388
2388
  }
2389
 
  for (uint i=0; i < arg_count ; i++)
 
2389
  for (uint32_t i=0; i < arg_count ; i++)
2390
2390
  {
2391
2391
    if (i == 0)
2392
2392
      res= args[i]->val_decimal(dec);
2525
2525
    String *field;
2526
2526
    if (!(field= args[0]->val_str(&value)))
2527
2527
      return 0;
2528
 
    for (uint i=1 ; i < arg_count ; i++)
 
2528
    for (uint32_t i=1 ; i < arg_count ; i++)
2529
2529
    {
2530
2530
      String *tmp_value=args[i]->val_str(&tmp);
2531
2531
      if (tmp_value && !sortcmp(field,tmp_value,cmp_collation.collation))
2537
2537
    int64_t val= args[0]->val_int();
2538
2538
    if (args[0]->null_value)
2539
2539
      return 0;
2540
 
    for (uint i=1; i < arg_count ; i++)
 
2540
    for (uint32_t i=1; i < arg_count ; i++)
2541
2541
    {
2542
2542
      if (val == args[i]->val_int() && !args[i]->null_value)
2543
2543
        return (int64_t) (i);
2549
2549
               dec_buf, *dec= args[0]->val_decimal(&dec_buf);
2550
2550
    if (args[0]->null_value)
2551
2551
      return 0;
2552
 
    for (uint i=1; i < arg_count; i++)
 
2552
    for (uint32_t i=1; i < arg_count; i++)
2553
2553
    {
2554
2554
      dec_arg= args[i]->val_decimal(&dec_arg_buf);
2555
2555
      if (!args[i]->null_value && !my_decimal_cmp(dec_arg, dec))
2561
2561
    double val= args[0]->val_real();
2562
2562
    if (args[0]->null_value)
2563
2563
      return 0;
2564
 
    for (uint i=1; i < arg_count ; i++)
 
2564
    for (uint32_t i=1; i < arg_count ; i++)
2565
2565
    {
2566
2566
      if (val == args[i]->val_real() && !args[i]->null_value)
2567
2567
        return (int64_t) (i);
2575
2575
{
2576
2576
  maybe_null=0; max_length=3;
2577
2577
  cmp_type= args[0]->result_type();
2578
 
  for (uint i=1; i < arg_count ; i++)
 
2578
  for (uint32_t i=1; i < arg_count ; i++)
2579
2579
    cmp_type= item_cmp_type(cmp_type, args[i]->result_type());
2580
2580
  if (cmp_type == STRING_RESULT)
2581
2581
    agg_arg_charsets(cmp_collation, args, arg_count, MY_COLL_CMP_CONV, 1);
2666
2666
    const char *str_end= buffer->ptr();
2667
2667
    const char *real_end= str_end+buffer->length();
2668
2668
    const unsigned char *find_str= (const unsigned char *) find->ptr();
2669
 
    uint find_str_len= find->length();
 
2669
    uint32_t find_str_len= find->length();
2670
2670
    int position= 0;
2671
2671
    while (1)
2672
2672
    {
2730
2730
  my_thread_id thread_id;
2731
2731
  void set_thread(THD *thd) { thread_id= thd->thread_id; }
2732
2732
 
2733
 
  User_level_lock(const unsigned char *key_arg,uint length, ulong id) 
 
2733
  User_level_lock(const unsigned char *key_arg,uint32_t length, ulong id) 
2734
2734
    :key_length(length),count(1),locked(1), thread_id(id)
2735
2735
  {
2736
2736
    key= (unsigned char*) my_memdup(key_arg,length,MYF(0));
2826
2826
}
2827
2827
 
2828
2828
#ifdef EXTRA_DEBUG
2829
 
void debug_sync_point(const char* lock_name, uint lock_timeout)
 
2829
void debug_sync_point(const char* lock_name, uint32_t lock_timeout)
2830
2830
{
2831
2831
}
2832
2832
 
2938
2938
                                              name.length)) &&
2939
2939
      create_if_not_exists)
2940
2940
  {
2941
 
    uint size=ALIGN_SIZE(sizeof(user_var_entry))+name.length+1+extra_size;
 
2941
    uint32_t size=ALIGN_SIZE(sizeof(user_var_entry))+name.length+1+extra_size;
2942
2942
    if (!hash_inited(hash))
2943
2943
      return 0;
2944
2944
    if (!(entry = (user_var_entry*) my_malloc(size,MYF(MY_WME | ME_FATALERROR))))
3066
3066
*/
3067
3067
 
3068
3068
static bool
3069
 
update_hash(user_var_entry *entry, bool set_null, void *ptr, uint length,
 
3069
update_hash(user_var_entry *entry, bool set_null, void *ptr, uint32_t length,
3070
3070
            Item_result type, const CHARSET_INFO * const cs, Derivation dv,
3071
3071
            bool unsigned_arg)
3072
3072
{
3126
3126
 
3127
3127
 
3128
3128
bool
3129
 
Item_func_set_user_var::update_hash(void *ptr, uint length,
 
3129
Item_func_set_user_var::update_hash(void *ptr, uint32_t length,
3130
3130
                                    Item_result res_type,
3131
3131
                                    const CHARSET_INFO * const cs, Derivation dv,
3132
3132
                                    bool unsigned_arg)
3209
3209
/** Get the value of a variable as a string. */
3210
3210
 
3211
3211
String *user_var_entry::val_str(bool *null_value, String *str,
3212
 
                                uint decimals)
 
3212
                                uint32_t decimals)
3213
3213
{
3214
3214
  if ((*null_value= (value == 0)))
3215
3215
    return (String*) 0;
3726
3726
    return 0;
3727
3727
  }
3728
3728
 
3729
 
  uint size;
 
3729
  uint32_t size;
3730
3730
  /*
3731
3731
    First we need to store value of var_entry, when the next situation
3732
3732
    appears:
3889
3889
}
3890
3890
 
3891
3891
 
3892
 
void Item_user_var_as_out_param::set_value(const char *str, uint length,
 
3892
void Item_user_var_as_out_param::set_value(const char *str, uint32_t length,
3893
3893
                                           const CHARSET_INFO * const cs)
3894
3894
{
3895
3895
  ::update_hash(entry, false, (void*)str, length, STRING_RESULT, cs,