MCPcopy Create free account
hub / github.com/mattn/go-sqlite3 / TestSetFileControlInt

Function TestSetFileControlInt

sqlite3_test.go:1975–2010  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1973}
1974
1975func TestSetFileControlInt(t *testing.T) {
1976 t.Run("PERSIST_WAL", func(t *testing.T) {
1977 tempFilename := TempFilename(t)
1978 defer os.Remove(tempFilename)
1979
1980 sql.Register("sqlite3_FCNTL_PERSIST_WAL", &SQLiteDriver{
1981 ConnectHook: func(conn *SQLiteConn) error {
1982 if err := conn.SetFileControlInt("", SQLITE_FCNTL_PERSIST_WAL, 1); err != nil {
1983 return fmt.Errorf("Unexpected error from SetFileControlInt(): %w", err)
1984 }
1985 return nil
1986 },
1987 })
1988
1989 db, err := sql.Open("sqlite3_FCNTL_PERSIST_WAL", tempFilename)
1990 if err != nil {
1991 t.Fatal("Failed to open database:", err)
1992 }
1993 defer db.Close()
1994
1995 // Set to WAL mode & write a page.
1996 if _, err := db.Exec(`PRAGMA journal_mode = wal`); err != nil {
1997 t.Fatal("Failed to set journal mode:", err)
1998 } else if _, err := db.Exec(`CREATE TABLE t (x)`); err != nil {
1999 t.Fatal("Failed to create table:", err)
2000 }
2001 if err := db.Close(); err != nil {
2002 t.Fatal("Failed to close database", err)
2003 }
2004
2005 // Ensure WAL file persists after close.
2006 if _, err := os.Stat(tempFilename + "-wal"); err != nil {
2007 t.Fatal("Expected WAL file to be persisted after close", err)
2008 }
2009 })
2010}
2011
2012func TestSetFileControlInt64(t *testing.T) {
2013 const GiB = 1024 * 1024 * 1024

Callers

nothing calls this directly

Calls 6

TempFilenameFunction · 0.85
RunMethod · 0.80
SetFileControlIntMethod · 0.80
OpenMethod · 0.65
CloseMethod · 0.65
ExecMethod · 0.45

Tested by

no test coverage detected