forked from ryantm/hdbc-mysql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Test.hs
33 lines (26 loc) · 1.01 KB
/
Test.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
module Main where
import Control.Monad
import Database.HDBC
import Database.HDBC.MySQL
connectDatabase :: IO Connection
connectDatabase = connectMySQL defaultMySQLConnectInfo
go :: IO ()
go = do conn <- connectDatabase
putStrLn $ "driver " ++ (show $ hdbcDriverName conn)
putStrLn $ "server version " ++ (show $ dbServerVer conn)
tables <- getTables conn
forM_ tables $ \t -> do
putStrLn $ "table " ++ t
cols <- describeTable conn t
forM_ cols $ \(name, desc) ->
putStrLn $ name ++ " " ++ (show desc)
rows0 <- quickQuery' conn "SELECT a FROM album" []
rows1 <- quickQuery' conn "SELECT str FROM album" []
forM_ (zip rows0 rows1) $ \(a, str) -> putStrLn $ "a=" ++ (show a) ++ ", str=" ++ (show str)
{-
stmt <- prepare conn "INSERT INTO album VALUES (?, ?)"
n <- execute stmt [SqlWord32 3000000000, SqlString "hello"]
commit conn
-}
main :: IO ()
main = handleSqlError (replicateM_ 1 go)