Compare commits

..

2 Commits

Author SHA1 Message Date
hoteas dcce8ace9e 数据库事务操作优化 2022-08-18 11:36:23 +08:00
hoteas 125ccc5c3b 数据库操作优化 2022-08-17 17:10:12 +08:00
+7 -3
View File
@@ -271,7 +271,11 @@ func (that *HoTimeDB) GetType() string {
// Action 事务,如果action返回true则执行成功;false则回滚
func (that *HoTimeDB) Action(action func(db HoTimeDB) (isSuccess bool)) (isSuccess bool) {
db := HoTimeDB{DB: that.DB, HoTimeCache: that.HoTimeCache, Prefix: that.Prefix}
db := HoTimeDB{that.DB, that.ContextBase, that.DBName,
that.HoTimeCache, that.Log, that.Type,
that.Prefix, that.LastQuery, that.LastData,
that.ConnectFunc, that.LastErr, that.limit, that.Tx,
that.SlaveDB, that.Mode}
tx, err := db.Begin()
if err != nil {
that.LastErr.SetError(err)
@@ -534,7 +538,7 @@ func (that *HoTimeDB) md5(query string, args ...interface{}) string {
func (that *HoTimeDB) Query(query string, args ...interface{}) []Map {
defer func() {
if that.Mode == 2 {
if that.Mode != 0 {
that.Log.Info("SQL:"+that.LastQuery, " DATA:", that.LastData, " ERROR:", that.LastErr.GetError())
}
}()
@@ -582,7 +586,7 @@ func (that *HoTimeDB) Query(query string, args ...interface{}) []Map {
func (that *HoTimeDB) Exec(query string, args ...interface{}) (sql.Result, *Error) {
defer func() {
if that.Mode == 2 {
if that.Mode != 0 {
that.Log.Info("SQL: "+that.LastQuery, " DATA: ", that.LastData, " ERROR: ", that.LastErr.GetError())
}
}()