package pg

import (
	

	
)

// ErrNoRows is returned by QueryOne and ExecOne when query returned zero rows
// but at least one row is expected.
var ErrNoRows = internal.ErrNoRows

// ErrMultiRows is returned by QueryOne and ExecOne when query returned
// multiple rows but exactly one row is expected.
var ErrMultiRows = internal.ErrMultiRows

// Error represents an error returned by PostgreSQL server
// using PostgreSQL ErrorResponse protocol.
//
// https://www.postgresql.org/docs/10/static/protocol-message-formats.html
type Error interface {
	error

	// Field returns a string value associated with an error field.
	//
	// https://www.postgresql.org/docs/10/static/protocol-error-fields.html
	Field(field byte) string

	// IntegrityViolation reports whether an error is a part of
	// Integrity Constraint Violation class of errors.
	//
	// https://www.postgresql.org/docs/10/static/errcodes-appendix.html
	IntegrityViolation() bool
}

var _ Error = (*internal.PGError)(nil)

func ( error,  bool) (bool, string) {
	if  == nil {
		return false, ""
	}
	if ,  := .(internal.Error);  {
		return false, ""
	}
	if ,  := .(Error);  {
		switch .Field('V') {
		case "FATAL", "PANIC":
			return true, ""
		}
		switch .Field('C') {
		case "25P02": // current transaction is aborted
			return true, "25P02"
		case "57014": // canceling statement due to user request
			return true, "57014"
		}
		return false, ""
	}
	if  {
		if ,  := .(net.Error);  && .Timeout() {
			return !.Temporary(), ""
		}
	}
	return true, ""
}

//------------------------------------------------------------------------------

type timeoutError interface {
	Timeout() bool
}