[ODBC-6] Illegal mix of collations when using parameters Created: 2014-05-05  Updated: 2015-01-14  Resolved: 2014-09-19

Status: Closed
Project: MariaDB Connector/ODBC
Component/s: None
Affects Version/s: 1.0.0
Fix Version/s: None

Type: Bug Priority: Blocker
Reporter: Ulf Engstrand Assignee: Lawrin Novitsky
Resolution: Fixed Votes: 0
Labels: None
Environment:

Windows Server 2008 R2
IIS 7.5
.NET Framework 4



 Description   

Application fails with the following exception when sending data as parameters.

System.Data.Odbc.OdbcException: ERROR [HY000] Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '='



 Comments   
Comment by Georg Richter [ 2014-05-05 ]

To analyze the bug I need some more information

  • the DSN string
  • ODBC trace log
  • if possible definition of the table structure(s)

Thanks!

Comment by Georg Richter [ 2014-05-08 ]

If you don't specify a character set in your DSN, utf8 as default is used.

Some query fails, since it contains a non latin1 character, e.g.

MariaDB [test]> set names utf8;
Query OK, 0 rows affected (0.01 sec)
 
MariaDB [test]> prepare my from "SELECT * FROM t1 WHERE a = 'я'";
ERROR 1267 (HY000): Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '='

Either find the statement which contains an invalid latin1 character or use a different character set in your DSN:

CHARSET=latin1

Comment by Ulf Engstrand [ 2014-05-09 ]

The problem remains, without specifying character set on the DSN:

SELECT `value` FROM xmldata WHERE `key` = 'Key1'; <--- Returns OK

var cmd = new System.Data.Odbc.OdbcCommand("SELECT `value` FROM xmldata WHERE `key` = ?", conn);
cmd.Parameters.Add(new System.Data.Odbc.OdbcParameter("", "Key1"));
This one fails, no special characters from what I can see.

However, when specifying character set latin1, the latter does not fail but returns no rows.

Comment by Georg Richter [ 2014-05-19 ]

Fixed in rev. 21

Comment by Lawrin Novitsky [ 2014-09-19 ]

Looks like the issue is still there - I observed same error with ado using parameters. Taking it over for further investigation and fixing

Comment by Lawrin Novitsky [ 2014-09-19 ]

Ok, looks like I reopened the bug a bit in hurry. Bug occurs if the field is different than the default charset used by the driver. But specifying CHARSET=<charset_used_in_db> perfectly cures the problem.
The testcase I used looks like this
Const DSN = "DSN=test"

Const adParamInput = &H0001

Const adCmdText = &H0001

Const adVarChar=200

Dim conn, rs, fld, cmd, pr

Set conn = CreateObject("ADODB.Connection")

conn.Open(DSN)

Set cmd = CreateObject("ADODB.Command")
cmd.ActiveConnection = conn
cmd.CommandText = "SELECT b FROM t WHERE a=?"
cmd.CommandType = adCmdText
Set pr = CreateObject("ADODB.Parameter")
'pr.Name = "a"
pr.Type = adVarChar
pr.Direction = adParamInput
pr.Size = 10
pr.Value = "фuu1"
cmd.Parameters.Append(pr)

Set rs = cmd.Execute()

Adding ;CHARSET=cp1251 to the connection string helped in my case(as the key field was in cp1251).
While checking the issue I stumbled upon ODBC-14 and fixed. Maybe it was real root of somebody's problems in similar scenario.

Generated at Thu Feb 08 03:25:33 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.