数据库错误操作优化

This commit is contained in:
hoteas 2022-08-18 12:33:01 +08:00
parent dcce8ace9e
commit 47c8736f34

View File

@ -566,18 +566,18 @@ func (that *HoTimeDB) Query(query string, args ...interface{}) []Map {
resl, err = db.Query(query, args...)
}
if err != nil && that.LastErr.GetError() != nil &&
that.LastErr.GetError().Error() == err.Error() {
return nil
}
that.LastErr.SetError(err)
if err != nil {
if err = db.Ping(); err == nil {
return that.Query(query, args...)
} else {
err = that.InitDb()
}
that.LastErr.SetError(err)
if err == nil {
return that.Query(query, args...)
}
}
return nil
}
@ -607,20 +607,18 @@ func (that *HoTimeDB) Exec(query string, args ...interface{}) (sql.Result, *Erro
resl, e = that.DB.Exec(query, args...)
}
if e != nil && that.LastErr.GetError() != nil &&
that.LastErr.GetError().Error() == e.Error() {
return resl, that.LastErr
}
that.LastErr.SetError(e)
//判断是否连接断开了
if e != nil {
if e = that.DB.Ping(); e == nil {
return that.Exec(query, args...)
} else {
e = that.InitDb()
}
that.LastErr.SetError(e)
if e == nil {
return that.Exec(query, args...)
}
}
return resl, that.LastErr
}