package pgx

import (
	
	
	
	

	
	
	
)
Rows is the result set returned from *Conn.Query. Rows must be closed before the *Conn can be used again. Rows are closed by explicitly calling Close(), calling Next() until it returns false, or when a fatal error occurs. Once a Rows is closed the only methods that may be called are Close(), Err(), and CommandTag(). Rows is an interface instead of a struct to allow tests to mock Query. However, adding a method to an interface is technically a breaking change. Because of this the Rows interface is partially excluded from semantic version requirements. Methods will not be removed or changed, but new methods may be added.
Close closes the rows, making the connection ready for use again. It is safe to call Close after rows is already closed.
	Close()
Err returns any error that occurred while reading.
	Err() error
CommandTag returns the command tag from this query. It is only available after Rows is closed.
	CommandTag() pgconn.CommandTag

	FieldDescriptions() []pgproto3.FieldDescription
Next prepares the next row for reading. It returns true if there is another row and false if no more rows are available. It automatically closes rows when all rows are read.
	Next() bool
Scan reads the values from the current row into dest values positionally. dest can include pointers to core types, values implementing the Scanner interface, and nil. nil will skip the value entirely.
	Scan(dest ...interface{}) error
Values returns the decoded row values.
	Values() ([]interface{}, error)
RawValues returns the unparsed bytes of the row values. The returned [][]byte is only valid until the next Next call or the Rows is closed. However, the underlying byte data is safe to retain a reference to and mutate.
	RawValues() [][]byte
}
Row is a convenience wrapper over Rows that is returned by QueryRow. Row is an interface instead of a struct to allow tests to mock QueryRow. However, adding a method to an interface is technically a breaking change. Because of this the Row interface is partially excluded from semantic version requirements. Methods will not be removed or changed, but new methods may be added.
Scan works the same as Rows. with the following exceptions. If no rows were found it returns ErrNoRows. If multiple rows are returned it ignores all but the first.
	Scan(dest ...interface{}) error
}
connRow implements the Row interface for Conn.QueryRow.
type connRow connRows

func ( *connRow) ( ...interface{}) ( error) {
	 := (*connRows)()

	if .Err() != nil {
		return .Err()
	}

	if !.Next() {
		if .Err() == nil {
			return ErrNoRows
		}
		return .Err()
	}

	.Scan(...)
	.Close()
	return .Err()
}

type rowLog interface {
	shouldLog(lvl LogLevel) bool
	log(ctx context.Context, lvl LogLevel, msg string, data map[string]interface{})
}
connRows implements the Rows interface for Conn.Query.
type connRows struct {
	ctx        context.Context
	logger     rowLog
	connInfo   *pgtype.ConnInfo
	values     [][]byte
	rowCount   int
	err        error
	commandTag pgconn.CommandTag
	startTime  time.Time
	sql        string
	args       []interface{}
	closed     bool
	conn       *Conn

	resultReader      *pgconn.ResultReader
	multiResultReader *pgconn.MultiResultReader

	scanPlans []pgtype.ScanPlan
}

func ( *connRows) () []pgproto3.FieldDescription {
	return .resultReader.FieldDescriptions()
}

func ( *connRows) () {
	if .closed {
		return
	}

	.closed = true

	if .resultReader != nil {
		var  error
		.commandTag,  = .resultReader.Close()
		if .err == nil {
			.err = 
		}
	}

	if .multiResultReader != nil {
		 := .multiResultReader.Close()
		if .err == nil {
			.err = 
		}
	}

	if .logger != nil {
		if .err == nil {
			if .logger.shouldLog(LogLevelInfo) {
				 := time.Now()
				.logger.log(.ctx, LogLevelInfo, "Query", map[string]interface{}{"sql": .sql, "args": logQueryArgs(.args), "time": .Sub(.startTime), "rowCount": .rowCount})
			}
		} else {
			if .logger.shouldLog(LogLevelError) {
				.logger.log(.ctx, LogLevelError, "Query", map[string]interface{}{"err": .err, "sql": .sql, "args": logQueryArgs(.args)})
			}
			if .err != nil && .conn.stmtcache != nil {
				.conn.stmtcache.StatementErrored(.sql, .err)
			}
		}
	}
}

func ( *connRows) () pgconn.CommandTag {
	return .commandTag
}

