Files
sqlite/errcodes_cgo.go
zeekayandHanzo Dev de3416cd9d Go 1.27.1, and the code it can say more simply
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]>
2026-09-16 19:24:34 -07:00

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
}