module DB.HSQL.Core where
import Prelude hiding(catch)
import Control.Monad(when,unless)
import Control.Exception(Exception,throw,catch,handle)
import Control.Concurrent.MVar(MVar,withMVar,modifyMVar_)
import Data.Dynamic(cast)
import DB.HSQL.Error(SqlError(SqlClosedHandle))
closeHandle :: MVar Bool
-> IO ()
-> IO ()
closeHandle ref action =
modifyMVar_ ref (\closed -> unless closed action
>> return True)
checkHandle :: MVar Bool
-> IO a
-> IO a
checkHandle ref action =
withMVar ref (\closed -> when closed (throw SqlClosedHandle)
>> action)
sqlExceptions :: Exception x
=> x
-> Maybe SqlError
sqlExceptions = cast
catchSql :: IO a -> (SqlError -> IO a) -> IO a
catchSql = catch
handleSql :: (SqlError -> IO a) -> IO a -> IO a
handleSql = handle