rowserrcheck

command module
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 18, 2021 License: MIT Imports: 2 Imported by: 0

README

rowserrcheck

CircleCI

rowserrcheck is a static analysis tool which checks whether sql.Rows.Err is correctly checked.

Install

You can get rowserrcheck by go get command.

$ go get -u github.com/jingyugao/rowserrcheck

Analyzer

rowserrcheck validates whether *database/sql.Rows of sql query calls method rows.Err() such as below code.

rows, _ := db.Query("select id from tb") // Wrong case
if err != nil {
	// handle error
}
for rows.Next(){
	// handle rows
}

This code is wrong. You must check rows.Err when finished scan rows.

rows, _ := db.Query("select id from tb") // Wrong case
for rows.Next(){
	// handle rows
}
if rows.Err()!=nil{
	// handle err
}

In the GoDoc of sql.Rows this rule is clearly described.

If you forget this sentence, and unluckly an invaliad connection error happend when fetch data from database, rows.Next will return false, and you will get an incomplete data, and even it seems everything is ok. This will cause serious accident.

Thanks

Thanks for timakin.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
passes

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL