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:
Brad Fitzpatrick 2013-02-21 10:43:00 -08:00
parent 5833c96b0a
commit bca3f5fca0
2 changed files with 36 additions and 1 deletions

View file

@ -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)
}
}