Database interface

Tim Docker timd@macquarie.com.au
Thu, 21 Aug 2003 18:43:55 +1000


Tom Pledger wrote:

 > How about introducing a Cursor abstract data type?
 > 
 >     doquery :: Process -> String -> b -> (Cursor -> b -> IO (b,
Bool))
 >                -> IO b
 >     stringv :: Cursor -> CInt -> IO String
 >     doublev :: Cursor -> CInt -> IO Double
 >     intv    :: Cursor -> CInt -> IO Int
 > 
 > This achieves the restriction you're after, because doquery is the
 > only exported producer of Cursor, and stringv etc. are the only
 > exported consumers of Cursor.

I like this. Not sure about whether I'd call it Cursor or just Row. Code
something like

    results <- doquery dbconn sqltext [] \row results -> do
        name    <- colv row 1
        address <- colv row 2
        return (name,address):results

seems quite tidy.

 > It also has the benefit that the function you pass to doquery can
make
 > other calls to doquery, without mucking up the 'current row' state.
 > There would be one current row per Cursor, not one per Process.

Is it normal or common to support multiple simultaneous queries on
a single DB connection?

Tim