package pgx

import (
	
	

	
)

type batchItem struct {
	query     string
	arguments []interface{}
}
Batch queries are a way of bundling multiple queries together to avoid unnecessary network round trips.
type Batch struct {
	items []*batchItem
}
Queue queues a query to batch b. query can be an SQL query or the name of a prepared statement.
func ( *Batch) ( string,  ...interface{}) {
	.items = append(.items, &batchItem{
		query:     ,
		arguments: ,
	})
}
Len returns number of queries that have been queued so far.
func ( *Batch) () int {
	return len(.items)
}

Exec reads the results from the next query in the batch as if the query has been sent with Conn.Exec.
	Exec() (pgconn.CommandTag, error)
Query reads the results from the next query in the batch as if the query has been sent with Conn.Query.
	Query() (Rows, error)
QueryRow reads the results from the next query in the batch as if the query has been sent with Conn.QueryRow.
	QueryRow() Row
Close closes the batch operation. This must be called before the underlying connection can be used again. Any error that occurred during a batch operation may have made it impossible to resyncronize the connection with the server. In this case the underlying connection will have been closed.
Exec reads the results from the next query in the batch as if the query has been sent with Exec.
func ( *batchResults) () (pgconn.CommandTag, error) {
	if .err != nil {
		return nil, .err
	}

	, ,  := .nextQueryAndArgs()

	if !.mrr.NextResult() {
		 := .mrr.Close()
		if  == nil {
			 = errors.New("no result")
		}
		if .conn.shouldLog(LogLevelError) {
			.conn.log(.ctx, LogLevelError, "BatchResult.Exec", map[string]interface{}{
				"sql":  ,
				"args": logQueryArgs(),
				"err":  ,
			})
		}
		return nil, 
	}

	,  := .mrr.ResultReader().Close()

	if  != nil {
		if .conn.shouldLog(LogLevelError) {
			.conn.log(.ctx, LogLevelError, "BatchResult.Exec", map[string]interface{}{
				"sql":  ,
				"args": logQueryArgs(),
				"err":  ,
			})
		}
	} else if .conn.shouldLog(LogLevelInfo) {
		.conn.log(.ctx, LogLevelInfo, "BatchResult.Exec", map[string]interface{}{
			"sql":        ,
			"args":       logQueryArgs(),
			"commandTag": ,
		})
	}

	return , 
}
Query reads the results from the next query in the batch as if the query has been sent with Query.
func ( *batchResults) () (Rows, error) {
	, ,  := .nextQueryAndArgs()
	if ! {
		 = "batch query"
	}

	if .err != nil {
		return &connRows{err: .err, closed: true}, .err
	}

	 := .conn.getRows(.ctx, , )

	if !.mrr.NextResult() {
		.err = .mrr.Close()
		if .err == nil {
			.err = errors.New("no result")
		}
		.closed = true

		if .conn.shouldLog(LogLevelError) {
			.conn.log(.ctx, LogLevelError, "BatchResult.Query", map[string]interface{}{
				"sql":  ,
				"args": logQueryArgs(),
				"err":  .err,
			})
		}

		return , .err
	}

	.resultReader = .mrr.ResultReader()
	return , nil
}
QueryRow reads the results from the next query in the batch as if the query has been sent with QueryRow.
func ( *batchResults) () Row {
	,  := .Query()
	return (*connRow)(.(*connRows))

}
Close closes the batch operation. Any error that occurred during a batch operation may have made it impossible to resyncronize the connection with the server. In this case the underlying connection will have been closed.
func ( *batchResults) () error {
	if .err != nil {
		return .err
	}
log any queries that haven't yet been logged by Exec or Query
	for {
		, ,  := .nextQueryAndArgs()
		if ! {
			break
		}

		if .conn.shouldLog(LogLevelInfo) {
			.conn.log(.ctx, LogLevelInfo, "BatchResult.Close", map[string]interface{}{
				"sql":  ,
				"args": logQueryArgs(),
			})
		}
	}

	return .mrr.Close()
}

func ( *batchResults) () ( string,  []interface{},  bool) {
	if .b != nil && .ix < len(.b.items) {
		 := .b.items[.ix]
		 = .query
		 = .arguments
		 = true
		.ix++
	}
	return