Files
sqlite/filecontrol_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

34 lines
1.1 KiB
Go

//go:build cgo && !sqlite_purego
package sqlite
import (
"fmt"
sqlite3 "github.com/hanzoai/csqlite"
)
// SetPersistWAL sets SQLite's SQLITE_FCNTL_PERSIST_WAL file control on rawConn —
// the raw driver connection handed to the callback of (*sql.Conn).Raw. When on,
// the -wal file is kept across the last connection close (SQLite otherwise
// deletes it), which WAL-shipping replication (hanzoai/replicate) requires so a
// crash mid-sync doesn't lose committed frames.
//
// It is the one backend-neutral way to set PERSIST_WAL; consumers never touch
// the csqlite/modernc conn type directly. Returns an error if rawConn is not
// this build's SQLite connection type.
//
// CGO backend: csqlite exposes SetFileControlInt; the op constant is csqlite's
// own SQLITE_FCNTL_PERSIST_WAL (= 10).
func SetPersistWAL(rawConn any, on bool) error {
c, ok := rawConn.(*sqlite3.SQLiteConn)
if !ok {
return fmt.Errorf("sqlite: SetPersistWAL: driver conn is %T, want *sqlite3.SQLiteConn", rawConn)
}
arg := 0
if on {
arg = 1
}
return c.SetFileControlInt("main", sqlite3.SQLITE_FCNTL_PERSIST_WAL, arg)
}