@@ -1,3 +1,5 @@
1+{-# LANGUAGE OverloadedStrings #-}
2+
13-----------------------------------------------------------------------------
24-- |
35-- Module : Database.PostgreSQL.Simple.LargeObjects
@@ -14,13 +16,32 @@ module Database.PostgreSQL.Simple.LargeObjects
1416 , Oid(..)
1517 ) where
1618
19+import Control.Applicative ((<$>))
20+import Control.Exception (throwIO)
1721import Database.PostgreSQL.LibPQ (Oid(..))
1822import qualified Database.PostgreSQL.LibPQ as PQ
1923import Database.PostgreSQL.Simple.Internal
2024import Foreign.C.Types(CInt)
2125
22−loImport :: Connection -> FilePath -> IO (Maybe Oid)
23−loImport conn path = withConnection conn $ \c -> PQ.loImport c path
26+loImport :: Connection -> FilePath -> IO Oid
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+
2437
25−loExport :: Connection -> Oid -> FilePath -> IO (Maybe ())
26−loExport conn oid path = withConnection conn $ \c -> PQ.loExport c oid path
38+loExport :: Connection -> Oid -> FilePath -> IO ()
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