数据库操作优化

This commit is contained in:
hoteas 2022-08-17 16:35:52 +08:00
parent 7a8b86ed12
commit 60f222b011

View File

@ -565,13 +565,15 @@ func (that *HoTimeDB) Query(query string, args ...interface{}) []Map {
that.LastErr.SetError(err) that.LastErr.SetError(err)
if err != nil { if err != nil {
if err = db.Ping(); err != nil { if err = db.Ping(); err == nil {
that.LastErr.SetError(err)
_ = that.InitDb()
if that.LastErr.GetError() != nil {
return nil
}
return that.Query(query, args...) return that.Query(query, args...)
} else {
err = that.InitDb()
that.LastErr.SetError(err)
if err == nil {
return that.Query(query, args...)
}
} }
return nil return nil
} }
@ -607,13 +609,14 @@ func (that *HoTimeDB) Exec(query string, args ...interface{}) (sql.Result, *Erro
//判断是否连接断开了 //判断是否连接断开了
if e != nil { if e != nil {
if e = that.DB.Ping(); e != nil { if e = that.DB.Ping(); e == nil {
that.LastErr.SetError(e)
_ = that.InitDb()
if that.LastErr.GetError() != nil {
return resl, that.LastErr
}
return that.Exec(query, args...) 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 return resl, that.LastErr
} }