forked from golang/hotime
数据库操作优化
This commit is contained in:
parent
7a8b86ed12
commit
60f222b011
@ -565,13 +565,15 @@ func (that *HoTimeDB) Query(query string, args ...interface{}) []Map {
|
||||
|
||||
that.LastErr.SetError(err)
|
||||
if err != nil {
|
||||
if err = db.Ping(); err != nil {
|
||||
that.LastErr.SetError(err)
|
||||
_ = that.InitDb()
|
||||
if that.LastErr.GetError() != nil {
|
||||
return 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,13 +609,14 @@ func (that *HoTimeDB) Exec(query string, args ...interface{}) (sql.Result, *Erro
|
||||
//判断是否连接断开了
|
||||
if e != nil {
|
||||
|
||||
if e = that.DB.Ping(); e != nil {
|
||||
that.LastErr.SetError(e)
|
||||
_ = that.InitDb()
|
||||
if that.LastErr.GetError() != nil {
|
||||
return resl, that.LastErr
|
||||
}
|
||||
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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user