Compare commits

...

590 Commits

Author SHA1 Message Date
drh ba76c160c7 Version 3.51.2
FossilOrigin-Name: b270f8339eb13b504d0b2ba154ebca966b7dde08e40c3ed7d559749818cb2075
2026-01-09 17:27:48 +00:00
dan f3e0993b9d To ensure that the sqlite3_hard_heap_limit() call it makes is effective, add "sqlite3_config(SQLITE_CONFIG_MEMSTATUS, 1);" to fuzzcheck.c.
FossilOrigin-Name: 10e11b9c539a8be50fd93bdf7cf5afe97d9757ce8577cac58426a1b218063e47
2026-01-09 16:21:26 +00:00
drh c51f318f6a Avoid signed integer overflow when an fts5 'merge' command is passed -2147483648 as a parameter.
FossilOrigin-Name: 127b3270f8716e0eda06ea6979def88283e15aecdceb5d56c82105b300c98bdc
2026-01-09 16:01:51 +00:00
drh 3a621d8a58 Fix potential OOB read on the undocumented test function rtreenode() in
the RTREE extension.

FossilOrigin-Name: f567ea96905ec58bb073b675e820ba505d3306338fdefd64bdd5cf965a3a9e88
2026-01-09 00:45:41 +00:00
drh b8c49d6f62 Fix yet another bug in the EXISTS-to-JOIN optimization.
FossilOrigin-Name: a23d3b50fd7c2013d83f868a3a4114880887ec8fb6e9917b43c243607caab67c
2026-01-03 15:22:08 +00:00
drh a303f7914d Ensure that loops created by the exists-to-join optimization use unique cursor numbers, even if the EXISTS expression in the WHERE clause is a copy of an expression from the result-set of the SELECT.
FossilOrigin-Name: d485e8fccc7cae338bd4cfe3e23d488926cf09a8c0ccc68b70446bbd8ceda652
2026-01-02 18:53:50 +00:00
drh 632632ced3 Use 64-bit integers to track memory allocation sizes in the CSV extension.
FossilOrigin-Name: 54398a2504a8a2ac47a461518df51406b29e63f1688f6ec108a41ac7b4b346f9
2025-12-31 18:46:13 +00:00
drh f8cae0b149 Update the autoconf tarball Makefile.msc to align with the canonical makefile.
FossilOrigin-Name: 390dfd6366a7e9a9b4c6454c0b281279d8fcf8ffdb14b8b4d945591cb37812bc
2025-12-31 11:00:51 +00:00
drh bc9cebcd1d Use sqlite3_malloc64() in all places in the compress.c extension to avoid
integer overflow.

FossilOrigin-Name: 15400ce39b83ebc384b5eb17eba87452b937c0b00117c1575a51c6e6139fe3b1
2025-12-31 10:59:40 +00:00
drh 2b0579b06b Fix a typo in check-in 0819fe670f9ceec7 that lead to incomplete protection against
buffer overflow in the zipfile extension.

FossilOrigin-Name: a3f135c0709b2ed2953d2e449107abc53b538b384bcd9bae5e370e3c9de8618a
2025-12-31 01:11:36 +00:00
drh 323199b57e Fix a memory leak in the fileio extension on windows. Other changes to
makefiles and similar to get zipfile testing working on Windows.

FossilOrigin-Name: 121b327f1f3941a9a44ab2d98e60f6e25b928ca9b54bbaa109239ba9012b3c3c
2025-12-19 23:47:07 +00:00
dan 67767084b6 Enhance the unixIsSharingShmNode() code (check-in [6385a1962c69c69c]) to avoid
possible deadlocks with threads in findResuableFd().

FossilOrigin-Name: f65aa46796068800905f6ff25efcb6338f864ce5bf8dcf6c7b9f5613b3973ab2
2025-12-15 14:56:57 +00:00
drh 55385fb79c Fix an incorrect answer that might arise if a scalar query is both
DISTINCT and contains an OFFSET clause.

FossilOrigin-Name: 35b306565a10c16737ee433728ca188852f01c12dfae0cc9212d21db932486fb
2025-12-09 13:29:08 +00:00
drh fced18af1a Increase the patch number to 3.51.2
FossilOrigin-Name: 58a2a8417f2e0baade43e4da1c74893ab991cfbb34e5e5767d82f201c0b0b389
2025-12-05 01:43:23 +00:00
drh 334fa0eb5a Ensure that the EXISTS-to-JOIN break happens even if the inner loop is
a "no-op" loop that never executes more than once because it is controlled
by a UNIQUE index.

FossilOrigin-Name: 0cf6211f0994474dc23ba5f38d2e6d0984360039798293eca757047e66d00c58
2025-12-05 01:38:59 +00:00
stephan e20e6f59c2 Fix a potential UAF in sqlite3.oo1.DB.exec()'s teardown pieces.
FossilOrigin-Name: 59e0b8a2812f9969402a719174506a20a231a66a15818e6e8830956de2d365e6
2025-12-01 19:20:20 +00:00
drh a1de06a4c6 Version 3.51.1
FossilOrigin-Name: 281fc0e9afc38674b9b0991943b9e9d1e64c6cbdb133d35f6f5c87ff6af38a88
2025-11-28 17:28:25 +00:00
drh 158436f53d A better fix for the issue with RETURNING triggers on eponymous
virtual tables and SQLITE_SCHEMA errors.

FossilOrigin-Name: 40ddaca3fb752425c26570365a9f31820786d21d043c1c0a4b49746ff9bc0782
2025-11-28 13:04:31 +00:00
drh d261437615 Fix a buffer overread in fts5 that might occur while processing a corrupt db.
FossilOrigin-Name: 712e31c59254f82e62a19e41d3b6ac15391dd6e9df966cacadfa9ae79415b243
2025-11-28 12:36:04 +00:00
drh 8c7f142470 Fix a problem in the xFilter() method of the fts5_vocab virtual table causing it to omit some result rows in some cases where a virtual cursor is used more than once by SQLite.
FossilOrigin-Name: 0c836387518dee719eaac8992c63da955630ac073a5e4ba4d887160dff42b898
2025-11-28 12:00:14 +00:00
drh 525d297450 CLI shell: ensure that .dump propagates its error code on error.
FossilOrigin-Name: 61222410c503916b832c1b76b028f1c73f4839a2067902f5db1d6a4a4459cb2b
2025-11-13 12:22:14 +00:00
drh 2605119d14 Fix a problem in the EXISTS-to-JOIN optimization so
that it works with nested WHERE and EXISTS statements.

FossilOrigin-Name: 728fac52017de1309c84c96e33ed99d6472d6b4831587312944b8d85a68d3343
2025-11-13 11:42:16 +00:00
drh de223ffbbd Merge various minor code and documentation fixes from trunk into the
patch branch for 3.51.

FossilOrigin-Name: 9a00fe5eb69050ddc569d2a857309c2779a48414135f0967531999b7afd84283
2025-11-13 11:34:38 +00:00
stephan ea0cda00d6 Kick off branch-3.51: bump version to 3.51.1 and cherrypick [0f712b6b0516dc151d].
FossilOrigin-Name: 1b908c439a4d2614cb6a4cec36d8d876eec68b1e2e80d6aad7e21d61d159df7d
2025-11-09 06:38:48 +00:00
drh c2aa8e3875 Version 3.51.0
FossilOrigin-Name: fb2c931ae597f8d00a37574ff67aeed3eced4e5547f9120744ae4bfa8e74527b
2025-11-04 19:38:17 +00:00
drh 1bf7eb3d49 Use the same compile-time options for the CLI in the auto-setup tarball
as are used in the canonical source tree.
[forum:/forumpost/8975130218|Forum post 8975130218].

FossilOrigin-Name: ccabbe06d4e0650eecc91296d6a3040ed7fef06b47e4d63393a2367c8c8f55cf
2025-11-03 15:34:25 +00:00
dan f1c37a357e Add new column "cwd" to the jobs table in testrunner.db. For recording the directory in which the test ran or is running.
FossilOrigin-Name: 334305a469a51ef0d768ba8443d8cab217f45394cc9f720748a489b10703193d
2025-11-03 15:29:51 +00:00
drh d95fffc9af Adjust the dbstatus2.test module so that it works on 32-bit builds in
addition to 64-bit builds.

FossilOrigin-Name: dcaaa71e750d56afde3e905aaf10729ec95e0ede00522e1b12af6b6345e744ac
2025-11-03 12:36:52 +00:00
drh 4733884eae Update test result output from test/dbstatus2.test module so that it
reports the actual value of nTmpSpill when that value is out of range.

FossilOrigin-Name: 382c8440d7a16eae49fa1644513ae045bfceb072d9b4005963f57f1a57fe94b2
2025-11-03 11:35:13 +00:00
drh 0dfa31d279 Fix the test/speedtest.tcl script so that the CC= command-line option works.
FossilOrigin-Name: 0de0ba878b9ec572d76d47112a0124df9f234fbb7a69c5f5a76ce8c439b11f6f
2025-11-03 10:40:06 +00:00
drh 15c6d88381 Fix a harmless memory leak in the CLI caused by the --cmd option generating
an error message.

FossilOrigin-Name: ab916bad188b150321e420ec0009d909c287e3790b5d6ec683e2df9ed457ff15
2025-11-03 10:14:20 +00:00
drh eaacb4ac37 Add pedantic OOM detection logic to some disused diagnostic and test code.
No changes to any deliverables.

FossilOrigin-Name: abb6945fc62a1855786bda1f473edef0e937a791c453387a0859a6ce0451635a
2025-11-02 22:57:26 +00:00
drh 0c747e1653 Update the test/walthread.test testing script so that it uses a random
database name.

FossilOrigin-Name: ce25a758d4cea1741cb3db6384720f17faef61b352d494ab410a83a41f1721d3
2025-11-01 20:14:43 +00:00
stephan e5c8467a8e Fix ext/wasm/mkdist.sh to use ./version-info instead of ../../version-info (a recent build change made to ensure that builds with a custom sqlite3.c embed that version info).
FossilOrigin-Name: d25a92d88923f880d6477a99f2a35528faea83e7db245f2b07db80613b4aeb8e
2025-11-01 14:49:05 +00:00
drh b2b8ab6bc8 Updates to the compile-for-windows.md document. No changes to code.
FossilOrigin-Name: 652310a9f0ef2a870b5033029278b1fbef28c2ec15405d1b32bf1d51df28266c
2025-10-31 17:45:59 +00:00
dan 7f70085071 Detect some cases of ambiguous column references in USING clauses that can come up with nested joins.
FossilOrigin-Name: 38c993c8b7137d6d5623d387292639634297c17da11befec9029f12a16a472f8
2025-10-31 16:07:31 +00:00
drh a183595edd Change the name of a file-scope constant array in carray.c so that it does
not conflict with other variables names in other files when carray.c is
amalgamated.  This is down to resolve a harmless compiler warning.

FossilOrigin-Name: 5afd815ada94d55c9c56efe339235d23ffbf1fb64511a5e460927a2c8deaaaf0
2025-10-31 15:18:29 +00:00
drh 63ab7c625c Update the main README.md file to use the robot-safe /rchvdwnld page on the
server for downloads.

FossilOrigin-Name: c1aa52361b8ede611f64b96f2394174389ce531b1d86b9cfec91d3b03c94f6ea
2025-10-31 13:44:51 +00:00
drh 1c19c06246 Fix the output of ".dump" in the CLI so that the sqlite_sequence table
is created using correct syntax.

FossilOrigin-Name: 4b9f2e1d4485ad3baf9285aa09b468469be929b18cb308f19af471d7aac66076
2025-10-31 11:23:44 +00:00
drh da17de532f New assert() statements to help out static analyzers.
FossilOrigin-Name: ba0c4bf072ed721a507855d68bde7f1c388396a19b69814b6e257b934f8b0fd9
2025-10-30 22:10:41 +00:00
stephan 1ed6441bb1 Add SQLITE_OMIT_WAL checks around some functions to avoid defining unused statics in such builds. Fixes OMIT_WAL builds on msys2 and passes tool/omittest-msvc.tcl.
FossilOrigin-Name: f9b89535dc279acf617f274b6edbad0610fc8e5c76d402fc8b5b9dc656e95caa
2025-10-30 21:11:01 +00:00
drh 139ec38ac8 Further improvements the ".dump" command to handle corner cases.
FossilOrigin-Name: cd0c77934ff32050380c2143bba7d4e6c07d5f08187cb5d5e8e7602854d1cda8
2025-10-30 18:52:48 +00:00
stephan 41fda52f3c Another (void), as per [dd6edfc09434].
FossilOrigin-Name: 7a822cfd388d7ac5765cffd5bd3d6e5b31abc6a360f9d5e27c0223f83a84237e
2025-10-30 18:48:19 +00:00
stephan 7fb2545905 Add (void) to two places for the sake of SQLITE_OMIT_WAL builds. Why these do not complain on tests in this tree, but do on a downstream tree (same machine, same compiler), is a mystery.
FossilOrigin-Name: dd6edfc09434b0d170d5ab462053497043016a4ec6b91a46db565ccf646aee20
2025-10-30 18:46:03 +00:00
stephan 3a61466a2f wasm: re-add SQLITE_OMIT_WAL to the c-pp-lite build flags.
FossilOrigin-Name: 617f8ac40e073c3fdc1144639b78617ad61113f4e873fc20c99399d2b60e1ceb
2025-10-30 18:39:28 +00:00
stephan 916fc1129c Macro tweaks to get SQLITE_OMIT_WAL building. Remove some nearby stray EOL whitespace.
FossilOrigin-Name: c31a944680f18a799c763238dbb0561f8b039905ce442533258905219b33b743
2025-10-30 18:38:14 +00:00
drh a8a99becb5 Fix a typo and improve wording in README.md
FossilOrigin-Name: 34a662ce24930a5e1a142f0b3ce427c4b1b61a306537820dc5e72996f8080d86
2025-10-30 18:33:58 +00:00
drh f3b396494f Updates to the tool/warnings.sh script for better compiler warnings.
FossilOrigin-Name: c9c64892c76cb9f2efb58428b349d43b075e7595b6a391d4818a7e9fb68b85fd
2025-10-30 18:32:32 +00:00
drh 4ebf49168a Fix a harmless compiler warning associated with flexarrays.
FossilOrigin-Name: f02cdf1d3ea8da8a09d115721845afeff5d6169dd7532ab486d3ed6db69cde2d
2025-10-30 17:23:17 +00:00
drh c6b86ba2ab Updates to the main README.md file.
FossilOrigin-Name: ab10c4cd9f9314bc62aa310ee796f63c82710c35659debe347e8ebcbf34d9e86
2025-10-30 15:43:57 +00:00
drh c5ff2aa7cf Fix the CLI ".dump" command so that it does not make duplicate
sqlite_sequence table entries as described in
[forum:/forumpost/b1674b56ad|forum thread b1674b56ad].

FossilOrigin-Name: c833f26a6780f919551e50c67d308e96293cec8481899354411d805617481f24
2025-10-30 11:39:49 +00:00
drh cb36dc3f3e Prevent a harmless signed integer overflow in the CLI if the argument
to the --skip option of the ".inport" command is -9223372036854775808.

