Created
February 18, 2019 06:48
-
-
Save giuliohome/39b35f9723f0364dc14edad9b0abbef7 to your computer and use it in GitHub Desktop.
This file contains 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
import Database.HDBC | |
import Database.HDBC.ODBC | |
data Person = Person | |
{ id :: Int | |
, name :: [Char] } | |
deriving Show | |
convRow :: [SqlValue] -> Person | |
convRow [sqlId, sqlDesc] = | |
Person intId desc | |
where intId = (fromSql sqlId) :: Int | |
desc = case fromSql sqlDesc of | |
Just x -> x | |
Nothing -> "NULL" | |
main = | |
let connectionString = "DSN=TestDB" | |
ioconn = connectODBC connectionString in | |
do | |
conn <- ioconn | |
vals <- quickQuery conn "SELECT TOP 10 * FROM Person;" [] | |
let rows = map convRow vals | |
mapM_ print rows |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment