- avoid log 1062(duplicate key) mysql error
This commit is contained in:
@@ -5,7 +5,9 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
|
"git.rosy.net.cn/jx-callback/globals"
|
||||||
"github.com/astaxie/beego/orm"
|
"github.com/astaxie/beego/orm"
|
||||||
|
"github.com/go-sql-driver/mysql"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -130,10 +132,14 @@ func CreateEntity(db *DaoDB, item interface{}) (err error) {
|
|||||||
if db == nil {
|
if db == nil {
|
||||||
db = GetDB()
|
db = GetDB()
|
||||||
}
|
}
|
||||||
err = utils.CallFuncLogError(func() error {
|
if _, err = db.db.Insert(item); err != nil {
|
||||||
_, err = db.db.Insert(item) // todo 这里需要将ID赋值么?
|
if mysqlErr, ok := err.(*mysql.MySQLError); ok {
|
||||||
return err
|
if mysqlErr.Number == 1062 {
|
||||||
}, reflect.TypeOf(item).Name())
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
globals.SugarLogger.Warnf("CreateEntity failed with error:%v", err)
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user