|
|
@ -1,4 +1,5 @@ |
|
|
|
// Copyright 2014 The Gogs Authors. All rights reserved.
|
|
|
|
// Copyright 2014 The Gogs Authors. All rights reserved.
|
|
|
|
|
|
|
|
// Copyright 2018 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
|
|
|
@ -184,6 +185,18 @@ func parsePostgreSQLHostPort(info string) (string, string) { |
|
|
|
return host, port |
|
|
|
return host, port |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func getPostgreSQLConnectionString(DBHost, DBUser, DBPasswd, DBName, DBParam, DBSSLMode string) (connStr string) { |
|
|
|
|
|
|
|
host, port := parsePostgreSQLHostPort(DBHost) |
|
|
|
|
|
|
|
if host[0] == '/' { // looks like a unix socket
|
|
|
|
|
|
|
|
connStr = fmt.Sprintf("postgres://%s:%s@:%s/%s%ssslmode=%s&host=%s", |
|
|
|
|
|
|
|
url.PathEscape(DBUser), url.PathEscape(DBPasswd), port, DBName, DBParam, DBSSLMode, host) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
connStr = fmt.Sprintf("postgres://%s:%s@%s:%s/%s%ssslmode=%s", |
|
|
|
|
|
|
|
url.PathEscape(DBUser), url.PathEscape(DBPasswd), host, port, DBName, DBParam, DBSSLMode) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func parseMSSQLHostPort(info string) (string, string) { |
|
|
|
func parseMSSQLHostPort(info string) (string, string) { |
|
|
|
host, port := "127.0.0.1", "1433" |
|
|
|
host, port := "127.0.0.1", "1433" |
|
|
|
if strings.Contains(info, ":") { |
|
|
|
if strings.Contains(info, ":") { |
|
|
@ -214,14 +227,7 @@ func getEngine() (*xorm.Engine, error) { |
|
|
|
DbCfg.User, DbCfg.Passwd, DbCfg.Host, DbCfg.Name, Param) |
|
|
|
DbCfg.User, DbCfg.Passwd, DbCfg.Host, DbCfg.Name, Param) |
|
|
|
} |
|
|
|
} |
|
|
|
case "postgres": |
|
|
|
case "postgres": |
|
|
|
host, port := parsePostgreSQLHostPort(DbCfg.Host) |
|
|
|
connStr = getPostgreSQLConnectionString(DbCfg.Host, DbCfg.User, DbCfg.Passwd, DbCfg.Name, Param, DbCfg.SSLMode) |
|
|
|
if host[0] == '/' { // looks like a unix socket
|
|
|
|
|
|
|
|
connStr = fmt.Sprintf("postgres://%s:%s@:%s/%s%ssslmode=%s&host=%s", |
|
|
|
|
|
|
|
url.QueryEscape(DbCfg.User), url.QueryEscape(DbCfg.Passwd), port, DbCfg.Name, Param, DbCfg.SSLMode, host) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
connStr = fmt.Sprintf("postgres://%s:%s@%s:%s/%s%ssslmode=%s", |
|
|
|
|
|
|
|
url.QueryEscape(DbCfg.User), url.QueryEscape(DbCfg.Passwd), host, port, DbCfg.Name, Param, DbCfg.SSLMode) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
case "mssql": |
|
|
|
case "mssql": |
|
|
|
host, port := parseMSSQLHostPort(DbCfg.Host) |
|
|
|
host, port := parseMSSQLHostPort(DbCfg.Host) |
|
|
|
connStr = fmt.Sprintf("server=%s; port=%s; database=%s; user id=%s; password=%s;", host, port, DbCfg.Name, DbCfg.User, DbCfg.Passwd) |
|
|
|
connStr = fmt.Sprintf("server=%s; port=%s; database=%s; user id=%s; password=%s;", host, port, DbCfg.Name, DbCfg.User, DbCfg.Passwd) |
|
|
|