This repository has been archived by the owner on Jul 11, 2019. It is now read-only.
forked from go-xorm/xorm
-
Notifications
You must be signed in to change notification settings - Fork 7
/
mssql_test.go
142 lines (119 loc) · 3.07 KB
/
mssql_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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package xorm
//
// +build windows
import (
"database/sql"
"testing"
_ "github.com/lunny/godbc"
)
const mssqlConnStr = "driver={SQL Server};Server=192.168.20.135;Database=xorm_test; uid=sa; pwd=1234;"
func newMssqlEngine() (*Engine, error) {
return NewEngine("odbc", mssqlConnStr)
}
func TestMssql(t *testing.T) {
engine, err := newMssqlEngine()
defer engine.Close()
if err != nil {
t.Error(err)
return
}
engine.ShowSQL = showTestSql
engine.ShowErr = showTestSql
engine.ShowWarn = showTestSql
engine.ShowDebug = showTestSql
testAll(engine, t)
testAll2(engine, t)
}
func TestMssqlWithCache(t *testing.T) {
engine, err := newMssqlEngine()
defer engine.Close()
if err != nil {
t.Error(err)
return
}
engine.SetDefaultCacher(NewLRUCacher(NewMemoryStore(), 1000))
engine.ShowSQL = showTestSql
engine.ShowErr = showTestSql
engine.ShowWarn = showTestSql
engine.ShowDebug = showTestSql
testAll(engine, t)
testAll2(engine, t)
}
func newMssqlDriverDB() (*sql.DB, error) {
return sql.Open("odbc", mssqlConnStr)
}
const (
createTableMssql = `IF NOT EXISTS (SELECT [name] FROM sys.tables WHERE [name] = 'big_struct' ) CREATE TABLE
"big_struct" ("id" BIGINT PRIMARY KEY IDENTITY NOT NULL, "name" VARCHAR(255) NULL, "title" VARCHAR(255) NULL,
"age" VARCHAR(255) NULL, "alias" VARCHAR(255) NULL, "nick_name" VARCHAR(255) NULL);
`
dropTableMssql = "IF EXISTS (SELECT * FROM sysobjects WHERE id = object_id(N'big_struct') and OBJECTPROPERTY(id, N'IsUserTable') = 1) DROP TABLE IF EXISTS `big_struct`;"
)
func BenchmarkMssqlDriverInsert(t *testing.B) {
doBenchDriver(newMssqlDriverDB, createTableMssql, dropTableMssql,
doBenchDriverInsert, t)
}
func BenchmarkMssqlDriverFind(t *testing.B) {
doBenchDriver(newMssqlDriverDB, createTableMssql, dropTableMssql,
doBenchDriverFind, t)
}
func BenchmarkMssqlNoCacheInsert(t *testing.B) {
engine, err := newMssqlEngine()
defer engine.Close()
if err != nil {
t.Error(err)
return
}
//engine.ShowSQL = true
doBenchInsert(engine, t)
}
func BenchmarkMssqlNoCacheFind(t *testing.B) {
engine, err := newMssqlEngine()
defer engine.Close()
if err != nil {
t.Error(err)
return
}
//engine.ShowSQL = true
doBenchFind(engine, t)
}
func BenchmarkMssqlNoCacheFindPtr(t *testing.B) {
engine, err := newMssqlEngine()
defer engine.Close()
if err != nil {
t.Error(err)
return
}
//engine.ShowSQL = true
doBenchFindPtr(engine, t)
}
func BenchmarkMssqlCacheInsert(t *testing.B) {
engine, err := newMssqlEngine()
defer engine.Close()
if err != nil {
t.Error(err)
return
}
engine.SetDefaultCacher(NewLRUCacher(NewMemoryStore(), 1000))
doBenchInsert(engine, t)
}
func BenchmarkMssqlCacheFind(t *testing.B) {
engine, err := newMssqlEngine()
defer engine.Close()
if err != nil {
t.Error(err)
return
}
engine.SetDefaultCacher(NewLRUCacher(NewMemoryStore(), 1000))
doBenchFind(engine, t)
}
func BenchmarkMssqlCacheFindPtr(t *testing.B) {
engine, err := newMssqlEngine()
defer engine.Close()
if err != nil {
t.Error(err)
return
}
engine.SetDefaultCacher(NewLRUCacher(NewMemoryStore(), 1000))
doBenchFindPtr(engine, t)
}