[Haskell-cafe] HDBC, character encoding
dons at galois.com
Wed Mar 26 13:43:37 EDT 2008
> 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
Are you using the utf8-string package for necessary IO ?
More information about the Haskell-Cafe