Skip to content

Commit

Permalink
connection reuse
Browse files Browse the repository at this point in the history
  • Loading branch information
martianzhang committed Dec 21, 2018
1 parent 16df1e3 commit 484af88
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
18 changes: 7 additions & 11 deletions database/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
6 changes: 4 additions & 2 deletions env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 484af88

Please sign in to comment.