[odb-users] how to persist utf8 string to database?

Boris Kolpackov boris at codesynthesis.com
Fri Aug 26 07:48:44 EDT 2011


spiritonly at gmail.com writes:

>       I have a mysql with utf-8 charset, and when i persist an object i have
> convert my string to std::string with utf8 encoding. But the string in
> database are illegible characters.

This is probably because the default client character set for a MySQL
connection is latin1. There is no easy way to change that in ODB 1.5.0
but I have added the charset argument to the odb::mysql::database class
constructors for the next release. I also checked and the patch applies
cleanly to libodb-mysql-1.5.0:


So you can give it a try. Here is the corresponding paragraph from the
updated ODB manual:

"The charset argument allows us to specify the client character set, that is,
the character set in which the application will encode its text data. Note
that this can be different from the MySQL server character set. If this
argument is not specified or is empty, then the default MySQL client character
set is used, normally latin1. Commonly used values for this argument are
latin1 (equivalent to Windows cp1252 and similar to ISO-8859-1) and utf8. For
other possible values as well as more information on character set support in
MySQL, refer to the MySQL documentation."


More information about the odb-users mailing list