forked from iamacarpet/go-sqlite3-win64
-
Notifications
You must be signed in to change notification settings - Fork 1
/
sqlite3_test.go
69 lines (63 loc) · 1.26 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// +build windows
package sqlite3
import (
"database/sql"
"log"
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
)
func init() {
DLLPath = filepath.Join(os.Getenv(`GOPATH`), `src`, `github.com/admpub/go-sqlite3-win64`)
}
func TestOpen(t *testing.T) {
f, err := os.Create(`./test.db`)
if err != nil {
t.Fatal(err)
}
f.Close()
db, err := sql.Open(`sqlite3`, `./test.db`)
if err != nil {
t.Fatal(err)
}
r, err := db.Exec(`CREATE TABLE test (
id integer PRIMARY KEY NOT NULL,
name varchar(30)
)`)
if err != nil {
t.Fatal(err)
}
log.Println(`sqlite3_threadsafe():`, sqlite3_threadsafe())
_ = r
r, err = db.Exec(`INSERT INTO test(name) VALUES ('first') `)
if err != nil {
t.Fatal(err)
}
rowid, err := r.LastInsertId()
if err != nil {
t.Fatal(err)
}
affected, err := r.RowsAffected()
if err != nil {
t.Fatal(err)
}
assert.Equal(t, int64(1), rowid)
assert.Equal(t, int64(1), affected)
r, err = db.Exec(`INSERT INTO test(name) VALUES ('second') `)
if err != nil {
t.Fatal(err)
}
rowid, err = r.LastInsertId()
if err != nil {
t.Fatal(err)
}
affected, err = r.RowsAffected()
if err != nil {
t.Fatal(err)
}
assert.Equal(t, int64(2), rowid)
assert.Equal(t, int64(1), affected)
db.Close()
os.Remove(`./test.db`)
}