Skip to content
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

Possible parsing bug with semicolons #119

Open
tgf9 opened this issue Oct 4, 2023 · 0 comments
Open

Possible parsing bug with semicolons #119

tgf9 opened this issue Oct 4, 2023 · 0 comments

Comments

@tgf9
Copy link

tgf9 commented Oct 4, 2023

If a query ends in a semicolon and there's another character after the semicolon, db.Query returns the following error.

bad parameter or other API misuse: not an error (21)

Here's a Go program that reproduces the issue.

package main

import (
	"database/sql"
	"fmt"
	"log"

	_ "github.com/glebarez/go-sqlite"
)

func main() {
	db, err := sql.Open("sqlite", ":memory:")
	if err != nil {
		log.Fatalln(err)
	}
	defer db.Close()

	if _, err := db.Exec("create table foo(id integer primary key, bar text)"); err != nil {
		log.Println(err)
		return
	}

	if _, err := db.Exec("insert into foo (bar) values (?)", "bar"); err != nil {
		log.Println(err)
		return
	}

	qs := []string{
		// bad parameter or other API misuse: not an error (21)
		"select id from foo limit 1; ",
		"select id from foo limit 1;\n",
		"select id from foo limit 1;\t",
		" select id from foo limit 1; ",

		// OK
		"select id from foo limit 1;",
		" select bar from foo limit 1;",
		"select bar from foo limit 1 ",
		" select bar from foo limit 1",
	}

	for _, q := range qs {
		var bar string
		if err := db.QueryRow(q).Scan(&bar); err != nil {
			fmt.Printf("FAIL: %q\n%s\n\n", q, err)
			continue
		}
		fmt.Printf("OK: %q\n", q)
	}
}

For github.com/glebarez/go-sqlite v1.21.2

Another SQLite library github.com/mattn/go-sqlite3 v1.14.17 does not exhibit this behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant