Copyright | (c) 2012-2013 Leonid Onokhov Joey Adams |
---|---|
License | BSD3 |
Maintainer | Leon P Smith <leon@melding-monads.com> |
Stability | experimental |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
| Module for parsing errors from postgresql error messages. Currently only parses integrity violation errors (class 23).
Note: Success of parsing may depend on language settings.
Synopsis
- data ConstraintViolation
- constraintViolation :: SqlError -> Maybe ConstraintViolation
- constraintViolationE :: SqlError -> Maybe (SqlError, ConstraintViolation)
- catchViolation :: (SqlError -> ConstraintViolation -> IO a) -> IO a -> IO a
- isSerializationError :: SqlError -> Bool
- isNoActiveTransactionError :: SqlError -> Bool
- isFailedTransactionError :: SqlError -> Bool
Documentation
data ConstraintViolation Source #
NotNullViolation ByteString | The field is a column name |
ForeignKeyViolation ByteString ByteString | Table name and name of violated constraint |
UniqueViolation ByteString | Name of violated constraint |
CheckViolation ByteString ByteString | Relation name (usually table), constraint name |
ExclusionViolation ByteString | Name of the exclusion violation constraint |
Instances
Exception ConstraintViolation Source # | |
Show ConstraintViolation Source # | |
Defined in Database.PostgreSQL.Simple.Errors showsPrec :: Int -> ConstraintViolation -> ShowS # show :: ConstraintViolation -> String # showList :: [ConstraintViolation] -> ShowS # | |
Eq ConstraintViolation Source # | |
Defined in Database.PostgreSQL.Simple.Errors (==) :: ConstraintViolation -> ConstraintViolation -> Bool # (/=) :: ConstraintViolation -> ConstraintViolation -> Bool # | |
Ord ConstraintViolation Source # | |
Defined in Database.PostgreSQL.Simple.Errors compare :: ConstraintViolation -> ConstraintViolation -> Ordering # (<) :: ConstraintViolation -> ConstraintViolation -> Bool # (<=) :: ConstraintViolation -> ConstraintViolation -> Bool # (>) :: ConstraintViolation -> ConstraintViolation -> Bool # (>=) :: ConstraintViolation -> ConstraintViolation -> Bool # max :: ConstraintViolation -> ConstraintViolation -> ConstraintViolation # min :: ConstraintViolation -> ConstraintViolation -> ConstraintViolation # |
constraintViolation :: SqlError -> Maybe ConstraintViolation Source #
Tries to convert SqlError
to ConstrainViolation
, checks sqlState and
succeeds only if able to parse sqlErrorMsg.
createUser = handleJust constraintViolation handler $ execute conn ... where handler (UniqueViolation "user_login_key") = ... handler _ = ...
constraintViolationE :: SqlError -> Maybe (SqlError, ConstraintViolation) Source #
Like constraintViolation, but also packs original SqlError.
createUser = handleJust constraintViolationE handler $ execute conn ... where handler (_, UniqueViolation "user_login_key") = ... handler (e, _) = throwIO e
catchViolation :: (SqlError -> ConstraintViolation -> IO a) -> IO a -> IO a Source #
Catches SqlError, tries to convert to ConstraintViolation, re-throws
on fail. Provides alternative interface to handleJust
createUser = catchViolation catcher $ execute conn ... where catcher _ (UniqueViolation "user_login_key") = ... catcher e _ = throwIO e
isSerializationError :: SqlError -> Bool Source #