-
Notifications
You must be signed in to change notification settings - Fork 0
/
binding_test.go
60 lines (52 loc) · 1.06 KB
/
binding_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
package sqlite3
import (
"fmt"
"os"
"runtime"
"testing"
)
func getLibrary() string {
switch runtime.GOOS {
case "darwin":
return "./deps/darwin/libsqlite-abi.dylib"
case "linux":
return "./deps/linux/libsqlite-abi.so"
case "windows":
return "./deps/windows/sqlite-abi.dll"
default:
panic(fmt.Errorf("GOOS=%s is not supported", runtime.GOOS))
}
}
func TestNewCSQLite(t *testing.T) {
sqlite, err := NewCSQLite(getLibrary())
if err != nil {
t.Error(err)
return
}
defer sqlite.Close()
ctx := sqlite.SQLiteInit("./tmp.db")
errCode := sqlite.SQLiteErrCode(ctx)
t.Log(errCode)
errMsg := sqlite.SQLiteErrMsg(ctx)
t.Log(errMsg)
res := sqlite.SQLiteExec(ctx, `
CREATE TABLE Users (
id INT PRIMARY KEY,
name VARCHAR(100),
age INT,
email VARCHAR(100),
created_at DATETIME
);
`)
errCode = sqlite.SQLiteErrCode(ctx)
t.Log(errCode)
errMsg = sqlite.SQLiteErrMsg(ctx)
t.Log(errMsg)
t.Log(res)
sqlite.SQLiteClose(ctx)
err = os.Remove("./tmp.db")
if err != nil {
t.Error(err)
return
}
}