Skip to content

Instantly share code, notes, and snippets.

@cmoore
Created July 19, 2009 02:54
Show Gist options
  • Save cmoore/149786 to your computer and use it in GitHub Desktop.
Save cmoore/149786 to your computer and use it in GitHub Desktop.
oc :: IO SQLiteHandle
oc = openConnection "data.rsd"
cc :: SQLiteHandle -> IO ()
cc x = closeConnection x
--
-- "table" <<++ [("column","value")]
-- Whee!
--
(<<++) :: String -> [(String,String)] -> IO Bool
(<<++) table cols =
do
h <- oc
let sql = "INSERT INTO " ++ table ++ " " ++
"(" ++ cnames cols ++ ") VALUES (" ++ cmarkers cols ++ ")"
let vals = map (\(x,y) -> ((":" ++ x), Text y)) cols
res <- (execParamStatement_ h sql vals )
cc h
case res of
Just _ -> return False
Nothing -> return True
where
cnames :: [(String,String)] -> String
cnames x =
DL.intercalate "," $ map (\(a,_) -> a) x
cmarkers :: [(String,String)] -> String
cmarkers x =
":" ++ ( DL.intercalate ",:" $ map (\(y,_) -> y ) x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment