mirror of https://github.com/mattn/go-sqlite3.git
Fix TestQueryer test to use exec for multistatement insertion
This commit is contained in:
parent
d5355d86f9
commit
f92b6bb2a1
|
@ -1063,36 +1063,44 @@ func TestQueryer(t *testing.T) {
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
_, err = db.Exec(`
|
_, err = db.Exec(`
|
||||||
create table foo (id integer);
|
create table foo (id integer);
|
||||||
`)
|
`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("Failed to call db.Query:", err)
|
t.Error("Failed to call db.Query:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
rows, err := db.Query(`
|
_, err = db.Exec(`
|
||||||
insert into foo(id) values(?);
|
insert into foo(id) values(?);
|
||||||
insert into foo(id) values(?);
|
insert into foo(id) values(?);
|
||||||
insert into foo(id) values(?);
|
insert into foo(id) values(?);
|
||||||
select id from foo order by id;
|
|
||||||
`, 3, 2, 1)
|
`, 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 {
|
if err != nil {
|
||||||
t.Error("Failed to call db.Query:", err)
|
t.Error("Failed to call db.Query:", err)
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
n := 1
|
n := 0
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var id int
|
var id int
|
||||||
err = rows.Scan(&id)
|
err = rows.Scan(&id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("Failed to db.Query:", err)
|
t.Error("Failed to db.Query:", err)
|
||||||
}
|
}
|
||||||
if id != n {
|
if id != n + 1 {
|
||||||
t.Error("Failed to db.Query: not matched results")
|
t.Error("Failed to db.Query: not matched results")
|
||||||
}
|
}
|
||||||
n = n + 1
|
n = n + 1
|
||||||
}
|
}
|
||||||
if n != 4 {
|
if err := rows.Err(); err != nil {
|
||||||
t.Errorf("Expected 3 rows but retrieved %v", n-1)
|
t.Errorf("Post-scan failed: %v\n", err)
|
||||||
|
}
|
||||||
|
if n != 3 {
|
||||||
|
t.Errorf("Expected 3 rows but retrieved %v", n)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue