From 5b74e9ce72fb9592241c42cf046f8f4c20446813 Mon Sep 17 00:00:00 2001 From: David Hill Date: Thu, 12 Sep 2013 11:38:11 -0400 Subject: [PATCH] add new test for WAL journal_mode --- sqlite3_test.go | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/sqlite3_test.go b/sqlite3_test.go index ec86aef..55536e8 100644 --- a/sqlite3_test.go +++ b/sqlite3_test.go @@ -580,6 +580,52 @@ func TestTransaction(t *testing.T) { } } +func TestWAL(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() + if _, err = db.Exec("PRAGMA journal_mode=WAL;"); err != nil { + t.Fatal("Failed to Exec PRAGMA journal_mode:", err) + } + if _, err = db.Exec("PRAGMA locking_mode=EXCLUSIVE;"); err != nil { + t.Fatal("Failed to Exec PRAGMA locking_mode:", err) + } + if _, err = db.Exec("CREATE TABLE test (id SERIAL, user TEXT NOT NULL, name TEXT NOT NULL);"); err != nil { + t.Fatal("Failed to Exec CREATE TABLE:", err) + } + if _, err = db.Exec("INSERT INTO test (user, name) VALUES ('user','name');"); err != nil { + t.Fatal("Failed to Exec INSERT:", err) + } + + trans, err := db.Begin() + if err != nil { + t.Fatal("Failed to Begin:", err) + } + s, err := trans.Prepare("INSERT INTO test (user, name) VALUES (?, ?);") + if err != nil { + t.Fatal("Failed to Prepare:", err) + } + + var count int + if err = trans.QueryRow("SELECT count(user) FROM test;").Scan(&count); err != nil { + t.Fatal("Failed to QueryRow:", err) + } + if _, err = s.Exec("bbbb", "aaaa"); err != nil { + t.Fatal("Failed to Exec prepared statement:", err) + } + if err = s.Close(); err != nil { + t.Fatal("Failed to Close prepared statement:", err) + } + if err = trans.Commit(); err != nil { + t.Fatal("Failed to Commit:", err) + } +} + // TODO: Execer & Queryer currently disabled // https://github.com/mattn/go-sqlite3/issues/82 //func TestExecer(t *testing.T) { @@ -645,4 +691,3 @@ func TestTransaction(t *testing.T) { // } // } //} -