From 823d03f3f85050628888ea743315df538b8e1c18 Mon Sep 17 00:00:00 2001 From: Gani Georgiev Date: Sat, 12 Oct 2024 01:53:22 +0300 Subject: [PATCH] return io.EOF for empty Query statements --- sqlite3.go | 2 +- sqlite3_test.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/sqlite3.go b/sqlite3.go index ce985ec..852e94a 100644 --- a/sqlite3.go +++ b/sqlite3.go @@ -2206,7 +2206,7 @@ func (rc *SQLiteRows) nextSyncLocked(dest []driver.Value) error { if rv != C.SQLITE_OK { return rc.s.c.lastError() } - return nil + return io.EOF } rc.declTypes() diff --git a/sqlite3_test.go b/sqlite3_test.go index 63c939d..c82bbe5 100644 --- a/sqlite3_test.go +++ b/sqlite3_test.go @@ -1997,6 +1997,34 @@ func TestNamedParam(t *testing.T) { } } +func TestEmptyQuery(t *testing.T) { + db, err := sql.Open("sqlite3", ":memory:") + if err != nil { + t.Fatal("Failed to open database:", err) + } + defer db.Close() + + queries := []string{ + "", + ";", + " -- comment ", + } + + for _, q := range queries { + t.Run(fmt.Sprintf("query:%q", q), func(t *testing.T) { + rows, err := db.Query(q) + if err != nil { + t.Fatal("Failed to run empty query:", err) + } + defer rows.Close() + + if rows.Next() != false { + t.Fatal("Expected no rows") + } + }) + } +} + var customFunctionOnce sync.Once func BenchmarkCustomFunctions(b *testing.B) {