This repository has been archived by the owner on Nov 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
sqlx_mssql_test.go
116 lines (89 loc) · 2.11 KB
/
sqlx_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
// +build cgo,mssql
package gdbc_test
import (
"net/url"
"testing"
"fmt"
"log"
"github.com/jmoiron/sqlx"
//"github.com/identitii/gdbc"
"github.com/identitii/gdbc/mssql"
_ "github.com/denisenkom/go-mssqldb"
)
var db = env("MSSQL_DB", "test")
var user = env("MSSQL_USER", "root")
var password = env("MSSQL_PASSWORD", "yourStrong(!)Password")
var host = env("MSSQL_HOST", "localhost")
var jdbcURL = fmt.Sprintf("%s:%s@jdbc:sqlserver://%s:1433;databaseName=%s", user, password, host, db)
func TestPing(t *testing.T) {
mssql.EnableTracing(false)
db := getDb(t, "gdbc-mssql", jdbcURL)
if db == nil {
return
}
defer db.Close()
log.Printf("Ping: %t", db.Ping())
}
func TestMultipleResultSet(t *testing.T) {
mssql.EnableTracing(false)
db := getDb(t, "gdbc-mssql", jdbcURL)
if db == nil {
return
}
defer db.Close()
type result1 struct {
hi int
there int
}
type result2 struct {
how string
are string
you string
}
rows, err := db.Query(`SELECT 1 as hi, 2 as there; SELECT '2' as how, '3' as are, '4' as you;`)
if err != nil {
panic(err)
}
if !rows.Next() {
panic("result set 1 should have a row")
}
var r1 result1
err = rows.Scan(&r1.hi, &r1.there)
if err != nil {
panic(err)
}
log.Printf("resultset1: %#v", r1)
if rows.Next() {
panic("result set 1 should only have one row")
}
if !rows.NextResultSet() {
panic("there should have been two result sets")
}
if !rows.Next() {
panic("result set 2 should have a row")
}
var r2 result2
err = rows.Scan(&r2.how, &r2.are, &r2.you)
if err != nil {
panic(err)
}
log.Printf("resultset2: %#v", r2)
if rows.Next() {
panic("result set 2 should only have one row")
}
}
func BenchmarkMSSQLJDBC(b *testing.B) {
benchmark(b, "gdbc-mssql", jdbcURL, sqlx.QUESTION)
}
func BenchmarkMSSQLGo(b *testing.B) {
query := url.Values{}
query.Add("database", db)
u := &url.URL{
Scheme: "sqlserver",
User: url.UserPassword(user, password),
Host: fmt.Sprintf("%s:%d", host, 1433),
// Path: instance, // if connecting to an instance instead of a port
RawQuery: query.Encode(),
}
benchmark(b, "sqlserver", u.String(), sqlx.DOLLAR)
}