Files
sqlite/hooks_cgo.go
zeekay 7e7906c584 feat: self-contained fork — cgo backend is hanzoai/csqlite, zero mattn/go-sqlite3
The cgo/SQLCipher path now imports github.com/hanzoai/csqlite (v0.1.0) — the
go-sqlite3 cgo bindings forked verbatim into a Hanzo repo — instead of
github.com/mattn/go-sqlite3. driver_cgo/hooks_cgo/errcodes_cgo/filecontrol_cgo
keep the sqlite3 import alias, so wrapper code is otherwise unchanged.

go.mod drops require mattn/go-sqlite3, adds require hanzoai/csqlite. mattn is
absent from go.mod/go.sum and every dep graph (cgo, !cgo, libsqlite3), so
consumers can delete the 'replace mattn/go-sqlite3 => v1.14.47' redirect.

SQLCipher unchanged and proven: SQLITE_REQUIRE_CODEC=1 TestEncryptionProof
PASSES through the fork (-tags libsqlite3 + libsqlcipher), cek_golden fixture
decrypts, all three build configs green. !cgo path stays on modernc.org/sqlite.

Minor bump v0.3.0 (backend module change is a dep-graph change, not a patch).
2026-07-12 19:30:25 -07:00

30 lines
894 B
Go

//go:build cgo && !sqlite_purego
package sqlite
import sqlite3 "github.com/hanzoai/csqlite"
// CommitHookRegisterer adapts a raw csqlite driver connection (obtained from
// (*sql.Conn).Raw) to HookRegisterer. csqlite's *SQLiteConn commit-hook type is
// `func() int` (not int32), so the adapter widens our CommitHookFn's int32
// result to csqlite's int. This is the SAME engine driver_cgo.go registers as
// the "sqlite" driver name. Returns (nil, false) if driverConn is not a csqlite
// connection.
func CommitHookRegisterer(driverConn any) (HookRegisterer, bool) {
c, ok := driverConn.(*sqlite3.SQLiteConn)
if !ok {
return nil, false
}
return cgoHook{c}, true
}
type cgoHook struct{ c *sqlite3.SQLiteConn }
func (m cgoHook) RegisterCommitHook(cb CommitHookFn) {
if cb == nil {
m.c.RegisterCommitHook(nil)
return
}
m.c.RegisterCommitHook(func() int { return int(cb()) })
}