Created
July 19, 2009 02:54
-
-
Save cmoore/149786 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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