module Database.HDBC.Types
(IConnection(..),
Statement(..),
SqlError(..),
nToSql, iToSql, posixToSql, fromSql, safeFromSql, toSql,
SqlValue(..),
ConnWrapper(..),
withWConn
)
where
import Database.HDBC.Statement
import Database.HDBC.ColTypes
import Control.Exception ( finally )
class IConnection conn where
disconnect :: conn -> IO ()
commit :: conn -> IO ()
rollback :: conn -> IO ()
runRaw :: conn -> String -> IO ()
runRaw conn
conn String
sql = do
Statement
sth <- conn -> String -> IO Statement
forall conn. IConnection conn => conn -> String -> IO Statement
prepare conn
conn String
sql
Integer
_ <- Statement -> [SqlValue] -> IO Integer
execute Statement
sth [] IO Integer -> IO () -> IO Integer
forall a b. IO a -> IO b -> IO a
`finally` Statement -> IO ()
finish Statement
sth
() -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
run :: conn -> String -> [SqlValue] -> IO Integer
prepare :: conn -> String -> IO Statement
clone :: conn -> IO conn
hdbcDriverName :: conn -> String
hdbcClientVer :: conn -> String
proxiedClientName :: conn -> String
proxiedClientVer :: conn -> String
dbServerVer :: conn -> String
dbTransactionSupport :: conn -> Bool
getTables :: conn -> IO [String]
describeTable :: conn -> String -> IO [(String, SqlColDesc)]
data ConnWrapper = forall conn. IConnection conn => ConnWrapper conn
withWConn :: forall b. ConnWrapper -> (forall conn. IConnection conn => conn -> b) -> b
withWConn :: ConnWrapper -> (forall conn. IConnection conn => conn -> b) -> b
withWConn ConnWrapper
conn forall conn. IConnection conn => conn -> b
f =
case ConnWrapper
conn of
ConnWrapper conn
x -> conn -> b
forall conn. IConnection conn => conn -> b
f conn
x
instance IConnection ConnWrapper where
disconnect :: ConnWrapper -> IO ()
disconnect ConnWrapper
w = ConnWrapper
-> (forall conn. IConnection conn => conn -> IO ()) -> IO ()
forall b.
ConnWrapper -> (forall conn. IConnection conn => conn -> b) -> b
withWConn ConnWrapper
w forall conn. IConnection conn => conn -> IO ()
disconnect
commit :: ConnWrapper -> IO ()
commit ConnWrapper
w = ConnWrapper
-> (forall conn. IConnection conn => conn -> IO ()) -> IO ()
forall b.
ConnWrapper -> (forall conn. IConnection conn => conn -> b) -> b
withWConn ConnWrapper
w forall conn. IConnection conn => conn -> IO ()
commit
rollback :: ConnWrapper -> IO ()
rollback ConnWrapper
w = ConnWrapper
-> (forall conn. IConnection conn => conn -> IO ()) -> IO ()
forall b.
ConnWrapper -> (forall conn. IConnection conn => conn -> b) -> b
withWConn ConnWrapper
w forall conn. IConnection conn => conn -> IO ()
rollback
runRaw :: ConnWrapper -> String -> IO ()
runRaw ConnWrapper
w = ConnWrapper
-> (forall conn. IConnection conn => conn -> String -> IO ())
-> String
-> IO ()
forall b.
ConnWrapper -> (forall conn. IConnection conn => conn -> b) -> b
withWConn ConnWrapper
w forall conn. IConnection conn => conn -> String -> IO ()
runRaw
run :: ConnWrapper -> String -> [SqlValue] -> IO Integer
run ConnWrapper
w = ConnWrapper
-> (forall conn.
IConnection conn =>
conn -> String -> [SqlValue] -> IO Integer)
-> String
-> [SqlValue]
-> IO Integer
forall b.
ConnWrapper -> (forall conn. IConnection conn => conn -> b) -> b
withWConn ConnWrapper
w forall conn.
IConnection conn =>
conn -> String -> [SqlValue] -> IO Integer
run
prepare :: ConnWrapper -> String -> IO Statement
prepare ConnWrapper
w = ConnWrapper
-> (forall conn.
IConnection conn =>
conn -> String -> IO Statement)
-> String
-> IO Statement
forall b.
ConnWrapper -> (forall conn. IConnection conn => conn -> b) -> b
withWConn ConnWrapper
w forall conn. IConnection conn => conn -> String -> IO Statement
prepare
clone :: ConnWrapper -> IO ConnWrapper
clone ConnWrapper
w = ConnWrapper
-> (forall conn. IConnection conn => conn -> IO ConnWrapper)
-> IO ConnWrapper
forall b.
ConnWrapper -> (forall conn. IConnection conn => conn -> b) -> b
withWConn ConnWrapper
w (\conn
dbh -> conn -> IO conn
forall conn. IConnection conn => conn -> IO conn
clone conn
dbh IO conn -> (conn -> IO ConnWrapper) -> IO ConnWrapper
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ConnWrapper -> IO ConnWrapper
forall (m :: * -> *) a. Monad m => a -> m a
return (ConnWrapper -> IO ConnWrapper)
-> (conn -> ConnWrapper) -> conn -> IO ConnWrapper
forall b c a. (b -> c) -> (a -> b) -> a -> c
. conn -> ConnWrapper
forall conn. IConnection conn => conn -> ConnWrapper
ConnWrapper)
hdbcDriverName :: ConnWrapper -> String
hdbcDriverName ConnWrapper
w = ConnWrapper
-> (forall conn. IConnection conn => conn -> String) -> String
forall b.
ConnWrapper -> (forall conn. IConnection conn => conn -> b) -> b
withWConn ConnWrapper
w forall conn. IConnection conn => conn -> String
hdbcDriverName
hdbcClientVer :: ConnWrapper -> String
hdbcClientVer ConnWrapper
w = ConnWrapper
-> (forall conn. IConnection conn => conn -> String) -> String
forall b.
ConnWrapper -> (forall conn. IConnection conn => conn -> b) -> b
withWConn ConnWrapper
w forall conn. IConnection conn => conn -> String
hdbcClientVer
proxiedClientName :: ConnWrapper -> String
proxiedClientName ConnWrapper
w = ConnWrapper
-> (forall conn. IConnection conn => conn -> String) -> String
forall b.
ConnWrapper -> (forall conn. IConnection conn => conn -> b) -> b
withWConn ConnWrapper
w forall conn. IConnection conn => conn -> String
proxiedClientName
proxiedClientVer :: ConnWrapper -> String
proxiedClientVer ConnWrapper
w = ConnWrapper
-> (forall conn. IConnection conn => conn -> String) -> String
forall b.
ConnWrapper -> (forall conn. IConnection conn => conn -> b) -> b
withWConn ConnWrapper
w forall conn. IConnection conn => conn -> String
proxiedClientVer
dbServerVer :: ConnWrapper -> String
dbServerVer ConnWrapper
w = ConnWrapper
-> (forall conn. IConnection conn => conn -> String) -> String
forall b.
ConnWrapper -> (forall conn. IConnection conn => conn -> b) -> b
withWConn ConnWrapper
w forall conn. IConnection conn => conn -> String
dbServerVer
dbTransactionSupport :: ConnWrapper -> Bool
dbTransactionSupport ConnWrapper
w = ConnWrapper
-> (forall conn. IConnection conn => conn -> Bool) -> Bool
forall b.
ConnWrapper -> (forall conn. IConnection conn => conn -> b) -> b
withWConn ConnWrapper
w forall conn. IConnection conn => conn -> Bool
dbTransactionSupport
getTables :: ConnWrapper -> IO [String]
getTables ConnWrapper
w = ConnWrapper
-> (forall conn. IConnection conn => conn -> IO [String])
-> IO [String]
forall b.
ConnWrapper -> (forall conn. IConnection conn => conn -> b) -> b
withWConn ConnWrapper
w forall conn. IConnection conn => conn -> IO [String]
getTables
describeTable :: ConnWrapper -> String -> IO [(String, SqlColDesc)]
describeTable ConnWrapper
w = ConnWrapper
-> (forall conn.
IConnection conn =>
conn -> String -> IO [(String, SqlColDesc)])
-> String
-> IO [(String, SqlColDesc)]
forall b.
ConnWrapper -> (forall conn. IConnection conn => conn -> b) -> b
withWConn ConnWrapper
w forall conn.
IConnection conn =>
conn -> String -> IO [(String, SqlColDesc)]
describeTable