18 lines
462 B
Go
18 lines
462 B
Go
//go:build cgo
|
|
|
|
package dberror
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/mattn/go-sqlite3"
|
|
)
|
|
|
|
// isSQLiteDuplicateKey 在启用CGO时识别SQLite驱动原因链;err为执行错误,返回是否唯一键或主键冲突。
|
|
func isSQLiteDuplicateKey(err error) bool {
|
|
var (
|
|
sqliteError sqlite3.Error
|
|
)
|
|
return errors.As(err, &sqliteError) && (sqliteError.ExtendedCode == sqlite3.ErrConstraintUnique || sqliteError.ExtendedCode == sqlite3.ErrConstraintPrimaryKey)
|
|
}
|