Skip to content

False positive: db.Queryx #35

Open

Description

@pellared

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")

Activity

  1. shubhamzanwar commented on Feb 8, 2024

    @shubhamzanwar

    ➕1

    we're facing the same issue in our workflows

  2. ryanrolds commented on Feb 8, 2024

    @ryanrolds
    Owner

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

  3. shubhamzanwar commented on Feb 20, 2024

    @shubhamzanwar

    How's it looking with this one? 🙏🏽

  4. Bodyancheq commented on Mar 7, 2024

    @Bodyancheq

    +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

  5. ivanovaleksey commented on Jun 21, 2024

    @ivanovaleksey

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

  6. added a commit that references this issue on Feb 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions