mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-13 07:10:25 +08:00
修复访问日志表可能无法自动创建的Bug
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/go-sql-driver/mysql"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
||||
@@ -38,3 +41,23 @@ func NewQuery(tx *dbs.Tx, dao dbs.DAOWrapper, adminId int64, userId int64) *dbs.
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// CheckSQLErrCode 检查数据库错误代码
|
||||
func CheckSQLErrCode(err error, code uint16) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
// 快速判断错误方法
|
||||
mysqlErr, ok := err.(*mysql.MySQLError)
|
||||
if ok && mysqlErr.Number == code { // Error 1050: Table 'xxx' already exists
|
||||
return true
|
||||
}
|
||||
|
||||
// 防止二次包装过程中错误丢失的保底错误判断方法
|
||||
if strings.Contains(err.Error(), "Error "+types.String(code)) {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user