sqlrows icon indicating copy to clipboard operation
sqlrows copied to clipboard

Add ability to check closing of transactions

Open agnivade opened this issue 5 years ago • 3 comments

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.

agnivade avatar Apr 04 '19 16:04 agnivade

@agnivade Thank you for a nice proposal.

First, this package is only for the validation of *sql.Rows. But in the future, with other analyzers, we'll mix them to check broad use-cases of database/sql

For this reason, I'm sorry I won't implement the checker of database transaction commit in this package. However, I definitely support this with creating another analyzer as soon as possible! So I keep this issue opened. Thanks.

timakin avatar Apr 04 '19 16:04 timakin

Great, thanks !

agnivade avatar Apr 04 '19 16:04 agnivade

If a common pattern is eventually established for checking for closing of both Rows and Transactions then the next logical check would be closing Prepared Statements.

jstangroome avatar Nov 19 '20 22:11 jstangroome