I am running code for a C# application that makes a call to a database to report on data. What's interesting is that the report works fine on my own PC, but when used at a client I got:
Illegal Mix of Collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) in concat
So far, I have checked the tables (ENGINE=InnoDB DEFAULT CHARSET=latin1;
), which are the same between our two databases. Additionally, I can backup the client database, restore it on my own PC and run the code and it works fine.
I suspect that it would be a MySQL related error, as they run MySQL Server 5.0, whereas I have MySQL Server 5.1 on my own computer. Are there any obvious discrepancies between these two versions or other obvious places to look that would cause the error on another PC but not my own?
Here is the offending code, which I was able to fix:
Original:
"Case when s.type in (" + IDList + ") then concat(s.id,(case when coalesce(p.ID, ps.ID) in ('ABC') then '.M' else '.U' end)) else case when s.id is NULL OR s.other_id='' then s.symbol else s.id end end as 'BLAH' "
Fix apported:
"Case when s.type in (" + IDList + ") then concat(CAST(s.id as CHAR),(case when coalesce(p.ID, ps.ID) in ('ABC') then '.M' else '.U' end)) else case when s.id is NULL OR s.other_id='' then s.symbol else s.id end end as 'BLAH' "
Would this be caused by the default charset being used by MySQL on their PC? The my.ini files do have an additional difference, which is that mine specifies:
'character-set-server=latin1'
whereas there's only contains:
'default-character-set=latin1'
Edited to include that the table columns are also specified with collation latin1_swedish_ci
in both databases.
Using the link in the first comment I used "show table status" and "show variables like "collation_database".
Show table status confirmed that each table's Collation was latin1_swedish_ci on both mine and the other system.
Show variables like collation_database confirmed that both my system and the other system have latin1_swedish_ci as the value