Skip to content

Instantly share code, notes, and snippets.

@fiber

fiber/sqltest.go Secret

Created July 15, 2014 15:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fiber/e096b0eca9d231740185 to your computer and use it in GitHub Desktop.
Save fiber/e096b0eca9d231740185 to your computer and use it in GitHub Desktop.
d56eb93 breaks this code
package main
import (
"database/sql"
"fmt"
_ "github.com/mattn/go-sqlite3"
"os"
"time"
)
func main() {
if _, err := os.Stat("sqltest.db1.sqlite3"); err != nil {
db, err := sql.Open("sqlite3", "sqltest.db1.sqlite3")
if err != nil {
fmt.Fprintf(os.Stderr, "failed to open: %v\n", err)
time.Sleep(60 * time.Second)
os.Exit(1)
}
db.Exec("CREATE TABLE foo (id int);")
db.Exec("INSERT INTO foo VALUES(1);")
db.Exec("INSERT INTO foo VALUES(2);")
db.Close()
}
for i := 0; i < 10000; i++ {
db, err := sql.Open("sqlite3", "sqltest.db1.sqlite3")
if err != nil {
fmt.Fprintf(os.Stderr, "[%v] failed to open: %v\n", i, err)
time.Sleep(60 * time.Second)
os.Exit(1)
}
for j := 0; j < 3; j++ {
rows, err := db.Query("select * from foo where id=1;")
if err != nil {
fmt.Fprintf(os.Stderr, "[%v/%v] query failed: %v\n", i, j, err)
time.Sleep(60 * time.Second)
os.Exit(1)
} else {
for rows.Next() {
var i int
if err := rows.Scan(&i); err != nil {
fmt.Fprintf(os.Stderr, "scan failed: %v\n", err)
}
}
if err := rows.Err(); err != nil {
fmt.Fprintf(os.Stderr, "post-scan failed: %v\n", err)
}
rows.Close()
}
}
db.Close()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment