sqlclosecheck icon indicating copy to clipboard operation
sqlclosecheck copied to clipboard

False positive: db.Queryx

Open pellared opened this issue 1 year ago • 5 comments

Version: v0.5.1

Repro steps:

package bug_test

import (
	"log"

	"github.com/jmoiron/sqlx"
)

func Example() {
	db, err := sqlx.Open("pgx", "postgres://localhost/db")
	if err != nil {
		log.Print(err)
		return
	}
	defer db.Close()

	rows, err := db.Queryx("SELECT * FROM users")
	if err != nil {
		log.Print(err)
		return
	}
	defer rows.Close()
}

Result (from golangci-lint):

example_test.go:17:24: Rows/Stmt/NamedStmt was not closed (sqlclosecheck)
        rows, err := db.Queryx("SELECT * FROM users")

pellared avatar Feb 08 '24 08:02 pellared

➕1

we're facing the same issue in our workflows

shubhamzanwar avatar Feb 08 '24 10:02 shubhamzanwar

Thank you for the report. I will take a look at this over the next few days.

ryanrolds avatar Feb 08 '24 16:02 ryanrolds

How's it looking with this one? 🙏🏽

shubhamzanwar avatar Feb 20 '24 15:02 shubhamzanwar

+1 in my project following code worked as a solution:

rows, err := db.Queryx("SELECT * FROM users")
if err != nil {
  log.Print(err)
  return
}
defer func() {
  _ = rows.Close()
}()

also worth mentioning: when I used sql instead of sqlx, there was no error

Bodyancheq avatar Mar 07 '24 12:03 Bodyancheq

Hi @ryanrolds ! Is there any progress on this issue?

ivanovaleksey avatar Jun 21 '24 14:06 ivanovaleksey