[Takusen] working out how to use bind variables
Michael Litchard
michael at schmong.org
Wed Aug 11 14:45:03 EDT 2010
Here's some toy code I have been playing with. The first few attempts
work fine, but the final line, where I try to use bind variables,
becomes a problem.
> import Database.PostgreSQL.Enumerator
> import Database.Enumerator
> main :: IO ()
> main = do
> let connection = connect [CAdbname "tutorialDB"]
> let foo = "test"
> let bar = 42
> withSession connection (execDDL (sql "create table activities (Activity char(20) PRIMARY KEY, cost int)"))
> withSession connection (execDDL (sql "create table students (Student char (20), ID int PRIMARY KEY)"))
> withSession connection (execDDL (sql "create table participants (Activity char (20) REFERENCES activities , ID int PRIMARY KEY)"))
> withSession connection (execDDL (sql "insert into activities (Activity,Cost) values ('golf', 27)"))
> withSession connection (execDML (cmdbind "insert into activities (Activity, Cost) values (?, ?)" [bindP foo, bindP bar]))
tutorial.lhs:16:26:
Couldn't match expected type `()' against inferred type `Int'
Expected type: DBM mark Session ()
Inferred type: DBM mark Session Int
In the second argument of `withSession', namely
`(execDML
(cmdbind
"insert into activities (Activity, Cost) values (?, ?)"
[bindP foo, bindP bar]))'
In the expression:
withSession
connection
(execDML
(cmdbind
"insert into activities (Activity, Cost) values (?, ?)"
[bindP foo, bindP bar]))
I know this means I need to fix the type, but I don't know how. I've
been looking at the code used for testing, plus the usage examples
from Enumerator.lhs. Haven't quite got it. Any help pointing me in the
right direction would be much welcome.
Michael Litchard
More information about the Takusen
mailing list