mauricio / postgresql-async

Async, Netty based, database drivers for PostgreSQL and MySQL written in Scala
Apache License 2.0
1.43k stars 222 forks source link

Cannot compare on `utf8mb4` field #176

Closed jilen closed 8 years ago

jilen commented 8 years ago
SELECT EXISTS (SELECT x_7.* FROM `account_stat` x_7 WHERE (((x_7.`weixin_id` = ?) AND (x_7.`cat` = ?)) AND (x_7.`date` = ?)) AND (x_7.`ref_id` = ?))

will produce

com.github.mauricio.async.db.mysql.exceptions.MySQLException: Error 1267 - #HY000 - Illegal mix of collations (utf8mb4_general_ci,IMPLICIT) and (utf8_bin,COERCIBLE) for operation '='

the table account_stat use utf8mb4

jilen commented 8 years ago

@mauricio Is it possible to use utf8mb4 charset for mysql-async?

jilen commented 8 years ago
class DripConnectionFactory(cfg: Configuration) extends MySQLConnectionFactory(cfg) {
  val charsetMapper = new CharsetMapper(Map(CharsetUtil.UTF_8 -> 45))
  override def create: MySQLConnection = {
    val connection = new MySQLConnection(cfg, charsetMapper)
    Await.result(connection.connect, cfg.connectTimeout )
    connection
  }
}

Solved this problem by manually define charset mapper like this