6testexpr = do db <- open_db "somedb.db"
7 let sql = (evalSQL [] ((SELECT ALL)(TBL ["tbl1"]) (OR (AND (MkCond (Equals (VCol "data")(VStr "data0"))) (MkCond (Equals (VCol "num")(VInt 1))) ) (MkCond (Equals (VCol "num")(VInt 2))))))
8 let x = (fst sql) -- get the string
9 let list = (snd sql) -- list of vals
10 liftIO(print x) -- use liftIO to turn this into DB type
11 stmt <- (prepare_db db x) -- prepare the statement
12 bindMulti stmt list -- bind the values in the list
13 exec_db_v2 stmt -- execute the prepared query
14 res <- toList_v1 db -- toList_v1 to get the result
15 liftIO(print res) -- print the result
16 finalize_db stmt -- Statment pointer must be finalized in the end
17 close_db db -- close the datbase
21testupdate = do db <- open_db "somedb.db"
22 let sql = (evalSQL [] (UPDATE (TBL ["tbl1"]) (WHERE (SET (MkCond (Equals(VCol "data") (VStr "data600"))) ) (MkCond (Equals (VCol "num") (VInt 2))) ) ))
26 stmt <- (prepare_db db x)
34testInsert = do db <- open_db "somedb.db"
35 let sql = (evalSQL [] (INSERT (TBL ["tbl1"]) [(VInt 3),(VStr "ham")]))
39 stmt <- (prepare_db db x)
47testNull = do db <- open_db "somedb.db"
48 let sql = (evalSQL [] ((SELECT ALL)(TBL ["tbl1"]) (MkCond (MkNULL (VCol "data")))))
52 stmt <- (prepare_db db x)
62testInsertWithCond : DB()
63testInsertWithCond = do db <- open_db "somedb.db"
64 let sql = (evalSQL [] (INSERTC (TBL ["tbl1"]) [(VCol "data"),(VCol "num")] [(VInt 30),(VStr "inserthere")]))
68 stmt <- (prepare_db db x)
75-- Nested queries need to have the same column as the outer queries.
77testNestedSel1 = do db <- open_db "somedb.db"
78 let sql = (evalSQL [] (SELECT (Cols ["data"]) (SELECT (Cols["num","data"]) (TBL ["tbl1"]) (MkCond (MkGT (VCol "num")(VInt 2))))Empty))
82 stmt <- (prepare_db db x)
91-- Testing Create Table
92testCreateTable : DB ()
93testCreateTable = do db <- open_db "somedb.db"
94 let sql = (evalSQL [] (CREATE (TBL ["mynewtbl"]) [ ((VCol "col"),(CInt "int"),(None)) ] ) )
98 stmt <- (prepare_db db x)
105-- This may be a bit slow
106testMultiTable : DB ()
107testMultiTable = do db <- open_db "somedb.db"
108 let sql = (evalSQL [] ((SELECT ALL )(TBL ["mytable","tbl1"]) (Empty) ) )
112 stmt <- (prepare_db db x)
122testSelAll = do db <- open_db "somedb.db"
123 let sql = (evalSQL [] ((SELECT ALL )(TBL ["tbl1"]) (Empty) ) )
127 stmt <- (prepare_db db x)
138main = do x <- runDB (testMultiTable) -- runDB : DB a -> IO a
139 --y <- runDB (testNestedSel1)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list