golangci-lint/test/testdata/execinquery.go

31 lines
793 B
Go
Raw Permalink Normal View History

//golangcitest:args -Eexecinquery
2022-03-29 19:31:56 +09:00
package testdata
import (
"context"
"database/sql"
)
func execInQuery(db *sql.DB) {
test := "a"
_, err := db.Query("Update * FROM hoge where id = ?", test) // want "Use Exec instead of Query to execute `UPDATE` query"
2022-03-29 19:31:56 +09:00
if err != nil {
return
}
db.QueryRow("Update * FROM hoge where id = ?", test) // want "Use Exec instead of QueryRow to execute `UPDATE` query"
2022-03-29 19:31:56 +09:00
if err != nil {
return
}
ctx := context.Background()
_, err = db.QueryContext(ctx, "Update * FROM hoge where id = ?", test) // want "Use ExecContext instead of QueryContext to execute `UPDATE` query"
2022-03-29 19:31:56 +09:00
if err != nil {
return
}
db.QueryRowContext(ctx, "Update * FROM hoge where id = ?", test) // want "Use ExecContext instead of QueryRowContext to execute `UPDATE` query"
2022-03-29 19:31:56 +09:00
}