Commit e2cfe7b6 authored by unknown's avatar unknown

ctype_utf8.result, ctype_utf8.test, item_strfunc.cc:

  LEFT() didn't work well in some cases.


sql/item_strfunc.cc:
  LEFT() didn't work well in some cases.
mysql-test/t/ctype_utf8.test:
  LEFT() didn't work well in some cases.
mysql-test/r/ctype_utf8.result:
  LEFT() didn't work well in some cases.
parent da60f197
......@@ -93,6 +93,9 @@ this is a test
select insert("aa",100,1,"b"),insert("aa",1,3,"b");
insert("aa",100,1,"b") insert("aa",1,3,"b")
aa b
select char_length(left(@a:='тест',5)), length(@a), @a;
char_length(left(@a:='тест',5)) length(@a) @a
4 8 тест
create table t1 select date_format("2004-01-19 10:10:10", "%Y-%m-%d");
show create table t1;
Table Create Table
......
......@@ -62,6 +62,12 @@ DROP TABLE t1;
select insert('txs',2,1,'hi'),insert('is ',4,0,'a'),insert('txxxxt',2,4,'es');
select insert("aa",100,1,"b"),insert("aa",1,3,"b");
#
# LELF() didn't work well with utf8 in some cases too.
#
select char_length(left(@a:='тест',5)), length(@a), @a;
#
# CREATE ... SELECT
#
......
......@@ -977,17 +977,19 @@ String *Item_func_left::val_str(String *str)
DBUG_ASSERT(fixed == 1);
String *res =args[0]->val_str(str);
long length =(long) args[1]->val_int();
uint char_pos;
if ((null_value=args[0]->null_value))
return 0;
if (length <= 0)
return &my_empty_string;
if (res->length() <= (uint) length)
if (res->length() <= (uint) length ||
res->length() <= (char_pos= res->charpos(length)))
return res;
if (&str_value == res)
str_value.length(res->charpos(length));
str_value.length(char_pos);
else
str_value.set(*res, 0, res->charpos(length));
str_value.set(*res, 0, char_pos);
return &str_value;
}
......
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