[Haskell-cafe] Network.CGI and SQL Queries

william murphy will.t.murphy at gmail.com
Thu Jul 21 02:46:52 CEST 2011


Hello there,

There's an odd error every time I try to run this code:

import Network.CGI
import Text.XHtml
import qualified Text.Html as H
import Database.HDBC
import Database.HDBC.Sqlite3
import System.Random

...

sqlReaderIO = do
    handle <- connectSqlite3 "table2.db"
    scoresSql <- quickQuery' handle "SELECT * FROM pachinkoScores ORDER BY
score, name" []
    let scores = map (map (\x -> fromSql x :: String)) scoresSql
    return (show scores)

...

cgiTMain = do ...
              scoresPassed <- sqlReaderIO
              output . renderHtml $ (inputForm n ss) maybe (inputForm n ss)
(\mT -> page "Loading..." (visual t v a mT ss) n v a (t + 1) mT) maxT


main = runCGI $ handleErrors cgiTMain


When I remove the "scoresPassed <- sqlReaderIO" line, the code run smoothly.
Nothing else references "scoresPassed". The ghc, however, gives me this
error when the line is included:

tankwSql.hs:144:15:
    No instance for (MonadCGI IO)
      arising from a use of `output'
    Possible fix: add an instance declaration for (MonadCGI IO)
    In the first argument of `(.)', namely `output'
    In the expression: output . renderHtml
    In the expression: output . renderHtml $ inputForm n

tankwSql.hs:147:30:
    Couldn't match expected type `CGIT m0 CGIResult'
                with actual type `IO CGIResult'
    In the first argument of `handleErrors', namely `cgiTMain'
    In the second argument of `($)', namely `handleErrors cgiTMain'
    In the expression: runCGI $ handleErrors cgiTMain

Thanks,

Will
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20110720/b696f758/attachment.htm>


More information about the Haskell-Cafe mailing list