~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item_func.cc

code clean move Item_func_ascii, Item_func_bit_count, Item_func_find_in_set, Item_func_ord  to functions directory

Show diffs side-by-side

added added

removed removed

Lines of Context:
366
366
}
367
367
 
368
368
 
369
 
int64_t Item_func_ascii::val_int()
370
 
{
371
 
  assert(fixed == 1);
372
 
  String *res=args[0]->val_str(&value);
373
 
  if (!res)
374
 
  {
375
 
    null_value=1;
376
 
    return 0;
377
 
  }
378
 
  null_value=0;
379
 
  return (int64_t) (res->length() ? (unsigned char) (*res)[0] : (unsigned char) 0);
380
 
}
381
 
 
382
369
int64_t Item_func_ord::val_int()
383
370
{
384
371
  assert(fixed == 1);
405
392
  return (int64_t) ((unsigned char) (*res)[0]);
406
393
}
407
394
 
408
 
        /* Search after a string in a string of strings separated by ',' */
409
 
        /* Returns number of found type >= 1 or 0 if not found */
410
 
        /* This optimizes searching in enums to bit testing! */
411
 
 
412
 
void Item_func_find_in_set::fix_length_and_dec()
413
 
{
414
 
  decimals=0;
415
 
  max_length=3;                                 // 1-999
416
 
  agg_arg_charsets(cmp_collation, args, 2, MY_COLL_CMP_CONV, 1);
417
 
}
418
 
 
419
 
static const char separator=',';
420
 
 
421
 
int64_t Item_func_find_in_set::val_int()
422
 
{
423
 
  assert(fixed == 1);
424
 
  if (enum_value)
425
 
  {
426
 
    uint64_t tmp=(uint64_t) args[1]->val_int();
427
 
    if (!(null_value=args[1]->null_value || args[0]->null_value))
428
 
    {
429
 
      if (tmp & enum_bit)
430
 
        return enum_value;
431
 
    }
432
 
    return 0L;
433
 
  }
434
 
 
435
 
  String *find=args[0]->val_str(&value);
436
 
  String *buffer=args[1]->val_str(&value2);
437
 
  if (!find || !buffer)
438
 
  {
439
 
    null_value=1;
440
 
    return 0; /* purecov: inspected */
441
 
  }
442
 
  null_value=0;
443
 
 
444
 
  int diff;
445
 
  if ((diff=buffer->length() - find->length()) >= 0)
446
 
  {
447
 
    my_wc_t wc;
448
 
    const CHARSET_INFO * const cs= cmp_collation.collation;
449
 
    const char *str_begin= buffer->ptr();
450
 
    const char *str_end= buffer->ptr();
451
 
    const char *real_end= str_end+buffer->length();
452
 
    const unsigned char *find_str= (const unsigned char *) find->ptr();
453
 
    uint32_t find_str_len= find->length();
454
 
    int position= 0;
455
 
    while (1)
456
 
    {
457
 
      int symbol_len;
458
 
      if ((symbol_len= cs->cset->mb_wc(cs, &wc, (unsigned char*) str_end, 
459
 
                                       (unsigned char*) real_end)) > 0)
460
 
      {
461
 
        const char *substr_end= str_end + symbol_len;
462
 
        bool is_last_item= (substr_end == real_end);
463
 
        bool is_separator= (wc == (my_wc_t) separator);
464
 
        if (is_separator || is_last_item)
465
 
        {
466
 
          position++;
467
 
          if (is_last_item && !is_separator)
468
 
            str_end= substr_end;
469
 
          if (!my_strnncoll(cs, (const unsigned char *) str_begin,
470
 
                            str_end - str_begin,
471
 
                            find_str, find_str_len))
472
 
            return (int64_t) position;
473
 
          else
474
 
            str_begin= substr_end;
475
 
        }
476
 
        str_end= substr_end;
477
 
      }
478
 
      else if (str_end - str_begin == 0 &&
479
 
               find_str_len == 0 &&
480
 
               wc == (my_wc_t) separator)
481
 
        return (int64_t) ++position;
482
 
      else
483
 
        return 0L;
484
 
    }
485
 
  }
486
 
  return 0;
487
 
}
488
 
 
489
 
int64_t Item_func_bit_count::val_int()
490
 
{
491
 
  assert(fixed == 1);
492
 
  uint64_t value= (uint64_t) args[0]->val_int();
493
 
  if ((null_value= args[0]->null_value))
494
 
    return 0; /* purecov: inspected */
495
 
  return (int64_t) my_count_bits(value);
496
 
}
497
 
 
498
395
/*
499
396
** User level locks
500
397
*/