In a Rails 4.0 app with Ruby 2.0, Turkish characters lead to the following ActiveRecord / MySQL error while trying to insert a record in the database. The problematic characters are for instance ğ and ş, but there is no problem with ü or Ç (which also seem to occur in latin charsets).
ActiveRecord::StatementInvalid (Mysql2::Error: Incorrect string value:
'\xC4\x9Fu\xC5\x9F ...' for column ...
How do you prevent this error? The application and the database use UTF-8 as standard encoding. "xC4\x9F" is UTF-8 encoding for "ğ", "\xC5\x9F" is UTF-8 for "ş". Both seem to be the problematic special characters. There is no problem with German (äöü) or French (áàâ) special characters. Contrary to ISO 8859-1 or ISO 8859-15 (only ISO 8859-9 supports all Turkish characters) it should be possible to store Turkish characters in UTF-8.
The MySQL collection settings for the database are as follows. Would it be helpful to switch collection_database
to a different value, such as utf8_unicode_ci
?
mysql> show variables like '%collation%';
+----------------------+-------------------+
| Variable_name | Value |
+----------------------+-------------------+
| collation_connection | utf8_general_ci |
| collation_database | latin1_swedish_ci |
| collation_server | latin1_swedish_ci |
+----------------------+-------------------+