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

Fix test queryer test #1079

Merged
merged 2 commits into from Sep 1, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 17 additions & 9 deletions sqlite3_test.go
Expand Up @@ -1063,36 +1063,44 @@ func TestQueryer(t *testing.T) {
defer db.Close()

_, err = db.Exec(`
create table foo (id integer);
create table foo (id integer);
`)
if err != nil {
t.Error("Failed to call db.Query:", err)
}

rows, err := db.Query(`
insert into foo(id) values(?);
insert into foo(id) values(?);
insert into foo(id) values(?);
select id from foo order by id;
_, err = db.Exec(`
insert into foo(id) values(?);
insert into foo(id) values(?);
insert into foo(id) values(?);
`, 3, 2, 1)
if err != nil {
t.Error("Failed to call db.Exec:", err)
}
rows, err := db.Query(`
select id from foo order by id;
`)
if err != nil {
t.Error("Failed to call db.Query:", err)
}
defer rows.Close()
n := 1
n := 0
for rows.Next() {
var id int
err = rows.Scan(&id)
if err != nil {
t.Error("Failed to db.Query:", err)
}
if id != n {
if id != n + 1 {
t.Error("Failed to db.Query: not matched results")
}
n = n + 1
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the missing call to rows.Err() after the loop.

if err := rows.Err(); err != nil {
t.Errorf("Post-scan failed: %v\n", err)
}
if n != 3 {
t.Errorf("Expected 3 rows but retrieved %v", n-1)
t.Errorf("Expected 3 rows but retrieved %v", n)
}
}

Expand Down