提交 531e16e4 编写于 作者: Y Your Name

修复部分sql stmt操作没有关闭的问题

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