Compare commits

...

2 Commits

Author SHA1 Message Date
hoteas 253cad35ef 数据库错误操作优化 2022-08-18 13:28:02 +08:00
hoteas 47c8736f34 数据库错误操作优化 2022-08-18 12:33:01 +08:00
+15 -15
View File
@@ -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
}
@@ -667,11 +665,13 @@ func (that *HoTimeDB) Select(table string, qu ...interface{}) []Map {
data := ObjToSlice(qu[intQs])
for i := 0; i < len(data); i++ {
k := data.GetString(i)
if strings.Contains(k, " AS ") {
if strings.Contains(k, " AS ") ||
strings.Contains(k, ".") {
query += " " + k + " "
} else {
query += " `" + k + "` "
}