Overview
Features
Download
Documentation
Community
Add-Ons & Services

MySQL with Latin1 encoding

Please post support and help requests here.

MySQL with Latin1 encoding

Postby Hitnrun » 02 Apr 2009, 23:05

Hello!

I am trying to retrive data from a MySQL table using POCO Data (SVN trunk), but the accented characters aren't appearing correctly:

Code: Select all
RODRIGO HERN┴N S┴NCHEZ S.


instead of

Code: Select all
RODRIGO HERNÁN SÁNCHEZ S.


probably because it is using UTF encoding instead of the iso-8859-1 that is on the table.

How is the correct way to deal with this?
Hitnrun
 
Posts: 20
Joined: 01 Apr 2009, 18:32

Re: MySQL with Latin1 encoding

Postby alex » 02 Apr 2009, 23:40

It depends what your target knows how to display. Eg. on Linux, you can do:

Code: Select all
std::string latin1Name, utf8Name;
session << "select myName from myTable", into(latin1Name), now;

Latin1Encoding latin1;
UTF8Encoding utf8;
TextConverter converter(latin1, utf8);
converter.convert(latin1Name, utf8Name);
std::cout << utf8Name << std::endl


And if your console is UTF-8 capable, it'll display characters right. On Windows, you'll want to use UTF-16 (see Poco::UnicodeConverter class).

Although I don't think it should affect this particular case, you may get hit elsewhere, so a word of warning is in place: we have just fixed a UTF-8 encoding bug for the upcoming 1.3.4 release.

Also, this just gave me an idea that it would be a good thing to enable Data library with text conversion capabilities. Now, if only I could find a volunteer to do the work ;-)
alex
 
Posts: 1115
Joined: 11 Jul 2006, 16:27
Location: United_States

Re: MySQL with Latin1 encoding

Postby alex » 02 Apr 2009, 23:47

alex wrote: On Windows, you'll want to use UTF-16 (see Poco::UnicodeConverter class).


I stand corrected here. I think you need to use UnicodeConverter only if you are converting from/to UTF-8, which Windows does not understand natively. Text conversions are such a bloody mess :-(. At any rate, to be truly platform-independent, POCO is UTF-8 based throughout, keep that in mind.
alex
 
Posts: 1115
Joined: 11 Jul 2006, 16:27
Location: United_States

Re: MySQL with Latin1 encoding

Postby Hitnrun » 03 Apr 2009, 18:49

alex wrote:It depends what your target knows how to display. Eg. on Linux, you can do:

Code: Select all
std::string latin1Name, utf8Name;
session << "select myName from myTable", into(latin1Name), now;

Latin1Encoding latin1;
UTF8Encoding utf8;
TextConverter converter(latin1, utf8);
converter.convert(latin1Name, utf8Name);
std::cout << utf8Name << std::endl


And if your console is UTF-8 capable, it'll display characters right. On Windows, you'll want to use UTF-16 (see Poco::UnicodeConverter class).

Although I don't think it should affect this particular case, you may get hit elsewhere, so a word of warning is in place: we have just fixed a UTF-8 encoding bug for the upcoming 1.3.4 release.

Also, this just gave me an idea that it would be a good thing to enable Data library with text conversion capabilities. Now, if only I could find a volunteer to do the work ;-)


That's what I wanted to know, I saw these conversion functions, but found no documentation about them.

My new project MIGHT use POCO, so I may be able to help on this development.
Hitnrun
 
Posts: 20
Joined: 01 Apr 2009, 18:32


Return to Support

Who is online

Users browsing this forum: No registered users and 1 guest