Skip to content

Commit

Permalink
Fix TestQueryer test to use exec for multistatement insertion
Browse files Browse the repository at this point in the history
  • Loading branch information
joshbuddy authored and mattn committed Sep 1, 2022
1 parent d5355d8 commit f92b6bb
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions sqlite3_test.go
Original file line number Diff line number Diff line change
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
}
if n != 4 {
t.Errorf("Expected 3 rows but retrieved %v", n-1)
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)
}
}

Expand Down

0 comments on commit f92b6bb

Please sign in to comment.