diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ef3cace..c2fb240 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -112,7 +112,7 @@ jobs: version: '10.1' flags: '-test.v -test.short' - name: openbsd - version: '7.7' + version: '7.8' flags: '-test.v -test.short' runs-on: ubuntu-latest needs: test @@ -128,7 +128,7 @@ jobs: run: .github/workflows/build-test.sh - name: Test - uses: cross-platform-actions/action@v0.29.0 + uses: cross-platform-actions/action@v0.30.0 with: operating_system: ${{ matrix.os.name }} architecture: ${{ matrix.os.arch }} diff --git a/conn.go b/conn.go index a7eca16..5794b16 100644 --- a/conn.go +++ b/conn.go @@ -420,21 +420,21 @@ func busyCallback(ctx context.Context, mod api.Module, pDB ptr_t, count int32) ( // Status retrieves runtime status information about a database connection. // // https://sqlite.org/c3ref/db_status.html -func (c *Conn) Status(op DBStatus, reset bool) (current, highwater int, err error) { +func (c *Conn) Status(op DBStatus, reset bool) (current, highwater int64, err error) { defer c.arena.mark()() - hiPtr := c.arena.new(intlen) - curPtr := c.arena.new(intlen) + hiPtr := c.arena.new(8) + curPtr := c.arena.new(8) var i int32 if reset { i = 1 } - rc := res_t(c.call("sqlite3_db_status", stk_t(c.handle), + rc := res_t(c.call("sqlite3_db_status64", stk_t(c.handle), stk_t(op), stk_t(curPtr), stk_t(hiPtr), stk_t(i))) if err = c.error(rc); err == nil { - current = int(util.Read32[int32](c.mod, curPtr)) - highwater = int(util.Read32[int32](c.mod, hiPtr)) + current = util.Read64[int64](c.mod, curPtr) + highwater = util.Read64[int64](c.mod, hiPtr) } return } diff --git a/const.go b/const.go index 4a7bae3..a5d92b5 100644 --- a/const.go +++ b/const.go @@ -234,7 +234,8 @@ const ( DBSTATUS_DEFERRED_FKS DBStatus = 10 DBSTATUS_CACHE_USED_SHARED DBStatus = 11 DBSTATUS_CACHE_SPILL DBStatus = 12 - // DBSTATUS_MAX DBStatus = 12 + DBSTATUS_TEMPBUF_SPILL DBStatus = 13 + // DBSTATUS_MAX DBStatus = 13 ) // DBConfig are the available database connection configuration options. diff --git a/embed/bcw2/bcw2.wasm b/embed/bcw2/bcw2.wasm index 18e8397..9a1a059 100755 Binary files a/embed/bcw2/bcw2.wasm and b/embed/bcw2/bcw2.wasm differ diff --git a/embed/bcw2/build.sh b/embed/bcw2/build.sh index a7276b3..15acaf9 100755 --- a/embed/bcw2/build.sh +++ b/embed/bcw2/build.sh @@ -15,9 +15,9 @@ cp "$ROOT"/sqlite3/*.[ch] build/ cp "$ROOT"/sqlite3/*.patch build/ cd sqlite/ -# https://sqlite.org/src/info/ba2174bdca7d1d1a -curl -#L https://github.com/sqlite/sqlite/archive/b46738f.tar.gz | tar xz --strip-components=1 -# curl -#L https://sqlite.org/src/tarball/sqlite.tar.gz?r=ba2174bdca | tar xz --strip-components=1 +# https://sqlite.org/src/info/0e862bc9ed7aa9ae +curl -#L https://github.com/sqlite/sqlite/archive/0b99392.tar.gz | tar xz --strip-components=1 +# curl -#L https://sqlite.org/src/tarball/sqlite.tar.gz?r=0e862bc9ed | tar xz --strip-components=1 if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" ]]; then MSYS_NO_PATHCONV=1 nmake /f makefile.msc sqlite3.c "OPTS=-DSQLITE_ENABLE_UPDATE_DELETE_LIMIT -DSQLITE_ENABLE_ORDERED_SET_AGGREGATES" @@ -67,4 +67,4 @@ cd ~- --enable-mutable-globals --enable-nontrapping-float-to-int \ --enable-simd --enable-bulk-memory --enable-sign-ext \ --enable-reference-types --enable-multivalue \ - --strip --strip-producers \ No newline at end of file + --strip --strip-producers diff --git a/embed/exports.txt b/embed/exports.txt index bb049c2..8a13450 100644 --- a/embed/exports.txt +++ b/embed/exports.txt @@ -59,7 +59,7 @@ sqlite3_db_filename sqlite3_db_name sqlite3_db_readonly sqlite3_db_release_memory -sqlite3_db_status +sqlite3_db_status64 sqlite3_declare_vtab sqlite3_errcode sqlite3_errmsg diff --git a/embed/init_test.go b/embed/init_test.go index 30b63f8..64f988b 100644 --- a/embed/init_test.go +++ b/embed/init_test.go @@ -19,7 +19,7 @@ func Test_init(t *testing.T) { if err != nil { t.Fatal(err) } - if version != "3.50.4" { + if version != "3.51.0" { t.Error(version) } } diff --git a/embed/sqlite3.wasm b/embed/sqlite3.wasm index e44b2cc..8d09414 100755 Binary files a/embed/sqlite3.wasm and b/embed/sqlite3.wasm differ diff --git a/internal/util/module.go b/internal/util/module.go index 06b90bb..a308b4e 100644 --- a/internal/util/module.go +++ b/internal/util/module.go @@ -26,11 +26,16 @@ func NewContext(ctx context.Context) context.Context { } func GetSystemError(ctx context.Context) error { - s := ctx.Value(moduleKey{}).(*moduleState) - return s.sysError + // Test needed to simplify testing. + s, ok := ctx.Value(moduleKey{}).(*moduleState) + if ok { + return s.sysError + } + return nil } func SetSystemError(ctx context.Context, err error) { + // Test needed to simplify testing. s, ok := ctx.Value(moduleKey{}).(*moduleState) if ok { s.sysError = err diff --git a/sqlite3/busy_timeout.patch b/sqlite3/busy_timeout.patch index 7707b8d..b6cf890 100644 --- a/sqlite3/busy_timeout.patch +++ b/sqlite3/busy_timeout.patch @@ -2,7 +2,7 @@ # handle, and interrupt, sqlite3_busy_timeout. --- sqlite3.c.orig +++ sqlite3.c -@@ -184474,7 +184474,7 @@ +@@ -186667,7 +186667,7 @@ if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT; #endif if( ms>0 ){ diff --git a/sqlite3/download.sh b/sqlite3/download.sh index 26cead9..80a34be 100755 --- a/sqlite3/download.sh +++ b/sqlite3/download.sh @@ -3,55 +3,54 @@ set -euo pipefail cd -P -- "$(dirname -- "$0")" -curl -#OL "https://sqlite.org/2025/sqlite-amalgamation-3500400.zip" +curl -#OL "https://sqlite.org/2025/sqlite-autoconf-3510000.tar.gz" # Verify download. -if hash=$(openssl dgst -sha3-256 sqlite-amalgamation-*.zip); then - if ! [[ $hash =~ f131b68e6ba5fb891cc13ebb5ff9555054c77294cb92d8d1268bad5dba4fa2a1 ]]; then +if hash=$(openssl dgst -sha3-256 sqlite-autoconf-*.tar.gz); then + if ! [[ $hash =~ fa52f9cc74dbca004aa650ae698036a3350611f672649e165078f4eae21d6a2e ]]; then echo $hash exit 1 fi fi 2> /dev/null -unzip -d . sqlite-amalgamation-*.zip -mv sqlite-amalgamation-*/sqlite3.c . -mv sqlite-amalgamation-*/sqlite3.h . -mv sqlite-amalgamation-*/sqlite3ext.h . -rm -rf sqlite-amalgamation-* +tar xzf sqlite-autoconf-*.tar.gz -# To test a snapshot: +# To test a snapshot instead: # curl -# https://sqlite.org/snapshot/sqlite-snapshot-202410081727.tar.gz | tar xz -# mv sqlite-snapshot-*/sqlite3.c . -# mv sqlite-snapshot-*/sqlite3.h . -# mv sqlite-snapshot-*/sqlite3ext.h . -# rm -rf sqlite-snapshot-* + +mv sqlite-*/sqlite3.c . +mv sqlite-*/sqlite3.h . +mv sqlite-*/sqlite3ext.h . +rm -r sqlite-* + +GITHUB_TAG="https://github.com/sqlite/sqlite/raw/version-3.51.0" mkdir -p ext/ cd ext/ -curl -#OL "https://github.com/sqlite/sqlite/raw/version-3.50.4/ext/misc/anycollseq.c" -curl -#OL "https://github.com/sqlite/sqlite/raw/version-3.50.4/ext/misc/base64.c" -curl -#OL "https://github.com/sqlite/sqlite/raw/version-3.50.4/ext/misc/decimal.c" -curl -#OL "https://github.com/sqlite/sqlite/raw/version-3.50.4/ext/misc/ieee754.c" -curl -#OL "https://github.com/sqlite/sqlite/raw/version-3.50.4/ext/misc/regexp.c" -curl -#OL "https://github.com/sqlite/sqlite/raw/version-3.50.4/ext/misc/series.c" -curl -#OL "https://github.com/sqlite/sqlite/raw/version-3.50.4/ext/misc/spellfix.c" -curl -#OL "https://github.com/sqlite/sqlite/raw/version-3.50.4/ext/misc/uint.c" +curl -#OL "$GITHUB_TAG/ext/misc/anycollseq.c" +curl -#OL "$GITHUB_TAG/ext/misc/base64.c" +curl -#OL "$GITHUB_TAG/ext/misc/decimal.c" +curl -#OL "$GITHUB_TAG/ext/misc/ieee754.c" +curl -#OL "$GITHUB_TAG/ext/misc/regexp.c" +curl -#OL "$GITHUB_TAG/ext/misc/series.c" +curl -#OL "$GITHUB_TAG/ext/misc/spellfix.c" +curl -#OL "$GITHUB_TAG/ext/misc/uint.c" cd ~- cd ../vfs/tests/mptest/testdata/ -curl -#OL "https://github.com/sqlite/sqlite/raw/version-3.50.4/mptest/config01.test" -curl -#OL "https://github.com/sqlite/sqlite/raw/version-3.50.4/mptest/config02.test" -curl -#OL "https://github.com/sqlite/sqlite/raw/version-3.50.4/mptest/crash01.test" -curl -#OL "https://github.com/sqlite/sqlite/raw/version-3.50.4/mptest/crash02.subtest" -curl -#OL "https://github.com/sqlite/sqlite/raw/version-3.50.4/mptest/multiwrite01.test" +curl -#OL "$GITHUB_TAG/mptest/config01.test" +curl -#OL "$GITHUB_TAG/mptest/config02.test" +curl -#OL "$GITHUB_TAG/mptest/crash01.test" +curl -#OL "$GITHUB_TAG/mptest/crash02.subtest" +curl -#OL "$GITHUB_TAG/mptest/multiwrite01.test" cd ~- cd ../vfs/tests/mptest/wasm/ -curl -#OL "https://github.com/sqlite/sqlite/raw/version-3.50.4/mptest/mptest.c" +curl -#OL "$GITHUB_TAG/mptest/mptest.c" cd ~- cd ../vfs/tests/speedtest1/wasm/ -curl -#OL "https://github.com/sqlite/sqlite/raw/version-3.50.4/test/speedtest1.c" +curl -#OL "$GITHUB_TAG/test/speedtest1.c" cd ~- -cat *.patch | patch -p0 --no-backup-if-mismatch \ No newline at end of file +cat *.patch | patch -p0 --no-backup-if-mismatch diff --git a/sqlite3/vfs_find.patch b/sqlite3/vfs_find.patch index ef01eea..4f58229 100644 --- a/sqlite3/vfs_find.patch +++ b/sqlite3/vfs_find.patch @@ -1,7 +1,7 @@ # Remove VFS registration. Go handles it. --- sqlite3.c.orig +++ sqlite3.c -@@ -26884,7 +26884,7 @@ +@@ -27176,7 +27176,7 @@ sqlite3_free(p); return sqlite3_os_init(); } @@ -10,7 +10,7 @@ /* ** The list of all registered VFS implementations. */ -@@ -26981,7 +26981,7 @@ +@@ -27273,7 +27273,7 @@ sqlite3_mutex_leave(mutex); return SQLITE_OK; } diff --git a/util/sql3util/wasm/sql3parse_table.wasm b/util/sql3util/wasm/sql3parse_table.wasm index 824a7bf..198f100 100755 Binary files a/util/sql3util/wasm/sql3parse_table.wasm and b/util/sql3util/wasm/sql3parse_table.wasm differ diff --git a/vfs/README.md b/vfs/README.md index 44d5944..f34e08b 100644 --- a/vfs/README.md +++ b/vfs/README.md @@ -20,11 +20,12 @@ The main differences to be aware of are ### File Locking POSIX advisory locks, -which SQLite uses on [Unix](https://github.com/sqlite/sqlite/blob/5d60f4/src/os_unix.c#L13-L14), -are [broken by design](https://github.com/sqlite/sqlite/blob/5d60f4/src/os_unix.c#L1074-L1162). +which SQLite uses on [Unix](https://github.com/sqlite/sqlite/blob/41fda52/src/os_unix.c#L13-L14), +are [broken by design](https://github.com/sqlite/sqlite/blob/41fda52/src/os_unix.c#L1188-L1276). Instead, on Linux and macOS, this package uses -[OFD locks](https://gnu.org/software/libc/manual/html_node/Open-File-Description-Locks.html) +[OFD locks](https://sourceware.org/glibc/manual/2.25/html_node/Open-File-Description-Locks.html) to synchronize access to database files. +OFD locks require [Linux 3.15](https://lwn.net/Articles/586904/). This package can also use [BSD locks](https://man.freebsd.org/cgi/man.cgi?query=flock&sektion=2), diff --git a/vfs/adiantum/hbsh.go b/vfs/adiantum/hbsh.go index 99a6efb..12fbc63 100644 --- a/vfs/adiantum/hbsh.go +++ b/vfs/adiantum/hbsh.go @@ -56,7 +56,7 @@ func (h *hbshVFS) OpenFilename(name *vfs.Filename, flags vfs.OpenFlag) (file vfs if hbsh == nil { file.Close() - return nil, flags, sqlite3.CANTOPEN + return nil, flags, sqlite3.IOERR_BADKEY } return &hbshFile{File: file, hbsh: hbsh, init: h.init}, flags, nil } @@ -108,7 +108,7 @@ func (h *hbshFile) Pragma(name string, value string) (string, error) { if h.hbsh = h.init.HBSH(key); h.hbsh != nil { return "ok", nil } - return "", sqlite3.CANTOPEN + return "", sqlite3.IOERR_BADKEY } func (h *hbshFile) ReadAt(p []byte, off int64) (n int, err error) { diff --git a/vfs/api.go b/vfs/api.go index ef0623e..4f4f833 100644 --- a/vfs/api.go +++ b/vfs/api.go @@ -207,6 +207,10 @@ type blockingSharedMemory interface { shmEnableBlocking(block bool) } +// FileControl makes it easy to forward all fileControl methods, +// which we want to do for the checksum VFS. +// However, this is not a safe default, and other VFSes +// should explicitly wrap the methods they want to wrap. type fileControl interface { File fileControl(ctx context.Context, mod api.Module, op _FcntlOpcode, pArg ptr_t) _ErrorCode diff --git a/vfs/filename.go b/vfs/filename.go index be16b3d..4d4fc4a 100644 --- a/vfs/filename.go +++ b/vfs/filename.go @@ -120,7 +120,7 @@ func (n *Filename) URIParameter(key string) string { } // Parse the format from: - // https://github.com/sqlite/sqlite/blob/b74eb0/src/pager.c#L4797-L4840 + // https://github.com/sqlite/sqlite/blob/41fda52/src/pager.c#L4821-L4864 // This avoids having to alloc/free the key just to find a value. for { k := util.ReadString(n.mod, ptr, _MAX_NAME) @@ -160,7 +160,7 @@ func (n *Filename) URIParameters() url.Values { var params url.Values // Parse the format from: - // https://github.com/sqlite/sqlite/blob/b74eb0/src/pager.c#L4797-L4840 + // https://github.com/sqlite/sqlite/blob/41fda52/src/pager.c#L4821-L4864 // This is the only way to support multiple valued keys. for { k := util.ReadString(n.mod, ptr, _MAX_NAME) diff --git a/vfs/tests/mptest/wasm/mptest.wasm b/vfs/tests/mptest/wasm/mptest.wasm index f6de181..97bbcda 100644 Binary files a/vfs/tests/mptest/wasm/mptest.wasm and b/vfs/tests/mptest/wasm/mptest.wasm differ diff --git a/vfs/tests/speedtest1/wasm/speedtest1.wasm b/vfs/tests/speedtest1/wasm/speedtest1.wasm index 58cf522..625836f 100644 Binary files a/vfs/tests/speedtest1/wasm/speedtest1.wasm and b/vfs/tests/speedtest1/wasm/speedtest1.wasm differ diff --git a/vfs/xts/xts.go b/vfs/xts/xts.go index 89e4c27..f39bca3 100644 --- a/vfs/xts/xts.go +++ b/vfs/xts/xts.go @@ -55,7 +55,7 @@ func (x *xtsVFS) OpenFilename(name *vfs.Filename, flags vfs.OpenFlag) (file vfs. if cipher == nil { file.Close() - return nil, flags, sqlite3.CANTOPEN + return nil, flags, sqlite3.IOERR_BADKEY } return &xtsFile{File: file, cipher: cipher, init: x.init}, flags, nil } @@ -103,7 +103,7 @@ func (x *xtsFile) Pragma(name string, value string) (string, error) { if x.cipher = x.init.XTS(key); x.cipher != nil { return "ok", nil } - return "", sqlite3.CANTOPEN + return "", sqlite3.IOERR_BADKEY } func (x *xtsFile) ReadAt(p []byte, off int64) (n int, err error) {