[Haskell-cafe] Trivial database access in Haskell

jeff p mutjida at gmail.com
Mon Dec 11 20:24:21 EST 2006


Hello,

> 1. Simple documentation of how to install the library (starting from a
> vanilla GHC installation on Windows, plus Oracle software, to the
> point where I can use the library in my code). All I need is Oracle
> access, so other database client libraries can be ignored. I'd rather
> not use ODBC, but will if required.
>
I use HDBC to connect (via the ODBC driver) to a MS SQL Server and a
Sybase server (ASE). I'm running on a windows machine inside of
cygwin. I had no trouble installing HDBC following the instructions in
the distribution with GHC 6.6; by distribution I mean the  files
hdbc_1.0.1.2.tar.gz (general HDBC library) and
hdbc-odbc_1.0.1.1.tar.gz (specific ODBC driver) from the HDBC gopher
page (http://gopher.quux.org:70/devel/hdbc).

> 2. Simple examples on how to actually run a query. For example, how do
> I code the follwing SQL*Plus code (should be pretty self-explanatory)
> in Haskell:
>
>     connect scott/tiger at mydb
>     select * from emp;
>
Here is a GHCi session:

    Prelude> :m Database.HDBC Database.HDBC.ODBC
    Prelude Database.HDBC.ODBC Database.HDBC>do c <- connectODBC
conStr; handleSqlError $ quickQuery c "select * from emp" []

where conStr is an appropriate ODBC connection string (e.g. "DSN =
mydb" if you have the DSN defined, or you can find the Oracle string
at http://www.connectionstrings.com/). This should cause a list of
lists of SqlValues to be printed which represent the rows in your
result set.

Here is the documentation for HDBC:

    http://darcs.complete.org/hdbc/doc/Database-HDBC.html

Although it is mostly type signatures, there is some explanation.
There are also a few useful haskell-cafe discussions on aspects of
using HDBC.

hope this helps,
  Jeff


More information about the Haskell-Cafe mailing list