summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/denisenkom/go-mssqldb/conn_str.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/denisenkom/go-mssqldb/conn_str.go')
-rw-r--r--vendor/github.com/denisenkom/go-mssqldb/conn_str.go21
1 files changed, 19 insertions, 2 deletions
diff --git a/vendor/github.com/denisenkom/go-mssqldb/conn_str.go b/vendor/github.com/denisenkom/go-mssqldb/conn_str.go
index 412a8716ad..4ff54b8955 100644
--- a/vendor/github.com/denisenkom/go-mssqldb/conn_str.go
+++ b/vendor/github.com/denisenkom/go-mssqldb/conn_str.go
@@ -11,6 +11,8 @@ import (
"unicode"
)
+const defaultServerPort = 1433
+
type connectParams struct {
logFlags uint64
port uint64
@@ -78,7 +80,7 @@ func parseConnectParams(dsn string) (connectParams, error) {
p.user = params["user id"]
p.password = params["password"]
- p.port = 1433
+ p.port = 0
strport, ok := params["port"]
if ok {
var err error
@@ -183,7 +185,7 @@ func parseConnectParams(dsn string) (connectParams, error) {
if ok {
p.serverSPN = serverSPN
} else {
- p.serverSPN = fmt.Sprintf("MSSQLSvc/%s:%d", p.host, p.port)
+ p.serverSPN = generateSpn(p.host, resolveServerPort(p.port))
}
workstation, ok := params["workstation id"]
@@ -205,6 +207,9 @@ func parseConnectParams(dsn string) (connectParams, error) {
appintent, ok := params["applicationintent"]
if ok {
if appintent == "ReadOnly" {
+ if p.database == "" {
+ return p, fmt.Errorf("Database must be specified when ApplicationIntent is ReadOnly")
+ }
p.typeFlags |= fReadOnlyIntent
}
}
@@ -451,3 +456,15 @@ func splitConnectionStringOdbc(dsn string) (map[string]string, error) {
func normalizeOdbcKey(s string) string {
return strings.ToLower(strings.TrimRightFunc(s, unicode.IsSpace))
}
+
+func resolveServerPort(port uint64) uint64 {
+ if port == 0 {
+ return defaultServerPort
+ }
+
+ return port
+}
+
+func generateSpn(host string, port uint64) string {
+ return fmt.Sprintf("MSSQLSvc/%s:%d", host, port)
+}