From 47c8736f344009e4b63566948f45bcc9fcd73cfe Mon Sep 17 00:00:00 2001 From: hoteas Date: Thu, 18 Aug 2022 12:33:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/hotimedb.go | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) 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 }