postgresql-simple-0.7.0.1: Mid-Level PostgreSQL client library

Copyright | (c) 2012-2013 Leonid Onokhov Joey Adams
License | BSD3
Maintainer | Leon P Smith <leon@melding-monads.com>
Stability | experimental
Safe Haskell | None
Language | Haskell2010

Database.PostgreSQL.Simple.Errors

Description

| 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
  - = NotNullViolation ByteString
  - | ForeignKeyViolation ByteString ByteString
  - | UniqueViolation ByteString
  - | CheckViolation ByteString ByteString
  - | ExclusionViolation ByteString
- 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 #

Constructors

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

Instances details

Exception ConstraintViolation Source # |
Instance details Defined in Database.PostgreSQL.Simple.Errors Methods toException :: ConstraintViolation -> SomeException Source # fromException :: SomeException -> Maybe ConstraintViolation Source # displayException :: ConstraintViolation -> String Source # backtraceDesired :: ConstraintViolation -> Bool Source #
Show ConstraintViolation Source # |
Instance details Defined in Database.PostgreSQL.Simple.Errors Methods showsPrec :: Int -> ConstraintViolation -> ShowS Source # show :: ConstraintViolation -> String Source # showList :: [ConstraintViolation] -> ShowS Source #
Eq ConstraintViolation Source # |
Instance details Defined in Database.PostgreSQL.Simple.Errors Methods (==) :: ConstraintViolation -> ConstraintViolation -> Bool Source # (/=) :: ConstraintViolation -> ConstraintViolation -> Bool Source #
Ord ConstraintViolation Source # |

Instance details

Defined in Database.PostgreSQL.Simple.Errors

Methods

compare :: ConstraintViolation -> ConstraintViolation -> Ordering Source #

(<) :: ConstraintViolation -> ConstraintViolation -> Bool Source #

(<=) :: ConstraintViolation -> ConstraintViolation -> Bool Source #

(>) :: ConstraintViolation -> ConstraintViolation -> Bool Source #

(>=) :: ConstraintViolation -> ConstraintViolation -> Bool Source #

max :: ConstraintViolation -> ConstraintViolation -> ConstraintViolation Source #

min :: ConstraintViolation -> ConstraintViolation -> ConstraintViolation Source #

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 #

isNoActiveTransactionError :: SqlError -> Bool Source #

isFailedTransactionError :: SqlError -> Bool Source #