git.iko.soy/typeable/postgresql-simple
on master help sign in
Fix compatibility with older versions of postgresql-libpq
be85ee9Leon P Smith
src/Database/PostgreSQL/Simple/Copy.hs+4
@@ -85,8 +85,12 @@ doCopy funcName conn template q = do
85 PQ.TuplesOk -> err
85 PQ.TuplesOk -> err
86 PQ.CopyOut -> return ()
86 PQ.CopyOut -> return ()
87 PQ.CopyIn -> return ()
87 PQ.CopyIn -> return ()
88+#if MIN_VERSION_postgresql_libpq(0,9,3)
88 PQ.CopyBoth -> errMsg "COPY BOTH is not supported"
89 PQ.CopyBoth -> errMsg "COPY BOTH is not supported"
90+#endif
91+#if MIN_VERSION_postgresql_libpq(0,9,2)
89 PQ.SingleTuple -> errMsg "single-row mode is not supported"
92 PQ.SingleTuple -> errMsg "single-row mode is not supported"
93+#endif
90 PQ.BadResponse -> throwResultError funcName result status
94 PQ.BadResponse -> throwResultError funcName result status
91 PQ.NonfatalError -> throwResultError funcName result status
95 PQ.NonfatalError -> throwResultError funcName result status
92 PQ.FatalError -> throwResultError funcName result status
96 PQ.FatalError -> throwResultError funcName result status
src/Database/PostgreSQL/Simple/Internal.hs+2
@@ -351,6 +351,7 @@ exec conn sql =
351 Just res -> do
351 Just res -> do
352 status <- PQ.resultStatus res
352 status <- PQ.resultStatus res
353 case status of
353 case status of
354+ -- FIXME: handle PQ.CopyBoth and PQ.SingleTuple
354 PQ.EmptyQuery -> getResult h mres'
355 PQ.EmptyQuery -> getResult h mres'
355 PQ.CommandOk -> getResult h mres'
356 PQ.CommandOk -> getResult h mres'
356 PQ.TuplesOk -> getResult h mres'
357 PQ.TuplesOk -> getResult h mres'
@@ -371,6 +372,7 @@ finishExecute :: Connection -> Query -> PQ.Result -> IO Int64
371finishExecute _conn q result = do
372finishExecute _conn q result = do
372 status <- PQ.resultStatus result
373 status <- PQ.resultStatus result
373 case status of
374 case status of
375+ -- FIXME: handle PQ.CopyBoth and PQ.SingleTuple
374 PQ.EmptyQuery -> throwIO $ QueryError "execute: Empty query" q
376 PQ.EmptyQuery -> throwIO $ QueryError "execute: Empty query" q
375 PQ.CommandOk -> do
377 PQ.CommandOk -> do
376 ncols <- PQ.nfields result
378 ncols <- PQ.nfields result
src/Database/PostgreSQL/Simple/Internal/PQResultUtils.hs+6−2
@@ -1,3 +1,4 @@
1+{-# LANGUAGE CPP #-}
1
2
2------------------------------------------------------------------------------
3------------------------------------------------------------------------------
3-- |
4-- |
@@ -41,8 +42,12 @@ finishQueryWith parser conn q result = do
41 PQ.CommandOk -> queryErr "query resulted in a command response"
42 PQ.CommandOk -> queryErr "query resulted in a command response"
42 PQ.CopyOut -> queryErr "query: COPY TO is not supported"
43 PQ.CopyOut -> queryErr "query: COPY TO is not supported"
43 PQ.CopyIn -> queryErr "query: COPY FROM is not supported"
44 PQ.CopyIn -> queryErr "query: COPY FROM is not supported"
45+#if MIN_VERSION_postgresql_libpq(0,9,3)
44 PQ.CopyBoth -> queryErr "query: COPY BOTH is not supported"
46 PQ.CopyBoth -> queryErr "query: COPY BOTH is not supported"
47+#endif
48+#if MIN_VERSION_postgresql_libpq(0,9,2)
45 PQ.SingleTuple -> queryErr "query: single-row mode is not supported"
49 PQ.SingleTuple -> queryErr "query: single-row mode is not supported"
50+#endif
46 PQ.BadResponse -> throwResultError "query" result status
51 PQ.BadResponse -> throwResultError "query" result status
47 PQ.NonfatalError -> throwResultError "query" result status
52 PQ.NonfatalError -> throwResultError "query" result status
48 PQ.FatalError -> throwResultError "query" result status
53 PQ.FatalError -> throwResultError "query" result status
@@ -67,8 +72,7 @@ getRowWith parser row ncols conn result = do
67 Nothing
72 Nothing
68 ""
73 ""
69 (show (unCol col) ++ " slots in target type")
74 (show (unCol col) ++ " slots in target type")
70− "mismatch between number of columns to \
75+ "mismatch between number of columns to convert and number in target type")
71− \convert and number in target type")
72 Errors [] -> throwIO $ ConversionFailed "" Nothing "" "" "unknown error"
76 Errors [] -> throwIO $ ConversionFailed "" Nothing "" "" "unknown error"
73 Errors [x] -> throwIO x
77 Errors [x] -> throwIO x
74 Errors xs -> throwIO $ ManyErrors xs
78 Errors xs -> throwIO $ ManyErrors xs