21 #include "sql_class.h"
45 static const char field_separator=
',';
47 ulonglong find_set(
TYPELIB *lib,
const char *str, uint length,
49 char **err_pos, uint *err_len,
bool *set_warning)
52 const char *end= str + strip->cset->lengthsp(strip, str, length);
58 const char *start= str;
61 const char *pos= start;
65 if (cs && cs->mbminlen > 1)
67 for ( ; pos < end; pos+= mblen)
70 if ((mblen= cs->cset->mb_wc(cs, &wc, (
const uchar *) pos,
71 (
const uchar *) end)) < 1)
73 if (wc == (my_wc_t) field_separator)
78 for (; pos != end && *pos != field_separator; pos++) ;
79 var_len= (uint) (pos - start);
80 uint find= cs ? find_type2(lib, start, var_len, cs) :
81 find_type(lib, start, var_len, (bool) 0);
82 if (!find && *err_len == 0)
84 *err_pos= (
char*) start;
89 found|= 1ULL << (find - 1);
114 uint find_type(
const TYPELIB *lib,
const char *find, uint length,
117 uint found_count=0, found_pos=0;
118 const char *end= find+length;
121 for (uint pos=0 ; (j=lib->type_names[pos++]) ; )
123 for (i=find ; i != end &&
124 my_toupper(system_charset_info,*i) ==
125 my_toupper(system_charset_info,*j) ; i++, j++) ;
134 return(found_count == 1 && part_match ? found_pos : 0);
155 uint find_type2(
const TYPELIB *typelib,
const char *x, uint length,
160 DBUG_ENTER(
"find_type2");
161 DBUG_PRINT(
"enter",(
"x: '%.*s' lib: 0x%lx", length, x, (
long) typelib));
165 DBUG_PRINT(
"exit",(
"no count"));
169 for (pos=0 ; (j=typelib->type_names[pos]) ; pos++)
171 if (!my_strnncoll(cs, (
const uchar*) x, length,
172 (
const uchar*) j, typelib->type_lengths[pos]))
175 DBUG_PRINT(
"exit",(
"Couldn't find type"));
193 void unhex_type2(
TYPELIB *interval)
195 for (uint pos= 0; pos < interval->count; pos++)
198 for (from= to= (
char*) interval->type_names[pos]; *from; )
208 *to++= (char) (hexchar_to_int(from[0]) << 4) +
209 hexchar_to_int(from[1]);
212 interval->type_lengths[pos] /= 2;
233 uint check_word(
TYPELIB *lib,
const char *val,
const char *end,
234 const char **end_of_word)
240 for (ptr= val ; ptr < end && my_isalpha(&my_charset_latin1, *ptr) ; ptr++)
242 if ((res=find_type(lib, val, (uint) (ptr - val), 1)) > 0)
268 uint strconvert(
CHARSET_INFO *from_cs,
const char *from,
274 uchar *to_end= (uchar*) to + to_length - 1;
275 my_charset_conv_mb_wc mb_wc= from_cs->cset->mb_wc;
276 my_charset_conv_wc_mb wc_mb= to_cs->cset->wc_mb;
287 if ((cnvres= (*mb_wc)(from_cs, &wc,
288 (uchar*) from, (uchar*) from + 10)) > 0)
294 else if (cnvres == MY_CS_ILSEQ)
305 if ((cnvres= (*wc_mb)(to_cs, wc, (uchar*) to, to_end)) > 0)
307 else if (cnvres == MY_CS_ILUNI && wc !=
'?')
317 *errors= error_count;
318 return (uint32) (to - to_start);
343 for (pos= haystack; pos->str; pos++)
344 if (!cs->coll->strnncollsp(cs, (uchar *) pos->str, pos->length,
345 (uchar *) needle->str, needle->length, 0))
347 return (pos - haystack);
353 char *set_to_string(THD *thd,
LEX_STRING *result, ulonglong
set,
356 char buff[STRING_BUFFER_USUAL_SIZE*8];
357 String tmp(buff,
sizeof(buff), &my_charset_latin1);
365 for (uint i= 0;
set; i++,
set >>= 1)
373 result->str= thd->strmake(tmp.ptr(), tmp.length()-1);
374 result->length= tmp.length()-1;
378 result->str=
const_cast<char*
>(
"");
384 char *flagset_to_string(THD *thd,
LEX_STRING *result, ulonglong
set,
387 char buff[STRING_BUFFER_USUAL_SIZE*8];
388 String tmp(buff,
sizeof(buff), &my_charset_latin1);
391 if (!result) result= &unused;
396 for (uint i= 0; lib[i+1]; i++,
set >>= 1)
399 tmp.append(
set & 1 ?
"=on," :
"=off,");
402 result->str= thd->strmake(tmp.ptr(), tmp.length()-1);
403 result->length= tmp.length()-1;