Skip to content

Commit

Permalink
Rename WAL, fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
ncruces committed Oct 23, 2024
1 parent c69ee0f commit 0cd0f48
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 11 deletions.
12 changes: 6 additions & 6 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions tests/wal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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
})
Expand Down
5 changes: 5 additions & 0 deletions util/sql3util/arg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions util/sql3util/sql3util.go
Original file line number Diff line number Diff line change
@@ -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
}
3 changes: 2 additions & 1 deletion vfs/vfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"crypto/rand"
"io"
"reflect"
"strings"
"time"

"github.com/tetratelabs/wazero"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 0cd0f48

Please sign in to comment.