Skip to content

Commit

Permalink
* Fixed a bug that caused a panic if no rows were returned in Insert/…
Browse files Browse the repository at this point in the history
…InsertAll.
  • Loading branch information
Dorus van de Spijker committed Mar 2, 2022
1 parent 3c5969e commit be5639a
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions mssql.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ func (m MSSQL) Insert(ctx context.Context, query rel.Query, primaryField string,
rows, err = m.DoQuery(ctx, statement, args)
)

defer rows.Close()
defer func() {
if rows != nil {
rows.Close()
}
}()

if err == nil && rows.Next() {
rows.Scan(&id)
}
Expand All @@ -62,7 +67,12 @@ func (m MSSQL) InsertAll(ctx context.Context, query rel.Query, primaryField stri
rows, err = m.DoQuery(ctx, statement, args)
)

defer rows.Close()
defer func() {
if rows != nil {
rows.Close()
}
}()

if err == nil {
for rows.Next() {
var id int64
Expand Down

0 comments on commit be5639a

Please sign in to comment.