Enable test for Queryer

This commit is contained in:
mattn 2014-06-26 04:06:39 +09:00
parent d9e7576acf
commit 5fb02bd99d
1 changed files with 40 additions and 40 deletions

View File

@ -660,43 +660,43 @@ func TestExecer(t *testing.T) {
}
}
//func TestQueryer(t *testing.T) {
// tempFilename := TempFilename()
// db, err := sql.Open("sqlite3", tempFilename)
// if err != nil {
// t.Fatal("Failed to open database:", err)
// }
// defer os.Remove(tempFilename)
// defer db.Close()
//
// _, err = db.Exec(`
// 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;
// `, 3, 2, 1)
// if err != nil {
// t.Error("Failed to call db.Query:", err)
// }
// defer rows.Close()
// n := 1
// if rows != nil {
// for rows.Next() {
// var id int
// err = rows.Scan(&id)
// if err != nil {
// t.Error("Failed to db.Query:", err)
// }
// if id != n {
// t.Error("Failed to db.Query: not matched results")
// }
// }
// }
//}
func TestQueryer(t *testing.T) {
tempFilename := TempFilename()
db, err := sql.Open("sqlite3", tempFilename)
if err != nil {
t.Fatal("Failed to open database:", err)
}
defer os.Remove(tempFilename)
defer db.Close()
_, err = db.Exec(`
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;
`, 3, 2, 1)
if err != nil {
t.Error("Failed to call db.Query:", err)
}
defer rows.Close()
n := 1
if rows != nil {
for rows.Next() {
var id int
err = rows.Scan(&id)
if err != nil {
t.Error("Failed to db.Query:", err)
}
if id != n {
t.Error("Failed to db.Query: not matched results")
}
}
}
}