packages feed

postgresql-libpq 0.10.0.0 → 0.10.1.0

raw patch · 5 files changed

+83/−23 lines, 5 filesdep +tastydep +tasty-hunitdep ~Win32dep ~base

Dependencies added: tasty, tasty-hunit

Dependency ranges changed: Win32, base

Files

CHANGELOG.md view
@@ -1,3 +1,8 @@+0.10.1.0+--------++- Fix issue with empty binary values (https://github.com/haskellari/postgresql-libpq/issues/54)+ 0.10.0.0 -------- 
postgresql-libpq.cabal view
@@ -1,6 +1,6 @@ cabal-version:      2.4 name:               postgresql-libpq-version:            0.10.0.0+version:            0.10.1.0 synopsis:           low-level binding to libpq description:   This is a binding to libpq: the C application@@ -24,7 +24,14 @@ build-type:         Custom extra-source-files: cbits/hs-libpq.h tested-with:-  GHC ==8.6.5 || ==8.8.4 || ==8.10.7 || ==9.0.2 || ==9.2.7 || ==9.4.4 || ==9.6.1+  GHC ==8.6.5+   || ==8.8.4+   || ==8.10.7+   || ==9.0.2+   || ==9.2.8+   || ==9.4.8+   || ==9.6.5+   || ==9.8.2  extra-source-files: CHANGELOG.md @@ -65,10 +72,11 @@     Database.PostgreSQL.LibPQ.Marshal     Database.PostgreSQL.LibPQ.Notify     Database.PostgreSQL.LibPQ.Oid+    Database.PostgreSQL.LibPQ.Ptr    build-depends:-    , base        >=4.12.0.0 && <4.19-    , bytestring  >=0.10.8.2 && <0.12+    , base        >=4.12.0.0 && <4.20+    , bytestring  >=0.10.8.2 && <0.13    if !os(windows)     build-depends: unix >=2.7.2.2 && <2.9@@ -107,6 +115,8 @@     , base     , bytestring     , postgresql-libpq+    , tasty             ^>=1.5+    , tasty-hunit       ^>=0.10.1  source-repository head   type:     git
src/Database/PostgreSQL/LibPQ.hs view
@@ -238,6 +238,7 @@ import Database.PostgreSQL.LibPQ.Marshal import Database.PostgreSQL.LibPQ.Notify import Database.PostgreSQL.LibPQ.Oid+import Database.PostgreSQL.LibPQ.Ptr  -- $dbconn -- The following functions deal with making a connection to a@@ -662,10 +663,13 @@ -- * 'ByteString' uses pinned memory -- * the reference to the 'CString' doesn't escape unsafeUseParamAsCString :: (B.ByteString, Format) -> (CString -> IO a) -> IO a-unsafeUseParamAsCString (bs, format) =+unsafeUseParamAsCString (bs, format) kont =     case format of-        Binary -> B.unsafeUseAsCString bs-        Text   -> B.useAsCString bs+        Binary -> B.unsafeUseAsCStringLen bs kont'+        Text   -> B.useAsCString bs kont+  where+    kont' (ptr, 0) = if ptr == nullPtr then kont emptyPtr else kont ptr+    kont' (ptr, _) = kont ptr  -- | Convert a list of parameters to the format expected by libpq FFI calls. withParams :: [Maybe (Oid, B.ByteString, Format)]
+ src/Database/PostgreSQL/LibPQ/Ptr.hs view
@@ -0,0 +1,7 @@+{-# LANGUAGE MagicHash #-}+module Database.PostgreSQL.LibPQ.Ptr (emptyPtr) where++import GHC.Ptr (Ptr (..))++emptyPtr :: Ptr a+emptyPtr = Ptr ""#
test/Smoke.hs view
@@ -1,17 +1,24 @@+{-# LANGUAGE OverloadedStrings #-} module Main (main) where -import Control.Monad (unless)+import Control.Monad             (unless)+import Data.Foldable             (toList) import Database.PostgreSQL.LibPQ-import Data.Foldable (toList)-import System.Environment (getEnvironment)-import System.Exit (exitFailure)+import System.Environment        (getEnvironment)+import System.Exit               (exitFailure)+import Test.Tasty                (defaultMain, testGroup)+import Test.Tasty.HUnit          (assertEqual, testCaseSteps) +import qualified Data.ByteString       as BS import qualified Data.ByteString.Char8 as BS8  main :: IO () main = do     libpqVersion >>= print-    withConnstring smoke+    withConnstring $ \connString -> defaultMain $ testGroup "postgresql-libpq"+        [ testCaseSteps "smoke" $ smoke connString+        , testCaseSteps "issue54" $ issue54 connString+        ]  withConnstring :: (BS8.ByteString -> IO ()) -> IO () withConnstring kont = do@@ -35,21 +42,48 @@         , "port=5432"         ] -smoke :: BS8.ByteString -> IO ()-smoke connstring = do+smoke :: BS8.ByteString -> (String -> IO ()) -> IO ()+smoke connstring info = do+    let infoShow x = info (show x)+     conn <- connectdb connstring      -- status functions-    db conn                >>= print-    user conn              >>= print-    host conn              >>= print-    port conn              >>= print-    status conn            >>= print-    transactionStatus conn >>= print-    protocolVersion conn   >>= print-    serverVersion conn     >>= print+    db conn                >>= infoShow+    user conn              >>= infoShow+    host conn              >>= infoShow+    port conn              >>= infoShow+    status conn            >>= infoShow+    transactionStatus conn >>= infoShow+    protocolVersion conn   >>= infoShow+    serverVersion conn     >>= infoShow      s <- status conn-    unless (s == ConnectionOk) exitFailure+    assertEqual "connection not ok" ConnectionOk s      finish conn++issue54 :: BS8.ByteString -> (String -> IO ()) -> IO ()+issue54 connString info = do+    conn <- connectdb connString++    Just result <- execParams conn+        "SELECT ($1 :: bytea), ($2 :: bytea)"+        [Just (Oid 17,"",Binary), Just (Oid 17,BS.empty,Binary)]+        Binary+    s <- resultStatus result+    assertEqual "result status" TuplesOk s++    -- ntuples result >>= info . show+    -- nfields result >>= info . show++    null1 <- getisnull result 0 0+    null2 <- getisnull result 0 1+    assertEqual "fst not null" False null1+    assertEqual "snd not null" False null2++    Just val1 <- getvalue result 0 0+    Just val2 <- getvalue result 0 1++    assertEqual "fst not null" BS.empty val1+    assertEqual "snd not null" BS.empty val2