forked from alexbrainman/odbc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
access_test.go
71 lines (61 loc) · 1.45 KB
/
access_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
70
71
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package odbc
import (
"database/sql"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
ole "github.com/go-ole/go-ole"
"github.com/go-ole/go-ole/oleutil"
)
func TestAccessMemo(t *testing.T) {
tmpdir, err := ioutil.TempDir("", "TestAccessMemo")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tmpdir)
dbfilename := filepath.Join(tmpdir, "db.mdb")
createAccessDB(t, dbfilename)
db, err := sql.Open("odbc", fmt.Sprintf("DRIVER={Microsoft Access Driver (*.mdb)};DBQ=%s;", dbfilename))
if err != nil {
t.Fatal(err)
}
defer db.Close()
err = db.Ping()
if err != nil {
t.Fatal(err)
}
_, err = db.Exec("create table mytable (m memo)")
if err != nil {
t.Fatal(err)
}
for s := ""; len(s) < 1000; s += "0123456789" {
_, err = db.Exec("insert into mytable (m) values (?)", s)
if err != nil {
t.Fatal(err)
}
}
}
func createAccessDB(t *testing.T, dbfilename string) {
err := ole.CoInitialize(0)
if err != nil {
t.Fatal(err)
}
defer ole.CoUninitialize()
unk, err := oleutil.CreateObject("adox.catalog")
if err != nil {
t.Fatal(err)
}
cat, err := unk.QueryInterface(ole.IID_IDispatch)
if err != nil {
t.Fatal(err)
}
_, err = oleutil.CallMethod(cat, "create", fmt.Sprintf("provider=microsoft.jet.oledb.4.0;data source=%s;", dbfilename))
if err != nil {
t.Fatal(err)
}
}