Closed
Description
Passing an empty to a string causes a panic in the database/sql layer. Is there some initialization I'm missing? I see nothing in the docs that state this should panic.
~/repos/go-empty-sql-statement/src/github/com/otoolep/go-empty-sql-statement (master)$ cat main.go
package main
import (
"database/sql"
"fmt"
"log"
"os"
_ "github.com/mattn/go-sqlite3"
)
func main() {
os.Remove("foo.bar")
db, err := sql.Open("sqlite3", "foo.bar")
if err != nil {
log.Fatalf("failed to open database: %s", err.Error())
}
results, err := db.Exec("")
if err != nil {
log.Fatalf("failed to get results: %s", err.Error())
}
li, err := results.LastInsertId()
fmt.Println(li, err)
}
~/repos/go-empty-sql-statement/src/github/com/otoolep/go-empty-sql-statement (master)$ go run main.go
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x4fa135]
goroutine 1 [running]:
database/sql.driverResult.LastInsertId(0x6513a0, 0xc000144000, 0x0, 0x0, 0x0, 0x0, 0x0)
/home/philip/.gvm/gos/go1.15/src/database/sql/sql.go:3266 +0x75
main.main()
/home/philip/repos/go-empty-sql-statement/src/github/com/otoolep/go-empty-sql-statement/main.go:24 +0xfd
exit status 2
~/repos/go-empty-sql-statement/src/github/com/otoolep/go-empty-sql-statement (master)$
Metadata
Metadata
Assignees
Labels
No labels