diff --git a/example/main.go b/example/main.go index 6d6aa0e..35e5314 100644 --- a/example/main.go +++ b/example/main.go @@ -15,6 +15,7 @@ func main() { fmt.Println(err) return } + defer db.Close() sqls := []string{ "create table foo (id integer not null primary key, name text)", @@ -39,7 +40,6 @@ func main() { return } defer stmt.Close() - for i := 0; i < 100; i++ { _, err = stmt.Exec(i, fmt.Sprintf("こんにちわ世界%03d", i)) if err != nil { @@ -55,11 +55,25 @@ func main() { return } defer rows.Close() - for rows.Next() { var id int var name string rows.Scan(&id, &name) println(id, name) } + rows.Close() + + stmt, err = db.Prepare("select name from foo where id = ?") + if err != nil { + fmt.Println(err) + return + } + defer stmt.Close() + var name string + err = stmt.QueryRow("3").Scan(&name) + if err != nil { + fmt.Println(err) + return + } + println(name) }