Tuesday, 4 August 2015

A Quick Visit to the Database

To tie together these threads let's actually issue that query to the database from Haskell...

Link to the modules for database access via ODBC (one I prepared earlier):

> :m +Database.HDBC
> :m +Database.HDBC.ODBC

Create a connection using the credentials set up in the ODBC settings:

> conn <- connectODBC "DSN=Lethbridge;UID=POLLY;PWD=S0wn4kb8J6f"

Get a record set back by sending the query via the connection:

> records <- quickQuery conn "select dept, sum(salary) from employees group by dept;" []

And what do we get back?

> records
[[SqlByteString "Ed",SqlInt32 175],[SqlByteString "MS",SqlInt32 320],[SqlByteString "Yale",SqlInt32 160]]

Close the session...

> commit conn
> disconnect conn

No comments:

Post a Comment