Skip to content

Commit 1238a37

Browse files
Remove redundancy in finishQueryWith
1 parent d8f6d7d commit 1238a37

1 file changed

Lines changed: 8 additions & 12 deletions

File tree

src/Database/PostgreSQL/Simple/Internal/PQResultUtils.hs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,22 @@ finishQueryWith :: RowParser r -> Connection -> Query -> PQ.Result -> IO [r]
3232
finishQueryWith parser conn q result = do
3333
status <- PQ.resultStatus result
3434
case status of
35-
PQ.EmptyQuery ->
36-
throwIO $ QueryError "query: Empty query" q
37-
PQ.CommandOk ->
38-
throwIO $ QueryError "query resulted in a command response" q
3935
PQ.TuplesOk -> do
4036
nrows <- PQ.ntuples result
4137
ncols <- PQ.nfields result
4238
forM' 0 (nrows-1) $ \row ->
4339
getRowWith parser row ncols conn result
44-
PQ.CopyOut ->
45-
throwIO $ QueryError "query: COPY TO is not supported" q
46-
PQ.CopyIn ->
47-
throwIO $ QueryError "query: COPY FROM is not supported" q
48-
PQ.CopyBoth ->
49-
throwIO $ QueryError "query: COPY BOTH is not supported" q
50-
PQ.SingleTuple ->
51-
throwIO $ QueryError "query: single-row mode is not supported" q
40+
PQ.EmptyQuery -> queryErr "query: Empty query"
41+
PQ.CommandOk -> queryErr "query resulted in a command response"
42+
PQ.CopyOut -> queryErr "query: COPY TO is not supported"
43+
PQ.CopyIn -> queryErr "query: COPY FROM is not supported"
44+
PQ.CopyBoth -> queryErr "query: COPY BOTH is not supported"
45+
PQ.SingleTuple -> queryErr "query: single-row mode is not supported"
5246
PQ.BadResponse -> throwResultError "query" result status
5347
PQ.NonfatalError -> throwResultError "query" result status
5448
PQ.FatalError -> throwResultError "query" result status
49+
where
50+
queryErr msg = throwIO $ QueryError msg q
5551

5652
getRowWith :: RowParser r -> PQ.Row -> PQ.Column -> Connection -> PQ.Result -> IO r
5753
getRowWith parser row ncols conn result = do

0 commit comments

Comments
 (0)