diff --git a/db/hotimedb.go b/db/hotimedb.go index 91fdab1..1385653 100644 --- a/db/hotimedb.go +++ b/db/hotimedb.go @@ -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...) - } } + that.LastErr.SetError(err) 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...) - } } + that.LastErr.SetError(e) return resl, that.LastErr }