We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
macOS 14.4.1, Go 1.20
When using db.Query to perform a query that does not return any rows, sqlmock panics instead of performing a no-op as other database drivers do.
db.Query
A workaround is to use db.Exec instead so that there is no rows object to close, but the sqlmock behavior is incorrect.
db.Exec
package main import ( "github.com/DATA-DOG/go-sqlmock" ) func assert(err error) { if err != nil { panic(err.Error()) } } func main() { db, mock, err := sqlmock.New() assert(err) mock.ExpectQuery("TRUNCATE table").WithoutArgs().WillReturnRows() rows, err := db.Query("TRUNCATE table") assert(err) err = rows.Close() assert(err) }
No error (or, at worst, an error returned from rows.Close)
rows.Close
panic: runtime error: index out of range [0] with length 0 goroutine 1 [running]: github.com/DATA-DOG/go-sqlmock.(*rowSets).Close(0x14000124040) /Users/rrosborough/.asdf/installs/golang/1.20/packages/pkg/mod/github.com/!d!a!t!a-!d!o!g/go-sqlmock@v1.5.2/rows.go:40 +0x64 database/sql.(*Rows).close.func1() /Users/rrosborough/.asdf/installs/golang/1.20/go/src/database/sql/sql.go:3287 +0x34 database/sql.withLock({0x100b84d50, 0x14000142000}, 0x14000149eb8) /Users/rrosborough/.asdf/installs/golang/1.20/go/src/database/sql/sql.go:3405 +0x7c database/sql.(*Rows).close(0x14000134180, {0x0, 0x0}) /Users/rrosborough/.asdf/installs/golang/1.20/go/src/database/sql/sql.go:3286 +0x130 database/sql.(*Rows).Close(0x140001360e0?) /Users/rrosborough/.asdf/installs/golang/1.20/go/src/database/sql/sql.go:3270 +0x24 main.main() /Users/rrosborough/temp/sqlmockexample/main.go:19 +0x12c
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Operating system and Go Version
macOS 14.4.1, Go 1.20
Issue
When using
db.Query
to perform a query that does not return any rows, sqlmock panics instead of performing a no-op as other database drivers do.A workaround is to use
db.Exec
instead so that there is no rows object to close, but the sqlmock behavior is incorrect.Reproduction steps
Expected Result
No error (or, at worst, an error returned from
rows.Close
)Actual Result
The text was updated successfully, but these errors were encountered: