|
|
@ -13,6 +13,7 @@ import ( |
|
|
|
"path" |
|
|
|
"path" |
|
|
|
"strings" |
|
|
|
"strings" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_ "github.com/denisenkom/go-mssqldb" |
|
|
|
_ "github.com/go-sql-driver/mysql" |
|
|
|
_ "github.com/go-sql-driver/mysql" |
|
|
|
"github.com/go-xorm/core" |
|
|
|
"github.com/go-xorm/core" |
|
|
|
"github.com/go-xorm/xorm" |
|
|
|
"github.com/go-xorm/xorm" |
|
|
@ -85,6 +86,8 @@ func LoadConfigs() { |
|
|
|
setting.UseMySQL = true |
|
|
|
setting.UseMySQL = true |
|
|
|
case "postgres": |
|
|
|
case "postgres": |
|
|
|
setting.UsePostgreSQL = true |
|
|
|
setting.UsePostgreSQL = true |
|
|
|
|
|
|
|
case "mssql": |
|
|
|
|
|
|
|
setting.UseMSSQL = true |
|
|
|
case "tidb": |
|
|
|
case "tidb": |
|
|
|
setting.UseTiDB = true |
|
|
|
setting.UseTiDB = true |
|
|
|
} |
|
|
|
} |
|
|
@ -113,6 +116,20 @@ func parsePostgreSQLHostPort(info string) (string, string) { |
|
|
|
return host, port |
|
|
|
return host, port |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func parseMSSQLHostPort(info string) (string, string) { |
|
|
|
|
|
|
|
host, port := "127.0.0.1", "1433" |
|
|
|
|
|
|
|
if strings.Contains(info, ":") { |
|
|
|
|
|
|
|
host = strings.Split(info, ":")[0] |
|
|
|
|
|
|
|
port = strings.Split(info, ":")[1] |
|
|
|
|
|
|
|
} else if strings.Contains(info, ",") { |
|
|
|
|
|
|
|
host = strings.Split(info, ",")[0] |
|
|
|
|
|
|
|
port = strings.TrimSpace(strings.Split(info, ",")[1]) |
|
|
|
|
|
|
|
} else if len(info) > 0 { |
|
|
|
|
|
|
|
host = info |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return host, port |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func getEngine() (*xorm.Engine, error) { |
|
|
|
func getEngine() (*xorm.Engine, error) { |
|
|
|
connStr := "" |
|
|
|
connStr := "" |
|
|
|
var Param string = "?" |
|
|
|
var Param string = "?" |
|
|
@ -137,6 +154,9 @@ func getEngine() (*xorm.Engine, error) { |
|
|
|
connStr = fmt.Sprintf("postgres://%s:%s@%s:%s/%s%ssslmode=%s", |
|
|
|
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) |
|
|
|
url.QueryEscape(DbCfg.User), url.QueryEscape(DbCfg.Passwd), host, port, DbCfg.Name, Param, DbCfg.SSLMode) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
case "mssql": |
|
|
|
|
|
|
|
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) |
|
|
|
case "sqlite3": |
|
|
|
case "sqlite3": |
|
|
|
if !EnableSQLite3 { |
|
|
|
if !EnableSQLite3 { |
|
|
|
return nil, errors.New("This binary version does not build support for SQLite3.") |
|
|
|
return nil, errors.New("This binary version does not build support for SQLite3.") |
|
|
|