diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9b71d2a..0a489b9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -65,9 +65,7 @@ jobs: run: gormlite/test.sh - name: Collect coverage - run: | - go install github.com/dave/courtney@latest - courtney + run: go run github.com/dave/courtney@latest if: | github.event_name == 'push' && matrix.os == 'ubuntu-latest' diff --git a/embed/README.md b/embed/README.md index 6ef19b0..b7b25c4 100644 --- a/embed/README.md +++ b/embed/README.md @@ -1,6 +1,6 @@ # Embeddable Wasm build of SQLite -This folder includes an embeddable Wasm build of SQLite 3.46.1 for use with +This folder includes an embeddable Wasm build of SQLite 3.47.0 for use with [`github.com/ncruces/go-sqlite3`](https://pkg.go.dev/github.com/ncruces/go-sqlite3). The following optional features are compiled in: diff --git a/embed/bcw2/README.md b/embed/bcw2/README.md index f97f216..a64f1d7 100644 --- a/embed/bcw2/README.md +++ b/embed/bcw2/README.md @@ -1,6 +1,6 @@ # Embeddable Wasm build of SQLite -This folder includes an embeddable Wasm build of SQLite 3.46.1, including the experimental +This folder includes an embeddable Wasm build of SQLite 3.47.0, including the experimental [`BEGIN CONCURRENT`](https://sqlite.org/src/doc/begin-concurrent/doc/begin_concurrent.md) and [Wal2](https://sqlite.org/cgi/src/doc/wal2/doc/wal2.md) patches. diff --git a/embed/bcw2/bcw2.wasm b/embed/bcw2/bcw2.wasm index 23cf0f1..b8e3694 100755 Binary files a/embed/bcw2/bcw2.wasm and b/embed/bcw2/bcw2.wasm differ diff --git a/embed/bcw2/bcw2_test.go b/embed/bcw2/bcw2_test.go index 89c86c7..d25944c 100644 --- a/embed/bcw2/bcw2_test.go +++ b/embed/bcw2/bcw2_test.go @@ -42,7 +42,7 @@ func Test_bcw2(t *testing.T) { if err != nil { t.Fatal(err) } - if version != "3.46.1" { + if version != "3.47.0" { t.Error(version) } } diff --git a/embed/bcw2/build.sh b/embed/bcw2/build.sh index 0514c77..238f0fa 100755 --- a/embed/bcw2/build.sh +++ b/embed/bcw2/build.sh @@ -13,7 +13,8 @@ mkdir -p build/ext/ cp "$ROOT"/sqlite3/*.[ch] build/ cp "$ROOT"/sqlite3/*.patch build/ -curl -# https://sqlite.org/src/tarball/sqlite.tar.gz?r=bedrock-3.46 | tar xz +# https://sqlite.org/src/info/d2d954d43abe20a3 +curl -# https://sqlite.org/src/tarball/sqlite.tar.gz?r=d2d954d4 | tar xz cd sqlite if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" ]]; then diff --git a/embed/init_test.go b/embed/init_test.go index b7ecaa4..e5d63e8 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.46.1" { + if version != "3.47.0" { t.Error(version) } } diff --git a/embed/sqlite3.wasm b/embed/sqlite3.wasm index 749a6ed..173ad0e 100755 Binary files a/embed/sqlite3.wasm and b/embed/sqlite3.wasm differ diff --git a/sqlite3/busy_timeout.patch b/sqlite3/busy_timeout.patch index 1d954e8..9855acd 100644 --- a/sqlite3/busy_timeout.patch +++ b/sqlite3/busy_timeout.patch @@ -1,8 +1,8 @@ -# Replace sqliteDefaultBusyCallback. -# This patch allows Go to handle (and interrupt) sqlite3_busy_timeout. +# Replace sqliteDefaultBusyCallback, so Go can +# handle, and interrupt, sqlite3_busy_timeout. --- sqlite3.c.orig +++ sqlite3.c -@@ -181614,7 +181614,7 @@ +@@ -182908,7 +182908,7 @@ if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT; #endif if( ms>0 ){ diff --git a/sqlite3/download.sh b/sqlite3/download.sh index fa3e67f..d3849fd 100755 --- a/sqlite3/download.sh +++ b/sqlite3/download.sh @@ -3,7 +3,7 @@ set -euo pipefail cd -P -- "$(dirname -- "$0")" -curl -#OL "https://sqlite.org/2024/sqlite-amalgamation-3460100.zip" +curl -#OL "https://sqlite.org/2024/sqlite-amalgamation-3470000.zip" unzip -d . sqlite-amalgamation-*.zip mv sqlite-amalgamation-*/sqlite3.c . mv sqlite-amalgamation-*/sqlite3.h . @@ -21,25 +21,25 @@ cat *.patch | patch --no-backup-if-mismatch mkdir -p ext/ cd ext/ -curl -#OL "https://github.com/sqlite/sqlite/raw/version-3.46.1/ext/misc/anycollseq.c" -curl -#OL "https://github.com/sqlite/sqlite/raw/version-3.46.1/ext/misc/base64.c" -curl -#OL "https://github.com/sqlite/sqlite/raw/version-3.46.1/ext/misc/decimal.c" -curl -#OL "https://github.com/sqlite/sqlite/raw/version-3.46.1/ext/misc/ieee754.c" -curl -#OL "https://github.com/sqlite/sqlite/raw/version-3.46.1/ext/misc/regexp.c" -curl -#OL "https://github.com/sqlite/sqlite/raw/version-3.46.1/ext/misc/series.c" -curl -#OL "https://github.com/sqlite/sqlite/raw/version-3.46.1/ext/misc/spellfix.c" -curl -#OL "https://github.com/sqlite/sqlite/raw/version-3.46.1/ext/misc/uint.c" +curl -#OL "https://github.com/sqlite/sqlite/raw/version-3.47.0/ext/misc/anycollseq.c" +curl -#OL "https://github.com/sqlite/sqlite/raw/version-3.47.0/ext/misc/base64.c" +curl -#OL "https://github.com/sqlite/sqlite/raw/version-3.47.0/ext/misc/decimal.c" +curl -#OL "https://github.com/sqlite/sqlite/raw/version-3.47.0/ext/misc/ieee754.c" +curl -#OL "https://github.com/sqlite/sqlite/raw/version-3.47.0/ext/misc/regexp.c" +curl -#OL "https://github.com/sqlite/sqlite/raw/version-3.47.0/ext/misc/series.c" +curl -#OL "https://github.com/sqlite/sqlite/raw/version-3.47.0/ext/misc/spellfix.c" +curl -#OL "https://github.com/sqlite/sqlite/raw/version-3.47.0/ext/misc/uint.c" cd ~- cd ../vfs/tests/mptest/testdata/ -curl -#OL "https://github.com/sqlite/sqlite/raw/version-3.46.1/mptest/mptest.c" -curl -#OL "https://github.com/sqlite/sqlite/raw/version-3.46.1/mptest/config01.test" -curl -#OL "https://github.com/sqlite/sqlite/raw/version-3.46.1/mptest/config02.test" -curl -#OL "https://github.com/sqlite/sqlite/raw/version-3.46.1/mptest/crash01.test" -curl -#OL "https://github.com/sqlite/sqlite/raw/version-3.46.1/mptest/crash02.subtest" -curl -#OL "https://github.com/sqlite/sqlite/raw/version-3.46.1/mptest/multiwrite01.test" +curl -#OL "https://github.com/sqlite/sqlite/raw/version-3.47.0/mptest/mptest.c" +curl -#OL "https://github.com/sqlite/sqlite/raw/version-3.47.0/mptest/config01.test" +curl -#OL "https://github.com/sqlite/sqlite/raw/version-3.47.0/mptest/config02.test" +curl -#OL "https://github.com/sqlite/sqlite/raw/version-3.47.0/mptest/crash01.test" +curl -#OL "https://github.com/sqlite/sqlite/raw/version-3.47.0/mptest/crash02.subtest" +curl -#OL "https://github.com/sqlite/sqlite/raw/version-3.47.0/mptest/multiwrite01.test" cd ~- cd ../vfs/tests/speedtest1/testdata/ -curl -#OL "https://github.com/sqlite/sqlite/raw/version-3.46.1/test/speedtest1.c" +curl -#OL "https://github.com/sqlite/sqlite/raw/version-3.47.0/test/speedtest1.c" cd ~- \ No newline at end of file diff --git a/sqlite3/long_double.patch b/sqlite3/long_double.patch deleted file mode 100644 index 7049c51..0000000 --- a/sqlite3/long_double.patch +++ /dev/null @@ -1,29 +0,0 @@ ---- sqlite3.c.orig -+++ sqlite3.c -@@ -35561,7 +35561,7 @@ - - if( e==0 ){ - *pResult = s; -- }else if( sqlite3Config.bUseLongDouble ){ -+ }else if( sizeof(LONGDOUBLE_TYPE)>8 && sqlite3Config.bUseLongDouble ){ - LONGDOUBLE_TYPE r = (LONGDOUBLE_TYPE)s; - if( e>0 ){ - while( e>=100 ){ e-=100; r *= 1.0e+100L; } -@@ -35967,7 +35967,7 @@ - /* Multiply r by powers of ten until it lands somewhere in between - ** 1.0e+19 and 1.0e+17. - */ -- if( sqlite3Config.bUseLongDouble ){ -+ if( sizeof(LONGDOUBLE_TYPE)>8 && sqlite3Config.bUseLongDouble ){ - LONGDOUBLE_TYPE rr = r; - if( rr>=1.0e+19 ){ - while( rr>=1.0e+119L ){ exp+=100; rr *= 1.0e-100L; } -@@ -89354,7 +89354,7 @@ - ** than NULL */ - return 1; - } -- if( sqlite3Config.bUseLongDouble ){ -+ if( sizeof(LONGDOUBLE_TYPE)>8 && sqlite3Config.bUseLongDouble ){ - LONGDOUBLE_TYPE x = (LONGDOUBLE_TYPE)i; - testcase( xr ); diff --git a/sqlite3/vfs.c b/sqlite3/vfs.c index 7c397ef..0a15aaa 100644 --- a/sqlite3/vfs.c +++ b/sqlite3/vfs.c @@ -89,59 +89,13 @@ struct go_file { go_handle handle; }; -int sqlite3_os_init() { - static sqlite3_vfs os_vfs = { - .iVersion = 2, - .szOsFile = sizeof(struct go_file), - .mxPathname = 1024, - .zName = "os", - - .xOpen = go_open_wrapper, - .xDelete = go_delete, - .xAccess = go_access, - .xFullPathname = go_full_pathname, - - .xRandomness = go_randomness, - .xSleep = go_sleep, - .xCurrentTimeInt64 = go_current_time_64, - }; - return sqlite3_vfs_register(&os_vfs, /*default=*/true); -} - -int localtime_s(struct tm *const pTm, time_t const *const pTime) { - return go_localtime(pTm, (sqlite3_int64)*pTime); -} - sqlite3_vfs *sqlite3_vfs_find(const char *zVfsName) { - if (zVfsName && go_vfs_find(zVfsName)) { - static sqlite3_vfs *go_vfs_list; - - for (sqlite3_vfs *it = go_vfs_list; it; it = it->pNext) { - if (!strcmp(zVfsName, it->zName)) { - return it; - } - } - - for (sqlite3_vfs **ptr = &go_vfs_list; *ptr;) { - sqlite3_vfs *it = *ptr; - if (go_vfs_find(it->zName)) { - ptr = &it->pNext; - } else { - *ptr = it->pNext; - free(it); - } - } - - sqlite3_vfs *head = go_vfs_list; - go_vfs_list = malloc(sizeof(sqlite3_vfs) + strlen(zVfsName) + 1); - char *name = (char *)(go_vfs_list + 1); - strcpy(name, zVfsName); - *go_vfs_list = (sqlite3_vfs){ + if (!zVfsName || !strcmp(zVfsName, "os")) { + static sqlite3_vfs os_vfs = { .iVersion = 2, .szOsFile = sizeof(struct go_file), .mxPathname = 1024, - .zName = name, - .pNext = head, + .zName = "os", .xOpen = go_open_wrapper, .xDelete = go_delete, @@ -152,9 +106,60 @@ sqlite3_vfs *sqlite3_vfs_find(const char *zVfsName) { .xSleep = go_sleep, .xCurrentTimeInt64 = go_current_time_64, }; - return go_vfs_list; + return &os_vfs; } - return sqlite3_vfs_find_orig(zVfsName); + + if (!go_vfs_find(zVfsName)) { + return NULL; + } + + static sqlite3_vfs *go_vfs_list; + + for (sqlite3_vfs *it = go_vfs_list; it; it = it->pNext) { + if (!strcmp(zVfsName, it->zName)) { + return it; + } + } + + for (sqlite3_vfs **ptr = &go_vfs_list; *ptr;) { + sqlite3_vfs *it = *ptr; + if (go_vfs_find(it->zName)) { + ptr = &it->pNext; + } else { + *ptr = it->pNext; + free(it); + } + } + + sqlite3_vfs *head = go_vfs_list; + go_vfs_list = malloc(sizeof(sqlite3_vfs) + strlen(zVfsName) + 1); + char *name = (char *)(go_vfs_list + 1); + strcpy(name, zVfsName); + *go_vfs_list = (sqlite3_vfs){ + .iVersion = 2, + .szOsFile = sizeof(struct go_file), + .mxPathname = 1024, + .zName = name, + .pNext = head, + + .xOpen = go_open_wrapper, + .xDelete = go_delete, + .xAccess = go_access, + .xFullPathname = go_full_pathname, + + .xRandomness = go_randomness, + .xSleep = go_sleep, + .xCurrentTimeInt64 = go_current_time_64, + }; + return go_vfs_list; +} + +int localtime_s(struct tm *const pTm, time_t const *const pTime) { + return go_localtime(pTm, (sqlite3_int64)*pTime); +} + +int sqlite3_os_init() { + return SQLITE_OK; } static_assert(offsetof(sqlite3_vfs, zName) == 16, "Unexpected offset"); diff --git a/sqlite3/vfs_find.patch b/sqlite3/vfs_find.patch index 5e4b999..a8c57a6 100644 --- a/sqlite3/vfs_find.patch +++ b/sqlite3/vfs_find.patch @@ -1,13 +1,21 @@ -# Wrap sqlite3_vfs_find. -# This patch allows Go VFSes to be (un)registered. +# Remove VFS registration. Go handles it. --- sqlite3.c.orig +++ sqlite3.c -@@ -26396,7 +26396,7 @@ - ** Locate a VFS by name. If no name is given, simply return the - ** first VFS on the list. +@@ -26594,7 +26594,7 @@ + sqlite3_free(p); + return sqlite3_os_init(); + } +- ++#if 0 // Go handles VFS registration. + /* + ** The list of all registered VFS implementations. */ --SQLITE_API sqlite3_vfs *sqlite3_vfs_find(const char *zVfs){ -+SQLITE_API sqlite3_vfs *sqlite3_vfs_find_orig(const char *zVfs){ - sqlite3_vfs *pVfs = 0; - #if SQLITE_THREADSAFE - sqlite3_mutex *mutex; +@@ -26691,7 +26691,7 @@ + sqlite3_mutex_leave(mutex); + return SQLITE_OK; + } +- ++#endif + /************** End of os.c **************************************************/ + /************** Begin file fault.c *******************************************/ + /* diff --git a/vfs/tests/mptest/testdata/mptest.wasm.bz2 b/vfs/tests/mptest/testdata/mptest.wasm.bz2 index 1229a7e..a6ffc5a 100644 --- a/vfs/tests/mptest/testdata/mptest.wasm.bz2 +++ b/vfs/tests/mptest/testdata/mptest.wasm.bz2 @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a16772cc8f0d3b86e068440876f5ea7861e687420725966cd991c8929d365904 -size 473706 +oid sha256:5c69a9b1c88bc735797d81f9ba979a2683f66f8b2fe88106dcbd1cdb0bb26043 +size 480731 diff --git a/vfs/tests/speedtest1/testdata/main.c b/vfs/tests/speedtest1/testdata/main.c index a5d6a5e..8b6ccf1 100644 --- a/vfs/tests/speedtest1/testdata/main.c +++ b/vfs/tests/speedtest1/testdata/main.c @@ -1,6 +1,3 @@ -#include -#include - #define sqliteBusyCallback sqliteDefaultBusyCallback // Amalgamation diff --git a/vfs/tests/speedtest1/testdata/speedtest1.wasm.bz2 b/vfs/tests/speedtest1/testdata/speedtest1.wasm.bz2 index 420b80f..0c49f4a 100644 --- a/vfs/tests/speedtest1/testdata/speedtest1.wasm.bz2 +++ b/vfs/tests/speedtest1/testdata/speedtest1.wasm.bz2 @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9a2b5c21bdc8214a2c5a278c34e06b9079813a487fbd575ca2d62386b206f809 -size 487023 +oid sha256:a2f414d7540e31733b6c2f1cbfb2f8d39506215487a1b73aa03f80d8a2fe371a +size 493518