saveX :: [String] -> Int->IO ()
saveX [] y= return ()
sav xs y=
do conn <- connectSqlite3 "cw.db"
stmt <- prepare conn "INSERT INTO pic (src,urlId) VALUES (?,?)"
executeMany stmt <what to add here>
commit conn
I have a table with two columns src and urlId and [String] contains list of src and Int is the urlID. I want to insert all the srcs to table with the urlId. I have tried few ways with converting tuples but toSql does not work for it. Please help me with this
There's an almost identical example in Real World Haskell:
Edit
For your specific case, this isn't a question about how to use HDBC, but about how to combine one piece of ordinary Haskell data,
y
, with a list of data,xs
. Themap
function takes a single function and applies it to every element in a list, returning a list of the results. If we put the singley
in a function, we canmap
it onto the list, and get a result for every item in the list. For example:Will result in:
To combine your one
y
that is a urlId with yourxs
that contain sources, you could writeThis would give you the following entire piece of code: