diff --git a/mysql-test/r/ctype_ucs.result b/mysql-test/r/ctype_ucs.result index f16524c020b..811696ef052 100644 --- a/mysql-test/r/ctype_ucs.result +++ b/mysql-test/r/ctype_ucs.result @@ -464,3 +464,9 @@ HEX(a) AAAA 000AAAAA DROP TABLE t1; +create table t1 (s1 char character set `ucs2` collate `ucs2_czech_ci`); +insert into t1 values ('0'),('1'),('2'),('a'),('b'),('c'); +select s1 from t1 where s1 > 'a' order by s1; +s1 +b +c diff --git a/mysql-test/t/ctype_ucs.test b/mysql-test/t/ctype_ucs.test index b8574fb7623..188ef571f7e 100644 --- a/mysql-test/t/ctype_ucs.test +++ b/mysql-test/t/ctype_ucs.test @@ -293,3 +293,14 @@ SELECT HEX(a) FROM t1; DROP TABLE t1; -- the same should be also done with enum and set + + +# +# Bug #5024 Server crashes with queries on fields +# with certain charset/collation settings +# + +create table t1 (s1 char character set `ucs2` collate `ucs2_czech_ci`); +insert into t1 values ('0'),('1'),('2'),('a'),('b'),('c'); +select s1 from t1 where s1 > 'a' order by s1; + diff --git a/sql/item.cc b/sql/item.cc index 658f5c42a43..c85aee724cb 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -176,10 +176,15 @@ void Item::set_name(const char *str, uint length, CHARSET_INFO *cs) name= (char*) str; return; } - while (length && !my_isgraph(cs,*str)) - { // Fix problem with yacc - length--; - str++; + if (cs->ctype) + { + // This will probably need a better implementation in the future: + // a function in CHARSET_INFO structure. + while (length && !my_isgraph(cs,*str)) + { // Fix problem with yacc + length--; + str++; + } } if (!my_charset_same(cs, system_charset_info)) {