1

According to "Incorrect string value" when trying to insert UTF-8 into MySQL via JDBC? , if I want to store data that contains 4-byted UTF-8 characters, mysql's column need to have a utf8mb4 encoding.

I'm using Zlib::Deflate.deflate to compress a string and would like to store it in Mysql.

Upon inserting the record, I get the following:

ActiveRecord::StatementInvalid: Mysql2::Error: Incorrect string value: '\x96Iv$!\x0C...'

So basically, I will either have to change the column's encoding or force Zlib::Deflat.deflate to generate only 3-byted UTF-8 characters. Is there a way to do this?

Community
  • 1
  • 1
Abdo
  • 13,549
  • 10
  • 79
  • 98

1 Answers1

1

Instead of storing the data as a UTF-8 string, I changed the column type to BLOB and stored the data as binary.

Note to self and others: if you want to store Zlib inflated data, make sure the column type is BLOB in mysql.

Abdo
  • 13,549
  • 10
  • 79
  • 98