mirror of
https://github.com/hanzoai/sqlite.git
synced 2026-10-30 18:22:26 +00:00
Modules declare go 1.27.1 and the build images follow. go fix applied the modernizers; omitzero is not applied, since it changes what the JSON says. Co-authored-by: Hanzo Dev <[email protected]>
32 lines
1.0 KiB
Go
32 lines
1.0 KiB
Go
//go:build cgo && !sqlite_purego
|
|
|
|
package sqlite
|
|
|
|
import (
|
|
"errors"
|
|
|
|
sqlite3 "github.com/hanzoai/csqlite"
|
|
)
|
|
|
|
// Reference constraint codes and the error unwrap for the CGO/csqlite backend
|
|
// (same build condition as driver_cgo.go / hooks_cgo.go). The values are
|
|
// SQLite's own extended result codes (numerically identical to modernc's
|
|
// lib.SQLITE_CONSTRAINT_*), sourced here from csqlite's typed constants.
|
|
var (
|
|
codeConstraintUnique = int(sqlite3.ErrConstraintUnique)
|
|
codeConstraintPrimaryKey = int(sqlite3.ErrConstraintPrimaryKey)
|
|
codeConstraintForeignKey = int(sqlite3.ErrConstraintForeignKey)
|
|
|
|
// The PRIMARY code every constraint extended code reduces to (SQLITE_CONSTRAINT).
|
|
codeConstraint = int(sqlite3.ErrConstraint)
|
|
)
|
|
|
|
// extendedCode extracts SQLite's extended result code from a csqlite error.
|
|
// sqlite3.Error is a VALUE type, so errors.As targets a value, not a pointer.
|
|
func extendedCode(err error) (int, bool) {
|
|
if e, ok := errors.AsType[sqlite3.Error](err); ok {
|
|
return int(e.ExtendedCode), true
|
|
}
|
|
return 0, false
|
|
}
|