github.com/vanstinator/golangci-lint@v0.0.0-20240223191551-cc572f00d9d1/test/testdata/execinquery.go (about)

     1  //golangcitest:args -Eexecinquery
     2  package testdata
     3  
     4  import (
     5  	"context"
     6  	"database/sql"
     7  )
     8  
     9  func execInQuery(db *sql.DB) {
    10  	test := "a"
    11  
    12  	_, err := db.Query("Update * FROM hoge where id = ?", test) // want "Use Exec instead of Query to execute `UPDATE` query"
    13  	if err != nil {
    14  		return
    15  	}
    16  
    17  	db.QueryRow("Update * FROM hoge where id = ?", test) // want "Use Exec instead of QueryRow to execute `UPDATE` query"
    18  	if err != nil {
    19  		return
    20  	}
    21  
    22  	ctx := context.Background()
    23  
    24  	_, err = db.QueryContext(ctx, "Update * FROM hoge where id = ?", test) // want "Use ExecContext instead of QueryContext to execute `UPDATE` query"
    25  	if err != nil {
    26  		return
    27  	}
    28  
    29  	db.QueryRowContext(ctx, "Update * FROM hoge where id = ?", test) // want "Use ExecContext instead of QueryRowContext to execute `UPDATE` query"
    30  }