git.iko.soy/typeable/postgresql-simple
on master help sign in
Large Object tweaks
23ab08dLeon P Smith
src/Database/PostgreSQL/Simple/LargeObjects.hs+25−4
@@ -1,3 +1,5 @@
1+{-# LANGUAGE OverloadedStrings #-}
2+
1-----------------------------------------------------------------------------
3-----------------------------------------------------------------------------
2-- |
4-- |
3-- Module : Database.PostgreSQL.Simple.LargeObjects
5-- Module : Database.PostgreSQL.Simple.LargeObjects
@@ -14,13 +16,32 @@ module Database.PostgreSQL.Simple.LargeObjects
14 , Oid(..)
16 , Oid(..)
15 ) where
17 ) where
16
18
19+import Control.Applicative ((<$>))
20+import Control.Exception (throwIO)
17import Database.PostgreSQL.LibPQ (Oid(..))
21import Database.PostgreSQL.LibPQ (Oid(..))
18import qualified Database.PostgreSQL.LibPQ as PQ
22import qualified Database.PostgreSQL.LibPQ as PQ
19import Database.PostgreSQL.Simple.Internal
23import Database.PostgreSQL.Simple.Internal
20import Foreign.C.Types(CInt)
24import Foreign.C.Types(CInt)
21
25
22−loImport :: Connection -> FilePath -> IO (Maybe Oid)
26+loImport :: Connection -> FilePath -> IO Oid
23−loImport conn path = withConnection conn $ \c -> PQ.loImport c path
27+loImport conn path = withConnection conn $ \c -> do
28+ res <- PQ.loImport c path
29+ case res of
30+ Nothing -> do
31+ msg <- maybe "loImport error" id <$> PQ.errorMessage c
32+ throwIO $ SqlError { sqlNativeError = -1 -- FIXME?
33+ , sqlErrorMsg = msg
34+ , sqlState = "" }
35+ Just x -> return x
36+
24
37
25−loExport :: Connection -> Oid -> FilePath -> IO (Maybe ())
38+loExport :: Connection -> Oid -> FilePath -> IO ()
26−loExport conn oid path = withConnection conn $ \c -> PQ.loExport c oid path
39+loExport conn oid path = withConnection conn $ \c -> do
40+ res <- PQ.loExport c oid path
41+ case res of
42+ Nothing -> do
43+ msg <- maybe "loExport error" id <$> PQ.errorMessage c
44+ throwIO $ SqlError { sqlNativeError = -1 -- FIXME?
45+ , sqlErrorMsg = msg
46+ , sqlState = "" }
47+ Just x -> return x