@@ -64,6 +64,7 @@ module Squeal.PostgreSQL.PQ
64 , resultErrorCode
64 , resultErrorCode
65 -- * Exceptions
65 -- * Exceptions
66 , SquealException (..)
66 , SquealException (..)
67 , catchSqueal
68 , catchSqueal
68 , handleSqueal
69 , handleSqueal
@@ -613,14 +614,17 @@ resultErrorCode
613 -> io (Maybe ByteString)
614 -> io (Maybe ByteString)
614resultErrorCode = liftResult (flip LibPQ.resultErrorField LibPQ.DiagSqlstate)
615resultErrorCode = liftResult (flip LibPQ.resultErrorField LibPQ.DiagSqlstate)
616−-- | `Exception`s that can be thrown by Squeal.
617+-- | the state of LibPQ
617−data SquealException
618+data PQState = PQState
619 { sqlExecStatus :: LibPQ.ExecStatus
619 { sqlExecStatus :: LibPQ.ExecStatus
620 , sqlStateCode :: Maybe ByteString
620 , sqlStateCode :: Maybe ByteString
621 -- ^ https://www.postgresql.org/docs/current/static/errcodes-appendix.html
621 -- ^ https://www.postgresql.org/docs/current/static/errcodes-appendix.html
622 , sqlErrorMessage :: Maybe ByteString
622 , sqlErrorMessage :: Maybe ByteString
623− }
623+ } deriving (Eq, Show)
625+-- | `Exception`s that can be thrown by Squeal.
627+ = PQException PQState
624 | ResultException Text
628 | ResultException Text
625 | ParseException Text
629 | ParseException Text
626 deriving (Eq, Show)
630 deriving (Eq, Show)
@@ -638,7 +642,7 @@ tryResult result = liftIO $ do
639 stateCode <- LibPQ.resultErrorField result LibPQ.DiagSqlstate
643 stateCode <- LibPQ.resultErrorField result LibPQ.DiagSqlstate
640 msg <- LibPQ.resultErrorMessage result
644 msg <- LibPQ.resultErrorMessage result
641− throw $ PQException status stateCode msg
645+ throw . PQException $ PQState status stateCode msg
643-- | Catch `SquealException`s.
647-- | Catch `SquealException`s.
644catchSqueal
648catchSqueal