[Haskell-beginners] Sqlite3 - INSERT statement question

Brent Yorgey byorgey at seas.upenn.edu
Thu Feb 3 18:25:36 CET 2011


On Thu, Feb 03, 2011 at 12:20:12PM -0500, Patrick Lynch wrote:
> Good morning,
> 
> I'm using "Real World Haskell" and a Windows Vista PC and I have Sqlite3 installed...[note: I had to change test1.db to /users/user/test1.db in order to get this to work, otherwise, neither the database nor the table could be created -- also, note c:/users/user/test1.db gives a syntax error], ghci doesn't like c:/]:
> 
> I tried to use the following example from the book but it failed...see following:
> 
> Prelude> :m Database.HDBC Database.HDBC.Sqlite3
> Prelude Database.HDBC Database.HDBC.Sqlite3> conn <- connectSqlite3 "/users/user/test1.db"
> ...
> Prelude Database.HDBC Database.HDBC.Sqlite3> run conn "INSERT INTO test VALUES (?, ?)" [toSql 0, toSql "zero"]
> 
> <interactive>:1:43:
>     No instance for (Data.Convertible.Base.Convertible t SqlValue)
>       arising from a use of `toSql' at <interactive>:1:43-49
>     Possible fix:
>       add an instance declaration for
>       (Data.Convertible.Base.Convertible t SqlValue)
>     In the expression: toSql 0
>     In the third argument of `run', namely `[toSql 0, toSql "zero"]'
>     In the expression:
>         run conn "INSERT INTO test VALUES (?, ?)" [toSql 0, toSql
>     "zero"]

I think the problem is that 0 is polymorphic, so GHC does not know
what type you want it to have, but its type determines which
Convertible instance is chosen.  It should work if you put a type
signature on the 0, like

  toSql (0 :: Int)

or

  toSql (0 :: Integer)

or whatever.

-Brent



More information about the Beginners mailing list