Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions callbacks/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ func Create(config *Config) func(db *gorm.DB) {
)
if db.AddError(err) == nil {
defer func() {
// Make sure it's processed and errors are taken into account.
if !rows.Next() {
db.AddError(rows.Err())
}
db.AddError(rows.Close())
}()
gorm.Scan(rows, db, mode)
Expand Down
4 changes: 4 additions & 0 deletions callbacks/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ func Delete(config *Config) func(db *gorm.DB) {

if rows, err := db.Statement.ConnPool.QueryContext(db.Statement.Context, db.Statement.SQL.String(), db.Statement.Vars...); db.AddError(err) == nil {
gorm.Scan(rows, db, mode)
// Make sure it's processed and errors are taken into account.
if !rows.Next() {
db.AddError(rows.Err())
}
db.AddError(rows.Close())
}
}
Expand Down
4 changes: 4 additions & 0 deletions callbacks/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ func Query(db *gorm.DB) {
return
}
defer func() {
// Make sure it's processed and errors are taken into account.
if !rows.Next() {
db.AddError(rows.Err())
}
db.AddError(rows.Close())
}()
gorm.Scan(rows, db, 0)
Expand Down
4 changes: 4 additions & 0 deletions callbacks/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ func Update(config *Config) func(db *gorm.DB) {
db.Statement.Dest = db.Statement.ReflectValue.Addr().Interface()
gorm.Scan(rows, db, mode)
db.Statement.Dest = dest
// Make sure it's processed and errors are taken into account.
if !rows.Next() {
db.AddError(rows.Err())
}
db.AddError(rows.Close())
}
} else {
Expand Down
4 changes: 0 additions & 4 deletions scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,6 @@ func Scan(rows Rows, db *DB, mode ScanMode) {
}
}

if err := rows.Err(); err != nil && err != db.Error {
db.AddError(err)
}

if db.RowsAffected == 0 && db.Statement.RaiseErrorOnNotFound && db.Error == nil {
db.AddError(ErrRecordNotFound)
}
Expand Down
Loading