提交 484af88f 编写于 作者: martianzhang's avatar martianzhang

connection reuse

上级 16df1e34
......@@ -134,22 +134,18 @@ func (db *Connector) Version() (int, error) {
// MySQL https://dev.mysql.com/doc/refman/8.0/en/comments.html
var versionStr string
var versionSeg []string
for res.Rows.Next() {
if res.Rows.Next() {
err = res.Rows.Scan(&versionStr)
if err != nil {
break
}
versionStr = strings.Split(versionStr, "-")[0]
versionSeg = strings.Split(versionStr, ".")
if len(versionSeg) == 3 {
versionStr = fmt.Sprintf("%s%02s%02s", versionSeg[0], versionSeg[1], versionSeg[2])
version, err = strconv.Atoi(versionStr)
}
break
}
if err := res.Rows.Close(); err != nil {
common.Log.Error(err.Error())
}
versionStr = strings.Split(versionStr, "-")[0]
versionSeg = strings.Split(versionStr, ".")
if len(versionSeg) == 3 {
versionStr = fmt.Sprintf("%s%02s%02s", versionSeg[0], versionSeg[1], versionSeg[2])
version, err = strconv.Atoi(versionStr)
}
return version, err
}
......
......@@ -367,11 +367,12 @@ func (ve VirtualEnv) createDatabase(rEnv *database.Connector, dbName string) err
if ddl == "" {
return fmt.Errorf("dbName: '%s' get create info error", dbName)
}
_, err = ve.Query(ddl)
res, err := ve.Query(ddl)
if err != nil {
common.Log.Warning("createDatabase, Error : %v", err)
return err
}
res.Rows.Close()
// 创建成功,添加映射记录
ve.DBRef[dbName] = dbHash
......@@ -449,12 +450,13 @@ func (ve VirtualEnv) createTable(rEnv *database.Connector, dbName, tbName string
// 改变数据环境
ve.Database = ve.DBRef[dbName]
_, err = ve.Query(ddl)
res, err := ve.Query(ddl)
if err != nil {
// 有可能是用户新建表,因此线上环境查不到
common.Log.Error("createTable, %s Error : %v", tbName, err)
return err
}
res.Rows.Close()
// 泵取数据
if common.Config.Sampling {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册