From 44bffa0b0564a0d28558202d6cebbbea5eee1729 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 19 Sep 2003 15:18:19 +0500 Subject: Fixed that multibyte charsets didn't honor multibyte sequence boundaries in functions LIKE and LOCATE in the case of "binary" collation. Comparison was done like if the strings were just a binary strings without character set assumption. --- sql/item_func.cc | 54 ++++++++++++------------------------------------------ 1 file changed, 12 insertions(+), 42 deletions(-) (limited to 'sql/item_func.cc') diff --git a/sql/item_func.cc b/sql/item_func.cc index fe419745b60..35df0dbe40d 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -1153,7 +1153,6 @@ longlong Item_func_locate::val_int() { String *a=args[0]->val_str(&value1); String *b=args[1]->val_str(&value2); - bool binary_cmp= (cmp_collation.collation->state & MY_CS_BINSORT) ? 1 : 0; if (!a || !b) { null_value=1; @@ -1161,55 +1160,26 @@ longlong Item_func_locate::val_int() } null_value=0; uint start=0; -#ifdef USE_MB uint start0=0; -#endif + int ind; + if (arg_count == 3) { - start=(uint) args[2]->val_int()-1; -#ifdef USE_MB - if (use_mb(cmp_collation.collation)) - { - start0=start; - if (!binary_cmp) - start=a->charpos(start); - } -#endif + start0= start =(uint) args[2]->val_int()-1; + start=a->charpos(start); + if (start > a->length() || start+b->length() > a->length()) return 0; } + if (!b->length()) // Found empty string at start return (longlong) (start+1); -#ifdef USE_MB - if (use_mb(cmp_collation.collation) && !binary_cmp) - { - const char *ptr=a->ptr()+start; - const char *search=b->ptr(); - const char *strend = ptr+a->length(); - const char *end=strend-b->length()+1; - const char *search_end=search+b->length(); - register uint32 l; - while (ptr < end) - { - if (*ptr == *search) - { - register char *i,*j; - i=(char*) ptr+1; j=(char*) search+1; - while (j != search_end) - if (*i++ != *j++) goto skipp; - return (longlong) start0+1; - } - skipp: - if ((l=my_ismbchar(cmp_collation.collation,ptr,strend))) - ptr+=l; - else ++ptr; - ++start0; - } - return 0; - } -#endif /* USE_MB */ - return (longlong) (binary_cmp ? a->strstr(*b,start) : - (a->strstr_case(*b,start)))+1; + + ind= cmp_collation.collation->coll->instr(cmp_collation.collation, + a->ptr()+start, a->length()-start, + b->ptr(), b->length()); + + return (longlong) (ind >= 0 ? ind + start0 + 1 : ind + 1); } -- cgit v1.2.1