From 60f222b0111cf147019708415ad1a2f9f27a7b43 Mon Sep 17 00:00:00 2001 From: hoteas Date: Wed, 17 Aug 2022 16:35:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/hotimedb.go | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) 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 }