git.iko.soy/typeable/postgresql-simple
on master help sign in
Minor reorganization
commitbebf49e33c22fedc8cba2c93908561d2f4d45889 authorLeon P Smith <leon@melding-monads.com> dateTue 20 Aug 2013, 04:22 (13 years ago) parentc61c692
2 files changed+23−19
src/Database/PostgreSQL/Simple/Errors.hs+22−2 src/Database/PostgreSQL/Simple/Transaction.hs+1−17
src/Database/PostgreSQL/Simple/Errors.hs+22−2
@@ -1,8 +1,8 @@
11{-# LANGUAGE DeriveDataTypeable #-}
22{-# LANGUAGE OverloadedStrings #-}
33
4−-- | Module for parsing errors from posgresql error messages.
5−-- Currently in only parses integrity violation errors (class 23).
4+-- | Module for parsing errors from postgresql error messages.
5+-- Currently only parses integrity violation errors (class 23).
66--
77-- /Note: Success of parsing may depend on language settings./
88----------------------------------------------------------
@@ -11,6 +11,9 @@ module Database.PostgreSQL.Simple.Errors
1111 , constraintViolation
1212 , constraintViolationE
1313 , catchViolation
14+ , isSerializationError
15+ , isNoActiveTransactionError
16+ , isFailedTransactionError
1417 )
1518 where
1619
@@ -106,3 +109,20 @@ parseQ2 = (,) <$> parseQ1 <*> parseQ1
106109
107110parseMaybe :: Parser a -> ByteString -> Maybe a
108111parseMaybe 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)
4040import qualified Data.ByteString as B
4141import Database.PostgreSQL.Simple.Internal
4242import Database.PostgreSQL.Simple.Types
43+import Database.PostgreSQL.Simple.Errors
4344import Database.PostgreSQL.Simple.Compat (mask, (<>))
4445
4546
@@ -244,20 +245,3 @@ rollbackToAndReleaseSavepoint conn (Savepoint name) =
244245 execute_ conn sql >> return ()
245246 where
246247 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