Skip to content

Instantly share code, notes, and snippets.

@giuliohome
Created February 18, 2019 06:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save giuliohome/39b35f9723f0364dc14edad9b0abbef7 to your computer and use it in GitHub Desktop.
Save giuliohome/39b35f9723f0364dc14edad9b0abbef7 to your computer and use it in GitHub Desktop.
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