mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
database/sql: check for nil Scan pointers
Return nice errors and don't panic. Fixes #4859 R=golang-dev, rsc CC=golang-dev https://golang.org/cl/7383046
This commit is contained in:
parent
5833c96b0a
commit
bca3f5fca0
2 changed files with 36 additions and 1 deletions
|
|
@ -696,3 +696,15 @@ func nullTestRun(t *testing.T, spec nullTestSpec) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// golang.org/issue/4859
|
||||
func TestQueryRowNilScanDest(t *testing.T) {
|
||||
db := newTestDB(t, "people")
|
||||
defer closeDB(t, db)
|
||||
var name *string // nil pointer
|
||||
err := db.QueryRow("SELECT|people|name|").Scan(name)
|
||||
want := "sql: Scan error on column index 0: destination pointer is nil"
|
||||
if err == nil || err.Error() != want {
|
||||
t.Errorf("error = %q; want %q", err.Error(), want)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue