diff options
-rw-r--r-- | mysql-test/r/func_str.result | 29 | ||||
-rw-r--r-- | mysql-test/t/func_str.test | 28 | ||||
-rw-r--r-- | sql/item_strfunc.cc | 6 |
3 files changed, 61 insertions, 2 deletions
diff --git a/mysql-test/r/func_str.result b/mysql-test/r/func_str.result index c2827d75e6a..bff8d0f1504 100644 --- a/mysql-test/r/func_str.result +++ b/mysql-test/r/func_str.result @@ -2659,6 +2659,35 @@ NULL NULL 8 drop table t1; End of 5.1 tests +# +# Start of 5.3 tests +# +# +# Bug#11829861: SUBSTRING_INDEX() RESULTS IN MISSING CHARACTERS WHEN USED +# INSIDE LOWER() +# +SET @user_at_host = 'root@mytinyhost-PC.local'; +SELECT LOWER(SUBSTRING_INDEX(@user_at_host, '@', -1)); +LOWER(SUBSTRING_INDEX(@user_at_host, '@', -1)) +mytinyhost-pc.local +# End of test BUG#11829861 +# +# Bug#42404: SUBSTRING_INDEX() RESULTS ARE INCONSISTENT +# +CREATE TABLE t (i INT NOT NULL, c CHAR(255) NOT NULL); +INSERT INTO t VALUES (0,'.www.mysql.com'),(1,'.wwwmysqlcom'); +SELECT i, SUBSTRING_INDEX(c, '.', -2) FROM t WHERE i = 1; +i SUBSTRING_INDEX(c, '.', -2) +1 .wwwmysqlcom +SELECT i, SUBSTRING_INDEX(c, '.', -2) FROM t; +i SUBSTRING_INDEX(c, '.', -2) +0 mysql.com +1 .wwwmysqlcom +DROP TABLE t; +# End of test BUG#42404 +# +# End of 5.3 tests +# Start of 5.4 tests SELECT format(12345678901234567890.123, 3); format(12345678901234567890.123, 3) diff --git a/mysql-test/t/func_str.test b/mysql-test/t/func_str.test index 0715fca7d96..c61ebbfa4bd 100644 --- a/mysql-test/t/func_str.test +++ b/mysql-test/t/func_str.test @@ -1409,6 +1409,34 @@ drop table t1; --echo End of 5.1 tests +--echo # +--echo # Start of 5.3 tests +--echo # + +--echo # +--echo # Bug#11829861: SUBSTRING_INDEX() RESULTS IN MISSING CHARACTERS WHEN USED +--echo # INSIDE LOWER() +--echo # +SET @user_at_host = 'root@mytinyhost-PC.local'; +SELECT LOWER(SUBSTRING_INDEX(@user_at_host, '@', -1)); +--echo # End of test BUG#11829861 + +--echo # +--echo # Bug#42404: SUBSTRING_INDEX() RESULTS ARE INCONSISTENT +--echo # + +CREATE TABLE t (i INT NOT NULL, c CHAR(255) NOT NULL); +INSERT INTO t VALUES (0,'.www.mysql.com'),(1,'.wwwmysqlcom'); +SELECT i, SUBSTRING_INDEX(c, '.', -2) FROM t WHERE i = 1; +SELECT i, SUBSTRING_INDEX(c, '.', -2) FROM t; +DROP TABLE t; +--echo # End of test BUG#42404 + +--echo # +--echo # End of 5.3 tests +--echo # + + --echo Start of 5.4 tests # # WL#4584 Internationalized number format diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 821f9359baf..14f964b3b6d 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -1265,7 +1265,7 @@ String *Item_str_conv::val_str(String *str) if (multiply == 1) { uint len; - res= copy_if_not_alloced(str,res,res->length()); + res= copy_if_not_alloced(&tmp_value, res, res->length()); len= converter(collation.collation, (char*) res->ptr(), res->length(), (char*) res->ptr(), res->length()); DBUG_ASSERT(len <= res->length()); @@ -1471,8 +1471,10 @@ void Item_func_substr_index::fix_length_and_dec() String *Item_func_substr_index::val_str(String *str) { DBUG_ASSERT(fixed == 1); + char buff[MAX_FIELD_WIDTH]; + String tmp(buff,sizeof(buff),system_charset_info); String *res= args[0]->val_str(str); - String *delimiter= args[1]->val_str(&tmp_value); + String *delimiter= args[1]->val_str(&tmp); int32 count= (int32) args[2]->val_int(); uint offset; |