FossilOrigin-Name: 247277d9373cb2614a1bc4c1e08b904315e5e8c0c2a7fbe9c2ac651481601642
2025-10-30 10:36:10 +00:00
stephan 7c86a0321e Remove an OMIT_WAL from the wasm build because it breaks with the current amalgamation (and isn't strictly needed here anyway).
FossilOrigin-Name: a7be7d155aa6f02075f939ab6d26cfdfe2d0832b59da39c8bf4a74fc4845bd05
2025-10-30 01:43:30 +00:00
drh d443f0a95f Fix a logic error introduced by [cea8bf79e18d55a8] which caused
"0 OR 2" to be evaluated as "2" instead of as "1".  Problem reported at
[forum:/forumpost/d5f32040c5d50d2d|forum post d5f32040c].

FossilOrigin-Name: 095cc4f22e63c98cbb2acabdbcaf02e59e67ec6d3cc219b5f42a714e3d53a264
2025-10-29 20:47:01 +00:00
stephan 34b1bf16ec Tiny cosmetic tweak to configure script output. No functional changes.
FossilOrigin-Name: e2c20aa5929e5b79aabca8a51fb3e32e0533526d64d7576d3caf1c847fff58b4
2025-10-28 22:09:43 +00:00
stephan 74cd3c53f9 Typo fixes in LICENSE.md from BrickViking.
FossilOrigin-Name: 26ddec291696dd99c7f84a21b2dd272ce9bf32598ca38413ac89432d45527f8d
2025-10-28 19:57:15 +00:00
drh ffbfc27fab Fix an signed integer overflow problem that can occur when using an oversize
value for the SQLITE_MAX_LENGTH compile-time option together with
multi-gigabyte operands to the OP_Concat operator.

FossilOrigin-Name: 724f2299f206cc9e7f830f984c50a8fc4ac1c17210d71d9affe657b45252b060
2025-10-28 13:24:50 +00:00
drh 5a9ada593f Add enhanced resistance to corruption after posix advisory locks on the
database file been unintentionally broken on unix by running
close(open(DBFILE)) from a separate thread.

FossilOrigin-Name: 6385a1962c69c69ca4775888f034a4eb892aa013689c000f3de6422da7c3c695
2025-10-28 10:50:55 +00:00
drh 9c0770537f Enhance the CLI so that it can handle inputs larger than 2 billion lines.
FossilOrigin-Name: 5daebf2d6013e73d89c9feb796e15b67c39577e5a9e9c86fa260995f4118f04b
2025-10-28 10:44:26 +00:00
drh 6cc222c3be Additional comments explaining what unixIsSharingShmNode() does. No
changes to code.

FossilOrigin-Name: 819fc87385fd5be8a847492478f4c4f247f64edf7c7161b641bfbac6b658bec5
2025-10-28 01:28:20 +00:00
drh db0d47b749 Omit unnecessary branches from the unixIsSharingShmNode() implementation.
FossilOrigin-Name: 2d5623bc27073c407ec63e401f095d12f0025dd276a0bdc26d8b94b1f13c9a36
2025-10-27 23:57:57 +00:00
drh e34f35c833 The unixIsSharingShmNode() function should always return false for the
unix-excl VFS.

FossilOrigin-Name: 770f35dae47a98554b18f8a7aa9f6b6e39ae2b3aa8dce8d75b5bed0c6f0f9c21
2025-10-27 15:44:16 +00:00
drh 626351d444 Implement an experimental defensive measure to try to prevent the -wal and
-shm files of an active WAL-mode database connection from being deleted out
from under the database connection in the case where the database SHARED
lock has been released by an accidental call to close() in a different
thread, or similar.

FossilOrigin-Name: ed1b9206640f66cb8abff444809ccab8a4a5157b5c90e9aacddc422210e63423
2025-10-27 14:24:02 +00:00
dan 6e27846323 Fix a minor over-allocation of heap memory in wal.c.
FossilOrigin-Name: 1803cb9bb6a13fb66956f729066b6eae64c3a1c0715102fb1a9994e395c12ba9
2025-10-27 11:39:07 +00:00
dan 8ce786f173 Fix sanitizer complaints in the regexp extension.
FossilOrigin-Name: 6ff9ecb89d769bc2a27f8a57130f28ec7478979d3e35ba765c16017b5bdf775d
2025-10-27 11:20:47 +00:00
stephan 6b9230d2a1 Merge the OPFS/SEE tests into trunk (where they should have been committed).
FossilOrigin-Name: f8a4d7abf0d1c9c92fa102165d08aed76fd766d49615e3d347b5547580355574
2025-10-26 21:58:41 +00:00
stephan d4ead9b9e4 A better/cleaner fix for [1c80ff88c0ce].
FossilOrigin-Name: 6138043bdde09224a764b5d5f18a9e2776c761c424f41b0d69427d92d47ec41c
2025-10-26 18:36:57 +00:00
stephan f57d368078 c-pp-lite: Fix another newline-related off-by-one which could cause newlines to get lost in @token@ filtering. Problem found in out-of-tree testing.
FossilOrigin-Name: 1c80ff88c0ce3d1c168c9bda734cf52114c35efdcf46a6da78f0ed9adc794eb8
2025-10-26 17:59:30 +00:00
stephan 3fceae3b95 Doc typo fix reported in the forum. No code changes.
FossilOrigin-Name: 6e065b6aa099f31493cfea22a729f92bb312147d8584f663fb75630a25772e43
2025-10-26 12:34:13 +00:00
drh 38113d392d Add the SQLITE_FCNTL_FILESTAT file control and the sqlite_filestat() SQL
function.

FossilOrigin-Name: 9870afcb2a360dff83e211009710bc85db238d9a6993afcc1eb38ca7699fb4a5
2025-10-25 22:22:58 +00:00
drh a105989856 Rename the file control to SQLITE_FCNTL_FILESTAT. Rename the SQL function
to sqlite_filestat().  Rename the enable macro to SQLITE_ENABLE_FILESTAT.

FossilOrigin-Name: ee797fec4eeace78caa2c5e463108bf1a6568db7c33d94d9fe6624cfc6b0d4fe
2025-10-25 20:46:09 +00:00
drh ecbeefecd0 Fix a bug in sqlite_file_info() output: It was showing the "pal" for
the main file descriptor when traversing other unused file descriptors
for the same inode.

FossilOrigin-Name: 3c4020d76e29c39483f6b92857ea470245afcd514870c63bd3373e0e213cd355
2025-10-25 19:51:16 +00:00
drh 2b24d8957e New --normal option for the ".open" command in the CLI. Also, when opening
the database for deduceDatabaseType(), use the same open-flags that will
be used subsequently for the official open, to avoid creating unusable
file descriptors that need to be held until all database instances close.

FossilOrigin-Name: 5e20a0435b1bd84d90c9a419219afe794fdf8ea73213f4c7ae5612c0375bed55
2025-10-25 19:36:12 +00:00
drh 726e836108 Add additional information about unix file descriptors to the same database file
in the sqlite_file_info() output.

FossilOrigin-Name: 64045f0a4d71ef068d64f2f25799cf1ae79c3cdb94039c73f1066290e3dbc943
2025-10-25 19:26:16 +00:00
drh 7be565f0cc Adjust unixPosixAdvisorLocks() to use redirectable system calls so that
it can be tested.

FossilOrigin-Name: eafe88b782875cd839fc27da509830e3e1d95781c686e27242a2844910203a42
2025-10-25 18:40:18 +00:00
drh c053b57716 Merge the CLI deduceDatabaseType fix from trunk.
FossilOrigin-Name: 82f907016ee75ca288d8ac0664d5c147fbfad42c5f8222211acc3220bd0eb609
2025-10-25 18:36:14 +00:00
drh 0d859b4828 Fix the CLI so that it does not try to open what might be an SQLite
database using open() in the deduceDatabaseType() routine, as this can
lead to broken posix advisory locks.

FossilOrigin-Name: 2a3a02715fa53673531575fa13aee056711139b409367cccc18654e82720c4e6
2025-10-25 18:35:29 +00:00
drh ab29c24dc3 Additional information about the unixShm shown.
FossilOrigin-Name: 85846c7fbeeaf5fccfcbe11a4b87c4ee49781456ccb4da1d090b7823d7b456d6
2025-10-25 14:06:36 +00:00
drh dcc07d3ca6 Do not attempt to show posix-advisory-locking status on journal files.
FossilOrigin-Name: 7f8baf64bb722d7dfdfca22d4f11a72113d5ed2b36d6cc6020fb0acf8185b3e7
2025-10-25 13:55:49 +00:00
drh 234c6c4bf0 The sqlite_file_info() function should always return JSON, unless there
is an OOM.

FossilOrigin-Name: 65aed79c29bf1aac0934475c02b358b916f413b20d2475ec7b631011f21f4e2b
2025-10-25 13:16:41 +00:00
drh 86319b841a New symbolic representation of posix advisory locking information
FossilOrigin-Name: b7d991ae04da1d6731b67fbdca65df996ec1c14a9530880fb7dbeeaef2575d14
2025-10-25 12:53:03 +00:00
drh f4e66056ac Merge trunk enhancements into the file-info branch.
FossilOrigin-Name: 73e1e081e9f7fc0ece98222669d13abde16197f0befc3343246a9e7da7856f02
2025-10-25 11:47:04 +00:00
drh 76db3a6e66 Stricter assert() statements on unixShmSystemLock().
FossilOrigin-Name: ed01ed337c04cce4cdbb6e80628b6f716d537e072b80067bd2bd6c5d18a1454f
2025-10-25 11:37:54 +00:00
drh 003737d1dc Improvements to the design of the /proc lock analysis.
FossilOrigin-Name: f2809dd3b266c0a6a6eb4ed62812a907493fb4006d26f8905df7ff2b1ca01a5e
2025-10-24 23:12:33 +00:00
stephan be4d0c2e2f Make it particularly clear in the wasm build output that unsupported builds are exactly that. Cosmetic tweak only, no functional changes.
FossilOrigin-Name: 86f53a2eb37d8ec98bc9d4c6b00253cc00d798e79c7d409e65d608354a556e19
2025-10-24 20:29:12 +00:00
drh aeb886bc53 Easier to read /proc lock interpretation.
FossilOrigin-Name: d7bcc54beb6463501c0559333455bd2a378798b58cb48f35590e9026d07acd2f
2025-10-24 20:26:13 +00:00
drh 2f9311c5cb Flesh out the sqlite_file_info() function further, and in particular
show locks based in /proc/PID/fdinfo/FD, when that information is
available.

FossilOrigin-Name: ce75111cced8a03f05cf47ef809b9f017f2dac3c64c6008d595f28dbfec32057
2025-10-24 20:04:16 +00:00
drh 093b26e8e0 New diagnostic SQL function "sqlite_file_info()" and its associated
file-control SQLITE_FCNTL_GET_INFO.

FossilOrigin-Name: 56ab9692583d5b64e1ab727e08a01c0a65b4e318b455c94397663ef8d3d7b6b8
2025-10-24 17:42:03 +00:00
stephan 63ee854264 Fix a duplicate SQLITE_API on sqlite3_carray_bind(), as reported in [forum:7499e8a19edc8908|forum post 7499e8a19e].
FossilOrigin-Name: 62917cd4297e734477d3201481548ddb7f79ec977b9da7d9313bc7f1c0091187
2025-10-24 17:16:00 +00:00
stephan 3ba506d9cc ext/wasm: dependencies fix for parallel builds attempted immediately after a distclean. Add version-info to the distclean rules.
FossilOrigin-Name: b99233fe3d901714c4369ba25c510050fb7a8a85c1168780108595e9639a6d15
2025-10-24 16:39:58 +00:00
stephan 67fa337744 ext/wasm/GNUmakefile: (A) When using a custom sqlite3.c, use sqlite3.h from the same directory instead of the top of this tree. (B) Re-add preprocessor flags for SEE which were misplaced during recent build refactoring.
FossilOrigin-Name: 1b1e530a9149ce62d3d53f5c558e358d4e6d1b00e0cce8bb04cb6b13d1841538
2025-10-24 16:25:23 +00:00
drh 033dbac510 Fix [4e713558f6c6ea3d] so that it supports separate builds of rtree.
FossilOrigin-Name: d030e955d703772e1637ef2c07d29816fc869ead0a15a85ec8b4633e5ca08e0a
2025-10-24 16:01:55 +00:00
stephan 9af334f54a Document minor discrepancies in how sqlite3_bind_pointer() and sqlite3_carray_bind() react to the SQLITE_TRANSIENT and SQLITE_STATIC finalizers.
FossilOrigin-Name: b92478c389a9ff57302c021444ced09aef067ab55394dcda38cde97a3f2628d4
2025-10-24 15:18:13 +00:00
stephan 4bb53ab2e4 Make explicit that sqlite3_bind_pointer() and sqlite3_carray_bind() call the provided destructor even if those routines fail, per [forum:6d81b10952|forum feedback].
FossilOrigin-Name: 1fcb0b60798c708fec53d9d69a65cca2e37a9af7a5fa654c7b2bba97056cd461
2025-10-24 14:30:42 +00:00
drh 7adc9a5978 Update the MSVC makefile for the amalgamation distribution.
FossilOrigin-Name: 440ce1cff2b7519912fec87f440894592e901d730bf74cf99479e7b1d047bf02
2025-10-24 13:23:43 +00:00
drh acdda1075d Enhance the tokenizer so that it is able to deal with individual tokens
larger than 2GiB.

FossilOrigin-Name: 4e713558f6c6ea3dfbc97d2eb0a328955ef6ad6f2ad05517efe9ed4a60181440
2025-10-24 13:18:31 +00:00
drh bc2691d5c1 In the CLI, improved error messages on input errors. Limit the size of a
single SQL statement to a little more than 2GB.

FossilOrigin-Name: 0b50e7e10aae3d57f1cbd38d02be50cfbd2d5148ab4a9be712afd8678787b7bd
2025-10-24 12:32:32 +00:00
drh 95c188d557 Limit the size of --hexdb files in the CLI to 2 billion lines, to avoid
overflowing the line number counter.

FossilOrigin-Name: 2adfd0f47b028b8378e6cc08dc22abf1606036bbd285a7bc3a0de0eaf6feeb8f
2025-10-24 09:24:56 +00:00
drh 4043096408 Additional defenses against over-sized inputs in the (unused) amatch.c
demonstration code.

FossilOrigin-Name: b9f6ae0767ce5d9cbc6fca6d63c929f919473fa669e50a0a460627e5fde2628c
2025-10-23 14:05:58 +00:00
drh d06a0be514 Fix a faulty error message in the ext/misc/fileio.c extension.
FossilOrigin-Name: 1fdef271cd15d0960a7933253a10f288e26771cdcf34b5cd22adbc49d6341bc5
2025-10-23 13:10:34 +00:00
drh 984e446891 Adjust some of the markdown in the LICENSE.md file so that it will hopefully
work better on GitHub.

FossilOrigin-Name: 773f9d3dcf1ac7a9ce7f0911f46301f3e0e01d699f73a264cab692299a8d615e
2025-10-22 00:38:28 +00:00
stephan 774ce0ba43 Back out [b144f875d6bddce6] and remove the former check for strchrnul() from the configure script.
FossilOrigin-Name: f4e059b2243c6db37b4dd201b03f0c1916baec5e9e1a660815fcd7eeaf530367
2025-10-21 16:15:53 +00:00
drh d41f5ef7e6 Reduce the maximum size of LIKE and GLOB patterns in the ossfuzz.c test
module to avoid false-positive infinite loop reports from OSS-Fuzz based
on long and complex fuzzer-generated LIKE/GLOB patterns that are not actually
infinite loops, but which do take a long time to resolve.

FossilOrigin-Name: 53edea286b0a38f4f9c7017276f3a826037919144d517f8c89ef0f35b65af5f1
2025-10-19 17:30:07 +00:00
drh efe8ae567c Use 64-bit memory allocations everywhere in the expert extension.
FossilOrigin-Name: 6caf793b8f406f5089e3811591bc69384646df16ee18d63bd63760eaaa95d122
2025-10-18 11:19:02 +00:00
drh 21c57abc53 Increase the range of integer indexes in the the merge() family of
SQL functions.

FossilOrigin-Name: 8d3943890ef3b533df35c4784c2a42c52503a4d9c3dbe67241510d8b70669b48
2025-10-18 11:04:03 +00:00
drh 31c86ca0a8 Fix a minor memory leak in the CLI that can occur following an error
in the ".output" dot-command.

FossilOrigin-Name: d1044bc0616fd20c63ca3b627ad0a116256870a082a72da26f98fb0f59ca44fd
2025-10-17 10:06:44 +00:00
stephan 9f36870a77 Resolve the MacOS-specific build issue reported in [forum:95edc7a8d7d1de59|forum post 95edc7a8d7d1de59], with help from Bo Lindbergh.
FossilOrigin-Name: b144f875d6bddce62e8f2ad42bfe5dfa6c2434f2ef3edb86847fb4c23aa46814
2025-10-16 23:42:39 +00:00
dan 9c3fcd932d Improve performance of the shell tool ".ar" command when it is given a large number of arguments.
FossilOrigin-Name: 8fed9de84bce01e88e0e8237e245c0ff9fe9f46394c603887e360658f5ef1ac1
2025-10-16 14:17:30 +00:00
drh 0a585a64d2 In dbpage.c, disable truncation on any update error, including errors
in sqlite3PagerWrite().

FossilOrigin-Name: eee5ba5d8a9d01000345185731c531eb84d3cb8e81bf429506c449d962aad843
2025-10-16 12:43:36 +00:00
stephan 6eaeea0a3b Fix an off-by-one in c-pp-lite.c which could cause @token@-processed output to get one duplicated byte.
FossilOrigin-Name: aa2f4c51604f4d4286c8a1ec7eaa6251892471e32087af695712513ee620ea46
2025-10-16 01:44:03 +00:00
stephan e826aa8e00 Minor JS doc updates. No code changes.
FossilOrigin-Name: fc2a026901b1a12526b92fff36d7acc226e554c9f351e6261c7ffd4887bcc337
2025-10-15 23:28:31 +00:00
stephan ff5d4c348c Resolve a valgrind-reported error in ext/wasm/c-pp-lite.c caused by successful exit colliding with the atexit() handler. Add -e SCRIPT support to c-pp-lite to facilitate testing.
FossilOrigin-Name: 7801c7225a18ccb2216b01663b30e3eb90a961e3d165af73f964c515b74fe745
2025-10-15 23:13:50 +00:00
dan f66a0600d8 Improve performance of the shell tool ".ar" command when it is given a large number of arguments.
FossilOrigin-Name: 0398897067ca5cdedfef0ce7a034ba6d5a2ce6104605ef4ed1c7549499435b44
2025-10-15 15:54:38 +00:00
drh 34c1e04cbf Fix memory allocation in the ".table" command of the .cli when the number
of tables in the database file approaches 2 billion.

FossilOrigin-Name: 5cbccab499bc3983aac1f57355552db607dee6c7ef4eb00d794dbee89c18db70
2025-10-15 10:52:45 +00:00
drh f83df5b150 Reestablish APIARMOR for the sqlite3_db_status() interface.
FossilOrigin-Name: 1738f0bdf5941a70684c82d2040561e53a272595026a837a9f9bab8508a46480
2025-10-14 19:21:46 +00:00
stephan d6cb2ccee6 JS/WASM: Expose sqlite3_db_status64(), sqlite3changeset_apply_v3(), sqlite3changeset_apply_v3_strm(), and SQLITE_DBSTATUS_TEMPBUF_SPILL.
FossilOrigin-Name: b13eafc9b6820517b450041a7e2be573a896b5b9e88b2b28df9f15e3cb91e23d
2025-10-14 18:23:32 +00:00
drh e7cf3fe4c8 Add the test/testloadext.c loadable extension to test the ability to use
the latest APIs using the loadable extension mechanism.

FossilOrigin-Name: a9bd7ed6f77c5e53f9130eac7eb999c662e9158fb229a462d29f18653284d6d0
2025-10-14 17:50:55 +00:00
drh efde2f6059 Add the sqlite3_db_status64() interface and the
SQLITE_DBSTATUS_TEMPSTORE_SPILL option for use in that interface.

FossilOrigin-Name: 9f8739ddea6ec6d8890d0e8f6a0143773a008e4f96bd02a48d4bfebb3f9b72fe
2025-10-14 17:09:06 +00:00
drh 53a6b7d138 Make the new sqlite3_db_status64() API accessible to extensions.
FossilOrigin-Name: 2ebd7330312f3ee4674c343b7a19b703f1f89611a6846a0e2be39867f9895522
2025-10-14 16:57:50 +00:00
stephan 4472c967a6 Fix two links in ext/wasm/README.md.
FossilOrigin-Name: 0f96eaeaa8c51c20f8d389bfd6d0d6371e8bb29ff7e8eaf3a0bcb35cb2b73338
2025-10-14 14:07:58 +00:00
drh abe709be8d Extra defenses against integer overflow in the decimal extension.
FossilOrigin-Name: 1a7414d9b5be7ce18b23c357fd98cd0e96d78ac626abfa6e4e0dee494b6a1efc
2025-10-14 14:03:09 +00:00
stephan 5dbbe50758 Add a section to ext/wasm/README.md about the dependency on wabt/wasm-strip for release builds.
FossilOrigin-Name: 0dbb13863b3ff1da1be664967ac05c79cf34f7a78def05fe4f6407c06cb4322a
2025-10-14 13:47:40 +00:00
stephan 9f136fc5ed Fix a makefile typo which caused a build directory to not get mkdir'd for the fiddle build.
FossilOrigin-Name: d98d5abf6d27c5359ff8c797ad57394b96074e47010bc4c24120ba69a967dc3c
2025-10-14 13:25:02 +00:00
drh 898ac77f55 Merge all the latest trunk enhancements into the dbstatus-spill branch.
FossilOrigin-Name: 55f2613c1bacddb05902d4d5dac3d2b49b91053e6249dd926bb953c763eafeb0
2025-10-14 11:18:45 +00:00
dan 264bcad69a Avoid integer overflows (a) when dealing with zeroblob(N) calls when 2*N is larger than 2^31, and (b) in fts5 when a corrupt record is close to 2^31 bytes in size. Both of these require special builds with SQLITE_MAX_LENGTH set to a non-default value.
FossilOrigin-Name: 27927519696dcb78ff72e245158ea6d33a1b2c3d4da314d4d0283c47d847c3da
2025-10-13 16:07:28 +00:00
drh a8bb50ce95 Fix a bug in concat_ws() in which an initial empty string was treated as if
it was a NULL value.

FossilOrigin-Name: eb2e4e46171c12f59aa5d571eeb310534360b110c3e7bda6eaf68f0e25546264
2025-10-13 12:36:54 +00:00
drh c93270ebc7 Enable CLI documentation for .imposter
FossilOrigin-Name: c639c7be029f86defe6cb8cef094e1126ec8ab3968e12d4d2bf6e6ab23c39821
2025-10-13 10:35:59 +00:00
drh 94356039d0 Fix broken hyperlinks in the documentation.
FossilOrigin-Name: 62e6b120c43cd855349bf1b40ad2fb992e31a6e2567e5b145cf1849445849da7
2025-10-12 19:17:31 +00:00
drh ee4676b3f7 Fix order of operations in the OP_Concat operator of the byte-code engine
to avoid any possibility of an integer overflow.

FossilOrigin-Name: 765e6569824ccc34292d6df16a6cd682e6503f20adebe0a43cd2118d69072a63
2025-10-12 10:31:34 +00:00
drh e4eaf174a5 Remove an unused variable from the generate_series implementation.
FossilOrigin-Name: a523e4adbf8e60ea8c3351f33aff793c6e425c594038e8578d12564bf47aac03
2025-10-11 18:44:54 +00:00
dan 59e1ab5576 Fix an assert() that could fail when reading a blob or text value larger than 1GiB from the database (requires a non-default build configuration). This is an assert() fix only, production builds were functioning correctly.
FossilOrigin-Name: 3e5ec5731f0c8c5f7da357c63d315aae5a2aca5c1b3567bc8c9386ccc2a798cf
2025-10-11 16:23:22 +00:00
drh 11878165f6 Improvements to the (rarely used) home-grown varients of seriesCeil()
and seriesFloor() based on ideas from
[forum:/forumpost/2025-10-11T12:36:56z|forum post 2025-10-11T12:36:56z].

FossilOrigin-Name: e6b9bfdb6f8f86d4d2891d65fee4274dcbc61c9e998d81f90232153c05788cab
2025-10-11 15:45:47 +00:00
drh 5013fd1f81 Provide alternative implementations of ceil() and floor() to the
generate_series() function so that it will build even when SQLite is
compiled using --disable-math.
[forum:/forumpost/91690fa646|Forum post 91690fa646].

FossilOrigin-Name: 97d6fd2c99578adb6a1e9b879ba5ae5ad798a8ef8f0646bf0102747d52148bff
2025-10-10 19:43:03 +00:00
dan eeb2e03b7b Back out [8bf26c956e]. It is not required following [8e7da8cf50].
FossilOrigin-Name: ea29180797aa4bb25180432e75a372277a6f6e2262906a9e765a3bddf8ca79d7
2025-10-10 16:04:19 +00:00
drh 80f0fcd31d Fix harmless compiler warnings.
FossilOrigin-Name: 4966d7a1ce42af8b1c50fdd40e651e80d0eeb8cb62dd882950cab275f98aba88
2025-10-10 14:31:46 +00:00
drh 8c1670642d Makefile updates to suppose carray() and percentile(). Add Carray to
the CLI and fuzzcheck to support debugging.

FossilOrigin-Name: fe9cf68b513d1e8cfcde90f1982a7f4123f54e3ebb004d961a99bdf6bec03a32
2025-10-10 14:22:05 +00:00
stephan e33786f09a Regenerate autoconf/Makefile.msc to squelch a 'make test' warning.
FossilOrigin-Name: f7f55dce184c433b7774ab569caaeae5994c63421de01e9ea36aa1dbecb2d579
2025-10-10 14:00:27 +00:00
drh f9d511319b Fix the carrayfault.test script so that it works in configurations that
do not support virtual tables.

FossilOrigin-Name: 767a667b91caff2e789179231f13a0d260c9837020c0ce1553b86e88cf9aa352
2025-10-10 13:43:53 +00:00
drh ea0d2cebd9 Avoid (apparently harmless) undefined behavior in CARRAY if the rowid
is used as a constraint in the WHERE clause.

FossilOrigin-Name: 200b3c8f6cebf34428b0b41fc05f7361771dfee3592cfcdce512084abcc99713
2025-10-10 10:40:37 +00:00
drh 7b34ca9cc1 Fix the sqlite3_bind_blob() interface so that it sets the encoding of the
underlying sqlite3_value object to the database encoding.  Fix for the
problem reported by
[forum:/forumpost/2025-10-07T12:47:25z|forum post 2025-10-07T12:47:25z].

FossilOrigin-Name: 8e7da8cf506059dde98000db2731b8c47951344263df680a12b7c95aaece2568
2025-10-10 00:59:28 +00:00
drh 8080411752 Fix the xBestIndex method on carray so that it gives a coherient query plan
in a join when some of the arguments to carray() come from other table
in the join.

FossilOrigin-Name: c8417b3261b2c9f20dcc38c482b9fc43acb97d933eb723c2f6698a7435a192eb
2025-10-10 00:26:46 +00:00
drh 97fa2fe414 Fix carrayfault.test so that it works with the new built-in CARRAY.
FossilOrigin-Name: 22f694682107036e68b67e48123d606aeff8cd8b7fedc8ab8ed9cc1a9cccd73f
2025-10-09 19:23:01 +00:00
stephan b4fdfc2f9a Update c-pp.c and rename it to c-pp-lite.c to match its new upstream name. Adapt the JS files and mkwasmbuilds.c for c-pp syntactic changes.
FossilOrigin-Name: bb13e46ddfcd1d3ca73845430d9a91c0ea3913762d39bbd94127783d77e4f63b
2025-10-09 15:28:59 +00:00
dan 40d299ae32 Avoid corrupting the fts5 index if a value that was inserted via sqlite3_bind_blob() in a non-utf8 db is deleted.
FossilOrigin-Name: 8bf26c956e199762d55c159392c2e3813a9e12b914d3ca33000bf332cd946cb0
2025-10-09 14:50:27 +00:00
drh 0f5a3f16f3 In the CLI, limit column widths specified by the ".width" command to
have an absolute value not more than 30,000.

FossilOrigin-Name: b3741f1101d25eded57a62b4967ec1bcce532dc9937c4b7b74cb689861efb442
2025-10-09 14:01:52 +00:00
drh 3be9a9b984 Move the carray() extension and the percentile extension into the
amalgamation.  Both are still turned off by default and must be
enable using SQLITE_ENABLE_CARRAY and SQLITE_ENABLE_PERCENTILE compile-time
options, so there is no increase in object code size.  However, these
extensions are now more easily available.

FossilOrigin-Name: 2d40dc2173ac394024ae267419bd8d3621f15d4cd2449c9c2f7310acc3b190f0
2025-10-08 19:01:00 +00:00
drh 8f2f5e4963 Add the SQLITE_ prefix to the type constants used by sqlite3_carray_bind().
FossilOrigin-Name: e11e9913e56d42d2baa07f1b549f212b873fe7343a06825682d843471c4a3640
2025-10-08 18:51:15 +00:00
stephan 0df9db4921 Make use of the new SQLITE_ENABLE_PERCENTILE in the wasm build.
FossilOrigin-Name: 937c084c2d9b20fde2d54e48257cb7018bd8c36d6f00ed6f1659b5ecc2f48ed4
2025-10-08 18:17:19 +00:00
drh 01f5e6e757 Add ENABLE compile-time options to enable carray() and median(). Hence
there is no new code and no increase in library size without the ENABLE
macros.

FossilOrigin-Name: 7dec290b413ca1bc67694743d8b771e1634fd85251f1a23d60aaf36c63f0f366
2025-10-08 18:11:37 +00:00
drh ba5cce9f08 This is how the percentile() family of functions might be integrated into
the amalgamation, should we elect to do such a thing.

FossilOrigin-Name: c2cfc9c92e35105e26a4c0887b0401ace15a874fd18046135de4b375ba968795
2025-10-08 16:29:14 +00:00
drh cdaff852bf Were we to choose to integrate the carray() table-valued function into the
amalgamation, that integration might look something like this.

FossilOrigin-Name: 2b43d5d7dcc5aee14a050c824a5e09b6a38a9c78ddcc25a994eba5d4c5ad9ba2
2025-10-08 15:32:55 +00:00
drh e15ef5b756 Fix harmless integer overflow in the CLI when arguments to --lookaside are
ridiculously large.

FossilOrigin-Name: 8bf337e6e609dd38de6002f2d3d3ebf52dd0462ed98a50e4b002a7c6860d30c5
2025-10-08 12:37:01 +00:00
dan d3973778a1 Fix an uninitialized variable problem in test1.c.
FossilOrigin-Name: 059203f658273712597d45d9b4a9cf1aea20368fe51224b38e28797b045fb6b8
2025-10-08 11:00:04 +00:00
drh 55085a2cc2 The ".dbtotxt" command in the CLI should not fail if the database is
uninitialized.  It should instead be a no-op.

FossilOrigin-Name: 2818ef64d9233095b065101392768071fbd95729cde060b954f48ea821fc549a
2025-10-08 09:52:52 +00:00
stephan b8d2ca1513 Function name doc typo fixes for sqlite3_source_id() (sic.).
FossilOrigin-Name: 03c3f12853163ce542239a98bdf8e830db2fc7ccf1edb2f9c783fcfdca858879
2025-10-08 02:05:15 +00:00
dan 6147a0f6a1 Add test cases for the carray module.
FossilOrigin-Name: dcfc0164a95eddb5e924c606850fe2015e8f2f516d36b380cbb79d6bdfe034fc
2025-10-07 21:02:37 +00:00
drh 308831d1c7 Improve the invariant checker module so that so that it added "+" before
"column ISNULL" in queries where the base query contains a GROUP BY, to
prevent the ISNULL term from being pushed down into the subquery, since
that can cause ambiguities if column is UNIQUE.

FossilOrigin-Name: b4ff920fbeef9a8590219596d73c09976da3da53c08a685be56f6b2cd2cdc70c
2025-10-07 18:06:05 +00:00
dan 9b6bc61dbd Fix some integer overflow warnings in the base64 and base85 extensions.
FossilOrigin-Name: 06b4bd2aba22c57f5a5fed606c3bee225dee6fdc13bb16cc58194040ef0d7d85
2025-10-07 15:14:03 +00:00
dan 7aa5271c72 Fix a minor problem with building sqlite3.c without manifest.tags.
FossilOrigin-Name: 140f0f9fd389c99dc6ba1fdca7658c43d8dc3f3c128484fbafa7d67c33fe1001
2025-10-06 20:11:18 +00:00
dan 9804ed7021 Avoid attempting to delete a file that is still open in sessionnoop2.test.
FossilOrigin-Name: 56f6d6c538fd4e0da8a7c4e4c4d1bd0b8cd83ffd126ae24daaf30fdf808e1a78
2025-10-06 17:52:52 +00:00
dan 75ef68e385 Avoid using randomblob() in walckptnoop.test, as it produces different results for different test permutations.
FossilOrigin-Name: 94ceb0f0cfef1da89ea2a7420f508024897d9b7c19ef9be9af88d3e6f48c297c
2025-10-06 17:20:26 +00:00
drh 35299c9076 Change the testrunner.tcl option from "--case" (singular) to "--cases".
Allow the argument to be a glob pattern, to pick up multiple cases.

FossilOrigin-Name: e205f87f5cf97b82781af690da1a3fbf3dc75f590783074e5a72c1d7e3bebbad
2025-10-06 16:57:49 +00:00
drh 87f53152ed Fix typo in the previous check-in that prevented the script from running.
FossilOrigin-Name: 797664700701effefbf4d87a791febae3bb68544bac23470351a11bcb3a87651
2025-10-06 16:56:12 +00:00
stephan 6f7c977ed9 Add info from the SQLITE_SCM_... macros to tool/version-info.c's --json output, prompted by [forum:0c513ae3fca7d55c|forum post 0c513ae3fc].
FossilOrigin-Name: 951882aa4e1684b7b0f7e10590de81eae1ddb8c5ac21588e3f9b9cd4cb9f0f51
2025-10-06 16:54:45 +00:00
drh ad7118fa68 Update testrunner.tcl so that the new option is --cases rather than singular
--case, and so that it is a glob pattern.

FossilOrigin-Name: 9488b4f00c9278de8c03f4a3cbd4f54e48e71c1eff45de4454f8bd49c080a930
2025-10-06 16:50:37 +00:00
drh 0ab87fc9a7 Fix typo in the "testprefix" for walckptnoop.test
FossilOrigin-Name: ff205f29934417e8150b5243245fb70389717b219e35bd8d60791a8485b69b33
2025-10-06 16:23:31 +00:00
drh 0611aeeed4 New testrunner.tcl option "--case DISPLAYLNAME" only runs the single case
(and its build dependencies) that exactly matches DISPLAYNAME.

FossilOrigin-Name: 8ea2e097b731514c284f255f12b08e15f63c7f49641a698e61ee7e47cc9d3c45
2025-10-06 15:53:52 +00:00
drh 566348f68b Fix testrunner.tcl so that --help output goes to stdout, not stderr.
FossilOrigin-Name: 441a759c225d4e710a693339402624e7ba52852c08aa64439ed4568c193ad529
2025-10-06 14:30:22 +00:00
drh d357d9d1cd Fix a subtle problem with short-circuit evaluation introduced by
[cea8bf79e18d55a8] and detected by the dbsqlfuzz fuzzer.  Test cases
in TH3.

FossilOrigin-Name: d71cd722c478288601c70df8cec8c242cc623d2147b30f4f68dad57c75b3ee4a
2025-10-06 11:50:35 +00:00
drh 833fb1ef59 Another small performance increase in the text format by using strchr() to
search for '%'.

FossilOrigin-Name: 59ad89ba07dd7b127f03f62a647f7328f08dbc0aa1b88b2b4529eb5b4c677775
2025-10-05 22:41:32 +00:00
stephan 34775b696b Fix a syntax error in the tcl script part of [199b6567bb41cd].
FossilOrigin-Name: a7ed85f27066b74263dbd3dfcefe5d378e524cc56cd3abac4032bc23f83b5d21
2025-10-05 19:56:57 +00:00
drh d310393158 Performance optimization in text formatter by using a hash table to look up
the operator character that follows %-subsitutions.

FossilOrigin-Name: 199b6567bb41cd41977e28b3e06e8c26c3300b3873f226a4699ec251a7bf8883
2025-10-05 19:30:05 +00:00
drh 275d08ad62 Minor clarifications to the JSONB format documentation.
FossilOrigin-Name: 0fc708b41fe99b315b32e4a6ac8d48d8250195f7de1ab1d9f6eaf50290781286
2025-10-03 18:17:13 +00:00
drh 1d574d3d71 Remove the memvfs.c extension, to prevent it from being misused.
See [forum:/forumpost/91811439aa|forum post 91811439aa] for the complaint
that prompted me to take down this demonstration code.  I have other things
to do rather than argue about posts such as the foregoing, so it is easier
to just take the code down.  If you need this code, you can downloading older
check-ins.  The beauty of DAG-based version control systems like Fossil
(and Git) is that nothing is ever lost; it is just stops appearing on
trunk.

FossilOrigin-Name: eb79110dcac80dde3bcca0929d67a8f8f6d2eea5695184b2b7c6788283f06902
2025-10-02 22:48:08 +00:00
drh e2ebc364cd Fix typo in the previous check-in. Remove surplus end-of-line whitespace
from the ext/misc/fossildelta.c extension.

FossilOrigin-Name: cc87551805dc1fcb05598339e526b304401b64a4eaaa2148a9d837b1423484ce
2025-10-02 19:35:58 +00:00
drh 0d9ec8b2ee Harden the debugging vtab "delta_parse()" which is part of the
ext/misc/fossildelta.c extension against malicious inputs.
[forum:/forumpost/be139437c3|forum post be139437c3].

FossilOrigin-Name: 4be6deee646f2c0f591ba81f902182ca9302050a7fb2729c7f64981307058b8b
2025-10-02 19:19:40 +00:00
drh 4defad2f29 In the ".open" command of the CLI if using the --new option with a URI
filename, then decode the URI to extract the actual filename prior to
trying to delete that file.

FossilOrigin-Name: 14ee3c1f03de274e5fa1efb471816a0001762623614253c24d58f41ea6af0628
2025-10-02 18:31:19 +00:00
dan 7d973ac52f Fix -DSQLITE_OS_OTHER=0 builds.
FossilOrigin-Name: 2971d7470110fcd43bdc8ad5d09d1f2f63f5a3bccda41810948a683e310ad908
2025-10-02 14:48:27 +00:00
drh b9c23fa541 Correction to [ae303dab2f534e2c] to use the right loop over the solver.
FossilOrigin-Name: 22b2700ac20bb8e5883d484bfd0aee7a0fbc99b92696d8ca850cd129e2ccbb43
2025-10-02 11:28:27 +00:00
dan cbc3cd47f0 Fix a buffer overrun in the zipfile extension that could occur while processing zip archives with extremely long file-names and comment fields.
FossilOrigin-Name: c284fda848038a61972fd1df5796f608a24ead109170aafe562a5d5787c46488
2025-10-02 11:16:22 +00:00
drh fa563eff1d Add the --ifexists option to the CLI and to the ".open" command of the CLI.
Also the undocumented and unsupported --exclusive option on the same.

FossilOrigin-Name: 9a1947814d235d270dec265bb85db37e75cc077289e444d3d00f8345016c683e
2025-10-01 20:41:02 +00:00
drh 65ee59bb26 Prevent embedded 0x00 characters in the output strings from confusing
the completion extension and causing it to read past the end of an array.
[forum:/forumpost/88a08b3201|Forum post 88a08b3201].

FossilOrigin-Name: 26f6d41f9d3ab656129af333d54a8645c6890314919bcae90351ba0c2240ceef
2025-10-01 19:01:19 +00:00
dan a9af4102f1 Fix a buffer overread in demo code in ext/misc/memvfs.c.
FossilOrigin-Name: 90f7318308ca8372cbd9f183d88ff6cb884446f6df0695294c9a9955c5109f72
2025-10-01 14:28:48 +00:00
drh 4af7048aeb Enable the CLI to be compiled with SQLITE_OMIT_AUTHORIZATION.
FossilOrigin-Name: afb2feb38043fef3c286030f9d1238c132f338e54233f2e4655323b388455c72
2025-09-30 19:11:00 +00:00
drh 0f76b0a4d6 Fix various compiler warnings.
FossilOrigin-Name: 24ee6c25b4745c8fd671d845b48b9ab98a787ccb348d560ad70f19d035e7990e
2025-09-30 17:37:18 +00:00
drh c8e6f627b8 Fix the new generate_series() to correctly deal with an explicit 0 as the step.
FossilOrigin-Name: b059413c440d1b831c9a462f7165a350001ba7a8cc77ca2a0a8f2bb73c830aba
2025-09-30 17:12:39 +00:00
dan d05bf5aedf Fix another potential buffer overread in the zipfile extension.
FossilOrigin-Name: 0819fe670f9ceec79f84eb09c234dc29f6581332f86a53d6a0547697404efff1
2025-09-30 11:17:40 +00:00
drh 5b15123fba Strengthen the fts5_locale() function against integer overflow attacks,
even when SQLite is compiled with oversize values for
SQLITE_MAX_LENGTH.

FossilOrigin-Name: f0dbd9d22f558dd002e2132381de3c82d55a670399b3e527b5962b025141676a
2025-09-30 10:11:44 +00:00
drh 974b8d7df0 Fix a problem with the merge at [cb604efdb40da95a].
FossilOrigin-Name: ee6102d4fe35b7b914aa2dc7c7dd37460910efedc9b2d192c2fb8cb0e6a1fd4e
2025-09-29 20:40:50 +00:00
drh 8f6b797a1b Change the name to SQLITE_DBSTATUS_TEMPBUF_SPILL.
FossilOrigin-Name: 4a60a9c63534f5d2f16af2c3c6581abe7ecf7adfdb39f17e557e73997ae03396
2025-09-29 19:57:43 +00:00
dan 3eccaa7915 Fix a buffer overread in the zipfile extension code.
FossilOrigin-Name: 70c2c99b6f12a3467c23b44adcaf2d7d780ba8317b72de2f6730b1d892cf0c85
2025-09-29 18:55:05 +00:00
drh c49ff175ef Merge the latest trunk enhancements into the dbstatus-spill branch
FossilOrigin-Name: cb604efdb40da95a759e2eeb9d73608859a94acde9d9782ca82757d3a1c15303
2025-09-29 18:48:00 +00:00
drh e6197c0d1d Improve whereSolver() so that it always finds a unique solution.
FossilOrigin-Name: ae303dab2f534e2c5132112b61fa5a097e7010fd8b652badee669fbe9df5cf53
2025-09-29 18:17:19 +00:00
drh 7e38287da4 Fix JSONB logic so that it correctly interprets large JSON5 hexadecimal
integer literals as positive numbers.

FossilOrigin-Name: 0ad5d77fc0a9d205cc061ee4923d885f6f28f77c1efef3cc10297036ce164e6d
2025-09-29 14:09:43 +00:00
drh 381df874f0 Large JSON5 hexadecimal integer literals are positive unless preceded by
a negative sign.

FossilOrigin-Name: 5a93d9dce2d134ca450955bb272baba43dfc76beb540b643bf4bd31f7eb9e0b9
2025-09-29 13:43:10 +00:00
drh b7f5885b3e Back out check-in [9abaa0ac2b304934] as the code removed there is necessary
after all.

FossilOrigin-Name: 27ae98629406bbaee2857f75c069b2ccd4757b247f0742e51b9e619e96b6dc45
2025-09-28 23:10:54 +00:00
drh 36ba76010c Revamp the implementation of generate_series to simplify and improve
long-term maintainability.

FossilOrigin-Name: 9041ca8543ff3d2a617ce4df696aa53269a7803716caaf55a8e61e59ee667040
2025-09-28 18:25:59 +00:00
stephan 436c8e5026 Remove the long-defunct wasmfs build of speedtest1 from index.html and re-enable the wasmfs scratchpad app (which still works). Fix the CFLAGS for the wasmfs build and the path to the wasm file for one of the JS.
FossilOrigin-Name: acaaf8cce9e780bf937436b4c987ed284aa0bba6f5ca9508d9dbad598af2991d
2025-09-28 18:03:29 +00:00
drh 1bf80f2dce Minor bug fixes. Many new test cases.
FossilOrigin-Name: 86dcc68d1816d970d8d5fb158696c3fe6c5ddcac2c255823110d656372503885
2025-09-28 17:24:42 +00:00
stephan 39bffbcd32 Use new c-pp features to simplify generation of the tester1 family of files.
FossilOrigin-Name: f7cab028c97b2c9ac9b561a4c33475aadd3f71cbd48ec4dd6e09c1bb19ec00cb
2025-09-28 12:47:09 +00:00
drh d3cd2a25b4 All legacy tests are passing. Want to add new test cases before merging.
FossilOrigin-Name: adb80761d2319e16b6db2b5e35fedc239fad0ed5d26d629a5ea659c90881f76a
2025-09-28 11:01:05 +00:00
drh 9ffb344ed9 The generate_series rewrite is working better now, but is still not
completely correct.

FossilOrigin-Name: 6c41d14707e6890ca6d0460c72178ccb710d7f41dead76f222f1382c5cbd5a9a
2025-09-28 10:36:23 +00:00
drh 5b047a8ec6 Refactor the generate_series extension. Compiles but does not yet work.
FossilOrigin-Name: 25e395a82f14513bf23c1e913fe24be77ad74fec1540f524e709f9cdfeb3dc56
2025-09-28 09:25:07 +00:00
drh c2f7be11bb Fix harmless typo in a comment.
FossilOrigin-Name: 1f6deabfff2fc2fed5fbff48d2637b48245e5a946a442c4bcc9b9ecb7c4848b9
2025-09-28 08:59:16 +00:00
stephan 1d592e0d62 Internal js/wasm tooling doc updates.
FossilOrigin-Name: 0d6ed44278a513b062539f32da49fa43952fcdf0bc1bba7b24ef3749bc4525a5
2025-09-28 02:30:25 +00:00
stephan 0b0c8734f3 Improve #if support in, and add #assert to, c-pp. Rename target=... preprocessor symbols to target:... because changes in the semantics for symbols which have an '=' makes some of those #if blocks mutually exclusive (which we won't want in rare cases involving the bundler-friendly builds).
FossilOrigin-Name: 54287487793d48f6dde919446ab7476aea0cc0aba3835c80f060a7b84221881a
2025-09-28 00:53:00 +00:00
drh 54f296389c Rework the bounds calculations on generate_series() in an attempt to
avoid signed integer overflow when the bounds are ridiculous values.

FossilOrigin-Name: 3d9148c7d7379a34a0c2a33a1eb2562234868bc0b14c3d16990b33e52fd4ebc5
2025-09-27 15:03:11 +00:00
stephan 41549103ac ext/wasm/c-pp.c: add #savepoint support. Consolidate how the diverse sqlite3_stmt handles are managed.
FossilOrigin-Name: b44650f907e9cb4ec908bb7525488e309946fac9d84cdac4cdde730527a440a9
2025-09-27 13:34:02 +00:00
drh c090488133 Use sqlite3_malloc64() and sqlite3_realloc64() everywhere in the CLI.
FossilOrigin-Name: b05c47009120840f74955114082f3a9c1206a81bd935a503fc359b5bde61c996
2025-09-27 13:00:37 +00:00
drh 943324c80d Fix a bug in the ".dbtotxt" command of the CLI that causes a NULL pointer
dereference if run on an in-memory database.

FossilOrigin-Name: 865352499223c3bdc5cb01a2f984d6e3fe74a028ab6a0cf2d92fec49383633f6
2025-09-27 12:35:25 +00:00
drh 18af487597 Avoid integer overflow in memory allocation for the
".import --csv" command in the CLI.

FossilOrigin-Name: a8093d45e0f59fd55ea4cba515e9e2eb3683bb0a4f4c062747cfb4074ae3db73
2025-09-27 12:29:28 +00:00
drh 15e4074084 Additional cleanup and refinement of the regexp.c extension.
FossilOrigin-Name: 2b34b750b5528b6dda195bc1a3895dc3fe46e70cbf992a78111316e2726c1ade
2025-09-27 11:54:49 +00:00
stephan 4ac2118c5d Teach c-pp how to replace configure-script-like @tokens@, giving us a much simpler way to get the proper WASM file name injected into each JS build.
FossilOrigin-Name: ffd5c8eaa89250a043b573c3eb66693dfec087a5b5eef184ae6d7bfbcf61235a
2025-09-27 11:38:35 +00:00
stephan 4bdfae9d40 Remove and edit some comments.
FossilOrigin-Name: 1fa7e32d264f8329a8c9b0b5b469f1fc7ccadee86696d65e05df7fa3868af158
2025-09-27 00:07:25 +00:00
stephan 5d0d30ae2d Add wasm.ptr to the module-symbols.html output.
FossilOrigin-Name: dced5a7c434b83553ede533f71e3133450795c12fc67acd1a55fdedfa8fed76c
2025-09-27 00:05:13 +00:00
stephan 836e895f9e Latest upstream c-pp.c for the ability to process multiple inputs and outputs in a single invocation.
FossilOrigin-Name: c7633373046ceb94f293b8fbd4f436a1eb281c2744d97334c6e7e3a803d8eac2
2025-09-27 00:04:28 +00:00
stephan 879066a0a2 Delay replacing the wasm file name strings until they're needed. Add target b-all to run all known wasm builds.
FossilOrigin-Name: a4edaecc9b0b649df53a99e05d9abfbc5bdb40d45c7c6940a50b24fa30dca158
2025-09-26 19:41:07 +00:00
stephan e309de27f9 Consolidate some duplicate code in mkwasmbuilds.c.
FossilOrigin-Name: 1078aa4f1e5685d45e31eea622865ddd077f367f1cec90fc267e8ba50cbe2ee9
2025-09-26 19:30:34 +00:00
stephan a34f87d25a Clean up how the speedtest1 64-bit test/demo files are generated. Make log output very slightly less verbose.
FossilOrigin-Name: 64715e92708e4f8c5b82c1f4ed71b75f418bf741f7f05516eab309582fbfad2b
2025-09-26 19:19:35 +00:00
stephan 42f9273da2 Get 64-bit builds of speedtest1.wasm running in order to better compare 32-/64-bit performance (spoiler alert: the latter is consistently roughly 10% slower). Add WASM heap usage info to speedtest1.
FossilOrigin-Name: 70b944cc0189309c2265b184381f2f050bced7b83f204d57b912def6e203982a
2025-09-26 18:29:00 +00:00
stephan 96c753ec56 Reinstate the Module.instantiateWasm() override and simplify how the wasm filename gets injected into the JS files.
FossilOrigin-Name: e878ffd2eaa87e2978c44fcd03a1eb6114a9ae31e31101898d682f43cf81000f
2025-09-26 17:11:39 +00:00
drh b62c26d999 Limit the complexity of a REGEXP pattern using SQLITE_LIMIT_LIKE_PATTERN_LENGTH
FossilOrigin-Name: 869c968569b09d05a5b7d587d8fddb3b4611daf7467dc157701e5dc6c9608606
2025-09-26 15:38:52 +00:00
drh 80d74f0934 In the regexp extension, limit the maximum value of integers in the
"{p,q}" syntax, as performance of the NFA used to do pattern matching
is linear in the maximum such integer.  The limit is SQLITE_MAX_REGEXP_REPEAT
which defaults to 999.  This helps to prevent DoS attacks in systems that
make use of the regexp extension.

FossilOrigin-Name: 911c745f88c0ee8569e67bbcbbab034264f8c981b505aadac3ce7289486a1a68
2025-09-26 13:14:20 +00:00
stephan 3a94a00768 Get wasmfs build working in the new setup. Disable the custom wasm loader because its generated makefile code is currently broken.
FossilOrigin-Name: 36bc2514f70af5608aa20903d9c38b316603e2f78f2cbf4a20c7c79b60c5b8d5
2025-09-26 12:49:41 +00:00
drh 8d2f3a1f82 Fix harmless integer overflows caused by over-sized integer constants in
the "{m,n}" syntax of the regexp extension.

FossilOrigin-Name: 8f17e1d869685b51f3368feed03dc06543ec16bc8fd81b8daad2ac2dbf99c5d6
2025-09-26 11:53:54 +00:00
stephan c839ea5d94 Docs and dead code removal in mkwasmbuilds.c.
FossilOrigin-Name: d022ee167b90a7c32049a93d476e869270018017f60551185024409730d77640
2025-09-26 11:47:13 +00:00
dan 6553a5d6a6 Fix some integer overflow problems when handling corrupt hexdb dumps in the shell tool. [forum:/forumpost/82b513b116 | Forum post 82b513b116].
FossilOrigin-Name: 730323f95d126162fd2867dbee1e1f1fc1d6e05b8a905a6767c4ab1cb43dacff
2025-09-26 11:45:13 +00:00
drh c9f1759c94 Add new table-valued functions jsonb_each() and jsonb_tree() that work just
like json_each() and json_tree() except that the "value" column is JSONB
instead of JSON text when the "type" is 'object' or 'array'.

FossilOrigin-Name: dfc41cb3aad7fedd834baaaba0d8e3aeb55a249af4f0934397652ea9c59dc9fc
2025-09-26 11:36:10 +00:00
drh a7a8d7fa87 Fix a harmless compiler warning.
FossilOrigin-Name: c50a3c45a20e5b9d48e749818bea06dfa99b729535e0617347c6ece1d277a447
2025-09-26 11:28:01 +00:00
stephan e040128ecd In c-pp.c, use (void)x instead of an empty if(x){} to flag unused arguments.
FossilOrigin-Name: df9ab8a35517e3a2baf4b19d07d46ce3f8b48043ccdeadef22bffc12e80461c3
2025-09-26 11:14:15 +00:00
drh 92f93556e5 On-demand loading of JSON virtual tables.
FossilOrigin-Name: 118f97ddcd8f888715825a623c02d42b92a82737a316f7bee4cd66f570945346
2025-09-26 10:29:07 +00:00
stephan 5ace5e0a38 More build docs. Add a speedtest1 64-bit build but it's not hooked up to any test apps yet. Improve invalid-arg detection in c-pp.
FossilOrigin-Name: 69086be8a155d70d9dd7b655b66809250b24fe6d5bcdc6cb5e0275446a43f51d
2025-09-26 02:18:28 +00:00
stephan c1254430d8 Build cleanups and dead code removal.
FossilOrigin-Name: b516109e5accc885b71900402c800ae855407552648861334c895f0e5dea4ee5
2025-09-26 01:38:07 +00:00
drh 3574ec40a6 Add JSON table-valued functions jsonb_each() and jsonb_tree().
FossilOrigin-Name: 2f8b461c636ce2c0e7970c00d1e6ea62cdef72273150fea6aabe4e9292724977
2025-09-25 23:32:23 +00:00
dan 51e3a140c9 Include writes to temp files by sort operations in the SQLITE_DBSTATUS_SPILL values.
FossilOrigin-Name: 4c1118ba40172af61d9304dec7a9c7344566e6a5963a317880ad232bebb40176
2025-09-25 19:32:29 +00:00
stephan ae48a2463b wasm dist: add --snapshot flag, add -64 flag to include 64-bit builds, and add module-symbols.html to the dist.
FossilOrigin-Name: e9a6391b377b6964620285192262a4dc9fe1712799f7aa8a8b37c5f718544ed2
2025-09-25 18:53:28 +00:00
stephan 3e7fe489e2 Replace ext/wasm/dist.make with mkdist.sh and get dist working with the new build. Fix the preprocessing flags for tester1-esm.html.
FossilOrigin-Name: ab6eb4d3b723107da488770b1849b9f1d1c491348f1eaa544e0e07356b8fac7d
2025-09-25 17:29:12 +00:00
stephan a4476ea1fa Overhaul the wasm build to (A) support more coexisting variants, e.g. 32/64-bit of both vanilla and esm, and (B) build each variant to its own subdir so that they can build in parallel. It can, with make -j4, now build all new variants in half the time it previously took for just the 32-bit builds. The new build logging output, though unconventional, serves two purposes: (A) improve my build-time situational awareness and (B) it help demystify some of the build steps and output files.
FossilOrigin-Name: 2f4be98614b49def2c2951887796c736269ef3bb7ba5b045cae5f748ae165a83
2025-09-25 15:17:58 +00:00
drh 5ad6e7b0e0 Fix the translation of "\v" in JSON5.
[forum:/forumpost/28e21085f9c6a4e7|Forum post 28e21085f9].

FossilOrigin-Name: 2914e8fc7b10e8b42c9a0fbd0e71f495714cee3cae67b8c238d37b1e7ec22359
2025-09-25 15:06:57 +00:00
stephan 5dbbbf4923 Remove some superfluous tabs and add the mkwasmbuilds ability to emit just its prologue.
FossilOrigin-Name: 75079401753778e3bc2f7fa307de9217e8d1ec395079fc1009060f707be32943
2025-09-25 14:44:03 +00:00
stephan 96d39ce7d2 Minor logging fix for the wasm-opt build step.
FossilOrigin-Name: 918eca02d162cfa98613f9d8d9b0901f9f94ae1bcb53d811b09baec6c3f06bbe
2025-09-25 14:39:41 +00:00
stephan 653e32e9a1 Move fiddle.make into the main makefile. Various adjacent cleanups and docs.
FossilOrigin-Name: fabd6160d0c128592ce512b1160dfa0b89b1fbb03e11cd185c6a4888a85cc7fb
2025-09-25 14:29:47 +00:00
dan 31efe5a0f2 Avoid an integer overflow in the shell tool when outputing hex dumps of blobs greater than 1GB in size.
FossilOrigin-Name: 4a1bb874f12adda26e91970b64e700cb904c126412989be4debac9a5647d6f69
2025-09-25 11:10:55 +00:00
drh dc868ef879 Convert the ShellText object in the CLI to use sqlite3_malloc64() rather than
plain malloc().  Avoid unnecessary quoting of table names in .dump output
and similar.  Improved detection of OOM in set_table_name().

FossilOrigin-Name: 6ce4f6dc15a575c318669051fe6590ad114b52ff3f3e260cdf7accccdd922d63
2025-09-25 10:55:54 +00:00
dan 4d488bd341 Avoid an integer overflow ([forum:/forumpost/b3abe06121 | forum post b3abe06121]) and a compiler warning ([forum:/forumpost/3db6aa9ed6 | forum post 3db6aa9ed6]) in the shell tool code.
FossilOrigin-Name: 39925489b347ec3126389c6dba1ee719373e50c6cea6944384a212c3a3e163d2
2025-09-25 10:50:11 +00:00
stephan 3ed76ca35b Minor build cleanups.
FossilOrigin-Name: 05e7ea021388fcac975779cd2a70e341e25670e70d1d9f372f15b823b2466750
2025-09-25 02:30:55 +00:00
stephan 99cb0049ee Consolidate the speedtest1 wasm build into the new mkwasmbuilds.c model. Remove the long-unused batch-runner JS tools.
FossilOrigin-Name: 980c033c05bf37c0e8f5e82486ee99ba1294cc9c9e2087aaf83b64e5d0118b5f
2025-09-25 02:02:48 +00:00
stephan ef565295f5 Wasm build deps fixes.
FossilOrigin-Name: fd0c649047f4e444ea682138a3555a973839627150e1124bb9d9ced17880a9e5
2025-09-25 00:53:30 +00:00
stephan 9daf58ee8d Move the static makefile code from mkwamsbuilds.c into the makefile. Move util.make back into the main makefile. Remove a bunch of dead makefile code and docs.
FossilOrigin-Name: 18beeb26bfa48f806866e0e330024535adabcf668071abc4b6251eb39de2701d
2025-09-24 23:07:45 +00:00
stephan 3675a69f1d Cosmetic makefile tweaks.
FossilOrigin-Name: 4ec7e6800e090f7e17469a77bc37b57d3e1777171a5b354dfc68345416de504f
2025-09-24 20:53:19 +00:00
drh 9444c29094 Fix the makefile so that "<tt>test/testrunner.tcl release --buildonly</tt>"
works on mac.  Apparently broken by [b7751d144330593b].

FossilOrigin-Name: 023365228f3264c53263b649365e7c133d8633010baf6e050fdee044a40454dd
2025-09-24 20:44:33 +00:00
stephan 6d3ae03f1e Get the tester1 worker1/promiser demos building again. Show WASM heap usage in tester1 if.
FossilOrigin-Name: 6691a84872f823c95b0bdc3db8e12d21c9561aa1e1ce1d787a977f2c5ef8225a
2025-09-24 20:39:08 +00:00
drh b8a62d9da7 Add an assert() to fix a harmless compiler warning in the session extension.
FossilOrigin-Name: d77b8ad96c695594668cd7019c7f607fe5efa5474dde0ece8b621051cf88a0b5
2025-09-24 20:09:48 +00:00
drh 1ecc36a2b0 Fix a harmless compiler warning in FTS5.
FossilOrigin-Name: 89f8d02075a7b265b1f0226a0f878903e1dce27ff1ac2e8a2d62d450b9b4ec76
2025-09-24 19:51:07 +00:00
drh 2c88a2ffb5 Rework the set_table_name() function in the CLI to use modern APIs.
[forum:/forumpost/2baa4acd64|Forum post 2baa4acd64].

FossilOrigin-Name: 821cc0e421bc14a68ebaee507e38a900e0c84ff6ba7ee95bf796cad387755232
2025-09-24 19:10:58 +00:00
drh 96bb92e70c Special case the "decimal(-0.0)" output to show exactly 0.0, just as it
does for positive zero. 
[forum:/forumpost/adc719d88d56ab22|Forum post adc719d88].

FossilOrigin-Name: 9ca4163bd93d78be5e4daf2b5d2b920d54d038c6fa8217dd2add0be0da6cd6b0
2025-09-24 17:49:09 +00:00
stephan 892109542b Generate 64-bit variants of tester1.js/html. Enhance c-pp to accept multiple input files.
FossilOrigin-Name: ef6c55e4499957fb46b213540786e5d3928ec096eae1fe759066ed011518e7a2
2025-09-24 17:46:08 +00:00
drh 68353d0531 Fix a harmless compiler warning in IEEE754.
FossilOrigin-Name: 7f72308322cd1f238e6c725ec6bff44ed42fb2619f3f52afe38e2faad838a63f
2025-09-24 17:38:13 +00:00
drh 2abc502ebc Additional short-circuit optimizations for AND/OR operators. Also fix
bugs in prior implementations (such as [0083d5169a46104a]).

FossilOrigin-Name: 63b686fe4cb1d5d82dd3a399aaafd1dfcbda533ca83b46ed2bc2750baa7f251d
2025-09-24 17:07:15 +00:00
drh dc90d7055c Simplification to the AND/OR short-circuit logic.
FossilOrigin-Name: 7be555a3b8500c43c2f30171af26bcda9bcb68f41992b792228218a56315e7c4
2025-09-24 16:26:44 +00:00
dan 2364fe3b38 Improve performance of window function queries that use "BETWEEN :x FOLLOWING AND :y FOLLOWING" where :y is a very large number.
FossilOrigin-Name: 1f0b7143575634929c0f77bafa888f0be2dd83f0c6c3deadd8299ac4ab8a8c01
2025-09-24 16:10:46 +00:00
drh 1f030eac9f Fixes to short-circuit AND/OR evaluation.
FossilOrigin-Name: bc4cadbd60b97d000d2e8be843acab9d82ddf10a8125fd9cc0ae101bb9850091
2025-09-24 14:43:42 +00:00
stephan 36baed3e2e Add docs to mkwasmbuilds.c explaining the purpose of each of the builds. Remove some inadvertent copy/paste hard tabs in some C-side makefile code.
FossilOrigin-Name: a2bd965e103026ff5c722357ed9e3432172bbc19d267e718ebd4a876eca41742
2025-09-24 13:59:53 +00:00
drh ca574fa1d5 Factor out the code that handles AND and OR short-circuiting into a
separate subroutine, for performance and legibility.

FossilOrigin-Name: cab84a65c3825c59f3a7a750f4983563ce7ad007125cbcf35c187326289fea89
2025-09-24 13:10:55 +00:00
drh feeacfb897 Fix incorrect buffer size computation for the base64() extension function.
[forum:/forumpost/b1993c858f|Forum post b1993c858f].

FossilOrigin-Name: 603efcd404f0013559ca5bd936fc39481a3aa33a10340bac27b751b6b286d0b7
2025-09-24 12:01:50 +00:00
drh b927708437 Restrict the size of the LIMIT on a generate_series() query to avoid
an integer overflow when computing the final output value.
[forum:/forumpost/479bfb0d3b|Forum post 479bfb0d3b].

FossilOrigin-Name: 266aacb4759945f7cf7a258014620f21225261246edc08e6e71ff5292baf22f3
2025-09-24 11:12:26 +00:00
stephan 8d93e83461 Cosmetic build tweaks.
FossilOrigin-Name: 431725330d6c63575dbf3404664a7af33d4d87c569560e99c18de93eb4d73935
2025-09-24 07:31:19 +00:00
stephan 205257791c Fix the positioning of the wasm-bare-bones flag init.
FossilOrigin-Name: f5167fb3615efc180e69333f99d82d6afc1d190e7f37b6a701895de00502d8c8
2025-09-24 07:00:37 +00:00
stephan 4500a87c95 In speedtest1, always use fatal_error() to exit fatally, instead of an fprintf/exit() pair, so that stdout/stderr get flushed consistently (which is significant for the WASM build).
FossilOrigin-Name: 1bd15cb343f6ce57f108291a8ed0f3ee2046932591d44edec133fe3ea43a2ef0
2025-09-24 06:59:47 +00:00
stephan 5c01f3fb83 Further wasm build refactoring. Get speedtest1 building again.
FossilOrigin-Name: 5434307dcd927686ce827da22de55020c4b431f888ac81ae3634d458ad0b563d
2025-09-24 06:43:24 +00:00
stephan e779baa099 Move some of the generated wasm makefile utility code out of C and into util.make.
FossilOrigin-Name: a2935758f534b51cac3d2e5ece74b369c806e3a994781744708e1590b9c32542
2025-09-24 04:58:14 +00:00
stephan 3b56f296e9 Generic build simplifications.
FossilOrigin-Name: 61648610c3e454fce77b78e6f6be1b71e27bb9587af03ae5c0e083eac7158a64
2025-09-24 03:05:31 +00:00
stephan 0dee14a559 Get fiddle building properly again and fiddle/fiddle.debug building in parallel.
FossilOrigin-Name: 85fe9c6155f72583cea46d38bf5e040623d71fb5317ff9373421dbfdb179b2b0
2025-09-24 01:50:08 +00:00
drh 9300c4a13c Improved short-circuit evaluation of AND and OR. All appears to work, but
there are still testing and performance issues to be worked out.

FossilOrigin-Name: 0d4447aa61848deecf9170afce031f7b353b91d58474f3f094ce34e46be7f99e
2025-09-24 00:13:28 +00:00
stephan ac37661a16 Get fiddle/fiddle.debug building again but they're incomplete and don't run.
FossilOrigin-Name: d725a075bc3303c5a26c4014f57162235cebc6491425083b4d80936de8f07fb0
2025-09-23 23:22:31 +00:00
drh cac1ef709f Improvements to short-circuit evaluation of AND and OR operators.
This is a partial and incomplete response to
[forum:/forumpost/f5adeb59ff77c056|forum post f5adeb59ff77c056].

FossilOrigin-Name: cea8bf79e18d55a8658e48a967cd0b7970b6f88badb769cfbb1f66ab24fb9ec8
2025-09-23 17:00:53 +00:00
drh 611ffbc981 In the ieee754 extension, render -0.0 as 'ieee754(-1,-3071)' instead of
'ieee754(1,-3071)' as that makes the sign clearer.  Both strings still
convert back to -0.0.  Note that negative zero
and positive zero are distinct values in ieee754.
[forum:/forumpost/1eab7e4a08|Forum post 1eab7e4a08].

FossilOrigin-Name: 136188c161a8a2d5166798fcbd341bd1d3f81da7291011f806d6b2153544832c
2025-09-23 16:01:45 +00:00
stephan cfce9b6a11 Get most of the wasm build (re)working and much prettier.
FossilOrigin-Name: a5a7890c75003a637a227b700dc342f4f4a24bd368b216bdb168b4ddfbe8f015
2025-09-23 13:49:44 +00:00
stephan a07871d332 Cosmetic wasm build tweaks. Fixed wasm-opt use, broken by this branch's refactoring.
FossilOrigin-Name: 4d7eff2afbcf023291bc1133c4413d1ea44f4096bb515e4bcd40bc8fc8d2a591
2025-09-23 10:46:17 +00:00
stephan 5c0850f8b8 Make it easier to pick out which parallel build messages belong to which wasm build.
FossilOrigin-Name: 913af3dd6a8da577ef19b0d82c8afec0c626d7fa5fddbdf418d2eb16c3050ab1
2025-09-23 08:44:07 +00:00
stephan ebb99967c2 More build restructuring.
FossilOrigin-Name: 7bee8ee76380b2c1beb320b55042f149c22f872c70b58461652fa5bcbf6ad3c7
2025-09-23 08:23:23 +00:00
stephan aa5b8f9d47 Create each distinct wasm build into its own dir, instead of all going to in jswasm/sqlite3.wasm, so that the build can now run in parallel.
FossilOrigin-Name: 47526a75f2ad85100b1eae7ab1cf9a9dddd4430a99f7a30aa0c16548d1db9d33
2025-09-23 06:31:24 +00:00
stephan 91b1b0de2b Start reworking the wasm build (again) with an eye towards simplifying it. Currently only the canonical and esm builds work, not fiddle, speedtest, nor the bundler stuff.
FossilOrigin-Name: 102c4a35b86405273d1f7e9e34466c9deed7831099a8207b6f48746b998193f9
2025-09-23 05:10:19 +00:00
stephan 12f17d41f9 Add makefile target '64bit' to ext/wasm/GNUmakefile to build the 64-bit bundles. It does not yet generate copies of the test apps to load/test them, pending other reworking of the build.
FossilOrigin-Name: 3e2ea990ad76f9e68d514568f53eaa692a1eb11695fceb1bcc58cea00605fff9
2025-09-23 02:04:07 +00:00
stephan a8bddde325 Slight correction to the diagram in the previous checkin.
FossilOrigin-Name: 6455af2703e78fb9b6df19cf4b46873d98ec91c3302dc0093a362d03ac48da91
2025-09-23 00:24:58 +00:00
stephan b19c14742d Add a high-level diagram showing how sqlite3.js gets assembled.
FossilOrigin-Name: e0dfa1e62ba6d71abe1f48969eb6f53c83f2c28d47b996ee223587d923cc282f
2025-09-22 23:48:05 +00:00
stephan e55a29f5fd Refactor and simplify the JS API bootstrap steps.
FossilOrigin-Name: a4f36fd93738f985d2c757c69eddca092732ce6148af98eb2595f9abe0d4fa44
2025-09-22 21:04:24 +00:00
stephan cfa48c17f7 Update ext/wasm/api/README.md for recent changes.
FossilOrigin-Name: 03b70686939e5f9ad984220a31674c23a1beb19f040c6327f24e23f0378555da
2025-09-22 18:05:10 +00:00
stephan 1ab3d7eafd Cleanups and docs in the internal parts of the JS lib bootstrapping. More tinkering with the custom (but still disabled) wasm file loader.
FossilOrigin-Name: 35651d9ab5529da915500fc50ca3833a004d0b7a19d98e8fbf39234d94697aec
2025-09-22 17:29:52 +00:00
drh 6ba22a75f3 Revise [a4430d262b3e129d] to preserve legacy behavior of the imposter
test-control.  The control argument must be 2 now to get read-only behavior.
The control argument of 1 goes back to the prior read/write behavior.

FossilOrigin-Name: 3e7ede2e6dc9ac8e746dafe0ecb5379044631e753e951f9ab97ec84addbd830a
2025-09-22 17:28:08 +00:00
stephan 2ea861a245 In wasm.ptr.coerce(), treat the undefined value the same as 0 for Number-type pointers for consistency with the BigInt coercion. The bindings have long treated both null and undefined as === 0 for pointer operations.
FossilOrigin-Name: ef73bb1ddae28c6a0b462a2a840bfaaec3fc70d843e9ab6c53097281ffc85a78
2025-09-22 13:13:02 +00:00
stephan 34d92f4ac6 Minor doc updates. No functional changes.
FossilOrigin-Name: 9c67299b452a2b19b5f4285feb975b30864a9415ccf62b7c7ebb1587a6545b33
2025-09-22 11:52:06 +00:00
stephan 8eefa2725b Rework the JS/WASM pieces for compatibility with both 32-bit and 64-bit WASM environments. This affects only the browser-side components, not the --with-wasi-sdk build nor the core library.
FossilOrigin-Name: 8ac367686fecd2e3ff1f4b4565e9f206a64237744e381704693df2e6efbe235a
2025-09-22 11:41:15 +00:00
dan 65551b5456 Fix a problem with handling of 4-byte utf-8 characters in the shell tool (not the sqlite library). Forum post [forum:/forumpost/184b372388 | 184b372388].
FossilOrigin-Name: f3e845cf38fc364bfa3f8d433b668f884d11286c823d87ee0ed124a991c94e14
2025-09-22 10:48:10 +00:00
stephan 5a2e3c4af2 Experimenting with a custom wasm loader, but don't enable it without an explicit build flag. The goal here is to make the WebAssembly.Module object available internally (the default loader hides it from us).
FossilOrigin-Name: e5f0256feab95c30a8e3e1e69963fb3e25ed2da296aff5bc6646fe96a76c0b81
2025-09-22 02:40:06 +00:00
stephan 1d49644650 Minor internal optimizations in the wasm glue.
FossilOrigin-Name: fb053a27d94f9caedfddf28680e13836343745376e84c8008641df6bb517cd8b
2025-09-21 23:15:12 +00:00
stephan 1e01174ac3 A minor optimization in wasm.realloc().
FossilOrigin-Name: 6a070f450ac9ee3d4d6a3e05ef8fa2071a684181ea160805e236c3bba226510a
2025-09-21 22:17:13 +00:00
stephan 60633a852d Remove some stale makefile comments. Add a little widget to fiddle's toolbar which shows whether it's running in 32- or 64-bit mode. Reduce fiddle's starting memory to 8MB.
FossilOrigin-Name: e99730f96e13f7497a871fdcc5eaa4187835f005a759f0fc79bbfe982f454437
2025-09-21 22:08:05 +00:00
stephan 589855f40e Improve db-close-time cleanup in the face of WASM environments which wrap wasm.exports in nullary wrappers.
FossilOrigin-Name: fbb63634eab83fda0090fe2c38bda735b497fd6e57dd36344559962e396dbb17
2025-09-21 21:37:44 +00:00
stephan e6db55f0e2 Fix a Number/BigInt descrepancy in oo1.DB() when passed a WASM-string db filename. Consolidate some duplicated internal code and adjacent minor cleanups.
FossilOrigin-Name: d078aff7817ccd4f891024e55703519307a53815d472086bf3d42b2be28698b3
2025-09-21 21:17:41 +00:00
stephan 50815f8ba4 Fix a StructType.dispose()/ondispose() memleak in Jaccwabyt bindings in 64-bit builds and update its docs for 64-bit additions. Remove the parts of tester1.js related to skipping specific tests in 64-bit builds.
FossilOrigin-Name: 6baea1d719b0c345fee5f32a3917ce9c507a2d8cb029eaca675daca77f297eba
2025-09-21 20:26:47 +00:00
stephan b10548a7b0 General cleanups and dead code removal.
FossilOrigin-Name: 0336fa95e15c53ac6ab8152a840163a5aac64725874ffb848ce1d95e3af90586
2025-09-21 19:39:06 +00:00
stephan cf0f11ac18 Remove some dead code and stray debug output. Fix (again) the JS SQLTester for 64-bit (the previous build was set to 32-bit).
FossilOrigin-Name: a6b9567001dad0293dc6a7fe9a7ec1a220e41d9426448e2ab91dbd551948be15
2025-09-21 19:01:15 +00:00
stephan 334b15d8fc Update the JS SQLTester for recent sqlite3.wasm changes.
FossilOrigin-Name: 0fa1830540bcb86f5c59b1a6a9ffd8727c194a64a131d9d362023c84a3b820cb
2025-09-21 18:42:25 +00:00
stephan 5b71447e8e Generic cleanups and simplifications in JS code.
FossilOrigin-Name: 074cf4e6c1775900204bb0d920111ee19601d5c63690e79e988e7fe6b040a647
2025-09-21 17:55:23 +00:00
stephan 128ae8ea3f Rename wasm config entry pointerSizeof to pointerSize for consistency with wasm.ptr.size.
FossilOrigin-Name: 2cd8ba740f9b14dc1408b62632c603076b070dc412bf7cbfb3b525f0c4912371
2025-09-21 14:25:29 +00:00
stephan 1e2156e926 Restructure the interface for the sqlite3.wasm pointer-size-dependent details.
FossilOrigin-Name: 8ac12e1f5144380d4ecc8b27a1f62dcda0e5a86409ae7149f62c33caeea19a23
2025-09-21 13:53:59 +00:00
stephan d97c59e2bc Reduce sqlite3.js build size by about 30kb by stripping out Emscripten's makeInvalidEarlyAccess() wrappers.
FossilOrigin-Name: a65bd978cbc646ec687ebcfc736a968e0597062251b2155caab42bca2d36f1e9
2025-09-21 11:49:23 +00:00
stephan 72d81265ab Reduce sqlite3.js build size by about 30kb by stripping out Emscripten's makeInvalidEarlyAccess() wrappers.
FossilOrigin-Name: 9fafe075d6f4c49fca45963b142f3e0f0e60d79cb462b7e24f9ed0b9a9677f28
2025-09-21 11:47:06 +00:00
stephan 23203a407e Remove some dead code.
FossilOrigin-Name: 1c2cd58d1a86d85e79ac912270e762e22f43f1d41d81a19ecd0ae6b2656c71b4
2025-09-21 11:39:53 +00:00
stephan ba6527af04 Minor cleanup in sqlite3.wasm.ptrAdd().
FossilOrigin-Name: f659595d2e9e019a77d0c86803dbeb4bd728221a665825896ec29f7c0c0bdc65
2025-09-21 11:15:00 +00:00
stephan f568a2f1bf Remove some fiddle debug output.
FossilOrigin-Name: c7cc374ff5ccd8b8f0a6cd0acada2a713626b5447cf014db12e18327fccfd36b
2025-09-21 01:03:16 +00:00
stephan 51127416a4 Resolve the non-functional 64-bit JS vtabs and VFSes. All wasm tests now pass on a 64-bit build. Investigation of the fiddle failure on a second db import is still pending.
FossilOrigin-Name: 7c44b48b628d3d93b13031e9fd08ed39fec35c661aca9e813a89348d6c415663
2025-09-21 00:59:23 +00:00
stephan d1b64404b3 Determine the WASM environment's pointer size at runtime instead of baking it in at build-time via the preprocessor.
FossilOrigin-Name: 21ac6aaa03517841b637924720354b9800d6e8b7bd5f6ee54a99f5f45b2ccdec
2025-09-20 23:21:24 +00:00
stephan 2674a4fdcb Add missing sqlite3_vtab::xIntegrity wasm mapping. Correct signatures for the (unused) xDlOpen and xDlError bindings. Disable OPFS-related tests in tester1.js in 64-bit builds.
FossilOrigin-Name: dccfa7098975d8c09eb6e7d30cd2ae30bc8234ef9a24f4a2ad5e9ffd29df72c2
2025-09-20 22:11:19 +00:00
stephan 3e205eff8e Add missing sqlite3_vtab::xIntegrity wasm mapping. Correct signatures for the (unused) xDlOpen and xDlError bindings. Disable OPFS-related tests in tester1.js in 64-bit builds.
FossilOrigin-Name: a106be90a2dba7476e54dbb4bdf47d0999031dae0ca82d73e51a48dadd6bcdc0
2025-09-20 22:10:59 +00:00
stephan 25e416dc3a Reinstate the working-again commit/rollback/update hook tests. The bug breaking those was the one-letter change at the top of this diff.
FossilOrigin-Name: c582513a77cd1d1d9479e5a4518ddf15ef5a213bed1bfb6af9bd21bf3be41f8a
2025-09-20 21:03:28 +00:00
stephan 7462b3749a Further tweaks towards 64-bit wasm. Fiddle is failing intermittently from the C level when importing a db and it's not yet clear what's happening there.
FossilOrigin-Name: 9fd82ebe31993c11e61a47205b7fc17a28283ec96cf278df1b6ea8a196d1fcb1
2025-09-20 20:23:59 +00:00
stephan 043136276a Get speedtest1's wasm build working.
FossilOrigin-Name: 2a61e3f1ccb1c2f115377d33af7d84d158b06c462e482fbbddf35c56d1fb58d8
2025-09-20 20:19:18 +00:00
stephan 93cd069fdf Improve deps handling of fiddle's gzipped output files to help avoid stale gz files during development (althttpd will prefer those over the uncompressed ones). Only compress the larger files, not the small html/js pieces.
FossilOrigin-Name: bb945f52909caa2577de38711883a79ca918b3716e5e0c2fed6e6ef12e19aeef
2025-09-20 20:17:17 +00:00
stephan 832dfd97d1 Get all but 3 of the tester1.js test groups running in 64-bit builds. The outliers are virtual tables and commit/rollback/update hooks.
FossilOrigin-Name: c135d9743698b3331e56f72160e2b78840aa2c8fa1a70daea9d4a0952dbda186
2025-09-20 18:51:10 +00:00
stephan a8756afdbc Get several hundred more lines of tester1.js running in 64-bit mode.
FossilOrigin-Name: f5105ee5defa042508a68a1f4e23b9fff46a1697b1a727e01c3edea3030fbcb5
2025-09-20 17:11:57 +00:00
stephan a2daecfc8c Further work on 64-bit WASM builds. It now gets through just shy of half of tester1.js.
FossilOrigin-Name: c8deed31365898e1379d577298fc80ef08a5531999d5b54a9f14337febed0260
2025-09-20 15:16:55 +00:00
dan cbefdaad9e If the file-system supports f2fs style atomic-writes, sync the directory after deleting a journal file in journal_mode=DELETE mode in synchronous=NORMAL or synchronous=FULL modes (as well as synchronous=EXTRA).
FossilOrigin-Name: e24b21699644a5b49181f2e63961b6a3fccb85605d0b6d109a6043341c194d99
2025-09-20 14:48:08 +00:00
drh 65a445d750 Fix the decimal_cmp() extension function to give correct results in
corner cases such as negative zero and two equivalent values where one
has extra trailing zeros to the right of the decimal point.
[forum:/forumpost/367c770224|Forum post 367c770224].

FossilOrigin-Name: 25b3626a018fa5916d0e129ee057c3f709c6e4d0b84a1a3102cad127a39a3db9
2025-09-20 14:32:12 +00:00
stephan bd5d297fec Get the wasm tests running in a 64-bit build up through (but not including) the oo1 bits.
FossilOrigin-Name: a5af46174a05e1414370884d1a99827af9286a60eff1c8ae1551e7fad3903f7a
2025-09-20 11:09:20 +00:00
stephan 22f9ca64db Get about 1/3rd of the tests running with MEMORY64=1, but the code noise level added by the BigInt/Number discrepancy is making this very unattractive. There are apparently irreconcilable differences between MEMORY64=1 and 2, in that they have different argument type expectations for methods such as WebAssembly.Table.get(), where MEMORY64=1 requires a BigInt a MEMORY64=2 requires a Number. We have no way to make that distinction from the JS code, and don't know what other APIs are affected by that quirk.
FossilOrigin-Name: 1e3b003ff99d2788d93e179504b711cb78846605774bf472589440d0136f20fa
2025-09-20 03:02:36 +00:00
stephan 6a03f2029b Baby steps towards 64-bit pointers. Get it building and testing again in 32-bit builds.
FossilOrigin-Name: f35bb66e3eb939d321afb3545c184013633ce35fa4cbd67b6be17a64997ece9d
2025-09-20 00:43:47 +00:00
stephan d6403a2d2e Initial experimentation with a -sMEMORY64=1 wasm build (full 64-bit). This compiles but does not pass tests due to friction between BigInt and Number types (e.g. Number(null)===0 but BigInt(null) throws, many functions are fussy about which of those types they'll take, and we cannot simply mix and match the two types transparently (1n+1 is not legal (but 1n>=1 is), so we can no longer do pointer arithmatic without hoop-jumping)). The library bootstraps but it's failing early on in tests due to this friction.
FossilOrigin-Name: cfd5c746a6111f49c9c83a56c3ef65223456306f2de6e20b36b1ca0c98b593e9
2025-09-19 23:21:00 +00:00
stephan 78202b9a3b Add some comments describing the ways in which building sqlite3.wasm with -sMEMORY64=(non-zero) fails.
FossilOrigin-Name: 0b14fd35ca37075bb65b2ab398f3324dc851347b1c042566eac23724013653f8
2025-09-19 20:10:05 +00:00
stephan a09a8ffa62 Initial build-side tweaks to pave the way for a 64-bit WASM build. Such a build does not yet work for reasons given in the makefile comments, but is an eventual goal.
FossilOrigin-Name: fe2e1681b6dac81508ab67d1247e1f92018c9998386789846d1715c2cc13d6a8
2025-09-19 19:28:13 +00:00
drh 723e8c88fa Improve imposter tables: (1) Read-only unless writeable_schema=ON
(2) --unsafe-testing no longer required (3) Does not interfere with
PRAGMA integrity_check.

FossilOrigin-Name: a4430d262b3e129d7f00be1661af563907d7b2e98560a9847cd399129f91247b
2025-09-19 17:33:29 +00:00
stephan d4cc844a2b Diverse cleanups and docs in the JS and kvvfs pieces. Functional changes: (A) ensure that the 'i32' JS/WASM func arg/result conversion works properly with a 64-bit-memory WASM build (which we neither use nor test but [https://webassembly.org/news/2025-09-17-wasm-3.0/ | the newly-ratified WASM 3.0] brings within potential reach). (B) Fix sqlite3_js_posix_create_file() to not deallocate its input array if the client passes in raw memory (the library has never used it that way but the API permits it).
FossilOrigin-Name: 79af65a694fbbb3d501fb2ebd835c259ca644e0dafdd71eeb9f0a7c0e9128a1e
2025-09-19 17:24:47 +00:00
drh 49a37f333a Improvements to imposter tables: (1) They are read-only unless writable-schema
is enabled.  (2) Because they are now read-only, the ".imposter" command
in the CLI no longer requires the --unsafe-testing command-line option.
(3) Imposter tables do not participate in a PRAGMA integrity_check and hence
do not cause false-positive errors.  However, you can still do an
integrity_check on the the imposter table itself by naming the imposter
table as the argument to integrity_check.

FossilOrigin-Name: ad152ddc4bcf6cfe840b9a36ab76a5ec36afdb1dd96eb7697e4b3df1bf63b00d
2025-09-19 17:24:12 +00:00
stephan 194d6edeb6 Wasm: (A) diverse internal doc updates. (B) when generating automated JS-to-WASM function proxies for converters which require an additional middle-man proxy, e.g. sqlite3_exec(), use the client-provided function, not the proxy function, as the cache key, to keep from re-generating the conversion in some common use patterns.
FossilOrigin-Name: 5e5139c2a162562cee0071d03954ebc0b8938da0b045ec3f5eba32dc8e19604d
2025-09-19 14:21:09 +00:00
drh e7fe1d3b3e Fix typo in the name of the CursorHints optimization in the CLI.
FossilOrigin-Name: 468a11fd415710042b23880772f6c2c7771008208823fe3b554227a9244dbf92
2025-09-19 09:18:22 +00:00
drh f5dc671a57 Fix a harmless compiler warning.
FossilOrigin-Name: 42c225a2ed7fc95f9b01467c64ba2bf97bca216fdcd6ab1ba3fb49c068650de9
2025-09-19 01:17:44 +00:00
drh e7efe1e201 Fix the new walckptnoop.test test module so that it works in various
alignments.

FossilOrigin-Name: 08689dacc1237a2b90dff4d32186b28054214f709dbff9e07057d3175c1c423a
2025-09-18 23:23:50 +00:00
drh 8f5503861f Try to make the carray extension easier to compile on VxWorks.
FossilOrigin-Name: 1a34c3f49ec48b551098f6781a3a6355aa3c9fd47fd9ebaef01f254b1dcafc9d
2025-09-18 19:59:56 +00:00
drh 7cbfa5b0d1 Include I/O consumed by ephermeral cursors in the SQLITE_DBSTATUS_SPILL
values.  Still need to add sorter.

FossilOrigin-Name: 118905b26a96825433f79b47fd3e7c2bdb137d84292fb9419e4436a961a9833a
2025-09-18 18:56:55 +00:00
drh 3312564540 Fix harmless compiler warning in the CLI.
[forum:/forumpost/ffdcdaba19|Forum post ffdcdaba19].

FossilOrigin-Name: 1626b6082d06c6fd66ff0a6d9fb3641c936ee8db326275e4fddfecf172c5a6eb
2025-09-18 16:48:37 +00:00
drh 16eedfbdda Initial implementation of SQLITE_DBSTATUS_SPILL. Does not yet take into
account sorters or transient tables.

FossilOrigin-Name: 4e63ee20f80e486ecc4aa4523afa43f994c267e638f8f084f0d6df369aa74a1d
2025-09-18 14:51:23 +00:00
stephan 9290d70466 Improve the quote-stripping when importing a db into fiddle, as reported in [forum:264050a3f3 | forum post 264050a3f3].
FossilOrigin-Name: 1a87c16fddf174380deba9bbe58079328baf9f9ca95210f63bc628e3ef3eeb26
2025-09-17 20:05:12 +00:00
drh 3e17953beb Add the sqlite3_db_status64() interface.
FossilOrigin-Name: bb5b982dba774e6b8011e6c980d34131c378967fadc59a18fed1cefda596449a
2025-09-17 19:19:52 +00:00
drh ac28cc30c0 Remove newly unreachable code in the solver of the query planner.
FossilOrigin-Name: 9abaa0ac2b3049341f36ff683ff6eebb589698bd910624aa24f11398d557b3c2
2025-09-17 17:09:07 +00:00
drh 12ed2fea03 In the date/time functions, a timezone suffix of "+00:00" should work
the same as "Z".
[forum:/forumpost/2025-09-17T10:12:14z|Forum post 2025-09-17T10:12:14z].

FossilOrigin-Name: 3b7a5babf0843c4b3ce93d26f1447218585ce645ec3acd942ac649204e16675a
2025-09-17 14:55:47 +00:00
dan a12c1dcca6 If the file-system supports f2fs style atomic-writes, sync the directory after deleting a journal file in journal_mode=DELETE mode in synchronous=NORMAL or synchronous=FULL modes (as well as synchronous=EXTRA).
FossilOrigin-Name: c1e37cb70a8e93368c19ba0fdb987f0616abac028e3541d793a4e6f005b0e513
2025-09-16 19:52:12 +00:00
dan 48790b48a7 Updates to where.c to handle vtabs in joins more similarly to regular tables.
FossilOrigin-Name: 9138223013505d3e0f1f2b40b51d521184aabd50732fdf4f6bed393cfa9475fc
2025-09-15 17:06:35 +00:00
dan e924087d30 Merge latest trunk with this branch.
FossilOrigin-Name: 0bb8c42951ed4fcda60f195b9cc84c80d5b8c0ff77c7517243708f43ba09cfdd
2025-09-15 16:09:54 +00:00
stephan c35f07ec2f Diverse internal cleanups in the JS/WASM pieces. A potential fix for a hypothetical db-close-time resource leak of a subset of automated JS-to-WASM function conversions in Safari. That browser exposes WASM-exported functions via nullary wrappers, which causes a handful of them to misbehave (not clean up) at sqlite3_close_v2()-time.
FossilOrigin-Name: fabbc8b6d184d52a513e80fabd900f578424fc8a8055e3d64fac54b9e28ea18a
2025-09-15 14:11:55 +00:00
stephan 36595d0630 Expose sqlite3_set_errmsg() to the JNI bindings.
FossilOrigin-Name: 292866a46948e8d707bd14864fd1b40eec1bd2e22dcd249ec94711b646c8a70b
2025-09-14 12:55:57 +00:00
stephan 6b8d7ac599 Expose the new sqlite3_set_errmsg() to wasm. Refactor JS's sqlite3__wasm_db_error() to wrap that instead of the WASM-specific routine which previously did that job. This resolves the TODO added in [ead8a3a94e].
FossilOrigin-Name: e447a50f3a3791c264a68000948daa64edb1857d51d256fbd1ff0f2c2b330d5e
2025-09-14 12:14:42 +00:00
dan 0247e15f69 Updates to where.c to handle vtabs in joins more similarly to regular tables.
FossilOrigin-Name: 991383262b0d07ebc79fdb6bed448013cea3a0ac13292d5397dce012b1e6a673
2025-09-13 19:23:12 +00:00
drh c7cb05813c Initialize the sqlite3_set_errmsg entry on the loadable extension thunk.
Also fix a harmless compiler warning in sqlite_dbpage.

FossilOrigin-Name: 031a43ae2bb06adefb3f66bf7d1cdae0020b25a1eeee7c3a3dd4447014b9d3f7
2025-09-13 18:28:34 +00:00
drh 419b93adbf Add --enable-dbstat and --enable-dbpage options to configure. Fix the
".dbtotxt" command in the CLI so that it uses the correct filename of
the database it is rendering as text.

FossilOrigin-Name: e04e6e681891020f78237fa6dc11bc2e2022c569b04ac96cb333bf59f1662cd1
2025-09-13 18:15:26 +00:00
drh 96455af950 Enhance the integerValue() routine in the CLI so that when its text input
specifies an out-of-range integer, the routine returns the nearest integer
that is representable as 64-bit twos-complement.

FossilOrigin-Name: 5d50279fcb66b479e76586b729f36d389b28940476ff70d61b0066a5d5d3ad0c
2025-09-13 17:53:14 +00:00
stephan a248d84fbe Add a TODO regarding replacing the internal sqlite3__wasm_db_error() with the new [34eda113c8819d | sqlite3_set_errmsg()], which serves the same role.
FossilOrigin-Name: ead8a3a94e0f349bcdced6a62af0349b0b7b731137c8d33e2ef0e7eecd107c1f
2025-09-12 17:36:23 +00:00
dan 2c4008fe26 Add sqlite3_set_errmsg(). Use this in sqlite3changeset_apply() to return any error code and error message via the SQLite handle.
FossilOrigin-Name: e34eda113c8819df46c139ccf749b686c8bfdd399f59345c6d6be3736bdf97cb
2025-09-12 17:13:59 +00:00
drh 195956af94 Typo fixes. Make sqlite3_set_errmsg() accessible to run-time loadable
extensions.

FossilOrigin-Name: 93a41e31322eec70476f7d81f4af7fb8476cad21a56d6b1048a9e0c0c440bf72
2025-09-12 15:31:33 +00:00
drh 28a7f01f90 Add more details to comments in the previous check-in.
FossilOrigin-Name: ed36b3aa4b68c6bb347b6851ea61bcad9712c4a9ed39e3fb4f84cb9b9ee48dc2
2025-09-12 15:20:39 +00:00
dan d968525382 Add experimental API sqlite3_set_errmsg(). Use this in sqlite3changeset_apply() to return any error code and error message via the SQLite handle.
FossilOrigin-Name: 4d5b60a1e57448f03af2a657fe7cdabb04ebaf9688d5cc700dd8f9892a5cba15
2025-09-12 15:02:47 +00:00
drh eb8089ef46 Fix an off-by-one error in sqlite3_rsync.
[forum:/info/46753431d4|Forum post 46753431d4].

FossilOrigin-Name: ef3b7be6f2037871f6f1b1944fed3dda28216e7f179080d3be2e2620c031f48c
2025-09-11 10:58:49 +00:00
drh 9455a6e8b8 Improved support for VxWorks.
FossilOrigin-Name: 5bc6b9352236df3091ee69b947d0c397264156539d13e5968ec3b9a6e55dc800
2025-09-11 10:43:57 +00:00
drh 56d831e064 Fix a harmless compiler warning in the CLI. Gcc generates identical
machine code before and after this change.
[forum:/forumpost/8bda0d896f|Forum post 8bda0d896f].

FossilOrigin-Name: dbca4fe34467653d083de42d0c75746cf171e96ee3867abe67a47ab88437fa71
2025-09-11 10:37:01 +00:00
stephan 7754f53045 Latest upstream autosetup, with project-local s/--debug/--autodebug-debug/ patch, for HP-UX-specific config bootstrapping code and latest jimsh.
FossilOrigin-Name: 1d2352a16cc0990037710b4a666f2f3b039c1973e0af29990d67d70bcdba0600
2025-09-11 10:14:10 +00:00
stephan 4619855103 Configure script portability improvements for HP-UX builds, with the help of HP-UX sysadmin Michael Osipov.
FossilOrigin-Name: 93cf2afa8ca529784f859da2f015bce3a251b23dafa6ca3d1db644a91969e237
2025-09-11 10:09:43 +00:00
stephan be4cf645a8 In mkautoconfamal.sh use $MAKE if it's set so that it can be made to work on platforms where 'make' from the PATH is not usable, e.g. HP-UX's standard make. This means that 'make snapshot-tarball' will inherit that value from the outer makefile and set it appropriate when the in-use make is named gmake.
FossilOrigin-Name: a8635cae05d2bce28d0c0c39b599cf8ca6f3b89b114fbeef519a8024692180c5
2025-09-11 10:08:19 +00:00
drh 065daf24b4 Minor #ifdef changes to the carray.c extension so that the source file can
be more easily imported into a larger program (such as TH3).

FossilOrigin-Name: f16fd1afbb65f88d7b94c2488ddd59549d71894ab5fcee46b4c55bfe646bfc9d
2025-09-10 20:28:57 +00:00
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
dan d61dbf7072 Change the order of some paragraphs within documentation comments in sqlite3session.h.
FossilOrigin-Name: f0102d7b25d854b5a937eb7de5e25f52c2ecf904234857c96bd1995f5dde0b66
2025-09-10 16:57:57 +00:00
drh 586361fa7c The GetSystemTimePreciseAsFileTime() API does not exist on 32-bit windows.
Adjust [c5dbe93114d318fe] so that it works with this limitation.

FossilOrigin-Name: 61d9e204c5801a94811fdb0afe2c04f9814e08f2e141afa6dbda0fa45f026f70
2025-09-10 14:28:07 +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 92f91ca37d Do not allow the local_getline() function in the CLI to allocate more
memory than can be counted using a 32-bit integer, thus limiting the
length of an input line to about one gigabyte.
[forum:/forumpost/c83b9affa2|Forum post c83b9affa2].

FossilOrigin-Name: 0f31711591c56f3896fb6f092752fb82c4ea646bf8e5838dfbe55302994ea091
2025-09-09 10:28:06 +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
305 changed files with 18865 additions and 42579 deletions
+10 -16
View File
@@ -30,14 +30,12 @@ The public domain source files usually contain a header comment
similar to the following to make it clear that the software is
public domain.
> ~~~
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.
~~~
> 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.
Almost every file you find in this source repository will be
public domain. But there are a small number of exceptions:
@@ -49,9 +47,7 @@ This repository contains a (relatively) small amount of non-public-domain
code used to help implement the configuration and build logic. In other
words, there are some non-public-domain files used to implement:
> ~~~
./configure && make
~~~
> ./configure && make
In all cases, the non-public-domain files included with this
repository have generous BSD-style licenses. So anyone is free to
@@ -69,7 +65,7 @@ third-party build scripts in order to compile SQLite.
Non-public-domain code included in this respository includes:
* The ["autosetup"](http://msteveb.github.io/autosetup/) configuration
system that is contained (mostly) the autosetup/ directory, but also
system that is contained (mostly) in the autosetup/ directory, but also
includes the "./configure" script at the top-level of this archive.
Autosetup has a separate BSD-style license. See the
[autosetup/LICENSE](http://msteveb.github.io/autosetup/license/)
@@ -79,13 +75,11 @@ Non-public-domain code included in this respository includes:
software found in the legacy autoconf/ directory and its
subdirectories.
The following unix shell command is can be run from the top-level
The following unix shell command can be run from the top-level
of this source repository in order to remove all non-public-domain
code:
> ~~~
rm -rf configure autosetup autoconf
~~~
> rm -rf configure autosetup autoconf
If you unpack this source repository and then run the command above, what
is left will be 100% public domain.
+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
+148 -33
View File
@@ -405,6 +405,7 @@ OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_STMTVTAB=1
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_DBPAGE_VTAB=1
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_DBSTAT_VTAB=1
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_BYTECODE_VTAB=1
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_CARRAY=1
!ENDIF
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_COLUMN_METADATA=1
!ENDIF
@@ -427,6 +428,7 @@ OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_PREUPDATE_HOOK=1
# Always enable math functions on Windows
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_MATH_FUNCTIONS
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_PERCENTILE
# Should the rbu extension be enabled? If so, add compilation options
# to enable it.
@@ -803,17 +805,21 @@ BCC = $(BCC) /d2guard4 -D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE
!IF $(DEBUG)>1
TCC = $(TCC) -MDd
BCC = $(BCC) -MDd
ZLIBCFLAGS = -nologo -MDd -W3 -O2 -Oy- -Zi
!ELSE
TCC = $(TCC) -MD
BCC = $(BCC) -MD
ZLIBCFLAGS = -nologo -MD -W3 -O2 -Oy- -Zi
!ENDIF
!ELSE
!IF $(DEBUG)>1
TCC = $(TCC) -MTd
BCC = $(BCC) -MTd
ZLIBCFLAGS = -nologo -MTd -W3 -O2 -Oy- -Zi
!ELSE
TCC = $(TCC) -MT
BCC = $(BCC) -MT
ZLIBCFLAGS = -nologo -MT -W3 -O2 -Oy- -Zi
!ENDIF
!ENDIF
@@ -1343,7 +1349,7 @@ LTLIBS = $(LTLIBS) $(LIBICU)
#
LIBOBJS0 = vdbe.lo parse.lo alter.lo analyze.lo attach.lo auth.lo \
backup.lo bitvec.lo btmutex.lo btree.lo build.lo \
callback.lo complete.lo ctime.lo \
callback.lo carray.lo complete.lo ctime.lo \
date.lo dbpage.lo dbstat.lo delete.lo \
expr.lo fault.lo fkey.lo \
fts3.lo fts3_aux.lo fts3_expr.lo fts3_hash.lo fts3_icu.lo \
@@ -1405,6 +1411,7 @@ SRC00 = \
$(TOP)\src\btree.c \
$(TOP)\src\build.c \
$(TOP)\src\callback.c \
$(TOP)\src\carray.c \
$(TOP)\src\complete.c \
ctime.c \
$(TOP)\src\date.c \
@@ -1638,7 +1645,6 @@ TESTEXT = \
$(TOP)\ext\misc\amatch.c \
$(TOP)\ext\misc\appendvfs.c \
$(TOP)\ext\misc\basexx.c \
$(TOP)\ext\misc\carray.c \
$(TOP)\ext\misc\cksumvfs.c \
$(TOP)\ext\misc\closure.c \
$(TOP)\ext\misc\csv.c \
@@ -1654,7 +1660,6 @@ TESTEXT = \
$(TOP)\ext\misc\mmapwarm.c \
$(TOP)\ext\misc\nextchar.c \
$(TOP)\ext\misc\normalize.c \
$(TOP)\ext\misc\percentile.c \
$(TOP)\ext\misc\prefixes.c \
$(TOP)\ext\misc\qpvtab.c \
$(TOP)\ext\misc\randomjson.c \
@@ -1766,6 +1771,7 @@ SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_DQS=0
SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_ENABLE_FTS4=1
SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_ENABLE_EXPLAIN_COMMENTS=1
SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_ENABLE_OFFSET_SQL_FUNC=1
SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_ENABLE_PERCENTILE=1
SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_ENABLE_UNKNOWN_SQL_FUNCTION=1
SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_ENABLE_STMT_SCANSTATUS=1
SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_STRICT_SUBTYPE=1
@@ -1780,6 +1786,7 @@ FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -I$(TOP)\test -I$(TOP)\ext\recover
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_MEMSYS5
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_OSS_FUZZ
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_BYTECODE_VTAB
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_CARRAY
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_DBPAGE_VTAB
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_DBSTAT_VTAB
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_BYTECODE_VTAB
@@ -1793,6 +1800,7 @@ FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_MATH_FUNCTIONS
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_MEMSYS5
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_NORMALIZE
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_OFFSET_SQL_FUNC
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_PERCENTILE
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_PREUPDATE_HOOK
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_RTREE
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_SESSION
@@ -1823,7 +1831,6 @@ FUZZCHECK_SRC = $(FUZZCHECK_SRC) $(TOP)\test\fuzzinvariants.c
FUZZCHECK_SRC = $(FUZZCHECK_SRC) $(TOP)\test\vt02.c
FUZZCHECK_SRC = $(FUZZCHECK_SRC) $(TOP)\ext\recover\dbdata.c
FUZZCHECK_SRC = $(FUZZCHECK_SRC) $(TOP)\ext\recover\sqlite3recover.c
FUZZCHECK_SRC = $(FUZZCHECK_SRC) $(TOP)\ext\misc\percentile.c
FUZZCHECK_SRC = $(FUZZCHECK_SRC) $(TOP)\ext\misc\randomjson.c
OSSSHELL_SRC = $(TOP)\test\ossshell.c $(TOP)\test\ossfuzz.c
@@ -2101,6 +2108,9 @@ build.lo: $(TOP)\src\build.c $(HDR)
callback.lo: $(TOP)\src\callback.c $(HDR)
$(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\callback.c
carray.lo: $(TOP)\src\carray.c $(HDR)
$(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\carray.c
complete.lo: $(TOP)\src\complete.c $(HDR)
$(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\complete.c
@@ -2384,7 +2394,6 @@ SHELL_DEP = \
$(TOP)\ext\misc\ieee754.c \
$(TOP)\ext\misc\memtrace.c \
$(TOP)\ext\misc\pcachetrace.c \
$(TOP)\ext\misc\percentile.c \
$(TOP)\ext\misc\regexp.c \
$(TOP)\ext\misc\series.c \
$(TOP)\ext\misc\sha1.c \
@@ -2411,7 +2420,7 @@ shell.c: $(SHELL_DEP) $(TOP)\tool\mkshellc.tcl $(JIM_TCLSH)
$(JIM_TCLSH) $(TOP)\tool\mkshellc.tcl shell.c
zlib:
pushd $(ZLIBDIR) && $(MAKE) /f win32\Makefile.msc clean $(ZLIBLIB) && popd
pushd $(ZLIBDIR) && $(MAKE) /f win32\Makefile.msc clean $(ZLIBLIB) CFLAGS="$(ZLIBCFLAGS)" && popd
# Rules to build the extension objects.
#
@@ -2485,24 +2494,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 +2507,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
@@ -2548,6 +2534,8 @@ TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_DEFAULT_PAGE_SIZE=1024
TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_ENABLE_STMTVTAB=1
TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_ENABLE_DBPAGE_VTAB=1
TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_ENABLE_BYTECODE_VTAB=1
TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_ENABLE_CARRAY=1
TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_ENABLE_PERCENTILE=1
TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_CKSUMVFS_STATIC=1
TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) $(TEST_CCONV_OPTS)
TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_STATIC_RANDOMJSON
@@ -2596,9 +2584,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,8 +2815,133 @@ tcl-env:
@echo JIM_TCLSH = $(JIM_TCLSH)
@echo VISUALSTUDIOVERSION = $(VISUALSTUDIOVERSION)
LSMDIR=$(TOP)\ext\lsm1
!INCLUDE $(LSMDIR)\Makefile.msc
env:
@echo ALL_TCL_TARGETS = $(ALL_TCL_TARGETS)
@echo API_ARMOR = $(API_ARMOR)
@echo ASAN = $(ASAN)
@echo BCC = $(BCC)
@echo BUILD_ZLIB = $(BUILD_ZLIB)
@echo CC = $(CC)
@echo CCOPTS = $(CCOPTS)
@echo CHECKER_DEPS = $(CHECKER_DEPS)
@echo CORE_CCONV_OPTS = $(CORE_CCONV_OPTS)
@echo CORE_COMPILE_OPTS = $(CORE_COMPILE_OPTS)
@echo CORE_LINK_DEP = $(CORE_LINK_DEP)
@echo CORE_LINK_OPTS = $(CORE_LINK_OPTS)
@echo CRTLIBPATH = $(CRTLIBPATH)
@echo CSC = $(CSC)
@echo DBFUZZ_COMPILE_OPTS = $(DBFUZZ_COMPILE_OPTS)
@echo DEBUG = $(DEBUG)
@echo DYNAMIC_SHELL = $(DYNAMIC_SHELL)
@echo EXT_FEATURE_FLAGS = $(EXT_FEATURE_FLAGS)
@echo EXTHDR = $(EXTHDR)
@echo EXTRA_SRC = $(EXTRA_SRC)
@echo FOR_UWP = $(FOR_UWP)
@echo FUZZCHECK_OPTS = $(FUZZCHECK_OPTS)
@echo FUZZCHECK_SRC = $(FUZZCHECK_SRC)
@echo FUZZDATA = $(FUZZDATA)
@echo FUZZERSHELL_COMPILE_OPTS = $(FUZZERSHELL_COMPILE_OPTS)
@echo HDR = $(HDR)
@echo ICUDIR = $(ICUDIR)
@echo ICUINCDIR = $(ICUINCDIR)
@echo ICULIBDIR = $(ICULIBDIR)
@echo JIM_TCLSH = $(JIM_TCLSH)
@echo KV_COMPILE_OPTS = $(KV_COMPILE_OPTS)
@echo LDFLAGS = $(LDFLAGS)
@echo LD = $(LD)
@echo LIBICU = $(LIBICU)
@echo LIBOBJ = $(LIBOBJ)
@echo LIBREADLINE = $(LIBREADLINE)
@echo LIBRESOBJS = $(LIBRESOBJS)
@echo LIBTCLPATH = $(LIBTCLPATH)
@echo LIBTCLSTUB = $(LIBTCLSTUB)
@echo LIBTCL = $(LIBTCL)
@echo LTCOMPILE = $(LTCOMPILE)
@echo LTLIB = $(LTLIB)
@echo LTLIBOPTS = $(LTLIBOPTS)
@echo LTLIBPATHS = $(LTLIBPATHS)
@echo LTLIBS = $(LTLIBS)
@echo LTLINK = $(LTLINK)
@echo LTLINKOPTS = $(LTLINKOPTS)
@echo LTRCOMPILE = $(LTRCOMPILE)
@echo MEMDEBUG = $(MEMDEBUG)
@echo MINIMAL_AMALGAMATION = $(MINIMAL_AMALGAMATION)
@echo MPTESTER_COMPILE_OPTS = $(MPTESTER_COMPILE_OPTS)
@echo NCC = $(NCC)
@echo NCRTLIBPATH = $(NCRTLIBPATH)
@echo NLTLIBPATHS = $(NLTLIBPATHS)
@echo NO_LINEMACROS = $(NO_LINEMACROS)
@echo NO_TCL = $(NO_TCL)
@echo NO_WARN = $(NO_WARN)
@echo NSDKLIBPATH = $(NSDKLIBPATH)
@echo NUCRTLIBPATH = $(NUCRTLIBPATH)
@echo OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS)
@echo OPTIMIZATIONS = $(OPTIMIZATIONS)
@echo OSSSHELL_SRC = $(OSSSHELL_SRC)
@echo OSTRACE = $(OSTRACE)
@echo RBU = $(RBU)
@echo RCC = $(RCC)
@echo RC = $(RC)
@echo READLINE_FLAGS = $(READLINE_FLAGS)
@echo REQ_FEATURE_FLAGS = $(REQ_FEATURE_FLAGS)
@echo RSYNC_OPT = $(RSYNC_OPT)
@echo RSYNC_SRC = $(RSYNC_SRC)
@echo SESSION = $(SESSION)
@echo SETLK_TIMEOUT = $(SETLK_TIMEOUT)
@echo SHELL_CCONV_OPTS = $(SHELL_CCONV_OPTS)
@echo SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS)
@echo SHELL_CORE_DEP = $(SHELL_CORE_DEP)
@echo SHELL_CORE_LIB = $(SHELL_CORE_LIB)
@echo SHELL_CORE_SRC = $(SHELL_CORE_SRC)
@echo SHELL_DEP = $(SHELL_DEP)
@echo SHELL_LINK_OPTS = $(SHELL_LINK_OPTS)
@echo SPLIT_AMALGAMATION = $(SPLIT_AMALGAMATION)
@echo SQLITETCLDECLSH = $(SQLITETCLDECLSH)
@echo SQLITE_TCL_DEP = $(SQLITE_TCL_DEP)
@echo SQLITETCLH = $(SQLITETCLH)
@echo SRC = $(SRC)
@echo STATICALLY_LINK_TCL = $(STATICALLY_LINK_TCL)
@echo ST_COMPILE_OPTS = $(ST_COMPILE_OPTS)
@echo STORELIBPATH = $(STORELIBPATH)
@echo SYMBOLS = $(SYMBOLS)
@echo TCC = $(TCC)
@echo TCLDIR = $(TCLDIR)
@echo TCLINCDIR = $(TCLINCDIR)
@echo TCLLIBDIR = $(TCLLIBDIR)
@echo TCLLIBPATHS = $(TCLLIBPATHS)
@echo TCLLIBS = $(TCLLIBS)
@echo TCLSH_CMD = $(TCLSH_CMD)
@echo TCLSQLITEEX = $(TCLSQLITEEX)
@echo TCLSUFFIX = $(TCLSUFFIX)
@echo TCLVERSION = $(TCLVERSION)
@echo TEST_CCONV_OPTS = $(TEST_CCONV_OPTS)
@echo TESTEXT = $(TESTEXT)
@echo TESTFIXTURE_DEP = $(TESTFIXTURE_DEP)
@echo TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS)
@echo TESTFIXTURE_SRC = $(TESTFIXTURE_SRC)
@echo TESTOPTS = $(TESTOPTS)
@echo TESTPROGS = $(TESTPROGS)
@echo TESTSRC = $(TESTSRC)
@echo TLIBS = $(TLIBS)
@echo TOP = $(TOP)
@echo UCRTLIBPATH = $(UCRTLIBPATH)
@echo USE_AMALGAMATION = $(USE_AMALGAMATION)
@echo USE_CRT_DLL = $(USE_CRT_DLL)
@echo USE_FATAL_WARN = $(USE_FATAL_WARN)
@echo USE_FULLWARN = $(USE_FULLWARN)
@echo USE_ICU = $(USE_ICU)
@echo USE_LISTINGS = $(USE_LISTINGS)
@echo USE_NATIVE_LIBPATHS = $(USE_NATIVE_LIBPATHS)
@echo USE_RC = $(USE_RC)
@echo USE_RUNTIME_CHECKS = $(USE_RUNTIME_CHECKS)
@echo USE_SEH = $(USE_SEH)
@echo USE_STDCALL = $(USE_STDCALL)
@echo USE_ZLIB = $(USE_ZLIB)
@echo XCOMPILE = $(XCOMPILE)
@echo ZLIBDIR = $(ZLIBDIR)
@echo ZLIBINCDIR = $(ZLIBINCDIR)
@echo ZLIBLIBDIR = $(ZLIBLIBDIR)
@echo ZLIBLIB = $(ZLIBLIB)
moreclean: clean
del /Q $(SQLITE3C) $(SQLITE3H) 2>NUL
@@ -2868,7 +2984,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>>
+18 -24
View File
@@ -2,8 +2,8 @@
This repository contains the complete source code for the
[SQLite database engine](https://sqlite.org/), including
many test scripts. However, other test scripts
and most of the documentation are managed separately.
many tests. Additional tests and most documentation
are managed separately.
See the [on-line documentation](https://sqlite.org/) for more information
about what SQLite is and how it works from a user's perspective. This
@@ -53,39 +53,32 @@ then no longer be fully in the public domain.
## Obtaining The SQLite Source Code
If you do not want to use Fossil, you can download tarballs or ZIP
archives or [SQLite archives](https://sqlite.org/cli.html#sqlar) as follows:
Source code tarballs or ZIP archives are available at:
* Latest trunk check-in as
[Tarball](https://sqlite.org/src/tarball/sqlite.tar.gz),
[ZIP-archive](https://sqlite.org/src/zip/sqlite.zip), or
[SQLite-archive](https://sqlite.org/src/sqlar/sqlite.sqlar).
* [Latest trunk check-in](https://sqlite.org/src/rchvdwnld/trunk).
* Latest release as
[Tarball](https://sqlite.org/src/tarball/sqlite.tar.gz?r=release),
[ZIP-archive](https://sqlite.org/src/zip/sqlite.zip?r=release), or
[SQLite-archive](https://sqlite.org/src/sqlar/sqlite.sqlar?r=release).
* [Latest release](https://sqlite.org/src/rchvdwnld/release)
* For other check-ins, substitute an appropriate branch name or
tag or hash prefix in place of "release" in the URLs of the previous
bullet. Or browse the [timeline](https://sqlite.org/src/timeline)
to locate the check-in desired, click on its information page link,
then click on the "Tarball" or "ZIP Archive" links on the information
page.
* For other check-ins, browse the
[project timeline](https://sqlite.org/src/timeline?y=ci) and
click on the check-in hash of the check-in you want to download.
On the resulting "info" page, click one of the options to the
right of the "**Downloads:**" label in the "**Overview**" section
near the top.
To access sources directly using [Fossil](https://fossil-scm.org/home),
first install Fossil version 2.0 or later.
Source tarballs and precompiled binaries available at
Source tarballs and precompiled binaries for Fossil are available at
<https://fossil-scm.org/home/uv/download.html>. Fossil is
a stand-alone program. To install, simply download or build the single
executable file and put that file someplace on your $PATH.
executable file and put that file someplace on your $PATH or %PATH%.
Then run commands like this:
mkdir -p ~/sqlite
cd ~/sqlite
fossil open https://sqlite.org/src
The "fossil open" command will take two or three minutes. Afterwards,
The initial "fossil open" command will take two or three minutes. Afterwards,
you can do fast, bandwidth-efficient updates to the whatever versions
of SQLite you like. Some examples:
@@ -152,7 +145,8 @@ show what changes are needed.
## Compiling for Windows Using MSVC
On Windows, everything can be compiled with MSVC.
You will also need a working installation of TCL.
You will also need a working installation of TCL if you want to run tests.
TCL is not required if you just want to build SQLite itself.
See the [compile-for-windows.md](doc/compile-for-windows.md) document for
additional information about how to install MSVC and TCL and configure your
build environment.
@@ -164,8 +158,8 @@ TCL library, using a command like this:
SQLite uses "tclsh.exe" as part of the build process, and so that
program will need to be somewhere on your %PATH%. SQLite itself
does not contain any TCL code, but it does use TCL to help with the
build process and to run tests. You may need to install TCL development
does not contain any TCL code, but it does use TCL to run tests.
You may need to install TCL development
libraries in order to successfully complete some makefile targets.
It is helpful, but is not required, to install the SQLite TCL extension
(the "tclextension-install" target) prior to running tests.
+1 -1
View File
@@ -1 +1 @@
3.51.0
3.51.2
+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 {
+19 -3
View File
@@ -117,6 +117,19 @@ sqlite_cfg.h: $(AS_AUTO_DEF)
# CFLAGS for sqlite3$(T.exe)
#
SHELL_OPT ?= @OPT_SHELL@
SHELL_OPT += -DSQLITE_DQS=0
SHELL_OPT += -DSQLITE_ENABLE_FTS4
#SHELL_OPT += -DSQLITE_ENABLE_FTS5
SHELL_OPT += -DSQLITE_ENABLE_RTREE
SHELL_OPT += -DSQLITE_ENABLE_EXPLAIN_COMMENTS
SHELL_OPT += -DSQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
SHELL_OPT += -DSQLITE_ENABLE_STMTVTAB
SHELL_OPT += -DSQLITE_ENABLE_DBPAGE_VTAB
SHELL_OPT += -DSQLITE_ENABLE_DBSTAT_VTAB
SHELL_OPT += -DSQLITE_ENABLE_BYTECODE_VTAB
SHELL_OPT += -DSQLITE_ENABLE_OFFSET_SQL_FUNC
SHELL_OPT += -DSQLITE_ENABLE_PERCENTILE
SHELL_OPT += -DSQLITE_STRICT_SUBTYPE=1
#
# Library-level feature flags
@@ -222,9 +235,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 +261,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)
+7
View File
@@ -327,6 +327,7 @@ OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_STMTVTAB=1
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_DBPAGE_VTAB=1
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_DBSTAT_VTAB=1
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_BYTECODE_VTAB=1
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_CARRAY=1
!ENDIF
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_COLUMN_METADATA=1
!ENDIF
@@ -349,6 +350,7 @@ OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_PREUPDATE_HOOK=1
# Always enable math functions on Windows
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_MATH_FUNCTIONS
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_PERCENTILE
# Should the rbu extension be enabled? If so, add compilation options
# to enable it.
@@ -693,17 +695,21 @@ BCC = $(BCC) /d2guard4 -D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE
!IF $(DEBUG)>1
TCC = $(TCC) -MDd
BCC = $(BCC) -MDd
ZLIBCFLAGS = -nologo -MDd -W3 -O2 -Oy- -Zi
!ELSE
TCC = $(TCC) -MD
BCC = $(BCC) -MD
ZLIBCFLAGS = -nologo -MD -W3 -O2 -Oy- -Zi
!ENDIF
!ELSE
!IF $(DEBUG)>1
TCC = $(TCC) -MTd
BCC = $(BCC) -MTd
ZLIBCFLAGS = -nologo -MTd -W3 -O2 -Oy- -Zi
!ELSE
TCC = $(TCC) -MT
BCC = $(BCC) -MT
ZLIBCFLAGS = -nologo -MT -W3 -O2 -Oy- -Zi
!ENDIF
!ENDIF
@@ -1015,6 +1021,7 @@ SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_DQS=0
SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_ENABLE_FTS4=1
SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_ENABLE_EXPLAIN_COMMENTS=1
SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_ENABLE_OFFSET_SQL_FUNC=1
SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_ENABLE_PERCENTILE=1
SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_ENABLE_UNKNOWN_SQL_FUNCTION=1
SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_ENABLE_STMT_SCANSTATUS=1
SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_STRICT_SUBTYPE=1
+3 -2
View File
@@ -119,7 +119,7 @@ TCLLIBDIR = @TCLLIBDIR@
# typically come from the ./configure command-line invocation).
#
CFLAGS.configure = @SH_CFLAGS@ @TEAISH_CFLAGS@ @CFLAGS@ @CPPFLAGS@ $(TCL_INCLUDE_SPEC)
#CFLAGS.configure += -DUSE_TCL_STUBS=1
CFLAGS.configure += -DUSE_TCL_STUBS=@TEAISH_USE_STUBS@
#
# LDFLAGS.configure = LDFLAGS as known at configure-time.
@@ -153,6 +153,7 @@ tx.src = @TEAISH_EXT_SRC@
# gets set up via the configure script.
#
tx.CFLAGS =
tx.CPPFLAGS =
#
# tx.LDFLAGS is typically set by teaish.make, whereas TEAISH_LDFLAGS
@@ -218,7 +219,7 @@ config.log: @TEAISH_TEST_TCL_IN@
# CC variant for compiling Tcl-using sources.
#
CC.tcl = \
$(CC) -o $@ $(CFLAGS.configure) $(CFLAGS) $(tx.CFLAGS)
$(CC) -o $@ $(CFLAGS.configure) $(CFLAGS) $(tx.CFLAGS) $(tx.CPPFLAGS)
#
# CC variant for linking $(tx.src) into an extension DLL. Note that
+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:
+11 -7
View File
@@ -406,8 +406,8 @@ proc options-add {opts} {
# Find the corresponding value in the user options
# and set the default if necessary
if {[string match "-*" $opt]} {
# This is a documentation-only option, like "-C <dir>"
set opthelp $opt
# We no longer support documentation-only options, like "-C <dir>"
autosetup-error "Option $opt is not supported"
} elseif {$colon eq ""} {
# Boolean option
lappend autosetup(options) $name
@@ -1611,7 +1611,7 @@ proc autosetup_output_block {type lines} {
# Generate a command reference from inline documentation
proc automf_command_reference {} {
lappend files $::autosetup(prog)
lappend files {*}[lsort [glob -nocomplain $::autosetup(libdir)/*.tcl]]
lappend files {*}[lsort [glob -nocomplain $::autosetup(libdir)/{*/*.tcl,*.tcl}]]
# We want to process all non-module files before module files
# and then modules in alphabetical order.
@@ -2124,7 +2124,7 @@ if {$autosetup(istcl)} {
set frame [info frame -$i]
if {[dict exists $frame file]} {
# We don't need proc, so use ""
lappend stacktrace "" [dict get $frame file] [dict get $frame line]
lappend stacktrace "" [dict get $frame file] [dict get $frame line] ""
}
}
return $stacktrace
@@ -2181,8 +2181,12 @@ proc error-location {msg} {
if {$::autosetup(debug)} {
return -code error $msg
}
# Search back through the stack trace for the first error in a .def file
foreach {p f l} [stacktrace] {
set vars {p f l cmd}
if {!$::autosetup(istcl) && ![dict exists $::tcl_platform stackFormat]} {
# Older versions of Jim had a 3 element stacktrace
set vars {p f l}
}
foreach $vars [stacktrace] {
if {[string match *.def $f]} {
return "[relative-path $f]:$l: Error: $msg"
}
@@ -2534,7 +2538,7 @@ if {[catch {main $argv} msg opts] == 1} {
show-notices
autosetup-full-error [error-dump $msg $opts $autosetup(debug)]
if {!$autosetup(debug)} {
puts stderr "Try: '[file tail $autosetup(exe)] --autosetup-debug' for a full stack trace"
puts stderr "Try: '[file tail $autosetup(exe)] --debug' for a full stack trace"
}
exit 1
}
+6 -4
View File
@@ -89,13 +89,15 @@ switch -glob -- [get-define host] {
define SH_SOPREFIX -Wl,-h,
}
}
*-*-hpux {
# XXX: These haven't been tested
define SHOBJ_CFLAGS "+O3 +z"
*-*-hpux* {
define SHOBJ_CFLAGS +z
define SHOBJ_LDFLAGS -b
define SH_CFLAGS +z
define SH_LDFLAGS -b
define SH_LINKFLAGS -Wl,+s
define LD_LIBRARY_PATH SHLIB_PATH
define SH_LINKRPATH "-Wl,+b -Wl,%s"
define SH_SOPREFIX -Wl,+h,
define STRIPLIBFLAGS -Wl,-s
}
*-*-haiku {
define SHOBJ_CFLAGS ""
+12 -25
View File
@@ -9132,7 +9132,7 @@ int Jim_StringEqObj(Jim_Obj *aObjPtr, Jim_Obj *bObjPtr)
const char *sA = Jim_GetString(aObjPtr, &Alen);
const char *sB = Jim_GetString(bObjPtr, &Blen);
return Alen == Blen && *sA == *sB && memcmp(sA, sB, Alen) == 0;
return Alen == Blen && memcmp(sA, sB, Alen) == 0;
}
}
@@ -10242,7 +10242,7 @@ static int JimCommandsHT_KeyCompare(void *privdata, const void *key1, const void
int len1, len2;
const char *str1 = Jim_GetStringNoQualifier((Jim_Obj *)key1, &len1);
const char *str2 = Jim_GetStringNoQualifier((Jim_Obj *)key2, &len2);
return len1 == len2 && *str1 == *str2 && memcmp(str1, str2, len1) == 0;
return len1 == len2 && memcmp(str1, str2, len1) == 0;
}
static void JimCommandsHT_ValDestructor(void *interp, void *val)
@@ -13864,13 +13864,6 @@ static int JimExprOpNumUnary(Jim_Interp *interp, struct JimExprNode *node)
case JIM_EXPROP_NOT:
wC = !bA;
break;
case JIM_EXPROP_UNARYPLUS:
case JIM_EXPROP_UNARYMINUS:
rc = JIM_ERR;
Jim_SetResultFormatted(interp,
"can't use non-numeric string as operand of \"%s\"",
node->type == JIM_EXPROP_UNARYPLUS ? "+" : "-");
break;
default:
abort();
}
@@ -19875,22 +19868,16 @@ wrongargs:
}
else if (errorCodeObj) {
int len = Jim_ListLength(interp, argv[idx + 1]);
int i;
if (len > Jim_ListLength(interp, errorCodeObj)) {
ret = JIM_OK;
ret = -1;
}
else {
int i;
ret = JIM_OK;
for (i = 0; i < len; i++) {
Jim_Obj *matchObj = Jim_ListGetIndex(interp, argv[idx + 1], i);
Jim_Obj *objPtr = Jim_ListGetIndex(interp, errorCodeObj, i);
if (Jim_StringCompareObj(interp, matchObj, objPtr, 0) != 0) {
ret = -1;
break;
}
for (i = 0; i < len; i++) {
Jim_Obj *matchObj = Jim_ListGetIndex(interp, argv[idx + 1], i);
Jim_Obj *objPtr = Jim_ListGetIndex(interp, errorCodeObj, i);
if (Jim_StringCompareObj(interp, matchObj, objPtr, 0) != 0) {
ret = -1;
break;
}
}
}
@@ -20266,7 +20253,7 @@ static int Jim_DictCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *arg
}
case OPT_SET:
return Jim_SetDictKeysVector(interp, argv[2], argv + 3, argc - 4, argv[argc - 1], JIM_ERRMSG | JIM_UNSHARED);
return Jim_SetDictKeysVector(interp, argv[2], argv + 3, argc - 4, argv[argc - 1], JIM_ERRMSG);
case OPT_EXISTS:{
int rc = Jim_DictKeysVector(interp, argv[2], argv + 3, argc - 3, &objPtr, JIM_NONE);
@@ -20278,7 +20265,7 @@ static int Jim_DictCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *arg
}
case OPT_UNSET:
if (Jim_SetDictKeysVector(interp, argv[2], argv + 3, argc - 3, NULL, JIM_UNSHARED) != JIM_OK) {
if (Jim_SetDictKeysVector(interp, argv[2], argv + 3, argc - 3, NULL, JIM_NONE) != JIM_OK) {
return JIM_ERR;
}
return JIM_OK;
+65 -16
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)};
@@ -555,7 +557,7 @@ proc proj-opt-define-bool {args} {
if {$invert} {
set rc [expr {!$rc}]
}
msg-result $rc
msg-result [string map {0 no 1 yes} $rc]
define $defName $rc
return $rc
}
@@ -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]
#
+96 -54
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
@@ -65,11 +65,12 @@ array set sqliteConfig [subst [proj-strip-hash-comments {
# The list of feature --flags which the --all flag implies. This
# requires special handling in a few places.
#
all-flag-enables {fts4 fts5 rtree geopoly session}
all-flag-enables {fts4 fts5 rtree geopoly session dbpage dbstat carray}
#
# 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 {
@@ -212,6 +220,9 @@ proc sqlite-configure {buildMode configScript} {
geopoly => {Enable the GEOPOLY extension}
rtree => {Enable the RTREE extension}
session => {Enable the SESSION extension}
dbpage => {Enable the sqlite3_dbpage extension}
dbstat => {Enable the sqlite3_dbstat extension}
carray=1 => {Disable the CARRAY extension}
all=$::sqliteConfig(all-flag-default) => {$allFlagHelp}
largefile=1
=> {This legacy flag has no effect on the library but may influence
@@ -321,7 +332,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 +348,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 +418,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 +435,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 +445,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 +460,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}
@@ -492,6 +504,7 @@ proc sqlite-configure-phase1 {buildMode} {
if {[file exists $srcdir/sqlite3.pc.in]} {
proj-dot-ins-append $srcdir/sqlite3.pc.in
}
sqlite-handle-hpux; # must be relatively early so that other config tests can work
}; # sqlite-configure-phase1
########################################################################
@@ -618,7 +631,7 @@ proc sqlite-check-common-system-deps {} {
# Check for needed/wanted functions
cc-check-functions gmtime_r isnan localtime_r localtime_s \
strchrnul usleep utime pread pread64 pwrite pwrite64
usleep utime pread pread64 pwrite pwrite64
apply {{} {
set ldrt ""
@@ -776,6 +789,9 @@ proc sqlite-handle-common-feature-flags {} {
}
scanstatus -DSQLITE_ENABLE_STMT_SCANSTATUS {}
column-metadata -DSQLITE_ENABLE_COLUMN_METADATA {}
dbpage -DSQLITE_ENABLE_DBPAGE_VTAB {}
dbstat -DSQLITE_ENABLE_DBSTAT_VTAB {}
carray -DSQLITE_ENABLE_CARRAY {}
}] {
if {$boolFlag ni $::autosetup(options)} {
# Skip flags which are in the canonical build but not
@@ -1017,7 +1033,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 +1051,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 +1101,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 +1115,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 +1132,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 +1242,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 +1283,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 +1337,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 +1430,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
@@ -1461,7 +1490,7 @@ proc sqlite-handle-math {} {
}
define LDFLAGS_MATH [get-define lib_ceil]
undefine lib_ceil
sqlite-add-feature-flag -DSQLITE_ENABLE_MATH_FUNCTIONS
sqlite-add-feature-flag -DSQLITE_ENABLE_MATH_FUNCTIONS -DSQLITE_ENABLE_PERCENTILE
msg-result "Enabling math SQL functions"
} {
define LDFLAGS_MATH ""
@@ -1523,6 +1552,19 @@ proc sqlite-handle-mac-install-name {} {
return $rc
}
#
# Checks specific to HP-UX.
#
proc sqlite-handle-hpux {} {
switch -glob -- [get-define host] {
*hpux* {
if {[cc-check-flags "-Ae"]} {
define-append CFLAGS -Ae
}
}
}
}
########################################################################
# Handles the --dll-basename configure flag. [define]'s
# SQLITE_DLL_BASENAME to the DLL's preferred base name (minus
+5 -1
View File
@@ -220,7 +220,9 @@ proc teaish-configure-core {} {
=> {Full pathname of tclsh to use. It is used for trying to find
tclConfig.sh. Warning: if its containing dir has multiple tclsh
versions, it may select the wrong tclConfig.sh!
Defaults to the $TCLSH environment variable.}
Defaults to the $TCLSH environment variable.}
tcl-stubs=0 => {Enable use of Tcl stubs library.}
# TEA has --with-tclinclude but it appears to only be useful for
# building an extension against an uninstalled copy of TCL's own
@@ -498,6 +500,8 @@ proc teaish__configure_phase1 {} {
}
teaish-checks-run -post
define TEAISH_USE_STUBS [opt-bool tcl-stubs]
apply {{} {
# Set up "vsatisfies" code for pkgIndex.tcl.in,
# _teaish.tester.tcl.in, and for a configure-time check. We would
+8 -17
View File
@@ -1,7 +1,7 @@
# Notes On Compiling SQLite On Windows 11
Below are step-by-step instructions on how to build SQLite from
canonical source on a new Windows 11 PC, as of 2024-10-09.
canonical source on a new Windows 11 PC, as of 2025-10-31.
See [](./compile-for-unix.md) for a similar guide for unix-like
systems, including MacOS.
@@ -24,7 +24,8 @@ systems, including MacOS.
application to your task bar, as you will use it a lot. Bring up
an instance of this command prompt and do all of the subsequent steps
in that "x64 Native Tools" command prompt. (Or use "x86" if you want
a 32-bit build.) The subsequent steps will not work in a vanilla
a 32-bit build. Or use "ARM64" if you want to do a build for Windows
on ARM.) The subsequent steps will not work in a vanilla
DOS prompt. Nor will they work in PowerShell.
3. *(Optional):* Install TCL development libraries.
@@ -133,9 +134,7 @@ following minor changes:
The command the developers use for building the deliverable DLL on the
[download page](https://sqlite.org/download.html) is as follows:
> ~~~~
nmake /f Makefile.msc sqlite3.dll USE_NATIVE_LIBPATHS=1 "OPTS=-DSQLITE_ENABLE_FTS3=1 -DSQLITE_ENABLE_FTS4=1 -DSQLITE_ENABLE_FTS5=1 -DSQLITE_ENABLE_RTREE=1 -DSQLITE_ENABLE_JSON1=1 -DSQLITE_ENABLE_GEOPOLY=1 -DSQLITE_ENABLE_SESSION=1 -DSQLITE_ENABLE_PREUPDATE_HOOK=1 -DSQLITE_ENABLE_SERIALIZE=1 -DSQLITE_ENABLE_MATH_FUNCTIONS=1"
~~~~
> nmake /f Makefile.msc sqlite3.dll USE_NATIVE_LIBPATHS=1 "OPTS=-DSQLITE_ENABLE_FTS3=1 -DSQLITE_ENABLE_FTS4=1 -DSQLITE_ENABLE_FTS5=1 -DSQLITE_ENABLE_RTREE=1 -DSQLITE_ENABLE_JSON1=1 -DSQLITE_ENABLE_GEOPOLY=1 -DSQLITE_ENABLE_SESSION=1 -DSQLITE_ENABLE_PREUPDATE_HOOK=1 -DSQLITE_ENABLE_SERIALIZE=1 -DSQLITE_ENABLE_MATH_FUNCTIONS=1"
That command generates both the sqlite3.dll and sqlite3.def files. The same
command works for both 32-bit and 64-bit builds.
@@ -147,9 +146,7 @@ with TCL in order to function. The [sqlite3_analyzer.exe program](https://sqlit
is an example. You can build as described above, and then
enter:
> ~~~~
nmake /f Makefile.msc sqlite3_analyzer.exe
~~~~
> nmake /f Makefile.msc sqlite3_analyzer.exe
And you will end up with a working executable. However, that executable
will depend on having the "tcl98.dll" library somewhere on your %PATH%.
@@ -175,17 +172,11 @@ statically linked so that it does not depend on separate DLL:
5. CD into your SQLite source code directory and build the desired
utility program, but add the following extra argument to the
nmake command line:
<blockquote><pre>
STATICALLY_LINK_TCL=1
</pre></blockquote>
<blockquote><pre>STATICALLY_LINK_TCL=1</pre></blockquote>
<p>So, for example, to build a statically linked version of
sqlite3_analyzer.exe, you might type:
<blockquote><pre>
nmake /f Makefile.msc STATICALLY_LINK_TCL=1 sqlite3_analyzer.exe
</pre></blockquote>
<blockquote><pre>nmake /f Makefile.msc STATICALLY_LINK_TCL=1 sqlite3_analyzer.exe</pre></blockquote>
6. After your executable is built, you can verify that it does not
depend on the TCL DLL by running:
<blockquote><pre>
dumpbin /dependents sqlite3_analyzer.exe
</pre></blockquote>
<blockquote><pre>dumpbin /dependents sqlite3_analyzer.exe</pre></blockquote>
+8 -9
View File
@@ -149,11 +149,10 @@ RFC 8259 format, without extensions. The payload is the ASCII
text representation of that numeric value.
<li value="4"><p><b>INT5</b> &rarr;
The element is a JSON integer value that is not in the
canonical format. The payload is the ASCII
text representation of that numeric value. Because the payload is in a
non-standard format, it will need to be translated when the JSONB is
converted into RFC 8259 text JSON.
The element is a JSON integer literal in hexadecimal notation.
The payload is the ASCII text representation of the literal.
Because the payload is in a non-standard format, it will need
to be translated when the JSONB is converted into RFC 8259 text JSON.
<li value="5"><p><b>FLOAT</b> &rarr;
The element is a JSON floating-point value in the canonical
@@ -162,10 +161,10 @@ text representation of that numeric value.
<li value="6"><p><b>FLOAT5</b> &rarr;
The element is a JSON floating-point value that is not in the
canonical format. The payload is the ASCII
text representation of that numeric value. Because the payload is in a
non-standard format, it will need to be translated when the JSONB is
converted into RFC 8259 text JSON.
canonical JSON format but rather the extended JSON5 format.
The payload is the ASCII text representation of that numeric value.
Because the payload is in a non-standard format, it will need to
be translated when the JSONB is converted into RFC 8259 text JSON.
<li value="7"><p><b>TEXT</b> &rarr;
The element is a JSON string value that does not contain
+27 -25
View File
@@ -172,11 +172,11 @@ struct sqlite3expert {
** Allocate and return nByte bytes of zeroed memory using sqlite3_malloc().
** If the allocation fails, set *pRc to SQLITE_NOMEM and return NULL.
*/
static void *idxMalloc(int *pRc, int nByte){
static void *idxMalloc(int *pRc, i64 nByte){
void *pRet;
assert( *pRc==SQLITE_OK );
assert( nByte>0 );
pRet = sqlite3_malloc(nByte);
pRet = sqlite3_malloc64(nByte);
if( pRet ){
memset(pRet, 0, nByte);
}else{
@@ -243,7 +243,7 @@ static int idxHashAdd(
return 1;
}
}
pEntry = idxMalloc(pRc, sizeof(IdxHashEntry) + nKey+1 + nVal+1);
pEntry = idxMalloc(pRc, sizeof(IdxHashEntry) + (i64)nKey+1 + (i64)nVal+1);
if( pEntry ){
pEntry->zKey = (char*)&pEntry[1];
memcpy(pEntry->zKey, zKey, nKey);
@@ -378,15 +378,15 @@ struct ExpertCsr {
};
static char *expertDequote(const char *zIn){
int n = STRLEN(zIn);
char *zRet = sqlite3_malloc(n);
i64 n = STRLEN(zIn);
char *zRet = sqlite3_malloc64(n);
assert( zIn[0]=='\'' );
assert( zIn[n-1]=='\'' );
if( zRet ){
int iOut = 0;
int iIn = 0;
i64 iOut = 0;
i64 iIn = 0;
for(iIn=1; iIn<(n-1); iIn++){
if( zIn[iIn]=='\'' ){
assert( zIn[iIn+1]=='\'' );
@@ -699,7 +699,7 @@ static int idxGetTableInfo(
sqlite3_stmt *p1 = 0;
int nCol = 0;
int nTab;
int nByte;
i64 nByte;
IdxTable *pNew = 0;
int rc, rc2;
char *pCsr = 0;
@@ -791,14 +791,14 @@ static char *idxAppendText(int *pRc, char *zIn, const char *zFmt, ...){
va_list ap;
char *zAppend = 0;
char *zRet = 0;
int nIn = zIn ? STRLEN(zIn) : 0;
int nAppend = 0;
i64 nIn = zIn ? STRLEN(zIn) : 0;
i64 nAppend = 0;
va_start(ap, zFmt);
if( *pRc==SQLITE_OK ){
zAppend = sqlite3_vmprintf(zFmt, ap);
if( zAppend ){
nAppend = STRLEN(zAppend);
zRet = (char*)sqlite3_malloc(nIn + nAppend + 1);
zRet = (char*)sqlite3_malloc64(nIn + nAppend + 1);
}
if( zAppend && zRet ){
if( nIn ) memcpy(zRet, zIn, nIn);
@@ -1562,8 +1562,8 @@ struct IdxRemCtx {
int eType; /* SQLITE_NULL, INTEGER, REAL, TEXT, BLOB */
i64 iVal; /* SQLITE_INTEGER value */
double rVal; /* SQLITE_FLOAT value */
int nByte; /* Bytes of space allocated at z */
int n; /* Size of buffer z */
i64 nByte; /* Bytes of space allocated at z */
i64 n; /* Size of buffer z */
char *z; /* SQLITE_TEXT/BLOB value */
} aSlot[1];
};
@@ -1599,11 +1599,13 @@ static void idxRemFunc(
break;
case SQLITE_BLOB:
sqlite3_result_blob(pCtx, pSlot->z, pSlot->n, SQLITE_TRANSIENT);
assert( pSlot->n <= 0x7fffffff );
sqlite3_result_blob(pCtx, pSlot->z, (int)pSlot->n, SQLITE_TRANSIENT);
break;
case SQLITE_TEXT:
sqlite3_result_text(pCtx, pSlot->z, pSlot->n, SQLITE_TRANSIENT);
assert( pSlot->n <= 0x7fffffff );
sqlite3_result_text(pCtx, pSlot->z, (int)pSlot->n, SQLITE_TRANSIENT);
break;
}
@@ -1623,10 +1625,10 @@ static void idxRemFunc(
case SQLITE_BLOB:
case SQLITE_TEXT: {
int nByte = sqlite3_value_bytes(argv[1]);
i64 nByte = sqlite3_value_bytes(argv[1]);
const void *pData = 0;
if( nByte>pSlot->nByte ){
char *zNew = (char*)sqlite3_realloc(pSlot->z, nByte*2);
char *zNew = (char*)sqlite3_realloc64(pSlot->z, nByte*2);
if( zNew==0 ){
sqlite3_result_error_nomem(pCtx);
return;
@@ -1681,7 +1683,7 @@ static int idxPopulateOneStat1(
int nCol = 0;
int i;
sqlite3_stmt *pQuery = 0;
int *aStat = 0;
i64 *aStat = 0;
int rc = SQLITE_OK;
assert( p->iSample>0 );
@@ -1727,7 +1729,7 @@ static int idxPopulateOneStat1(
sqlite3_free(zQuery);
if( rc==SQLITE_OK ){
aStat = (int*)idxMalloc(&rc, sizeof(int)*(nCol+1));
aStat = (i64*)idxMalloc(&rc, sizeof(i64)*(nCol+1));
}
if( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pQuery) ){
IdxHashEntry *pEntry;
@@ -1744,11 +1746,11 @@ static int idxPopulateOneStat1(
}
if( rc==SQLITE_OK ){
int s0 = aStat[0];
zStat = sqlite3_mprintf("%d", s0);
i64 s0 = aStat[0];
zStat = sqlite3_mprintf("%lld", s0);
if( zStat==0 ) rc = SQLITE_NOMEM;
for(i=1; rc==SQLITE_OK && i<=nCol; i++){
zStat = idxAppendText(&rc, zStat, " %d", (s0+aStat[i]/2) / aStat[i]);
zStat = idxAppendText(&rc, zStat, " %lld", (s0+aStat[i]/2) / aStat[i]);
}
}
@@ -1827,7 +1829,7 @@ static int idxPopulateStat1(sqlite3expert *p, char **pzErr){
rc = sqlite3_exec(p->dbm, "ANALYZE; PRAGMA writable_schema=1", 0, 0, 0);
if( rc==SQLITE_OK ){
int nByte = sizeof(struct IdxRemCtx) + (sizeof(struct IdxRemSlot) * nMax);
i64 nByte = sizeof(struct IdxRemCtx) + (sizeof(struct IdxRemSlot) * nMax);
pCtx = (struct IdxRemCtx*)idxMalloc(&rc, nByte);
}
@@ -1844,7 +1846,7 @@ static int idxPopulateStat1(sqlite3expert *p, char **pzErr){
}
if( rc==SQLITE_OK ){
pCtx->nSlot = nMax+1;
pCtx->nSlot = (i64)nMax+1;
rc = idxPrepareStmt(p->dbm, &pAllIndex, pzErr, zAllIndex);
}
if( rc==SQLITE_OK ){
@@ -2111,7 +2113,7 @@ int sqlite3_expert_sql(
if( pStmt ){
IdxStatement *pNew;
const char *z = sqlite3_sql(pStmt);
int n = STRLEN(z);
i64 n = STRLEN(z);
pNew = (IdxStatement*)idxMalloc(&rc, sizeof(IdxStatement) + n+1);
if( rc==SQLITE_OK ){
pNew->zSql = (char*)&pNew[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
View File
@@ -17,10 +17,6 @@
#include <string.h>
#include <assert.h>
#ifndef SQLITE_AMALGAMATION
typedef sqlite3_int64 i64;
#endif
/*
** Characters that may appear in the second argument to matchinfo().
*/
+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);
}
+15 -16
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
@@ -88,7 +81,13 @@ typedef sqlite3_uint64 u64;
# define FLEXARRAY 1
#endif
#endif
#endif /* SQLITE_AMALGAMATION */
/*
** Constants for the largest and smallest possible 32-bit signed integers.
*/
# define LARGEST_INT32 ((int)(0x7fffffff))
# define SMALLEST_INT32 ((int)((-1) - LARGEST_INT32))
/* Truncate very long tokens to this many bytes. Hard limit is
** (65536-1-1-4-9)==65521 bytes. The limiting factor is the 16-bit offset
@@ -822,7 +821,7 @@ int sqlite3Fts5ExprPattern(
** i64 iRowid = sqlite3Fts5ExprRowid(pExpr);
** }
*/
int sqlite3Fts5ExprFirst(Fts5Expr*, Fts5Index *pIdx, i64 iMin, int bDesc);
int sqlite3Fts5ExprFirst(Fts5Expr*, Fts5Index *pIdx, i64 iMin, i64, int bDesc);
int sqlite3Fts5ExprNext(Fts5Expr*, i64 iMax);
int sqlite3Fts5ExprEof(Fts5Expr*);
i64 sqlite3Fts5ExprRowid(Fts5Expr*);
+10 -1
View File
@@ -1549,7 +1549,13 @@ static int fts5ExprNodeFirst(Fts5Expr *pExpr, Fts5ExprNode *pNode){
** Return SQLITE_OK if successful, or an SQLite error code otherwise. It
** is not considered an error if the query does not match any documents.
*/
int sqlite3Fts5ExprFirst(Fts5Expr *p, Fts5Index *pIdx, i64 iFirst, int bDesc){
int sqlite3Fts5ExprFirst(
Fts5Expr *p,
Fts5Index *pIdx,
i64 iFirst,
i64 iLast,
int bDesc
){
Fts5ExprNode *pRoot = p->pRoot;
int rc; /* Return code */
@@ -1571,6 +1577,9 @@ int sqlite3Fts5ExprFirst(Fts5Expr *p, Fts5Index *pIdx, i64 iFirst, int bDesc){
assert( pRoot->bEof==0 );
rc = fts5ExprNodeNext(p, pRoot, 0, 0);
}
if( fts5RowidCmp(p, pRoot->iRowid, iLast)>0 ){
pRoot->bEof = 1;
}
return rc;
}
+50 -29
View File
@@ -877,9 +877,9 @@ static Fts5Data *fts5DataRead(Fts5Index *p, i64 iRowid){
if( rc==SQLITE_OK ){
u8 *aOut = 0; /* Read blob data into this buffer */
int nByte = sqlite3_blob_bytes(p->pReader);
int szData = (sizeof(Fts5Data) + 7) & ~7;
sqlite3_int64 nAlloc = szData + nByte + FTS5_DATA_PADDING;
i64 nByte = sqlite3_blob_bytes(p->pReader);
i64 szData = (sizeof(Fts5Data) + 7) & ~7;
i64 nAlloc = szData + nByte + FTS5_DATA_PADDING;
pRet = (Fts5Data*)sqlite3_malloc64(nAlloc);
if( pRet ){
pRet->nn = nByte;
@@ -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 ){
@@ -2074,6 +2074,7 @@ static void fts5SegIterReverseInitPage(Fts5Index *p, Fts5SegIter *pIter){
while( 1 ){
u64 iDelta = 0;
if( i>=n ) break;
if( eDetail==FTS5_DETAIL_NONE ){
/* todo */
if( i<n && a[i]==0 ){
@@ -2481,18 +2482,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 +5848,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 ){
@@ -5928,7 +5931,7 @@ int sqlite3Fts5IndexMerge(Fts5Index *p, int nMerge){
fts5StructureRelease(pStruct);
pStruct = pNew;
nMin = 1;
nMerge = nMerge*-1;
nMerge = (nMerge==SMALLEST_INT32 ? LARGEST_INT32 : (nMerge*-1));
}
if( pStruct && pStruct->nLevel ){
if( fts5IndexMerge(p, &pStruct, nMerge, nMin) ){
@@ -6820,11 +6823,14 @@ 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;
memset(pTmp, 0, SZ_FTS5STRUCTURE(1));
pTmp = &uFts.sFts;
memset(uFts.tmpSpace, 0, sizeof(uFts.tmpSpace));
if( p->pConfig->bContentlessDelete ){
pTmp->nOriginCntr = 1;
}
@@ -8284,19 +8290,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 +8360,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 +8369,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 +8627,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 +8670,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 +8688,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 +8697,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);
}
+37 -17
View File
@@ -511,6 +511,17 @@ static void fts5SetUniqueFlag(sqlite3_index_info *pIdxInfo){
#endif
}
static void fts5SetEstimatedRows(sqlite3_index_info *pIdxInfo, i64 nRow){
#if SQLITE_VERSION_NUMBER>=3008002
#ifndef SQLITE_CORE
if( sqlite3_libversion_number()>=3008002 )
#endif
{
pIdxInfo->estimatedRows = nRow;
}
#endif
}
static int fts5UsePatternMatch(
Fts5Config *pConfig,
struct sqlite3_index_constraint *p
@@ -646,7 +657,7 @@ static int fts5BestIndexMethod(sqlite3_vtab *pVTab, sqlite3_index_info *pInfo){
nSeenMatch++;
idxStr[iIdxStr++] = 'M';
sqlite3_snprintf(6, &idxStr[iIdxStr], "%d", iCol);
idxStr += strlen(&idxStr[iIdxStr]);
iIdxStr += (int)strlen(&idxStr[iIdxStr]);
assert( idxStr[iIdxStr]=='\0' );
}
pInfo->aConstraintUsage[i].argvIndex = ++iCons;
@@ -665,6 +676,7 @@ static int fts5BestIndexMethod(sqlite3_vtab *pVTab, sqlite3_index_info *pInfo){
idxStr[iIdxStr++] = '=';
bSeenEq = 1;
pInfo->aConstraintUsage[i].argvIndex = ++iCons;
pInfo->aConstraintUsage[i].omit = 1;
}
}
}
@@ -712,17 +724,21 @@ static int fts5BestIndexMethod(sqlite3_vtab *pVTab, sqlite3_index_info *pInfo){
/* Calculate the estimated cost based on the flags set in idxFlags. */
if( bSeenEq ){
pInfo->estimatedCost = nSeenMatch ? 1000.0 : 10.0;
if( nSeenMatch==0 ) fts5SetUniqueFlag(pInfo);
}else if( bSeenLt && bSeenGt ){
pInfo->estimatedCost = nSeenMatch ? 5000.0 : 250000.0;
}else if( bSeenLt || bSeenGt ){
pInfo->estimatedCost = nSeenMatch ? 7500.0 : 750000.0;
pInfo->estimatedCost = nSeenMatch ? 1000.0 : 25.0;
fts5SetUniqueFlag(pInfo);
fts5SetEstimatedRows(pInfo, 1);
}else{
pInfo->estimatedCost = nSeenMatch ? 10000.0 : 1000000.0;
}
for(i=1; i<nSeenMatch; i++){
pInfo->estimatedCost *= 0.4;
if( bSeenLt && bSeenGt ){
pInfo->estimatedCost = nSeenMatch ? 5000.0 : 750000.0;
}else if( bSeenLt || bSeenGt ){
pInfo->estimatedCost = nSeenMatch ? 7500.0 : 2250000.0;
}else{
pInfo->estimatedCost = nSeenMatch ? 10000.0 : 3000000.0;
}
for(i=1; i<nSeenMatch; i++){
pInfo->estimatedCost *= 0.4;
}
fts5SetEstimatedRows(pInfo, (i64)(pInfo->estimatedCost / 4.0));
}
pInfo->idxNum = idxFlags;
@@ -921,7 +937,9 @@ static int fts5CursorReseek(Fts5Cursor *pCsr, int *pbSkip){
int bDesc = pCsr->bDesc;
i64 iRowid = sqlite3Fts5ExprRowid(pCsr->pExpr);
rc = sqlite3Fts5ExprFirst(pCsr->pExpr, pTab->p.pIndex, iRowid, bDesc);
rc = sqlite3Fts5ExprFirst(
pCsr->pExpr, pTab->p.pIndex, iRowid, pCsr->iLastRowid, bDesc
);
if( rc==SQLITE_OK && iRowid!=sqlite3Fts5ExprRowid(pCsr->pExpr) ){
*pbSkip = 1;
}
@@ -1093,7 +1111,9 @@ static int fts5CursorFirstSorted(
static int fts5CursorFirst(Fts5FullTable *pTab, Fts5Cursor *pCsr, int bDesc){
int rc;
Fts5Expr *pExpr = pCsr->pExpr;
rc = sqlite3Fts5ExprFirst(pExpr, pTab->p.pIndex, pCsr->iFirstRowid, bDesc);
rc = sqlite3Fts5ExprFirst(
pExpr, pTab->p.pIndex, pCsr->iFirstRowid, pCsr->iLastRowid, bDesc
);
if( sqlite3Fts5ExprEof(pExpr) ){
CsrFlagSet(pCsr, FTS5CSR_EOF);
}
@@ -3601,9 +3621,9 @@ static void fts5LocaleFunc(
sqlite3_value **apArg /* Function arguments */
){
const char *zLocale = 0;
int nLocale = 0;
i64 nLocale = 0;
const char *zText = 0;
int nText = 0;
i64 nText = 0;
assert( nArg==2 );
UNUSED_PARAM(nArg);
@@ -3620,10 +3640,10 @@ static void fts5LocaleFunc(
Fts5Global *p = (Fts5Global*)sqlite3_user_data(pCtx);
u8 *pBlob = 0;
u8 *pCsr = 0;
int nBlob = 0;
i64 nBlob = 0;
nBlob = FTS5_LOCALE_HDR_SIZE + nLocale + 1 + nText;
pBlob = (u8*)sqlite3_malloc(nBlob);
pBlob = (u8*)sqlite3_malloc64(nBlob);
if( pBlob==0 ){
sqlite3_result_error_nomem(pCtx);
return;
+11
View File
@@ -396,7 +396,12 @@ static int fts5VocabOpenMethod(
return rc;
}
/*
** Restore cursor pCsr to the state it was in immediately after being
** created by the xOpen() method.
*/
static void fts5VocabResetCursor(Fts5VocabCursor *pCsr){
int nCol = pCsr->pFts5->pConfig->nCol;
pCsr->rowid = 0;
sqlite3Fts5IterClose(pCsr->pIter);
sqlite3Fts5StructureRelease(pCsr->pStruct);
@@ -406,6 +411,12 @@ static void fts5VocabResetCursor(Fts5VocabCursor *pCsr){
pCsr->nLeTerm = -1;
pCsr->zLeTerm = 0;
pCsr->bEof = 0;
pCsr->iCol = 0;
pCsr->iInstPos = 0;
pCsr->iInstOff = 0;
pCsr->colUsed = 0;
memset(pCsr->aCnt, 0, sizeof(i64)*nCol);
memset(pCsr->aDoc, 0, sizeof(i64)*nCol);
}
/*
+33
View File
@@ -294,6 +294,39 @@ do_execsql_test 7.0 {
INSERT INTO x1 VALUES($doc);
}
#-------------------------------------------------------------------------
# Forum post: https://sqlite.org/forum/forumpost/ea4d8c9acb
#
reset_db
do_execsql_test 8.0 {
PRAGMA encoding = 'UTF-16le';
CREATE VIRTUAL TABLE vt0 USING fts5(c0);
}
set v [db one {SELECT x'2a12'}]
do_execsql_test 8.1 {
INSERT INTO vt0 VALUES ($v);
}
do_execsql_test 8.2 {
SELECT quote(c0) FROM vt0
} {X'2A12'}
do_execsql_test 8.3 {
INSERT INTO vt0(vt0) VALUES('integrity-check');
} {}
reset_db
do_execsql_test 8.4 {
PRAGMA encoding = 'UTF-16le';
CREATE VIRTUAL TABLE vt0 USING fts5(c0);
}
do_execsql_test 8.5 {
INSERT INTO vt0 VALUES (x'2a12');
}
do_execsql_test 8.6 {
SELECT quote(c0) FROM vt0
} {X'2A12'}
do_execsql_test 8.7 {
INSERT INTO vt0(vt0) VALUES('integrity-check');
} {}
} ;# foreach_detail_mode...
+577 -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,582 @@ 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/}
#-------------------------------------------------------------------------
reset_db
do_test 84.0 {
sqlite3 db {}
db deserialize [decode_hexdb {
.open --hexdb
| size 53248 pagesize 4096 filename c1a.txt.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 0d .....@ ........
| 32: 00 00 00 02 00 00 00 01 00 00 00 09 00 00 00 04 ................
| 48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 ................
| 96: 00 00 00 00 0d 0f c7 00 07 0d 92 00 0f 8d 0f 36 ...............6
| 112: 0e cb 0e 6b 0e 0e 0d b6 0d 92 0d 92 00 00 00 00 ...k............
| 3472: 00 00 22 08 06 17 11 11 01 31 74 61 62 6c 65 74 .........1tablet
| 3488: 32 74 32 0d 43 52 45 41 54 45 20 54 41 42 4c 45 2t2.CREATE TABLE
| 3504: 20 74 32 28 78 29 56 07 06 17 1f 1f 01 7d 74 61 t2(x)V.......ta
| 3520: 62 6c 65 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63 blet1_configt1_c
| 3536: 6f 6e 66 69 67 07 43 52 45 41 54 45 20 54 41 42 onfig.CREATE TAB
| 3552: 4c 45 20 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b LE 't1_config'(k
| 3568: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 76 29 PRIMARY KEY, v)
| 3584: 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 5b 06 WITHOUT ROWID[.
| 3600: 07 17 21 21 01 81 01 74 61 62 6c 65 74 31 5f 64 ..!!...tablet1_d
| 3616: 6f 63 73 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65 ocsizet1_docsize
| 3632: 06 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74 .CREATE TABLE 't
| 3648: 31 5f 64 6f 63 73 69 7a 65 27 28 69 64 20 49 4e 1_docsize'(id IN
| 3664: 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 TEGER PRIMARY KE
| 3680: 59 2c 20 73 7a 20 42 4c 4f 42 29 5e 05 07 17 21 Y, sz BLOB)^...!
| 3696: 21 01 81 07 74 61 62 6c 65 74 31 5f 63 6f 6e 74 !...tablet1_cont
| 3712: 65 6e 74 74 31 5f 63 6f 6e 74 65 6e 74 05 43 52 entt1_content.CR
| 3728: 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63 EATE TABLE 't1_c
| 3744: 6f 6e 74 65 6e 74 27 28 69 64 20 49 4e 54 45 47 ontent'(id INTEG
| 3760: 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 ER PRIMARY KEY,
| 3776: 63 30 2c 20 63 31 2c 20 63 32 29 69 04 07 17 19 c0, c1, c2)i....
| 3792: 19 01 81 2d 74 61 62 6c 65 74 31 5f 69 64 78 74 ...-tablet1_idxt
| 3808: 31 5f 69 64 78 04 43 52 45 41 54 45 20 54 41 42 1_idx.CREATE TAB
| 3824: 4c 45 20 27 74 31 5f 69 64 78 27 28 73 65 67 69 LE 't1_idx'(segi
| 3840: 64 2c 20 74 65 72 6d 2c 20 70 67 6e 6f 2c 20 50 d, term, pgno, P
| 3856: 52 49 4d 41 52 59 20 4b 45 59 28 73 65 67 69 64 RIMARY KEY(segid
| 3872: 2c 20 74 65 72 6d 29 29 20 57 49 54 48 4f 55 54 , term)) WITHOUT
| 3888: 20 52 4f 57 49 44 55 03 07 17 1b 1b 01 81 01 74 ROWIDU........t
| 3904: 61 62 6c 65 74 31 5f 64 61 74 61 74 31 5f 64 61 ablet1_datat1_da
| 3920: 74 61 03 43 52 45 41 54 45 20 54 41 42 4c 45 20 ta.CREATE TABLE
| 3936: 27 74 31 5f 64 61 74 61 27 28 69 64 20 49 4e 54 't1_data'(id INT
| 3952: 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 EGER PRIMARY KEY
| 3968: 2c 20 62 6c 6f 63 6b 20 42 4c 4f 42 29 38 02 06 , block BLOB)8..
| 3984: 17 11 11 08 5f 74 61 62 6c 65 74 31 74 31 43 52 ...._tablet1t1CR
| 4000: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 EATE VIRTUAL TAB
| 4016: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 35 LE t1 USING fts5
| 4032: 28 61 2c 62 2c 63 29 00 00 00 39 00 00 00 00 00 (a,b,c)...9.....
| page 3 offset 8192
| 0: 05 00 00 00 02 0f f1 00 00 00 00 0c 0f fb 0f f1 ................
| 4064: 00 00 0b 01 03 00 1c 81 3a 84 5e 81 3a 81 3a 0a ........:.^.:.:.
| 4080: 0a 00 00 00 0b 84 80 80 80 80 01 00 00 00 0a 0a ................
| page 4 offset 12288
| 0: 0a 00 00 00 01 0f fa 00 0f fa 00 00 00 00 00 00 ................
| 4080: 00 00 00 00 00 00 00 00 00 00 05 04 09 0c 01 02 ................
| page 7 offset 24576
| 0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 00 00 00 00 ................
| 4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04 ........version.
| page 10 offset 36864
| 0: 0d 00 00 00 02 0f e2 00 0f e2 0f ef 00 00 00 00 ................
| 4064: 00 00 0b 01 03 00 1c 81 3a 84 5e 81 3a 81 3a 0f ........:.^.:.:.
| 4080: 0a 03 00 24 00 00 00 00 01 01 02 00 01 01 01 09 ...$............
| page 11 offset 40960
| 0: 0d 00 00 00 01 00 22 00 00 22 00 00 00 00 00 00 ................
| 32: 00 00 9f 56 84 80 80 80 80 01 04 00 bf 30 00 00 ...V.........0..
| 48: 0f 58 02 30 30 19 02 05 01 02 05 01 02 05 16 02 .X.00...........
| 64: 05 01 02 05 01 02 05 61 02 05 01 02 05 01 02 05 .......a........
| 80: 13 02 05 01 02 05 01 02 05 0d 02 03 01 02 03 01 ................
| 96: 02 03 02 09 78 66 66 66 66 66 66 66 65 81 17 02 ....xfffffffe...
| 112: 05 01 02 05 01 02 05 01 01 31 04 02 04 01 02 04 .........1......
| 128: 01 02 04 01 02 05 01 02 05 01 02 05 0d 02 06 01 ................
| 144: 02 06 01 02 06 02 01 30 79 02 04 01 02 04 01 02 .......0y.......
| 160: 04 03 02 30 30 2b 02 05 01 02 05 01 02 05 58 02 ...00+........X.
| 176: 05 01 02 05 01 02 05 01 02 05 01 02 05 01 02 05 ................
| 192: 16 02 05 01 02 05 01 02 05 05 06 30 30 30 30 30 ...........00000
| 208: 30 81 0b 02 04 01 02 04 01 02 04 10 02 05 01 02 0...............
| 224: 05 01 02 05 03 02 32 34 76 02 05 01 02 05 01 02 ......24v.......
| 240: 05 02 01 38 07 02 04 01 02 04 01 02 04 01 01 32 ...8...........2
| 256: 28 02 04 01 02 04 01 02 04 04 02 05 01 02 05 01 (...............
| 272: 02 05 02 01 30 1f 02 05 01 02 05 01 02 05 03 02 ....0...........
| 288: 30 30 10 02 05 01 02 05 01 02 05 6a 02 04 01 02 00.........j....
| 304: 04 01 02 04 02 08 35 30 30 30 30 30 30 30 81 26 ......50000000.&
| 320: 02 05 01 02 05 01 02 05 01 01 33 07 02 06 01 02 ..........3.....
| 336: 06 01 02 06 81 2c 02 04 01 02 04 01 02 04 02 04 .....,..........
| 352: 32 37 36 36 81 23 02 05 01 02 05 01 02 05 01 01 2766.#..........
| 368: 34 13 02 05 01 02 05 01 02 05 02 03 30 39 36 1c 4...........096.
| 384: 02 05 01 02 05 01 02 05 07 02 05 01 02 05 01 02 ................
| 400: 05 01 03 35 30 30 7f 02 05 01 02 05 01 02 05 04 ...500..........
| 416: 02 30 30 81 0e 02 06 01 02 06 01 02 06 06 03 30 .00............0
| 432: 30 30 81 11 02 04 01 02 04 01 02 04 01 05 36 35 00............65
| 448: 35 33 36 81 1a 02 05 01 02 05 01 02 05 01 04 38 536............8
| 464: 31 39 32 81 02 02 06 01 02 06 01 02 06 01 05 61 192............a
| 480: 6c 6c 6f 77 01 02 02 01 02 02 01 02 02 02 02 72 llow...........r
| 496: 67 81 08 02 04 01 02 04 01 02 04 02 05 74 6f 6d g............tom
| 512: 69 63 04 02 02 01 02 02 01 02 02 03 06 74 61 63 ic...........tac
| 528: 68 65 64 79 02 03 01 02 03 01 02 03 02 0d 75 74 hedy..........ut
| 544: 6f 63 68 65 63 6b 70 6f 69 6e 74 2b 02 04 01 02 ocheckpoint+....
| 560: 04 01 02 04 05 06 76 61 63 75 75 6d 0d 02 03 01 ......vacuum....
| 576: 02 03 01 02 03 01 06 62 69 6e 61 72 79 03 06 01 .......binary...
| 592: 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 ................
| 608: 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02 ................
| 624: 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02 03 ................
| 640: 06 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 ................
| 656: 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 ................
| 672: 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 ................
| 688: 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02 ................
| 704: 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02 03 ................
| 720: 06 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 ................
| 736: 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 ................
| 752: 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 ................
| 768: 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02 ................
| 784: 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02 03 ................
| 800: 06 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 ................
| 816: 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 ................
| 832: 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 ................
| 848: 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02 ................
| 864: 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02 03 ................
| 880: 06 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 ................
| 896: 01 02 02 02 07 79 74 65 63 6f 64 65 37 02 03 01 .....ytecode7...
| 912: 02 03 01 02 03 01 05 63 61 63 68 65 10 02 03 01 .......cache....
| 928: 02 03 01 01 03 02 04 6c 61 6e 67 07 02 03 01 02 .......lang.....
| 944: 03 01 02 03 02 05 6f 6c 75 6d 6e 7c 02 03 01 02 ......olumn|....
| 960: 03 01 02 03 03 06 6d 6d 65 6e 74 73 43 02 04 01 ......mmentsC...
| 976: 02 04 01 02 04 04 05 70 69 6c 65 72 07 02 02 01 .......piler....
| 992: 02 02 01 02 02 05 04 6f 75 6e 64 7f 02 03 01 02 .......ound.....
| 1008: 03 01 02 03 03 03 75 6e 74 81 17 02 04 01 02 04 ......unt.......
| 1024: 01 02 04 02 05 75 72 73 6f 72 3a 02 03 01 02 03 .....ursor:.....
| 1040: 01 02 03 01 06 64 62 70 61 67 65 3d 02 03 01 02 .....dbpage=....
| 1056: 03 01 02 03 03 04 73 74 61 74 40 02 03 01 02 03 ......stat@.....
| 1072: 01 02 03 02 04 65 62 75 67 0a 02 02 01 02 02 01 .....ebug.......
| 1088: 02 02 03 05 66 61 75 6c 74 0d 02 02 01 02 02 01 ....fault.......
| 1104: 02 02 01 02 02 01 02 02 01 02 02 01 02 02 01 02 ................
| 1120: 02 01 02 02 01 02 02 01 02 02 01 02 02 01 02 02 ................
| 1136: 01 02 02 01 02 02 01 02 02 01 02 02 01 02 02 01 ................
| 1152: 02 02 01 02 02 01 02 02 01 02 02 01 02 02 01 02 ................
| 1168: 02 01 02 02 01 02 02 01 02 02 01 02 02 01 02 02 ................
| 1184: 01 02 02 01 02 02 01 02 02 01 02 02 01 02 02 01 ................
| 1200: 02 02 01 02 02 01 02 02 01 02 02 01 02 02 4f 02 ..............O.
| 1216: 03 01 02 03 01 02 03 03 03 70 74 68 81 05 02 04 .........pth....
| 1232: 01 02 04 01 02 04 19 02 04 01 02 04 01 02 04 02 ................
| 1248: 05 69 72 65 63 74 34 02 02 01 02 02 01 02 02 01 .irect4.........
| 1264: 06 65 6e 61 62 6c 65 37 02 02 01 02 02 01 02 02 .enable7........
| 1280: 01 02 02 01 02 02 01 02 02 01 02 02 01 02 02 01 ................
| 1296: 02 02 01 02 02 01 02 02 01 02 02 01 02 02 01 02 ................
| 1312: 02 01 02 02 01 02 02 01 02 02 01 02 02 01 02 02 ................
| 1328: 01 02 02 01 02 02 01 02 02 01 02 02 01 02 02 01 ................
| 1344: 02 02 01 02 02 01 02 02 01 02 02 01 02 02 01 02 ................
| 1360: 02 01 02 02 01 02 02 01 02 02 01 02 02 01 02 02 ................
| 1376: 01 02 02 01 02 02 01 02 02 01 02 02 01 02 02 01 ................
| 1392: 02 02 01 02 02 01 02 02 01 02 02 01 02 02 01 02 ................
| 1408: 02 01 02 02 01 02 02 01 02 02 01 02 02 01 02 02 ................
| 1424: 01 02 02 01 02 02 01 02 02 01 02 02 01 02 02 01 ................
| 1440: 02 02 01 02 02 01 02 02 01 02 02 01 02 02 01 02 ................
| 1456: 02 01 02 02 02 06 78 70 6c 61 69 6e 43 02 03 01 ......xplainC...
| 1472: 02 03 01 02 03 04 01 72 81 05 02 03 01 02 03 01 .......r........
| 1488: 02 03 03 07 74 65 6e 73 69 6f 6e 81 2f 02 04 01 ....tension./...
| 1504: 02 04 01 02 04 01 04 66 69 6c 65 13 02 03 01 02 .......file.....
| 1520: 03 01 02 03 02 05 6f 72 6d 61 74 13 02 04 01 02 ......ormat.....
| 1536: 04 01 02 04 02 03 74 73 33 46 02 03 01 02 03 01 ......ts3F......
| 1552: 02 03 01 02 03 01 02 03 01 02 03 04 01 34 4c 02 .............4L.
| 1568: 03 01 02 03 01 02 03 04 01 35 4f 02 03 01 02 03 .........5O.....
| 1584: 01 02 03 02 03 75 6e 63 5e 02 05 01 02 05 01 02 .....unc^.......
| 1600: 05 05 04 74 69 6f 6e 73 02 05 01 02 05 01 02 05 ...tions........
| 1616: 13 02 03 01 02 03 01 02 03 09 01 73 55 02 04 01 ...........sU...
| 1632: 02 04 01 02 04 01 07 67 65 6f 70 6f 6c 79 52 02 .......geopolyR.
| 1648: 03 01 02 03 01 02 03 01 05 68 69 6e 74 73 3a 02 .........hints:.
| 1664: 04 01 02 04 01 02 04 02 03 6f 6f 6b 61 02 04 01 .........ooka...
| 1680: 02 04 01 02 04 01 02 69 6e 01 02 04 01 02 04 01 .......in.......
| 1696: 02 04 03 04 69 74 73 7a 1f 02 04 01 02 04 01 02 ....itsz........
| 1712: 04 03 08 74 72 69 6e 73 69 63 73 04 02 03 01 02 ...trinsics.....
| 1728: 03 01 02 03 01 07 6a 6f 75 72 6e 61 6c 16 02 03 ......journal...
| 1744: 01 02 03 01 02 03 01 06 6c 65 6e 67 74 68 81 0b ........length..
| 1760: 02 03 01 02 03 01 02 03 01 02 05 01 02 05 01 02 ................
| 1776: 05 0d 02 04 01 02 04 01 02 04 02 03 69 6b 65 81 ............ike.
| 1792: 0e 02 03 01 02 03 01 02 03 03 03 6d 69 74 16 02 ...........mit..
| 1808: 05 01 02 05 01 02 05 5e 02 04 01 02 04 01 02 04 .......^........
| 1824: 02 03 6f 61 64 81 2f 02 03 01 02 03 01 02 03 01 ..oad./.........
| 1840: 06 6d 61 6c 6c 6f 63 76 02 02 01 02 02 01 02 02 .mallocv........
| 1856: 3a 02 03 01 02 03 01 02 03 03 02 74 68 55 02 03 :..........thU..
| 1872: 01 02 03 01 02 03 03 01 78 79 02 02 01 02 02 01 ........xy......
| 1888: 02 02 01 02 02 01 02 02 01 02 02 01 02 02 01 02 ................
| 1904: 02 01 02 02 01 02 02 01 02 02 01 02 02 01 02 02 ................
| 1920: 01 02 02 01 02 02 01 02 02 01 02 02 01 02 02 01 ................
| 1936: 02 02 01 02 02 01 02 02 01 02 02 01 02 02 01 02 ................
| 1952: 02 01 02 02 01 02 02 01 02 02 01 02 02 01 02 02 ................
| 1968: 01 02 02 01 02 02 01 02 02 01 02 02 01 02 02 01 ................
| 1984: 02 02 01 02 02 01 02 02 01 02 02 01 02 02 01 02 ................
| 2000: 02 01 02 02 01 02 02 01 02 02 01 02 02 01 02 02 ................
| 2016: 01 02 02 01 02 02 01 02 02 01 02 02 01 02 02 01 ................
| 2032: 02 02 02 05 65 6d 6f 72 79 81 11 02 03 01 02 03 ....emory.......
| 2048: 01 02 03 04 04 73 79 73 35 58 02 03 01 02 03 01 .....sys5X......
| 2064: 02 03 02 03 6d 61 70 19 02 03 01 02 03 01 02 03 ....map.........
| 2080: 79 02 03 01 02 03 01 02 03 02 04 75 74 65 78 81 y..........utex.
| 2096: 2c 02 02 01 02 02 01 02 02 01 06 6e 6f 63 61 73 ,..........nocas
| 2112: 65 02 06 01 02 02 03 06 01 02 02 03 06 01 02 02 e...............
| 2128: 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02 03 ................
| 2144: 06 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 ................
| 2160: 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 ................
| 2176: 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 ................
| 2192: 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02 ................
| 2208: 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02 03 ................
| 2224: 06 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 ................
| 2240: 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 ................
| 2256: 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 ................
| 2272: 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02 ................
| 2288: 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02 03 ................
| 2304: 06 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 ................
| 2320: 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 ................
| 2336: 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 ................
| 2352: 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02 ................
| 2368: 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02 03 ................
| 2384: 06 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 ................
| 2400: 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 ................
| 2416: 02 02 03 06 01 02 02 03 07 72 6d 61 6c 69 7a 65 .........rmalize
| 2432: 5b 02 03 01 02 03 01 02 03 02 05 75 6d 62 65 72 [..........umber
| 2448: 81 23 02 04 01 02 04 01 02 04 01 06 6f 66 66 73 .#..........offs
| 2464: 65 74 5e 02 03 01 02 03 01 02 03 02 03 6d 69 74 et^..........mit
| 2480: 81 2c 02 03 01 02 03 01 02 03 01 02 02 01 02 02 .,..............
| 2496: 01 02 02 02 01 70 81 26 02 04 01 02 04 01 02 04 .....p.&........
| 2512: 02 07 76 65 72 66 6c 6f 77 34 02 03 01 02 03 01 ..verflow4......
| 2528: 02 03 01 04 70 61 67 65 1c 02 03 01 02 03 01 02 ....page........
| 2544: 03 64 02 04 01 02 04 01 02 04 13 02 03 01 02 03 .d..............
| 2560: 01 02 03 01 02 03 01 02 03 01 02 03 03 09 72 65 ..............re
| 2576: 6e 74 68 65 73 69 73 49 02 04 01 02 04 01 02 04 nthesisI........
| 2592: 03 05 74 74 65 72 6e 81 0e 02 04 01 02 04 01 02 ..ttern.........
| 2608: 04 02 05 63 61 63 68 65 1f 02 03 01 02 03 01 02 ...cache........
| 2624: 03 02 08 72 65 75 70 64 61 74 65 61 02 03 01 02 ...reupdatea....
| 2640: 03 01 02 03 01 04 72 65 61 64 34 02 04 01 02 04 ......read4.....
| 2656: 01 02 04 03 07 63 75 72 73 69 76 65 22 02 03 01 .....cursive....
| 2672: 02 03 01 02 03 02 04 6f 77 69 64 01 02 03 01 02 .......owid.....
| 2688: 03 01 02 03 02 04 74 72 65 65 64 02 03 01 02 03 ......treed.....
| 2704: 01 02 03 04 02 69 6d 01 06 01 02 02 03 06 01 02 .....im.........
| 2720: 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02 ................
| 2736: 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02 03 ................
| 2752: 06 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 ................
| 2768: 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 ................
| 2784: 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 ................
| 2800: 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02 ................
| 2816: 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02 03 ................
| 2832: 06 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 ................
| 2848: 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 ................
| 2864: 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 ................
| 2880: 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02 ................
| 2896: 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02 03 ................
| 2912: 06 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 ................
| 2928: 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 ................
| 2944: 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 ................
| 2960: 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02 ................
| 2976: 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02 03 ................
| 2992: 06 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 ................
| 3008: 01 02 02 03 06 01 02 02 03 06 01 02 02 01 0a 73 ...............s
| 3024: 63 61 6e 73 74 61 74 75 73 70 02 04 01 02 04 01 canstatusp......
| 3040: 02 04 02 05 65 63 74 6f 72 25 02 03 01 02 03 01 ....ector%......
| 3056: 02 03 03 04 6c 65 63 74 7f 02 04 01 02 04 01 02 ....lect........
| 3072: 04 03 05 73 73 69 6f 6e 67 02 03 01 02 03 01 02 ...ssiong.......
| 3088: 03 02 03 69 7a 65 10 02 04 01 02 04 01 02 04 04 ...ize..........
| 3104: 02 04 01 02 04 01 02 04 01 02 04 01 02 04 01 02 ................
| 3120: 04 01 02 04 01 02 04 01 02 04 07 02 04 01 02 04 ................
| 3136: 01 02 04 5b 02 05 01 02 05 01 02 05 10 02 04 01 ...[............
| 3152: 02 04 01 02 04 04 02 04 01 02 04 01 02 04 02 03 ................
| 3168: 6f 66 74 76 02 03 01 02 03 01 02 03 02 02 71 6c oftv..........ql
| 3184: 5e 02 04 01 02 04 01 02 04 13 02 04 01 02 04 01 ^...............
| 3200: 02 04 28 02 03 01 02 03 01 02 03 02 04 74 61 74 ..(..........tat
| 3216: 34 6a 02 03 01 02 03 01 02 03 03 02 6d 74 70 02 4j..........mtp.
| 3232: 03 01 02 03 01 02 03 05 04 76 74 61 62 6d 02 03 .........vtabm..
| 3248: 01 02 03 01 02 03 03 03 6f 72 65 81 35 02 03 01 ........ore.5...
| 3264: 02 03 01 02 03 02 0a 79 6e 63 68 72 6f 6e 6f 75 .......ynchronou
| 3280: 73 28 02 03 01 02 03 01 02 03 04 02 04 01 02 04 s(..............
| 3296: 01 02 04 03 04 73 74 65 6d 81 32 02 02 01 02 02 .....stem.2.....
| 3312: 01 02 02 01 04 74 65 6d 70 81 35 02 02 01 02 02 .....temp.5.....
| 3328: 01 02 02 02 06 68 72 65 61 64 73 31 02 04 01 02 .....hreads1....
| 3344: 04 01 02 04 76 02 04 01 02 04 01 02 04 08 03 61 ....v..........a
| 3360: 66 65 81 38 02 02 01 02 02 01 02 02 02 06 72 69 fe.8..........ri
| 3376: 67 67 65 72 81 20 02 03 01 02 03 01 02 03 08 01 gger. ..........
| 3392: 73 22 02 04 01 02 04 01 02 04 01 07 75 6e 6b 6e s...........unkn
| 3408: 6f 77 6e 73 02 03 01 02 03 01 02 03 01 08 76 61 owns..........va
| 3424: 72 69 61 62 6c 65 81 23 02 03 01 02 03 01 02 03 riable.#........
| 3440: 02 03 64 62 65 81 26 02 03 01 02 03 01 02 03 02 ..dbe.&.........
| 3456: 03 69 65 77 01 02 05 01 02 05 01 02 05 02 03 74 .iew...........t
| 3472: 61 62 37 02 04 01 02 04 01 02 04 04 02 04 01 02 ab7.............
| 3488: 04 01 02 04 01 02 04 01 02 04 01 02 04 01 03 77 ...............w
| 3504: 61 6c 2b 02 03 01 02 03 01 02 03 01 02 03 01 02 al+.............
| 3520: 03 01 02 03 02 05 6f 72 6b 65 72 31 02 03 01 02 ......orker1....
| 3536: 03 01 02 03 76 02 03 01 02 03 01 02 03 01 01 78 ....v..........x
| 3552: 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 ................
| 3568: 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 ................
| 3584: 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 ................
| 3600: 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 ................
| 3616: 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 ................
| 3632: 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 ................
| 3648: 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 ................
| 3664: 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 ................
| 3680: 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 ................
| 3696: 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 ................
| 3712: 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 ................
| 3728: 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 ................
| 3744: 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 ................
| 3760: 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 ................
| 3776: 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 ................
| 3792: 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 ................
| 3808: 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 ................
| 3824: 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 ................
| 3840: 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 ................
| 3856: 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 ................
| 3872: 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 ................
| 3888: 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 ................
| 3904: 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 ................
| 3920: 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 ................
| 3936: 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 ................
| 3952: 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 ................
| 3968: 06 01 01 02 01 06 04 30 15 1e 0c 28 1b 0d 0c 15 .......0...(....
| 3984: 0c 16 14 16 10 0c 17 0e 0e 0f 11 10 10 0e 10 11 ................
| 4000: 18 11 82 3e 12 10 0f 10 11 10 0f 0f 10 11 0f 0f ...>............
| 4016: 81 05 18 10 81 45 11 0d 13 0f 10 17 0c 0c 0e 18 .....E..........
| 4032: 0c 12 10 0e 0d 0f 13 12 24 0f 17 0f 1a 0d 81 1c ........$.......
| 4048: 11 0f 17 10 82 3e 12 11 11 18 0d 12 2a 14 11 10 .....>......*...
| 4064: 13 0f 12 0f 0f 82 3a 15 10 0f 10 4d 0e 1f 0f 0d ......:....M....
| 4080: 0f 0f 1e 10 10 1a 0f 12 0c 12 14 0f 0e 20 17 19 ............. ..
| page 12 offset 45056
| 0: 0d 00 00 00 01 0d f4 00 0d f4 00 00 00 00 00 00 ................
| 3568: 00 00 00 00 84 04 84 80 80 80 80 02 04 00 88 0c ................
| 3584: 00 07 02 00 01 01 02 56 06 01 01 02 01 06 01 01 .......V........
| 3600: 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 ................
| 3616: 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 ................
| 3632: 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 ................
| 3648: 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 ................
| 3664: 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 ................
| 3680: 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 ................
| 3696: 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 ................
| 3712: 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 ................
| 3728: 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 ................
| 3744: 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 ................
| 3760: 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 ................
| 3776: 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 ................
| 3792: 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 ................
| 3808: 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 ................
| 3824: 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 ................
| 3840: 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 ................
| 3856: 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 ................
| 3872: 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 ................
| 3888: 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 ................
| 3904: 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 ................
| 3920: 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 ................
| 3936: 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 ................
| 3952: 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 ................
| 3968: 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 ................
| 3984: 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 ................
| 4000: 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 ................
| 4016: 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 ................
| 4032: 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 ................
| 4048: 52 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 R...............
| 4064: 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 ................
| 4080: 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 ................
| end c1a.txt.db
}]} {}
do_catchsql_test 84.1 {
SELECT * FROM t1('R*R*x') ORDER BY rowid DESC;
} {1 {fts5: corruption found reading blob 137438953475 from table "t1"}}
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
+53
View File
@@ -0,0 +1,53 @@
# 2025 October 13
#
# 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 test is focused on really large position lists. Those that require
# 4 or 5 byte position-list size varints. Because of the amount of memory
# required, these tests only run on 64-bit platforms.
#
source [file join [file dirname [info script]] fts5_common.tcl]
set testprefix fts5corruptbig
# If SQLITE_ENABLE_FTS5 is not defined, omit this file.
ifcapable !fts5 {
finish_test
return
}
if { $tcl_platform(wordSize)<8 } {
finish_test
return
}
if { $SQLITE_MAX_LENGTH!=0x7FFFFFFF } {
finish_test
return
}
do_execsql_test 1.0 {
CREATE VIRTUAL TABLE t1 USING fts5(x);
}
do_execsql_test 1.1 {
UPDATE t1_data SET block = zeroblob(2147483640) WHERE id=10;
}
do_execsql_test 1.2 {
SELECT id, length(block) FROM t1_data
} {1 0 10 2147483640}
do_catchsql_test 1.3 {
SELECT * FROM t1('abc')
} {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 {
+69
View File
@@ -0,0 +1,69 @@
# 2014 June 17
#
# 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 FTS5 module.
#
source [file join [file dirname [info script]] fts5_common.tcl]
set testprefix fts5join
# If SQLITE_ENABLE_FTS5 is not defined, omit this file.
ifcapable !fts5 {
finish_test
return
}
do_execsql_test 1.0 {
CREATE VIRTUAL TABLE vt USING fts5(x);
INSERT INTO vt VALUES('abc');
INSERT INTO vt VALUES('xyz');
CREATE TABLE t1(a INTEGER PRIMARY KEY, b TIMESTAMP);
INSERT INTO t1 VALUES(1, 1), (2, 2);
CREATE INDEX i1 ON t1(b);
}
# set sqlite_where_trace [expr 0xFFF]
do_eqp_test 1.1 {
SELECT * FROM vt, t1 WHERE vt.rowid = t1.rowid ORDER BY t1.rowid;
} {
QUERY PLAN
|--SCAN t1
`--SCAN vt VIRTUAL TABLE INDEX 0:=
}
do_eqp_test 1.2 {
SELECT * FROM vt, t1 WHERE vt.rowid = t1.rowid AND b>? ORDER BY b LIMIT 10
} {
QUERY PLAN
|--SEARCH t1 USING COVERING INDEX i1 (b>?)
`--SCAN vt VIRTUAL TABLE INDEX 0:=
}
do_eqp_test 1.3 {
SELECT * FROM vt, t1 WHERE vt.rowid = t1.rowid AND b>?
} {
QUERY PLAN
|--SEARCH t1 USING COVERING INDEX i1 (b>?)
`--SCAN vt VIRTUAL TABLE INDEX 0:=
}
do_eqp_test 1.4 {
SELECT * FROM vt, t1 WHERE vt.rowid = t1.rowid ORDER BY b
} {
QUERY PLAN
|--SCAN t1 USING COVERING INDEX i1
`--SCAN vt VIRTUAL TABLE INDEX 0:=
}
finish_test
+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
+16
View File
@@ -238,6 +238,22 @@ do_execsql_test 6.3 {
INSERT INTO g1(g1) VALUES('integrity-check');
}
#--------------------------------------------------------------------------
# Check that passing -2147483648 as the parameter to a merge command
# does not cause a signed integer overflow error.
#
reset_db
do_execsql_test 7.0 {
CREATE VIRTUAL TABLE f1 USING fts5(a);
}
do_execsql_test 7.1 {
INSERT INTO f1 VALUES('one two three');
INSERT INTO f1 VALUES('four five six');
INSERT INTO f1 VALUES('seven eight nine');
}
do_execsql_test 7.2 {
INSERT INTO f1(f1, rank) VALUES('merge', -2147483648);
}
finish_test
+12
View File
@@ -685,5 +685,17 @@ do_execsql_test 26.1 {
COMMIT;
}
#-------------------------------------------------------------------------
reset_db
do_execsql_test 27.0 {
CREATE VIRTUAL TABLE ft1 USING fts5(a, b);
INSERT INTO ft1(rowid, a, b) VALUES(3, '3', '3');
}
do_execsql_test 27.1 {
SELECT * FROM ft1 WHERE rowid=3 AND b MATCH 'hello';
}
finish_test
+4 -4
View File
@@ -38,15 +38,15 @@ foreach {tn sql uses} {
1.2 { DELETE FROM ft WHERE rowid=? } 0
1.3 { DELETE FROM ft WHERE rowid=? } 0
1.4 { DELETE FROM ft WHERE ft MATCH '1' } 1
1.5 { DELETE FROM ft WHERE ft MATCH '1' AND rowid=? } 1
1.6 { DELETE FROM ft WHERE ft MATCH '1' AND rowid=? } 1
1.5 { DELETE FROM ft WHERE ft MATCH '1' AND rowid=? } 0
1.6 { DELETE FROM ft WHERE ft MATCH '1' AND rowid=? } 0
2.1 { UPDATE ft SET content='a b c' } 1
2.2 { UPDATE ft SET content='a b c' WHERE rowid=? } 0
2.3 { UPDATE ft SET content='a b c' WHERE rowid=? } 0
2.4 { UPDATE ft SET content='a b c' WHERE ft MATCH '1' } 1
2.5 { UPDATE ft SET content='a b c' WHERE ft MATCH '1' AND rowid=? } 1
2.6 { UPDATE ft SET content='a b c' WHERE ft MATCH '1' AND rowid=? } 1
2.5 { UPDATE ft SET content='a b c' WHERE ft MATCH '1' AND rowid=? } 0
2.6 { UPDATE ft SET content='a b c' WHERE ft MATCH '1' AND rowid=? } 0
} {
do_test 1.$tn { sql_uses_stmt db $sql } $uses
}
+22
View File
@@ -305,6 +305,28 @@ do_catchsql_test 6.2 {
sqlite3_fts5_may_be_corrupt 0
#-------------------------------------------------------------------------
reset_db
do_execsql_test 7.0 {
CREATE VIRTUAL TABLE t1 USING fts5(a, b);
CREATE VIRTUAL TABLE v1 USING fts5vocab(t1, col);
INSERT INTO t1 VALUES('xx', 'xx');
CREATE TABLE x1(t);
INSERT INTO x1 VALUES('xx');
INSERT INTO x1 VALUES('xx');
SELECT term, col FROM v1;
} {
xx a xx b
}
do_execsql_test 7.1 {
SELECT * FROM x1 WHERE 'a'=(SELECT col FROM v1 WHERE term=t)
} {xx xx}
finish_test
+2
View File
@@ -139,6 +139,7 @@ do_test 2.3 {
sqlite3_test_control SQLITE_TESTCTRL_IMPOSTER db main 0 0
db eval {
PRAGMA writable_schema=on;
DELETE FROM imp1 WHERE rowid=1;
DELETE FROM imp2 WHERE rowid=2;
}
@@ -174,6 +175,7 @@ do_test 3.2 {
sqlite3_test_control SQLITE_TESTCTRL_IMPOSTER db main 0 0
db eval {
PRAGMA writable_schema=on;
DELETE FROM imp1 WHERE a=5;
}
execsql_pp {
+1
View File
@@ -29,6 +29,7 @@ do_execsql_test 1.0 {
proc imposter_edit {obj create sql} {
sqlite3 xdb test.db
set pgno [xdb one {SELECT rootpage FROM sqlite_schema WHERE name=$obj}]
xdb eval {PRAGMA Writable_schema=ON}
sqlite3_test_control SQLITE_TESTCTRL_IMPOSTER xdb main 1 $pgno
xdb eval $create
+1
View File
@@ -160,6 +160,7 @@ static char *intckMprintf(sqlite3_intck *p, const char *zFmt, ...){
sqlite3_free(zRet);
zRet = 0;
}
va_end(ap);
return zRet;
}
+21 -4
View File
@@ -168,6 +168,10 @@
** Creates a verbose JNI function name. Suffix must be
** the JNI-mangled form of the function's name, minus the
** prefix seen in this macro.
**
** If you get java.lang.UnsatisfiedLinkError when calling newly-added
** native bindings, be sure that the mangled name is correct. It can
** be found in the generated sqlite3-jni.h.
*/
#define JniFuncName(Suffix) \
Java_org_sqlite_jni_capi_CApi_sqlite3_ ## Suffix
@@ -177,10 +181,10 @@
JNIEXPORT ReturnType JNICALL JniFuncName(Suffix)
/*
** S3JniApi's intent is that CFunc be the C API func(s) the
** being-declared JNI function is wrapping, making it easier to find
** that function's JNI-side entry point. The other args are for JniDecl.
** See the many examples in this file.
** S3JniApi's intent is that CFunc be the name(s) of the C API func(s)
** the being-declared JNI function is wrapping, making it easier to
** find those bindings' JNI-side entry points. The other args are for
** JniDecl. See the many examples in this file.
*/
#define S3JniApi(CFunc,ReturnType,Suffix) JniDecl(ReturnType,Suffix)
@@ -3856,6 +3860,19 @@ S3JniApi(sqlite3_errmsg(),jstring,1errmsg)(
effect should be identical to using errmsg16(), however. */;
}
S3JniApi(sqlite3_set_errmsg(),jint,1set_1errmsg)(
JniArgsEnvClass, jobject jpDb, jint errCode, jstring msg
){
sqlite3 * const pDb = PtrGet_sqlite3(jpDb);
const char *zUtf8;
jint rc;
if( !pDb ) return SQLITE_MISUSE;
zUtf8 = msg ? s3jni_jstring_to_mutf8(msg) : NULL;
rc = sqlite3_set_errmsg(pDb, (int)errCode, zUtf8);
s3jni_mutf8_release(msg, zUtf8);
return rc;
}
S3JniApi(sqlite3_errstr(),jstring,1errstr)(
JniArgsEnvClass, jint rcCode
){
+9 -1
View File
@@ -1342,7 +1342,7 @@ JNIEXPORT jint JNICALL Java_org_sqlite_jni_capi_CApi_sqlite3_1data_1count
* Method: sqlite3_db_config
* Signature: (Lorg/sqlite/jni/capi/sqlite3;IILorg/sqlite/jni/capi/OutputPointer/Int32;)I
*/
JNIEXPORT jint JNICALL Java_org_sqlite_jni_capi_CApi_sqlite3_1db_1config__Lorg_sqlite_jni_capi_sqlite3_2IILorg_sqlite_jni_capi_OutputPointer_00024Int32_2
JNIEXPORT jint JNICALL Java_org_sqlite_jni_capi_CApi_sqlite3_1db_1config__Lorg_sqlite_jni_capi_sqlite3_2IILorg_sqlite_jni_capi_OutputPointer_Int32_2
(JNIEnv *, jclass, jobject, jint, jint, jobject);
/*
@@ -1417,6 +1417,14 @@ JNIEXPORT jint JNICALL Java_org_sqlite_jni_capi_CApi_sqlite3_1errcode
JNIEXPORT jstring JNICALL Java_org_sqlite_jni_capi_CApi_sqlite3_1errmsg
(JNIEnv *, jclass, jobject);
/*
* Class: org_sqlite_jni_capi_CApi
* Method: sqlite3_set_errmsg
* Signature: (Lorg/sqlite/jni/capi/sqlite3;ILjava/lang/String;)I
*/
JNIEXPORT jint JNICALL Java_org_sqlite_jni_capi_CApi_sqlite3_1set_1errmsg
(JNIEnv *, jclass, jobject, jint, jstring);
/*
* Class: org_sqlite_jni_capi_CApi
* Method: sqlite3_error_offset
+6 -1
View File
@@ -1197,10 +1197,15 @@ public final class CApi {
public static native String sqlite3_errmsg(@NotNull sqlite3 db);
/** Added in 3.51.0. */
public static native int sqlite3_set_errmsg(@NotNull sqlite3 db,
int resultCode,
String msg);
private static native int sqlite3_error_offset(@NotNull long ptrToDb);
/**
Note that the returned byte offset values assume UTF-8-encoded
Caveat: the returned byte offset values assume UTF-8-encoded
inputs, so won't always match character offsets in Java Strings.
*/
public static int sqlite3_error_offset(@NotNull sqlite3 db){
@@ -1874,6 +1874,20 @@ public class Tester1 implements Runnable {
sqlite3_close_v2(db);
}
private void testSetErrmsg(){
final sqlite3 db = createNewDb();
int rc = sqlite3_set_errmsg(db, SQLITE_RANGE, "nope");
affirm( 0==rc );
affirm( SQLITE_MISUSE == sqlite3_set_errmsg(null, 0, null) );
affirm( "nope".equals(sqlite3_errmsg(db)) );
affirm( SQLITE_RANGE == sqlite3_errcode(db) );
rc = sqlite3_set_errmsg(db, 0, null);
affirm( "not an error".equals(sqlite3_errmsg(db)) );
affirm( 0 == sqlite3_errcode(db) );
sqlite3_close_v2(db);
}
/* Copy/paste/rename this to add new tests. */
private void _testTemplate(){
final sqlite3 db = createNewDb();
-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
-10
View File
@@ -9,11 +9,6 @@ Each source file contains a description in its header comment. See the
header comments for details about each extension. Additional notes are
as follows:
* **carray.c** &mdash; This module implements the
[carray](https://sqlite.org/carray.html) table-valued function.
It is a good example of how to go about implementing a custom
[table-valued function](https://sqlite.org/vtab.html#tabfunc2).
* **csv.c** &mdash; A [virtual table](https://sqlite.org/vtab.html)
for reading
[Comma-Separated-Value (CSV) files](https://en.wikipedia.org/wiki/Comma-separated_values).
@@ -28,11 +23,6 @@ as follows:
[SQLite amalgamation](https://sqlite.org/amalgamation.html). See
<https://sqlite.org/json1.html> for additional information.
* **memvfs.c** &mdash; This file implements a custom
[VFS](https://sqlite.org/vfs.html) that stores an entire database
file in a single block of RAM. It serves as a good example of how
to implement a simple custom VFS.
* **rot13.c** &mdash; This file implements the very simple rot13()
substitution function. This file makes a good template for implementing
new custom SQL functions for SQLite.
+5 -5
View File
@@ -514,7 +514,7 @@ struct amatch_cursor {
sqlite3_int64 iRowid; /* The rowid of the current word */
amatch_langid iLang; /* Use this language ID */
amatch_cost rLimit; /* Maximum cost of any term */
int nBuf; /* Space allocated for zBuf */
sqlite3_int64 nBuf; /* Space allocated for zBuf */
int oomErr; /* True following an OOM error */
int nWord; /* Number of amatch_word objects */
char *zBuf; /* Temp-use buffer space */
@@ -1039,7 +1039,7 @@ static void amatchAddWord(
nTail = (int)strlen(zWordTail);
if( nBase+nTail+3>pCur->nBuf ){
pCur->nBuf = nBase+nTail+100;
pCur->zBuf = sqlite3_realloc(pCur->zBuf, pCur->nBuf);
pCur->zBuf = sqlite3_realloc64(pCur->zBuf, pCur->nBuf);
if( pCur->zBuf==0 ){
pCur->nBuf = 0;
return;
@@ -1105,13 +1105,13 @@ static int amatchNext(sqlite3_vtab_cursor *cur){
amatch_avl *pNode;
int isMatch = 0;
amatch_vtab *p = pCur->pVtab;
int nWord;
sqlite3_int64 nWord;
int rc;
int i;
const char *zW;
amatch_rule *pRule;
char *zBuf = 0;
char nBuf = 0;
sqlite3_int64 nBuf = 0;
char zNext[8];
char zNextIn[8];
int nNextIn;
@@ -1158,7 +1158,7 @@ static int amatchNext(sqlite3_vtab_cursor *cur){
nWord = (int)strlen(pWord->zWord+2);
if( nWord+20>nBuf ){
nBuf = (char)(nWord+100);
zBuf = sqlite3_realloc(zBuf, nBuf);
zBuf = sqlite3_realloc64(zBuf, nBuf);
if( zBuf==0 ) return SQLITE_NOMEM;
}
amatchStrcpy(zBuf, pWord->zWord+2);
+4 -2
View File
@@ -207,7 +207,9 @@ static u8* fromBase64( char *pIn, int ncIn, u8 *pOut ){
/* This function does the work for the SQLite base64(x) UDF. */
static void base64(sqlite3_context *context, int na, sqlite3_value *av[]){
int nb, nc, nv = sqlite3_value_bytes(av[0]);
sqlite3_int64 nb;
sqlite3_int64 nv = sqlite3_value_bytes(av[0]);
sqlite3_int64 nc;
int nvMax = sqlite3_limit(sqlite3_context_db_handle(context),
SQLITE_LIMIT_LENGTH, -1);
char *cBuf;
@@ -216,7 +218,7 @@ static void base64(sqlite3_context *context, int na, sqlite3_value *av[]){
switch( sqlite3_value_type(av[0]) ){
case SQLITE_BLOB:
nb = nv;
nc = 4*(nv+2/3); /* quads needed */
nc = 4*((nv+2)/3); /* quads needed */
nc += (nc+(B64_DARK_MAX-1))/B64_DARK_MAX + 1; /* LFs and a 0-terminator */
if( nvMax < nc ){
sqlite3_result_error(context, "blob expanded to base64 too big", -1);
+1 -1
View File
@@ -286,7 +286,7 @@ static void is_base85(sqlite3_context *context, int na, sqlite3_value *av[]){
/* This function does the work for the SQLite base85(x) UDF. */
static void base85(sqlite3_context *context, int na, sqlite3_value *av[]){
int nb, nc, nv = sqlite3_value_bytes(av[0]);
sqlite3_int64 nb, nc, nv = sqlite3_value_bytes(av[0]);
int nvMax = sqlite3_limit(sqlite3_context_db_handle(context),
SQLITE_LIMIT_LENGTH, -1);
char *cBuf;
-50
View File
@@ -1,50 +0,0 @@
/*
** 2020-11-17
**
** 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.
**
*************************************************************************
**
** Interface definitions for the CARRAY table-valued function
** extension.
*/
#ifndef _CARRAY_H
#define _CARRAY_H
#include "sqlite3.h" /* Required for error code definitions */
#ifdef __cplusplus
extern "C" {
#endif
/* Use this interface to bind an array to the single-argument version
** of CARRAY().
*/
SQLITE_API int sqlite3_carray_bind(
sqlite3_stmt *pStmt, /* Statement to be bound */
int i, /* Parameter index */
void *aData, /* Pointer to array data */
int nData, /* Number of data elements */
int mFlags, /* CARRAY flags */
void (*xDel)(void*) /* Destructgor for aData*/
);
/* Allowed values for the mFlags parameter to sqlite3_carray_bind().
*/
#define CARRAY_INT32 0 /* Data is 32-bit signed integers */
#define CARRAY_INT64 1 /* Data is 64-bit signed integers */
#define CARRAY_DOUBLE 2 /* Data is doubles */
#define CARRAY_TEXT 3 /* Data is char* */
#define CARRAY_BLOB 4 /* Data is struct iovec */
#ifdef __cplusplus
} /* end of the 'extern "C"' block */
#endif
#endif /* ifndef _CARRAY_H */
+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;
+3
View File
@@ -370,6 +370,7 @@ static int completionFilter(
if( pCur->nPrefix>0 ){
pCur->zPrefix = sqlite3_mprintf("%s", sqlite3_value_text(argv[iArg]));
if( pCur->zPrefix==0 ) return SQLITE_NOMEM;
pCur->nPrefix = (int)strlen(pCur->zPrefix);
}
iArg = 1;
}
@@ -378,6 +379,7 @@ static int completionFilter(
if( pCur->nLine>0 ){
pCur->zLine = sqlite3_mprintf("%s", sqlite3_value_text(argv[iArg]));
if( pCur->zLine==0 ) return SQLITE_NOMEM;
pCur->nLine = (int)strlen(pCur->zLine);
}
}
if( pCur->zLine!=0 && pCur->zPrefix==0 ){
@@ -389,6 +391,7 @@ static int completionFilter(
if( pCur->nPrefix>0 ){
pCur->zPrefix = sqlite3_mprintf("%.*s", pCur->nPrefix, pCur->zLine + i);
if( pCur->zPrefix==0 ) return SQLITE_NOMEM;
pCur->nPrefix = (int)strlen(pCur->zPrefix);
}
}
pCur->iRowid = 0;
+2 -2
View File
@@ -59,7 +59,7 @@ static void compressFunc(
pIn = sqlite3_value_blob(argv[0]);
nIn = sqlite3_value_bytes(argv[0]);
nOut = 13 + nIn + (nIn+999)/1000;
pOut = sqlite3_malloc( nOut+5 );
pOut = sqlite3_malloc64( nOut+5 );
for(i=4; i>=0; i--){
x[i] = (nIn >> (7*(4-i)))&0x7f;
}
@@ -98,7 +98,7 @@ static void uncompressFunc(
nOut = (nOut<<7) | (pIn[i]&0x7f);
if( (pIn[i]&0x80)!=0 ){ i++; break; }
}
pOut = sqlite3_malloc( nOut+1 );
pOut = sqlite3_malloc64( nOut+1 );
rc = uncompress(pOut, &nOut, &pIn[i], nIn-i);
if( rc==Z_OK ){
sqlite3_result_blob(context, pOut, nOut, sqlite3_free);
+7 -5
View File
@@ -62,6 +62,9 @@ SQLITE_EXTENSION_INIT1
# define CSV_NOINLINE
#endif
#ifndef SQLITEINT_H
typedef sqlite3_int64 i64;
#endif
/* Max size of the error message in a CsvReader */
#define CSV_MXERR 200
@@ -74,9 +77,9 @@ typedef struct CsvReader CsvReader;
struct CsvReader {
FILE *in; /* Read the CSV text from this input stream */
char *z; /* Accumulated text for a field */
int n; /* Number of bytes in z */
int nAlloc; /* Space allocated for z[] */
int nLine; /* Current line number */
i64 n; /* Number of bytes in z */
i64 nAlloc; /* Space allocated for z[] */
i64 nLine; /* Current line number */
int bNotFirst; /* True if prior text has been seen */
int cTerm; /* Character that terminated the most recent field */
size_t iIn; /* Next unread character in the input buffer */
@@ -174,7 +177,7 @@ static int csv_getc(CsvReader *p){
** Return 0 on success and non-zero if there is an OOM error */
static CSV_NOINLINE int csv_resize_and_append(CsvReader *p, char c){
char *zNew;
int nNew = p->nAlloc*2 + 100;
i64 nNew = p->nAlloc*2 + 100;
zNew = sqlite3_realloc64(p->z, nNew);
if( zNew ){
p->z = zNew;
@@ -510,7 +513,6 @@ static int csvtabConnect(
# define CSV_DATA (azPValue[1])
# define CSV_SCHEMA (azPValue[2])
assert( sizeof(azPValue)==sizeof(azParam) );
memset(&sRdr, 0, sizeof(sRdr));
memset(azPValue, 0, sizeof(azPValue));

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