diff options
Diffstat (limited to 'ext')
-rw-r--r-- | ext/session/session1.test | 2 | ||||
-rw-r--r-- | ext/session/session9.test | 4 | ||||
-rw-r--r-- | ext/session/sessionnoact.test | 66 | ||||
-rw-r--r-- | ext/session/sqlite3session.c | 5 | ||||
-rw-r--r-- | ext/wasm/README-dist.txt | 12 | ||||
-rw-r--r-- | ext/wasm/README.md | 9 | ||||
-rw-r--r-- | ext/wasm/api/README.md | 24 |
7 files changed, 100 insertions, 22 deletions
diff --git a/ext/session/session1.test b/ext/session/session1.test index dfc1aa895..6da905179 100644 --- a/ext/session/session1.test +++ b/ext/session/session1.test @@ -285,7 +285,7 @@ do_conflict_test $tn.3.2.3 -tables t2 -sql { {FOREIGN_KEY 1} } do_execsql_test $tn.3.2.4 "SELECT * FROM t2" {} -do_db2_test $tn.3.2.5 "SELECT * FROM t2" {1 one 2 two 4 five} +do_db2_test $tn.3.2.5 "SELECT * FROM t2" {4 five} # Test UPDATE changesets. # diff --git a/ext/session/session9.test b/ext/session/session9.test index 6b7d1648b..5c406c344 100644 --- a/ext/session/session9.test +++ b/ext/session/session9.test @@ -80,7 +80,7 @@ foreach {tn delrow trans conflictargs conflictret} { 8 3 1 {FOREIGN_KEY 1} ABORT } { - set A(OMIT,0) {1 SQLITE_CONSTRAINT} + set A(OMIT,0) {0 {}} set A(OMIT,1) {0 {}} set A(ABORT,0) {1 SQLITE_CONSTRAINT} set A(ABORT,1) {1 SQLITE_CONSTRAINT} @@ -95,7 +95,7 @@ foreach {tn delrow trans conflictargs conflictret} { do_test 1.2.$tn.2 { set ::xConflict } $conflictargs - set A(OMIT,0) {0 0} + set A(OMIT,0) {1 1} set A(OMIT,1) {1 1} set A(ABORT,0) {0 0} set A(ABORT,1) {0 0} diff --git a/ext/session/sessionnoact.test b/ext/session/sessionnoact.test index e447bc8a1..54e9a6215 100644 --- a/ext/session/sessionnoact.test +++ b/ext/session/sessionnoact.test @@ -59,7 +59,7 @@ do_execsql_test 1.2 { set ::nConflict 0 proc conflict {args} { incr ::nConflict - return "OMIT" + return "ABORT" } sqlite3changeset_apply_v2 db $C conflict @@ -111,6 +111,9 @@ do_execsql_test 1.8 { # Check that a changeset that causes an FK violation may not be applied, # even if SQLITE_CHANGESETAPPLY_FKNOACTION is specified. # +# UPDATE: Unless the conflict-handler returns OMIT. In that case it can +# be committed. See test cases 3.* in this file. +# reset_db do_execsql_test 2.0 { CREATE TABLE p1(a INTEGER PRIMARY KEY, b, c UNIQUE); @@ -164,5 +167,66 @@ do_execsql_test 2.8 { SELECT * FROM c1; } {two} +#------------------------------------------------------------------------- +# +reset_db +do_execsql_test 3.0 { + CREATE TABLE p1(a INTEGER PRIMARY KEY, b, c UNIQUE); + INSERT INTO p1 VALUES(1, 1, 'one'); + INSERT INTO p1 VALUES(2, 2, 'two'); + + CREATE TABLE c1(x REFERENCES p1(c) ON DELETE CASCADE); + INSERT INTO c1 VALUES('two'); +} + +set ::nConflict 0 +proc conflict {args} { + incr ::nConflict + return "OMIT" +} + +db_save + +set C [changeset_from_sql { + DELETE FROM p1 WHERE a=2; +}] + +db_restore_and_reopen + +do_test 3.1 { + sqlite3changeset_apply_v2 -noaction db $C conflict +} {} +do_execsql_test 3.2 { + SELECT * FROM p1 +} {1 1 one} + +db_restore_and_reopen +db eval { PRAGMA foreign_keys = 1 } + +do_test 3.3 { + list [catch { sqlite3changeset_apply_v2 -noaction db $C conflict } msg] $msg +} {0 {}} +do_execsql_test 3.4 { + SELECT * FROM p1; +} {1 1 one} +do_execsql_test 3.5 { + SELECT * FROM c1; +} {two} + +db_restore_and_reopen +db eval { PRAGMA foreign_keys = 1 } + +do_test 3.6 { + list [catch { + sqlite3changeset_apply_v2 -ignorenoop -noaction db $C conflict + } msg] $msg +} {0 {}} +do_execsql_test 3.7 { + SELECT * FROM p1; +} {1 1 one} +do_execsql_test 3.8 { + SELECT * FROM c1; +} {two} + finish_test diff --git a/ext/session/sqlite3session.c b/ext/session/sqlite3session.c index d78dd9b06..66b21d63a 100644 --- a/ext/session/sqlite3session.c +++ b/ext/session/sqlite3session.c @@ -5318,6 +5318,11 @@ static int sessionChangesetApply( } } + { + int rc2 = sqlite3_exec(db, "PRAGMA defer_foreign_keys = 0", 0, 0, 0); + if( rc==SQLITE_OK ) rc = rc2; + } + if( (flags & SQLITE_CHANGESETAPPLY_NOSAVEPOINT)==0 ){ if( rc==SQLITE_OK ){ rc = sqlite3_exec(db, "RELEASE changeset_apply", 0, 0, 0); diff --git a/ext/wasm/README-dist.txt b/ext/wasm/README-dist.txt index 6656a2072..4a527fc5e 100644 --- a/ext/wasm/README-dist.txt +++ b/ext/wasm/README-dist.txt @@ -31,16 +31,20 @@ build: use of and is not demonstrated here. Browsers will not serve WASM files from file:// URLs, so the test and -demonstration apps require a web server and that server must include -the following headers in its response when serving the files: +demonstration apps require a web server and that server must, for the +OPFS[^1]-related features, include the following headers in its response +when serving the files: Cross-Origin-Opener-Policy: same-origin Cross-Origin-Embedder-Policy: require-corp -The core library will function without those headers but certain -features, most notably OPFS storage, will not be available. +Most functionality will work without those headers but the OPFS[^1] +storage capability will not be available without them. One simple way to get the demo apps up and running on Unix-style systems is to install althttpd (https://sqlite.org/althttpd) and run: althttpd --enable-sab --page index.html + + +[^1]: https://developer.mozilla.org/en-US/docs/Web/API/File_System_API/Origin_private_file_system diff --git a/ext/wasm/README.md b/ext/wasm/README.md index 21330f0eb..c41e54bd2 100644 --- a/ext/wasm/README.md +++ b/ext/wasm/README.md @@ -35,7 +35,7 @@ after upgrading it! Our build process makes no guarantees about which Emscripten version(s) will or won't work, but it's important that production builds are built using a compatible version. During active development, the EMSDK is frequently updated, the goal being to keep -sqlite3.wasm working with "the latest" EMSDK.) +`sqlite3.wasm` working with "the latest" EMSDK.) The SQLite configure script will search for the EMSDK. One way to ensure that it finds it is: @@ -95,14 +95,14 @@ $ make httpd That will open the system's browser and visit the index page, from which (almost) all of the test and demo applications can be accessed. (`ext/wasm/SQLTester` is not listed in that page because it's only of -real utility when it's used in conjunction with the proprietary test -suite, which most users don't have access to.) +real utility when it's used in conjunction with the project's +proprietary test suite, which most users don't have access to.) Note that when serving this app via [althttpd][], it must be a version from 2022-09-26 or newer so that it recognizes the `--enable-sab` flag, which causes althttpd to emit two HTTP response headers which are required to enable JavaScript's `SharedArrayBuffer` and `Atomics` -APIs. Those APIs are required in order to enable the OPFS-related +APIs. Those APIs are required in order to enable the [OPFS][]-related features in the apps which use them. # Testing on a remote machine that is accessed via SSH @@ -129,3 +129,4 @@ be tunneled using SSH. [emscripten]: https://emscripten.org [althttpd]: https://sqlite.org/althttpd [SharedArrayBuffer]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer +[OPFS]: https://developer.mozilla.org/en-US/docs/Web/API/File_System_API/Origin_private_file_system diff --git a/ext/wasm/api/README.md b/ext/wasm/api/README.md index ebd4aaacb..ce7e58ebe 100644 --- a/ext/wasm/api/README.md +++ b/ext/wasm/api/README.md @@ -85,17 +85,18 @@ browser client: Installs the `sqlite3.vtab` namespace, which contain helpers for use by downstream code which creates `sqlite3_module` implementations. - **`sqlite3-vfs-opfs.c-pp.js`**\ - is an sqlite3 VFS implementation which supports the Origin-Private - FileSystem (OPFS) as a storage layer to provide persistent storage - for database files in a browser. It requires... + is an sqlite3 VFS implementation which supports the [Origin-Private + FileSystem (OPFS)][OPFS] as a storage layer to provide persistent + storage for database files in a browser. It requires... - **`sqlite3-opfs-async-proxy.js`**\ - is the asynchronous backend part of the OPFS proxy. It speaks - directly to the (async) OPFS API and channels those results back - to its synchronous counterpart. This file, because it must be - started in its own Worker, is not part of the amalgamation. + is the asynchronous backend part of the [OPFS][] proxy. It + speaks directly to the (async) OPFS API and channels those + results back to its synchronous counterpart. This file, because + it must be started in its own Worker, is not part of the + amalgamation. - **`sqlite3-vfs-opfs-sahpool.c-pp.js`**\ - is another sqlite3 VFS supporting the OPFS, but uses a completely - different approach that the above-listed one. + is another sqlite3 VFS supporting the [OPFS][], but uses a + completely different approach that the above-listed one. - **`sqlite3-api-cleanup.js`**\ The previous files do not immediately extend the library. Instead they add callback functions to be called during its @@ -152,7 +153,7 @@ into the build-generated `sqlite3.js` along with `sqlite3-api.js`. flag. This file overwrites the Emscripten-installed `sqlite3InitModule()` function with one which, after the module is loaded, also initializes the asynchronous parts of the sqlite3 - module. For example, the OPFS VFS support. + module. For example, the [OPFS][] VFS support. <a id='c-pp'></a> Preprocessing of Source Files @@ -164,3 +165,6 @@ builds. The preprocessor application itself is in [`c-pp.c`](/file/ext/wasm/c-pp.c) and the complete technical details of such preprocessing are maintained in [`GNUMakefile`](/file/ext/wasm/GNUmakefile). + + +[OPFS]: https://developer.mozilla.org/en-US/docs/Web/API/File_System_API/Origin_private_file_system |