未验证 提交 be26ce34 编写于 作者: E Eolink 提交者: GitHub

Merge pull request #37 from Dot-Liu/master

修复部分stmt操作没有关闭的问题
......@@ -58,7 +58,6 @@ func InitTable() error {
if err != nil {
Tx.Rollback()
log.Error("InitTable error:",err,"\t sql:",sql)
panic(err)
return err
}
}
......
......@@ -356,6 +356,7 @@ func BatchEditAPIBalance(apiIDList []string, balance string) (string, error) {
if err != nil {
return "[ERROR]Fail to Prepare SQL!", err
}
defer stmt.Close()
_, err = stmt.Exec(now, now, balance)
if err != nil {
return "[ERROR]Fail to excute SQL statement!", err
......@@ -375,6 +376,7 @@ func BatchEditAPIGroup(apiIDList []string, groupID int) (string, error) {
if err != nil {
return "[ERROR]Fail to Prepare SQL!", err
}
defer stmt.Close()
_, err = stmt.Exec(now, now, groupID)
if err != nil {
return "[ERROR]Fail to excute SQL statement!", err
......
......@@ -20,6 +20,9 @@ func AddAPIToStrategy(apiList []string, strategyID string) (bool, string, error)
stmt1, _ := Tx.Prepare(sql1)
stmt2, _ := Tx.Prepare(sql2)
stmt3, _ := Tx.Prepare(sql3)
defer stmt1.Close()
defer stmt2.Close()
defer stmt3.Close()
for _, apiID := range apiList {
id, err := strconv.Atoi(apiID)
......@@ -64,7 +67,7 @@ func SetAPITargetOfStrategy(apiID int, strategyID string, target string) (bool,
if err != nil {
return false, err.Error(), err
}
defer stmt.Close()
_, e := stmt.Exec(target, apiID, strategyID)
if e != nil {
......@@ -93,7 +96,7 @@ func BatchSetAPITargetOfStrategy(apiIds []int, strategyID string, target string)
if err != nil {
return false, err.Error(), err
}
defer stmt.Close()
_, e := stmt.Exec(s...)
if e != nil {
......
......@@ -14,6 +14,7 @@ func Get(name string) (*entity.LogConfig, error) {
if e != nil {
return nil, e
}
defer stmt.Close()
ent := &entity.LogConfig{}
err := stmt.QueryRow(name).Scan(
&ent.Name,
......@@ -37,6 +38,7 @@ func Set(ent *entity.LogConfig) error {
if e != nil {
return e
}
defer stmt.Close()
_, err := stmt.Exec(
ent.Name,
ent.Enable,
......
......@@ -115,6 +115,7 @@ func Delete(name string) (string, error) {
if err != nil {
return "[ERROR]Illegal SQL statement!", err
}
defer stmt.Close()
_, err = stmt.Exec(name)
if err != nil {
return "[ERROR]DELETE fail", err
......@@ -132,10 +133,12 @@ func BatchDelete(balanceNames []string) (string, error) {
if err != nil {
return "[ERROR]Illegal SQL statement!", err
}
defer stmt.Close()
stmt2, err := db.Prepare(sql2)
if err != nil {
return "[ERROR]Illegal SQL statement!", err
}
defer stmt2.Close()
for _, balanceName := range balanceNames {
stmt.Exec(balanceName)
stmt2.Exec(balanceName)
......
......@@ -17,7 +17,7 @@ func Add(name, driver, desc, config, clusterConfig string, isDefault, healthChec
if e != nil {
return e
}
defer stmt.Close()
_, err := stmt.Exec(name, driver, isDefault, desc, config, clusterConfig, healthCheck, healthCheckPath, healthCheckPeriod, healthCheckCode, healthCheckTimeOut, now, now)
return err
}
......@@ -38,6 +38,7 @@ func EditGatewayBaseConfig(successCode string, nodeUpdatePeriod, monitorUpdatePe
if err != nil {
return false, "[ERROR]Illegal SQL Statement!", err
}
defer stmt.Close()
_, err = stmt.Exec(successCode, nodeUpdatePeriod, monitorUpdatePeriod, monitorTimeout)
if err != nil {
return false, "[ERROR]Fail to excute SQL Statement!", err
......@@ -60,6 +61,7 @@ func EditGatewayAlarmConfig(apiAlertInfo, sender, senderPassword, smtpAddress st
if err != nil {
return false, "[ERROR]Illegal SQL Statement!", err
}
defer stmt.Close()
_, err = stmt.Exec(apiAlertInfo, alertStatus, sender, senderPassword, smtpAddress, smtpPort, smtpProtocol)
if err != nil {
return false, "[ERROR]Fail to excute SQL Statement!", err
......
......@@ -203,11 +203,13 @@ func UpdateAllNodeClusterID(clusterID int) {
_, err := Tx.Exec(sql, clusterID)
if err != nil {
Tx.Rollback()
return
}
sql = "UPDATE goku_node_group SET clusterID = ?;"
_, err = Tx.Exec(sql, clusterID)
if err != nil {
Tx.Rollback()
return
}
Tx.Commit()
}
......@@ -54,6 +54,7 @@ func DeleteProject(projectID int) (bool, string, error) {
sql := "SELECT groupID FROM goku_gateway_api_group WHERE projectID = ?;"
rows, err := Tx.Query(sql, projectID)
if err != nil {
Tx.Rollback()
return false, "", err
}
//延时关闭Rows
......
......@@ -30,7 +30,7 @@ func AddStrategy(strategyName string, groupID int) (bool, string, error) {
return false, "[ERROR]Empty strategy id !", nil
}
stmt, err := db.Prepare(`INSERT INTO goku_gateway_strategy (strategyID,strategyName,updateTime,createTime,groupID) VALUES (?,?,?,?,?);`)
defer stmt.Close()
if err != nil {
return false, "[ERROR]Illegal SQL statement!", err
}
......
......@@ -27,7 +27,6 @@ func AddPluginToStrategy(pluginName, config, strategyID string) (bool, interface
result, err := Tx.Exec("INSERT INTO goku_conn_plugin_strategy (pluginName,pluginConfig,strategyID,createTime,updateTime,pluginStatus) VALUES (?,?,?,?,?,?);", pluginName, config, strategyID, now, now, 1)
if err != nil {
Tx.Rollback()
panic(err)
return false, "[ERROR]Fail to insert data", errors.New("[ERROR]Fail to insert data")
}
connID, err := result.LastInsertId()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册