diff --git a/example/main.go b/example/main.go index 5e28a57..2fb4515 100644 --- a/example/main.go +++ b/example/main.go @@ -1,60 +1,60 @@ -package main - -import ( - "exp/sql" - "fmt" - "os" - _ "github.com/mattn/go-sqlite3" -) - -func main() { - os.Remove("./foo.db") - - db, err := sql.Open("sqlite3", "./foo.db") - if err != nil { - fmt.Println(err) - return - } - - sqls := []string { - "create table foo (id integer not null primary key, name text)", - "delete from foo", - } - for _, sql := range(sqls) { - _, err = db.Exec(sql) - if err != nil { - fmt.Printf("%q: %s\n", err, sql) - return - } - } - - stmt, err := db.Prepare("insert into foo(id, name) values(?, ?)") - if err != nil { - fmt.Println(err) - return - } - defer stmt.Close() - - for i := 0; i < 100; i++ { - _, err = stmt.Exec(i, fmt.Sprintf("こんにちわ世界%03d", i)) - if err != nil { - fmt.Println(err) - return - } - } - - rows, err := db.Query("select id, name from foo") - if err != nil { - fmt.Println(err) - return - } - defer rows.Close() - - for rows.Next() { - var id int - var name string - rows.Scan(&id, &name) - println(id, name) - } - -} +package main + +import ( + "exp/sql" + "fmt" + _ "github.com/mattn/go-sqlite3" + "os" +) + +func main() { + os.Remove("./foo.db") + + db, err := sql.Open("sqlite3", "./foo.db") + if err != nil { + fmt.Println(err) + return + } + + sqls := []string{ + "create table foo (id integer not null primary key, name text)", + "delete from foo", + } + for _, sql := range sqls { + _, err = db.Exec(sql) + if err != nil { + fmt.Printf("%q: %s\n", err, sql) + return + } + } + + stmt, err := db.Prepare("insert into foo(id, name) values(?, ?)") + if err != nil { + fmt.Println(err) + return + } + defer stmt.Close() + + for i := 0; i < 100; i++ { + _, err = stmt.Exec(i, fmt.Sprintf("こんにちわ世界%03d", i)) + if err != nil { + fmt.Println(err) + return + } + } + + rows, err := db.Query("select id, name from foo") + if err != nil { + fmt.Println(err) + return + } + defer rows.Close() + + for rows.Next() { + var id int + var name string + rows.Scan(&id, &name) + println(id, name) + } + +}