Skip to content

Return io.EOF for empty Query statements #1285

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sqlite3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
28 changes: 28 additions & 0 deletions sqlite3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down