-
Notifications
You must be signed in to change notification settings - Fork 24
/
sqlite3_test.go
55 lines (48 loc) · 1.42 KB
/
sqlite3_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package sqlite3
import (
"os"
"testing"
)
func TestSession(t *testing.T) {
Session("test.db", func(db *Database) {
FOO.Drop(db)
FOO.Create(db)
db.runQuery(t, "INSERT INTO foo values (1, 'this is a test')")
db.runQuery(t, "INSERT INTO foo values (?, ?)", 2, "holy moly")
db.stepThroughRows(t, FOO)
})
}
func TestTransientSession(t *testing.T) {
TransientSession(func(db *Database) {
FOO.Drop(db)
FOO.Create(db)
db.runQuery(t, "INSERT INTO foo values (1, 'this is a test')")
db.runQuery(t, "INSERT INTO foo values (?, ?)", 2, "holy moly")
db.stepThroughRows(t, FOO)
})
}
func TestOpen(t *testing.T) {
// Test for issue #13
// Create a new database
filename := "new.db"
os.Remove(filename)
db, e := Open(filename)
if e != nil {
t.Fatalf("Creating %v failed with error: %v", db, e)
}
if _, e = db.Execute( "CREATE TABLE foo (id INTEGER PRIMARY KEY ASC, name VARCHAR(10));" ); e != nil {
t.Fatalf("Create Table foo failed with error: %v", e)
}
db.Close()
if _, e := os.Stat(filename); e != nil {
t.Fatalf("Checking %v existence failed with error: %v", filename, e)
}
// If new.db already exists and is a valid SQLite3 database this should succeed
if db, e = Open(filename); e != nil {
t.Fatalf("Reopening %v failed with error: %v", db, e)
}
defer db.Close()
if _, e = db.Execute( "INSERT INTO foo (id,name) VALUES ('1', 'John');" ); e != nil {
t.Fatalf("Insert into foo failed with error: %v", e)
}
}