[Haskell-cafe] Access to Oracle database from Haskell

Henning Thielemann lemming at henning-thielemann.de
Tue Jun 24 16:38:34 EDT 2008


On Tue, 24 Jun 2008, Alistair Bayley wrote:

> 2008/6/24 Henning Thielemann <lemming at henning-thielemann.de>:
>>
>> (Btw. Takusen should be split into
>> several packages for all database backends because Cabal flags must not
>> influence the package interface.)
>
> I don't understand this (cabal flags must not influence package
> interface). I thought that was the point of cabal flags? I wanted to
> have a single package installation, and this seems like the best way.

No, if a package imports Takusen - how can it be assert that it can import 
the Oracle back-end? It can't because it can reference the Takusen package 
only by its name and a version. Flags are there to make a package appear 
consistent under different circumstances (e.g. Windows and Unix, or 
GHC-6.4 and GHC-6.8). If the back-end modules would not be exported, then 
the API would remain the same for different back-ends and that would be 
ok.

>> But on installation Cabal complains about missing /usr/oci directory.
>
> When you run configure, you should get output that says:
> Using Oracle: <path>
>
> What is <path>?

I don't get these questions.

> The Setup.hs assumes the entire Oracle installation is under a single
> root folder ($ORACLE_HOME); is this not true on Linux?

Ah, I must have set ORACLE_HOME for the Takusen installation ... should be 
documented. However in my case, this doesn't change the path used by 
Takusen's Setup/install.


$ echo $ORACLE_HOME
/usr/lib/oracle/10.2.0.4/client
$ ls $ORACLE_HOME
bin  lib
$ ll $ORACLE_HOME/lib
-rw-r--r-- 1 root root     1525 17. Feb 09:58 glogin.sql
lrwxrwxrwx 1 root root       17 24. Jun 15:36 libclntsh.so -> libclntsh.so.10.1
-rw-r--r-- 1 root root 19076649 17. Feb 09:57 libclntsh.so.10.1
-rw-r--r-- 1 root root  5656445 17. Feb 09:57 libnnz10.so
lrwxrwxrwx 1 root root       15 24. Jun 15:36 libocci.so -> libocci.so.10.1
-rw-r--r-- 1 root root  1398244 17. Feb 09:57 libocci.so.10.1
-rw-r--r-- 1 root root 72698427 17. Feb 09:57 libociei.so
-rw-r--r-- 1 root root   120443 17. Feb 09:57 libocijdbc10.so
-rw-r--r-- 1 root root  1434263 17. Feb 09:58 libsqlplusic.so
-rw-r--r-- 1 root root  1069221 17. Feb 09:58 libsqlplus.so
-rw-r--r-- 1 root root   781311 17. Feb 09:58 libsqora.so.10.1
-rw-r--r-- 1 root root  1555682 17. Feb 09:57 ojdbc14.jar

I assume that libociei.so is the library I need.


$ runhaskell Setup.hs configure --user -f oracle
Configuring Takusen-0.8.2...
$ runhaskell Setup.hs build && runhaskell Setup.hs haddock
Preprocessing library Takusen-0.8.2...
Building Takusen-0.8.2...
/usr/bin/ar: creating dist/build/libHSTakusen-0.8.2.a
Preprocessing library Takusen-0.8.2...
Running Haddock for Takusen-0.8.2...
Preprocessing library Takusen-0.8.2...
...
Documentation created: dist/doc/html/Takusen/index.html
$ runhaskell Setup.hs install
Installing:
[...]/lib/Takusen-0.8.2/ghc-6.8.2
Registering Takusen-0.8.2...
Reading package info from "dist/installed-pkg-config" ... done.
ghc-pkg: /usr/oci doesn't exist or isn't a directory (use --force to override)



>> Once I will get Takusen running with OCI - how would I use it? Is there a
>> minimal example which connects to an Oracle database, performing a very
>> simple query?
>
> There's an example in the README.txt, which I've tweaked here for Oracle:
>
> {-# OPTIONS -fglasgow-exts #-}
> {-# OPTIONS -fallow-overlapping-instances #-}
> module Main where
> import Database.Oracle.Enumerator
> import Control.Monad.Trans (liftIO)
> main = flip catchDB reportRethrow $
>  withSession (connect "user" "pswd" "dbname") (do
>    let iter (s::String) (_::String) = result s
>    result <- doQuery (sql "select 'Hello world.' from dual") iter ""
>    liftIO (putStrLn result)
>    )

Thanks for the adapted example!


More information about the Haskell-Cafe mailing list