testExtendedQuery :: IO ()
testExtendedQuery = withConnectionCommonAll $ \c -> do
    let rawConn = connRawConnection c
        sname = StatementName "statement"
        pname = PortalName "portal"
        statement = StatementSQL "SELECT $1 + $2"
    sendMessage rawConn $ Parse sname statement [Oid 23, Oid 23]
    sendMessage rawConn $
        Bind pname sname Text [Just $ PE.bytea "1", Just $ PE.bytea "2"] Text
    sendMessage rawConn $ Execute pname noLimitToReceive
    sendMessage rawConn $ DescribeStatement sname
    sendMessage rawConn $ DescribePortal pname
    sendMessage rawConn $ CloseStatement sname
    sendMessage rawConn $ ClosePortal pname
    sendMessage rawConn Flush
    sendMessage rawConn Sync

    msgs <- collectUntilReadyForQuery c
    assertNoErrorResponse msgs
    assertContains msgs isBindComplete "BindComplete"
    assertContains msgs isCloseComplete "CloseComplete"
    assertContains msgs isParseComplete "ParseComplete"
    assertContains msgs isDataRow "DataRow"
    assertContains msgs isCommandComplete "CommandComplete"
    assertContains msgs isParameterDecription "ParameterDescription"
    assertContains msgs isRowDescription "RowDescription"
  where
    isBindComplete          BindComplete             = True
    isBindComplete          _                        = False
    isCloseComplete         CloseComplete            = True
    isCloseComplete         _                        = False
    isParseComplete         ParseComplete            = True
    isParseComplete         _                        = False
    isDataRow               DataRow{}                = True
    isDataRow               _                        = False
    isCommandComplete       (CommandComplete _)      = True
    isCommandComplete       _                        = False
    isParameterDecription   (ParameterDescription _) = True
    isParameterDecription   _                        = False
    isRowDescription        (RowDescription _)       = True
    isRowDescription        _                        = False

-- | Tests that PostgreSQL returns `EmptyQueryResponse` when a query
-- string is empty.
testExtendedQuery :: IO ()
testExtendedQuery = withConnectionCommonAll $ \c -> do
    let rawConn = connRawConnection c
        sname = StatementName "statement"
        pname = PortalName "portal"
        statement = StatementSQL "SELECT $1 + $2"
    sendMessage rawConn $ Parse sname statement [Oid 23, Oid 23]
    sendMessage rawConn $
        Bind pname sname Text [Just $ PE.bytea "1", Just $ PE.bytea "2"] Text
    sendMessage rawConn $ Execute pname noLimitToReceive
    sendMessage rawConn $ DescribeStatement sname
    sendMessage rawConn $ DescribePortal pname
    sendMessage rawConn $ CloseStatement sname
    sendMessage rawConn $ ClosePortal pname
    sendMessage rawConn Flush
    sendMessage rawConn Sync

    msgs <- collectUntilReadyForQuery c
    assertNoErrorResponse msgs
    assertContains msgs isBindComplete "BindComplete"
    assertContains msgs isCloseComplete "CloseComplete"
    assertContains msgs isParseComplete "ParseComplete"
    assertContains msgs isDataRow "DataRow"
    assertContains msgs isCommandComplete "CommandComplete"
    assertContains msgs isParameterDecription "ParameterDescription"
    assertContains msgs isRowDescription "RowDescription"
  where
    isBindComplete          BindComplete             = True
    isBindComplete          _                        = False
    isCloseComplete         CloseComplete            = True
    isCloseComplete         _                        = False
    isParseComplete         ParseComplete            = True
    isParseComplete         _                        = False
    isDataRow               DataRow{}                = True
    isDataRow               _                        = False
    isCommandComplete       (CommandComplete _)      = True
    isCommandComplete       _                        = False
    isParameterDecription   (ParameterDescription _) = True
    isParameterDecription   _                        = False
    isRowDescription        (RowDescription _)       = True
    isRowDescription        _                        = False

-- | Tests that PostgreSQL returns `EmptyQueryResponse` when a query
-- string is empty.
testExtendedQuery = withConnectionCommonAll $ \c -> do
    let rawConn = connRawConnection c
        sname = StatementName "statement"
        pname = PortalName "portal"
        statement = StatementSQL "SELECT $1 + $2"
    sendMessage rawConn $ Parse sname statement [Oid 23, Oid 23]
    sendMessage rawConn $
        Bind pname sname Text [Just $ PE.bytea "1", Just $ PE.bytea "2"] Text
    sendMessage rawConn $ Execute pname noLimitToReceive
    sendMessage rawConn $ DescribeStatement sname
    sendMessage rawConn $ DescribePortal pname
    sendMessage rawConn $ CloseStatement sname
    sendMessage rawConn $ ClosePortal pname
    sendMessage rawConn Flush
    sendMessage rawConn Sync

    msgs <- collectUntilReadyForQuery c
    assertNoErrorResponse msgs
    assertContains msgs isBindComplete "BindComplete"
    assertContains msgs isCloseComplete "CloseComplete"
    assertContains msgs isParseComplete "ParseComplete"
    assertContains msgs isDataRow "DataRow"
    assertContains msgs isCommandComplete "CommandComplete"
    assertContains msgs isParameterDecription "ParameterDescription"
    assertContains msgs isRowDescription "RowDescription"
  where
    isBindComplete          BindComplete             = True
    isBindComplete          _                        = False
    isCloseComplete         CloseComplete            = True
    isCloseComplete         _                        = False
    isParseComplete         ParseComplete            = True
    isParseComplete         _                        = False
    isDataRow               DataRow{}                = True
    isDataRow               _                        = False
    isCommandComplete       (CommandComplete _)      = True
    isCommandComplete       _                        = False
    isParameterDecription   (ParameterDescription _) = True
    isParameterDecription   _                        = False
    isRowDescription        (RowDescription _)       = True
    isRowDescription        _                        = False

-- | Tests that PostgreSQL returns `EmptyQueryResponse` when a query
-- string is empty.