Commit 965afd45 authored by unknown's avatar unknown

func_like.result, func_like.test:

  adding test case.
item_cmpfunc.cc:
  Bug#12611
  ESCAPE + LIKE do not work when the escape char is a multibyte one
  Additional fix for 8bit character sets:
  escape character must be converted into
  operation character set.


sql/item_cmpfunc.cc:
  Bug#12611
  ESCAPE + LIKE do not work when the escape char is a multibyte one
  Additional fix for 8bit character sets:
  escape character must be converted into
  operation character set.
mysql-test/t/func_like.test:
  adding test case.
mysql-test/r/func_like.result:
  adding test case.
parent e254105b
......@@ -158,3 +158,10 @@ DROP TABLE t1;
select _cp866'aaaaaaaaa' like _cp866'%aaaa%' collate cp866_bin;
_cp866'aaaaaaaaa' like _cp866'%aaaa%' collate cp866_bin
1
set names koi8r;
select 'andre%' like 'andre%' escape '';
'andre%' like 'andre%' escape ''
1
select _cp1251'andre%' like convert('andre%' using cp1251) escape '';
_cp1251'andre%' like convert('andre%' using cp1251) escape ''
1
......@@ -96,4 +96,21 @@ DROP TABLE t1;
#
select _cp866'aaaaaaaaa' like _cp866'%aaaa%' collate cp866_bin;
#
# Check 8bit escape character
#
set names koi8r;
select 'andre%' like 'andre%' escape '';
# Check 8bit escape character with charset conversion:
# For "a LIKE b ESCAPE c" expressions,
# escape character is converted into the operation character set,
# which is result of aggregation of character sets of "a" and "b".
# "c" itself doesn't take part in aggregation, because its collation
# doesn't matter, escape character is always compared binary.
# In the example below, escape character is converted from koi8r into cp1251:
#
select _cp1251'andre%' like convert('andre%' using cp1251) escape '';
#
# End of 4.1 tests
......@@ -2307,7 +2307,24 @@ bool Item_func_like::fix_fields(THD *thd, TABLE_LIST *tlist, Item ** ref)
}
else
{
escape= *(escape_str->ptr());
/*
In the case of 8bit character set, we pass native
code instead of Unicode code as "escape" argument.
Convert to "cs" if charset of escape differs.
*/
uint32 unused;
if (escape_str->needs_conversion(escape_str->length(),
escape_str->charset(), cs, &unused))
{
char ch;
uint errors;
uint32 cnvlen= copy_and_convert(&ch, 1, cs, escape_str->ptr(),
escape_str->length(),
escape_str->charset(), &errors);
escape= cnvlen ? ch : '\\';
}
else
escape= *(escape_str->ptr());
}
}
else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment