git.iko.soy/typeable/postgresql-simple
on master help sign in
Consume all results after a COPY

Closes #119. This patch feels wrong, but it fixes the test case. It'll have to do for now, as a quick fix. Among other things, I believe that PQ.getResult can block. Ugh. This whole issue has definitely highlighted some of the annoyances I have with libpq, but at least it's still fantastically better than ODBC.

commitca3b230937dcc892022c57eb0695a5f145c46eb6 authorLeon P Smith <leon@melding-monads.com> dateSun 7 Sep 2014, 18:21 (12 years ago) parent6182abc
1 file changed+10
src/Database/PostgreSQL/Simple/Copy.hs+10
src/Database/PostgreSQL/Simple/Copy.hs+10
@@ -186,6 +186,7 @@ putCopyEnd conn = withConnection conn $ \pqconn -> do
186186putCopyError :: Connection -> B.ByteString -> IO ()
187187putCopyError conn err = withConnection conn $ \pqconn -> do
188188 doCopyIn funcName (\c -> PQ.putCopyEnd c (Just err)) pqconn
189+ consumeResults pqconn
189190 where
190191 funcName = "Database.PostgreSQL.Simple.Copy.putCopyError"
191192
@@ -220,6 +221,7 @@ getCopyCommandTag :: B.ByteString -> PQ.Connection -> IO Int64
220221getCopyCommandTag funcName pqconn = do
221222 result <- maybe (fail errCmdStatus) return =<< PQ.getResult pqconn
222223 cmdStat <- maybe (fail errCmdStatus) return =<< PQ.cmdStatus result
224+ consumeResults pqconn
223225 let rowCount = P.string "COPY " *> (P.decimal <* P.endOfInput)
224226 case P.parseOnly rowCount cmdStat of
225227 Left _ -> fail errCmdStatusFmt
@@ -227,3 +229,11 @@ getCopyCommandTag funcName pqconn = do
227229 where
228230 errCmdStatus = B.unpack funcName ++ ": failed to fetch command status"
229231 errCmdStatusFmt = B.unpack funcName ++ ": failed to parse command status"
232+
233+
234+consumeResults :: PQ.Connection -> IO ()
235+consumeResults pqconn = do
236+ mres <- PQ.getResult pqconn
237+ case mres of
238+ Nothing -> return ()
239+ Just _ -> consumeResults pqconn