I have a problem here which looks like a bug in MariaDB to me, but before posting it to the MariaDB bug database I wanted to post it here, maybe I am doing something wrong.
The problem can easily be reproduced with the following code:
public static void main(String[] args) throws ReplicationException, SQLException {
byte[] cb3 = {-61, -92, 98, -29, -125, -70, -61, -87}; //equals to "äb?é", with “?” being a japanese character
String corrupt = new String(cb3, Charsets.UTF_8);
MariaDB db = new MariaDB();
Connection conn = db.getConnection();
//byte[] latinBytes = corrupt.getBytes(Charset.forName("ISO-8859-1")); //workaround
//corrupt = new String(latinBytes, Charset.forName("ISO-8859-1")); //workaround
PreparedStatement sqlInsert = conn.prepareStatement("insert into prep values (?)");
sqlInsert.setString(1, corrupt);
sqlInsert.execute();
conn.commit();
System.out.println("insert ok");
PreparedStatement sqlSelect = conn.prepareStatement("select * from prep where text=? ");
sqlSelect.setString(1, corrupt);
sqlSelect.execute();
}
On my MariaDB (which has character set latin1!), there is a table prep: "create table prep (text varchar(10));" When i run this code, the insert works perfectly: the japanese character gets converted to "?", as expected. However, the sqlSelect doesnt work at all and yields the feared error message "Illegal mix of collations (latin1_general_cs,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '='".
If I change the sql to "select * from prep where text=? collate latin1_general_cs", I get the error message "COLLATION 'latin1_general_cs' is not valid for CHARACTER SET 'utf8'". Therefore i concluded that my bind variable "corrupt" was not converted to latin1 for the where clause. However, I expected this conversion because it worked with the insert.
There is a working workaround: if you activate the two lines "//workaround", the String will be converted in java before giving it to the database. However, I feel that this should not be neccessary.
Running the same code on an oracle database yields no error. Can somebody run this on a mysql database?
So, does this look like a bug to you, or am I missing something.
Additional infos:
MariaDB version 10.0.14, MariaDB Client Library for java: 1.1.7
The jdbc connection string looks like this:
"jdbc:mariadb://localhost:3306/myDb?rewriteBatchedStatements=true&useServerPrepStmts=false"
To start the database I use the default "my-large.ini".
I created the database with this code:
create database myDb
DEFAULT CHARACTER SET latin1
COLLATE latin1_general_cs;
Update: I submitted a bug report to the mariaDB team: https://mariadb.atlassian.net/browse/CONJ-117
sqlInsert.execute();statement fails with "java.sql.SQLDataException: Incorrect string value: '\xE3\x83\xBA\xC3\xA9' for column 'text' at row 1".prep.textisvarchar(10)with collationlatin1_general_ci(as it was for my MySQL test). If you can suggest how I might tweak my MariaDB test case to get past that please let me know.