405
392
return (int64_t) ((unsigned char) (*res)[0]);
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! */
412
void Item_func_find_in_set::fix_length_and_dec()
415
max_length=3; // 1-999
416
agg_arg_charsets(cmp_collation, args, 2, MY_COLL_CMP_CONV, 1);
419
static const char separator=',';
421
int64_t Item_func_find_in_set::val_int()
426
uint64_t tmp=(uint64_t) args[1]->val_int();
427
if (!(null_value=args[1]->null_value || args[0]->null_value))
435
String *find=args[0]->val_str(&value);
436
String *buffer=args[1]->val_str(&value2);
437
if (!find || !buffer)
440
return 0; /* purecov: inspected */
445
if ((diff=buffer->length() - find->length()) >= 0)
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();
458
if ((symbol_len= cs->cset->mb_wc(cs, &wc, (unsigned char*) str_end,
459
(unsigned char*) real_end)) > 0)
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)
467
if (is_last_item && !is_separator)
469
if (!my_strnncoll(cs, (const unsigned char *) str_begin,
471
find_str, find_str_len))
472
return (int64_t) position;
474
str_begin= substr_end;
478
else if (str_end - str_begin == 0 &&
480
wc == (my_wc_t) separator)
481
return (int64_t) ++position;
489
int64_t Item_func_bit_count::val_int()
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);
499
396
** User level locks