Update of /cvsroot/htoolkit/HSQL/PostgreSQL
In directory sc8-pr-cvs1:/tmp/cvs-serv30505/PostgreSQL
Modified Files:
HSQL.hsc
Log Message:
The helper functions now closes the statement even if the processing action raises an exeption
Index: HSQL.hsc
===================================================================
RCS file: /cvsroot/htoolkit/HSQL/PostgreSQL/HSQL.hsc,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** HSQL.hsc 27 Sep 2003 09:42:28 -0000 1.8
--- HSQL.hsc 27 Sep 2003 09:44:13 -0000 1.9
***************
*** 623,647 ****
-- | The 'forEachRow' function iterates through the result set in 'Statement' and
! -- executes the given action for each row in the set. After processing the last row
! -- the statement is automatically closed.
forEachRow :: (Statement -> s -> IO s) -- ^ an action
-> Statement -- ^ the statement
-> s -- ^ initial state
-> IO s -- ^ final state
! forEachRow f stmt s = do
! success <- fetch stmt
! if success then f stmt s >>= forEachRow f stmt else closeStatement stmt >> return s
-- | The 'forEachRow\'' function is analogous to 'forEachRow' but doesn't provide state.
forEachRow' :: (Statement -> IO ()) -> Statement -> IO ()
! forEachRow' f stmt = do
! success <- fetch stmt
! if success then f stmt >> forEachRow' f stmt else closeStatement stmt
-- | The 'collectRows' function iterates through the result set in 'Statement' and
-- executes the given action for each row in the set. The values returned from action
! -- are collected and returned as list.
collectRows :: (Statement -> IO a) -> Statement -> IO [a]
! collectRows f stmt = loop
where
loop = do
--- 623,654 ----
-- | The 'forEachRow' function iterates through the result set in 'Statement' and
! -- executes the given action for each row in the set. The function closes the 'Statement'
! -- after the last row processing or if the given action raises an exception.
forEachRow :: (Statement -> s -> IO s) -- ^ an action
-> Statement -- ^ the statement
-> s -- ^ initial state
-> IO s -- ^ final state
! forEachRow f stmt s = loop s `finally` closeStatement stmt
! where
! loop s = do
! success <- fetch stmt
! if success then f stmt s >>= loop else return s
-- | The 'forEachRow\'' function is analogous to 'forEachRow' but doesn't provide state.
+ -- The function closes the 'Statement' after the last row processing or if the given
+ -- action raises an exception.
forEachRow' :: (Statement -> IO ()) -> Statement -> IO ()
! forEachRow' f stmt = loop `finally` closeStatement stmt
! where
! loop = do
! success <- fetch stmt
! when success (f stmt >> loop)
-- | The 'collectRows' function iterates through the result set in 'Statement' and
-- executes the given action for each row in the set. The values returned from action
! -- are collected and returned as list. The function closes the 'Statement' after the
! -- last row processing or if the given action raises an exception.
collectRows :: (Statement -> IO a) -> Statement -> IO [a]
! collectRows f stmt = loop `finally` closeStatement stmt
where
loop = do
***************
*** 652,654 ****
xs <- loop
return (x:xs)
! else closeStatement stmt >> return []
--- 659,661 ----
xs <- loop
return (x:xs)
! else return []
|