brianmario/mysql2 — pull request #470 by sodabrew (2013-12-27 21:52:08+00:00)
Title: Use rb_str_conv_enc_opts to transcode error strings in MySQL < 5.5

This resolves the problem in pwnall/rails5738 but does not pass our own specs on MySQL 5.1, as it appears to be allowing invalid UTF-8 characters through (in the case of our tests, there is a Big5-encoded Chinese character U+9020 which is not valid UTF-8).

The transcoding function calls are now:
``` C
rb_encoding *err_enc = rb_ascii8bit_encoding();
rb_error_msg = rb_str_conv_enc_opts(rb_error_msg, err_enc, conn_enc, ECONV_UNDEF_REPLACE | ECONV_INVALID_REPLACE, Qnil);
rb_sql_state = rb_str_conv_enc_opts(rb_sql_state, err_enc, conn_enc, ECONV_UNDEF_REPLACE | ECONV_INVALID_REPLACE, Qnil);
```