summaryrefslogtreecommitdiff
path: root/vendor/github.com/jackc/pgx/v5/rows.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/jackc/pgx/v5/rows.go')
-rw-r--r--vendor/github.com/jackc/pgx/v5/rows.go13
1 files changed, 10 insertions, 3 deletions
diff --git a/vendor/github.com/jackc/pgx/v5/rows.go b/vendor/github.com/jackc/pgx/v5/rows.go
index f23625d4c..f6f26f479 100644
--- a/vendor/github.com/jackc/pgx/v5/rows.go
+++ b/vendor/github.com/jackc/pgx/v5/rows.go
@@ -272,7 +272,7 @@ func (rows *baseRows) Scan(dest ...any) error {
err := rows.scanPlans[i].Scan(values[i], dst)
if err != nil {
- err = ScanArgError{ColumnIndex: i, Err: err}
+ err = ScanArgError{ColumnIndex: i, FieldName: fieldDescriptions[i].Name, Err: err}
rows.fatal(err)
return err
}
@@ -334,11 +334,16 @@ func (rows *baseRows) Conn() *Conn {
type ScanArgError struct {
ColumnIndex int
+ FieldName string
Err error
}
func (e ScanArgError) Error() string {
- return fmt.Sprintf("can't scan into dest[%d]: %v", e.ColumnIndex, e.Err)
+ if e.FieldName == "?column?" { // Don't include the fieldname if it's unknown
+ return fmt.Sprintf("can't scan into dest[%d]: %v", e.ColumnIndex, e.Err)
+ }
+
+ return fmt.Sprintf("can't scan into dest[%d] (col: %s): %v", e.ColumnIndex, e.FieldName, e.Err)
}
func (e ScanArgError) Unwrap() error {
@@ -366,7 +371,7 @@ func ScanRow(typeMap *pgtype.Map, fieldDescriptions []pgconn.FieldDescription, v
err := typeMap.Scan(fieldDescriptions[i].DataTypeOID, fieldDescriptions[i].Format, values[i], d)
if err != nil {
- return ScanArgError{ColumnIndex: i, Err: err}
+ return ScanArgError{ColumnIndex: i, FieldName: fieldDescriptions[i].Name, Err: err}
}
}
@@ -468,6 +473,8 @@ func CollectOneRow[T any](rows Rows, fn RowToFunc[T]) (T, error) {
return value, err
}
+ // The defer rows.Close() won't have executed yet. If the query returned more than one row, rows would still be open.
+ // rows.Close() must be called before rows.Err() so we explicitly call it here.
rows.Close()
return value, rows.Err()
}