Excuse me if this question is misplaced or too trivial. I'm writing a CGI program in Haskell (CGI/HDBC/Sqlite3), the database contains UTF-8 strings. If I use HDBC.fetchRow() to retrieve the data, then HDBC.fromSql() to convert the data to Haskell, then Text.XHtml constructs to dsplay it, I get wrong results in the browser (ASCII rendering of UTF-8 characters, which looks like garbage). What is the way to do this correctly? Thanks -- L. Kalman -- Laszlo Kalman Theoretical Linguistics Program, kalman@nytud.hu Budapest University (ELTE) Research Institute for Linguistics, Room 209 P.O. Box 701/518, 1399 Budapest, Hungary (+36-1) 351 4830 x148, fax: (+36-1) 322 9297 http://budling.nytud.hu/~kalman "Me die? That'll be the last thing I do!"
kalman:
Excuse me if this question is misplaced or too trivial.
I'm writing a CGI program in Haskell (CGI/HDBC/Sqlite3), the database contains UTF-8 strings. If I use HDBC.fetchRow() to retrieve the data, then HDBC.fromSql() to convert the data to Haskell, then Text.XHtml constructs to dsplay it, I get wrong results in the browser (ASCII rendering of UTF-8 characters, which looks like garbage). What is the way to do this correctly?
You may need to write the strings to the database using the utf8-string package. Also, if you're never actually decoding the data, it may be your CGI app generating a page with the wrong content type. When starting up your CGI app, set the content type to utf8, main = runFastCGIorCGI $ ... setHeader "Content-type" "text/plain; charset=utf-8" ... So check the headers being generated are of the correct type. Cheers, Don
Dear Don, thanks very much!
You may need to write the strings to the database using the utf8-string package. My program may not be the only one writing into the database. But I now *read* from the database using utf8-string, which solves the problem:
import Codec.Binary.UTF8.String ( decodeString ) then (decodeString $ fromSql sqlString) returns the correct string. Unfortunately, utf8-string is not part of my ghc distribution (6-6-1, Ubuntu), and my repositories also don't contain it. I had to download it from http://hackage.haskell.org/cgi-bin/hackage-scripts/package/utf8-string-0.2 and install it by hand. (This may not be the optimal solution, though.) [Of course, the charset=utf-8 content type was included in the header from the outset.] Best regards and thanks again for the immediate help -- L. Kalman -- Laszlo Kalman Theoretical Linguistics Program, kalman@nytud.hu Budapest University (ELTE) Research Institute for Linguistics, Room 209 P.O. Box 701/518, 1399 Budapest, Hungary (+36-1) 351 4830 x148, fax: (+36-1) 322 9297 http://budling.nytud.hu/~kalman "Me die? That'll be the last thing I do!"
participants (2)
-
Don Stewart -
László Kálmán