mattn / mattn/go-sqlite3

Empty query causes loop

Open
#950 5 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
9.2k
Forks
1.2k
Avg merge
19m
Merged PRs (30d)
4

Description

By mistake stupid me executed an empty query. This resulted in an (infinite?) loop and hanged my application.

The minimal example below reproduces this. This example uses an in-memory database, but it occurs with a database file as well.

Version: v1.14.7

db, err := sql.Open("sqlite3", ":memory:")
if err != nil {
	panic(err)
}
defer db.Close()

stmt, err := db.Prepare("") // empty query
if err != nil {
	panic(err)
}
defer stmt.Close()

rows, err := stmt.Query()
if err != nil {
	panic(err)
}
defer rows.Close()

count := 0
for rows.Next() {
	var dummy string
	rows.Scan(&dummy) // this can be omitted

	log.Printf("%d: [%+v]\n", count, dummy)
	count++
}

Results in:

0: []
1: []
2: []
3: []
4: []
...

I don't know what the expected behavior should be. Maybe return an error?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the minimal Go reproduction against the reported v1.14.7 behavior and trace how the empty query is handled through statement execution and row iteration. Define the expected empty-query behavior, then add coverage showing that rows.Next does not loop indefinitely and that the result or error is consistent.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, sqlite
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.