[Haskell-cafe] HDBC, character encoding

Bjorn Bringert bjorn at bringert.net
Mon Mar 31 12:42:25 EDT 2008


2008/3/26 Adrian Neumann <aneumann at inf.fu-berlin.de>:
> 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...

I think that Peter Gammie (copied) has some code to deal with this.

/Björn


More information about the Haskell-Cafe mailing list