git.iko.soy/typeable/postgresql-simple
on master help sign in
Minor reorganization
bebf49eLeon P Smith
src/Database/PostgreSQL/Simple/Errors.hs+22−2
@@ -1,8 +1,8 @@
1{-# LANGUAGE DeriveDataTypeable #-}
1{-# LANGUAGE DeriveDataTypeable #-}
2{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE OverloadedStrings #-}
3
3
4−-- | Module for parsing errors from posgresql error messages.
4+-- | Module for parsing errors from postgresql error messages.
5−-- Currently in only parses integrity violation errors (class 23).
5+-- Currently only parses integrity violation errors (class 23).
6--
6--
7-- /Note: Success of parsing may depend on language settings./
7-- /Note: Success of parsing may depend on language settings./
8----------------------------------------------------------
8----------------------------------------------------------
@@ -11,6 +11,9 @@ module Database.PostgreSQL.Simple.Errors
11 , constraintViolation
11 , constraintViolation
12 , constraintViolationE
12 , constraintViolationE
13 , catchViolation
13 , catchViolation
14+ , isSerializationError
15+ , isNoActiveTransactionError
16+ , isFailedTransactionError
14 )
17 )
15 where
18 where
16
19
@@ -106,3 +109,20 @@ parseQ2 = (,) <$> parseQ1 <*> parseQ1
106
109
107parseMaybe :: Parser a -> ByteString -> Maybe a
110parseMaybe :: Parser a -> ByteString -> Maybe a
108parseMaybe p b = either (const Nothing) Just $ parseOnly p b
111parseMaybe p b = either (const Nothing) Just $ parseOnly p b
112+
113+------------------------------------------------------------------------
114+-- Error predicates
115+--
116+-- http://www.postgresql.org/docs/current/static/errcodes-appendix.html
117+
118+isSerializationError :: SqlError -> Bool
119+isSerializationError = isSqlState "40001"
120+
121+isNoActiveTransactionError :: SqlError -> Bool
122+isNoActiveTransactionError = isSqlState "25P01"
123+
124+isFailedTransactionError :: SqlError -> Bool
125+isFailedTransactionError = isSqlState "25P02"
126+
127+isSqlState :: ByteString -> SqlError -> Bool
128+isSqlState s SqlError{..} = sqlState == s
src/Database/PostgreSQL/Simple/Transaction.hs+1−17
@@ -40,6 +40,7 @@ import Data.ByteString (ByteString)
40import qualified Data.ByteString as B
40import qualified Data.ByteString as B
41import Database.PostgreSQL.Simple.Internal
41import Database.PostgreSQL.Simple.Internal
42import Database.PostgreSQL.Simple.Types
42import Database.PostgreSQL.Simple.Types
43+import Database.PostgreSQL.Simple.Errors
43import Database.PostgreSQL.Simple.Compat (mask, (<>))
44import Database.PostgreSQL.Simple.Compat (mask, (<>))
44
45
45
46
@@ -244,20 +245,3 @@ rollbackToAndReleaseSavepoint conn (Savepoint name) =
244 execute_ conn sql >> return ()
245 execute_ conn sql >> return ()
245 where
246 where
246 sql = "ROLLBACK TO SAVEPOINT " <> name <> "; RELEASE SAVEPOINT " <> name
247 sql = "ROLLBACK TO SAVEPOINT " <> name <> "; RELEASE SAVEPOINT " <> name
247−
248−------------------------------------------------------------------------
249−-- Error predicates
250−--
251−-- http://www.postgresql.org/docs/current/static/errcodes-appendix.html
252−
253−isSerializationError :: SqlError -> Bool
254−isSerializationError = isSqlState "40001"
255−
256−isNoActiveTransactionError :: SqlError -> Bool
257−isNoActiveTransactionError = isSqlState "25P01"
258−
259−isFailedTransactionError :: SqlError -> Bool
260−isFailedTransactionError = isSqlState "25P02"
261−
262−isSqlState :: ByteString -> SqlError -> Bool
263−isSqlState s SqlError{..} = sqlState == s