sqlstore: add support for checking if error is constraint validation error

This commit is contained in:
Marcus Efraimsson
2018-09-27 13:38:22 +02:00
parent c5278af6c4
commit d093244282
9 changed files with 1156 additions and 19 deletions
@@ -5,6 +5,8 @@ import (
"strconv"
"strings"
"github.com/VividCortex/mysqlerr"
"github.com/go-sql-driver/mysql"
"github.com/go-xorm/xorm"
)
@@ -125,3 +127,13 @@ func (db *Mysql) CleanDB() error {
return nil
}
func (db *Mysql) IsUniqueConstraintViolation(err error) bool {
if driverErr, ok := err.(*mysql.MySQLError); ok {
if driverErr.Number == mysqlerr.ER_DUP_ENTRY {
return true
}
}
return false
}