go version go1.17.5 darwin/amd64
github.com/gogf/gf/v2 v2.0.0-rc.0.20220104132444-99455e328b35
import _ "github.com/sijms/go-ora/v2" 1.然后覆盖oracle驱动 2.连接字符串格式: conn, err := sql.Open("oracle", "oracle://user:pass@host:port/db_name") 3.随便执行一条查询,或者ping() 这时候会发现解析连接字符串的结果是错误的!目测是对”:“的判断处理有问题。
希望能正确解析连接字符串。另外,如下两处的代码,硬编码不统一:
driverMap = map[string]Driver{
"mysql": &DriverMysql{},
"mssql": &DriverMssql{},
"pgsql": &DriverPgsql{},
"oracle": &DriverOracle{}, // 这里使用了oracle
"sqlite": &DriverSqlite{},
}
func (d DriverOracle) Open(config ConfigNode) (db *sql.DB, err error) {
var (
source string
driver = "oci8" //这里使用了oci8
)
if config.Link != "" {
source = config.Link
} else {
source = fmt.Sprintf(
"%s/%s@%s:%s/%s",
config.User, config.Pass, config.Host, config.Port, config.Name,
)
}
intlog.Printf(d.GetCtx(), "Open: %s", source)
if db, err = sql.Open(driver, source); err != nil {
err = gerror.WrapCodef(
gcode.CodeDbOperationError, err,
sql.Open failed for driver "%s" by source "%s"
, driver, source,
)
return nil, err
}
return
}