[Haskell-beginners] Simple UTF-8 output

Christopher Howard christopher.howard at frigidcode.com
Sat May 28 06:35:52 CEST 2011


On 05/27/2011 08:01 PM, Christopher Howard wrote:
> On 05/26/2011 11:38 PM, Erik de Castro Lopo wrote:
>> Elvio Toccalino wrote:
>>
>>> I usually pull such values as ByteStrings. The utf8-strings package
>>> provides printing functions for such data.
>>> Also, if you'd like to work on it as Text, there's the
>>> Data.Text.Encodings module, to decodeUTF8 or decodeASCII ByteString's
>>> into Text.
>>
>> I would recommend Data.Text because that is designed for Text
>> encodings while ByteString is designed for handling arrays
>> of bytes (eg things like data read from an network socket).
>>
>> Cheers,
>> Erik
> 
> Thank you everyone for your responses, but I'm still having trouble with
> this issue. This is what I've learned so far:
> 
> - The problem is not my terminal: commands like putStrLn "\228" produce
> the correct character.
> - The problem doesn't seem to be my MySQL database. The character
> encoding on the database and on the table are set to UTF-8. I can view
> the characters just fine when in the MySQL client.
> - I looked again at the character numbers on the special characters
> being outputted by my program: They are not the correct Unicode numbers.
> Apparently the special characters are somehow getting mangled when I
> pull them from the database.
> - The choice to put the query results into ByteStrings was not mine,
> that is just what is in the results list that quickQuery gives me. I
> tried converting to Text and then to String by using "unpack (decodeUtf8
> byte_str)"; however, when the program goes to print its first line with
> an extended character, it just throws the exception: "*** Exception:
> Cannot decode byte '\xe6': Data.Text.Encoding.decodeUtf8: Invalid UTF-8
> stream".
> 

Update: I think this may be a problem with the myodbc5 driver. If I
connect with isql and then select the data, the results with extended
characters have the text either mangled or replaced with "***ERROR***".
So I am thinking either this MySQL driver for unixODBC either is not
able to handle the UTF-8, or (more likely) I don't have the correct
options in my .odbc.ini config file.

-- 
frigidcode.com
theologia.indicium.us



More information about the Beginners mailing list