Add error checking in simple example for tx.Commit

Based on https://golang.org/pkg/database/sql/#Tx.Commit this function returns an error type.
So why not check it.
This commit is contained in:
Kristóf Havasi 2021-05-05 22:00:24 +02:00 committed by mattn
parent 43dcd3131f
commit b819467576
1 changed files with 4 additions and 1 deletions

View File

@ -42,7 +42,10 @@ func main() {
log.Fatal(err) log.Fatal(err)
} }
} }
tx.Commit() err = tx.Commit()
if err != nil {
log.Fatal(err)
}
rows, err := db.Query("select id, name from foo") rows, err := db.Query("select id, name from foo")
if err != nil { if err != nil {