Skip to content

Commit bbe5f66

Browse files
committed
Don't panic when querying with only comments
1 parent 58e032d commit bbe5f66

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

sqlite3.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2239,6 +2239,9 @@ func stmtArgs(args []driver.NamedValue, start, na int) []driver.NamedValue {
22392239
}
22402240

22412241
func (s *SQLiteStmt) bind(args []driver.NamedValue) error {
2242+
if s.s == nil {
2243+
return nil
2244+
}
22422245
rv := C._sqlite3_reset_clear(s.s)
22432246
if rv != C.SQLITE_ROW && rv != C.SQLITE_OK && rv != C.SQLITE_DONE {
22442247
return s.c.lastError()

sqlite3_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2063,6 +2063,16 @@ func TestNamedParamClearBindings(t *testing.T) {
20632063
if z.Valid {
20642064
t.Errorf("Expected z to be NULL, got %d", z.Int64)
20652065
}
2066+
2067+
// Ensure empty statements don't cause panics.
2068+
_, _ = db.Exec("---- comment")
2069+
if err != nil {
2070+
t.Fatal("Failed to exec comment only:", err)
2071+
}
2072+
_ = db.QueryRow("---- comment")
2073+
if err != nil {
2074+
t.Fatal("Failed to query comment only:", err)
2075+
}
20662076
}
20672077

20682078
var customFunctionOnce sync.Once

0 commit comments

Comments
 (0)