8000 Test describing statements · postgres-haskell/postgres-wire@89c8720 · GitHub
[go: up one dir, main page]

Skip to content

Commit 89c8720

Browse files
Test describing statements
1 parent 3a4ca4c commit 89c8720

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

postgres-wire.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ test-suite postgres-wire-test
7070
build-depends: base
7171
, postgres-wire
7272
, bytestring
73+
, vector
7374
, tasty
7475
, tasty-hunit
7576
ghc-options: -threaded -rtsopts -with-rtsopts=-N

src/Database/PostgreSQL/Driver/Connection.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,10 +404,10 @@ collectBeforeReadyForQuery conn = do
404404
-- | Public
405405
describeStatement
406406
:: Connection
407-
-> StatementSQL
407+
-> B.ByteString
408408
-> IO (Either Error (V.Vector Oid, V.Vector FieldDescription))
409409
describeStatement conn stmt = do
410-
sendMessage s $ Parse sname stmt []
410+
sendMessage s $ Parse sname (StatementSQL stmt) []
411411
sendMessage s $ DescribeStatement sname
412412
sendMessage s Sync
413413
parseMessages <$> collectBeforeReadyForQuery conn

src/Database/PostgreSQL/Protocol/Types.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import Data.ByteString (ByteString)
1616
import Data.Vector (Vector)
1717

1818
-- Common
19-
newtype Oid = Oid { unOid :: Int32 } deriving (Show)
19+
newtype Oid = Oid { unOid :: Int32 } deriving (Show, Eq)
2020
newtype StatementName = StatementName ByteString deriving (Show)
2121
newtype StatementSQL = StatementSQL ByteString deriving (Show, Eq, Hashable)
2222
newtype PortalName = PortalName ByteString deriving (Show)

tests/Driver.hs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Control.Monad
66
import Data.Either
77
import qualified Data.ByteString as B
88
import qualified Data.ByteString.Char8 as BS
9+
import qualified Data.Vector as V
910

1011
import Test.Tasty
1112
import Test.Tasty.HUnit
@@ -22,6 +23,9 @@ testDriver = testGroup "Driver"
2223
, testCase "Empty query" testEmptyQuery
2324
, testCase "Query without result" testQueryWithoutResult
2425
, testCase "Invalid queries" testInvalidBatch
26+
, testCase "Describe statement" testDescribeStatement
27+
, testCase "Describe statement with no data" testDescribeStatementNoData
28+
, testCase "Describe empty statement" testDescribeStatementEmpty
2529
]
2630

2731
makeQuery1 :: B.ByteString -> Query
@@ -117,3 +121,24 @@ testInvalidBatch = do
117121
readReadyForQuery c
118122
checkInvalidResult c $ length qs
119123

124+
testDescribeStatement :: IO ()
125+
testDescribeStatement = withConnection $ \c -> do
126+
r <- describeStatement c $
127+
"select typname, typnamespace, typowner, typlen, typbyval,"
128+
<> "typcategory, typispreferred, typisdefined, typdelim, typrelid,"
129+
<> "typelem, typarray from pg_type where typtypmod = $1 "
130+
<> "and typisdefined = $2"
131+
assertBool "Should be Right" $ isRight r
132+
133+
testDescribeStatementNoData :: IO ()
134+
testDescribeStatementNoData = withConnection $ \c -> do
135+
r <- fromRight <$> describeStatement c "SET client_encoding TO UTF8"
136+
assertBool "Should be empty" $ V.null (fst r)
137+
assertBool "Should be empty" $ V.null (snd r)
138+
139+
testDescribeStatementEmpty :: IO ()
140+
testDescribeStatementEmpty = withConnection $ \c -> do
141+
r <- fromRight <$> describeStatement c ""
142+
assertBool "Should be empty" $ V.null (fst r)
143+
assertBool "Should be empty" $ V.null (snd r)
144+

0 commit comments

Comments
 (0)
0