git.iko.soy/typeable/postgresql-simple
on master help sign in
Exception improvements
6dc833fLeon P Smith
src/Database/PostgreSQL/Simple.hs+10−12
@@ -235,7 +235,6 @@ finishExecute :: Connection -> Query -> PQ.Result -> IO Int64
235finishExecute conn q result = do
235finishExecute conn q result = do
236 status <- PQ.resultStatus result
236 status <- PQ.resultStatus result
237 case status of
237 case status of
238− PQ.EmptyQuery -> fail "empty query" -- FIXME: error message
239 PQ.CommandOk -> do
238 PQ.CommandOk -> do
240 ncols <- PQ.nfields result
239 ncols <- PQ.nfields result
241 if ncols /= 0
240 if ncols /= 0
@@ -256,10 +255,10 @@ finishExecute conn q result = do
256 errormsg <- maybe "" id <$> PQ.resultErrorMessage result
255 errormsg <- maybe "" id <$> PQ.resultErrorMessage result
257 statusmsg <- PQ.resStatus status
256 statusmsg <- PQ.resStatus status
258 state <- maybe "" id <$> PQ.resultErrorField result PQ.DiagSqlstate
257 state <- maybe "" id <$> PQ.resultErrorField result PQ.DiagSqlstate
259− throw $ SqlError { sqlState = state
258+ throwIO $ SqlError { sqlState = state
260− , sqlNativeError = 0 -- FIXME
259+ , sqlNativeError = fromEnum status
261− , sqlErrorMsg = B.concat [ "execute: ", statusmsg
260+ , sqlErrorMsg = B.concat [ "execute: ", statusmsg
262− , ": ", errormsg ]}
261+ , ": ", errormsg ]}
263 where
262 where
264 toInteger str = B.foldl' delta 0 str
263 toInteger str = B.foldl' delta 0 str
265 where
264 where
@@ -377,7 +376,6 @@ finishQuery :: (QueryResults r) => Connection -> Query -> PQ.Result -> IO [r]
377finishQuery conn q result = do
376finishQuery conn q result = do
378 status <- PQ.resultStatus result
377 status <- PQ.resultStatus result
379 case status of
378 case status of
380− PQ.EmptyQuery -> fail "empty query" -- FIXME: error message
381 PQ.CommandOk -> do
379 PQ.CommandOk -> do
382 throwIO $ QueryError "query resulted in a command response" q
380 throwIO $ QueryError "query resulted in a command response" q
383 PQ.TuplesOk -> do
381 PQ.TuplesOk -> do
@@ -398,10 +396,10 @@ finishQuery conn q result = do
398 errormsg <- maybe "" id <$> PQ.resultErrorMessage result
396 errormsg <- maybe "" id <$> PQ.resultErrorMessage result
399 statusmsg <- PQ.resStatus status
397 statusmsg <- PQ.resStatus status
400 state <- maybe "" id <$> PQ.resultErrorField result PQ.DiagSqlstate
398 state <- maybe "" id <$> PQ.resultErrorField result PQ.DiagSqlstate
401− throw $ SqlError { sqlState = state
399+ throwIO $ SqlError { sqlState = state
402− , sqlNativeError = 0 -- FIXME
400+ , sqlNativeError = fromEnum status
403− , sqlErrorMsg = B.concat [ "execute: ", statusmsg
401+ , sqlErrorMsg = B.concat [ "query: ", statusmsg
404− , ": ", errormsg ]}
402+ , ": ", errormsg ]}
405
403
406{--
404{--
407withResult (Base.storeResult conn) q $ \r fs -> do
405withResult (Base.storeResult conn) q $ \r fs -> do
@@ -711,13 +709,13 @@ fmtError msg q xs = throw FormatError {
711--
709--
712-- * For numeric types, any Haskell type that can accurately represent
710-- * For numeric types, any Haskell type that can accurately represent
713-- all values of the given PostgreSQL type is considered \"compatible\".
711-- 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@
715-- column to a Haskell 'Int'. The Haskell 'Float' type can accurately
713-- column to a Haskell 'Int'. The Haskell 'Float' type can accurately
716-- represent a @SMALLINT@, so it is considered compatble with those types.
714-- represent a @SMALLINT@, so it is considered compatble with those types.
717--
715--
718-- * A numeric compatibility check is based only on the type of a
716-- * A numeric compatibility check is based only on the type of a
719-- column, /not/ on its values. For instance, a PostgreSQL 64-bit
717-- 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
721-- 'Int16', even if it contains the value @1@.
719-- 'Int16', even if it contains the value @1@.
722--
720--
723-- * If a numeric incompatibility is found, 'query' will throw a
721-- * 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 =
138 mres <- PQ.exec h sql
138 mres <- PQ.exec h sql
139 case mres of
139 case mres of
140 Nothing -> do
140 Nothing -> do
141− msg <- PQ.errorMessage h
141+ msg <- maybe "execute error" id <$> PQ.errorMessage h
142− -- FIXME better error message
142+ throwIO $ SqlError { sqlNativeError = -1 -- FIXME?
143− fail ("Postgres Error: " ++ show msg)
143+ , sqlErrorMsg = msg
144+ , sqlState = "" }
144 Just res -> do
145 Just res -> do
145 return res
146 return res
146
147
src/Database/PostgreSQL/Simple/Result.hs+2−2
@@ -16,8 +16,8 @@
16-- A Haskell numeric type is considered to be compatible with all
16-- A Haskell numeric type is considered to be compatible with all
17-- PostgreSQL numeric types that are less accurate than it. For instance,
17-- PostgreSQL numeric types that are less accurate than it. For instance,
18-- the Haskell 'Double' type is compatible with the PostgreSQL's 32-bit
18-- 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,
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@,
20+-- since a 'Double' might lose precision if representing a 64-bit @BigInt@,
21-- the two are /not/ considered compatible.
21-- the two are /not/ considered compatible.
22--
22--
23------------------------------------------------------------------------------
23------------------------------------------------------------------------------