func ( *connRows) () error {
	return .err
}
fatal signals an error occurred after the query was sent to the server. It closes the rows automatically.
func ( *connRows) ( error) {
	if .err != nil {
		return
	}

	.err = 
	.Close()
}

func ( *connRows) () bool {
	if .closed {
		return false
	}

	if .resultReader.NextRow() {
		.rowCount++
		.values = .resultReader.Values()
		return true
	} else {
		.Close()
		return false
	}
}

func ( *connRows) ( ...interface{}) error {
	 := .connInfo
	 := .FieldDescriptions()
	 := .values

	if len() != len() {
		 := fmt.Errorf("number of field descriptions must equal number of values, got %d and %d", len(), len())
		.fatal()
		return 
	}
	if len() != len() {
		 := fmt.Errorf("number of field descriptions must equal number of destinations, got %d and %d", len(), len())
		.fatal()
		return 
	}

	if .scanPlans == nil {
		.scanPlans = make([]pgtype.ScanPlan, len())
		for  := range  {
			.scanPlans[] = .PlanScan([].DataTypeOID, [].Format, [])
		}
	}

	for ,  := range  {
		if  == nil {
			continue
		}

		 := .scanPlans[].Scan(, [].DataTypeOID, [].Format, [], )
		if  != nil {
			 = ScanArgError{ColumnIndex: , Err: }
			.fatal()
			return 
		}
	}

	return nil
}

func ( *connRows) () ([]interface{}, error) {
	if .closed {
		return nil, errors.New("rows is closed")
	}

	 := make([]interface{}, 0, len(.FieldDescriptions()))

	for  := range .FieldDescriptions() {
		 := .values[]
		 := &.FieldDescriptions()[]

		if  == nil {
			 = append(, nil)
			continue
		}

		if ,  := .connInfo.DataTypeForOID(.DataTypeOID);  {
			 := .Value

			switch .Format {
			case TextFormatCode:
				,  := .(pgtype.TextDecoder)
				if ! {
					 = &pgtype.GenericText{}
				}
				 := .DecodeText(.connInfo, )
				if  != nil {
					.fatal()
				}
				 = append(, .(pgtype.Value).Get())
			case BinaryFormatCode:
				,  := .(pgtype.BinaryDecoder)
				if ! {
					 = &pgtype.GenericBinary{}
				}
				 := .DecodeBinary(.connInfo, )
				if  != nil {
					.fatal()
				}
				 = append(, .Get())
			default:
				.fatal(errors.New("Unknown format code"))
			}
		} else {
			switch .Format {
			case TextFormatCode:
				 := &pgtype.GenericText{}
				 := .DecodeText(.connInfo, )
				if  != nil {
					.fatal()
				}
				 = append(, .Get())
			case BinaryFormatCode:
				 := &pgtype.GenericBinary{}
				 := .DecodeBinary(.connInfo, )
				if  != nil {
					.fatal()
				}
				 = append(, .Get())
			default:
				.fatal(errors.New("Unknown format code"))
			}
		}

		if .Err() != nil {
			return nil, .Err()
		}
	}

	return , .Err()
}

func ( *connRows) () [][]byte {
	return .values
}

type ScanArgError struct {
	ColumnIndex int
	Err         error
}

func ( ScanArgError) () string {
	return fmt.Sprintf("can't scan into dest[%d]: %v", .ColumnIndex, .Err)
}

func ( ScanArgError) () error {
	return .Err
}
ScanRow decodes raw row data into dest. It can be used to scan rows read from the lower level pgconn interface. connInfo - OID to Go type mapping. fieldDescriptions - OID and format of values values - the raw data as returned from the PostgreSQL server dest - the destination that values will be decoded into
func ( *pgtype.ConnInfo,  []pgproto3.FieldDescription,  [][]byte,  ...interface{}) error {
	if len() != len() {
		return fmt.Errorf("number of field descriptions must equal number of values, got %d and %d", len(), len())
	}
	if len() != len() {
		return fmt.Errorf("number of field descriptions must equal number of destinations, got %d and %d", len(), len())
	}

	for ,  := range  {
		if  == nil {
			continue
		}

		 := .Scan([].DataTypeOID, [].Format, [], )
		if  != nil {
			return ScanArgError{ColumnIndex: , Err: }
		}
	}

	return nil