git.iko.soy/typeable/postgresql-simple
on master help sign in
Remove redundancy in finishQueryWith
1238a37Bardur Arantsson
src/Database/PostgreSQL/Simple/Internal/PQResultUtils.hs+8−12
@@ -32,26 +32,22 @@ finishQueryWith :: RowParser r -> Connection -> Query -> PQ.Result -> IO [r]
32finishQueryWith parser conn q result = do
32finishQueryWith parser conn q result = do
33 status <- PQ.resultStatus result
33 status <- PQ.resultStatus result
34 case status of
34 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
39 PQ.TuplesOk -> do
35 PQ.TuplesOk -> do
40 nrows <- PQ.ntuples result
36 nrows <- PQ.ntuples result
41 ncols <- PQ.nfields result
37 ncols <- PQ.nfields result
42 forM' 0 (nrows-1) $ \row ->
38 forM' 0 (nrows-1) $ \row ->
43 getRowWith parser row ncols conn result
39 getRowWith parser row ncols conn result
44− PQ.CopyOut ->
40+ PQ.EmptyQuery -> queryErr "query: Empty query"
41+ PQ.CommandOk -> queryErr "query resulted in a command response"
45− throwIO $ QueryError "query: COPY TO is not supported" q
42+ PQ.CopyOut -> queryErr "query: COPY TO is not supported"
46− PQ.CopyIn ->
47− throwIO $ QueryError "query: COPY FROM is not supported" q
43+ PQ.CopyIn -> queryErr "query: COPY FROM is not supported"
48− PQ.CopyBoth ->
49− throwIO $ QueryError "query: COPY BOTH is not supported" q
44+ PQ.CopyBoth -> queryErr "query: COPY BOTH is not supported"
50− PQ.SingleTuple ->
51− throwIO $ QueryError "query: single-row mode is not supported" q
45+ PQ.SingleTuple -> queryErr "query: single-row mode is not supported"
52 PQ.BadResponse -> throwResultError "query" result status
46 PQ.BadResponse -> throwResultError "query" result status
53 PQ.NonfatalError -> throwResultError "query" result status
47 PQ.NonfatalError -> throwResultError "query" result status
54 PQ.FatalError -> throwResultError "query" result status
48 PQ.FatalError -> throwResultError "query" result status
49+ where
50+ queryErr msg = throwIO $ QueryError msg q
55
51
56getRowWith :: RowParser r -> PQ.Row -> PQ.Column -> Connection -> PQ.Result -> IO r
52getRowWith :: RowParser r -> PQ.Row -> PQ.Column -> Connection -> PQ.Result -> IO r
57getRowWith parser row ncols conn result = do
53getRowWith parser row ncols conn result = do