Bug #7874 CONCAT() gives wrong results mixing latin1 field and utf8 string literals
Submitted: 13 Jan 2005 14:12 Modified: 18 Jan 2005 14:24
Reporter: Ryan Schmidt Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:4.1.8 OS:N/A
Assigned to: Alexander Barkov CPU Architecture:Any

[13 Jan 2005 14:12] Ryan Schmidt
Description:
With a latin1 database with latin1 fields and a latin1 connection to the database I can concatenate 
string literals with a field and get expected results. But with a utf8 connection to the same 
database I get strange results.

Tried two different servers (a PC with Gentoo Linux and the Gentoo Portage version of MySQL 
4.1.8, and a Mac OS X 10.3.7 machine with the official MySQL 4.1.8 binary package); happens on 
both.

Tried two different engines (MyISAM and InnoDB); happens on both.

Tried from a command-line client and from within a PHP script; happens on both.

How to repeat:

USE test;

CREATE TABLE `concat-test` (
	`id` int(10) unsigned NOT NULL auto_increment,
	`user` varchar(255) NOT NULL default '',
	`pass` varchar(255) NOT NULL default '',
	PRIMARY KEY (`id`),
	UNIQUE KEY `user` (`user`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

INSERT INTO `concat-test`
VALUES
	(1, 'one', '123456'),
	(2, 'two', 'abcdef'),
	(3, 'three', 'ghijkl'),
	(4, 'four', 'mnopqr');

SET NAMES latin1;

SELECT `user`, `pass`, CONCAT('>>', `pass`, '<<') AS concat FROM `concat-test`;

+-------+--------+------------+
| user  | pass   | concat     |
+-------+--------+------------+
| one   | 123456 | >>123456<< |
| two   | abcdef | >>abcdef<< |
| three | ghijkl | >>ghijkl<< |
| four  | mnopqr | >>mnopqr<< |
+-------+--------+------------+

SET NAMES utf8;

SELECT `user`, `pass`, CONCAT('>>', `pass`, '<<') AS concat FROM `concat-test`;

+-------+--------+------------------------------------+
| user  | pass   | concat                             |
+-------+--------+------------------------------------+
| one   | 123456 | >>123456<<                         |
| two   | abcdef | >>123456<<abcdef<<                 |
| three | ghijkl | >>123456<<abcdef<<ghijkl<<         |
| four  | mnopqr | >>123456<<abcdef<<ghijkl<<mnopqr<< |
+-------+--------+------------------------------------+
[18 Jan 2005 6:50] Alexander Barkov
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.

If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information 
about accessing the source trees is available at
    http://www.mysql.com/doc/en/Installing_source_tree.html

Additional info:

Fixed in 4.1.9
[18 Jan 2005 14:24] Alexander Barkov
Sorry, 

  fixed in 4.1.10
[22 Jan 2006 20:42] Emil Obermayr
I have 4.1.10a shipped with Suse9.3 hier and get still similar wrong results with concat

update test set a=concat( b,c) where a='';

works nicely, while 

update test set a=concat( b,' ',c) where a=''; 

"caches" entries from one records to the next when server default is latin1 and DB is utf8