From 8ffd9a919069664c4d07dcd72be095abd9f80c5b Mon Sep 17 00:00:00 2001 From: "ram@gw.mysql.r18.ru" <> Date: Tue, 9 Mar 2004 16:52:37 +0400 Subject: [PATCH] Fix for the bug #3089: SUBSTRING bug when mixed with CONCAT and ORDER BY --- mysql-test/r/func_str.result | 10 ++++++++++ mysql-test/t/func_str.test | 13 +++++++++++++ sql/item_strfunc.cc | 2 +- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/func_str.result b/mysql-test/r/func_str.result index d213883df76..eb09a746a1c 100644 --- a/mysql-test/r/func_str.result +++ b/mysql-test/r/func_str.result @@ -624,3 +624,13 @@ Note 1003 select high_priority md5(_latin1'hello') AS `md5('hello')`,sha(_latin1 SELECT lpad(12345, 5, "#"); lpad(12345, 5, "#") 12345 +create table t1 (id int(1), str varchar(10)) DEFAULT CHARSET=utf8; +insert into t1 values (1,'aaaaaaaaaa'), (2,'bbbbbbbbbb'); +create table t2 (id int(1), str varchar(10)) DEFAULT CHARSET=utf8; +insert into t2 values (1,'cccccccccc'), (2,'dddddddddd'); +select substring(concat(t1.str, t2.str), 1, 15) "name" from t1, t2 +where t2.id=t1.id order by name; +name +aaaaaaaaaaccccc +bbbbbbbbbbddddd +drop table t1, t2; diff --git a/mysql-test/t/func_str.test b/mysql-test/t/func_str.test index 6e4fc21f4b0..c9ead51c0a6 100644 --- a/mysql-test/t/func_str.test +++ b/mysql-test/t/func_str.test @@ -360,3 +360,16 @@ explain extended select md5('hello'), sha('abc'), sha1('abc'), soundex(''), 'moo # SELECT lpad(12345, 5, "#"); + + +# +# Bug #3089 +# + +create table t1 (id int(1), str varchar(10)) DEFAULT CHARSET=utf8; +insert into t1 values (1,'aaaaaaaaaa'), (2,'bbbbbbbbbb'); +create table t2 (id int(1), str varchar(10)) DEFAULT CHARSET=utf8; +insert into t2 values (1,'cccccccccc'), (2,'dddddddddd'); +select substring(concat(t1.str, t2.str), 1, 15) "name" from t1, t2 +where t2.id=t1.id order by name; +drop table t1, t2; diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index b9604cf900b..518b9ca624b 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -1033,7 +1033,7 @@ void Item_func_substr::fix_length_and_dec() } if (arg_count == 3 && args[2]->const_item()) { - int32 length= (int32) args[2]->val_int() * default_charset_info->mbmaxlen; + int32 length= (int32) args[2]->val_int() * collation.collation->mbmaxlen; if (length <= 0) max_length=0; /* purecov: inspected */ else