mirror of
https://github.com/ncruces/go-sqlite3.git
synced 2026-01-12 05:59:14 +00:00
Rename WAL, fixes.
This commit is contained in:
12
config.go
12
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
|
||||
|
||||
@@ -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
|
||||
})
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user