All Unkept
Posted in: Haskell, Rants  —  13 July 2007

HSQL and HaskellDB anguish

I'm trying to use Haskell for a database app, and, as usual for Haskell, I'm finding the lack of decent documentation a real pain.

HaskellDB looks like a nice, high level approach to using databases, and, despite the look of its main page, the project isn't dead. However, when running the tests, I get this:

Problem with FlatDB:
user error (Couldn't load Database.HaskellDB.FlatDB.driver from package haskelldb-flat-0.10)
Skipping FlatDB
Problem with HSQL MySQL:
user error (Couldn't load Database.HaskellDB.HSQL.MySQL.driver from package haskelldb-hsql-mysql-0.10)
Skipping HSQL MySQL
Problem with HSQL SQLite:
user error (Couldn't load Database.HaskellDB.HSQL.SQLite.driver from package haskelldb-hsql-sqlite-0.10)
Skipping HSQL SQLite
Cases: 0  Tried: 0  Errors: 0  Failures: 0
Skipped databases: ["FlatDB","HSQL MySQL","HSQL SQLite"]

This is despite having followed the build instructions carefully. I don't even know if I'm doing the right thing with these tests -- they obviously require some configuration, which I think I've done right, but there is no README for running the tests. I've googled for the error, with no results (next step the mailing list, but it seems crazy that I can't even get this far without subscribing to a mailing list and bothering someone). Also, the test suite doesn't actually compile without a minor fix, which indicates that not many people are actively running these tests, so maybe this entire test suite is non-functional. Who knows?

So, I'll see if I can just use HSQL straight. Unfortunately, there is no real documentation or tutorial for HSQL, nothing in the sources that tells you how to do even a basic test -- the online tutorials are very old and don't seem to actually cover making a connection. I tried this as a test app:

import Database.HSQL.MySQL (connect)
import Database.HSQL

main = do
        c <- connect "localhost" "my_db" "my_username" "my_password"
        disconnect c
        return ()

It compiles, but throws this extremely helpful exception:

*** Exception: (unknown)

So, I'm giving up for now. HaskellDB also appears to have an HDBC backend (HDBC being another lower level SQL library, like HSQL), so I'll try HDBC when I get the motivation. I want to know that I have libraries that basically work before I invest any time on this, and tests or basic examples are essential to finding this out. Unfortunately these things seem to be somewhat lacking.

OK, </rant>

Comments §

§ On 14 July 2007, evtujo wrote:
220 This won't help with your current problem, but did you see this upcoming book:

http://www.realworldhaskell.org/blog/

I'm not sure if they are still looking but at one point they were looking for previewers.

§ On 14 July 2007, David wrote:
221 It is curious. I successfully use haskelldb in windows with the odbc driver, the HDBC_odbc backend and the embedded Firebird database. I never tried HSQL. I remember that haskelldb compile without errors and everything ran fine.

What version of haskelldb are you using?

I recommend you the one that live in hackage.haskell.org. Don't run the test. If your program connect with your db, then everything must be ok.

Good luck.

§ On 14 July 2007, Terje Pedersen wrote:
222 If you modify your code like this you can track the SqlError.

import Database.HSQL.MySQL (connect)
import Database.HSQL
import Control.Exception

main =
  catchDyn (do
    c <- connect "localhost" "my_db" "my_username" "my_password"
    disconnect c
    return ())
    handler
  where handler :: SqlError -> IO ()
        handler err = print err

§ On 15 July 2007, Terje Pedersen wrote:
223 http://senikk.com/blog/view/493 <- more HSQL code also reading from DB (PS! norwegian text)

§ On 16 July 2007, luke wrote:
224 Terje: Thanks for the help! It looks like I may get somewhere with this now. Also its very useful more generally to know how to print exceptions, it show how much of a haskell newbie I am.

§ On 21 August 2007, david wrote:
242 What is currently the best library to use when connecting to a mysql db ?

§ On 11 June 2008, Sudeept wrote:
321 http://book.realworldhaskell.org/beta/databases.html
this is a good site for HDBC and it works good.
Also the error "Exception unknown" may be because you create a table already created or read from nowhere etc.

Add comment

Format:

  • Javascript has to be on to get past my spam protection, and cookies, and there is a delay, sorry for any inconvenience!
  • I reserve the right to moderate comments.