Git Product home page Git Product logo

sqlrows's People

Contributors

bbrodriges avatar jtorvald avatar sryoya avatar timakin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

sqlrows's Issues

False positives and false negatives

I believe the program does not function like it should. It only works if I put rows.Close directly under the line of the query (which is not good). If I make that a defer rows.Close() I get:
./main.go:16:8: using rows before checking for errors
which you should expect

        rows, err := readDB.Query("SELECT 1")
        if err != nil {
                panic(err)
        }
        defer rows.Close()

$ go vet -vettool=$(which sqlrows) ./...
#./main.go:15:27: rows.Close must be called

Source code

package main
  
import (
        "database/sql"
        _ "github.com/go-sql-driver/mysql"
)

func main(){
        
        readDB, err := sql.Open("mysql", "root:root@tcp(localhost:3306)/mysql?parseTime=true&charset=utf8mb4")
        if err != nil {
                panic(err.Error()) 
        }       
        
        rows, err := readDB.Query("SELECT 1")
        // rows.Close() // no warnings, which is incorrect
        // defer rows.Close() // gives ./main.go:16:8: using rows before checking for errors
        if err != nil {
                panic(err)
        }
        defer rows.Close() // correct but does not get noticed

}

Add ability to check closing of transactions

Hi, thanks for creating this. I would love to use this tool if this supports checking transactions too. Usually, rows.Close() is something that is not missed. But I miss closing transactions often.

I would want to check that transactions are always either committed or rolled back before the function returns.

Something like

tx, err := db.Begin()
if err != nil {
	return err
}
err = doSomething()
if err != nil {
	tx.Rollback()
	return err
}
return nil // error !! We are not doing tx.Commit() before returning.

Will it be possible to add something like this ? Thanks.

panic: *ssa.Phi during rows declaration without assignment

sqlrows panics when parsing the following code:

var rows *sql.Rows
if foo {
    rows, err = queryFoo()
} else {
    rows, err = queryBar()
}
if err != nil { return err }
defer rows.Close()

After digging in, it seems this is because var rows *sql.Rows comes in as an *ssa.Phi rather than an *ssa.Extract.

panic: *ssa.UnOp during rows.Close()

The following code seems to cause sqlrows to panic:

rows, err := db.Query(a, b, c)
if err != nil {
    return err
}
func() {
    defer rows.Close()

    // read from rows...
}()

After digging in some, it seems that the deferred rows.Close() call inside of the closure is dereferencing the *sql.Rows value, because it comes out as an *ssa.UnOp instead of an *ssa.Extract.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.