Compare commits

...

219 Commits

Author SHA1 Message Date
drh 0b8e4294d5 Use a separate mutex (SQLITE_MUTEX_STATIC_VFS2) for the VxWorks file list
in os_unix.c.

FossilOrigin-Name: 8f45f1a9d9208fbf124c4087092718b83cd653126bc1ed5f388e3577561f615b
2025-09-10 18:34:09 +00:00
drh e7f190b8e1 If open files in VxWorks, do not unlink the file unless the file was marked
as delete-on-close.

FossilOrigin-Name: bb6114dbbf3bfbea57cd9be21666299663e94576b0175f6aeefd1d0f7107398e
2025-09-09 19:00:55 +00:00
drh 130a2f52b1 Do not allow attempts to open files in VxWorks unless the full pathname is
provided.

FossilOrigin-Name: 4720205249214c01f6e63738e4927c0f53c853346cc2dfa45522aaa469f4d702
2025-09-09 17:39:28 +00:00
drh 4edee00ee0 Fix a potential memory leak in the VxWorks VFS that can occur following
an OOM or I/O error during xOpen().

FossilOrigin-Name: cb880145d899832cca0612b89024a54d188ed706600fa812ea74587d69c261be
2025-09-08 19:56:14 +00:00
drh 91020438c0 In VxWorks, temporary filenames must be full absolute pathnames in order for
vxworksFindFileId() to work.

FossilOrigin-Name: 1fc94becc5971812c3a91fb1410cb54f6ecb9e50da2d30863dc840cbf4e6c1f5
2025-09-08 18:45:58 +00:00
drh b4af09c80e Add the ability to compile with -DOS_VXWORKS=1 on Linux systems, in an
effort to debug the VxWorks capabilities without actually having to
run VxWorks.

FossilOrigin-Name: c87e68d791215729fb513c651e77c6ef6bb260deff37ed2ab6e99b777271bdfe
2025-09-08 17:52:17 +00:00
dan 75ca99ab99 Add "PRAGMA wal_checkpoint = noop" and SQLITE_CHECKPOINT_NOOP. To request a checkpoint that checkpoints zero frames.
FossilOrigin-Name: 4384ad8918801780f2660817dead919020423eb94aa880fff9b04f2d5f5d932f
2025-09-08 15:15:24 +00:00
dan cf0ba94657 Merge trunk changes into this branch.
FossilOrigin-Name: 3bac76a86baae830d4fdc9e4055470d84549fde56b4cf217ebd96cb486554461
2025-09-08 14:40:17 +00:00
dan d7d632d581 Add documentation comment for SQLITE_CHECKPOINT_NOOP.
FossilOrigin-Name: 2b9c495d02724f19ab16612b0e671dfc612f04342222d9901cd0debd08da4cf0
2025-09-08 14:32:32 +00:00
dan 4cefe53a33 Improve documentation of SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER.
FossilOrigin-Name: d7b2fb5363203f475887f277aed4a91e5a83440c169a86b3bf1e4fdf130bbaed
2025-09-06 15:27:01 +00:00
stephan afd432f86e WAL API doc tweaks based on suggestions from [forum:16e94b4bdcfbdc57|forum post 16e94b4bdcf].
FossilOrigin-Name: 1bb7eaf784687cd877c5c0552bb511659767670259e64bc108e7972e356d3cfc
2025-09-05 13:26:24 +00:00
stephan 7aadad63e9 Build portability fixes for HP-UX, reported in [forum:d80ecdaddd885149 | forum post d80ecdaddd8]. The full fix also requires a patch to autosetup/cc-shared.tcl, but that's pending because it's upstream code.
FossilOrigin-Name: 5f38c8aa8fe9993cafde69a85e96e32c283a6bc142238a9d10f3637c93cd474b
2025-09-05 12:14:22 +00:00
dan b9bf2d9382 Add tests to check that SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER is working.
FossilOrigin-Name: beb092d8105e5a1ce95339527bf96799e2ce073591b055f71a5f1dc1d0a0c49c
2025-09-05 11:20:11 +00:00
dan d8d88d9390 Add "PRAGMA wal_checkpoint = noop" and SQLITE_CHECKPOINT_NOOP. To request a checkpoint that checkpoints zero frames.
FossilOrigin-Name: 48be3d020cf0c732557b3d956198a1abcab79424be03f447e2bb89f4d68dc8ff
2025-09-04 19:33:23 +00:00
stephan c0e3a8ca19 Generic doc updates in ext/wasm's makefiles. No functional changes.
FossilOrigin-Name: 02721457cea255a5117a46b77cc87d2e09acb64340ce94089c5b5e6edc5b5033
2025-09-04 18:00:53 +00:00
drh f28c0f37f2 Use Pgno instead of int for the pgno field in the DbpageCursor object.
The same machine code is generated, but using an unsigned value seems
safer in the long run.
[forum:/forumpost/ccec20a858|Forum post ccec20a858].

FossilOrigin-Name: 26ecdde06cce063143144a79c0b4979ed5ec27548da6f127176a420c1c3f17ce
2025-09-04 09:26:53 +00:00
dan 2af776ff59 Fix a typo in a comment in carray.h.
FossilOrigin-Name: a4e137de0e82fbba890c2a608578f02f3666d2c25fb76f95ddf2d6a096a30e6c
2025-09-03 21:19:11 +00:00
stephan 8fb8782e2a Random wasm internal doc cleanups. No code changes.
FossilOrigin-Name: 70923a00cfca2c64b7c7c824325ab75cdd05d452b79d2eaf43297898af891c47
2025-09-03 13:39:15 +00:00
dan 7fa9e45746 Add test case for pushing WHERE constraints into a UNION sub-query that uses virtual tables.
FossilOrigin-Name: 13c80e903ee7f178528918716b11fc0b57fc50b923dcd8aeabf9e6e04e93cdae
2025-09-02 14:59:16 +00:00
stephan 6f341f499a Latest side-stream autosetup/proj.tcl for improved compile-commands feature detection.
FossilOrigin-Name: 55744ca8b8f2f95ba8bd3e01ef89e21e26c8547912c9d5637afe772d17f34486
2025-09-01 13:01:20 +00:00
stephan f91151bfa1 Fix a line-wrap change made in [50234bc9e9fe58da] which broke the docsrc build by splitting a link reference across two lines, which the doc processor does not like. Problem reported in [forum:ea1fe5f421549899 | forum post ea1fe5f4215].
FossilOrigin-Name: 321938063e2d6c579b992bbbed5210c8a051a8b2fe858bb88f95dbd8fb0f35dc
2025-09-01 00:32:43 +00:00
dan 20bfeccb65 Update test script reservebytes.test so that it works with the "prepare" permutation.
FossilOrigin-Name: 4ac774364b693a4b992c997c64bf425e2765133a7a25963cbf2b02c180eeaba5
2025-08-29 16:51:16 +00:00
dan f942995fd2 Ensure POSIX builds work as expected (no extra usleep() calls) if SQLITE_ENABLE_SETLK_TIMEOUT is defined.
FossilOrigin-Name: f04a826bac1620b28c32252fa2ceaccc5dfbb21405a6a98942f95d3d1ca89acb
2025-08-29 15:56:38 +00:00
stephan 62ed0b79da Add 'from a check-out' to the mksqlite3h.tcl manifest instructions.
FossilOrigin-Name: 7728a74ca87934c333a66e46dc1f88ce572473e345d9ff20e5d566c0e26da82d
2025-08-29 11:21:08 +00:00
stephan a00b9b99ba Fix the mksqlite3h.tcl SQLITE_SCM_... changes to work from out-of-tree builds. Problem reported in [forum:812f8d6ff4|forum post 812f8d6ff4].
FossilOrigin-Name: 127f0ab16370fe02b4456669bf60e45ce8c96c4e24b2db3080eaf376d77e0df8
2025-08-29 11:09:20 +00:00
stephan 9976684d26 Remove some commented-out debugging lines and fix a doc typo. No code changes.
FossilOrigin-Name: af32cb3e30ee527a89768b98d8646e2b25d3fb642e61e805187bb3e4613b0960
2025-08-28 17:10:44 +00:00
stephan 8200750eb1 Add macros SQLITE_SCM_BRANCH/TAGS/DATETIME to sqlite3.h, pulled from the fossil-generated manifest.tags.
FossilOrigin-Name: db6b6240ad465f865dd2ca8fa0cdfba8b5315c45041b91b76efade6427c213e1
2025-08-28 17:05:37 +00:00
stephan dca1f04f07 Remove sqlite3expert.h from the compiler invocation for that tool, as it (A) doesn't need to be there and (B) it causes some compilers problems (as reported in [forum:a1085109e7db4cf3 | forum post a1085109e7]). This bug was faithfully carried over from the legacy build.
FossilOrigin-Name: 9f0a16f6e893d51f760a8c1e2cb4709fdd16ccb2c0258695767f8305f407f4ac
2025-08-28 15:04:52 +00:00
dan 1df00568b3 Add test to ensure that changing the number of reserved bytes in a database using VACUUM does not confuse other connections in stock SQLite.
FossilOrigin-Name: 6bf54bbc4d503e8ebeb804dfb318383770e85d434dacbbbd8f6dadc7595b1856
2025-08-27 11:21:44 +00:00
dan f8b5cc695c Fix a typo in a comment.
FossilOrigin-Name: d2a74d5c36f600fa8d7dc03f6914482a2afca6e4ff557a0007d14f4304645ba1
2025-08-25 16:41:04 +00:00
dan 3c2b02d919 Check that certain ON clauses do not refer to tables to their right as a separate step after parsing a SELECT statement, instead of as part of the planner stage. For for [forum:ccfb3b5052 | forum post ccfb3b5052].
FossilOrigin-Name: e0beda7ffe92abf6322db8314c42940adab7f89a35d38124355cb3464ee70b9f
2025-08-25 14:27:31 +00:00
drh 08a256958f For the --pagecache option of the CLI, if the SIZE parameter is a
power-of-two, automatically round it up to using the PCACHE_HDRSZ.

FossilOrigin-Name: e7a2ba842cb571df66d204b8d5989ecdc78be7205fdaf1de1783c63c9118d465
2025-08-25 13:04:26 +00:00
dan 7af1d61886 Add test case to this branch to show that it handles cases where ON clauses use select-list aliases to refer to columns to their right.
FossilOrigin-Name: 4d34ab4acf0343a22ea8097fa4b1e87a1b0a13be864d5bee0c7a8341c09b8002
2025-08-25 11:47:15 +00:00
drh c6925d5922 Small simplification to the query flattener logic.
FossilOrigin-Name: cbfe3f0c84eecef4308e1904cce4fe013ee1986ab6c85e82f92736fc80c0a358
2025-08-23 18:18:03 +00:00
dan 4bace197e1 Fix the cases in joinI.test on this branch.
FossilOrigin-Name: 23ac2377315af02b73db6ae37bfeeda1453e41efb702a6b707346956c2d41a9d
2025-08-23 16:26:36 +00:00
drh 81b8ad0830 Fix cksumvfs test case added by [e3bd1feccaee8ff2] so that it works
with varying page sizes.  Test case change only - no changes to code.

FossilOrigin-Name: b6f8f086dacd11f57bdb0eef79f25bce209816a0748f16009372c62dc3edd5ae
2025-08-23 11:09:53 +00:00
drh b33477c5b4 Fix the sqlite3SetJoinExpr() routine so that it correctly sets the
join flags on CASE expressions.

FossilOrigin-Name: a4107c947c03ed48de3ab3f516cec8a3c092cec8ee19145fb564152e5cd16c85
2025-08-22 21:46:22 +00:00
drh d271627f96 Steal the test/joinI.test from the on-clause-error-fix branch that
demonstrates that this branch does not work.

FossilOrigin-Name: d163535ec8d463d74112d38a606fa4d900e66deb1a414c947973cd1880e41526
2025-08-22 19:30:26 +00:00
drh fbb07ff67f Remember if a SELECT statement contains an ON clause. If it does, then after
name resolution, scan the WHERE clause to verify that the ON clause does not
reference tables to its right.

FossilOrigin-Name: 0ec8a8f64434f8cc04f02a356ecaa409ebd886566ba09c32f0fff8ebd103a609
2025-08-22 19:17:44 +00:00
drh db97d2ef81 Enhance treeview so that it shows the contents of ON clauses while
they are still attached to the SrcItem object and before they are
moved into the WHERE clause.

FossilOrigin-Name: 3e285bc117bcbfafe083709d27cca776d6ba418a9f0f58a6d4178035fba2d6ca
2025-08-22 18:19:26 +00:00
drh 6f15549f91 Experimental minor simplification of the query flattener.
FossilOrigin-Name: 953ea637d51192a6fb9c2ae84e097ae14e8a9c7fa7c98db90a39819b5f97f60e
2025-08-22 16:34:55 +00:00
drh 90916e5ba0 Fix a minor typo in a comment.
FossilOrigin-Name: 9ada44eb6d26532e45cdd2ed8d5707f1734d0177a13b493ff9cf070e0a992522
2025-08-21 18:47:01 +00:00
stephan 8376b87ae3 Add config as an alias for the reconfigure makefile target. Minor makefile doc tweaks. Random typo fixes in shell.c.in and tclsqlite.h pointed out by the misspell makefile target. No code changes.
FossilOrigin-Name: 9f15182776b30676c9aae9bcb5d4ad7580359fbdd607c2a9227c9cf2c81a4054
2025-08-21 17:59:28 +00:00
stephan 1702244d2e Remove some resolved TODOs from the makefile. Ensure that testfixture links against TCL_LIBS.
FossilOrigin-Name: b7751d144330593b5d41cb50e44b5134baad722be65173a7f55887f5e86a8c9d
2025-08-21 17:39:44 +00:00
drh bb4743c278 The sqlite3_prepare() and similar interfaces should not return
SQLITE_ERROR_RETRY.
[forum:/forumpost/aa61ab56adb56159|Forum post aa61ab56].

FossilOrigin-Name: 4e473cf0c21dd78d457f5728086372464e82de95c5431a2587efd580f5076291
2025-08-20 23:29:59 +00:00
drh 5e972ddd9f Add an assert() to prove that sqlite3_prepare() does not return
SQLITE_ERROR_RETRY.

FossilOrigin-Name: 6c6a8a596f5d578cc7d35c577608492c0314cdb84ed67b9f068d90fb0b42f4de
2025-08-20 23:13:49 +00:00
drh 51d3e6d51c Change a newly unreachable branch into an ALWAYS().
FossilOrigin-Name: 99556be3fd99e6b7c520b0ae2090f59c6f58375750f9d571f9f586bce0a21504
2025-08-20 21:12:40 +00:00
dan 1be5689087 Avoid returning SQLITE_ERROR_RETRY if collation sequences associated with the table's PK cannot be found when creating an index. Possible fix for [forum:aa61ab56ad | forum post aa61ab56ad].
FossilOrigin-Name: ac649e5b9ca9b8f7729defa8d646df8c0cb57977a5eedcfa2cf1147d109a17f1
2025-08-20 15:42:23 +00:00
dan c30e1a10ef Fix a problem with SQLITE_CHANGESET_CONFLICT conflicts caused by DELETE triggers within a call to sqlite3changset_apply_v2() with SQLITE_CHANGESETAPPLY_IGNORENOOP specified.
FossilOrigin-Name: 138e2aab43ac07aaf8c5389105ff6d3e107ff2d35badcb48233664fcb9661471
2025-08-20 11:21:35 +00:00
stephan 4a27581f14 In builds without HAVE_FCHMOD (e.g. WASI), make the chmod() of temp files a no-op, analog to how lack of HAVE_FCHOWN is handled, as discussed in [forum:98d5158d3fdd7a41 | forum post 98d5158d3f].
FossilOrigin-Name: 7d13e8e403ba00d37b950caa359d74452319247495284d252efa6473bad15b64
2025-08-20 09:43:15 +00:00
dan 697d29ea49 Fix a problem causing an SQLITE_CHANGESET_DATA conflict of a DELETE operation to be incorrectly ignored if the SQLITE_CHANGESETAPPLY_IGNORENOOP is specified.
FossilOrigin-Name: 78b543f85ac6643f3b69bf1250c6362f00e030f93f460ef7d04902682ef64ee9
2025-08-19 21:35:23 +00:00
stephan 7f84ce0ea9 Add a doc sentence about sqlite3_set_clientdata()'s result value, per request in [forum:bda6c22b6a | forum post bda6c22b6a]. No code changes.
FossilOrigin-Name: c664cee321fc449283ecfc073c45057c078299be33dc0c170b156d81a6698b55
2025-08-16 10:17:04 +00:00
dan a6c95406c1 Avoid depending on HAVE_STDINT_H and SQLITE_PTRSIZE and other things in non-amalgamation builds of fts5.
FossilOrigin-Name: 309fdd496673bf58984fb16aef3d4cc2ad8c9f6dad7687509f4d708fed5ba41b
2025-08-14 19:36:59 +00:00
stephan e3fc1fc8dd Minor internal cleanups in the configure script. No behavioral changes.
FossilOrigin-Name: c42269e5ce3688fccee16cf35e1101f36afc3ccc19bef57b177d46c84db2435a
2025-08-13 19:59:37 +00:00
dan 6f097125cd Have cksumvfs write checksums to the database file only, not the wal file. Writing them to the wal file breaks wal file recovery.
FossilOrigin-Name: e3bd1feccaee8ff2f68b7b863769dd739e8a434fd32fed73deeeec885628311c
2025-08-13 19:13:16 +00:00
dan 0e77c3fa4d In cksumvfs, do not write checksums to the wal file, as this prevents recovery from working.
FossilOrigin-Name: 5bf48c7e31904f1f7048499c630801846df89f262b32ea1e49fb6e039eaad11a
2025-08-13 18:37:41 +00:00
stephan 527062ac5e Minor autosetup/README.md tweaks.
FossilOrigin-Name: bd7530bf6afdad391b223651632e1b4d59ab5ec806c7a94daadc7f09091321f4
2025-08-13 18:30:42 +00:00
stephan 656563cce9 Move the forced NDEBUG in fts3Int.h up above the #include of assert.h, as reported in [forum:8f16dd9480aad85f | forum post 8f16dd9480aad85f].
FossilOrigin-Name: 3b06d1c9b6c03f38029a8b98fef6253647878c0f8b05447ec0c8122f189c90dc
2025-08-13 17:58:47 +00:00
stephan 6cebfa56cc Doc updates in the configure script. No functional changes.
FossilOrigin-Name: 47c4a2ddd1966aa8564e105fc1f2ba3c9c1668b44d4979424f65148d7976064c
2025-08-13 16:49:55 +00:00
dan 8e875fa3bd Fix a problem with the checksum-vfs and direct-overflow-reads. Forum post [forum:350e147cd1 | 350e147cd1].
FossilOrigin-Name: 7b7ce5f17fd63932a050b917b4356c23eec6040d1c4f51136393d7c6e3d40a63
2025-08-13 14:40:24 +00:00
dan c5c9c6093b Fix a problem with the checksum-vfs and direct-overflow-reads.
FossilOrigin-Name: 8288edb9f930206f117823cf1d18af632dc6adbd7c4c3b9bcfc252e1a5e5b9cd
2025-08-13 14:35:14 +00:00
stephan 16478dbfdd Doc cleanups in main.mk. No functional changes.
FossilOrigin-Name: 839c998443880161af06b9f7470ebfc828251c3c1accdae5f0fbbcc13408474c
2025-08-13 11:46:05 +00:00
dan a939a635a2 Fix a problem with reading wal mode databases from UNC shares on windows introduced by [e88212b10a7829ff].
FossilOrigin-Name: f341e7812984b41acd7dd2dd795a1716a8826af4326578dcdf7d7fdd55124ceb
2025-08-12 19:02:48 +00:00
dan 3f85939bf0 Fix a problem building testfixture on non SQLITE_OS_WIN platforms.
FossilOrigin-Name: 9e6fa73467892eb2333c0a94ca38b66b7cc0432326de93ff131ecde4c165114e
2025-08-12 18:57:02 +00:00
dan b1406a6550 On windows, when opening a UNC path, fall back to using a single file handle shared between all connections for locking.
FossilOrigin-Name: 5c0202d96c3a20a2cbcd38eba5e62371606894a0cbc2da4f60e10a1b5fa7bd04
2025-08-12 17:55:34 +00:00
drh 1ecc135cc5 The off-by-one fix at [3e627d66ebdef8df] is insufficient. An index
can hold twice as many columns as a table, if the table is a WITHOUT ROWID
table.  The limit should be twice the maximum, not just one more than the
maximum.  Problem discovered by OSSFuzz.

FossilOrigin-Name: a836126bbec5c14432ed7fc7e9e6f8ebcd5dd1116d3ac8a9a0d25c8f62cc51fe
2025-08-11 13:17:10 +00:00
dan 9081b89720 Replace some 32-bit arithmetic in fts3_write.c with 64-bit to avoid the possibility of integer overflow.
FossilOrigin-Name: 6711110b1c7589311f012deee4d4dd5b771fa44ad328b471c9ef583960795199
2025-08-11 10:54:39 +00:00
stephan 88f7807fa6 Add an explicit call to sqlite3_initialize() to sqlite3_rsync so that it works when built with SQLITE_OMIT_AUTOINIT, as suggested in [forum:c4ec6b33097b8536 | forum post c4ec6b33097b8536].
FossilOrigin-Name: 8c9db6237154d1c153916ed821f576f91b353bf988182127d2a619506707d6bd
2025-08-07 20:20:22 +00:00
stephan 11ba513fe5 Skip checking for dlopen() on mingw builds and those which include "windows" in their host tuple, as suggested in [forum:2436c8ffed | forum post 2436c8ffed]. Those environments identify as Windows for SQLite's purposes so use LoadLibrary().
FossilOrigin-Name: 69b87d4fa8089ef6101e976131dfd5c47dbc3d8c01a7e7d90a444b7a4794f78b
2025-08-06 19:16:16 +00:00
drh e7440380c2 Do not allow the number of terms in an ORDER BY or GROUP BY clause to
exceed the maximum number of columns in a table.

FossilOrigin-Name: 139e587c7b349e771d67a8b4ee02ab3ad5d5712d4ff4713dad63cb765bdee248
2025-08-06 19:12:10 +00:00
drh e6061cba7f Fix Windows makefile breakage caused by [ae9d7c9c922bb241].
FossilOrigin-Name: c41324139d6a75b0d37aeec2b0572c63207dd0b06e6a99e4fb221be564e73024
2025-08-06 19:05:39 +00:00
stephan 5d06c6b3f1 Add *.obj to the make clean target for the sake of the Unix-on-Windows environments.
FossilOrigin-Name: da07e0c02fe7de7b67f2564c29f49f251ae2374c0e269d246bd13e68a9a73328
2025-08-06 16:51:12 +00:00
stephan de048aeda9 Extend the sqlite3_rsync PATH to include /opt/local/bin, per request in [forum:ca3c1bb7ca8e03 | forum post ca3c1bb7ca8e03].
FossilOrigin-Name: 79a14a5ebd0e8a0aa7f7bb180fcaa348a3ecd046662e3ee05a34f2c9a7db3dd6
2025-08-06 15:57:44 +00:00
drh 7270a56fdf Minor bug fixes in the script added by the previous check-in
FossilOrigin-Name: 2e1a2db3f92b0bd484d979b422fe28e86732121594d190b76dbf46f5d7533643
2025-08-06 12:47:58 +00:00
drh aa86b2a373 Add a script to build ARM64EC binaries on Windows11 for ARM64.
FossilOrigin-Name: 2d5b74b84a9c778183a11070623e89b553ba9cde905b779dbf115ea95aa0ca9b
2025-08-06 12:43:06 +00:00
drh ff1d5e5bb8 Fix a possible printf() of a NULL string in fuzzcheck. (Passing a NULL to
"%s" in SQLite's internal printf() prints the text
"NULL", but it apparently segfaults glibc.  Whatever.)
[forum:/forumpost/e07d56579b|Forum post e07d56579b].

FossilOrigin-Name: 4ec69baf4f2a75585b92388cbc352836116381dce3f2d44a3b0f7d3360a17cf0
2025-08-05 23:01:31 +00:00
drh cd70a44d45 Remove the <i>experimental</i> lsm1 extension from trunk, in as much as
readers were thinking that this was a supported extension and were reporting
bugs against it.

FossilOrigin-Name: ae9d7c9c922bb241363aa690b42b9664c4ad6e76ed5ce474daf1ab44461bc6a3
2025-08-05 12:01:43 +00:00
drh 332eb8e63c Add bounds checking and error messages and improved comments
to the (unused) zorder extension function.
[forum:/forumpost/e3f1ede174|Forum post e3f1ede174]

FossilOrigin-Name: 6bb717acf706e6ffd4671660ca78237e6a42863f344518e6d21065bf735f971e
2025-08-05 10:54:56 +00:00
drh f9c2cff2fe Improved defenses against corrupt ZIP archives in the zipfile extension.
FossilOrigin-Name: 642e89191deaf75db236102248c662aeef65bcd3dcbdfea694256583556be75f
2025-08-05 01:53:03 +00:00
drh eff534e1a5 Back out a recently added NEVER().
FossilOrigin-Name: 4fcdd5bdb061d550b4a35594eb16c9a1699c76caf1d906f1781b4f9cb29ac80c
2025-08-05 00:16:40 +00:00
drh a37bf61539 Fix a bug in the fuzzcheck.c test program introduced by [1cccea0508f5c8b8].
FossilOrigin-Name: 90b217e11c988785d19b8efbba435250c120837492f430cf16d6d4524dd55136
2025-08-04 23:37:48 +00:00
drh d7d77eb56d When doing an indexed row-value comparison using an IN operator where the
order of the columns in the row-value need to be rearranged in order to match
the index, be sure to make affinity conversions before the rearranging of
columns so that the correct affinity is applied.  Fix for the bug
reported by [forum:/forumpost/eab63506cf|forum post eab63506cf].  This
problem goes back almost nine years to [ddb5f0558c445699].

FossilOrigin-Name: 8800c13deca3717c8a9bed42ef5f09752e4ca8a31adfb4ab0545e0e2b5684bd0
2025-08-04 23:05:35 +00:00
dan 82b08cc8ef Add an assert() to verify that IN_INDEX_NOOP is not used for vector operations.
FossilOrigin-Name: 49c587c6d204841a3d26f183812913ebd585006259040fdf7ba68346cc75580a
2025-08-04 20:48:37 +00:00
drh e318c4573b Remove the "experimental" mark the snapshot interfaces.
FossilOrigin-Name: 015dc43f628a6f5054152b05b20eb03b6a1153231f824c910a4416792af05272
2025-08-04 19:35:20 +00:00
drh 8725bf916d Fix harmless compiler warnings arising from [1cccea0508f5c8b8].
FossilOrigin-Name: d682557464a6069a93f890bb0aa983cea020ccde8261335ceeab19b9b6423863
2025-08-04 11:50:41 +00:00
stephan 1f4c281b0b Minor doc typo fix in sqliteLimit.h.
FossilOrigin-Name: 8bb315ef7429a60899f5afe878a3b1aa146b18eef2ac9f4d6eca98587a2255cd
2025-08-04 11:20:31 +00:00
stephan 1cf61ce636 Add a note to sqlite3_deserialize() that a schema name of NULL implies the main db, a former shortcoming pointed out in [forum:0543d8aa8e|forum post 0543d8aa8e].
FossilOrigin-Name: 50234bc9e9fe58daf820ed5a1355f1d173728b5d33a7534244f1acff974baa30
2025-08-03 08:56:16 +00:00
drh cd552cf99f Tag a condition in os_unix.c as unreachable.
FossilOrigin-Name: 151844ad5451295104f18f4823d2fdaf041f22bc09099f1fa3f90898aafa7ea5
2025-08-02 17:37:59 +00:00
stephan 8c30f16a2e Fiddle: move the About button into the main toolbar. Extend the About text with some info which only shows up (or is only hidden) when terminal mode is available.
FossilOrigin-Name: da524d6c61330fb004dade810c5ad84bb6d37625786c1d0fd473593f2448d904
2025-08-02 15:04:50 +00:00
stephan f681a9a7d8 Fiddle: make the toolbar visible in terminal mode and hide non-terminal-mode options when in terminal mode. Move the terminal/split-view toggle button into the toolbar. Improve the view-switching handling.
FossilOrigin-Name: 711bf423d213a2c468c32a48c0b09927cdfdffce36e5e4a3b35a32bfa055ff82
2025-08-02 14:50:01 +00:00
stephan 380ef6006b Fiddle: move the About button into the header bar and get it working together with the optional jquery.terminal console mode.
FossilOrigin-Name: 9639382c5478115df7c1584c14a52c176fe747df73078419be4ab276374a704b
2025-08-02 13:21:07 +00:00
stephan a0e569d5ba Fiddle: add an about/info/help view and a button to toggle it. Change the color schema to a more conventional black/white. Force imported databases out of WAL mode, which doesn't work in fiddle.
FossilOrigin-Name: 27d1d0100c0cb6e5c0c576be0f99209bb905f302008d8c257039adf8c5402f7d
2025-08-02 12:06:37 +00:00
drh 46c7568db5 Ensure that stack space allocated for a flexible array has the correct
alignment.  Fix to [d4307a0d43f42e96] to for some compilers
(DeveloperStudio) and platforms (Sparc).

FossilOrigin-Name: 1cccea0508f5c8b8ff751f407873713adc33f8642dcb6cdd495fd2d72ebcbdd3
2025-07-31 12:25:23 +00:00
stephan 210b182b79 Generic JS doc touchups. No functional changes.
FossilOrigin-Name: cc5f126ea4fa4a1abf183c95d151a7e9bd151b90c5c581d3be56db23bbe05a19
2025-07-31 09:54:09 +00:00
drh 1e687a4187 On MacOS, when increasing the size of files on FAT filesystems from 0 to
1 byte in order to preserve their inode numbers, be sure to fsync() the file.

FossilOrigin-Name: 727efa8559852012cf3381baf5fcb1da198ff27d8856ce7b813920b99367dee5
2025-07-31 09:45:20 +00:00
stephan 67695a30ea Minor doc and consistency improvements to [cf7163f82ca380958].
FossilOrigin-Name: 690a7273226df361f3eaa90f9b693ba554ed9d9456c19c5d3a12e812eca49eab
2025-07-31 07:44:18 +00:00
stephan 3e616d3445 Back out [e283d817e3a9] because further testing has proven it unnecessary.
FossilOrigin-Name: 7318a00de64ec89c2a08d86e9f50c694894c4b59b07ff52b0d1f9f0ab8c4df44
2025-07-30 21:39:27 +00:00
stephan d38777134b Move the flexarray union members from [527bbc1676a85a9] to the end of their respective objects.
FossilOrigin-Name: 3082e07926695863bd5ef51c3c4803fbe267dc0d9b6ac9a717c225459f8988ba
2025-07-30 21:34:47 +00:00
stephan df23b518da Apply alignment-related patches suggested in [forum:41cd226375cd49c6 | forum post 41cd226375].
FossilOrigin-Name: 527bbc1676a85a927352cd10a292afe041a72692ec0b1360e5a1ccaa19a32fcb
2025-07-30 19:48:12 +00:00
drh 7957c70947 Default pointer size for the __SUNPRO_C compiler is 4 bytes.
FossilOrigin-Name: e283d817e3a93a3cd42c7b79e08e5fb61cb4fa4734137b92f1748dbbe8b8b919
2025-07-30 18:23:33 +00:00
stephan b79848edd4 JS: ensure that sqlite3WorkerPromiser.v2.defaultConfig initially refers to sqlite3WorkerPromiser.defaultConfig. This fixes a longstanding oversight rather than a known in-the-wild problem.
FossilOrigin-Name: cf7163f82ca380958a79350473b2c5a2cebda7496d6d575fa2835c362010fea1
2025-07-30 16:17:14 +00:00
stephan 1560d52f82 Adjust the previous check-in to replace the db's WASM address with yet another random number, and increase the range of random numbers, reducing the chance of cross-worker db ID collision to 1 in many billions.
FossilOrigin-Name: f5e2a72c57e802c5042ab8343e5009ba9f22ca7138a1c78f4b8201ab9b4fd395
2025-07-30 15:02:32 +00:00
stephan f402509b62 JS: add a random element when assigning db IDs to Worker1 db instances. This addresses [https://github.com/sqlite/sqlite-wasm/issues/113 | the npm project's ticket #113], which demonstrates that two independent workers can end up generating non-globally-unique IDs. That's not a bug, per se, but it makes the IDs useless for client-side mapping of db connection IDs to client-side state, so we add some randomness to them.
FossilOrigin-Name: 6d2a43075fda9c4eae28f9ca4aaf459c41d305c861947a47fb2cbd513249c4b9
2025-07-30 14:50:44 +00:00
drh bac6793a8a Enhance the printf formatter for %#f such that the minus sign is omitted
if the '+' is missing and all digits shown in the rendering are zero.
Thus, for example, '%#.2f' renders -0.004 as "0.00" instead of "-0.00".

FossilOrigin-Name: 09e1d7c7b4615262dd03adf1be201122f3cb8909ad381d67f51c812f07e25719
2025-07-30 13:37:49 +00:00
dan 7423ecb0a9 Fix SQLITE_OMIT_WAL builds on windows.
FossilOrigin-Name: 575271c3ae53c64784a2aa1e9b7c6cdcb0402022967155dd176a6b1f1e560b50
2025-07-29 11:04:32 +00:00
drh 7bcb650f57 Add new extended error codes to SQLITE_ERROR and SQLITE_IOERR, for use
by extensions.

FossilOrigin-Name: 02b241bc4ce72d50a8d7621a663e759443b532a5ff9354fc3266ad6bb9433ed4
2025-07-26 12:51:18 +00:00
drh 6d7be8293e Do not apply the [/info/e33da6d5dc964db8|EXISTS-to-JOIN optimization] if
the subquery contains a LIMIT clause.
[forum:/forumpost/2025-07-23T10:59:14z|forum post 2025-07-23T10:59:14z].

FossilOrigin-Name: 314c493f273a34dff7b9f954e7553bc540bbcf5b913f779ef9ce0b9ba11acf7a
2025-07-23 12:48:16 +00:00
drh 5a6f651397 Fix a potentially uninitialized field in the WhereLoop object that is used
as part of the skip-ahead-distinct optimization.  This fixes various
[forum:/timeline?ymd=20250722&u=yxchen&vfx|recent forum reports from yxchen].

FossilOrigin-Name: c10f9970c6a3ffacaef0f0728fc7ff11011686835dc78ca43035c0493e0af319
2025-07-22 15:51:41 +00:00
stephan d649d7b90c Apply [ebb346c5aa]'s change to sqlite3.1, as reported in [forum:bf92f78344 | forum post bf92f78344].
FossilOrigin-Name: 477211be60cd873d078293f0dd767506c069c3dd83bc1759ae7258d4d3dff359
2025-07-21 18:00:44 +00:00
stephan 095d399e7c Ensure that certain local files are not inadvertently carried over into the snapshot tarball and causing confusing build results.
FossilOrigin-Name: 47fdf7ed2cad7ec56118cf4f77297b1178cd2104a21b19d4afad46437a944378
2025-07-20 18:29:35 +00:00
stephan fdd37e9637 Teach autoconf/tea/configure to be able to run from the canonical source tree so that a snapshot build or appropriate symlinks are not necessary in order to test the extension.
FossilOrigin-Name: 71b9365b848d9b2bc75336ebbec815eba3a7ed5168798759753a990a1b706fc8
2025-07-20 18:05:45 +00:00
drh 2445ee0e37 Factor out the unusual encoding-change case from vdbeCompareMemString() for
a performance improvement in the common case, and a small size reduction.

FossilOrigin-Name: cbd46ab8a8b4622f42dd9f87f28b812c1d6fa5ea73a4e8f1253514455f397783
2025-07-19 20:10:07 +00:00
drh ea8f9708c5 Small performance optimization in sqlite3VdbeRecordUnpack().
FossilOrigin-Name: eae168def2ff11f57f730f8a3bd86748b0943077e37b2709c10de0aecff664ec
2025-07-19 19:54:44 +00:00
drh bcd14a0a3e Split the (internal) sqlite3VdbeCheckFk() routine into two variants,
sqlite3VdbeCheckFkImmediate() and sqlite3VdbeCheckFkDeferred(), which
run faster than the combined general-purpose variant.

FossilOrigin-Name: 872b1b52ed93ef85911c2ef87b15673f9e102aef564f208e0a916af62671df93
2025-07-19 18:46:03 +00:00
drh c585e03a4b Use fewer CPU cycles to commit a read transaction.
FossilOrigin-Name: 861e55656abb208b4f1f2c8808c76c0454427af85a8930ab53f9c053605f39c7
2025-07-19 18:17:06 +00:00
stephan 1f436ad563 Add SQLITE_SELFORDER1 to JS's sqlite3.capi namespace. It's only useful when built with an sqlite3.c which itself was created with -DSQLITE_ENABLE_ORDERED_SET_AGGREGATES, which the canonical build does not do but custom builds may.
FossilOrigin-Name: fdd15e938ccfac9e871d781d1c8fe8be6dbd9e8cbbcb8b7f0b035e5ceebb8746
2025-07-18 22:18:41 +00:00
drh daa4cdf84a Fix a minor comment inaccuracy.
FossilOrigin-Name: b66fcb61a1d044fa18419ab382a8b159e9b6bb52956917d8a9de4dccf8dc9a87
2025-07-18 19:17:32 +00:00
drh bae748a76e Increase the precision of the "real time" output from the ".timer" command
in the CLI from milliseconds to microseconds.

FossilOrigin-Name: c5dbe93114d318fea431859e388af74aeb4cb854c514c9910590441c990321f3
2025-07-18 17:40:34 +00:00
drh 74cc109780 Ensure that the accumulator for an aggregate always gets initialized,
even when the aggregate is on the right side of a LEFT JOIN and never
gets evaluated.  This fixes a problem introduced by [663f5dd32d9db832]
and found by dbsqlfuzz.  Test cases in TH3.

FossilOrigin-Name: 235cf6586b9ac914a32bd8adfd460daae998687f02f0998a7aa3c6bfc857d1c9
2025-07-18 12:10:15 +00:00
stephan 01a2953350 Pedantic internal build doc fix.
FossilOrigin-Name: 9ef429a8507745e0a6fae4f0ec1dc2b142dad1357f9a7ff576e7834c8ff5c6fe
2025-07-17 19:18:01 +00:00
stephan cf05295a85 Diverse wasm build cleanups.
FossilOrigin-Name: 14ca18f72a7edde7c65a6c6b23fdc3f5ed6860371795926045c987f7b2c75e1b
2025-07-16 20:50:40 +00:00
dan 91db1c413b Fix vtabH.test so that it works on windows even if there are files that begin with "$" in the root directory.
FossilOrigin-Name: 19a79219a7d52272102ff09d19e6b9b87e88e0070592fd7e6040bd8ce66ad238
2025-07-16 17:24:31 +00:00
stephan 10687e283a Remove some stray makefile debug output.
FossilOrigin-Name: 7ef22c3d11088210d2267375ec188bd352b067614200394b9877f2e40dc12bb2
2025-07-16 16:56:33 +00:00
stephan 074b1aa42d In the wasm makefiles, replace X:=Y with X=Y because := has different semantics depending on the make impl and its use is arguably a bad muscle-memory habit worth breaking. These makefiles are very specifically for GNU make, but long-term it would be nice to eliminate that requirement.
FossilOrigin-Name: d4203311a2f39189ed8f30d519468aed8983af7772a5b247e7557d3e1936064e
2025-07-16 14:51:23 +00:00
stephan 522ce56734 wasm: remove some extraneous levels of makefile var and fix the (unsupported) wasmfs speedtest1 build to account for var renaming which happened long before this.
FossilOrigin-Name: 35b2315343e22ca12c6ee3f5be8741eba889bb6461e08fad0a8ae7db033319cb
2025-07-16 13:22:38 +00:00
stephan 68b74e2c42 Remove an unnecessary step from the wasm builds and account for a recent Emscripten-internal code-generation change which caused a post-build cleanup step to not actually clean up (harmless, but adds about 26k of useless stuff to the resulting JS).
FossilOrigin-Name: a8ed16989dcd324bd9caa09aec7979249deaf59ca13bc377379ddd83c53379cd
2025-07-16 11:56:16 +00:00
stephan e5a7b815af Further internal wasm build cleanups. No functional changes.
FossilOrigin-Name: 8364d89c3bc1d1dbd95b4324a41bd655251ebd2da5b9f1b9f9aceba9c3d26d3d
2025-07-16 11:09:18 +00:00
stephan f98148be9c Internal refactoring of the WASM build makefile rule generator, working towards parallelizing the various build modes (which is not currently possible because most modes share the same sqlite3.wasm output file name).
FossilOrigin-Name: 1062b61e9c949d76791ed7974cf6c38d1cec9797a930e9ad7ca851130f5e9a48
2025-07-16 10:34:14 +00:00
stephan 27e13f4f3a Teach the sqlite3 CLI shell to look in XDG_STATE_HOME for the CLI history file before falling back to its historical location in the user's home directory.
FossilOrigin-Name: 1e663374c3fcc20ab0b3250aa1ff9d5e5ac391c89808ad589aa30c8882d4b61e
2025-07-16 09:27:55 +00:00
dan 81e9bbf8da Avoid evaluating special vtab operators (e.g. MATCH) that are part of ON clauses attached to left joins from being evaluated too early. Fix for [forum:/forumpost/428ef7c468 | forum post 428ef7c468].
FossilOrigin-Name: 9f184f8dfa5ef6d57e10376adc30e0060ceda07d283c23dfdfe3dbdd6608f839
2025-07-15 19:00:01 +00:00
dan 7d20c2e8a3 Add test case to between.test.
FossilOrigin-Name: ffebbb7ae977adc6c729d30b51f2ff29d416e018d82e450d87ccd973472819c8
2025-07-15 18:51:46 +00:00
dan 192d0ff8cc Optimize allocation of large tombstone arrays in fts5.
FossilOrigin-Name: 0fcc3cbdfa21adf97aed01fa76991cccf9380e2755b0182a9e2c94e3c8fb38d7
2025-07-15 14:06:15 +00:00
drh 97e6368abc Add the snapshot-zip makefile targets for both Windows and Posix.
FossilOrigin-Name: 8c73c0c5935431556f687556bfdb459754609f07c6366c810a55bf7583ee303d
2025-07-14 18:27:32 +00:00
drh 1c11aa3da2 Enhance the "mktoolzip.tcl" script (used by the "tool-zip" makefile target) so that
it uses "fossil test-filezip" to build the ZIP archive if available, and so that
it also generates windows-dll-*.zip on Windows platforms.

FossilOrigin-Name: 63ddc215eb6106985c53d3c8d99f5445a92acf4359a6bb2681882c49583df871
2025-07-14 16:05:59 +00:00
dan bf5f1f5172 In rtree.c, ensure that the pReadAux statement is reset whenever the bAuxValid flag is cleared. Fix for [forum:/forumpost/3e45ed31d8 | forum post 3e45ed31d8].
FossilOrigin-Name: 3c0afda372cd688e9aff7be1c0a41f557c8c8819f5f47420166ce8255cd806c8
2025-07-14 15:40:25 +00:00
dan 194f0bada7 In rtree.c, ensure that the pReadAux statement is reset whenever the bAuxValid flag is cleared. Possible fix for [forum:/forumpost/3e45ed31d8 | forum post 3e45ed31d8].
FossilOrigin-Name: 1740f9a09850f6647fc1f6384353d89a1ac0b2b15c429b576b6014eada71937e
2025-07-14 15:34:11 +00:00
dan 08f8111bd8 Add new sessions function sqlite3changeset_apply_v3() and its streaming equivalent. This allows changesets to be filtered on a per-change basis, not just per-table.
FossilOrigin-Name: 10ebd7a119ef1985755ef143a941fbaed1b5ca1c8a71e011c8bbc70e383fd337
2025-07-14 14:51:43 +00:00
drh f8addcf937 Fix harmless compiler warnings in builds that use SQLITE_OMIT_DATETIME_FUNCS.
FossilOrigin-Name: e11fbf9fd630a7de2e0b0e4b67dded05b905b2a0ba04aa7e915ca9df2d9ebe21
2025-07-14 09:41:59 +00:00
dan bcfe38b96a Avoid evaluating special vtab operators (e.g. MATCH) that are part of ON clauses attached to left joins from being evaluated too early. Possible fix for [forum:/forumpost/428ef7c468 | forum post 428ef7c468].
FossilOrigin-Name: 18ba07c152294a96d510a7851a0860f982ff1e0725afeebed9a343f550f6925a
2025-07-12 18:14:41 +00:00
stephan 1b8f6558f8 wasm: introduce the sqlite3.oo1.DB.wrapHandle() and Stmt.wrapHandle() APIs, which enable clients to wrap (sqlite3*) resp. (sqlite3_stmt*) pointers in their oo1 API counterparts, optionally with or without taking over ownership of the pointer.
FossilOrigin-Name: e5d079549594ca44852773b8919894866394e47ad725dadc7f65242413a219d3
2025-07-11 19:52:36 +00:00
stephan 1f68085849 Clearer docs for the unowned db/stmt handle mechanism.
FossilOrigin-Name: 53401b5435e30c4b47b6e203976b714d616246d734b5876a34f53f6388f872f8
2025-07-11 19:44:42 +00:00
stephan c493e4516a Correct a one-too-many-exclamation-points bug which caused the opposite of intended semantics in oo1.Stmt.pointer ownership.
FossilOrigin-Name: 91e709f36d36174534b4cf4ff548a558e66cca5e23a6c8c106bc43375fc3ce72
2025-07-11 19:34:30 +00:00
drh 69b5674b40 Additional header comment documentation in the ext/misc/vtablog.c test extension.
FossilOrigin-Name: 3656acfaa3011321a6e17fb81e5bdedcfffeab6035f133ab89ae9589bf5bef72
2025-07-11 17:02:11 +00:00
stephan 0eca9db776 speedtest1: in WASM builds, disable the "app" test set by default because that one set is triggering file-not-found errors for the db file for reasons not yet understood.
FossilOrigin-Name: 9d68971c58261bce72b49c574cf07ad31add62bee814c58840b927fed7eb87b1
2025-07-11 11:06:25 +00:00
stephan c066f2af9c Do not export the numerous Emscripten HEAPxy symbols and remove the last remaining JS code which references them. They have long-since been replaced by internal equivalents and a specific feature check on one of them (which is also no longer needed) is triggering an exception from Emscripten. More details are in [https://github.com/emscripten-core/emscripten/issues/24656 | Emscripten ticket #24656], noting that this is not an Emscripten bug but an Emscripten behavior change brought it to light.
FossilOrigin-Name: b9462dc1461c830466f4e1de4a4d3bf249e3f81aea363f13462ea915769878d9
2025-07-11 10:27:06 +00:00
drh 625d0b70fe Improve the accuracy of the ETC on both devtest and releasetest.
FossilOrigin-Name: a3f96cafdc0e1f2eeccc6509f1f9c26d2c48668953550f299cf2805a0a063014
2025-07-10 20:45:00 +00:00
drh 45bff0ea64 Add the estkey column to the jobs table of testrunner.db. The plan is to
use this to collect measurements that will help generate improved ETAs for
a test run.

FossilOrigin-Name: 9eccf5267c6423c9dd4da1d61b62bbb6fbba44fb8089da79f89c84e8b77ff0f0
2025-07-10 17:19:08 +00:00
stephan 07b483c48e Minor internal doc correction in vdbeInt.h.
FossilOrigin-Name: c3a2ef639c22255a298cbccb7fd871ec9b24929f82bf95d6982b12daf5c963d6
2025-07-10 09:27:57 +00:00
stephan 6fd9469a32 Minor JS doc tweaks.
FossilOrigin-Name: 34d893b4837be8bb679e9809befd98201dd79c8d2054f41429b18793b77e840f
2025-07-10 09:25:57 +00:00
drh 33c2e37f98 Fix the empty-table optimization on INTERSECT so that it does not try to
use an uninitialized register for LIMIT processing.

FossilOrigin-Name: 6918ada008507b4564ca0dc5f4f6818c49a42eb14a16285b2074e21dcc8f2c3f
2025-07-09 20:11:49 +00:00
stephan 2ba5a93e8f wasm: DB.wrapHandle() no longer accepts a DB object as its first argument, as there's no apparent use case for proxying one DB object with another. Doc improvements for the new code.
FossilOrigin-Name: 0ee19db02a9b9320681d4393d9ba52889d149eac8ee114fc7b7f52a57271c139
2025-07-09 13:43:53 +00:00
stephan 6276637075 wasm: add a few tests demonstrating that oo1.Stmt.paramaterCount's new impl does not change visible behaviors. Add the c-pp-filtered files to 'make clean'.
FossilOrigin-Name: 3fe61545967f82190011edb90b1be6a448b590555c7ba5f8e96494aeea8f88ce
2025-07-09 13:13:01 +00:00
drh 8663a78ec9 Fix a possible user-after free following OOM in the EXISTS-to-JOIN
optimization.

FossilOrigin-Name: 498ee8d514e64cdc93a8d68e1971b6326c6132daf25067936bec921c42494caa
2025-07-08 22:11:39 +00:00
drh aa12f0027b Adjustments to test/incrblob4.test so that it works on both Linux and Mac
in spite of error message differences between those platforms.  Minor change
to termIsEquivalent() to provide 100% MC/DC.

FossilOrigin-Name: 720387f8604f7cd997f1850ed62ce6ab32608155d7f02a89c695041caafc4067
2025-07-08 20:28:35 +00:00
drh 9a13a21223 New optimizations to detect early when queries return no rows due to
tables being empty.  This includes the EXISTS-to-JOIN optimization that
tries to transform EXISTS constraints into additional terms of the FROM
clause.

FossilOrigin-Name: e33da6d5dc964db817d1bc63c9083aecd93d49ee14d5198600b47eaf7c5b9331
2025-07-08 19:53:36 +00:00
dan 9b91aac83b Fix a problem with the fix in [5cb8e342e1].
FossilOrigin-Name: 043ff54fb746c54bc6cfa6aa8c8a32c876c09d36163125916ad01024b98d447b
2025-07-08 19:02:26 +00:00
dan acd1d93497 Fix another problem with running fts5 integrity-check in SQLITE_DEBUG builds, this one causing an assert() failure.
FossilOrigin-Name: 5cb8e342e1d33a0fd04fd022900eeada46a2ee23f15c6abca1b37633e77429d6
2025-07-08 18:44:56 +00:00
drh 449b34571e Enable the EXISTS-to-JOIN optimization if the outer query has no
FROM clause.

FossilOrigin-Name: 1b9b124f9a35ebd1ac4ea70ef1ee08a4c82c11da690d4164f6b785a6fd9730d9
2025-07-08 17:28:09 +00:00
dan 9615cf93c8 If SQLITE_DEBUG is defined, fts5 does extra checks as part of integrity-check. Ensure that errors from these extra checks are only reported if the other, normal, tests all pass. This fixes a test case in fts5corrupt3.test that was failing if SQLITE_DEBUG was defined.
FossilOrigin-Name: 98a53fb276fa1fa733da2dd3255c35ce9f6af9b9feef6e76fb577b6d142167a2
2025-07-08 14:54:20 +00:00
drh 925b79039c Fix test case results in FTS5 that were changed error message improvements
in [48044a6b57c0a16c] but which were omitted from that check-in.

FossilOrigin-Name: e1f8e0240b14f1338e947634e840af785e5042a09cd365975e922a13a562f4cd
2025-07-08 12:37:25 +00:00
dan 7fc6e6a272 Only run preupdate-hook tests in incrblob4.test if the preupdate-hook is enabled in the build.
FossilOrigin-Name: 56314b6b53c86ae131f780e20b62bdeabccba6d62dda41becc1c4b2e87cee07b
2025-07-07 20:47:23 +00:00
drh 8c8443a38a Small performance optimization in the resolver.
FossilOrigin-Name: 840646df0696706bd4dd7a04dfc8b16ad80c24cbcbc57a22c9e65a93cc17af2b
2025-07-07 19:03:50 +00:00
drh 44a03671c4 Merge the latest trunk enhancements and fixes into the empty-table-optimizations branch.
FossilOrigin-Name: f15cdf07573c05276a13885d74bae21a93544766344f19ef939b7a69edd1073b
2025-07-07 18:35:51 +00:00
drh 0a5508aeb4 Rework the fix to the problem described by
[forum:/forumpost/b9647a113b465950|forum post b9647a113b] so that it
provides a more complete fix that covers cases that were not resolved by
the original fix, and so that it does not cause performance regressions.

FossilOrigin-Name: 28db0d152d90fb5e62d03ea5caceabe8901be98522aef3dc2b54564fbc35355d
2025-07-07 16:19:44 +00:00
drh 4fe1ac8fe1 Simplifications to the row-value IN operator logic. Do not let the query
planner accept a WhereLoop for a row-value IN operator that uses the same
index column more than once.

FossilOrigin-Name: d2adf61f21a3ce901a2b08199ad0de191e88ef16e097c5f7a75c95ad958eff12
2025-07-07 15:40:53 +00:00
stephan 24d290e7b0 Work around the Emscripten 4.10 regression described in [https://github.com/emscripten-core/emscripten/issues/24656 | Emscripten ticket #24656]. Problem reported off-list by BrickViking.
FossilOrigin-Name: c385475b250f3364507a95c5832137098a9bb7c7fc12ab3bb116e1fad7bb7645
2025-07-07 12:11:26 +00:00
dan 8504d37b99 Avoid invoking the preupdate hook from within sqlite3_blob_write() if the cursor is already invalid.
FossilOrigin-Name: 9f335b9a4e9e761a0c6afd6dc69665a24506141bde88530bf59fcbdf957ae881
2025-07-07 11:37:55 +00:00
drh 4aacd1ef8e Back out the fix at [ba7d5bad32ad6aac] because it does not always work and because
it causes a performance regression.  Add new test cases for row-value lookups of
indexes that contain redundant columns, three of which are currently failing.  This
branch is seeking an improved solution to the redundant index column problem for
row-value lookups.

FossilOrigin-Name: ad8ddcefab5cc526b1cd77731e00939c672e61ca83350d28961b67635d20da03
2025-07-07 10:54:00 +00:00
drh 0840460689 Fix parser error introduced by [325e547a2195571e]. See
[forum:/forumpost/095dbfc06e5b1f7e|forum post 095dbfc06e5].

FossilOrigin-Name: 4eefab44941fc6e17742fa49c8734e7f00a2177d82bc572e596228add53aad39
2025-07-07 02:18:27 +00:00
stephan 240319decd Remove some dead JS code and some extraneous debug output from test code.
FossilOrigin-Name: 6e73770a7f3845055e0130012d844c32c4a1bfdb87e8379c161e1a266a808143
2025-07-06 15:36:28 +00:00
stephan 787f4c3f09 JS doc additions.
FossilOrigin-Name: 7933505f0c1d25c6ee81ead8edc5ea649a84ec0582321bcf5ed4a17232750f90
2025-07-06 15:13:06 +00:00
stephan 4d453cc2ed Experimentally add sqlite3.oo1.DB/Stmt.wrapHandle(), which allow DB/Stmt instances to wrap a (sqlite3*)/(sqlite3_stmt*) optionally with or without taking ownership of it. The intent is to enable mix-and-match use of the C API, the oo1 API, and any other hypothetical API which exposes those pointers. oo1.Stmt.parameterCount is now a property access interceptor like Stmt.columnCount is, but that doesn't change how it's used.
FossilOrigin-Name: 1227543b87c3320d6b80e0f61b88ea53b68779966a0295c4d6a1db6369c48207
2025-07-06 15:01:44 +00:00
drh c701d17366 Improvements to the EXPLAIN QUERY PLAN output for EXISTS-to-JOIN.
FossilOrigin-Name: 6b1ecbaa2ee405be040901dceac45d027d35c313622748ba4dbbd404e297a7fa
2025-07-06 01:19:09 +00:00
drh 8bc112e3e4 Enhance the EXISTS-to-JOIN optimization so that it works on EXISTS subqueries
that do not have a WHERE clause, and so that it works on nested EXISTS
subqueries.

FossilOrigin-Name: c1d5295724f9cf7f49e0786d28016eff2d268a2b670f934d24c76787626089db
2025-07-05 23:33:21 +00:00
stephan 27408ab9c9 Add 'reconfigure' target to Makefile.in to re-run the configure script with the same flags it was generated with.
FossilOrigin-Name: c60907e77b32824aaaf024d299cdaf161b5f64fc927ffe5d5455eeb5754e6b01
2025-07-04 18:32:18 +00:00
stephan d9eae6b75a Propagate the -ldl and -lpthread flags, if needed, into sqlite3.pc, per request in [forum:44a58c807353162f | forum post 44a58c807353162f].
FossilOrigin-Name: 64f5f14322349b47451b8cac03bf8cd6f1ae45a8822e7f1ddee3d0b265047501
2025-07-04 17:20:37 +00:00
drh 45bc9b9f97 Merge fixes from trunk into the empty-table-optimizations branch
FossilOrigin-Name: 6f98b16d210a9f5b6ca4b4599e3dab3263eddbae7c70ddbcabf988f4a1014e8b
2025-07-04 14:24:18 +00:00
drh e33ea17d24 Fix harmless compiler warnings.
FossilOrigin-Name: 13af4acebe09b047756c22b800136cffaba532e7fcaa448a4edf4fedb94e9bbc
2025-07-04 12:25:24 +00:00
drh a12e92d2f7 Remove an ALWAYS() added by [960a8e6fc91f4] that turns out to be false
in some cases of malformed SQL.

FossilOrigin-Name: cc8171461bf35f584888a24b844c8b79ad30155b19b61161e9f3abc276e8aae5
2025-07-04 11:48:11 +00:00
drh 478dfc7e74 Do not allow the EXISTS-to-JOIN optimization if the EXISTS clause is based
on a view, since that view might expand into a join.

FossilOrigin-Name: 872c41feddafcc21a02f1229ce017ceea9f8e309a4dd5b6e323477d67f975947
2025-07-04 11:06:34 +00:00
drh 1b62720fa8 Improve the early-termination optimization so that it works in queries
which use the LIKE optimization in the outer loop.

FossilOrigin-Name: b4e4d148243cfcb09aa0aaca30e83812b42e2780073e55c0e8c6e3da16243dfc
2025-07-04 10:26:55 +00:00
drh 1e3a862b79 Merge the latest trunk fixes and enhancements into the empty-table-optimizations branch
FossilOrigin-Name: d4f47e04f5880e99a53089e2dd5cde64a7ea44f059d9906b5d11324896546714
2025-07-03 20:51:08 +00:00
dan bd05edd98f Fix a few cases where LIMIT clauses that were part of scalar sub-queries on virtual tables were not being passed to xBestIndex methods correctly.
FossilOrigin-Name: 960a8e6fc91f47add3a089dc6cef013109deadf809994c5149ad3bdfb3884de0
2025-07-03 16:05:41 +00:00
drh a24a397b8b Improvements to sqlite3_vtab_rhs_value() logging in the
ext/misc/vtablog.c extension.

FossilOrigin-Name: 25131ee84f53dab1191e02c19cefd256aed2828c7edea325fcc0ba3b0a668583
2025-07-03 15:50:18 +00:00
dan 0e6e05d4d5 Make the value of an explicit LIMIT clause on a scalar sub-query available to xBestIndex for simple "LIMIT 0" and "LIMIT 1" queries.
FossilOrigin-Name: 33b6a63caafccc61b3193714911cd8b5dd9b7f1798054b8c7845b23688d531f2
2025-07-03 15:32:27 +00:00
dan c525e6e817 Make handling of LIMIT clauses in correlated sub-queries on virtual tables more efficient.
FossilOrigin-Name: 7214cb2a5b35190a06a1040cd4c54f325d347f8d8e36a07fd76c0a421e266522
2025-07-03 14:28:47 +00:00
drh 1ff6f19d8b Enhancements to the xBestIndex output from the ext/misc/vtablog.c
extension.

FossilOrigin-Name: 8b31acc0b18f38eb4af6efebd1ea25cd65a146651101579aee20afd9ec6dc2de
2025-07-03 14:10:03 +00:00
drh bfb4993364 Fix an uninitialized variable added yesterday by [d27d34fb746280e7].
This problem was discovered overnight by 
[https://github.com/google/oss-fuzz|OSSFuzz].

FossilOrigin-Name: 6db4703f1178fc808f3a75c355fb6638fb12c88f6e1ce7f579e200ced8089114
2025-07-03 11:52:17 +00:00
drh debc8f7bb7 Minor tweaks to the exists-to-join optimization.
FossilOrigin-Name: 9cb600ad576c68647ed943a0773019312c5f01c9c1ca9ff0bf1214b03a531b48
2025-07-03 00:17:27 +00:00
drh aa54d7a0ca Merge in the exists-to-join optimization that has been modified
to relax the requirement of having an indexed join constraint.

FossilOrigin-Name: 1c1aef2b7feae29066d0330699ab634ef41f5b60cdcd479a60cb1a5409553138
2025-07-02 20:46:02 +00:00
drh eb27359e5e Fix VDBE coverage
FossilOrigin-Name: ff593a16d61cc5c588d1737deb822abb90b1759475a4cabfcf608978b1191487
2025-07-02 17:43:59 +00:00
drh 33f3273705 Early exit if one of the inner loops of a 3-way or larger join is an
empty table.

FossilOrigin-Name: eaad6ac707a5960d9518d4049b7b1759e7512727ce87be3c402408144bda0a97
2025-07-02 14:53:48 +00:00
drh 216676664d If the LHS for an EXCEPT or INTERSECT operator is empty, skip over the
computation of the RHS.

FossilOrigin-Name: 13f096ae8a850a05d4a8684561066f11693ee66289e6568c44ef32822cca06f6
2025-07-02 13:19:24 +00:00
drh 6245e5a46b Improve the bytecode for joins such that it exits earlier if it determines
that no output is possible.

FossilOrigin-Name: 2d2b61cba44a756a3a41ef5c95bbb0c0b7111f4b679c578fec9bd0b214cca367
2025-07-02 11:47:54 +00:00
drh caf0473652 Ensure that Expr.op2 values for TK_AGG_FUNCTION nodes are adjusted when
query flattening.

FossilOrigin-Name: d27d34fb746280e7e81335db4e195914b15403ef0da7b2955550553dd78fbe9a
2025-07-02 02:03:43 +00:00
drh 2427ce16d9 Improved comments on bytecode used to implement aggregate queries, to aid
in debugging.

FossilOrigin-Name: a1a8b85cdba64a17dcdcd4e6b42b872957cec2dc05b0ac34dfcd82f59344034b
2025-07-01 23:17:36 +00:00
drh 46bfcc1a21 Improved byte-code comments for the short-circuit optimization of
[0083d5169a46104a], to aid in debugging.

FossilOrigin-Name: 113f9d10e347eeaa893ff8b47a461009e0b12589374b93cf3e0bddd19c702dea
2025-07-01 20:32:45 +00:00
drh 5e71497404 Cache and reuse virtual table cursors in the bytecode engine.
FossilOrigin-Name: 2d187d4232d750cb1840f1d89c8aed65962cb0883c1d7f91c554b451e475c514
2025-07-01 17:36:55 +00:00
dan 526399b0fd Avoid an assert() failure in fts5 that may occur when processing corrupt records.
FossilOrigin-Name: 8afd6ca85724a69970181042d6aac53742ea2b76ded5966b2541c3afe1121fb9
2025-07-01 16:21:47 +00:00
drh e1910ed1d2 Merge trunk fixes into the empty-table-optimizations branch.
FossilOrigin-Name: 63306e447efb3ac17e789a331ed3bb65459eb8b79d66e9c185ba3bd852f34ce3
2025-07-01 15:13:37 +00:00
drh d82c6a2cf7 When attempting to optimize "expr AND false" to "false" and
"expr IN ()" to "false", take care not to delete aggregate functions
in the "expr" as doing so can change the meaning of the query.
See [forum:/forumpost/f4878de3e7dd4764|forum thread f4878de3e7].

FossilOrigin-Name: 77397bd67d918db57d5ac545d6d963194806fdabcdaa8f822b6b09e4cfe8b715
2025-07-01 12:43:13 +00:00
drh 3d21dcc924 More aggressive optimization of addrHalt for RIGHT JOIN.
FossilOrigin-Name: 5e51d1c0dfcafef9e71c99de3f626dee157c935724b84c6e0c630299a880446f
2025-06-30 21:07:08 +00:00
drh ba56f7020d Compute WhereLevel.addrBrk and .addrHalt early so that those labels can be
used to abort loops early.  Use this to improve performance on two more
of the cases described by [forum:/forumpost/52651713ac|forum post 52651713ac].

FossilOrigin-Name: 6fc0b9ac23be6840542982de4bb282ebca1db8b5ab3baefdde95a997c1506e81
2025-06-30 20:19:19 +00:00
drh 99f1aa03fb Strive to skip the evaluation of scalar subqueries that are part of a
larger expression if the result from the scalar subquery does not change the
result of the overall expression.

FossilOrigin-Name: 0083d5169a46104a25355bdd9d5a2f4027b049191ebda571dd228477ec217296
2025-06-30 16:41:40 +00:00
drh 280559b446 For all binary operators, try to avoid computing subquery operands if the
other operand is NULL.

FossilOrigin-Name: d86eb16283c4b573c506d4faa422d5d9aeb6abc279d8e6a8e2104737162d417f
2025-06-30 12:14:47 +00:00
drh e2e81e6983 Slightly smaller and faster version of the previous check-in.
FossilOrigin-Name: f6e6fd02f4ad49c390a2d3c9626d57f9b2fff1f67eb361b30074cc1f5121810e
2025-06-30 11:04:55 +00:00
drh e24f20a4f5 Factor out the code that tries to avoid evaluating subquery operands if the
other operand is NULL into a subroutine, so that it can be more easily reused
by other parts of the code generator.

FossilOrigin-Name: 3c6c71bcea16443b82234414137dfa1b59e2ee8fe5097906c738fc1228fec4e6
2025-06-30 10:30:47 +00:00
drh 311d73efc2 Improve the bytecode generated for comparisons so that if one operand is
a subquery and the other operand evaluates to NULL, the subquery operand
is not even computed.  This fixes 5 of the 12 slow queries described
in [forum:/forumpost/52651713ac|forum post 52651713ac].

FossilOrigin-Name: f147bc04776ac0056412f69dfc518016c0d5b4e9d964664e3d88f595fb29dbe0
2025-06-28 17:59:15 +00:00
drh a3ee3860a2 Merge all the latest trunk enhancements into the exists-to-join branch.
FossilOrigin-Name: 9084a4c8726a2c7ba1c381886e29c7b86121d531282be0d63d5988d84f6f448d
2024-07-31 23:46:10 +00:00
drh c96e47c80e Merge the latest trunk enhancements into the exists-to-join branch.
FossilOrigin-Name: fc643f8a12e9b7448136b281f798e18dfebe0a3df5115d930b965c8a33933e2d
2024-06-27 14:54:15 +00:00
drh 620a00ee32 Do not attempt the exists-to-join optimization if the FROM clause is full.
FossilOrigin-Name: 8e3a1d2850337a902ab36b1d6a0dad4ae35030b71d1e15547f6e7487c1f86d18
2024-06-20 12:07:25 +00:00
dan 62b954d545 Add tests for the change on this branch.
FossilOrigin-Name: ae19ff9ba819439fd107e745b6e8e503e5b68bfdb9da58b74035413704ad3caf
2024-06-14 18:06:25 +00:00
dan 0d92e66dfc Do not attempt the exists-to-join optimization for expressions from the ON clause of joins.
FossilOrigin-Name: 4666433cbd9af21c2e0440b10bcb39878624a39485e2bb514553b276acb8a401
2024-06-12 17:01:00 +00:00
drh ddc62664bf Provide the ability to disable the exists-to-join optimization using
SQLITE_TESTCTRL_OPTIMIZATIONS.  Provide tree-trace output for the optimization.

FossilOrigin-Name: 33a3f327855b427ae6ba0057218d043a1417bc9d780728f47f23acdd836e1686
2024-06-11 18:22:48 +00:00
drh b4f41b801a Merge trunk enhancements into the exists-to-join branch.
FossilOrigin-Name: 5f25a9518a675efbd0525cc2f5595ee7bc7122be7cfecdf6b20c909185dea370
2024-06-11 17:37:36 +00:00
dan df77e56cde Add missing calls to sqlite3exprSkipCollateAndLikely() to the enchancement on this branch.
FossilOrigin-Name: 078537d057d638389e3ab3bc04bcac53f342c7bf1d8d75222296ef42d09e9ee7
2024-06-10 19:45:33 +00:00
dan dc9a262319 Fix a crash that could occur when the SELECT in an EXISTS(SELECT ...) used an unknown collation sequence.
FossilOrigin-Name: f3009a6d7facd1ead520d588c5ad089db76d8641cd3dae076f2405492d7defcd
2024-06-10 19:31:18 +00:00
dan b111f1cb2a Add extra tests for the changes on this branch.
FossilOrigin-Name: a6365c778f2a6d6fa78e8520553373898f382ce73bf6496533e26291648ef5d1
2024-06-08 18:13:12 +00:00
dan 5525ac1049 Experimental optimization to rewrite a SELECT with an EXISTS(...) expression in the WHERE clause as a join.
FossilOrigin-Name: 972a33db0b0e924b78d5309d222d8ea298bd59c72da14ea2d14e8e2caaad1e0a
2024-06-07 21:00:42 +00:00
168 changed files with 6362 additions and 35306 deletions
+5 -15
View File
@@ -11,17 +11,6 @@
#
all:
########################################################################
#
# Known TODOs/FIXMEs/TOIMPROVEs for the autosetup port, in no
# particular order...
#
# - TEA pieces.
#
# - Replace the autotools-specific distribution deliverable(s).
#
# - Confirm whether cross-compilation works and patch it
# appropriately.
#
# Maintenance reminders:
#
# - This makefile should remain as POSIX-make-compatible as possible:
@@ -264,7 +253,9 @@ AS_AUTO_DEF = $(TOP)/auto.def
# invoked with to produce this makefile.
#
AS_AUTORECONFIG = @SQLITE_AUTORECONFIG@
.PHONY: config reconfigure
config reconfigure:
$(AS_AUTORECONFIG)
USE_AMALGAMATION ?= @USE_AMALGAMATION@
LINK_TOOLS_DYNAMICALLY ?= @LINK_TOOLS_DYNAMICALLY@
AMALGAMATION_GEN_FLAGS ?= --linemacros=@AMALGAMATION_LINE_MACROS@
@@ -322,9 +313,8 @@ fiddle: sqlite3.c shell.c
./custom.rws: ./tool/custom.txt
@echo 'Updating custom dictionary from tool/custom.txt'
aspell --lang=en create master ./custom.rws < ./tool/custom.txt
# Note that jimsh does not work here:
# https://github.com/msteveb/jimtcl/issues/319
misspell: ./custom.rws has_tclsh84
# $(JIMSH) does not work with spellsift.tcl
$(TCLSH_CMD) ./tool/spellsift.tcl ./src/*.c ./src/*.h ./src/*.in
#
@@ -341,7 +331,7 @@ distclean: distclean-autosetup
#
# tool/version-info: a utility for emitting sqlite3 version info
# in various forms.
# in various forms. It's used by ext/wasm/.
#
version-info$(T.exe): $(TOP)/tool/version-info.c Makefile sqlite3.h
$(T.link) $(ST_OPT) -o $@ $(TOP)/tool/version-info.c
+4 -28
View File
@@ -2485,24 +2485,6 @@ FTS5_SRC = \
$(TOP)\ext\fts5\fts5_varint.c \
$(TOP)\ext\fts5\fts5_vocab.c
LSM1_SRC = \
$(TOP)\ext\lsm1\lsm.h \
$(TOP)\ext\lsm1\lsmInt.h \
$(TOP)\ext\lsm1\lsm_ckpt.c \
$(TOP)\ext\lsm1\lsm_file.c \
$(TOP)\ext\lsm1\lsm_log.c \
$(TOP)\ext\lsm1\lsm_main.c \
$(TOP)\ext\lsm1\lsm_mem.c \
$(TOP)\ext\lsm1\lsm_mutex.c \
$(TOP)\ext\lsm1\lsm_shared.c \
$(TOP)\ext\lsm1\lsm_sorted.c \
$(TOP)\ext\lsm1\lsm_str.c \
$(TOP)\ext\lsm1\lsm_tree.c \
$(TOP)\ext\lsm1\lsm_unix.c \
$(TOP)\ext\lsm1\lsm_varint.c \
$(TOP)\ext\lsm1\lsm_vtab.c \
$(TOP)\ext\lsm1\lsm_win32.c
fts5parse.c: $(TOP)\ext\fts5\fts5parse.y lemon.exe
copy /Y $(TOP)\ext\fts5\fts5parse.y .
copy /B fts5parse.y +,,
@@ -2516,11 +2498,6 @@ fts5.c: $(FTS5_SRC) $(JIM_TCLSH)
copy /Y $(TOP)\ext\fts5\fts5.h .
copy /B fts5.h +,,
lsm1.c: $(LSM1_SRC) $(JIM_TCLSH)
$(JIM_TCLSH) $(TOP)\ext\lsm1\tool\mklsm1c.tcl
copy /Y $(TOP)\ext\lsm1\lsm.h .
copy /B lsm.h +,,
fts5.lo: fts5.c $(HDR) $(EXTHDR)
$(LTCOMPILE) $(CORE_COMPILE_OPTS) $(NO_WARN) -DSQLITE_CORE -c fts5.c
@@ -2596,9 +2573,12 @@ extensiontest: testfixture.exe testloadext.dll
@set PATH=$(LIBTCLPATH);$(PATH)
.\testfixture.exe $(TOP)\test\loadext.test $(TESTOPTS)
tool-zip: testfixture.exe sqlite3.exe sqldiff.exe sqlite3_analyzer.exe sqlite3_rsync.exe $(TOP)\tool\mktoolzip.tcl
tool-zip: testfixture.exe sqlite3.exe sqldiff.exe sqlite3_analyzer.exe sqlite3_rsync.exe sqlite3.dll $(TOP)\tool\mktoolzip.tcl
.\testfixture.exe $(TOP)\tool\mktoolzip.tcl
snapshot-zip: testfixture.exe sqlite3.exe sqldiff.exe sqlite3_analyzer.exe sqlite3_rsync.exe sqlite3.dll $(TOP)\tool\mktoolzip.tcl
.\testfixture.exe $(TOP)\tool\mktoolzip.tcl --snapshot
coretestprogs: testfixture.exe sqlite3.exe
testprogs: $(TESTPROGS) srcck1.exe fuzzcheck.exe sessionfuzz.exe
@@ -2824,9 +2804,6 @@ tcl-env:
@echo JIM_TCLSH = $(JIM_TCLSH)
@echo VISUALSTUDIOVERSION = $(VISUALSTUDIOVERSION)
LSMDIR=$(TOP)\ext\lsm1
!INCLUDE $(LSMDIR)\Makefile.msc
moreclean: clean
del /Q $(SQLITE3C) $(SQLITE3H) 2>NUL
# <</mark>>
@@ -2868,7 +2845,6 @@ clean:
del /Q kvtest.exe ossshell.exe scrub.exe 2>NUL
del /Q showshm.exe sqlite3_checker.* sqlite3_expert.exe 2>NUL
del /Q fts5.* fts5parse.* 2>NUL
del /Q lsm.h lsm1.c 2>NUL
del /q src-verify.exe 2>NUL
del /q jimsh.exe jimsh0.exe 2>NUL
# <</mark>>
+5
View File
@@ -12,6 +12,11 @@
#
# JimTCL: https://jim.tcl.tk
#
# Code-diver notes: APIs names starting with "sqlite-" are specific to
# this project and can be found in autosetup/sqlite-config.tcl. Names
# starting with "proj-" are project-agnostic and found in
# autosetup/proj.tcl.
#
use sqlite-config
sqlite-configure canonical {
proj-if-opt-truthy dev {
+6 -3
View File
@@ -222,9 +222,12 @@ install: install-lib
# Flags to link the shell app either directly against sqlite3.c
# (ENABLE_STATIC_SHELL==1) or libsqlite3.so (ENABLE_STATIC_SHELL==0).
#
# Maintenance reminder: placement of $(LDFLAGS) is more relevant for
# some platforms than others:
# https://sqlite.org/forum/forumpost/d80ecdaddd
ENABLE_STATIC_SHELL = @ENABLE_STATIC_SHELL@
sqlite3-shell-link-flags.1 = $(TOP)/sqlite3.c $(LDFLAGS.libsqlite3)
sqlite3-shell-link-flags.0 = -L. -lsqlite3 $(LDFLAGS.zlib) $(LDFLAGS.math)
sqlite3-shell-link-flags.1 = $(TOP)/sqlite3.c $(LDFLAGS) $(LDFLAGS.libsqlite3)
sqlite3-shell-link-flags.0 = $(LDFLAGS) -L. -lsqlite3 $(LDFLAGS.zlib) $(LDFLAGS.math)
sqlite3-shell-deps.1 = $(TOP)/sqlite3.c
sqlite3-shell-deps.0 = $(libsqlite3.DLL)
#
@@ -245,7 +248,7 @@ sqlite3$(T.exe): $(TOP)/shell.c $(sqlite3-shell-deps.$(ENABLE_STATIC_SHELL))
$(sqlite3-shell-static.flags.$(STATIC_CLI_SHELL)) \
-I. $(OPT_FEATURE_FLAGS) $(SHELL_OPT) \
$(CFLAGS) $(CFLAGS.readline) $(CFLAGS.icu) \
$(LDFLAGS) $(LDFLAGS.readline)
$(LDFLAGS.readline)
sqlite3$(T.exe)-1:
sqlite3$(T.exe)-0: sqlite3$(T.exe)
+15 -2
View File
@@ -1,7 +1,20 @@
#!/bin/sh
# Look for and run autosetup...
dir0="`dirname "$0"`"
dirA="$dir0/../autosetup"
# This is the case ^^^^^^^^^^^^ in the SQLite "autoconf" bundle.
dirA="$dir0"
if [ -d $dirA/autosetup ]; then
# A local copy of autosetup
dirA=$dirA/autosetup
elif [ -d $dirA/../autosetup ]; then
# SQLite "autoconf" bundle
dirA=$dirA/../autosetup
elif [ -d $dirA/../../autosetup ]; then
# SQLite canonical source tree
dirA=$dirA/../../autosetup
else
echo "$0: Cannot find autosetup" 1>&2
exit 1
fi
WRAPPER="$0"; export WRAPPER; exec "`"$dirA/autosetup-find-tclsh"`" \
"$dirA/autosetup" --teaish-extension-dir="$dir0" \
"$@"
+4 -3
View File
@@ -380,8 +380,9 @@ and its own special handling of `--enable-...` flags makes `--debug`
an alias for `--enable-debug`. As this project has a long history of
using `--enable-debug`, we patch autosetup to use the name
`--autosetup-debug` in place of `--debug`. That requires (as of this
writing) four small edits in [](/file/autosetup/autosetup), as
demonstrated in [check-in 3296c8d3](/info/3296c8d3).
writing) four small edits in
[/autosetup/autosetup](/file/autosetup/autosetup), as demonstrated in
[check-in 3296c8d3](/info/3296c8d3).
If autosetup is upgraded and this patch is _not_ applied the invoking
`./configure` will fail loudly because of the declaration of the
@@ -426,7 +427,7 @@ proc sqlite-custom-flags {} {
```
That function must return either an empty string or a list in the form
used internally by `sqlite-config.tcl:sqlite-configure`.
used internally by [sqlite-config.tcl][]'s `sqlite-configure`.
Next, define:
+64 -15
View File
@@ -378,8 +378,8 @@ proc proj-bin-define {binName {defName {}}} {
#
# Despite using cc-path-progs to do the search, this function clears
# any define'd name that function stores for the result (because the
# caller has no sensible way of knowing which result it was unless
# they pass only a single argument).
# caller has no sensible way of knowing which [define] name it has
# unless they pass only a single argument).
#
proc proj-first-bin-of {args} {
set rc ""
@@ -451,7 +451,9 @@ proc proj-opt-set {flag {val 1}} {
# @proj-opt-exists flag
#
# Returns 1 if the given flag has been defined as a legal configure
# option, else returns 0.
# option, else returns 0. Options set via proj-opt-set "exist" for
# this purpose even if they were not defined via autosetup's
# [options] function.
#
proc proj-opt-exists {flag} {
expr {$flag in $::autosetup(options)};
@@ -704,11 +706,20 @@ proc proj-file-write {args} {
}
#
# @proj-check-compile-commands ?configFlag?
# @proj-check-compile-commands ?-assume-for-clang? ?configFlag?
#
# Checks the compiler for compile_commands.json support. If passed an
# argument it is assumed to be the name of an autosetup boolean config
# which controls whether to run/skip this check.
# Checks the compiler for compile_commands.json support. If
# $configFlag is not empty then it is assumed to be the name of an
# autosetup boolean config which controls whether to run/skip this
# check.
#
# If -assume-for-clang is provided and $configFlag is not empty and CC
# matches *clang* and no --$configFlag was explicitly provided to the
# configure script then behave as if --$configFlag had been provided.
# To disable that assumption, either don't pass -assume-for-clang or
# pass --$configFlag=0 to the configure script. (The reason for this
# behavior is that clang supports compile-commands but some other
# compilers report false positives with these tests.)
#
# Returns 1 if supported, else 0, and defines HAVE_COMPILE_COMMANDS to
# that value. Defines MAKE_COMPILATION_DB to "yes" if supported, "no"
@@ -716,12 +727,38 @@ proc proj-file-write {args} {
# HAVE_COMPILE_COMMANDS is preferred.
#
# ACHTUNG: this test has a long history of false positive results
# because of compilers reacting differently to the -MJ flag.
# because of compilers reacting differently to the -MJ flag. Because
# of this, it is recommended that this support be an opt-in feature,
# rather than an on-by-default default one. That is: in the
# configure script define the option as
# {--the-flag-name=0 => {Enable ....}}
#
proc proj-check-compile-commands {{configFlag {}}} {
proc proj-check-compile-commands {args} {
set i 0
set configFlag {}
set fAssumeForClang 0
set doAssume 0
msg-checking "compile_commands.json support... "
if {"" ne $configFlag && ![proj-opt-truthy $configFlag]} {
msg-result "explicitly disabled"
if {"-assume-for-clang" eq [lindex $args 0]} {
lassign $args - configFlag
incr fAssumeForClang
} elseif {1 == [llength $args]} {
lassign $args configFlag
} else {
proj-error "Invalid arguments"
}
if {1 == $fAssumeForClang && "" ne $configFlag} {
if {[string match *clang* [get-define CC]]
&& ![proj-opt-was-provided $configFlag]
&& ![proj-opt-truthy $configFlag]} {
proj-indented-notice [subst -nocommands -nobackslashes {
CC appears to be clang, so assuming that --$configFlag is likely
to work. To disable this assumption use --$configFlag=0.}]
incr doAssume
}
}
if {!$doAssume && "" ne $configFlag && ![proj-opt-truthy $configFlag]} {
msg-result "check disabled. Use --${configFlag} to enable it."
define HAVE_COMPILE_COMMANDS 0
define MAKE_COMPILATION_DB no
return 0
@@ -730,7 +767,7 @@ proc proj-check-compile-commands {{configFlag {}}} {
# This test reportedly incorrectly succeeds on one of
# Martin G.'s older systems. drh also reports a false
# positive on an unspecified older Mac system.
msg-result "compiler supports compile_commands.json"
msg-result "compiler supports -MJ. Assuming it's useful for compile_commands.json"
define MAKE_COMPILATION_DB yes; # deprecated
define HAVE_COMPILE_COMMANDS 1
return 1
@@ -1133,6 +1170,10 @@ proc proj-check-rpath {} {
if {"" eq $wl} {
set wl [proj-cc-check-Wl-flag -R$lp]
}
if {"" eq $wl} {
# HP-UX: https://sqlite.org/forum/forumpost/d80ecdaddd
set wl [proj-cc-check-Wl-flag +b $lp]
}
define LDFLAGS_RPATH $wl
}
}
@@ -1142,7 +1183,7 @@ proc proj-check-rpath {} {
#
# @proj-check-soname ?libname?
#
# Checks whether CC supports the -Wl,soname,lib... flag. If so, it
# Checks whether CC supports the -Wl,-soname,lib... flag. If so, it
# returns 1 and defines LDFLAGS_SONAME_PREFIX to the flag's prefix, to
# which the client would need to append "libwhatever.N". If not, it
# returns 0 and defines LDFLAGS_SONAME_PREFIX to an empty string.
@@ -1158,6 +1199,10 @@ proc proj-check-soname {{libname "libfoo.so.0"}} {
if {[cc-check-flags "-Wl,-soname,${libname}"]} {
define LDFLAGS_SONAME_PREFIX "-Wl,-soname,"
return 1
} elseif {[cc-check-flags "-Wl,+h,${libname}"]} {
# HP-UX: https://sqlite.org/forum/forumpost/d80ecdaddd
define LDFLAGS_SONAME_PREFIX "-Wl,+h,"
return 1
} else {
define LDFLAGS_SONAME_PREFIX ""
return 0
@@ -1604,7 +1649,7 @@ proc proj-tclConfig-sh-to-autosetup {tclConfigSh} {
#
# Similar modifications may be made for --mandir.
#
# Returns 1 if it modifies the environment, else 0.
# Returns >0 if it modifies the environment, else 0.
#
proc proj-tweak-default-env-dirs {} {
set rc 0
@@ -1643,7 +1688,11 @@ proc proj-tweak-default-env-dirs {} {
# processing the file. In the context of that script, the vars
# $dotInsIn and $dotInsOut will be set to the input and output file
# names. This can be used, for example, to make the output file
# executable or perform validation on its contents.
# executable or perform validation on its contents:
#
## proj-dot-ins-append my.sh.in my.sh {
## catch {exec chmod u+x $dotInsOut}
## }
#
# See [proj-dot-ins-process], [proj-dot-ins-list]
#
+73 -51
View File
@@ -1,7 +1,7 @@
# This file holds functions for autosetup which are specific to the
# sqlite build tree. They are in this file, instead of auto.def, so
# that they can be reused in the autoconf sub-tree. This file requires
# functions from proj.tcl.
# functions from the project-agnostic proj.tcl.
if {[string first " " $autosetup(srcdir)] != -1} {
user-error "The pathname of the source tree\
@@ -11,7 +11,7 @@ if {[string first " " $autosetup(builddir)] != -1} {
user-error "The pathname of the build directory\
may not contain space characters"
}
#parray ::autosetup; exit 0
use proj
#
# We want the package version info to be emitted early on, but doing
@@ -69,7 +69,8 @@ array set sqliteConfig [subst [proj-strip-hash-comments {
#
# Default value for the --all flag. Can hypothetically be modified
# by non-canonical builds.
# by non-canonical builds (it was added for a Tcl extension build
# mode which was eventually removed).
#
all-flag-default 0
}]]
@@ -92,7 +93,7 @@ array set sqliteConfig [subst [proj-strip-hash-comments {
# sqlite-configure BUILD_NAME { build-specific configure script }
#
# There are snippets of build-mode-specific decision-making in
# [sqlite-configure-finalize]
# [sqlite-configure-finalize], which gets run after $configScript.
proc sqlite-configure {buildMode configScript} {
proj-assert {$::sqliteConfig(build-mode) eq "unknown"} \
"sqlite-configure must not be called more than once"
@@ -112,8 +113,10 @@ proc sqlite-configure {buildMode configScript} {
#
# Reference: https://msteveb.github.io/autosetup/developer/
#
# All configure flags must be described in an 'options' call. The
# general syntax is:
# All configure flags must be described in one or more calls to
# autosetup's [options] and [options-add] functions. The general
# syntax of the single argument to those functions is a list contain
# a mapping of flags to help text:
#
# FLAG => {Help text}
#
@@ -164,13 +167,18 @@ proc sqlite-configure {buildMode configScript} {
########################################################################
set allFlags {
# Structure: a list of M {Z} pairs, where M is a descriptive
# option group name and Z is a list of X Y pairs. X is a list of
# option group name and Z is a list of X Y pairs. X is a list of
# $buildMode name(s) to which the Y flags apply, or {*} to apply
# to all builds. Y is a {block} in the form expected by
# autosetup's [options] command. Each block which is applicable
# to $buildMode is appended to a new list before that list is
# passed on to [options]. The order of each Y and sub-Y is
# retained, which is significant for rendering of --help.
# autosetup's [options] and [options-add] command. Each block
# which is applicable to $buildMode is passed on to
# [options-add]. The order of each Y and sub-Y is retained, which
# is significant for rendering of --help.
#
# Maintenance note: [options] does not support comments in
# options, but we filter this object through
# [proj-strip-hash-comments] to remove them before passing them on
# to [options].
# When writing {help text blocks}, be aware that:
#
@@ -180,7 +188,7 @@ proc sqlite-configure {buildMode configScript} {
# pretty-printed.
#
# B) Vars and commands are NOT expanded, but we use a [subst] call
# below which will replace (only) var refs.
# below which will replace (only) $var refs.
# Options for how to build the library
build-modes {
@@ -321,7 +329,7 @@ proc sqlite-configure {buildMode configScript} {
Needed only by ext/wasm. Default=EMSDK env var.}
amalgamation-extra-src:FILES
=> {Space-separated list of soure files to append as-is to the resulting
=> {Space-separated list of source files to append as-is to the resulting
sqlite3.c amalgamation file. May be provided multiple times.}
}
}
@@ -337,7 +345,6 @@ proc sqlite-configure {buildMode configScript} {
}
{canonical autoconf} {
rpath=1 => {Disable use of the rpath linker flag}
# soname: https://sqlite.org/src/forumpost/5a3b44f510df8ded
soname:=legacy
=> {SONAME for libsqlite3.so. "none", or not using this flag, sets no
@@ -408,7 +415,6 @@ proc sqlite-configure {buildMode configScript} {
# ^^^ lappend of [sqlite-custom-flags] introduces weirdness if
# we delay [proj-strip-hash-comments] until after that.
########################################################################
# sqlite-custom.tcl is intended only for vendor-branch-specific
# customization. See autosetup/README.md#branch-customization for
@@ -426,6 +432,8 @@ proc sqlite-configure {buildMode configScript} {
}
}
#lappend allFlags just-testing {{*} {soname:=duplicateEntry => {x}}}
# Filter allFlags to create the set of [options] legal for this build
foreach {group XY} [subst -nobackslashes -nocommands $allFlags] {
foreach {X Y} $XY {
@@ -434,7 +442,7 @@ proc sqlite-configure {buildMode configScript} {
}
}
}
#lappend opts "soname:=duplicateEntry => {x}"; #just testing
if {[catch {options {}} msg xopts]} {
# Workaround for <https://github.com/msteveb/autosetup/issues/73>
# where [options] behaves oddly on _some_ TCL builds when it's
@@ -449,8 +457,9 @@ proc sqlite-configure {buildMode configScript} {
########################################################################
# Runs "phase 1" of the configure process: after initial --flags
# handling but before the build-specific parts are run. $buildMode
# must be the mode which was passed to [sqlite-configure].
# handling but before sqlite-configure's $configScript argument is
# run. $buildMode must be the mode which was passed to
# [sqlite-configure].
proc sqlite-configure-phase1 {buildMode} {
define PACKAGE_NAME sqlite
define PACKAGE_URL {https://sqlite.org}
@@ -1017,7 +1026,7 @@ proc sqlite-handle-emsdk {} {
proc sqlite-get-readline-dir-list {} {
# Historical note: the dirs list, except for the inclusion of
# $prefix and some platform-specific dirs, originates from the
# legacy configure script
# legacy configure script.
set dirs [list [get-define prefix]]
switch -glob -- [get-define host] {
*-linux-android {
@@ -1035,7 +1044,7 @@ proc sqlite-get-readline-dir-list {} {
if {[opt-val with-readline-ldflags] in {auto ""}} {
# If the user did not supply their own --with-readline-ldflags
# value, hijack that flag to inject options which are known to
# work on a default Haiku installation.
# work on Haiku OS installations.
if {"" ne [glob -nocomplain /boot/system/lib/libreadline*]} {
proj-opt-set with-readline-ldflags {-L/boot/system/lib -lreadline}
}
@@ -1085,8 +1094,8 @@ proc sqlite-get-readline-dir-list {} {
# 4) Default to automatic search for optional readline
#
# 5) Try to find readline or editline. If it's not found AND the
# corresponding --FEATURE flag was explicitly given, fail fatally,
# else fail silently.
# corresponding --FEATURE flag was explicitly given then fail
# fatally, else fail non-fatally.
proc sqlite-check-line-editing {} {
msg-result "Checking for line-editing capability..."
define HAVE_READLINE 0
@@ -1099,7 +1108,7 @@ proc sqlite-check-line-editing {} {
# if the library is not found.
set libsForReadline {readline edit} ; # -l<LIB> names to check for readline().
# The libedit check changes this.
set editLibName "readline" ; # "readline" or "editline"
set editLibName "readline" ; # "readline" or "editline"
set editLibDef "HAVE_READLINE" ; # "HAVE_READLINE" or "HAVE_EDITLINE"
set dirLn [opt-val with-linenoise]
if {"" ne $dirLn} {
@@ -1116,7 +1125,7 @@ proc sqlite-check-line-editing {} {
foreach f $lnCOpts {
if {[file exists $dirLn/$f]} {
set lnC $dirLn/$f
break;
break
}
}
if {"" eq $lnC} {
@@ -1226,16 +1235,18 @@ proc sqlite-check-line-editing {} {
set rlLib [opt-val with-readline-ldflags]
#proc-debug "rlLib=$rlLib"
if {$rlLib in {auto ""}} {
set rlLib ""
set libTerm ""
if {[proj-check-function-in-lib tgetent "$editLibName ncurses curses termcap"]} {
set rlLib "" ; # make sure it's not "auto", as we may append to it below
set libTerm ""; # lib with tgetent(3)
if {[proj-check-function-in-lib tgetent [list $editLibName ncurses curses termcap]]} {
# ^^^ that libs list comes from the legacy configure script ^^^
set libTerm [get-define lib_tgetent]
undefine lib_tgetent
}
if {$editLibName eq $libTerm} {
# tgetent(3) was found in the editing library
set rlLib $libTerm
} elseif {[proj-check-function-in-lib readline $libsForReadline $libTerm]} {
# tgetent(3) was found in an external lib
set rlLib [get-define lib_readline]
lappend rlLib $libTerm
undefine lib_readline
@@ -1265,8 +1276,8 @@ proc sqlite-check-line-editing {} {
msg-result "Using $editLibName flags: $rlInc $rlLib"
# Check whether rl_completion_matches() has a signature we can use
# and disable that sub-feature if it doesn't.
if {![cctest \
-cflags "$rlInc -D${editLibDef}" -libs $rlLib -nooutput 1 -source {
if {![cctest -cflags "$rlInc -D${editLibDef}" -libs $rlLib -nooutput 1 \
-source {
#include <stdio.h>
#ifdef HAVE_EDITLINE
#include <editline/readline.h>
@@ -1319,7 +1330,7 @@ proc sqlite-handle-line-editing {} {
# - pkg-config: use only pkg-config to determine flags
# - /path/to/icu-config: use that to determine flags
#
# If --with-icu-config is used as neither pkg-config nor icu-config
# If --with-icu-config is used and neither pkg-config nor icu-config
# are found, fail fatally.
#
# If both --with-icu-ldflags and --with-icu-config are provided, they
@@ -1412,39 +1423,50 @@ proc sqlite-handle-icu {} {
# Makes the following environment changes:
#
# - defines LDFLAGS_DLOPEN to any linker flags needed for this
# feature. It may legally be empty on some systems where dlopen()
# is in libc.
# feature. It may legally be empty on (A) some systems where
# dlopen() is in libc and (B) certain Unix-esque Windows
# environments which identify as Windows for SQLite's purposes so
# use LoadLibrary().
#
# - If the feature is not available, adds
# -DSQLITE_OMIT_LOAD_EXTENSION=1 to the feature flags list.
proc sqlite-handle-load-extension {} {
define LDFLAGS_DLOPEN ""
set found 0
set suffix ""
proj-if-opt-truthy load-extension {
set found [proj-check-function-in-lib dlopen dl]
if {$found} {
define LDFLAGS_DLOPEN [get-define lib_dlopen]
undefine lib_dlopen
} else {
if {[proj-opt-was-provided load-extension]} {
# Explicit --enable-load-extension: fail if not found
proj-indented-notice -error {
--enable-load-extension was provided but dlopen()
not found. Use --disable-load-extension to bypass this
check.
}
} else {
# It was implicitly enabled: warn if not found
proj-indented-notice {
WARNING: dlopen() not found, so loadable module support will
be disabled. Use --disable-load-extension to bypass this
check.
switch -glob -- [get-define host] {
*-*-mingw* - *windows* {
incr found
set suffix "Using LoadLibrary()"
}
default {
set found [proj-check-function-in-lib dlopen dl]
if {$found} {
set suffix [define LDFLAGS_DLOPEN [get-define lib_dlopen]]
undefine lib_dlopen
} else {
if {[proj-opt-was-provided load-extension]} {
# Explicit --enable-load-extension: fail if not found
proj-indented-notice -error {
--enable-load-extension was provided but dlopen()
not found. Use --disable-load-extension to bypass this
check.
}
} else {
# It was implicitly enabled: warn if not found
proj-indented-notice {
WARNING: dlopen() not found, so loadable module support will
be disabled. Use --disable-load-extension to bypass this
check.
}
}
}
}
}
}
if {$found} {
msg-result "Loadable extension support enabled."
msg-result "Loadable extension support enabled. $suffix"
} else {
msg-result "Disabling loadable extension support. Use --enable-load-extension to enable them."
sqlite-add-feature-flag -DSQLITE_OMIT_LOAD_EXTENSION=1
+8 -12
View File
@@ -14,6 +14,13 @@
#ifndef _FTSINT_H
#define _FTSINT_H
/*
** Activate assert() only if SQLITE_TEST is enabled.
*/
#if !defined(NDEBUG) && !defined(SQLITE_DEBUG)
# define NDEBUG 1
#endif
#include <assert.h>
#include <stdlib.h>
#include <stddef.h>
@@ -21,10 +28,6 @@
#include <string.h>
#include <stdarg.h>
#if !defined(NDEBUG) && !defined(SQLITE_DEBUG)
# define NDEBUG 1
#endif
/* FTS3/FTS4 require virtual tables */
#ifdef SQLITE_OMIT_VIRTUALTABLE
# undef SQLITE_ENABLE_FTS3
@@ -44,7 +47,7 @@
/* If not building as part of the core, include sqlite3ext.h. */
#ifndef SQLITE_CORE
# include "sqlite3ext.h"
# include "sqlite3ext.h"
SQLITE_EXTENSION_INIT3
#endif
@@ -186,13 +189,6 @@ typedef sqlite3_int64 i64; /* 8-byte signed integer */
*/
#define UNUSED_PARAMETER(x) (void)(x)
/*
** Activate assert() only if SQLITE_TEST is enabled.
*/
#if !defined(NDEBUG) && !defined(SQLITE_DEBUG)
# define NDEBUG 1
#endif
/*
** The TESTONLY macro is used to enclose variable declarations or
** other bits of code that are needed to support the arguments
+4 -4
View File
@@ -3714,8 +3714,8 @@ struct NodeWriter {
** to an appendable b-tree segment.
*/
struct IncrmergeWriter {
int nLeafEst; /* Space allocated for leaf blocks */
int nWork; /* Number of leaf pages flushed */
i64 nLeafEst; /* Space allocated for leaf blocks */
i64 nWork; /* Number of leaf pages flushed */
sqlite3_int64 iAbsLevel; /* Absolute level of input segments */
int iIdx; /* Index of *output* segment in iAbsLevel+1 */
sqlite3_int64 iStart; /* Block number of first allocated block */
@@ -4461,7 +4461,7 @@ static int fts3IncrmergeWriter(
){
int rc; /* Return Code */
int i; /* Iterator variable */
int nLeafEst = 0; /* Blocks allocated for leaf nodes */
i64 nLeafEst = 0; /* Blocks allocated for leaf nodes */
sqlite3_stmt *pLeafEst = 0; /* SQL used to determine nLeafEst */
sqlite3_stmt *pFirstBlock = 0; /* SQL used to determine first block */
@@ -4471,7 +4471,7 @@ static int fts3IncrmergeWriter(
sqlite3_bind_int64(pLeafEst, 1, iAbsLevel);
sqlite3_bind_int64(pLeafEst, 2, pCsr->nSegment);
if( SQLITE_ROW==sqlite3_step(pLeafEst) ){
nLeafEst = sqlite3_column_int(pLeafEst, 0);
nLeafEst = sqlite3_column_int64(pLeafEst, 0);
}
rc = sqlite3_reset(pLeafEst);
}
+7 -14
View File
@@ -60,21 +60,14 @@ typedef sqlite3_uint64 u64;
# define LARGEST_INT64 (0xffffffff|(((i64)0x7fffffff)<<32))
# define SMALLEST_INT64 (((i64)-1) - LARGEST_INT64)
/* The uptr type is an unsigned integer large enough to hold a pointer
/*
** This macro is used in a single assert() within fts5 to check that an
** allocation is aligned to an 8-byte boundary. But it is a complicated
** macro to get right for multiple platforms without generating warnings.
** So instead of reproducing the entire definition from sqliteInt.h, we
** just do without this assert() for the rare non-amalgamation builds.
*/
#if defined(HAVE_STDINT_H)
typedef uintptr_t uptr;
#elif SQLITE_PTRSIZE==4
typedef u32 uptr;
#else
typedef u64 uptr;
#endif
#ifdef SQLITE_4_BYTE_ALIGNED_MALLOC
# define EIGHT_BYTE_ALIGNMENT(X) ((((uptr)(X) - (uptr)0)&3)==0)
#else
# define EIGHT_BYTE_ALIGNMENT(X) ((((uptr)(X) - (uptr)0)&7)==0)
#endif
#define EIGHT_BYTE_ALIGNMENT(x) 1
/*
** Macros needed to provide flexible arrays in a portable way
+44 -24
View File
@@ -1986,9 +1986,9 @@ static void fts5SegIterSetNext(Fts5Index *p, Fts5SegIter *pIter){
** leave an error in the Fts5Index object.
*/
static void fts5SegIterAllocTombstone(Fts5Index *p, Fts5SegIter *pIter){
const int nTomb = pIter->pSeg->nPgTombstone;
const i64 nTomb = (i64)pIter->pSeg->nPgTombstone;
if( nTomb>0 ){
int nByte = SZ_FTS5TOMBSTONEARRAY(nTomb+1);
i64 nByte = SZ_FTS5TOMBSTONEARRAY(nTomb+1);
Fts5TombstoneArray *pNew;
pNew = (Fts5TombstoneArray*)sqlite3Fts5MallocZero(&p->rc, nByte);
if( pNew ){
@@ -2481,18 +2481,20 @@ static void fts5SegIterReverse(Fts5Index *p, Fts5SegIter *pIter){
fts5DataRelease(pIter->pLeaf);
pIter->pLeaf = pLast;
pIter->iLeafPgno = pgnoLast;
iOff = fts5LeafFirstRowidOff(pLast);
if( iOff>pLast->szLeaf ){
FTS5_CORRUPT_ITER(p, pIter);
return;
}
iOff += fts5GetVarint(&pLast->p[iOff], (u64*)&pIter->iRowid);
pIter->iLeafOffset = iOff;
if( p->rc==SQLITE_OK ){
iOff = fts5LeafFirstRowidOff(pLast);
if( iOff>pLast->szLeaf ){
FTS5_CORRUPT_ITER(p, pIter);
return;
}
iOff += fts5GetVarint(&pLast->p[iOff], (u64*)&pIter->iRowid);
pIter->iLeafOffset = iOff;
if( fts5LeafIsTermless(pLast) ){
pIter->iEndofDoclist = pLast->nn+1;
}else{
pIter->iEndofDoclist = fts5LeafFirstTermOff(pLast);
if( fts5LeafIsTermless(pLast) ){
pIter->iEndofDoclist = pLast->nn+1;
}else{
pIter->iEndofDoclist = fts5LeafFirstTermOff(pLast);
}
}
}
@@ -5845,7 +5847,7 @@ static Fts5Structure *fts5IndexOptimizeStruct(
}
nByte += (((i64)pStruct->nLevel)+1) * sizeof(Fts5StructureLevel);
assert( nByte==SZ_FTS5STRUCTURE(pStruct->nLevel+2) );
assert( nByte==(i64)SZ_FTS5STRUCTURE(pStruct->nLevel+2) );
pNew = (Fts5Structure*)sqlite3Fts5MallocZero(&p->rc, nByte);
if( pNew ){
@@ -6820,10 +6822,13 @@ int sqlite3Fts5IndexRollback(Fts5Index *p){
*/
int sqlite3Fts5IndexReinit(Fts5Index *p){
Fts5Structure *pTmp;
u8 tmpSpace[SZ_FTS5STRUCTURE(1)];
union {
Fts5Structure sFts;
u8 tmpSpace[SZ_FTS5STRUCTURE(1)];
} uFts;
fts5StructureInvalidate(p);
fts5IndexDiscardData(p);
pTmp = (Fts5Structure*)tmpSpace;
pTmp = &uFts.sFts;
memset(pTmp, 0, SZ_FTS5STRUCTURE(1));
if( p->pConfig->bContentlessDelete ){
pTmp->nOriginCntr = 1;
@@ -8284,19 +8289,27 @@ static int fts5TestUtf8(const char *z, int n){
/*
** This function is also purely an internal test. It does not contribute to
** FTS functionality, or even the integrity-check, in any way.
**
** This function sets output variable (*pbFail) to true if the test fails. Or
** leaves it unchanged if the test succeeds.
*/
static void fts5TestTerm(
Fts5Index *p,
Fts5Buffer *pPrev, /* Previous term */
const char *z, int n, /* Possibly new term to test */
u64 expected,
u64 *pCksum
u64 *pCksum,
int *pbFail
){
int rc = p->rc;
if( pPrev->n==0 ){
fts5BufferSet(&rc, pPrev, n, (const u8*)z);
}else
if( rc==SQLITE_OK && (pPrev->n!=n || memcmp(pPrev->p, z, n)) ){
if( *pbFail==0
&& rc==SQLITE_OK
&& (pPrev->n!=n || memcmp(pPrev->p, z, n))
&& (p->pHash==0 || p->pHash->nEntry==0)
){
u64 cksum3 = *pCksum;
const char *zTerm = (const char*)&pPrev->p[1]; /* term sans prefix-byte */
int nTerm = pPrev->n-1; /* Size of zTerm in bytes */
@@ -8346,7 +8359,7 @@ static void fts5TestTerm(
fts5BufferSet(&rc, pPrev, n, (const u8*)z);
if( rc==SQLITE_OK && cksum3!=expected ){
rc = FTS5_CORRUPT;
*pbFail = 1;
}
*pCksum = cksum3;
}
@@ -8355,7 +8368,7 @@ static void fts5TestTerm(
#else
# define fts5TestDlidxReverse(x,y,z)
# define fts5TestTerm(u,v,w,x,y,z)
# define fts5TestTerm(t,u,v,w,x,y,z)
#endif
/*
@@ -8613,6 +8626,7 @@ int sqlite3Fts5IndexIntegrityCheck(Fts5Index *p, u64 cksum, int bUseCksum){
/* Used by extra internal tests only run if NDEBUG is not defined */
u64 cksum3 = 0; /* Checksum based on contents of indexes */
Fts5Buffer term = {0,0,0}; /* Buffer used to hold most recent term */
int bTestFail = 0;
#endif
const int flags = FTS5INDEX_QUERY_NOOUTPUT;
@@ -8655,7 +8669,7 @@ int sqlite3Fts5IndexIntegrityCheck(Fts5Index *p, u64 cksum, int bUseCksum){
char *z = (char*)fts5MultiIterTerm(pIter, &n);
/* If this is a new term, query for it. Update cksum3 with the results. */
fts5TestTerm(p, &term, z, n, cksum2, &cksum3);
fts5TestTerm(p, &term, z, n, cksum2, &cksum3, &bTestFail);
if( p->rc ) break;
if( eDetail==FTS5_DETAIL_NONE ){
@@ -8673,7 +8687,7 @@ int sqlite3Fts5IndexIntegrityCheck(Fts5Index *p, u64 cksum, int bUseCksum){
}
}
}
fts5TestTerm(p, &term, 0, 0, cksum2, &cksum3);
fts5TestTerm(p, &term, 0, 0, cksum2, &cksum3, &bTestFail);
fts5MultiIterFree(pIter);
if( p->rc==SQLITE_OK && bUseCksum && cksum!=cksum2 ){
@@ -8682,11 +8696,17 @@ int sqlite3Fts5IndexIntegrityCheck(Fts5Index *p, u64 cksum, int bUseCksum){
"fts5: checksum mismatch for table \"%s\"", p->pConfig->zName
);
}
fts5StructureRelease(pStruct);
#ifdef SQLITE_DEBUG
/* In SQLITE_DEBUG builds, expensive extra checks were run as part of
** the integrity-check above. If no other errors were detected, but one
** of these tests failed, set the result to SQLITE_CORRUPT_VTAB here. */
if( p->rc==SQLITE_OK && bTestFail ){
p->rc = FTS5_CORRUPT;
}
fts5BufferFree(&term);
#endif
fts5StructureRelease(pStruct);
fts5BufferFree(&poslist);
return fts5IndexReturn(p);
}
+215 -3
View File
@@ -6644,7 +6644,7 @@ do_test 48.0 {
do_catchsql_test 48.1 {
INSERT INTO t1(t1) VALUES('integrity-check');
} {1 {database disk image is malformed}}
} {1 {fts5: corruption on page 1, segment 1, table "t1"}}
#--------------------------------------------------------------------------
reset_db
@@ -10106,7 +10106,7 @@ do_test 68.0 {
do_catchsql_test 68.1 {
PRAGMA reverse_unordered_selects=ON;
INSERT INTO t1(t1) SELECT x FROM t2;
} {1 {database disk image is malformed}}
} {1 {fts5: corruption on page 1, segment 1, table "t1"}}
#-------------------------------------------------------------------------
reset_db
@@ -15909,8 +15909,220 @@ do_catchsql_test 82.4 {
SAVEPOINT b;
} {1 {database disk image is malformed}}
#-------------------------------------------------------------------------
reset_db
do_test 83.0 {
sqlite3 db {}
db deserialize [decode_hexdb {
.open --hexdb
| size 24576 pagesize 4096 filename crash-c4a4c5492615bd.db
| page 1 offset 0
| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3.
| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 06 .....@ ........
| 32: 00 00 00 00 00 00 00 00 00 00 00 06 00 00 00 00 ................
| 96: 00 00 00 00 0d 00 00 00 06 0e 0f 00 0f aa 0f 53 ...............S
| 112: 0e e8 0e 8b 0e 33 0e 0f 00 01 00 00 00 00 00 00 .....3..........
| 3584: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 22 ................
| 3600: 06 06 17 11 11 01 31 74 61 62 6c 65 62 62 62 62 ......1tablebbbb
| 3616: 06 43 52 45 41 54 45 20 54 41 42 4c 45 20 62 62 .CREATE TABLE bb
| 3632: 28 61 29 56 05 06 17 1f 1f 01 7d 74 61 62 6c 65 (a)V.......table
| 3648: 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63 6f 6e 66 t1_configt1_conf
| 3664: 69 67 05 43 52 45 41 54 45 20 54 41 42 4c 45 20 ig.CREATE TABLE
| 3680: 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b 20 50 52 't1_config'(k PR
| 3696: 49 4d 41 52 59 20 4b 45 59 2c 20 76 29 20 57 49 IMARY KEY, v) WI
| 3712: 54 48 4f 55 54 20 52 4f 57 49 44 5b 04 07 17 21 THOUT ROWID[...!
| 3728: 21 01 81 01 74 61 62 6c 65 74 31 5f 64 6f 63 73 !...tablet1_docs
| 3744: 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65 04 43 52 izet1_docsize.CR
| 3760: 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 64 EATE TABLE 't1_d
| 3776: 6f 63 73 69 7a 65 27 28 69 64 20 49 4e 54 45 47 ocsize'(id INTEG
| 3792: 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 ER PRIMARY KEY,
| 3808: 73 7a 20 42 4c 4f 42 29 69 03 07 17 19 19 01 81 sz BLOB)i.......
| 3824: 2d 74 61 62 6c 65 74 31 5f 69 64 78 74 31 5f 69 -tablet1_idxt1_i
| 3840: 64 78 03 43 52 45 41 54 45 20 54 41 42 4c 45 20 dx.CREATE TABLE
| 3856: 27 74 31 5f 69 64 78 27 28 73 65 67 69 64 2c 20 't1_idx'(segid,
| 3872: 74 65 72 6d 2c 20 70 67 6e 6f 2c 20 50 52 49 4d term, pgno, PRIM
| 3888: 41 52 59 20 4b 45 59 28 73 65 67 69 64 2c 20 74 ARY KEY(segid, t
| 3904: 65 72 6d 29 29 20 57 49 54 48 4f 55 54 20 52 4f erm)) WITHOUT RO
| 3920: 57 49 44 55 02 07 17 1b 1b 01 81 01 74 61 62 6c WIDU........tabl
| 3936: 65 74 31 5f 64 61 74 61 74 31 5f 64 61 74 61 02 et1_datat1_data.
| 3952: 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 CREATE TABLE 't1
| 3968: 5f 64 61 74 61 27 28 69 64 20 49 4e 54 45 47 45 _data'(id INTEGE
| 3984: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 62 R PRIMARY KEY, b
| 4000: 6c 6f 63 6b 20 42 4c 4f 42 29 54 01 07 17 11 11 lock BLOB)T.....
| 4016: 08 81 15 74 61 62 6c 65 74 31 74 31 43 52 45 41 ...tablet1t1CREA
| 4032: 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45 TE VIRTUAL TABLE
| 4048: 20 74 31 20 55 53 49 4e 47 20 66 74 73 35 28 61 t1 USING fts5(a
| 4064: 2c 62 2c 70 72 65 66 69 78 3d 22 31 2c 32 2c 33 ,b,prefix=.1,2,3
| 4080: 2c 34 22 2c 20 63 6f 6e 74 65 6e 74 3d 22 22 29 ,4., content=..)
| page 2 offset 4096
| 0: 0d 0b 6a 00 37 09 4c 02 0f e7 09 4c 0f c6 0f a4 ..j.7.L....L....
| 16: 0f 88 0f 6d 0f 4b 0f 2c 0f 0e 0e ec 0e cd 0e ad ...m.K.,........
| 32: 0e 8e 0e 6c 0e 4b 0e 29 0e 08 0d e6 0d c4 0d b5 ...l.K.)........
| 48: 0d 97 0d 76 0d 54 0d 31 0d 15 0c f3 0c d3 0c b5 ...v.T.1........
| 64: 0c 95 0c 73 0c 54 0c 32 0c 10 0b ee 0b cc 0b b0 ...s.T.2........
| 80: 0b 8d 0b 7e 0b 48 0b 2e 0b 00 4a ef fa cc 0a ad ...~.H....J.....
| 96: 0a 8c 0a 6d 0a 4d 0a 2b 0a 0c 09 00 00 00 00 00 ...m.M.+........
| 2368: 00 00 00 00 00 00 00 00 00 00 00 00 15 0a 03 00 ................
| 2384: 30 00 00 00 01 01 03 35 00 03 01 01 12 02 01 12 0......5........
| 2400: 03 01 11 1c 8c 80 80 80 80 10 03 00 3e 00 00 00 ............>...
| 2416: 17 01 05 05 34 74 61 62 6c 03 02 03 01 04 77 68 ....4tabl.....wh
| 2432: 65 72 03 02 06 09 1b 8c 80 80 80 80 0f 03 00 3c er.............<
| 2448: 00 00 00 16 05 34 66 74 73 34 03 02 02 01 04 6e .....4fts4.....n
| 2464: 75 6d 62 03 07 01 04 09 1b 8c 80 80 80 80 0e 03 umb.............
| 2480: 00 3c 00 00 00 16 04 33 74 68 65 03 06 01 01 04 .<.....3the.....
| 2496: 01 03 77 68 65 03 02 04 04 0a 1b 8c 80 80 80 80 ..whe...........
| 2512: 0d 03 00 3c 00 00 00 16 04 33 6e 75 6d 03 06 01 ...<.....3num...
| 2528: 01 05 01 03 74 61 62 03 02 03 04 0a 19 8c 80 80 ....tab.........
| 2544: 80 80 0c 03 00 38 00 00 00 14 03 32 77 68 03 02 .....8.....2wh..
| 2560: 04 00 04 33 66 74 73 03 02 02 04 07 18 8c 80 80 ...3fts.........
| 2576: 80 80 0b 03 00 36 00 00 00 13 03 32 74 61 03 02 .....6.....2ta..
| 2592: 03 02 01 68 03 06 01 01 04 04 07 1b 8c 80 80 80 ...h............
| 2608: 80 0a 03 00 3c 00 00 00 16 03 32 6e 75 03 06 01 ....<.....2nu...
| 2624: 01 05 01 02 6f 66 03 06 01 01 06 04 09 19 8c 80 ....of..........
| 2640: 80 80 80 09 03 00 38 00 00 00 14 03 32 66 74 03 ......8.....2ft.
| 2656: 02 02 01 02 69 73 02 06 01 01 03 04 07 18 8c 80 ....is..........
| 2672: 80 80 22 08 03 00 36 00 00 00 13 02 31 74 03 08 ......6.....1t..
| 2688: 03 01 01 04 01 01 77 03 02 04 04 09 1a 8c 80 80 ......w.........
| 2704: 80 80 07 03 00 3a 00 00 00 15 02 31 6e 03 08 01 .....:.....1n...
| 2720: 01 02 05 01 01 6f 03 06 01 01 06 04 09 18 8c 80 .....o..........
| 2736: 80 80 80 06 03 00 36 00 00 00 13 04 02 31 66 03 ......6......1f.
| 2752: 02 02 01 01 69 03 06 01 01 03 05 06 1c 8c 80 80 ....i...........
| 2768: 80 80 05 03 00 3e 00 00 00 17 04 30 74 68 65 03 .....>.....0the.
| 2784: 06 01 01 04 01 05 77 68 65 72 65 03 02 04 0a 15 ......where.....
| 2800: 8c 80 80 80 80 04 03 00 30 00 00 00 11 01 01 06 ........0.......
| 2816: 06 30 74 61 62 6c 65 03 01 f3 07 1c 8c 80 80 80 .0table.........
| 2832: 80 03 03 00 3e 00 00 00 17 07 30 6e 75 6d 62 65 ....>.....0numbe
| 2848: 72 03 06 01 01 05 01 02 6f 66 03 06 04 0d 13 8c r.......of......
| 2864: 80 80 80 80 02 03 00 2c 00 00 00 0f 01 01 03 02 .......,........
| 2880: 30 6e 03 06 01 01 02 07 1b 8c 80 80 80 80 01 03 0n..............
| 2896: 00 3c 00 00 00 16 08 30 66 74 73 34 61 75 78 03 .<.....0fts4aux.
| 2912: 02 02 01 02 69 73 03 06 04 0c 00 00 00 14 2a 00 ....is........*.
| 2928: 00 00 01 01 02 24 00 02 01 01 12 02 01 12 08 88 .....$..........
| 2944: 80 80 80 80 12 03 00 16 00 00 00 05 02 1c 88 80 ................
| 2960: 80 80 80 11 03 00 3e 00 00 00 17 05 34 72 6f 77 ......>.....4row
| 2976: 73 02 06 01 01 05 01 04 74 68 65 72 02 02 04 0b s.......ther....
| 2992: 15 88 80 80 80 80 10 03 00 30 00 00 00 11 02 01 .........0......
| 3008: 01 07 05 34 62 65 74 77 02 02 04 08 1b 88 80 80 ...4betw........
| 3024: 80 80 0f 03 00 3c 00 00 00 16 04 04 33 72 6f 77 .....<......3row
| 3040: 02 06 01 01 05 01 03 74 68 65 02 08 05 0a 1b 88 .......the......
| 3056: 80 80 80 80 0e 03 00 3c 00 00 00 16 01 01 02 04 .......<........
| 3072: 33 61 72 65 02 02 b3 01 03 62 65 74 02 02 07 08 3are.....bet....
| 3088: 1b 88 80 80 80 80 0d 03 00 3c 00 00 00 16 03 32 .........<.....2
| 3104: 74 68 02 08 02 01 01 07 00 04 33 61 6e 64 02 06 th........3and..
| 3120: 04 0a 1b 88 80 80 80 80 0c 03 00 3c 00 00 00 16 ...........<....
| 3136: 03 32 69 6e 02 06 01 01 06 01 02 72 6f 02 06 01 .2in.......ro...
| 3152: 01 05 04 09 18 88 80 80 80 80 0b 03 00 36 00 0f .............6..
| 3168: f0 13 02 03 32 61 72 02 02 03 01 02 62 65 02 02 ....2ar.....be..
| 3184: 03 05 07 1b 88 80 80 80 80 0a 03 00 3c dd 00 00 ............<...
| 3200: 18 c2 31 74 02 08 02 01 01 07 00 03 32 61 6e 02 ..1t........2an.
| 3216: 06 01 01 04 09 19 88 80 80 80 80 09 03 00 38 00 ..............8.
| 3232: 00 00 14 02 31 6e 02 06 01 01 03 01 01 72 02 06 ....1n.......r..
| 3248: 01 01 05 04 08 17 88 80 80 80 80 08 03 00 34 00 ..............4.
| 3264: 00 00 12 02 31 62 02 02 04 01 01 69 02 06 01 01 ....1b.....i....
| 3280: 06 04 06 19 88 80 90 80 80 07 03 00 38 00 00 00 ............8...
| 3296: 14 04 02 31 32 02 02 05 01 01 61 02 08 03 01 01 ...12.....a.....
| 3312: 02 05 06 1b 88 80 80 80 80 06 03 00 3c 00 00 00 ............<...
| 3328: 16 06 30 74 68 65 72 65 02 02 02 00 02 31 31 02 ..0there.....11.
| 3344: 06 01 01 04 0a 15 88 80 80 80 80 05 03 00 30 00 ..............0.
| 3360: 00 00 11 01 01 05 04 30 74 68 65 02 06 01 01 07 .......0the.....
| 3376: 07 1c 88 80 80 80 80 04 03 00 3e 00 00 00 17 01 ..........>.....
| 3392: 01 06 02 30 6e 02 06 01 01 03 01 04 72 6f 77 73 ...0n.......rows
| 3408: 02 06 07 08 1b 88 80 80 80 80 03 03 00 3c 00 00 .............<..
| 3424: 00 16 08 30 62 65 74 77 65 65 6e 02 02 04 01 02 ...0between.....
| 3440: 69 6e 02 06 04 0c 1a 88 80 80 80 80 02 03 00 3a in.............:
| 3456: 00 00 00 15 04 30 61 6e 64 02 06 01 01 02 02 02 .....0and.......
| 3472: 72 65 02 02 03 04 0a 17 88 80 80 80 80 01 03 00 re..............
| 3488: 34 00 00 0c 52 02 30 31 02 06 01 01 04 01 01 32 4...R.01.......2
| 3504: 02 02 05 04 08 08 84 80 80 80 80 12 03 00 16 00 ................
| 3520: 00 00 05 04 1b 84 80 80 80 80 11 03 00 3c 00 00 .............<..
| 3536: 00 16 05 34 74 61 62 6c 01 06 00 f1 05 02 03 65 ...4tabl.......e
| 3552: 72 6d 01 02 04 0b 1b 84 80 80 80 80 10 03 00 3c rm.............<
| 3568: 00 00 00 16 05 34 65 61 63 68 01 02 03 01 04 70 .....4each.....p
| 3584: 72 65 73 01 02 05 04 09 1a 84 80 80 80 80 0f 03 res.............
| 3600: 00 3a 00 00 00 15 04 33 74 65 72 01 02 04 02 02 .:.....3ter.....
| 3616: 68 65 01 06 01 01 03 04 08 1b 84 80 80 80 80 0e he..............
| 3632: 03 00 3c 00 00 00 16 04 33 70 72 65 01 02 05 01 ..<.....3pre....
| 3648: 03 74 61 62 01 06 01 01 05 04 08 1a 84 80 80 80 .tab............
| 3664: 80 0d 03 00 3a 00 00 00 15 04 33 66 6f 72 01 02 ....:.....3for..
| 3680: 02 02 02 74 73 01 06 01 01 04 04 08 1b 84 80 80 ...ts...........
| 3696: 80 80 0c 03 00 3c 00 00 00 16 03 32 74 68 01 06 .....<.....2th..
| 3712: 01 01 03 00 04 33 65 61 63 01 02 03 04 09 18 74 .....3eac......t
| 3728: 80 80 80 80 0b 03 00 36 00 00 00 13 03 32 74 61 .......6.....2ta
| 3744: 01 06 01 01 05 02 01 65 01 02 04 04 09 19 84 80 .......e........
| 3760: 80 80 80 0a 03 00 38 00 00 00 14 03 32 69 6e 01 ......8.....2in.
| 3776: 06 01 01 02 11 02 70 62 01 02 05 04 09 18 84 80 ......pb........
| 3792: 80 80 80 09 03 00 36 00 00 00 13 03 32 66 6f 01 ......6.....2fo.
| 3808: 02 02 02 01 74 01 06 01 01 04 04 07 1b 84 80 80 ....t...........
| 3824: 80 80 08 03 00 3c 0d c0 00 16 12 31 74 01 0a 04 .....<.....1t...
| 3840: 01 01 03 04 00 03 32 65 61 01 02 03 04 0a 17 84 ......2ea.......
| 3856: 80 80 80 80 07 03 00 34 00 00 00 12 02 31 69 01 .......4.....1i.
| 3872: 06 01 01 02 01 01 70 01 02 05 04 08 18 84 80 80 ......p.........
| 3888: 80 80 06 03 00 36 00 00 00 13 02 31 65 01 02 03 .....6.....1e...
| 3904: 01 01 66 01 08 02 5b 01 04 04 06 1b 84 80 80 80 ..f...[.........
| 3920: 80 05 03 00 3c 00 00 00 16 05 30 74 65 72 6d 01 ....<.....0term.
| 3936: 02 04 02 02 68 65 01 06 01 01 03 04 09 14 84 80 ....he..........
| 3952: 80 80 80 04 03 00 2e 00 00 00 10 06 30 74 61 62 ............0tab
| 3968: 6c 65 01 06 01 01 05 04 15 84 80 80 80 80 03 03 le..............
| 3984: 00 30 00 00 00 11 01 f8 30 70 72 65 73 65 6e 74 .0......0present
| 4000: 01 02 05 05 1b 84 80 80 80 80 02 03 00 3c 00 00 .............<..
| 4016: 00 16 04 30 66 74 73 01 06 01 01 04 01 02 69 6e ...0fts.......in
| 4032: 01 06 01 01 04 0a 1a 84 80 80 80 80 01 03 00 3a ...............:
| 4048: 00 00 00 15 05 30 65 61 63 68 01 02 03 01 03 66 .....0each.....f
| 4064: 6f 72 01 02 02 04 09 06 01 03 00 12 03 0b 0f 00 or..............
| 4080: 00 08 8c 80 80 80 80 11 03 00 16 00 00 00 05 04 ................
| page 3 offset 8192
| 0: 0a 00 00 00 32 0e 4f 00 0f fa 0f f1 0f e9 0f e1 ....2.O.........
| 16: 0f d8 0f d1 0f c9 0f c1 0f b9 0f b1 0f a9 0f a0 ................
| 32: 0f 98 0f 90 0f 87 0f 80 0f 78 0f 71 0f 68 0f 5f .........x.q.h._
| 48: 0f 56 0f 4d 0f 41 0f 38 0f 2f 0f 26 0f 1d 0f 13 .V.M.A.8./.&....
| 64: 0f 0a 0f 01 0e f7 0e ee 0e e6 0e dd 0e d6 0e cd ................
| 80: 0e c3 0e ba 0e b0 0e a8 0e 9f 0e 96 0e 00 00 00 ................
| 3648: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 08 ................
| 3664: 04 01 10 01 03 34 74 20 07 04 02 4e 01 03 34 1e .....4t ...N..4.
| 3680: 09 04 01 12 01 03 33 74 68 1c 08 04 01 10 01 03 ......3th.......
| 3696: 33 6e 1a 08 04 01 10 01 03 32 77 18 08 04 01 10 3n.......2w.....
| 3712: 01 03 32 74 16 08 04 01 10 01 03 32 6e 14 07 04 ..2t.......2n...
| 3728: 01 0e 01 03 32 12 08 04 01 10 01 03 31 74 10 08 ....2.......1t..
| 3744: 04 01 10 01 03 31 6e 0e 07 04 01 0e 01 03 31 0c .....1n.......1.
| 3760: 09 04 01 12 01 03 30 74 68 0a 08 04 01 10 01 03 ......0th.......
| 3776: 30 74 08 19 04 01 12 01 03 30 6e 75 06 08 04 01 0t.......0nu....
| 3792: 10 01 03 30 6e 04 06 04 01 0c 01 03 02 08 04 01 ...0n...........
| 3808: 10 01 02 34 72 22 07 04 01 0e 01 02 34 20 08 04 ...4r.......4 ..
| 3824: 01 10 01 02 33 72 1e 09 04 01 12 01 02 33 61 72 ....3r.......3ar
| 3840: 1c 08 04 01 10 01 02 32 74 1a 08 04 01 10 01 02 .......2t.......
| 3856: 32 69 18 09 04 01 12 01 02 32 60 82 16 08 04 01 2i.......2`.....
| 3872: 10 01 02 31 74 14 08 04 01 10 01 02 31 6e 12 08 ...1t.......1n..
| 3888: 04 01 10 01 02 31 62 10 08 04 01 10 01 02 31 32 .....1b.......12
| 3904: 0e 0b 04 01 16 01 02 30 74 68 65 72 0c 08 04 01 .......0ther....
| 3920: 10 01 02 30 74 0a 08 04 01 10 01 02 30 6e 08 08 ...0t.......0n..
| 3936: 04 01 10 01 02 30 62 06 08 04 01 10 01 02 30 61 .....0b.......0a
| 3952: 04 06 04 01 0c 01 02 02 07 04 09 10 01 34 74 22 .............4t.
| 3968: 06 04 09 0e 01 34 20 08 04 09 12 01 33 74 65 1e .....4 .....3te.
| 3984: 07 04 09 10 01 33 70 1c 07 04 09 10 01 33 66 1a .....3p......3f.
| 4000: 08 04 09 12 01 32 74 68 18 07 04 09 10 01 32 74 .....2th......2t
| 4016: 16 07 04 09 10 01 32 69 14 07 04 09 10 01 32 66 ......2i......2f
| 4032: 12 07 04 09 10 01 31 74 10 07 04 09 10 01 31 69 ......1t......1i
| 4048: 0e 06 04 09 0e 01 31 0c 08 04 09 12 01 30 74 65 ......1......0te
| 4064: 0a 07 04 09 10 01 30 74 08 07 04 09 10 01 30 70 ......0t......0p
| 4080: 06 08 04 09 12 01 30 66 74 04 05 04 09 0c 01 02 ......0ft.......
| page 4 offset 12288
| 0: 0d 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
| 4064: 00 00 00 00 00 00 00 00 00 00 00 05 03 03 00 10 ................
| 4080: 03 05 05 02 03 00 10 04 06 05 01 03 00 10 04 04 ................
| page 5 offset 16384
| 0: 0a 00 00 00 02 0f eb 00 0f eb 0f f4 00 00 00 00 ................
| 4064: 00 00 00 00 00 00 00 00 00 00 00 08 03 15 01 70 ...............p
| 4080: 67 83 7a 18 0b 03 1b 01 76 65 72 73 69 6f 6e 04 g.z.....version.
| page 6 offset 20480
| 0: 0d 00 00 00 03 0f f2 00 0f fc 0f 00 00 00 00 00 ................
| 4080: 00 00 03 03 02 01 03 03 02 02 01 02 02 01 02 09 ................
| end crash-c4a4c5492615bd.db
}]} {}
do_catchsql_test 83.1 {
SELECT * FROM t1('R*R*R*R*R*R*R*R*') WHERE (a,b)<=(current_date,0 BETWEEN 'a'<>11 AND '') ORDER BY rowid DESC;
} {/.*fts5: corruption found/}
sqlite3_fts5_may_be_corrupt 0
finish_test
+53
View File
@@ -90,5 +90,58 @@ do_execsql_test 3.7 {
SELECT * FROM sqlite_schema
}
#-------------------------------------------------------------------------
reset_db
proc hex_to_blob {hex} {
binary encode hex $hex
}
db func hex_to_blob hex_to_blob
do_execsql_test 4.0 {
CREATE VIRTUAL TABLE x1 USING fts5(x, content='', contentless_delete=1);
BEGIN;
INSERT INTO x1(rowid, x) VALUES(1, 'a b c d e f g h');
INSERT INTO x1(rowid, x) VALUES(2, 'a b c d e f g h');
COMMIT;
DELETE FROM x1 WHERE rowid=1;
}
do_execsql_test 4.1 {
SELECT hex(block) FROM x1_data WHERE id=10
} {
00000000FF00000101010200010101010101010102
}
do_execsql_test 4.2.1 {
UPDATE x1_data SET block=
X'00000000FF00000101010200010101010101819C9B95A8000102'
WHERE id=10;
}
do_catchsql_test 4.2.2 {
SELECT * FROM x1('c d e');
} {1 {out of memory}}
do_execsql_test 4.3.1 {
UPDATE x1_data SET block=
X'00000000FF000001010102000101010101019282AFF9A0000102'
WHERE id=10;
}
do_catchsql_test 4.3.2 {
SELECT * FROM x1('c d e');
} {1 {out of memory}}
do_execsql_test 4.4.1 {
UPDATE x1_data SET block=
X'00000000FF000001010102000101010101018181808080130102'
WHERE id=10;
}
do_catchsql_test 4.3.2 {
SELECT * FROM x1('c d e');
} {1 {out of memory}}
finish_test
+6
View File
@@ -37,6 +37,12 @@ do_execsql_test 2.1 {
INSERT INTO yy(yy) VALUES('integrity-check');
}
db close
sqlite3 db test.db
do_execsql_test 2.1 {
INSERT INTO yy(yy) VALUES('integrity-check');
}
#--------------------------------------------------------------------
#
do_execsql_test 3.0 {
+49
View File
@@ -40,4 +40,53 @@ do_execsql_test 1.2 {
SELECT * FROM t1 LEFT JOIN vt ON (vt MATCH 'abc')
} {1 abc 2 abc}
do_execsql_test 1.3 {
DELETE FROM t1;
INSERT INTO t1 VALUES(14);
}
do_execsql_test 1.4 {
SELECT * FROM vt LEFT JOIN t1 ON vt.rowid = 1;
} {
abc 14
xyz {}
}
#-------------------------------------------------------------------------
reset_db
do_execsql_test 2.0 {
CREATE VIRTUAL TABLE t0 USING fts5(a,b);
INSERT INTO t0(a,b)VALUES(1,0);
CREATE TABLE t1(x);
}
do_execsql_test 2.1 {
SELECT * FROM t0 LEFT JOIN t1;
} {1 0 {}}
breakpoint
do_catchsql_test 2.2 {
SELECT * FROM t0 LEFT JOIN t1 ON t0.b MATCH '1';
} {1 {no query solution}}
do_execsql_test 2.3 {
SELECT * FROM t0 LEFT JOIN t1 ON +b MATCH '1';
} {1 0 {}}
#-------------------------------------------------------------------------
reset_db
do_execsql_test 3.0 {
CREATE VIRTUAL TABLE t0 USING fts5(c0, c1);
INSERT INTO t0(c0,c1) VALUES (1,0);
}
do_catchsql_test 3.1 {
SELECT * FROM t0
LEFT JOIN ( SELECT 0 AS col_0 )
ON ((((t0.c1 MATCH '1')AND(CASE WHEN t0.c0 THEN CAST(t0.c1 AS INTEGER) ELSE 1 END))));
} {1 {no query solution}}
finish_test
-56
View File
@@ -1,56 +0,0 @@
#
# This Makefile is designed for use with main.mk in the root directory of
# this project. After including main.mk, the users makefile should contain:
#
# LSMDIR=$(TOP)/ext/lsm1/
# LSMOPTS=-fPIC
# include $(LSMDIR)/Makefile
#
# The most useful targets are [lsmtest] and [lsm.so].
#
LSMOBJ = \
lsm_ckpt.o \
lsm_file.o \
lsm_log.o \
lsm_main.o \
lsm_mem.o \
lsm_mutex.o \
lsm_shared.o \
lsm_sorted.o \
lsm_str.o \
lsm_tree.o \
lsm_unix.o \
lsm_win32.o \
lsm_varint.o \
lsm_vtab.o
LSMHDR = \
$(LSMDIR)/lsm.h \
$(LSMDIR)/lsmInt.h
LSMTESTSRC = $(LSMDIR)/lsm-test/lsmtest1.c $(LSMDIR)/lsm-test/lsmtest2.c \
$(LSMDIR)/lsm-test/lsmtest3.c $(LSMDIR)/lsm-test/lsmtest4.c \
$(LSMDIR)/lsm-test/lsmtest5.c $(LSMDIR)/lsm-test/lsmtest6.c \
$(LSMDIR)/lsm-test/lsmtest7.c $(LSMDIR)/lsm-test/lsmtest8.c \
$(LSMDIR)/lsm-test/lsmtest9.c \
$(LSMDIR)/lsm-test/lsmtest_datasource.c \
$(LSMDIR)/lsm-test/lsmtest_func.c $(LSMDIR)/lsm-test/lsmtest_io.c \
$(LSMDIR)/lsm-test/lsmtest_main.c $(LSMDIR)/lsm-test/lsmtest_mem.c \
$(LSMDIR)/lsm-test/lsmtest_tdb.c $(LSMDIR)/lsm-test/lsmtest_tdb3.c \
$(LSMDIR)/lsm-test/lsmtest_util.c $(LSMDIR)/lsm-test/lsmtest_win32.c
# all: lsm.so
LSMOPTS += -fPIC -DLSM_MUTEX_PTHREADS=1 -I$(LSMDIR) -DHAVE_ZLIB
lsm.so: $(LSMOBJ)
$(T.link) -shared -fPIC -o lsm.so $(LSMOBJ)
%.o: $(LSMDIR)/%.c $(LSMHDR) sqlite3.h
$(T.link) $(LSMOPTS) -c $<
lsmtest$(EXE): $(LSMOBJ) $(LSMTESTSRC) $(LSMTESTHDR) sqlite3.o
# $(T.link) -c $(TOP)/lsm-test/lsmtest_tdb2.cc
$(T.link) $(LSMOPTS) $(LSMTESTSRC) $(LSMOBJ) sqlite3.o -o lsmtest$(EXE) $(THREADLIB) -lz
-102
View File
@@ -1,102 +0,0 @@
#
# This Makefile is designed for use with Makefile.msc in the root directory
# of this project. The Makefile.msc should contain:
#
# LSMDIR=$(TOP)\ext\lsm1
# !INCLUDE $(LSMDIR)\Makefile.msc
#
# The most useful targets are [lsmtest.exe] and [lsm.dll].
#
LSMOBJ = \
lsm_ckpt.lo \
lsm_file.lo \
lsm_log.lo \
lsm_main.lo \
lsm_mem.lo \
lsm_mutex.lo \
lsm_shared.lo \
lsm_sorted.lo \
lsm_str.lo \
lsm_tree.lo \
lsm_unix.lo \
lsm_win32.lo \
lsm_varint.lo \
lsm_vtab.lo
LSMHDR = \
$(LSMDIR)\lsm.h \
$(LSMDIR)\lsmInt.h
LSMTESTSRC = $(LSMDIR)\lsm-test\lsmtest1.c $(LSMDIR)\lsm-test\lsmtest2.c \
$(LSMDIR)\lsm-test\lsmtest3.c $(LSMDIR)\lsm-test\lsmtest4.c \
$(LSMDIR)\lsm-test\lsmtest5.c $(LSMDIR)\lsm-test\lsmtest6.c \
$(LSMDIR)\lsm-test\lsmtest7.c $(LSMDIR)\lsm-test\lsmtest8.c \
$(LSMDIR)\lsm-test\lsmtest9.c \
$(LSMDIR)\lsm-test\lsmtest_datasource.c \
$(LSMDIR)\lsm-test\lsmtest_func.c $(LSMDIR)\lsm-test\lsmtest_io.c \
$(LSMDIR)\lsm-test\lsmtest_main.c $(LSMDIR)\lsm-test\lsmtest_mem.c \
$(LSMDIR)\lsm-test\lsmtest_tdb.c $(LSMDIR)\lsm-test\lsmtest_tdb3.c \
$(LSMDIR)\lsm-test\lsmtest_util.c $(LSMDIR)\lsm-test\lsmtest_win32.c
# all: lsm.dll lsmtest.exe
LSMOPTS = $(NO_WARN) -DLSM_MUTEX_WIN32=1 -I$(LSMDIR)
!IF $(DEBUG)>2
LSMOPTS = $(LSMOPTS) -DLSM_DEBUG=1
!ENDIF
!IF $(MEMDEBUG)!=0
LSMOPTS = $(LSMOPTS) -DLSM_DEBUG_MEM=1
!ENDIF
lsm_ckpt.lo: $(LSMDIR)\lsm_ckpt.c $(LSMHDR) $(SQLITE3H)
$(LTCOMPILE) $(LSMOPTS) -c $(LSMDIR)\lsm_ckpt.c
lsm_file.lo: $(LSMDIR)\lsm_file.c $(LSMHDR) $(SQLITE3H)
$(LTCOMPILE) $(LSMOPTS) -c $(LSMDIR)\lsm_file.c
lsm_log.lo: $(LSMDIR)\lsm_log.c $(LSMHDR) $(SQLITE3H)
$(LTCOMPILE) $(LSMOPTS) -c $(LSMDIR)\lsm_log.c
lsm_main.lo: $(LSMDIR)\lsm_main.c $(LSMHDR) $(SQLITE3H)
$(LTCOMPILE) $(LSMOPTS) -c $(LSMDIR)\lsm_main.c
lsm_mem.lo: $(LSMDIR)\lsm_mem.c $(LSMHDR) $(SQLITE3H)
$(LTCOMPILE) $(LSMOPTS) -c $(LSMDIR)\lsm_mem.c
lsm_mutex.lo: $(LSMDIR)\lsm_mutex.c $(LSMHDR) $(SQLITE3H)
$(LTCOMPILE) $(LSMOPTS) -c $(LSMDIR)\lsm_mutex.c
lsm_shared.lo: $(LSMDIR)\lsm_shared.c $(LSMHDR) $(SQLITE3H)
$(LTCOMPILE) $(LSMOPTS) -c $(LSMDIR)\lsm_shared.c
lsm_sorted.lo: $(LSMDIR)\lsm_sorted.c $(LSMHDR) $(SQLITE3H)
$(LTCOMPILE) $(LSMOPTS) -c $(LSMDIR)\lsm_sorted.c
lsm_str.lo: $(LSMDIR)\lsm_str.c $(LSMHDR) $(SQLITE3H)
$(LTCOMPILE) $(LSMOPTS) -c $(LSMDIR)\lsm_str.c
lsm_tree.lo: $(LSMDIR)\lsm_tree.c $(LSMHDR) $(SQLITE3H)
$(LTCOMPILE) $(LSMOPTS) -c $(LSMDIR)\lsm_tree.c
lsm_unix.lo: $(LSMDIR)\lsm_unix.c $(LSMHDR) $(SQLITE3H)
$(LTCOMPILE) $(LSMOPTS) -c $(LSMDIR)\lsm_unix.c
lsm_win32.lo: $(LSMDIR)\lsm_win32.c $(LSMHDR) $(SQLITE3H)
$(LTCOMPILE) $(LSMOPTS) -c $(LSMDIR)\lsm_win32.c
lsm_varint.lo: $(LSMDIR)\lsm_varint.c $(LSMHDR) $(SQLITE3H)
$(LTCOMPILE) $(LSMOPTS) -c $(LSMDIR)\lsm_varint.c
lsm_vtab.lo: $(LSMDIR)\lsm_vtab.c $(LSMHDR) $(SQLITE3H)
$(LTCOMPILE) $(LSMOPTS) -c $(LSMDIR)\lsm_vtab.c
lsm.dll: $(LSMOBJ)
$(LD) $(LDFLAGS) $(LTLINKOPTS) $(LTLIBPATHS) /DLL /OUT:$@ $(LSMOBJ)
copy /Y $@ $(LSMDIR)\$@
lsmtest.exe: $(LSMOBJ) $(LSMTESTSRC) $(LSMTESTHDR) $(LIBOBJ)
$(LTLINK) $(LSMOPTS) $(LSMTESTSRC) /link $(LSMOBJ) $(LIBOBJ)
copy /Y $@ $(LSMDIR)\$@
-40
View File
@@ -1,40 +0,0 @@
Organization of test case files:
lsmtest1.c: Data tests. Tests that perform many inserts and deletes on a
database file, then verify that the contents of the database can
be queried.
lsmtest2.c: Crash tests. Tests that attempt to verify that the database
recovers correctly following an application or system crash.
lsmtest3.c: Rollback tests. Tests that focus on the explicit rollback of
transactions and sub-transactions.
lsmtest4.c: Multi-client tests.
lsmtest5.c: Multi-client tests with a different thread for each client.
lsmtest6.c: OOM injection tests.
lsmtest7.c: API tests.
lsmtest8.c: Writer crash tests. Tests in this file attempt to verify that
the system recovers and other clients proceed unaffected if
a process fails in the middle of a write transaction.
The difference from lsmtest2.c is that this file tests
live-recovery (recovery from a failure that occurs while other
clients are still running) whereas lsmtest2.c tests recovery
from a system or power failure.
lsmtest9.c: More data tests. These focus on testing that calling
lsm_work(nMerge=1) to compact the database does not corrupt it.
In other words, that databases containing block-redirects
can be read and written.
-303
View File
@@ -1,303 +0,0 @@
#ifndef __WRAPPER_INT_H_
#define __WRAPPER_INT_H_
#include "lsmtest_tdb.h"
#include "sqlite3.h"
#include "lsm.h"
#include <assert.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#ifndef _WIN32
# include <unistd.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <ctype.h>
#include <stdlib.h>
#include <errno.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifdef _WIN32
# include "windows.h"
# define gettimeofday win32GetTimeOfDay
# define F_OK (0)
# define sleep(sec) Sleep(1000 * (sec))
# define usleep(usec) Sleep(((usec) + 999) / 1000)
# ifdef _MSC_VER
# include <io.h>
# define snprintf _snprintf
# define fsync(fd) FlushFileBuffers((HANDLE)_get_osfhandle((fd)))
# define fdatasync(fd) FlushFileBuffers((HANDLE)_get_osfhandle((fd)))
# define __va_copy(dst,src) ((dst) = (src))
# define ftruncate(fd,sz) ((_chsize_s((fd), (sz))==0) ? 0 : -1)
# else
# error Unsupported C compiler for Windows.
# endif
int win32GetTimeOfDay(struct timeval *, void *);
#endif
#ifndef _LSM_INT_H
typedef unsigned int u32;
typedef unsigned char u8;
typedef long long int i64;
typedef unsigned long long int u64;
#endif
#define ArraySize(x) ((int)(sizeof(x) / sizeof((x)[0])))
#define MIN(x,y) ((x)<(y) ? (x) : (y))
#define MAX(x,y) ((x)>(y) ? (x) : (y))
#define unused_parameter(x) (void)(x)
#define TESTDB_DEFAULT_PAGE_SIZE 4096
#define TESTDB_DEFAULT_CACHE_SIZE 2048
#ifndef _O_BINARY
# define _O_BINARY (0)
#endif
/*
** Ideally, these should be in wrapper.c. But they are here instead so that
** they can be used by the C++ database wrappers in wrapper2.cc.
*/
typedef struct DatabaseMethods DatabaseMethods;
struct TestDb {
DatabaseMethods const *pMethods; /* Database methods */
const char *zLibrary; /* Library name for tdb_open() */
};
struct DatabaseMethods {
int (*xClose)(TestDb *);
int (*xWrite)(TestDb *, void *, int , void *, int);
int (*xDelete)(TestDb *, void *, int);
int (*xDeleteRange)(TestDb *, void *, int, void *, int);
int (*xFetch)(TestDb *, void *, int, void **, int *);
int (*xScan)(TestDb *, void *, int, void *, int, void *, int,
void (*)(void *, void *, int , void *, int)
);
int (*xBegin)(TestDb *, int);
int (*xCommit)(TestDb *, int);
int (*xRollback)(TestDb *, int);
};
/*
** Functions in wrapper2.cc (a C++ source file). wrapper2.cc contains the
** wrapper for Kyoto Cabinet. Kyoto cabinet has a C API, but
** the primary interface is the C++ API.
*/
int test_kc_open(const char*, const char *zFilename, int bClear, TestDb **ppDb);
int test_kc_close(TestDb *);
int test_kc_write(TestDb *, void *, int , void *, int);
int test_kc_delete(TestDb *, void *, int);
int test_kc_delete_range(TestDb *, void *, int, void *, int);
int test_kc_fetch(TestDb *, void *, int, void **, int *);
int test_kc_scan(TestDb *, void *, int, void *, int, void *, int,
void (*)(void *, void *, int , void *, int)
);
int test_mdb_open(const char*, const char *zFile, int bClear, TestDb **ppDb);
int test_mdb_close(TestDb *);
int test_mdb_write(TestDb *, void *, int , void *, int);
int test_mdb_delete(TestDb *, void *, int);
int test_mdb_fetch(TestDb *, void *, int, void **, int *);
int test_mdb_scan(TestDb *, void *, int, void *, int, void *, int,
void (*)(void *, void *, int , void *, int)
);
/*
** Functions in wrapper3.c. This file contains the tdb wrapper for lsm.
** The wrapper for lsm is a bit more involved than the others, as it
** includes code for a couple of different lsm configurations, and for
** various types of fault injection and robustness testing.
*/
int test_lsm_open(const char*, const char *zFile, int bClear, TestDb **ppDb);
int test_lsm_lomem_open(const char*, const char*, int bClear, TestDb **ppDb);
int test_lsm_lomem2_open(const char*, const char*, int bClear, TestDb **ppDb);
int test_lsm_zip_open(const char*, const char*, int bClear, TestDb **ppDb);
int test_lsm_small_open(const char*, const char*, int bClear, TestDb **ppDb);
int test_lsm_mt2(const char*, const char *zFile, int bClear, TestDb **ppDb);
int test_lsm_mt3(const char*, const char *zFile, int bClear, TestDb **ppDb);
int tdb_lsm_configure(lsm_db *, const char *);
/* Functions in lsmtest_tdb4.c */
int test_bt_open(const char*, const char *zFile, int bClear, TestDb **ppDb);
int test_fbt_open(const char*, const char *zFile, int bClear, TestDb **ppDb);
int test_fbts_open(const char*, const char *zFile, int bClear, TestDb **ppDb);
/* Functions in testutil.c. */
int testPrngInit(void);
u32 testPrngValue(u32 iVal);
void testPrngArray(u32 iVal, u32 *aOut, int nOut);
void testPrngString(u32 iVal, char *aOut, int nOut);
void testErrorInit(int argc, char **);
void testPrintError(const char *zFormat, ...);
void testPrintUsage(const char *zArgs);
void testPrintFUsage(const char *zFormat, ...);
void testTimeInit(void);
int testTimeGet(void);
/* Functions in testmem.c. */
void testMallocInstall(lsm_env *pEnv);
void testMallocUninstall(lsm_env *pEnv);
void testMallocCheck(lsm_env *pEnv, int *, int *, FILE *);
void testMallocOom(lsm_env *pEnv, int, int, void(*)(void*), void *);
void testMallocOomEnable(lsm_env *pEnv, int);
/* lsmtest.c */
TestDb *testOpen(const char *zSystem, int, int *pRc);
void testReopen(TestDb **ppDb, int *pRc);
void testClose(TestDb **ppDb);
void testFetch(TestDb *, void *, int, void *, int, int *);
void testWrite(TestDb *, void *, int, void *, int, int *);
void testDelete(TestDb *, void *, int, int *);
void testDeleteRange(TestDb *, void *, int, void *, int, int *);
void testWriteStr(TestDb *, const char *, const char *zVal, int *pRc);
void testFetchStr(TestDb *, const char *, const char *, int *pRc);
void testBegin(TestDb *pDb, int iTrans, int *pRc);
void testCommit(TestDb *pDb, int iTrans, int *pRc);
void test_failed(void);
char *testMallocPrintf(const char *zFormat, ...);
char *testMallocVPrintf(const char *zFormat, va_list ap);
int testGlobMatch(const char *zPattern, const char *zStr);
void testScanCompare(TestDb *, TestDb *, int, void *, int, void *, int, int *);
void testFetchCompare(TestDb *, TestDb *, void *, int, int *);
void *testMalloc(int);
void *testMallocCopy(void *pCopy, int nByte);
void *testRealloc(void *, int);
void testFree(void *);
/* lsmtest_bt.c */
int do_bt(int nArg, char **azArg);
/* testio.c */
int testVfsConfigureDb(TestDb *pDb);
/* testfunc.c */
int do_show(int nArg, char **azArg);
int do_work(int nArg, char **azArg);
/* testio.c */
int do_io(int nArg, char **azArg);
/* lsmtest2.c */
void do_crash_test(const char *zPattern, int *pRc);
int do_rollback_test(int nArg, char **azArg);
/* test3.c */
void test_rollback(const char *zSystem, const char *zPattern, int *pRc);
/* test4.c */
void test_mc(const char *zSystem, const char *zPattern, int *pRc);
/* test5.c */
void test_mt(const char *zSystem, const char *zPattern, int *pRc);
/* lsmtest6.c */
void test_oom(const char *zPattern, int *pRc);
void testDeleteLsmdb(const char *zFile);
void testSaveDb(const char *zFile, const char *zAuxExt);
void testRestoreDb(const char *zFile, const char *zAuxExt);
void testCopyLsmdb(const char *zFrom, const char *zTo);
/* lsmtest7.c */
void test_api(const char *zPattern, int *pRc);
/* lsmtest8.c */
void do_writer_crash_test(const char *zPattern, int *pRc);
/*************************************************************************
** Interface to functionality in test_datasource.c.
*/
typedef struct Datasource Datasource;
typedef struct DatasourceDefn DatasourceDefn;
struct DatasourceDefn {
int eType; /* A TEST_DATASOURCE_* value */
int nMinKey; /* Minimum key size */
int nMaxKey; /* Maximum key size */
int nMinVal; /* Minimum value size */
int nMaxVal; /* Maximum value size */
};
#define TEST_DATASOURCE_RANDOM 1
#define TEST_DATASOURCE_SEQUENCE 2
char *testDatasourceName(const DatasourceDefn *);
Datasource *testDatasourceNew(const DatasourceDefn *);
void testDatasourceFree(Datasource *);
void testDatasourceEntry(Datasource *, int, void **, int *, void **, int *);
/* End of test_datasource.c interface.
*************************************************************************/
void testDatasourceFetch(
TestDb *pDb, /* Database handle */
Datasource *pData,
int iKey,
int *pRc /* IN/OUT: Error code */
);
void testWriteDatasource(TestDb *, Datasource *, int, int *);
void testWriteDatasourceRange(TestDb *, Datasource *, int, int, int *);
void testDeleteDatasource(TestDb *, Datasource *, int, int *);
void testDeleteDatasourceRange(TestDb *, Datasource *, int, int, int *);
/* test1.c */
void test_data_1(const char *, const char *, int *pRc);
void test_data_2(const char *, const char *, int *pRc);
void test_data_3(const char *, const char *, int *pRc);
void testDbContents(TestDb *, Datasource *, int, int, int, int, int, int *);
void testCaseProgress(int, int, int, int *);
int testCaseNDot(void);
void testCompareDb(Datasource *, int, int, TestDb *, TestDb *, int *);
int testControlDb(TestDb **ppDb);
typedef struct CksumDb CksumDb;
CksumDb *testCksumArrayNew(Datasource *, int, int, int);
char *testCksumArrayGet(CksumDb *, int);
void testCksumArrayFree(CksumDb *);
void testCaseStart(int *pRc, char *zFmt, ...);
void testCaseFinish(int rc);
void testCaseSkip(void);
int testCaseBegin(int *, const char *, const char *, ...);
#define TEST_CKSUM_BYTES 29
int testCksumDatabase(TestDb *pDb, char *zOut);
int testCountDatabase(TestDb *pDb);
void testCompareInt(int, int, int *);
void testCompareStr(const char *z1, const char *z2, int *pRc);
/* lsmtest9.c */
void test_data_4(const char *, const char *, int *pRc);
/*
** Similar to the Tcl_GetIndexFromObjStruct() Tcl library function.
*/
#define testArgSelect(w,x,y,z) testArgSelectX(w,x,sizeof(w[0]),y,z)
int testArgSelectX(void *, const char *, int, const char *, int *);
#ifdef __cplusplus
} /* End of the 'extern "C"' block */
#endif
#endif
-656
View File
@@ -1,656 +0,0 @@
#include "lsmtest.h"
#define DATA_SEQUENTIAL TEST_DATASOURCE_SEQUENCE
#define DATA_RANDOM TEST_DATASOURCE_RANDOM
typedef struct Datatest1 Datatest1;
typedef struct Datatest2 Datatest2;
/*
** An instance of the following structure contains parameters used to
** customize the test function in this file. Test procedure:
**
** 1. Create a data-source based on the "datasource definition" vars.
**
** 2. Insert nRow key value pairs into the database.
**
** 3. Delete all keys from the database. Deletes are done in the same
** order as the inserts.
**
** During steps 2 and 3 above, after each Datatest1.nVerify inserts or
** deletes, the following:
**
** a. Run Datasource.nTest key lookups and check the results are as expected.
**
** b. If Datasource.bTestScan is true, run a handful (8) of range
** queries (scanning forwards and backwards). Check that the results
** are as expected.
**
** c. Close and reopen the database. Then run (a) and (b) again.
*/
struct Datatest1 {
/* Datasource definition */
DatasourceDefn defn;
/* Test procedure parameters */
int nRow; /* Number of rows to insert then delete */
int nVerify; /* How often to verify the db contents */
int nTest; /* Number of keys to test (0==all) */
int bTestScan; /* True to do scan tests */
};
/*
** An instance of the following data structure is used to describe the
** second type of test case in this file. The chief difference between
** these tests and those described by Datatest1 is that these tests also
** experiment with range-delete operations. Tests proceed as follows:
**
** 1. Open the datasource described by Datatest2.defn.
**
** 2. Open a connection on an empty database.
**
** 3. Do this Datatest2.nIter times:
**
** a) Insert Datatest2.nWrite key-value pairs from the datasource.
**
** b) Select two pseudo-random keys and use them as the start
** and end points of a range-delete operation.
**
** c) Verify that the contents of the database are as expected (see
** below for details).
**
** d) Close and then reopen the database handle.
**
** e) Verify that the contents of the database are still as expected.
**
** The inserts and range deletes are run twice - once on the database being
** tested and once using a control system (sqlite3, kc etc. - something that
** works). In order to verify that the contents of the db being tested are
** correct, the test runs a bunch of scans and lookups on both the test and
** control databases. If the results are the same, the test passes.
*/
struct Datatest2 {
DatasourceDefn defn;
int nRange;
int nWrite; /* Number of writes per iteration */
int nIter; /* Total number of iterations to run */
};
/*
** Generate a unique name for the test case pTest with database system
** zSystem.
*/
static char *getName(const char *zSystem, int bRecover, Datatest1 *pTest){
char *zRet;
char *zData;
zData = testDatasourceName(&pTest->defn);
zRet = testMallocPrintf("data.%s.%s.rec=%d.%d.%d",
zSystem, zData, bRecover, pTest->nRow, pTest->nVerify
);
testFree(zData);
return zRet;
}
int testControlDb(TestDb **ppDb){
#ifdef HAVE_KYOTOCABINET
return tdb_open("kyotocabinet", "tmp.db", 1, ppDb);
#else
return tdb_open("sqlite3", "", 1, ppDb);
#endif
}
void testDatasourceFetch(
TestDb *pDb, /* Database handle */
Datasource *pData,
int iKey,
int *pRc /* IN/OUT: Error code */
){
void *pKey; int nKey; /* Database key to query for */
void *pVal; int nVal; /* Expected result of query */
testDatasourceEntry(pData, iKey, &pKey, &nKey, &pVal, &nVal);
testFetch(pDb, pKey, nKey, pVal, nVal, pRc);
}
/*
** This function is called to test that the contents of database pDb
** are as expected. In this case, expected is defined as containing
** key-value pairs iFirst through iLast, inclusive, from data source
** pData. In other words, a loop like the following could be used to
** construct a database with identical contents from scratch.
**
** for(i=iFirst; i<=iLast; i++){
** testDatasourceEntry(pData, i, &pKey, &nKey, &pVal, &nVal);
** // insert (pKey, nKey) -> (pVal, nVal) into database
** }
**
** The key domain consists of keys 0 to (nRow-1), inclusive, from
** data source pData. For both scan and lookup tests, keys are selected
** pseudo-randomly from within this set.
**
** This function runs nLookupTest lookup tests and nScanTest scan tests.
**
** A lookup test consists of selecting a key from the domain and querying
** pDb for it. The test fails if the presence of the key and, if present,
** the associated value do not match the expectations defined above.
**
** A scan test involves selecting a key from the domain and running
** the following queries:
**
** 1. Scan all keys equal to or greater than the key, in ascending order.
** 2. Scan all keys equal to or smaller than the key, in descending order.
**
** Additionally, if nLookupTest is greater than zero, the following are
** run once:
**
** 1. Scan all keys in the db, in ascending order.
** 2. Scan all keys in the db, in descending order.
**
** As you would assume, the test fails if the returned values do not match
** expectations.
*/
void testDbContents(
TestDb *pDb, /* Database handle being tested */
Datasource *pData, /* pDb contains data from here */
int nRow, /* Size of key domain */
int iFirst, /* Index of first key from pData in pDb */
int iLast, /* Index of last key from pData in pDb */
int nLookupTest, /* Number of lookup tests to run */
int nScanTest, /* Number of scan tests to run */
int *pRc /* IN/OUT: Error code */
){
int j;
int rc = *pRc;
if( rc==0 && nScanTest ){
TestDb *pDb2 = 0;
/* Open a control db (i.e. one that we assume works) */
rc = testControlDb(&pDb2);
for(j=iFirst; rc==0 && j<=iLast; j++){
void *pKey; int nKey; /* Database key to insert */
void *pVal; int nVal; /* Database value to insert */
testDatasourceEntry(pData, j, &pKey, &nKey, &pVal, &nVal);
rc = tdb_write(pDb2, pKey, nKey, pVal, nVal);
}
if( rc==0 ){
int iKey1;
int iKey2;
void *pKey1; int nKey1; /* Start key */
void *pKey2; int nKey2; /* Final key */
iKey1 = testPrngValue((iFirst<<8) + (iLast<<16)) % nRow;
iKey2 = testPrngValue((iLast<<8) + (iFirst<<16)) % nRow;
testDatasourceEntry(pData, iKey1, &pKey2, &nKey1, 0, 0);
pKey1 = testMalloc(nKey1+1);
memcpy(pKey1, pKey2, nKey1+1);
testDatasourceEntry(pData, iKey2, &pKey2, &nKey2, 0, 0);
testScanCompare(pDb2, pDb, 0, 0, 0, 0, 0, &rc);
testScanCompare(pDb2, pDb, 0, 0, 0, pKey2, nKey2, &rc);
testScanCompare(pDb2, pDb, 0, pKey1, nKey1, 0, 0, &rc);
testScanCompare(pDb2, pDb, 0, pKey1, nKey1, pKey2, nKey2, &rc);
testScanCompare(pDb2, pDb, 1, 0, 0, 0, 0, &rc);
testScanCompare(pDb2, pDb, 1, 0, 0, pKey2, nKey2, &rc);
testScanCompare(pDb2, pDb, 1, pKey1, nKey1, 0, 0, &rc);
testScanCompare(pDb2, pDb, 1, pKey1, nKey1, pKey2, nKey2, &rc);
testFree(pKey1);
}
tdb_close(pDb2);
}
/* Test some lookups. */
for(j=0; rc==0 && j<nLookupTest; j++){
int iKey; /* Datasource key to test */
void *pKey; int nKey; /* Database key to query for */
void *pVal; int nVal; /* Expected result of query */
if( nLookupTest>=nRow ){
iKey = j;
}else{
iKey = testPrngValue(j + (iFirst<<8) + (iLast<<16)) % nRow;
}
testDatasourceEntry(pData, iKey, &pKey, &nKey, &pVal, &nVal);
if( iFirst>iKey || iKey>iLast ){
pVal = 0;
nVal = -1;
}
testFetch(pDb, pKey, nKey, pVal, nVal, &rc);
}
*pRc = rc;
}
/*
** This function should be called during long running test cases to output
** the progress dots (...) to stdout.
*/
void testCaseProgress(int i, int n, int nDot, int *piDot){
int iDot = *piDot;
while( iDot < ( ((nDot*2+1) * i) / (n*2) ) ){
printf(".");
fflush(stdout);
iDot++;
}
*piDot = iDot;
}
int testCaseNDot(void){ return 20; }
#if 0
static void printScanCb(
void *pCtx, void *pKey, int nKey, void *pVal, int nVal
){
printf("%s\n", (char *)pKey);
fflush(stdout);
}
#endif
void testReopenRecover(TestDb **ppDb, int *pRc){
if( *pRc==0 ){
const char *zLib = tdb_library_name(*ppDb);
const char *zDflt = tdb_default_db(zLib);
testCopyLsmdb(zDflt, "bak.db");
testClose(ppDb);
testCopyLsmdb("bak.db", zDflt);
*pRc = tdb_open(zLib, 0, 0, ppDb);
}
}
static void doDataTest1(
const char *zSystem, /* Database system to test */
int bRecover,
Datatest1 *p, /* Structure containing test parameters */
int *pRc /* OUT: Error code */
){
int i;
int iDot;
int rc = LSM_OK;
Datasource *pData;
TestDb *pDb;
int iToggle = 0;
/* Start the test case, open a database and allocate the datasource. */
pDb = testOpen(zSystem, 1, &rc);
pData = testDatasourceNew(&p->defn);
i = 0;
iDot = 0;
while( rc==LSM_OK && i<p->nRow ){
/* Insert some data */
testWriteDatasourceRange(pDb, pData, i, p->nVerify, &rc);
i += p->nVerify;
if( iToggle ) testBegin(pDb, 1, &rc);
/* Check that the db content is correct. */
testDbContents(pDb, pData, p->nRow, 0, i-1, p->nTest, p->bTestScan, &rc);
if( iToggle ) testCommit(pDb, 0, &rc);
iToggle = (iToggle+1)%2;
if( bRecover ){
testReopenRecover(&pDb, &rc);
}else{
testReopen(&pDb, &rc);
}
/* Check that the db content is still correct. */
testDbContents(pDb, pData, p->nRow, 0, i-1, p->nTest, p->bTestScan, &rc);
/* Update the progress dots... */
testCaseProgress(i, p->nRow, testCaseNDot()/2, &iDot);
}
i = 0;
iDot = 0;
while( rc==LSM_OK && i<p->nRow ){
/* Delete some entries */
testDeleteDatasourceRange(pDb, pData, i, p->nVerify, &rc);
i += p->nVerify;
/* Check that the db content is correct. */
testDbContents(pDb, pData, p->nRow, i, p->nRow-1,p->nTest,p->bTestScan,&rc);
/* Close and reopen the database. */
if( bRecover ){
testReopenRecover(&pDb, &rc);
}else{
testReopen(&pDb, &rc);
}
/* Check that the db content is still correct. */
testDbContents(pDb, pData, p->nRow, i, p->nRow-1,p->nTest,p->bTestScan,&rc);
/* Update the progress dots... */
testCaseProgress(i, p->nRow, testCaseNDot()/2, &iDot);
}
/* Free the datasource, close the database and finish the test case. */
testDatasourceFree(pData);
tdb_close(pDb);
testCaseFinish(rc);
*pRc = rc;
}
void test_data_1(
const char *zSystem, /* Database system name */
const char *zPattern, /* Run test cases that match this pattern */
int *pRc /* IN/OUT: Error code */
){
Datatest1 aTest[] = {
{ {DATA_RANDOM, 500,600, 1000,2000}, 1000, 100, 10, 0},
{ {DATA_RANDOM, 20,25, 100,200}, 1000, 250, 1000, 1},
{ {DATA_RANDOM, 8,10, 100,200}, 1000, 250, 1000, 1},
{ {DATA_RANDOM, 8,10, 10,20}, 1000, 250, 1000, 1},
{ {DATA_RANDOM, 8,10, 1000,2000}, 1000, 250, 1000, 1},
{ {DATA_RANDOM, 8,100, 10000,20000}, 100, 25, 100, 1},
{ {DATA_RANDOM, 80,100, 10,20}, 1000, 250, 1000, 1},
{ {DATA_RANDOM, 5000,6000, 10,20}, 100, 25, 100, 1},
{ {DATA_SEQUENTIAL, 5,10, 10,20}, 1000, 250, 1000, 1},
{ {DATA_SEQUENTIAL, 5,10, 100,200}, 1000, 250, 1000, 1},
{ {DATA_SEQUENTIAL, 5,10, 1000,2000}, 1000, 250, 1000, 1},
{ {DATA_SEQUENTIAL, 5,100, 10000,20000}, 100, 25, 100, 1},
{ {DATA_RANDOM, 10,10, 100,100}, 100000, 1000, 100, 0},
{ {DATA_SEQUENTIAL, 10,10, 100,100}, 100000, 1000, 100, 0},
};
int i;
int bRecover;
for(bRecover=0; bRecover<2; bRecover++){
if( bRecover==1 && memcmp(zSystem, "lsm", 3) ) break;
for(i=0; *pRc==LSM_OK && i<ArraySize(aTest); i++){
char *zName = getName(zSystem, bRecover, &aTest[i]);
if( testCaseBegin(pRc, zPattern, "%s", zName) ){
doDataTest1(zSystem, bRecover, &aTest[i], pRc);
}
testFree(zName);
}
}
}
void testCompareDb(
Datasource *pData,
int nData,
int iSeed,
TestDb *pControl,
TestDb *pDb,
int *pRc
){
int i;
static int nCall = 0;
nCall++;
testScanCompare(pControl, pDb, 0, 0, 0, 0, 0, pRc);
testScanCompare(pControl, pDb, 1, 0, 0, 0, 0, pRc);
if( *pRc==0 ){
int iKey1;
int iKey2;
void *pKey1; int nKey1; /* Start key */
void *pKey2; int nKey2; /* Final key */
iKey1 = testPrngValue(iSeed) % nData;
iKey2 = testPrngValue(iSeed+1) % nData;
testDatasourceEntry(pData, iKey1, &pKey2, &nKey1, 0, 0);
pKey1 = testMalloc(nKey1+1);
memcpy(pKey1, pKey2, nKey1+1);
testDatasourceEntry(pData, iKey2, &pKey2, &nKey2, 0, 0);
testScanCompare(pControl, pDb, 0, 0, 0, pKey2, nKey2, pRc);
testScanCompare(pControl, pDb, 0, pKey1, nKey1, 0, 0, pRc);
testScanCompare(pControl, pDb, 0, pKey1, nKey1, pKey2, nKey2, pRc);
testScanCompare(pControl, pDb, 1, 0, 0, pKey2, nKey2, pRc);
testScanCompare(pControl, pDb, 1, pKey1, nKey1, 0, 0, pRc);
testScanCompare(pControl, pDb, 1, pKey1, nKey1, pKey2, nKey2, pRc);
testFree(pKey1);
}
for(i=0; i<nData && *pRc==0; i++){
void *pKey; int nKey;
testDatasourceEntry(pData, i, &pKey, &nKey, 0, 0);
testFetchCompare(pControl, pDb, pKey, nKey, pRc);
}
}
static void doDataTest2(
const char *zSystem, /* Database system to test */
int bRecover,
Datatest2 *p, /* Structure containing test parameters */
int *pRc /* OUT: Error code */
){
TestDb *pDb;
TestDb *pControl;
Datasource *pData;
int i;
int rc = LSM_OK;
int iDot = 0;
/* Start the test case, open a database and allocate the datasource. */
pDb = testOpen(zSystem, 1, &rc);
pData = testDatasourceNew(&p->defn);
rc = testControlDb(&pControl);
if( tdb_lsm(pDb) ){
int nBuf = 32 * 1024 * 1024;
lsm_config(tdb_lsm(pDb), LSM_CONFIG_AUTOFLUSH, &nBuf);
}
for(i=0; rc==0 && i<p->nIter; i++){
void *pKey1; int nKey1;
void *pKey2; int nKey2;
int ii;
int nRange = MIN(p->nIter*p->nWrite, p->nRange);
for(ii=0; rc==0 && ii<p->nWrite; ii++){
int iKey = (i*p->nWrite + ii) % p->nRange;
testWriteDatasource(pControl, pData, iKey, &rc);
testWriteDatasource(pDb, pData, iKey, &rc);
}
testDatasourceEntry(pData, i+1000000, &pKey1, &nKey1, 0, 0);
pKey1 = testMallocCopy(pKey1, nKey1);
testDatasourceEntry(pData, i+2000000, &pKey2, &nKey2, 0, 0);
testDeleteRange(pDb, pKey1, nKey1, pKey2, nKey2, &rc);
testDeleteRange(pControl, pKey1, nKey1, pKey2, nKey2, &rc);
testFree(pKey1);
testCompareDb(pData, nRange, i, pControl, pDb, &rc);
if( bRecover ){
testReopenRecover(&pDb, &rc);
}else{
testReopen(&pDb, &rc);
}
testCompareDb(pData, nRange, i, pControl, pDb, &rc);
/* Update the progress dots... */
testCaseProgress(i, p->nIter, testCaseNDot(), &iDot);
}
testClose(&pDb);
testClose(&pControl);
testDatasourceFree(pData);
testCaseFinish(rc);
*pRc = rc;
}
static char *getName2(const char *zSystem, int bRecover, Datatest2 *pTest){
char *zRet;
char *zData;
zData = testDatasourceName(&pTest->defn);
zRet = testMallocPrintf("data2.%s.%s.rec=%d.%d.%d.%d",
zSystem, zData, bRecover, pTest->nRange, pTest->nWrite, pTest->nIter
);
testFree(zData);
return zRet;
}
void test_data_2(
const char *zSystem, /* Database system name */
const char *zPattern, /* Run test cases that match this pattern */
int *pRc /* IN/OUT: Error code */
){
Datatest2 aTest[] = {
/* defn, nRange, nWrite, nIter */
{ {DATA_RANDOM, 20,25, 100,200}, 10000, 10, 50 },
{ {DATA_RANDOM, 20,25, 100,200}, 10000, 200, 50 },
{ {DATA_RANDOM, 20,25, 100,200}, 100, 10, 1000 },
{ {DATA_RANDOM, 20,25, 100,200}, 100, 200, 50 },
};
int i;
int bRecover;
for(bRecover=0; bRecover<2; bRecover++){
if( bRecover==1 && memcmp(zSystem, "lsm", 3) ) break;
for(i=0; *pRc==LSM_OK && i<ArraySize(aTest); i++){
char *zName = getName2(zSystem, bRecover, &aTest[i]);
if( testCaseBegin(pRc, zPattern, "%s", zName) ){
doDataTest2(zSystem, bRecover, &aTest[i], pRc);
}
testFree(zName);
}
}
}
/*************************************************************************
** Test case data3.*
*/
typedef struct Datatest3 Datatest3;
struct Datatest3 {
int nRange; /* Keys are between 1 and this value, incl. */
int nIter; /* Number of iterations */
int nWrite; /* Number of writes per iteration */
int nDelete; /* Number of deletes per iteration */
int nValMin; /* Minimum value size for writes */
int nValMax; /* Maximum value size for writes */
};
void testPutU32(u8 *aBuf, u32 iVal){
aBuf[0] = (iVal >> 24) & 0xFF;
aBuf[1] = (iVal >> 16) & 0xFF;
aBuf[2] = (iVal >> 8) & 0xFF;
aBuf[3] = (iVal >> 0) & 0xFF;
}
void dt3PutKey(u8 *aBuf, int iKey){
assert( iKey<100000 && iKey>=0 );
sprintf((char *)aBuf, "%.5d", iKey);
}
static void doDataTest3(
const char *zSystem, /* Database system to test */
Datatest3 *p, /* Structure containing test parameters */
int *pRc /* OUT: Error code */
){
int iDot = 0;
int rc = *pRc;
TestDb *pDb;
u8 *abPresent; /* Array of boolean */
char *aVal; /* Buffer to hold values */
int i;
u32 iSeq = 10; /* prng counter */
abPresent = (u8 *)testMalloc(p->nRange+1);
aVal = (char *)testMalloc(p->nValMax+1);
pDb = testOpen(zSystem, 1, &rc);
for(i=0; i<p->nIter && rc==0; i++){
int ii;
testCaseProgress(i, p->nIter, testCaseNDot(), &iDot);
/* Perform nWrite inserts */
for(ii=0; ii<p->nWrite; ii++){
u8 aKey[6];
u32 iKey;
int nVal;
iKey = (testPrngValue(iSeq++) % p->nRange) + 1;
nVal = (testPrngValue(iSeq++) % (p->nValMax - p->nValMin)) + p->nValMin;
testPrngString(testPrngValue(iSeq++), aVal, nVal);
dt3PutKey(aKey, iKey);
testWrite(pDb, aKey, sizeof(aKey)-1, aVal, nVal, &rc);
abPresent[iKey] = 1;
}
/* Perform nDelete deletes */
for(ii=0; ii<p->nDelete; ii++){
u8 aKey1[6];
u8 aKey2[6];
u32 iKey;
iKey = (testPrngValue(iSeq++) % p->nRange) + 1;
dt3PutKey(aKey1, iKey-1);
dt3PutKey(aKey2, iKey+1);
testDeleteRange(pDb, aKey1, sizeof(aKey1)-1, aKey2, sizeof(aKey2)-1, &rc);
abPresent[iKey] = 0;
}
testReopen(&pDb, &rc);
for(ii=1; rc==0 && ii<=p->nRange; ii++){
int nDbVal;
void *pDbVal;
u8 aKey[6];
int dbrc;
dt3PutKey(aKey, ii);
dbrc = tdb_fetch(pDb, aKey, sizeof(aKey)-1, &pDbVal, &nDbVal);
testCompareInt(0, dbrc, &rc);
if( abPresent[ii] ){
testCompareInt(1, (nDbVal>0), &rc);
}else{
testCompareInt(1, (nDbVal<0), &rc);
}
}
}
testClose(&pDb);
testCaseFinish(rc);
*pRc = rc;
}
static char *getName3(const char *zSystem, Datatest3 *p){
return testMallocPrintf("data3.%s.%d.%d.%d.%d.(%d..%d)",
zSystem, p->nRange, p->nIter, p->nWrite, p->nDelete,
p->nValMin, p->nValMax
);
}
void test_data_3(
const char *zSystem, /* Database system name */
const char *zPattern, /* Run test cases that match this pattern */
int *pRc /* IN/OUT: Error code */
){
Datatest3 aTest[] = {
/* nRange, nIter, nWrite, nDelete, nValMin, nValMax */
{ 100, 1000, 5, 5, 50, 100 },
{ 100, 1000, 2, 2, 5, 10 },
};
int i;
for(i=0; *pRc==LSM_OK && i<ArraySize(aTest); i++){
char *zName = getName3(zSystem, &aTest[i]);
if( testCaseBegin(pRc, zPattern, "%s", zName) ){
doDataTest3(zSystem, &aTest[i], pRc);
}
testFree(zName);
}
}
-488
View File
@@ -1,488 +0,0 @@
/*
** This file contains tests related to recovery following application
** and system crashes (power failures) while writing to the database.
*/
#include "lsmtest.h"
/*
** Structure used by testCksumDatabase() to accumulate checksum values in.
*/
typedef struct Cksum Cksum;
struct Cksum {
int nRow;
int cksum1;
int cksum2;
};
/*
** tdb_scan() callback used by testCksumDatabase()
*/
static void scanCksumDb(
void *pCtx,
void *pKey, int nKey,
void *pVal, int nVal
){
Cksum *p = (Cksum *)pCtx;
int i;
p->nRow++;
for(i=0; i<nKey; i++){
p->cksum1 += ((u8 *)pKey)[i];
p->cksum2 += p->cksum1;
}
for(i=0; i<nVal; i++){
p->cksum1 += ((u8 *)pVal)[i];
p->cksum2 += p->cksum1;
}
}
/*
** tdb_scan() callback used by testCountDatabase()
*/
static void scanCountDb(
void *pCtx,
void *pKey, int nKey,
void *pVal, int nVal
){
Cksum *p = (Cksum *)pCtx;
p->nRow++;
unused_parameter(pKey);
unused_parameter(nKey);
unused_parameter(pVal);
unused_parameter(nVal);
}
/*
** Iterate through the entire contents of database pDb. Write a checksum
** string based on the db contents into buffer zOut before returning. A
** checksum string is at most 29 (TEST_CKSUM_BYTES) bytes in size:
**
** * 32-bit integer (10 bytes)
** * 1 space (1 byte)
** * 32-bit hex (8 bytes)
** * 1 space (1 byte)
** * 32-bit hex (8 bytes)
** * nul-terminator (1 byte)
**
** The number of entries in the database is returned.
*/
int testCksumDatabase(
TestDb *pDb, /* Database handle */
char *zOut /* Buffer to write checksum to */
){
Cksum cksum;
memset(&cksum, 0, sizeof(Cksum));
tdb_scan(pDb, (void *)&cksum, 0, 0, 0, 0, 0, scanCksumDb);
sprintf(zOut, "%d %x %x",
cksum.nRow, (u32)cksum.cksum1, (u32)cksum.cksum2
);
assert( strlen(zOut)<TEST_CKSUM_BYTES );
return cksum.nRow;
}
int testCountDatabase(TestDb *pDb){
Cksum cksum;
memset(&cksum, 0, sizeof(Cksum));
tdb_scan(pDb, (void *)&cksum, 0, 0, 0, 0, 0, scanCountDb);
return cksum.nRow;
}
/*
** This function is a no-op if *pRc is not 0 when it is called.
**
** Otherwise, the two nul-terminated strings z1 and z1 are compared. If
** they are the same, the function returns without doing anything. Otherwise,
** an error message is printed, *pRc is set to 1 and the test_failed()
** function called.
*/
void testCompareStr(const char *z1, const char *z2, int *pRc){
if( *pRc==0 ){
if( strcmp(z1, z2) ){
testPrintError("testCompareStr: \"%s\" != \"%s\"\n", z1, z2);
*pRc = 1;
test_failed();
}
}
}
/*
** This function is a no-op if *pRc is not 0 when it is called.
**
** Otherwise, the two integers i1 and i2 are compared. If they are equal,
** the function returns without doing anything. Otherwise, an error message
** is printed, *pRc is set to 1 and the test_failed() function called.
*/
void testCompareInt(int i1, int i2, int *pRc){
if( *pRc==0 && i1!=i2 ){
testPrintError("testCompareInt: %d != %d\n", i1, i2);
*pRc = 1;
test_failed();
}
}
void testCaseStart(int *pRc, char *zFmt, ...){
va_list ap;
va_start(ap, zFmt);
vprintf(zFmt, ap);
printf(" ...");
va_end(ap);
*pRc = 0;
fflush(stdout);
}
/*
** This function is a no-op if *pRc is non-zero when it is called. Zero
** is returned in this case.
**
** Otherwise, the zFmt (a printf style format string) and following arguments
** are used to create a test case name. If zPattern is NULL or a glob pattern
** that matches the test case name, 1 is returned and the test case started.
** Otherwise, zero is returned and the test case does not start.
*/
int testCaseBegin(int *pRc, const char *zPattern, const char *zFmt, ...){
int res = 0;
if( *pRc==0 ){
char *zTest;
va_list ap;
va_start(ap, zFmt);
zTest = testMallocVPrintf(zFmt, ap);
va_end(ap);
if( zPattern==0 || testGlobMatch(zPattern, zTest) ){
printf("%-50s ...", zTest);
res = 1;
}
testFree(zTest);
fflush(stdout);
}
return res;
}
void testCaseFinish(int rc){
if( rc==0 ){
printf("Ok\n");
}else{
printf("FAILED\n");
}
fflush(stdout);
}
void testCaseSkip(){
printf("Skipped\n");
}
void testSetupSavedLsmdb(
const char *zCfg,
const char *zFile,
Datasource *pData,
int nRow,
int *pRc
){
if( *pRc==0 ){
int rc;
TestDb *pDb;
rc = tdb_lsm_open(zCfg, zFile, 1, &pDb);
if( rc==0 ){
testWriteDatasourceRange(pDb, pData, 0, nRow, &rc);
testClose(&pDb);
if( rc==0 ) testSaveDb(zFile, "log");
}
*pRc = rc;
}
}
/*
** This function is a no-op if *pRc is non-zero when it is called.
**
** Open the LSM database identified by zFile and compute its checksum
** (a string, as returned by testCksumDatabase()). If the checksum is
** identical to zExpect1 or, if it is not NULL, zExpect2, the test passes.
** Otherwise, print an error message and set *pRc to 1.
*/
static void testCompareCksumLsmdb(
const char *zFile, /* Path to LSM database */
int bCompress, /* True if db is compressed */
const char *zExpect1, /* Expected checksum 1 */
const char *zExpect2, /* Expected checksum 2 (or NULL) */
int *pRc /* IN/OUT: Test case error code */
){
if( *pRc==0 ){
char zCksum[TEST_CKSUM_BYTES];
TestDb *pDb;
*pRc = tdb_lsm_open((bCompress?"compression=1 mmap=0":""), zFile, 0, &pDb);
testCksumDatabase(pDb, zCksum);
testClose(&pDb);
if( *pRc==0 ){
int r1 = 0;
int r2 = -1;
r1 = strcmp(zCksum, zExpect1);
if( zExpect2 ) r2 = strcmp(zCksum, zExpect2);
if( r1 && r2 ){
if( zExpect2 ){
testPrintError("testCompareCksumLsmdb: \"%s\" != (\"%s\" OR \"%s\")",
zCksum, zExpect1, zExpect2
);
}else{
testPrintError("testCompareCksumLsmdb: \"%s\" != \"%s\"",
zCksum, zExpect1
);
}
*pRc = 1;
test_failed();
}
}
}
}
#if 0 /* not used */
static void testCompareCksumBtdb(
const char *zFile, /* Path to LSM database */
const char *zExpect1, /* Expected checksum 1 */
const char *zExpect2, /* Expected checksum 2 (or NULL) */
int *pRc /* IN/OUT: Test case error code */
){
if( *pRc==0 ){
char zCksum[TEST_CKSUM_BYTES];
TestDb *pDb;
*pRc = tdb_open("bt", zFile, 0, &pDb);
testCksumDatabase(pDb, zCksum);
testClose(&pDb);
if( *pRc==0 ){
int r1 = 0;
int r2 = -1;
r1 = strcmp(zCksum, zExpect1);
if( zExpect2 ) r2 = strcmp(zCksum, zExpect2);
if( r1 && r2 ){
if( zExpect2 ){
testPrintError("testCompareCksumLsmdb: \"%s\" != (\"%s\" OR \"%s\")",
zCksum, zExpect1, zExpect2
);
}else{
testPrintError("testCompareCksumLsmdb: \"%s\" != \"%s\"",
zCksum, zExpect1
);
}
*pRc = 1;
test_failed();
}
}
}
}
#endif /* not used */
/* Above this point are reusable test routines. Not clear that they
** should really be in this file.
*************************************************************************/
/*
** This test verifies that if a system crash occurs while doing merge work
** on the db, no data is lost.
*/
static void crash_test1(int bCompress, int *pRc){
const char *DBNAME = "testdb.lsm";
const DatasourceDefn defn = {TEST_DATASOURCE_RANDOM, 12, 16, 200, 200};
const int nRow = 5000; /* Database size */
const int nIter = 200; /* Number of test iterations */
const int nWork = 20; /* Maximum lsm_work() calls per iteration */
const int nPage = 15; /* Pages per lsm_work call */
int i;
int iDot = 0;
Datasource *pData;
CksumDb *pCksumDb;
TestDb *pDb;
char *zCfg;
const char *azConfig[2] = {
"page_size=1024 block_size=65536 autoflush=16384 safety=2 mmap=0",
"page_size=1024 block_size=65536 autoflush=16384 safety=2 "
" compression=1 mmap=0"
};
assert( bCompress==0 || bCompress==1 );
/* Allocate datasource. And calculate the expected checksums. */
pData = testDatasourceNew(&defn);
pCksumDb = testCksumArrayNew(pData, nRow, nRow, 1);
/* Setup and save the initial database. */
zCfg = testMallocPrintf("%s automerge=7", azConfig[bCompress]);
testSetupSavedLsmdb(zCfg, DBNAME, pData, 5000, pRc);
testFree(zCfg);
for(i=0; i<nIter && *pRc==0; i++){
int iWork;
int testrc = 0;
testCaseProgress(i, nIter, testCaseNDot(), &iDot);
/* Restore and open the database. */
testRestoreDb(DBNAME, "log");
testrc = tdb_lsm_open(azConfig[bCompress], DBNAME, 0, &pDb);
assert( testrc==0 );
/* Call lsm_work() on the db */
tdb_lsm_prepare_sync_crash(pDb, 1 + (i%(nWork*2)));
for(iWork=0; testrc==0 && iWork<nWork; iWork++){
int nWrite = 0;
lsm_db *db = tdb_lsm(pDb);
testrc = lsm_work(db, 0, nPage, &nWrite);
/* assert( testrc!=0 || nWrite>0 ); */
if( testrc==0 ) testrc = lsm_checkpoint(db, 0);
}
tdb_close(pDb);
/* Check that the database content is still correct */
testCompareCksumLsmdb(DBNAME,
bCompress, testCksumArrayGet(pCksumDb, nRow), 0, pRc);
}
testCksumArrayFree(pCksumDb);
testDatasourceFree(pData);
}
/*
** This test verifies that if a system crash occurs while committing a
** transaction to the log file, no earlier transactions are lost or damaged.
*/
static void crash_test2(int bCompress, int *pRc){
const char *DBNAME = "testdb.lsm";
const DatasourceDefn defn = {TEST_DATASOURCE_RANDOM, 12, 16, 1000, 1000};
const int nIter = 200;
const int nInsert = 20;
int i;
int iDot = 0;
Datasource *pData;
CksumDb *pCksumDb;
TestDb *pDb;
/* Allocate datasource. And calculate the expected checksums. */
pData = testDatasourceNew(&defn);
pCksumDb = testCksumArrayNew(pData, 100, 100+nInsert, 1);
/* Setup and save the initial database. */
testSetupSavedLsmdb("", DBNAME, pData, 100, pRc);
for(i=0; i<nIter && *pRc==0; i++){
int iIns;
int testrc = 0;
testCaseProgress(i, nIter, testCaseNDot(), &iDot);
/* Restore and open the database. */
testRestoreDb(DBNAME, "log");
testrc = tdb_lsm_open("safety=2", DBNAME, 0, &pDb);
assert( testrc==0 );
/* Insert nInsert records into the database. Crash midway through. */
tdb_lsm_prepare_sync_crash(pDb, 1 + (i%(nInsert+2)));
for(iIns=0; iIns<nInsert; iIns++){
void *pKey; int nKey;
void *pVal; int nVal;
testDatasourceEntry(pData, 100+iIns, &pKey, &nKey, &pVal, &nVal);
testrc = tdb_write(pDb, pKey, nKey, pVal, nVal);
if( testrc ) break;
}
tdb_close(pDb);
/* Check that no data was lost when the system crashed. */
testCompareCksumLsmdb(DBNAME, bCompress,
testCksumArrayGet(pCksumDb, 100 + iIns),
testCksumArrayGet(pCksumDb, 100 + iIns + 1),
pRc
);
}
testDatasourceFree(pData);
testCksumArrayFree(pCksumDb);
}
/*
** This test verifies that if a system crash occurs when checkpointing
** the database, data is not lost (assuming that any writes not synced
** to the db have been synced into the log file).
*/
static void crash_test3(int bCompress, int *pRc){
const char *DBNAME = "testdb.lsm";
const int nIter = 100;
const DatasourceDefn defn = {TEST_DATASOURCE_RANDOM, 12, 16, 1000, 1000};
int i;
int iDot = 0;
Datasource *pData;
CksumDb *pCksumDb;
TestDb *pDb;
/* Allocate datasource. And calculate the expected checksums. */
pData = testDatasourceNew(&defn);
pCksumDb = testCksumArrayNew(pData, 110, 150, 10);
/* Setup and save the initial database. */
testSetupSavedLsmdb("", DBNAME, pData, 100, pRc);
for(i=0; i<nIter && *pRc==0; i++){
int iOpen;
testCaseProgress(i, nIter, testCaseNDot(), &iDot);
testRestoreDb(DBNAME, "log");
for(iOpen=0; iOpen<5; iOpen++){
/* Open the database. Insert 10 more records. */
pDb = testOpen("lsm", 0, pRc);
testWriteDatasourceRange(pDb, pData, 100+iOpen*10, 10, pRc);
/* Schedule a crash simulation then close the db. */
tdb_lsm_prepare_sync_crash(pDb, 1 + (i%2));
tdb_close(pDb);
/* Open the database and check that the crash did not cause any
** data loss. */
testCompareCksumLsmdb(DBNAME, bCompress,
testCksumArrayGet(pCksumDb, 110 + iOpen*10), 0,
pRc
);
}
}
testDatasourceFree(pData);
testCksumArrayFree(pCksumDb);
}
void do_crash_test(const char *zPattern, int *pRc){
struct Test {
const char *zTest;
void (*x)(int, int *);
int bCompress;
} aTest [] = {
{ "crash.lsm.1", crash_test1, 0 },
#ifdef HAVE_ZLIB
{ "crash.lsm_zip.1", crash_test1, 1 },
#endif
{ "crash.lsm.2", crash_test2, 0 },
{ "crash.lsm.3", crash_test3, 0 },
};
int i;
for(i=0; *pRc==LSM_OK && i<ArraySize(aTest); i++){
struct Test *p = &aTest[i];
if( testCaseBegin(pRc, zPattern, "%s", p->zTest) ){
p->x(p->bCompress, pRc);
testCaseFinish(*pRc);
}
}
}
-238
View File
@@ -1,238 +0,0 @@
/*
** This file contains tests related to the explicit rollback of database
** transactions and sub-transactions.
*/
/*
** Repeat 2000 times (until the db contains 100,000 entries):
**
** 1. Open a transaction and insert 500 rows, opening a nested
** sub-transaction each 100 rows.
**
** 2. Roll back to each sub-transaction savepoint. Check the database
** checksum looks Ok.
**
** 3. Every second iteration, roll back the main transaction. Check the
** db checksum is correct. Every other iteration, commit the main
** transaction (increasing the size of the db by 100 rows).
*/
#include "lsmtest.h"
struct CksumDb {
int nFirst;
int nLast;
int nStep;
char **azCksum;
};
CksumDb *testCksumArrayNew(
Datasource *pData,
int nFirst,
int nLast,
int nStep
){
TestDb *pDb;
CksumDb *pRet;
int i;
int nEntry;
int rc = 0;
assert( nLast>=nFirst && ((nLast-nFirst)%nStep)==0 );
pRet = malloc(sizeof(CksumDb));
memset(pRet, 0, sizeof(CksumDb));
pRet->nFirst = nFirst;
pRet->nLast = nLast;
pRet->nStep = nStep;
nEntry = 1 + ((nLast - nFirst) / nStep);
/* Allocate space so that azCksum is an array of nEntry pointers to
** buffers each TEST_CKSUM_BYTES in size. */
pRet->azCksum = (char **)malloc(nEntry * (sizeof(char *) + TEST_CKSUM_BYTES));
for(i=0; i<nEntry; i++){
char *pStart = (char *)(&pRet->azCksum[nEntry]);
pRet->azCksum[i] = &pStart[i * TEST_CKSUM_BYTES];
}
tdb_open("lsm", "tempdb.lsm", 1, &pDb);
testWriteDatasourceRange(pDb, pData, 0, nFirst, &rc);
for(i=0; i<nEntry; i++){
testCksumDatabase(pDb, pRet->azCksum[i]);
if( i==nEntry ) break;
testWriteDatasourceRange(pDb, pData, nFirst+i*nStep, nStep, &rc);
}
tdb_close(pDb);
return pRet;
}
char *testCksumArrayGet(CksumDb *p, int nRow){
int i;
assert( nRow>=p->nFirst );
assert( nRow<=p->nLast );
assert( ((nRow-p->nFirst) % p->nStep)==0 );
i = (nRow - p->nFirst) / p->nStep;
return p->azCksum[i];
}
void testCksumArrayFree(CksumDb *p){
free(p->azCksum);
memset(p, 0x55, sizeof(*p));
free(p);
}
/* End of CksumDb code.
**************************************************************************/
/*
** Test utility function. Write key-value pair $i from datasource pData
** into database pDb.
*/
void testWriteDatasource(TestDb *pDb, Datasource *pData, int i, int *pRc){
void *pKey; int nKey;
void *pVal; int nVal;
testDatasourceEntry(pData, i, &pKey, &nKey, &pVal, &nVal);
testWrite(pDb, pKey, nKey, pVal, nVal, pRc);
}
/*
** Test utility function. Delete datasource pData key $i from database pDb.
*/
void testDeleteDatasource(TestDb *pDb, Datasource *pData, int i, int *pRc){
void *pKey; int nKey;
testDatasourceEntry(pData, i, &pKey, &nKey, 0, 0);
testDelete(pDb, pKey, nKey, pRc);
}
/*
** This function inserts nWrite key/value pairs into database pDb - the
** nWrite key value pairs starting at iFirst from data source pData.
*/
void testWriteDatasourceRange(
TestDb *pDb, /* Database to write to */
Datasource *pData, /* Data source to read values from */
int iFirst, /* Index of first key/value pair */
int nWrite, /* Number of key/value pairs to write */
int *pRc /* IN/OUT: Error code */
){
int i;
for(i=0; i<nWrite; i++){
testWriteDatasource(pDb, pData, iFirst+i, pRc);
}
}
void testDeleteDatasourceRange(
TestDb *pDb, /* Database to write to */
Datasource *pData, /* Data source to read keys from */
int iFirst, /* Index of first key */
int nWrite, /* Number of keys to delete */
int *pRc /* IN/OUT: Error code */
){
int i;
for(i=0; i<nWrite; i++){
testDeleteDatasource(pDb, pData, iFirst+i, pRc);
}
}
static char *getName(const char *zSystem){
char *zRet;
zRet = testMallocPrintf("rollback.%s", zSystem);
return zRet;
}
static int rollback_test_1(
const char *zSystem,
Datasource *pData
){
const int nRepeat = 100;
TestDb *pDb;
int rc;
int i;
CksumDb *pCksum;
char *zName;
zName = getName(zSystem);
testCaseStart(&rc, zName);
testFree(zName);
pCksum = testCksumArrayNew(pData, 0, nRepeat*100, 100);
pDb = 0;
rc = tdb_open(zSystem, 0, 1, &pDb);
if( pDb && tdb_transaction_support(pDb)==0 ){
testCaseSkip();
goto skip_rollback_test;
}
for(i=0; i<nRepeat && rc==0; i++){
char zCksum[TEST_CKSUM_BYTES];
int nCurrent = (((i+1)/2) * 100);
int nDbRow;
int iTrans;
/* Check that the database is the expected size. */
nDbRow = testCountDatabase(pDb);
testCompareInt(nCurrent, nDbRow, &rc);
for(iTrans=2; iTrans<=6 && rc==0; iTrans++){
tdb_begin(pDb, iTrans);
testWriteDatasourceRange(pDb, pData, nCurrent, 100, &rc);
nCurrent += 100;
}
testCksumDatabase(pDb, zCksum);
testCompareStr(zCksum, testCksumArrayGet(pCksum, nCurrent), &rc);
for(iTrans=6; iTrans>2 && rc==0; iTrans--){
tdb_rollback(pDb, iTrans);
nCurrent -= 100;
testCksumDatabase(pDb, zCksum);
testCompareStr(zCksum, testCksumArrayGet(pCksum, nCurrent), &rc);
}
if( i%2 ){
tdb_rollback(pDb, 0);
nCurrent -= 100;
testCksumDatabase(pDb, zCksum);
testCompareStr(zCksum, testCksumArrayGet(pCksum, nCurrent), &rc);
}else{
tdb_commit(pDb, 0);
}
}
testCaseFinish(rc);
skip_rollback_test:
tdb_close(pDb);
testCksumArrayFree(pCksum);
return rc;
}
void test_rollback(
const char *zSystem,
const char *zPattern,
int *pRc
){
if( *pRc==0 ){
int bRun = 1;
if( zPattern ){
char *zName = getName(zSystem);
bRun = testGlobMatch(zPattern, zName);
testFree(zName);
}
if( bRun ){
DatasourceDefn defn = { TEST_DATASOURCE_RANDOM, 10, 15, 50, 100 };
Datasource *pData = testDatasourceNew(&defn);
*pRc = rollback_test_1(zSystem, pData);
testDatasourceFree(pData);
}
}
}
-127
View File
@@ -1,127 +0,0 @@
/*
** This file contains test cases involving multiple database clients.
*/
#include "lsmtest.h"
/*
** The following code implements test cases "mc1.*".
**
** This test case uses one writer and $nReader readers. All connections
** are driven by a single thread. All connections are opened at the start
** of the test and remain open until the test is finished.
**
** The test consists of $nStep steps. Each step the following is performed:
**
** 1. The writer inserts $nWriteStep records into the db.
**
** 2. The writer checks that the contents of the db are as expected.
**
** 3. Each reader that currently has an open read transaction also checks
** that the contents of the db are as expected (according to the snapshot
** the read transaction is reading - see below).
**
** After step 1, reader 1 opens a read transaction. After step 2, reader
** 2 opens a read transaction, and so on. At step ($nReader+1), reader 1
** closes the current read transaction and opens a new one. And so on.
** The result is that at step N (for N > $nReader), there exists a reader
** with an open read transaction reading the snapshot committed following
** steps (N-$nReader-1) to N.
*/
typedef struct Mctest Mctest;
struct Mctest {
DatasourceDefn defn; /* Datasource to use */
int nStep; /* Total number of steps in test */
int nWriteStep; /* Number of rows to insert each step */
int nReader; /* Number of read connections */
};
static void do_mc_test(
const char *zSystem, /* Database system to test */
Mctest *pTest,
int *pRc /* IN/OUT: return code */
){
const int nDomain = pTest->nStep * pTest->nWriteStep;
Datasource *pData; /* Source of data */
TestDb *pDb; /* First database connection (writer) */
int iReader; /* Used to iterate through aReader */
int iStep; /* Current step in test */
int iDot = 0; /* Current step in test */
/* Array of reader connections */
struct Reader {
TestDb *pDb; /* Connection handle */
int iLast; /* Current snapshot contains keys 0..iLast */
} *aReader;
/* Create a data source */
pData = testDatasourceNew(&pTest->defn);
/* Open the writer connection */
pDb = testOpen(zSystem, 1, pRc);
/* Allocate aReader */
aReader = (struct Reader *)testMalloc(sizeof(aReader[0]) * pTest->nReader);
for(iReader=0; iReader<pTest->nReader; iReader++){
aReader[iReader].pDb = testOpen(zSystem, 0, pRc);
}
for(iStep=0; iStep<pTest->nStep; iStep++){
int iLast;
int iBegin; /* Start read trans using aReader[iBegin] */
/* Insert nWriteStep more records into the database */
int iFirst = iStep*pTest->nWriteStep;
testWriteDatasourceRange(pDb, pData, iFirst, pTest->nWriteStep, pRc);
/* Check that the db is Ok according to the writer */
iLast = (iStep+1) * pTest->nWriteStep - 1;
testDbContents(pDb, pData, nDomain, 0, iLast, iLast, 1, pRc);
/* Have reader (iStep % nReader) open a read transaction here. */
iBegin = (iStep % pTest->nReader);
if( iBegin<iStep ) tdb_commit(aReader[iBegin].pDb, 0);
tdb_begin(aReader[iBegin].pDb, 1);
aReader[iBegin].iLast = iLast;
/* Check that the db is Ok for each open reader */
for(iReader=0; iReader<pTest->nReader && aReader[iReader].iLast; iReader++){
iLast = aReader[iReader].iLast;
testDbContents(
aReader[iReader].pDb, pData, nDomain, 0, iLast, iLast, 1, pRc
);
}
/* Report progress */
testCaseProgress(iStep, pTest->nStep, testCaseNDot(), &iDot);
}
/* Close all readers */
for(iReader=0; iReader<pTest->nReader; iReader++){
testClose(&aReader[iReader].pDb);
}
testFree(aReader);
/* Close the writer-connection and free the datasource */
testClose(&pDb);
testDatasourceFree(pData);
}
void test_mc(
const char *zSystem, /* Database system name */
const char *zPattern, /* Run test cases that match this pattern */
int *pRc /* IN/OUT: Error code */
){
int i;
Mctest aTest[] = {
{ { TEST_DATASOURCE_RANDOM, 10,10, 100,100 }, 100, 10, 5 },
};
for(i=0; i<ArraySize(aTest); i++){
if( testCaseBegin(pRc, zPattern, "mc1.%s.%d", zSystem, i) ){
do_mc_test(zSystem, &aTest[i], pRc);
testCaseFinish(*pRc);
}
}
}
-633
View File
@@ -1,633 +0,0 @@
/*
** This file is broken into three semi-autonomous parts:
**
** 1. The database functions.
** 2. The thread wrappers.
** 3. The implementation of the mt1.* tests.
*/
/*************************************************************************
** DATABASE CONTENTS:
**
** The database contains up to N key/value pairs, where N is some large
** number (say 10,000,000). Keys are integer values between 0 and (N-1).
** The value associated with each key is a pseudo-random blob of data.
**
** Key/value pair keys are encoded as the two bytes "k." followed by a
** 10-digit decimal number. i.e. key 45 -> "k.0000000045".
**
** As well as the key/value pairs, the database also contains checksum
** entries. The checksums form a hierarchy - for every F key/value
** entries there is one level 1 checksum. And for each F level 1 checksums
** there is one level 2 checksum. And so on.
**
** Checksum keys are encoded as the two byte "c." followed by the
** checksum level, followed by a 10 digit decimal number containing
** the value of the first key that contributes to the checksum value.
** For example, assuming F==10, the level 1 checksum that spans keys
** 10 to 19 is "c.1.0000000010".
**
** Clients may perform one of two operations on the database: a read
** or a write.
**
** READ OPERATIONS:
**
** A read operation scans a range of F key/value pairs. It computes
** the expected checksum and then compares the computed value to the
** actual value stored in the level 1 checksum entry. It then scans
** the group of F level 1 checksums, and compares the computed checksum
** to the associated level 2 checksum value, and so on until the
** highest level checksum value has been verified.
**
** If a checksum ever fails to match the expected value, the test
** has failed.
**
** WRITE OPERATIONS:
**
** A write operation involves writing (possibly clobbering) a single
** key/value pair. The associated level 1 checksum is then recalculated
** updated. Then the level 2 checksum, and so on until the highest
** level checksum has been modified.
**
** All updates occur inside a single transaction.
**
** INTERFACE:
**
** The interface used by test cases to read and write the db consists
** of type DbParameters and the following functions:
**
** dbReadOperation()
** dbWriteOperation()
*/
#include "lsmtest.h"
typedef struct DbParameters DbParameters;
struct DbParameters {
int nFanout; /* Checksum fanout (F) */
int nKey; /* Size of key space (N) */
};
#define DB_KEY_BYTES (2+5+10+1)
/*
** Argument aBuf[] must point to a buffer at least DB_KEY_BYTES in size.
** This function populates the buffer with a nul-terminated key string
** corresponding to key iKey.
*/
static void dbFormatKey(
DbParameters *pParam,
int iLevel,
int iKey, /* Key value */
char *aBuf /* Write key string here */
){
if( iLevel==0 ){
snprintf(aBuf, DB_KEY_BYTES, "k.%.10d", iKey);
}else{
int f = 1;
int i;
for(i=0; i<iLevel; i++) f = f * pParam->nFanout;
snprintf(aBuf, DB_KEY_BYTES, "c.%d.%.10d", iLevel, f*(iKey/f));
}
}
/*
** Argument aBuf[] must point to a buffer at least DB_KEY_BYTES in size.
** This function populates the buffer with the string representation of
** checksum value iVal.
*/
static void dbFormatCksumValue(u32 iVal, char *aBuf){
snprintf(aBuf, DB_KEY_BYTES, "%.10u", iVal);
}
/*
** Return the highest level of checksum in the database described
** by *pParam.
*/
static int dbMaxLevel(DbParameters *pParam){
int iMax;
int n = 1;
for(iMax=0; n<pParam->nKey; iMax++){
n = n * pParam->nFanout;
}
return iMax;
}
static void dbCksum(
void *pCtx, /* IN/OUT: Pointer to u32 containing cksum */
void *pKey, int nKey, /* Database key. Unused. */
void *pVal, int nVal /* Database value. Checksum this. */
){
u8 *aVal = (u8 *)pVal;
u32 *pCksum = (u32 *)pCtx;
u32 cksum = *pCksum;
int i;
unused_parameter(pKey);
unused_parameter(nKey);
for(i=0; i<nVal; i++){
cksum += (cksum<<3) + (int)aVal[i];
}
*pCksum = cksum;
}
/*
** Compute the value of the checksum stored on level iLevel that contains
** data from key iKey by scanning the pParam->nFanout entries at level
** iLevel-1.
*/
static u32 dbComputeCksum(
DbParameters *pParam, /* Database parameters */
TestDb *pDb, /* Database connection handle */
int iLevel, /* Level of checksum to compute */
int iKey, /* Compute checksum for this key */
int *pRc /* IN/OUT: Error code */
){
u32 cksum = 0;
if( *pRc==0 ){
int nFirst;
int nLast;
int iFirst = 0;
int iLast = 0;
int i;
int f = 1;
char zFirst[DB_KEY_BYTES];
char zLast[DB_KEY_BYTES];
assert( iLevel>=1 );
for(i=0; i<iLevel; i++) f = f * pParam->nFanout;
iFirst = f*(iKey/f);
iLast = iFirst + f - 1;
dbFormatKey(pParam, iLevel-1, iFirst, zFirst);
dbFormatKey(pParam, iLevel-1, iLast, zLast);
nFirst = strlen(zFirst);
nLast = strlen(zLast);
*pRc = tdb_scan(pDb, (u32*)&cksum, 0, zFirst, nFirst, zLast, nLast,dbCksum);
}
return cksum;
}
static void dbReadOperation(
DbParameters *pParam, /* Database parameters */
TestDb *pDb, /* Database connection handle */
void (*xDelay)(void *),
void *pDelayCtx,
int iKey, /* Key to read */
int *pRc /* IN/OUT: Error code */
){
const int iMax = dbMaxLevel(pParam);
int i;
if( tdb_transaction_support(pDb) ) testBegin(pDb, 1, pRc);
for(i=1; *pRc==0 && i<=iMax; i++){
char zCksum[DB_KEY_BYTES];
char zKey[DB_KEY_BYTES];
u32 iCksum = 0;
iCksum = dbComputeCksum(pParam, pDb, i, iKey, pRc);
if( iCksum ){
if( xDelay && i==1 ) xDelay(pDelayCtx);
dbFormatCksumValue(iCksum, zCksum);
dbFormatKey(pParam, i, iKey, zKey);
testFetchStr(pDb, zKey, zCksum, pRc);
}
}
if( tdb_transaction_support(pDb) ) testCommit(pDb, 0, pRc);
}
static int dbWriteOperation(
DbParameters *pParam, /* Database parameters */
TestDb *pDb, /* Database connection handle */
int iKey, /* Key to write to */
const char *zValue, /* Nul-terminated value to write */
int *pRc /* IN/OUT: Error code */
){
const int iMax = dbMaxLevel(pParam);
char zKey[DB_KEY_BYTES];
int i;
int rc;
assert( iKey>=0 && iKey<pParam->nKey );
dbFormatKey(pParam, 0, iKey, zKey);
/* Open a write transaction. This may fail - SQLITE4_BUSY */
if( *pRc==0 && tdb_transaction_support(pDb) ){
rc = tdb_begin(pDb, 2);
if( rc==5 ) return 0;
*pRc = rc;
}
testWriteStr(pDb, zKey, zValue, pRc);
for(i=1; i<=iMax; i++){
char zCksum[DB_KEY_BYTES];
u32 iCksum = 0;
iCksum = dbComputeCksum(pParam, pDb, i, iKey, pRc);
dbFormatCksumValue(iCksum, zCksum);
dbFormatKey(pParam, i, iKey, zKey);
testWriteStr(pDb, zKey, zCksum, pRc);
}
if( tdb_transaction_support(pDb) ) testCommit(pDb, 0, pRc);
return 1;
}
/*************************************************************************
** The following block contains testXXX() functions that implement a
** wrapper around the systems native multi-thread support. There are no
** synchronization primitives - just functions to launch and join
** threads. Wrapper functions are:
**
** testThreadSupport()
**
** testThreadInit()
** testThreadShutdown()
** testThreadLaunch()
** testThreadWait()
**
** testThreadSetHalt()
** testThreadGetHalt()
** testThreadSetResult()
** testThreadGetResult()
**
** testThreadEnterMutex()
** testThreadLeaveMutex()
*/
typedef struct ThreadSet ThreadSet;
#ifdef LSM_MUTEX_PTHREADS
#include <pthread.h>
#include <unistd.h>
typedef struct Thread Thread;
struct Thread {
int rc;
char *zMsg;
pthread_t id;
void (*xMain)(ThreadSet *, int, void *);
void *pCtx;
ThreadSet *pThreadSet;
};
struct ThreadSet {
int bHalt; /* Halt flag */
int nThread; /* Number of threads */
Thread *aThread; /* Array of Thread structures */
pthread_mutex_t mutex; /* Mutex used for cheating */
};
/*
** Return true if this build supports threads, or false otherwise. If
** this function returns false, no other testThreadXXX() functions should
** be called.
*/
static int testThreadSupport(){ return 1; }
/*
** Allocate and return a thread-set handle with enough space allocated
** to handle up to nMax threads. Each call to this function should be
** matched by a call to testThreadShutdown() to delete the object.
*/
static ThreadSet *testThreadInit(int nMax){
int nByte; /* Total space to allocate */
ThreadSet *p; /* Return value */
nByte = sizeof(ThreadSet) + sizeof(struct Thread) * nMax;
p = (ThreadSet *)testMalloc(nByte);
p->nThread = nMax;
p->aThread = (Thread *)&p[1];
pthread_mutex_init(&p->mutex, 0);
return p;
}
/*
** Delete a thread-set object and release all resources held by it.
*/
static void testThreadShutdown(ThreadSet *p){
int i;
for(i=0; i<p->nThread; i++){
testFree(p->aThread[i].zMsg);
}
pthread_mutex_destroy(&p->mutex);
testFree(p);
}
static void *ttMain(void *pArg){
Thread *pThread = (Thread *)pArg;
int iThread;
iThread = (pThread - pThread->pThreadSet->aThread);
pThread->xMain(pThread->pThreadSet, iThread, pThread->pCtx);
return 0;
}
/*
** Launch a new thread.
*/
static int testThreadLaunch(
ThreadSet *p,
int iThread,
void (*xMain)(ThreadSet *, int, void *),
void *pCtx
){
int rc;
Thread *pThread;
assert( iThread>=0 && iThread<p->nThread );
pThread = &p->aThread[iThread];
assert( pThread->pThreadSet==0 );
pThread->xMain = xMain;
pThread->pCtx = pCtx;
pThread->pThreadSet = p;
rc = pthread_create(&pThread->id, 0, ttMain, (void *)pThread);
return rc;
}
/*
** Set the thread-set "halt" flag.
*/
static void testThreadSetHalt(ThreadSet *pThreadSet){
pThreadSet->bHalt = 1;
}
/*
** Return the current value of the thread-set "halt" flag.
*/
static int testThreadGetHalt(ThreadSet *pThreadSet){
return pThreadSet->bHalt;
}
static void testThreadSleep(ThreadSet *pThreadSet, int nMs){
int nRem = nMs;
while( nRem>0 && testThreadGetHalt(pThreadSet)==0 ){
usleep(50000);
nRem -= 50;
}
}
/*
** Wait for all threads launched to finish before returning. If nMs
** is greater than zero, set the "halt" flag to tell all threads
** to halt after waiting nMs milliseconds.
*/
static void testThreadWait(ThreadSet *pThreadSet, int nMs){
int i;
testThreadSleep(pThreadSet, nMs);
testThreadSetHalt(pThreadSet);
for(i=0; i<pThreadSet->nThread; i++){
Thread *pThread = &pThreadSet->aThread[i];
if( pThread->xMain ){
pthread_join(pThread->id, 0);
}
}
}
/*
** Set the result for thread iThread.
*/
static void testThreadSetResult(
ThreadSet *pThreadSet, /* Thread-set handle */
int iThread, /* Set result for this thread */
int rc, /* Result error code */
char *zFmt, /* Result string format */
... /* Result string formatting args... */
){
va_list ap;
testFree(pThreadSet->aThread[iThread].zMsg);
pThreadSet->aThread[iThread].rc = rc;
pThreadSet->aThread[iThread].zMsg = 0;
if( zFmt ){
va_start(ap, zFmt);
pThreadSet->aThread[iThread].zMsg = testMallocVPrintf(zFmt, ap);
va_end(ap);
}
}
/*
** Retrieve the result for thread iThread.
*/
static int testThreadGetResult(
ThreadSet *pThreadSet, /* Thread-set handle */
int iThread, /* Get result for this thread */
const char **pzRes /* OUT: Pointer to result string */
){
if( pzRes ) *pzRes = pThreadSet->aThread[iThread].zMsg;
return pThreadSet->aThread[iThread].rc;
}
/*
** Enter and leave the test case mutex.
*/
#if 0
static void testThreadEnterMutex(ThreadSet *p){
pthread_mutex_lock(&p->mutex);
}
static void testThreadLeaveMutex(ThreadSet *p){
pthread_mutex_unlock(&p->mutex);
}
#endif
#endif
#if !defined(LSM_MUTEX_PTHREADS)
static int testThreadSupport(){ return 0; }
#define testThreadInit(a) 0
#define testThreadShutdown(a)
#define testThreadLaunch(a,b,c,d) 0
#define testThreadWait(a,b)
#define testThreadSetHalt(a)
#define testThreadGetHalt(a) 0
#define testThreadGetResult(a,b,c) 0
#define testThreadSleep(a,b) 0
static void testThreadSetResult(ThreadSet *a, int b, int c, char *d, ...){
unused_parameter(a);
unused_parameter(b);
unused_parameter(c);
unused_parameter(d);
}
#endif
/* End of threads wrapper.
*************************************************************************/
/*************************************************************************
** Below this point is the third part of this file - the implementation
** of the mt1.* tests.
*/
typedef struct Mt1Test Mt1Test;
struct Mt1Test {
DbParameters param; /* Description of database to read/write */
int nReadwrite; /* Number of read/write threads */
int nFastReader; /* Number of fast reader threads */
int nSlowReader; /* Number of slow reader threads */
int nMs; /* How long to run for */
const char *zSystem; /* Database system to test */
};
typedef struct Mt1DelayCtx Mt1DelayCtx;
struct Mt1DelayCtx {
ThreadSet *pSet; /* Threadset to sleep within */
int nMs; /* Sleep in ms */
};
static void xMt1Delay(void *pCtx){
Mt1DelayCtx *p = (Mt1DelayCtx *)pCtx;
testThreadSleep(p->pSet, p->nMs);
}
#define MT1_THREAD_RDWR 0
#define MT1_THREAD_SLOW 1
#define MT1_THREAD_FAST 2
static void xMt1Work(lsm_db *pDb, void *pCtx){
#if 0
char *z = 0;
lsm_info(pDb, LSM_INFO_DB_STRUCTURE, &z);
printf("%s\n", z);
fflush(stdout);
#endif
}
/*
** This is the main() proc for all threads in test case "mt1".
*/
static void mt1Main(ThreadSet *pThreadSet, int iThread, void *pCtx){
Mt1Test *p = (Mt1Test *)pCtx; /* Test parameters */
Mt1DelayCtx delay;
int nRead = 0; /* Number of calls to dbReadOperation() */
int nWrite = 0; /* Number of completed database writes */
int rc = 0; /* Error code */
int iPrng; /* Prng argument variable */
TestDb *pDb; /* Database handle */
int eType;
delay.pSet = pThreadSet;
delay.nMs = 0;
if( iThread<p->nReadwrite ){
eType = MT1_THREAD_RDWR;
}else if( iThread<(p->nReadwrite+p->nFastReader) ){
eType = MT1_THREAD_FAST;
}else{
eType = MT1_THREAD_SLOW;
delay.nMs = (p->nMs / 20);
}
/* Open a new database connection. Initialize the pseudo-random number
** argument based on the thread number. */
iPrng = testPrngValue(iThread);
pDb = testOpen(p->zSystem, 0, &rc);
if( rc==0 ){
tdb_lsm_config_work_hook(pDb, xMt1Work, 0);
}
/* Loop until either an error occurs or some other thread sets the
** halt flag. */
while( rc==0 && testThreadGetHalt(pThreadSet)==0 ){
int iKey;
/* Perform a read operation on an arbitrarily selected key. */
iKey = (testPrngValue(iPrng++) % p->param.nKey);
dbReadOperation(&p->param, pDb, xMt1Delay, (void *)&delay, iKey, &rc);
if( rc ) continue;
nRead++;
/* Attempt to write an arbitrary key value pair (and update the associated
** checksum entries). dbWriteOperation() returns 1 if the write is
** successful, or 0 if it failed with an LSM_BUSY error. */
if( eType==MT1_THREAD_RDWR ){
char aValue[50];
char aRnd[25];
iKey = (testPrngValue(iPrng++) % p->param.nKey);
testPrngString(iPrng, aRnd, sizeof(aRnd));
iPrng += sizeof(aRnd);
snprintf(aValue, sizeof(aValue), "%d.%s", iThread, aRnd);
nWrite += dbWriteOperation(&p->param, pDb, iKey, aValue, &rc);
}
}
testClose(&pDb);
/* If an error has occured, set the thread error code and the threadset
** halt flag to tell the other test threads to halt. Otherwise, set the
** thread error code to 0 and post a message with the number of read
** and write operations completed. */
if( rc ){
testThreadSetResult(pThreadSet, iThread, rc, 0);
testThreadSetHalt(pThreadSet);
}else{
testThreadSetResult(pThreadSet, iThread, 0, "r/w: %d/%d", nRead, nWrite);
}
}
static void do_test_mt1(
const char *zSystem, /* Database system name */
const char *zPattern, /* Run test cases that match this pattern */
int *pRc /* IN/OUT: Error code */
){
Mt1Test aTest[] = {
/* param, nReadwrite, nFastReader, nSlowReader, nMs, zSystem */
{ {10, 1000}, 4, 0, 0, 10000, 0 },
{ {10, 1000}, 4, 4, 2, 100000, 0 },
{ {10, 100000}, 4, 0, 0, 10000, 0 },
{ {10, 100000}, 4, 4, 2, 100000, 0 },
};
int i;
for(i=0; *pRc==0 && i<ArraySize(aTest); i++){
Mt1Test *p = &aTest[i];
int bRun = testCaseBegin(pRc, zPattern,
"mt1.%s.db=%d,%d.ms=%d.rdwr=%d.fast=%d.slow=%d",
zSystem, p->param.nFanout, p->param.nKey,
p->nMs, p->nReadwrite, p->nFastReader, p->nSlowReader
);
if( bRun ){
TestDb *pDb;
ThreadSet *pSet;
int iThread;
int nThread;
p->zSystem = zSystem;
pDb = testOpen(zSystem, 1, pRc);
nThread = p->nReadwrite + p->nFastReader + p->nSlowReader;
pSet = testThreadInit(nThread);
for(iThread=0; *pRc==0 && iThread<nThread; iThread++){
testThreadLaunch(pSet, iThread, mt1Main, (void *)p);
}
testThreadWait(pSet, p->nMs);
for(iThread=0; *pRc==0 && iThread<nThread; iThread++){
*pRc = testThreadGetResult(pSet, iThread, 0);
}
testCaseFinish(*pRc);
for(iThread=0; *pRc==0 && iThread<nThread; iThread++){
const char *zMsg = 0;
*pRc = testThreadGetResult(pSet, iThread, &zMsg);
printf(" Info: thread %d (%d): %s\n", iThread, *pRc, zMsg);
}
testThreadShutdown(pSet);
testClose(&pDb);
}
}
}
void test_mt(
const char *zSystem, /* Database system name */
const char *zPattern, /* Run test cases that match this pattern */
int *pRc /* IN/OUT: Error code */
){
if( testThreadSupport()==0 ) return;
do_test_mt1(zSystem, zPattern, pRc);
}
-661
View File
@@ -1,661 +0,0 @@
#include "lsmtest.h"
typedef struct OomTest OomTest;
struct OomTest {
lsm_env *pEnv;
int iNext; /* Next value to pass to testMallocOom() */
int nFail; /* Number of OOM events injected */
int bEnable;
int rc; /* Test case error code */
};
static void testOomStart(OomTest *p){
memset(p, 0, sizeof(OomTest));
p->iNext = 1;
p->bEnable = 1;
p->nFail = 1;
p->pEnv = tdb_lsm_env();
}
static void xOomHook(OomTest *p){
p->nFail++;
}
static int testOomContinue(OomTest *p){
if( p->rc!=0 || (p->iNext>1 && p->nFail==0) ){
return 0;
}
p->nFail = 0;
testMallocOom(p->pEnv, p->iNext, 0, (void (*)(void*))xOomHook, (void *)p);
return 1;
}
static void testOomEnable(OomTest *p, int bEnable){
p->bEnable = bEnable;
testMallocOomEnable(p->pEnv, bEnable);
}
static void testOomNext(OomTest *p){
p->iNext++;
}
static int testOomHit(OomTest *p){
return (p->nFail>0);
}
static int testOomFinish(OomTest *p){
return p->rc;
}
static void testOomAssert(OomTest *p, int bVal){
if( bVal==0 ){
test_failed();
p->rc = 1;
}
}
/*
** Test that the error code matches the state of the OomTest object passed
** as the first argument. Specifically, check that rc is LSM_NOMEM if an
** OOM error has already been injected, or LSM_OK if not.
*/
static void testOomAssertRc(OomTest *p, int rc){
testOomAssert(p, rc==LSM_OK || rc==LSM_NOMEM);
testOomAssert(p, testOomHit(p)==(rc==LSM_NOMEM) || p->bEnable==0 );
}
static void testOomOpen(
OomTest *pOom,
const char *zName,
lsm_db **ppDb,
int *pRc
){
if( *pRc==LSM_OK ){
int rc;
rc = lsm_new(tdb_lsm_env(), ppDb);
if( rc==LSM_OK ) rc = lsm_open(*ppDb, zName);
testOomAssertRc(pOom, rc);
*pRc = rc;
}
}
static void testOomFetch(
OomTest *pOom,
lsm_db *pDb,
void *pKey, int nKey,
void *pVal, int nVal,
int *pRc
){
testOomAssertRc(pOom, *pRc);
if( *pRc==LSM_OK ){
lsm_cursor *pCsr;
int rc;
rc = lsm_csr_open(pDb, &pCsr);
if( rc==LSM_OK ) rc = lsm_csr_seek(pCsr, pKey, nKey, 0);
testOomAssertRc(pOom, rc);
if( rc==LSM_OK ){
const void *p; int n;
testOomAssert(pOom, lsm_csr_valid(pCsr));
rc = lsm_csr_key(pCsr, &p, &n);
testOomAssertRc(pOom, rc);
testOomAssert(pOom, rc!=LSM_OK || (n==nKey && memcmp(pKey, p, nKey)==0) );
}
if( rc==LSM_OK ){
const void *p; int n;
testOomAssert(pOom, lsm_csr_valid(pCsr));
rc = lsm_csr_value(pCsr, &p, &n);
testOomAssertRc(pOom, rc);
testOomAssert(pOom, rc!=LSM_OK || (n==nVal && memcmp(pVal, p, nVal)==0) );
}
lsm_csr_close(pCsr);
*pRc = rc;
}
}
static void testOomWrite(
OomTest *pOom,
lsm_db *pDb,
void *pKey, int nKey,
void *pVal, int nVal,
int *pRc
){
testOomAssertRc(pOom, *pRc);
if( *pRc==LSM_OK ){
int rc;
rc = lsm_insert(pDb, pKey, nKey, pVal, nVal);
testOomAssertRc(pOom, rc);
*pRc = rc;
}
}
static void testOomFetchStr(
OomTest *pOom,
lsm_db *pDb,
const char *zKey,
const char *zVal,
int *pRc
){
int nKey = strlen(zKey);
int nVal = strlen(zVal);
testOomFetch(pOom, pDb, (void *)zKey, nKey, (void *)zVal, nVal, pRc);
}
static void testOomFetchData(
OomTest *pOom,
lsm_db *pDb,
Datasource *pData,
int iKey,
int *pRc
){
void *pKey; int nKey;
void *pVal; int nVal;
testDatasourceEntry(pData, iKey, &pKey, &nKey, &pVal, &nVal);
testOomFetch(pOom, pDb, pKey, nKey, pVal, nVal, pRc);
}
static void testOomWriteStr(
OomTest *pOom,
lsm_db *pDb,
const char *zKey,
const char *zVal,
int *pRc
){
int nKey = strlen(zKey);
int nVal = strlen(zVal);
testOomWrite(pOom, pDb, (void *)zKey, nKey, (void *)zVal, nVal, pRc);
}
static void testOomWriteData(
OomTest *pOom,
lsm_db *pDb,
Datasource *pData,
int iKey,
int *pRc
){
void *pKey; int nKey;
void *pVal; int nVal;
testDatasourceEntry(pData, iKey, &pKey, &nKey, &pVal, &nVal);
testOomWrite(pOom, pDb, pKey, nKey, pVal, nVal, pRc);
}
static void testOomScan(
OomTest *pOom,
lsm_db *pDb,
int bReverse,
const void *pKey, int nKey,
int nScan,
int *pRc
){
if( *pRc==0 ){
int rc;
int iScan = 0;
lsm_cursor *pCsr;
int (*xAdvance)(lsm_cursor *) = 0;
rc = lsm_csr_open(pDb, &pCsr);
testOomAssertRc(pOom, rc);
if( rc==LSM_OK ){
if( bReverse ){
rc = lsm_csr_seek(pCsr, pKey, nKey, LSM_SEEK_LE);
xAdvance = lsm_csr_prev;
}else{
rc = lsm_csr_seek(pCsr, pKey, nKey, LSM_SEEK_GE);
xAdvance = lsm_csr_next;
}
}
testOomAssertRc(pOom, rc);
while( rc==LSM_OK && lsm_csr_valid(pCsr) && iScan<nScan ){
const void *p; int n;
rc = lsm_csr_key(pCsr, &p, &n);
testOomAssertRc(pOom, rc);
if( rc==LSM_OK ){
rc = lsm_csr_value(pCsr, &p, &n);
testOomAssertRc(pOom, rc);
}
if( rc==LSM_OK ){
rc = xAdvance(pCsr);
testOomAssertRc(pOom, rc);
}
iScan++;
}
lsm_csr_close(pCsr);
*pRc = rc;
}
}
#define LSMTEST6_TESTDB "testdb.lsm"
void testDeleteLsmdb(const char *zFile){
char *zLog = testMallocPrintf("%s-log", zFile);
char *zShm = testMallocPrintf("%s-shm", zFile);
unlink(zFile);
unlink(zLog);
unlink(zShm);
testFree(zLog);
testFree(zShm);
}
static void copy_file(const char *zFrom, const char *zTo, int isDatabase){
if( access(zFrom, F_OK) ){
unlink(zTo);
}else{
int fd1;
int fd2;
off_t sz;
off_t i;
struct stat buf;
u8 *aBuf;
fd1 = open(zFrom, O_RDONLY | _O_BINARY, 0644);
fd2 = open(zTo, O_RDWR | O_CREAT | _O_BINARY, 0644);
fstat(fd1, &buf);
sz = buf.st_size;
ftruncate(fd2, sz);
aBuf = testMalloc(4096);
for(i=0; i<sz; i+=4096){
int bLockPage = isDatabase && i == 0;
int nByte = MIN((bLockPage ? 4066 : 4096), sz - i);
memset(aBuf, 0, 4096);
read(fd1, aBuf, nByte);
write(fd2, aBuf, nByte);
if( bLockPage ){
lseek(fd1, 4096, SEEK_SET);
lseek(fd2, 4096, SEEK_SET);
}
}
testFree(aBuf);
close(fd1);
close(fd2);
}
}
void testCopyLsmdb(const char *zFrom, const char *zTo){
char *zLog1 = testMallocPrintf("%s-log", zFrom);
char *zLog2 = testMallocPrintf("%s-log", zTo);
char *zShm1 = testMallocPrintf("%s-shm", zFrom);
char *zShm2 = testMallocPrintf("%s-shm", zTo);
unlink(zShm2);
unlink(zLog2);
unlink(zTo);
copy_file(zFrom, zTo, 1);
copy_file(zLog1, zLog2, 0);
copy_file(zShm1, zShm2, 0);
testFree(zLog1); testFree(zLog2); testFree(zShm1); testFree(zShm2);
}
/*
** File zFile is the path to a database. This function makes backups
** of the database file and its log as follows:
**
** cp $(zFile) $(zFile)-save
** cp $(zFile)-$(zAux) $(zFile)-save-$(zAux)
**
** Function testRestoreDb() can be used to copy the files back in the
** other direction.
*/
void testSaveDb(const char *zFile, const char *zAux){
char *zLog = testMallocPrintf("%s-%s", zFile, zAux);
char *zFileSave = testMallocPrintf("%s-save", zFile);
char *zLogSave = testMallocPrintf("%s-%s-save", zFile, zAux);
unlink(zFileSave);
unlink(zLogSave);
copy_file(zFile, zFileSave, 1);
copy_file(zLog, zLogSave, 0);
testFree(zLog); testFree(zFileSave); testFree(zLogSave);
}
/*
** File zFile is the path to a database. This function restores
** a backup of the database made by a previous call to testSaveDb().
** Specifically, it does the equivalent of:
**
** cp $(zFile)-save $(zFile)
** cp $(zFile)-save-$(zAux) $(zFile)-$(zAux)
*/
void testRestoreDb(const char *zFile, const char *zAux){
char *zLog = testMallocPrintf("%s-%s", zFile, zAux);
char *zFileSave = testMallocPrintf("%s-save", zFile);
char *zLogSave = testMallocPrintf("%s-%s-save", zFile, zAux);
copy_file(zFileSave, zFile, 1);
copy_file(zLogSave, zLog, 0);
testFree(zLog); testFree(zFileSave); testFree(zLogSave);
}
static int lsmWriteStr(lsm_db *pDb, const char *zKey, const char *zVal){
int nKey = strlen(zKey);
int nVal = strlen(zVal);
return lsm_insert(pDb, (void *)zKey, nKey, (void *)zVal, nVal);
}
static void setup_delete_db(void){
testDeleteLsmdb(LSMTEST6_TESTDB);
}
/*
** Create a small database. With the following content:
**
** "one" -> "one"
** "two" -> "four"
** "three" -> "nine"
** "four" -> "sixteen"
** "five" -> "twentyfive"
** "six" -> "thirtysix"
** "seven" -> "fourtynine"
** "eight" -> "sixtyfour"
*/
static void setup_populate_db(void){
const char *azStr[] = {
"one", "one",
"two", "four",
"three", "nine",
"four", "sixteen",
"five", "twentyfive",
"six", "thirtysix",
"seven", "fourtynine",
"eight", "sixtyfour",
};
int rc;
int ii;
lsm_db *pDb;
testDeleteLsmdb(LSMTEST6_TESTDB);
rc = lsm_new(tdb_lsm_env(), &pDb);
if( rc==LSM_OK ) rc = lsm_open(pDb, LSMTEST6_TESTDB);
for(ii=0; rc==LSM_OK && ii<ArraySize(azStr); ii+=2){
rc = lsmWriteStr(pDb, azStr[ii], azStr[ii+1]);
}
lsm_close(pDb);
testSaveDb(LSMTEST6_TESTDB, "log");
assert( rc==LSM_OK );
}
static Datasource *getDatasource(void){
const DatasourceDefn defn = { TEST_DATASOURCE_RANDOM, 10, 15, 200, 250 };
return testDatasourceNew(&defn);
}
/*
** Set up a database file with the following properties:
**
** * Page size is 1024 bytes.
** * Block size is 64 KB.
** * Contains 5000 key-value pairs starting at 0 from the
** datasource returned getDatasource().
*/
static void setup_populate_db2(void){
Datasource *pData;
int ii;
int rc;
int nBlocksize = 64*1024;
int nPagesize = 1024;
int nWritebuffer = 4*1024;
lsm_db *pDb;
testDeleteLsmdb(LSMTEST6_TESTDB);
rc = lsm_new(tdb_lsm_env(), &pDb);
if( rc==LSM_OK ) rc = lsm_open(pDb, LSMTEST6_TESTDB);
lsm_config(pDb, LSM_CONFIG_BLOCK_SIZE, &nBlocksize);
lsm_config(pDb, LSM_CONFIG_PAGE_SIZE, &nPagesize);
lsm_config(pDb, LSM_CONFIG_AUTOFLUSH, &nWritebuffer);
pData = getDatasource();
for(ii=0; rc==LSM_OK && ii<5000; ii++){
void *pKey; int nKey;
void *pVal; int nVal;
testDatasourceEntry(pData, ii, &pKey, &nKey, &pVal, &nVal);
lsm_insert(pDb, pKey, nKey, pVal, nVal);
}
testDatasourceFree(pData);
lsm_close(pDb);
testSaveDb(LSMTEST6_TESTDB, "log");
assert( rc==LSM_OK );
}
/*
** Test the results of OOM conditions in lsm_new().
*/
static void simple_oom_1(OomTest *pOom){
int rc;
lsm_db *pDb;
rc = lsm_new(tdb_lsm_env(), &pDb);
testOomAssertRc(pOom, rc);
lsm_close(pDb);
}
/*
** Test the results of OOM conditions in lsm_open().
*/
static void simple_oom_2(OomTest *pOom){
int rc;
lsm_db *pDb;
rc = lsm_new(tdb_lsm_env(), &pDb);
if( rc==LSM_OK ){
rc = lsm_open(pDb, "testdb.lsm");
}
testOomAssertRc(pOom, rc);
lsm_close(pDb);
}
/*
** Test the results of OOM conditions in simple fetch operations.
*/
static void simple_oom_3(OomTest *pOom){
int rc = LSM_OK;
lsm_db *pDb;
testOomOpen(pOom, LSMTEST6_TESTDB, &pDb, &rc);
testOomFetchStr(pOom, pDb, "four", "sixteen", &rc);
testOomFetchStr(pOom, pDb, "seven", "fourtynine", &rc);
testOomFetchStr(pOom, pDb, "one", "one", &rc);
testOomFetchStr(pOom, pDb, "eight", "sixtyfour", &rc);
lsm_close(pDb);
}
/*
** Test the results of OOM conditions in simple write operations.
*/
static void simple_oom_4(OomTest *pOom){
int rc = LSM_OK;
lsm_db *pDb;
testDeleteLsmdb(LSMTEST6_TESTDB);
testOomOpen(pOom, LSMTEST6_TESTDB, &pDb, &rc);
testOomWriteStr(pOom, pDb, "123", "onetwothree", &rc);
testOomWriteStr(pOom, pDb, "456", "fourfivesix", &rc);
testOomWriteStr(pOom, pDb, "789", "seveneightnine", &rc);
testOomWriteStr(pOom, pDb, "123", "teneleventwelve", &rc);
testOomWriteStr(pOom, pDb, "456", "fourteenfifteensixteen", &rc);
lsm_close(pDb);
}
static void simple_oom_5(OomTest *pOom){
Datasource *pData = getDatasource();
int rc = LSM_OK;
lsm_db *pDb;
testRestoreDb(LSMTEST6_TESTDB, "log");
testOomOpen(pOom, LSMTEST6_TESTDB, &pDb, &rc);
testOomFetchData(pOom, pDb, pData, 3333, &rc);
testOomFetchData(pOom, pDb, pData, 0, &rc);
testOomFetchData(pOom, pDb, pData, 4999, &rc);
lsm_close(pDb);
testDatasourceFree(pData);
}
static void simple_oom_6(OomTest *pOom){
Datasource *pData = getDatasource();
int rc = LSM_OK;
lsm_db *pDb;
testRestoreDb(LSMTEST6_TESTDB, "log");
testOomOpen(pOom, LSMTEST6_TESTDB, &pDb, &rc);
testOomWriteData(pOom, pDb, pData, 5000, &rc);
testOomWriteData(pOom, pDb, pData, 5001, &rc);
testOomWriteData(pOom, pDb, pData, 5002, &rc);
testOomFetchData(pOom, pDb, pData, 5001, &rc);
testOomFetchData(pOom, pDb, pData, 1234, &rc);
lsm_close(pDb);
testDatasourceFree(pData);
}
static void simple_oom_7(OomTest *pOom){
Datasource *pData = getDatasource();
int rc = LSM_OK;
lsm_db *pDb;
testRestoreDb(LSMTEST6_TESTDB, "log");
testOomOpen(pOom, LSMTEST6_TESTDB, &pDb, &rc);
testOomScan(pOom, pDb, 0, "abc", 3, 20, &rc);
lsm_close(pDb);
testDatasourceFree(pData);
}
static void simple_oom_8(OomTest *pOom){
Datasource *pData = getDatasource();
int rc = LSM_OK;
lsm_db *pDb;
testRestoreDb(LSMTEST6_TESTDB, "log");
testOomOpen(pOom, LSMTEST6_TESTDB, &pDb, &rc);
testOomScan(pOom, pDb, 1, "xyz", 3, 20, &rc);
lsm_close(pDb);
testDatasourceFree(pData);
}
/*
** This test case has two clients connected to a database. The first client
** hits an OOM while writing to the database. Check that the second
** connection is still able to query the db following the OOM.
*/
static void simple_oom2_1(OomTest *pOom){
const int nRecord = 100; /* Number of records initially in db */
const int nIns = 10; /* Number of records inserted with OOM */
Datasource *pData = getDatasource();
int rc = LSM_OK;
lsm_db *pDb1;
lsm_db *pDb2;
int i;
testDeleteLsmdb(LSMTEST6_TESTDB);
/* Open the two connections. Initialize the in-memory tree so that it
** contains 100 records. Do all this with OOM injection disabled. */
testOomEnable(pOom, 0);
testOomOpen(pOom, LSMTEST6_TESTDB, &pDb1, &rc);
testOomOpen(pOom, LSMTEST6_TESTDB, &pDb2, &rc);
for(i=0; i<nRecord; i++){
testOomWriteData(pOom, pDb1, pData, i, &rc);
}
testOomEnable(pOom, 1);
assert( rc==0 );
/* Insert 10 more records using pDb1. Stop when an OOM is encountered. */
for(i=nRecord; i<nRecord+nIns; i++){
testOomWriteData(pOom, pDb1, pData, i, &rc);
if( rc ) break;
}
testOomAssertRc(pOom, rc);
/* Switch off OOM injection. Write a few rows using pDb2. Then check
** that the database may be successfully queried. */
testOomEnable(pOom, 0);
rc = 0;
for(; i<nRecord+nIns && rc==0; i++){
testOomWriteData(pOom, pDb2, pData, i, &rc);
}
for(i=0; i<nRecord+nIns; i++) testOomFetchData(pOom, pDb2, pData, i, &rc);
testOomEnable(pOom, 1);
lsm_close(pDb1);
lsm_close(pDb2);
testDatasourceFree(pData);
}
static void do_test_oom1(const char *zPattern, int *pRc){
struct SimpleOom {
const char *zName;
void (*xSetup)(void);
void (*xFunc)(OomTest *);
} aSimple[] = {
{ "oom1.lsm.1", setup_delete_db, simple_oom_1 },
{ "oom1.lsm.2", setup_delete_db, simple_oom_2 },
{ "oom1.lsm.3", setup_populate_db, simple_oom_3 },
{ "oom1.lsm.4", setup_delete_db, simple_oom_4 },
{ "oom1.lsm.5", setup_populate_db2, simple_oom_5 },
{ "oom1.lsm.6", setup_populate_db2, simple_oom_6 },
{ "oom1.lsm.7", setup_populate_db2, simple_oom_7 },
{ "oom1.lsm.8", setup_populate_db2, simple_oom_8 },
{ "oom2.lsm.1", setup_delete_db, simple_oom2_1 },
};
int i;
for(i=0; i<ArraySize(aSimple); i++){
if( *pRc==0 && testCaseBegin(pRc, zPattern, "%s", aSimple[i].zName) ){
OomTest t;
if( aSimple[i].xSetup ){
aSimple[i].xSetup();
}
for(testOomStart(&t); testOomContinue(&t); testOomNext(&t)){
aSimple[i].xFunc(&t);
}
printf("(%d injections).", t.iNext-2);
testCaseFinish( (*pRc = testOomFinish(&t)) );
testMallocOom(tdb_lsm_env(), 0, 0, 0, 0);
}
}
}
void test_oom(
const char *zPattern, /* Run test cases that match this pattern */
int *pRc /* IN/OUT: Error code */
){
do_test_oom1(zPattern, pRc);
}
-206
View File
@@ -1,206 +0,0 @@
#include "lsmtest.h"
/*
** Test that the rules for when lsm_csr_next() and lsm_csr_prev() are
** enforced. Specifically:
**
** * Both functions always return LSM_MISUSE if the cursor is at EOF
** when they are called.
**
** * lsm_csr_next() may only be used after lsm_csr_seek(LSM_SEEK_GE) or
** lsm_csr_first().
**
** * lsm_csr_prev() may only be used after lsm_csr_seek(LSM_SEEK_LE) or
** lsm_csr_last().
*/
static void do_test_api1_lsm(lsm_db *pDb, int *pRc){
int ret;
lsm_cursor *pCsr;
lsm_cursor *pCsr2;
int nKey;
const void *pKey;
ret = lsm_csr_open(pDb, &pCsr);
testCompareInt(LSM_OK, ret, pRc);
ret = lsm_csr_next(pCsr);
testCompareInt(LSM_MISUSE, ret, pRc);
ret = lsm_csr_prev(pCsr);
testCompareInt(LSM_MISUSE, ret, pRc);
ret = lsm_csr_seek(pCsr, "jjj", 3, LSM_SEEK_GE);
testCompareInt(LSM_OK, ret, pRc);
ret = lsm_csr_next(pCsr);
testCompareInt(LSM_OK, ret, pRc);
ret = lsm_csr_prev(pCsr);
testCompareInt(LSM_MISUSE, ret, pRc);
ret = lsm_csr_seek(pCsr, "jjj", 3, LSM_SEEK_LE);
testCompareInt(LSM_OK, ret, pRc);
ret = lsm_csr_next(pCsr);
testCompareInt(LSM_MISUSE, ret, pRc);
ret = lsm_csr_prev(pCsr);
testCompareInt(LSM_OK, ret, pRc);
ret = lsm_csr_seek(pCsr, "jjj", 3, LSM_SEEK_LEFAST);
testCompareInt(LSM_OK, ret, pRc);
ret = lsm_csr_next(pCsr);
testCompareInt(LSM_MISUSE, ret, pRc);
ret = lsm_csr_prev(pCsr);
testCompareInt(LSM_MISUSE, ret, pRc);
ret = lsm_csr_key(pCsr, &pKey, &nKey);
testCompareInt(LSM_OK, ret, pRc);
ret = lsm_csr_open(pDb, &pCsr2);
testCompareInt(LSM_OK, ret, pRc);
ret = lsm_csr_seek(pCsr2, pKey, nKey, LSM_SEEK_EQ);
testCompareInt(LSM_OK, ret, pRc);
testCompareInt(1, lsm_csr_valid(pCsr2), pRc);
ret = lsm_csr_next(pCsr2);
testCompareInt(LSM_MISUSE, ret, pRc);
ret = lsm_csr_prev(pCsr2);
testCompareInt(LSM_MISUSE, ret, pRc);
lsm_csr_close(pCsr2);
ret = lsm_csr_first(pCsr);
testCompareInt(LSM_OK, ret, pRc);
ret = lsm_csr_next(pCsr);
testCompareInt(LSM_OK, ret, pRc);
ret = lsm_csr_prev(pCsr);
testCompareInt(LSM_MISUSE, ret, pRc);
ret = lsm_csr_last(pCsr);
testCompareInt(LSM_OK, ret, pRc);
ret = lsm_csr_prev(pCsr);
testCompareInt(LSM_OK, ret, pRc);
ret = lsm_csr_next(pCsr);
testCompareInt(LSM_MISUSE, ret, pRc);
ret = lsm_csr_first(pCsr);
while( lsm_csr_valid(pCsr) ){
ret = lsm_csr_next(pCsr);
testCompareInt(LSM_OK, ret, pRc);
}
ret = lsm_csr_next(pCsr);
testCompareInt(LSM_OK, ret, pRc);
ret = lsm_csr_prev(pCsr);
testCompareInt(LSM_MISUSE, ret, pRc);
ret = lsm_csr_last(pCsr);
while( lsm_csr_valid(pCsr) ){
ret = lsm_csr_prev(pCsr);
testCompareInt(LSM_OK, ret, pRc);
}
ret = lsm_csr_prev(pCsr);
testCompareInt(LSM_OK, ret, pRc);
ret = lsm_csr_next(pCsr);
testCompareInt(LSM_MISUSE, ret, pRc);
lsm_csr_close(pCsr);
}
static void do_test_api1(const char *zPattern, int *pRc){
if( testCaseBegin(pRc, zPattern, "api1.lsm") ){
const DatasourceDefn defn = { TEST_DATASOURCE_RANDOM, 10, 15, 200, 250 };
Datasource *pData;
TestDb *pDb;
int rc = 0;
pDb = testOpen("lsm_lomem", 1, &rc);
pData = testDatasourceNew(&defn);
testWriteDatasourceRange(pDb, pData, 0, 1000, pRc);
do_test_api1_lsm(tdb_lsm(pDb), pRc);
testDatasourceFree(pData);
testClose(&pDb);
testCaseFinish(*pRc);
}
}
static lsm_db *newLsmConnection(
const char *zDb,
int nPgsz,
int nBlksz,
int *pRc
){
lsm_db *db = 0;
if( *pRc==0 ){
int n1 = nPgsz;
int n2 = nBlksz;
*pRc = lsm_new(tdb_lsm_env(), &db);
if( *pRc==0 ){
if( n1 ) lsm_config(db, LSM_CONFIG_PAGE_SIZE, &n1);
if( n2 ) lsm_config(db, LSM_CONFIG_BLOCK_SIZE, &n2);
*pRc = lsm_open(db, "testdb.lsm");
}
}
return db;
}
static void testPagesize(lsm_db *db, int nPgsz, int nBlksz, int *pRc){
if( *pRc==0 ){
int n1 = 0;
int n2 = 0;
lsm_config(db, LSM_CONFIG_PAGE_SIZE, &n1);
lsm_config(db, LSM_CONFIG_BLOCK_SIZE, &n2);
testCompareInt(n1, nPgsz, pRc);
testCompareInt(n2, nBlksz, pRc);
}
}
/*
** Test case "api2" tests that the default page and block sizes of a
** database may only be modified before lsm_open() is called. And that
** after lsm_open() is called lsm_config() may be used to read the
** actual page and block size of the db.
*/
static void do_test_api2(const char *zPattern, int *pRc){
if( *pRc==0 && testCaseBegin(pRc, zPattern, "api2.lsm") ){
lsm_db *db1 = 0;
lsm_db *db2 = 0;
testDeleteLsmdb("testdb.lsm");
db1 = newLsmConnection("testdb.lsm", 0, 0, pRc);
testPagesize(db1, 4096, 1024, pRc);
db2 = newLsmConnection("testdb.lsm", 1024, 64*1024, pRc);
testPagesize(db2, 4096, 1024, pRc);
lsm_close(db1);
lsm_close(db2);
testDeleteLsmdb("testdb.lsm");
db1 = newLsmConnection("testdb.lsm", 1024, 64*1024, pRc);
testPagesize(db1, 1024, 64*1024, pRc);
db2 = newLsmConnection("testdb.lsm", 0, 0, pRc);
testPagesize(db2, 1024, 64*1024, pRc);
lsm_close(db1);
lsm_close(db2);
testDeleteLsmdb("testdb.lsm");
db1 = newLsmConnection("testdb.lsm", 8192, 2*1024, pRc);
testPagesize(db1, 8192, 2*1024, pRc);
db2 = newLsmConnection("testdb.lsm", 1024, 64*1024, pRc);
testPagesize(db2, 8192, 2*1024, pRc);
lsm_close(db1);
lsm_close(db2);
testCaseFinish(*pRc);
}
}
void test_api(
const char *zPattern, /* Run test cases that match this pattern */
int *pRc /* IN/OUT: Error code */
){
do_test_api1(zPattern, pRc);
do_test_api2(zPattern, pRc);
}
-324
View File
@@ -1,324 +0,0 @@
/*
** This file contains test cases to verify that "live-recovery" following
** a mid-transaction failure of a writer process.
*/
/*
** This test file includes lsmInt.h to get access to the definition of the
** ShmHeader structure. This is required to cause strategic damage to the
** shared memory header as part of recovery testing.
*/
#include "lsmInt.h"
#include "lsmtest.h"
typedef struct SetupStep SetupStep;
struct SetupStep {
int bFlush; /* Flush to disk and checkpoint */
int iInsStart; /* First key-value from ds to insert */
int nIns; /* Number of rows to insert */
int iDelStart; /* First key from ds to delete */
int nDel; /* Number of rows to delete */
};
static void doSetupStep(
TestDb *pDb,
Datasource *pData,
const SetupStep *pStep,
int *pRc
){
testWriteDatasourceRange(pDb, pData, pStep->iInsStart, pStep->nIns, pRc);
testDeleteDatasourceRange(pDb, pData, pStep->iDelStart, pStep->nDel, pRc);
if( *pRc==0 ){
int nSave = -1;
int nBuf = 64;
lsm_db *db = tdb_lsm(pDb);
lsm_config(db, LSM_CONFIG_AUTOFLUSH, &nSave);
lsm_config(db, LSM_CONFIG_AUTOFLUSH, &nBuf);
lsm_begin(db, 1);
lsm_commit(db, 0);
lsm_config(db, LSM_CONFIG_AUTOFLUSH, &nSave);
*pRc = lsm_work(db, 0, 0, 0);
if( *pRc==0 ){
*pRc = lsm_checkpoint(db, 0);
}
}
}
static void doSetupStepArray(
TestDb *pDb,
Datasource *pData,
const SetupStep *aStep,
int nStep
){
int i;
for(i=0; i<nStep; i++){
int rc = 0;
doSetupStep(pDb, pData, &aStep[i], &rc);
assert( rc==0 );
}
}
static void setupDatabase1(TestDb *pDb, Datasource **ppData){
const SetupStep aStep[] = {
{ 0, 1, 2000, 0, 0 },
{ 1, 0, 0, 0, 0 },
{ 0, 10001, 1000, 0, 0 },
};
const DatasourceDefn defn = {TEST_DATASOURCE_RANDOM, 12, 16, 100, 500};
Datasource *pData;
pData = testDatasourceNew(&defn);
doSetupStepArray(pDb, pData, aStep, ArraySize(aStep));
if( ppData ){
*ppData = pData;
}else{
testDatasourceFree(pData);
}
}
#include <stdio.h>
void testReadFile(const char *zFile, int iOff, void *pOut, int nByte, int *pRc){
if( *pRc==0 ){
FILE *fd;
fd = fopen(zFile, "rb");
if( fd==0 ){
*pRc = 1;
}else{
if( 0!=fseek(fd, iOff, SEEK_SET) ){
*pRc = 1;
}else{
assert( nByte>=0 );
if( (size_t)nByte!=fread(pOut, 1, nByte, fd) ){
*pRc = 1;
}
}
fclose(fd);
}
}
}
void testWriteFile(
const char *zFile,
int iOff,
void *pOut,
int nByte,
int *pRc
){
if( *pRc==0 ){
FILE *fd;
fd = fopen(zFile, "r+b");
if( fd==0 ){
*pRc = 1;
}else{
if( 0!=fseek(fd, iOff, SEEK_SET) ){
*pRc = 1;
}else{
assert( nByte>=0 );
if( (size_t)nByte!=fwrite(pOut, 1, nByte, fd) ){
*pRc = 1;
}
}
fclose(fd);
}
}
}
static ShmHeader *getShmHeader(const char *zDb){
int rc = 0;
char *zShm = testMallocPrintf("%s-shm", zDb);
ShmHeader *pHdr;
pHdr = testMalloc(sizeof(ShmHeader));
testReadFile(zShm, 0, (void *)pHdr, sizeof(ShmHeader), &rc);
assert( rc==0 );
return pHdr;
}
/*
** This function makes a copy of the three files associated with LSM
** database zDb (i.e. if zDb is "test.db", it makes copies of "test.db",
** "test.db-log" and "test.db-shm").
**
** It then opens a new database connection to the copy with the xLock() call
** instrumented so that it appears that some other process already connected
** to the db (holding a shared lock on DMS2). This prevents recovery from
** running. Then:
**
** 1) Check that the checksum of the database is zCksum.
** 2) Write a few keys to the database. Then delete the same keys.
** 3) Check that the checksum is zCksum.
** 4) Flush the db to disk and run a checkpoint.
** 5) Check once more that the checksum is still zCksum.
*/
static void doLiveRecovery(const char *zDb, const char *zCksum, int *pRc){
if( *pRc==LSM_OK ){
const DatasourceDefn defn = {TEST_DATASOURCE_RANDOM, 20, 25, 100, 500};
Datasource *pData;
const char *zCopy = "testcopy.lsm";
char zCksum2[TEST_CKSUM_BYTES];
TestDb *pDb = 0;
int rc;
pData = testDatasourceNew(&defn);
testCopyLsmdb(zDb, zCopy);
rc = tdb_lsm_open("test_no_recovery=1", zCopy, 0, &pDb);
if( rc==0 ){
ShmHeader *pHdr;
lsm_db *db;
testCksumDatabase(pDb, zCksum2);
testCompareStr(zCksum, zCksum2, &rc);
testWriteDatasourceRange(pDb, pData, 1, 10, &rc);
testDeleteDatasourceRange(pDb, pData, 1, 10, &rc);
/* Test that the two tree-headers are now consistent. */
pHdr = getShmHeader(zCopy);
if( rc==0 && memcmp(&pHdr->hdr1, &pHdr->hdr2, sizeof(pHdr->hdr1)) ){
rc = 1;
}
testFree(pHdr);
if( rc==0 ){
int nBuf = 64;
db = tdb_lsm(pDb);
lsm_config(db, LSM_CONFIG_AUTOFLUSH, &nBuf);
lsm_begin(db, 1);
lsm_commit(db, 0);
rc = lsm_work(db, 0, 0, 0);
}
testCksumDatabase(pDb, zCksum2);
testCompareStr(zCksum, zCksum2, &rc);
}
testDatasourceFree(pData);
testClose(&pDb);
testDeleteLsmdb(zCopy);
*pRc = rc;
}
}
static void doWriterCrash1(int *pRc){
const int nWrite = 2000;
const int nStep = 10;
const int iWriteStart = 20000;
int rc = 0;
TestDb *pDb = 0;
Datasource *pData = 0;
rc = tdb_lsm_open("autowork=0", "testdb.lsm", 1, &pDb);
if( rc==0 ){
int iDot = 0;
char zCksum[TEST_CKSUM_BYTES];
int i;
setupDatabase1(pDb, &pData);
testCksumDatabase(pDb, zCksum);
testBegin(pDb, 2, &rc);
for(i=0; rc==0 && i<nWrite; i+=nStep){
testCaseProgress(i, nWrite, testCaseNDot(), &iDot);
testWriteDatasourceRange(pDb, pData, iWriteStart+i, nStep, &rc);
doLiveRecovery("testdb.lsm", zCksum, &rc);
}
}
testCommit(pDb, 0, &rc);
testClose(&pDb);
testDatasourceFree(pData);
*pRc = rc;
}
/*
** This test case verifies that inconsistent tree-headers in shared-memory
** are resolved correctly.
*/
static void doWriterCrash2(int *pRc){
int rc = 0;
TestDb *pDb = 0;
Datasource *pData = 0;
rc = tdb_lsm_open("autowork=0", "testdb.lsm", 1, &pDb);
if( rc==0 ){
ShmHeader *pHdr1;
ShmHeader *pHdr2;
char zCksum1[TEST_CKSUM_BYTES];
char zCksum2[TEST_CKSUM_BYTES];
pHdr1 = testMalloc(sizeof(ShmHeader));
pHdr2 = testMalloc(sizeof(ShmHeader));
setupDatabase1(pDb, &pData);
/* Grab a copy of the shared-memory header. And the db checksum */
testReadFile("testdb.lsm-shm", 0, (void *)pHdr1, sizeof(ShmHeader), &rc);
testCksumDatabase(pDb, zCksum1);
/* Modify the database */
testBegin(pDb, 2, &rc);
testWriteDatasourceRange(pDb, pData, 30000, 200, &rc);
testCommit(pDb, 0, &rc);
/* Grab a second copy of the shared-memory header. And the db checksum */
testReadFile("testdb.lsm-shm", 0, (void *)pHdr2, sizeof(ShmHeader), &rc);
testCksumDatabase(pDb, zCksum2);
doLiveRecovery("testdb.lsm", zCksum2, &rc);
/* If both tree-headers are valid, tree-header-1 is used. */
memcpy(&pHdr2->hdr1, &pHdr1->hdr1, sizeof(pHdr1->hdr1));
pHdr2->bWriter = 1;
testWriteFile("testdb.lsm-shm", 0, (void *)pHdr2, sizeof(ShmHeader), &rc);
doLiveRecovery("testdb.lsm", zCksum1, &rc);
/* If both tree-headers are valid, tree-header-1 is used. */
memcpy(&pHdr2->hdr1, &pHdr2->hdr2, sizeof(pHdr1->hdr1));
memcpy(&pHdr2->hdr2, &pHdr1->hdr1, sizeof(pHdr1->hdr1));
pHdr2->bWriter = 1;
testWriteFile("testdb.lsm-shm", 0, (void *)pHdr2, sizeof(ShmHeader), &rc);
doLiveRecovery("testdb.lsm", zCksum2, &rc);
/* If tree-header 1 is invalid, tree-header-2 is used */
memcpy(&pHdr2->hdr2, &pHdr2->hdr1, sizeof(pHdr1->hdr1));
pHdr2->hdr1.aCksum[0] = 5;
pHdr2->hdr1.aCksum[0] = 6;
pHdr2->bWriter = 1;
testWriteFile("testdb.lsm-shm", 0, (void *)pHdr2, sizeof(ShmHeader), &rc);
doLiveRecovery("testdb.lsm", zCksum2, &rc);
/* If tree-header 2 is invalid, tree-header-1 is used */
memcpy(&pHdr2->hdr1, &pHdr2->hdr2, sizeof(pHdr1->hdr1));
pHdr2->hdr2.aCksum[0] = 5;
pHdr2->hdr2.aCksum[0] = 6;
pHdr2->bWriter = 1;
testWriteFile("testdb.lsm-shm", 0, (void *)pHdr2, sizeof(ShmHeader), &rc);
doLiveRecovery("testdb.lsm", zCksum2, &rc);
testFree(pHdr1);
testFree(pHdr2);
testClose(&pDb);
}
*pRc = rc;
}
void do_writer_crash_test(const char *zPattern, int *pRc){
struct Test {
const char *zName;
void (*xFunc)(int *);
} aTest[] = {
{ "writercrash1.lsm", doWriterCrash1 },
{ "writercrash2.lsm", doWriterCrash2 },
};
int i;
for(i=0; i<ArraySize(aTest); i++){
struct Test *p = &aTest[i];
if( testCaseBegin(pRc, zPattern, p->zName) ){
p->xFunc(pRc);
testCaseFinish(*pRc);
}
}
}
-140
View File
@@ -1,140 +0,0 @@
#include "lsmtest.h"
#define DATA_SEQUENTIAL TEST_DATASOURCE_SEQUENCE
#define DATA_RANDOM TEST_DATASOURCE_RANDOM
typedef struct Datatest4 Datatest4;
/*
** Test overview:
**
** 1. Insert (Datatest4.nRec) records into a database.
**
** 2. Repeat (Datatest4.nRepeat) times:
**
** 2a. Delete 2/3 of the records in the database.
**
** 2b. Run lsm_work(nMerge=1).
**
** 2c. Insert as many records as were deleted in 2a.
**
** 2d. Check database content is as expected.
**
** 2e. If (Datatest4.bReopen) is true, close and reopen the database.
*/
struct Datatest4 {
/* Datasource definition */
DatasourceDefn defn;
int nRec;
int nRepeat;
int bReopen;
};
static void doDataTest4(
const char *zSystem, /* Database system to test */
Datatest4 *p, /* Structure containing test parameters */
int *pRc /* OUT: Error code */
){
lsm_db *db = 0;
TestDb *pDb;
TestDb *pControl;
Datasource *pData;
int i;
int rc = 0;
int iDot = 0;
int bMultiThreaded = 0; /* True for MT LSM database */
int nRecOn3 = (p->nRec / 3);
int iData = 0;
/* Start the test case, open a database and allocate the datasource. */
rc = testControlDb(&pControl);
pDb = testOpen(zSystem, 1, &rc);
pData = testDatasourceNew(&p->defn);
if( rc==0 ){
db = tdb_lsm(pDb);
bMultiThreaded = tdb_lsm_multithread(pDb);
}
testWriteDatasourceRange(pControl, pData, iData, nRecOn3*3, &rc);
testWriteDatasourceRange(pDb, pData, iData, nRecOn3*3, &rc);
for(i=0; rc==0 && i<p->nRepeat; i++){
testDeleteDatasourceRange(pControl, pData, iData, nRecOn3*2, &rc);
testDeleteDatasourceRange(pDb, pData, iData, nRecOn3*2, &rc);
if( db ){
int nDone;
#if 0
fprintf(stderr, "lsm_work() start...\n"); fflush(stderr);
#endif
do {
nDone = 0;
rc = lsm_work(db, 1, (1<<30), &nDone);
}while( rc==0 && nDone>0 );
if( bMultiThreaded && rc==LSM_BUSY ) rc = LSM_OK;
#if 0
fprintf(stderr, "lsm_work() done...\n"); fflush(stderr);
#endif
}
if( i+1<p->nRepeat ){
iData += (nRecOn3*2);
testWriteDatasourceRange(pControl, pData, iData+nRecOn3, nRecOn3*2, &rc);
testWriteDatasourceRange(pDb, pData, iData+nRecOn3, nRecOn3*2, &rc);
testCompareDb(pData, nRecOn3*3, iData, pControl, pDb, &rc);
/* If Datatest4.bReopen is true, close and reopen the database */
if( p->bReopen ){
testReopen(&pDb, &rc);
if( rc==0 ) db = tdb_lsm(pDb);
}
}
/* Update the progress dots... */
testCaseProgress(i, p->nRepeat, testCaseNDot(), &iDot);
}
testClose(&pDb);
testClose(&pControl);
testDatasourceFree(pData);
testCaseFinish(rc);
*pRc = rc;
}
static char *getName4(const char *zSystem, Datatest4 *pTest){
char *zRet;
char *zData;
zData = testDatasourceName(&pTest->defn);
zRet = testMallocPrintf("data4.%s.%s.%d.%d.%d",
zSystem, zData, pTest->nRec, pTest->nRepeat, pTest->bReopen
);
testFree(zData);
return zRet;
}
void test_data_4(
const char *zSystem, /* Database system name */
const char *zPattern, /* Run test cases that match this pattern */
int *pRc /* IN/OUT: Error code */
){
Datatest4 aTest[] = {
/* defn, nRec, nRepeat, bReopen */
{ {DATA_RANDOM, 20,25, 500,600}, 10000, 10, 0 },
{ {DATA_RANDOM, 20,25, 500,600}, 10000, 10, 1 },
};
int i;
for(i=0; *pRc==LSM_OK && i<ArraySize(aTest); i++){
char *zName = getName4(zSystem, &aTest[i]);
if( testCaseBegin(pRc, zPattern, "%s", zName) ){
doDataTest4(zSystem, &aTest[i], pRc);
}
testFree(zName);
}
}
-71
View File
@@ -1,71 +0,0 @@
#include "lsmtest.h"
#include "bt.h"
int do_bt(int nArg, char **azArg){
struct Option {
const char *zName;
int bPgno;
int eOpt;
} aOpt [] = {
{ "dbhdr", 0, BT_INFO_HDRDUMP },
{ "filename", 0, BT_INFO_FILENAME },
{ "block_freelist", 0, BT_INFO_BLOCK_FREELIST },
{ "page_freelist", 0, BT_INFO_PAGE_FREELIST },
{ "filename", 0, BT_INFO_FILENAME },
{ "page", 1, BT_INFO_PAGEDUMP },
{ "page_ascii", 1, BT_INFO_PAGEDUMP_ASCII },
{ "leaks", 0, BT_INFO_PAGE_LEAKS },
{ 0, 0 }
};
int iOpt;
int rc;
bt_info buf;
char *zOpt;
char *zFile;
bt_db *db = 0;
if( nArg<2 ){
testPrintUsage("FILENAME OPTION ...");
return -1;
}
zFile = azArg[0];
zOpt = azArg[1];
rc = testArgSelect(aOpt, "option", zOpt, &iOpt);
if( rc!=0 ) return rc;
if( nArg!=2+aOpt[iOpt].bPgno ){
testPrintFUsage("FILENAME %s %s", zOpt, aOpt[iOpt].bPgno ? "PGNO" : "");
return -4;
}
rc = sqlite4BtNew(sqlite4_env_default(), 0, &db);
if( rc!=SQLITE4_OK ){
testPrintError("sqlite4BtNew() failed: %d", rc);
return -2;
}
rc = sqlite4BtOpen(db, zFile);
if( rc!=SQLITE4_OK ){
testPrintError("sqlite4BtOpen() failed: %d", rc);
return -3;
}
buf.eType = aOpt[iOpt].eOpt;
buf.pgno = 0;
sqlite4_buffer_init(&buf.output, 0);
if( aOpt[iOpt].bPgno ){
buf.pgno = (u32)atoi(azArg[2]);
}
rc = sqlite4BtControl(db, BT_CONTROL_INFO, &buf);
if( rc!=SQLITE4_OK ){
testPrintError("sqlite4BtControl() failed: %d\n", rc);
return -4;
}
printf("%s\n", (char*)buf.output.p);
sqlite4_buffer_clear(&buf.output);
return 0;
}
-96
View File
@@ -1,96 +0,0 @@
#include "lsmtest.h"
struct Datasource {
int eType;
int nMinKey;
int nMaxKey;
int nMinVal;
int nMaxVal;
char *aKey;
char *aVal;
};
void testDatasourceEntry(
Datasource *p,
int iData,
void **ppKey, int *pnKey,
void **ppVal, int *pnVal
){
assert( (ppKey==0)==(pnKey==0) );
assert( (ppVal==0)==(pnVal==0) );
if( ppKey ){
int nKey = 0;
switch( p->eType ){
case TEST_DATASOURCE_RANDOM: {
int nRange = (1 + p->nMaxKey - p->nMinKey);
nKey = (int)( testPrngValue((u32)iData) % nRange ) + p->nMinKey;
testPrngString((u32)iData, p->aKey, nKey);
break;
}
case TEST_DATASOURCE_SEQUENCE:
nKey = sprintf(p->aKey, "%012d", iData);
break;
}
*ppKey = p->aKey;
*pnKey = nKey;
}
if( ppVal ){
u32 nVal = testPrngValue((u32)iData)%(1+p->nMaxVal-p->nMinVal)+p->nMinVal;
testPrngString((u32)~iData, p->aVal, (int)nVal);
*ppVal = p->aVal;
*pnVal = (int)nVal;
}
}
void testDatasourceFree(Datasource *p){
testFree(p);
}
/*
** Return a pointer to a nul-terminated string that corresponds to the
** contents of the datasource-definition passed as the first argument.
** The caller should eventually free the returned pointer using testFree().
*/
char *testDatasourceName(const DatasourceDefn *p){
char *zRet;
zRet = testMallocPrintf("%s.(%d-%d).(%d-%d)",
(p->eType==TEST_DATASOURCE_SEQUENCE ? "seq" : "rnd"),
p->nMinKey, p->nMaxKey,
p->nMinVal, p->nMaxVal
);
return zRet;
}
Datasource *testDatasourceNew(const DatasourceDefn *pDefn){
Datasource *p;
int nMinKey;
int nMaxKey;
int nMinVal;
int nMaxVal;
if( pDefn->eType==TEST_DATASOURCE_SEQUENCE ){
nMinKey = 128;
nMaxKey = 128;
}else{
nMinKey = MAX(0, pDefn->nMinKey);
nMaxKey = MAX(nMinKey, pDefn->nMaxKey);
}
nMinVal = MAX(0, pDefn->nMinVal);
nMaxVal = MAX(nMinVal, pDefn->nMaxVal);
p = (Datasource *)testMalloc(sizeof(Datasource) + nMaxKey + nMaxVal + 1);
p->eType = pDefn->eType;
p->nMinKey = nMinKey;
p->nMinVal = nMinVal;
p->nMaxKey = nMaxKey;
p->nMaxVal = nMaxVal;
p->aKey = (char *)&p[1];
p->aVal = &p->aKey[nMaxKey];
return p;
};
-177
View File
@@ -1,177 +0,0 @@
#include "lsmtest.h"
int do_work(int nArg, char **azArg){
struct Option {
const char *zName;
} aOpt [] = {
{ "-nmerge" },
{ "-nkb" },
{ 0 }
};
lsm_db *pDb;
int rc;
int i;
const char *zDb;
int nMerge = 1;
int nKB = (1<<30);
if( nArg==0 ) goto usage;
zDb = azArg[nArg-1];
for(i=0; i<(nArg-1); i++){
int iSel;
rc = testArgSelect(aOpt, "option", azArg[i], &iSel);
if( rc ) return rc;
switch( iSel ){
case 0:
i++;
if( i==(nArg-1) ) goto usage;
nMerge = atoi(azArg[i]);
break;
case 1:
i++;
if( i==(nArg-1) ) goto usage;
nKB = atoi(azArg[i]);
break;
}
}
rc = lsm_new(0, &pDb);
if( rc!=LSM_OK ){
testPrintError("lsm_open(): rc=%d\n", rc);
}else{
rc = lsm_open(pDb, zDb);
if( rc!=LSM_OK ){
testPrintError("lsm_open(): rc=%d\n", rc);
}else{
int n = -1;
lsm_config(pDb, LSM_CONFIG_BLOCK_SIZE, &n);
n = n*2;
lsm_config(pDb, LSM_CONFIG_AUTOCHECKPOINT, &n);
rc = lsm_work(pDb, nMerge, nKB, 0);
if( rc!=LSM_OK ){
testPrintError("lsm_work(): rc=%d\n", rc);
}
}
}
if( rc==LSM_OK ){
rc = lsm_checkpoint(pDb, 0);
}
lsm_close(pDb);
return rc;
usage:
testPrintUsage("?-optimize? ?-n N? DATABASE");
return -1;
}
/*
** lsmtest show ?-config LSM-CONFIG? DATABASE ?COMMAND ?PGNO??
*/
int do_show(int nArg, char **azArg){
lsm_db *pDb;
int rc;
const char *zDb;
int eOpt = LSM_INFO_DB_STRUCTURE;
unsigned int iPg = 0;
int bConfig = 0;
const char *zConfig = "";
struct Option {
const char *zName;
int bConfig;
int eOpt;
} aOpt [] = {
{ "array", 0, LSM_INFO_ARRAY_STRUCTURE },
{ "array-pages", 0, LSM_INFO_ARRAY_PAGES },
{ "blocksize", 1, LSM_CONFIG_BLOCK_SIZE },
{ "pagesize", 1, LSM_CONFIG_PAGE_SIZE },
{ "freelist", 0, LSM_INFO_FREELIST },
{ "page-ascii", 0, LSM_INFO_PAGE_ASCII_DUMP },
{ "page-hex", 0, LSM_INFO_PAGE_HEX_DUMP },
{ 0, 0 }
};
char *z = 0;
int iDb = 0; /* Index of DATABASE in azArg[] */
/* Check if there is a "-config" option: */
if( nArg>2 && strlen(azArg[0])>1
&& memcmp(azArg[0], "-config", strlen(azArg[0]))==0
){
zConfig = azArg[1];
iDb = 2;
}
if( nArg<(iDb+1) ) goto usage;
if( nArg>(iDb+1) ){
rc = testArgSelect(aOpt, "option", azArg[iDb+1], &eOpt);
if( rc!=0 ) return rc;
bConfig = aOpt[eOpt].bConfig;
eOpt = aOpt[eOpt].eOpt;
if( (bConfig==0 && eOpt==LSM_INFO_FREELIST)
|| (bConfig==1 && eOpt==LSM_CONFIG_BLOCK_SIZE)
|| (bConfig==1 && eOpt==LSM_CONFIG_PAGE_SIZE)
){
if( nArg!=(iDb+2) ) goto usage;
}else{
if( nArg!=(iDb+3) ) goto usage;
iPg = atoi(azArg[iDb+2]);
}
}
zDb = azArg[iDb];
rc = lsm_new(0, &pDb);
tdb_lsm_configure(pDb, zConfig);
if( rc!=LSM_OK ){
testPrintError("lsm_new(): rc=%d\n", rc);
}else{
rc = lsm_open(pDb, zDb);
if( rc!=LSM_OK ){
testPrintError("lsm_open(): rc=%d\n", rc);
}
}
if( rc==LSM_OK ){
if( bConfig==0 ){
switch( eOpt ){
case LSM_INFO_DB_STRUCTURE:
case LSM_INFO_FREELIST:
rc = lsm_info(pDb, eOpt, &z);
break;
case LSM_INFO_ARRAY_STRUCTURE:
case LSM_INFO_ARRAY_PAGES:
case LSM_INFO_PAGE_ASCII_DUMP:
case LSM_INFO_PAGE_HEX_DUMP:
rc = lsm_info(pDb, eOpt, iPg, &z);
break;
default:
assert( !"no chance" );
}
if( rc==LSM_OK ){
printf("%s\n", z ? z : "");
fflush(stdout);
}
lsm_free(lsm_get_env(pDb), z);
}else{
int iRes = -1;
lsm_config(pDb, eOpt, &iRes);
printf("%d\n", iRes);
fflush(stdout);
}
}
lsm_close(pDb);
return rc;
usage:
testPrintUsage("DATABASE ?array|page-ascii|page-hex PGNO?");
return -1;
}
-248
View File
@@ -1,248 +0,0 @@
/*
** SUMMARY
**
** This file implements the 'io' subcommand of the test program. It is used
** for testing the performance of various combinations of write() and fsync()
** system calls. All operations occur on a single file, which may or may not
** exist when a test is started.
**
** A test consists of a series of commands. Each command is either a write
** or an fsync. A write is specified as "<amount>@<offset>", where <amount>
** is the amount of data written, and <offset> is the offset of the file
** to write to. An <amount> or an <offset> is specified as an integer number
** of bytes. Or, if postfixed with a "K", "M" or "G", an integer number of
** KB, MB or GB, respectively. An fsync is simply "S". All commands are
** case-insensitive.
**
** Example test program:
**
** 2M@6M 1492K@4M S 4096@4K S
**
** This program writes 2 MB of data starting at the offset 6MB offset of
** the file, followed by 1492 KB of data written at the 4MB offset of the
** file, followed by a call to fsync(), a write of 4KB of data at byte
** offset 4096, and finally another call to fsync().
**
** Commands may either be specified on the command line (one command per
** command line argument) or read from stdin. Commands read from stdin
** must be separated by white-space.
**
** COMMAND LINE INVOCATION
**
** The sub-command implemented in this file must be invoked with at least
** two arguments - the path to the file to write to and the page-size to
** use for writing. If there are more than two arguments, then each
** subsequent argument is assumed to be a test command. If there are exactly
** two arguments, the test commands are read from stdin.
**
** A write command does not result in a single call to system call write().
** Instead, the specified region is written sequentially using one or
** more calls to write(), each of which writes not more than one page of
** data. For example, if the page-size is 4KB, the command "2M@6M" results
** in 512 calls to write(), each of which writes 4KB of data.
**
** EXAMPLES
**
** Two equivalent examples:
**
** $ lsmtest io testfile.db 4KB 2M@6M 1492K@4M S 4096@4K S
** 3544K written in 129 ms
** $ echo "2M@6M 1492K@4M S 4096@4K S" | lsmtest io testfile.db 4096
** 3544K written in 127 ms
**
*/
#include "lsmtest.h"
typedef struct IoContext IoContext;
struct IoContext {
int fd;
int nWrite;
};
/*
** As isspace(3)
*/
static int safe_isspace(char c){
if( c&0x80) return 0;
return isspace(c);
}
/*
** As isdigit(3)
*/
static int safe_isdigit(char c){
if( c&0x80) return 0;
return isdigit(c);
}
static i64 getNextSize(char *zIn, char **pzOut, int *pRc){
i64 iRet = 0;
if( *pRc==0 ){
char *z = zIn;
if( !safe_isdigit(*z) ){
*pRc = 1;
return 0;
}
/* Process digits */
while( safe_isdigit(*z) ){
iRet = iRet*10 + (*z - '0');
z++;
}
/* Process suffix */
switch( *z ){
case 'k': case 'K':
iRet = iRet * 1024;
z++;
break;
case 'm': case 'M':
iRet = iRet * 1024 * 1024;
z++;
break;
case 'g': case 'G':
iRet = iRet * 1024 * 1024 * 1024;
z++;
break;
}
if( pzOut ) *pzOut = z;
}
return iRet;
}
static int doOneCmd(
IoContext *pCtx,
u8 *aData,
int pgsz,
char *zCmd,
char **pzOut
){
char c;
char *z = zCmd;
while( safe_isspace(*z) ) z++;
c = *z;
if( c==0 ){
if( pzOut ) *pzOut = z;
return 0;
}
if( c=='s' || c=='S' ){
if( pzOut ) *pzOut = &z[1];
return fdatasync(pCtx->fd);
}
if( safe_isdigit(c) ){
i64 iOff = 0;
int nByte = 0;
int rc = 0;
int nPg;
int iPg;
nByte = (int)getNextSize(z, &z, &rc);
if( rc || *z!='@' ) goto bad_command;
z++;
iOff = getNextSize(z, &z, &rc);
if( rc || (safe_isspace(*z)==0 && *z!='\0') ) goto bad_command;
if( pzOut ) *pzOut = z;
nPg = (nByte+pgsz-1) / pgsz;
lseek(pCtx->fd, (off_t)iOff, SEEK_SET);
for(iPg=0; iPg<nPg; iPg++){
write(pCtx->fd, aData, pgsz);
}
pCtx->nWrite += nByte/1024;
return 0;
}
bad_command:
testPrintError("unrecognized command: %s", zCmd);
return 1;
}
static int readStdin(char **pzOut){
int nAlloc = 128;
char *zOut = 0;
int nOut = 0;
while( !feof(stdin) ){
int nRead;
nAlloc = nAlloc*2;
zOut = realloc(zOut, nAlloc);
nRead = fread(&zOut[nOut], 1, nAlloc-nOut-1, stdin);
if( nRead==0 ) break;
nOut += nRead;
zOut[nOut] = '\0';
}
*pzOut = zOut;
return 0;
}
int do_io(int nArg, char **azArg){
IoContext ctx;
int pgsz;
char *zFile;
char *zPgsz;
int i;
int rc = 0;
char *zStdin = 0;
char *z;
u8 *aData;
memset(&ctx, 0, sizeof(IoContext));
if( nArg<2 ){
testPrintUsage("FILE PGSZ ?CMD-1 ...?");
return -1;
}
zFile = azArg[0];
zPgsz = azArg[1];
pgsz = (int)getNextSize(zPgsz, 0, &rc);
if( pgsz<=0 ){
testPrintError("Ridiculous page size: %d", pgsz);
return -1;
}
aData = malloc(pgsz);
memset(aData, 0x77, pgsz);
ctx.fd = open(zFile, O_RDWR|O_CREAT|_O_BINARY, 0644);
if( ctx.fd<0 ){
perror("open: ");
return -1;
}
if( nArg==2 ){
readStdin(&zStdin);
testTimeInit();
z = zStdin;
while( *z && rc==0 ){
rc = doOneCmd(&ctx, aData, pgsz, z, &z);
}
}else{
testTimeInit();
for(i=2; i<nArg; i++){
rc = doOneCmd(&ctx, aData, pgsz, azArg[i], 0);
}
}
printf("%dK written in %d ms\n", ctx.nWrite, testTimeGet());
free(zStdin);
close(ctx.fd);
return 0;
}
File diff suppressed because it is too large Load Diff
-409
View File
@@ -1,409 +0,0 @@
#include <stdio.h>
#include <assert.h>
#include <string.h>
#define ArraySize(x) ((int)(sizeof(x) / sizeof((x)[0])))
#define MIN(x,y) ((x)<(y) ? (x) : (y))
typedef unsigned int u32;
typedef unsigned char u8;
typedef long long int i64;
typedef unsigned long long int u64;
#if defined(__GLIBC__) && defined(LSM_DEBUG_MEM)
extern int backtrace(void**,int);
extern void backtrace_symbols_fd(void*const*,int,int);
# define TM_BACKTRACE 12
#else
# define backtrace(A,B) 1
# define backtrace_symbols_fd(A,B,C)
#endif
typedef struct TmBlockHdr TmBlockHdr;
typedef struct TmAgg TmAgg;
typedef struct TmGlobal TmGlobal;
struct TmGlobal {
/* Linked list of all currently outstanding allocations. And a table of
** all allocations, past and present, indexed by backtrace() info. */
TmBlockHdr *pFirst;
#ifdef TM_BACKTRACE
TmAgg *aHash[10000];
#endif
/* Underlying malloc/realloc/free functions */
void *(*xMalloc)(int); /* underlying malloc(3) function */
void *(*xRealloc)(void *, int); /* underlying realloc(3) function */
void (*xFree)(void *); /* underlying free(3) function */
/* Mutex to protect pFirst and aHash */
void (*xEnterMutex)(TmGlobal*); /* Call this to enter the mutex */
void (*xLeaveMutex)(TmGlobal*); /* Call this to leave mutex */
void (*xDelMutex)(TmGlobal*); /* Call this to delete mutex */
void *pMutex; /* Mutex handle */
void *(*xSaveMalloc)(void *, size_t);
void *(*xSaveRealloc)(void *, void *, size_t);
void (*xSaveFree)(void *, void *);
/* OOM injection scheduling. If nCountdown is greater than zero when a
** malloc attempt is made, it is decremented. If this means nCountdown
** transitions from 1 to 0, then the allocation fails. If bPersist is true
** when this happens, nCountdown is then incremented back to 1 (so that the
** next attempt fails too).
*/
int nCountdown;
int bPersist;
int bEnable;
void (*xHook)(void *);
void *pHookCtx;
};
struct TmBlockHdr {
TmBlockHdr *pNext;
TmBlockHdr *pPrev;
int nByte;
#ifdef TM_BACKTRACE
TmAgg *pAgg;
#endif
u32 iForeGuard;
};
#ifdef TM_BACKTRACE
struct TmAgg {
int nAlloc; /* Number of allocations at this path */
int nByte; /* Total number of bytes allocated */
int nOutAlloc; /* Number of outstanding allocations */
int nOutByte; /* Number of outstanding bytes */
void *aFrame[TM_BACKTRACE]; /* backtrace() output */
TmAgg *pNext; /* Next object in hash-table collision */
};
#endif
#define FOREGUARD 0x80F5E153
#define REARGUARD 0xE4676B53
static const u32 rearguard = REARGUARD;
#define ROUND8(x) (((x)+7)&~7)
#define BLOCK_HDR_SIZE (ROUND8( sizeof(TmBlockHdr) ))
static void lsmtest_oom_error(void){
static int nErr = 0;
nErr++;
}
static void tmEnterMutex(TmGlobal *pTm){
pTm->xEnterMutex(pTm);
}
static void tmLeaveMutex(TmGlobal *pTm){
pTm->xLeaveMutex(pTm);
}
static void *tmMalloc(TmGlobal *pTm, int nByte){
TmBlockHdr *pNew; /* New allocation header block */
u8 *pUser; /* Return value */
int nReq; /* Total number of bytes requested */
assert( sizeof(rearguard)==4 );
nReq = BLOCK_HDR_SIZE + nByte + 4;
pNew = (TmBlockHdr *)pTm->xMalloc(nReq);
memset(pNew, 0, sizeof(TmBlockHdr));
tmEnterMutex(pTm);
assert( pTm->nCountdown>=0 );
assert( pTm->bPersist==0 || pTm->bPersist==1 );
if( pTm->bEnable && pTm->nCountdown==1 ){
/* Simulate an OOM error. */
lsmtest_oom_error();
pTm->xFree(pNew);
pTm->nCountdown = pTm->bPersist;
if( pTm->xHook ) pTm->xHook(pTm->pHookCtx);
pUser = 0;
}else{
if( pTm->bEnable && pTm->nCountdown ) pTm->nCountdown--;
pNew->iForeGuard = FOREGUARD;
pNew->nByte = nByte;
pNew->pNext = pTm->pFirst;
if( pTm->pFirst ){
pTm->pFirst->pPrev = pNew;
}
pTm->pFirst = pNew;
pUser = &((u8 *)pNew)[BLOCK_HDR_SIZE];
memset(pUser, 0x56, nByte);
memcpy(&pUser[nByte], &rearguard, 4);
#ifdef TM_BACKTRACE
{
TmAgg *pAgg;
int i;
u32 iHash = 0;
void *aFrame[TM_BACKTRACE];
memset(aFrame, 0, sizeof(aFrame));
backtrace(aFrame, TM_BACKTRACE);
for(i=0; i<ArraySize(aFrame); i++){
iHash += (u64)(aFrame[i]) + (iHash<<3);
}
iHash = iHash % ArraySize(pTm->aHash);
for(pAgg=pTm->aHash[iHash]; pAgg; pAgg=pAgg->pNext){
if( memcmp(pAgg->aFrame, aFrame, sizeof(aFrame))==0 ) break;
}
if( !pAgg ){
pAgg = (TmAgg *)pTm->xMalloc(sizeof(TmAgg));
memset(pAgg, 0, sizeof(TmAgg));
memcpy(pAgg->aFrame, aFrame, sizeof(aFrame));
pAgg->pNext = pTm->aHash[iHash];
pTm->aHash[iHash] = pAgg;
}
pAgg->nAlloc++;
pAgg->nByte += nByte;
pAgg->nOutAlloc++;
pAgg->nOutByte += nByte;
pNew->pAgg = pAgg;
}
#endif
}
tmLeaveMutex(pTm);
return pUser;
}
static void tmFree(TmGlobal *pTm, void *p){
if( p ){
TmBlockHdr *pHdr;
u8 *pUser = (u8 *)p;
tmEnterMutex(pTm);
pHdr = (TmBlockHdr *)(pUser - BLOCK_HDR_SIZE);
assert( pHdr->iForeGuard==FOREGUARD );
assert( 0==memcmp(&pUser[pHdr->nByte], &rearguard, 4) );
if( pHdr->pPrev ){
assert( pHdr->pPrev->pNext==pHdr );
pHdr->pPrev->pNext = pHdr->pNext;
}else{
assert( pHdr==pTm->pFirst );
pTm->pFirst = pHdr->pNext;
}
if( pHdr->pNext ){
assert( pHdr->pNext->pPrev==pHdr );
pHdr->pNext->pPrev = pHdr->pPrev;
}
#ifdef TM_BACKTRACE
pHdr->pAgg->nOutAlloc--;
pHdr->pAgg->nOutByte -= pHdr->nByte;
#endif
tmLeaveMutex(pTm);
memset(pUser, 0x58, pHdr->nByte);
memset(pHdr, 0x57, sizeof(TmBlockHdr));
pTm->xFree(pHdr);
}
}
static void *tmRealloc(TmGlobal *pTm, void *p, int nByte){
void *pNew;
pNew = tmMalloc(pTm, nByte);
if( pNew && p ){
TmBlockHdr *pHdr;
u8 *pUser = (u8 *)p;
pHdr = (TmBlockHdr *)(pUser - BLOCK_HDR_SIZE);
memcpy(pNew, p, MIN(nByte, pHdr->nByte));
tmFree(pTm, p);
}
return pNew;
}
static void tmMallocOom(
TmGlobal *pTm,
int nCountdown,
int bPersist,
void (*xHook)(void *),
void *pHookCtx
){
assert( nCountdown>=0 );
assert( bPersist==0 || bPersist==1 );
pTm->nCountdown = nCountdown;
pTm->bPersist = bPersist;
pTm->xHook = xHook;
pTm->pHookCtx = pHookCtx;
pTm->bEnable = 1;
}
static void tmMallocOomEnable(
TmGlobal *pTm,
int bEnable
){
pTm->bEnable = bEnable;
}
static void tmMallocCheck(
TmGlobal *pTm,
int *pnLeakAlloc,
int *pnLeakByte,
FILE *pFile
){
TmBlockHdr *pHdr;
int nLeak = 0;
int nByte = 0;
if( pTm==0 ) return;
for(pHdr=pTm->pFirst; pHdr; pHdr=pHdr->pNext){
nLeak++;
nByte += pHdr->nByte;
}
if( pnLeakAlloc ) *pnLeakAlloc = nLeak;
if( pnLeakByte ) *pnLeakByte = nByte;
#ifdef TM_BACKTRACE
if( pFile ){
int i;
fprintf(pFile, "LEAKS\n");
for(i=0; i<ArraySize(pTm->aHash); i++){
TmAgg *pAgg;
for(pAgg=pTm->aHash[i]; pAgg; pAgg=pAgg->pNext){
if( pAgg->nOutAlloc ){
int j;
fprintf(pFile, "%d %d ", pAgg->nOutByte, pAgg->nOutAlloc);
for(j=0; j<TM_BACKTRACE; j++){
fprintf(pFile, "%p ", pAgg->aFrame[j]);
}
fprintf(pFile, "\n");
}
}
}
fprintf(pFile, "\nALLOCATIONS\n");
for(i=0; i<ArraySize(pTm->aHash); i++){
TmAgg *pAgg;
for(pAgg=pTm->aHash[i]; pAgg; pAgg=pAgg->pNext){
int j;
fprintf(pFile, "%d %d ", pAgg->nByte, pAgg->nAlloc);
for(j=0; j<TM_BACKTRACE; j++) fprintf(pFile, "%p ", pAgg->aFrame[j]);
fprintf(pFile, "\n");
}
}
}
#else
(void)pFile;
#endif
}
#include "lsm.h"
#include "stdlib.h"
typedef struct LsmMutex LsmMutex;
struct LsmMutex {
lsm_env *pEnv;
lsm_mutex *pMutex;
};
static void tmLsmMutexEnter(TmGlobal *pTm){
LsmMutex *p = (LsmMutex *)pTm->pMutex;
p->pEnv->xMutexEnter(p->pMutex);
}
static void tmLsmMutexLeave(TmGlobal *pTm){
LsmMutex *p = (LsmMutex *)(pTm->pMutex);
p->pEnv->xMutexLeave(p->pMutex);
}
static void tmLsmMutexDel(TmGlobal *pTm){
LsmMutex *p = (LsmMutex *)pTm->pMutex;
pTm->xFree(p);
}
static void *tmLsmMalloc(int n){ return malloc(n); }
static void tmLsmFree(void *ptr){ free(ptr); }
static void *tmLsmRealloc(void *ptr, int n){ return realloc(ptr, n); }
static void *tmLsmEnvMalloc(lsm_env *p, size_t n){
return tmMalloc((TmGlobal *)(p->pMemCtx), n);
}
static void tmLsmEnvFree(lsm_env *p, void *ptr){
tmFree((TmGlobal *)(p->pMemCtx), ptr);
}
static void *tmLsmEnvRealloc(lsm_env *p, void *ptr, size_t n){
return tmRealloc((TmGlobal *)(p->pMemCtx), ptr, n);
}
void testMallocInstall(lsm_env *pEnv){
TmGlobal *pGlobal;
LsmMutex *pMutex;
assert( pEnv->pMemCtx==0 );
/* Allocate and populate a TmGlobal structure. */
pGlobal = (TmGlobal *)tmLsmMalloc(sizeof(TmGlobal));
memset(pGlobal, 0, sizeof(TmGlobal));
pGlobal->xMalloc = tmLsmMalloc;
pGlobal->xRealloc = tmLsmRealloc;
pGlobal->xFree = tmLsmFree;
pMutex = (LsmMutex *)pGlobal->xMalloc(sizeof(LsmMutex));
pMutex->pEnv = pEnv;
pEnv->xMutexStatic(pEnv, LSM_MUTEX_HEAP, &pMutex->pMutex);
pGlobal->xEnterMutex = tmLsmMutexEnter;
pGlobal->xLeaveMutex = tmLsmMutexLeave;
pGlobal->xDelMutex = tmLsmMutexDel;
pGlobal->pMutex = (void *)pMutex;
pGlobal->xSaveMalloc = pEnv->xMalloc;
pGlobal->xSaveRealloc = pEnv->xRealloc;
pGlobal->xSaveFree = pEnv->xFree;
/* Set up pEnv to the use the new TmGlobal */
pEnv->pMemCtx = (void *)pGlobal;
pEnv->xMalloc = tmLsmEnvMalloc;
pEnv->xRealloc = tmLsmEnvRealloc;
pEnv->xFree = tmLsmEnvFree;
}
void testMallocUninstall(lsm_env *pEnv){
TmGlobal *p = (TmGlobal *)pEnv->pMemCtx;
pEnv->pMemCtx = 0;
if( p ){
pEnv->xMalloc = p->xSaveMalloc;
pEnv->xRealloc = p->xSaveRealloc;
pEnv->xFree = p->xSaveFree;
p->xDelMutex(p);
tmLsmFree(p);
}
}
void testMallocCheck(
lsm_env *pEnv,
int *pnLeakAlloc,
int *pnLeakByte,
FILE *pFile
){
if( pEnv->pMemCtx==0 ){
*pnLeakAlloc = 0;
*pnLeakByte = 0;
}else{
tmMallocCheck((TmGlobal *)(pEnv->pMemCtx), pnLeakAlloc, pnLeakByte, pFile);
}
}
void testMallocOom(
lsm_env *pEnv,
int nCountdown,
int bPersist,
void (*xHook)(void *),
void *pHookCtx
){
TmGlobal *pTm = (TmGlobal *)(pEnv->pMemCtx);
tmMallocOom(pTm, nCountdown, bPersist, xHook, pHookCtx);
}
void testMallocOomEnable(lsm_env *pEnv, int bEnable){
TmGlobal *pTm = (TmGlobal *)(pEnv->pMemCtx);
tmMallocOomEnable(pTm, bEnable);
}
-846
View File
@@ -1,846 +0,0 @@
/*
** This program attempts to test the correctness of some facets of the
** LSM database library. Specifically, that the contents of the database
** are maintained correctly during a series of inserts and deletes.
*/
#include "lsmtest_tdb.h"
#include "lsm.h"
#include "lsmtest.h"
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#ifndef _WIN32
# include <unistd.h>
#endif
#include <stdio.h>
typedef struct SqlDb SqlDb;
static int error_transaction_function(TestDb *p, int iLevel){
unused_parameter(p);
unused_parameter(iLevel);
return -1;
}
/*************************************************************************
** Begin wrapper for LevelDB.
*/
#ifdef HAVE_LEVELDB
#include <leveldb/c.h>
typedef struct LevelDb LevelDb;
struct LevelDb {
TestDb base;
leveldb_t *db;
leveldb_options_t *pOpt;
leveldb_writeoptions_t *pWriteOpt;
leveldb_readoptions_t *pReadOpt;
char *pVal;
};
static int test_leveldb_close(TestDb *pTestDb){
LevelDb *pDb = (LevelDb *)pTestDb;
leveldb_close(pDb->db);
leveldb_writeoptions_destroy(pDb->pWriteOpt);
leveldb_readoptions_destroy(pDb->pReadOpt);
leveldb_options_destroy(pDb->pOpt);
free(pDb->pVal);
free(pDb);
return 0;
}
static int test_leveldb_write(
TestDb *pTestDb,
void *pKey,
int nKey,
void *pVal,
int nVal
){
LevelDb *pDb = (LevelDb *)pTestDb;
char *zErr = 0;
leveldb_put(pDb->db, pDb->pWriteOpt, pKey, nKey, pVal, nVal, &zErr);
return (zErr!=0);
}
static int test_leveldb_delete(TestDb *pTestDb, void *pKey, int nKey){
LevelDb *pDb = (LevelDb *)pTestDb;
char *zErr = 0;
leveldb_delete(pDb->db, pDb->pWriteOpt, pKey, nKey, &zErr);
return (zErr!=0);
}
static int test_leveldb_fetch(
TestDb *pTestDb,
void *pKey,
int nKey,
void **ppVal,
int *pnVal
){
LevelDb *pDb = (LevelDb *)pTestDb;
char *zErr = 0;
size_t nVal = 0;
if( pKey==0 ) return 0;
free(pDb->pVal);
pDb->pVal = leveldb_get(pDb->db, pDb->pReadOpt, pKey, nKey, &nVal, &zErr);
*ppVal = (void *)(pDb->pVal);
if( pDb->pVal==0 ){
*pnVal = -1;
}else{
*pnVal = (int)nVal;
}
return (zErr!=0);
}
static int test_leveldb_scan(
TestDb *pTestDb,
void *pCtx,
int bReverse,
void *pKey1, int nKey1, /* Start of search */
void *pKey2, int nKey2, /* End of search */
void (*xCallback)(void *, void *, int , void *, int)
){
LevelDb *pDb = (LevelDb *)pTestDb;
leveldb_iterator_t *iter;
iter = leveldb_create_iterator(pDb->db, pDb->pReadOpt);
if( bReverse==0 ){
if( pKey1 ){
leveldb_iter_seek(iter, pKey1, nKey1);
}else{
leveldb_iter_seek_to_first(iter);
}
}else{
if( pKey2 ){
leveldb_iter_seek(iter, pKey2, nKey2);
if( leveldb_iter_valid(iter)==0 ){
leveldb_iter_seek_to_last(iter);
}else{
const char *k; size_t n;
int res;
k = leveldb_iter_key(iter, &n);
res = memcmp(k, pKey2, MIN(n, nKey2));
if( res==0 ) res = n - nKey2;
assert( res>=0 );
if( res>0 ){
leveldb_iter_prev(iter);
}
}
}else{
leveldb_iter_seek_to_last(iter);
}
}
while( leveldb_iter_valid(iter) ){
const char *k; size_t n;
const char *v; size_t n2;
int res;
k = leveldb_iter_key(iter, &n);
if( bReverse==0 && pKey2 ){
res = memcmp(k, pKey2, MIN(n, nKey2));
if( res==0 ) res = n - nKey2;
if( res>0 ) break;
}
if( bReverse!=0 && pKey1 ){
res = memcmp(k, pKey1, MIN(n, nKey1));
if( res==0 ) res = n - nKey1;
if( res<0 ) break;
}
v = leveldb_iter_value(iter, &n2);
xCallback(pCtx, (void *)k, n, (void *)v, n2);
if( bReverse==0 ){
leveldb_iter_next(iter);
}else{
leveldb_iter_prev(iter);
}
}
leveldb_iter_destroy(iter);
return 0;
}
static int test_leveldb_open(
const char *zSpec,
const char *zFilename,
int bClear,
TestDb **ppDb
){
static const DatabaseMethods LeveldbMethods = {
test_leveldb_close,
test_leveldb_write,
test_leveldb_delete,
0,
test_leveldb_fetch,
test_leveldb_scan,
error_transaction_function,
error_transaction_function,
error_transaction_function
};
LevelDb *pLevelDb;
char *zErr = 0;
if( bClear ){
char *zCmd = sqlite3_mprintf("rm -rf %s\n", zFilename);
system(zCmd);
sqlite3_free(zCmd);
}
pLevelDb = (LevelDb *)malloc(sizeof(LevelDb));
memset(pLevelDb, 0, sizeof(LevelDb));
pLevelDb->pOpt = leveldb_options_create();
leveldb_options_set_create_if_missing(pLevelDb->pOpt, 1);
pLevelDb->pWriteOpt = leveldb_writeoptions_create();
pLevelDb->pReadOpt = leveldb_readoptions_create();
pLevelDb->db = leveldb_open(pLevelDb->pOpt, zFilename, &zErr);
if( zErr ){
test_leveldb_close((TestDb *)pLevelDb);
*ppDb = 0;
return 1;
}
*ppDb = (TestDb *)pLevelDb;
pLevelDb->base.pMethods = &LeveldbMethods;
return 0;
}
#endif /* HAVE_LEVELDB */
/*
** End wrapper for LevelDB.
*************************************************************************/
#ifdef HAVE_KYOTOCABINET
static int kc_close(TestDb *pTestDb){
return test_kc_close(pTestDb);
}
static int kc_write(
TestDb *pTestDb,
void *pKey,
int nKey,
void *pVal,
int nVal
){
return test_kc_write(pTestDb, pKey, nKey, pVal, nVal);
}
static int kc_delete(TestDb *pTestDb, void *pKey, int nKey){
return test_kc_delete(pTestDb, pKey, nKey);
}
static int kc_delete_range(
TestDb *pTestDb,
void *pKey1, int nKey1,
void *pKey2, int nKey2
){
return test_kc_delete_range(pTestDb, pKey1, nKey1, pKey2, nKey2);
}
static int kc_fetch(
TestDb *pTestDb,
void *pKey,
int nKey,
void **ppVal,
int *pnVal
){
if( pKey==0 ) return LSM_OK;
return test_kc_fetch(pTestDb, pKey, nKey, ppVal, pnVal);
}
static int kc_scan(
TestDb *pTestDb,
void *pCtx,
int bReverse,
void *pFirst, int nFirst,
void *pLast, int nLast,
void (*xCallback)(void *, void *, int , void *, int)
){
return test_kc_scan(
pTestDb, pCtx, bReverse, pFirst, nFirst, pLast, nLast, xCallback
);
}
static int kc_open(
const char *zSpec,
const char *zFilename,
int bClear,
TestDb **ppDb
){
static const DatabaseMethods KcdbMethods = {
kc_close,
kc_write,
kc_delete,
kc_delete_range,
kc_fetch,
kc_scan,
error_transaction_function,
error_transaction_function,
error_transaction_function
};
int rc;
TestDb *pTestDb = 0;
rc = test_kc_open(zFilename, bClear, &pTestDb);
if( rc!=0 ){
*ppDb = 0;
return rc;
}
pTestDb->pMethods = &KcdbMethods;
*ppDb = pTestDb;
return 0;
}
#endif /* HAVE_KYOTOCABINET */
/*
** End wrapper for Kyoto cabinet.
*************************************************************************/
#ifdef HAVE_MDB
static int mdb_close(TestDb *pTestDb){
return test_mdb_close(pTestDb);
}
static int mdb_write(
TestDb *pTestDb,
void *pKey,
int nKey,
void *pVal,
int nVal
){
return test_mdb_write(pTestDb, pKey, nKey, pVal, nVal);
}
static int mdb_delete(TestDb *pTestDb, void *pKey, int nKey){
return test_mdb_delete(pTestDb, pKey, nKey);
}
static int mdb_fetch(
TestDb *pTestDb,
void *pKey,
int nKey,
void **ppVal,
int *pnVal
){
if( pKey==0 ) return LSM_OK;
return test_mdb_fetch(pTestDb, pKey, nKey, ppVal, pnVal);
}
static int mdb_scan(
TestDb *pTestDb,
void *pCtx,
int bReverse,
void *pFirst, int nFirst,
void *pLast, int nLast,
void (*xCallback)(void *, void *, int , void *, int)
){
return test_mdb_scan(
pTestDb, pCtx, bReverse, pFirst, nFirst, pLast, nLast, xCallback
);
}
static int mdb_open(
const char *zSpec,
const char *zFilename,
int bClear,
TestDb **ppDb
){
static const DatabaseMethods KcdbMethods = {
mdb_close,
mdb_write,
mdb_delete,
0,
mdb_fetch,
mdb_scan,
error_transaction_function,
error_transaction_function,
error_transaction_function
};
int rc;
TestDb *pTestDb = 0;
rc = test_mdb_open(zSpec, zFilename, bClear, &pTestDb);
if( rc!=0 ){
*ppDb = 0;
return rc;
}
pTestDb->pMethods = &KcdbMethods;
*ppDb = pTestDb;
return 0;
}
#endif /* HAVE_MDB */
/*************************************************************************
** Begin wrapper for SQLite.
*/
/*
** nOpenTrans:
** The number of open nested transactions, in the same sense as used
** by the tdb_begin/commit/rollback and SQLite 4 KV interfaces. If this
** value is 0, there are no transactions open at all. If it is 1, then
** there is a read transaction. If it is 2 or greater, then there are
** (nOpenTrans-1) nested write transactions open.
*/
struct SqlDb {
TestDb base;
sqlite3 *db;
sqlite3_stmt *pInsert;
sqlite3_stmt *pDelete;
sqlite3_stmt *pDeleteRange;
sqlite3_stmt *pFetch;
sqlite3_stmt *apScan[8];
int nOpenTrans;
/* Used by sql_fetch() to allocate space for results */
int nAlloc;
u8 *aAlloc;
};
static int sql_close(TestDb *pTestDb){
SqlDb *pDb = (SqlDb *)pTestDb;
sqlite3_finalize(pDb->pInsert);
sqlite3_finalize(pDb->pDelete);
sqlite3_finalize(pDb->pDeleteRange);
sqlite3_finalize(pDb->pFetch);
sqlite3_finalize(pDb->apScan[0]);
sqlite3_finalize(pDb->apScan[1]);
sqlite3_finalize(pDb->apScan[2]);
sqlite3_finalize(pDb->apScan[3]);
sqlite3_finalize(pDb->apScan[4]);
sqlite3_finalize(pDb->apScan[5]);
sqlite3_finalize(pDb->apScan[6]);
sqlite3_finalize(pDb->apScan[7]);
sqlite3_close(pDb->db);
free((char *)pDb->aAlloc);
free((char *)pDb);
return SQLITE_OK;
}
static int sql_write(
TestDb *pTestDb,
void *pKey,
int nKey,
void *pVal,
int nVal
){
SqlDb *pDb = (SqlDb *)pTestDb;
sqlite3_bind_blob(pDb->pInsert, 1, pKey, nKey, SQLITE_STATIC);
sqlite3_bind_blob(pDb->pInsert, 2, pVal, nVal, SQLITE_STATIC);
sqlite3_step(pDb->pInsert);
return sqlite3_reset(pDb->pInsert);
}
static int sql_delete(TestDb *pTestDb, void *pKey, int nKey){
SqlDb *pDb = (SqlDb *)pTestDb;
sqlite3_bind_blob(pDb->pDelete, 1, pKey, nKey, SQLITE_STATIC);
sqlite3_step(pDb->pDelete);
return sqlite3_reset(pDb->pDelete);
}
static int sql_delete_range(
TestDb *pTestDb,
void *pKey1, int nKey1,
void *pKey2, int nKey2
){
SqlDb *pDb = (SqlDb *)pTestDb;
sqlite3_bind_blob(pDb->pDeleteRange, 1, pKey1, nKey1, SQLITE_STATIC);
sqlite3_bind_blob(pDb->pDeleteRange, 2, pKey2, nKey2, SQLITE_STATIC);
sqlite3_step(pDb->pDeleteRange);
return sqlite3_reset(pDb->pDeleteRange);
}
static int sql_fetch(
TestDb *pTestDb,
void *pKey,
int nKey,
void **ppVal,
int *pnVal
){
SqlDb *pDb = (SqlDb *)pTestDb;
int rc;
sqlite3_reset(pDb->pFetch);
if( pKey==0 ){
assert( ppVal==0 );
assert( pnVal==0 );
return LSM_OK;
}
sqlite3_bind_blob(pDb->pFetch, 1, pKey, nKey, SQLITE_STATIC);
rc = sqlite3_step(pDb->pFetch);
if( rc==SQLITE_ROW ){
int nVal = sqlite3_column_bytes(pDb->pFetch, 0);
u8 *aVal = (void *)sqlite3_column_blob(pDb->pFetch, 0);
if( nVal>pDb->nAlloc ){
free(pDb->aAlloc);
pDb->aAlloc = (u8 *)malloc(nVal*2);
pDb->nAlloc = nVal*2;
}
memcpy(pDb->aAlloc, aVal, nVal);
*pnVal = nVal;
*ppVal = (void *)pDb->aAlloc;
}else{
*pnVal = -1;
*ppVal = 0;
}
rc = sqlite3_reset(pDb->pFetch);
return rc;
}
static int sql_scan(
TestDb *pTestDb,
void *pCtx,
int bReverse,
void *pFirst, int nFirst,
void *pLast, int nLast,
void (*xCallback)(void *, void *, int , void *, int)
){
SqlDb *pDb = (SqlDb *)pTestDb;
sqlite3_stmt *pScan;
assert( bReverse==1 || bReverse==0 );
pScan = pDb->apScan[(pFirst==0) + (pLast==0)*2 + bReverse*4];
if( pFirst ) sqlite3_bind_blob(pScan, 1, pFirst, nFirst, SQLITE_STATIC);
if( pLast ) sqlite3_bind_blob(pScan, 2, pLast, nLast, SQLITE_STATIC);
while( SQLITE_ROW==sqlite3_step(pScan) ){
void *pKey; int nKey;
void *pVal; int nVal;
nKey = sqlite3_column_bytes(pScan, 0);
pKey = (void *)sqlite3_column_blob(pScan, 0);
nVal = sqlite3_column_bytes(pScan, 1);
pVal = (void *)sqlite3_column_blob(pScan, 1);
xCallback(pCtx, pKey, nKey, pVal, nVal);
}
return sqlite3_reset(pScan);
}
static int sql_begin(TestDb *pTestDb, int iLevel){
int i;
SqlDb *pDb = (SqlDb *)pTestDb;
/* iLevel==0 is a no-op */
if( iLevel==0 ) return 0;
/* If there are no transactions at all open, open a read transaction. */
if( pDb->nOpenTrans==0 ){
int rc = sqlite3_exec(pDb->db,
"BEGIN; SELECT * FROM sqlite_schema LIMIT 1;" , 0, 0, 0
);
if( rc!=0 ) return rc;
pDb->nOpenTrans = 1;
}
/* Open any required write transactions */
for(i=pDb->nOpenTrans; i<iLevel; i++){
char *zSql = sqlite3_mprintf("SAVEPOINT x%d", i);
int rc = sqlite3_exec(pDb->db, zSql, 0, 0, 0);
sqlite3_free(zSql);
if( rc!=SQLITE_OK ) return rc;
}
pDb->nOpenTrans = iLevel;
return 0;
}
static int sql_commit(TestDb *pTestDb, int iLevel){
SqlDb *pDb = (SqlDb *)pTestDb;
assert( iLevel>=0 );
/* Close the read transaction if requested. */
if( pDb->nOpenTrans>=1 && iLevel==0 ){
int rc = sqlite3_exec(pDb->db, "COMMIT", 0, 0, 0);
if( rc!=0 ) return rc;
pDb->nOpenTrans = 0;
}
/* Close write transactions as required */
if( pDb->nOpenTrans>iLevel ){
char *zSql = sqlite3_mprintf("RELEASE x%d", iLevel);
int rc = sqlite3_exec(pDb->db, zSql, 0, 0, 0);
sqlite3_free(zSql);
if( rc!=0 ) return rc;
}
pDb->nOpenTrans = iLevel;
return 0;
}
static int sql_rollback(TestDb *pTestDb, int iLevel){
SqlDb *pDb = (SqlDb *)pTestDb;
assert( iLevel>=0 );
if( pDb->nOpenTrans>=1 && iLevel==0 ){
/* Close the read transaction if requested. */
int rc = sqlite3_exec(pDb->db, "ROLLBACK", 0, 0, 0);
if( rc!=0 ) return rc;
}else if( pDb->nOpenTrans>1 && iLevel==1 ){
/* Or, rollback and close the top-level write transaction */
int rc = sqlite3_exec(pDb->db, "ROLLBACK TO x1; RELEASE x1;", 0, 0, 0);
if( rc!=0 ) return rc;
}else{
/* Or, just roll back some nested transactions */
char *zSql = sqlite3_mprintf("ROLLBACK TO x%d", iLevel-1);
int rc = sqlite3_exec(pDb->db, zSql, 0, 0, 0);
sqlite3_free(zSql);
if( rc!=0 ) return rc;
}
pDb->nOpenTrans = iLevel;
return 0;
}
static int sql_open(
const char *zSpec,
const char *zFilename,
int bClear,
TestDb **ppDb
){
static const DatabaseMethods SqlMethods = {
sql_close,
sql_write,
sql_delete,
sql_delete_range,
sql_fetch,
sql_scan,
sql_begin,
sql_commit,
sql_rollback
};
const char *zCreate = "CREATE TABLE IF NOT EXISTS t1(k PRIMARY KEY, v)";
const char *zInsert = "REPLACE INTO t1 VALUES(?, ?)";
const char *zDelete = "DELETE FROM t1 WHERE k = ?";
const char *zRange = "DELETE FROM t1 WHERE k>? AND k<?";
const char *zFetch = "SELECT v FROM t1 WHERE k = ?";
const char *zScan0 = "SELECT * FROM t1 WHERE k BETWEEN ?1 AND ?2 ORDER BY k";
const char *zScan1 = "SELECT * FROM t1 WHERE k <= ?2 ORDER BY k";
const char *zScan2 = "SELECT * FROM t1 WHERE k >= ?1 ORDER BY k";
const char *zScan3 = "SELECT * FROM t1 ORDER BY k";
const char *zScan4 =
"SELECT * FROM t1 WHERE k BETWEEN ?1 AND ?2 ORDER BY k DESC";
const char *zScan5 = "SELECT * FROM t1 WHERE k <= ?2 ORDER BY k DESC";
const char *zScan6 = "SELECT * FROM t1 WHERE k >= ?1 ORDER BY k DESC";
const char *zScan7 = "SELECT * FROM t1 ORDER BY k DESC";
int rc;
SqlDb *pDb;
char *zPragma;
if( bClear && zFilename && zFilename[0] ){
unlink(zFilename);
}
pDb = (SqlDb *)malloc(sizeof(SqlDb));
memset(pDb, 0, sizeof(SqlDb));
pDb->base.pMethods = &SqlMethods;
if( 0!=(rc = sqlite3_open(zFilename, &pDb->db))
|| 0!=(rc = sqlite3_exec(pDb->db, zCreate, 0, 0, 0))
|| 0!=(rc = sqlite3_prepare_v2(pDb->db, zInsert, -1, &pDb->pInsert, 0))
|| 0!=(rc = sqlite3_prepare_v2(pDb->db, zDelete, -1, &pDb->pDelete, 0))
|| 0!=(rc = sqlite3_prepare_v2(pDb->db, zRange, -1, &pDb->pDeleteRange, 0))
|| 0!=(rc = sqlite3_prepare_v2(pDb->db, zFetch, -1, &pDb->pFetch, 0))
|| 0!=(rc = sqlite3_prepare_v2(pDb->db, zScan0, -1, &pDb->apScan[0], 0))
|| 0!=(rc = sqlite3_prepare_v2(pDb->db, zScan1, -1, &pDb->apScan[1], 0))
|| 0!=(rc = sqlite3_prepare_v2(pDb->db, zScan2, -1, &pDb->apScan[2], 0))
|| 0!=(rc = sqlite3_prepare_v2(pDb->db, zScan3, -1, &pDb->apScan[3], 0))
|| 0!=(rc = sqlite3_prepare_v2(pDb->db, zScan4, -1, &pDb->apScan[4], 0))
|| 0!=(rc = sqlite3_prepare_v2(pDb->db, zScan5, -1, &pDb->apScan[5], 0))
|| 0!=(rc = sqlite3_prepare_v2(pDb->db, zScan6, -1, &pDb->apScan[6], 0))
|| 0!=(rc = sqlite3_prepare_v2(pDb->db, zScan7, -1, &pDb->apScan[7], 0))
){
*ppDb = 0;
sql_close((TestDb *)pDb);
return rc;
}
zPragma = sqlite3_mprintf("PRAGMA page_size=%d", TESTDB_DEFAULT_PAGE_SIZE);
sqlite3_exec(pDb->db, zPragma, 0, 0, 0);
sqlite3_free(zPragma);
zPragma = sqlite3_mprintf("PRAGMA cache_size=%d", TESTDB_DEFAULT_CACHE_SIZE);
sqlite3_exec(pDb->db, zPragma, 0, 0, 0);
sqlite3_free(zPragma);
/* sqlite3_exec(pDb->db, "PRAGMA locking_mode=EXCLUSIVE", 0, 0, 0); */
sqlite3_exec(pDb->db, "PRAGMA synchronous=OFF", 0, 0, 0);
sqlite3_exec(pDb->db, "PRAGMA journal_mode=WAL", 0, 0, 0);
sqlite3_exec(pDb->db, "PRAGMA wal_autocheckpoint=4096", 0, 0, 0);
if( zSpec ){
rc = sqlite3_exec(pDb->db, zSpec, 0, 0, 0);
if( rc!=SQLITE_OK ){
sql_close((TestDb *)pDb);
return rc;
}
}
*ppDb = (TestDb *)pDb;
return 0;
}
/*
** End wrapper for SQLite.
*************************************************************************/
/*************************************************************************
** Begin exported functions.
*/
static struct Lib {
const char *zName;
const char *zDefaultDb;
int (*xOpen)(const char *, const char *zFilename, int bClear, TestDb **ppDb);
} aLib[] = {
{ "sqlite3", "testdb.sqlite", sql_open },
{ "lsm_small", "testdb.lsm_small", test_lsm_small_open },
{ "lsm_lomem", "testdb.lsm_lomem", test_lsm_lomem_open },
{ "lsm_lomem2", "testdb.lsm_lomem2", test_lsm_lomem2_open },
#ifdef HAVE_ZLIB
{ "lsm_zip", "testdb.lsm_zip", test_lsm_zip_open },
#endif
{ "lsm", "testdb.lsm", test_lsm_open },
#ifdef LSM_MUTEX_PTHREADS
{ "lsm_mt2", "testdb.lsm_mt2", test_lsm_mt2 },
{ "lsm_mt3", "testdb.lsm_mt3", test_lsm_mt3 },
#endif
#ifdef HAVE_LEVELDB
{ "leveldb", "testdb.leveldb", test_leveldb_open },
#endif
#ifdef HAVE_KYOTOCABINET
{ "kyotocabinet", "testdb.kc", kc_open },
#endif
#ifdef HAVE_MDB
{ "mdb", "./testdb.mdb", mdb_open }
#endif
};
const char *tdb_system_name(int i){
if( i<0 || i>=ArraySize(aLib) ) return 0;
return aLib[i].zName;
}
const char *tdb_default_db(const char *zSys){
int i;
for(i=0; i<ArraySize(aLib); i++){
if( strcmp(aLib[i].zName, zSys)==0 ) return aLib[i].zDefaultDb;
}
return 0;
}
int tdb_open(const char *zLib, const char *zDb, int bClear, TestDb **ppDb){
int i;
int rc = 1;
const char *zSpec = 0;
int nLib = 0;
while( zLib[nLib] && zLib[nLib]!=' ' ){
nLib++;
}
zSpec = &zLib[nLib];
while( *zSpec==' ' ) zSpec++;
if( *zSpec=='\0' ) zSpec = 0;
for(i=0; i<ArraySize(aLib); i++){
if( (int)strlen(aLib[i].zName)==nLib
&& 0==memcmp(zLib, aLib[i].zName, nLib) ){
rc = aLib[i].xOpen(zSpec, (zDb ? zDb : aLib[i].zDefaultDb), bClear, ppDb);
if( rc==0 ){
(*ppDb)->zLibrary = aLib[i].zName;
}
break;
}
}
if( rc ){
/* Failed to find the requested database library. Return an error. */
*ppDb = 0;
}
return rc;
}
int tdb_close(TestDb *pDb){
if( pDb ){
return pDb->pMethods->xClose(pDb);
}
return 0;
}
int tdb_write(TestDb *pDb, void *pKey, int nKey, void *pVal, int nVal){
return pDb->pMethods->xWrite(pDb, pKey, nKey, pVal, nVal);
}
int tdb_delete(TestDb *pDb, void *pKey, int nKey){
return pDb->pMethods->xDelete(pDb, pKey, nKey);
}
int tdb_delete_range(
TestDb *pDb, void *pKey1, int nKey1, void *pKey2, int nKey2
){
return pDb->pMethods->xDeleteRange(pDb, pKey1, nKey1, pKey2, nKey2);
}
int tdb_fetch(TestDb *pDb, void *pKey, int nKey, void **ppVal, int *pnVal){
return pDb->pMethods->xFetch(pDb, pKey, nKey, ppVal, pnVal);
}
int tdb_scan(
TestDb *pDb, /* Database handle */
void *pCtx, /* Context pointer to pass to xCallback */
int bReverse, /* True to scan in reverse order */
void *pKey1, int nKey1, /* Start of search */
void *pKey2, int nKey2, /* End of search */
void (*xCallback)(void *pCtx, void *pKey, int nKey, void *pVal, int nVal)
){
return pDb->pMethods->xScan(
pDb, pCtx, bReverse, pKey1, nKey1, pKey2, nKey2, xCallback
);
}
int tdb_begin(TestDb *pDb, int iLevel){
return pDb->pMethods->xBegin(pDb, iLevel);
}
int tdb_commit(TestDb *pDb, int iLevel){
return pDb->pMethods->xCommit(pDb, iLevel);
}
int tdb_rollback(TestDb *pDb, int iLevel){
return pDb->pMethods->xRollback(pDb, iLevel);
}
int tdb_transaction_support(TestDb *pDb){
return (pDb->pMethods->xBegin != error_transaction_function);
}
const char *tdb_library_name(TestDb *pDb){
return pDb->zLibrary;
}
/*
** End exported functions.
*************************************************************************/
-174
View File
@@ -1,174 +0,0 @@
/*
** This file is the interface to a very simple database library used for
** testing. The interface is similar to that of the LSM. The main virtue
** of this library is that the same API may be used to access a key-value
** store implemented by LSM, SQLite or another database system. Which
** makes it easy to use for correctness and performance tests.
*/
#ifndef __WRAPPER_H_
#define __WRAPPER_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "lsm.h"
typedef struct TestDb TestDb;
/*
** Open a new database connection. The first argument is the name of the
** database library to use. e.g. something like:
**
** "sqlite3"
** "lsm"
**
** See function tdb_system_name() for a list of available database systems.
**
** The second argument is the name of the database to open (e.g. a filename).
**
** If the third parameter is non-zero, then any existing database by the
** name of zDb is removed before opening a new one. If it is zero, then an
** existing database may be opened.
*/
int tdb_open(const char *zLibrary, const char *zDb, int bClear, TestDb **ppDb);
/*
** Close a database handle.
*/
int tdb_close(TestDb *pDb);
/*
** Write a new key/value into the database.
*/
int tdb_write(TestDb *pDb, void *pKey, int nKey, void *pVal, int nVal);
/*
** Delete a key from the database.
*/
int tdb_delete(TestDb *pDb, void *pKey, int nKey);
/*
** Delete a range of keys from the database.
*/
int tdb_delete_range(TestDb *, void *pKey1, int nKey1, void *pKey2, int nKey2);
/*
** Query the database for key (pKey/nKey). If no entry is found, set *ppVal
** to 0 and *pnVal to -1 before returning. Otherwise, set *ppVal and *pnVal
** to a pointer to and size of the value associated with (pKey/nKey).
*/
int tdb_fetch(TestDb *pDb, void *pKey, int nKey, void **ppVal, int *pnVal);
/*
** Open and close nested transactions. Currently, these functions only
** work for SQLite3 and LSM systems. Use the tdb_transaction_support()
** function to determine if a given TestDb handle supports these methods.
**
** These functions and the iLevel parameter follow the same conventions as
** the SQLite 4 transaction interface. Note that this is slightly different
** from the way LSM does things. As follows:
**
** tdb_begin():
** A successful call to tdb_begin() with (iLevel>1) guarantees that
** there are at least (iLevel-1) write transactions open. If iLevel==1,
** then it guarantees that at least a read-transaction is open. Calling
** tdb_begin() with iLevel==0 is a no-op.
**
** tdb_commit():
** A successful call to tdb_commit() with (iLevel>1) guarantees that
** there are at most (iLevel-1) write transactions open. If iLevel==1,
** then it guarantees that there are no write transactions open (although
** a read-transaction may remain open). Calling tdb_commit() with
** iLevel==0 ensures that all transactions, read or write, have been
** closed and committed.
**
** tdb_rollback():
** This call is similar to tdb_commit(), except that instead of committing
** transactions, it reverts them. For example, calling tdb_rollback() with
** iLevel==2 ensures that there is at most one write transaction open, and
** restores the database to the state that it was in when that transaction
** was opened.
**
** In other words, tdb_commit() just closes transactions - tdb_rollback()
** closes transactions and then restores the database to the state it
** was in before those transactions were even opened.
*/
int tdb_begin(TestDb *pDb, int iLevel);
int tdb_commit(TestDb *pDb, int iLevel);
int tdb_rollback(TestDb *pDb, int iLevel);
/*
** Return true if transactions are supported, or false otherwise.
*/
int tdb_transaction_support(TestDb *pDb);
/*
** Return the name of the database library (as passed to tdb_open()) used
** by the handled passed as the first argument.
*/
const char *tdb_library_name(TestDb *pDb);
/*
** Scan a range of database keys. Invoke the callback function for each
** key visited.
*/
int tdb_scan(
TestDb *pDb, /* Database handle */
void *pCtx, /* Context pointer to pass to xCallback */
int bReverse, /* True to scan in reverse order */
void *pKey1, int nKey1, /* Start of search */
void *pKey2, int nKey2, /* End of search */
void (*xCallback)(void *pCtx, void *pKey, int nKey, void *pVal, int nVal)
);
const char *tdb_system_name(int i);
const char *tdb_default_db(const char *zSys);
int tdb_lsm_open(const char *zCfg, const char *zDb, int bClear, TestDb **ppDb);
/*
** If the TestDb handle passed as an argument is a wrapper around an LSM
** database, return the LSM handle. Otherwise, if the argument is some other
** database system, return NULL.
*/
lsm_db *tdb_lsm(TestDb *pDb);
/*
** Return true if the db passed as an argument is a multi-threaded LSM
** connection.
*/
int tdb_lsm_multithread(TestDb *pDb);
/*
** Return a pointer to the lsm_env object used by all lsm database
** connections initialized as a copy of the object returned by
** lsm_default_env(). It may be modified (e.g. to override functions)
** if the caller can guarantee that it is not already in use.
*/
lsm_env *tdb_lsm_env(void);
/*
** The following functions only work with LSM database handles. It is
** illegal to call them with any other type of database handle specified
** as an argument.
*/
void tdb_lsm_enable_log(TestDb *pDb, int bEnable);
void tdb_lsm_application_crash(TestDb *pDb);
void tdb_lsm_prepare_system_crash(TestDb *pDb);
void tdb_lsm_system_crash(TestDb *pDb);
void tdb_lsm_prepare_sync_crash(TestDb *pDb, int iSync);
void tdb_lsm_safety(TestDb *pDb, int eMode);
void tdb_lsm_config_work_hook(TestDb *pDb, void (*)(lsm_db *, void *), void *);
void tdb_lsm_write_hook(TestDb *, void(*)(void*,int,lsm_i64,int,int), void*);
int tdb_lsm_config_str(TestDb *pDb, const char *zStr);
#ifdef __cplusplus
} /* End of the 'extern "C"' block */
#endif
#endif
-369
View File
@@ -1,369 +0,0 @@
#include "lsmtest.h"
#include <stdlib.h>
#ifdef HAVE_KYOTOCABINET
#include "kcpolydb.h"
extern "C" {
struct KcDb {
TestDb base;
kyotocabinet::TreeDB* db;
char *pVal;
};
}
int test_kc_open(const char *zFilename, int bClear, TestDb **ppDb){
KcDb *pKcDb;
int ok;
int rc = 0;
if( bClear ){
char *zCmd = sqlite3_mprintf("rm -rf %s\n", zFilename);
system(zCmd);
sqlite3_free(zCmd);
}
pKcDb = (KcDb *)malloc(sizeof(KcDb));
memset(pKcDb, 0, sizeof(KcDb));
pKcDb->db = new kyotocabinet::TreeDB();
pKcDb->db->tune_page(TESTDB_DEFAULT_PAGE_SIZE);
pKcDb->db->tune_page_cache(
TESTDB_DEFAULT_PAGE_SIZE * TESTDB_DEFAULT_CACHE_SIZE
);
ok = pKcDb->db->open(zFilename,
kyotocabinet::PolyDB::OWRITER | kyotocabinet::PolyDB::OCREATE
);
if( ok==0 ){
free(pKcDb);
pKcDb = 0;
rc = 1;
}
*ppDb = (TestDb *)pKcDb;
return rc;
}
int test_kc_close(TestDb *pDb){
KcDb *pKcDb = (KcDb *)pDb;
if( pKcDb->pVal ){
delete [] pKcDb->pVal;
}
pKcDb->db->close();
delete pKcDb->db;
free(pKcDb);
return 0;
}
int test_kc_write(TestDb *pDb, void *pKey, int nKey, void *pVal, int nVal){
KcDb *pKcDb = (KcDb *)pDb;
int ok;
ok = pKcDb->db->set((const char *)pKey, nKey, (const char *)pVal, nVal);
return (ok ? 0 : 1);
}
int test_kc_delete(TestDb *pDb, void *pKey, int nKey){
KcDb *pKcDb = (KcDb *)pDb;
int ok;
ok = pKcDb->db->remove((const char *)pKey, nKey);
return (ok ? 0 : 1);
}
int test_kc_delete_range(
TestDb *pDb,
void *pKey1, int nKey1,
void *pKey2, int nKey2
){
int res;
KcDb *pKcDb = (KcDb *)pDb;
kyotocabinet::DB::Cursor* pCur = pKcDb->db->cursor();
if( pKey1 ){
res = pCur->jump((const char *)pKey1, nKey1);
}else{
res = pCur->jump();
}
while( 1 ){
const char *pKey; size_t nKey;
const char *pVal; size_t nVal;
pKey = pCur->get(&nKey, &pVal, &nVal);
if( pKey==0 ) break;
#ifndef NDEBUG
if( pKey1 ){
res = memcmp(pKey, pKey1, MIN((size_t)nKey1, nKey));
assert( res>0 || (res==0 && nKey>nKey1) );
}
#endif
if( pKey2 ){
res = memcmp(pKey, pKey2, MIN((size_t)nKey2, nKey));
if( res>0 || (res==0 && (size_t)nKey2<nKey) ){
delete [] pKey;
break;
}
}
pCur->remove();
delete [] pKey;
}
delete pCur;
return 0;
}
int test_kc_fetch(
TestDb *pDb,
void *pKey,
int nKey,
void **ppVal,
int *pnVal
){
KcDb *pKcDb = (KcDb *)pDb;
size_t nVal;
if( pKcDb->pVal ){
delete [] pKcDb->pVal;
pKcDb->pVal = 0;
}
pKcDb->pVal = pKcDb->db->get((const char *)pKey, nKey, &nVal);
if( pKcDb->pVal ){
*ppVal = pKcDb->pVal;
*pnVal = nVal;
}else{
*ppVal = 0;
*pnVal = -1;
}
return 0;
}
int test_kc_scan(
TestDb *pDb, /* Database handle */
void *pCtx, /* Context pointer to pass to xCallback */
int bReverse, /* True for a reverse order scan */
void *pKey1, int nKey1, /* Start of search */
void *pKey2, int nKey2, /* End of search */
void (*xCallback)(void *pCtx, void *pKey, int nKey, void *pVal, int nVal)
){
KcDb *pKcDb = (KcDb *)pDb;
kyotocabinet::DB::Cursor* pCur = pKcDb->db->cursor();
int res;
if( bReverse==0 ){
if( pKey1 ){
res = pCur->jump((const char *)pKey1, nKey1);
}else{
res = pCur->jump();
}
}else{
if( pKey2 ){
res = pCur->jump_back((const char *)pKey2, nKey2);
}else{
res = pCur->jump_back();
}
}
while( res ){
const char *pKey; size_t nKey;
const char *pVal; size_t nVal;
pKey = pCur->get(&nKey, &pVal, &nVal);
if( bReverse==0 && pKey2 ){
res = memcmp(pKey, pKey2, MIN((size_t)nKey2, nKey));
if( res>0 || (res==0 && (size_t)nKey2<nKey) ){
delete [] pKey;
break;
}
}else if( bReverse!=0 && pKey1 ){
res = memcmp(pKey, pKey1, MIN((size_t)nKey1, nKey));
if( res<0 || (res==0 && (size_t)nKey1>nKey) ){
delete [] pKey;
break;
}
}
xCallback(pCtx, (void *)pKey, (int)nKey, (void *)pVal, (int)nVal);
delete [] pKey;
if( bReverse ){
res = pCur->step_back();
}else{
res = pCur->step();
}
}
delete pCur;
return 0;
}
#endif /* HAVE_KYOTOCABINET */
#ifdef HAVE_MDB
#include "lmdb.h"
extern "C" {
struct MdbDb {
TestDb base;
MDB_env *env;
MDB_dbi dbi;
};
}
int test_mdb_open(
const char *zSpec,
const char *zFilename,
int bClear,
TestDb **ppDb
){
MDB_txn *txn;
MdbDb *pMdb;
int rc;
if( bClear ){
char *zCmd = sqlite3_mprintf("rm -rf %s\n", zFilename);
system(zCmd);
sqlite3_free(zCmd);
}
pMdb = (MdbDb *)malloc(sizeof(MdbDb));
memset(pMdb, 0, sizeof(MdbDb));
rc = mdb_env_create(&pMdb->env);
if( rc==0 ) rc = mdb_env_set_mapsize(pMdb->env, 1*1024*1024*1024);
if( rc==0 ) rc = mdb_env_open(pMdb->env, zFilename, MDB_NOSYNC|MDB_NOSUBDIR, 0600);
if( rc==0 ) rc = mdb_txn_begin(pMdb->env, NULL, 0, &txn);
if( rc==0 ){
rc = mdb_open(txn, NULL, 0, &pMdb->dbi);
mdb_txn_commit(txn);
}
*ppDb = (TestDb *)pMdb;
return rc;
}
int test_mdb_close(TestDb *pDb){
MdbDb *pMdb = (MdbDb *)pDb;
mdb_close(pMdb->env, pMdb->dbi);
mdb_env_close(pMdb->env);
free(pMdb);
return 0;
}
int test_mdb_write(TestDb *pDb, void *pKey, int nKey, void *pVal, int nVal){
int rc;
MdbDb *pMdb = (MdbDb *)pDb;
MDB_val val;
MDB_val key;
MDB_txn *txn;
val.mv_size = nVal;
val.mv_data = pVal;
key.mv_size = nKey;
key.mv_data = pKey;
rc = mdb_txn_begin(pMdb->env, NULL, 0, &txn);
if( rc==0 ){
rc = mdb_put(txn, pMdb->dbi, &key, &val, 0);
if( rc==0 ){
rc = mdb_txn_commit(txn);
}else{
mdb_txn_abort(txn);
}
}
return rc;
}
int test_mdb_delete(TestDb *pDb, void *pKey, int nKey){
int rc;
MdbDb *pMdb = (MdbDb *)pDb;
MDB_val key;
MDB_txn *txn;
key.mv_size = nKey;
key.mv_data = pKey;
rc = mdb_txn_begin(pMdb->env, NULL, 0, &txn);
if( rc==0 ){
rc = mdb_del(txn, pMdb->dbi, &key, 0);
if( rc==0 ){
rc = mdb_txn_commit(txn);
}else{
mdb_txn_abort(txn);
}
}
return rc;
}
int test_mdb_fetch(
TestDb *pDb,
void *pKey,
int nKey,
void **ppVal,
int *pnVal
){
int rc;
MdbDb *pMdb = (MdbDb *)pDb;
MDB_val key;
MDB_txn *txn;
key.mv_size = nKey;
key.mv_data = pKey;
rc = mdb_txn_begin(pMdb->env, NULL, MDB_RDONLY, &txn);
if( rc==0 ){
MDB_val val = {0, 0};
rc = mdb_get(txn, pMdb->dbi, &key, &val);
if( rc==MDB_NOTFOUND ){
rc = 0;
*ppVal = 0;
*pnVal = -1;
}else{
*ppVal = val.mv_data;
*pnVal = val.mv_size;
}
mdb_txn_commit(txn);
}
return rc;
}
int test_mdb_scan(
TestDb *pDb, /* Database handle */
void *pCtx, /* Context pointer to pass to xCallback */
int bReverse, /* True for a reverse order scan */
void *pKey1, int nKey1, /* Start of search */
void *pKey2, int nKey2, /* End of search */
void (*xCallback)(void *pCtx, void *pKey, int nKey, void *pVal, int nVal)
){
MdbDb *pMdb = (MdbDb *)pDb;
int rc;
MDB_cursor_op op = bReverse ? MDB_PREV : MDB_NEXT;
MDB_txn *txn;
rc = mdb_txn_begin(pMdb->env, NULL, MDB_RDONLY, &txn);
if( rc==0 ){
MDB_cursor *csr;
MDB_val key = {0, 0};
MDB_val val = {0, 0};
rc = mdb_cursor_open(txn, pMdb->dbi, &csr);
if( rc==0 ){
while( mdb_cursor_get(csr, &key, &val, op)==0 ){
xCallback(pCtx, key.mv_data, key.mv_size, val.mv_data, val.mv_size);
}
mdb_cursor_close(csr);
}
}
return rc;
}
#endif /* HAVE_MDB */
File diff suppressed because it is too large Load Diff
-980
View File
@@ -1,980 +0,0 @@
/*
** This file contains the TestDb bt wrapper.
*/
#include "lsmtest_tdb.h"
#include "lsmtest.h"
#include <unistd.h>
#include "bt.h"
#include <pthread.h>
typedef struct BtDb BtDb;
typedef struct BtFile BtFile;
/* Background checkpointer interface (see implementations below). */
typedef struct bt_ckpter bt_ckpter;
static int bgc_attach(BtDb *pDb, const char*);
static int bgc_detach(BtDb *pDb);
/*
** Each database or log file opened by a database handle is wrapped by
** an object of the following type.
*/
struct BtFile {
BtDb *pBt; /* Database handle that opened this file */
bt_env *pVfs; /* Underlying VFS */
bt_file *pFile; /* File handle belonging to underlying VFS */
int nSectorSize; /* Size of sectors in bytes */
int nSector; /* Allocated size of nSector array */
u8 **apSector; /* Original sector data */
};
/*
** nCrashSync:
** If this value is non-zero, then a "crash-test" is running. If
** nCrashSync==1, then the crash is simulated during the very next
** call to the xSync() VFS method (on either the db or log file).
** If nCrashSync==2, the following call to xSync(), and so on.
**
** bCrash:
** After a crash is simulated, this variable is set. Any subsequent
** attempts to write to a file or modify the file system in any way
** fail once this is set. All the caller can do is close the connection.
**
** bFastInsert:
** If this variable is set to true, then a BT_CONTROL_FAST_INSERT_OP
** control is issued before each callto BtReplace() or BtCsrOpen().
*/
struct BtDb {
TestDb base; /* Base class */
bt_db *pBt; /* bt database handle */
sqlite4_env *pEnv; /* SQLite environment (for malloc/free) */
bt_env *pVfs; /* Underlying VFS */
int bFastInsert; /* True to use fast-insert */
/* Space for bt_fetch() results */
u8 *aBuffer; /* Space to store results */
int nBuffer; /* Allocated size of aBuffer[] in bytes */
int nRef;
/* Background checkpointer used by mt connections */
bt_ckpter *pCkpter;
/* Stuff used for crash test simulation */
BtFile *apFile[2]; /* Database and log files used by pBt */
bt_env env; /* Private VFS for this object */
int nCrashSync; /* Number of syncs until crash (see above) */
int bCrash; /* True once a crash has been simulated */
};
static int btVfsFullpath(
sqlite4_env *pEnv,
bt_env *pVfs,
const char *z,
char **pzOut
){
BtDb *pBt = (BtDb*)pVfs->pVfsCtx;
if( pBt->bCrash ) return SQLITE4_IOERR;
return pBt->pVfs->xFullpath(pEnv, pBt->pVfs, z, pzOut);
}
static int btVfsOpen(
sqlite4_env *pEnv,
bt_env *pVfs,
const char *zFile,
int flags, bt_file **ppFile
){
BtFile *p;
BtDb *pBt = (BtDb*)pVfs->pVfsCtx;
int rc;
if( pBt->bCrash ) return SQLITE4_IOERR;
p = (BtFile*)testMalloc(sizeof(BtFile));
if( !p ) return SQLITE4_NOMEM;
if( flags & BT_OPEN_DATABASE ){
pBt->apFile[0] = p;
}else if( flags & BT_OPEN_LOG ){
pBt->apFile[1] = p;
}
if( (flags & BT_OPEN_SHARED)==0 ){
p->pBt = pBt;
}
p->pVfs = pBt->pVfs;
rc = pBt->pVfs->xOpen(pEnv, pVfs, zFile, flags, &p->pFile);
if( rc!=SQLITE4_OK ){
testFree(p);
p = 0;
}else{
pBt->nRef++;
}
*ppFile = (bt_file*)p;
return rc;
}
static int btVfsSize(bt_file *pFile, sqlite4_int64 *piRes){
BtFile *p = (BtFile*)pFile;
if( p->pBt && p->pBt->bCrash ) return SQLITE4_IOERR;
return p->pVfs->xSize(p->pFile, piRes);
}
static int btVfsRead(bt_file *pFile, sqlite4_int64 iOff, void *pBuf, int nBuf){
BtFile *p = (BtFile*)pFile;
if( p->pBt && p->pBt->bCrash ) return SQLITE4_IOERR;
return p->pVfs->xRead(p->pFile, iOff, pBuf, nBuf);
}
static int btFlushSectors(BtFile *p, int iFile){
sqlite4_int64 iSz;
int rc;
int i;
u8 *aTmp = 0;
rc = p->pBt->pVfs->xSize(p->pFile, &iSz);
for(i=0; rc==SQLITE4_OK && i<p->nSector; i++){
if( p->pBt->bCrash && p->apSector[i] ){
/* The system is simulating a crash. There are three choices for
** this sector:
**
** 1) Leave it as it is (simulating a successful write),
** 2) Restore the original data (simulating a lost write),
** 3) Populate the disk sector with garbage data.
*/
sqlite4_int64 iSOff = p->nSectorSize*i;
int nWrite = MIN(p->nSectorSize, iSz - iSOff);
if( nWrite ){
u8 *aWrite = 0;
int iOpt = (testPrngValue(i) % 3) + 1;
if( iOpt==1 ){
aWrite = p->apSector[i];
}else if( iOpt==3 ){
if( aTmp==0 ) aTmp = testMalloc(p->nSectorSize);
aWrite = aTmp;
testPrngArray(i*13, (u32*)aWrite, nWrite/sizeof(u32));
}
#if 0
fprintf(stderr, "handle sector %d of %s with %s\n", i,
iFile==0 ? "db" : "log",
iOpt==1 ? "rollback" : iOpt==2 ? "write" : "omit"
);
fflush(stderr);
#endif
if( aWrite ){
rc = p->pBt->pVfs->xWrite(p->pFile, iSOff, aWrite, nWrite);
}
}
}
testFree(p->apSector[i]);
p->apSector[i] = 0;
}
testFree(aTmp);
return rc;
}
static int btSaveSectors(BtFile *p, sqlite4_int64 iOff, int nBuf){
int rc;
sqlite4_int64 iSz; /* Size of file on disk */
int iFirst; /* First sector affected */
int iSector; /* Current sector */
int iLast; /* Last sector affected */
if( p->nSectorSize==0 ){
p->nSectorSize = p->pBt->pVfs->xSectorSize(p->pFile);
if( p->nSectorSize<512 ) p->nSectorSize = 512;
}
iLast = (iOff+nBuf-1) / p->nSectorSize;
iFirst = iOff / p->nSectorSize;
rc = p->pBt->pVfs->xSize(p->pFile, &iSz);
for(iSector=iFirst; rc==SQLITE4_OK && iSector<=iLast; iSector++){
int nRead;
sqlite4_int64 iSOff = iSector * p->nSectorSize;
u8 *aBuf = testMalloc(p->nSectorSize);
nRead = MIN(p->nSectorSize, (iSz - iSOff));
if( nRead>0 ){
rc = p->pBt->pVfs->xRead(p->pFile, iSOff, aBuf, nRead);
}
while( rc==SQLITE4_OK && iSector>=p->nSector ){
int nNew = p->nSector + 32;
u8 **apNew = (u8**)testMalloc(nNew * sizeof(u8*));
memcpy(apNew, p->apSector, p->nSector*sizeof(u8*));
testFree(p->apSector);
p->apSector = apNew;
p->nSector = nNew;
}
p->apSector[iSector] = aBuf;
}
return rc;
}
static int btVfsWrite(bt_file *pFile, sqlite4_int64 iOff, void *pBuf, int nBuf){
BtFile *p = (BtFile*)pFile;
if( p->pBt && p->pBt->bCrash ) return SQLITE4_IOERR;
if( p->pBt && p->pBt->nCrashSync ){
btSaveSectors(p, iOff, nBuf);
}
return p->pVfs->xWrite(p->pFile, iOff, pBuf, nBuf);
}
static int btVfsTruncate(bt_file *pFile, sqlite4_int64 iOff){
BtFile *p = (BtFile*)pFile;
if( p->pBt && p->pBt->bCrash ) return SQLITE4_IOERR;
return p->pVfs->xTruncate(p->pFile, iOff);
}
static int btVfsSync(bt_file *pFile){
int rc = SQLITE4_OK;
BtFile *p = (BtFile*)pFile;
BtDb *pBt = p->pBt;
if( pBt ){
if( pBt->bCrash ) return SQLITE4_IOERR;
if( pBt->nCrashSync ){
pBt->nCrashSync--;
pBt->bCrash = (pBt->nCrashSync==0);
if( pBt->bCrash ){
btFlushSectors(pBt->apFile[0], 0);
btFlushSectors(pBt->apFile[1], 1);
rc = SQLITE4_IOERR;
}else{
btFlushSectors(p, 0);
}
}
}
if( rc==SQLITE4_OK ){
rc = p->pVfs->xSync(p->pFile);
}
return rc;
}
static int btVfsSectorSize(bt_file *pFile){
BtFile *p = (BtFile*)pFile;
return p->pVfs->xSectorSize(p->pFile);
}
static void btDeref(BtDb *p){
p->nRef--;
assert( p->nRef>=0 );
if( p->nRef<=0 ) testFree(p);
}
static int btVfsClose(bt_file *pFile){
BtFile *p = (BtFile*)pFile;
BtDb *pBt = p->pBt;
int rc;
if( pBt ){
btFlushSectors(p, 0);
if( p==pBt->apFile[0] ) pBt->apFile[0] = 0;
if( p==pBt->apFile[1] ) pBt->apFile[1] = 0;
}
testFree(p->apSector);
rc = p->pVfs->xClose(p->pFile);
#if 0
btDeref(p->pBt);
#endif
testFree(p);
return rc;
}
static int btVfsUnlink(sqlite4_env *pEnv, bt_env *pVfs, const char *zFile){
BtDb *pBt = (BtDb*)pVfs->pVfsCtx;
if( pBt->bCrash ) return SQLITE4_IOERR;
return pBt->pVfs->xUnlink(pEnv, pBt->pVfs, zFile);
}
static int btVfsLock(bt_file *pFile, int iLock, int eType){
BtFile *p = (BtFile*)pFile;
if( p->pBt && p->pBt->bCrash ) return SQLITE4_IOERR;
return p->pVfs->xLock(p->pFile, iLock, eType);
}
static int btVfsTestLock(bt_file *pFile, int iLock, int nLock, int eType){
BtFile *p = (BtFile*)pFile;
if( p->pBt && p->pBt->bCrash ) return SQLITE4_IOERR;
return p->pVfs->xTestLock(p->pFile, iLock, nLock, eType);
}
static int btVfsShmMap(bt_file *pFile, int iChunk, int sz, void **ppOut){
BtFile *p = (BtFile*)pFile;
if( p->pBt && p->pBt->bCrash ) return SQLITE4_IOERR;
return p->pVfs->xShmMap(p->pFile, iChunk, sz, ppOut);
}
static void btVfsShmBarrier(bt_file *pFile){
BtFile *p = (BtFile*)pFile;
return p->pVfs->xShmBarrier(p->pFile);
}
static int btVfsShmUnmap(bt_file *pFile, int bDelete){
BtFile *p = (BtFile*)pFile;
if( p->pBt && p->pBt->bCrash ) return SQLITE4_IOERR;
return p->pVfs->xShmUnmap(p->pFile, bDelete);
}
static int bt_close(TestDb *pTestDb){
BtDb *p = (BtDb*)pTestDb;
int rc = sqlite4BtClose(p->pBt);
free(p->aBuffer);
if( p->apFile[0] ) p->apFile[0]->pBt = 0;
if( p->apFile[1] ) p->apFile[1]->pBt = 0;
bgc_detach(p);
testFree(p);
return rc;
}
static int btMinTransaction(BtDb *p, int iMin, int *piLevel){
int iLevel;
int rc = SQLITE4_OK;
iLevel = sqlite4BtTransactionLevel(p->pBt);
if( iLevel<iMin ){
rc = sqlite4BtBegin(p->pBt, iMin);
*piLevel = iLevel;
}else{
*piLevel = -1;
}
return rc;
}
static int btRestoreTransaction(BtDb *p, int iLevel, int rcin){
int rc = rcin;
if( iLevel>=0 ){
if( rc==SQLITE4_OK ){
rc = sqlite4BtCommit(p->pBt, iLevel);
}else{
sqlite4BtRollback(p->pBt, iLevel);
}
assert( iLevel==sqlite4BtTransactionLevel(p->pBt) );
}
return rc;
}
static int bt_write(TestDb *pTestDb, void *pK, int nK, void *pV, int nV){
BtDb *p = (BtDb*)pTestDb;
int iLevel;
int rc;
rc = btMinTransaction(p, 2, &iLevel);
if( rc==SQLITE4_OK ){
if( p->bFastInsert ) sqlite4BtControl(p->pBt, BT_CONTROL_FAST_INSERT_OP, 0);
rc = sqlite4BtReplace(p->pBt, pK, nK, pV, nV);
rc = btRestoreTransaction(p, iLevel, rc);
}
return rc;
}
static int bt_delete(TestDb *pTestDb, void *pK, int nK){
return bt_write(pTestDb, pK, nK, 0, -1);
}
static int bt_delete_range(
TestDb *pTestDb,
void *pKey1, int nKey1,
void *pKey2, int nKey2
){
BtDb *p = (BtDb*)pTestDb;
bt_cursor *pCsr = 0;
int rc = SQLITE4_OK;
int iLevel;
rc = btMinTransaction(p, 2, &iLevel);
if( rc==SQLITE4_OK ){
if( p->bFastInsert ) sqlite4BtControl(p->pBt, BT_CONTROL_FAST_INSERT_OP, 0);
rc = sqlite4BtCsrOpen(p->pBt, 0, &pCsr);
}
while( rc==SQLITE4_OK ){
const void *pK;
int n;
int nCmp;
int res;
rc = sqlite4BtCsrSeek(pCsr, pKey1, nKey1, BT_SEEK_GE);
if( rc==SQLITE4_INEXACT ) rc = SQLITE4_OK;
if( rc!=SQLITE4_OK ) break;
rc = sqlite4BtCsrKey(pCsr, &pK, &n);
if( rc!=SQLITE4_OK ) break;
nCmp = MIN(n, nKey1);
res = memcmp(pKey1, pK, nCmp);
assert( res<0 || (res==0 && nKey1<=n) );
if( res==0 && nKey1==n ){
rc = sqlite4BtCsrNext(pCsr);
if( rc!=SQLITE4_OK ) break;
rc = sqlite4BtCsrKey(pCsr, &pK, &n);
if( rc!=SQLITE4_OK ) break;
}
nCmp = MIN(n, nKey2);
res = memcmp(pKey2, pK, nCmp);
if( res<0 || (res==0 && nKey2<=n) ) break;
rc = sqlite4BtDelete(pCsr);
}
if( rc==SQLITE4_NOTFOUND ) rc = SQLITE4_OK;
sqlite4BtCsrClose(pCsr);
rc = btRestoreTransaction(p, iLevel, rc);
return rc;
}
static int bt_fetch(
TestDb *pTestDb,
void *pK, int nK,
void **ppVal, int *pnVal
){
BtDb *p = (BtDb*)pTestDb;
bt_cursor *pCsr = 0;
int iLevel;
int rc = SQLITE4_OK;
iLevel = sqlite4BtTransactionLevel(p->pBt);
if( iLevel==0 ){
rc = sqlite4BtBegin(p->pBt, 1);
if( rc!=SQLITE4_OK ) return rc;
}
if( p->bFastInsert ) sqlite4BtControl(p->pBt, BT_CONTROL_FAST_INSERT_OP, 0);
rc = sqlite4BtCsrOpen(p->pBt, 0, &pCsr);
if( rc==SQLITE4_OK ){
rc = sqlite4BtCsrSeek(pCsr, pK, nK, BT_SEEK_EQ);
if( rc==SQLITE4_OK ){
const void *pV = 0;
int nV = 0;
rc = sqlite4BtCsrData(pCsr, 0, -1, &pV, &nV);
if( rc==SQLITE4_OK ){
if( nV>p->nBuffer ){
free(p->aBuffer);
p->aBuffer = (u8*)malloc(nV*2);
p->nBuffer = nV*2;
}
memcpy(p->aBuffer, pV, nV);
*pnVal = nV;
*ppVal = (void*)(p->aBuffer);
}
}else if( rc==SQLITE4_INEXACT || rc==SQLITE4_NOTFOUND ){
*ppVal = 0;
*pnVal = -1;
rc = SQLITE4_OK;
}
sqlite4BtCsrClose(pCsr);
}
if( iLevel==0 ) sqlite4BtCommit(p->pBt, 0);
return rc;
}
static int bt_scan(
TestDb *pTestDb,
void *pCtx,
int bReverse,
void *pFirst, int nFirst,
void *pLast, int nLast,
void (*xCallback)(void *, void *, int , void *, int)
){
BtDb *p = (BtDb*)pTestDb;
bt_cursor *pCsr = 0;
int rc;
int iLevel;
rc = btMinTransaction(p, 1, &iLevel);
if( rc==SQLITE4_OK ){
if( p->bFastInsert ) sqlite4BtControl(p->pBt, BT_CONTROL_FAST_INSERT_OP, 0);
rc = sqlite4BtCsrOpen(p->pBt, 0, &pCsr);
}
if( rc==SQLITE4_OK ){
if( bReverse ){
if( pLast ){
rc = sqlite4BtCsrSeek(pCsr, pLast, nLast, BT_SEEK_LE);
}else{
rc = sqlite4BtCsrLast(pCsr);
}
}else{
rc = sqlite4BtCsrSeek(pCsr, pFirst, nFirst, BT_SEEK_GE);
}
if( rc==SQLITE4_INEXACT ) rc = SQLITE4_OK;
while( rc==SQLITE4_OK ){
const void *pK = 0; int nK = 0;
const void *pV = 0; int nV = 0;
rc = sqlite4BtCsrKey(pCsr, &pK, &nK);
if( rc==SQLITE4_OK ){
rc = sqlite4BtCsrData(pCsr, 0, -1, &pV, &nV);
}
if( rc!=SQLITE4_OK ) break;
if( bReverse ){
if( pFirst ){
int res;
int nCmp = MIN(nK, nFirst);
res = memcmp(pFirst, pK, nCmp);
if( res>0 || (res==0 && nK<nFirst) ) break;
}
}else{
if( pLast ){
int res;
int nCmp = MIN(nK, nLast);
res = memcmp(pLast, pK, nCmp);
if( res<0 || (res==0 && nK>nLast) ) break;
}
}
xCallback(pCtx, (void*)pK, nK, (void*)pV, nV);
if( bReverse ){
rc = sqlite4BtCsrPrev(pCsr);
}else{
rc = sqlite4BtCsrNext(pCsr);
}
}
if( rc==SQLITE4_NOTFOUND ) rc = SQLITE4_OK;
sqlite4BtCsrClose(pCsr);
}
rc = btRestoreTransaction(p, iLevel, rc);
return rc;
}
static int bt_begin(TestDb *pTestDb, int iLvl){
BtDb *p = (BtDb*)pTestDb;
int rc = sqlite4BtBegin(p->pBt, iLvl);
return rc;
}
static int bt_commit(TestDb *pTestDb, int iLvl){
BtDb *p = (BtDb*)pTestDb;
int rc = sqlite4BtCommit(p->pBt, iLvl);
return rc;
}
static int bt_rollback(TestDb *pTestDb, int iLvl){
BtDb *p = (BtDb*)pTestDb;
int rc = sqlite4BtRollback(p->pBt, iLvl);
return rc;
}
static int testParseOption(
const char **pzIn, /* IN/OUT: pointer to next option */
const char **pzOpt, /* OUT: nul-terminated option name */
const char **pzArg, /* OUT: nul-terminated option argument */
char *pSpace /* Temporary space for output params */
){
const char *p = *pzIn;
const char *pStart;
int n;
char *pOut = pSpace;
while( *p==' ' ) p++;
pStart = p;
while( *p && *p!='=' ) p++;
if( *p==0 ) return 1;
n = (p - pStart);
memcpy(pOut, pStart, n);
*pzOpt = pOut;
pOut += n;
*pOut++ = '\0';
p++;
pStart = p;
while( *p && *p!=' ' ) p++;
n = (p - pStart);
memcpy(pOut, pStart, n);
*pzArg = pOut;
pOut += n;
*pOut++ = '\0';
*pzIn = p;
return 0;
}
static int testParseInt(const char *z, int *piVal){
int i = 0;
const char *p = z;
while( *p>='0' && *p<='9' ){
i = i*10 + (*p - '0');
p++;
}
if( *p=='K' || *p=='k' ){
i = i * 1024;
p++;
}else if( *p=='M' || *p=='m' ){
i = i * 1024 * 1024;
p++;
}
if( *p ) return SQLITE4_ERROR;
*piVal = i;
return SQLITE4_OK;
}
static int testBtConfigure(BtDb *pDb, const char *zCfg, int *pbMt){
int rc = SQLITE4_OK;
if( zCfg ){
struct CfgParam {
const char *zParam;
int eParam;
} aParam[] = {
{ "safety", BT_CONTROL_SAFETY },
{ "autockpt", BT_CONTROL_AUTOCKPT },
{ "multiproc", BT_CONTROL_MULTIPROC },
{ "blksz", BT_CONTROL_BLKSZ },
{ "pagesz", BT_CONTROL_PAGESZ },
{ "mt", -1 },
{ "fastinsert", -2 },
{ 0, 0 }
};
const char *z = zCfg;
int n = strlen(z);
char *aSpace;
const char *zOpt;
const char *zArg;
aSpace = (char*)testMalloc(n+2);
while( rc==SQLITE4_OK && 0==testParseOption(&z, &zOpt, &zArg, aSpace) ){
int i;
int iVal;
rc = testArgSelect(aParam, "param", zOpt, &i);
if( rc!=SQLITE4_OK ) break;
rc = testParseInt(zArg, &iVal);
if( rc!=SQLITE4_OK ) break;
switch( aParam[i].eParam ){
case -1:
*pbMt = iVal;
break;
case -2:
pDb->bFastInsert = 1;
break;
default:
rc = sqlite4BtControl(pDb->pBt, aParam[i].eParam, (void*)&iVal);
break;
}
}
testFree(aSpace);
}
return rc;
}
int test_bt_open(
const char *zSpec,
const char *zFilename,
int bClear,
TestDb **ppDb
){
static const DatabaseMethods SqlMethods = {
bt_close,
bt_write,
bt_delete,
bt_delete_range,
bt_fetch,
bt_scan,
bt_begin,
bt_commit,
bt_rollback
};
BtDb *p = 0;
bt_db *pBt = 0;
int rc;
sqlite4_env *pEnv = sqlite4_env_default();
if( bClear && zFilename && zFilename[0] ){
char *zLog = sqlite3_mprintf("%s-wal", zFilename);
unlink(zFilename);
unlink(zLog);
sqlite3_free(zLog);
}
rc = sqlite4BtNew(pEnv, 0, &pBt);
if( rc==SQLITE4_OK ){
int mt = 0; /* True for multi-threaded connection */
p = (BtDb*)testMalloc(sizeof(BtDb));
p->base.pMethods = &SqlMethods;
p->pBt = pBt;
p->pEnv = pEnv;
p->nRef = 1;
p->env.pVfsCtx = (void*)p;
p->env.xFullpath = btVfsFullpath;
p->env.xOpen = btVfsOpen;
p->env.xSize = btVfsSize;
p->env.xRead = btVfsRead;
p->env.xWrite = btVfsWrite;
p->env.xTruncate = btVfsTruncate;
p->env.xSync = btVfsSync;
p->env.xSectorSize = btVfsSectorSize;
p->env.xClose = btVfsClose;
p->env.xUnlink = btVfsUnlink;
p->env.xLock = btVfsLock;
p->env.xTestLock = btVfsTestLock;
p->env.xShmMap = btVfsShmMap;
p->env.xShmBarrier = btVfsShmBarrier;
p->env.xShmUnmap = btVfsShmUnmap;
sqlite4BtControl(pBt, BT_CONTROL_GETVFS, (void*)&p->pVfs);
sqlite4BtControl(pBt, BT_CONTROL_SETVFS, (void*)&p->env);
rc = testBtConfigure(p, zSpec, &mt);
if( rc==SQLITE4_OK ){
rc = sqlite4BtOpen(pBt, zFilename);
}
if( rc==SQLITE4_OK && mt ){
int nAuto = 0;
rc = bgc_attach(p, zSpec);
sqlite4BtControl(pBt, BT_CONTROL_AUTOCKPT, (void*)&nAuto);
}
}
if( rc!=SQLITE4_OK && p ){
bt_close(&p->base);
}
*ppDb = &p->base;
return rc;
}
int test_fbt_open(
const char *zSpec,
const char *zFilename,
int bClear,
TestDb **ppDb
){
return test_bt_open("fast=1", zFilename, bClear, ppDb);
}
int test_fbts_open(
const char *zSpec,
const char *zFilename,
int bClear,
TestDb **ppDb
){
return test_bt_open("fast=1 blksz=32K pagesz=512", zFilename, bClear, ppDb);
}
void tdb_bt_prepare_sync_crash(TestDb *pTestDb, int iSync){
BtDb *p = (BtDb*)pTestDb;
assert( pTestDb->pMethods->xClose==bt_close );
assert( p->bCrash==0 );
p->nCrashSync = iSync;
}
bt_db *tdb_bt(TestDb *pDb){
if( pDb->pMethods->xClose==bt_close ){
return ((BtDb *)pDb)->pBt;
}
return 0;
}
/*************************************************************************
** Beginning of code for background checkpointer.
*/
struct bt_ckpter {
sqlite4_buffer file; /* File name */
sqlite4_buffer spec; /* Options */
int nLogsize; /* Minimum log size to checkpoint */
int nRef; /* Number of clients */
int bDoWork; /* Set by client threads */
pthread_t ckpter_thread; /* Checkpointer thread */
pthread_cond_t ckpter_cond; /* Condition var the ckpter waits on */
pthread_mutex_t ckpter_mutex; /* Mutex used with ckpter_cond */
bt_ckpter *pNext; /* Next object in list at gBgc.pCkpter */
};
static struct GlobalBackgroundCheckpointer {
bt_ckpter *pCkpter; /* Linked list of checkpointers */
} gBgc;
static void *bgc_main(void *pArg){
BtDb *pDb = 0;
int rc;
int mt;
bt_ckpter *pCkpter = (bt_ckpter*)pArg;
rc = test_bt_open("", (char*)pCkpter->file.p, 0, (TestDb**)&pDb);
assert( rc==SQLITE4_OK );
rc = testBtConfigure(pDb, (char*)pCkpter->spec.p, &mt);
while( pCkpter->nRef>0 ){
bt_db *db = pDb->pBt;
int nLog = 0;
sqlite4BtBegin(db, 1);
sqlite4BtCommit(db, 0);
sqlite4BtControl(db, BT_CONTROL_LOGSIZE, (void*)&nLog);
if( nLog>=pCkpter->nLogsize ){
int rc;
bt_checkpoint ckpt;
memset(&ckpt, 0, sizeof(bt_checkpoint));
ckpt.nFrameBuffer = nLog/2;
rc = sqlite4BtControl(db, BT_CONTROL_CHECKPOINT, (void*)&ckpt);
assert( rc==SQLITE4_OK );
sqlite4BtControl(db, BT_CONTROL_LOGSIZE, (void*)&nLog);
}
/* The thread will wake up when it is signaled either because another
** thread has created some work for this one or because the connection
** is being closed. */
pthread_mutex_lock(&pCkpter->ckpter_mutex);
if( pCkpter->bDoWork==0 ){
pthread_cond_wait(&pCkpter->ckpter_cond, &pCkpter->ckpter_mutex);
}
pCkpter->bDoWork = 0;
pthread_mutex_unlock(&pCkpter->ckpter_mutex);
}
if( pDb ) bt_close((TestDb*)pDb);
return 0;
}
static void bgc_logsize_cb(void *pCtx, int nLogsize){
bt_ckpter *p = (bt_ckpter*)pCtx;
if( nLogsize>=p->nLogsize ){
pthread_mutex_lock(&p->ckpter_mutex);
p->bDoWork = 1;
pthread_cond_signal(&p->ckpter_cond);
pthread_mutex_unlock(&p->ckpter_mutex);
}
}
static int bgc_attach(BtDb *pDb, const char *zSpec){
int rc;
int n;
bt_info info;
bt_ckpter *pCkpter;
/* Figure out the full path to the database opened by handle pDb. */
info.eType = BT_INFO_FILENAME;
info.pgno = 0;
sqlite4_buffer_init(&info.output, 0);
rc = sqlite4BtControl(pDb->pBt, BT_CONTROL_INFO, (void*)&info);
if( rc!=SQLITE4_OK ) return rc;
sqlite4_mutex_enter(sqlite4_mutex_alloc(pDb->pEnv, SQLITE4_MUTEX_STATIC_KV));
/* Search for an existing bt_ckpter object. */
n = info.output.n;
for(pCkpter=gBgc.pCkpter; pCkpter; pCkpter=pCkpter->pNext){
if( n==pCkpter->file.n && 0==memcmp(info.output.p, pCkpter->file.p, n) ){
break;
}
}
/* Failed to find a suitable checkpointer. Create a new one. */
if( pCkpter==0 ){
bt_logsizecb cb;
pCkpter = testMalloc(sizeof(bt_ckpter));
memcpy(&pCkpter->file, &info.output, sizeof(sqlite4_buffer));
info.output.p = 0;
pCkpter->pNext = gBgc.pCkpter;
pCkpter->nLogsize = 1000;
gBgc.pCkpter = pCkpter;
pCkpter->nRef = 1;
sqlite4_buffer_init(&pCkpter->spec, 0);
rc = sqlite4_buffer_set(&pCkpter->spec, zSpec, strlen(zSpec)+1);
assert( rc==SQLITE4_OK );
/* Kick off the checkpointer thread. */
if( rc==0 ) rc = pthread_cond_init(&pCkpter->ckpter_cond, 0);
if( rc==0 ) rc = pthread_mutex_init(&pCkpter->ckpter_mutex, 0);
if( rc==0 ){
rc = pthread_create(&pCkpter->ckpter_thread, 0, bgc_main, (void*)pCkpter);
}
assert( rc==0 ); /* todo: Fix this */
/* Set up the logsize callback for the client thread */
cb.pCtx = (void*)pCkpter;
cb.xLogsize = bgc_logsize_cb;
sqlite4BtControl(pDb->pBt, BT_CONTROL_LOGSIZECB, (void*)&cb);
}else{
pCkpter->nRef++;
}
/* Assuming a checkpointer was encountered or effected, attach the
** connection to it. */
if( pCkpter ){
pDb->pCkpter = pCkpter;
}
sqlite4_mutex_leave(sqlite4_mutex_alloc(pDb->pEnv, SQLITE4_MUTEX_STATIC_KV));
sqlite4_buffer_clear(&info.output);
return rc;
}
static int bgc_detach(BtDb *pDb){
int rc = SQLITE4_OK;
bt_ckpter *pCkpter = pDb->pCkpter;
if( pCkpter ){
int bShutdown = 0; /* True if this is the last reference */
sqlite4_mutex_enter(sqlite4_mutex_alloc(pDb->pEnv,SQLITE4_MUTEX_STATIC_KV));
pCkpter->nRef--;
if( pCkpter->nRef==0 ){
bt_ckpter **pp;
*pp = pCkpter->pNext;
for(pp=&gBgc.pCkpter; *pp!=pCkpter; pp=&((*pp)->pNext));
bShutdown = 1;
}
sqlite4_mutex_leave(sqlite4_mutex_alloc(pDb->pEnv,SQLITE4_MUTEX_STATIC_KV));
if( bShutdown ){
void *pDummy;
/* Signal the checkpointer thread. */
pthread_mutex_lock(&pCkpter->ckpter_mutex);
pCkpter->bDoWork = 1;
pthread_cond_signal(&pCkpter->ckpter_cond);
pthread_mutex_unlock(&pCkpter->ckpter_mutex);
/* Join the checkpointer thread. */
pthread_join(pCkpter->ckpter_thread, &pDummy);
pthread_cond_destroy(&pCkpter->ckpter_cond);
pthread_mutex_destroy(&pCkpter->ckpter_mutex);
sqlite4_buffer_clear(&pCkpter->file);
sqlite4_buffer_clear(&pCkpter->spec);
testFree(pCkpter);
}
pDb->pCkpter = 0;
}
return rc;
}
/*
** End of background checkpointer.
*************************************************************************/
-223
View File
@@ -1,223 +0,0 @@
#include "lsmtest.h"
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#ifndef _WIN32
# include <sys/time.h>
#endif
/*
** Global variables used within this module.
*/
static struct TestutilGlobal {
char **argv;
int argc;
} g = {0, 0};
static struct TestutilRnd {
unsigned int aRand1[2048]; /* Bits 0..10 */
unsigned int aRand2[2048]; /* Bits 11..21 */
unsigned int aRand3[1024]; /* Bits 22..31 */
} r;
/*************************************************************************
** The following block is a copy of the implementation of SQLite function
** sqlite3_randomness. This version has two important differences:
**
** 1. It always uses the same seed. So the sequence of random data output
** is the same for every run of the program.
**
** 2. It is not threadsafe.
*/
static struct sqlite3PrngType {
unsigned char i, j; /* State variables */
unsigned char s[256]; /* State variables */
} sqlite3Prng = {
0xAF, 0x28,
{
0x71, 0xF5, 0xB4, 0x6E, 0x80, 0xAB, 0x1D, 0xB8,
0xFB, 0xB7, 0x49, 0xBF, 0xFF, 0x72, 0x2D, 0x14,
0x79, 0x09, 0xE3, 0x78, 0x76, 0xB0, 0x2C, 0x0A,
0x8E, 0x23, 0xEE, 0xDF, 0xE0, 0x9A, 0x2F, 0x67,
0xE1, 0xBE, 0x0E, 0xA7, 0x08, 0x97, 0xEB, 0x77,
0x78, 0xBA, 0x9D, 0xCA, 0x49, 0x4C, 0x60, 0x9A,
0xF6, 0xBD, 0xDA, 0x7F, 0xBC, 0x48, 0x58, 0x52,
0xE5, 0xCD, 0x83, 0x72, 0x23, 0x52, 0xFF, 0x6D,
0xEF, 0x0F, 0x82, 0x29, 0xA0, 0x83, 0x3F, 0x7D,
0xA4, 0x88, 0x31, 0xE7, 0x88, 0x92, 0x3B, 0x9B,
0x3B, 0x2C, 0xC2, 0x4C, 0x71, 0xA2, 0xB0, 0xEA,
0x36, 0xD0, 0x00, 0xF1, 0xD3, 0x39, 0x17, 0x5D,
0x2A, 0x7A, 0xE4, 0xAD, 0xE1, 0x64, 0xCE, 0x0F,
0x9C, 0xD9, 0xF5, 0xED, 0xB0, 0x22, 0x5E, 0x62,
0x97, 0x02, 0xA3, 0x8C, 0x67, 0x80, 0xFC, 0x88,
0x14, 0x0B, 0x15, 0x10, 0x0F, 0xC7, 0x40, 0xD4,
0xF1, 0xF9, 0x0E, 0x1A, 0xCE, 0xB9, 0x1E, 0xA1,
0x72, 0x8E, 0xD7, 0x78, 0x39, 0xCD, 0xF4, 0x5D,
0x2A, 0x59, 0x26, 0x34, 0xF2, 0x73, 0x0B, 0xA0,
0x02, 0x51, 0x2C, 0x03, 0xA3, 0xA7, 0x43, 0x13,
0xE8, 0x98, 0x2B, 0xD2, 0x53, 0xF8, 0xEE, 0x91,
0x7D, 0xE7, 0xE3, 0xDA, 0xD5, 0xBB, 0xC0, 0x92,
0x9D, 0x98, 0x01, 0x2C, 0xF9, 0xB9, 0xA0, 0xEB,
0xCF, 0x32, 0xFA, 0x01, 0x49, 0xA5, 0x1D, 0x9A,
0x76, 0x86, 0x3F, 0x40, 0xD4, 0x89, 0x8F, 0x9C,
0xE2, 0xE3, 0x11, 0x31, 0x37, 0xB2, 0x49, 0x28,
0x35, 0xC0, 0x99, 0xB6, 0xD0, 0xBC, 0x66, 0x35,
0xF7, 0x83, 0x5B, 0xD7, 0x37, 0x1A, 0x2B, 0x18,
0xA6, 0xFF, 0x8D, 0x7C, 0x81, 0xA8, 0xFC, 0x9E,
0xC4, 0xEC, 0x80, 0xD0, 0x98, 0xA7, 0x76, 0xCC,
0x9C, 0x2F, 0x7B, 0xFF, 0x8E, 0x0E, 0xBB, 0x90,
0xAE, 0x13, 0x06, 0xF5, 0x1C, 0x4E, 0x52, 0xF7
}
};
/* Generate and return single random byte */
static unsigned char randomByte(void){
unsigned char t;
sqlite3Prng.i++;
t = sqlite3Prng.s[sqlite3Prng.i];
sqlite3Prng.j += t;
sqlite3Prng.s[sqlite3Prng.i] = sqlite3Prng.s[sqlite3Prng.j];
sqlite3Prng.s[sqlite3Prng.j] = t;
t += sqlite3Prng.s[sqlite3Prng.i];
return sqlite3Prng.s[t];
}
/*
** Return N random bytes.
*/
static void randomBlob(int nBuf, unsigned char *zBuf){
int i;
for(i=0; i<nBuf; i++){
zBuf[i] = randomByte();
}
}
/*
** End of code copied from SQLite.
*************************************************************************/
int testPrngInit(void){
randomBlob(sizeof(r.aRand1), (unsigned char *)r.aRand1);
randomBlob(sizeof(r.aRand2), (unsigned char *)r.aRand2);
randomBlob(sizeof(r.aRand3), (unsigned char *)r.aRand3);
return 0;
}
unsigned int testPrngValue(unsigned int iVal){
return
r.aRand1[iVal & 0x000007FF] ^
r.aRand2[(iVal>>11) & 0x000007FF] ^
r.aRand3[(iVal>>22) & 0x000003FF]
;
}
void testPrngArray(unsigned int iVal, unsigned int *aOut, int nOut){
int i;
for(i=0; i<nOut; i++){
aOut[i] = testPrngValue(iVal+i);
}
}
void testPrngString(unsigned int iVal, char *aOut, int nOut){
int i;
for(i=0; i<(nOut-1); i++){
aOut[i] = 'a' + (testPrngValue(iVal+i) % 26);
}
aOut[i] = '\0';
}
void testErrorInit(int argc, char **argv){
g.argc = argc;
g.argv = argv;
}
void testPrintError(const char *zFormat, ...){
va_list ap;
va_start(ap, zFormat);
vfprintf(stderr, zFormat, ap);
va_end(ap);
}
void testPrintFUsage(const char *zFormat, ...){
va_list ap;
va_start(ap, zFormat);
fprintf(stderr, "Usage: %s %s ", g.argv[0], g.argv[1]);
vfprintf(stderr, zFormat, ap);
fprintf(stderr, "\n");
va_end(ap);
}
void testPrintUsage(const char *zArgs){
testPrintError("Usage: %s %s %s\n", g.argv[0], g.argv[1], zArgs);
}
static void argError(void *aData, const char *zType, int sz, const char *zArg){
struct Entry { const char *zName; };
struct Entry *pEntry;
const char *zPrev = 0;
testPrintError("unrecognized %s \"%s\": must be ", zType, zArg);
for(pEntry=(struct Entry *)aData;
pEntry->zName;
pEntry=(struct Entry *)&((unsigned char *)pEntry)[sz]
){
if( zPrev ){ testPrintError("%s, ", zPrev); }
zPrev = pEntry->zName;
}
testPrintError("or %s\n", zPrev);
}
int testArgSelectX(
void *aData,
const char *zType,
int sz,
const char *zArg,
int *piOut
){
struct Entry { const char *zName; };
struct Entry *pEntry;
int nArg = strlen(zArg);
int i = 0;
int iOut = -1;
int nOut = 0;
for(pEntry=(struct Entry *)aData;
pEntry->zName;
pEntry=(struct Entry *)&((unsigned char *)pEntry)[sz]
){
int nName = strlen(pEntry->zName);
if( nArg<=nName && memcmp(pEntry->zName, zArg, nArg)==0 ){
iOut = i;
if( nName==nArg ){
nOut = 1;
break;
}
nOut++;
}
i++;
}
if( nOut!=1 ){
argError(aData, zType, sz, zArg);
}else{
*piOut = iOut;
}
return (nOut!=1);
}
struct timeval zero_time;
void testTimeInit(void){
gettimeofday(&zero_time, 0);
}
int testTimeGet(void){
struct timeval now;
gettimeofday(&now, 0);
return
(((int)now.tv_sec - (int)zero_time.tv_sec)*1000) +
(((int)now.tv_usec - (int)zero_time.tv_usec)/1000);
}
-30
View File
@@ -1,30 +0,0 @@
#include "lsmtest.h"
#ifdef _WIN32
#define TICKS_PER_SECOND (10000000)
#define TICKS_PER_MICROSECOND (10)
#define TICKS_UNIX_EPOCH (116444736000000000LL)
int win32GetTimeOfDay(
struct timeval *tp,
void *tzp
){
FILETIME fileTime;
ULONGLONG ticks;
ULONGLONG unixTicks;
unused_parameter(tzp);
memset(&fileTime, 0, sizeof(FILETIME));
GetSystemTimeAsFileTime(&fileTime);
ticks = (ULONGLONG)fileTime.dwHighDateTime << 32;
ticks |= (ULONGLONG)fileTime.dwLowDateTime;
unixTicks = ticks - TICKS_UNIX_EPOCH;
tp->tv_sec = (long)(unixTicks / TICKS_PER_SECOND);
unixTicks -= ((ULONGLONG)tp->tv_sec * TICKS_PER_SECOND);
tp->tv_usec = (long)(unixTicks / TICKS_PER_MICROSECOND);
return 0;
}
#endif
-684
View File
@@ -1,684 +0,0 @@
/*
** 2011-08-10
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
**
** This file defines the LSM API.
*/
#ifndef _LSM_H
#define _LSM_H
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
** Opaque handle types.
*/
typedef struct lsm_compress lsm_compress; /* Compression library functions */
typedef struct lsm_compress_factory lsm_compress_factory;
typedef struct lsm_cursor lsm_cursor; /* Database cursor handle */
typedef struct lsm_db lsm_db; /* Database connection handle */
typedef struct lsm_env lsm_env; /* Runtime environment */
typedef struct lsm_file lsm_file; /* OS file handle */
typedef struct lsm_mutex lsm_mutex; /* Mutex handle */
/* 64-bit integer type used for file offsets. */
typedef long long int lsm_i64; /* 64-bit signed integer type */
/* Candidate values for the 3rd argument to lsm_env.xLock() */
#define LSM_LOCK_UNLOCK 0
#define LSM_LOCK_SHARED 1
#define LSM_LOCK_EXCL 2
/* Flags for lsm_env.xOpen() */
#define LSM_OPEN_READONLY 0x0001
/*
** CAPI: Database Runtime Environment
**
** Run-time environment used by LSM
*/
struct lsm_env {
int nByte; /* Size of this structure in bytes */
int iVersion; /* Version number of this structure (1) */
/****** file i/o ***********************************************/
void *pVfsCtx;
int (*xFullpath)(lsm_env*, const char *, char *, int *);
int (*xOpen)(lsm_env*, const char *, int flags, lsm_file **);
int (*xRead)(lsm_file *, lsm_i64, void *, int);
int (*xWrite)(lsm_file *, lsm_i64, void *, int);
int (*xTruncate)(lsm_file *, lsm_i64);
int (*xSync)(lsm_file *);
int (*xSectorSize)(lsm_file *);
int (*xRemap)(lsm_file *, lsm_i64, void **, lsm_i64*);
int (*xFileid)(lsm_file *, void *pBuf, int *pnBuf);
int (*xClose)(lsm_file *);
int (*xUnlink)(lsm_env*, const char *);
int (*xLock)(lsm_file*, int, int);
int (*xTestLock)(lsm_file*, int, int, int);
int (*xShmMap)(lsm_file*, int, int, void **);
void (*xShmBarrier)(void);
int (*xShmUnmap)(lsm_file*, int);
/****** memory allocation ****************************************/
void *pMemCtx;
void *(*xMalloc)(lsm_env*, size_t); /* malloc(3) function */
void *(*xRealloc)(lsm_env*, void *, size_t); /* realloc(3) function */
void (*xFree)(lsm_env*, void *); /* free(3) function */
size_t (*xSize)(lsm_env*, void *); /* xSize function */
/****** mutexes ****************************************************/
void *pMutexCtx;
int (*xMutexStatic)(lsm_env*,int,lsm_mutex**); /* Obtain a static mutex */
int (*xMutexNew)(lsm_env*, lsm_mutex**); /* Get a new dynamic mutex */
void (*xMutexDel)(lsm_mutex *); /* Delete an allocated mutex */
void (*xMutexEnter)(lsm_mutex *); /* Grab a mutex */
int (*xMutexTry)(lsm_mutex *); /* Attempt to obtain a mutex */
void (*xMutexLeave)(lsm_mutex *); /* Leave a mutex */
int (*xMutexHeld)(lsm_mutex *); /* Return true if mutex is held */
int (*xMutexNotHeld)(lsm_mutex *); /* Return true if mutex not held */
/****** other ****************************************************/
int (*xSleep)(lsm_env*, int microseconds);
/* New fields may be added in future releases, in which case the
** iVersion value will increase. */
};
/*
** Values that may be passed as the second argument to xMutexStatic.
*/
#define LSM_MUTEX_GLOBAL 1
#define LSM_MUTEX_HEAP 2
/*
** CAPI: LSM Error Codes
*/
#define LSM_OK 0
#define LSM_ERROR 1
#define LSM_BUSY 5
#define LSM_NOMEM 7
#define LSM_READONLY 8
#define LSM_IOERR 10
#define LSM_CORRUPT 11
#define LSM_FULL 13
#define LSM_CANTOPEN 14
#define LSM_PROTOCOL 15
#define LSM_MISUSE 21
#define LSM_MISMATCH 50
#define LSM_IOERR_NOENT (LSM_IOERR | (1<<8))
/*
** CAPI: Creating and Destroying Database Connection Handles
**
** Open and close a database connection handle.
*/
int lsm_new(lsm_env*, lsm_db **ppDb);
int lsm_close(lsm_db *pDb);
/*
** CAPI: Connecting to a Database
*/
int lsm_open(lsm_db *pDb, const char *zFilename);
/*
** CAPI: Obtaining pointers to database environments
**
** Return a pointer to the environment used by the database connection
** passed as the first argument. Assuming the argument is valid, this
** function always returns a valid environment pointer - it cannot fail.
*/
lsm_env *lsm_get_env(lsm_db *pDb);
/*
** The lsm_default_env() function returns a pointer to the default LSM
** environment for the current platform.
*/
lsm_env *lsm_default_env(void);
/*
** CAPI: Configuring a database connection.
**
** The lsm_config() function is used to configure a database connection.
*/
int lsm_config(lsm_db *, int, ...);
/*
** The following values may be passed as the second argument to lsm_config().
**
** LSM_CONFIG_AUTOFLUSH:
** A read/write integer parameter.
**
** This value determines the amount of data allowed to accumulate in a
** live in-memory tree before it is marked as old. After committing a
** transaction, a connection checks if the size of the live in-memory tree,
** including data structure overhead, is greater than the value of this
** option in KB. If it is, and there is not already an old in-memory tree,
** the live in-memory tree is marked as old.
**
** The maximum allowable value is 1048576 (1GB). There is no minimum
** value. If this parameter is set to zero, then an attempt is made to
** mark the live in-memory tree as old after each transaction is committed.
**
** The default value is 1024 (1MB).
**
** LSM_CONFIG_PAGE_SIZE:
** A read/write integer parameter. This parameter may only be set before
** lsm_open() has been called.
**
** LSM_CONFIG_BLOCK_SIZE:
** A read/write integer parameter.
**
** This parameter may only be set before lsm_open() has been called. It
** must be set to a power of two between 64 and 65536, inclusive (block
** sizes between 64KB and 64MB).
**
** If the connection creates a new database, the block size of the new
** database is set to the value of this option in KB. After lsm_open()
** has been called, querying this parameter returns the actual block
** size of the opened database.
**
** The default value is 1024 (1MB blocks).
**
** LSM_CONFIG_SAFETY:
** A read/write integer parameter. Valid values are 0, 1 (the default)
** and 2. This parameter determines how robust the database is in the
** face of a system crash (e.g. a power failure or operating system
** crash). As follows:
**
** 0 (off): No robustness. A system crash may corrupt the database.
**
** 1 (normal): Some robustness. A system crash may not corrupt the
** database file, but recently committed transactions may
** be lost following recovery.
**
** 2 (full): Full robustness. A system crash may not corrupt the
** database file. Following recovery the database file
** contains all successfully committed transactions.
**
** LSM_CONFIG_AUTOWORK:
** A read/write integer parameter.
**
** LSM_CONFIG_AUTOCHECKPOINT:
** A read/write integer parameter.
**
** If this option is set to non-zero value N, then a checkpoint is
** automatically attempted after each N KB of data have been written to
** the database file.
**
** The amount of uncheckpointed data already written to the database file
** is a global parameter. After performing database work (writing to the
** database file), the process checks if the total amount of uncheckpointed
** data exceeds the value of this paramter. If so, a checkpoint is performed.
** This means that this option may cause the connection to perform a
** checkpoint even if the current connection has itself written very little
** data into the database file.
**
** The default value is 2048 (checkpoint every 2MB).
**
** LSM_CONFIG_MMAP:
** A read/write integer parameter. If this value is set to 0, then the
** database file is accessed using ordinary read/write IO functions. Or,
** if it is set to 1, then the database file is memory mapped and accessed
** that way. If this parameter is set to any value N greater than 1, then
** up to the first N KB of the file are memory mapped, and any remainder
** accessed using read/write IO.
**
** The default value is 1 on 64-bit platforms and 32768 on 32-bit platforms.
**
**
** LSM_CONFIG_USE_LOG:
** A read/write boolean parameter. True (the default) to use the log
** file normally. False otherwise.
**
** LSM_CONFIG_AUTOMERGE:
** A read/write integer parameter. The minimum number of segments to
** merge together at a time. Default value 4.
**
** LSM_CONFIG_MAX_FREELIST:
** A read/write integer parameter. The maximum number of free-list
** entries that are stored in a database checkpoint (the others are
** stored elsewhere in the database).
**
** There is no reason for an application to configure or query this
** parameter. It is only present because configuring a small value
** makes certain parts of the lsm code easier to test.
**
** LSM_CONFIG_MULTIPLE_PROCESSES:
** A read/write boolean parameter. This parameter may only be set before
** lsm_open() has been called. If true, the library uses shared-memory
** and posix advisory locks to co-ordinate access by clients from within
** multiple processes. Otherwise, if false, all database clients must be
** located in the same process. The default value is true.
**
** LSM_CONFIG_SET_COMPRESSION:
** Set the compression methods used to compress and decompress database
** content. The argument to this option should be a pointer to a structure
** of type lsm_compress. The lsm_config() method takes a copy of the
** structures contents.
**
** This option may only be used before lsm_open() is called. Invoking it
** after lsm_open() has been called results in an LSM_MISUSE error.
**
** LSM_CONFIG_GET_COMPRESSION:
** Query the compression methods used to compress and decompress database
** content.
**
** LSM_CONFIG_SET_COMPRESSION_FACTORY:
** Configure a factory method to be invoked in case of an LSM_MISMATCH
** error.
**
** LSM_CONFIG_READONLY:
** A read/write boolean parameter. This parameter may only be set before
** lsm_open() is called.
*/
#define LSM_CONFIG_AUTOFLUSH 1
#define LSM_CONFIG_PAGE_SIZE 2
#define LSM_CONFIG_SAFETY 3
#define LSM_CONFIG_BLOCK_SIZE 4
#define LSM_CONFIG_AUTOWORK 5
#define LSM_CONFIG_MMAP 7
#define LSM_CONFIG_USE_LOG 8
#define LSM_CONFIG_AUTOMERGE 9
#define LSM_CONFIG_MAX_FREELIST 10
#define LSM_CONFIG_MULTIPLE_PROCESSES 11
#define LSM_CONFIG_AUTOCHECKPOINT 12
#define LSM_CONFIG_SET_COMPRESSION 13
#define LSM_CONFIG_GET_COMPRESSION 14
#define LSM_CONFIG_SET_COMPRESSION_FACTORY 15
#define LSM_CONFIG_READONLY 16
#define LSM_SAFETY_OFF 0
#define LSM_SAFETY_NORMAL 1
#define LSM_SAFETY_FULL 2
/*
** CAPI: Compression and/or Encryption Hooks
*/
struct lsm_compress {
void *pCtx;
unsigned int iId;
int (*xBound)(void *, int nSrc);
int (*xCompress)(void *, char *, int *, const char *, int);
int (*xUncompress)(void *, char *, int *, const char *, int);
void (*xFree)(void *pCtx);
};
struct lsm_compress_factory {
void *pCtx;
int (*xFactory)(void *, lsm_db *, unsigned int);
void (*xFree)(void *pCtx);
};
#define LSM_COMPRESSION_EMPTY 0
#define LSM_COMPRESSION_NONE 1
/*
** CAPI: Allocating and Freeing Memory
**
** Invoke the memory allocation functions that belong to environment
** pEnv. Or the system defaults if no memory allocation functions have
** been registered.
*/
void *lsm_malloc(lsm_env*, size_t);
void *lsm_realloc(lsm_env*, void *, size_t);
void lsm_free(lsm_env*, void *);
/*
** CAPI: Querying a Connection For Operational Data
**
** Query a database connection for operational statistics or data.
*/
int lsm_info(lsm_db *, int, ...);
int lsm_get_user_version(lsm_db *, unsigned int *);
int lsm_set_user_version(lsm_db *, unsigned int);
/*
** The following values may be passed as the second argument to lsm_info().
**
** LSM_INFO_NWRITE:
** The third parameter should be of type (int *). The location pointed
** to by the third parameter is set to the number of 4KB pages written to
** the database file during the lifetime of this connection.
**
** LSM_INFO_NREAD:
** The third parameter should be of type (int *). The location pointed
** to by the third parameter is set to the number of 4KB pages read from
** the database file during the lifetime of this connection.
**
** LSM_INFO_DB_STRUCTURE:
** The third argument should be of type (char **). The location pointed
** to is populated with a pointer to a nul-terminated string containing
** the string representation of a Tcl data-structure reflecting the
** current structure of the database file. Specifically, the current state
** of the worker snapshot. The returned string should be eventually freed
** by the caller using lsm_free().
**
** The returned list contains one element for each level in the database,
** in order from most to least recent. Each element contains a
** single element for each segment comprising the corresponding level,
** starting with the lhs segment, then each of the rhs segments (if any)
** in order from most to least recent.
**
** Each segment element is itself a list of 4 integer values, as follows:
**
** <ol><li> First page of segment
** <li> Last page of segment
** <li> Root page of segment (if applicable)
** <li> Total number of pages in segment
** </ol>
**
** LSM_INFO_ARRAY_STRUCTURE:
** There should be two arguments passed following this option (i.e. a
** total of four arguments passed to lsm_info()). The first argument
** should be the page number of the first page in a database array
** (perhaps obtained from an earlier INFO_DB_STRUCTURE call). The second
** trailing argument should be of type (char **). The location pointed
** to is populated with a pointer to a nul-terminated string that must
** be eventually freed using lsm_free() by the caller.
**
** The output string contains the text representation of a Tcl list of
** integers. Each pair of integers represent a range of pages used by
** the identified array. For example, if the array occupies database
** pages 993 to 1024, then pages 2048 to 2777, then the returned string
** will be "993 1024 2048 2777".
**
** If the specified integer argument does not correspond to the first
** page of any database array, LSM_ERROR is returned and the output
** pointer is set to a NULL value.
**
** LSM_INFO_LOG_STRUCTURE:
** The third argument should be of type (char **). The location pointed
** to is populated with a pointer to a nul-terminated string containing
** the string representation of a Tcl data-structure. The returned
** string should be eventually freed by the caller using lsm_free().
**
** The Tcl structure returned is a list of six integers that describe
** the current structure of the log file.
**
** LSM_INFO_ARRAY_PAGES:
**
** LSM_INFO_PAGE_ASCII_DUMP:
** As with LSM_INFO_ARRAY_STRUCTURE, there should be two arguments passed
** with calls that specify this option - an integer page number and a
** (char **) used to return a nul-terminated string that must be later
** freed using lsm_free(). In this case the output string is populated
** with a human-readable description of the page content.
**
** If the page cannot be decoded, it is not an error. In this case the
** human-readable output message will report the systems failure to
** interpret the page data.
**
** LSM_INFO_PAGE_HEX_DUMP:
** This argument is similar to PAGE_ASCII_DUMP, except that keys and
** values are represented using hexadecimal notation instead of ascii.
**
** LSM_INFO_FREELIST:
** The third argument should be of type (char **). The location pointed
** to is populated with a pointer to a nul-terminated string containing
** the string representation of a Tcl data-structure. The returned
** string should be eventually freed by the caller using lsm_free().
**
** The Tcl structure returned is a list containing one element for each
** free block in the database. The element itself consists of two
** integers - the block number and the id of the snapshot that freed it.
**
** LSM_INFO_CHECKPOINT_SIZE:
** The third argument should be of type (int *). The location pointed to
** by this argument is populated with the number of KB written to the
** database file since the most recent checkpoint.
**
** LSM_INFO_TREE_SIZE:
** If this value is passed as the second argument to an lsm_info() call, it
** should be followed by two arguments of type (int *) (for a total of four
** arguments).
**
** At any time, there are either one or two tree structures held in shared
** memory that new database clients will access (there may also be additional
** tree structures being used by older clients - this API does not provide
** information on them). One tree structure - the current tree - is used to
** accumulate new data written to the database. The other tree structure -
** the old tree - is a read-only tree holding older data and may be flushed
** to disk at any time.
**
** Assuming no error occurs, the location pointed to by the first of the two
** (int *) arguments is set to the size of the old in-memory tree in KB.
** The second is set to the size of the current, or live in-memory tree.
**
** LSM_INFO_COMPRESSION_ID:
** This value should be followed by a single argument of type
** (unsigned int *). If successful, the location pointed to is populated
** with the database compression id before returning.
*/
#define LSM_INFO_NWRITE 1
#define LSM_INFO_NREAD 2
#define LSM_INFO_DB_STRUCTURE 3
#define LSM_INFO_LOG_STRUCTURE 4
#define LSM_INFO_ARRAY_STRUCTURE 5
#define LSM_INFO_PAGE_ASCII_DUMP 6
#define LSM_INFO_PAGE_HEX_DUMP 7
#define LSM_INFO_FREELIST 8
#define LSM_INFO_ARRAY_PAGES 9
#define LSM_INFO_CHECKPOINT_SIZE 10
#define LSM_INFO_TREE_SIZE 11
#define LSM_INFO_FREELIST_SIZE 12
#define LSM_INFO_COMPRESSION_ID 13
/*
** CAPI: Opening and Closing Write Transactions
**
** These functions are used to open and close transactions and nested
** sub-transactions.
**
** The lsm_begin() function is used to open transactions and sub-transactions.
** A successful call to lsm_begin() ensures that there are at least iLevel
** nested transactions open. To open a top-level transaction, pass iLevel=1.
** To open a sub-transaction within the top-level transaction, iLevel=2.
** Passing iLevel=0 is a no-op.
**
** lsm_commit() is used to commit transactions and sub-transactions. A
** successful call to lsm_commit() ensures that there are at most iLevel
** nested transactions open. To commit a top-level transaction, pass iLevel=0.
** To commit all sub-transactions inside the main transaction, pass iLevel=1.
**
** Function lsm_rollback() is used to roll back transactions and
** sub-transactions. A successful call to lsm_rollback() restores the database
** to the state it was in when the iLevel'th nested sub-transaction (if any)
** was first opened. And then closes transactions to ensure that there are
** at most iLevel nested transactions open. Passing iLevel=0 rolls back and
** closes the top-level transaction. iLevel=1 also rolls back the top-level
** transaction, but leaves it open. iLevel=2 rolls back the sub-transaction
** nested directly inside the top-level transaction (and leaves it open).
*/
int lsm_begin(lsm_db *pDb, int iLevel);
int lsm_commit(lsm_db *pDb, int iLevel);
int lsm_rollback(lsm_db *pDb, int iLevel);
/*
** CAPI: Writing to a Database
**
** Write a new value into the database. If a value with a duplicate key
** already exists it is replaced.
*/
int lsm_insert(lsm_db*, const void *pKey, int nKey, const void *pVal, int nVal);
/*
** Delete a value from the database. No error is returned if the specified
** key value does not exist in the database.
*/
int lsm_delete(lsm_db *, const void *pKey, int nKey);
/*
** Delete all database entries with keys that are greater than (pKey1/nKey1)
** and smaller than (pKey2/nKey2). Note that keys (pKey1/nKey1) and
** (pKey2/nKey2) themselves, if they exist in the database, are not deleted.
**
** Return LSM_OK if successful, or an LSM error code otherwise.
*/
int lsm_delete_range(lsm_db *,
const void *pKey1, int nKey1, const void *pKey2, int nKey2
);
/*
** CAPI: Explicit Database Work and Checkpointing
**
** This function is called by a thread to work on the database structure.
*/
int lsm_work(lsm_db *pDb, int nMerge, int nKB, int *pnWrite);
int lsm_flush(lsm_db *pDb);
/*
** Attempt to checkpoint the current database snapshot. Return an LSM
** error code if an error occurs or LSM_OK otherwise.
**
** If the current snapshot has already been checkpointed, calling this
** function is a no-op. In this case if pnKB is not NULL, *pnKB is
** set to 0. Or, if the current snapshot is successfully checkpointed
** by this function and pbKB is not NULL, *pnKB is set to the number
** of bytes written to the database file since the previous checkpoint
** (the same measure as returned by the LSM_INFO_CHECKPOINT_SIZE query).
*/
int lsm_checkpoint(lsm_db *pDb, int *pnKB);
/*
** CAPI: Opening and Closing Database Cursors
**
** Open and close a database cursor.
*/
int lsm_csr_open(lsm_db *pDb, lsm_cursor **ppCsr);
int lsm_csr_close(lsm_cursor *pCsr);
/*
** CAPI: Positioning Database Cursors
**
** If the fourth parameter is LSM_SEEK_EQ, LSM_SEEK_GE or LSM_SEEK_LE,
** this function searches the database for an entry with key (pKey/nKey).
** If an error occurs, an LSM error code is returned. Otherwise, LSM_OK.
**
** If no error occurs and the requested key is present in the database, the
** cursor is left pointing to the entry with the specified key. Or, if the
** specified key is not present in the database the state of the cursor
** depends on the value passed as the final parameter, as follows:
**
** LSM_SEEK_EQ:
** The cursor is left at EOF (invalidated). A call to lsm_csr_valid()
** returns non-zero.
**
** LSM_SEEK_LE:
** The cursor is left pointing to the largest key in the database that
** is smaller than (pKey/nKey). If the database contains no keys smaller
** than (pKey/nKey), the cursor is left at EOF.
**
** LSM_SEEK_GE:
** The cursor is left pointing to the smallest key in the database that
** is larger than (pKey/nKey). If the database contains no keys larger
** than (pKey/nKey), the cursor is left at EOF.
**
** If the fourth parameter is LSM_SEEK_LEFAST, this function searches the
** database in a similar manner to LSM_SEEK_LE, with two differences:
**
** <ol><li>Even if a key can be found (the cursor is not left at EOF), the
** lsm_csr_value() function may not be used (attempts to do so return
** LSM_MISUSE).
**
** <li>The key that the cursor is left pointing to may be one that has
** been recently deleted from the database. In this case it is
** guaranteed that the returned key is larger than any key currently
** in the database that is less than or equal to (pKey/nKey).
** </ol>
**
** LSM_SEEK_LEFAST requests are intended to be used to allocate database
** keys.
*/
int lsm_csr_seek(lsm_cursor *pCsr, const void *pKey, int nKey, int eSeek);
int lsm_csr_first(lsm_cursor *pCsr);
int lsm_csr_last(lsm_cursor *pCsr);
/*
** Advance the specified cursor to the next or previous key in the database.
** Return LSM_OK if successful, or an LSM error code otherwise.
**
** Functions lsm_csr_seek(), lsm_csr_first() and lsm_csr_last() are "seek"
** functions. Whether or not lsm_csr_next and lsm_csr_prev may be called
** successfully also depends on the most recent seek function called on
** the cursor. Specifically:
**
** <ul>
** <li> At least one seek function must have been called on the cursor.
** <li> To call lsm_csr_next(), the most recent call to a seek function must
** have been either lsm_csr_first() or a call to lsm_csr_seek() specifying
** LSM_SEEK_GE.
** <li> To call lsm_csr_prev(), the most recent call to a seek function must
** have been either lsm_csr_last() or a call to lsm_csr_seek() specifying
** LSM_SEEK_LE.
** </ul>
**
** Otherwise, if the above conditions are not met when lsm_csr_next or
** lsm_csr_prev is called, LSM_MISUSE is returned and the cursor position
** remains unchanged.
*/
int lsm_csr_next(lsm_cursor *pCsr);
int lsm_csr_prev(lsm_cursor *pCsr);
/*
** Values that may be passed as the fourth argument to lsm_csr_seek().
*/
#define LSM_SEEK_LEFAST -2
#define LSM_SEEK_LE -1
#define LSM_SEEK_EQ 0
#define LSM_SEEK_GE 1
/*
** CAPI: Extracting Data From Database Cursors
**
** Retrieve data from a database cursor.
*/
int lsm_csr_valid(lsm_cursor *pCsr);
int lsm_csr_key(lsm_cursor *pCsr, const void **ppKey, int *pnKey);
int lsm_csr_value(lsm_cursor *pCsr, const void **ppVal, int *pnVal);
/*
** If no error occurs, this function compares the database key passed via
** the pKey/nKey arguments with the key that the cursor passed as the first
** argument currently points to. If the cursors key is less than, equal to
** or greater than pKey/nKey, *piRes is set to less than, equal to or greater
** than zero before returning. LSM_OK is returned in this case.
**
** Or, if an error occurs, an LSM error code is returned and the final
** value of *piRes is undefined. If the cursor does not point to a valid
** key when this function is called, LSM_MISUSE is returned.
*/
int lsm_csr_cmp(lsm_cursor *pCsr, const void *pKey, int nKey, int *piRes);
/*
** CAPI: Change these!!
**
** Configure a callback to which debugging and other messages should
** be directed. Only useful for debugging lsm.
*/
void lsm_config_log(lsm_db *, void (*)(void *, int, const char *), void *);
/*
** Configure a callback that is invoked if the database connection ever
** writes to the database file.
*/
void lsm_config_work_hook(lsm_db *, void (*)(lsm_db *, void *), void *);
/* ENDOFAPI */
#ifdef __cplusplus
} /* End of the 'extern "C"' block */
#endif
#endif /* ifndef _LSM_H */
-997
View File
@@ -1,997 +0,0 @@
/*
** 2011-08-18
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** Internal structure definitions for the LSM module.
*/
#ifndef _LSM_INT_H
#define _LSM_INT_H
#include "lsm.h"
#include <assert.h>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#ifdef _WIN32
# ifdef _MSC_VER
# define snprintf _snprintf
# endif
#else
# include <unistd.h>
#endif
#ifdef NDEBUG
# ifdef LSM_DEBUG_EXPENSIVE
# undef LSM_DEBUG_EXPENSIVE
# endif
# ifdef LSM_DEBUG
# undef LSM_DEBUG
# endif
#else
# ifndef LSM_DEBUG
# define LSM_DEBUG
# endif
#endif
/* #define LSM_DEBUG_EXPENSIVE 1 */
/*
** Default values for various data structure parameters. These may be
** overridden by calls to lsm_config().
*/
#define LSM_DFLT_PAGE_SIZE (4 * 1024)
#define LSM_DFLT_BLOCK_SIZE (1 * 1024 * 1024)
#define LSM_DFLT_AUTOFLUSH (1 * 1024 * 1024)
#define LSM_DFLT_AUTOCHECKPOINT (i64)(2 * 1024 * 1024)
#define LSM_DFLT_AUTOWORK 1
#define LSM_DFLT_LOG_SIZE (128*1024)
#define LSM_DFLT_AUTOMERGE 4
#define LSM_DFLT_SAFETY LSM_SAFETY_NORMAL
#define LSM_DFLT_MMAP (LSM_IS_64_BIT ? 1 : 32768)
#define LSM_DFLT_MULTIPLE_PROCESSES 1
#define LSM_DFLT_USE_LOG 1
/* Initial values for log file checksums. These are only used if the
** database file does not contain a valid checkpoint. */
#define LSM_CKSUM0_INIT 42
#define LSM_CKSUM1_INIT 42
/* "mmap" mode is currently only used in environments with 64-bit address
** spaces. The following macro is used to test for this. */
#define LSM_IS_64_BIT (sizeof(void*)==8)
#define LSM_AUTOWORK_QUANT 32
typedef struct Database Database;
typedef struct DbLog DbLog;
typedef struct FileSystem FileSystem;
typedef struct Freelist Freelist;
typedef struct FreelistEntry FreelistEntry;
typedef struct Level Level;
typedef struct LogMark LogMark;
typedef struct LogRegion LogRegion;
typedef struct LogWriter LogWriter;
typedef struct LsmString LsmString;
typedef struct Mempool Mempool;
typedef struct Merge Merge;
typedef struct MergeInput MergeInput;
typedef struct MetaPage MetaPage;
typedef struct MultiCursor MultiCursor;
typedef struct Page Page;
typedef struct Redirect Redirect;
typedef struct Segment Segment;
typedef struct SegmentMerger SegmentMerger;
typedef struct ShmChunk ShmChunk;
typedef struct ShmHeader ShmHeader;
typedef struct ShmReader ShmReader;
typedef struct Snapshot Snapshot;
typedef struct TransMark TransMark;
typedef struct Tree Tree;
typedef struct TreeCursor TreeCursor;
typedef struct TreeHeader TreeHeader;
typedef struct TreeMark TreeMark;
typedef struct TreeRoot TreeRoot;
#ifndef _SQLITEINT_H_
typedef unsigned char u8;
typedef unsigned short int u16;
typedef unsigned int u32;
typedef lsm_i64 i64;
typedef unsigned long long int u64;
#endif
/* A page number is a 64-bit integer. */
typedef i64 LsmPgno;
#ifdef LSM_DEBUG
int lsmErrorBkpt(int);
#else
# define lsmErrorBkpt(x) (x)
#endif
#define LSM_PROTOCOL_BKPT lsmErrorBkpt(LSM_PROTOCOL)
#define LSM_IOERR_BKPT lsmErrorBkpt(LSM_IOERR)
#define LSM_NOMEM_BKPT lsmErrorBkpt(LSM_NOMEM)
#define LSM_CORRUPT_BKPT lsmErrorBkpt(LSM_CORRUPT)
#define LSM_MISUSE_BKPT lsmErrorBkpt(LSM_MISUSE)
#define unused_parameter(x) (void)(x)
#define array_size(x) (sizeof(x)/sizeof(x[0]))
/* The size of each shared-memory chunk */
#define LSM_SHM_CHUNK_SIZE (32*1024)
/* The number of bytes reserved at the start of each shm chunk for MM. */
#define LSM_SHM_CHUNK_HDR (sizeof(ShmChunk))
/* The number of available read locks. */
#define LSM_LOCK_NREADER 6
/* The number of available read-write client locks. */
#define LSM_LOCK_NRWCLIENT 16
/* Lock definitions.
*/
#define LSM_LOCK_DMS1 1 /* Serialize connect/disconnect ops */
#define LSM_LOCK_DMS2 2 /* Read-write connections */
#define LSM_LOCK_DMS3 3 /* Read-only connections */
#define LSM_LOCK_WRITER 4
#define LSM_LOCK_WORKER 5
#define LSM_LOCK_CHECKPOINTER 6
#define LSM_LOCK_ROTRANS 7
#define LSM_LOCK_READER(i) ((i) + LSM_LOCK_ROTRANS + 1)
#define LSM_LOCK_RWCLIENT(i) ((i) + LSM_LOCK_READER(LSM_LOCK_NREADER))
#define LSM_N_LOCK LSM_LOCK_RWCLIENT(LSM_LOCK_NRWCLIENT)
/*
** Meta-page size and usable size.
*/
#define LSM_META_PAGE_SIZE 4096
#define LSM_META_RW_PAGE_SIZE (LSM_META_PAGE_SIZE - LSM_N_LOCK)
/*
** Hard limit on the number of free-list entries that may be stored in
** a checkpoint (the remainder are stored as a system record in the LSM).
** See also LSM_CONFIG_MAX_FREELIST.
*/
#define LSM_MAX_FREELIST_ENTRIES 24
#define LSM_MAX_BLOCK_REDIRECTS 16
#define LSM_ATTEMPTS_BEFORE_PROTOCOL 10000
/*
** Each entry stored in the LSM (or in-memory tree structure) has an
** associated mask of the following flags.
*/
#define LSM_START_DELETE 0x01 /* Start of open-ended delete range */
#define LSM_END_DELETE 0x02 /* End of open-ended delete range */
#define LSM_POINT_DELETE 0x04 /* Delete this key */
#define LSM_INSERT 0x08 /* Insert this key and value */
#define LSM_SEPARATOR 0x10 /* True if entry is separator key only */
#define LSM_SYSTEMKEY 0x20 /* True if entry is a system key (FREELIST) */
#define LSM_CONTIGUOUS 0x40 /* Used in lsm_tree.c */
/*
** A string that can grow by appending.
*/
struct LsmString {
lsm_env *pEnv; /* Run-time environment */
int n; /* Size of string. -1 indicates error */
int nAlloc; /* Space allocated for z[] */
char *z; /* The string content */
};
typedef struct LsmFile LsmFile;
struct LsmFile {
lsm_file *pFile;
LsmFile *pNext;
};
/*
** An instance of the following type is used to store an ordered list of
** u32 values.
**
** Note: This is a place-holder implementation. It should be replaced by
** a version that avoids making a single large allocation when the array
** contains a large number of values. For this reason, the internals of
** this object should only manipulated by the intArrayXXX() functions in
** lsm_tree.c.
*/
typedef struct IntArray IntArray;
struct IntArray {
int nAlloc;
int nArray;
u32 *aArray;
};
struct Redirect {
int n; /* Number of redirects */
struct RedirectEntry {
int iFrom;
int iTo;
} *a;
};
/*
** An instance of this structure represents a point in the history of the
** tree structure to roll back to. Refer to comments in lsm_tree.c for
** details.
*/
struct TreeMark {
u32 iRoot; /* Offset of root node in shm file */
u32 nHeight; /* Current height of tree structure */
u32 iWrite; /* Write offset in shm file */
u32 nChunk; /* Number of chunks in shared-memory file */
u32 iFirst; /* First chunk in linked list */
u32 iNextShmid; /* Next id to allocate */
int iRollback; /* Index in lsm->rollback to revert to */
};
/*
** An instance of this structure represents a point in the database log.
*/
struct LogMark {
i64 iOff; /* Offset into log (see lsm_log.c) */
int nBuf; /* Size of in-memory buffer here */
u8 aBuf[8]; /* Bytes of content in aBuf[] */
u32 cksum0; /* Checksum 0 at offset (iOff-nBuf) */
u32 cksum1; /* Checksum 1 at offset (iOff-nBuf) */
};
struct TransMark {
TreeMark tree;
LogMark log;
};
/*
** A structure that defines the start and end offsets of a region in the
** log file. The size of the region in bytes is (iEnd - iStart), so if
** iEnd==iStart the region is zero bytes in size.
*/
struct LogRegion {
i64 iStart; /* Start of region in log file */
i64 iEnd; /* End of region in log file */
};
struct DbLog {
u32 cksum0; /* Checksum 0 at offset iOff */
u32 cksum1; /* Checksum 1 at offset iOff */
i64 iSnapshotId; /* Log space has been reclaimed to this ss */
LogRegion aRegion[3]; /* Log file regions (see docs in lsm_log.c) */
};
struct TreeRoot {
u32 iRoot;
u32 nHeight;
u32 nByte; /* Total size of this tree in bytes */
u32 iTransId;
};
/*
** Tree header structure.
*/
struct TreeHeader {
u32 iUsedShmid; /* Id of first shm chunk used by this tree */
u32 iNextShmid; /* Shm-id of next chunk allocated */
u32 iFirst; /* Chunk number of smallest shm-id */
u32 nChunk; /* Number of chunks in shared-memory file */
TreeRoot root; /* Root and height of current tree */
u32 iWrite; /* Write offset in shm file */
TreeRoot oldroot; /* Root and height of the previous tree */
u32 iOldShmid; /* Last shm-id used by previous tree */
u32 iUsrVersion; /* get/set_user_version() value */
i64 iOldLog; /* Log offset associated with old tree */
u32 oldcksum0;
u32 oldcksum1;
DbLog log; /* Current layout of log file */
u32 aCksum[2]; /* Checksums 1 and 2. */
};
/*
** Database handle structure.
**
** mLock:
** A bitmask representing the locks currently held by the connection.
** An LSM database supports N distinct locks, where N is some number less
** than or equal to 32. Locks are numbered starting from 1 (see the
** definitions for LSM_LOCK_WRITER and co.).
**
** The least significant 32-bits in mLock represent EXCLUSIVE locks. The
** most significant are SHARED locks. So, if a connection holds a SHARED
** lock on lock region iLock, then the following is true:
**
** (mLock & ((iLock+32-1) << 1))
**
** Or for an EXCLUSIVE lock:
**
** (mLock & ((iLock-1) << 1))
**
** pCsr:
** Points to the head of a linked list that contains all currently open
** cursors. Once this list becomes empty, the user has no outstanding
** cursors and the database handle can be successfully closed.
**
** pCsrCache:
** This list contains cursor objects that have been closed using
** lsm_csr_close(). Each time a cursor is closed, it is shifted from
** the pCsr list to this list. When a new cursor is opened, this list
** is inspected to see if there exists a cursor object that can be
** reused. This is an optimization only.
*/
struct lsm_db {
/* Database handle configuration */
lsm_env *pEnv; /* runtime environment */
int (*xCmp)(void *, int, void *, int); /* Compare function */
/* Values configured by calls to lsm_config */
int eSafety; /* LSM_SAFETY_OFF, NORMAL or FULL */
int bAutowork; /* Configured by LSM_CONFIG_AUTOWORK */
int nTreeLimit; /* Configured by LSM_CONFIG_AUTOFLUSH */
int nMerge; /* Configured by LSM_CONFIG_AUTOMERGE */
int bUseLog; /* Configured by LSM_CONFIG_USE_LOG */
int nDfltPgsz; /* Configured by LSM_CONFIG_PAGE_SIZE */
int nDfltBlksz; /* Configured by LSM_CONFIG_BLOCK_SIZE */
int nMaxFreelist; /* Configured by LSM_CONFIG_MAX_FREELIST */
int iMmap; /* Configured by LSM_CONFIG_MMAP */
i64 nAutockpt; /* Configured by LSM_CONFIG_AUTOCHECKPOINT */
int bMultiProc; /* Configured by L_C_MULTIPLE_PROCESSES */
int bReadonly; /* Configured by LSM_CONFIG_READONLY */
lsm_compress compress; /* Compression callbacks */
lsm_compress_factory factory; /* Compression callback factory */
/* Sub-system handles */
FileSystem *pFS; /* On-disk portion of database */
Database *pDatabase; /* Database shared data */
int iRwclient; /* Read-write client lock held (-1 == none) */
/* Client transaction context */
Snapshot *pClient; /* Client snapshot */
int iReader; /* Read lock held (-1 == unlocked) */
int bRoTrans; /* True if a read-only db trans is open */
MultiCursor *pCsr; /* List of all open cursors */
LogWriter *pLogWriter; /* Context for writing to the log file */
int nTransOpen; /* Number of opened write transactions */
int nTransAlloc; /* Allocated size of aTrans[] array */
TransMark *aTrans; /* Array of marks for transaction rollback */
IntArray rollback; /* List of tree-nodes to roll back */
int bDiscardOld; /* True if lsmTreeDiscardOld() was called */
MultiCursor *pCsrCache; /* List of all closed cursors */
/* Worker context */
Snapshot *pWorker; /* Worker snapshot (or NULL) */
Freelist *pFreelist; /* See sortedNewToplevel() */
int bUseFreelist; /* True to use pFreelist */
int bIncrMerge; /* True if currently doing a merge */
int bInFactory; /* True if within factory.xFactory() */
/* Debugging message callback */
void (*xLog)(void *, int, const char *);
void *pLogCtx;
/* Work done notification callback */
void (*xWork)(lsm_db *, void *);
void *pWorkCtx;
u64 mLock; /* Mask of current locks. See lsmShmLock(). */
lsm_db *pNext; /* Next connection to same database */
int nShm; /* Size of apShm[] array */
void **apShm; /* Shared memory chunks */
ShmHeader *pShmhdr; /* Live shared-memory header */
TreeHeader treehdr; /* Local copy of tree-header */
u32 aSnapshot[LSM_META_PAGE_SIZE / sizeof(u32)];
};
struct Segment {
LsmPgno iFirst; /* First page of this run */
LsmPgno iLastPg; /* Last page of this run */
LsmPgno iRoot; /* Root page number (if any) */
LsmPgno nSize; /* Size of this run in pages */
Redirect *pRedirect; /* Block redirects (or NULL) */
};
/*
** iSplitTopic/pSplitKey/nSplitKey:
** If nRight>0, this buffer contains a copy of the largest key that has
** already been written to the left-hand-side of the level.
*/
struct Level {
Segment lhs; /* Left-hand (main) segment */
int nRight; /* Size of apRight[] array */
Segment *aRhs; /* Old segments being merged into this */
int iSplitTopic; /* Split key topic (if nRight>0) */
void *pSplitKey; /* Pointer to split-key (if nRight>0) */
int nSplitKey; /* Number of bytes in split-key */
u16 iAge; /* Number of times data has been written */
u16 flags; /* Mask of LEVEL_XXX bits */
Merge *pMerge; /* Merge operation currently underway */
Level *pNext; /* Next level in tree */
};
/*
** The Level.flags field is set to a combination of the following bits.
**
** LEVEL_FREELIST_ONLY:
** Set if the level consists entirely of free-list entries.
**
** LEVEL_INCOMPLETE:
** This is set while a new toplevel level is being constructed. It is
** never set for any level other than a new toplevel.
*/
#define LEVEL_FREELIST_ONLY 0x0001
#define LEVEL_INCOMPLETE 0x0002
/*
** A structure describing an ongoing merge. There is an instance of this
** structure for every Level currently undergoing a merge in the worker
** snapshot.
**
** It is assumed that code that uses an instance of this structure has
** access to the associated Level struct.
**
** iOutputOff:
** The byte offset to write to next within the last page of the
** output segment.
*/
struct MergeInput {
LsmPgno iPg; /* Page on which next input is stored */
int iCell; /* Cell containing next input to merge */
};
struct Merge {
int nInput; /* Number of input runs being merged */
MergeInput *aInput; /* Array nInput entries in size */
MergeInput splitkey; /* Location in file of current splitkey */
int nSkip; /* Number of separators entries to skip */
int iOutputOff; /* Write offset on output page */
LsmPgno iCurrentPtr; /* Current pointer value */
};
/*
** The first argument to this macro is a pointer to a Segment structure.
** Returns true if the structure instance indicates that the separators
** array is valid.
*/
#define segmentHasSeparators(pSegment) ((pSegment)->sep.iFirst>0)
/*
** The values that accompany the lock held by a database reader.
*/
struct ShmReader {
u32 iTreeId;
i64 iLsmId;
};
/*
** An instance of this structure is stored in the first shared-memory
** page. The shared-memory header.
**
** bWriter:
** Immediately after opening a write transaction taking the WRITER lock,
** each writer client sets this flag. It is cleared right before the
** WRITER lock is relinquished. If a subsequent writer finds that this
** flag is already set when a write transaction is opened, this indicates
** that a previous writer failed mid-transaction.
**
** iMetaPage:
** If the database file does not contain a valid, synced, checkpoint, this
** value is set to 0. Otherwise, it is set to the meta-page number that
** contains the most recently written checkpoint (either 1 or 2).
**
** hdr1, hdr2:
** The two copies of the in-memory tree header. Two copies are required
** in case a writer fails while updating one of them.
*/
struct ShmHeader {
u32 aSnap1[LSM_META_PAGE_SIZE / 4];
u32 aSnap2[LSM_META_PAGE_SIZE / 4];
u32 bWriter;
u32 iMetaPage;
TreeHeader hdr1;
TreeHeader hdr2;
ShmReader aReader[LSM_LOCK_NREADER];
};
/*
** An instance of this structure is stored at the start of each shared-memory
** chunk except the first (which is the header chunk - see above).
*/
struct ShmChunk {
u32 iShmid;
u32 iNext;
};
/*
** Maximum number of shared-memory chunks allowed in the *-shm file. Since
** each shared-memory chunk is 32KB in size, this is a theoretical limit only.
*/
#define LSM_MAX_SHMCHUNKS (1<<30)
/* Return true if shm-sequence "a" is larger than or equal to "b" */
#define shm_sequence_ge(a, b) (((u32)a-(u32)b) < LSM_MAX_SHMCHUNKS)
#define LSM_APPLIST_SZ 4
/*
** An instance of the following structure stores the in-memory part of
** the current free block list. This structure is to the free block list
** as the in-memory tree is to the users database content. The contents
** of the free block list is found by merging the in-memory components
** with those stored in the LSM, just as the contents of the database is
** found by merging the in-memory tree with the user data entries in the
** LSM.
**
** Each FreelistEntry structure in the array represents either an insert
** or delete operation on the free-list. For deletes, the FreelistEntry.iId
** field is set to -1. For inserts, it is set to zero or greater.
**
** The array of FreelistEntry structures is always sorted in order of
** block number (ascending).
**
** When the in-memory free block list is written into the LSM, each insert
** operation is written separately. The entry key is the bitwise inverse
** of the block number as a 32-bit big-endian integer. This is done so that
** the entries in the LSM are sorted in descending order of block id.
** The associated value is the snapshot id, formated as a varint.
*/
struct Freelist {
FreelistEntry *aEntry; /* Free list entries */
int nEntry; /* Number of valid slots in aEntry[] */
int nAlloc; /* Allocated size of aEntry[] */
};
struct FreelistEntry {
u32 iBlk; /* Block number */
i64 iId; /* Largest snapshot id to use this block */
};
/*
** A snapshot of a database. A snapshot contains all the information required
** to read or write a database file on disk. See the description of struct
** Database below for further details.
*/
struct Snapshot {
Database *pDatabase; /* Database this snapshot belongs to */
u32 iCmpId; /* Id of compression scheme */
Level *pLevel; /* Pointer to level 0 of snapshot (or NULL) */
i64 iId; /* Snapshot id */
i64 iLogOff; /* Log file offset */
Redirect redirect; /* Block redirection array */
/* Used by worker snapshots only */
int nBlock; /* Number of blocks in database file */
LsmPgno aiAppend[LSM_APPLIST_SZ]; /* Append point list */
Freelist freelist; /* Free block list */
u32 nWrite; /* Total number of pages written to disk */
};
#define LSM_INITIAL_SNAPSHOT_ID 11
/*
** Functions from file "lsm_ckpt.c".
*/
int lsmCheckpointWrite(lsm_db *, u32 *);
int lsmCheckpointLevels(lsm_db *, int, void **, int *);
int lsmCheckpointLoadLevels(lsm_db *pDb, void *pVal, int nVal);
int lsmCheckpointRecover(lsm_db *);
int lsmCheckpointDeserialize(lsm_db *, int, u32 *, Snapshot **);
int lsmCheckpointLoadWorker(lsm_db *pDb);
int lsmCheckpointStore(lsm_db *pDb, int);
int lsmCheckpointLoad(lsm_db *pDb, int *);
int lsmCheckpointLoadOk(lsm_db *pDb, int);
int lsmCheckpointClientCacheOk(lsm_db *);
u32 lsmCheckpointNBlock(u32 *);
i64 lsmCheckpointId(u32 *, int);
u32 lsmCheckpointNWrite(u32 *, int);
i64 lsmCheckpointLogOffset(u32 *);
int lsmCheckpointPgsz(u32 *);
int lsmCheckpointBlksz(u32 *);
void lsmCheckpointLogoffset(u32 *aCkpt, DbLog *pLog);
void lsmCheckpointZeroLogoffset(lsm_db *);
int lsmCheckpointSaveWorker(lsm_db *pDb, int);
int lsmDatabaseFull(lsm_db *pDb);
int lsmCheckpointSynced(lsm_db *pDb, i64 *piId, i64 *piLog, u32 *pnWrite);
int lsmCheckpointSize(lsm_db *db, int *pnByte);
int lsmInfoCompressionId(lsm_db *db, u32 *piCmpId);
/*
** Functions from file "lsm_tree.c".
*/
int lsmTreeNew(lsm_env *, int (*)(void *, int, void *, int), Tree **ppTree);
void lsmTreeRelease(lsm_env *, Tree *);
int lsmTreeInit(lsm_db *);
int lsmTreeRepair(lsm_db *);
void lsmTreeMakeOld(lsm_db *pDb);
void lsmTreeDiscardOld(lsm_db *pDb);
int lsmTreeHasOld(lsm_db *pDb);
int lsmTreeSize(lsm_db *);
int lsmTreeEndTransaction(lsm_db *pDb, int bCommit);
int lsmTreeLoadHeader(lsm_db *pDb, int *);
int lsmTreeLoadHeaderOk(lsm_db *, int);
int lsmTreeInsert(lsm_db *pDb, void *pKey, int nKey, void *pVal, int nVal);
int lsmTreeDelete(lsm_db *db, void *pKey1, int nKey1, void *pKey2, int nKey2);
void lsmTreeRollback(lsm_db *pDb, TreeMark *pMark);
void lsmTreeMark(lsm_db *pDb, TreeMark *pMark);
int lsmTreeCursorNew(lsm_db *pDb, int, TreeCursor **);
void lsmTreeCursorDestroy(TreeCursor *);
int lsmTreeCursorSeek(TreeCursor *pCsr, void *pKey, int nKey, int *pRes);
int lsmTreeCursorNext(TreeCursor *pCsr);
int lsmTreeCursorPrev(TreeCursor *pCsr);
int lsmTreeCursorEnd(TreeCursor *pCsr, int bLast);
void lsmTreeCursorReset(TreeCursor *pCsr);
int lsmTreeCursorKey(TreeCursor *pCsr, int *pFlags, void **ppKey, int *pnKey);
int lsmTreeCursorFlags(TreeCursor *pCsr);
int lsmTreeCursorValue(TreeCursor *pCsr, void **ppVal, int *pnVal);
int lsmTreeCursorValid(TreeCursor *pCsr);
int lsmTreeCursorSave(TreeCursor *pCsr);
void lsmFlagsToString(int flags, char *zFlags);
/*
** Functions from file "mem.c".
*/
void *lsmMalloc(lsm_env*, size_t);
void lsmFree(lsm_env*, void *);
void *lsmRealloc(lsm_env*, void *, size_t);
void *lsmReallocOrFree(lsm_env*, void *, size_t);
void *lsmReallocOrFreeRc(lsm_env *, void *, size_t, int *);
void *lsmMallocZeroRc(lsm_env*, size_t, int *);
void *lsmMallocRc(lsm_env*, size_t, int *);
void *lsmMallocZero(lsm_env *pEnv, size_t);
char *lsmMallocStrdup(lsm_env *pEnv, const char *);
/*
** Functions from file "lsm_mutex.c".
*/
int lsmMutexStatic(lsm_env*, int, lsm_mutex **);
int lsmMutexNew(lsm_env*, lsm_mutex **);
void lsmMutexDel(lsm_env*, lsm_mutex *);
void lsmMutexEnter(lsm_env*, lsm_mutex *);
int lsmMutexTry(lsm_env*, lsm_mutex *);
void lsmMutexLeave(lsm_env*, lsm_mutex *);
#ifndef NDEBUG
int lsmMutexHeld(lsm_env *, lsm_mutex *);
int lsmMutexNotHeld(lsm_env *, lsm_mutex *);
#endif
/**************************************************************************
** Start of functions from "lsm_file.c".
*/
int lsmFsOpen(lsm_db *, const char *, int);
int lsmFsOpenLog(lsm_db *, int *);
void lsmFsCloseLog(lsm_db *);
void lsmFsClose(FileSystem *);
int lsmFsUnmap(FileSystem *);
int lsmFsConfigure(lsm_db *db);
int lsmFsBlockSize(FileSystem *);
void lsmFsSetBlockSize(FileSystem *, int);
int lsmFsMoveBlock(FileSystem *pFS, Segment *pSeg, int iTo, int iFrom);
int lsmFsPageSize(FileSystem *);
void lsmFsSetPageSize(FileSystem *, int);
int lsmFsFileid(lsm_db *pDb, void **ppId, int *pnId);
/* Creating, populating, gobbling and deleting sorted runs. */
void lsmFsGobble(lsm_db *, Segment *, LsmPgno *, int);
int lsmFsSortedDelete(FileSystem *, Snapshot *, int, Segment *);
int lsmFsSortedFinish(FileSystem *, Segment *);
int lsmFsSortedAppend(FileSystem *, Snapshot *, Level *, int, Page **);
int lsmFsSortedPadding(FileSystem *, Snapshot *, Segment *);
/* Functions to retrieve the lsm_env pointer from a FileSystem or Page object */
lsm_env *lsmFsEnv(FileSystem *);
lsm_env *lsmPageEnv(Page *);
FileSystem *lsmPageFS(Page *);
int lsmFsSectorSize(FileSystem *);
void lsmSortedSplitkey(lsm_db *, Level *, int *);
/* Reading sorted run content. */
int lsmFsDbPageLast(FileSystem *pFS, Segment *pSeg, Page **ppPg);
int lsmFsDbPageGet(FileSystem *, Segment *, LsmPgno, Page **);
int lsmFsDbPageNext(Segment *, Page *, int eDir, Page **);
u8 *lsmFsPageData(Page *, int *);
int lsmFsPageRelease(Page *);
int lsmFsPagePersist(Page *);
void lsmFsPageRef(Page *);
LsmPgno lsmFsPageNumber(Page *);
int lsmFsNRead(FileSystem *);
int lsmFsNWrite(FileSystem *);
int lsmFsMetaPageGet(FileSystem *, int, int, MetaPage **);
int lsmFsMetaPageRelease(MetaPage *);
u8 *lsmFsMetaPageData(MetaPage *, int *);
#ifdef LSM_DEBUG
int lsmFsDbPageIsLast(Segment *pSeg, Page *pPg);
int lsmFsIntegrityCheck(lsm_db *);
#endif
LsmPgno lsmFsRedirectPage(FileSystem *, Redirect *, LsmPgno);
int lsmFsPageWritable(Page *);
/* Functions to read, write and sync the log file. */
int lsmFsWriteLog(FileSystem *pFS, i64 iOff, LsmString *pStr);
int lsmFsSyncLog(FileSystem *pFS);
int lsmFsReadLog(FileSystem *pFS, i64 iOff, int nRead, LsmString *pStr);
int lsmFsTruncateLog(FileSystem *pFS, i64 nByte);
int lsmFsTruncateDb(FileSystem *pFS, i64 nByte);
int lsmFsCloseAndDeleteLog(FileSystem *pFS);
LsmFile *lsmFsDeferClose(FileSystem *pFS);
/* And to sync the db file */
int lsmFsSyncDb(FileSystem *, int);
void lsmFsFlushWaiting(FileSystem *, int *);
/* Used by lsm_info(ARRAY_STRUCTURE) and lsm_config(MMAP) */
int lsmInfoArrayStructure(lsm_db *pDb, int bBlock, LsmPgno iFirst, char **pz);
int lsmInfoArrayPages(lsm_db *pDb, LsmPgno iFirst, char **pzOut);
int lsmConfigMmap(lsm_db *pDb, int *piParam);
int lsmEnvOpen(lsm_env *, const char *, int, lsm_file **);
int lsmEnvClose(lsm_env *pEnv, lsm_file *pFile);
int lsmEnvLock(lsm_env *pEnv, lsm_file *pFile, int iLock, int eLock);
int lsmEnvTestLock(lsm_env *pEnv, lsm_file *pFile, int iLock, int nLock, int);
int lsmEnvShmMap(lsm_env *, lsm_file *, int, int, void **);
void lsmEnvShmBarrier(lsm_env *);
void lsmEnvShmUnmap(lsm_env *, lsm_file *, int);
void lsmEnvSleep(lsm_env *, int);
int lsmFsReadSyncedId(lsm_db *db, int, i64 *piVal);
int lsmFsSegmentContainsPg(FileSystem *pFS, Segment *, LsmPgno, int *);
void lsmFsPurgeCache(FileSystem *);
/*
** End of functions from "lsm_file.c".
**************************************************************************/
/*
** Functions from file "lsm_sorted.c".
*/
int lsmInfoPageDump(lsm_db *, LsmPgno, int, char **);
void lsmSortedCleanup(lsm_db *);
int lsmSortedAutoWork(lsm_db *, int nUnit);
int lsmSortedWalkFreelist(lsm_db *, int, int (*)(void *, int, i64), void *);
int lsmSaveWorker(lsm_db *, int);
int lsmFlushTreeToDisk(lsm_db *pDb);
void lsmSortedRemap(lsm_db *pDb);
void lsmSortedFreeLevel(lsm_env *pEnv, Level *);
int lsmSortedAdvanceAll(lsm_db *pDb);
int lsmSortedLoadMerge(lsm_db *, Level *, u32 *, int *);
int lsmSortedLoadFreelist(lsm_db *pDb, void **, int *);
void *lsmSortedSplitKey(Level *pLevel, int *pnByte);
void lsmSortedSaveTreeCursors(lsm_db *);
int lsmMCursorNew(lsm_db *, MultiCursor **);
void lsmMCursorClose(MultiCursor *, int);
int lsmMCursorSeek(MultiCursor *, int, void *, int , int);
int lsmMCursorFirst(MultiCursor *);
int lsmMCursorPrev(MultiCursor *);
int lsmMCursorLast(MultiCursor *);
int lsmMCursorValid(MultiCursor *);
int lsmMCursorNext(MultiCursor *);
int lsmMCursorKey(MultiCursor *, void **, int *);
int lsmMCursorValue(MultiCursor *, void **, int *);
int lsmMCursorType(MultiCursor *, int *);
lsm_db *lsmMCursorDb(MultiCursor *);
void lsmMCursorFreeCache(lsm_db *);
int lsmSaveCursors(lsm_db *pDb);
int lsmRestoreCursors(lsm_db *pDb);
void lsmSortedDumpStructure(lsm_db *pDb, Snapshot *, int, int, const char *);
void lsmFsDumpBlocklists(lsm_db *);
void lsmSortedExpandBtreePage(Page *pPg, int nOrig);
void lsmPutU32(u8 *, u32);
u32 lsmGetU32(u8 *);
u64 lsmGetU64(u8 *);
/*
** Functions from "lsm_varint.c".
*/
int lsmVarintPut32(u8 *, int);
int lsmVarintGet32(u8 *, int *);
int lsmVarintPut64(u8 *aData, i64 iVal);
int lsmVarintGet64(const u8 *aData, i64 *piVal);
int lsmVarintLen64(i64);
int lsmVarintLen32(int);
int lsmVarintSize(u8 c);
/*
** Functions from file "main.c".
*/
void lsmLogMessage(lsm_db *, int, const char *, ...);
int lsmInfoFreelist(lsm_db *pDb, char **pzOut);
/*
** Functions from file "lsm_log.c".
*/
int lsmLogBegin(lsm_db *pDb);
int lsmLogWrite(lsm_db *, int, void *, int, void *, int);
int lsmLogCommit(lsm_db *);
void lsmLogEnd(lsm_db *pDb, int bCommit);
void lsmLogTell(lsm_db *, LogMark *);
void lsmLogSeek(lsm_db *, LogMark *);
void lsmLogClose(lsm_db *);
int lsmLogRecover(lsm_db *);
int lsmInfoLogStructure(lsm_db *pDb, char **pzVal);
/* Valid values for the second argument to lsmLogWrite(). */
#define LSM_WRITE 0x06
#define LSM_DELETE 0x08
#define LSM_DRANGE 0x0A
/**************************************************************************
** Functions from file "lsm_shared.c".
*/
int lsmDbDatabaseConnect(lsm_db*, const char *);
void lsmDbDatabaseRelease(lsm_db *);
int lsmBeginReadTrans(lsm_db *);
int lsmBeginWriteTrans(lsm_db *);
int lsmBeginFlush(lsm_db *);
int lsmDetectRoTrans(lsm_db *db, int *);
int lsmBeginRoTrans(lsm_db *db);
int lsmBeginWork(lsm_db *);
void lsmFinishWork(lsm_db *, int, int *);
int lsmFinishRecovery(lsm_db *);
void lsmFinishReadTrans(lsm_db *);
int lsmFinishWriteTrans(lsm_db *, int);
int lsmFinishFlush(lsm_db *, int);
int lsmSnapshotSetFreelist(lsm_db *, int *, int);
Snapshot *lsmDbSnapshotClient(lsm_db *);
Snapshot *lsmDbSnapshotWorker(lsm_db *);
void lsmSnapshotSetCkptid(Snapshot *, i64);
Level *lsmDbSnapshotLevel(Snapshot *);
void lsmDbSnapshotSetLevel(Snapshot *, Level *);
void lsmDbRecoveryComplete(lsm_db *, int);
int lsmBlockAllocate(lsm_db *, int, int *);
int lsmBlockFree(lsm_db *, int);
int lsmBlockRefree(lsm_db *, int);
void lsmFreelistDeltaBegin(lsm_db *);
void lsmFreelistDeltaEnd(lsm_db *);
int lsmFreelistDelta(lsm_db *pDb);
DbLog *lsmDatabaseLog(lsm_db *pDb);
#ifdef LSM_DEBUG
int lsmHoldingClientMutex(lsm_db *pDb);
int lsmShmAssertLock(lsm_db *db, int iLock, int eOp);
int lsmShmAssertWorker(lsm_db *db);
#endif
void lsmFreeSnapshot(lsm_env *, Snapshot *);
/* Candidate values for the 3rd argument to lsmShmLock() */
#define LSM_LOCK_UNLOCK 0
#define LSM_LOCK_SHARED 1
#define LSM_LOCK_EXCL 2
int lsmShmCacheChunks(lsm_db *db, int nChunk);
int lsmShmLock(lsm_db *db, int iLock, int eOp, int bBlock);
int lsmShmTestLock(lsm_db *db, int iLock, int nLock, int eOp);
void lsmShmBarrier(lsm_db *db);
#ifdef LSM_DEBUG
void lsmShmHasLock(lsm_db *db, int iLock, int eOp);
#else
# define lsmShmHasLock(x,y,z)
#endif
int lsmReadlock(lsm_db *, i64 iLsm, u32 iShmMin, u32 iShmMax);
int lsmLsmInUse(lsm_db *db, i64 iLsmId, int *pbInUse);
int lsmTreeInUse(lsm_db *db, u32 iLsmId, int *pbInUse);
int lsmFreelistAppend(lsm_env *pEnv, Freelist *p, int iBlk, i64 iId);
int lsmDbMultiProc(lsm_db *);
void lsmDbDeferredClose(lsm_db *, lsm_file *, LsmFile *);
LsmFile *lsmDbRecycleFd(lsm_db *);
int lsmWalkFreelist(lsm_db *, int, int (*)(void *, int, i64), void *);
int lsmCheckCompressionId(lsm_db *, u32);
/**************************************************************************
** functions in lsm_str.c
*/
void lsmStringInit(LsmString*, lsm_env *pEnv);
int lsmStringExtend(LsmString*, int);
int lsmStringAppend(LsmString*, const char *, int);
void lsmStringVAppendf(LsmString*, const char *zFormat, va_list, va_list);
void lsmStringAppendf(LsmString*, const char *zFormat, ...);
void lsmStringClear(LsmString*);
char *lsmMallocPrintf(lsm_env*, const char*, ...);
int lsmStringBinAppend(LsmString *pStr, const u8 *a, int n);
int lsmStrlen(const char *zName);
/*
** Round up a number to the next larger multiple of 8. This is used
** to force 8-byte alignment on 64-bit architectures.
*/
#define ROUND8(x) (((x)+7)&~7)
#define LSM_MIN(x,y) ((x)>(y) ? (y) : (x))
#define LSM_MAX(x,y) ((x)>(y) ? (x) : (y))
#endif
-1239
View File
File diff suppressed because it is too large Load Diff
-3311
View File
File diff suppressed because it is too large Load Diff
-1156
View File
File diff suppressed because it is too large Load Diff
-1008
View File
File diff suppressed because it is too large Load Diff
-104
View File
@@ -1,104 +0,0 @@
/*
** 2011-08-18
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
**
** Helper routines for memory allocation.
*/
#include "lsmInt.h"
/*
** The following routines are called internally by LSM sub-routines. In
** this case a valid environment pointer must be supplied.
*/
void *lsmMalloc(lsm_env *pEnv, size_t N){
assert( pEnv );
return pEnv->xMalloc(pEnv, N);
}
void lsmFree(lsm_env *pEnv, void *p){
assert( pEnv );
pEnv->xFree(pEnv, p);
}
void *lsmRealloc(lsm_env *pEnv, void *p, size_t N){
assert( pEnv );
return pEnv->xRealloc(pEnv, p, N);
}
/*
** Core memory allocation routines for LSM.
*/
void *lsm_malloc(lsm_env *pEnv, size_t N){
return lsmMalloc(pEnv ? pEnv : lsm_default_env(), N);
}
void lsm_free(lsm_env *pEnv, void *p){
lsmFree(pEnv ? pEnv : lsm_default_env(), p);
}
void *lsm_realloc(lsm_env *pEnv, void *p, size_t N){
return lsmRealloc(pEnv ? pEnv : lsm_default_env(), p, N);
}
void *lsmMallocZero(lsm_env *pEnv, size_t N){
void *pRet;
assert( pEnv );
pRet = lsmMalloc(pEnv, N);
if( pRet ) memset(pRet, 0, N);
return pRet;
}
void *lsmMallocRc(lsm_env *pEnv, size_t N, int *pRc){
void *pRet = 0;
if( *pRc==LSM_OK ){
pRet = lsmMalloc(pEnv, N);
if( pRet==0 ){
*pRc = LSM_NOMEM_BKPT;
}
}
return pRet;
}
void *lsmMallocZeroRc(lsm_env *pEnv, size_t N, int *pRc){
void *pRet = 0;
if( *pRc==LSM_OK ){
pRet = lsmMallocZero(pEnv, N);
if( pRet==0 ){
*pRc = LSM_NOMEM_BKPT;
}
}
return pRet;
}
void *lsmReallocOrFree(lsm_env *pEnv, void *p, size_t N){
void *pNew;
pNew = lsm_realloc(pEnv, p, N);
if( !pNew ) lsm_free(pEnv, p);
return pNew;
}
void *lsmReallocOrFreeRc(lsm_env *pEnv, void *p, size_t N, int *pRc){
void *pRet = 0;
if( *pRc ){
lsmFree(pEnv, p);
}else{
pRet = lsmReallocOrFree(pEnv, p, N);
if( !pRet ) *pRc = LSM_NOMEM_BKPT;
}
return pRet;
}
char *lsmMallocStrdup(lsm_env *pEnv, const char *zIn){
int nByte;
char *zRet;
nByte = strlen(zIn);
zRet = lsmMalloc(pEnv, nByte+1);
if( zRet ){
memcpy(zRet, zIn, nByte+1);
}
return zRet;
}
-88
View File
@@ -1,88 +0,0 @@
/*
** 2012-01-30
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
**
** Mutex functions for LSM.
*/
#include "lsmInt.h"
/*
** Allocate a new mutex.
*/
int lsmMutexNew(lsm_env *pEnv, lsm_mutex **ppNew){
return pEnv->xMutexNew(pEnv, ppNew);
}
/*
** Return a handle for one of the static mutexes.
*/
int lsmMutexStatic(lsm_env *pEnv, int iMutex, lsm_mutex **ppStatic){
return pEnv->xMutexStatic(pEnv, iMutex, ppStatic);
}
/*
** Free a mutex allocated by lsmMutexNew().
*/
void lsmMutexDel(lsm_env *pEnv, lsm_mutex *pMutex){
if( pMutex ) pEnv->xMutexDel(pMutex);
}
/*
** Enter a mutex.
*/
void lsmMutexEnter(lsm_env *pEnv, lsm_mutex *pMutex){
pEnv->xMutexEnter(pMutex);
}
/*
** Attempt to enter a mutex, but do not block. If successful, return zero.
** Otherwise, if the mutex is already held by some other thread and is not
** entered, return non zero.
**
** Each successful call to this function must be matched by a call to
** lsmMutexLeave().
*/
int lsmMutexTry(lsm_env *pEnv, lsm_mutex *pMutex){
return pEnv->xMutexTry(pMutex);
}
/*
** Leave a mutex.
*/
void lsmMutexLeave(lsm_env *pEnv, lsm_mutex *pMutex){
pEnv->xMutexLeave(pMutex);
}
#ifndef NDEBUG
/*
** Return non-zero if the mutex passed as the second argument is held
** by the calling thread, or zero otherwise. If the implementation is not
** able to tell if the mutex is held by the caller, it should return
** non-zero.
**
** This function is only used as part of assert() statements.
*/
int lsmMutexHeld(lsm_env *pEnv, lsm_mutex *pMutex){
return pEnv->xMutexHeld ? pEnv->xMutexHeld(pMutex) : 1;
}
/*
** Return non-zero if the mutex passed as the second argument is not
** held by the calling thread, or zero otherwise. If the implementation
** is not able to tell if the mutex is held by the caller, it should
** return non-zero.
**
** This function is only used as part of assert() statements.
*/
int lsmMutexNotHeld(lsm_env *pEnv, lsm_mutex *pMutex){
return pEnv->xMutexNotHeld ? pEnv->xMutexNotHeld(pMutex) : 1;
}
#endif
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
-148
View File
@@ -1,148 +0,0 @@
/*
** 2012-04-27
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
**
** Dynamic string functions.
*/
#include "lsmInt.h"
/*
** Turn bulk and uninitialized memory into an LsmString object
*/
void lsmStringInit(LsmString *pStr, lsm_env *pEnv){
memset(pStr, 0, sizeof(pStr[0]));
pStr->pEnv = pEnv;
}
/*
** Increase the memory allocated for holding the string. Realloc as needed.
**
** If a memory allocation error occurs, set pStr->n to -1 and free the existing
** allocation. If a prior memory allocation has occurred, this routine is a
** no-op.
*/
int lsmStringExtend(LsmString *pStr, int nNew){
assert( nNew>0 );
if( pStr->n<0 ) return LSM_NOMEM;
if( pStr->n + nNew >= pStr->nAlloc ){
int nAlloc = pStr->n + nNew + 100;
char *zNew = lsmRealloc(pStr->pEnv, pStr->z, nAlloc);
if( zNew==0 ){
lsmFree(pStr->pEnv, pStr->z);
nAlloc = 0;
pStr->n = -1;
}
pStr->nAlloc = nAlloc;
pStr->z = zNew;
}
return (pStr->z ? LSM_OK : LSM_NOMEM_BKPT);
}
/*
** Clear an LsmString object, releasing any allocated memory that it holds.
** This also clears the error indication (if any).
*/
void lsmStringClear(LsmString *pStr){
lsmFree(pStr->pEnv, pStr->z);
lsmStringInit(pStr, pStr->pEnv);
}
/*
** Append N bytes of text to the end of an LsmString object. If
** N is negative, append the entire string.
**
** If the string is in an error state, this routine is a no-op.
*/
int lsmStringAppend(LsmString *pStr, const char *z, int N){
int rc;
if( N<0 ) N = (int)strlen(z);
rc = lsmStringExtend(pStr, N+1);
if( pStr->nAlloc ){
memcpy(pStr->z+pStr->n, z, N+1);
pStr->n += N;
}
return rc;
}
int lsmStringBinAppend(LsmString *pStr, const u8 *a, int n){
int rc;
rc = lsmStringExtend(pStr, n);
if( pStr->nAlloc ){
memcpy(pStr->z+pStr->n, a, n);
pStr->n += n;
}
return rc;
}
/*
** Append printf-formatted content to an LsmString.
*/
void lsmStringVAppendf(
LsmString *pStr,
const char *zFormat,
va_list ap1,
va_list ap2
){
#if (!defined(__STDC_VERSION__) || (__STDC_VERSION__<199901L)) && \
!defined(__APPLE__)
extern int vsnprintf(char *str, size_t size, const char *format, va_list ap)
/* Compatibility crutch for C89 compilation mode. sqlite3_vsnprintf()
does not work identically and causes test failures if used here.
For the time being we are assuming that the target has vsnprintf(),
but that is not guaranteed to be the case for pure C89 platforms.
*/;
#endif
int nWrite;
int nAvail;
nAvail = pStr->nAlloc - pStr->n;
nWrite = vsnprintf(pStr->z + pStr->n, nAvail, zFormat, ap1);
if( nWrite>=nAvail ){
lsmStringExtend(pStr, nWrite+1);
if( pStr->nAlloc==0 ) return;
nWrite = vsnprintf(pStr->z + pStr->n, nWrite+1, zFormat, ap2);
}
pStr->n += nWrite;
pStr->z[pStr->n] = 0;
}
void lsmStringAppendf(LsmString *pStr, const char *zFormat, ...){
va_list ap, ap2;
va_start(ap, zFormat);
va_start(ap2, zFormat);
lsmStringVAppendf(pStr, zFormat, ap, ap2);
va_end(ap);
va_end(ap2);
}
int lsmStrlen(const char *zName){
int nRet = 0;
while( zName[nRet] ) nRet++;
return nRet;
}
/*
** Write into memory obtained from lsm_malloc().
*/
char *lsmMallocPrintf(lsm_env *pEnv, const char *zFormat, ...){
LsmString s;
va_list ap, ap2;
lsmStringInit(&s, pEnv);
va_start(ap, zFormat);
va_start(ap2, zFormat);
lsmStringVAppendf(&s, zFormat, ap, ap2);
va_end(ap);
va_end(ap2);
if( s.n<0 ) return 0;
return (char *)lsmReallocOrFree(pEnv, s.z, s.n+1);
}
-2465
View File
File diff suppressed because it is too large Load Diff
-753
View File
@@ -1,753 +0,0 @@
/*
** 2011-12-03
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
**
** Unix-specific run-time environment implementation for LSM.
*/
#ifndef _WIN32
#if defined(__GNUC__) || defined(__TINYC__)
/* workaround for ftruncate() visibility on gcc. */
# ifndef _XOPEN_SOURCE
# define _XOPEN_SOURCE 500
# endif
#endif
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <ctype.h>
#include <unistd.h>
#include <errno.h>
#include <sys/mman.h>
#include "lsmInt.h"
/* There is no fdatasync() call on Android */
#ifdef __ANDROID__
# define fdatasync(x) fsync(x)
#endif
/*
** An open file is an instance of the following object
*/
typedef struct PosixFile PosixFile;
struct PosixFile {
lsm_env *pEnv; /* The run-time environment */
const char *zName; /* Full path to file */
int fd; /* The open file descriptor */
int shmfd; /* Shared memory file-descriptor */
void *pMap; /* Pointer to mapping of file fd */
off_t nMap; /* Size of mapping at pMap in bytes */
int nShm; /* Number of entries in array apShm[] */
void **apShm; /* Array of 32K shared memory segments */
};
static char *posixShmFile(PosixFile *p){
char *zShm;
int nName = strlen(p->zName);
zShm = (char *)lsmMalloc(p->pEnv, nName+4+1);
if( zShm ){
memcpy(zShm, p->zName, nName);
memcpy(&zShm[nName], "-shm", 5);
}
return zShm;
}
static int lsmPosixOsOpen(
lsm_env *pEnv,
const char *zFile,
int flags,
lsm_file **ppFile
){
int rc = LSM_OK;
PosixFile *p;
p = lsm_malloc(pEnv, sizeof(PosixFile));
if( p==0 ){
rc = LSM_NOMEM;
}else{
int bReadonly = (flags & LSM_OPEN_READONLY);
int oflags = (bReadonly ? O_RDONLY : (O_RDWR|O_CREAT));
memset(p, 0, sizeof(PosixFile));
p->zName = zFile;
p->pEnv = pEnv;
p->fd = open(zFile, oflags, 0644);
if( p->fd<0 ){
lsm_free(pEnv, p);
p = 0;
if( errno==ENOENT ){
rc = lsmErrorBkpt(LSM_IOERR_NOENT);
}else{
rc = LSM_IOERR_BKPT;
}
}
}
*ppFile = (lsm_file *)p;
return rc;
}
static int lsmPosixOsWrite(
lsm_file *pFile, /* File to write to */
lsm_i64 iOff, /* Offset to write to */
void *pData, /* Write data from this buffer */
int nData /* Bytes of data to write */
){
int rc = LSM_OK;
PosixFile *p = (PosixFile *)pFile;
off_t offset;
offset = lseek(p->fd, (off_t)iOff, SEEK_SET);
if( offset!=iOff ){
rc = LSM_IOERR_BKPT;
}else{
ssize_t prc = write(p->fd, pData, (size_t)nData);
if( prc<0 ) rc = LSM_IOERR_BKPT;
}
return rc;
}
static int lsmPosixOsTruncate(
lsm_file *pFile, /* File to write to */
lsm_i64 nSize /* Size to truncate file to */
){
PosixFile *p = (PosixFile *)pFile;
int rc = LSM_OK; /* Return code */
int prc; /* Posix Return Code */
struct stat sStat; /* Result of fstat() invocation */
prc = fstat(p->fd, &sStat);
if( prc==0 && sStat.st_size>nSize ){
prc = ftruncate(p->fd, (off_t)nSize);
}
if( prc<0 ) rc = LSM_IOERR_BKPT;
return rc;
}
static int lsmPosixOsRead(
lsm_file *pFile, /* File to read from */
lsm_i64 iOff, /* Offset to read from */
void *pData, /* Read data into this buffer */
int nData /* Bytes of data to read */
){
int rc = LSM_OK;
PosixFile *p = (PosixFile *)pFile;
off_t offset;
offset = lseek(p->fd, (off_t)iOff, SEEK_SET);
if( offset!=iOff ){
rc = LSM_IOERR_BKPT;
}else{
ssize_t prc = read(p->fd, pData, (size_t)nData);
if( prc<0 ){
rc = LSM_IOERR_BKPT;
}else if( prc<nData ){
memset(&((u8 *)pData)[prc], 0, nData - prc);
}
}
return rc;
}
static int lsmPosixOsSync(lsm_file *pFile){
int rc = LSM_OK;
#ifndef LSM_NO_SYNC
PosixFile *p = (PosixFile *)pFile;
int prc = 0;
if( p->pMap ){
prc = msync(p->pMap, p->nMap, MS_SYNC);
}
if( prc==0 ) prc = fdatasync(p->fd);
if( prc<0 ) rc = LSM_IOERR_BKPT;
#else
(void)pFile;
#endif
return rc;
}
static int lsmPosixOsSectorSize(lsm_file *pFile){
return 512;
}
static int lsmPosixOsRemap(
lsm_file *pFile,
lsm_i64 iMin,
void **ppOut,
lsm_i64 *pnOut
){
off_t iSz;
int prc;
PosixFile *p = (PosixFile *)pFile;
struct stat buf;
/* If the file is between 0 and 2MB in size, extend it in chunks of 256K.
** Thereafter, in chunks of 1MB at a time. */
const int aIncrSz[] = {256*1024, 1024*1024};
int nIncrSz = aIncrSz[iMin>(2*1024*1024)];
if( p->pMap ){
munmap(p->pMap, p->nMap);
*ppOut = p->pMap = 0;
*pnOut = p->nMap = 0;
}
if( iMin>=0 ){
memset(&buf, 0, sizeof(buf));
prc = fstat(p->fd, &buf);
if( prc!=0 ) return LSM_IOERR_BKPT;
iSz = buf.st_size;
if( iSz<iMin ){
iSz = ((iMin + nIncrSz-1) / nIncrSz) * nIncrSz;
prc = ftruncate(p->fd, iSz);
if( prc!=0 ) return LSM_IOERR_BKPT;
}
p->pMap = mmap(0, iSz, PROT_READ|PROT_WRITE, MAP_SHARED, p->fd, 0);
if( p->pMap==MAP_FAILED ){
p->pMap = 0;
return LSM_IOERR_BKPT;
}
p->nMap = iSz;
}
*ppOut = p->pMap;
*pnOut = p->nMap;
return LSM_OK;
}
static int lsmPosixOsFullpath(
lsm_env *pEnv,
const char *zName,
char *zOut,
int *pnOut
){
int nBuf = *pnOut;
int nReq;
if( zName[0]!='/' ){
char *z;
char *zTmp;
int nTmp = 512;
zTmp = lsmMalloc(pEnv, nTmp);
while( zTmp ){
z = getcwd(zTmp, nTmp);
if( z || errno!=ERANGE ) break;
nTmp = nTmp*2;
zTmp = lsmReallocOrFree(pEnv, zTmp, nTmp);
}
if( zTmp==0 ) return LSM_NOMEM_BKPT;
if( z==0 ) return LSM_IOERR_BKPT;
assert( z==zTmp );
nTmp = strlen(zTmp);
nReq = nTmp + 1 + strlen(zName) + 1;
if( nReq<=nBuf ){
memcpy(zOut, zTmp, nTmp);
zOut[nTmp] = '/';
memcpy(&zOut[nTmp+1], zName, strlen(zName)+1);
}
lsmFree(pEnv, zTmp);
}else{
nReq = strlen(zName)+1;
if( nReq<=nBuf ){
memcpy(zOut, zName, strlen(zName)+1);
}
}
*pnOut = nReq;
return LSM_OK;
}
static int lsmPosixOsFileid(
lsm_file *pFile,
void *pBuf,
int *pnBuf
){
int prc;
int nBuf;
int nReq;
PosixFile *p = (PosixFile *)pFile;
struct stat buf;
nBuf = *pnBuf;
nReq = (sizeof(buf.st_dev) + sizeof(buf.st_ino));
*pnBuf = nReq;
if( nReq>nBuf ) return LSM_OK;
memset(&buf, 0, sizeof(buf));
prc = fstat(p->fd, &buf);
if( prc!=0 ) return LSM_IOERR_BKPT;
memcpy(pBuf, &buf.st_dev, sizeof(buf.st_dev));
memcpy(&(((u8 *)pBuf)[sizeof(buf.st_dev)]), &buf.st_ino, sizeof(buf.st_ino));
return LSM_OK;
}
static int lsmPosixOsUnlink(lsm_env *pEnv, const char *zFile){
int prc = unlink(zFile);
return prc ? LSM_IOERR_BKPT : LSM_OK;
}
static int lsmPosixOsLock(lsm_file *pFile, int iLock, int eType){
int rc = LSM_OK;
PosixFile *p = (PosixFile *)pFile;
static const short aType[3] = { F_UNLCK, F_RDLCK, F_WRLCK };
struct flock lock;
assert( aType[LSM_LOCK_UNLOCK]==F_UNLCK );
assert( aType[LSM_LOCK_SHARED]==F_RDLCK );
assert( aType[LSM_LOCK_EXCL]==F_WRLCK );
assert( eType>=0 && eType<array_size(aType) );
assert( iLock>0 && iLock<=32 );
memset(&lock, 0, sizeof(lock));
lock.l_whence = SEEK_SET;
lock.l_len = 1;
lock.l_type = aType[eType];
lock.l_start = (4096-iLock);
if( fcntl(p->fd, F_SETLK, &lock) ){
int e = errno;
if( e==EACCES || e==EAGAIN ){
rc = LSM_BUSY;
}else{
rc = LSM_IOERR_BKPT;
}
}
return rc;
}
static int lsmPosixOsTestLock(lsm_file *pFile, int iLock, int nLock, int eType){
int rc = LSM_OK;
PosixFile *p = (PosixFile *)pFile;
static const short aType[3] = { 0, F_RDLCK, F_WRLCK };
struct flock lock;
assert( eType==LSM_LOCK_SHARED || eType==LSM_LOCK_EXCL );
assert( aType[LSM_LOCK_SHARED]==F_RDLCK );
assert( aType[LSM_LOCK_EXCL]==F_WRLCK );
assert( eType>=0 && eType<array_size(aType) );
assert( iLock>0 && iLock<=32 );
memset(&lock, 0, sizeof(lock));
lock.l_whence = SEEK_SET;
lock.l_len = nLock;
lock.l_type = aType[eType];
lock.l_start = (4096-iLock-nLock+1);
if( fcntl(p->fd, F_GETLK, &lock) ){
rc = LSM_IOERR_BKPT;
}else if( lock.l_type!=F_UNLCK ){
rc = LSM_BUSY;
}
return rc;
}
static int lsmPosixOsShmMap(lsm_file *pFile, int iChunk, int sz, void **ppShm){
PosixFile *p = (PosixFile *)pFile;
*ppShm = 0;
assert( sz==LSM_SHM_CHUNK_SIZE );
if( iChunk>=p->nShm ){
int i;
void **apNew;
int nNew = iChunk+1;
off_t nReq = nNew * LSM_SHM_CHUNK_SIZE;
struct stat sStat;
/* If the shared-memory file has not been opened, open it now. */
if( p->shmfd<=0 ){
char *zShm = posixShmFile(p);
if( !zShm ) return LSM_NOMEM_BKPT;
p->shmfd = open(zShm, O_RDWR|O_CREAT, 0644);
lsmFree(p->pEnv, zShm);
if( p->shmfd<0 ){
return LSM_IOERR_BKPT;
}
}
/* If the shared-memory file is not large enough to contain the
** requested chunk, cause it to grow. */
if( fstat(p->shmfd, &sStat) ){
return LSM_IOERR_BKPT;
}
if( sStat.st_size<nReq ){
if( ftruncate(p->shmfd, nReq) ){
return LSM_IOERR_BKPT;
}
}
apNew = (void **)lsmRealloc(p->pEnv, p->apShm, sizeof(void *) * nNew);
if( !apNew ) return LSM_NOMEM_BKPT;
for(i=p->nShm; i<nNew; i++){
apNew[i] = 0;
}
p->apShm = apNew;
p->nShm = nNew;
}
if( p->apShm[iChunk]==0 ){
p->apShm[iChunk] = mmap(0, LSM_SHM_CHUNK_SIZE,
PROT_READ|PROT_WRITE, MAP_SHARED, p->shmfd, iChunk*LSM_SHM_CHUNK_SIZE
);
if( p->apShm[iChunk]==MAP_FAILED ){
p->apShm[iChunk] = 0;
return LSM_IOERR_BKPT;
}
}
*ppShm = p->apShm[iChunk];
return LSM_OK;
}
static void lsmPosixOsShmBarrier(void){
}
static int lsmPosixOsShmUnmap(lsm_file *pFile, int bDelete){
PosixFile *p = (PosixFile *)pFile;
if( p->shmfd>0 ){
int i;
for(i=0; i<p->nShm; i++){
if( p->apShm[i] ){
munmap(p->apShm[i], LSM_SHM_CHUNK_SIZE);
p->apShm[i] = 0;
}
}
close(p->shmfd);
p->shmfd = 0;
if( bDelete ){
char *zShm = posixShmFile(p);
if( zShm ) unlink(zShm);
lsmFree(p->pEnv, zShm);
}
}
return LSM_OK;
}
static int lsmPosixOsClose(lsm_file *pFile){
PosixFile *p = (PosixFile *)pFile;
lsmPosixOsShmUnmap(pFile, 0);
if( p->pMap ) munmap(p->pMap, p->nMap);
close(p->fd);
lsm_free(p->pEnv, p->apShm);
lsm_free(p->pEnv, p);
return LSM_OK;
}
static int lsmPosixOsSleep(lsm_env *pEnv, int us){
#if 0
/* Apparently on Android usleep() returns void */
if( usleep(us) ) return LSM_IOERR;
#endif
usleep(us);
return LSM_OK;
}
/****************************************************************************
** Memory allocation routines.
*/
#define BLOCK_HDR_SIZE ROUND8( sizeof(size_t) )
static void *lsmPosixOsMalloc(lsm_env *pEnv, size_t N){
unsigned char * m;
N += BLOCK_HDR_SIZE;
m = (unsigned char *)malloc(N);
*((size_t*)m) = N;
return m + BLOCK_HDR_SIZE;
}
static void lsmPosixOsFree(lsm_env *pEnv, void *p){
if(p){
free( ((unsigned char *)p) - BLOCK_HDR_SIZE );
}
}
static void *lsmPosixOsRealloc(lsm_env *pEnv, void *p, size_t N){
unsigned char * m = (unsigned char *)p;
if(1>N){
lsmPosixOsFree( pEnv, p );
return NULL;
}else if(NULL==p){
return lsmPosixOsMalloc(pEnv, N);
}else{
void * re = NULL;
m -= BLOCK_HDR_SIZE;
#if 0 /* arguable: don't shrink */
size_t * sz = (size_t*)m;
if(*sz >= (size_t)N){
return p;
}
#endif
re = realloc( m, N + BLOCK_HDR_SIZE );
if(re){
m = (unsigned char *)re;
*((size_t*)m) = N;
return m + BLOCK_HDR_SIZE;
}else{
return NULL;
}
}
}
static size_t lsmPosixOsMSize(lsm_env *pEnv, void *p){
unsigned char * m = (unsigned char *)p;
return *((size_t*)(m-BLOCK_HDR_SIZE));
}
#undef BLOCK_HDR_SIZE
#ifdef LSM_MUTEX_PTHREADS
/*************************************************************************
** Mutex methods for pthreads based systems. If LSM_MUTEX_PTHREADS is
** missing then a no-op implementation of mutexes found in lsm_mutex.c
** will be used instead.
*/
#include <pthread.h>
typedef struct PthreadMutex PthreadMutex;
struct PthreadMutex {
lsm_env *pEnv;
pthread_mutex_t mutex;
#ifdef LSM_DEBUG
pthread_t owner;
#endif
};
#ifdef LSM_DEBUG
# define LSM_PTHREAD_STATIC_MUTEX { 0, PTHREAD_MUTEX_INITIALIZER, 0 }
#else
# define LSM_PTHREAD_STATIC_MUTEX { 0, PTHREAD_MUTEX_INITIALIZER }
#endif
static int lsmPosixOsMutexStatic(
lsm_env *pEnv,
int iMutex,
lsm_mutex **ppStatic
){
static PthreadMutex sMutex[2] = {
LSM_PTHREAD_STATIC_MUTEX,
LSM_PTHREAD_STATIC_MUTEX
};
assert( iMutex==LSM_MUTEX_GLOBAL || iMutex==LSM_MUTEX_HEAP );
assert( LSM_MUTEX_GLOBAL==1 && LSM_MUTEX_HEAP==2 );
*ppStatic = (lsm_mutex *)&sMutex[iMutex-1];
return LSM_OK;
}
static int lsmPosixOsMutexNew(lsm_env *pEnv, lsm_mutex **ppNew){
PthreadMutex *pMutex; /* Pointer to new mutex */
pthread_mutexattr_t attr; /* Attributes object */
pMutex = (PthreadMutex *)lsmMallocZero(pEnv, sizeof(PthreadMutex));
if( !pMutex ) return LSM_NOMEM_BKPT;
pMutex->pEnv = pEnv;
pthread_mutexattr_init(&attr);
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(&pMutex->mutex, &attr);
pthread_mutexattr_destroy(&attr);
*ppNew = (lsm_mutex *)pMutex;
return LSM_OK;
}
static void lsmPosixOsMutexDel(lsm_mutex *p){
PthreadMutex *pMutex = (PthreadMutex *)p;
pthread_mutex_destroy(&pMutex->mutex);
lsmFree(pMutex->pEnv, pMutex);
}
static void lsmPosixOsMutexEnter(lsm_mutex *p){
PthreadMutex *pMutex = (PthreadMutex *)p;
pthread_mutex_lock(&pMutex->mutex);
#ifdef LSM_DEBUG
assert( !pthread_equal(pMutex->owner, pthread_self()) );
pMutex->owner = pthread_self();
assert( pthread_equal(pMutex->owner, pthread_self()) );
#endif
}
static int lsmPosixOsMutexTry(lsm_mutex *p){
int ret;
PthreadMutex *pMutex = (PthreadMutex *)p;
ret = pthread_mutex_trylock(&pMutex->mutex);
#ifdef LSM_DEBUG
if( ret==0 ){
assert( !pthread_equal(pMutex->owner, pthread_self()) );
pMutex->owner = pthread_self();
assert( pthread_equal(pMutex->owner, pthread_self()) );
}
#endif
return ret;
}
static void lsmPosixOsMutexLeave(lsm_mutex *p){
PthreadMutex *pMutex = (PthreadMutex *)p;
#ifdef LSM_DEBUG
assert( pthread_equal(pMutex->owner, pthread_self()) );
pMutex->owner = 0;
assert( !pthread_equal(pMutex->owner, pthread_self()) );
#endif
pthread_mutex_unlock(&pMutex->mutex);
}
#ifdef LSM_DEBUG
static int lsmPosixOsMutexHeld(lsm_mutex *p){
PthreadMutex *pMutex = (PthreadMutex *)p;
return pMutex ? pthread_equal(pMutex->owner, pthread_self()) : 1;
}
static int lsmPosixOsMutexNotHeld(lsm_mutex *p){
PthreadMutex *pMutex = (PthreadMutex *)p;
return pMutex ? !pthread_equal(pMutex->owner, pthread_self()) : 1;
}
#endif
/*
** End of pthreads mutex implementation.
*************************************************************************/
#else
/*************************************************************************
** Noop mutex implementation
*/
typedef struct NoopMutex NoopMutex;
struct NoopMutex {
lsm_env *pEnv; /* Environment handle (for xFree()) */
int bHeld; /* True if mutex is held */
int bStatic; /* True for a static mutex */
};
static NoopMutex aStaticNoopMutex[2] = {
{0, 0, 1},
{0, 0, 1},
};
static int lsmPosixOsMutexStatic(
lsm_env *pEnv,
int iMutex,
lsm_mutex **ppStatic
){
assert( iMutex>=1 && iMutex<=(int)array_size(aStaticNoopMutex) );
*ppStatic = (lsm_mutex *)&aStaticNoopMutex[iMutex-1];
return LSM_OK;
}
static int lsmPosixOsMutexNew(lsm_env *pEnv, lsm_mutex **ppNew){
NoopMutex *p;
p = (NoopMutex *)lsmMallocZero(pEnv, sizeof(NoopMutex));
if( p ) p->pEnv = pEnv;
*ppNew = (lsm_mutex *)p;
return (p ? LSM_OK : LSM_NOMEM_BKPT);
}
static void lsmPosixOsMutexDel(lsm_mutex *pMutex) {
NoopMutex *p = (NoopMutex *)pMutex;
assert( p->bStatic==0 && p->pEnv );
lsmFree(p->pEnv, p);
}
static void lsmPosixOsMutexEnter(lsm_mutex *pMutex){
NoopMutex *p = (NoopMutex *)pMutex;
assert( p->bHeld==0 );
p->bHeld = 1;
}
static int lsmPosixOsMutexTry(lsm_mutex *pMutex){
NoopMutex *p = (NoopMutex *)pMutex;
assert( p->bHeld==0 );
p->bHeld = 1;
return 0;
}
static void lsmPosixOsMutexLeave(lsm_mutex *pMutex){
NoopMutex *p = (NoopMutex *)pMutex;
assert( p->bHeld==1 );
p->bHeld = 0;
}
#ifdef LSM_DEBUG
static int lsmPosixOsMutexHeld(lsm_mutex *pMutex){
NoopMutex *p = (NoopMutex *)pMutex;
return p ? p->bHeld : 1;
}
static int lsmPosixOsMutexNotHeld(lsm_mutex *pMutex){
NoopMutex *p = (NoopMutex *)pMutex;
return p ? !p->bHeld : 1;
}
#endif
/***************************************************************************/
#endif /* else LSM_MUTEX_NONE */
/* Without LSM_DEBUG, the MutexHeld tests are never called */
#ifndef LSM_DEBUG
# define lsmPosixOsMutexHeld 0
# define lsmPosixOsMutexNotHeld 0
#endif
lsm_env *lsm_default_env(void){
static lsm_env posix_env = {
sizeof(lsm_env), /* nByte */
1, /* iVersion */
/***** file i/o ******************/
0, /* pVfsCtx */
lsmPosixOsFullpath, /* xFullpath */
lsmPosixOsOpen, /* xOpen */
lsmPosixOsRead, /* xRead */
lsmPosixOsWrite, /* xWrite */
lsmPosixOsTruncate, /* xTruncate */
lsmPosixOsSync, /* xSync */
lsmPosixOsSectorSize, /* xSectorSize */
lsmPosixOsRemap, /* xRemap */
lsmPosixOsFileid, /* xFileid */
lsmPosixOsClose, /* xClose */
lsmPosixOsUnlink, /* xUnlink */
lsmPosixOsLock, /* xLock */
lsmPosixOsTestLock, /* xTestLock */
lsmPosixOsShmMap, /* xShmMap */
lsmPosixOsShmBarrier, /* xShmBarrier */
lsmPosixOsShmUnmap, /* xShmUnmap */
/***** memory allocation *********/
0, /* pMemCtx */
lsmPosixOsMalloc, /* xMalloc */
lsmPosixOsRealloc, /* xRealloc */
lsmPosixOsFree, /* xFree */
lsmPosixOsMSize, /* xSize */
/***** mutexes *********************/
0, /* pMutexCtx */
lsmPosixOsMutexStatic, /* xMutexStatic */
lsmPosixOsMutexNew, /* xMutexNew */
lsmPosixOsMutexDel, /* xMutexDel */
lsmPosixOsMutexEnter, /* xMutexEnter */
lsmPosixOsMutexTry, /* xMutexTry */
lsmPosixOsMutexLeave, /* xMutexLeave */
lsmPosixOsMutexHeld, /* xMutexHeld */
lsmPosixOsMutexNotHeld, /* xMutexNotHeld */
/***** other *********************/
lsmPosixOsSleep, /* xSleep */
};
return &posix_env;
}
#endif
-201
View File
@@ -1,201 +0,0 @@
/*
** 2012-02-08
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
**
** SQLite4-compatible varint implementation.
*/
#include "lsmInt.h"
/*************************************************************************
** The following is a copy of the varint.c module from SQLite 4.
*/
/*
** Decode the varint in z[]. Write the integer value into *pResult and
** return the number of bytes in the varint.
*/
static int lsmSqlite4GetVarint64(const unsigned char *z, u64 *pResult){
unsigned int x;
if( z[0]<=240 ){
*pResult = z[0];
return 1;
}
if( z[0]<=248 ){
*pResult = (z[0]-241)*256 + z[1] + 240;
return 2;
}
if( z[0]==249 ){
*pResult = 2288 + 256*z[1] + z[2];
return 3;
}
if( z[0]==250 ){
*pResult = (z[1]<<16) + (z[2]<<8) + z[3];
return 4;
}
x = (z[1]<<24) + (z[2]<<16) + (z[3]<<8) + z[4];
if( z[0]==251 ){
*pResult = x;
return 5;
}
if( z[0]==252 ){
*pResult = (((u64)x)<<8) + z[5];
return 6;
}
if( z[0]==253 ){
*pResult = (((u64)x)<<16) + (z[5]<<8) + z[6];
return 7;
}
if( z[0]==254 ){
*pResult = (((u64)x)<<24) + (z[5]<<16) + (z[6]<<8) + z[7];
return 8;
}
*pResult = (((u64)x)<<32) +
(0xffffffff & ((z[5]<<24) + (z[6]<<16) + (z[7]<<8) + z[8]));
return 9;
}
/*
** Write a 32-bit unsigned integer as 4 big-endian bytes.
*/
static void lsmVarintWrite32(unsigned char *z, unsigned int y){
z[0] = (unsigned char)(y>>24);
z[1] = (unsigned char)(y>>16);
z[2] = (unsigned char)(y>>8);
z[3] = (unsigned char)(y);
}
/*
** Write a varint into z[]. The buffer z[] must be at least 9 characters
** long to accommodate the largest possible varint. Return the number of
** bytes of z[] used.
*/
static int lsmSqlite4PutVarint64(unsigned char *z, u64 x){
unsigned int w, y;
if( x<=240 ){
z[0] = (unsigned char)x;
return 1;
}
if( x<=2287 ){
y = (unsigned int)(x - 240);
z[0] = (unsigned char)(y/256 + 241);
z[1] = (unsigned char)(y%256);
return 2;
}
if( x<=67823 ){
y = (unsigned int)(x - 2288);
z[0] = 249;
z[1] = (unsigned char)(y/256);
z[2] = (unsigned char)(y%256);
return 3;
}
y = (unsigned int)x;
w = (unsigned int)(x>>32);
if( w==0 ){
if( y<=16777215 ){
z[0] = 250;
z[1] = (unsigned char)(y>>16);
z[2] = (unsigned char)(y>>8);
z[3] = (unsigned char)(y);
return 4;
}
z[0] = 251;
lsmVarintWrite32(z+1, y);
return 5;
}
if( w<=255 ){
z[0] = 252;
z[1] = (unsigned char)w;
lsmVarintWrite32(z+2, y);
return 6;
}
if( w<=32767 ){
z[0] = 253;
z[1] = (unsigned char)(w>>8);
z[2] = (unsigned char)w;
lsmVarintWrite32(z+3, y);
return 7;
}
if( w<=16777215 ){
z[0] = 254;
z[1] = (unsigned char)(w>>16);
z[2] = (unsigned char)(w>>8);
z[3] = (unsigned char)w;
lsmVarintWrite32(z+4, y);
return 8;
}
z[0] = 255;
lsmVarintWrite32(z+1, w);
lsmVarintWrite32(z+5, y);
return 9;
}
/*
** End of SQLite 4 code.
*************************************************************************/
int lsmVarintPut64(u8 *aData, i64 iVal){
return lsmSqlite4PutVarint64(aData, (u64)iVal);
}
int lsmVarintGet64(const u8 *aData, i64 *piVal){
return lsmSqlite4GetVarint64(aData, (u64 *)piVal);
}
int lsmVarintPut32(u8 *aData, int iVal){
return lsmSqlite4PutVarint64(aData, (u64)iVal);
}
int lsmVarintGet32(u8 *z, int *piVal){
u64 i;
int ret;
if( z[0]<=240 ){
*piVal = z[0];
return 1;
}
if( z[0]<=248 ){
*piVal = (z[0]-241)*256 + z[1] + 240;
return 2;
}
if( z[0]==249 ){
*piVal = 2288 + 256*z[1] + z[2];
return 3;
}
if( z[0]==250 ){
*piVal = (z[1]<<16) + (z[2]<<8) + z[3];
return 4;
}
ret = lsmSqlite4GetVarint64(z, &i);
*piVal = (int)i;
return ret;
}
int lsmVarintLen32(int n){
u8 aData[9];
return lsmVarintPut32(aData, n);
}
int lsmVarintLen64(i64 n){
u8 aData[9];
return lsmVarintPut64(aData, n);
}
/*
** The argument is the first byte of a varint. This function returns the
** total number of bytes in the entire varint (including the first byte).
*/
int lsmVarintSize(u8 c){
if( c<241 ) return 1;
if( c<249 ) return 2;
return (int)(c - 246);
}
-1084
View File
File diff suppressed because it is too large Load Diff
-1063
View File
File diff suppressed because it is too large Load Diff
-38
View File
@@ -1,38 +0,0 @@
# 2014 Dec 19
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
#
if {![info exists testdir]} {
set testdir [file join [file dirname [info script]] .. .. .. test]
}
source $testdir/tester.tcl
# Check if the lsm1 extension has been compiled.
if {$::tcl_platform(platform) == "windows"} {
set lsm1 lsm.dll
} else {
set lsm1 lsm.so
}
if {[file exists [file join .. $lsm1]]} {
proc return_if_no_lsm1 {} {}
} else {
proc return_if_no_lsm1 {} {
finish_test
return -code return
}
return
}
proc load_lsm1_vtab {db} {
db enable_load_extension 1
db eval {SELECT load_extension('../lsm')}
}
-152
View File
@@ -1,152 +0,0 @@
# 2017 July 14
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#*************************************************************************
# This file implements regression tests for SQLite library. The
# focus of this script is testing the lsm1 virtual table module.
#
source [file join [file dirname [info script]] lsm1_common.tcl]
set testprefix lsm1_simple
return_if_no_lsm1
load_lsm1_vtab db
forcedelete testlsm.db
do_execsql_test 100 {
CREATE VIRTUAL TABLE x1 USING lsm1(testlsm.db,a,UINT,b,c,d);
PRAGMA table_info(x1);
} {
0 a UINT 1 {} 1
1 b {} 0 {} 0
2 c {} 0 {} 0
3 d {} 0 {} 0
}
do_execsql_test 110 {
INSERT INTO x1(a,b,c,d) VALUES(15, 11, 22, 33),(8,'banjo',x'333231',NULL),
(12,NULL,3.25,-559281390);
SELECT a, quote(b), quote(c), quote(d) FROM x1;
} {8 'banjo' X'333231' NULL 12 NULL 3.25 -559281390 15 11 22 33}
do_execsql_test 111 {
SELECT a, quote(lsm1_key), quote(lsm1_value) FROM x1;
} {8 X'08' X'2162616E6A6F1633323105' 12 X'0C' X'05320000000000000A401FFB42ABE9DB' 15 X'0F' X'4284C6'}
do_execsql_test 120 {
UPDATE x1 SET d = d+1.0 WHERE a=15;
SELECT a, quote(b), quote(c), quote(d) FROM x1;
} {8 'banjo' X'333231' NULL 12 NULL 3.25 -559281390 15 11 22 34.0}
do_execsql_test 130 {
UPDATE x1 SET a=123456789 WHERE a=12;
SELECT a, quote(b), quote(c), quote(d) FROM x1;
} {8 'banjo' X'333231' NULL 15 11 22 34.0 123456789 NULL 3.25 -559281390}
do_execsql_test 131 {
SELECT quote(lsm1_key), printf('0x%x',a) FROM x1 WHERE a > 100000000;
} {X'FB075BCD15' 0x75bcd15}
do_execsql_test 140 {
DELETE FROM x1 WHERE a=15;
SELECT a, quote(b), quote(c), quote(d) FROM x1;
} {8 'banjo' X'333231' NULL 123456789 NULL 3.25 -559281390}
do_test 150 {
lsort [glob testlsm.db*]
} {testlsm.db testlsm.db-log testlsm.db-shm}
db close
do_test 160 {
lsort [glob testlsm.db*]
} {testlsm.db}
forcedelete testlsm.db
forcedelete test.db
sqlite3 db test.db
load_lsm1_vtab db
do_execsql_test 200 {
CREATE VIRTUAL TABLE x1 USING lsm1(testlsm.db,a,TEXT,b,c,d);
PRAGMA table_info(x1);
} {
0 a TEXT 1 {} 1
1 b {} 0 {} 0
2 c {} 0 {} 0
3 d {} 0 {} 0
}
do_execsql_test 210 {
INSERT INTO x1(a,b,c,d) VALUES(15, 11, 22, 33),(8,'banjo',x'333231',NULL),
(12,NULL,3.25,-559281390);
SELECT quote(a), quote(b), quote(c), quote(d), '|' FROM x1;
} {'12' NULL 3.25 -559281390 | '15' 11 22 33 | '8' 'banjo' X'333231' NULL |}
do_execsql_test 211 {
SELECT quote(a), quote(lsm1_key), quote(lsm1_value), '|' FROM x1;
} {'12' X'3132' X'05320000000000000A401FFB42ABE9DB' | '15' X'3135' X'4284C6' | '8' X'38' X'2162616E6A6F1633323105' |}
do_execsql_test 212 {
SELECT quote(a), quote(lsm1_key), quote(lsm1_value) FROM x1 WHERE a='12';
} {'12' X'3132' X'05320000000000000A401FFB42ABE9DB'}
#-------------------------------------------------------------------------
reset_db
forcedelete testlsm.db
load_lsm1_vtab db
do_execsql_test 300 {
CREATE VIRTUAL TABLE x1 USING lsm1(testlsm.db,a,TEXT,b,c,d);
}
do_eqp_test 310 {
SELECT * FROM x1 WHERE a=?
} {SCAN TABLE x1 VIRTUAL TABLE INDEX 0:}
do_eqp_test 320 {
SELECT * FROM x1 WHERE a>?
} {SCAN TABLE x1 VIRTUAL TABLE INDEX 2:}
do_eqp_test 330 {
SELECT * FROM x1 WHERE a<?
} {SCAN TABLE x1 VIRTUAL TABLE INDEX 3:}
do_eqp_test 340 {
SELECT * FROM x1 WHERE a BETWEEN ? AND ?
} {SCAN TABLE x1 VIRTUAL TABLE INDEX 1:}
#-------------------------------------------------------------------------
reset_db
forcedelete testlsm.db
load_lsm1_vtab db
do_execsql_test 400 {
CREATE VIRTUAL TABLE x1 USING lsm1(testlsm.db,a,TEXT,b);
INSERT INTO x1 VALUES('one', 1);
INSERT INTO x1 VALUES('two', 2);
INSERT INTO x1 VALUES('three', 3);
INSERT INTO x1 VALUES('four', 4);
INSERT INTO x1 VALUES('five', 5);
}
do_execsql_test 410 {
SELECT b FROM x1 WHERE a = 'two'
} {2}
do_execsql_test 411 {
SELECT b FROM x1 WHERE a = 'one'
} {1}
do_execsql_test 412 {
SELECT b FROM x1 WHERE a = 'five'
} {5}
do_execsql_test 420 {
SELECT b FROM x1 WHERE a BETWEEN 'one' AND 'three';
} {1 3}
do_execsql_test 421 {
SELECT b FROM x1 WHERE a BETWEEN 'five' AND 'two';
} {5 4 1 3 2}
do_execsql_test 421 {
SELECT b FROM x1 WHERE a > 'five';
} {4 1 3 2}
do_execsql_test 421 {
SELECT b FROM x1 WHERE a <= 'three';
} {3 1 4 5}
finish_test
-88
View File
@@ -1,88 +0,0 @@
#!/bin/sh
# restart with tclsh \
exec tclsh "$0" "$@"
set srcdir [file dirname [file dirname [info script]]]
set G(src) [string map [list %dir% $srcdir] {
%dir%/lsm.h
%dir%/lsmInt.h
%dir%/lsm_vtab.c
%dir%/lsm_ckpt.c
%dir%/lsm_file.c
%dir%/lsm_log.c
%dir%/lsm_main.c
%dir%/lsm_mem.c
%dir%/lsm_mutex.c
%dir%/lsm_shared.c
%dir%/lsm_sorted.c
%dir%/lsm_str.c
%dir%/lsm_tree.c
%dir%/lsm_unix.c
%dir%/lsm_varint.c
%dir%/lsm_win32.c
}]
set G(hdr) {
#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_LSM1)
#if !defined(NDEBUG) && !defined(SQLITE_DEBUG)
# define NDEBUG 1
#endif
#if defined(NDEBUG) && defined(SQLITE_DEBUG)
# undef NDEBUG
#endif
}
set G(footer) {
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_LSM1) */
}
#-------------------------------------------------------------------------
# Read and return the entire contents of text file $zFile from disk.
#
proc readfile {zFile} {
set fd [open $zFile]
set data [read $fd]
close $fd
return $data
}
proc lsm1c_init {zOut} {
global G
set G(fd) stdout
set G(fd) [open $zOut w]
puts -nonewline $G(fd) $G(hdr)
}
proc lsm1c_printfile {zIn} {
global G
set data [readfile $zIn]
set zTail [file tail $zIn]
puts $G(fd) "#line 1 \"$zTail\""
foreach line [split $data "\n"] {
if {[regexp {^# *include.*lsm} $line]} {
set line "/* $line */"
} elseif { [regexp {^(const )?[a-zA-Z][a-zA-Z0-9]* [*]?lsm[^_]} $line] } {
set line "static $line"
}
puts $G(fd) $line
}
}
proc lsm1c_close {} {
global G
puts -nonewline $G(fd) $G(footer)
if {$G(fd)!="stdout"} {
close $G(fd)
}
}
lsm1c_init lsm1.c
foreach f $G(src) { lsm1c_printfile $f }
lsm1c_close
+1 -1
View File
@@ -32,7 +32,7 @@ SQLITE_API int sqlite3_carray_bind(
void *aData, /* Pointer to array data */
int nData, /* Number of data elements */
int mFlags, /* CARRAY flags */
void (*xDel)(void*) /* Destructgor for aData*/
void (*xDel)(void*) /* Destructor for aData */
);
/* Allowed values for the mFlags parameter to sqlite3_carray_bind().
+5 -38
View File
@@ -197,8 +197,6 @@ struct CksmFile {
char computeCksm; /* True to compute checksums.
** Always true if reserve size is 8. */
char verifyCksm; /* True to verify checksums */
char isWal; /* True if processing a WAL file */
char inCkpt; /* Currently doing a checkpoint */
CksmFile *pPartner; /* Ptr from WAL to main-db, or from main-db to WAL */
};
@@ -444,11 +442,9 @@ static int cksmRead(
** (1) the size indicates that we are dealing with a complete
** database page
** (2) checksum verification is enabled
** (3) we are not in the middle of checkpoint
*/
if( iAmt>=512 && (iAmt & (iAmt-1))==0 /* (1) */
&& p->verifyCksm /* (2) */
&& !p->inCkpt /* (3) */
){
u8 cksum[8];
cksmCompute((u8*)zBuf, iAmt-8, cksum);
@@ -489,7 +485,6 @@ static int cksmWrite(
*/
if( iAmt>=512
&& p->computeCksm
&& !p->inCkpt
){
cksmCompute((u8*)zBuf, iAmt-8, ((u8*)zBuf)+iAmt-8);
}
@@ -576,21 +571,6 @@ static int cksmFileControl(sqlite3_file *pFile, int op, void *pArg){
/* Do not allow page size changes on a checksum database */
return SQLITE_OK;
}
}else if( op==SQLITE_FCNTL_CKPT_START || op==SQLITE_FCNTL_CKPT_DONE ){
p->inCkpt = op==SQLITE_FCNTL_CKPT_START;
if( p->pPartner ) p->pPartner->inCkpt = p->inCkpt;
}else if( op==SQLITE_FCNTL_CKSM_FILE ){
/* This VFS needs to obtain a pointer to the corresponding database
** file handle from within xOpen() calls to open wal files. To do this,
** it uses the sqlite3_database_file_object() API to obtain a pointer
** to the file-handle used by SQLite to access the db file. This is
** fine if cksmvfs happens to be the top-level VFS, but not if there
** are one or more wrapper VFS. To handle this case, this file-control
** is used to extract the cksmvfs file-handle from any wrapper file
** handle. */
sqlite3_file **ppFile = (sqlite3_file**)pArg;
*ppFile = (sqlite3_file*)p;
return SQLITE_OK;
}
rc = pFile->pMethods->xFileControl(pFile, op, pArg);
if( rc==SQLITE_OK && op==SQLITE_FCNTL_VFSNAME ){
@@ -611,8 +591,10 @@ static int cksmSectorSize(sqlite3_file *pFile){
** Return the device characteristic flags supported by a cksm-file.
*/
static int cksmDeviceCharacteristics(sqlite3_file *pFile){
int devchar = 0;
pFile = ORIGFILE(pFile);
return pFile->pMethods->xDeviceCharacteristics(pFile);
devchar = pFile->pMethods->xDeviceCharacteristics(pFile);
return (devchar & ~SQLITE_IOCAP_SUBPAGE_READ);
}
/* Create a shared memory file mapping */
@@ -689,7 +671,7 @@ static int cksmOpen(
sqlite3_vfs *pSubVfs;
int rc;
pSubVfs = ORIGVFS(pVfs);
if( (flags & (SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_WAL))==0 ){
if( (flags & SQLITE_OPEN_MAIN_DB)==0 ){
return pSubVfs->xOpen(pSubVfs, zName, pFile, flags, pOutFlags);
}
p = (CksmFile*)pFile;
@@ -698,19 +680,6 @@ static int cksmOpen(
pFile->pMethods = &cksm_io_methods;
rc = pSubVfs->xOpen(pSubVfs, zName, pSubFile, flags, pOutFlags);
if( rc ) goto cksm_open_done;
if( flags & SQLITE_OPEN_WAL ){
sqlite3_file *pDb = sqlite3_database_file_object(zName);
rc = pDb->pMethods->xFileControl(pDb, SQLITE_FCNTL_CKSM_FILE, (void*)&pDb);
assert( rc==SQLITE_OK );
p->pPartner = (CksmFile*)pDb;
assert( p->pPartner->pPartner==0 );
p->pPartner->pPartner = p;
p->isWal = 1;
p->computeCksm = p->pPartner->computeCksm;
}else{
p->isWal = 0;
p->computeCksm = 0;
}
p->zFName = zName;
cksm_open_done:
if( rc ) pFile->pMethods = 0;
@@ -820,9 +789,7 @@ static int cksmRegisterFunc(
*/
static int cksmRegisterVfs(void){
int rc = SQLITE_OK;
sqlite3_vfs *pOrig;
if( sqlite3_vfs_find("cksmvfs")!=0 ) return SQLITE_OK;
pOrig = sqlite3_vfs_find(0);
sqlite3_vfs *pOrig = sqlite3_vfs_find(0);
if( pOrig==0 ) return SQLITE_ERROR;
cksm_vfs.iVersion = pOrig->iVersion;
cksm_vfs.pAppData = pOrig;
+52 -3
View File
@@ -14,6 +14,13 @@
** on stdout when its key interfaces are called. This is intended for
** interactive analysis and debugging of virtual table interfaces.
**
** To build this extension as a separately loaded shared library or
** DLL, use compiler command-lines similar to the following:
**
** (linux) gcc -fPIC -shared vtablog.c -o vtablog.so
** (mac) clang -fPIC -dynamiclib vtablog.c -o vtablog.dylib
** (windows) cl vtablog.c -link -dll -out:vtablog.dll
**
** Usage example:
**
** .load ./vtablog
@@ -435,6 +442,39 @@ static int vtablogFilter(
return SQLITE_OK;
}
/*
** Return an sqlite3_index_info operator name in static space.
** The name is possibly overwritten on subsequent calls.
*/
static char *vtablogOpName(unsigned char op){
static char zUnknown[30];
char *zOut;
switch( op ){
case SQLITE_INDEX_CONSTRAINT_EQ: zOut = "EQ"; break;
case SQLITE_INDEX_CONSTRAINT_GT: zOut = "GT"; break;
case SQLITE_INDEX_CONSTRAINT_LE: zOut = "LE"; break;
case SQLITE_INDEX_CONSTRAINT_LT: zOut = "LT"; break;
case SQLITE_INDEX_CONSTRAINT_GE: zOut = "GE"; break;
case SQLITE_INDEX_CONSTRAINT_MATCH: zOut = "MATCH"; break;
case SQLITE_INDEX_CONSTRAINT_LIKE: zOut = "LIKE"; break;
case SQLITE_INDEX_CONSTRAINT_GLOB: zOut = "GLOB"; break;
case SQLITE_INDEX_CONSTRAINT_REGEXP: zOut = "REGEXP"; break;
case SQLITE_INDEX_CONSTRAINT_NE: zOut = "NE"; break;
case SQLITE_INDEX_CONSTRAINT_ISNOT: zOut = "ISNOT"; break;
case SQLITE_INDEX_CONSTRAINT_ISNOTNULL: zOut = "ISNOTNULL"; break;
case SQLITE_INDEX_CONSTRAINT_ISNULL: zOut = "ISNULL"; break;
case SQLITE_INDEX_CONSTRAINT_IS: zOut = "IS"; break;
case SQLITE_INDEX_CONSTRAINT_LIMIT: zOut = "LIMIT"; break;
case SQLITE_INDEX_CONSTRAINT_OFFSET: zOut = "OFFSET"; break;
case SQLITE_INDEX_CONSTRAINT_FUNCTION: zOut = "FUNCTION"; break;
default:
sqlite3_snprintf(sizeof(zUnknown),zUnknown,"%d",op);
zOut = zUnknown;
break;
}
return zOut;
}
/*
** SQLite will invoke this method one or more times while planning a query
** that uses the vtablog virtual table. This routine needs to create
@@ -451,14 +491,23 @@ static int vtablogBestIndex(
printf(" colUsed: 0x%016llx\n", p->colUsed);
printf(" nConstraint: %d\n", p->nConstraint);
for(i=0; i<p->nConstraint; i++){
sqlite3_value *pVal = 0;
int rc = sqlite3_vtab_rhs_value(p, i, &pVal);
printf(
" constraint[%d]: col=%d termid=%d op=%d usabled=%d collseq=%s\n",
" constraint[%d]: col=%d termid=%d op=%s usabled=%d coll=%s rhs=",
i,
p->aConstraint[i].iColumn,
p->aConstraint[i].iTermOffset,
p->aConstraint[i].op,
vtablogOpName(p->aConstraint[i].op),
p->aConstraint[i].usable,
sqlite3_vtab_collation(p,i));
sqlite3_vtab_collation(p,i)
);
if( rc==SQLITE_OK ){
vtablogQuote(pVal);
printf("\n");
}else{
printf("N/A\n");
}
}
printf(" nOrderBy: %d\n", p->nOrderBy);
for(i=0; i<p->nOrderBy; i++){
+20 -2
View File
@@ -116,6 +116,7 @@ static const char ZIPFILE_SCHEMA[] =
#define ZIPFILE_F_COLUMN_IDX 7 /* Index of column "file" in the above */
#define ZIPFILE_BUFFER_SIZE (64*1024)
#define ZIPFILE_MX_NAME (250) /* Windows limitation on filename size */
/*
@@ -672,6 +673,7 @@ static int zipfileReadLFH(
pLFH->szUncompressed = zipfileRead32(aRead);
pLFH->nFile = zipfileRead16(aRead);
pLFH->nExtra = zipfileRead16(aRead);
if( pLFH->nFile>ZIPFILE_MX_NAME ) rc = SQLITE_ERROR;
}
return rc;
}
@@ -885,8 +887,12 @@ static int zipfileGetEntry(
pNew->iDataOff = pNew->cds.iOffset + ZIPFILE_LFH_FIXED_SZ;
pNew->iDataOff += lfh.nFile + lfh.nExtra;
if( aBlob && pNew->cds.szCompressed ){
pNew->aData = &pNew->aExtra[nExtra];
memcpy(pNew->aData, &aBlob[pNew->iDataOff], pNew->cds.szCompressed);
if( pNew->iDataOff + pNew->cds.szCompressed > nBlob ){
rc = SQLITE_CORRUPT;
}else{
pNew->aData = &pNew->aExtra[nExtra];
memcpy(pNew->aData, &aBlob[pNew->iDataOff], pNew->cds.szCompressed);
}
}
}else{
*pzErr = sqlite3_mprintf("failed to read LFH at offset %d",
@@ -1673,6 +1679,11 @@ static int zipfileUpdate(
zPath = (const char*)sqlite3_value_text(apVal[2]);
if( zPath==0 ) zPath = "";
nPath = (int)strlen(zPath);
if( nPath>ZIPFILE_MX_NAME ){
zipfileTableErr(pTab, "filename too long; max: %d bytes",
ZIPFILE_MX_NAME);
rc = SQLITE_CONSTRAINT;
}
mTime = zipfileGetTime(apVal[4]);
}
@@ -2034,6 +2045,13 @@ static void zipfileStep(sqlite3_context *pCtx, int nVal, sqlite3_value **apVal){
rc = SQLITE_ERROR;
goto zipfile_step_out;
}
if( nName>ZIPFILE_MX_NAME ){
zErr = sqlite3_mprintf(
"filename argument to zipfile() too big; max: %d bytes",
ZIPFILE_MX_NAME);
rc = SQLITE_ERROR;
goto zipfile_step_out;
}
/* Inspect the 'method' parameter. This must be either 0 (store), 8 (use
** deflate compression) or NULL (choose automatically). */
+46 -14
View File
@@ -16,6 +16,17 @@
**
** unzorder(Z,N,I) Extract the I-th dimension from N-dimensional
** Morton code Z.
**
** Compiling:
**
** (linux) gcc -fPIC -shared zorder.c -o zorder.so
** (mac) clang -fPIC -dynamiclib zorder.c -o zorder.dylib
** (windows) cl zorder.c -link -dll -out:zorder.dll
**
** Usage example:
**
** .load ./zorder
** SELECT zorder(1,2,3,4);
*/
#include "sqlite3ext.h"
SQLITE_EXTENSION_INIT1
@@ -25,43 +36,53 @@ SQLITE_EXTENSION_INIT1
/*
** Functions: zorder(X0,X1,....)
**
** Convert integers X0, X1, ... into morton code.
** Convert integers X0, X1, ... into morton code. There must be at least
** two arguments. There may be no more than 24 arguments.
**
** The output is a signed 64-bit integer. If any argument is too large,
** an error is thrown.
** The output is a signed 64-bit integer. If any argument is too large
** to be successfully encoded into a morton code, an error is raised.
*/
static void zorderFunc(
sqlite3_context *context,
int argc,
sqlite3_value **argv
){
sqlite3_int64 z, x[63];
sqlite3_int64 z, x[24];
int i, j;
z = 0;
if( argc<2 || argc>24 ){
sqlite3_result_error(context,
"zorder() needs between 2 and 24 arguments4", -1);
return;
}
for(i=0; i<argc; i++){
x[i] = sqlite3_value_int64(argv[i]);
}
if( argc>0 ){
for(i=0; i<63; i++){
j = i%argc;
z |= (x[j]&1)<<i;
x[j] >>= 1;
}
for(i=0; i<63; i++){
j = i%argc;
z |= (x[j]&1)<<i;
x[j] >>= 1;
}
sqlite3_result_int64(context, z);
for(i=0; i<argc; i++){
if( x[i] ){
sqlite3_result_error(context, "parameter too large", -1);
char *z = sqlite3_mprintf(
"the %r argument to zorder() (%lld) is too large "
"for a 64-bit %d-dimensional Morton code",
i+1, sqlite3_value_int64(argv[i]), argc);
sqlite3_result_error(context, z, -1);
sqlite3_free(z);
break;
}
}
}
/*
** Functions: unzorder(Z,N,I)
** Function: unzorder(Z,N,K)
**
** Assuming that Z is an N-dimensional Morton code, extract the I-th
** dimension.
** Assuming that Z is an N-dimensional Morton code, extract the K-th
** dimension. K is between 0 and N-1. N must be between 2 and 24.
*/
static void unzorderFunc(
sqlite3_context *context,
@@ -72,7 +93,18 @@ static void unzorderFunc(
int j, k;
z = sqlite3_value_int64(argv[0]);
n = sqlite3_value_int64(argv[1]);
if( n<2 || n>24 ){
sqlite3_result_error(context,
"N argument to unzorder(Z,N,K) should be between 2 and 24",
-1);
return;
}
i = sqlite3_value_int64(argv[2]);
if( i<0 || i>=n ){
sqlite3_result_error(context,
"K argument to unzorder(Z,N,K) should be between 0 and N-1", -1);
return;
}
x = 0;
for(k=0, j=i; j<63; j+=n, k++){
x |= ((z>>j)&1)<<k;
+6
View File
@@ -1135,6 +1135,12 @@ static void resetCursor(RtreeCursor *pCsr){
pCsr->base.pVtab = (sqlite3_vtab*)pRtree;
pCsr->pReadAux = pStmt;
/* The following will only fail if the previous sqlite3_step() call failed,
** in which case the error has already been caught. This statement never
** encounters an error within an sqlite3_column_xxx() function, as it
** calls sqlite3_column_value(), which does not use malloc(). So it is safe
** to ignore the error code here. */
sqlite3_reset(pStmt);
}
/*
+19
View File
@@ -99,5 +99,24 @@ do_execsql_test rtreeH-300 {
ORDER BY id;
} {box-48,48 box-49,48 box-48,49 xbox-49,49}
#-------------------------------------------------------------------------
reset_db
do_execsql_test rtreeH-300 {
CREATE TABLE t0(c0);
INSERT INTO t0(c0) VALUES (NULL);
INSERT INTO t0(c0) VALUES (1);
CREATE VIRTUAL TABLE t1 USING rtree(c0, c1, c2, +c3 BLOB );
INSERT INTO t1(c2, c3, c0) VALUES (1, 2, 1);
}
do_execsql_test rtreeH-310 {
SELECT 1 FROM t1 WHERE t1.c3;
} {1}
do_execsql_test rtreeH-320 {
SELECT * FROM t0 WHERE NOT EXISTS (
SELECT 1 FROM t1 WHERE t1.c3 OR t0.c0 ISNULL
);
} {}
finish_test
+88
View File
@@ -0,0 +1,88 @@
# 2015 July 14
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
#
#
if {![info exists testdir]} {
set testdir [file join [file dirname [info script]] .. .. test]
}
source [file join [file dirname [info script]] session_common.tcl]
source $testdir/tester.tcl
ifcapable !session {finish_test; return}
set testprefix sessionI
forcedelete test.db2
sqlite3 db2 test.db2
do_test 1.0 {
do_common_sql {
CREATE TABLE t1(x INTEGER PRIMARY KEY, y);
}
} {}
set C [changeset_from_sql {
INSERT INTO t1 VALUES(1, 'one');
INSERT INTO t1 VALUES(2, 'two');
INSERT INTO t1 VALUES(3, 'three');
INSERT INTO t1 VALUES(4, 'four');
INSERT INTO t1 VALUES(5, 'five');
INSERT INTO t1 VALUES(6, 'six');
}]
do_execsql_test 1.1 {
SELECT * FROM t1
} {
1 one 2 two 3 three 4 four 5 five 6 six
}
proc xFilter {data} {
foreach {op tname flag pk old new} $data {}
if {$op=="INSERT"} {
set ipk [lindex $new 1]
return [expr $ipk % 2]
}
return 1
}
proc xConflict {args} {
}
sqlite3changeset_apply_v3 db2 $C xConflict xFilter
do_execsql_test -db db2 1.2 {
SELECT * FROM t1
} {
1 one 3 three 5 five
}
do_execsql_test -db db2 1.3 {
DELETE FROM t1
}
sqlite3changeset_apply_v3 db2 $C xConflict
do_execsql_test -db db2 1.4 {
SELECT * FROM t1
} {
1 one 2 two 3 three 4 four 5 five 6 six
}
proc xFilter2 {data} {
return 0
}
do_execsql_test -db db2 1.5 {
DELETE FROM t1
}
sqlite3changeset_apply_v3 db2 $C xConflict xFilter2
do_execsql_test -db db2 1.6 {
SELECT * FROM t1
} { }
finish_test
+141
View File
@@ -174,6 +174,147 @@ do_test 3.5 {
{INSERT sqlite_stat1 CONFLICT {t xyz t sqlite_autoindex_xyz_1 t {100 1 1}} {t xyz t sqlite_autoindex_xyz_1 t {200 1 1}}}
}]
#-------------------------------------------------------------------------
# Test that the conflict-handler is invoked for conflicts caused by
# DELETE ops even if SQLITE_CHANGESETAPPLY_IGNORENOOP is specified.
#
set ::conflict_list [list]
proc xConflict {args} {
lappend ::conflict_list $args
return "OMIT"
}
foreach {tn wo} {
1 ""
2 " WITHOUT ROWID "
} {
reset_db
forcedelete test.db2
do_execsql_test 4.$tn.0 "
CREATE TABLE x1(a INTEGER PRIMARY KEY, b, c) $wo;
INSERT INTO x1 VALUES(1, 'one', 'i');
INSERT INTO x1 VALUES(2, 'two', 'ii');
INSERT INTO x1 VALUES(3, 'three', 'iii');
VACUUM INTO 'test.db2';
"
set C [changeset_from_sql {
DELETE FROM x1 WHERE a=2;
}]
sqlite3 db2 test.db2
do_execsql_test -db db2 4.$tn.1 {
UPDATE x1 SET b='four hundred' WHERE a=2;
}
do_test 4.$tn.2.1 {
set ::conflict_list [list]
sqlite3changeset_apply_v2 db2 $C xConflict
set ::conflict_list
} [list {*}{
{DELETE x1 DATA {i 2 t two t ii} {i 2 t {four hundred} t ii}}
}]
do_test 4.$tn.2.2 {
set ::conflict_list [list]
sqlite3changeset_apply_v2 -ignorenoop db2 $C xConflict
set ::conflict_list
} [list {*}{
{DELETE x1 DATA {i 2 t two t ii} {i 2 t {four hundred} t ii}}
}]
}
foreach {tn wo} {
1 ""
2 " WITHOUT ROWID "
} {
reset_db
forcedelete test.db2
do_execsql_test 5.$tn.0 "
PRAGMA foreign_keys = ON;
CREATE TABLE p1(a INTEGER PRIMARY KEY, b, c) $wo;
CREATE TABLE c1(a INTEGER PRIMARY KEY REFERENCES p1, b);
INSERT INTO p1 VALUES(1, 'one', 'i');
INSERT INTO p1 VALUES(2, 'two', 'ii');
INSERT INTO p1 VALUES(3, 'three', 'iii');
VACUUM INTO 'test.db2';
"
set C [changeset_from_sql {
DELETE FROM p1 WHERE a=2;
}]
sqlite3 db2 test.db2
do_execsql_test -db db2 5.$tn.1 {
PRAGMA foreign_keys = ON;
INSERT INTO c1 VALUES(2, 'xyz');
}
do_test 5.$tn.2.1 {
set ::conflict_list [list]
sqlite3changeset_apply_v2 db2 $C xConflict
set ::conflict_list
} [list {*}{
{FOREIGN_KEY 1}
}]
# Reinsert the row deleted by test case 5.$tn.2.1
execsql { INSERT INTO p1 VALUES(2, 'two', 'ii') } db2
do_test 5.$tn.2.2 {
set ::conflict_list [list]
sqlite3changeset_apply_v2 -ignorenoop db2 $C xConflict
set ::conflict_list
} [list {*}{
{FOREIGN_KEY 1}
}]
}
foreach {tn wo} {
1 ""
2 " WITHOUT ROWID "
} {
reset_db
forcedelete test.db2
do_execsql_test 6.$tn.0 "
CREATE TABLE x1(a INTEGER PRIMARY KEY, b, c) $wo;
CREATE TABLE x2(x UNIQUE);
INSERT INTO x1 VALUES(1, 'one', 'i');
INSERT INTO x1 VALUES(2, 'two', 'ii');
INSERT INTO x1 VALUES(3, 'three', 'iii');
VACUUM INTO 'test.db2';
"
set C [changeset_from_sql {
DELETE FROM x1 WHERE a=2;
}]
sqlite3 db2 test.db2
do_execsql_test -db db2 6.$tn.1 {
INSERT INTO x2 VALUES(0);
CREATE TRIGGER tr1 AFTER DELETE ON x1 BEGIN
INSERT INTO x2 VALUES(0);
END;
}
do_test 6.$tn.2.1 {
set ::conflict_list [list]
sqlite3changeset_apply_v2 db2 $C xConflict
set ::conflict_list
} [list {*}{
{DELETE x1 CONSTRAINT {i 2 t two t ii}}
}]
breakpoint
do_test 6.$tn.2.2 {
set ::conflict_list [list]
sqlite3changeset_apply_v2 -ignorenoop db2 $C xConflict
set ::conflict_list
} [list {*}{
{DELETE x1 CONSTRAINT {i 2 t two t ii}}
}]
}
finish_test
+163 -30
View File
@@ -4833,7 +4833,7 @@ static int sessionConflictHandler(
void *pCtx, /* First argument for conflict handler */
int *pbReplace /* OUT: Set to true if PK row is found */
){
int res = 0; /* Value returned by conflict handler */
int res = SQLITE_CHANGESET_OMIT;/* Value returned by conflict handler */
int rc;
int nCol;
int op;
@@ -4854,11 +4854,9 @@ static int sessionConflictHandler(
if( rc==SQLITE_ROW ){
/* There exists another row with the new.* primary key. */
if( p->bIgnoreNoop
&& sqlite3_column_int(p->pSelect, sqlite3_column_count(p->pSelect)-1)
if( 0==p->bIgnoreNoop
|| 0==sqlite3_column_int(p->pSelect, sqlite3_column_count(p->pSelect)-1)
){
res = SQLITE_CHANGESET_OMIT;
}else{
pIter->pConflict = p->pSelect;
res = xConflict(pCtx, eType, pIter);
pIter->pConflict = 0;
@@ -4872,7 +4870,9 @@ static int sessionConflictHandler(
int nBlob = pIter->in.iNext - pIter->in.iCurrent;
sessionAppendBlob(&p->constraints, aBlob, nBlob, &rc);
return SQLITE_OK;
}else{
}else if( p->bIgnoreNoop==0 || op!=SQLITE_DELETE
|| eType==SQLITE_CHANGESET_CONFLICT
){
/* No other row with the new.* primary key. */
res = xConflict(pCtx, eType+1, pIter);
if( res==SQLITE_CHANGESET_REPLACE ) rc = SQLITE_MISUSE;
@@ -4970,7 +4970,7 @@ static int sessionApplyOneOp(
sqlite3_step(p->pDelete);
rc = sqlite3_reset(p->pDelete);
if( rc==SQLITE_OK && sqlite3_changes(p->db)==0 && p->bIgnoreNoop==0 ){
if( rc==SQLITE_OK && sqlite3_changes(p->db)==0 ){
rc = sessionConflictHandler(
SQLITE_CHANGESET_DATA, p, pIter, xConflict, pCtx, pbRetry
);
@@ -5182,6 +5182,10 @@ static int sessionChangesetApply(
void *pCtx, /* Copy of sixth arg to _apply() */
const char *zTab /* Table name */
),
int(*xFilterIter)(
void *pCtx, /* Copy of sixth arg to _apply() */
sqlite3_changeset_iter *p
),
int(*xConflict)(
void *pCtx, /* Copy of fifth arg to _apply() */
int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
@@ -5322,6 +5326,9 @@ static int sessionChangesetApply(
** next change. A log message has already been issued. */
if( schemaMismatch ) continue;
/* If this is a call to apply_v3(), invoke xFilterIter here. */
if( xFilterIter && 0==xFilterIter(pCtx, pIter) ) continue;
rc = sessionApplyOneWithRetry(db, pIter, &sApply, xConflict, pCtx);
}
@@ -5389,6 +5396,87 @@ static int sessionChangesetApply(
return rc;
}
/*
** This function is called by all six sqlite3changeset_apply() variants:
**
** + sqlite3changeset_apply()
** + sqlite3changeset_apply_v2()
** + sqlite3changeset_apply_v3()
** + sqlite3changeset_apply_strm()
** + sqlite3changeset_apply_strm_v2()
** + sqlite3changeset_apply_strm_v3()
**
** Arguments passed to this function are as follows:
**
** db:
** Database handle to apply changeset to main database of.
**
** nChangeset/pChangeset:
** These are both passed zero for the streaming variants. For the normal
** apply() functions, these are passed the size of and the buffer containing
** the changeset, respectively.
**
** xInput/pIn:
** These are both passed zero for the normal variants. For the streaming
** apply() functions, these are passed the input callback and context
** pointer, respectively.
**
** xFilter:
** The filter function as passed to apply() or apply_v2() (to filter by
** table name), if any. This is always NULL for apply_v3() calls.
**
** xFilterIter:
** The filter function as passed to apply_v3(), if any.
**
** xConflict:
** The conflict handler callback (must not be NULL).
**
** pCtx:
** The context pointer passed to the xFilter and xConflict handler callbacks.
**
** ppRebase, pnRebase:
** Zero for apply(). The rebase changeset output pointers, if any, for
** apply_v2() and apply_v3().
**
** flags:
** Zero for apply(). The flags parameter for apply_v2() and apply_v3().
*/
static int sessionChangesetApplyV23(
sqlite3 *db, /* Apply change to "main" db of this handle */
int nChangeset, /* Size of changeset in bytes */
void *pChangeset, /* Changeset blob */
int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */
void *pIn, /* First arg for xInput */
int(*xFilter)(
void *pCtx, /* Copy of sixth arg to _apply() */
const char *zTab /* Table name */
),
int(*xFilterIter)(
void *pCtx, /* Copy of sixth arg to _apply() */
sqlite3_changeset_iter *p /* Handle describing current change */
),
int(*xConflict)(
void *pCtx, /* Copy of sixth arg to _apply() */
int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
sqlite3_changeset_iter *p /* Handle describing change and conflict */
),
void *pCtx, /* First argument passed to xConflict */
void **ppRebase, int *pnRebase,
int flags
){
sqlite3_changeset_iter *pIter; /* Iterator to skip through changeset */
int bInverse = !!(flags & SQLITE_CHANGESETAPPLY_INVERT);
int rc = sessionChangesetStart(
&pIter, xInput, pIn, nChangeset, pChangeset, bInverse, 1
);
if( rc==SQLITE_OK ){
rc = sessionChangesetApply(db, pIter,
xFilter, xFilterIter, xConflict, pCtx, ppRebase, pnRebase, flags
);
}
return rc;
}
/*
** Apply the changeset passed via pChangeset/nChangeset to the main
** database attached to handle "db".
@@ -5410,17 +5498,39 @@ int sqlite3changeset_apply_v2(
void **ppRebase, int *pnRebase,
int flags
){
sqlite3_changeset_iter *pIter; /* Iterator to skip through changeset */
int bInv = !!(flags & SQLITE_CHANGESETAPPLY_INVERT);
int rc = sessionChangesetStart(&pIter, 0, 0, nChangeset, pChangeset, bInv, 1);
return sessionChangesetApplyV23(db,
nChangeset, pChangeset, 0, 0,
xFilter, 0, xConflict, pCtx,
ppRebase, pnRebase, flags
);
}
if( rc==SQLITE_OK ){
rc = sessionChangesetApply(
db, pIter, xFilter, xConflict, pCtx, ppRebase, pnRebase, flags
);
}
return rc;
/*
** Apply the changeset passed via pChangeset/nChangeset to the main
** database attached to handle "db".
*/
int sqlite3changeset_apply_v3(
sqlite3 *db, /* Apply change to "main" db of this handle */
int nChangeset, /* Size of changeset in bytes */
void *pChangeset, /* Changeset blob */
int(*xFilter)(
void *pCtx, /* Copy of sixth arg to _apply() */
sqlite3_changeset_iter *p /* Handle describing current change */
),
int(*xConflict)(
void *pCtx, /* Copy of sixth arg to _apply() */
int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
sqlite3_changeset_iter *p /* Handle describing change and conflict */
),
void *pCtx, /* First argument passed to xConflict */
void **ppRebase, int *pnRebase,
int flags
){
return sessionChangesetApplyV23(db,
nChangeset, pChangeset, 0, 0,
0, xFilter, xConflict, pCtx,
ppRebase, pnRebase, flags
);
}
/*
@@ -5443,8 +5553,10 @@ int sqlite3changeset_apply(
),
void *pCtx /* First argument passed to xConflict */
){
return sqlite3changeset_apply_v2(
db, nChangeset, pChangeset, xFilter, xConflict, pCtx, 0, 0, 0
return sessionChangesetApplyV23(db,
nChangeset, pChangeset, 0, 0,
xFilter, 0, xConflict, pCtx,
0, 0, 0
);
}
@@ -5453,6 +5565,29 @@ int sqlite3changeset_apply(
** attached to handle "db". Invoke the supplied conflict handler callback
** to resolve any conflicts encountered while applying the change.
*/
int sqlite3changeset_apply_v3_strm(
sqlite3 *db, /* Apply change to "main" db of this handle */
int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */
void *pIn, /* First arg for xInput */
int(*xFilter)(
void *pCtx, /* Copy of sixth arg to _apply() */
sqlite3_changeset_iter *p
),
int(*xConflict)(
void *pCtx, /* Copy of sixth arg to _apply() */
int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
sqlite3_changeset_iter *p /* Handle describing change and conflict */
),
void *pCtx, /* First argument passed to xConflict */
void **ppRebase, int *pnRebase,
int flags
){
return sessionChangesetApplyV23(db,
0, 0, xInput, pIn,
0, xFilter, xConflict, pCtx,
ppRebase, pnRebase, flags
);
}
int sqlite3changeset_apply_v2_strm(
sqlite3 *db, /* Apply change to "main" db of this handle */
int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */
@@ -5470,15 +5605,11 @@ int sqlite3changeset_apply_v2_strm(
void **ppRebase, int *pnRebase,
int flags
){
sqlite3_changeset_iter *pIter; /* Iterator to skip through changeset */
int bInverse = !!(flags & SQLITE_CHANGESETAPPLY_INVERT);
int rc = sessionChangesetStart(&pIter, xInput, pIn, 0, 0, bInverse, 1);
if( rc==SQLITE_OK ){
rc = sessionChangesetApply(
db, pIter, xFilter, xConflict, pCtx, ppRebase, pnRebase, flags
);
}
return rc;
return sessionChangesetApplyV23(db,
0, 0, xInput, pIn,
xFilter, 0, xConflict, pCtx,
ppRebase, pnRebase, flags
);
}
int sqlite3changeset_apply_strm(
sqlite3 *db, /* Apply change to "main" db of this handle */
@@ -5495,8 +5626,10 @@ int sqlite3changeset_apply_strm(
),
void *pCtx /* First argument passed to xConflict */
){
return sqlite3changeset_apply_v2_strm(
db, xInput, pIn, xFilter, xConflict, pCtx, 0, 0, 0
return sessionChangesetApplyV23(db,
0, 0, xInput, pIn,
xFilter, 0, xConflict, pCtx,
0, 0, 0
);
}
+55 -12
View File
@@ -1115,13 +1115,22 @@ void sqlite3changegroup_delete(sqlite3_changegroup*);
** the changeset passed via the second and third arguments.
**
** The fourth argument (xFilter) passed to these functions is the "filter
** callback". If it is not NULL, then for each table affected by at least one
** change in the changeset, the filter callback is invoked with
** the table name as the second argument, and a copy of the context pointer
** passed as the sixth argument as the first. If the "filter callback"
** returns zero, then no attempt is made to apply any changes to the table.
** Otherwise, if the return value is non-zero or the xFilter argument to
** is NULL, all changes related to the table are attempted.
** callback". This may be passed NULL, in which case all changes in the
** changeset are applied to the database. For sqlite3changeset_apply() and
** sqlite3_changeset_apply_v2(), if it is not NULL, then it is invoked once
** for each table affected by at least one change in the changeset. In this
** case the table name is passed as the second argument, and a copy of
** the context pointer passed as the sixth argument to apply() or apply_v2()
** as the first. If the "filter callback" returns zero, then no attempt is
** made to apply any changes to the table. Otherwise, if the return value is
** non-zero, all changes related to the table are attempted.
**
** For sqlite3_changeset_apply_v3(), the xFilter callback is invoked once
** per change. The second argument in this case is an sqlite3_changeset_iter
** that may be queried using the usual APIs for the details of the current
** change. If the "filter callback" returns zero in this case, then no attempt
** is made to apply the current change. If it returns non-zero, the change
** is applied.
**
** For each table that is not excluded by the filter callback, this function
** tests that the target database contains a compatible table. A table is
@@ -1142,11 +1151,11 @@ void sqlite3changegroup_delete(sqlite3_changegroup*);
** one such warning is issued for each table in the changeset.
**
** For each change for which there is a compatible table, an attempt is made
** to modify the table contents according to the UPDATE, INSERT or DELETE
** change. If a change cannot be applied cleanly, the conflict handler
** function passed as the fifth argument to sqlite3changeset_apply() may be
** invoked. A description of exactly when the conflict handler is invoked for
** each type of change is below.
** to modify the table contents according to each UPDATE, INSERT or DELETE
** change that is not excluded by a filter callback. If a change cannot be
** applied cleanly, the conflict handler function passed as the fifth argument
** to sqlite3changeset_apply() may be invoked. A description of exactly when
** the conflict handler is invoked for each type of change is below.
**
** Unlike the xFilter argument, xConflict may not be passed NULL. The results
** of passing anything other than a valid function pointer as the xConflict
@@ -1297,6 +1306,23 @@ int sqlite3changeset_apply_v2(
void **ppRebase, int *pnRebase, /* OUT: Rebase data */
int flags /* SESSION_CHANGESETAPPLY_* flags */
);
int sqlite3changeset_apply_v3(
sqlite3 *db, /* Apply change to "main" db of this handle */
int nChangeset, /* Size of changeset in bytes */
void *pChangeset, /* Changeset blob */
int(*xFilter)(
void *pCtx, /* Copy of sixth arg to _apply() */
sqlite3_changeset_iter *p /* Handle describing change */
),
int(*xConflict)(
void *pCtx, /* Copy of sixth arg to _apply() */
int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
sqlite3_changeset_iter *p /* Handle describing change and conflict */
),
void *pCtx, /* First argument passed to xConflict */
void **ppRebase, int *pnRebase, /* OUT: Rebase data */
int flags /* SESSION_CHANGESETAPPLY_* flags */
);
/*
** CAPI3REF: Flags for sqlite3changeset_apply_v2
@@ -1716,6 +1742,23 @@ int sqlite3changeset_apply_v2_strm(
void **ppRebase, int *pnRebase,
int flags
);
int sqlite3changeset_apply_v3_strm(
sqlite3 *db, /* Apply change to "main" db of this handle */
int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */
void *pIn, /* First arg for xInput */
int(*xFilter)(
void *pCtx, /* Copy of sixth arg to _apply() */
sqlite3_changeset_iter *p
),
int(*xConflict)(
void *pCtx, /* Copy of sixth arg to _apply() */
int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
sqlite3_changeset_iter *p /* Handle describing change and conflict */
),
void *pCtx, /* First argument passed to xConflict */
void **ppRebase, int *pnRebase,
int flags
);
int sqlite3changeset_concat_strm(
int (*xInputA)(void *pIn, void *pData, int *pnData),
void *pInA,
+141 -84
View File
@@ -520,6 +520,65 @@ static int test_obj_eq_string(Tcl_Obj *p, const char *z){
return (nObj==n && (n==0 || 0==memcmp(zObj, z, n)));
}
static Tcl_Obj *testIterData(sqlite3_changeset_iter *pIter){
Tcl_Obj *pVar = 0;
int nCol; /* Number of columns in table */
int nCol2; /* Number of columns in table */
int op; /* SQLITE_INSERT, UPDATE or DELETE */
const char *zTab; /* Name of table change applies to */
Tcl_Obj *pOld; /* Vector of old.* values */
Tcl_Obj *pNew; /* Vector of new.* values */
int bIndirect;
char *zPK;
unsigned char *abPK;
int i;
sqlite3changeset_op(pIter, &zTab, &nCol, &op, &bIndirect);
pVar = Tcl_NewObj();
Tcl_ListObjAppendElement(0, pVar, Tcl_NewStringObj(
op==SQLITE_INSERT ? "INSERT" :
op==SQLITE_UPDATE ? "UPDATE" :
"DELETE", -1
));
Tcl_ListObjAppendElement(0, pVar, Tcl_NewStringObj(zTab, -1));
Tcl_ListObjAppendElement(0, pVar, Tcl_NewBooleanObj(bIndirect));
zPK = ckalloc(nCol+1);
memset(zPK, 0, nCol+1);
sqlite3changeset_pk(pIter, &abPK, &nCol2);
assert( nCol==nCol2 );
for(i=0; i<nCol; i++){
zPK[i] = (abPK[i] ? 'X' : '.');
}
Tcl_ListObjAppendElement(0, pVar, Tcl_NewStringObj(zPK, -1));
ckfree(zPK);
pOld = Tcl_NewObj();
if( op!=SQLITE_INSERT ){
for(i=0; i<nCol; i++){
sqlite3_value *pVal;
sqlite3changeset_old(pIter, i, &pVal);
test_append_value(pOld, pVal);
}
}
pNew = Tcl_NewObj();
if( op!=SQLITE_DELETE ){
for(i=0; i<nCol; i++){
sqlite3_value *pVal;
sqlite3changeset_new(pIter, i, &pVal);
test_append_value(pNew, pVal);
}
}
Tcl_ListObjAppendElement(0, pVar, pOld);
Tcl_ListObjAppendElement(0, pVar, pNew);
return pVar;
}
static int test_filter_handler(
void *pCtx, /* Pointer to TestConflictHandler structure */
const char *zTab /* Table name */
@@ -543,6 +602,29 @@ static int test_filter_handler(
return res;
}
static int test_filter_v3_handler(
void *pCtx, /* Pointer to TestConflictHandler structure */
sqlite3_changeset_iter *pIter
){
TestConflictHandler *p = (TestConflictHandler *)pCtx;
int res = 1;
Tcl_Obj *pEval = 0;
Tcl_Interp *interp = p->interp;
pEval = Tcl_DuplicateObj(p->pFilterScript);
Tcl_IncrRefCount(pEval);
Tcl_ListObjAppendElement(0, pEval, testIterData(pIter));
if( TCL_OK!=Tcl_EvalObjEx(interp, pEval, TCL_EVAL_GLOBAL)
|| TCL_OK!=Tcl_GetIntFromObj(interp, Tcl_GetObjResult(interp), &res)
){
Tcl_BackgroundError(interp);
}
Tcl_DecrRefCount(pEval);
return res;
}
static int test_conflict_handler(
void *pCtx, /* Pointer to TestConflictHandler structure */
int eConf, /* DATA, MISSING, CONFLICT, CONSTRAINT */
@@ -776,7 +858,7 @@ static int testStreamInput(
static int SQLITE_TCLAPI testSqlite3changesetApply(
int bV2,
int iVersion,
void * clientData,
Tcl_Interp *interp,
int objc,
@@ -793,11 +875,13 @@ static int SQLITE_TCLAPI testSqlite3changesetApply(
int nRebase = 0;
int flags = 0; /* Flags for apply_v2() */
assert( iVersion==1 || iVersion==2 || iVersion==3 );
memset(&sStr, 0, sizeof(sStr));
sStr.nStream = test_tcl_integer(interp, SESSION_STREAM_TCL_VAR);
/* Check for the -nosavepoint, -invert or -ignorenoop switches */
if( bV2 ){
if( iVersion==2 || iVersion==3 ){
while( objc>1 ){
const char *z1 = Tcl_GetString(objv[1]);
int n = (int)strlen(z1);
@@ -822,7 +906,7 @@ static int SQLITE_TCLAPI testSqlite3changesetApply(
if( objc!=4 && objc!=5 ){
const char *zMsg;
if( bV2 ){
if( iVersion==2 || iVersion==3 ){
zMsg = "?-nosavepoint? ?-inverse? ?-ignorenoop? "
"DB CHANGESET CONFLICT-SCRIPT ?FILTER-SCRIPT?";
}else{
@@ -842,30 +926,49 @@ static int SQLITE_TCLAPI testSqlite3changesetApply(
ctx.interp = interp;
if( sStr.nStream==0 ){
if( bV2==0 ){
rc = sqlite3changeset_apply(db, (int)nChangeset, pChangeset,
(objc==5)?test_filter_handler:0, test_conflict_handler, (void *)&ctx
);
}else{
rc = sqlite3changeset_apply_v2(db, (int)nChangeset, pChangeset,
(objc==5)?test_filter_handler:0, test_conflict_handler, (void *)&ctx,
&pRebase, &nRebase, flags
);
switch( iVersion ){
case 1:
rc = sqlite3changeset_apply(db, (int)nChangeset, pChangeset,
(objc==5)?test_filter_handler:0, test_conflict_handler, (void*)&ctx
);
break;
case 2:
rc = sqlite3changeset_apply_v2(db, (int)nChangeset, pChangeset,
(objc==5)?test_filter_handler:0, test_conflict_handler, (void*)&ctx,
&pRebase, &nRebase, flags
);
break;
case 3:
rc = sqlite3changeset_apply_v3(db, (int)nChangeset, pChangeset,
(objc==5)?test_filter_v3_handler:0, test_conflict_handler,
(void*)&ctx, &pRebase, &nRebase, flags
);
break;
}
}else{
sStr.aData = (unsigned char*)pChangeset;
sStr.nData = (int)nChangeset;
if( bV2==0 ){
rc = sqlite3changeset_apply_strm(db, testStreamInput, (void*)&sStr,
(objc==5) ? test_filter_handler : 0,
test_conflict_handler, (void *)&ctx
);
}else{
rc = sqlite3changeset_apply_v2_strm(db, testStreamInput, (void*)&sStr,
(objc==5) ? test_filter_handler : 0,
test_conflict_handler, (void *)&ctx,
&pRebase, &nRebase, flags
);
switch( iVersion ){
case 1:
rc = sqlite3changeset_apply_strm(db, testStreamInput, (void*)&sStr,
(objc==5) ? test_filter_handler : 0,
test_conflict_handler, (void *)&ctx
);
break;
case 2:
rc = sqlite3changeset_apply_v2_strm(db, testStreamInput, (void*)&sStr,
(objc==5) ? test_filter_handler : 0,
test_conflict_handler, (void *)&ctx,
&pRebase, &nRebase, flags
);
break;
case 3:
rc = sqlite3changeset_apply_v3_strm(db, testStreamInput, (void*)&sStr,
(objc==5) ? test_filter_v3_handler : 0,
test_conflict_handler, (void *)&ctx,
&pRebase, &nRebase, flags
);
break;
}
}
@@ -873,7 +976,7 @@ static int SQLITE_TCLAPI testSqlite3changesetApply(
return test_session_error(interp, rc, 0);
}else{
Tcl_ResetResult(interp);
if( bV2 && pRebase ){
if( (iVersion==2 || iVersion==3) && pRebase ){
Tcl_SetObjResult(interp, Tcl_NewByteArrayObj(pRebase, nRebase));
}
}
@@ -890,7 +993,7 @@ static int SQLITE_TCLAPI test_sqlite3changeset_apply(
int objc,
Tcl_Obj *CONST objv[]
){
return testSqlite3changesetApply(0, clientData, interp, objc, objv);
return testSqlite3changesetApply(1, clientData, interp, objc, objv);
}
/*
** sqlite3changeset_apply_v2 DB CHANGESET CONFLICT-SCRIPT ?FILTER-SCRIPT?
@@ -901,7 +1004,18 @@ static int SQLITE_TCLAPI test_sqlite3changeset_apply_v2(
int objc,
Tcl_Obj *CONST objv[]
){
return testSqlite3changesetApply(1, clientData, interp, objc, objv);
return testSqlite3changesetApply(2, clientData, interp, objc, objv);
}
/*
** sqlite3changeset_apply_v3 DB CHANGESET CONFLICT-SCRIPT ?FILTER-SCRIPT?
*/
static int SQLITE_TCLAPI test_sqlite3changeset_apply_v3(
void * clientData,
Tcl_Interp *interp,
int objc,
Tcl_Obj *CONST objv[]
){
return testSqlite3changesetApply(3, clientData, interp, objc, objv);
}
/*
@@ -1034,64 +1148,6 @@ static int SQLITE_TCLAPI test_sqlite3changeset_concat(
return rc;
}
static Tcl_Obj *testIterData(sqlite3_changeset_iter *pIter){
Tcl_Obj *pVar = 0;
int nCol; /* Number of columns in table */
int nCol2; /* Number of columns in table */
int op; /* SQLITE_INSERT, UPDATE or DELETE */
const char *zTab; /* Name of table change applies to */
Tcl_Obj *pOld; /* Vector of old.* values */
Tcl_Obj *pNew; /* Vector of new.* values */
int bIndirect;
char *zPK;
unsigned char *abPK;
int i;
sqlite3changeset_op(pIter, &zTab, &nCol, &op, &bIndirect);
pVar = Tcl_NewObj();
Tcl_ListObjAppendElement(0, pVar, Tcl_NewStringObj(
op==SQLITE_INSERT ? "INSERT" :
op==SQLITE_UPDATE ? "UPDATE" :
"DELETE", -1
));
Tcl_ListObjAppendElement(0, pVar, Tcl_NewStringObj(zTab, -1));
Tcl_ListObjAppendElement(0, pVar, Tcl_NewBooleanObj(bIndirect));
zPK = ckalloc(nCol+1);
memset(zPK, 0, nCol+1);
sqlite3changeset_pk(pIter, &abPK, &nCol2);
assert( nCol==nCol2 );
for(i=0; i<nCol; i++){
zPK[i] = (abPK[i] ? 'X' : '.');
}
Tcl_ListObjAppendElement(0, pVar, Tcl_NewStringObj(zPK, -1));
ckfree(zPK);
pOld = Tcl_NewObj();
if( op!=SQLITE_INSERT ){
for(i=0; i<nCol; i++){
sqlite3_value *pVal;
sqlite3changeset_old(pIter, i, &pVal);
test_append_value(pOld, pVal);
}
}
pNew = Tcl_NewObj();
if( op!=SQLITE_DELETE ){
for(i=0; i<nCol; i++){
sqlite3_value *pVal;
sqlite3changeset_new(pIter, i, &pVal);
test_append_value(pNew, pVal);
}
}
Tcl_ListObjAppendElement(0, pVar, pOld);
Tcl_ListObjAppendElement(0, pVar, pNew);
return pVar;
}
/*
** sqlite3session_foreach VARNAME CHANGESET SCRIPT
*/
@@ -1751,6 +1807,7 @@ int TestSession_Init(Tcl_Interp *interp){
{ "sqlite3changeset_concat", test_sqlite3changeset_concat },
{ "sqlite3changeset_apply", test_sqlite3changeset_apply },
{ "sqlite3changeset_apply_v2", test_sqlite3changeset_apply_v2 },
{ "sqlite3changeset_apply_v3", test_sqlite3changeset_apply_v3 },
{ "sqlite3changeset_apply_replace_all",
test_sqlite3changeset_apply_replace_all },
{ "sql_exec_changeset", test_sql_exec_changeset },
+210 -189
View File
@@ -1,11 +1,10 @@
#######################################################################
# This GNU makefile drives the build of the sqlite3 WASM
# components. It is not part of the canonical build process.
# This GNU makefile creates the canonical sqlite3 WASM builds.
#
# This build assumes a Linux platform and is not intended for
# general-purpose client-level use, except for creating builds with
# custom configurations. It is primarily intended for the sqlite
# project's own development of the JS/WASM components.
# custom configurations. It is primarily intended for the SQLite
# project's own development of its JS/WASM components.
#
# Primary targets:
#
@@ -39,10 +38,11 @@
########################################################################
default: all
#default: quick
MAKEFILE := $(lastword $(MAKEFILE_LIST))
CLEAN_FILES :=
DISTCLEAN_FILES := config.make
MAKING_CLEAN := $(if $(filter %clean,$(MAKECMDGOALS)),1,0)
MAKEFILE = $(lastword $(MAKEFILE_LIST))
MAKEFILE.fiddle = fiddle.make
CLEAN_FILES =
DISTCLEAN_FILES = config.make
MAKING_CLEAN = $(if $(filter %clean,$(MAKECMDGOALS)),1,0)
.PHONY: clean distclean
clean:
-rm -f $(CLEAN_FILES)
@@ -53,17 +53,17 @@ distclean: clean
########################################################################
# Special-case builds for which we require certain pre-conditions
# which, if not met, may cause warnings or fatal errors in the build.
# This also affects the default optimization level flags. Note that
# the fiddle targets are in this list because they are used for
# generating sqlite.org/fiddle.
OPTIMIZED_TARGETS := dist snapshot fiddle fiddle.debug
# This also affects the default optimization level flags. The fiddle
# targets are in this list because they are used for generating
# sqlite.org/fiddle.
OPTIMIZED_TARGETS = dist snapshot fiddle fiddle.debug
ifeq (1,$(MAKING_CLEAN))
bin.wasm-strip := echo "not stripping"
bin.wasm-opt := irrelevant
bin.emcc := irrelevant
bin.bash := irrelevant
emcc.version := unknown
bin.wasm-strip = echo "not stripping"
bin.wasm-opt = irrelevant
bin.emcc = irrelevant
bin.bash = irrelevant
emcc.version = unknown
else
# Include config.make and perform some bootstrapping...
ifeq (,$(wildcard ./config.make))
@@ -76,7 +76,7 @@ else
ifeq (,$(bin.emcc))
$(error Configure script did not find emcc)
endif
emcc.version := $(shell $(bin.emcc) --version | sed -n 1p | sed -e 's/^.* \([3-9][^ ]*\) .*$$/\1/;')
emcc.version = $(shell $(bin.emcc) --version | sed -n 1p | sed -e 's/^.* \([3-9][^ ]*\) .*$$/\1/;')
$(info using emcc version [$(emcc.version)])
ifeq (,$(bin.wasm-strip))
####################################################################
@@ -98,7 +98,7 @@ else
ifneq (,$(filter $(OPTIMIZED_TARGETS),$(MAKECMDGOALS)))
$(error Cannot make release-quality binary because wasm-strip is not available.)
endif
bin.wasm-strip := echo "not wasm-stripping"
bin.wasm-strip = echo "not wasm-stripping"
endif
ifeq (,$(filter $(OPTIMIZED_TARGETS),$(MAKECMDGOALS)))
$(info ==============================================================)
@@ -108,7 +108,7 @@ else
endif
endif
# ^^^ end of are-we-MAKING_CLEAN
maybe-wasm-strip := $(bin.wasm-strip)
maybe-wasm-strip = $(bin.wasm-strip)
########################################################################
# JS_BUILD_NAMES exists for documentation purposes only. It enumerates
@@ -118,7 +118,7 @@ maybe-wasm-strip := $(bin.wasm-strip)
#
# - sqlite3-wasmfs = WASMFS-capable library build
#
JS_BUILD_NAMES := sqlite3 sqlite3-wasmfs
JS_BUILD_NAMES = sqlite3 sqlite3-wasmfs
########################################################################
# JS_BUILD_MODES exists for documentation purposes only. It enumerates
@@ -133,38 +133,41 @@ JS_BUILD_NAMES := sqlite3 sqlite3-wasmfs
# - bundler-friendly = esm slightly tweaked for "bundler"
# tools. Bundlers are invariably based on node.js, so these builds
# are intended to be read at build-time by node.js but with a final
# target of browsers.
# target of browsers. All bundler-friendly builds are UNTESTED.
# They are provided primarily for use by the community-supported
# subproject which hosts npm builds of sqlite3, and they are
# actively supported only to the extent needed by that subproject.
#
# - node = for use by node.js for node.js, as opposed to by node.js on
# behalf of browser-side code (use bundler-friendly for that). Note
# that persistent storage (OPFS) is not available in these builds.
# These builds are UNTESTED and UNSUPPORTED!
#
JS_BUILD_MODES := vanilla esm bunder-friendly node
JS_BUILD_MODES = vanilla esm bunder-friendly node
########################################################################
# dir.top = the top dir of the canonical build tree, where
# sqlite3.[ch] live.
dir.top := ../..
dir.top = ../..
# Maintenance reminder: some Emscripten flags require absolute paths
# but we want relative paths for most stuff simply to reduce
# noise. The $(abspath...) GNU make function can transform relative
# paths to absolute.
dir.wasm := $(patsubst %/,%,$(dir $(MAKEFILE)))
dir.api := api
dir.jacc := jaccwabyt
dir.common := common
dir.fiddle := fiddle
dir.fiddle-debug := fiddle-debug
dir.tool := $(dir.top)/tool
dir.wasm = $(patsubst %/,%,$(dir $(MAKEFILE)))
dir.api = api
dir.jacc = jaccwabyt
dir.common = common
dir.fiddle = fiddle
dir.fiddle-debug = fiddle-debug
dir.tool = $(dir.top)/tool
# dir.dout = output dir for deliverables
dir.dout := $(dir.wasm)/jswasm
dir.dout = $(dir.wasm)/jswasm
# dir.tmp = output dir for intermediary build files, as opposed to
# end-user deliverables.
dir.tmp := $(dir.wasm)/bld
dir.wasmfs := $(dir.dout)
dir.tmp = $(dir.wasm)/bld
dir.wasmfs = $(dir.dout)
MKDIR.bld := $(dir.tmp)
MKDIR.bld = $(dir.tmp)
$(MKDIR.bld):
@mkdir -p $@ $(dir.dout)
@@ -188,17 +191,17 @@ CLEAN_FILES += *~ $(dir.jacc)/*~ $(dir.api)/*~ $(dir.common)/*~ $(dir.fiddle)/*~
# $(sqlite3.canonical.c) must point to the sqlite3.c in
# the sqlite3 canonical source tree, as that source file
# is required for certain utility and test code.
sqlite3.canonical.c := $(dir.top)/sqlite3.c
sqlite3.canonical.c = $(dir.top)/sqlite3.c
sqlite3.c ?= $(firstword $(wildcard $(dir.top)/sqlite3-see.c) $(sqlite3.canonical.c))
sqlite3.h := $(dir.top)/sqlite3.h
sqlite3.h = $(dir.top)/sqlite3.h
ifeq (1,$(MAKING_CLEAN))
SQLITE_C_IS_SEE := 0
SQLITE_C_IS_SEE = 0
else
ifeq (,$(shell grep sqlite3_activate_see $(sqlite3.c)))
SQLITE_C_IS_SEE := 0
SQLITE_C_IS_SEE = 0
else
SQLITE_C_IS_SEE := 1
SQLITE_C_IS_SEE = 1
$(info This is an SEE build)
endif
endif
@@ -216,19 +219,19 @@ $(sqlite3.c): $(sqlite3.h)
# barebones=1 disables all "extraneous" stuff from sqlite3-wasm.c, the
# goal being to create a WASM file with only the core APIs.
ifeq (1,$(barebones))
wasm-bare-bones := 1
wasm-bare-bones = 1
$(info ==============================================================)
$(info == This is a bare-bones build. It trades away features for)
$(info == a smaller .wasm file.)
$(info ==============================================================)
else
wasm-bare-bones := 0
wasm-bare-bones = 0
endif
# undefine barebones # relatively new gmake feature, not ubiquitous
# Common options for building sqlite3-wasm.c and speedtest1.c.
# Explicit ENABLEs...
SQLITE_OPT.common := \
SQLITE_OPT.common = \
-DSQLITE_THREADSAFE=0 \
-DSQLITE_TEMP_STORE=2 \
-DSQLITE_ENABLE_MATH_FUNCTIONS \
@@ -249,7 +252,7 @@ SQLITE_OPT.common := \
SQLITE_OPT.common += -DSQLITE_WASM_ENABLE_C_TESTS
# Extra flags for full-featured builds...
SQLITE_OPT.full-featured := \
SQLITE_OPT.full-featured = \
-DSQLITE_ENABLE_BYTECODE_VTAB \
-DSQLITE_ENABLE_DBPAGE_VTAB \
-DSQLITE_ENABLE_DBSTAT_VTAB \
@@ -265,12 +268,12 @@ SQLITE_OPT.full-featured := \
ifeq (0,$(wasm-bare-bones))
# The so-called canonical build is full-featured:
SQLITE_OPT := \
SQLITE_OPT = \
$(SQLITE_OPT.common) \
$(SQLITE_OPT.full-featured)
else
# The so-called bare-bones build is exactly that:
SQLITE_OPT := \
SQLITE_OPT = \
$(SQLITE_OPT.common) \
-DSQLITE_WASM_BARE_BONES
# SQLITE_WASM_BARE_BONES tells sqlite3-wasm.c to explicitly omit
@@ -345,10 +348,10 @@ endif
# See example_extra_init.c for an example implementation.
########################################################################
sqlite3_wasm_extra_init.c ?= $(wildcard sqlite3_wasm_extra_init.c)
cflags.wasm_extra_init :=
cflags.wasm_extra_init =
ifneq (,$(sqlite3_wasm_extra_init.c))
$(info Enabling SQLITE_EXTRA_INIT via $(sqlite3_wasm_extra_init.c).)
cflags.wasm_extra_init := -DSQLITE_WASM_EXTRA_INIT
cflags.wasm_extra_init = -DSQLITE_WASM_EXTRA_INIT
endif
#########################################################################
@@ -362,7 +365,7 @@ endif
# end result is that the generated JS files may have static version
# info from $(bin.version-info) which differ from their runtime-emitted
# version info (e.g. from sqlite3_libversion()).
bin.version-info := $(dir.top)/version-info
bin.version-info = $(dir.top)/version-info
.NOTPARALLEL: $(bin.version-info)
$(bin.version-info): $(dir.tool)/version-info.c $(sqlite3.h) $(dir.top)/Makefile
$(MAKE) -C $(dir.top) version-info
@@ -373,7 +376,7 @@ $(bin.version-info): $(dir.tool)/version-info.c $(sqlite3.h) $(dir.top)/Makefile
# don't need for all builds. That app's -k flag is of particular
# importance here, as it allows us to retain the opening comment
# block(s), which contain the license header and version info.
bin.stripccomments := $(dir.tool)/stripccomments
bin.stripccomments = $(dir.tool)/stripccomments
$(bin.stripccomments): $(bin.stripccomments).c $(MAKEFILE)
$(CC) -o $@ $<
DISTCLEAN_FILES += $(bin.stripccomments)
@@ -410,7 +413,7 @@ DISTCLEAN_FILES += $(bin.stripccomments)
#
# -D... flags which should be included in all invocations should be
# appended to $(SQLITE.CALL.C-PP.FILTER.global).
bin.c-pp := ./c-pp
bin.c-pp = ./c-pp
$(bin.c-pp): c-pp.c $(sqlite3.c) # $(MAKEFILE)
$(CC) -O0 -o $@ c-pp.c $(sqlite3.c) '-DCMPP_DEFAULT_DELIM="//#"' -I$(dir.top) \
-DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_OMIT_DEPRECATED -DSQLITE_OMIT_UTF16 \
@@ -429,13 +432,13 @@ define SQLITE.CALL.C-PP.FILTER
$(2): $(1) $$(MAKEFILE_LIST) $$(bin.c-pp)
@mkdir -p $$(dir $$@)
$$(bin.c-pp) -f $(1) -o $$@ $(3) $(SQLITE.CALL.C-PP.FILTER.global)
#CLEAN_FILES += $(2)
CLEAN_FILES += $(2)
endef
# /end SQLITE.CALL.C-PP.FILTER
########################################################################
# cflags.common = C compiler flags for all builds
cflags.common := -I. -I$(dir $(sqlite3.c))
cflags.common = -I. -I$(dir $(sqlite3.c))
# emcc.WASM_BIGINT = 1 for BigInt (C int64) support, else 0. The API
# disables certain features if BigInt is not enabled and such builds
# _are not tested_ on any regular basis.
@@ -450,15 +453,32 @@ emcc.WASM_BIGINT ?= 1
# has shown -Oz to produce the smallest deliverables with only a
# roughly 10% performance hit in the resulting WASM file compared to
# -O2 (which consistently creates the fastest-running deliverables).
# Build time suffers greatly compared to -O0, which is why -O0 is the
# default.
ifeq (,$(filter $(OPTIMIZED_TARGETS),$(MAKECMDGOALS)))
emcc_opt ?= -O0
else
emcc_opt ?= -Oz
endif
# Our JS code installs bindings of each sqlite3_...() WASM export. The
# generated Emscripten JS file does the same using its own framework,
# but we don't use those results and can speed up lib init, and reduce
# memory cost a bit, by stripping them out. Emscripten-side changes
# can "break" this, causing this to be a no-op, but the worst that can
# happen in that case is that it doesn't actually strip anything,
# leading to slightly larger JS files.
#
# This snippet is intended to be used in makefile targets which
# generate an Emscripten module and where $@ is the module's .js/.mjs
# file.
SQLITE.strip-createExportWrapper = \
sed -i -e '/^.*= \(_sqlite3\|_fiddle\)[^=]* = createExportWrapper/d' $@ || exit; \
echo '(Probably) stripped out extraneous createExportWrapper() parts.'
# When passing emcc_opt from the CLI, += and re-assignment have no
# effect, so emcc_opt+=-g3 doesn't work. So...
emcc_opt_full := $(emcc_opt) -g3
emcc_opt_full = $(emcc_opt) -g3
# ^^^ ALWAYS use -g3. See below for why.
#
# ^^^ -flto improves runtime speed at -O0 considerably but doubles
@@ -483,37 +503,34 @@ emcc_opt_full := $(emcc_opt) -g3
#
# Much practice has demonstrated that -O2 consistently gives the best
# runtime speeds, but not by a large enough factor to rule out use of
# -Oz when small deliverable size is a priority.
# -Oz when smaller deliverable size is a priority.
########################################################################
########################################################################
# EXPORTED_FUNCTIONS.* = files for use with Emscripten's
# -sEXPORTED_FUNCTION flag.
EXPORTED_FUNCTIONS.api.core := $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-core
EXPORTED_FUNCTIONS.api.in := $(EXPORTED_FUNCTIONS.api.core)
EXPORTED_FUNCTIONS.api.core = $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-core
EXPORTED_FUNCTIONS.api.in = $(EXPORTED_FUNCTIONS.api.core)
ifeq (1,$(SQLITE_C_IS_SEE))
EXPORTED_FUNCTIONS.api.in += $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-see
endif
ifeq (0,$(wasm-bare-bones))
EXPORTED_FUNCTIONS.api.in += $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-extras
endif
EXPORTED_FUNCTIONS.api := $(dir.tmp)/EXPORTED_FUNCTIONS.api
EXPORTED_FUNCTIONS.api = $(dir.tmp)/EXPORTED_FUNCTIONS.api
$(EXPORTED_FUNCTIONS.api): $(MKDIR.bld) $(EXPORTED_FUNCTIONS.api.in) $(sqlite3.c) $(MAKEFILE)
cat $(EXPORTED_FUNCTIONS.api.in) > $@
########################################################################
# sqlite3-license-version.js = generated JS file with the license
# header and version info.
sqlite3-license-version.js := $(dir.tmp)/sqlite3-license-version.js
# sqlite3-license-version-header.js = JS file containing only the
# license header.
sqlite3-license-version-header.js := $(dir.api)/sqlite3-license-version-header.js
sqlite3-license-version.js = $(dir.tmp)/sqlite3-license-version.js
# sqlite3-api-build-version.js = generated JS file which populates the
# sqlite3.version object using $(bin.version-info).
sqlite3-api-build-version.js := $(dir.tmp)/sqlite3-api-build-version.js
sqlite3-api-build-version.js = $(dir.tmp)/sqlite3-api-build-version.js
# sqlite3-api.jses = the list of JS files which make up
# $(sqlite3-api.js.in), in the order they need to be assembled.
sqlite3-api.jses := $(sqlite3-license-version.js)
sqlite3-api.jses = $(sqlite3-license-version.js)
# sqlite3-api-prologue.js: initial bootstrapping bits:
sqlite3-api.jses += $(dir.api)/sqlite3-api-prologue.js
# whwhasm.js and jaccwabyt.js: Low-level utils, mostly replacing
@@ -547,13 +564,13 @@ sqlite3-api.jses += $(dir.api)/sqlite3-api-cleanup.js
# SOAP.js is an external API file which is part of our distribution
# but not part of the sqlite3-api.js amalgamation. It's a component of
# the first OPFS VFS and necessarily an external file.
SOAP.js := $(dir.api)/sqlite3-opfs-async-proxy.js
SOAP.js.bld := $(dir.dout)/$(notdir $(SOAP.js))
SOAP.js = $(dir.api)/sqlite3-opfs-async-proxy.js
SOAP.js.bld = $(dir.dout)/$(notdir $(SOAP.js))
#
# $(sqlite3-api.ext.jses) = API-related files which are standalone files,
# not part of the amalgamation.
#
sqlite3-api.ext.jses := $(SOAP.js.bld)
sqlite3-api.ext.jses = $(SOAP.js.bld)
$(SOAP.js.bld): $(SOAP.js)
cp $< $@
@@ -570,20 +587,26 @@ $(SOAP.js.bld): $(SOAP.js)
# them. Tools like wasm-objdump can be used to find the list of
# imports but it's questionable whether a non-Emscripten tool could
# realistically use that info to provide proper implementations.
#
# Sidebar: some of the imports are used soley by the Emscripten glue,
# which the sqlite3 JS code does not rely on.
#
# We build $(sqlite3-api*.*) "because we can" and because it might be
# a useful point of experimentation for some clients, but the
# above-described caveat may well make them unusable for real-life
# clients.
# 2025-09-04: the most significant WASM imports sqlite3.wasm relies on
# are (A) sqlite3_malloc/sqlite3_free() (the memory-management APIs
# used by the whole library) and (B) the libc proxies for POSIX I/O
# emulation (arguably one of Emscripten's most convenient features
# when building C code for WASM). If we eliminate the POSIX I/O
# emulation then we could hypothetically eliminate all, or maybe all
# but one, Emscripten import dependency. We would either need to add
# our own POSIX emulation layer (not a trivial effort) or restrict the
# library to use of only in-memory VFSes and the JS-side VFSes.
#
# sqlite3-api.js.in = the generated sqlite3-api.js before it gets
# sqlite3-api.js.in = the amalgamated sqlite3-api.js before it gets
# preprocessed. It contains all of $(sqlite3-api.jses) but none of the
# Emscripten-specific headers and footers.
sqlite3-api.js.in := $(dir.tmp)/sqlite3-api.c-pp.js
sqlite3-api.js.in = $(dir.tmp)/sqlite3-api.c-pp.js
$(sqlite3-api.js.in): $(MKDIR.bld) $(sqlite3-api.jses) $(MAKEFILE)
@echo "Making $@..."
@echo "Making $@ ..."
@for i in $(sqlite3-api.jses); do \
echo "/* BEGIN FILE: $$i */"; \
cat $$i; \
@@ -592,7 +615,7 @@ $(sqlite3-api.js.in): $(MKDIR.bld) $(sqlite3-api.jses) $(MAKEFILE)
########################################################################
# emcc flags for .c/.o/.wasm/.js.
emcc.flags :=
emcc.flags =
ifeq (1,$(emcc.verbose))
emcc.flags += -v
# -v is _very_ loud but also informative about what it's doing
@@ -601,25 +624,25 @@ endif
########################################################################
# emcc flags for .c/.o.
emcc.cflags :=
emcc.cflags =
emcc.cflags += -std=c99 -fPIC
# -------------^^^^^^^^ we need c99 for $(sqlite3-wasm.c), primarily
# for variadic macros and snprintf() to implement
# sqlite3_wasm_enum_json().
# sqlite3__wasm_enum_json().
emcc.cflags += -I. -I$(dir.top)
########################################################################
# emcc flags specific to building .js/.wasm files...
emcc.jsflags := -fPIC
emcc.jsflags = -fPIC
emcc.jsflags += --no-entry
emcc.jsflags += -sWASM_BIGINT=$(emcc.WASM_BIGINT)
emcc.jsflags += -sMODULARIZE
emcc.jsflags += -sDYNAMIC_EXECUTION=0
emcc.jsflags += -sNO_POLYFILL
emcc.jsflags += -sEXPORTED_FUNCTIONS=@$(EXPORTED_FUNCTIONS.api)
emcc.exportedRuntimeMethods := \
-sEXPORTED_RUNTIME_METHODS=wasmMemory,HEAP8,HEAPU8,HEAP16,HEAPU16,HEAP32,HEAPU32,HEAP64,HEAPU64
emcc.exportedRuntimeMethods = \
-sEXPORTED_RUNTIME_METHODS=wasmMemory
# wasmMemory ==> required by our code for use with -sIMPORTED_MEMORY
# Emscripten 4.0.7 (2025-04-15) stops exporting HEAP* by default
# Emscripten 4.0.7 (2025-04-15) stops exporting HEAP* by default.
emcc.jsflags += $(emcc.exportedRuntimeMethods)
emcc.jsflags += -sUSE_CLOSURE_COMPILER=0
emcc.jsflags += -sIMPORTED_MEMORY
@@ -640,38 +663,39 @@ emcc.jsflags += -sSTRICT_JS=0
# -sSTRICT=1 Causes failures about unknown symbols which the build
# tools should be installing, e.g. __syscall_geteuid32
# -sENVIRONMENT values for the various build modes:
emcc.environment.vanilla := web,worker
emcc.environment.bundler-friendly := $(emcc.environment.vanilla)
emcc.environment.esm := $(emcc.environment.vanilla)
emcc.environment.node := node
# Note that adding ",node" to the list for the other builds causes
# Emscripten to generate code which confuses node: it cannot reliably
# determine whether the build is for a browser or for node.
# emcc -sENVIRONMENT values for the various build modes:
emcc.environment.vanilla = web,worker
emcc.environment.bundler-friendly = $(emcc.environment.vanilla)
emcc.environment.esm = $(emcc.environment.vanilla)
emcc.environment.node = node
# Adding ",node" to the list for the other builds causes Emscripten to
# generate code which confuses node: it cannot reliably determine
# whether the build is for a browser or for node. We neither build nor
# test node builds on a regular basis. They are fully unsupported.
########################################################################
# -sINITIAL_MEMORY: How much memory we need to start with is governed
# at least in part by whether -sALLOW_MEMORY_GROWTH is enabled. If so,
# we can start with less. If not, we need as much as we'll ever
# possibly use (which, of course, we can't know for sure). Note,
# however, that speedtest1 shows that performance for even moderate
# workloads MAY suffer considerably if we start small and have to grow
# at runtime. e.g. OPFS-backed (speedtest1 --size 75) take MAY take X
# time with 16mb+ memory and 3X time when starting with 8MB. However,
# such test results are inconsistent due to browser internals which
# are opaque to us.
# possibly use (which, of course, we can't know for sure). speedtest1
# shows that performance for even moderate workloads MAY suffer
# considerably if we start small and have to grow at runtime.
# e.g. OPFS-backed (speedtest1 --size 75) take MAY take X time with
# 16mb+ memory and 3X time when starting with 8MB. However, such test
# results are inconsistent due to browser internals which are opaque
# to us.
#
# 2024-03-04: emsdk 3.1.55 replaces INITIAL_MEMORY with INITIAL_HEAP,
# but also says (in its changelog): "Note that it is currently not
# supported in all configurations (#21071)."
# https://github.com/emscripten-core/emscripten/blob/main/ChangeLog.md
emcc.jsflags += -sALLOW_MEMORY_GROWTH
emcc.INITIAL_MEMORY.128 := 134217728
emcc.INITIAL_MEMORY.96 := 100663296
emcc.INITIAL_MEMORY.64 := 67108864
emcc.INITIAL_MEMORY.32 := 33554432
emcc.INITIAL_MEMORY.16 := 16777216
emcc.INITIAL_MEMORY.8 := 8388608
emcc.INITIAL_MEMORY.128 = 134217728
emcc.INITIAL_MEMORY.96 = 100663296
emcc.INITIAL_MEMORY.64 = 67108864
emcc.INITIAL_MEMORY.32 = 33554432
emcc.INITIAL_MEMORY.16 = 16777216
emcc.INITIAL_MEMORY.8 = 8388608
emcc.INITIAL_MEMORY ?= 16
ifeq (,$(emcc.INITIAL_MEMORY.$(emcc.INITIAL_MEMORY)))
$(error emcc.INITIAL_MEMORY must be one of: 8, 16, 32, 64, 96, 128 (megabytes))
@@ -704,7 +728,7 @@ emcc.jsflags += -sSTACK_SIZE=512KB
# symbols: we cannot "delete" the Emscripten-defined
# $(sqlite3.js.init-func) from vanilla builds (as opposed to ESM
# builds) because it's declared with "var".
sqlite3.js.init-func := sqlite3InitModule
sqlite3.js.init-func = sqlite3InitModule
emcc.jsflags += -sEXPORT_NAME=$(sqlite3.js.init-func)
emcc.jsflags += -sGLOBAL_BASE=4096 # HYPOTHETICALLY keep func table indexes from overlapping w/ heap addr.
#emcc.jsflags += -sSTRICT # fails due to missing __syscall_...()
@@ -772,17 +796,17 @@ $(sqlite3-api-build-version.js): $(MKDIR.bld) $(bin.version-info) $(MAKEFILE)
#
# Maintenance reminder: there are awk binaries out there which do not
# support -e SCRIPT.
$(sqlite3-license-version.js): $(MKDIR.bld) $(sqlite3.h) $(sqlite3-license-version-header.js) \
$(MAKEFILE)
$(sqlite3-license-version.js): $(MKDIR.bld) $(sqlite3.h) \
$(dir.api)/sqlite3-license-version-header.js $(MAKEFILE)
@echo "Making $@..."; { \
cat $(sqlite3-license-version-header.js); \
cat $(dir.api)/sqlite3-license-version-header.js; \
echo '/*'; \
echo '** This code was built from sqlite3 version...'; \
echo "**"; \
awk '/define SQLITE_VERSION/{$$1=""; print "**" $$0}' $(sqlite3.h); \
awk '/define SQLITE_SOURCE_ID/{$$1=""; print "**" $$0}' $(sqlite3.h); \
echo "**"; \
echo "** Using the Emscripten SDK version $(emcc.version)."; \
echo "** with the help of Emscripten SDK version $(emcc.version)."; \
echo '*/'; \
} > $@
@@ -794,9 +818,9 @@ $(sqlite3-license-version.js): $(MKDIR.bld) $(sqlite3.h) $(sqlite3-license-versi
# --post-js injects code which runs after the WASM module is loaded
# and includes the entirety of the library plus some
# Emscripten-specific post-bootstrapping code.
pre-js.js.in := $(dir.api)/pre-js.c-pp.js
post-js.js.in := $(dir.tmp)/post-js.c-pp.js
post-jses.js := \
pre-js.js.in = $(dir.api)/pre-js.c-pp.js
post-js.js.in = $(dir.tmp)/post-js.c-pp.js
post-jses.js = \
$(dir.api)/post-js-header.js \
$(sqlite3-api.js.in) \
$(dir.api)/post-js-footer.js
@@ -812,10 +836,10 @@ $(post-js.js.in): $(MKDIR.bld) $(post-jses.js) $(MAKEFILE)
# Undocumented Emscripten feature: if the target file extension is
# "mjs", it defaults to ES6 module builds:
# https://github.com/emscripten-core/emscripten/issues/14383
sqlite3.wasm := $(dir.dout)/sqlite3.wasm
sqlite3-wasm.c := $(dir.api)/sqlite3-wasm.c
sqlite3-wasm.cfiles := $(sqlite3-wasm.c) $(sqlite3_wasm_extra_init.c)
sqlite3-wasmfs.cfiles := $(sqlite3-wasm.cfiles)
sqlite3.wasm = $(dir.dout)/sqlite3.wasm
sqlite3-wasm.c = $(dir.api)/sqlite3-wasm.c
sqlite3-wasm.cfiles = $(sqlite3-wasm.c) $(sqlite3_wasm_extra_init.c)
sqlite3-wasmfs.cfiles = $(sqlite3-wasm.cfiles)
# sqlite3-wasm.o vs sqlite3-wasm.c: building against the latter
# (predictably) results in a slightly faster binary. We're close
# enough to the target speed requirements that the 500ms makes a
@@ -860,17 +884,9 @@ if [ x1 = x$(1) ]; then \
fi
endef
sqlite3-api.js := $(dir.dout)/sqlite3-api.js
sqlite3.js := $(dir.dout)/sqlite3.js
sqlite3-api.mjs := $(dir.dout)/sqlite3-api.mjs
sqlite3.mjs := $(dir.dout)/sqlite3.mjs
sqlite3-api-bundler-friendly.mjs := $(dir.dout)/sqlite3-api-bundler-friendly.mjs
sqlite3-bundler-friendly.mjs := $(dir.dout)/sqlite3-bundler-friendly.mjs
sqlite3-api-node.mjs := $(dir.dout)/sqlite3-api-node.mjs
sqlite3-node.mjs := $(dir.dout)/sqlite3-node.mjs
sqlite3-api-wasmfs.mjs := $(dir.tmp)/sqlite3-api-wasmfs.mjs
sqlite3-wasmfs.mjs := $(dir.wasmfs)/sqlite3-wasmfs.mjs
EXPORTED_FUNCTIONS.fiddle := $(dir.tmp)/EXPORTED_FUNCTIONS.fiddle
sqlite3.js = $(dir.dout)/sqlite3.js
sqlite3.mjs = $(dir.dout)/sqlite3.mjs
EXPORTED_FUNCTIONS.fiddle = $(dir.tmp)/EXPORTED_FUNCTIONS.fiddle
# The various -D... values used by *.c-pp.js include:
#
@@ -892,6 +908,8 @@ EXPORTED_FUNCTIONS.fiddle := $(dir.tmp)/EXPORTED_FUNCTIONS.fiddle
# part, as it's unable to reliably determine whether the target is
# a browser or node.
#
# We repeat: all node.js builds are 100% untested and unsupported.
#
########################################################################
########################################################################
# We have to ensure that we do not build $(sqlite3*.*js) in parallel
@@ -904,24 +922,10 @@ EXPORTED_FUNCTIONS.fiddle := $(dir.tmp)/EXPORTED_FUNCTIONS.fiddle
# build time).
$(sqlite3.wasm): $(sqlite3.js)
$(sqlite3.mjs): $(sqlite3.js)
$(sqlite3-bundler-friendly.mjs): $(sqlite3.mjs)
$(sqlite3-node.mjs): $(sqlite3.mjs)
$(dir.dout)/sqlite3-bundler-friendly.mjs: $(sqlite3.mjs)
$(dir.dout)/sqlite3-node.mjs: $(sqlite3.mjs)
#CLEAN_FILES += $(sqlite3.wasm)
########################################################################
# We need separate copies of certain supplementary JS files for the
# bundler-friendly build. Concretely, any supplemental JS files which
# themselves use importScripts() or Workers or URL() constructors
# which refer to other in-tree (m)JS files require a bundler-friendly
# copy.
sqlite3-worker1.js.in := $(dir.api)/sqlite3-worker1.c-pp.js
sqlite3-worker1-promiser.js.in := $(dir.api)/sqlite3-worker1-promiser.c-pp.js
sqlite3-worker1.js := $(dir.dout)/sqlite3-worker1.js
sqlite3-worker1-promiser.js := $(dir.dout)/sqlite3-worker1-promiser.js
sqlite3-worker1-promiser.mjs := $(dir.dout)/sqlite3-worker1-promiser.mjs
sqlite3-worker1-bundler-friendly.mjs := $(dir.dout)/sqlite3-worker1-bundler-friendly.mjs
sqlite3-worker1-promiser-bundler-friendly.js := $(dir.dout)/sqlite3-worker1-promiser-bundler-friendly.js
ifneq (1,$(MAKING_CLEAN))
# This block MUST come between the above definitions of
# sqlite3-...js/mjs and the $(eval) calls below this block which use
@@ -934,7 +938,10 @@ ifneq (1,$(MAKING_CLEAN))
# the $ references in those languages made it just as illegible as the
# native makefile code. Somewhat surprisingly, moving that code generation
# to C makes it slightly less illegible than the previous 3 options.
bin.mkwb := ./mkwasmbuilds
#
# Maintenance note: the various $(c-pp.D.XYZ) vars are defined via
# $(bin.mkwb).
bin.mkwb = ./mkwasmbuilds
$(bin.mkwb): $(bin.mkwb).c $(MAKEFILE)
$(CC) -o $@ $<
DISTCLEAN_FILES += $(bin.mkwb)
@@ -946,45 +953,60 @@ DISTCLEAN_FILES += $(bin.mkwb)
endif
DISTCLEAN_FILES += .wasmbuilds.make
$(eval $(call SQLITE.CALL.C-PP.FILTER,$(sqlite3-worker1.js.in),$(sqlite3-worker1.js)))
$(eval $(call SQLITE.CALL.C-PP.FILTER,$(sqlite3-worker1.js.in),$(sqlite3-worker1-bundler-friendly.mjs),\
########################################################################
# We need separate copies of certain supplementary JS files for the
# bundler-friendly build. Concretely, any supplemental JS files which
# themselves use importScripts() or Workers or URL() constructors
# which refer to other in-tree (m)JS files require a bundler-friendly
# copy. Bundler-friendly builds replace certain references to string
# vars/expressions with string literals, as bundler tools are static
# code analyzers and cannot cope with the former.
#
# Most of what follows is the generation of those copies.
$(eval $(call SQLITE.CALL.C-PP.FILTER,$(dir.api)/sqlite3-worker1.c-pp.js,\
$(dir.dout)/sqlite3-worker1.js))
$(eval $(call SQLITE.CALL.C-PP.FILTER,$(dir.api)/sqlite3-worker1.c-pp.js,\
$(dir.dout)/sqlite3-worker1-bundler-friendly.mjs,\
$(c-pp.D.sqlite3-bundler-friendly)))
$(eval $(call SQLITE.CALL.C-PP.FILTER,$(sqlite3-worker1-promiser.js.in),$(sqlite3-worker1-promiser.js)))
$(eval $(call SQLITE.CALL.C-PP.FILTER,$(sqlite3-worker1-promiser.js.in),\
$(sqlite3-worker1-promiser-bundler-friendly.js),\
$(eval $(call SQLITE.CALL.C-PP.FILTER,$(dir.api)/sqlite3-worker1-promiser.c-pp.js,\
$(dir.dout)/sqlite3-worker1-promiser.js))
$(eval $(call SQLITE.CALL.C-PP.FILTER,$(dir.api)/sqlite3-worker1-promiser.c-pp.js,\
$(dir.dout)/sqlite3-worker1-promiser-bundler-friendly.js,\
$(c-pp.D.sqlite3-bundler-friendly)))
$(eval $(call SQLITE.CALL.C-PP.FILTER,$(sqlite3-worker1-promiser.js.in),$(sqlite3-worker1-promiser.mjs),\
$(eval $(call SQLITE.CALL.C-PP.FILTER,$(dir.api)/sqlite3-worker1-promiser.c-pp.js,\
$(dir.dout)/sqlite3-worker1-promiser.mjs,\
-Dtarget=es6-module -Dtarget=es6-bundler-friendly))
$(sqlite3-bundler-friendly.mjs): $(sqlite3-worker1-bundler-friendly.mjs) \
$(sqlite3-worker1-promiser-bundler-friendly.js)
$(eval $(call SQLITE.CALL.C-PP.FILTER,demo-worker1-promiser.c-pp.js,demo-worker1-promiser.js))
$(eval $(call SQLITE.CALL.C-PP.FILTER,demo-worker1-promiser.c-pp.js,demo-worker1-promiser.mjs,\
-Dtarget=es6-module))
$(eval $(call SQLITE.CALL.C-PP.FILTER,demo-worker1-promiser.c-pp.html,demo-worker1-promiser.html))
$(eval $(call SQLITE.CALL.C-PP.FILTER,demo-worker1-promiser.c-pp.html,demo-worker1-promiser-esm.html,\
-Dtarget=es6-module))
all: $(sqlite3-worker1.js) \
$(sqlite3-worker1-promiser.js) $(sqlite3-worker1-promiser.mjs)
demo-worker1-promiser.html: $(sqlite3-worker1-promiser.js) demo-worker1-promiser.js
$(dir.dout)/sqlite3-bundler-friendly.mjs: \
$(dir.dout)/sqlite3-worker1-bundler-friendly.mjs \
$(dir.dout)/sqlite3-worker1-promiser-bundler-friendly.js
demo-worker1-promiser.html: $(dir.dout)/sqlite3-worker1-promiser.js demo-worker1-promiser.js
demo-worker1-promiser-esm.html: $(sqlite3-worker1-promiser.mjs) demo-worker1-promiser.mjs
all: demo-worker1-promiser.html demo-worker1-promiser-esm.html
sqlite3-api.ext.jses += \
$(sqlite3-worker1-promiser.mjs) \
$(sqlite3-worker1-bundler-friendly.mjs) \
$(sqlite3-worker1.js)
$(dir.dout)/sqlite3-worker1-promiser.mjs \
$(dir.dout)/sqlite3-worker1-promiser.js \
$(dir.dout)/sqlite3-worker1-bundler-friendly.mjs \
$(dir.dout)/sqlite3-worker1.js
all quick: $(sqlite3-api.ext.jses)
q: quick
########################################################################
# batch-runner.js is part of one of the test apps which reads in SQL
# dumps generated by $(speedtest1) and executes them.
dir.sql := sql
speedtest1 := ../../speedtest1
speedtest1.c := ../../test/speedtest1.c
speedtest1.sql := $(dir.sql)/speedtest1.sql
speedtest1.cliflags := --size 10 --big-transactions
dir.sql = sql
speedtest1 = ../../speedtest1
speedtest1.c = ../../test/speedtest1.c
speedtest1.sql = $(dir.sql)/speedtest1.sql
speedtest1.cliflags = --size 10 --big-transactions
$(speedtest1):
$(MAKE) -C ../.. speedtest1
$(speedtest1.sql): $(speedtest1) $(MAKEFILE)
@@ -1005,8 +1027,8 @@ batch: batch-runner.list
#
# emcc.speedtest1.common = emcc flags used by multiple builds of speedtest1
# emcc.speedtest1 = emcc flags used by main build of speedtest1
emcc.speedtest1.common := $(emcc_opt_full)
emcc.speedtest1 := -I. -I$(dir $(sqlite3.canonical.c))
emcc.speedtest1.common = $(emcc_opt_full)
emcc.speedtest1 = -I. -I$(dir $(sqlite3.canonical.c))
emcc.speedtest1 += -sENVIRONMENT=web
emcc.speedtest1 += -sALLOW_MEMORY_GROWTH
emcc.speedtest1 += -sINITIAL_MEMORY=$(emcc.INITIAL_MEMORY.$(emcc.INITIAL_MEMORY))
@@ -1019,7 +1041,7 @@ emcc.speedtest1.common += -Wno-limited-postlink-optimizations
emcc.speedtest1.common += -Wno-unused-main
# ^^^^ -Wno-unused-main is for emcc 3.1.52+. speedtest1 has a wasm_main() which is
# exported and called by the JS code.
EXPORTED_FUNCTIONS.speedtest1 := $(abspath $(dir.tmp)/EXPORTED_FUNCTIONS.speedtest1)
EXPORTED_FUNCTIONS.speedtest1 = $(abspath $(dir.tmp)/EXPORTED_FUNCTIONS.speedtest1)
emcc.speedtest1.common += -sSTACK_SIZE=512KB
emcc.speedtest1.common += -sEXPORTED_FUNCTIONS=@$(EXPORTED_FUNCTIONS.speedtest1)
emcc.speedtest1.common += $(emcc.exportedRuntimeMethods)
@@ -1028,8 +1050,8 @@ emcc.speedtest1.common += -sDYNAMIC_EXECUTION=0
emcc.speedtest1.common += --minify 0
emcc.speedtest1.common += -sEXPORT_NAME=$(sqlite3.js.init-func)
emcc.speedtest1.common += -sWASM_BIGINT=$(emcc.WASM_BIGINT)
speedtest1.exit-runtime0 := -sEXIT_RUNTIME=0
speedtest1.exit-runtime1 := -sEXIT_RUNTIME=1
speedtest1.exit-runtime0 = -sEXIT_RUNTIME=0
speedtest1.exit-runtime1 = -sEXIT_RUNTIME=1
# Re -sEXIT_RUNTIME=1 vs 0: if it's 1 and speedtest1 crashes, we get
# this error from emscripten:
#
@@ -1050,10 +1072,9 @@ speedtest1.exit-runtime1 := -sEXIT_RUNTIME=1
$(EXPORTED_FUNCTIONS.speedtest1): $(MKDIR.bld) $(EXPORTED_FUNCTIONS.api.core)
@echo "Making $@ ..."
@{ echo _wasm_main; cat $(EXPORTED_FUNCTIONS.api.core); } > $@
speedtest1.js := $(dir.dout)/speedtest1.js
speedtest1.wasm := $(dir.dout)/speedtest1.wasm
emcc.flags.speedtest1-vanilla := $(cflags.common) -DSQLITE_SPEEDTEST1_WASM
speedtest1.cfiles := $(speedtest1.c) $(sqlite3-wasm.c)
speedtest1.js = $(dir.dout)/speedtest1.js
emcc.flags.speedtest1-vanilla = $(cflags.common) -DSQLITE_SPEEDTEST1_WASM
speedtest1.cfiles = $(speedtest1.c) $(sqlite3-wasm.c)
$(speedtest1.js): $(MAKEFILE) $(speedtest1.cfiles) \
$(pre-post-speedtest1-vanilla.deps) \
$(EXPORTED_FUNCTIONS.speedtest1)
@@ -1067,14 +1088,13 @@ $(speedtest1.js): $(MAKEFILE) $(speedtest1.cfiles) \
-USQLITE_C -DSQLITE_C=$(sqlite3.canonical.c) \
$(speedtest1.exit-runtime0) \
-o $@ $(speedtest1.cfiles) -lm
$(maybe-wasm-strip) $(speedtest1.wasm)
sed -i -e '/^var _sqlite3.*createExportWrapper/d' $@
chmod -x $(speedtest1.wasm)
ls -la $@ $(speedtest1.wasm)
@chmod -x $(basename $@).wasm
@$(maybe-wasm-strip) $(basename $@).wasm
@$(SQLITE.strip-createExportWrapper)
@ls -la $@ $(speedtest1.wasm)
speedtest1: $(speedtest1.js)
all: speedtest1
#CLEAN_FILES += $(speedtest1.js) $(speedtest1.wasm)
# end speedtest1.js
########################################################################
@@ -1099,7 +1119,7 @@ $(eval $(call SQLITE.CALL.C-PP.FILTER,tester1.c-pp.js,tester1.mjs,$(c-pp.D.sqlit
$(eval $(call SQLITE.CALL.C-PP.FILTER,tester1.c-pp.html,tester1.html))
$(eval $(call SQLITE.CALL.C-PP.FILTER,tester1.c-pp.html,tester1-esm.html,$(c-pp.D.sqlite3-esm)))
tester1: tester1.js tester1.mjs tester1.html tester1-esm.html
# Note that we do not include $(sqlite3-bundler-friendly.mjs) in this
# We do not include $(dir.dout)/sqlite3-bundler-friendly.mjs in this
# because bundlers are client-specific.
all quick: tester1
quick: $(sqlite3.js)
@@ -1111,7 +1131,7 @@ quick: $(sqlite3.js)
# painful.
.PHONY: o0 o1 o2 o3 os oz
emcc-opt-extra :=
emcc-opt-extra =
#ifeq (1,$(wasm-bare-bones))
#emcc-opt-extra += -flto
# ^^^^ -flto can have a considerably performance boost at -O0 but
@@ -1138,8 +1158,8 @@ oz: clean
########################################################################
# Sub-makes...
# sqlite.org/fiddle application...
include fiddle.make
# https://sqlite.org/fiddle application...
include $(MAKEFILE.fiddle)
# Only add wasmfs if wasmfs.enable=1 or we're running (dist)clean
ifneq (,$(filter wasmfs,$(MAKECMDGOALS)))
@@ -1157,16 +1177,17 @@ ifeq (1,$(wasmfs.enable))
# little benefit.
#
########################################################################
# Some platforms do not support the WASMFS build. Raspberry Pi OS is one
# of them. As such platforms are discovered, add their (uname -m) name
# to PLATFORMS_WITH_NO_WASMFS to exclude the wasmfs build parts.
PLATFORMS_WITH_NO_WASMFS := aarch64 # add any others here
THIS_ARCH := $(shell /usr/bin/uname -m)
# Some platforms do not support the WASMFS build. Raspberry Pi OS is
# one of them (or was when that comment was initially written). As
# such platforms are discovered, add their (uname -m) name to
# PLATFORMS_WITH_NO_WASMFS to exclude the wasmfs build parts.
PLATFORMS_WITH_NO_WASMFS = aarch64 # add any others here
THIS_ARCH = $(shell /usr/bin/uname -m)
ifneq (,$(filter $(THIS_ARCH),$(PLATFORMS_WITH_NO_WASMFS)))
$(info This platform does not support the WASMFS build.)
HAVE_WASMFS := 0
HAVE_WASMFS = 0
else
HAVE_WASMFS := 1
HAVE_WASMFS = 1
include wasmfs.make
endif
endif
@@ -1192,8 +1213,8 @@ push-testing:
echo "SSH failed: it's likely that stale content will be served via old gzip files."
########################################################################
# If we find a copy of the sqlite.org/wasm docs checked out, copy
# certain files over to it, noting that some need automatable edits...
# If we find a copy of https://sqlite.org/wasm checked out, copy
# certain files over to it, applying some automated edits...
wasm.docs.home ?= ../../../wasm
wasm.docs.found = $(if $(wildcard $(wasm.docs.home)/api-index.md),\
$(wildcard $(wasm.docs.home)),)
@@ -1204,7 +1225,7 @@ update-docs:
echo "Pass wasm.docs.home=/path/to/wasm/docs/checkout or edit this makefile to suit."; \
exit 127
else
wasm.docs.jswasm := $(wasm.docs.home)/jswasm
wasm.docs.jswasm = $(wasm.docs.home)/jswasm
update-docs: $(bin.stripccomments) $(sqlite3.js) $(sqlite3.wasm)
@echo "Copying files to the /wasm docs. Be sure to use an -Oz build for this!"
cp $(sqlite3.wasm) $(wasm.docs.jswasm)/.
+4 -4
View File
@@ -98,10 +98,10 @@ which (almost) all of the test and demo applications can be accessed.
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`
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
features in the apps which use them.
+25 -20
View File
@@ -16,9 +16,9 @@ multiple JS files because:
3. Certain components must be in their own standalone files in order
to be loaded as JS Workers.
Note that the structure described here is the current state of things,
as of this writing, but is not set in stone forever and may change
at any time.
The structure described here is the current state of things, as of
this writing, but is not set in stone forever and may change at any
time.
The overall idea is that the following files get concatenated
together, in the listed order, the resulting file is loaded by a
@@ -29,13 +29,15 @@ browser client:
objects. This is exposed as a function, rather than objects, so that
the next step can pass in a config object which abstracts away parts
of the WASM environment, to facilitate plugging it in to arbitrary
WASM toolchains.
WASM toolchains. The bootstrapping function gets removed from the
global scope in a later stage of the bootstrapping process.
- **`../common/whwasmutil.js`**\
A semi-third-party collection of JS/WASM utility code intended to
replace much of the Emscripten glue. The sqlite3 APIs internally use
these APIs instead of their Emscripten counterparts, in order to be
more portable to arbitrary WASM toolchains. This API is
configurable, in principle, for use with arbitrary WASM
more portable to arbitrary WASM toolchains and help reduce
regressions caused by toolchain-level behavioral changes. This API
is configurable, in principle, for use with arbitrary WASM
toolchains. It is "semi-third-party" in that it was created in order
to support this tree but is standalone and maintained together
with...
@@ -48,8 +50,8 @@ browser client:
- **`sqlite3-api-glue.js`**\
Invokes functionality exposed by the previous two files to flesh out
low-level parts of `sqlite3-api-prologue.js`. Most of these pieces
related to populating the `sqlite3.capi.wasm` object. This file
also deletes most global-scope symbols the above files create,
involve populating the `sqlite3.capi.wasm` object. This file also
deletes most global-scope symbols the above files create,
effectively moving them into the scope being used for initializing
the API.
- **`<build>/sqlite3-api-build-version.js`**\
@@ -60,8 +62,8 @@ browser client:
Provides a high-level object-oriented wrapper to the lower-level C
API, colloquially known as OO API #1. Its API is similar to other
high-level sqlite3 JS wrappers and should feel relatively familiar
to anyone familiar with such APIs. That said, it is not a "required
component" and can be elided from builds which do not want it.
to anyone familiar with such APIs. It is not a "required component"
and can be elided from builds which do not want it.
- **`sqlite3-api-worker1.js`**\
A Worker-thread-based API which uses OO API #1 to provide an
interface to a database which can be driven from the main Window
@@ -96,7 +98,7 @@ browser client:
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.
completely different approach than 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
@@ -106,8 +108,11 @@ browser client:
process, which is what finally executes the initialization code
installed by the previous files. As of this writing, this code
ensures that the previous files leave no more than a single global
symbol installed. When adapting the API for non-Emscripten
toolchains, this "should" be the only file where changes are needed.
symbol installed - `sqlite3InitModule()`. When adapting the API for
non-Emscripten toolchains, this "should" be the only file, of those
in this list, where changes are needed. The Emscripten-specific
pieces described below may also require counterparts in any as-yet
hypothetical alternative build.
**Files with the extension `.c-pp.js`** are intended [to be processed
@@ -130,25 +135,25 @@ WASM-specific helper functions, at least one of which requires access
to private/static `sqlite3.c` internals. `sqlite3.wasm` is compiled
from this file rather than `sqlite3.c`.
The following files are part of the build process but are injected
into the build-generated `sqlite3.js` along with `sqlite3-api.js`.
The following Emscripten-specific files are injected into the
build-generated `sqlite3.js` along with `sqlite3-api.js`.
- `extern-pre-js.js`\
- **`extern-pre-js.js`**\
Emscripten-specific header for Emscripten's `--extern-pre-js`
flag. As of this writing, that file is only used for experimentation
purposes and holds no code relevant to the production deliverables.
- `pre-js.c-pp.js`\
- **`pre-js.c-pp.js`**\
Emscripten-specific header for Emscripten's `--pre-js` flag. This
file is intended as a place to override certain Emscripten behavior
before it starts up, but corner-case Emscripten bugs keep that from
being a reality.
- `post-js-header.js`\
- **`post-js-header.js`**\
Emscripten-specific header for the `--post-js` input. It opens up
a lexical scope by starting a post-run handler for Emscripten.
- `post-js-footer.js`\
- **`post-js-footer.js`**\
Emscripten-specific footer for the `--post-js` input. This closes
off the lexical scope opened by `post-js-header.js`.
- `extern-post-js.c-pp.js`\
- **`extern-post-js.c-pp.js`**\
Emscripten-specific header for Emscripten's `--extern-post-js`
flag. This file overwrites the Emscripten-installed
`sqlite3InitModule()` function with one which, after the module is
+6 -7
View File
@@ -4,10 +4,9 @@
a blank line for a sed-based kludge for the ES6 build. */
/* extern-post-js.js must be appended to the resulting sqlite3.js
file. It gets its name from being used as the value for the
--extern-post-js=... Emscripten flag. Note that this code, unlike
most of the associated JS code, runs outside of the
Emscripten-generated module init scope, in the current
global scope. */
--extern-post-js=... Emscripten flag. This code, unlike most of the
associated JS code, runs outside of the Emscripten-generated module
init scope, in the current global scope. */
//#if target=es6-module
const toExportForESM =
//#endif
@@ -78,9 +77,9 @@ const toExportForESM =
EmscriptenModule['ENVIRONMENT_IS_PTHREAD']){
/** Workaround for wasmfs-generated worker, which calls this
routine from each individual thread and requires that its
argument be returned. The conditional criteria above are
fragile, based solely on inspection of the offending code,
not public Emscripten details. */
argument be returned. The if() condition above is fragile,
based solely on inspection of the offending code, not
public Emscripten details. */
//console.warn("sqlite3InitModule() returning E-module.",EmscriptenModule);
return EmscriptenModule;
}
+1 -1
View File
@@ -23,7 +23,7 @@ sqlite3InitModuleState.debugModule('globalThis.location =',globalThis.location);
1) If URL param named the same as `path` is set, it is returned.
2) If sqlite3InitModuleState.sqlite3Dir is set, then (thatName + path)
is returned (note that it's assumed to end with '/').
is returned (it's assumed to end with '/').
3) If this code is running in the main UI thread AND it was loaded
from a SCRIPT tag, the directory part of that URL is used
+244 -87
View File
@@ -13,7 +13,7 @@
This file contains the so-called OO #1 API wrapper for the sqlite3
WASM build. It requires that sqlite3-api-glue.js has already run
and it installs its deliverable as globalThis.sqlite3.oo1.
and it installs its deliverable as sqlite3.oo1.
*/
globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
const toss3 = (...args)=>{throw new sqlite3.SQLite3Error(...args)};
@@ -37,6 +37,21 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
it.
*/
const __ptrMap = new WeakMap();
/**
A Set of oo1.DB or oo1.Stmt objects which are proxies for
(sqlite3*) resp. (sqlite3_stmt*) pointers which themselves are
owned elsewhere. Objects in this Set do not own their underlying
handle and that handle must be guaranteed (by the client) to
outlive the proxy. DB.close()/Stmt.finalize() methods will remove
the object from this Set _instead_ of closing/finalizing the
pointer. These proxies are primarily intended as a way to briefly
wrap an (sqlite3[_stmt]*) object as an oo1.DB/Stmt without taking
over ownership, to take advantage of simplifies usage compared to
the C API while not imposing any change of ownership.
See DB.wrapHandle() and Stmt.wrapHandle().
*/
const __doesNotOwnHandle = new Set();
/**
Map of DB instances to objects, each object being a map of Stmt
wasm pointers to Stmt objects.
@@ -234,73 +249,89 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
};
}
const opt = ctor.normalizeArgs(...args);
let fn = opt.filename, vfsName = opt.vfs, flagsStr = opt.flags;
if(('string'!==typeof fn && 'number'!==typeof fn)
|| 'string'!==typeof flagsStr
|| (vfsName && ('string'!==typeof vfsName && 'number'!==typeof vfsName))){
sqlite3.config.error("Invalid DB ctor args",opt,arguments);
toss3("Invalid arguments for DB constructor.");
}
let fnJs = ('number'===typeof fn) ? wasm.cstrToJs(fn) : fn;
const vfsCheck = ctor._name2vfs[fnJs];
if(vfsCheck){
vfsName = vfsCheck.vfs;
fn = fnJs = vfsCheck.filename(fnJs);
}
let pDb, oflags = 0;
if( flagsStr.indexOf('c')>=0 ){
oflags |= capi.SQLITE_OPEN_CREATE | capi.SQLITE_OPEN_READWRITE;
}
if( flagsStr.indexOf('w')>=0 ) oflags |= capi.SQLITE_OPEN_READWRITE;
if( 0===oflags ) oflags |= capi.SQLITE_OPEN_READONLY;
oflags |= capi.SQLITE_OPEN_EXRESCODE;
const stack = wasm.pstack.pointer;
try {
const pPtr = wasm.pstack.allocPtr() /* output (sqlite3**) arg */;
let rc = capi.sqlite3_open_v2(fn, pPtr, oflags, vfsName || 0);
pDb = wasm.peekPtr(pPtr);
checkSqlite3Rc(pDb, rc);
capi.sqlite3_extended_result_codes(pDb, 1);
if(flagsStr.indexOf('t')>=0){
capi.sqlite3_trace_v2(pDb, capi.SQLITE_TRACE_STMT,
__dbTraceToConsole, pDb);
//sqlite3.config.debug("DB ctor",opt);
let pDb;
if( (pDb = opt['sqlite3*']) ){
/* This property ^^^^^ is very specifically NOT DOCUMENTED and
NOT part of the public API. This is a back door for functions
like DB.wrapDbHandle(). */
//sqlite3.config.debug("creating proxy db from",opt);
if( !opt['sqlite3*:takeOwnership'] ){
/* This is object does not own its handle. */
__doesNotOwnHandle.add(this);
}
}catch( e ){
if( pDb ) capi.sqlite3_close_v2(pDb);
throw e;
}finally{
wasm.pstack.restore(stack);
this.filename = capi.sqlite3_db_filename(pDb,'main');
}else{
let fn = opt.filename, vfsName = opt.vfs, flagsStr = opt.flags;
if(('string'!==typeof fn && 'number'!==typeof fn)
|| 'string'!==typeof flagsStr
|| (vfsName && ('string'!==typeof vfsName && 'number'!==typeof vfsName))){
sqlite3.config.error("Invalid DB ctor args",opt,arguments);
toss3("Invalid arguments for DB constructor.");
}
let fnJs = ('number'===typeof fn) ? wasm.cstrToJs(fn) : fn;
const vfsCheck = ctor._name2vfs[fnJs];
if(vfsCheck){
vfsName = vfsCheck.vfs;
fn = fnJs = vfsCheck.filename(fnJs);
}
let oflags = 0;
if( flagsStr.indexOf('c')>=0 ){
oflags |= capi.SQLITE_OPEN_CREATE | capi.SQLITE_OPEN_READWRITE;
}
if( flagsStr.indexOf('w')>=0 ) oflags |= capi.SQLITE_OPEN_READWRITE;
if( 0===oflags ) oflags |= capi.SQLITE_OPEN_READONLY;
oflags |= capi.SQLITE_OPEN_EXRESCODE;
const stack = wasm.pstack.pointer;
try {
const pPtr = wasm.pstack.allocPtr() /* output (sqlite3**) arg */;
let rc = capi.sqlite3_open_v2(fn, pPtr, oflags, vfsName || 0);
pDb = wasm.peekPtr(pPtr);
checkSqlite3Rc(pDb, rc);
capi.sqlite3_extended_result_codes(pDb, 1);
if(flagsStr.indexOf('t')>=0){
capi.sqlite3_trace_v2(pDb, capi.SQLITE_TRACE_STMT,
__dbTraceToConsole, pDb);
}
}catch( e ){
if( pDb ) capi.sqlite3_close_v2(pDb);
throw e;
}finally{
wasm.pstack.restore(stack);
}
this.filename = fnJs;
}
this.filename = fnJs;
__ptrMap.set(this, pDb);
__stmtMap.set(this, Object.create(null));
try{
if( !opt['sqlite3*'] ){
try{
//#if enable-see
dbCtorApplySEEKey(this,opt);
dbCtorApplySEEKey(this,opt);
//#endif
// Check for per-VFS post-open SQL/callback...
const pVfs = capi.sqlite3_js_db_vfs(pDb)
|| toss3("Internal error: cannot get VFS for new db handle.");
const postInitSql = __vfsPostOpenCallback[pVfs];
if(postInitSql){
/**
Reminder: if this db is encrypted and the client did _not_ pass
in the key, any init code will fail, causing the ctor to throw.
We don't actually know whether the db is encrypted, so we cannot
sensibly apply any heuristics which skip the init code only for
encrypted databases for which no key has yet been supplied.
*/
if(postInitSql instanceof Function){
postInitSql(this, sqlite3);
}else{
checkSqlite3Rc(
pDb, capi.sqlite3_exec(pDb, postInitSql, 0, 0, 0)
);
// Check for per-VFS post-open SQL/callback...
const pVfs = capi.sqlite3_js_db_vfs(pDb)
|| toss3("Internal error: cannot get VFS for new db handle.");
const postInitSql = __vfsPostOpenCallback[pVfs];
if(postInitSql){
/**
Reminder: if this db is encrypted and the client did _not_ pass
in the key, any init code will fail, causing the ctor to throw.
We don't actually know whether the db is encrypted, so we cannot
sensibly apply any heuristics which skip the init code only for
encrypted databases for which no key has yet been supplied.
*/
if(postInitSql instanceof Function){
postInitSql(this, sqlite3);
}else{
checkSqlite3Rc(
pDb, capi.sqlite3_exec(pDb, postInitSql, 0, 0, 0)
);
}
}
}catch(e){
this.close();
throw e;
}
}catch(e){
this.close();
throw e;
}
};
@@ -403,7 +434,6 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
- `vfs`: the VFS fname
//#if enable-see
SEE-capable builds optionally support ONE of the following
additional options:
@@ -429,7 +459,6 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
is supplied and the database is encrypted, execution of the
post-initialization SQL will fail, causing the constructor to
throw.
//#endif enable-see
The `filename` and `vfs` arguments may be either JS strings or
@@ -457,8 +486,8 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
/**
Internal-use enum for mapping JS types to DB-bindable types.
These do not (and need not) line up with the SQLITE_type
values. All values in this enum must be truthy and distinct
but they need not be numbers.
values. All values in this enum must be truthy and (mostly)
distinct but they need not be numbers.
*/
const BindTypes = {
null: 1,
@@ -467,7 +496,6 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
boolean: 4,
blob: 5
};
BindTypes['undefined'] == BindTypes.null;
if(wasm.bigIntEnabled){
BindTypes.bigint = BindTypes.number;
}
@@ -486,26 +514,30 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
- `db`: the DB object which created the statement.
- `columnCount`: the number of result columns in the query, or 0
for queries which cannot return results. This property is a proxy
for sqlite3_column_count() and its use in loops should be avoided
because of the call overhead associated with that. The
`columnCount` is not cached when the Stmt is created because a
schema change made via a separate db connection between this
statement's preparation and when it is stepped may invalidate it.
for queries which cannot return results. This property is a
read-only proxy for sqlite3_column_count() and its use in loops
should be avoided because of the call overhead associated with
that. The `columnCount` is not cached when the Stmt is created
because a schema change made between this statement's preparation
and when it is stepped may invalidate it.
- `parameterCount`: the number of bindable parameters in the query.
- `parameterCount`: the number of bindable parameters in the
query. Like `columnCount`, this property is ready-only and is a
proxy for a C API call.
As a general rule, most methods of this class will throw if
called on an instance which has been finalized. For brevity's
sake, the method docs do not all repeat this warning.
*/
const Stmt = function(){
const Stmt = function(/*oo1db, stmtPtr, BindTypes [,takeOwnership=true] */){
if(BindTypes!==arguments[2]){
toss3(capi.SQLITE_MISUSE, "Do not call the Stmt constructor directly. Use DB.prepare().");
}
this.db = arguments[0];
__ptrMap.set(this, arguments[1]);
this.parameterCount = capi.sqlite3_bind_parameter_count(this.pointer);
if( arguments.length>3 && !arguments[3] ){
__doesNotOwnHandle.add(this);
}
};
/** Throws if the given DB has been closed, else it is returned. */
@@ -698,10 +730,10 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
},
/**
Finalizes all open statements and closes this database
connection. This is a no-op if the db has already been
closed. After calling close(), `this.pointer` will resolve to
`undefined`, so that can be used to check whether the db
instance is still opened.
connection (with one exception noted below). This is a no-op if
the db has already been closed. After calling close(),
`this.pointer` will resolve to `undefined`, and that can be
used to check whether the db instance is still opened.
If this.onclose.before is a function then it is called before
any close-related cleanup.
@@ -721,14 +753,19 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
all, will never trigger close(), so onclose handlers are not a
reliable way to implement close-time cleanup or maintenance of
a db.
If this instance was created using DB.wrapHandle() and does not
own this.pointer then it does not close the db handle but it
does perform all other work, such as calling onclose callbacks
and disassociating this object from this.pointer.
*/
close: function(){
if(this.pointer){
const pDb = this.pointer;
if(pDb){
if(this.onclose && (this.onclose.before instanceof Function)){
try{this.onclose.before(this)}
catch(e){/*ignore*/}
}
const pDb = this.pointer;
Object.keys(__stmtMap.get(this)).forEach((k,s)=>{
if(s && s.pointer){
try{s.finalize()}
@@ -737,7 +774,9 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
});
__ptrMap.delete(this);
__stmtMap.delete(this);
capi.sqlite3_close_v2(pDb);
if( !__doesNotOwnHandle.delete(this) ){
capi.sqlite3_close_v2(pDb);
}
if(this.onclose && (this.onclose.after instanceof Function)){
try{this.onclose.after(this)}
catch(e){/*ignore*/}
@@ -1450,9 +1489,63 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
*/
checkRc: function(resultCode){
return checkSqlite3Rc(this, resultCode);
}
},
}/*DB.prototype*/;
/**
Returns a new oo1.DB instance which wraps the given (sqlite3*)
WASM pointer, optionally with or without taking over ownership of
that pointer.
The first argument must be either a non-NULL (sqlite3*) WASM
pointer.
The second argument, defaulting to false, specifies ownership of
the first argument. If it is truthy, the returned object will
pass that pointer to sqlite3_close() when its close() method is
called, otherwise it will not.
Throws if pDb is not a non-0 WASM pointer.
The caller MUST GUARANTEE that the passed-in handle will outlive
the returned object, i.e. that it will not be closed. If it is closed,
this object will hold a stale pointer and results are undefined.
Aside from its lifetime, the proxy is to be treated as any other
DB instance, including the requirement of calling close() on
it. close() will free up internal resources owned by the proxy
and disassociate the proxy from that handle but will not
actually close the proxied db handle unless this function is
passed a thruthy second argument.
To stress:
- DO NOT call sqlite3_close() (or similar) on the being-proxied
pointer while a proxy is active.
- ALWAYS eventually call close() on the returned object. If the
proxy does not own the underlying handle then its MUST be
closed BEFORE the being-proxied handle is closed.
Design notes:
- wrapHandle() "could" accept a DB object instance as its first
argument and proxy thatDb.pointer but there is currently no use
case where doing so would be useful, so it does not allow
that. That restriction may be lifted in a future version.
*/
DB.wrapHandle = function(pDb, takeOwnership=false){
if( !pDb || !wasm.isPtr(pDb) ){
throw new sqlite3.SQLite3Error(capi.SQLITE_MISUSE,
"Argument must be a WASM sqlite3 pointer");
}
return new DB({
/* This ctor call style is very specifically internal-use-only.
It is not documented and may change at any time. */
"sqlite3*": pDb,
"sqlite3*:takeOwnership": !!takeOwnership
});
};
/** Throws if the given Stmt has been finalized, else stmt is
returned. */
@@ -1474,8 +1567,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
case BindTypes.string:
return t;
case BindTypes.bigint:
if(wasm.bigIntEnabled) return t;
/* else fall through */
return wasm.bigIntEnabled ? t : undefined;
default:
return util.isBindableTypedArray(v) ? BindTypes.blob : undefined;
}
@@ -1641,12 +1733,19 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
This method always throws if called when it is illegal to do
so. Namely, when triggered via a per-row callback handler of a
DB.exec() call.
If Stmt does not own its underlying (sqlite3_stmt*) (see
Stmt.wrapHandle()) then this function will not pass it to
sqlite3_finalize().
*/
finalize: function(){
if(this.pointer){
const ptr = this.pointer;
if(ptr){
affirmNotLockedByExec(this,'finalize()');
const rc = capi.sqlite3_finalize(this.pointer);
delete __stmtMap.get(this.db)[this.pointer];
const rc = (__doesNotOwnHandle.delete(this)
? 0
: capi.sqlite3_finalize(ptr));
delete __stmtMap.get(this.db)[ptr];
__ptrMap.delete(this);
__execLock.delete(this);
__stmtMayGet.delete(this);
@@ -2134,6 +2233,64 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
set: ()=>toss3("The columnCount property is read-only.")
});
Object.defineProperty(Stmt.prototype, 'parameterCount', {
enumerable: false,
get: function(){return capi.sqlite3_bind_parameter_count(this.pointer)},
set: ()=>toss3("The parameterCount property is read-only.")
});
/**
The Stmt counterpart of oo1.DB.wrapHandle(), this creates a Stmt
instance which wraps a WASM (sqlite3_stmt*) in the oo1 API,
optionally with or without taking over ownership of that pointer.
The first argument must be an oo1.DB instance[^1].
The second argument must be a valid WASM (sqlite3_stmt*), as
produced by sqlite3_prepare_v2() and sqlite3_prepare_v3().
The third argument, defaulting to false, specifies whether the
returned Stmt object takes over ownership of the underlying
(sqlite3_stmt*). If true, the returned object's finalize() method
will finalize that handle, else it will not. If it is false,
ownership of pStmt is unchanged and pStmt MUST outlive the
returned object or results are undefined.
This function throws if the arguments are invalid. On success it
returns a new Stmt object which wraps the given statement
pointer.
Like all Stmt objects, the finalize() method must eventually be
called on the returned object to free up internal resources,
regardless of whether this function's third argument is true or
not.
[^1]: The first argument cannot be a (sqlite3*) because the
resulting Stmt object requires a parent DB object. It is not yet
determined whether it would be of general benefit to refactor the
DB/Stmt pair internals to communicate in terms of the underlying
(sqlite3*) rather than a DB object. If so, we could laxen the
first argument's requirement and allow an (sqlite3*). Because
DB.wrapHandle() enables multiple DB objects to proxy the same
(sqlite3*), we cannot unambiguously translate the first arugment
from (sqlite3*) to DB instances for us with this function's first
argument.
*/
Stmt.wrapHandle = function(oo1db, pStmt, takeOwnership=false){
let ctor = Stmt;
if( !(oo1db instanceof DB) || !oo1db.pointer ){
throw new sqlite3.SQLite3Error(sqlite3.SQLITE_MISUSE,
"First argument must be an opened "+
"sqlite3.oo1.DB instance");
}
if( !pStmt || !wasm.isPtr(pStmt) ){
throw new sqlite3.SQLite3Error(sqlite3.SQLITE_MISUSE,
"Second argument must be a WASM "+
"sqlite3_stmt pointer");
}
return new Stmt(oo1db, pStmt, BindTypes, !!takeOwnership);
}
/** The OO API's public namespace. */
sqlite3.oo1 = {
DB,
+1 -16
View File
@@ -134,22 +134,7 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
const config = Object.assign(Object.create(null),{
exports: undefined,
memory: undefined,
bigIntEnabled: (()=>{
if('undefined'!==typeof Module){
/* Emscripten module will contain HEAPU64 when built with
-sWASM_BIGINT=1, else it will not.
As of emsdk 3.1.55, when building in strict mode, HEAPxyz
are only available if _explicitly_ included in the exports,
else they are not. We do not (as of 2024-03-04) use -sSTRICT
for the canonical builds.
*/
if( !!Module.HEAPU64 ) return true;
/* Else fall through and hope for the best. Nobody _really_
builds this without BigInt support, do they? */
}
return !!globalThis.BigInt64Array;
})(),
bigIntEnabled: !!globalThis.BigInt64Array,
debug: console.debug.bind(console),
warn: console.warn.bind(console),
error: console.error.bind(console),
+11 -2
View File
@@ -385,10 +385,19 @@ sqlite3.initWorker1API = function(){
const getDbId = function(db){
let id = wState.idMap.get(db);
if(id) return id;
id = 'db#'+(++wState.idSeq)+'@'+db.pointer;
id = 'db#'+(++wState.idSeq)+':'+
Math.floor(Math.random() * 100000000)+':'+
Math.floor(Math.random() * 100000000);
/** ^^^ can't simply use db.pointer b/c closing/opening may re-use
the same address, which could map pending messages to a wrong
instance. */
instance.
2025-07: https://github.com/sqlite/sqlite-wasm/issues/113
demonstrates that two Worker1s can end up with the same IDs,
despite using different instances of the library, so we need
to add some randomness to the IDs instead of relying on the
pointer addresses.
*/
wState.idMap.set(db, id);
return id;
};
+1
View File
@@ -939,6 +939,7 @@ const char * sqlite3__wasm_enum_json(void){
DefInt(SQLITE_INNOCUOUS);
DefInt(SQLITE_SUBTYPE);
DefInt(SQLITE_RESULT_SUBTYPE);
DefInt(SQLITE_SELFORDER1);
} _DefGroup;
DefGroup(version) {
+10 -9
View File
@@ -130,12 +130,10 @@
Notable shortcomings:
- This API was not designed with ES6 modules in mind. Neither Firefox
nor Safari support, as of March 2023, the {type:"module"} flag to the
Worker constructor, so that particular usage is not something we're going
to target for the time being:
https://developer.mozilla.org/en-US/docs/Web/API/Worker/Worker
- "v1" of this this API is not suitable for use as an ESM module
because ESM worker modules were not widely supported when it was
developed. For use as an ESM module, see the "v2" interface later
on in this file.
*/
globalThis.sqlite3Worker1Promiser = function callee(config = callee.defaultConfig){
// Inspired by: https://stackoverflow.com/a/52439530
@@ -296,7 +294,7 @@ globalThis.sqlite3Worker1Promiser.defaultConfig = {
after calling the original function and will reject if that
function throws.
*/
sqlite3Worker1Promiser.v2 = function(config){
globalThis.sqlite3Worker1Promiser.v2 = function callee(config = callee.defaultConfig){
let oldFunc;
if( 'function' == typeof config ){
oldFunc = config;
@@ -326,11 +324,14 @@ sqlite3Worker1Promiser.v2 = function(config){
}
return p;
}.bind({
/* We do this because clients are
recommended to delete globalThis.sqlite3Worker1Promiser. */
/* We do this because clients are recommended to delete
globalThis.sqlite3Worker1Promiser. */
original: sqlite3Worker1Promiser
});
globalThis.sqlite3Worker1Promiser.v2.defaultConfig =
globalThis.sqlite3Worker1Promiser.defaultConfig;
//#if target=es6-module
/**
When built as a module, we export sqlite3Worker1Promiser.v2()
+18 -14
View File
@@ -1773,10 +1773,10 @@ globalThis.WhWasmUtilInstaller = function(target){
does not have a stable interface. */
xArg.FuncPtrAdapter.warnOnUse = false;
/** If true, convertArg() will FuncPtrAdapter.debugOut() when it
(un)installs a function binding to/from WASM. Note that
deinstallation of bindScope=transient bindings happens
via scopedAllocPop() so will not be output. */
/** If true, convertArg() will call FuncPtrAdapter.debugOut() when
it (un)installs a function binding to/from WASM. Note that
deinstallation of bindScope=transient bindings happens via
scopedAllocPop() so will not be output. */
xArg.FuncPtrAdapter.debugFuncInstall = false;
/** Function used for debug output. */
@@ -1827,9 +1827,8 @@ globalThis.WhWasmUtilInstaller = function(target){
The first argument must be one of:
- A JavaScript function.
- The name of a WASM-exported function. In the latter case xGet()
is used to fetch the exported function, which throws if it's not
found.
- The name of a WASM-exported function. xGet() is used to fetch
the exported function, which throws if it's not found.
- A pointer into the indirect function table. e.g. a pointer
returned from target.installFunction().
@@ -1874,9 +1873,6 @@ globalThis.WhWasmUtilInstaller = function(target){
which convert their argument to an integer and truncate it to
the given bit length.
- `N*` (args): a type name in the form `N*`, where N is a numeric
type name, is treated the same as WASM pointer.
- `*` and `pointer` (args): are assumed to be WASM pointer values
and are returned coerced to an appropriately-sized pointer
value (i32 or i64). Non-numeric values will coerce to 0 and
@@ -1887,7 +1883,15 @@ globalThis.WhWasmUtilInstaller = function(target){
WASM pointer numeric type.
- `**` (args): is simply a descriptive alias for the WASM pointer
type. It's primarily intended to mark output-pointer arguments.
type. It's primarily intended to mark output-pointer arguments,
noting that JS's view of WASM does not distinguish between
pointers and pointers-to-pointers, so all such interpretation
of `**`, as distinct from `*`, necessarily happens at the
client level.
- `NumType*` (args): a type name in this form, where T is
the name of a numeric mapping, e.g. 'int16' or 'double',
is treated like `*`.
- `i64` (args and results): passes the value to BigInt() to
convert it to an int64. Only available if bigIntEnabled is
@@ -1916,7 +1920,7 @@ globalThis.WhWasmUtilInstaller = function(target){
UTF-8-encoded C-string to pass to the exported function,
cleaning it up before the wrapper returns. If a long-lived
C-string pointer is required, that requires client-side code
to create the string, then pass its pointer to the function.
to create the string then pass its pointer to the function.
- Else the arg is assumed to be a pointer to a string the
client has already allocated and it's passed on as
@@ -2091,8 +2095,8 @@ globalThis.WhWasmUtilInstaller = function(target){
easily convert, e.g., to C-strings, and have them cleaned up
automatically before the wrapper returns to the caller. Likewise,
if a _result_ adapter uses scoped allocation, the result will be
freed before because they would be freed before the wrapper
returns, leading to chaos and undefined behavior.
freed before the wrapper returns, leading to chaos and undefined
behavior.
Except when called as a getter, this function returns itself.
*/
+7 -6
View File
@@ -1,15 +1,16 @@
# Gets filtered by the configure script
# config.make.in gets filtered by the top-most configure script to
# create config.make.
bin.bash = @BIN_BASH@
bin.emcc = @EMCC_WRAPPER@
bin.wasm-strip = @BIN_WASM_STRIP@
bin.wasm-opt = @BIN_WASM_OPT@
SHELL := $(bin.bash)
SHELL = $(bin.bash)
# The following overrides can be uncommented to test various
# validation and if/else branches the makefile code:
#
#bin.bash :=
#bin.emcc :=
#bin.wasm-strip :=
#bin.wasm-opt :=
#bin.bash =
#bin.emcc =
#bin.wasm-strip =
#bin.wasm-opt =
+41 -43
View File
@@ -3,15 +3,14 @@
#
# Intended to include'd by ./GNUmakefile.
#
# 'make dist' rules for creating a distribution archive of the WASM/JS
# pieces, noting that we only build a dist of the built files, not the
# numerous pieces required to build them.
# 'make dist' rules for creating a distribution archive of the SQLite
# WASM/JS deliverables.
#
# Use 'make snapshot' to create "snapshot" releases. They use a
# distinctly different zip file and top directory name to distinguish
# Use 'make snapshot' to create "snapshot" releases. They use
# distinctly different zip file and top directory names to distinguish
# them from release builds.
#######################################################################
MAKEFILE.dist := $(lastword $(MAKEFILE_LIST))
MAKEFILE.dist = $(lastword $(MAKEFILE_LIST))
########################################################################
# Chicken/egg situation: we need $(bin.version-info) to get the
@@ -20,35 +19,35 @@ MAKEFILE.dist := $(lastword $(MAKEFILE_LIST))
# have to use a temporary name for the archive until we can get
# that binary built.
ifeq (1,$(SQLITE_C_IS_SEE))
dist-name-extra := -see
dist-name-extra = -see
else
dist-name-extra :=
dist-name-extra =
endif
ifeq (,$(filter snapshot,$(MAKECMDGOALS)))
dist-name-prefix := sqlite-wasm$(dist-name-extra)
dist-name-prefix = sqlite-wasm$(dist-name-extra)
else
dist-name-prefix := sqlite-wasm$(dist-name-extra)-snapshot-$(shell /usr/bin/date +%Y%m%d)
dist-name-prefix = sqlite-wasm$(dist-name-extra)-snapshot-$(shell /usr/bin/date +%Y%m%d)
endif
dist-name := $(dist-name-prefix)-TEMP
dist-name = $(dist-name-prefix)-TEMP
########################################################################
# dist.build must be the name of a target which triggers the build of
# the files to be packed into the dist archive. The intention is that
# it be one of (o0, o1, o2, o3, os, oz), each of which uses like-named
# -Ox optimization level flags. The o2 target provides the best
# overall runtime speeds. The oz target provides slightly slower
# speeds (roughly 10%) with significantly smaller WASM file
# sizes. Note that -O2 (the o2 target) results in faster binaries than
# both -O3 and -Os (the o3 and os targets) in all tests run to
# date. Our general policy is that we want the smallest binaries for
# dist zip files, so use the oz build unless there is a compelling
# reason not to.
# $(dist.build) must be the name of a target which triggers the build
# of the files to be packed into the dist archive. The intention is
# that it be one of (o0, o1, o2, o3, os, oz), each of which uses
# like-named -Ox optimization level flags. The o2 target provides the
# best overall runtime speeds. The oz target provides slightly slower
# speeds (roughly 10%) with significantly smaller WASM file sizes. -O2
# (the o2 target) consistently results in faster binaries than both
# -O3 and -Os (the o3 and os targets) in all tests run to date. Our
# general policy is that we want the smallest binaries for dist zip
# files, so use the oz build unless there is a compelling reason not
# to.
dist.build ?= oz
dist-dir.top := $(dist-name)
dist-dir.jswasm := $(dist-dir.top)/$(notdir $(dir.dout))
dist-dir.common := $(dist-dir.top)/common
dist.top.extras := \
dist-dir.top = $(dist-name)
dist-dir.jswasm = $(dist-dir.top)/$(notdir $(dir.dout))
dist-dir.common = $(dist-dir.top)/common
dist.top.extras = \
demo-123.html demo-123-worker.html demo-123.js \
tester1.html tester1-worker.html tester1-esm.html \
tester1.js tester1.mjs \
@@ -56,16 +55,12 @@ dist.top.extras := \
demo-worker1.html demo-worker1.js \
demo-worker1-promiser.html demo-worker1-promiser.js \
demo-worker1-promiser-esm.html demo-worker1-promiser.mjs
dist.jswasm.extras := $(sqlite3.wasm) \
dist.jswasm.extras = $(sqlite3.wasm) \
$(sqlite3-api.ext.jses)
dist.common.extras := \
dist.common.extras = \
$(wildcard $(dir.common)/*.css) \
$(dir.common)/SqliteTestUtil.js
#$(info sqlite3-worker1-promiser.mjs = $(sqlite3-worker1-promiser.mjs))
#$(info sqlite3-worker1.js = $(sqlite3-worker1.js))
#$(info sqlite3-api.ext.jses = $(sqlite3-api.ext.jses))
#$(info dist.jswasm.extras = $(dist.jswasm.extras))
.PHONY: dist snapshot
# DIST_STRIP_COMMENTS $(call)able to be used in stripping C-style
# from the dist copies of certain files.
@@ -77,12 +72,12 @@ $(bin.stripccomments) $(2) < $(1) > $(dist-dir.jswasm)/$(notdir $(1)) || exit;
endef
# STRIP_K1.js = list of JS files which need to be passed through
# $(bin.stripcomments) with a single -k flag.
STRIP_K1.js := $(sqlite3-worker1.js) $(sqlite3-worker1-promiser.js) \
STRIP_K1.js = $(sqlite3-worker1.js) $(sqlite3-worker1-promiser.js) \
$(sqlite3-worker1-bundler-friendly.js) \
$(sqlite3-api.ext.jses)
# STRIP_K2.js = list of JS files which need to be passed through
# $(bin.stripcomments) with two -k flags.
STRIP_K2.js := $(sqlite3.js) $(sqlite3.mjs) \
STRIP_K2.js = $(sqlite3.js) $(sqlite3.mjs) \
$(sqlite3-bundler-friendly.mjs) $(sqlite3-node.mjs)
########################################################################
# dist: create the end-user deliverable archive.
@@ -94,18 +89,21 @@ STRIP_K2.js := $(sqlite3.js) $(sqlite3.mjs) \
# dist's deps must be trimmed to non-generated files or
# files which are _not_ cleaned up by the clean target.
#
# Note that we require $(bin.version-info) in order to figure out the
# dist file's name, so cannot (without a recursive make) have the
# target name equal to the archive name.
# We require $(bin.version-info) in order to figure out the dist
# file's name, so cannot (without a recursive make) have the target
# name equal to the archive name.
#
# 2025-01-15: Emsdk 4.0.0 introduces, in its generated code, a regex
# which contains the pattern /*. That, of course, confuses any C-style
# comment-stripper which is not specifically JS-aware and smart enough
# to know that it's in a regex or string literal. Because of that,
# comment-stripping is currently disabled, which means the builds will
# be significantly larger than before.
#apply_comment_stripper := false
apply_comment_stripper := true
# comment-stripping was briefly disabled, resulting in functionally
# identical but significantly larger JS files. That issue with the
# comment-stripper has been resolved, but $(apply_comment_stripper)
# can be set to false to disable it if a similar problem arises.
#
#apply_comment_stripper = false
apply_comment_stripper = true
# ^^^ shell command true or false
dist: \
$(bin.stripccomments) $(bin.version-info) \
@@ -138,7 +136,7 @@ ifeq (,$(wasm.docs.found))
snapshot: dist
@echo "To upload the snapshot build to the wasm docs server:"; \
echo "1) move $(dist-name-prefix)*.zip to the top of a wasm docs checkout."; \
echo "2) run 'make uv-sync'"
echo "2) From that checkout run 'make uv-sync'"
else
snapshot: dist
@echo "Moving snapshot to [$(wasm.docs.found)]..."; \
@@ -150,5 +148,5 @@ endif
# copied into the new $(dist-name) dir.
.PHONY: dist-clean
clean: dist-clean
dist-clean:
dist-clean: # not to be confused with distclean
rm -fr $(dist-name) $(wildcard sqlite-wasm-*.zip)
+19 -29
View File
@@ -3,13 +3,12 @@
#
# Intended to include'd by ./GNUmakefile.
#######################################################################
MAKEFILE.fiddle := $(lastword $(MAKEFILE_LIST))
########################################################################
# shell.c and its build flags...
ifneq (1,$(MAKING_CLEAN))
make-np-0 := make -C $(dir.top) -n -p
make-np-1 := sed -e 's/(TOP)/(dir.top)/g'
make-np-0 = make -C $(dir.top) -n -p
make-np-1 = sed -e 's/(TOP)/(dir.top)/g'
# Extract SHELL_OPT and SHELL_DEP from the top-most makefile and import
# them as vars here...
$(eval $(shell $(make-np-0) | grep -e '^SHELL_OPT ' | $(make-np-1)))
@@ -27,7 +26,7 @@ endif
# /shell.c
########################################################################
EXPORTED_FUNCTIONS.fiddle := $(dir.tmp)/EXPORTED_FUNCTIONS.fiddle
EXPORTED_FUNCTIONS.fiddle = $(dir.tmp)/EXPORTED_FUNCTIONS.fiddle
fiddle.emcc-flags = \
$(emcc.cflags) $(emcc_opt_full) \
--minify 0 \
@@ -40,9 +39,8 @@ fiddle.emcc-flags = \
-sWASM_BIGINT=$(emcc.WASM_BIGINT) \
-sEXPORT_NAME=$(sqlite3.js.init-func) \
-Wno-limited-postlink-optimizations \
$(emcc.exportedRuntimeMethods) \
$(emcc.exportedRuntimeMethods),FS \
-sEXPORTED_FUNCTIONS=@$(abspath $(EXPORTED_FUNCTIONS.fiddle)) \
-sEXPORTED_RUNTIME_METHODS=FS,wasmMemory \
$(SQLITE_OPT.full-featured) \
$(SQLITE_OPT.common) \
$(SHELL_OPT) \
@@ -53,12 +51,12 @@ fiddle.emcc-flags = \
# Flags specifically for debug builds of fiddle. Performance suffers
# greatly in debug builds.
fiddle.emcc-flags.debug := $(fiddle.emcc-flags) \
fiddle.emcc-flags.debug = $(fiddle.emcc-flags) \
-DSQLITE_DEBUG \
-DSQLITE_ENABLE_SELECTTRACE \
-DSQLITE_ENABLE_WHERETRACE
fiddle.EXPORTED_FUNCTIONS.in := \
fiddle.EXPORTED_FUNCTIONS.in = \
EXPORTED_FUNCTIONS.fiddle.in \
$(dir.api)/EXPORTED_FUNCTIONS.sqlite3-core \
$(dir.api)/EXPORTED_FUNCTIONS.sqlite3-extras
@@ -67,10 +65,7 @@ $(EXPORTED_FUNCTIONS.fiddle): $(MKDIR.bld) $(fiddle.EXPORTED_FUNCTIONS.in) \
$(MAKEFILE.fiddle)
sort -u $(fiddle.EXPORTED_FUNCTIONS.in) > $@
fiddle.cses := $(dir.top)/shell.c $(sqlite3-wasm.c)
fiddle: $(fiddle-module.js) $(fiddle-module.js.debug)
fiddle.debug: $(fiddle-module.js.debug)
fiddle.cses = $(dir.top)/shell.c $(sqlite3-wasm.c)
clean: clean-fiddle
clean-fiddle:
@@ -84,10 +79,9 @@ clean-fiddle:
all: fiddle
########################################################################
# fiddle_remote is the remote destination for the fiddle app. It
# must be a [user@]HOST:/path for rsync.
# Note that the target "should probably" contain a symlink of
# index.html -> fiddle.html.
# fiddle_remote is the remote destination for the fiddle app. It must
# be a [user@]HOST:/path for rsync. The target "should probably"
# contain a symlink of index.html -> fiddle.html.
fiddle_remote ?=
ifeq (,$(fiddle_remote))
ifneq (,$(wildcard /home/stephan))
@@ -154,11 +148,6 @@ push-fiddle: fiddle
# because certain execution environments disallow those constructs.
# This flag is not strictly necessary, however.
#
# -sWASM_BIGINT is UNTESTED but "should" allow the int64-using C APIs
# to work with JS/wasm, insofar as the JS environment supports the
# BigInt type. That support requires an extremely recent browser:
# Safari didn't get that support until late 2020.
#
# --no-entry: for compiling library code with no main(). If this is
# not supplied and the code has a main(), it is called as part of the
# module init process. Note that main() is #if'd out of shell.c
@@ -180,14 +169,15 @@ push-fiddle: fiddle
# minification makes little difference in terms of overall
# distributable size.
#
# --minify 0: disables minification of the generated JS code,
# regardless of optimization level. Minification of the JS has
# minimal overall effect in the larger scheme of things and results
# in JS files which can neither be edited nor viewed as text files in
# Fossil (which flags them as binary because of their extreme line
# lengths). Interestingly, whether or not the comments in the
# generated JS file get stripped is unaffected by this setting and
# depends entirely on the optimization level. Higher optimization
# --minify 0: supposedly disables minification of the generated JS
# code, regardless of optimization level, but that's not quite true:
# search the main makefile for wasm-strip for details. Minification
# of the JS has minimal overall effect in the larger scheme of things
# and results in JS files which can neither be edited nor viewed as
# text files in Fossil (which flags them as binary because of their
# extreme line lengths). Interestingly, whether or not the comments
# in the generated JS file get stripped is unaffected by this setting
# and depends entirely on the optimization level. Higher optimization
# levels reduce the size of the JS considerably even without
# minification.
#
+6 -3
View File
@@ -163,9 +163,11 @@
fiddleModule.isDead = true;
return false;
}
stdout("SQLite version", capi.sqlite3_libversion(),
capi.sqlite3_sourceid().substr(0,19));
stdout('Welcome to the "fiddle" shell.');
wMsg('sqlite-version', {
lib: capi.sqlite3_libversion(),
srcId: capi.sqlite3_sourceid()
});
stdout('Welcome to the "fiddle" shell. Tap the About button for more info.');
if(capi.sqlite3_vfs_find("opfs")){
stdout("\nOPFS is available. To open a persistent db, use:\n\n",
" .open file:name?vfs=opfs\n\nbut note that some",
@@ -281,6 +283,7 @@
stderr("'open' expects {buffer:Uint8Array} containing an uploaded db.");
return;
}
buffer.set([1,1], 18)/*force db out of WAL mode*/;
const fn = (
opt.filename
? opt.filename.split(/[/\\]/).pop().replace('"','_')
+180 -118
View File
@@ -329,6 +329,21 @@
SF.worker = new Worker('fiddle-worker.js'+self.location.search);
SF.worker.onmessage = (ev)=>SF.runMsgHandlers(ev.data);
SF.addMsgHandler(['stdout', 'stderr'], (ev)=>SF.echo(ev.data));
SF.addMsgHandler('sqlite-version', (ev)=>{
const v = ev.data;
const a = E('#sqlite-version-link');
const li = v.srcId.split(' ')/*DATE TIME HASH*/;
a.setAttribute('href',
//'https://sqlite.org/src/timeline/?c='+li[2].substr(0,20)
'https://sqlite.org/src/info/'+li[2].substr(0,20)
);
a.setAttribute('target', '_blank');
a.innerText = [
v.lib,
v.srcId.substr(0,34)
].join(' ');
SF.echo("SQLite version",a.innerText);
});
/* querySelectorAll() proxy */
const EAll = function(/*[element=document,] cssSelector*/){
@@ -391,6 +406,143 @@
self.onSFLoaded();
});
SF.e ={
about: E('#view-about'),
split: E('#view-split'),
terminal: E('#view-terminal'),
hideInTerminal: EAll('.hide-in-terminal'
/* Elements to hide when in terminal mode */)
};
SF.eViews = EAll('.app-view');
SF.setMainView = function(eMain){
if( SF.e.main === eMain ) return;
SF.eViews.forEach((e)=>{
if( e===eMain ) e.classList.remove('hidden');
else e.classList.add('hidden');
});
SF.e.hideInTerminal.forEach(e=>{
if( eMain === SF.e.terminal ) e.classList.add('hidden');
else e.classList.remove('hidden');
});
SF.e.main = eMain;
SF.ForceResizeKludge();
};
/** Toggle the "About" view on and off. */
SF.toggleAbout = function(){
if( SF.e.about.classList.contains('hidden') ){
SF.e.about.$returnTo = SF.e.main;
SF.setMainView( SF.e.about );
}else{
const e = SF.e.about.$returnTo;
delete SF.e.about.$returnTo;
SF.setMainView( e );
}
};
/**
Given a DOM element, this routine measures its "effective
height", which is the bounding top/bottom range of this element
and all of its children, recursively. For some DOM structure
cases, a parent may have a reported height of 0 even though
children have non-0 sizes.
Returns 0 if !e or if the element really has no height.
*/
const effectiveHeight = function f(e){
if(!e) return 0;
if(!f.measure){
f.measure = function callee(e, depth){
if(!e) return;
const m = e.getBoundingClientRect();
if(0===depth){
callee.top = m.top;
callee.bottom = m.bottom;
}else{
callee.top = m.top ? Math.min(callee.top, m.top) : callee.top;
callee.bottom = Math.max(callee.bottom, m.bottom);
}
Array.prototype.forEach.call(e.children,(e)=>callee(e,depth+1));
if(0===depth){
//console.debug("measure() height:",e.className, callee.top, callee.bottom, (callee.bottom - callee.top));
f.extra += callee.bottom - callee.top;
}
return f.extra;
};
}
f.extra = 0;
f.measure(e,0);
return f.extra;
};
/**
Returns a function, that, as long as it continues to be invoked,
will not be triggered. The function will be called after it stops
being called for N milliseconds. If `immediate` is passed, call
the callback immediately and hinder future invocations until at
least the given time has passed.
If passed only 1 argument, or passed a falsy 2nd argument,
the default wait time set in this function's $defaultDelay
property is used.
Source: underscore.js, by way of https://davidwalsh.name/javascript-debounce-function
*/
const debounce = function f(func, wait, immediate) {
var timeout;
if(!wait) wait = f.$defaultDelay;
return function() {
const context = this, args = Array.prototype.slice.call(arguments);
const later = function() {
timeout = undefined;
if(!immediate) func.apply(context, args);
};
const callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if(callNow) func.apply(context, args);
};
};
debounce.$defaultDelay = 500 /*arbitrary*/;
SF.ForceResizeKludge = (function(){
/* Workaround for Safari mayhem regarding use of vh CSS
units.... We cannot use vh units to set the main view
size because Safari chokes on that, so we calculate
that height here. Larger than ~95% is too big for
Firefox on Android, causing the input area to move
off-screen. */
const eVisibles = EAll('.app-view');
const elemsToCount = [
/* Elements which we need to always count in the
visible body size. */
E('body > header'),
E('body > footer'),
E('body > fieldset.options')
];
const resized = function f(){
if(f.$disabled) return;
const wh = window.innerHeight;
var ht;
var extra = 0;
elemsToCount.forEach((e)=>e ? extra += effectiveHeight(e) : false);
ht = wh - extra;
eVisibles.forEach(function(e){
e.style.height =
e.style.maxHeight = [
"calc(", (ht>=100 ? ht : 100), "px",
" - 2em"/*fudge value*/,")"
/* ^^^^ hypothetically not needed, but both
Chrome/FF on Linux will force scrollbars on the
body if this value is too small. */
].join('');
});
};
resized.$disabled = true/*gets deleted when setup is finished*/;
window.addEventListener('resize', debounce(resized, 250), false);
return resized;
})();
/**
Performs all app initialization which must wait until after the
worker module is loaded. This function removes itself when it's
@@ -398,9 +550,19 @@
*/
self.onSFLoaded = function(){
delete this.onSFLoaded;
// Unhide all elements which start out hidden
EAll('.initially-hidden').forEach((e)=>e.classList.remove('initially-hidden'));
SF.e.main = EAll('.app-view:not(.hidden)')[0]
/** The main view widget. Initially the first non-hidden
.app-view element. */;
if( (new URL(self.location.href).searchParams).has('about') ){
SF.toggleAbout() /* for use while editing the About page */;
}
E('#btn-reset').addEventListener('click',()=>SF.resetDb());
EAll('#btn-about, #btn-about-close').forEach((e)=>{
e.addEventListener('click',()=>SF.toggleAbout())
});
const taInput = E('#input');
const btnClearIn = E('#btn-clear');
const selectExamples = E('#select-examples');
@@ -618,108 +780,6 @@
}, false);
});
/**
Given a DOM element, this routine measures its "effective
height", which is the bounding top/bottom range of this element
and all of its children, recursively. For some DOM structure
cases, a parent may have a reported height of 0 even though
children have non-0 sizes.
Returns 0 if !e or if the element really has no height.
*/
const effectiveHeight = function f(e){
if(!e) return 0;
if(!f.measure){
f.measure = function callee(e, depth){
if(!e) return;
const m = e.getBoundingClientRect();
if(0===depth){
callee.top = m.top;
callee.bottom = m.bottom;
}else{
callee.top = m.top ? Math.min(callee.top, m.top) : callee.top;
callee.bottom = Math.max(callee.bottom, m.bottom);
}
Array.prototype.forEach.call(e.children,(e)=>callee(e,depth+1));
if(0===depth){
//console.debug("measure() height:",e.className, callee.top, callee.bottom, (callee.bottom - callee.top));
f.extra += callee.bottom - callee.top;
}
return f.extra;
};
}
f.extra = 0;
f.measure(e,0);
return f.extra;
};
/**
Returns a function, that, as long as it continues to be invoked,
will not be triggered. The function will be called after it stops
being called for N milliseconds. If `immediate` is passed, call
the callback immediately and hinder future invocations until at
least the given time has passed.
If passed only 1 argument, or passed a falsy 2nd argument,
the default wait time set in this function's $defaultDelay
property is used.
Source: underscore.js, by way of https://davidwalsh.name/javascript-debounce-function
*/
const debounce = function f(func, wait, immediate) {
var timeout;
if(!wait) wait = f.$defaultDelay;
return function() {
const context = this, args = Array.prototype.slice.call(arguments);
const later = function() {
timeout = undefined;
if(!immediate) func.apply(context, args);
};
const callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if(callNow) func.apply(context, args);
};
};
debounce.$defaultDelay = 500 /*arbitrary*/;
const ForceResizeKludge = (function(){
/* Workaround for Safari mayhem regarding use of vh CSS
units.... We cannot use vh units to set the main view
size because Safari chokes on that, so we calculate
that height here. Larger than ~95% is too big for
Firefox on Android, causing the input area to move
off-screen. */
const appViews = EAll('.app-view');
const elemsToCount = [
/* Elements which we need to always count in the
visible body size. */
E('body > header'),
E('body > footer')
];
const resized = function f(){
if(f.$disabled) return;
const wh = window.innerHeight;
var ht;
var extra = 0;
elemsToCount.forEach((e)=>e ? extra += effectiveHeight(e) : false);
ht = wh - extra;
appViews.forEach(function(e){
e.style.height =
e.style.maxHeight = [
"calc(", (ht>=100 ? ht : 100), "px",
" - 2em"/*fudge value*/,")"
/* ^^^^ hypothetically not needed, but both
Chrome/FF on Linux will force scrollbars on the
body if this value is too small. */
].join('');
});
};
resized.$disabled = true/*gets deleted when setup is finished*/;
window.addEventListener('resize', debounce(resized, 250), false);
return resized;
})();
/** Set up a selection list of examples */
(function(){
const xElem = E('#select-examples');
@@ -790,33 +850,35 @@
})()/* example queries */;
//SF.echo(null/*clear any output generated by the init process*/);
if(window.jQuery && window.jQuery.terminal){
if(window.jQuery && window.jQuery.terminal && SF.e.terminal){
/* Set up the terminal-style view... */
const eTerm = window.jQuery('#view-terminal').empty();
SF.jqTerm = eTerm.terminal(SF.dbExec.bind(SF),{
const jqeTerm = window.jQuery(SF.e.terminal).empty();
SF.jqTerm = jqeTerm.terminal(SF.dbExec.bind(SF),{
prompt: 'sqlite> ',
greetings: false /* note that the docs incorrectly call this 'greeting' */
});
EAll('.unhide-if-terminal-available').forEach(e=>{
e.classList.remove('hidden');
});
EAll('.remove-if-terminal-available').forEach(e=>{
e.parentElement.removeChild(e);
});
/* Set up a button to toggle the views... */
const head = E('header#titlebar');
const ePlaceholder = E('#terminal-button-placeholder');
ePlaceholder.classList.add('labeled-input');
ePlaceholder.classList.remove('hidden');
const btnToggleView = document.createElement('button');
btnToggleView.appendChild(document.createTextNode("Toggle View"));
head.appendChild(btnToggleView);
btnToggleView.innerText = "Toggle view";
ePlaceholder.appendChild( btnToggleView );
btnToggleView.addEventListener('click',function f(){
EAll('.app-view').forEach(e=>e.classList.toggle('hidden'));
if(document.body.classList.toggle('terminal-mode')){
ForceResizeKludge();
}
const terminalOn = document.body.classList.toggle('terminal-mode');
SF.setMainView( terminalOn ? SF.e.terminal : SF.e.split );
}, false);
btnToggleView.click()/*default to terminal view*/;
}
SF.echo('This experimental app is provided in the hope that it',
'may prove interesting or useful but is not an officially',
'supported deliverable of the sqlite project. It is subject to',
'any number of changes or outright removal at any time.\n');
const urlParams = new URL(self.location.href).searchParams;
SF.dbExec(urlParams.get('sql') || null);
delete ForceResizeKludge.$disabled;
ForceResizeKludge();
delete SF.ForceResizeKludge.$disabled;
SF.ForceResizeKludge();
}/*onSFLoaded()*/;
})();
+138 -48
View File
@@ -5,16 +5,27 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>SQLite3 Fiddle</title>
<link rel="shortcut icon" href="data:image/x-icon;," type="image/x-icon">
<!-- to add a toggleable terminal-style view, uncomment the following
two lines and ensure that these files are on the web server. -->
<!--
To add a terminal-style view using jquery.terminal[^1],
uncomment the following two HTML lines and ensure that these
files are on the web server.
jquery-bundle.min.js is a concatenation of jquery.min.js from
[^2] and jquery.terminal.min.js from [^1].
jquery.terminal.min.css is from [^1].
[^1]: https://github.com/jcubic/jquery.terminal
[^2]: https://jquery.com
-->
<!--script src="jqterm/jqterm-bundle.min.js"></script>
<link rel="stylesheet" href="jqterm/jquery.terminal.min.css"/-->
<link rel="stylesheet" href="jqterm/jquery.terminal.min.css"-->
<style>
/* The following styles are for app-level use. */
:root {
--sqlite-blue: #044a64;
--textarea-color1: #044a64;
--textarea-color1: #000 /*044a64 is nice too*/;
--textarea-color2: white;
--size: 1.25 /* used by jqterm to calculate font size and the default is too tiny.*/;
}
textarea {
font-family: monospace;
@@ -170,6 +181,17 @@
display: flex;
flex-direction: column-reverse;
}
#view-about {
flex: auto;
overflow: auto;
}
#view-about h1:first-child {
display: flex;
}
#view-about h1:first-child > button {
align-self: center;
margin-left: 1em;
}
/* emcscript-related styling, used during the module load/intialization processes... */
.emscripten { padding-right: 0; margin-left: auto; margin-right: auto; display: block; }
@@ -200,8 +222,10 @@
<body>
<header id='titlebar'>
<span>SQLite3 Fiddle</span>
<span class='powered-by'>Powered by
<a href='https://sqlite.org'>SQLite3</a></span>
<span id='titlebar-buttons'>
<span class='powered-by'>Powered by
<a href='https://sqlite.org'>SQLite3</a></span>
</span>
</header>
<!-- emscripten bits -->
<figure id="module-spinner">
@@ -215,7 +239,7 @@
</figure>
<div class="emscripten" id="module-status">Downloading...</div>
<div class="emscripten">
<progress value="0" max="100" id="module-progress" hidden='1'></progress>
<progress value="0" max="100" id="module-progress" hidden='1'></progress>
</div><!-- /emscripten bits -->
<div id='view-terminal' class='app-view hidden initially-hidden'>
@@ -224,45 +248,6 @@
</div>
<div id='view-split' class='app-view initially-hidden'>
<fieldset class='options collapsible'>
<legend><button class='fieldset-toggle'>Options</button></legend>
<div class=''>
<span class='labeled-input'>
<input type='checkbox' id='opt-cb-sbs'
data-csstgt='#main-wrapper'
data-cssclass='side-by-side'
data-config='sideBySide'>
<label for='opt-cb-sbs'>Side-by-side</label>
</span>
<span class='labeled-input'>
<input type='checkbox' id='opt-cb-swapio'
data-csstgt='#main-wrapper'
data-cssclass='swapio'
data-config='swapInOut'>
<label for='opt-cb-swapio'>Swap in/out</label>
</span>
<span class='labeled-input'>
<input type='checkbox' id='opt-cb-autoscroll'
data-config='autoScrollOutput'>
<label for='opt-cb-autoscroll'>Auto-scroll output</label>
</span>
<span class='labeled-input'>
<input type='checkbox' id='opt-cb-autoclear'
data-config='autoClearOutput'>
<label for='opt-cb-autoclear'>Auto-clear output</label>
</span>
<span class='labeled-input'>
<input type='file' id='load-db' class='hidden'/>
<button id='btn-load-db'>Load DB...</button>
</span>
<span class='labeled-input'>
<button id='btn-export'>Download DB</button>
</span>
<span class='labeled-input'>
<button id='btn-reset'>Reset DB</button>
</span>
</div>
</fieldset><!-- .options -->
<div id='main-wrapper' class=''>
<fieldset class='zone-wrapper input'>
<legend><div class='button-bar'>
@@ -295,8 +280,113 @@
<div><textarea id="output" readonly
placeholder="Shell output."></textarea></div>
</fieldset>
</div>
</div><!-- #main-wrapper -->
</div> <!-- #view-split -->
<script src="fiddle.js"></script>
<div class='hidden app-view' id='view-about'>
<h1>About SQLite Fiddle <button id='btn-about-close'>close</button></h1>
<p>Fiddle is a JavaScript application wrapping a <a href='https://webassembly.org'>WebAssembly</a>
build of <a href="https://sqlite.org/cli.html">the SQLite CLI shell</a>, slightly
modified to account for browser-based user input. Aside from the different layout,
it works just like the CLI shell. This copy was built with SQLite version
<a id='sqlite-version-link'></a>.
</p>
<p>This app is provided in the hope that it may prove interesting or useful
but it is not an officially-supported deliverable of the SQLite project.
It is subject to any number of changes or outright removal at any time.
That said, for as long as it's online we do respond to support requests
in <a href="https://sqlite.org/forum">the SQLite forum</a>.
</p>
<p>This app runs on your device. After loading, it does not interact
with the remote server at all. Similarly, this app does not use any
HTTP cookies.</p>
<p>Fiddle databases are transient in-memory databases unless they
specifically use a persistent storage option (if available, help
text in the SQL result output area will indicate how to use
persistent storage when this app starts up).
</p>
<h1>Usage Summary</h1>
<ul>
<li class='hidden unhide-if-terminal-available'>In "terminal
mode" it accepts input just like the CLI shell does.</li>
<li>In split-view mode:
<ul>
<li>Input can be executed with either the Run
button or tapping one of Ctrl-enter or Shift-enter from within
the text input field. If a portion of the input field is
selected, only that portion will be run.
</li>
<li>The various toggle checkboxes can be used to tweak the layout
and behaviors. Those toggles are persistent if the JS environment
allows it.
</li>
</ul>
</li>
<li class='remove-if-terminal-available'>"Terminal mode" is
not available in this deployment.
</li>
<li>Databases can be imported and exported using the buttons in
the Options toolbar. No specific limit for imported database
sizes is imposed, but large databases may cause it to fail with
an out-of-memory error.</li>
<!--li></li-->
</ul>
</div><!-- #view-about -->
<fieldset class='options'>
<legend>Options</legend>
<div class=''>
<span class='labeled-input'>
<input type='file' id='load-db' class='hidden'/>
<button id='btn-load-db'>Load DB...</button>
</span>
<span class='labeled-input'>
<button id='btn-export'>Download DB</button>
</span>
<span class='labeled-input'>
<button id='btn-reset'>Reset DB</button>
</span>
<span id='terminal-button-placeholder' class='hidden'></span>
<span class='labeled-input'>
<button id='btn-about'>About...</button>
</span>
<span class='labeled-input hide-in-terminal'>
<input type='checkbox' id='opt-cb-sbs'
data-csstgt='#main-wrapper'
data-cssclass='side-by-side'
data-config='sideBySide'
>
<label for='opt-cb-sbs'>Side-by-side</label>
</span>
<span class='labeled-input hide-in-terminal'>
<input type='checkbox' id='opt-cb-swapio'
data-csstgt='#main-wrapper'
data-cssclass='swapio'
data-config='swapInOut'
>
<label for='opt-cb-swapio'>Swap in/out</label>
</span>
<span class='labeled-input hide-in-terminal'>
<input type='checkbox' id='opt-cb-autoscroll'
data-config='autoScrollOutput'
>
<label for='opt-cb-autoscroll'>Auto-scroll output</label>
</span>
<span class='labeled-input hide-in-terminal'>
<input type='checkbox' id='opt-cb-autoclear'
data-config='autoClearOutput'>
<label for='opt-cb-autoclear'>Auto-clear output</label>
</span>
</div>
</fieldset><!-- .options -->
<script src="fiddle.js"></script>
</body>
</html>
+203 -144
View File
@@ -11,18 +11,17 @@
*************************************************************************
**
** This app's single purpose is to emit parts of the Makefile code for
** building sqlite3's WASM build. The main motivation is to generate
** code which "can" be created via GNU Make's eval command but is
** sqlite3's canonical WASM build. The main motivation is to generate
** code which "could" be created via GNU Make's eval command but is
** highly illegible when constructed that way. Attempts to write this
** app in Bash and TCL have suffered from the problem that both
** require escaping $ symbols, making the resulting script code as
** illegible as the eval spaghetti we want to get away from. Writing
** it in C is, somewhat surprisingly, _slightly_ less illegible than
** writing it in bash, tcl, or native Make code.
** app in Bash and TCL have suffered from the problem that those
** languages require escaping $ symbols, making the resulting script
** code as illegible as the eval spaghetti we want to get away
** from. Maintaining it in C is, somewhat surprisingly, _slightly_
** less illegible than writing it in bash, tcl, or native Make code.
**
** The emitted makefile code is not standalone - it depends on
** variables and $(call)able functions from the main makefile.
**
*/
#undef NDEBUG
@@ -33,38 +32,145 @@
#define pf printf
#define ps puts
/* Very common printf() args combo. */
#define zNM zName, zMode
/*
** Valid names for the zName arguments.
** Valid build names. Each build is a combination of one of these and
** one of JS_BUILD_MODES, but only certain combinations are legal.
** This macro and JS_BUILD_MODES exist solely for documentation
** purposes: they are not expanded into code anywhere.
*/
#define JS_BUILD_NAMES sqlite3 sqlite3-wasmfs
/*
** Valid names for the zMode arguments of the "sqlite3" build. For the
** "sqlite3-wasmfs" build, only "esm" (ES6 Module) is legal.
** Valid build modes. For the "sqlite3-wasmfs" build, only "esm" (ES6
** Module) is legal.
*/
#define JS_BUILD_MODES vanilla esm bundler-friendly node
/* Separator to help eyeballs find the different sections */
/* Separator to help eyeballs find the different output sections */
static const char * zBanner =
"\n########################################################################\n";
/*
** Flags for use with BuildDef::flags and the 3rd argument to
** mk_pre_post().
**
** Maintenance reminder: do not combine flags within this enum,
** e.g. LIBMODE_BUNDLER_FRIENDLY=0x02|LIBMODE_ESM, as that will lead
** to breakage in some of the flag checks.
*/
enum LibModeFlags {
/* Indicates an ESM module build. */
LIBMODE_ESM = 0x01,
/* Indicates a "bundler-friendly" build mode. */
LIBMODE_BUNDLER_FRIENDLY = 0x02,
/* Indicates that this build is unsupported. Such builds are not
** added to the 'all' target. The unsupported builds exist primarily
** for experimentation's sake. */
LIBMODE_UNSUPPORTED = 0x04,
/* Indicates a node.js-for-node.js build (untested and
** unsupported). */
LIBMODE_NODEJS = 0x08,
/* Indicates a wasmfs build (untested and unsupported). */
LIBMODE_WASMFS = 0x10
};
/*
** Info needed for building one combination of JS_BUILD_NAMES and
** JS_BUILD_MODE, noting that only a subset of those combinations are
** legal/sensical.
*/
struct BuildDef {
const char *zName; /* Name from JS_BUILD_NAMES */
const char *zMode; /* Name from JS_BUILD_MODES */
int flags; /* Flags from LibModeFlags */
const char *zJsOut; /* Name of generated sqlite3.js/.mjs */
/* TODO: dynamically determine zJsOut based on zName, zMode, and
flags. */
const char *zCmppD; /* Extra -D... flags for c-pp */
const char *zEmcc; /* Extra flags for emcc */
};
typedef struct BuildDef BuildDef;
/*
** The set of WASM builds for the library (as opposed to the apps
** (fiddle, speedtest1)). This array must end with an empty sentinel
** entry. Their order is mostly insignificant, but some makefile vars
** used by some builds are set up by prior builds. Because of that,
** the (sqlite3, vanilla), (sqlite3, esm), and (sqlite3,
** bundler-friendly) builds should be defined first (in that order).
*/
const BuildDef aBuildDefs[] = {
{/* Core build */
"sqlite3", "vanilla", 0, "$(sqlite3.js)", 0, 0},
{/* Core ESM */
"sqlite3", "esm", LIBMODE_ESM, "$(sqlite3.mjs)",
"-Dtarget=es6-module", 0},
{/* Core bundler-friendly build. Untested and "not really"
** supported, but required by the downstream npm subproject.
** Testing these would require special-purpose node-based tools and
** custom test apps. Or we can pass them off as-is to the npm
** subproject and they spot failures pretty quickly ;). */
"sqlite3", "bundler-friendly",
LIBMODE_BUNDLER_FRIENDLY | LIBMODE_ESM,
"$(dir.dout)/sqlite3-bundler-friendly.mjs",
"$(c-pp.D.sqlite3-esm) -Dtarget=es6-bundler-friendly", 0},
{/* node.js mode. Untested and unsupported. */
"sqlite3", "node", LIBMODE_UNSUPPORTED | LIBMODE_NODEJS,
"$(dir.dout)/sqlite3-node.mjs",
"$(c-pp.D.sqlite3-bundler-friendly) -Dtarget=node", 0},
{/* Wasmfs build. Fully unsupported and largely untested. */
"sqlite3-wasmfs", "esm" ,
LIBMODE_UNSUPPORTED | LIBMODE_WASMFS | LIBMODE_ESM,
"$(dir.wasmfs)/sqlite3-wasmfs.mjs",
"$(c-pp.D.sqlite3-bundler-friendly) -Dwasmfs",
"-sEXPORT_ES6 -sUSE_ES6_IMPORT_META"},
{/*End-of-list sentinel*/0,0,0,0,0,0}
};
/*
** Emits common vars needed by the rest of the emitted code (but not
** needed by makefile code outside of these generated pieces).
*/
static void mk_prologue(void){
/* A 0-terminated list of makefile vars which we expect to have been
** set up by this point in the build process. */
char const * aRequiredVars[] = {
"dir.top",
"dir.api", "dir.dout", "dir.tmp",
"sqlite3-license-version.js",
"MAKEFILE", "MAKEFILE_LIST",
/* Fiddle... */
"dir.fiddle", "dir.fiddle-debug",
"MAKEFILE.fiddle",
"EXPORTED_FUNCTIONS.fiddle",
/*"just-testing",*/
0
};
char const * zVar;
int i;
pf("%s# Build setup sanity checks...\n", zBanner);
for( i = 0; (zVar = aRequiredVars[i]); ++i ){
pf("ifeq (,$(%s))\n", zVar);
pf(" $(error build process error: expecting make var $$(%s) to "
"have been set up by now)\n", zVar);
ps("endif");
}
pf("%s", zBanner);
ps("# extern-post-js* and extern-pre-js* are files for use with");
ps("# Emscripten's --extern-pre-js and --extern-post-js flags.");
ps("extern-pre-js.js := $(dir.api)/extern-pre-js.js");
ps("extern-post-js.js.in := $(dir.api)/extern-post-js.c-pp.js");
ps("extern-pre-js.js = $(dir.api)/extern-pre-js.js");
ps("extern-post-js.js.in = $(dir.api)/extern-post-js.c-pp.js");
ps("# Emscripten flags for --[extern-][pre|post]-js=... for the");
ps("# various builds.");
ps("pre-post-common.flags := --extern-pre-js=$(sqlite3-license-version.js)");
ps("# pre-post-jses.deps.* = a list of dependencies for the");
ps("# --[extern-][pre/post]-js files.");
ps("pre-post-jses.deps.common := $(extern-pre-js.js) $(sqlite3-license-version.js)");
ps("pre-post-common.flags = --extern-pre-js=$(sqlite3-license-version.js)");
ps("# pre-post-jses.deps.* = a list of dependencies for the\n"
"# --[extern-][pre/post]-js files.");
ps("pre-post-jses.deps.common = $(extern-pre-js.js) $(sqlite3-license-version.js)");
{
/* SQLITE.CALL.WASM-OPT = shell code to run $(1) (source wasm file
@@ -127,7 +233,7 @@ static void mk_prologue(void){
"\t\techo -n 'After wasm-opt: '; \\\n"
"\t\tls -l $(1); \\\n"
"\telse \\\n"
"\t\techo 'WARNING: ignoring wasm-opt failure'; \\\n"
"\t\techo 'WARNING: ignoring wasm-opt failure for $(1)'; \\\n"
"\tfi\n",
zOptFlags
);
@@ -136,28 +242,6 @@ static void mk_prologue(void){
}
}
/*
** Flags for use with the 3rd argument to mk_pre_post() and
** mk_lib_mode().
**
** Maintenance reminder: do not combine flags within this enum,
** e.g. LIBMODE_BUNDLER_FRIENDLY=0x02|LIBMODE_ESM, as that will lead
** to breakage in some of the flag checks.
*/
enum LibModeFlags {
/* Indicates an ESM module build. */
LIBMODE_ESM = 0x01,
/* Indicates a "bundler-friendly" build mode. */
LIBMODE_BUNDLER_FRIENDLY = 0x02,
/* Indicates to _not_ add this build to the 'all' target. */
LIBMODE_DONT_ADD_TO_ALL = 0x04,
/* Indicates a node.js-for-node.js build (untested and
** unsupported). */
LIBMODE_NODEJS = 0x08,
/* Indicates a wasmfs build (untested and unsupported). */
LIBMODE_WASMFS = 0x10
};
/*
** Emits makefile code for setting up values for the --pre-js=FILE,
** --post-js=FILE, and --extern-post-js=FILE emcc flags, as well as
@@ -165,24 +249,26 @@ enum LibModeFlags {
*/
static void mk_pre_post(const char *zName /* build name */,
const char *zMode /* build mode */,
int flags /* LIBMODE_... mask */,
const char *zCmppD /* optional -D flags for c-pp for the
** --pre/--post-js files. */){
/* Very common printf() args combo. */
#define zNM zName, zMode
pf("%s# Begin --pre/--post flags for %s-%s\n", zBanner, zNM);
pf("c-pp.D.%s-%s := %s\n", zNM, zCmppD ? zCmppD : "");
pf("c-pp.D.%s-%s = %s\n", zNM, zCmppD ? zCmppD : "");
pf("pre-post-%s-%s.flags ?=\n", zNM);
/* --pre-js=... */
pf("pre-js.js.%s-%s := $(dir.tmp)/pre-js.%s-%s.js\n",
pf("pre-js.js.%s-%s = $(dir.tmp)/pre-js.%s-%s.js\n",
zNM, zNM);
pf("$(pre-js.js.%s-%s): $(MAKEFILE_LIST)\n", zNM);
pf("$(pre-js.js.%s-%s): $(MAKEFILE_LIST) $(sqlite3-license-version.js)\n", zNM);
#if 1
pf("$(eval $(call SQLITE.CALL.C-PP.FILTER,$(pre-js.js.in),$(pre-js.js.%s-%s),"
"$(c-pp.D.%s-%s)))\n", zNM, zNM);
#else
/* This part is needed if/when we re-enable the custom
** Module.instantiateModule() impl in api/pre-js.c-pp.js. */
pf("pre-js.js.%s-%s.intermediary := $(dir.tmp)/pre-js.%s-%s.intermediary.js\n",
pf("pre-js.js.%s-%s.intermediary = $(dir.tmp)/pre-js.%s-%s.intermediary.js\n",
zNM, zNM);
pf("$(eval $(call SQLITE.CALL.C-PP.FILTER,$(pre-js.js.in),$(pre-js.js.%s-%s.intermediary),"
"$(c-pp.D.%s-%s) -Dcustom-Module.instantiateModule))\n", zNM, zNM);
@@ -200,17 +286,17 @@ static void mk_pre_post(const char *zName /* build name */,
#endif
/* --post-js=... */
pf("post-js.js.%s-%s := $(dir.tmp)/post-js.%s-%s.js\n", zNM, zNM);
pf("post-js.js.%s-%s = $(dir.tmp)/post-js.%s-%s.js\n", zNM, zNM);
pf("$(eval $(call SQLITE.CALL.C-PP.FILTER,$(post-js.js.in),"
"$(post-js.js.%s-%s),$(c-pp.D.%s-%s)))\n", zNM, zNM);
/* --extern-post-js=... */
pf("extern-post-js.js.%s-%s := $(dir.tmp)/extern-post-js.%s-%s.js\n", zNM, zNM);
pf("extern-post-js.js.%s-%s = $(dir.tmp)/extern-post-js.%s-%s.js\n", zNM, zNM);
pf("$(eval $(call SQLITE.CALL.C-PP.FILTER,$(extern-post-js.js.in),$(extern-post-js.js.%s-%s),"
"$(c-pp.D.%s-%s)))\n", zNM, zNM);
/* Combined flags for use with emcc... */
pf("pre-post-common.flags.%s-%s := "
pf("pre-post-common.flags.%s-%s = "
"$(pre-post-common.flags) "
"--post-js=$(post-js.js.%s-%s) "
"--extern-post-js=$(extern-post-js.js.%s-%s)\n", zNM, zNM, zNM);
@@ -219,30 +305,29 @@ static void mk_pre_post(const char *zName /* build name */,
"--pre-js=$(pre-js.js.%s-%s)\n", zNM, zNM, zNM);
/* Set up deps... */
pf("pre-post-jses.%s-%s.deps := $(pre-post-jses.deps.common) "
pf("pre-post-jses.%s-%s.deps = $(pre-post-jses.deps.common) "
"$(post-js.js.%s-%s) $(extern-post-js.js.%s-%s)\n",
zNM, zNM, zNM);
pf("pre-post-%s-%s.deps := $(pre-post-jses.%s-%s.deps) $(dir.tmp)/pre-js.%s-%s.js\n",
pf("pre-post-%s-%s.deps = $(pre-post-jses.%s-%s.deps) $(dir.tmp)/pre-js.%s-%s.js\n",
zNM, zNM, zNM);
pf("# End --pre/--post flags for %s-%s%s", zNM, zBanner);
#undef zNM
}
/*
** Emits rules for the fiddle builds.
**
*/
static void mk_fiddle(){
static void mk_fiddle(void){
int i = 0;
mk_pre_post("fiddle-module","vanilla", 0, 0);
mk_pre_post("fiddle-module","vanilla", 0);
for( ; i < 2; ++i ){
/* 0==normal, 1==debug */
const char *zTail = i ? ".debug" : "";
const char *zDir = i ? "$(dir.fiddle-debug)" : "$(dir.fiddle)";
pf("%s# Begin fiddle%s\n", zBanner, zTail);
pf("fiddle-module.js%s := %s/fiddle-module.js\n", zTail, zDir);
pf("fiddle-module.wasm%s := "
"$(subst .js,.wasm,$(fiddle-module.js%s))\n", zTail, zTail);
pf("fiddle-module.js%s = %s/fiddle-module.js\n", zTail, zDir);
pf("$(fiddle-module.js%s):%s $(MAKEFILE_LIST) $(MAKEFILE.fiddle) "
"$(EXPORTED_FUNCTIONS.fiddle) "
"$(fiddle.cses) $(pre-post-fiddle-module-vanilla.deps) "
@@ -254,7 +339,9 @@ static void mk_fiddle(){
pf("\t$(bin.emcc) -o $@ $(fiddle.emcc-flags%s) "
"$(pre-post-fiddle-module-vanilla.flags) $(fiddle.cses)\n",
zTail);
pf("\t$(maybe-wasm-strip) $(fiddle-module.wasm%s)\n", zTail);
ps("\t@chmod -x $(basename $@).wasm");
ps("\t@$(maybe-wasm-strip) $(basename $@).wasm");
ps("\t@$(SQLITE.strip-createExportWrapper)");
pf("\t@cp -p $(SOAP.js) $(dir $@)\n");
if( 1==i ){/*fiddle.debug*/
pf("\tcp -p $(dir.fiddle)/index.html "
@@ -263,13 +350,13 @@ static void mk_fiddle(){
"$(dir $@)\n");
}
pf("\t@for i in %s/*.*js %s/*.html %s/*.wasm; do \\\n"
"\t\ttest -f $${i} || continue; \\\n"
"\t\ttest -f $${i} || continue; \\\n"
"\t\tgzip < $${i} > $${i}.gz; \\\n"
"\tdone\n", zDir, zDir, zDir);
if( 0==i ){
ps("fiddle: $(fiddle-module.js)");
}else{
ps("fiddle-debug: $(fiddle-module-debug.js)");
ps("fiddle-debug: $(fiddle-module.js.debug)");
}
pf("# End fiddle%s%s", zTail, zBanner);
}
@@ -280,138 +367,110 @@ static void mk_fiddle(){
** by the combination of zName and zMode, each of which must be values
** from JS_BUILD_NAMES resp. JS_BUILD_MODES.
*/
static void mk_lib_mode(const char *zName /* build name */,
const char *zMode /* build mode */,
int flags /* LIBMODE_... mask */,
const char *zApiJsOut /* name of generated sqlite3-api.js/.mjs */,
const char *zJsOut /* name of generated sqlite3.js/.mjs */,
const char *zCmppD /* extra -D flags for c-pp */,
const char *zEmcc /* extra flags for emcc */){
static void mk_lib_mode(const BuildDef * pB){
const char * zWasmOut = "$(basename $@).wasm"
/* The various targets named X.js or X.mjs (zJsOut) also generate
** X.wasm, and we need that part of the name to perform some
** post-processing after Emscripten generates X.wasm. */;
assert( zName );
assert( zMode );
assert( zApiJsOut );
assert( zJsOut );
if( !zCmppD ) zCmppD = "";
if( !zEmcc ) zEmcc = "";
assert( pB->zName );
assert( pB->zMode );
assert( pB->zJsOut );
/* Very common printf() args combo. */
#define zNM pB->zName, pB->zMode
pf("%s# Begin build [%s-%s]\n", zBanner, zNM);
pf("# zApiJsOut=%s\n# zJsOut=%s\n# zCmppD=%s\n", zApiJsOut, zJsOut, zCmppD);
pf("$(info Setting up build [%s-%s]: %s)\n", zNM, zJsOut);
mk_pre_post(zNM, flags, zCmppD);
pf("%s# Begin build [%s-%s]. flags=0x%02x\n", zBanner, zNM, pB->flags);
pf("# zJsOut=%s\n# zCmppD=%s\n", pB->zJsOut,
pB->zCmppD ? pB->zCmppD : "<none>");
pf("$(info Setting up build [%s-%s]: %s)\n", zNM, pB->zJsOut);
mk_pre_post(zNM, pB->zCmppD);
pf("\nemcc.flags.%s.%s ?=\n", zNM);
if( zEmcc[0] ){
pf("emcc.flags.%s.%s += %s\n", zNM, zEmcc);
if( pB->zEmcc && pB->zEmcc[0] ){
pf("emcc.flags.%s.%s += %s\n", zNM, pB->zEmcc);
}
pf("$(eval $(call SQLITE.CALL.C-PP.FILTER, $(sqlite3-api.js.in), %s, %s))\n",
zApiJsOut, zCmppD);
/* target zJsOut */
pf("%s: %s $(MAKEFILE_LIST) $(sqlite3-wasm.cfiles) $(EXPORTED_FUNCTIONS.api) "
/* target pB->zJsOut */
pf("%s: $(MAKEFILE_LIST) $(sqlite3-wasm.cfiles) $(EXPORTED_FUNCTIONS.api) "
"$(pre-post-%s-%s.deps) "
"$(sqlite3-api.ext.jses)"
/* ^^^ maintenance reminder: we set these as deps so that they
get copied into place early. That allows the developer to
reload the base-most test pages while the later-stage builds
are still compiling, which is especially helpful when running
builds with long build times (like -Oz). */
** get copied into place early. That allows the developer to
** reload the base-most test pages while the later-stage builds
** are still compiling, which is especially helpful when running
** builds with long build times (like -Oz). */
"\n",
zJsOut, zApiJsOut, zNM);
pB->zJsOut, zNM);
pf("\t@echo \"Building $@ ...\"\n");
if( LIBMODE_UNSUPPORTED & pB->flags ){
ps("\t@echo 'ACHTUNG: $@ is an unsupported build. "
"Use at your own risk.'");
}
pf("\t$(bin.emcc) -o $@ $(emcc_opt_full) $(emcc.flags) \\\n");
pf("\t\t$(emcc.jsflags) -sENVIRONMENT=$(emcc.environment.%s) \\\n", zMode);
pf("\t\t$(emcc.jsflags) -sENVIRONMENT=$(emcc.environment.%s) \\\n",
pB->zMode);
pf("\t\t$(pre-post-%s-%s.flags) \\\n", zNM);
pf("\t\t$(emcc.flags.%s) $(emcc.flags.%s.%s) \\\n", zName, zNM);
pf("\t\t$(emcc.flags.%s) $(emcc.flags.%s.%s) \\\n", pB->zName, zNM);
pf("\t\t$(cflags.common) $(SQLITE_OPT) \\\n"
"\t\t$(cflags.%s) $(cflags.%s.%s) \\\n"
"\t\t$(cflags.wasm_extra_init) $(sqlite3-wasm.cfiles)\n", zName, zNM);
if( (LIBMODE_ESM & flags) || (LIBMODE_NODEJS & flags) ){
"\t\t$(cflags.wasm_extra_init) $(sqlite3-wasm.cfiles)\n", pB->zName, zNM);
if( (LIBMODE_ESM & pB->flags) || (LIBMODE_NODEJS & pB->flags) ){
/* TODO? Replace this $(call) with the corresponding makefile
** code. OTOH, we also use this $(call) in the speedtest1-wasmfs
** build, which is not part of the rules emitted by this
** program. */
pf("\t@$(call SQLITE.CALL.xJS.ESM-EXPORT-DEFAULT,1,%d)\n",
(LIBMODE_WASMFS & flags) ? 1 : 0);
(LIBMODE_WASMFS & pB->flags) ? 1 : 0);
}
pf("\t@chmod -x %s; \\\n"
"\t\t$(maybe-wasm-strip) %s;\n",
zWasmOut, zWasmOut);
pf("\t@chmod -x %s\n", zWasmOut);
pf("\t@$(maybe-wasm-strip) %s\n", zWasmOut);
pf("\t@$(call SQLITE.CALL.WASM-OPT,%s)\n", zWasmOut);
pf("\t@sed -i -e '/^var _sqlite3.*createExportWrapper/d' %s || exit; \\\n"
/* ^^^^^^ reminder: Mac/BSD sed has no -i flag */
"\t\techo 'Stripped out createExportWrapper() parts.'\n",
zJsOut) /* Our JS code installs bindings of each WASM export. The
generated Emscripten JS file does the same using its
own framework, but we don't use those results and can
speed up lib init, and reduce memory cost
considerably, by stripping them out. */;
ps("\t@$(SQLITE.strip-createExportWrapper)");
/*
** The above $(bin.emcc) call will write zJsOut and will create a
** like-named .wasm file (zWasmOut). That .wasm file name gets
** hard-coded into zJsOut so we need to, for some cases, patch
** zJsOut to use the name sqlite3.wasm instead. Note that the
** The above $(bin.emcc) call will write pB->zJsOut, a.k.a. $@, and
** will create a like-named .wasm file (zWasmOut). That .wasm file
** name gets hard-coded into $@ so we need to, for some cases, patch
** zJsOut to use the name sqlite3.wasm instead. Note that the
** resulting .wasm file is identical for all builds for which zEmcc
** is empty.
*/
if( (LIBMODE_BUNDLER_FRIENDLY & flags)
|| (LIBMODE_NODEJS & flags) ){
pf("\t@echo 'Patching $@ for %s.wasm...'; \\\n", zName);
if( (LIBMODE_BUNDLER_FRIENDLY & pB->flags) ){
pf("\t@echo 'Patching $@ for %s.wasm...'; \\\n", pB->zName);
pf("\t\trm -f %s; \\\n", zWasmOut);
pf("\t\tsed -i -e 's/%s-%s.wasm/%s.wasm/g' $@ || exit;\n",
/* ^^^^^^ reminder: Mac/BSD sed has no -i flag */
zNM, zName);
/* ^^^^^^ reminder: Mac/BSD sed has no -i flag but this
** build process explicitly requires a Linux system. */
zNM, pB->zName);
pf("\t@ls -la $@\n");
if( LIBMODE_BUNDLER_FRIENDLY & flags ){
if( LIBMODE_BUNDLER_FRIENDLY & pB->flags ){
/* Avoid a 3rd occurrence of the bug fixed by 65798c09a00662a3,
** which was (in two cases) caused by makefile refactoring and
** not recognized until after a release was made with the broken
** sqlite3-bundler-friendly.mjs: */
** sqlite3-bundler-friendly.mjs (which is used by the npm
** subproject but is otherwise untested/unsupported): */
pf("\t@if grep -e '^ *importScripts(' $@; "
"then echo 'ERROR: bug fixed in 65798c09a00662a3 has re-appeared'; "
"exit 1; fi;\n");
}
}else{
pf("\t@ls -la %s $@\n", zWasmOut);
}
if( 0==(LIBMODE_DONT_ADD_TO_ALL & flags) ){
pf("all: %s\n", zJsOut);
if( 0==(LIBMODE_UNSUPPORTED & pB->flags) ){
pf("all: %s\n", pB->zJsOut);
}
pf("# End build [%s-%s]%s", zNM, zBanner);
#undef zNM
}
int main(void){
int rc = 0;
const BuildDef *pB = &aBuildDefs[0];
pf("# What follows was GENERATED by %s. Edit at your own risk.\n", __FILE__);
mk_prologue();
mk_lib_mode("sqlite3", "vanilla", 0,
"$(sqlite3-api.js)", "$(sqlite3.js)", 0, 0);
mk_lib_mode("sqlite3", "esm", LIBMODE_ESM,
"$(sqlite3-api.mjs)", "$(sqlite3.mjs)",
"-Dtarget=es6-module", 0);
mk_lib_mode("sqlite3", "bundler-friendly",
LIBMODE_BUNDLER_FRIENDLY | LIBMODE_ESM,
"$(sqlite3-api-bundler-friendly.mjs)",
"$(sqlite3-bundler-friendly.mjs)",
"$(c-pp.D.sqlite3-esm) -Dtarget=es6-bundler-friendly", 0);
mk_lib_mode("sqlite3" , "node",
LIBMODE_NODEJS | LIBMODE_DONT_ADD_TO_ALL,
"$(sqlite3-api-node.mjs)", "$(sqlite3-node.mjs)",
"$(c-pp.D.sqlite3-bundler-friendly) -Dtarget=node", 0);
mk_lib_mode("sqlite3-wasmfs", "esm" ,
LIBMODE_WASMFS | LIBMODE_ESM | LIBMODE_DONT_ADD_TO_ALL,
/* The sqlite3-wasmfs build is optional and needs to be invoked
** conditionally using info we don't have here. */
"$(sqlite3-api-wasmfs.mjs)", "$(sqlite3-wasmfs.mjs)",
"$(c-pp.D.sqlite3-bundler-friendly) -Dwasmfs",
"-sEXPORT_ES6 -sUSE_ES6_IMPORT_META");
for( ; pB->zName; ++pB ){
mk_lib_mode( pB );
}
mk_fiddle();
mk_pre_post("speedtest1","vanilla", 0, 0);
mk_pre_post("speedtest1-wasmfs","esm", 0,
mk_pre_post("speedtest1","vanilla", 0);
mk_pre_post("speedtest1-wasmfs","esm",
"$(c-pp.D.sqlite3-bundler-friendly) -Dwasmfs");
return rc;
}
+3 -4
View File
@@ -23,11 +23,10 @@
</figure>
<div class="emscripten" id="module-status">Downloading...</div>
<div class="emscripten">
<progress value="0" max="100" id="module-progress" hidden='1'></progress>
<progress value="0" max="100" id="module-progress" hidden='1'></progress>
</div><!-- /emscripten bits -->
<div class='warning'>This page starts running the main exe when it loads, which will
block the UI until it finishes! Adding UI controls to manually configure and start it
are TODO.</div>
block the UI until it finishes!</div>
</div>
<div class='warning'>Achtung: running it with the dev tools open may
<em>drastically</em> slow it down. For faster results, keep the dev
@@ -118,7 +117,7 @@
argv.push("--vfs", vfs);
log2('',"Using VFS:",vfs);
if('kvvfs' === vfs){
forceSize = 2 /* 5 uses approx. 4.96mb */;
forceSize = 2 /* >2 is too big as of mid-2025 */;
dbFile = 'session';
log2('warning',"kvvfs VFS: forcing --size",forceSize,
"and filename '"+dbFile+"'.");
+104 -2
View File
@@ -41,7 +41,7 @@
ES6 worker module build:
./c-pp -f tester1.c-pp.js -o tester1-esm.js -Dtarget=es6-module
./c-pp -f tester1.c-pp.js -o tester1-esm.mjs -Dtarget=es6-module
*/
//#if target=es6-module
import {default as sqlite3InitModule} from './jswasm/sqlite3.mjs';
@@ -221,7 +221,7 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
else if(filter instanceof Function) pass = filter(err);
else if('string' === typeof filter) pass = (err.message === filter);
if(!pass){
throw new Error(msg || ("Filter rejected this exception: "+err.message));
throw new Error(msg || ("Filter rejected this exception: <<"+err.message+">>"));
}
return this;
},
@@ -1209,6 +1209,104 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
}
}
})
////////////////////////////////////////////////////////////////////
.t({
name: "oo1.DB/Stmt.wrapDbHandle()",
test: function(sqlite3){
/* Maintenance reminder: this function is early in the list to
demonstrate that the wrappers for this.db created by this
function do not interfere with downstream tests, e.g. by
closing this.db.pointer. */
//sqlite3.config.debug("Proxying",this.db);
const misuseMsg = "SQLITE_MISUSE: Argument must be a WASM sqlite3 pointer";
T.mustThrowMatching(()=>sqlite3.oo1.DB.wrapHandle(this.db), misuseMsg)
.mustThrowMatching(()=>sqlite3.oo1.DB.wrapHandle(0), misuseMsg);
let dw = sqlite3.oo1.DB.wrapHandle(this.db.pointer);
//sqlite3.config.debug('dw',dw);
T.assert( dw, '!!dw' )
.assert( dw instanceof sqlite3.oo1.DB, 'dw is-a oo1.DB' )
.assert( dw.pointer, 'dw.pointer' )
.assert( dw.pointer === this.db.pointer, 'dw.pointer===db.pointer' )
.assert( dw.filename === this.db.filename, 'dw.filename===db.filename' );
T.assert( dw === dw.exec("select 1") );
let q;
try {
q = dw.prepare("select 1");
T.assert( q.step() )
.assert( !q.step() );
}finally{
if( q ) q.finalize();
}
dw.close();
T.assert( !dw.pointer )
.assert( this.db === this.db.exec("select 1") );
dw = undefined;
let pDb = 0, pStmt = 0;
const stack = wasm.pstack.pointer;
try {
const ppOut = wasm.pstack.allocPtr();
T.assert( 0===wasm.peekPtr(ppOut) );
let rc = capi.sqlite3_open_v2( ":memory:", ppOut,
capi.SQLITE_OPEN_CREATE
| capi.SQLITE_OPEN_READWRITE,
0);
T.assert( 0===rc, 'open_v2()' );
pDb = wasm.peekPtr(ppOut);
wasm.pokePtr(ppOut, 0);
T.assert( pDb>0, 'pDb>0' );
const pTmp = pDb;
dw = sqlite3.oo1.DB.wrapHandle(pDb, true);
pDb = 0;
//sqlite3.config.debug("dw",dw);
T.assert( pTmp===dw.pointer, 'pDb===dw.pointer' );
T.assert( dw.filename === "", "dw.filename == "+dw.filename );
let q = dw.prepare("select 1");
try {
T.assert( q.step(), "step()" );
T.assert( !q.step(), "!step()" );
}finally{
q.finalize();
q = undefined;
}
T.assert( dw===dw.exec("select 1") );
dw.affirmOpen();
const select1 = "select 1";
rc = capi.sqlite3_prepare_v2( dw, select1, -1, ppOut, 0 );
T.assert( 0===rc, 'prepare_v2() rc='+rc );
pStmt = wasm.peekPtr(ppOut);
T.assert( pStmt && wasm.isPtr(pStmt), 'pStmt is valid?' );
try {
//log( "capi.sqlite3_sql() =",capi.sqlite3_sql(pStmt));
T.assert( select1 === capi.sqlite3_sql(pStmt), 'SQL mismatch' );
q = sqlite3.oo1.Stmt.wrapHandle(dw, pStmt, false);
//log("q@"+pStmt+" does not own handle");
T.assert( q.step(), "step()" )
.assert( !q.step(), "!step()" );
q.finalize();
q = undefined;
T.assert( select1 === capi.sqlite3_sql(pStmt), 'SQL mismatch'
/* This will fail if we've mismanaged pStmt's lifetime */);
q = sqlite3.oo1.Stmt.wrapHandle(dw, pStmt, true);
pStmt = 0;
q.reset();
T.assert( q.step(), "step()" )
.assert( !q.step(), "!step()" );
}finally{
if( pStmt ) capi.sqlite3_finalize(pStmt)
if( q ) q.finalize();
}
}finally{
wasm.pstack.restore(stack);
if( pDb ){ capi.sqlite3_close_v2(pDb); }
else if( dw ){ dw.close(); }
}
}
})/*oo1.DB/Stmt.wrapHandle()*/
////////////////////////////////////////////////////////////////////
.t('sqlite3_db_config() and sqlite3_db_status()', function(sqlite3){
let rc = capi.sqlite3_db_config(this.db, capi.SQLITE_DBCONFIG_LEGACY_ALTER_TABLE, 0, 0);
@@ -1268,6 +1366,7 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
/columnCount property is read-only/)
.assert(1===st.columnCount)
.assert(0===st.parameterCount)
.assert(0===capi.sqlite3_bind_parameter_count(st))
.mustThrow(()=>st.bind(1,null))
.assert(true===st.step())
.assert(3 === st.get(0))
@@ -1490,6 +1589,8 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
let st = db.prepare("update t set b=:b where a='blob'");
try {
T.assert(0===st.columnCount)
.assert(1===st.parameterCount)
.assert(1===capi.sqlite3_bind_parameter_count(st))
.assert( false===st.isReadOnly() );
const ndx = st.getParamIndex(':b');
T.assert(1===ndx);
@@ -3329,6 +3430,7 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
db.exec("create table t(a)");
const stmt = db.prepare("insert into t(a) values($a)");
T.assert( 1===capi.sqlite3_bind_parameter_count(stmt) )
.assert( 1===stmt.parameterCount )
.assert( 1===capi.sqlite3_bind_parameter_index(stmt, "$a") )
.assert( 0===capi.sqlite3_bind_parameter_index(stmt, ":a") )
.assert( 1===stmt.getParamIndex("$a") )
+21 -25
View File
@@ -5,31 +5,28 @@
# sqlite3.wasm. It is intended to be "include"d from the main
# GNUMakefile.
########################################################################
MAKEFILE.wasmfs := $(lastword $(MAKEFILE_LIST))
MAKEFILE.wasmfs = $(lastword $(MAKEFILE_LIST))
# ensure that the following message starts on line 10 or higher for proper
# $(warning) alignment!
ifneq (1,$(MAKING_CLEAN))
$(warning !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!)
$(warning !! The WASMFS build is not well-supported. WASMFS is a proverbial)
$(warning !! moving target, sometimes changing in incompatible ways between)
$(warning !! Emscripten versions. This build is provided for adventurous folks)
$(warning !! and is not a supported deliverable of the SQLite project.)
$(warning !! The WASMFS build is unsupported. Use at your own risk.
$(warning !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!)
endif
sqlite3-wasmfs.js := $(dir.wasmfs)/sqlite3-wasmfs.js
sqlite3-wasmfs.wasm := $(dir.wasmfs)/sqlite3-wasmfs.wasm
sqlite3-wasmfs.js = $(dir.wasmfs)/sqlite3-wasmfs.js
sqlite3-wasmfs.wasm = $(dir.wasmfs)/sqlite3-wasmfs.wasm
########################################################################
# emcc flags for .c/.o.
cflags.sqlite3-wasmfs :=
cflags.sqlite3-wasmfs =
cflags.sqlite3-wasmfs += -std=c99 -fPIC
cflags.sqlite3-wasmfs += -pthread
cflags.sqlite3-wasmfs += -DSQLITE_ENABLE_WASMFS
########################################################################
# emcc flags specific to building the final .js/.wasm file...
emcc.flags.sqlite3-wasmfs :=
emcc.flags.sqlite3-wasmfs =
emcc.flags.sqlite3-wasmfs += \
-sEXPORTED_RUNTIME_METHODS=wasmMemory
# wasmMemory ==> for -sIMPORTED_MEMORY
@@ -43,7 +40,7 @@ emcc.flags.sqlite3-wasmfs += -Wno-limited-postlink-optimizations
emcc.flags.sqlite3-wasmfs += -sMEMORY64=0
emcc.flags.sqlite3-wasmfs += -sINITIAL_MEMORY=$(emcc.INITIAL_MEMORY.128)
# ^^^^ 64MB is not enough for WASMFS/OPFS test runs using batch-runner.js
sqlite3-wasmfs.fsflags := -pthread -sWASMFS \
sqlite3-wasmfs.fsflags = -pthread -sWASMFS \
-sPTHREAD_POOL_SIZE=1 \
-sERROR_ON_UNDEFINED_SYMBOLS=0 -sLLD_REPORT_UNDEFINED
# ^^^^^ why undefined symbols are necessary for the wasmfs build is anyone's guess.
@@ -53,10 +50,9 @@ emcc.flags.sqlite3-wasmfs += -sALLOW_MEMORY_GROWTH=0
# USE_PTHREADS + ALLOW_MEMORY_GROWTH may run non-wasm code slowly,
# see https://github.com/WebAssembly/design/issues/1271 [-Wpthreads-mem-growth]
# And, indeed, it runs slowly if memory is permitted to grow.
#emcc.flags.sqlite3-wasmfs.vanilla :=
#emcc.flags.sqlite3-wasmfs.esm := -sEXPORT_ES6 -sUSE_ES6_IMPORT_META
all: $(sqlite3-wasmfs.mjs)
$(sqlite3-wasmfs.js) $(sqlite3-wasmfs.mjs): $(MAKEFILE.wasmfs)
#emcc.flags.sqlite3-wasmfs.vanilla =
#emcc.flags.sqlite3-wasmfs.esm = -sEXPORT_ES6 -sUSE_ES6_IMPORT_META
$(sqlite3-wasmfs.js) $(dir.wasmfs)/sqlite3-wasmfs.mjs: $(MAKEFILE.wasmfs)
########################################################################
# Build quirk: we cannot build BOTH .js and .mjs with our current
# build infrastructure because the supplemental *.worker.js files get
@@ -68,31 +64,31 @@ $(sqlite3-wasmfs.js) $(sqlite3-wasmfs.mjs): $(MAKEFILE.wasmfs)
# names is that it means that the corresponding .wasm file is also
# built/saved multiple times. It is likely that anyone wanting to use
# WASMFS will want an ES6 module, so that's what we build here.
wasmfs.build.ext := mjs
$(sqlite3-wasmfs.js) $(sqlite3-wasmfs.mjs): $(SOAP.js.bld)
wasmfs.build.ext = mjs
$(sqlite3-wasmfs.js) $(dir.wasmfs)/sqlite3-wasmfs.mjs: $(SOAP.js.bld)
ifeq (js,$(wasmfs.build.ext))
$(sqlite3-wasmfs.wasm): $(sqlite3-wasmfs.js)
wasmfs: $(sqlite3-wasmfs.js)
else
$(sqlite3-wasmfs.wasm): $(sqlite3-wasmfs.mjs)
wasmfs: $(sqlite3-wasmfs.mjs)
$(sqlite3-wasmfs.wasm): $(dir.wasmfs)/sqlite3-wasmfs.mjs
wasmfs: $(dir.wasmfs)/sqlite3-wasmfs.mjs
endif
all: wasmfs
########################################################################
# speedtest1 for wasmfs.
speedtest1-wasmfs.mjs := $(dir.wasmfs)/speedtest1-wasmfs.mjs
speedtest1-wasmfs.wasm := $(subst .mjs,.wasm,$(speedtest1-wasmfs.mjs))
emcc.flags.speedtest1-wasmfs := $(sqlite3-wasmfs.fsflags)
speedtest1-wasmfs.mjs = $(dir.wasmfs)/speedtest1-wasmfs.mjs
speedtest1-wasmfs.wasm = $(subst .mjs,.wasm,$(speedtest1-wasmfs.mjs))
emcc.flags.speedtest1-wasmfs = $(sqlite3-wasmfs.fsflags)
emcc.flags.speedtest1-wasmfs += $(SQLITE_OPT)
emcc.flags.speedtest1-wasmfs += -sALLOW_MEMORY_GROWTH=0
emcc.flags.speedtest1-wasmfs += -sINITIAL_MEMORY=$(emcc.INITIAL_MEMORY.128)
#$(eval $(call call-make-pre-js,speedtest1-wasmfs,ems))
#$(info speedtest DEPS=pre-post-sqlite3-wasmfs-esm.deps=$(pre-post-sqlite3-wasmfs-esm.deps))
$(speedtest1-wasmfs.mjs): $(speedtest1.cfiles) $(sqlite3-wasmfs.js) \
$(MAKEFILE) $(MAKEFILE.wasmfs) \
$(pre-post-sqlite3-wasmfs-esm.deps) \
$(MAKEFILE) $(MAKEFILE.wasmfs) $(pre-post-sqlite3-wasmfs-esm.deps) \
$(EXPORTED_FUNCTIONS.speedtest1)
@echo "Building $@ ..."
$(emcc.bin) \
$(bin.emcc) \
$(pre-post-sqlite3-wasmfs-esm.flags) \
$(cflags.common) \
$(cflags.sqlite3-wasmfs) \
+28 -21
View File
@@ -11,8 +11,8 @@
# POSIX Make compatible. "bmake" (BSD make) is available on most
# Linux systems, so compatibility is relatively easy to test. As a
# harmless exception, this file sometimes uses $(MAKEFILE_LIST) as a
# dependency. That var, in GNU Make, lists all of the makefile
# currently loaded.
# dependency. That var, in GNU Make, holds a list of all of the
# makefiles currently loaded.
#
# The variables listed below must be defined before this script is
# invoked. This file will use defaults, very possibly invalid, for any
@@ -62,8 +62,8 @@ AR.flags ?= cr
#
# $(B.exe) =
#
# File extension for executables on the build platform. ".exe" for
# Windows and "" everywhere else.
# File extension for executables on the build platform:. .exe for
# Windows and empty everywhere else.
#
B.exe ?=
#
@@ -76,8 +76,8 @@ B.lib ?= .a
#
# $(T.exe) =
#
# File extension for executables on the target platform. ".exe" for
# Windows and "" everywhere else.
# File extension for executables on the target platform: .exe for
# Windows and empty everywhere else.
#
T.exe ?= $(B.exe)
#
@@ -100,7 +100,7 @@ TCLSH_CMD ?= tclsh
#
# JimTCL is part of the autosetup suite and is suitable for all
# current in-tree code-generation TCL jobs, but it requires that we
# build it with non-default flags. Note that the build tree will, if
# build it with non-default flags. The canonical build tree will, if
# no system-level tclsh is found, also have a ./jimsh0 binary. That
# one is a bare-bones build for the configure process, whereas we need
# to build it with another option enabled for use with the various
@@ -118,9 +118,10 @@ JIMSH ?= ./jimsh$(T.exe)
# $(B.tclsh) =
#
# The TCL interpreter for in-tree code generation. May be either the
# in-tree JimTCL ($(JIMSH)) or the canonical TCL ($(TCLSH_CMD). If
# in-tree JimTCL ($(JIMSH)) or the canonical TCL ($(TCLSH_CMD)). If
# it's JimTCL, it must be compiled with -DHAVE_REALPATH (Unix) or
# -DHAVE__FULLPATH (Windows).
# -DHAVE__FULLPATH (Windows) so that the Tcl function [file normalize]
# can work.
#
B.tclsh ?= $(JIMSH)
@@ -253,20 +254,20 @@ EXTRA_SRC ?=
# and ENABLE flags must be passed to the LEMON parser generator and
# the mkkeywordhash tool as well. This is normally set by the
# configure process, and passing a custom value to a
# coonfigure-filtered Makefile may not work.
# configure-filtered Makefile may not work.
#
# When using the canonical makefile, add $(OPTIONS)=... on the make
# command line to append additional options to the
# $(OPT_FEATURE_FLAGS). Note that some flags, because they influence
# generation of the SQL parser, only work if the build is specifically
# configured to account for them. Adding them later, when compiling
# the amalgamation separately, may or may not work.
# $(OPT_FEATURE_FLAGS). Some flags, because they influence generation
# of the SQL parser, only work if the build is specifically configured
# to account for them. Adding them later, when compiling the
# amalgamation separately, may or may not work.
#
# $(OPTS)=... is another way of influencing C compilation. It is
# distinctly separate from $(OPTIONS) and $(OPT_FEATURE_FLAGS) but,
# like those, $(OPTS) applies to all invocations of $(T.cc) (and some
# invocations of $(B.cc). The configure process does not set either of
# $(OPTIONS) or $(OPTS).
# invocations of $(B.cc)). The configure process does not set either
# of $(OPTIONS) or $(OPTS).
#
OPT_FEATURE_FLAGS ?=
#
@@ -1123,7 +1124,9 @@ libsqlite3.LIB = libsqlite3$(T.lib)
#
# libsqlite3.DLL.install-rules => the suffix of the symoblic name of
# the makefile rules for installing the DLL.
# the makefile rules for installing the DLL. Must be one of
# (unix-generic, msys, mingw, cygwin, darwin) and a target named
# install-dll-THATNAME is responsible for DLL installation.
libsqlite3.DLL.install-rules ?= unix-generic
# Rules to build the LEMON compiler generator
@@ -1686,7 +1689,7 @@ CFLAGS.tclextension = $(CFLAGS.intree_includes) $(CFLAGS.env) $(OPT_FEATURE_FLAG
#
# Build the SQLite TCL extension in a way that make it compatible
# with whatever version of TCL is running as $TCLSH_CMD, possibly defined
# by --with-tclsh=
# by --with-tclsh=/path/to/tclsh.
#
tclextension: tclsqlite3.c
$(TCLSH_CMD) $(TOP)/tool/buildtclext.tcl --build-only \
@@ -1798,7 +1801,7 @@ TESTFIXTURE_SRC += $(TESTFIXTURE_SRC$(USE_AMALGAMATION))
testfixture$(T.exe): $(T.tcl.env.sh) has_tclsh85 $(TESTFIXTURE_SRC)
$(T.link.tcl) -DSQLITE_NO_SYNC=1 $(TESTFIXTURE_FLAGS) \
-o $@ $(TESTFIXTURE_SRC) \
$$TCL_LIB_SPEC $$TCL_INCLUDE_SPEC \
$$TCL_LIB_SPEC $$TCL_INCLUDE_SPEC $$TCL_LIBS \
$(LDFLAGS.libsqlite3)
coretestprogs: testfixture$(B.exe) sqlite3$(B.exe)
@@ -1960,7 +1963,7 @@ xbin: sqltclsh$(T.exe) sqlite3_analyzer$(T.exe)
sqlite3_expert$(T.exe): $(TOP)/ext/expert/sqlite3expert.h $(TOP)/ext/expert/sqlite3expert.c \
$(TOP)/ext/expert/expert.c sqlite3.c
$(T.link) $(TOP)/ext/expert/sqlite3expert.h $(TOP)/ext/expert/sqlite3expert.c \
$(T.link) $(TOP)/ext/expert/sqlite3expert.c \
$(TOP)/ext/expert/expert.c sqlite3.c -o sqlite3_expert $(LDFLAGS.libsqlite3)
xbin: sqlite3_expert$(T.exe)
@@ -2113,6 +2116,10 @@ tool-zip: testfixture$(T.exe) sqlite3$(T.exe) sqldiff$(T.exe) \
sqlite3_analyzer$(T.exe) sqlite3_rsync$(T.exe) $(TOP)/tool/mktoolzip.tcl
strip sqlite3$(T.exe) sqldiff$(T.exe) sqlite3_analyzer$(T.exe) sqlite3_rsync$(T.exe)
./testfixture$(T.exe) $(TOP)/tool/mktoolzip.tcl
snapshot-zip: testfixture$(T.exe) sqlite3$(T.exe) sqldiff$(T.exe) \
sqlite3_analyzer$(T.exe) sqlite3_rsync$(T.exe) $(TOP)/tool/mktoolzip.tcl
strip sqlite3$(T.exe) sqldiff$(T.exe) sqlite3_analyzer$(T.exe) sqlite3_rsync$(T.exe)
./testfixture$(T.exe) $(TOP)/tool/mktoolzip.tcl --snapshot
clean-tool-zip:
rm -f sqlite-tools-*.zip
clean: clean-tool-zip
@@ -2475,7 +2482,7 @@ help:
#
#
tidy:
rm -f *.o *.c *.da *.bb *.bbg gmon.* *.rws sqlite3$(T.exe)
rm -f *.o *.obj *.c *.da *.bb *.bbg gmon.* *.rws sqlite3$(T.exe)
rm -f fts5.h keywordhash.h opcodes.h sqlite3.h sqlite3ext.h sqlite3session.h
rm -rf .libs .deps tsrc .target_source
rm -f lemon$(B.exe) sqlite*.tar.gz
+126 -160
View File
@@ -1,12 +1,12 @@
C Squelch\sa\slegitimate\sbut\sharmless\s'discards\sconst'\swarning.
D 2025-07-16T09:20:02.408
C Use\sa\sseparate\smutex\s(SQLITE_MUTEX_STATIC_VFS2)\sfor\sthe\sVxWorks\sfile\slist\nin\sos_unix.c.
D 2025-09-10T18:34:09.319
F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md e108e1e69ae8e8a59e93c455654b8ac9356a11720d3345df2a4743e9590fb20d
F Makefile.in d8bc4aee9fb645c9f2ff0e3a30585d17a0df076bb6a33f0f20bab4999abb45a0
F Makefile.in 3ce07126d7e87c7464301482e161fdae6a51d0a2aa06b200b8f0000ef4d6163b
F Makefile.linux-generic bd3e3cacd369821a6241d4ea1967395c962dfe3057e38cb0a435cee0e8b789d0
F Makefile.msc ec2011bbdfc917d6a1c7c173dabb29c14ead0dd8e2e0b67278a00ae4ba576a77
F Makefile.msc b87ac9041d87f61fabd6074e6d8b71dd7f78c884a2307bbb9301f9d436ce9242
F README.md e28077cfbef795e99c9c75ed95aa7257a1166709b562076441a8506ac421b7c1
F VERSION 16eddb43056a79c1977427ab7a05f3457c373fa159dcdced8754eb89ce7e06b8
F art/icon-243x273.gif 9750b734f82fdb3dc43127753d5e6fbf3b62c9f4e136c2fbf573b2f57ea87af5
@@ -15,9 +15,9 @@ F art/sqlite370.eps aa97a671332b432a54e1d74ff5e8775be34200c2
F art/sqlite370.ico af56c1d00fee7cd4753e8631ed60703ed0fc6e90
F art/sqlite370.jpg d512473dae7e378a67e28ff96a34da7cb331def2
F art/sqlite370.svg 40b7e2fe8aac3add5d56dd86ab8d427a4eca5bcb3fe4f8946cb3794e1821d531
F auto.def 82c32443a91c1062f7a48beec37dbb2d8d03447b1286bce8df5ebb6d8d353f8a
F auto.def 44a0d1bf09d78355fc88251ccbf8e64e6341fd89c11de68a01c3645e53a2bade
F autoconf/Makefile.fallback 22fe523eb36dfce31e0f6349f782eb084e86a5620b2b0b4f84a2d6133f53f5ac
F autoconf/Makefile.in d0926d2309e563b5ebdfd711e5c218533acab79829a05eef4e97c3a92e17bf42
F autoconf/Makefile.in 306f500fce8cae9e1af9459f1ac7fe89ce46999594ef3fdc62dc9d7d651fb091
F autoconf/Makefile.msc f15ad424ca2820df8e39d9157965710af0a64d87773706706a12ea4f96e3a0d8
F autoconf/README.first f1d3876e9a7852c22f275a6f06814e64934cecbc0b5b9617d64849094c1fd136
F autoconf/README.txt b749816b8452b3af994dc6d607394bef3df1736d7e09359f1087de8439a52807
@@ -26,14 +26,14 @@ F autoconf/tea/Makefile.in bf6b43eafcd18766d81a8f0085cfc9cb051d8abae9031a8e7c3f5
F autoconf/tea/README.txt 23475876343498ef2b514cc7510e8f1559a17e8e03fbc7a41c1c8a3b89e7b7e3
F autoconf/tea/_teaish.tester.tcl.in 8253b44be88e2e3f21de95a65d3a90c2be8e70b7bdd08a5b80e337ba7402f8f1
F autoconf/tea/auto.def ce95b9450e2fa4ba5dc857e208fe10f4e6f2d737796ac3278aee6079db417529
F autoconf/tea/configure d0b12b984edca6030d1976375b80157ac78b5b90a5b4f0dcee39357f63f4a80b x
F autoconf/tea/configure 993eb27dafb35253965f9c0eb0eeefd113cae0508361c8fd90a4b58c3caf14ec x
F autoconf/tea/license.terms 13bd403c9610fd2b76ece0ab50c4c5eda933d523
F autoconf/tea/pkgIndex.tcl.in e07da6b94561f4aa382bab65b1ccceb04701b97bf59d007c1d1f20a222b22d07
F autoconf/tea/teaish.tcl 81feb417e718ed75cdd7e2fdf6771f3da80dae97377a90c4d5b62b3754abbf1d
F autoconf/tea/teaish.test.tcl cfe94e1fb79dd078f650295be59843d470125e0cc3a17a1414c1fb8d77f4aea6
F autosetup/LICENSE 41a26aebdd2cd185d1e2b210f71b7ce234496979f6b35aef2cbf6b80cbed4ce4
F autosetup/README.autosetup a78ff8c4a3d2636a4268736672a74bf14a82f42687fcf0631a70c516075c031e
F autosetup/README.md f324bb9f9bf1cc787122034df53fbfdfed28ee2657e6652b763d992ab0d04829
F autosetup/README.md ce0f95980a687bb861bd830b76bc4b48513567be5cf5ee7004f4f3439ffe3841
F autosetup/autosetup 74a9782b68d07934510190fbd03fc6ad92e63f0ea3b5cbffa5f0bd271ad60f01 x
F autosetup/autosetup-config.guess dfa101c5e8220e864d5e9c72a85e87110df60260d36cb951ad0a85d6d9eaa463 x
F autosetup/autosetup-config.sub a38fb074d0dece01cf919e9fb534a26011608aa8fa606490864295328526cd73 x
@@ -46,8 +46,8 @@ F autosetup/cc.tcl c0fcc50ca91deff8741e449ddad05bcd08268bc31177e613a6343bbd1fd3e
F autosetup/find_tclconfig.tcl e64886ffe3b982d4df42cd28ed91fe0b5940c2c5785e126c1821baf61bc86a7e
F autosetup/jimsh0.c 563b966c137a4ce3c9333e5196723b7ac0919140a9d7989eb440463cd855c367
F autosetup/pkg-config.tcl 4e635bf39022ff65e0d5434339dd41503ea48fc53822c9c5bde88b02d3d952ba
F autosetup/proj.tcl 6aac1eb3059fc511c8e1659f33b96eb2a216a371ed9b28be6661374061be9b15
F autosetup/sqlite-config.tcl 3177dedd7bd49465fa06677fd743c4966eee5702a9ddf4914c2c1af5e5972a52
F autosetup/proj.tcl ec30c4bc301b6e9eb937655744a7315f863f804fc66400d975bcf9352ac96a1d
F autosetup/sqlite-config.tcl f2d2cf0917a17068ab2897b2009e31a05a4481a0786cd6ea15f643fef325bbe3
F autosetup/system.tcl 51d4be76cd9a9074704b584e5c9cbba616202c8468cf9ba8a4f8294a7ab1dba9
F autosetup/teaish/README.txt b40071e6f8506500a2f7f71d5fc69e0bf87b9d7678dd9da1e5b4d0acbf40b1ca
F autosetup/teaish/core.tcl aee092fc71986d1272b835ea7492bb55ffc213a289502e4f14da80cf67b7e3c3
@@ -81,7 +81,7 @@ F ext/fts3/README.tokenizers b92bdeb8b46503f0dd301d364efc5ef59ef9fa8e2758b8e742f
F ext/fts3/README.txt 8c18f41574404623b76917b9da66fcb0ab38328d
F ext/fts3/fts3.c 4f02858ab845a97bedf06e6cc1fba49a81fe5e00a26df68d0ad0f00a5814fa70
F ext/fts3/fts3.h 3a10a0af180d502cecc50df77b1b22df142817fe
F ext/fts3/fts3Int.h d0f70d602be987501cf6eff86a06a0b5d0389929c6abe24972d59594e6f4cb03
F ext/fts3/fts3Int.h ed9b8bc5ed5be402069651e49d4855cb849af706cf3fe68548f58a2c21eefc7f
F ext/fts3/fts3_aux.c 7eab82a9cf0830f6551ba3abfdbe73ed39e322a4d3940ee82fbf723674ecd9f3
F ext/fts3/fts3_expr.c 5c13796638d8192c388777166075cdc8bc4b6712024cd5b72c31acdbefce5984
F ext/fts3/fts3_hash.c d9dba473741445789330c7513d4f65737c92df23c3212784312931641814672a
@@ -97,7 +97,7 @@ F ext/fts3/fts3_tokenizer.h 64c6ef6c5272c51ebe60fc607a896e84288fcbc3
F ext/fts3/fts3_tokenizer1.c c1de4ae28356ad98ccb8b2e3388a7fdcce7607b5523738c9afb6275dab765154
F ext/fts3/fts3_unicode.c de426ff05c1c2e7bce161cf6b706638419c3a1d9c2667de9cb9dc0458c18e226
F ext/fts3/fts3_unicode2.c 416eb7e1e81142703520d284b768ca2751d40e31fa912cae24ba74860532bf0f
F ext/fts3/fts3_write.c 4e967e31f34447b5e5a52583250cd22660cd5774c3ba3054d2eb6725f562b45f
F ext/fts3/fts3_write.c 2bee1c5828f6401adffd07ca64260aeb79d64138958273a56de8fa5e8759a0c1
F ext/fts3/fts3speed.tcl b54caf6a18d38174f1a6e84219950d85e98bb1e9
F ext/fts3/tool/fts3cov.sh c331d006359456cf6f8f953e37f2b9c7d568f3863f00bb5f7eb87fea4ac01b73
F ext/fts3/tool/fts3view.c 413c346399159df81f86c4928b7c4a455caab73bfbc8cd68f950f632e5751674
@@ -107,13 +107,13 @@ F ext/fts3/unicode/mkunicode.tcl cbf5f7b5c8ce8014bad731f246f2e520eece908465de477
F ext/fts3/unicode/parseunicode.tcl a981bd6466d12dd17967515801c3ff23f74a281be1a03cf1e6f52a6959fc77eb
F ext/fts5/extract_api_docs.tcl 009cf59c77afa86d137b0cca3e3b1a5efbe2264faa2df233f9a7aa8563926d15
F ext/fts5/fts5.h ff5d3cc88b29e41612bfb29eb723e29e38973de62ca75ba3e8f94ccb67f5b5f2
F ext/fts5/fts5Int.h cc1e6ed28e1fbde71e4427ba6d15b0c73a4f8f119adeb4f7bcc97e3336fbbeac
F ext/fts5/fts5Int.h 97f373ecedf024fa7bf23989c3e529132225c169e440fe1f48e9b28dfed05ddc
F ext/fts5/fts5_aux.c da4a7a9a11ec15c6df0699d908915a209bcde48f0b04101461316b59f71abffb
F ext/fts5/fts5_buffer.c f1e6d0324d7c55329d340673befc26681a372a4d36086caa8d1ec7d7c53066c7
F ext/fts5/fts5_config.c e7d8dd062b44a66cd77e5a0f74f23a2354cd1f3f8575afb967b2773c3384f7f8
F ext/fts5/fts5_expr.c be9e5f7f11d87e7bd3680832c93c13050fe351994b5052b0215c2ef40312c23a
F ext/fts5/fts5_hash.c a6266cedd801ab7964fa9e74ebcdda6d30ec6a96107fa24148ec6b7b5b80f6e0
F ext/fts5/fts5_index.c 1906bb292b65121aa7d88cabb2a486bea58de75c600271e5011fb86ccc2e427a
F ext/fts5/fts5_index.c 2a1be0fb3c1b185f84b08b8032ba332c82defa182ff125833c0fecba0a4938b0
F ext/fts5/fts5_main.c e558225168845dc708abeb2ad10415696e5a3249bcba1810ba3c7ef80764962e
F ext/fts5/fts5_storage.c 19bc7c4cbe1e6a2dd9849ef7d84b5ca1fcbf194cefc3e386b901e00e08bf05c2
F ext/fts5/fts5_tcl.c 7fb5a3d3404099075aaa2457307cb459bbc257c0de3dbd52b1e80a5b503e0329
@@ -162,12 +162,12 @@ F ext/fts5/test/fts5contentless4.test ec34dc69ef474ca9997dae6d91e072906e0e9a5a4b
F ext/fts5/test/fts5contentless5.test 38cd0392c730dc7090c550321ce3c24ba4c392bc97308b51a4180e9959dca7b5
F ext/fts5/test/fts5corrupt.test 237fce1c3261bb3a5bec333b0f0dbf5b105ec32627ef14cccbda3cfe13833193
F ext/fts5/test/fts5corrupt2.test 4a03a158c2cb617c9f76d26b35c1ef2534124bc0bbddcea38dfd5b170ebea27b
F ext/fts5/test/fts5corrupt3.test e4852b2472dd25556431fd48fe88e4d0c8cf3e18e010c5ea308345e1cdf97bd5
F ext/fts5/test/fts5corrupt3.test 43d6a836892d79ab738ab89b3b6f4ae46c07ee966193e4b357bbb14e7f81d5da
F ext/fts5/test/fts5corrupt4.test dc08d19f5b8943e95a7778a7d8da592042504faf18dd93f68f7d7a0d7d7dd733
F ext/fts5/test/fts5corrupt5.test 73985d4fe6d8f0d5d5c7bcf79ae7c6522c376cd6ad710a0ff2f26e0c2e222abe
F ext/fts5/test/fts5corrupt6.test 2d72db743db7b5d9c9a6d0cfef24d799ed1aa5e8192b66c40e871a37ed9eed06
F ext/fts5/test/fts5corrupt7.test 814aab492d7a09abb5bfdd81cc66fc206d7f3868f9a3bae91876e02efc466fb3
F ext/fts5/test/fts5corrupt8.test 7618b102b9b3a5a3494271f4975ab5837e2fb3f61f5adfcdeeb31772c859e6df
F ext/fts5/test/fts5corrupt8.test 0b10750caf8aa23fa1c379ca4caf6130d41454505e4d5315590f4061eedcbe44
F ext/fts5/test/fts5delete.test 2a5008f8b1174ef41d1974e606928c20e4f9da77d9f8347aed818994d89cced4
F ext/fts5/test/fts5detail.test 54015e9c43ec4ba542cfb93268abdf280e0300f350efd08ee411284b03595cc4
F ext/fts5/test/fts5determin.test 1b77879b2ae818b5b71c859e534ee334dac088b7cf3ff3bf76a2c82b1c788d11
@@ -197,11 +197,11 @@ F ext/fts5/test/fts5first.test bfd685b96905bf541d99d8644e0a7219d1d833455a08ab64e
F ext/fts5/test/fts5full.test 97d263c1072f4a560929cca31e70f65d2ae232610e17e6affcf7e979df59547b
F ext/fts5/test/fts5fuzz1.test 238d8c45f3b81342aa384de3e581ff2fa330bf922a7b69e484bbc06051a1080e
F ext/fts5/test/fts5hash.test fd3e0367fbf0b0944d6936fdb22696350f57b9871069c6766251578a103e8a14
F ext/fts5/test/fts5integrity.test 646796671205dae46af5bb12a49b5696483cfe8e12d71d21454940b13ace95ab
F ext/fts5/test/fts5integrity.test c423ce16fd1ccadcac7fc22f794226b2bb00f5a187c0ab1d9f8502521b1bae05
F ext/fts5/test/fts5integrity2.test 4c3636615c0201232c44a8105d5cb14fd5499fd0ee3014d7ffd7e83aac76ece8
F ext/fts5/test/fts5interrupt.test 20d04204d3e341b104c0c24a41596b6393a3a81eba1044c168db0e106f9ac92c
F ext/fts5/test/fts5lastrowid.test f36298a1fb9f988bde060a274a7ce638faa9c38a31400f8d2d27ea9373e0c4a1
F ext/fts5/test/fts5leftjoin.test c0b4cafb9661379e576dc4405c0891d8fcc2782680740513c4d1fc114b43d4ad
F ext/fts5/test/fts5leftjoin.test 1c14b51f4d1344a89e488160882f05a2246dd7e70c5cf077c8fb473e03c66338
F ext/fts5/test/fts5limits.test 8ab67cf5d311c124b6ceb0062d0297767176df4572d955fce79fa43004dff01c
F ext/fts5/test/fts5locale.test 83ba7ee12628b540d3098f39c39c1de0c0440eddff8f7512c8c698d0c4a3ae3c
F ext/fts5/test/fts5matchinfo.test bc9e74157773db7f00aec1e85587f1145956ebdf1672c136f0f04323b2752aa0
@@ -352,51 +352,6 @@ F ext/jni/src/org/sqlite/jni/wrapper1/WindowFunction.java c7d1452f9ff26175b3c19b
F ext/jni/src/tests/000-000-sanity.test c3427a0e0ac84d7cbe4c95fdc1cd4b61f9ddcf43443408f3000139478c4dc745
F ext/jni/src/tests/000-001-ignored.test e17e874c6ab3c437f1293d88093cf06286083b65bf162317f91bbfd92f961b70
F ext/jni/src/tests/900-001-fts.test bf0ce17a8d082773450e91f2388f5bbb2dfa316d0b676c313c637a91198090f0
F ext/lsm1/Makefile 851a8108af2f00d6086b7be8a76fe54eabe2dd4cfd4171fd39285c5b11bee90d
F ext/lsm1/Makefile.msc f8c878b467232226de288da320e1ac71c131f5ec91e08b21f502303347260013
F ext/lsm1/lsm-test/README 87ea529d2abe615e856d4714bfe8bb185e6c2771b8612aa6298588b7b43e6f86
F ext/lsm1/lsm-test/lsmtest.h cf58528ffe0cfe535e91b44584e2ec5fb1caacdabecef0d8dcf83bf83168bf28
F ext/lsm1/lsm-test/lsmtest1.c 54374fe88cee888c52c31160013c26184288f47a45b23d4d85390aa539733aab
F ext/lsm1/lsm-test/lsmtest2.c 188b09aec776516aeedcfd13b9c6faf85ba16b3671a0897a2c740ee00a5dc4f8
F ext/lsm1/lsm-test/lsmtest3.c 9ab87528a36dbf4a61d7c8ad954f5ee368c0878c127b84b942b2e2abe522de26
F ext/lsm1/lsm-test/lsmtest4.c d258d6a245db5d8eaede096e2368d23f859c5e92c80ab9122463f708514fe10c
F ext/lsm1/lsm-test/lsmtest5.c 8d5242a0f870d65eeada191c8945781fed9cb8ece3886573790ebd373b62dac5
F ext/lsm1/lsm-test/lsmtest6.c 869cb4a172cd07d1a75b3aeaecd61d0a477787b3b8668bad0d3ff0f43b642b7c
F ext/lsm1/lsm-test/lsmtest7.c 7a917455a0f956a8ed3f44f5c9387ec0ea6627714874464cc3fa5c5a9cabb2f2
F ext/lsm1/lsm-test/lsmtest8.c 773f226163d0f0d62701e3764d0c35fd4365faca74098bd63648bc57d6f14402
F ext/lsm1/lsm-test/lsmtest9.c 0a168757b757b106191acf43143dbbb5b2d76e57a3c8fd3018cecbaee1080aba
F ext/lsm1/lsm-test/lsmtest_bt.c 79b24bfd37e05fd626c35ec23bc5bb62d8a403afd66c710335384884dc1366d7
F ext/lsm1/lsm-test/lsmtest_datasource.c 5d770be191d0ca51315926723009b2c25c0b4b8136840494ef710ac324aa916c
F ext/lsm1/lsm-test/lsmtest_func.c 159aa401bc8032bfa3d8cf2977bd687abebab880255895a5eb45770d626fa38d
F ext/lsm1/lsm-test/lsmtest_io.c cf11b27b129c6bd5818fa1d440176502dc27229f0db892b4479118d61993ea20
F ext/lsm1/lsm-test/lsmtest_main.c a9bc647738c0dcaebf205d6d194b3ce4a6ef3925801cd2d919f0a4ea33a15aeb
F ext/lsm1/lsm-test/lsmtest_mem.c 4e63c764345ab1df59d4f13a77980c6f3643798210b10d6cdbd785b4b888fda5
F ext/lsm1/lsm-test/lsmtest_tdb.c 754b1ca8e1cfa7b29cbe2e4ab500f7eee0059033741b8d83267afe6f495a536d
F ext/lsm1/lsm-test/lsmtest_tdb.h 8733eee249b12956a9df8322994b43d19bd8c02ad2e8b0bb5164db4d6ccc1735
F ext/lsm1/lsm-test/lsmtest_tdb2.cc aebe50f2cb7a759214241938046fe5f00da66e4217637f946f436ca209776af9
F ext/lsm1/lsm-test/lsmtest_tdb3.c 7a7ccae189f5bb25bcd1ec3bbd740529706eded7f6729a5a0a9eeaeb57785320
F ext/lsm1/lsm-test/lsmtest_tdb4.c cbe230727b9413d244062943371af1421ace472ccb023b75af6540e0fa52b1bb
F ext/lsm1/lsm-test/lsmtest_util.c 241622db5a332a09c8e6e7606b617d288a37b557f7d3bce0bb97809f67cc2806
F ext/lsm1/lsm-test/lsmtest_win32.c 0e0a224674c4d3170631c41b026b56c7e1672b151f5261e1b4cc19068641da2d
F ext/lsm1/lsm.h 0f6f64ff071471cb87bf98beb8386566f30ea001
F ext/lsm1/lsmInt.h 8e4ead919951d700c2d065326b22c8bf055b7fec6e75514c6151b5bb5d9d3030
F ext/lsm1/lsm_ckpt.c 702a08e9fd92695976d759b259e2258330da99b3f8ac845f145e418cb70902ee
F ext/lsm1/lsm_file.c 4bbc4cb1a558089d884e1e5a17b021d9056ae62add32dd6906d070954c7fe954
F ext/lsm1/lsm_log.c 9450d193db7a50c96805f10f393ac8b08b2009b6330b7df7ae1e4b442ed219a7
F ext/lsm1/lsm_main.c 87770a9c7e73859fce7620cb79623776ba4b30369086229ad82c3e6eeaf45457
F ext/lsm1/lsm_mem.c 4c51ea9fa285ee6e35301b33491642d071740a0a
F ext/lsm1/lsm_mutex.c 378edf0a2b142b4f7640ee982df06d50b98788ea
F ext/lsm1/lsm_shared.c c67282a4f2c91e2a3362bdd40a81f9041cd587973ffc4bca8b8fbdab5470dee1
F ext/lsm1/lsm_sorted.c 1bae85469458793adf753f7c5e695d8d15e33f28bc0ca07ebc9f1b58e853c56c
F ext/lsm1/lsm_str.c 65e361b488c87b10bf3e5c0070b14ffc602cf84f094880bece77bbf6678bca82
F ext/lsm1/lsm_tree.c 682679d7ef2b8b6f2fe77aeb532c8d29695bca671c220b0abac77069de5fb9fb
F ext/lsm1/lsm_unix.c 11e0a5c19d754a4e1d93dfad06de8cc201f10f886b8e61a4c599ed34e334fc24
F ext/lsm1/lsm_varint.c fe134ad7b2db1ecd99b6a155d2f3625cfd497730e227ae18892452e457b73327
F ext/lsm1/lsm_vtab.c 0bc7d2702150e9d5513118f23fdb5d7f3642884e6c0dde332da08b016857887a
F ext/lsm1/lsm_win32.c 0a4acbd7e8d136dd3a5753f0a9e7a9802263a9d96cef3278cf120bcaa724db7c
F ext/lsm1/test/lsm1_common.tcl 5ed4bab07c93be2e4f300ebe46007ecf4b3e20bc5fbe1dedaf04a8774a6d8d82
F ext/lsm1/test/lsm1_simple.test a04d08e8661ae6fc53786c67f0bd102c6692f003e859dde03ed9ac3f12e066e5
F ext/lsm1/tool/mklsm1c.tcl f31561bbee5349f0a554d1ad7236ac1991fc09176626f529f6078e07335398b0
F ext/misc/README.md af13c3bf4405709eb1e2e1e3a39c3be6a15c3189ab8a0642bb107c6eb223b298
F ext/misc/amatch.c 2db45b1499b275d8340af6337a13d6216e4ceb2ddb41f4042b9801be7b5e593d
F ext/misc/anycollseq.c 5ffdfde9829eeac52219136ad6aa7cd9a4edb3b15f4f2532de52f4a22525eddb
@@ -407,8 +362,8 @@ F ext/misc/basexx.c 89ad6b76558efbceb627afd5e2ef1d84b2e96d9aaf9b7ecb20e3d00b51be
F ext/misc/blobio.c a867c4c4617f6ec223a307ebfe0eabb45e0992f74dd47722b96f3e631c0edb2a
F ext/misc/btreeinfo.c 8f5e6da2c82ec2f06ee0216e922370a436dafdbb06ffa7a552203515ff9e7ddf
F ext/misc/carray.c 34fac63770971611c5285de0a9f0ac67d504eaf66be891f637add9290f1c76a5
F ext/misc/carray.h 503209952ccf2431c7fd899ebb92bf46bf7635b38aace42ec8aa1b8d7b6e98a5
F ext/misc/cksumvfs.c 3a7931dd30667be6348af919f3f9e6188dfd7646b42af8e399a499b327f5bd63
F ext/misc/carray.h 4bef8af4e9ddda024f5540cc4d456c3e4a4a7624d6315edf85dce1ce8419beb8
F ext/misc/cksumvfs.c 9d7d0cf1a8893ac5d48922bfe9f3f217b4a61a6265f559263a02bb2001259913
F ext/misc/closure.c 5559daf1daf742228431db929d1aa86dd535a4224cc634a81d2fd0d1e6ad7839
F ext/misc/completion.c c3c8b3cc1293c34f04f8746a3adfbfedb43f00d113f8c984a1ed09433317e507
F ext/misc/compress.c 2c79a74330e0e0ba6cb3f7397f8ba5af12d46377ef5d3ee075e12dd8a6ed57f0
@@ -456,12 +411,12 @@ F ext/misc/uuid.c 5bb2264c1b64d163efa46509544fd7500cb8769cb7c16dd52052da8d961505
F ext/misc/vfslog.c 3932ab932eeb2601dbc4447cb14d445aaa9fbe43b863ef5f014401c3420afd20
F ext/misc/vfsstat.c 0b23c0a69a2b63dc0ef0af44f9c1fc977300c480a1f7a9814500369d8211f56e
F ext/misc/vfstrace.c 0e4b8b17ac0675ea90f6d168d8214687e06ca3efbc0060aad4814994d82b41fb
F ext/misc/vtablog.c a197addbbd1e267a5476274b74953e1b6f050e28516f0a5fe7d6382753165ee6
F ext/misc/vtablog.c 9f7e02e9e8de585f3bfb48405db36c2eb4b680a23a67d7a4b738dd20f6ad7aec
F ext/misc/vtshim.c e5bce24ab8c532f4fdc600148718fe1802cb6ed57417f1c1032d8961f72b0e8f
F ext/misc/wholenumber.c 0fa0c082676b7868bf2fa918e911133f2b349bcdceabd1198bba5f65b4fc0668
F ext/misc/windirent.h 02211ce51f3034c675f2dbf4d228194d51b3ee05734678bad5106fff6292e60c
F ext/misc/zipfile.c b62147ac4985eaac4e368d529b1f4f43ad6bc9ac13d6805d907fff3afdac64d3
F ext/misc/zorder.c b0ff58fa643afa1d846786d51ea8d5c4b6b35aa0254ab5a82617db92f3adda64
F ext/misc/zipfile.c 360cc8e0b13398a27abae2baa5d136462718994053ef918e86f4e2dd238657c7
F ext/misc/zorder.c bddff2e1b9661a90c95c2a9a9c7ecd8908afab5763256294dd12d609d4664eee
F ext/rbu/rbu.c 801450b24eaf14440d8fd20385aacc751d5c9d6123398df41b1b5aa804bf4ce8
F ext/rbu/rbu1.test 25870dd7db7eb5597e2b4d6e29e7a7e095abf332660f67d89959552ce8f8f255
F ext/rbu/rbu10.test 7c22caa32c2ff26983ca8320779a31495a6555737684af7aba3daaf762ef3363
@@ -539,7 +494,7 @@ F ext/repair/test/checkindex01.test b530f141413b587c9eb78ff734de6bb79bc3515c3350
F ext/repair/test/test.tcl 686d76d888dffd021f64260abf29a55c57b2cedfa7fc69150b42b1d6119aac3c
F ext/rtree/README 734aa36238bcd2dee91db5dba107d5fcbdb02396612811377a8ad50f1272b1c1
F ext/rtree/geopoly.c f0573d5109fdc658a180db0db6eec86ab2a1cf5ce58ec66cbf3356167ea757eb
F ext/rtree/rtree.c a1f04a2013bc8f982307760615d1cee591355ac4723c74c3761c128d5c6954ab
F ext/rtree/rtree.c 86967c5a501f895b9705366b8cd9c37f15a9ebdff770ceb719c7deeeb2c22b72
F ext/rtree/rtree.h 4a690463901cb5e6127cf05eb8e642f127012fd5003830dbc974eca5802d9412
F ext/rtree/rtree1.test e0608db762b2aadca0ecb6f97396cf66244490adc3ba88f2a292b27be3e1da3e
F ext/rtree/rtree2.test 9d9deddbb16fd0c30c36e6b4fdc3ee3132d765567f0f9432ee71e1303d32603d
@@ -557,7 +512,7 @@ F ext/rtree/rtreeD.test fe46aa7f012e137bd58294409b16c0d43976c3bb92c8f710481e577c
F ext/rtree/rtreeE.test e65d3fc625da1800b412fc8785817327d43ccfec5f5973912d8c9e471928caa9
F ext/rtree/rtreeF.test 81ffa7ef51c4e4618d497a57328c265bf576990c7070633b623b23cd450ed331
F ext/rtree/rtreeG.test 1b9ca6e3effb48f4161edaa463ddeaa8fca4b2526d084f9cbf5dbe4e0184939c
F ext/rtree/rtreeH.test 0885151ee8429242625600ae47142cca935332c70a06737f35af53a7bd7aaf90
F ext/rtree/rtreeH.test c304651ee87dbb60296366d2c802f3043c3d00506c79a5c85bd20f2c9274498b
F ext/rtree/rtreeI.test 608e77f7fde9be5a12eae316baef640fffaafcfa90a3d67443e78123e19c4ca4
F ext/rtree/rtreeJ.test 93227ccd4d6c328f5ac46a902b8880041509dd2d68f6ce71560f0d8ab5bb507a
F ext/rtree/rtree_perf.tcl 6c18c1f23cd48e0f948930c98dfdd37dfccb5195
@@ -594,6 +549,7 @@ F ext/session/sessionE.test b2010949c9d7415306f64e3c2072ddabc4b8250c98478d3c0c4d
F ext/session/sessionF.test d37ed800881e742c208df443537bf29aa49fd56eac520d0f0c6df3e6320f3401
F ext/session/sessionG.test 3efe388282d641b65485b5462e67851002cd91a282dc95b685d085eb8efdad0a
F ext/session/sessionH.test 71bbff6b1abb2c4ac62b84dee53273c37e0b21e5fde3aed80929403e091ef859
F ext/session/sessionI.test 11e7b6729fc942982a5104a40132f70a2e964d64d60dc5809b8206465af74822
F ext/session/session_common.tcl a31f537a929a695a852d241c9434f2847cadf329856401921139fbb03a5a7697
F ext/session/session_gen.test 942a0002df10da53c45b40b581cc3ed25e7ff42bda1e7ba497273dc2887aa8e6
F ext/session/session_speed_test.c dcf0ef58d76b70c8fbd9eab3be77cf9deb8bc1638fed8be518b62d6cbdef88b3
@@ -611,19 +567,19 @@ F ext/session/sessioninvert.test 9018f6a7387ac745084b6374c5e1aa14d648b372e6e1181
F ext/session/sessionmem.test f2a735db84a3e9e19f571033b725b0b2daf847f3f28b1da55a0c1a4e74f1de09
F ext/session/sessionnoact.test 4c7ae5c7d351cb5323bca62b6b095592ad24bd90a6713c178b62ab0063d23e19
F ext/session/sessionnoop.test a9366a36a95ef85f8a3687856ebef46983df399541174cb1ede2ee53b8011bc7
F ext/session/sessionnoop2.test de4672dce88464396ec9f30ed08c6c01643a69c53ae540fadbbf6d30642d64e8
F ext/session/sessionnoop2.test 5beecd3ffcfbc1ef199d3536e91cc3186b438d587531ff334b6b0fc9b7d8ef10
F ext/session/sessionrebase.test 702378bdcb5062f1106e74457beca8797d09c113a81768734a58b197b5b334e2
F ext/session/sessionrowid.test 85187c2f1b38861a5844868126f69f9ec62223a03449a98a80600a44396f7363
F ext/session/sessionsize.test 8fcf4685993c3dbaa46a24183940ab9f5aa9ed0d23e5fb63bfffbdb56134b795
F ext/session/sessionstat1.test 5e718d5888c0c49bbb33a7a4f816366db85f59f6a4f97544a806421b85dc2dec
F ext/session/sessionwor.test 6fd9a2256442cebde5b2284936ae9e0d54bde692d0f5fd009ecef8511f4cf3fc
F ext/session/sqlite3session.c 6b0877fe1ab832aa4b85eaca72606dfd1630a1363a1be7af10ee1042a5ec719e
F ext/session/sqlite3session.h 9bb1a6687b467764b35178dc29bbd2c57ab8cd3acdc8a62f088c34ad17e4fe2b
F ext/session/test_session.c 2ddff73ea368d827028c32851b291416e1008845832feb27b751d15e57e13cc3
F ext/session/sqlite3session.c 9205e6e8f389ea44a8118082ce3832374da92284a60e4fb3ea6b1b421f0dbc54
F ext/session/sqlite3session.h b81e8536ce4b83babafd700f4ff67017804b6c1d71df963b30d3972958e7f4a7
F ext/session/test_session.c 8766b5973a6323934cb51248f621c3dc87ad2a98f023c3cc280d79e7d78d36fb
F ext/wasm/EXPORTED_FUNCTIONS.fiddle.in 27450c8b8c70875a260aca55435ec927068b34cef801a96205adb81bdcefc65c
F ext/wasm/GNUmakefile a05bb1766f97c88cb42fbfe9e349c799c691f8ae0dc959e9d9469f0bcee89350
F ext/wasm/GNUmakefile 89e18d6e4783841a5236930b988df27e02317b3ac440a1a5571de4a79df3c8e7
F ext/wasm/README-dist.txt f01081a850ce38a56706af6b481e3a7878e24e42b314cfcd4b129f0f8427066a
F ext/wasm/README.md b89605f65661cf35bf034ff6d43e448cc169b8017fc105d498e33b81218b482c
F ext/wasm/README.md 66ace67ae98a45e4116f2ca5425b716887bcee4d64febee804ff6398e1ae9ec7
F ext/wasm/SQLTester/GNUmakefile e0794f676d55819951bbfae45cc5e8d7818dc460492dc317ce7f0d2eca15caff
F ext/wasm/SQLTester/SQLTester.mjs 66e1adc3d79467b68e3e40614fd42c1a577c7e219ec0985db966eded52a941e5
F ext/wasm/SQLTester/SQLTester.run.mjs 57f2adb33f43f2784abbf8026c1bfd049d8013af1998e7dcb8b50c89ffc332e0
@@ -633,25 +589,25 @@ F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-core 2bcbbfe3b95c043ed6037e2708a2ee078
F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-extras cb4fa8842c875b6ee99381523792975c5ebb7371bd27fbd1bd863a43c7f3505a
F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-see fb29e62082a658f0d81102488414d422c393c4b20cc2f685b216bc566237957b
F ext/wasm/api/EXPORTED_RUNTIME_METHODS.sqlite3-api 1ec3c73e7d66e95529c3c64ac3de2470b0e9e7fbf7a5b41261c367cf4f1b7287
F ext/wasm/api/README.md c64ec8e84449c069e0217706d9d7d31b3bd53627228b2ba0c3cddbdc2350ca66
F ext/wasm/api/extern-post-js.c-pp.js 3fcd904f1204685dea84e5ae90d8b7e65a1dcebab1e838386d8328b74cce46c9
F ext/wasm/api/README.md 7f029c5fe83b3493931d2fb915e2febd3536267d538a56408a6fef284ea38d29
F ext/wasm/api/extern-post-js.c-pp.js d8f5ffa354c790d89681d0a23594c02347d28046d60151bd598712fbdff6056c
F ext/wasm/api/extern-pre-js.js cc61c09c7a24a07dbecb4c352453c3985170cec12b4e7e7e7a4d11d43c5c8f41
F ext/wasm/api/post-js-footer.js 365405929f41ca0e6d389ed8a8da3f3c93e11d3ef43a90ae151e37fa9f75bf41
F ext/wasm/api/post-js-header.js 53740d824e5d9027eb1e6fd59e216abbd2136740ce260ea5f0699ff2acb0a701
F ext/wasm/api/pre-js.c-pp.js a614a2c82b12c4d96d8e3ba77330329efc53c4d56a8a7e60ade900f341866cfb
F ext/wasm/api/pre-js.c-pp.js 58f823de197e2c10d76179aa05410a593b7ae03e1ece983bb42ffd818e8857e1
F ext/wasm/api/sqlite3-api-cleanup.js 3ac1786e461ada63033143be8c3b00b26b939540661f3e839515bb92f2e35359
F ext/wasm/api/sqlite3-api-glue.c-pp.js 0b76510f3650053bac67ca8947cb6ab9d050ad2218118a2e7796dd37be832ffa
F ext/wasm/api/sqlite3-api-oo1.c-pp.js c68d6da0088c2527156fca9163a721abe08e7bd077b15404fd8d292f4612adc1
F ext/wasm/api/sqlite3-api-prologue.js 8708570165f5b4bce9a78ccd91bc9ddf8735970ac1c4d659e36c9a7d9a644bb4
F ext/wasm/api/sqlite3-api-worker1.c-pp.js f646a65257973b8c4481f8a6a216370b85644f23e64b126e7ae113570587c0ab
F ext/wasm/api/sqlite3-api-oo1.c-pp.js 852f2cd6acddbae487fc4f1c3ec952e6c1e2033aa4e6c7091d330d983c87c032
F ext/wasm/api/sqlite3-api-prologue.js 4f1c2a9dc9caf631907766e9872c27d11b255ccae779e8af01c7f8b932817214
F ext/wasm/api/sqlite3-api-worker1.c-pp.js 760191cd13416e6f5adfd9fcc8a97fed5645c9e0a5fbac213a2d4ce2d79a4334
F ext/wasm/api/sqlite3-license-version-header.js 0c807a421f0187e778dc1078f10d2994b915123c1223fe752b60afdcd1263f89
F ext/wasm/api/sqlite3-opfs-async-proxy.js 9654b565b346dc609b75d15337f20acfa7af7d9d558da1afeb9b6d8eaa404966
F ext/wasm/api/sqlite3-vfs-helper.c-pp.js 3f828cc66758acb40e9c5b4dcfd87fd478a14c8fb7f0630264e6c7fa0e57515d
F ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js 0f68a64e508598910e7c01214ae27d603dfc8baec6a184506fafac603a901931
F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js 4ab0704ee198de7d1059eccedc7703c931510b588d10af0ee36ea5b3ebbac284
F ext/wasm/api/sqlite3-vtab-helper.c-pp.js e809739d71e8b35dfe1b55d24d91f02d04239e6aef7ca1ea92a15a29e704f616
F ext/wasm/api/sqlite3-wasm.c d2672a83b99a89db6bab31eccf9f93fca15a01838d8b0224967db6d4c4bff560
F ext/wasm/api/sqlite3-worker1-promiser.c-pp.js bc65debfe43b81fc39fb25c40ad0cc1946bd82580fbf644351107b544d6177ee
F ext/wasm/api/sqlite3-wasm.c 292db8be42a6ba29a7df2cc2723553a47627853d7c1fdcf8fa37743cf5d85497
F ext/wasm/api/sqlite3-worker1-promiser.c-pp.js 4ad256b4ff7f839ad18931ed35d46cced544207bd2209665ec552e193f7f4544
F ext/wasm/api/sqlite3-worker1.c-pp.js 5e8706c2c4af2a57fbcdc02f4e7ef79869971bc21bb8ede777687786ce1c92d5
F ext/wasm/batch-runner-sahpool.html e9a38fdeb36a13eac7b50241dfe7ae066fe3f51f5c0b0151e7baee5fce0d07a7
F ext/wasm/batch-runner-sahpool.js 54a3ac228e6c4703fe72fb65c897e19156263a51fe9b7e21d2834a45e876aabd
@@ -661,8 +617,8 @@ F ext/wasm/c-pp.c cca55c5b55ebd8d29916adbedb0e40baa12caa9a2e8429f812683c308f9b0e
F ext/wasm/common/SqliteTestUtil.js 7adaeffef757d8708418dc9190f72df22367b531831775804b31598b44f6aa51
F ext/wasm/common/emscripten.css 11bd104b6c0d597c67d40cc8ecc0a60dae2b965151e3b6a37fa5708bac3acd15
F ext/wasm/common/testing.css e97549bab24126c24e0daabfe2de9bb478fb0a69fdb2ddd0a73a992c091aad6f
F ext/wasm/common/whwasmutil.js 5e7fe4a2547831e003356c201ca28d9a0d6a19ab1fe2c8f63f82464fecd2cef7
F ext/wasm/config.make.in 4bc43443f768a61efd43cf995a5e618f58ac9afc0936706014193537d82c41cb
F ext/wasm/common/whwasmutil.js ea50e847cf08c2a96694f87d00b49fb97ee5fe62c15439cc269c8e1d9ab74c0a
F ext/wasm/config.make.in c424ae1cc3c89274520ad312509d36c4daa34a3fce5d0c688e5f8f4365e1049a
F ext/wasm/demo-123-worker.html a0b58d9caef098a626a1a1db567076fca4245e8d60ba94557ede8684350a81ed
F ext/wasm/demo-123.html 8c70a412ce386bd3796534257935eb1e3ea5c581e5d5aea0490b8232e570a508
F ext/wasm/demo-123.js c7b3cca50c55841c381a9ca4f9396e5bbdc6114273d0b10a43e378e32e7be5bf
@@ -672,17 +628,17 @@ F ext/wasm/demo-worker1-promiser.c-pp.html 635cf90685805e21772a5f7a35d1ace80f98a
F ext/wasm/demo-worker1-promiser.c-pp.js af168699d3cab1c27ad2364ebe06cd49db300bdbf404e23b00d5742ed52816ba
F ext/wasm/demo-worker1.html 2c178c1890a2beb5a5fecb1453e796d067a4b8d3d2a04d65ca2eb1ab2c68ef5d
F ext/wasm/demo-worker1.js 08720227e98fa5b44761cf6e219269cee3e9dd0421d8d91459535da776950314
F ext/wasm/dist.make 92ef4ffe33022a50f92d602acabad10bd8dd91759f3eb7df27fc6d7d37072b96
F ext/wasm/dist.make 57f5da2f0de5a297b5a0bc39ffec736380050578240ab24d864c2ff1b3634a3b
F ext/wasm/example_extra_init.c 2347cd69d19d839ef4e5e77b7855103a7fe3ef2af86f2e8c95839afd8b05862f
F ext/wasm/fiddle.make c6d7a3d6cc03bb5f21acb295c1233820d0dbf5c6a89b28dc2e093edcc001c45a
F ext/wasm/fiddle/fiddle-worker.js 850e66fce39b89d59e161d1abac43a181a4caa89ddeea162765d660277cd84ce
F ext/wasm/fiddle/fiddle.js 2a2f27b4be2674f501fff61c4a09e44dcf2295731a26b5c28e439f3a573bd269
F ext/wasm/fiddle/index.html 7fcfb221165183bef0e05d5af9ceb79b527e799b1708ab05de0ec0eaebd5b7bf
F ext/wasm/fiddle.make ea505d11aa2a89551e1693ed4c71ee6a163364ca14f806dda295d0beb26ec0ea
F ext/wasm/fiddle/fiddle-worker.js 50d3edf54c0c0e3657e876724ec2c10069f55f3e40af20864d72f6f6e9ad00f8
F ext/wasm/fiddle/fiddle.js f0b96f978c7c77fea8d092aa79c77849ce111d7b1ba60ffba07675009682184e
F ext/wasm/fiddle/index.html 17c7d6b21f40fbf462162c4311b63d760b065e419d9f5a96534963b0e52af940
F ext/wasm/index-dist.html 56132399702b15d70c474c3f1952541e25cb0922942868f70daf188f024b3730
F ext/wasm/index.html bcaa00eca521b372a6a62c7e7b17a870b0fcdf3e418a5921df1fd61e5344080d
F ext/wasm/jaccwabyt/jaccwabyt.js 6e4f26d0edb5c2e7d381b7eff1924832a040a12274afab2d1e1789027e9f6c5c
F ext/wasm/jaccwabyt/jaccwabyt.md 1128e3563e7eff90b5a373395251fc76cb32386fad1fea6075b0f34a8f1b9bdf
F ext/wasm/mkwasmbuilds.c 5b096a3c9fdf6e67eb20329dc685f995e820248a67fa970633c2c8f49bf472ad
F ext/wasm/mkwasmbuilds.c cc66cfaf8673ece3c30ca7fe28f6111481090648098a143ea619a8820b8fbe82
F ext/wasm/module-symbols.html dc476b403369b26a1a23773e13b80f41b9a49f0825e81435fe3600a7cfbbe337
F ext/wasm/scratchpad-wasmfs.html a3d7388f3c4b263676b58b526846e9d02dfcb4014ff29d3a5040935286af5b96
F ext/wasm/scratchpad-wasmfs.mjs 66034b9256b218de59248aad796760a1584c1dd842231505895eff00dbd57c63
@@ -690,7 +646,7 @@ F ext/wasm/speedtest1-wasmfs.html 0e9d335a9b5b5fafe6e1bc8dc0f0ca7e22e6eb916682a2
F ext/wasm/speedtest1-wasmfs.mjs c77c7231338ed5c0e1ce16aa29106df8e5b5cf11a48319c49433490a8d3ded30
F ext/wasm/speedtest1-worker.html d24d1e06caf3dcd83430c8c3d87761ff7555fd06eaeaf2fc02ce49cf45f0d032
F ext/wasm/speedtest1-worker.js 95e549e13a4d35863a9a7fc66122b5f546c0130d3be7b06dfcc556eb66d24bde
F ext/wasm/speedtest1.html 217bf15d43065634a27a06dbd5c9a320f6da9932dbcdfc963d482bc2f99dbea9
F ext/wasm/speedtest1.html e2a0e0bd12243ca34b11235bf9f3c229f4574ea1125f2ecf2bf0589853d6f9c8
F ext/wasm/split-speedtest1-script.sh a3e271938d4d14ee49105eb05567c6a69ba4c1f1293583ad5af0cd3a3779e205 x
F ext/wasm/sql/000-mandelbrot.sql 775337a4b80938ac8146aedf88808282f04d02d983d82675bd63d9c2d97a15f0
F ext/wasm/sql/001-sudoku.sql 35b7cb7239ba5d5f193bc05ec379bcf66891bce6f2a5b3879f2f78d0917299b5
@@ -698,7 +654,7 @@ F ext/wasm/test-opfs-vfs.html 1f2d672f3f3fce810dfd48a8d56914aba22e45c6834e262555
F ext/wasm/test-opfs-vfs.js 1618670e466f424aa289859fe0ec8ded223e42e9e69b5c851f809baaaca1a00c
F ext/wasm/tester1-worker.html ebc4b820a128963afce328ecf63ab200bd923309eb939f4110510ab449e9814c
F ext/wasm/tester1.c-pp.html 1c1bc78b858af2019e663b1a31e76657b73dc24bede28ca92fbe917c3a972af2
F ext/wasm/tester1.c-pp.js 766a2ba51a2619d41a49be7c6a1ad014c1d23fc97b67496e4f103038203eb17d
F ext/wasm/tester1.c-pp.js 0abba4bd54f6b22adaadf836c04d3163399f7a8a490fd60f20daac5f9c42b47d
F ext/wasm/tests/opfs/concurrency/index.html 657578a6e9ce1e9b8be951549ed93a6a471f4520a99e5b545928668f4285fb5e
F ext/wasm/tests/opfs/concurrency/test.js d08889a5bb6e61937d0b8cbb78c9efbefbf65ad09f510589c779b7cc6a803a88
F ext/wasm/tests/opfs/concurrency/worker.js 0a8c1a3e6ebb38aabbee24f122693f1fb29d599948915c76906681bb7da1d3d2
@@ -707,9 +663,9 @@ F ext/wasm/tests/opfs/sahpool/digest.html 206d08a34dc8bd570b2581d3d9ab3ecad3201b
F ext/wasm/tests/opfs/sahpool/index.html be736567fd92d3ecb9754c145755037cbbd2bca01385e2732294b53f4c842328
F ext/wasm/tests/opfs/sahpool/sahpool-pausing.js f264925cfc82155de38cecb3d204c36e0f6991460fff0cb7c15079454679a4e2
F ext/wasm/tests/opfs/sahpool/sahpool-worker.js bd25a43fc2ab2d1bafd8f2854ad3943ef673f7c3be03e95ecf1612ff6e8e2a61
F ext/wasm/wasmfs.make 68999f5bd8c489239592d59a420f8c627c99169bbd6fa16a404751f757b9f702
F ext/wasm/wasmfs.make 411dd94b40406572caddf88392a1ccc4deed0f88d260516e59ca6e0c887ee861
F magic.txt 5ade0bc977aa135e79e3faaea894d5671b26107cc91e70783aa7dc83f22f3ba0
F main.mk 3ced12d068b22957f4e82a0b94a2c1d83b37dcf39c087263691267f7bfb39a84
F main.mk d865589aa95918787659459f7dddd0680f99034e7b111fc161035d736c670a47
F mptest/config01.test 3c6adcbc50b991866855f1977ff172eb6d901271
F mptest/config02.test 4415dfe36c48785f751e16e32c20b077c28ae504
F mptest/crash01.test 61e61469e257df0850df4293d7d4d6c2af301421
@@ -717,8 +673,8 @@ F mptest/crash02.subtest f4ef05adcd15d60e5d2bd654204f2c008b519df8
F mptest/mptest.c aa41ace6dbc5050d76b02548d3521e6bbccae4f0
F mptest/multiwrite01.test dab5c5f8f9534971efce679152c5146da265222d
F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b
F sqlite3.1 9e426a150af072be26b0661bcd54567692d979e99bc7daf55b22b952ff8e41a6
F sqlite3.pc.in 0977c03a4da7c4204bd60e784a0efb8d51a190448aba78a4e973fe7192bdaf03
F sqlite3.1 1b9c24374a85dfc7eb8fa7c4266ee0db4f9609cceecfc5481cd8307e5af04366
F sqlite3.pc.in e6dee284fba59ef500092fdc1843df3be8433323a3733c91da96690a50a5b398
F src/alter.c fc7bbbeb9e89c7124bf5772ce474b333b7bdc18d6e080763211a40fde69fb1da
F src/analyze.c 03bcfc083fc0cccaa9ded93604e1d4244ea245c17285d463ef6a60425fcb247d
F src/attach.c 9af61b63b10ee702b1594ecd24fb8cea0839cfdb6addee52fba26fa879f5db9d
@@ -726,17 +682,17 @@ F src/auth.c 54ab9c6c5803b47c0d45b76ce27eff22a03b4b1f767c5945a3a4eb13aa4c78dc
F src/backup.c 5c97e8023aab1ce14a42387eb3ae00ba5a0644569e3476f38661fa6f824c3523
F src/bitvec.c e242d4496774dfc88fa278177dd23b607dce369ccafb3f61b41638eea2c9b399
F src/btmutex.c 30dada73a819a1ef5b7583786370dce1842e12e1ad941e4d05ac29695528daea
F src/btree.c 81fb44041929a605e293185bd4091cb24c468a108afe8ba1d93a81a8823de47f
F src/btree.h 18e5e7b2124c23426a283523e5f31a4bff029131b795bb82391f9d2f3136fc50
F src/btree.c cb5b8ceb9baa02a63a2f83dec09c4153e1cfbdf9c2adef5c62c26d2160eeb067
F src/btree.h e823c46d87f63d904d735a24b76146d19f51f04445ea561f71cc3382fd1307f0
F src/btreeInt.h 9c0f9ea5c9b5f4dcaea18111d43efe95f2ac276cd86d770dce10fd99ccc93886
F src/build.c 67c1db4c5e89a8519fe9b6dafc287f6bc3627696b5b8536dc5e06db570d8c05f
F src/build.c 213a9d24c931ef4694564894cda8dac8dbeb1519d428fd2d7ae622ac357c05a5
F src/callback.c acae8c8dddda41ee85cfdf19b926eefe830f371069f8aadca3aa39adf5b1c859
F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e
F src/date.c 9db4d604e699a73e10b8e85a44db074a1f04c0591a77e2abfd77703f50dce1e9
F src/dbpage.c b3e218f8ed74fcbb7fa805df8ca669a3718d397617b3d8a8aac3307dc315c4d6
F src/dbpage.c a6f7f16fde5656686b05705d41a4cb339db8262dc4d11699b7b40ba503db624e
F src/dbstat.c 73362c0df0f40ad5523a6f5501224959d0976757b511299bf892313e79d14f5c
F src/delete.c 03a77ba20e54f0f42ebd8eddf15411ed6bdb06a2c472ac4b6b336521bf7cea42
F src/expr.c dbb55f616dc6e5ad3507bb62ef609a48aaf1f909e40d6878d57d7626213933c5
F src/expr.c 0cad74107489c688449d7fec47b605c61a75c6da707031dfc4c76d1ac75667b3
F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007
F src/fkey.c 928ed2517e8732113d2b9821aa37af639688d752f4ea9ac6e0e393d713eeb76f
F src/func.c de47a8295503aa130baae5e6d9868ecf4f7c4dbffa65d83ad1f70bdbac0ee2d6
@@ -749,7 +705,7 @@ F src/insert.c dfd311b0ac2d4f6359e62013db67799757f4d2cc56cca5c10f4888acfbbfa3fd
F src/json.c cb87977b1ee25ee7d27505d65a9261b687395bf895342c8ba566b7c01aee2047
F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa
F src/loadext.c d7edd8e671237539d795d30daaf888908a2c82e99bade4c78f3be021e8b7d655
F src/main.c eb46066bf2f0bec2dd89229572de5a9c479c47da134e2422e7a0056e9510cbee
F src/main.c 458e79da86c957a094c1c256136af43e7dfec2c58475ee9cbbda4dc202005021
F src/malloc.c 410e570b30c26cc36e3372577df50f7a96ee3eed5b2b161c6b6b48773c650c5e
F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645
F src/mem1.c 3bb59158c38e05f6270e761a9f435bf19827a264c13d1631c58b84bdc96d73b2
@@ -770,33 +726,33 @@ F src/os.h 1ff5ae51d339d0e30d8a9d814f4b8f8e448169304d83a7ed9db66a65732f3e63
F src/os_common.h 6c0eb8dd40ef3e12fe585a13e709710267a258e2c8dd1c40b1948a1d14582e06
F src/os_kv.c 4d39e1f1c180b11162c6dc4aa8ad34053873a639bac6baae23272fc03349986a
F src/os_setup.h 6011ad7af5db4e05155f385eb3a9b4470688de6f65d6166b8956e58a3d872107
F src/os_unix.c 04e054ab86d86a7be99ebe5265922687791a40df5afc781d059beb47f4a40acd
F src/os_win.c b8d3cfdf2f40e2f9715b7d8df64f3c0c7ee18743a2dd0c4fc70c1d57fa1aadc7
F src/os_unix.c b3da55bc4bb214b2bfb1e430b10e9d3ebcf6b11741921ab044c9b9539c8fcc4f
F src/os_win.c f81a7cffdfe8c593a840895b3f64290714f0186b06302d2c397012252d830374
F src/os_win.h 4c247cdb6d407c75186c94a1e84d5a22cbae4adcec93fcae8d2bc1f956fd1f19
F src/pager.c 23c0f17deb892da6b32fef1f465507df7ab5cd01d774288cb43695658a649259
F src/pager.c ee48e0cc9ae4abfd7c37b838bff62a14d520a9fa311007fa57929ac7cc5d609c
F src/pager.h 6137149346e6c8a3ddc1eeb40aee46381e9bc8b0fcc6dda8a1efde993c2275b8
F src/parse.y e426d7323311554c75b0aebc426d0fe3c88d9777ffefed236f343ad9e661dc4c
F src/parse.y 619c3e92a54686c5e47923688c4b9bf7ec534a4690db5677acc28b299c403250
F src/pcache.c 588cc3c5ccaaadde689ed35ce5c5c891a1f7b1f4d1f56f6cf0143b74d8ee6484
F src/pcache.h 1497ce1b823cf00094bb0cf3bac37b345937e6f910890c626b16512316d3abf5
F src/pcache1.c 131ca0daf4e66b4608d2945ae76d6ed90de3f60539afbd5ef9ec65667a5f2fcd
F src/pragma.c 30b535d0a66348df844ee36f890617b4cf45e9a22dcbc47ec3ca92909c50aaf1
F src/prepare.c 1832be043fce7d489959aae6f994c452d023914714c4d5457beaed51c0f3d126
F src/printf.c 71b6d3a0093bf23f473e25480ca0024e8962681506c75f4ffd3d343a3f0ab113
F src/pragma.c 20847ce727fa0efe64de13f54427d44d25df7a00c806f198463dc37041aeeed0
F src/prepare.c 2af0b5c1ec787c8eebd21baa9d79caf4a4dc3a18e76ce2edbf2027d706bca37a
F src/printf.c 5f0c957af9699e849d786e8fbaa3baab648ca5612230dc17916434c14bc8698f
F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c
F src/resolve.c d40fe18d7c2fd0339f5846ffcf7d6809866e380acdf14c76fb2af87e9fe13f64
F src/resolve.c f8d1d011aba0964ff1bdccd049d4d2c2fec217efd90d202a4bb775e926b2c25d
F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97
F src/select.c 882d739e0d5e6c7a8b46a3cca3ada37fe1a56301f1360d6b141312c666bbe482
F src/shell.c.in 550ca8a09f8ac55203e69aae34e429b79d92cb44edf7419d8f3dd88eefab5d39
F src/sqlite.h.in 5c54f2461a1ea529bab8499148a2b238e2d4bb571d59e8ea5322d0c190abb693
F src/select.c b95181711d59c36d9789e67f76c4cfec64b99f9629a50be5e6566e117b87d957
F src/shell.c.in 51c8452b3e6b9a0dfa3df853dd16f147e5e4ae2002deb775cf8a2fccf01c3c6c
F src/sqlite.h.in 79dd3963888543f3120536608bf51024c93c7eb163a255098ffd569710189781
F src/sqlite3.rc 015537e6ac1eec6c7050e17b616c2ffe6f70fca241835a84a4f0d5937383c479
F src/sqlite3ext.h 0bfd049bb2088cc44c2ad54f2079d1c6e43091a4e1ce8868779b75f6c1484f1e
F src/sqliteInt.h 005542f8760edf9b62f014abccb876cf64533b64475a40a89402054d62535288
F src/sqliteLimit.h 6d817c28a8f19af95e6f4921933b7fbbca48a962bce0eb0ec81e8bb3ef38e68b
F src/sqliteInt.h 27c73e48878d31ef230ba867d1f8c3af6aed357fd93ccc605d3f1aae007ea62b
F src/sqliteLimit.h fe70bd8983e5d317a264f2ea97473b359faf3ebb0827877a76813f5cf0cdc364
F src/status.c 0e72e4f6be6ccfde2488eb63210297e75f569f3ce9920f6c3d77590ec6ce5ffd
F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1
F src/tclsqlite.c 3c604c49e6cf4211960a9ddb9505280fd22cde32175f40884c641c0f5a286036
F src/tclsqlite.h 65e2c761446e1c9fa0342b7d2612a703483643c8b6a316d12a65b745a4727395
F src/test1.c 13cc07851f989141b29f7ca3c6c90f6d18f90081ab423c66716c8cb29d277d1f
F src/tclsqlite.h 614b3780a62522bc9f8f2b9fb22689e8009958e7aa77e572d0f3149050af348a
F src/test1.c 82d8aab7162a758d030728cab6ae6011785234854b7d6d2aebd877f985d1016a
F src/test2.c 62f0830958f9075692c29c6de51b495ae8969e1bef85f239ffcd9ba5fb44a5ff
F src/test3.c 432646f581d8af1bb495e58fc98234380250954f5d5535e507fc785eccc3987a
F src/test4.c 0ac87fc13cdb334ab3a71823f99b6c32a6bebe5d603cd6a71d84c823d43a25a0
@@ -844,33 +800,33 @@ F src/test_vfs.c b4135c1308516adf0dfd494e6d6c33114e03732be899eace0502919b674586b
F src/test_window.c 6d80e11fba89a1796525e6f0048ff0c7789aa2c6b0b11c80827dc1437bd8ea72
F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9
F src/threads.c 4ae07fa022a3dc7c5beb373cf744a85d3c5c6c3c
F src/tokenize.c 3e37ac2b6cbb9b0abe33827b0153c27595269afd7152b48019808974481aca2c
F src/treeview.c d85ce76e6d1498d781957c07cb234da6d77ce0ed2d196480d516f54dabc62279
F src/trigger.c 3ffb8ed6b64dbcc0ccae6e82435d01be3bf547e13b814e2d46f7df9bef84748e
F src/tokenize.c 8400646d2830afc2f2dc465a75e3a92e4bedeea623f19dbd79c0c12d0dd6dda2
F src/treeview.c 3ce7ac9835d2d70cc1c868b01b747ae8a062322e155701e58e3d62ca79aada7a
F src/trigger.c d5cf2541ff048f30b6a0507eb3d1ec4e695c53584e3b2298a5bf248714fe185e
F src/update.c 3e5e7ff66fa19ebe4d1b113d480639a24cc1175adbefabbd1a948a07f28e37cf
F src/upsert.c 215328c3f91623c520ec8672c44323553f12caeb4f01b1090ebdca99fdf7b4f1
F src/utf.c 7267c3fb9e2467020507601af3354c2446c61f444387e094c779dccd5ca62165
F src/util.c 36fb1150062957280777655976f3f9a75db236cb8207a0770ceae8d5ec17fcd3
F src/vacuum.c 1bacdd0a81d2b5dc1c508fbf0d938c89fa78dd8d5b46ec92686d44030d4f4789
F src/vdbe.c 7e29623ca387880b8893e69135a0ff240c3dcaf0710f7a46a5f95b062cf93883
F src/vdbe.h 93761ed7c6b8bc19524912fd9b9b587d41bf4f1d0ade650a00dadc10518d8958
F src/vdbeInt.h 0bc581a9763be385e3af715e8c0a503ba8422c2b7074922faf4bb0d6ae31b15e
F src/vdbe.c 07084aa0152c8d4e74e7b86c0cf744732f0f9b1fd62bd7098252cadb741c630a
F src/vdbe.h ea1f1b52f0efe422f80d88da3c57e4eadc72856e29a22f1ff08e502ec6ba5f08
F src/vdbeInt.h 52896dd4d5b62190c53db14b09fc2484434eb594c963df0fa66eb8a94527b02e
F src/vdbeapi.c f9a4881a9674fec3fa13da35044a1484d3c4b95f9ec891cc8ffb02ef2b7a41df
F src/vdbeaux.c fd2c6b19a8892c31a2adc719f156f313560f9cc490cdbd04ff08fdae5d7aedb7
F src/vdbeblob.c b1b4032cac46b41e44b957c4d00aee9851f862dfd85ecb68116ba49884b03dfd
F src/vdbeaux.c b701e5920fe74b907eb8211d1f63fef96adc65dfd6e1ad6ed0843c71d8c65205
F src/vdbeblob.c b3f0640db9642fbdc88bd6ebcc83d6009514cafc98f062f675f2c8d505d82692
F src/vdbemem.c e67d9c6484d868c879d20c70d00bf4a9058082f1d4058607ca15d50eb3aebc21
F src/vdbesort.c cb6f472e83ca12c46aa7de0ac0a9d11458b357986f2617a1c90dfb19a542ecbe
F src/vdbetrace.c fe0bc29ebd4e02c8bc5c1945f1d2e6be5927ec12c06d89b03ef2a4def34bf823
F src/vdbevtab.c fc46b9cbd759dc013f0b3724549cc0d71379183c667df3a5988f7e2f1bd485f3
F src/vtab.c 828221bdbeaaa6d62126ee6d07fd4ec0d09dcaea846f87ad01944d8b7e548859
F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9
F src/wal.c 20be6f0a25a80b7897cf2a5369bfd37ef198e6f0b6cdef16d83eee856056b159
F src/vxworks.h 9d18819c5235b49c2340a8a4d48195ec5d5afb637b152406de95a9436beeaeab
F src/wal.c a278339ecf5f194fd71fff1f0da1368de50e3a32edc3e9944e1ee1f4610476ff
F src/wal.h ba252daaa94f889f4b2c17c027e823d9be47ce39da1d3799886bbd51f0490452
F src/walker.c d5006d6b005e4ea7302ad390957a8d41ed83faa177e412f89bc5600a7462a014
F src/where.c a99fa3061a0155d2cb0e2c91df76dbf834750272a8d79ec5e2dce3ed4e6abad6
F src/whereInt.h 02b646ea41a8342815b3628f8064c32618ea2e0f20b83216ea08cad11f0ac5aa
F src/wherecode.c 9710e62379c000189476404f923d4d1b192d0def222fdd287b820cc085a0d555
F src/whereexpr.c 566ca4382e07a4ba1fd86c97ae0781cdf84004c7d9c59466bf5db75733548807
F src/where.c f2f075bd17065922235632feb368efe92a7f03d42797eb575267574fbf6d4218
F src/whereInt.h 8d94cb116c9e06205c3d5ac87af065fc044f8cf08bfdccd94b6ea1c1308e65da
F src/wherecode.c 71c5c6804b7f882dec8ec858758accae02fcfca13df3cc720f1f258e663ec7c5
F src/whereexpr.c 403a44eeec1a0f0914fccc6a59376b6924bc00ef6728fe6ffce4cf3051b320fc
F src/window.c d01227141f622f24fbe36ca105fbe6ef023f9fd98f1ccd65da95f88886565db5
F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2
F test/affinity2.test 4d7a34d328e58ca2a2d78fd76c27614a41ca7ddf4312ded9c68c04f430b3b47d
@@ -878,7 +834,7 @@ F test/affinity3.test 9b7d1133e11d5edd7805573c4ab6f3ba73b0b74a1f280d5b130d4bf350
F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
F test/aggfault.test 777f269d0da5b0c2524c7ff6d99ae9a93db4f1b1839a914dd2a12e3035c29829
F test/aggnested.test 610b0ce2c3e8f3daee25f9752800ee8d785db10da4aa1fbeea0ea1aabaf1d704
F test/aggorderby.test cc3abf5de64d46ff66395ca8c2346b66c2576d5aedb7bffc5b0742508856e3bf
F test/aggorderby.test 7be65e743f82ee49ba62da1c799e59341d23884a99edfe093df0cdfaac94cbbb
F test/alias.test 4529fbc152f190268a15f9384a5651bbbabc9d87
F test/all.test cf929f721e20960ca9db89471fa44f9176322ba8f25e97193f91881c223643b3
F test/alter.test 3c00eff1e2036b9f93e9cd0f3d3e63750ac87ecb5bc71b9d7bd07cbf2ac4c494
@@ -898,8 +854,8 @@ F test/altermalloc2.test 17fb3724c4b004c469c27dc4ef181608aa644555fbd3f3236767584
F test/altermalloc3.test 8040e486368403f2fdd6fc3998258b499bd4cc2f3ddbb5f8f874cd436f076e81
F test/alterqf.test 8ec03d776de9c391daa0078ea8f838903bdcfb11dfae4ba3576b48436834ccba
F test/altertab.test 8a2712f9076da5012a002d0b5cc0a421398a5bf61c25bab41b77c427586a7a27
F test/altertab2.test 4bad0fa9b1ad6e62d07bc2ddb0807fb98ba80ee06d6593db2e514ec1821cae3a
F test/altertab3.test b331ae34e69594e19605e3297805202d6156fcc8f75379dfd972a2e51cae8721
F test/altertab2.test 0889ba0700cc1cdb7bc7d25975aa61fece34f621de963d0886e2395716b38576
F test/altertab3.test 471b8898d10bbc6488db9c23dc76811f405de6707d2d342b1b8b6fd1f13cd3c8
F test/altertrig.test aacc980b657354fe2d3d4d3a004f07d04ccc1a93e5ef82d68a79088c274ddc6b
F test/amatch1.test b5ae7065f042b7f4c1c922933f4700add50cdb9f
F test/analyze.test 2fb21d7d64748636384e6cb8998dbf83968caf644c07fcb4f76c18f2e7ede94b
@@ -962,9 +918,10 @@ F test/bestindex8.test b63a4f171a2c83d481bb14c431a8b72e85d27b2ffdaa0435a95d58ca9
F test/bestindex9.test 1a4b93db117fd8abe74ae9be982f86aa72f01e60cd4ac541e6ede39673a451a0
F test/bestindexA.test e1b5def6b190797cacf008e6815ffb78fb30261999030d60a728d572eef44c7f
F test/bestindexB.test 328b97b69cd1a20928d5997f9ecb04d2e00f1d18e19ab27f9e9adb44d7bc51ce
F test/bestindexC.test 2df6ada16d8f00d9bb6a9664d9c323560aeed0e0ebc7a32b99d85d70037fd250
F test/bestindexC.test 95b4a527b1a5d07951d731604a6d4cf7e5a806b39cea0e7819d4c9667e11c3fc
F test/bestindexD.test 6a8f6f84990bcf17dfa59652a1f935beddb7afd96f8302830fbc86b0a13df3c3
F test/between.test b9a65fb065391980119e8a781a7409d3fcf059d89968279c750e190a9a1d5263
F test/bestindexE.test f0c7105d1e7facaa8f5e6c498849cc6dcadd533b35ea9e5e1176e54a9a2d70f1
F test/between.test e7587149796101cbe8d5f8abae8d2a7b87f04d8226610aa1091615005dcf4d54
F test/bigfile.test aa74f4e5db51c8e54a1d9de9fa65d01d1eb20b59
F test/bigfile2.test 1b489a3a39ae90c7f027b79110d6b4e1dbc71bfc
F test/bigmmap.test 6021e205487347c6d7e5a541aa472a4b8efc4e9f4a3799a823b61a8e6616105d
@@ -1006,7 +963,7 @@ F test/changes2.test 07949edcc732af28cb54276bfb7d99723bccc1e905a423648bf57ac5cb0
F test/check.test 3a7972ccbaad80d496833da8714d69d9d5d4ce9e7211af1cd2a06ae488a7de12
F test/checkfault.test da6cb3d50247169efcb20bdf57863a3ccfa1d27d9e55cd324f0680096970f014
F test/chunksize.test faea11c5d6df9d392252a8dd879e1b1d68c9d3e8b7909cbed8bcec3b60c706f1
F test/cksumvfs.test 6f05dc95847c06a3dc10eee6b5ab1351d78314a52d0db15717c9388f4cb96646
F test/cksumvfs.test 38748166f486c59e8d94f3ee705040031ed3790a4dd69c4a9eef64f623a30ad4
F test/close.test eccbad8ecd611d974cbf47278c3d4e5874faf02d811338d5d348af42d56d647c
F test/closure01.test 9905883f1b171a4638f98fc764879f154e214a306d3d8daf412a15e7f3a9b1e0
F test/coalesce.test cee0dccb9fbd2d494b77234bccf9dc6c6786eb91
@@ -1131,7 +1088,7 @@ F test/enc.test b5503a87b31cea8a5084c6e447383f9ca08933bd2f29d97b6b6201081b2343eb
F test/enc2.test 872afe58db772e7dfa1ad8e0759f8cc820e9efc8172d460fae83023101c2e435
F test/enc3.test 55ef64416d72975c66167310a51dc9fc544ba3ae4858b8d5ab22f4cb6500b087
F test/enc4.test c8f1ce3618508fd0909945beb8b8831feef2c020
F test/eqp.test 82f221e8cd588434d7f3bba9a0f4c78cbe7a541615a41632e12f50608bfb4a99
F test/eqp.test 746db9fe11629a0d00328e1721cc2a2e4726d574b677ab14de35fd914f54cc82
F test/eqp2.test 6e8996148de88f0e7670491e92e712a2920a369b4406f21a27c3c9b6a46b68dd
F test/errmsg.test eae9f091eb39ce7e20305de45d8e5d115b68fa856fba4ea6757b6ca3705ff7f9
F test/errofst1.test 6da78363739ba8991f498396ab331b5d64e7ab5c4172c12b5884683ef523ac53
@@ -1140,6 +1097,9 @@ F test/exclusive.test 7ff63be7503990921838d5c9f77f6e33e68e48ed1a9d48cd28745bf650
F test/exclusive2.test cd70b1d9c6fffd336f9795b711dcc5d9ceba133ad3f7001da3fda63615bdc91e
F test/exec.test e949714dc127eaa5ecc7d723efec1ec27118fdd7
F test/exists.test 79a75323c78f02bbe9c251ea502a092f9ef63dac
F test/existsexpr.test 9c4b77c4729281cc2ae63b9b460d0598ce28cc7876135e3e2c21629bbc8d077a
F test/existsexpr2.test dc23e76389eff3d29f6488ff733012a3560cd67ec8cfaecbecd52cced5d5af11
F test/existsfault.test ff41c11f3052c1bbd4f8dd557802310026253d67d7c4e3a180c16d2f0862973e
F test/expr.test 4ada8eb822c45ef27a36851a258004d43c1e95e7c82585a1217e732084e4482c
F test/expr2.test c27327ae9c017a7ff6280123f67aff496f912da74d78c888926d68b46ec75fd8
F test/exprfault.test da33606d799718e2f8e34efd0e5858884a1ad87f608774c552a7f5517cc27181
@@ -1187,6 +1147,7 @@ F test/fts3am.test 218aa6ba0dfc50c7c16b2022aac5c6be593d08d8
F test/fts3an.test a49ccadc07a2f7d646ec1b81bc09da2d85a85b18
F test/fts3ao.test 266989148fec6d9f1bb6c5382f7aa3dcea0e9cd444576e28dd2b9287ac7dd220
F test/fts3atoken.test dc2078ce464914efe3a8dfc545dd034a0fc14f2ab425c240471d5a5f1c721400
F test/fts3atoken2.test aa6664d26277064844ead962f5988c28b091c51b112f36d30fa33bd83fecf906
F test/fts3auto.test 649aa4c198d7acc5cd6355e19ee073d051c40d9e88a43fc3d88af46bdf3e99d5
F test/fts3aux1.test 1880eaa75c586cd10f53080479a2b819b3915ae7ce55c4e0ba8f1fe05ac0a6a7
F test/fts3aux2.test 2459e7fa3e22734aed237d1e2ae192f5541c4d8b218956ad2d90754977bf907f
@@ -1281,7 +1242,7 @@ F test/fuzz3.test 70ba57260364b83e964707b9d4b5625284239768ab907dd387c740c0370ce3
F test/fuzz4.test c229bcdb45518a89e1d208a21343e061503460ac69fae1539320a89f572eb634
F test/fuzz_common.tcl b7197de6ed1ee8250a4f82d67876f4561b42ee8cbbfc6160dcb66331bad3f830
F test/fuzz_malloc.test f348276e732e814802e39f042b1f6da6362a610af73a528d8f76898fde6b22f2
F test/fuzzcheck.c 19f8af47a5c4ee2c3943fdee270f1f14e3d83fe968a9737a7557fb4e3c06efc1
F test/fuzzcheck.c c2d8a1fd5762bc3bea337360cbd98f481137f533ae9db563a1e581dfbe2901ba
F test/fuzzdata1.db 3e86d9cf5aea68ddb8e27c02d7dfdaa226347426c7eb814918e4d95475bf8517
F test/fuzzdata2.db 128b3feeb78918d075c9b14b48610145a0dd4c8d6f1ca7c2870c7e425f5bf31f
F test/fuzzdata3.db c6586d3e3cef0fbc18108f9bb649aa77bfc38aba
@@ -1315,7 +1276,7 @@ F test/in7.test d9efdee00b074a60c6343993b2eda78bc369ab080dad864513c73f8aca89d566
F test/incrblob.test c9b96afc292aeff43d6687bcb09b0280aa599822
F test/incrblob2.test a494c9e848560039a23974b9119cfc2cf3ad3bd15cc2694ee6367ae537ef8f1f
F test/incrblob3.test 67621a04b3084113bf38ce03797d70eca012d9d8f948193b8f655df577b0da6f
F test/incrblob4.test 21a52a6843a56cdcce968c6a86b72a7066d0e6ba
F test/incrblob4.test a8d6b5ff04055fcec747a50b78485ebf4fcd80074e0b3cedbe952bde346da54a
F test/incrblob_err.test 89372a28f1d98254f03fed705f9efcd34ef61a674df16d2dbb4726944a2de5e9
F test/incrblobfault.test de274b1e329169c2c3438f9528994807ea8201ebf38ae9f157d34bf3ec0cc549
F test/incrcorrupt.test 6c567fbf870aa9e91866fe52ce6f200cd548939a
@@ -1376,6 +1337,7 @@ F test/joinD.test 2ce62e7353a0702ca5e70008faf319c1d4686aa19fba34275c6d1da0e960be
F test/joinE.test d5d182f3812771e2c0d97c9dcf5dbe4c41c8e21c82560e59358731c4a3981d6b
F test/joinF.test 53dd66158806823ea680dd7543b5406af151b5aafa5cd06a7f3231cd94938127
F test/joinH.test fd76024ff104baec16417db5cafc0894ad4e0863e70803e63c1bba0322706339
F test/joinI.test fc7d24a2b1e444979b83bd92c30ebb975cebb5b9eae4442ce94969bd8d083053
F test/journal1.test bc61a4228db11bffca118bd358ba4b868524bf080f3532749de6c539656e20fa
F test/journal2.test 9dac6b4ba0ca79c3b21446bbae993a462c2397c4
F test/journal3.test e5aeff93a7776cf644dbc48dec277655cff80a1cd24689036abc87869b120ea6
@@ -1387,7 +1349,7 @@ F test/json/json-generator.tcl dc0dd0f393800c98658fc4c47eaa6af29d4e17527380cd286
F test/json/json-q1.txt 65f9d1cdcc4cffa9823fb73ed936aae5658700cd001fde448f68bfb91c807307
F test/json/json-speed-check.sh 7d5898808ce7542762318306ae6075a30f5e7ee115c4a409f487e123afe91d88 x
F test/json/jsonb-q1.txt 1e180fe6491efab307e318b22879e3a736ac9a96539bbde7911a13ee5b33abc7
F test/json101.test 8237a484c256965eab1678fd950a32ac56325bb7d0dadbd095a46b0ddd95d62b
F test/json101.test cf53254f0f0c1399a01b21fc58fee0e63a12a556be91b9ee9faccdb8b82c083c
F test/json102.test 9b2e5ada10845ff84853b3feaae2ce51ce7145ae458f74c6a6cecc6ef6ee3ae1
F test/json103.test 355746a6b66aa438f214b4fae454b13068fad2444b5f693e0d538ad1c059b264
F test/json104.test 1b844a70cddcfa2e4cd81a5db0657b2e61e7f00868310f24f56a9ba0114348c1
@@ -1494,7 +1456,7 @@ F test/notify1.test 669b2b743618efdc18ca4b02f45423d5d2304abf
F test/notify2.test 2ecabaa1305083856b7c39cf32816b612740c161
F test/notify3.test 796c7b7157f55c93b4e672b724e9c923a6fc6aa72ac419379a623e2350472e22
F test/notnull.test a37b663d5bb728d66fc182016613fb8e4a0a4bbf3d75b8876a7527f7d4ed3f18
F test/notnull2.test 2ac7b4e04917148c7a1a9ed36df20150175ce942f07f5714375b29acbaca7106
F test/notnull2.test 5b7dd6e82c409b2d011ad6acf19ae4bf0816a9c69ccf600b529d7405d7c49874
F test/notnullfault.test fc4bb7845582a2b3db376001ef49118393b1b11abe0d24adb03db057ee2b73d5
F test/null.test b7ff206a1c60fe01aa2abd33ef9ea83c93727d993ca8a613de86e925c9f2bc6f
F test/nulls1.test 7a5e4346ee4285034100b4cd20e6784f16a9d6c927e44ecdf10034086bbee9c9
@@ -1529,12 +1491,12 @@ F test/pagerfault2.test caf4c7facb914fd3b03a17b31ae2b180c8d6ca1f
F test/pagerfault3.test 1003fcda009bf48a8e22a516e193b6ef0dd1bbd8
F test/pageropt.test 84e4cc5cbca285357f7906e99b21be4f2bf5abc0
F test/pagesize.test 5769fc62d8c890a83a503f67d47508dfdc543305
F test/parser1.test 6ccdf5e459a5dc4673d3273dc311a7e9742ca952dd0551a6a6320d27035ce4b3
F test/parser1.test 131f4733472252d53d8ed681115257866f55740ab697fa05900d766049348f27
F test/pcache.test c8acbedd3b6fd0f9a7ca887a83b11d24a007972b
F test/pcache2.test af7f3deb1a819f77a6d0d81534e97d1cf62cd442
F test/pendingrace.test e99efc5ab3584da3dfc8cd6a0ec4e5a42214820574f5ea24ee93f1d84655f463
F test/percentile.test 52ba89d6ee6b65f770972b67dace358bab7cdbd532803d3db157845268e789cd
F test/permutations.test 5260363b43b3fad4becb49b58d0b53e6024e1c18dc169b154d0b98db5630bbf2
F test/permutations.test e6de4f5777f7785737ac3d1d964b8656e5477a134665b2fe8a91884ab9b685b3
F test/pg_common.tcl 3b27542224db1e713ae387459b5d117c836a5f6e328846922993b6d2b7640d9f
F test/pragma.test 7d07b7bb76e273215d6a20c4f83c3062cc28976c737ccb70a686025801e86c8f
F test/pragma2.test e5d5c176360c321344249354c0c16aec46214c9f
@@ -1565,6 +1527,7 @@ F test/recover.test c76d05f33f0271fba0f0752170e03b0ab5952dc61dcea7ab3ba40df03c4c
F test/regexp1.test 8f2a8bc1569666e29a4cee6c1a666cd224eb6d50e2470d1dc1df995170f3e0f1
F test/regexp2.test 55ed41da802b0e284ac7e2fe944be3948f93ff25abbca0361a609acfed1368b5
F test/reindex.test cd9d6021729910ece82267b4f5e1b5ac2911a7566c43b43c176a6a4732e2118d
F test/reservebytes.test 6163640b5a5120c0dee6591481e673a0fa0bf0d12d4da7513bad692c1a49a162
F test/resetdb.test 54c06f18bc832ac6d6319e5ab23d5c8dd49fdbeec7c696d791682a8006bd5fc3
F test/resolver01.test f4022acafda7f4d40eca94dbf16bc5fc4ac30ceb
F test/returning1.test 212cd4111bb941a60abf608f20250db666c21eb1bc4d49217e96c87ff3ab9d1a
@@ -1576,7 +1539,7 @@ F test/round1.test 29c3c9039936ed024d672f003c4d35ee11c14c0acb75c5f7d6188ff16190c
F test/rowallock.test 3f88ec6819489d0b2341c7a7528ae17c053ab7cc
F test/rowhash.test 0bc1d31415e4575d10cacf31e1a66b5cc0f8be81
F test/rowid.test d27191b5ce794c05bf61081e8b2c546a1844c1641321dcaf7fb785234256cc8e
F test/rowvalue.test 9c873b2f6e7ce72b24ef133f93515c07a6a7dac4846a344ebc2af7b8bfdf5147
F test/rowvalue.test 93474d8e1c496e970bdcc3a7f54ac835adda667d2fd971957b4bce0c0b11707b
F test/rowvalue2.test 060d238b7e5639a7c5630cb5e63e311b44efef2b
F test/rowvalue3.test 103e9a224ca0548dd0d67e439f39c5dd16de4200221a333927372408c025324c
F test/rowvalue4.test bac9326d1e886656650f67c0ec484eb5f452244a8209c6af508e9a862ace08ed
@@ -1686,7 +1649,7 @@ F test/speed4p.explain 6b5f104ebeb34a038b2f714150f51d01143e59aa
F test/speed4p.test 377a0c48e5a92e0b11c1c5ebb1bc9d83a7312c922bc0cb05970ef5d6a96d1f0c
F test/speedtest.md ee958457ae1b729d9715ae33c0320600000bf1d9ddea1a88dcf79f56729d6fad
F test/speedtest.tcl 405411356fbc54af15987b7ffeec330a49138f71584220fb8fe1948b2f7ac907 x
F test/speedtest1.c 64b8804b053a796eab22f8b23fb181000f05d7b3e2aa44f022117ea543bc5a2a
F test/speedtest1.c a9b002a7bfed99ba3166c2a9b8ae45a95b4c2d37f891e1637c022f9e1d15e3f9
F test/spellfix.test 951a6405d49d1a23d6b78027d3877b4a33eeb8221dcab5704b499755bb4f552e
F test/spellfix2.test dfc8f519a3fc204cb2dfa8b4f29821ae90f6f8c3
F test/spellfix3.test 0f9efaaa502a0e0a09848028518a6fb096c8ad33
@@ -1733,8 +1696,9 @@ F test/temptable2.test 76821347810ecc88203e6ef0dd6897b6036ac788e9dd3e6b04fd4d163
F test/temptable3.test d11a0974e52b347e45ee54ef1923c91ed91e4637
F test/temptrigger.test 38f0ca479b1822d3117069e014daabcaacefffcc
F test/tester.tcl 463ae33b8bf75ac77451df19bd65e7c415c2e9891227c7c9e657d0a2d8e1074a
F test/testrunner.tcl 614c4a28f7f730acd7bec53e17d76602fb480e0d538b6ec548169e03a093f92d x
F test/testrunner_data.tcl 02dd645b647d907c959fbf232b7ff7d869c2ae430d5117443fc1e16a0d32243a
F test/testrunner.tcl b42f7736968cafc9e69bb5d0b87fc81b375fb4c3f44e19b472cccd91d41a416a x
F test/testrunner_data.tcl c507a9afa911c03446ed90442ffd4a98aca02882c3d51bd1177c24795674def8
F test/testrunner_estwork.tcl 7927a84327259a32854926f68a75292e33a61e7e052fdbfcb01f18696c99c724
F test/thread001.test a0985c117eab62c0c65526e9fa5d1360dd1cac5b03bde223902763274ce21899
F test/thread002.test c24c83408e35ba5a952a3638b7ac03ccdf1ce4409289c54a050ac4c5f1de7502
F test/thread003.test ee4c9efc3b86a6a2767516a37bd64251272560a7
@@ -1989,7 +1953,7 @@ F test/vtabC.test 4528f459a13136f982e75614d120aef165f17292
F test/vtabD.test 05b3f1d77117271671089e48719524b676842e96
F test/vtabE.test 2a143fe75a11275781d1fd1988d86b66a3f69cb98f4add62e3da8fd0f637b45f
F test/vtabF.test 1918844c7c902f6a16c8dacf1ec8f84886d6e78b
F test/vtabH.test a9417d92111629e2c33e0f3b06cc84bcd611753d0fc017b3ce6ae96572bc2f2f
F test/vtabH.test 3fe4c1cbc93a85971990f379116255e2d4f14b583be4d0b9cca67e90226041f1
F test/vtabI.test 751b07636700dbdea328e4265b6077ccd6811a3f
F test/vtabJ.test a6aef49d558af90fae10565b29501f82a95781cb4f797f2d13e2d19f9b6bc77b
F test/vtabK.test 13293177528fada1235c0112db0d187d754af1355c5a39371abd365104e3afbf
@@ -2014,6 +1978,7 @@ F test/wal_common.tcl 204d1721ac13c5e0c7fae6380315b5ab7f4e8423f580d826c5e9df1995
F test/walbak.test 018d4e5a3d45c6298d11b99f09a8ef6876527946
F test/walbig.test f437473a16cfb314867c6b5d1dbcd519e73e3434
F test/walblock.test 6bb472e82730e7e4e81395e907a01d8cfc2bd9e1f01f8a9184ca572e2955a4bf
F test/walckptnoop.test 5d40e7959a6ef4bdc7aaf773f86c8f210e2a1e6d0ca5c9ad1389311665741bef
F test/walcksum.test 50e204500eed9c691b6045e467bb2923f49aa93d8adf315e2be135fdb202c1c2
F test/walcrash.test 21038858cc552077b0522f50b0fa87e38139306a
F test/walcrash2.test a0edab4e5390f03b99a790de89aad15d6ec70b36
@@ -2110,7 +2075,7 @@ F test/without_rowid3.test 39ab0dd773eaa62e59b17093f875327630f54c4145458f6d2b053
F test/without_rowid4.test 4e08bcbaee0399f35d58b5581881e7a6243d458a
F test/without_rowid5.test f14298eb5ac8013894b75141c3f4f5f325a6ad0eded55516eef72c49e60a67cb
F test/without_rowid6.test efbd7add62c59bf5ca97bf8da674e734e6a70ef979234e816166824b4d258f68
F test/without_rowid7.test d7c59a93d726b55812d620f8f284e01904a5b85f9ee9eea8f2f68571a5e8c40e
F test/without_rowid7.test 747d3fbef7108d416d6416694b03d8ff046dc9cc82b3d911715feb472444b95a
F test/wordcount.c d721a4b6fae93e6e33449700bce1686bc23257c27425bc3ef1599dc912adec66
F test/writecrash.test 13520af28f376bfc8c0bcd130efc1fff20bb165198e8b94cf153f1f754154bb9
F test/zeroblob.test 7b74cefc7b281dfa2b07cd237987fbe94b4a2037a7771e9e83f2d5f608b1d99e
@@ -2152,7 +2117,7 @@ F tool/logest.c c34e5944318415de513d29a6098df247a9618c96d83c38d4abd88641fe46e669
F tool/max-limits.c cbb635fbb37ae4d05f240bfb5b5270bb63c54439
F tool/merge-test.tcl de76b62f2de2a92d4c1ca4f976bce0aea6899e0229e250479b229b2a1914b176
F tool/mkamalzip.tcl 8aa5ebe7973c8b8774062d34e15fea9815c4cc2ceea3a9b184695f005910876a
F tool/mkautoconfamal.sh 564378ae48cc8f4c8c68ef6d00228a0b2a70e2e3e4c67f26be1dd05d9730fefd
F tool/mkautoconfamal.sh cf72166369d9d1df9df1ae9fcad03a7939808d7273784b56fd78b913587637a1
F tool/mkccode.tcl c42a8f8cf78f92e83795d5447460dbce7aaf78a3bbf9082f1507dc71a3665f3c x
F tool/mkctimec.tcl 11c9eda4a8d18c74b79280b30506d832849fd1855e6d9e95e1fd506f1d211c37 x
F tool/mkkeywordhash.c 6b0be901c47f9ad42215fc995eb2f4384ac49213b1fba395102ec3e999acf559
@@ -2165,11 +2130,12 @@ F tool/mkshellc.tcl bab0a72a68384181a5706712dfdf6815f6526446d4e8aacace2de5e80cda
F tool/mksourceid.c 36aa8020014aed0836fd13c51d6dc9219b0df1761d6b5f58ff5b616211b079b9
F tool/mksqlite3c-noext.tcl 351c55256213154cabb051a3c870ef9f4487de905015141ae50dc7578a901b84
F tool/mksqlite3c.tcl f11b63445c4840509248bd4aa151a81aea25d5415fef71943c8d436eba4f3b3c
F tool/mksqlite3h.tcl 989948c6a26e188e673d7c2f2f093ea3acd816ad6ac65bab596280075c8f3a45
F tool/mksqlite3h.tcl 7b8de72c29b17b338acde81c389f3af04bf34fd25e96c5f29743d1dd285ed49e
F tool/mksqlite3internalh.tcl 46ef6ed6ccd3c36e23051109dd25085d8edef3887635cea25afa81c4adf4d4db
F tool/mksrczip.tcl 81efd9974dbb36005383f2cd655520057a2ae5aa85ac2441a80c7c28f803ac52
F tool/mktoolzip.tcl 34b4e92be544f820e2cc26f143f7d5aec511e826ec394cc82969a5dcf7c7a27c
F tool/mktoolzip.tcl c9f388b2b0751982aef29a0c1d80f7959dbe38065ebb4421c39844e92622b086
F tool/mkvsix.tcl 67b40996a50f985a573278eea32fc5a5eb6110bdf14d33f1d8086e48c69e540a
F tool/mkwinarm64ec.tcl 171f79234fa53552a129b360356df5599fdab15239caffb3d29c571292728033
F tool/offsets.c 8ed2b344d33f06e71366a9b93ccedaa38c096cc1dbd4c3c26ad08c6115285845
F tool/omittest-msvc.tcl d6b8f501ac1d7798c4126065030f89812379012cad98a1735d6d7221492abc08
F tool/omittest.tcl bec70ef0e16255c8d9eb06ecd7edf823c07a60a836186cdbce3528fb34b67995
@@ -2190,7 +2156,7 @@ F tool/spellsift.tcl 52b4b04dc4333c7ab024f09d9d66ed6b6f7c6eb00b38497a09f338fa55d
F tool/split-sqlite3c.tcl 4969fd642dad0ea483e4e104163021d92baf98f6a8eac981fe48525f9b873430
F tool/sqldiff.c 134be7866be19f8beb32043d5aea5657f01aaeae2df8d33d758ff722c78666b9
F tool/sqlite3_analyzer.c.in 14f02cb5ec3c264cd6107d1f1dad77092b1cf440fc196c30b69ae87b56a1a43b
F tool/sqlite3_rsync.c c1e1a737ebb458a4ccbbaa21e5eaa878448fef1aaa71b879b9a685785e28987f
F tool/sqlite3_rsync.c 0a47e601bdca0d300cbd53834bc59848b787bf3bfe3099b4eb27d08c81d571db
F tool/sqltclsh.c.in 1bcc2e9da58fadf17b0bf6a50e68c1159e602ce057210b655d50bad5aaaef898
F tool/sqltclsh.tcl 862f4cf1418df5e1315b5db3b5ebe88969e2a784525af5fbf9596592f14ed848
F tool/src-verify.c 6c655d9a8d6b30f3648fc78a79bf3838ed68f8543869d380c43ea9f17b3b8501
@@ -2208,8 +2174,8 @@ F tool/version-info.c 3b36468a90faf1bbd59c65fd0eb66522d9f941eedd364fabccd7227350
F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee87c1b31a7
F tool/warnings.sh 1ad0169b022b280bcaaf94a7fa231591be96b514230ab5c98fbf15cd7df842dd
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
P ebb346c5aa427b9e84a035278ee245d54810d9954efef12b898f2d7bc0ff630c
R debb7a97a27a2dab2543b88f76ae8cc2
U stephan
Z affb48d71da77c1ae112258e0a7a4bb5
P bb6114dbbf3bfbea57cd9be21666299663e94576b0175f6aeefd1d0f7107398e
R 014427910e7a9ddec7a51b8b4173351b
U drh
Z c33f9a334f3b1502222626b4f7b7e337
# Remove this line to create a well-formed Fossil manifest.
+2
View File
@@ -0,0 +1,2 @@
branch vxworks
tag vxworks
+1 -1
View File
@@ -1 +1 @@
73539fe0932494234b8f2293b0dbc1f0aac60a7d00fdaf4a59c2da654ce26f5b
8f45f1a9d9208fbf124c4087092718b83cd653126bc1ed5f388e3577561f615b
+1 -1
View File
@@ -140,7 +140,7 @@ continue prompt = " ...> "
o If the environment variable XDG_CONFIG_HOME is set then
.B ${XDG_CONFIG_HOME}/sqlite3/sqliterc
is checked, else
.B ~/.local/config/sqlite3/sqliterc
.B ~/.config/sqlite3/sqliterc
is checked. If the selected file does not exist then the fallback of
.B ~/.sqliterc
is used. It should generally only contain meta-commands.
+1 -1
View File
@@ -9,5 +9,5 @@ Name: SQLite
Description: SQL database engine
Version: @PACKAGE_VERSION@
Libs: -L${libdir} -lsqlite3
Libs.private: @LDFLAGS_MATH@ @LDFLAGS_ZLIB@ @LDFLAGS_ICU@
Libs.private: @LDFLAGS_MATH@ @LDFLAGS_ZLIB@ @LDFLAGS_DLOPEN@ @LDFLAGS_PTHREAD@ @LDFLAGS_ICU@
Cflags: -I${includedir}

Some files were not shown because too many files have changed in this diff Show More