summaryrefslogtreecommitdiff
path: root/vendor/github.com/jackc/pgx/v5/batch.go
diff options
context:
space:
mode:
authorLibravatar dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>2024-09-16 09:26:41 +0200
committerLibravatar GitHub <noreply@github.com>2024-09-16 09:26:41 +0200
commitca729aa4a06b5d7e5587e2b2e2a0b87bfb17513c (patch)
tree15147a61f3a12edba73c2add3aabf620b49c5d36 /vendor/github.com/jackc/pgx/v5/batch.go
parent[bugfix] Hoist filterable text field extraction out of loop (#3297) (diff)
downloadgotosocial-ca729aa4a06b5d7e5587e2b2e2a0b87bfb17513c.tar.xz
[chore]: Bump github.com/jackc/pgx/v5 from 5.6.0 to 5.7.1 (#3302)
Bumps [github.com/jackc/pgx/v5](https://github.com/jackc/pgx) from 5.6.0 to 5.7.1. - [Changelog](https://github.com/jackc/pgx/blob/master/CHANGELOG.md) - [Commits](https://github.com/jackc/pgx/compare/v5.6.0...v5.7.1) --- updated-dependencies: - dependency-name: github.com/jackc/pgx/v5 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Diffstat (limited to 'vendor/github.com/jackc/pgx/v5/batch.go')
-rw-r--r--vendor/github.com/jackc/pgx/v5/batch.go44
1 files changed, 27 insertions, 17 deletions
diff --git a/vendor/github.com/jackc/pgx/v5/batch.go b/vendor/github.com/jackc/pgx/v5/batch.go
index 3540f57f5..c3c2834f2 100644
--- a/vendor/github.com/jackc/pgx/v5/batch.go
+++ b/vendor/github.com/jackc/pgx/v5/batch.go
@@ -60,9 +60,13 @@ type Batch struct {
QueuedQueries []*QueuedQuery
}
-// Queue queues a query to batch b. query can be an SQL query or the name of a prepared statement.
-// The only pgx option argument that is supported is QueryRewriter. Queries are executed using the
-// connection's DefaultQueryExecMode.
+// Queue queues a query to batch b. query can be an SQL query or the name of a prepared statement. The only pgx option
+// argument that is supported is QueryRewriter. Queries are executed using the connection's DefaultQueryExecMode.
+//
+// While query can contain multiple statements if the connection's DefaultQueryExecMode is QueryModeSimple, this should
+// be avoided. QueuedQuery.Fn must not be set as it will only be called for the first query. That is, QueuedQuery.Query,
+// QueuedQuery.QueryRow, and QueuedQuery.Exec must not be called. In addition, any error messages or tracing that
+// include the current query may reference the wrong query.
func (b *Batch) Queue(query string, arguments ...any) *QueuedQuery {
qq := &QueuedQuery{
SQL: query,
@@ -128,7 +132,7 @@ func (br *batchResults) Exec() (pgconn.CommandTag, error) {
if !br.mrr.NextResult() {
err := br.mrr.Close()
if err == nil {
- err = errors.New("no result")
+ err = errors.New("no more results in batch")
}
if br.conn.batchTracer != nil {
br.conn.batchTracer.TraceBatchQuery(br.ctx, br.conn, TraceBatchQueryData{
@@ -180,7 +184,7 @@ func (br *batchResults) Query() (Rows, error) {
if !br.mrr.NextResult() {
rows.err = br.mrr.Close()
if rows.err == nil {
- rows.err = errors.New("no result")
+ rows.err = errors.New("no more results in batch")
}
rows.closed = true
@@ -287,7 +291,10 @@ func (br *pipelineBatchResults) Exec() (pgconn.CommandTag, error) {
return pgconn.CommandTag{}, br.err
}
- query, arguments, _ := br.nextQueryAndArgs()
+ query, arguments, err := br.nextQueryAndArgs()
+ if err != nil {
+ return pgconn.CommandTag{}, err
+ }
results, err := br.pipeline.GetResults()
if err != nil {
@@ -330,9 +337,9 @@ func (br *pipelineBatchResults) Query() (Rows, error) {
return &baseRows{err: br.err, closed: true}, br.err
}
- query, arguments, ok := br.nextQueryAndArgs()
- if !ok {
- query = "batch query"
+ query, arguments, err := br.nextQueryAndArgs()
+ if err != nil {
+ return &baseRows{err: err, closed: true}, err
}
rows := br.conn.getRows(br.ctx, query, arguments)
@@ -421,13 +428,16 @@ func (br *pipelineBatchResults) earlyError() error {
return br.err
}
-func (br *pipelineBatchResults) nextQueryAndArgs() (query string, args []any, ok bool) {
- if br.b != nil && br.qqIdx < len(br.b.QueuedQueries) {
- bi := br.b.QueuedQueries[br.qqIdx]
- query = bi.SQL
- args = bi.Arguments
- ok = true
- br.qqIdx++
+func (br *pipelineBatchResults) nextQueryAndArgs() (query string, args []any, err error) {
+ if br.b == nil {
+ return "", nil, errors.New("no reference to batch")
}
- return
+
+ if br.qqIdx >= len(br.b.QueuedQueries) {
+ return "", nil, errors.New("no more results in batch")
+ }
+
+ bi := br.b.QueuedQueries[br.qqIdx]
+ br.qqIdx++
+ return bi.SQL, bi.Arguments, nil
}