summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <bar@noter.(none)>2005-05-09 20:55:06 +0500
committerunknown <bar@noter.(none)>2005-05-09 20:55:06 +0500
commit61587d17a0f9acc1269a43031b76895d6a80d959 (patch)
tree62cc9154f67665fb008399917539a75e960af706
parent1852f3c7b647179f1b7d5ea27a8dffd8eecbf791 (diff)
downloadmariadb-git-61587d17a0f9acc1269a43031b76895d6a80d959.tar.gz
SUBSTR with negative argument didn't workclone-4.1.12-build
with multi-byte strings, length() instead of numchars() where used in a mistake.
-rw-r--r--mysql-test/r/ctype_utf8.result3
-rw-r--r--mysql-test/t/ctype_utf8.test6
-rw-r--r--sql/item_strfunc.cc2
3 files changed, 10 insertions, 1 deletions
diff --git a/mysql-test/r/ctype_utf8.result b/mysql-test/r/ctype_utf8.result
index 78c56bffbd3..ffdb7cb0f3d 100644
--- a/mysql-test/r/ctype_utf8.result
+++ b/mysql-test/r/ctype_utf8.result
@@ -817,6 +817,9 @@ drop table t1;
select 'c' like '\_' as want0;
want0
0
+SELECT SUBSTR('вася',-2);
+SUBSTR('вася',-2)
+ся
create table t1 (id integer, a varchar(100) character set utf8 collate utf8_unicode_ci);
insert into t1 values (1, 'Test');
select * from t1 where soundex(a) = soundex('Test');
diff --git a/mysql-test/t/ctype_utf8.test b/mysql-test/t/ctype_utf8.test
index 194354f8718..02024adb34e 100644
--- a/mysql-test/t/ctype_utf8.test
+++ b/mysql-test/t/ctype_utf8.test
@@ -667,6 +667,12 @@ drop table t1;
select 'c' like '\_' as want0;
#
+# SUBSTR with negative offset didn't work with multi-byte strings
+#
+SELECT SUBSTR('вася',-2);
+
+
+#
# Bug #7730 Server crash using soundex on an utf8 table
#
create table t1 (id integer, a varchar(100) character set utf8 collate utf8_unicode_ci);
diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc
index 8b9351d95a5..baba4d9b786 100644
--- a/sql/item_strfunc.cc
+++ b/sql/item_strfunc.cc
@@ -1023,7 +1023,7 @@ String *Item_func_substr::val_str(String *str)
if ((null_value=(args[0]->null_value || args[1]->null_value ||
(arg_count == 3 && args[2]->null_value))))
return 0; /* purecov: inspected */
- start= (int32)((start < 0) ? res->length() + start : start -1);
+ start= (int32)((start < 0) ? res->numchars() + start : start -1);
start=res->charpos(start);
length=res->charpos(length,start);
if (start < 0 || (uint) start+1 > res->length() || length <= 0)