From 0cd0f4836515ce6577e3cefabb7162817f37900c Mon Sep 17 00:00:00 2001 From: Nuno Cruces Date: Thu, 24 Oct 2024 00:22:20 +0100 Subject: [PATCH] Rename WAL, fixes. --- config.go | 12 ++++++------ tests/wal_test.go | 8 ++++---- util/sql3util/arg.go | 5 +++++ util/sql3util/sql3util.go | 7 +++++++ vfs/vfs.go | 3 ++- 5 files changed, 24 insertions(+), 11 deletions(-) diff --git a/config.go b/config.go index 1d437e0..1d155a7 100644 --- a/config.go +++ b/config.go @@ -250,10 +250,10 @@ func traceCallback(ctx context.Context, mod api.Module, evt TraceEvent, pDB, pAr return rc } -// WalCheckpoint checkpoints a WAL database. +// WALCheckpoint checkpoints a WAL database. // // https://sqlite.org/c3ref/wal_checkpoint_v2.html -func (c *Conn) WalCheckpoint(schema string, mode CheckpointMode) (nLog, nCkpt int, err error) { +func (c *Conn) WALCheckpoint(schema string, mode CheckpointMode) (nLog, nCkpt int, err error) { defer c.arena.mark()() nLogPtr := c.arena.new(ptrlen) nCkptPtr := c.arena.new(ptrlen) @@ -266,19 +266,19 @@ func (c *Conn) WalCheckpoint(schema string, mode CheckpointMode) (nLog, nCkpt in return nLog, nCkpt, c.error(r) } -// WalAutoCheckpoint configures WAL auto-checkpoints. +// WALAutoCheckpoint configures WAL auto-checkpoints. // // https://sqlite.org/c3ref/wal_autocheckpoint.html -func (c *Conn) WalAutoCheckpoint(pages int) error { +func (c *Conn) WALAutoCheckpoint(pages int) error { r := c.call("sqlite3_wal_autocheckpoint", uint64(c.handle), uint64(pages)) return c.error(r) } -// WalHook registers a callback function to be invoked +// WALHook registers a callback function to be invoked // each time data is committed to a database in WAL mode. // // https://sqlite.org/c3ref/wal_hook.html -func (c *Conn) WalHook(cb func(db *Conn, schema string, pages int) error) { +func (c *Conn) WALHook(cb func(db *Conn, schema string, pages int) error) { var enable uint64 if cb != nil { enable = 1 diff --git a/tests/wal_test.go b/tests/wal_test.go index 432841e..477edac 100644 --- a/tests/wal_test.go +++ b/tests/wal_test.go @@ -104,7 +104,7 @@ func TestWAL_readonly(t *testing.T) { } } -func TestConn_WalCheckpoint(t *testing.T) { +func TestConn_WALCheckpoint(t *testing.T) { if !vfs.SupportsFileLocking { t.Skip("skipping without locks") } @@ -118,13 +118,13 @@ func TestConn_WalCheckpoint(t *testing.T) { } defer db.Close() - err = db.WalAutoCheckpoint(1000) + err = db.WALAutoCheckpoint(1000) if err != nil { t.Fatal(err) } - db.WalHook(func(db *sqlite3.Conn, schema string, pages int) error { - log, ckpt, err := db.WalCheckpoint(schema, sqlite3.CHECKPOINT_FULL) + db.WALHook(func(db *sqlite3.Conn, schema string, pages int) error { + log, ckpt, err := db.WALCheckpoint(schema, sqlite3.CHECKPOINT_FULL) t.Log(log, ckpt, err) return err }) diff --git a/util/sql3util/arg.go b/util/sql3util/arg.go index b75f7dd..3e8c728 100644 --- a/util/sql3util/arg.go +++ b/util/sql3util/arg.go @@ -13,6 +13,8 @@ func NamedArg(arg string) (key, val string) { } // Unquote unquotes a string. +// +// https://sqlite.org/lang_keywords.html func Unquote(val string) string { if len(val) < 2 { return val @@ -40,6 +42,9 @@ func Unquote(val string) string { return strings.ReplaceAll(rst, old, new) } +// ParseBool parses a boolean. +// +// https://sqlite.org/pragma.html#syntax func ParseBool(s string) (b, ok bool) { if len(s) == 0 { return false, false diff --git a/util/sql3util/sql3util.go b/util/sql3util/sql3util.go index 2c4bf83..6be6192 100644 --- a/util/sql3util/sql3util.go +++ b/util/sql3util/sql3util.go @@ -1,2 +1,9 @@ // Package sql3util implements SQLite utilities. package sql3util + +// ValidPageSize returns true if s is a valid page size. +// +// https://sqlite.org/fileformat.html#pages +func ValidPageSize(s int) bool { + return 512 <= s && s <= 65536 && s&(s-1) == 0 +} diff --git a/vfs/vfs.go b/vfs/vfs.go index d4519fb..277146a 100644 --- a/vfs/vfs.go +++ b/vfs/vfs.go @@ -5,6 +5,7 @@ import ( "crypto/rand" "io" "reflect" + "strings" "time" "github.com/tetratelabs/wazero" @@ -343,7 +344,7 @@ func vfsFileControl(ctx context.Context, mod api.Module, pFile uint32, op _Fcntl value = util.ReadString(mod, ptr, _MAX_SQL_LENGTH) } - out, err := file.Pragma(name, value) + out, err := file.Pragma(strings.ToLower(name), value) ret := vfsErrorCode(err, _ERROR) if ret == _ERROR {