diff options
author | unknown <bar@mysql.com> | 2005-01-18 10:42:29 +0400 |
---|---|---|
committer | unknown <bar@mysql.com> | 2005-01-18 10:42:29 +0400 |
commit | ec0daa744fe6b1141e4d8815b574c2a1e38366e8 (patch) | |
tree | 94e4f578dbb80e2efbd3f28d088dc43520e7bbb0 | |
parent | 985805ce6afefaf2715732809aa00c5396990662 (diff) | |
download | mariadb-git-ec0daa744fe6b1141e4d8815b574c2a1e38366e8.tar.gz |
#7874: CONCAT() gives wrong results mixing latin1 field and utf8 string literals
We should not overwrite res if it is returned from a const item.
-rw-r--r-- | mysql-test/r/ctype_utf8.result | 12 | ||||
-rw-r--r-- | mysql-test/t/ctype_utf8.test | 12 | ||||
-rw-r--r-- | sql/item_strfunc.cc | 3 |
3 files changed, 26 insertions, 1 deletions
diff --git a/mysql-test/r/ctype_utf8.result b/mysql-test/r/ctype_utf8.result index f62d754392b..415ed33ad40 100644 --- a/mysql-test/r/ctype_utf8.result +++ b/mysql-test/r/ctype_utf8.result @@ -849,3 +849,15 @@ utf8_bin 6109 utf8_bin 61 utf8_bin 6120 drop table t1; +CREATE TABLE t1 ( +user varchar(255) NOT NULL default '' +) ENGINE=MyISAM DEFAULT CHARSET=latin1; +INSERT INTO t1 VALUES ('one'),('two'); +SELECT CHARSET('a'); +CHARSET('a') +utf8 +SELECT user, CONCAT('<', user, '>') AS c FROM t1; +user c +one <one> +two <two> +DROP TABLE t1; diff --git a/mysql-test/t/ctype_utf8.test b/mysql-test/t/ctype_utf8.test index a57db4455ab..8e3eb71c3e5 100644 --- a/mysql-test/t/ctype_utf8.test +++ b/mysql-test/t/ctype_utf8.test @@ -681,3 +681,15 @@ SET collation_connection='utf8_general_ci'; -- source include/ctype_filesort.inc SET collation_connection='utf8_bin'; -- source include/ctype_filesort.inc + +# +# Bug #7874 CONCAT() gives wrong results mixing +# latin1 field and utf8 string literals +# +CREATE TABLE t1 ( + user varchar(255) NOT NULL default '' +) ENGINE=MyISAM DEFAULT CHARSET=latin1; +INSERT INTO t1 VALUES ('one'),('two'); +SELECT CHARSET('a'); +SELECT user, CONCAT('<', user, '>') AS c FROM t1; +DROP TABLE t1; diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 8341dda0a41..f131d849d62 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -275,7 +275,8 @@ String *Item_func_concat::val_str(String *str) current_thd->variables.max_allowed_packet); goto null; } - if (res->alloced_length() >= res->length()+res2->length()) + if (!args[0]->const_item() && + res->alloced_length() >= res->length()+res2->length()) { // Use old buffer res->append(*res2); } |