Skip to content

Commit 321a16a

Browse files
author
Grant Monroe
committed
Added bindings to sendDescribePrepared and sendDescribePortal.
1 parent 8e2313a commit 321a16a

File tree

1 file changed

+46
-6
lines changed

1 file changed

+46
-6
lines changed

Database/PQ.hsc

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ module Database.PQ
9797
, sendQueryParams
9898
, sendPrepare
9999
, sendQueryPrepared
100-
--, sendDescribePrepared
101-
--, sendDescribePortal
100+
, sendDescribePrepared
101+
, sendDescribePortal
102102
, getResult
103103
, consumeInput
104104
, isBusy
@@ -636,6 +636,40 @@ sendQueryPrepared connection stmtName mPairs rFmt =
636636
)
637637

638638

639+
-- | Submits a request to obtain information about the specified
640+
-- prepared statement, without waiting for completion.
641+
--
642+
-- This is an asynchronous version of 'describePrepared': it returns
643+
-- 'True' if it was able to dispatch the request, and 'False' if
644+
-- not. After a successful call, call 'getResult' to obtain the
645+
-- results. The function's parameters are handled identically to
646+
-- 'describePrepared'. Like 'describePrepared', it will not work on
647+
-- 2.0-protocol connections.
648+
sendDescribePrepared :: Connection
649+
-> B.ByteString -- ^ stmtName
650+
-> IO Bool
651+
sendDescribePrepared connection stmtName =
652+
enumFromConn connection $ \c ->
653+
B.useAsCString stmtName $ \s ->
654+
c_PQsendDescribePrepared c s
655+
656+
657+
-- | Submits a request to obtain information about the specified
658+
-- portal, without waiting for completion.
659+
--
660+
-- This is an asynchronous version of 'describePortal': it returns
661+
-- 'True' if it was able to dispatch the request, and 'False' if
662+
-- not. After a successful call, call 'getResult' to obtain the
663+
-- results. The function's parameters are handled identically to
664+
-- 'describePortal'. Like 'describePortal', it will not work on
665+
-- 2.0-protocol connections.
666+
sendDescribePortal :: Connection
667+
-> B.ByteString -- ^ portalName
668+
-> IO Bool
669+
sendDescribePortal connection portalName =
670+
enumFromConn connection $ \c ->
671+
B.useAsCString portalName $ \p ->
672+
c_PQsendDescribePortal c p
639673

640674

641675
-- | Make a connection to the database server in a nonblocking manner.
@@ -779,10 +813,10 @@ isnonblocking :: Connection
779813
isnonblocking connection = enumFromConn connection c_PQisnonblocking
780814

781815

782-
-- | Waits for the next result from a prior sendQuery, sendQueryParams,
783-
-- sendPrepare, or sendQueryPrepared call, and returns it. A null
784-
-- pointer is returned when the command is complete and there will be
785-
-- no more results.
816+
-- | Waits for the next result from a prior 'sendQuery',
817+
-- 'sendQueryParams', 'sendPrepare', or 'sendQueryPrepared' call, and
818+
-- returns it. A null pointer is returned when the command is complete
819+
-- and there will be no more results.
786820
getResult :: Connection
787821
-> IO (Maybe Result)
788822
getResult connection =
@@ -1408,6 +1442,12 @@ foreign import ccall unsafe "libpq-fe.h PQsendQueryPrepared"
14081442
c_PQsendQueryPrepared :: Ptr PGconn -> CString -> CInt -> Ptr CString
14091443
-> Ptr CInt -> Ptr CInt -> CInt -> IO CInt
14101444

1445+
foreign import ccall unsafe "libpq-fe.h PQsendDescribePrepared"
1446+
c_PQsendDescribePrepared :: Ptr PGconn -> CString -> IO CInt
1447+
1448+
foreign import ccall unsafe "libpq-fe.h PQsendDescribePortal"
1449+
c_PQsendDescribePortal :: Ptr PGconn -> CString -> IO CInt
1450+
14111451
foreign import ccall unsafe "libpq-fe.h PQflush"
14121452
c_PQflush :: Ptr PGconn ->IO CInt
14131453

0 commit comments

Comments
 (0)