packages feed

postgresql-libpq 0.8.2.1 → 0.8.2.2

raw patch · 2 files changed

+65/−55 lines, 2 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

Database/PostgreSQL/LibPQ.hsc view
@@ -229,7 +229,7 @@                                                ) import qualified Data.ByteString as B -#if __GLASGOW_HASKELL__ >= 700+#if __GLASGOW_HASKELL__ >= 700 && __GLASGOW_HASKELL__ < 706 import Control.Concurrent (newMVar, tryTakeMVar) #endif @@ -266,7 +266,9 @@     do connPtr <- B.useAsCString conninfo c_PQconnectdb        if connPtr == nullPtr            then fail "libpq failed to allocate a PGconn structure"-#if __GLASGOW_HASKELL__ >= 700+#if __GLASGOW_HASKELL__ >= 706+           else Conn `fmap` FC.newForeignPtr connPtr (pqfinish connPtr)+#elif __GLASGOW_HASKELL__ >= 700            else Conn `fmap` newForeignPtrOnce connPtr (pqfinish connPtr) #else            else Conn `fmap` newForeignPtr p_PQfinish connPtr@@ -279,13 +281,21 @@     do connPtr <- B.useAsCString connStr c_PQconnectStart        if connPtr == nullPtr            then fail "libpq failed to allocate a PGconn structure"-#if __GLASGOW_HASKELL__ >= 700+#if __GLASGOW_HASKELL__ >= 706+           else Conn `fmap` FC.newForeignPtr connPtr (pqfinish connPtr)+#elif __GLASGOW_HASKELL__ >= 700            else Conn `fmap` newForeignPtrOnce connPtr (pqfinish connPtr) #else            else Conn `fmap` newForeignPtr p_PQfinish connPtr #endif  #if __GLASGOW_HASKELL__ >= 700+-- | This covers the case when a connection is closed while other Haskell+--   threads are using GHC's IO manager to wait on the descriptor.  This is+--   commonly the case with asynchronous notifications, for example.  Since+--   libpq is responsible for opening and closing the file descriptor, GHC's+--   IO manager needs to be informed that the file descriptor has been+--   closed.  The IO manager will then raise an exception in those threads. pqfinish :: Ptr PGconn -> IO () pqfinish conn = do    mfd <- c_PQsocket conn@@ -294,7 +304,9 @@            -- This case may be worth investigating further            c_PQfinish conn      fd -> closeFdWith (\_ -> c_PQfinish conn) (Fd fd)+#endif +#if __GLASGOW_HASKELL__ >= 700 && __GLASGOW_HASKELL__ < 706 -- | Workaround for bug in 'FC.newForeignPtr' before base 4.6.  Ensure the -- finalizer is only run once, to prevent a segfault.  See GHC ticket #7170 --@@ -417,7 +429,7 @@          (#const PGRES_POLLING_OK)      -> return PollingOk          (#const PGRES_POLLING_WRITING) -> return PollingWriting          (#const PGRES_POLLING_FAILED)  -> return PollingFailed-         _ -> error $ "unexpected polling status " ++ show code+         _ -> fail $ "unexpected polling status " ++ show code   -- | Closes the connection to the server.@@ -516,17 +528,17 @@        -> IO ConnStatus status connection = do   stat <- withConn connection c_PQstatus-  return $ case stat of-             (#const CONNECTION_OK)               -> ConnectionOk-             (#const CONNECTION_BAD)              -> ConnectionBad-             (#const CONNECTION_STARTED)          -> ConnectionStarted-             (#const CONNECTION_MADE)             -> ConnectionMade-             (#const CONNECTION_AWAITING_RESPONSE)-> ConnectionAwaitingResponse-             (#const CONNECTION_AUTH_OK)          -> ConnectionAuthOk-             (#const CONNECTION_SETENV)           -> ConnectionSetEnv-             (#const CONNECTION_SSL_STARTUP)      -> ConnectionSSLStartup-             --(#const CONNECTION_NEEDED)           -> ConnectionNeeded-             c -> error $ "Unknown connection status " ++ show c+  case stat of+    (#const CONNECTION_OK)               -> return ConnectionOk+    (#const CONNECTION_BAD)              -> return ConnectionBad+    (#const CONNECTION_STARTED)          -> return ConnectionStarted+    (#const CONNECTION_MADE)             -> return ConnectionMade+    (#const CONNECTION_AWAITING_RESPONSE)-> return ConnectionAwaitingResponse+    (#const CONNECTION_AUTH_OK)          -> return ConnectionAuthOk+    (#const CONNECTION_SETENV)           -> return ConnectionSetEnv+    (#const CONNECTION_SSL_STARTUP)      -> return ConnectionSSLStartup+    --(#const CONNECTION_NEEDED)           -> ConnectionNeeded+    c -> fail $ "Unknown connection status " ++ show c   data TransactionStatus = TransIdle    -- ^ currently idle@@ -544,13 +556,13 @@                   -> IO TransactionStatus transactionStatus connection = do     stat <- withConn connection c_PQtransactionStatus-    return $ case stat of-               (#const PQTRANS_IDLE)    -> TransIdle-               (#const PQTRANS_ACTIVE)  -> TransActive-               (#const PQTRANS_INTRANS) -> TransInTrans-               (#const PQTRANS_INERROR) -> TransInError-               (#const PQTRANS_UNKNOWN) -> TransUnknown-               c -> error $ "Unknown transaction status " ++ show c+    case stat of+      (#const PQTRANS_IDLE)    -> return TransIdle+      (#const PQTRANS_ACTIVE)  -> return TransActive+      (#const PQTRANS_INTRANS) -> return TransInTrans+      (#const PQTRANS_INERROR) -> return TransInError+      (#const PQTRANS_UNKNOWN) -> return TransUnknown+      c -> fail $ "Unknown transaction status " ++ show c   -- | Looks up a current parameter setting of the server.@@ -1180,9 +1192,9 @@     do num <- withForeignPtr res $ \resPtr ->               B.useAsCString columnName $ \columnNamePtr ->                   c_PQfnumber resPtr columnNamePtr-       return $ if num == -1-                  then Nothing-                  else Just $ toColumn num+       return $! if num == -1+                   then Nothing+                   else Just $ toColumn num   -- | Returns the OID of the table from which the given column was@@ -1502,7 +1514,7 @@  putCopyCString :: Connection -> CStringLen -> IO CopyInResult putCopyCString conn (str, len) =-    fmap toCopyInResult $+    toCopyInResult <$!>         withConn conn $ \ptr -> c_PQputCopyData ptr str (fromIntegral len)  @@ -1517,10 +1529,10 @@ -- result status of the @COPY@ command.  Then return to normal operation. putCopyEnd :: Connection -> Maybe B.ByteString -> IO CopyInResult putCopyEnd conn Nothing =-    fmap toCopyInResult $+    toCopyInResult <$!>         withConn conn $ \ptr -> c_PQputCopyEnd ptr nullPtr putCopyEnd conn (Just errormsg) =-    fmap toCopyInResult $+    toCopyInResult <$!>         B.useAsCString errormsg $ \errormsg_cstr ->             withConn conn $ \ptr -> c_PQputCopyEnd ptr errormsg_cstr @@ -1543,13 +1555,13 @@ getCopyData conn async = alloca $ \strp -> withConn conn $ \c -> do     len <- c_PQgetCopyData c strp (if async then 1 else 0)     if len <= 0-      then return $ case compare len (-1) of-                      LT -> CopyOutError-                      EQ -> CopyOutDone-                      GT -> CopyOutWouldBlock+      then return $! case compare len (-1) of+                       LT -> CopyOutError+                       EQ -> CopyOutDone+                       GT -> CopyOutWouldBlock       else do         fp <- newForeignPtr p_PQfreemem =<< peek strp-        return (CopyOutRow (B.fromForeignPtr fp 0 (fromIntegral len)))+        return $! CopyOutRow (B.fromForeignPtr fp 0 (fromIntegral len))   -- $asynccommand@@ -1756,7 +1768,7 @@ setnonblocking connection blocking =     do let arg = fromIntegral $ fromEnum blocking        stat <- withConn connection $ \ptr -> c_PQsetnonblocking ptr arg-       return $ stat == 0+       return $! stat == 0   -- | Returns the blocking status of the database connection.@@ -1927,7 +1939,7 @@                B.useAsCString enc $ \s ->                    c_PQsetClientEncoding c s -       return $ stat == 0+       return $! stat == 0   data Verbosity = ErrorsTerse@@ -1967,14 +1979,7 @@ withConn :: Connection          -> (Ptr PGconn -> IO b)          -> IO b-withConn connection f =-    withConn' connection $ flip withForeignPtr f---withConn' :: Connection-          -> (ForeignPtr PGconn -> IO b)-          -> IO b-withConn' (Conn fp) f = f fp+withConn (Conn fp) f = withForeignPtr fp f   enumFromConn :: (Integral a, Enum b) => Connection@@ -2069,6 +2074,11 @@                 ReadWriteMode -> (#const INV_READ) .|. (#const INV_WRITE)                 AppendMode    -> (#const INV_WRITE) +(<$!>) :: (a -> b) -> IO a -> IO b+f <$!> ma = ma >>= \a -> return $! f a+infixr 0 <$!>+{-# INLINE (<$!>) #-}+ toMaybeOid :: Oid -> Maybe Oid toMaybeOid oid | oid == invalidOid = Nothing                | otherwise         = Just oid@@ -2088,7 +2098,7 @@ loCreat :: Connection -> IO (Maybe Oid) loCreat connection     = withConn connection $ \c -> do-        toMaybeOid `fmap` c_lo_creat c (loMode ReadMode)+        toMaybeOid <$!> c_lo_creat c (loMode ReadMode)  -- | Creates a new large object with a particular Object ID.  Returns -- 'Nothing' if the requested Object ID is already in use by some other@@ -2098,7 +2108,7 @@ loCreate :: Connection -> Oid -> IO (Maybe Oid) loCreate connection oid     = withConn connection $ \c -> do-        toMaybeOid `fmap` c_lo_create c oid+        toMaybeOid <$!> c_lo_create c oid  -- | Imports an operating system file as a large object.  Note that the -- file is read by the client interface library, not by the server; so it@@ -2109,7 +2119,7 @@ loImport connection filepath     = withConn connection $ \c -> do         withCString filepath $ \f -> do-          toMaybeOid `fmap` c_lo_import c f+          toMaybeOid <$!> c_lo_import c f  -- | Imports an operating system file as a large object with the given -- Object ID.  Combines the behavior of 'loImport' and 'loCreate'@@ -2118,7 +2128,7 @@ loImportWithOid connection filepath oid     = withConn connection $ \c -> do         withCString filepath $ \f -> do-          toMaybeOid `fmap` c_lo_import_with_oid c f oid+          toMaybeOid <$!> c_lo_import_with_oid c f oid  -- | Exports a large object into a operating system file.  Note that -- the file is written by the client interface library, not the server.@@ -2128,7 +2138,7 @@ loExport connection oid filepath     = withConn connection $ \c -> do         withCString filepath $ \f -> do-          negError `fmap` c_lo_export c oid f+          negError <$!> c_lo_export c oid f  -- | Opens an existing large object for reading or writing.  The Oid specifies -- the large object to open.  A large object cannot be opened before it is@@ -2185,7 +2195,7 @@ loWrite connection (LoFd fd) bytes     = withConn connection $ \c -> do         B.unsafeUseAsCStringLen bytes $ \(byteptr,len) -> do-          nonnegInt `fmap` c_lo_write c fd byteptr (fromIntegral len)+          nonnegInt <$!> c_lo_write c fd byteptr (fromIntegral len)  -- | @loRead conn fd len@ reads up to @len@ bytes from the large object -- descriptor @fd@.  In the event of an error,  'Nothing' is returned.@@ -2224,7 +2234,7 @@ loTell :: Connection -> LoFd -> IO (Maybe Int) loTell connection (LoFd fd)     = withConn connection $ \c -> do-        nonnegInt `fmap` c_lo_tell c fd+        nonnegInt <$!> c_lo_tell c fd  -- | Truncates a large object to a given length.  If the length is greater -- than the current large object,  then the large object is extended with@@ -2238,7 +2248,7 @@ loTruncate :: Connection -> LoFd -> Int -> IO (Maybe ()) loTruncate connection (LoFd fd) size     = withConn connection $ \c -> do-        negError `fmap` c_lo_truncate c fd (fromIntegral size)+        negError <$!> c_lo_truncate c fd (fromIntegral size)  -- | Closes a large object descriptor.  Any large object descriptors that -- remain open at the end of a transaction will be closed automatically.@@ -2246,14 +2256,14 @@ loClose :: Connection -> LoFd -> IO (Maybe ()) loClose connection (LoFd fd)     = withConn connection $ \c -> do-        negError `fmap` c_lo_close c fd+        negError <$!> c_lo_close c fd  -- | Removes a large object from the database.  loUnlink :: Connection -> Oid -> IO (Maybe ()) loUnlink connection oid     = withConn connection $ \c -> do-        negError `fmap` c_lo_unlink c oid+        negError <$!> c_lo_unlink c oid  foreign import ccall        "libpq-fe.h PQconnectdb"     c_PQconnectdb :: CString ->IO (Ptr PGconn)
postgresql-libpq.cabal view
@@ -1,5 +1,5 @@ Name:                postgresql-libpq-Version:             0.8.2.1+Version:             0.8.2.2 Synopsis:            low-level binding to libpq  Description:         This is a binding to libpq: the C application@@ -38,4 +38,4 @@ source-repository this   type:     git   location: http://github.com/lpsmith/postgresql-libpq-  tag:      v0.8.2.1+  tag:      v0.8.2.2