diff --git a/db/hotimedb.go b/db/hotimedb.go index 70c2f62..dc976f8 100644 --- a/db/hotimedb.go +++ b/db/hotimedb.go @@ -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 }