[Haskell-cafe] HDBC, character encoding

Adrian Neumann aneumann at inf.fu-berlin.de
Wed Mar 26 06:56:05 EDT 2008


Hi,

I wrote a CGI program to access a Postgres database using HDBC. The  
database stores books and I want to display those from a certain  
author. Everything works fine, unless I search for someone with an  
umlaut in his name. Böll, for example. I have a function like this

 > bookByAuthor :: Connection -> AutorName -> IO [[String]]
 > bookByAuthor c aName = do
 >	writeFile "./err.log" ((show aName)++" "++(show $ toSql aName))
 >	rows <- quickQuery c "SELECT * FROM buecher WHERE lower 
(autor_name) LIKE ? ORDER BY autor_name, buch_name" [toSql $ map  
toLower $ '%':aName++"%"]
 >	return $ map (map fromSql) rows

It returns me a SqlError. However, doing the same in ghci works  
perfectly. I can't understand why. err.log contains

 > "b\195\182ll" SqlString "b\195\182ll"

which is ok I think. Since

 > quickQuery c "SELECT * FROM buecher WHERE lower(autor_name) LIKE ?  
ORDER BY autor_name, buch_name" [toSql "%b\195\182%"]

works in ghci. I have tried "b\246ll", but that doesn't even work in  
ghci, although the database-encoding is utf-8. This all is really  
annoying...

Adrian
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 186 bytes
Desc: Signierter Teil der Nachricht
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20080326/bb1b3785/PGP.bin


More information about the Haskell-Cafe mailing list