git.iko.soy/typeable/postgresql-simple
on master help sign in
Exception improvements
commit6dc833fc381a27e43f53d4e4d216fd3fb555e7a0 authorLeon P Smith <leon@melding-monads.com> dateFri 30 Dec 2011, 00:41 (15 years ago) parente20ffa2
3 files changed+16−17
src/Database/PostgreSQL/Simple.hs+10−12 src/Database/PostgreSQL/Simple/Internal.hs+4−3 src/Database/PostgreSQL/Simple/Result.hs+2−2
src/Database/PostgreSQL/Simple.hs+10−12
@@ -235,7 +235,6 @@ finishExecute :: Connection -> Query -> PQ.Result -> IO Int64
235235finishExecute conn q result = do
236236 status <- PQ.resultStatus result
237237 case status of
238− PQ.EmptyQuery -> fail "empty query" -- FIXME: error message
239238 PQ.CommandOk -> do
240239 ncols <- PQ.nfields result
241240 if ncols /= 0
@@ -256,10 +255,10 @@ finishExecute conn q result = do
256255 errormsg <- maybe "" id <$> PQ.resultErrorMessage result
257256 statusmsg <- PQ.resStatus status
258257 state <- maybe "" id <$> PQ.resultErrorField result PQ.DiagSqlstate
259− throw $ SqlError { sqlState = state
260− , sqlNativeError = 0 -- FIXME
261− , sqlErrorMsg = B.concat [ "execute: ", statusmsg
262− , ": ", errormsg ]}
258+ throwIO $ SqlError { sqlState = state
259+ , sqlNativeError = fromEnum status
260+ , sqlErrorMsg = B.concat [ "execute: ", statusmsg
261+ , ": ", errormsg ]}
263262 where
264263 toInteger str = B.foldl' delta 0 str
265264 where
@@ -377,7 +376,6 @@ finishQuery :: (QueryResults r) => Connection -> Query -> PQ.Result -> IO [r]
377376finishQuery conn q result = do
378377 status <- PQ.resultStatus result
379378 case status of
380− PQ.EmptyQuery -> fail "empty query" -- FIXME: error message
381379 PQ.CommandOk -> do
382380 throwIO $ QueryError "query resulted in a command response" q
383381 PQ.TuplesOk -> do
@@ -398,10 +396,10 @@ finishQuery conn q result = do
398396 errormsg <- maybe "" id <$> PQ.resultErrorMessage result
399397 statusmsg <- PQ.resStatus status
400398 state <- maybe "" id <$> PQ.resultErrorField result PQ.DiagSqlstate
401− throw $ SqlError { sqlState = state
402− , sqlNativeError = 0 -- FIXME
403− , sqlErrorMsg = B.concat [ "execute: ", statusmsg
404− , ": ", errormsg ]}
399+ throwIO $ SqlError { sqlState = state
400+ , sqlNativeError = fromEnum status
401+ , sqlErrorMsg = B.concat [ "query: ", statusmsg
402+ , ": ", errormsg ]}
405403
406404{--
407405withResult (Base.storeResult conn) q $ \r fs -> do
@@ -711,13 +709,13 @@ fmtError msg q xs = throw FormatError {
711709--
712710-- * For numeric types, any Haskell type that can accurately represent
713711-- all values of the given PostgreSQL type is considered \"compatible\".
714−-- For instance, you can always extract a PostgreSQL 16-bit @SMALLINT@
712+-- For instance, you can always extract a PostgreSQL 16-bit @SMALLINT@
715713-- column to a Haskell 'Int'. The Haskell 'Float' type can accurately
716714-- represent a @SMALLINT@, so it is considered compatble with those types.
717715--
718716-- * A numeric compatibility check is based only on the type of a
719717-- column, /not/ on its values. For instance, a PostgreSQL 64-bit
720−-- @BIGINT@ column will be considered incompatible with a Haskell
718+-- @BIGINT@ column will be considered incompatible with a Haskell
721719-- 'Int16', even if it contains the value @1@.
722720--
723721-- * If a numeric incompatibility is found, 'query' will throw a
src/Database/PostgreSQL/Simple/Internal.hs+4−3
@@ -138,9 +138,10 @@ exec conn sql =
138138 mres <- PQ.exec h sql
139139 case mres of
140140 Nothing -> do
141− msg <- PQ.errorMessage h
142− -- FIXME better error message
143− fail ("Postgres Error: " ++ show msg)
141+ msg <- maybe "execute error" id <$> PQ.errorMessage h
142+ throwIO $ SqlError { sqlNativeError = -1 -- FIXME?
143+ , sqlErrorMsg = msg
144+ , sqlState = "" }
144145 Just res -> do
145146 return res
146147
src/Database/PostgreSQL/Simple/Result.hs+2−2
@@ -16,8 +16,8 @@
1616-- A Haskell numeric type is considered to be compatible with all
1717-- PostgreSQL numeric types that are less accurate than it. For instance,
1818-- the Haskell 'Double' type is compatible with the PostgreSQL's 32-bit
19−-- @Int@ type because it can represent a @Int@ exactly. On the other hand,
20−-- since a 'Double' might lose precision if representing a 64-bit @BigInt@,
19+-- @Int@ type because it can represent a @Int@ exactly. On the other hand,
20+-- since a 'Double' might lose precision if representing a 64-bit @BigInt@,
2121-- the two are /not/ considered compatible.
2222--
2323------------------------------------------------------------------------------