diff options
author | 6543 <6543@obermui.de> | 2019-12-28 18:14:38 +0100 |
---|---|---|
committer | zeripath <art27@cantab.net> | 2019-12-28 17:14:38 +0000 |
commit | 599c0ee75ffea3ad5f0049ac7d275081370eb149 (patch) | |
tree | 302526970cb789ef9f984c9314daba7e3f152e04 /vendor/github.com | |
parent | ed67bbe4442cc26fc64102c04d6fbea348f52e7c (diff) | |
download | gitea-599c0ee75ffea3ad5f0049ac7d275081370eb149.tar.gz gitea-599c0ee75ffea3ad5f0049ac7d275081370eb149.zip |
go-mssqldb UPDATE (#9522)
Diffstat (limited to 'vendor/github.com')
-rw-r--r-- | vendor/github.com/denisenkom/go-mssqldb/README.md | 2 | ||||
-rw-r--r-- | vendor/github.com/denisenkom/go-mssqldb/conn_str.go | 21 | ||||
-rw-r--r-- | vendor/github.com/denisenkom/go-mssqldb/mssql.go | 2 | ||||
-rw-r--r-- | vendor/github.com/denisenkom/go-mssqldb/tds.go | 11 |
4 files changed, 28 insertions, 8 deletions
diff --git a/vendor/github.com/denisenkom/go-mssqldb/README.md b/vendor/github.com/denisenkom/go-mssqldb/README.md index 669b0fe991..b655176bb6 100644 --- a/vendor/github.com/denisenkom/go-mssqldb/README.md +++ b/vendor/github.com/denisenkom/go-mssqldb/README.md @@ -56,7 +56,7 @@ Other supported formats are listed below. * `hostNameInCertificate` - Specifies the Common Name (CN) in the server certificate. Default value is the server host. * `ServerSPN` - The kerberos SPN (Service Principal Name) for the server. Default is MSSQLSvc/host:port. * `Workstation ID` - The workstation name (default is the host name) -* `ApplicationIntent` - Can be given the value `ReadOnly` to initiate a read-only connection to an Availability Group listener. +* `ApplicationIntent` - Can be given the value `ReadOnly` to initiate a read-only connection to an Availability Group listener. The `database` must be specified when connecting with `Application Intent` set to `ReadOnly`. ### The connection string can be specified in one of three formats: 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) +} diff --git a/vendor/github.com/denisenkom/go-mssqldb/mssql.go b/vendor/github.com/denisenkom/go-mssqldb/mssql.go index e37109cd4a..5d81516919 100644 --- a/vendor/github.com/denisenkom/go-mssqldb/mssql.go +++ b/vendor/github.com/denisenkom/go-mssqldb/mssql.go @@ -613,11 +613,13 @@ loop: break loop case doneStruct: if token.isError() { + cancel() return nil, s.c.checkBadConn(token.getError()) } case ReturnStatus: s.c.setReturnStatus(token) case error: + cancel() return nil, s.c.checkBadConn(token) } } diff --git a/vendor/github.com/denisenkom/go-mssqldb/tds.go b/vendor/github.com/denisenkom/go-mssqldb/tds.go index 5a9f53b705..9419836448 100644 --- a/vendor/github.com/denisenkom/go-mssqldb/tds.go +++ b/vendor/github.com/denisenkom/go-mssqldb/tds.go @@ -666,14 +666,14 @@ func dialConnection(ctx context.Context, c *Connector, p connectParams) (conn ne } if len(ips) == 1 { d := c.getDialer(&p) - addr := net.JoinHostPort(ips[0].String(), strconv.Itoa(int(p.port))) + addr := net.JoinHostPort(ips[0].String(), strconv.Itoa(int(resolveServerPort(p.port)))) conn, err = d.DialContext(ctx, "tcp", addr) } else { //Try Dials in parallel to avoid waiting for timeouts. connChan := make(chan net.Conn, len(ips)) errChan := make(chan error, len(ips)) - portStr := strconv.Itoa(int(p.port)) + portStr := strconv.Itoa(int(resolveServerPort(p.port))) for _, ip := range ips { go func(ip net.IP) { d := c.getDialer(&p) @@ -711,7 +711,7 @@ func dialConnection(ctx context.Context, c *Connector, p connectParams) (conn ne // Can't do the usual err != nil check, as it is possible to have gotten an error before a successful connection if conn == nil { f := "Unable to open tcp connection with host '%v:%v': %v" - return nil, fmt.Errorf(f, p.host, p.port, err.Error()) + return nil, fmt.Errorf(f, p.host, resolveServerPort(p.port), err.Error()) } return conn, err } @@ -724,7 +724,7 @@ func connect(ctx context.Context, c *Connector, log optionalLogger, p connectPar defer cancel() } // if instance is specified use instance resolution service - if p.instance != "" { + if p.instance != "" && p.port == 0 { p.instance = strings.ToUpper(p.instance) d := c.getDialer(&p) instances, err := getInstances(dialCtx, d, p.host) @@ -737,11 +737,12 @@ func connect(ctx context.Context, c *Connector, log optionalLogger, p connectPar f := "No instance matching '%v' returned from host '%v'" return nil, fmt.Errorf(f, p.instance, p.host) } - p.port, err = strconv.ParseUint(strport, 0, 16) + port, err := strconv.ParseUint(strport, 0, 16) if err != nil { f := "Invalid tcp port returned from Sql Server Browser '%v': %v" return nil, fmt.Errorf(f, strport, err.Error()) } + p.port = port } initiate_connection: |