Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 432d59d483 | |||
| 60f222b011 |
+16
-14
@@ -13,7 +13,6 @@ import (
|
||||
"reflect"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type HoTimeDB struct {
|
||||
@@ -315,7 +314,7 @@ func (that *HoTimeDB) InitDb(err ...*Error) *Error {
|
||||
e := that.SlaveDB.Ping()
|
||||
that.LastErr.SetError(e)
|
||||
}
|
||||
that.DB.SetConnMaxLifetime(time.Second)
|
||||
//that.DB.SetConnMaxLifetime(time.Second)
|
||||
return that.LastErr
|
||||
}
|
||||
|
||||
@@ -565,13 +564,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 +608,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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user