Compare commits

...

569 Commits

Author SHA1 Message Date
stephan e5ca18182a Revert the native impl of kvvfs's xOpen() (as distinct from the JS impl which the wasm build uses) to the historical db name restrictions of 'local' or 'session', failing with SQLITE_CANTOPEN if passed another name. [ec866b04d088e53b] overhauled support for kvvfs db names in JS but it turns out that the native impl still relies on those names in order to match journals to databases. Correct a related too-lenient assert() in the WASM pieces.
FossilOrigin-Name: fabcad09176cce96cacdd55ef3dde3be5b8062f513ac13a70e3db874358e6be2
2026-06-15 12:22:06 +00:00
dan 23e50585eb Fix a problem that could cause fts5 to return incorrect answers when performing prefix queries on tokens with synonyms. Bug [bugs:/info/2026-06-14T11:11:06Z | 2026-06-14T11:11:06Z].
FossilOrigin-Name: 323d87541a63f0b2c64271c78ad6ebd5d04220da59aebfdfbc07caa691af816a
2026-06-15 11:47:52 +00:00
dan b273dc8de1 Regardless of whether the platform is 32 or 64-bits, Use 64-bit arithmetic to calculate buffer sizes in the fts3_snippet(). Bug [bugs:/info/2026-06-14T09:19:52Z | 2026-06-14T09:19:52Z].
FossilOrigin-Name: 79dc1949b2171c46f6649743ed7dbbf6b83046901ec18ffcbc37a2a47544b100
2026-06-15 11:03:13 +00:00
drh 9c2ac0b6e3 Fix rounding behavior in the decimal extension when all leading digits
are 9 and there is not fractional component.
[bugs:/info/2026-06-15T03:49:42Z|Bug 2026-06-15T03:49:42Z].

FossilOrigin-Name: c6a3b18ee9eb4b8dda57fab94aea9c61aed5e1ffe600f0bcf2c90ca752f2512b
2026-06-15 10:13:31 +00:00
drh a5e5116228 Prevent array overflow when decoding a corrupted value from the
underlying key/value store.
[bugs:/info/2026-06-14T21:58:12Z|Bug 2026-06-14T21:58:12Z]

FossilOrigin-Name: 732c8f81b5a914831c36610ddaed3da15a7f9fdbf54f44872e181b941368d702
2026-06-15 01:24:06 +00:00
drh 5d59375ac8 Remove the unused, untested, experiemental "blobio.c" extension, to
avoid confusing AIs.
[bugs:/info/2026-06-14T15:12:50Z|Bug 2026-06-14T15:12:50Z]

FossilOrigin-Name: 45918d5e97a0c29c6fa03d09ac8e131dcca3bf4268bf4f5c46c221b1f900651a
2026-06-14 22:01:56 +00:00
drh 1b828b8770 Do not allow ridiculous "columns=N" values in the (unused) csv virtual
table in the extensions folder.
[bugs:/info/2026-06-14T15:22:47Z|Bug 2026-06-14T15:22:47Z]

FossilOrigin-Name: ecae4a2ddf103fe575c6864d201e83a9bb084b511685397db41b3349c91b38e6
2026-06-14 20:10:28 +00:00
drh d8f6cc7ea4 Make the --header option to the CLI sticky, so that it does not get
turned off by subsequence --csv or similar mode change options.
[bugs:/info/2026-06-13T11:49:18Z|Bug 2026-06-13T11:49:18Z]

FossilOrigin-Name: b19cef1862444ee694eeea2254aa9a8d74d2343da5a8257c22e3068f388aa2fd
2026-06-13 18:04:18 +00:00
dan 2884421c05 When reading a super-journal name from a journal file, allocate a new buffer rather than using Pager.pTmpSpace. This prevents a buffer overrun that could occur when using a VFS with a large sqlite3_vfs.mxPathname value with a database with a small page size.
FossilOrigin-Name: 7f71859841af7cb0806f58e9c8013a990fcca72b807a0513156d7127ce5c7b62
2026-06-12 18:35:24 +00:00
dan 7459c01689 Fix errors in comments on this branch. Also prefer SQLITE_NOMEM_BKPT to SQLITE_NOMEM.
FossilOrigin-Name: ac17669e840dbac5c7c75e9b6014cca2d289aba8de36f9d1d0d61186e8cc6207
2026-06-12 17:32:44 +00:00
dan 053048a40f Fix a memory leak that could follow an OOM error in the new code on this branch.
FossilOrigin-Name: d4774a898730d9ef7564bba0a8531748e31e6517ab29564c2f5a0196c1584451
2026-06-12 17:16:12 +00:00
drh 2ca10782d2 Improved documentation for sqlite3_deserialize().
FossilOrigin-Name: f15d076820f4a0d9e7fa32d99575bce27bde5e987bb415e6cfb69b06f0da7e1e
2026-06-12 16:47:45 +00:00
drh 2429af2e0c Do not use shared locks on SHM files when the filename is a long DOS-device
path.  Only used shared locks for UNC paths.  Do not confuse the
long-DOS-device syntax with UNC paths.

FossilOrigin-Name: a4691489f21bb1645bb8de649268dd457af53c5f613f2a7fd2e5569f029efa87
2026-06-12 16:26:39 +00:00
dan 865a8f3072 Fix a buffer overwrite in fts3 that could occur while processing NEAR queries against corrupt records. Bug [bugs:/info/2026-06-11T23:11:26Z | 2026-06-11T23:11:26Z].
FossilOrigin-Name: b0f773e99eb45cde0953e4870a0a7436c35277c95146fdab3aa06ebbc076c79e
2026-06-12 15:36:26 +00:00
drh 124f449319 When using a read-only WAL/SHM, handle a corrupt page size in the WAL
file correctly.
[bugs:/info/2026-06-11T22:20:03Z|Bug 2026-06-11T22:20:03Z].

FossilOrigin-Name: 09ab0a1bac4eb7de651f78cfd3027b452308da7e04c4ccd7f46c402c82fd6ca5
2026-06-12 12:15:42 +00:00
drh 76ad3be617 Add the --raw option to the dbtotxt command-line tool, for debugging.
FossilOrigin-Name: abfecc08209c9377b6762125b2372e4eb1ab56b4d0399467c8fbe5cfc11c806e
2026-06-12 11:55:39 +00:00
dan 23d0a08176 Fix a signed integer overflow that could occur in fts3 when processing corrupt database records. Bug [bugs:/info/2026-06-11T23:12:25Z | 2026-06-11T23:12:25Z].
FossilOrigin-Name: 978d04f051c06aff798f915b0774da19a0b4f89f9daee124f7e62b12afaaced8
2026-06-12 11:24:30 +00:00
drh b14202f86e Comment improvements on the ".ar -x" command of the CLI. No changes to code.
FossilOrigin-Name: 5b939fb1a284088c4bd46adf517cf598816e2262cd77ee2d9caaab1cef2ce9a1
2026-06-11 23:11:14 +00:00
drh 0b9f4ee89c Fix harmless compiler warnings.
FossilOrigin-Name: dd0c161fcd1619518cd4671d64afb6afeec44c140ec176ccb8616d381a88f42f
2026-06-11 22:48:16 +00:00
drh d1b9001a7f Further improvements to the ".ar" command of the CLI.
FossilOrigin-Name: 6149b938c7a1e95a0fb8600a81557dd0e3efb7b312f3806e2c09d03acf9f4b17
2026-06-11 16:39:41 +00:00
drh d57abdb017 Three-pass algorithm for the ".ar x" command in the CLI, so that symlinks
are created after all regular files are created.

FossilOrigin-Name: 37a80d20fe1948db15ac72432ed7bf3d573c80807fe0a58c58440647e3c34ab8
2026-06-11 14:28:48 +00:00
drh 970b3bc4c4 Add the (undocumented) --debug option to the ".ar" command in the CLI
FossilOrigin-Name: 3a040ffc47fa3e38b36716587c56d9b071d9c69d9daaa9cf0ef6baa654419ab5
2026-06-11 14:14:37 +00:00
drh d688d1551a Improved detection of corrupt node IDs in RTree shadow tables.
Test case in TH3.

FossilOrigin-Name: e01a185a699d0c4ad2341ce2114bc826f02768735cef67179a1127229a073d03
2026-06-11 01:31:19 +00:00
dan dacabb4a33 When reading a super-journal name from a journal file, allocate a new buffer rather than using Pager.pTmpSpace. This prevents a buffer overrun that could occur when using a VFS with a large sqlite3_vfs.mxPathname value with a database with a small page size.
FossilOrigin-Name: 37aa82a50a0a1c5edb4c4f2de1cb00fa009ebbfeb420df3de72231c5d883518a
2026-06-10 20:10:19 +00:00
dan 2bd7ac6716 Fix a signed-integer overflow in fts5 that might occur when dealing with strategicly corrupted records. Bug [bugs:/info/2026-06-10T03:56:42Z | 2026-06-10T03:56:42Z].
FossilOrigin-Name: fc6442ee54795fbeb746539193716238aa653d80170523bc327ae3ce0d945ebf
2026-06-10 16:51:20 +00:00
drh 49edbe2150 Detect an OOM condition in the realpath() function of the fileio.c extension
and cause that function to return NULL.  To Do:  we should go back in and
fix realpath() to raise an SQLITE_NOMEM error on OOM rather than returning
NULL.  But we will delay that, in as much as OOMs are all but impossible
on modern OSes.
[bug:/info/2026-06-10T07:46:32Z|Bug 2026-06-10T07:46:32Z].

FossilOrigin-Name: 8b961dc3d27c5aa62a5dc7c2e44f8b505817e184f8499f3bb903e06b5aec1b72
2026-06-10 10:40:29 +00:00
drh 062016c2fd Fix a possible signed integer overflow in the RBU extension given a
maliciously crafted delta.
[bugs:/info/2026-06-10T06:41:54Z|Bug 2026-06-10T06:41:54Z].

FossilOrigin-Name: 8531c0c3b61771592b055b0c22e903b8301a4161c7bcb7f9fc54d730b080d095
2026-06-10 10:13:11 +00:00
drh 84ead09d94 Harden code that processes Fossil Deltas against OOM and maliciously
malformed delta blobs.
[bugs:/info/2026-06-10T07:01:00Z|Bug 2026-06-10T07:01:00Z] and
[bugs:/info/2026-06-10T07:06:43Z|Bug 2026-06-10T07:06:43Z].

FossilOrigin-Name: 67271c31292bc1bddbb5e144c881c85c9f91b3963a1db4bae1f738adab50f7c0
2026-06-10 09:51:33 +00:00
dan 2cb57d9d4a Avoid a possible integer overflow when fts5 tokenizes a very large document. Only possible with non-standard builds that use large values of SQLITE_MAX_LENGTH. Bug [bugs:/info/2026-06-09T05:27:16Z | 2026-06-09T05:27:16Z].
FossilOrigin-Name: d562e91374e2bebcf75a00776b4def532bb71914a07e37c8507f7a5918db1d3b
2026-06-09 10:43:37 +00:00
drh 2f5d281796 Change loop counter variables from int to i64 to avoid a potential
integer overflow inside an assert() statement when SQLite is compiled 
with SQLITE_DEBUG and an extra-large SQLITE_MAX_LENGTH.  Does not
affect production builds.
[bugs:/info/2026-06-09T08:53:14Z|Bug 2026-06-09T08:53:14Z].

FossilOrigin-Name: 77f615d9833b1f5eaabcb1a6b59af3a6698752abcd16592091f1630beec5969e
2026-06-09 10:16:40 +00:00
drh 6a1efec20a Fix builds on i486 CPUs. [forum:/info/2025-01-25T12:58:44Z|Forum 2025-01-25T12:58:44Z].
FossilOrigin-Name: 4cb349370daab17123770c814c71872a3e4c616a3f984569b3d7f97f9c3f5ea0
2026-06-08 18:15:27 +00:00
dan 082e41f17b Fix another buffer overread in fts5 when processing corrupt records. Bug [bugs:/info/2026-06-08T16:03:39Z | 2026-06-08T16:03:39Z ].
FossilOrigin-Name: 8ba5acabf9a0273ffbc2ba0bacc7f0b000690db91081858e4e563d6cbeeb4e7a
2026-06-08 17:48:00 +00:00
dan 19a2ba1f5b Fix a buffer overread that could occur in fts5 when processing corrupt records. Bug [bugs:/info/2026-06-08T11:15:52Z | 2026-06-08T11:15:52Z]
FossilOrigin-Name: b07441cfc06b8e6b47a4f4a6e0f5c261da580d5afe82444cc7f42a9f39ea7026
2026-06-08 15:20:49 +00:00
dan b677c5afd4 Avoid a potential use-after-free in fts5. Report [bugs:/info/2026-06-08T08:45:27Z | 2026-06-08T08:45:27Z].
FossilOrigin-Name: 9c018b02dbfb071c748d540ad679a4dbdc0fb88a62988e02cb51a3403509febe
2026-06-08 12:03:52 +00:00
dan 7340b032d1 Clamp the nToken parameter to the fts5 snippet() function between 0 and 64. It has always been documented this way, but not previously implemented. Report [bugs:/info/2026-06-08T08:29:00Z | 2026-06-08T08:29:00Z].
FossilOrigin-Name: 4af1d9b3e54a7c42552e61284456bbd7089e525d4aa55e580f7518956d8521bb
2026-06-08 11:24:05 +00:00
dan 2bc3763ec5 Add extra tests to check that non-deterministic functions may not be used in indexes.
FossilOrigin-Name: beeef9dc2b1d778ca628c5e3adc097778646933233ea5ea4f03d2cace0199c17
2026-06-08 10:47:55 +00:00
drh a6812a4242 Improvements to the GCC compiler bug work-around of check-in [7fae321095ebec77].
FossilOrigin-Name: 247894f70d8616cb16468025809513a7db70086d24d2a289b50b4e8d9e073eb4
2026-06-06 18:32:53 +00:00
drh 6bf7825ac5 Minor performance enhancement and improved comments on the quicksort
algorithm used by the median() implementation in func.c.

FossilOrigin-Name: 2800f6a75bbb6ddc86f2e029a7d36ff08febe03812302fb7931eb68da316f74d
2026-06-06 17:20:35 +00:00
drh 192b3a539b A new approach to working around the GCC bug.
FossilOrigin-Name: 2f95186ea568b27d45bd19fca1e03b878afb0b1ea0938875897c7323bdeab8a2
2026-06-05 00:11:56 +00:00
drh 002d33d8c5 Disable the vector-IN-SELECT optimization if the number of columns is so
large that it would cause the WhereTerm.nChild column to wrap.
[bugs:/info/2026-06-04T10:00:49Z|Bug 2026-06-04T10:00:49Z].

FossilOrigin-Name: bb49dfc948048779a30deff9a3d1bb39846f6f72c26a2bdcdd0e386251720fe6
2026-06-04 16:56:11 +00:00
dan ee181f479a Fix a crash that could be caused by configuring the pager-cache with a bulk allocation too small to fit even one page. Bug [bugs:/info/2026-06-04T07:03:12Z | 2026-06-04T07:03:12Z].
FossilOrigin-Name: b4b9dc632b06f932759bc2fceeb6fa1dd6e0de329106ae1d34be874ea1695859
2026-06-04 11:48:18 +00:00
drh 076db92d85 Fix a possible NULL pointer derefence in the (experimental and untested)
uuid.c extension.
[bugs:/info/2026-06-04T09:50:59Z|Bug 2026-06-04T09:50:59Z].

FossilOrigin-Name: fa6374fe3ae1530f0b5ba10b7e6fb703ffe5dd592c532a965e7d50b7d2d70a5f
2026-06-04 11:42:23 +00:00
drh 2dacda40a6 Extra testcase() macros to ensure adequate testing of the previous
check-in.

FossilOrigin-Name: 003013ccabaaa7aea1e78844474ed5032ee9c9824f98c5d36687ac5256a5e128
2026-06-04 11:39:13 +00:00
dan 62a3734e78 Fix problems with expressions like "(?,?,?) IN (SELECT c,b,a FROM ...)" when there is an index on columns "c", "b" and "a", but not in that order. Bug [bugs:/info/2026-06-04T07:02:53Z | 2026-06-04T07:02:53Z].
FossilOrigin-Name: 07667afd0f17b73b58df8ace6a2a5c3a593276f9b7804cb14d4705051258dd75
2026-06-04 11:19:43 +00:00
drh 95d072cc81 Clearly mark the ext/misc/wholenumber.c extension as "testing and
debugging use only".  Fix a potential integer overflow that can occur
if the above warning is ignored.
[bugs:/info/2026-06-04T09:40:28Z|Bug 2026-06-04T09:40:28Z].

FossilOrigin-Name: 44154ea9ae99d532d5c7268d70bd8b32751f7a82c367c7bd1ec0e6948d71d1b8
2026-06-04 11:18:11 +00:00
dan 0120735de1 Update the utf-8 decoder in the ICU extension to treat invalid sequences as codepoint 0xFFFD, matching the core. Report [bugs:/info/2026-06-03T04:04:46Z | 2026-06-03T04:04:46Z].
FossilOrigin-Name: 840be0ee62c0ba34f4916c382e2d07071bebd8ce7bca31deb1616869722bfa4d
2026-06-03 17:21:12 +00:00
dan d80528ad4d Fix a faulty assert() in rtree that could fire when processing an unusually large record. Bug [bugs:/info/2026-06-03T14:44:46Z | 2026-06-03T14:44:46Z].
FossilOrigin-Name: e7335dd377a73fc2b913076ee659ed2b0c4a131b16e04b1b55fae677d6b56e8a
2026-06-03 16:46:15 +00:00
drh c2d29194a8 Use tail recursion on the larger of the two partitions when doing a
quicksort as part of the implementation of the median() function,
to avoid excess stack usage on pathological inputs.
[bugs:/info/2026-06-03T07:26:42Z|Bug 2026-06-03T07:26:42Z].

FossilOrigin-Name: 7dc987165c030c260ba90a8878291b5ceb037c48c2f437a8fb3f05b6c4f84fde
2026-06-03 16:21:17 +00:00
dan 61523e22f9 Fix an integer overflow problem in fts3 that could lead to a buffer overwrite on platforms where size_t is 32-bits. Bug [bugs:/info/2026-06-03T04:28:51Z | 2026-06-03T04:28:51Z].
FossilOrigin-Name: ef0c66d2a2e0b8f523633efca66a97236bb5a502525eb6a00a28a350ec7c76e6
2026-06-03 15:29:59 +00:00
dan 51b2c3863b Fix another buffer overread in fts5 that could occur when processing corrupt records. Bug [bugs:/info/2026-06-03T03:54:40Z | 2026-06-03T03:54:40Z].
FossilOrigin-Name: b5337c87cc314e6830615e4efe2d4723fa7cedf87ce404f60d6e520aeab77cbc
2026-06-03 14:58:13 +00:00
dan 6feeafc7de Fix another potential buffer overrun that could occur in fts5 when processing corrupt records.
FossilOrigin-Name: 6ee44b199512b8cac604bf062f893a9047af4b5bfc881bb7cb69ae42d0a0adb4
2026-06-03 13:49:33 +00:00
drh a735462db6 Fix a potential UAF bug in the zipfile extension.
[bugs:/info/2026-06-03T10:58:51Z|Bug 2026-06-03T10:58:51Z].

FossilOrigin-Name: 1fb5e9169ace6bea2bdf9013f39002c1ce5dc9ce51d6007bec22d91f456c15f0
2026-06-03 13:12:20 +00:00
drh d2240cc988 Fix negative array index in "testing and debugging uses only" extension
qpvtab.c.
[bugs:/info/2026-06-03T07:26:26Z|Bug 2026-06-03T07:26:26Z].

FossilOrigin-Name: d066699fcacd87496645f3aa3c4049935410ae2451879a033102304c80273deb
2026-06-03 12:43:50 +00:00
dan 942b7c555a Avoid excessive recursion and stack overflow in fts3 when processing a corrupt
database.

FossilOrigin-Name: 21369378769195f20f839231f625582552eaa3f79044ca3e3efb7f9476b515a8
2026-06-03 11:37:45 +00:00
drh 069e5acd63 The prefix_length() function should stop at the first NUL terminator.
[bugs:/info/2026-06-03T07:42:00Z|Bug 2026-06-03T07:42:00Z].

FossilOrigin-Name: a9b8bdea0683bb03015ea1ee38f75636c80c189eed4b786b6d3d654a831cfdfb
2026-06-03 11:07:47 +00:00
drh 1c0a370472 Make the (unused, untested, and unsupported) ext/misc/compress.c routines
responsive to OOM conditions.
[bugs:/info/2026-06-03T08:28:36Z|Bug 2026-06-03T08:28:36Z].

FossilOrigin-Name: e3120e2a4339d51210645b14d075abba27dd97bd6bd6d42f445dd5baf3d337e3
2026-06-03 10:55:08 +00:00
dan 2acb57c1be Fix a case where sqlite3expert could be tricked into executing arbitrary SQL by a corrupt database schema.
FossilOrigin-Name: 8a633070e62bdc83a7cf895fd1a22c04b13579659df7cee9584d95096bfffab1
2026-06-02 15:20:37 +00:00
dan 2a28b15748 Add extra test case to zipfile.test. No code changes.
FossilOrigin-Name: 83fe72bcdf866bdaf3043ae5b0c1eb45a9d50a01b24b7a531858271dd746baab
2026-06-02 11:11:02 +00:00
drh b1637e5408 Fix the CLI so that it works when compiled using STDCALL on
Microsoft x86.  Change should not affect other platforms.
[forum:/info/2026-06-02T09:44:12Z|Forum 2026-06-02T09:44:12Z].

FossilOrigin-Name: 83adece349aed73b8d0a3aec141213ea329150eb529f4fd9774ca157b49d02fc
2026-06-02 10:08:30 +00:00
drh b48ca02d64 Enhance PRAGMA integrity_check so that it better detects incorrect
header sizes at the beginning of cells.

FossilOrigin-Name: 08bb2878e7575ab069f8f132537880a47a4d4543a1ac8bffc55e32488223245c
2026-06-01 20:02:17 +00:00
dan c28f2d22b6 Disable transitive WHERE constraints when there are explicit COLLATE operators. Fix for report [bugs:/info/ffddcd3617 | 2026-05-31T08:33:10Z].
FossilOrigin-Name: 18ee3a17c589cfd34500b6a6547d0cb51aea4dd14b4e1e4b2d0cf0dbfb32378e
2026-06-01 18:01:13 +00:00
dan 48a591fa6b Minor performance improvement for the patch on this branch.
FossilOrigin-Name: 2702fecc5c47704bdae535459e59260b55c571ff3b7d09617541e36829d4cf9c
2026-06-01 17:56:11 +00:00
dan 2c351bbf82 Fix minor problems surrounding transitive WHERE constraints and explicit COLLATE terms.
FossilOrigin-Name: 9500238a1d603a3f08a8fc0954725d5d217aab339720146ea0bc700e47b81c3c
2026-06-01 17:40:23 +00:00
drh ddea119f82 Make sure the authenticator is called for columns that are part of
a USING in a FULL JOIN.
[bugs:/info/2026-05-31T02:00:37Z|Bug 2026-05-31T02:00:37Z].

FossilOrigin-Name: 4ef88a36f9d9669b0d74c58f79ad497803885ff6078e5f9685f13c96eab397cc
2026-06-01 16:49:39 +00:00
dan 03aa9a7b50 For expressions of the form "(x, y...) IN (SELECT a, b ...)" where the result is not true, consider the collation sequences of columns "a" and "b" when determinining if the result should be false or NULL. Bug report [bugs:/info/0785f45e67 | 2026-05-31T02:10:44Z].
FossilOrigin-Name: 04d7a9d788cf0bb811483baceb9142f67d4a2380d4af409d5300a92f7972472e
2026-06-01 16:20:40 +00:00
dan 62d17739bc Better handle a (possibly) potential buffer overrun in fts5. Based on the report in [bugs:/info/38e75aa4f9 | 2026-05-31T09:06:13Z].
FossilOrigin-Name: 9d0e39408075f22dd56ad5fb50ef458c0cd6a4ec234dd43b3a5f5e0ac4447b61
2026-06-01 15:03:53 +00:00
stephan f55434ab30 Remove the data type ANY added to the shell's CSV exports in [aff74e71ea734e1a], as discussed in [forum:2ea4c50f69fc9829|forum post 2026-06-01T12:01:59Z].
FossilOrigin-Name: a6a347aec5ff33b24d877ac0f04018f4e93748361da62ed27b1abec77840963e
2026-06-01 13:14:48 +00:00
drh 0a04687373 Do not allow the argument to a table-valued function to reference a table
to its right, even if the SELECT is inside a common table expression.
This is a replacement for the fix at [3c0a277e6741c722].  Fix
for multiple dbsqlfuzz reports and probably also a fix
for [bugs:/info/b6c6fad96c|Bug 2026-06-01T07:23:11Z].

FossilOrigin-Name: d96271db6a3a44e50d1a977250c4cc14178612a6c838e7c51c5f79fda45ae19f
2026-06-01 12:36:28 +00:00
drh c079bd08a2 Test case to show that the change fixes the original carray problem.
FossilOrigin-Name: 8df6671ae8211b706b7d4f073c5166f0f41f3c11339bc4d28997e8a205a39545
2026-06-01 12:30:13 +00:00
drh 5cae890219 Improvements to sqlite3SelectCheckOnClauses() to be more accurate in
identifying table-valued functions that references tables to the right.

FossilOrigin-Name: e5bae3687dbb470ead7e8d6bf428b1fbb1e9f10c214bc2a91e93e68fb2ae6ff7
2026-06-01 12:19:30 +00:00
drh f3eea1efa4 Back out the recent change to carray. The intent is to fix this problem
in a different way so that it works for all table-valued functions.

FossilOrigin-Name: 43e02dbb0dbe7192304125cd3298b3f4bbac02395d4d03f7f8d5f96b465eb43e
2026-06-01 12:07:21 +00:00
dan 3040da55a8 Fix an integer overflow that could lead to a buffer overrun in the zipfile extension. Bug [bugs:/info/2026-06-01T10:16:47Z | 2026-06-01T10:16:47Z].
FossilOrigin-Name: a8dac6af353c02aed8eaaba5921e036d3f3a6639367ae70e8c75d759c7b4ab52
2026-06-01 11:52:23 +00:00
dan 1a760748a6 Update new test in zipfile.test so that it does not run if SQLITE_MAX_LENGTH is too small.
FossilOrigin-Name: cc86820e198db6ee4e62f455d3dd9877d73873aaccad6ceffd0b34452d35c89c
2026-06-01 11:50:55 +00:00
dan 5481274912 Fix an integer overflow that could lead to a buffer overrun in the zipfile extension. Bug [bugs:/info/2026-06-01T10:16:47Z | 2026-06-01T10:16:47Z].
FossilOrigin-Name: 7c740d2cfd22a89258be2221860ca10985f0fc16dc7a17a99fc282d7105dc38e
2026-06-01 10:56:11 +00:00
drh 6c218ba0ad Extra defenses against integer overflows in the untested, unused, and
unsupported transliterate() SQL extension function found in the
ext/misc/spellfix.c extension.
[bugs:/info/2026-06-01T10:34:57Z|Bug 2026-06-01T10:34:57Z].

FossilOrigin-Name: 2b073519b6080abc8872b0728c64827cc088d1b43f132cd2aeb396f06de3d36f
2026-06-01 10:53:28 +00:00
drh ca8593ce68 Fix the carray virtual table so that it gives no solution if it cannot
find a usable first parameter.  dbsqlfuzz find.

FossilOrigin-Name: 3c0a277e6741c72281e12c44d85902aa6780890a7f59bacc3ac2b35ba27f7211
2026-05-31 19:41:16 +00:00
drh af6fdd2673 Test case to cover the bug fix in the previous check-in.
FossilOrigin-Name: 5b28d49b61d5edc9fef896e685bf227b7e1716c0cc666fd2ebe0d5ea0d11af06
2026-05-31 17:01:44 +00:00
drh 1cd9eb3811 Fix the zipfile extension so that ZIP archives containing files whose names
contain embedded \000 bytes do not cause problems.
[bugs:/info/2026-05-31T11:43:05Z|Bug 2026-05-31T11:43:05Z].

FossilOrigin-Name: c12ff342a90c61a0a82c8e63d2d94fecec10dff498da666873ff6aaa15c23dfd
2026-05-31 15:49:57 +00:00
drh 7437c19a01 Fiddle should default to using NO_COLOR since the JS console does not
support ANSI X3.64.

FossilOrigin-Name: bde6190fdeb530bfb92524ab5542f3f4b64adf31c31de1e00fe4430a8e00411f
2026-05-31 09:38:28 +00:00
drh d076d98ec8 Fix the format() SQL function so that it reports TOOBIG and NOMEM errors.
Fix a possible integer overflow on %#Q formatting.
[bugs:/info/2026-05-31T02:00:07Z|Bug 2026-05-31T02:00:07Z].

FossilOrigin-Name: 3bfe0510aecccf113b9d008c308fca3096e9c45c59b919c0b91bb4703415988f
2026-05-31 09:18:31 +00:00
drh 72f0bd609c Add a test to ensure an application does not try to create a geopoly
virtual table with too many columns.
[bugs:/info/2026-05-30T12:47:27Z|Bug 2026-05-30T12:47:27Z].

FossilOrigin-Name: 2c605bfb1562d7a3609ad6ffd7446def12f1ac7084e41b9c6723e998c156501d
2026-05-30 13:23:25 +00:00
drh 7aad2942c2 Harden the diskused.c extension against NULL pointer deferences that
might have previously occurred when given a corrupt database file.
[bug:/info/2026-05-30T07:08:55Z|Bug 2026-05-30T07:08:55Z].

FossilOrigin-Name: 7487a1c59d3aaea9f8b2569dca76bbccf21948b1e7bd8a1d841e04382db696f4
2026-05-30 10:24:03 +00:00
drh 07ded24fbb Remove the untested and undocumented "scrub" utility program. It was written
in 2016, but made obsolete by the [VACUUM INTO] command in 2019.

FossilOrigin-Name: 27d67fb175e839f6e7450f54166b52e0a6137c075758511da32fd82c57c310c4
2026-05-30 10:09:33 +00:00
drh 5b98467d28 Be sure to do floating-point to text conversions in JSON to the full
17-digits.

FossilOrigin-Name: 61a776650cdc3fe632bdb1dc39f50f542b00a9e5b468180eb54b69750d0cd70c
2026-05-29 23:14:22 +00:00
drh 3d006d0d00 Rename the ext/misc/analyze.c extension to ext/misc/diskused.c, to avoid
confusion with the src/analyze.c file.  The function is now called
"diskused(X)" instead of "analyze(X)".  The CLI command is renamed
from ".dbstat" to ".diskused".

FossilOrigin-Name: c7839f7a1749b38f8a36c06d93a7b59095e91ce753e8dd020de273ca8f73a239
2026-05-29 14:57:38 +00:00
drh 991cbd78b3 The -csv option to the CLI also sets "-limits off", for legacy
compatibility, and because that seems to make sense.
[forum:/info/2026-05-28T16:23:36Z|Forum thread 2026-05-28T16:23:36Z].

FossilOrigin-Name: d15cd64160192119a5f12afec14dbfbb30fb38a8557cb9dc559b3f061c15687a
2026-05-29 12:23:38 +00:00
dan 6a8e887a64 Avoid a resource leak in an error path in the icu extension.
FossilOrigin-Name: 87c37dab7e53d1bd891f3fed624963b35ab15a785706d0964b5d07ab70421c10
2026-05-28 11:29:05 +00:00
drh 43ab3c2a84 Fix an infinite loop that can occur in the unused, untested, and
unsupported ext/misc/btreeinfo.c extension if it is presented with
a corrupt database file.
[bugs:/forumpost/b43c44cc1c|Bug 2026-05-28T05:41:01Z].

FossilOrigin-Name: 646e9b49153ebd7e09e3ef72cc4f64fb685d0cfd8b158ef7d11d37c50c3f0b7e
2026-05-28 11:16:55 +00:00
dan 9b7ea5700b Fix a problem with shell tool function analyze() and schema objects with name containing "%" characters.
FossilOrigin-Name: c6d5793d5d2212c979e2fe5eb12c3844bfc1f2029bd8d076fec030a04f6d4bb5
2026-05-28 11:12:29 +00:00
drh 720d3afa7e Fix potential integer overflow in btree overflow page cache computation,
reported by Project Fortify.  Test cases in TH3.

FossilOrigin-Name: dfa674d6e6bffdb930dbefa767831db7862c322b6d3c7a6322f0fa0f087aaaf9
2026-05-28 10:14:25 +00:00
stephan 4cc2dbd54d Patch test/indexexpr1.test to work when built with SQLITE_DQS=0. Addresses [forum:2026-05-26T18:08:20Z|forum post 2026-05-26T18:08:20Z].
FossilOrigin-Name: b470a5d69e70d3440467e7792231f8556111d2c1126cf62879bbfd214ac0a9e0
2026-05-26 19:25:36 +00:00
stephan b79ffe60b6 Fix an OOM check in shell.c.in. Addresses [forum:2026-05-26T15:02:35Z|forum post 2026-05-26T15:02:35Z].
FossilOrigin-Name: e78198e6aec57c28e33a5b1c5ae9943115a35d2fbfa04c8428318567f17eefbe
2026-05-26 17:15:54 +00:00
dan 6e3e557c81 Fix a potential 1-byte overread in sqlite3changeset_invert() when processing a corrupt buffer.
FossilOrigin-Name: 78eaa605cb6c14e5bd49a898b4c737957bd60c8714913cc2341f4ffe3bfe81fe
2026-05-26 15:03:30 +00:00
dan 18bee1617f Fix a 32-bit integer overflow in sqlite3changegroup_change_blob() that could lead to a buffer overwrite.
FossilOrigin-Name: 8a289158e2baeee8aa5e601bde46b0482361064ede09e4108f519270efdd5f69
2026-05-26 14:18:50 +00:00
drh 2315f282be Fix QRF so that it works sensibly with "--wrap 1"
FossilOrigin-Name: 48f950b2a1ef841d915ca733baf324a1af98e644b660f238dd5018015340a6c6
2026-05-26 13:54:57 +00:00
drh ce2f503c1c Strength the defense against malicious command-line arguments in the
sqlite3_rsync utility program.

FossilOrigin-Name: c84d596b6da22061627282d444913c88dc2f9bd82e86957183f7e732f2713b33
2026-05-26 11:23:00 +00:00
drh 5554aa27e6 Fix HTML ">" quoting in QRF.
[bugs:/forumpost/f72dfbdeff|Bug f72dfbdeff].

FossilOrigin-Name: 5cee1097b47d850989ebecdb9d2c814e6968240fe3bacb5598ca85067cb95692
2026-05-25 23:44:37 +00:00
drh 5cfa63e6c8 Fix a minor problem with test case mjournal-3.3.
FossilOrigin-Name: 80093dc0610438cd506d230eca12e699e05395aecb8048c5bc066379b927e8bb
2026-05-25 20:45:43 +00:00
drh 0ca827a590 Early malformed JSON errors in json_each() and json_tree() to prevent
excess output.

FossilOrigin-Name: eb4d7e1b86b1d1bece01f621c9991a11f4812bf515a973b5036b09a1392134e2
2026-05-25 19:47:58 +00:00
drh 7e20b624db Fix to testrunner.tcl so that it will run on FreeBSD.
[forum:/info/2026-05-25T18:50:36Z|Forum post 2026-05-25T18:50:36Z]

FossilOrigin-Name: 97b66687b3f772e225e1792194a7f54a2ae187c84de1d76227846503631b5c2f
2026-05-25 19:32:52 +00:00
drh 94c8755a95 Enhance the defenses against malformed JSONB in the jsonbPayloadSize()
routine.

FossilOrigin-Name: 32c9f71a989fa4c81a613398ca5c1e68eb88b2a90ac4a4a7bf39e755717f43b1
2026-05-25 18:46:42 +00:00
dan 8c9071ae4e Use "-encoding iso8859-1" instead of "-encoding binary" in mjournal.test so that the script works with both Tcl 8 and 9.
FossilOrigin-Name: 897b443fb35d550891315890a5af473d347af3b6ecea11fcafafb5b06a1b50a5
2026-05-25 18:14:58 +00:00
dan e1233bb609 Fix a potential 1 byte overwrite that could occur when processing a carefully crafted super-journal file.
FossilOrigin-Name: b3766c3afd0ac4d31f158ee5938f19d72a047872e422b5f19b1567c60640f54d
2026-05-25 17:58:07 +00:00
dan 00ba6a6635 Fix a potential buffer overwrite that could occur when in fts5 when handling corrupt records.
FossilOrigin-Name: de009593f692251c4a033742b1e79c4ddb5ddcb174209d58c4d1bea19ceb360c
2026-05-25 17:09:37 +00:00
drh 3020203708 Make the /A substitution in the CLI prompt expansion responsive to the
SQLITE_CLI_APPNAME compile-time option.

FossilOrigin-Name: 624dc12e9e6dece22f7d247b66f0889755295cb2154502ade6553c13b8fecd83
2026-05-23 12:14:05 +00:00
drh db7fe319ed Strengthen the statement about not accepting agentic code.
FossilOrigin-Name: 64b707f4b3177384b611df5f5e4ca7da44d86313f74ff943a00581a6dd924b08
2026-05-22 17:51:15 +00:00
dan 3eb6a5ee33 Update the session module so that it can apply changesets containing two or more UPDATE changes that form a dependency loop - so that no single UPDATE can be applied independently without violating a constraint.
FossilOrigin-Name: 32c762bbb187e3bc964dcaad0949ebeb4da21331be842a5868feeac6088790ca
2026-05-22 14:29:33 +00:00
dan f380599476 Add the SQLITE_CHANGESETAPPLY_NOUPDATELOOP option to the sqlite3_changeset_apply_v2/3() method. To disable the extra processing to commit changesets that swap two or more values subject to a UNIQUE constraint between rows.
FossilOrigin-Name: eba02092bcf1713a646ecf8febd53a83bc803cf1b17e2e4fc590c14d886a8d27
2026-05-22 14:22:14 +00:00
drh a1e5778889 Add a prototype AGENTS.md file
FossilOrigin-Name: 3dd1181120b9910a96090b5b3cad5f0829fadeffeb6ffaad17031540a5749513
2026-05-22 11:15:25 +00:00
drh 8f70ec615f Fix the VFSes so that there is no 32-bit integer overflow in the
xShmMap method if the WAL file size exceeds about 25 terabytes, or
if the header is corrupted to make SQLite think that the WAL file size
is that big.
[bugs:/info/2026-05-21T03:53:03Z|Bug 2026-05-21T03:53:03Z].

FossilOrigin-Name: 9ac4a33a2932d353c4871fd8e09c10addf827f1fc3fc9380037d738cf2cd0353
2026-05-21 15:14:35 +00:00
dan de739c3450 Merge latest trunk changes with this branch.
FossilOrigin-Name: c6226d508d6af28fcd42fecd482014c3e284923871d3d8f5177f728cbf3457c5
2026-05-21 15:13:17 +00:00
dan c597ed79d1 Fix a buffer overread in the session module that could occur when processing a corrupt changeset.
FossilOrigin-Name: 869a51ae84dfaaf824c872e4b3024f35eea7fa67bb584759a2d42ebf8404ef6e
2026-05-21 14:58:36 +00:00
drh f305e1921b Performance optimization to the sqlite3ExprCollSeqMatch() routine.
FossilOrigin-Name: 035f1d2f284a081e6aef01cc773a3784458ec8e6297f3fbf4063670a9e65278c
2026-05-21 14:48:43 +00:00
drh 3dbab77bf1 Remove dead code created by [20c2f8ce9242c3db].
FossilOrigin-Name: 68c5fd5fa0f986b782519472398b068ba7c295c56a0e0199b8e0509d0d1685fb
2026-05-21 14:16:47 +00:00
drh da18b56b25 Limit the length of inputs to the spellfix1_editdist() extension
function (not part of the standard SQLite build and rarely used)
to 99999 characters, to avoid any possibility of integer overflow.
[bugs:/forumpost/5da728247a|Bug 5da728247a].

FossilOrigin-Name: 51ebf0e04efcbe982e62f2228553700b8c1147a37c70fdfaa0e377184b3ac936
2026-05-21 13:37:15 +00:00
drh ecd9748590 A join constraint is not an equivalence unless both operands have the
same collation.
[bugs:/info/2026-05-21T03:39:28Z|Bug 2026-05-21T03:39:28Z].
Error goes back to version 3.7.17, 13 years ago.

FossilOrigin-Name: 20c2f8ce9242c3dbb8054f01c6c7338763c830b7c1491a99c8e1de98ce8f0a5b
2026-05-21 13:03:18 +00:00
drh 6ae9949399 Enhance the xfer-optimization to verify access to the source table using
the authorizer, if an authorizer is registered.
[bugs:/info/2026-05-21T03:31:22Z|Bug 2026-05-21T03:31:22Z].

FossilOrigin-Name: d1cdb817cafd03a4081b254a71672ba07e5b637994d3f2f925532f17af0a67dc
2026-05-21 12:04:20 +00:00
drh 37e253208f Improved entropy collection on Windows.
FossilOrigin-Name: b734b76af3f732e0db8a002781bae57aa7a01c4a7f5151605144a6aeef993a21
2026-05-20 20:03:07 +00:00
dan b869ed6b06 Fix a bug causing the session module to dereference a NULL pointer when applying a corrupt changeset.
FossilOrigin-Name: e807d4e3798efd532b3d78d1dfe513ed4fbd3cb793dd0ae5c30cae6031422b10
2026-05-20 15:06:34 +00:00
drh ccf23dadea Check-in [7cf841f3613c8302] was incomplete in that it did not remove
the incorrect assert() statement.  Fixed here.

FossilOrigin-Name: c19bacca13f699953bbf50afb867035a94080b8a48111cf3d87bced880a3e620
2026-05-20 11:53:15 +00:00
dan d3dc8e5ae5 Avoid returning an SQLITE_SCHEMA error from within sqlite3session_diff() if the schema has been recently modified. First <a href=https://sqlite.org/bugs/forumpost/269f1e9cef>reported here</a>.
FossilOrigin-Name: 20110547a117912be68d91bc006e92c45beffde16c6bcdf062bf8971c9a9a864
2026-05-20 11:41:24 +00:00
drh badc42fd74 Fix a test case added by [1249eeb1b9759038] that does not work for
the config=prepare permutation.

FossilOrigin-Name: 6aaeeffc2c7abbe32050da40bcbffc5f8d596e6df4603b8f8f23294f2465f25e
2026-05-20 01:32:30 +00:00
drh fd9eba554a Improvements to testrunner.tcl: Make C-program tests responsive to the
pattern list.  Do not remove build steps until the very end when we are
certain that the build step is not required.  The pattern list matches
the exact text of the displayname column of the jobs table.

FossilOrigin-Name: 3f409c0e1be6b71eca92eccf0b9de3ef5923a6a57be49540ebe190fc6a6d06d4
2026-05-20 00:16:20 +00:00
dan 8154476ff8 Fix a potential buffer overread in fts5 that could occur when handling corrupt records.
FossilOrigin-Name: 70021c3291b38192832c99fa4d8155249dd39f5b26334595c71f5cee66d13ebb
2026-05-19 20:27:54 +00:00
drh d258b93356 Silently ignore nested porter tokenizers in FTS5. Having nested porter
tokenizers is pointless, but it does use stack space unnecessarily.
[bugs:/forumpost/a7766198f1|Bug report a7766198f1].

FossilOrigin-Name: 0bdeedf56c9d7209d1ea8f950d0ef03c78cbf677528d9d30c5f4ec48c4e1a571
2026-05-19 19:33:49 +00:00
dan 3ef3ecdf8a Remove new unreachable code from this branch.
FossilOrigin-Name: 07f81e256fde5796c0d8bcedff8fad4368639386f40881c0844e9c86a69b6fad
2026-05-19 18:58:59 +00:00
drh 632b618063 Prevent integer overflow in the ICU extension.
[bugs:/forumpost/844bdd7d5c|Bug report 844bdd7d5c].

FossilOrigin-Name: c20cb75ca07d0553d7a847c65a40efb2e5c587579ec32b02121a8963c70db12f
2026-05-19 18:56:11 +00:00
drh d58b463ffb Fix an assertion fault that can occur in RTree given a carefully
corrupted database.
[bugs:/forumpost/2026-05-18T06:46:01Z|Bug report 2026-05-18T06:46:01Z].

FossilOrigin-Name: 7cf841f3613c8302a419638bdec83b1b9799f00cfedbfe40dca0a1a005c196b5
2026-05-19 18:45:05 +00:00
dan 1a0555610d Fix problems with error handling when applying changesets with update loops.
FossilOrigin-Name: f797925df05f1a53392dba416aa72067716bb6e38ebc679d313f8a98f89c5913
2026-05-19 18:28:03 +00:00
dan 079f8dc682 Merge trunk changes into this branch.
FossilOrigin-Name: e480e126fc1550948bd1a3635f0e3a862353dcd8b0f1921ab6e66d699110b477
2026-05-19 17:15:05 +00:00
dan 4da2ddf50e Avoid a potential 1 byte overread in sqlite3changegroup_add() when processing a corrupt changeset buffer.
FossilOrigin-Name: 4d8c3a2919dc942a0a044ec7582a688e0f93e91f4a465bb94390fbe3ad1b50b4
2026-05-19 17:12:39 +00:00
drh fdf746967c Add an sqlite3FaultSim() call to the changes at [6193e4105b6a58ea] to
make them testable.

FossilOrigin-Name: 0de3d95500b7ecd41a09d81f176c1510896e811b3e468e1cf50f752305fdb06f
2026-05-19 17:05:28 +00:00
dan c7ddaf2479 Merge latest trunk changes into this branch.
FossilOrigin-Name: 1f71b530c9e8ddce5b25ed0971447cd925f9194afc7a2f929429318a5fcb5a72
2026-05-19 16:07:22 +00:00
drh 45b4213160 Fix a incorrect assert() from [52dd437d51d3c1af] reported by OSSFuzz.
FossilOrigin-Name: 64b49e4d431d35db0920c7fc8a89d38ce2d2d2dbf42a7caf76aaa9685d66601b
2026-05-19 16:07:08 +00:00
drh cbbeddbd67 Add the "make" subcommand to testrunner.tcl
FossilOrigin-Name: 00d546812810252a4d51ff796931dc2ff5bdd5173ddb8f95fb5efccd897087ff
2026-05-19 15:13:03 +00:00
drh db5aebce43 Early detection of attempts to overwrite an in-use cache page due
to database corruption.
[https://issues.chromium.org/issues/513858286|Chromium 513858286].

FossilOrigin-Name: 6193e4105b6a58eac2bc17c5b2d55fdae332816b59beed1fe24c15dff1372322
2026-05-19 12:40:00 +00:00
drh 4d3f3c7070 Security enhancements to the untested and unused fossildelta.c extension.
Bug reports [bugs:/forumpost/3ac3fe3d71|3ac3fe3d71] and
[bugs:/forumpost/e7e470b760|e7e470b760].

FossilOrigin-Name: 2d3fbbe421d3b0ad8fa08255fd30af7f2d947919ebb90fa9c9c4ee72ffd880b4
2026-05-19 11:15:33 +00:00
drh bc94e5dbb6 Limit the size of input strings to the (disused) spellfix extension
to avoid excessive runtime and integer overflows.
[bugs:/forumpost/24a33e5d10|Bugs report 24a33e5d10].

FossilOrigin-Name: 4b16b80cf2e26c41f0828d65883145dc81c0987110c3f04a864cec43e7c418e5
2026-05-19 10:30:13 +00:00
drh d0fd0cc2fa Fix a NULL pointer dereference in the obscure (and unused) prefixes
extension, which I had forgotten even existed.
[bugs:/forumpost/24a33e5d10|Bug report 24a33e5d10].

FossilOrigin-Name: 4880adc053b0f21633936347fd5610e4338b15da39607d8ba5a6b32d1516e8cb
2026-05-18 23:58:14 +00:00
drh 1192d6f5b1 Fix an off-by-one error in matchinfo('b') for FTS3 when there are a large
number of columns.
[bugs:/forumpost/42d5f799d1|Bug report 42d5f799d1].

FossilOrigin-Name: c0f2cd6d292bb3554539a309a2ecfa0a12f0248cfcbb5594391607b107a62cd2
2026-05-18 21:45:06 +00:00
drh a20f63e0ef Limit the NEAR span in FTS3 to 1 billion, to avoid integer overflow.
[bugs:/forumpost/4cfcf164d2|Bug report 4cfcf164d2].

FossilOrigin-Name: adcb44f9dcfd34df4cf4f5cc418ecac9f2ca09723442379dfedcba532c45de77
2026-05-18 20:43:15 +00:00
dan a497743e24 Fix a problem applying changesets that contain multiple UPDATE constraint loops.
FossilOrigin-Name: 8e89aafab1b8fa7d59ac98c39b7f1c1cc23a98ba868a5dac83dee63688786a3f
2026-05-18 20:34:56 +00:00
drh a2d992a000 Prevent integer overflow due to database corruption in.
fts3auxNextMethod().
[bugs:/forumpost/bce19272cf|Bug report bce19272cf].

FossilOrigin-Name: d903795e3bdf91607f23dace5a15a070139b32e34aed8540a6c2e19c39e997be
2026-05-18 20:27:57 +00:00
drh 62cd986418 When a subquery is an argument to an SQLITE_SUBTYPE function, then set
the EP_SubtArg flag on the result-set expressions of that subquery.
[bugs:/forumpost/8de44412fd|Bug report 8de44412fd].

FossilOrigin-Name: d75c08c8416bde3f510a135ea07cc217ba6183eacda6ba895bccbf57efe9284f
2026-05-18 19:44:04 +00:00
dan 4dd11e33e4 Update the session module so that it can apply changesets containing two or more UPDATE changes that form a dependency loop - so that no single UPDATE can be applied independently without violating a constraint.
FossilOrigin-Name: 5f8010599fb33fbe1dadc894a679056a5d38040ab4f09772cd59827941e9348b
2026-05-18 18:59:06 +00:00
drh de94ec87fc Fix the window-function variant of the json_group_object() function so
that it correctly handles NULL entries.
[bugs:/forumpost/0de87b23b3|Bug report 0de87b23b3].

FossilOrigin-Name: ac3a958b0ab7766544bb406aa990668d2235ab26fb68c75ded3f71273d97b18c
2026-05-18 17:55:40 +00:00
drh e087d0f266 Do not attempt the OR-optimization on conjuncts that contain COLLATE
operators because (1) such cases are rare and (2) they are tricky to
get right and are thus prone to bugs and hard to test.
[bugs:/forumpost/329521b269|Bugs report 329521b269] is one
such bug that goes back about 20 years and thus demonstrates both
points of the previous sentence.

FossilOrigin-Name: 622882529558b4779dfb7246bd5a9de776555c8f940bb941397fb56fb9f97e43
2026-05-18 14:28:53 +00:00
drh b6ea7f0550 Fix a harmless compiler warning caused by [460243ee4c28873d].
FossilOrigin-Name: e076ac7b648988b48b546e19b5ef2e50061b44c85bc2645362409e295e3b4b11
2026-05-18 11:44:09 +00:00
drh e4ba14bc40 Correction to the bugfix at [212c68249cc0e890] so that it works
for 2nd and subsequent terms of a row value.
[bugs:/forumpost/ba8084256b|Bugs report ba8084256b].

FossilOrigin-Name: 49a3c6ade45ea31187ac8dbba0452fcad487e76f2219bfa6435feab545b5f632
2026-05-18 11:35:44 +00:00
drh b969f8c2f1 Raise an error in the dbpage virtual table if the page number on an insert
is too large. [bugs:/forumpost/f363b34881|Bug report f363b34881].

FossilOrigin-Name: 2bbc8f1404e3cbaa8fe24e2ea2d774daf2bf3b232fbd8978a1a37e4f8f0f629d
2026-05-18 10:19:14 +00:00
stephan c1bf93ecb6 Add a reference to the new sqlite.org/bugs forum.
FossilOrigin-Name: f2fe7e7a184e482411ddf792a1964e6ce30a28185da9fa79488d097382c352fd
2026-05-18 10:00:35 +00:00
drh fd88eed8fa Fix the ".prompt" command so that it honors -bail.
FossilOrigin-Name: 5b58bdd33f0410624523fc8adc230db4e5f57283d234a5f0d26a2790629bc0f9
2026-05-17 19:21:30 +00:00
drh f77a5af2b3 Fix the new %J and %j formats so they work correctly with a zero precision.
FossilOrigin-Name: 428b924dd6e228c879338c5c5edbe68bdc4d8d8e80c37e3d070a8a34b57300c1
2026-05-17 17:50:32 +00:00
drh 6df919b723 Fix the sqlite3_value_numeric_type() interface so that it works even if
the argument is an sqlite3_value object that came from sqlite3_value_dup().
[forum:/forumpost/15c4a323bb|Forum post 15c4a323bb].

FossilOrigin-Name: 460243ee4c28873d5c484a91af7ec18d03d0e726b8bb4e1e680b588e5f371400
2026-05-17 17:18:12 +00:00
drh cb388ec9a3 In the CLI, make the NO_COLOR prompt the same as the default prompt, only
without any color.

FossilOrigin-Name: cc05e9749c14d6ff4e396ad387c42d53b696680ce74ce6a92f6fb71ed9a53ae5
2026-05-17 16:35:36 +00:00
drh 0e30396fe2 When two tables are joined by USING, the affinity and collating sequence of
the join column will be the same as one or the other of the columns in the
two tables (which are hopefully the same).

FossilOrigin-Name: cbb6f72c10b1224088b9d604a0e014e7020e8d79a317ebb4af420ba3b72f40cc
2026-05-16 20:21:55 +00:00
drh fc12461f5c When two tables are joined by USING, the affinity of the join column can
be the affinity of the corresponding column in either table.  But it must
be one or the other.

FossilOrigin-Name: 8cc0b52cca2d6b155b4b169e6f9de9e7d2dc61c40f89920c2b6bf86e549ab6f7
2026-05-16 19:40:55 +00:00
drh 3cfe5c3dad Fix false-negatives in the sqlite3ExprCanReturnSubtype() routine having
to do with CASE, CAST, and COLLATE expressions and the "+" no-op operator.
[forum:/forumpost/1f0168a120:Forum post 1f0168a120].

FossilOrigin-Name: 9be94e961457967408cbd0acf11877fbb323a48eee405fff53755770f1b3261a
2026-05-16 17:28:56 +00:00
drh d3265d1473 Improved comment on sqlite3ExprCanReturnSubtype() as well as one very
minor efficiency improvement.

FossilOrigin-Name: b57d6b76b0f9f4f154997af83f14d545bf2b6b8f7194746835e4c34885db227a
2026-05-16 16:02:08 +00:00
dan 61d9f8f881 When using an index on a CASE expression that may return a value with a subtype, avoid discarding any subtype.
FossilOrigin-Name: 69c9a82cbaea7b6faa6a357dd884b1e0d2bc684d847efb31a2d64c75fabf5428
2026-05-15 19:44:24 +00:00
dan 397a3c4a04 Have window functions sum(), total() and avg() correctly handle the obscure case where integer overflow occurs as part of the same step that adds the first real value to the running total.
FossilOrigin-Name: 614f8cbc374c7a2d39826706f16ab1c17e75abb420a70be356c7eefa95b271a5
2026-05-15 18:36:11 +00:00
dan 0c3b3f93d1 Have the sqlite_dbpage module correctly handle constraints of the form "WHERE pgno=$pgno" when $pgno is an integer that cannot be represented as a signed, 32-bit value.
FossilOrigin-Name: 350152d5124b71b3dd640c109dbac5f05a3a9583a335fbe25f707e1b754c1c74
2026-05-15 17:24:34 +00:00
drh 9f3208e1f8 If there is a WHERE clause constraint of the form "a=$var", then
automatically reprepare the query if the binding of $var changes, as
that could affect the query plan.

FossilOrigin-Name: 1249eeb1b9759038b6d10dcd8d65f64f81e8529b28e5e24f9fc5759e9a1c88a5
2026-05-14 22:39:41 +00:00
dan 672b87d0d5 Handle constraints like "a=$var" where the value bound to $var is -1, 0 or 1 in the same way as a literal -1, 0, 1. This might cause excessive reprepares.
FossilOrigin-Name: 224e827e87ac8aa4b18ff9b2193decbdcd832579bf6b6e0883c03db90ebd5319
2026-05-14 17:54:23 +00:00
drh 02dc8d0c5f Harden the QRF extension against integer overflow problems.
FossilOrigin-Name: 83d3a0d39b0b36a47003206d390935d4c94f7a906ada02f69e0ad1eef2f22d59
2026-05-14 13:29:59 +00:00
drh 13b63ed930 In QRF, relax the constraint on the screen width so that it can be as
wide as a 32-bit signed integer can count.
[forum:/forumpost/2570051b60|Forum post 2570051b60].

FossilOrigin-Name: 91439d95dc81adebf8226f2b7c33ca62a4b7163cfc14e03993524aa17b5767f3
2026-05-14 12:46:41 +00:00
drh 6166c2ee48 Raise an error if an ALTER TABLE ADD COLUMN statement tries to add
a CHECK constraint that contains an internal-use-only SQL function.

FossilOrigin-Name: 52dd437d51d3c1af0777350daeebf1159033eede3f58fcc5ebaeaec8869ffaff
2026-05-14 11:35:17 +00:00
drh a3e7c597b5 Correction to the documentation for sqlite3_uri_int64().
FossilOrigin-Name: 58472fdab0691f7f03f15201542f15148ed7734bfeb495370386d666ae4beded
2026-05-14 10:36:50 +00:00
dan cf632ddb7e Fix the sqlite3changegroup_change_finish() API so that it correctly handles NULL being passed for the pzErr parameter.
FossilOrigin-Name: f81d6d7bc8943729f678a3b62921a96764b15b9cc11d8a5753e48210a1b59617
2026-05-13 20:37:30 +00:00
drh a8fdc0e0c0 Additional changes to the Windows VFS to try to get the system to a point
where it will compile for UWP.

FossilOrigin-Name: 3ddc07110dacef98c14b852dcdc4f11d1c0f4061008bf3a61e2df707b0dc6c6b
2026-05-13 20:06:08 +00:00
drh 8b803c716c Change to compile-time option that omits non-UWP system calls to
SQLITE_UWP.  Takes steps to eliminate all non-UWP system calls when that
compile-time option is used.

FossilOrigin-Name: b167c4c96e6a753952eb4be95d6283b50a9c59f4ecf59d60cf10d8de9cb115d8
2026-05-13 18:07:01 +00:00
drh 077be44cc2 In the Windows OS interface, use CreateFileMappingFromApp() and
MapViewOfFilFromApp() if SQLITE_OS_WINRT is defined.

FossilOrigin-Name: 3c51436b43ab77b88134851a2773147b49a3c4fb5b0416db5e318b6e12d3b708
2026-05-13 15:11:04 +00:00
drh 1f9c2ed674 On Windows, use only GetSystemTimeAsFileTime() and not GetSystemTime().
Also add a TCL script that will renumber the systemcall thunk for Windows.

FossilOrigin-Name: 4b7f0130d68c7a0b98e87d09d0a661c85554215cb111478305307960deab3921
2026-05-13 13:55:31 +00:00
stephan 887fa2fe83 Modify [2990dd27dd] to use setlocale(LC_CTYPE) instead of setlocale(LC_ALL). Same effect but hypothetically a smaller scope.
FossilOrigin-Name: 8be57f96f6a72753fd983d7b6b9924c3b60f57c5664eeb7dfe7a0799739597c0
2026-05-13 12:12:54 +00:00
stephan 73da727480 Slightly rework the --editline configure flag for purposes of distinguishing between the two conventional libedit headers. When using libedit, invoke setlocale(), which appears to resolve [forum:aad7a634916ff050|forum post aad7a63491]'s report of non-ASCII input failng to work when linking against libedit.
FossilOrigin-Name: 2990dd27dda4333e8ccf9225ff5af690d4062276dd2ad60ee7df922aa6be99ee
2026-05-13 12:06:27 +00:00
drh 94f56f5800 Use GetTickCount64() instead of GetTickCount() in Windows, for portability
to UWP.

FossilOrigin-Name: ea65ae964e21541d8f7c00ec679a608d34bc94408d9cc479b2d7fb08bf0e3cdf
2026-05-13 10:47:40 +00:00
stephan 93d7dc266b In Haiku OS builds, fix the --editline configure flag to actually link against libedit rather than libreadline.
FossilOrigin-Name: 642168d386074d1398b52c2d952e4cb153617f7bed82fb99d76b6d28dc8242bc
2026-05-13 07:33:31 +00:00
drh 1d2f71ce4a Do not allow internal-use-only functions to be used in CHECK constraints
that are added as part of ALTER TABLE ADD COLUMN.

FossilOrigin-Name: 28272746fb13dcdbe2a4f21ef30446c316dfc843aa3d48f135f490abaee34198
2026-05-12 19:33:04 +00:00
drh 431b85963f Fix a copy/paste error in a comment. No changes to code.
FossilOrigin-Name: 2741193e81750512cae8bb14ebc03fa11dde100da144488b4da1c81a351e4ff6
2026-05-12 18:06:44 +00:00
drh 054aff6272 Fix the insert4.test test module so that it works when SQLite is
compiled with SQLITE_OMIT_VIRTUALTABLE.

FossilOrigin-Name: bff9db9b5eb05ec3f99e35cb4c198d24bcb9ee7ceb2401bf55627788ac2b96db
2026-05-12 12:34:16 +00:00
drh 657721fd32 Attempt to disable false-positive GCC compiler warning.
FossilOrigin-Name: e377b4d375f2ec64085d953e87739904bbbccf09d82db99fe0579368c985ca84
2026-05-12 11:47:01 +00:00
drh e14c16189e Fix the xfer-optimization such that if the destination table has
constraints on the hidden rowid, the optimization is not attempted.
[forum:/forumpost/6dcc95e3ca|Forum post 6dcc95e3ca].

FossilOrigin-Name: da9ca357fb24f39a4a3292ca447773c6233a3084721abfbd5665a45ee8a4bed4
2026-05-11 16:58:05 +00:00
drh 88be32c9d3 Prevent internal-use-only SQL functions from being used inside of a CHECK
constraint added using ALTER TABLE ADD CONSTRAINT.
[forum:/forumpost/6256ee34ed|Forum post 6256ee34ed].

FossilOrigin-Name: 07beb966daddd0dfea36265eb38ebfcfbb10b0cbccda458dea501eda330a49f0
2026-05-11 14:22:45 +00:00
drh cf420c9910 Fix comment typos. Add test cases.
FossilOrigin-Name: 7a85921ae585f948f084bd8fccc1cc002539415e629aa0021d58afc17e5471a3
2026-05-11 14:14:25 +00:00
drh 5f6a6fa6f0 An alternative fix to ALTER TABLE ADD CONSTRAINT.
FossilOrigin-Name: a231fc6d58abb3b76d0e669babdb377e41b5a348d155ab5f2c1fe49eefbbf3a9
2026-05-11 12:38:18 +00:00
dan eb83e32cef Improve detection of corrupt database records in fts5.
FossilOrigin-Name: 87b653731171a26396f9796b0a5c436593571d39e991d8d040ef4473cf459b67
2026-05-11 11:53:07 +00:00
dan 79db323ce1 Fix potential buffer overwrite that could occur in fts5 when processing corrupt records.
FossilOrigin-Name: 4a5ad516ea93926c0d5206b4d72c3675905d2bf666b27a649256b93eb95c671b
2026-05-11 11:12:06 +00:00
drh 219acc9f4f Fix harmless bug in testing logic. No changes to deliverables.
FossilOrigin-Name: c4a6e62b5f36f9df988d2ec12a92a614e9e813cdcd50198ec2827c33745a362a
2026-05-11 11:05:17 +00:00
drh 8bee9cd3cf Hush-up a false-positive compiler warning from GCC. See
[forum:/forumpost/281ace196961082c|forum thread 281ace196961082c].

FossilOrigin-Name: 45a215290896eee9776c2b1727363f6e1c1aad5b521f4f92b13981a5da5d0f54
2026-05-11 10:25:58 +00:00
drh f8ca671997 Fix the xfer optimization so that it does not work if the destination is
a STRICT table that is incompatible with the source.
[forum:/forumpost/4955d2235c22ef4e|Forum post 4955d2235c22ef4e].

FossilOrigin-Name: 5e916b2a8fd41ffc42c29bfc9b5333b7a579f37fe094bd0b6b00e2f176c4e3fe
2026-05-11 00:53:44 +00:00
stephan 15670b1b3f Minor config script doc tweaks.
FossilOrigin-Name: 678954553e123de9eb0bbe7c3101039218edd27d282b015f51e69a2eba683feb
2026-05-09 14:32:16 +00:00
stephan df300e8e51 In sqlite-config.tcl remove a reference to the platform name apple when checking for Mac platforms, relying on a check for darwin instead, analog to [b5c6cb13cff53f]. Intended to resolve [forum:c26b856db7dd5caf|forum post c26b856db7dd5caf].
FossilOrigin-Name: 7ccffe38b4b99c61e4bfc703dc4b3516d7c2a72d73680b699886ee43eea9bd21
2026-05-09 14:01:57 +00:00
drh 2c8f97159c Fix upward propagation of expression properties into row-value expressions.
[forum:/info/8387cc287240643e|Forum post 8387cc287240643e].

FossilOrigin-Name: 0372dd717b852da8dc2c6b0ff2da02a2ac25bc0486a38e4c2a970694d897b6c9
2026-05-09 13:54:40 +00:00
drh 993bc6b171 Improved detection of OOM in the regexp_bytecode() SQLite function
(available in debug builds only).
[forum:/forumpost/a3a10e1c7b5dd1d2|Forum post a3a10e1c7b5dd1d2].

FossilOrigin-Name: 172e8c35badadc3c5eb5065da8ed2161093a0adff0ecfb5b162f78a9fb55bb34
2026-05-09 13:16:18 +00:00
drh 86d1ef8bf7 Fix an integer truncation problem due to oversized inputs to the
approximate_match virtual table extension.
[forum:/info/625f687e4d25c392|Forum post 625f687e4d25c392].

FossilOrigin-Name: 2881e17cc030814b350ca371fd2fd2089d3ff2fcc4ea52654de8bc5c2fc95222
2026-05-09 12:41:23 +00:00
drh e707e68420 Fix a corner-case floating-point rounding problem in the generate_series()
virtual table, introduced by [c113e31b818d1677] and reported by
[forum:/info/6e6cf9054bea2b1d|forum post 6e6cf9054bea2b1d].

FossilOrigin-Name: ff56785674ebeb1d4bab66ba0827956a2728c8c14419f933d40dc0152efbd4f5
2026-05-09 12:03:14 +00:00
drh 1788b7b719 Remove unnecessary and incorrect assert() statements in the new %J code.
FossilOrigin-Name: 5a8497dbec80b55a2dedc8a6f9ee823243e01a08d37ceeed1f87214dfe527d63
2026-05-07 20:45:57 +00:00
drh d4c4e91674 Add the %J and %j conversions to printf() - rendering JSON string
literals.

FossilOrigin-Name: 7e6fd838a15f08bf15d57f1887ed1019b58aa6be9eb7b162e67e0d9412082c6d
2026-05-07 15:04:30 +00:00
drh 4f95a67b0c Fix harmless UB by declaring a constant 1 to be unsigned.
FossilOrigin-Name: c5235734a6787b9c59a356f4e0ccbb3f262b8d9a6407ebd415afc87e859b0498
2026-05-07 14:47:21 +00:00
drh 31c19f587d Fix another off-by-one error.
FossilOrigin-Name: 8ae724a647dfcb986c4037caaab07e5d0188e66b66039a4758937c963f1fcbf7
2026-05-07 14:30:34 +00:00
drh bfc0414b9a Bug fixes in the new %J and %j logic.
FossilOrigin-Name: d1b55572c76569cb1e999028e79bcf2e76069f8778f0c8e933ace606d7b6a8b2
2026-05-07 14:14:05 +00:00
drh f9db8b2350 Add support for width to %J and %j.
FossilOrigin-Name: 0b102f2076586c08b134c78cc18acdd05555fa2b534c895535e96a0466661910
2026-05-07 10:46:39 +00:00
drh ad37ec3aa2 Separate conversion letters %J and %j. %J includes surrounding quotes and
%j omits them.  Some test cases added.

FossilOrigin-Name: ea7c2c1a6bd32695fc3a1f2295b4c4719e3d9dd0a8f6480e7c95e17b564c3391
2026-05-07 08:58:10 +00:00
drh 4b77e36dec Get precision working on %J, both with and with the ! flag. Width is
still a no-op, and there are no test cases.  Incremental check-in.

FossilOrigin-Name: 18166bce208c64b7f3afaa88c27a10e0295a89f9c72942dcaa949cf7efb479e6
2026-05-07 00:02:55 +00:00
drh 3ece90420d Experimental prototype of the %J conversion in printf().
FossilOrigin-Name: 7f6b1bae0849f0a840b95ae95aa6fdc6d51b72fdd50493649f584ad7829a3060
2026-05-06 20:48:34 +00:00
drh 8ff6523afd Fix a minor typo in a comment in the json module.
FossilOrigin-Name: 5c6d3e9d83af94234f67b06bd23c4eb0178a80c74c39be4945b3282244630020
2026-05-06 19:13:21 +00:00
stephan 821323938d Minor internal doc typo fixes.
FossilOrigin-Name: d588680240a7f4395f2ef52dd78635de66120a677a41a28ceb96921b3333973d
2026-05-06 06:57:42 +00:00
stephan e572525306 Delete the OPFS SEE test dbs when done with them.
FossilOrigin-Name: cbb9f7bcd04c586d523192f32c0ce7dcec72a76bb9a9c3b67fcde1f9e79f7218
2026-05-05 15:31:41 +00:00
stephan 082aebfa0d Add importDb() tests of SEE databases for the opfs/opfs-wl VFSes, analog to the opfs-sahpool test in [a5a9ac7ad6622b].
FossilOrigin-Name: 534d388031dfacf83cb40c712150a376db10393c98936a33ea80da0166b3dbeb
2026-05-05 15:26:24 +00:00
stephan 6f842b8da4 For the various OPFS VFS db-import routines, in SEE builds (only) relax the is-this-a-db check to allow for SEE dbs not having the usual header string in cleartext. Addresses [https://sqlite.org/see/forumpost/f84bef3552|SEE forum post f84bef3552].
FossilOrigin-Name: a5a9ac7ad6622b5b07193aa279deefde7d59ca17f81aba9dd78ee90718446993
2026-05-05 08:51:10 +00:00
stephan 3d84988efe Fix a predicate which causes a false error in the OPFS SAHPool tests when building with SEE.
FossilOrigin-Name: 97ab0a2fd56501d08bc2ab2adbe70a4130f6c5b5db343941fa16c7b34c550bd3
2026-05-05 08:11:55 +00:00
stephan 128f65ca6d Add #include time.h to shell.c.in to get fiddle building with emcc 5.x.
FossilOrigin-Name: ae675dfe7946d37f224f22ad34b6ebe049fb1426cb3d49d88ebc10d0b7634e40
2026-05-05 07:57:54 +00:00
drh 79a4591478 Fix a test case on CLI ".help" output due to the output changing because
of check-in [1590b401ff0670b6].

FossilOrigin-Name: b6ad35096d48de29fd8da498ac23cd7eba9194a70cad05ec49c318f11fe77199
2026-05-04 18:36:04 +00:00
dan 14fa0e9b86 When using the OR-optimization on a loop created by exists-to-join, do the early-exit logic for the whole loop, not for each individual OR branch. Possible fix for forum post [forum:c8b205720c | c8b205720c].
FossilOrigin-Name: 70a5d091241748aea63aa13bb218b573d0b84615a0682c2ec693addbfe9bc2f4
2026-05-04 18:16:09 +00:00
dan b4d42c6702 When using the OR-optimization on a loop created by exists-to-join, do the early-exit logic for the whole loop, not for each individual OR branch. Possible fix for forum post [forum:c8b205720c | c8b205720c].
FossilOrigin-Name: 3d197dd03c47a0fb687064131dbf519b8c587a47f9c2bccfdb83d7eae8418336
2026-05-04 17:16:43 +00:00
stephan 3ed7926e2f Add a missing tcl quote which breaks the build on msys2.
FossilOrigin-Name: 9380be51c76392eca9544f1fd56373406d2ce001e77a8d476deb772968f2aacc
2026-05-04 16:18:25 +00:00
drh 8923a68c5f Add the --color and --no-color options to the ".prompt" command of the CLI.
FossilOrigin-Name: 1590b401ff0670b68910504c281e67ecae7ae357ba3ed65f96dabaabd7aaeb7f
2026-05-04 12:58:05 +00:00
drh c94c21d0a6 Honor the NO_COLOR environment variable. If NO_COLOR is set and
SQLITE_PS1 and SQLITE_PS2 are not set, then the default prompt is
monochrome and ANSI escapes are omitted.  Also change the name of
the SQLITE_PS_NOANSI compile-time option to SQLITE_NO_COLOR.

FossilOrigin-Name: 7e4134e3ff1ca8712f5fc78fadae665549450988dc43af27c7fe0c77f10ce3fb
2026-05-04 10:14:13 +00:00
drh fb7c642990 New test cases for the shell prompt
FossilOrigin-Name: 2340cbbd230bdadedbb5d3eb9cfd287fd934e69ce5a2c989e141b0fc87b947aa
2026-05-03 18:31:49 +00:00
drh 2bc658c387 Improvements to the non-printing character delimiter logic in the CLI
prompt, for improved accuracy and for improved testability.

FossilOrigin-Name: f5649795cd8d7a1f270037ef0b212ea605c1665ec05a75a6da0b250f2aeab070
2026-05-03 15:53:52 +00:00
drh f02745088c Change the non-printing character escapes for editline to U+0001 and
U+0002.  Also insert those escapes for readline.  Readline does not
need it (because it can figure them out on its own) but they are needed
when editline is being used in readline-compatibility mode, and we have
no way of distinguishing between editline and readline in that case, so
we might as well include them.

FossilOrigin-Name: b9545b0f0b6fa0a777a064e1410b17f52cb49d853c188f9b8b3a772bd810ece3
2026-05-02 23:40:40 +00:00
drh 596008f078 Attempt to automatically insert U+0001 escape bytes before and after
ANSI X3.64 escape sequences when using editline, to work around the
limitations of editline.

FossilOrigin-Name: 63050bee6e5ed46cead14bd5a02b0cb6a7dbcdcb6a56601b90c10cf1c8d84efc
2026-05-02 23:03:42 +00:00
drh 1c9e8ca88b Fix a harmless compiler warning on some MSVC versions.
FossilOrigin-Name: bb8f6deeff31e9cc9b5a88b17b29dc6cd4fb4515134fa8e9758e33e42bbe89b0
2026-05-02 20:19:31 +00:00
drh c70fbd39f9 Minor optimization to the authorizer.
FossilOrigin-Name: 625f78a630bbf897f945065f1b85a92fe26e426302c8f6edc4d26a817ff62358
2026-05-02 17:30:33 +00:00
drh 9db9f18985 Fix harmless compiler warnings.
FossilOrigin-Name: a0d0b5aff51088699e5ad0a726c350d10744b1779acd9ee54232659fb4c352a4
2026-05-02 15:58:28 +00:00
drh f107c52d4c Close database connections in a timely manner to fix test script problems
on Windows.

FossilOrigin-Name: 068a53865a17d4c2b4ce227fc08a2c019d1dbf31d833842ec08ab5665a3565a3
2026-05-02 11:47:22 +00:00
drh 7509c6351e Fix an SQLITE_MISUSE memory error in check-ini [1f940357f7bb160b].
FossilOrigin-Name: fc64113e8f9aee0161e682db7c244a7849f2db86551a557b276deb1785941476
2026-05-01 17:42:15 +00:00
drh 57e46429fe Harden the recovery extension against SQL injections coming from the
sqlite_schema table of the database being recovered.

FossilOrigin-Name: 9190f1b9b8889e4d80c370db36b916744d5779de0ec51da0369bbe74adb7b931
2026-05-01 16:06:21 +00:00
drh a9c2e08087 Check-in [1786fcd5b4ee6cd9] works great and generates correct code, but it
upset UBSAN.  This check-in fixes the UBSAN complaint.

FossilOrigin-Name: 7cd76847e8c9b683e39c1063a343288f11b4aa5e9302394fe0c4244d361ee4f1
2026-05-01 16:03:51 +00:00
drh 7f1f4c803d The value for /f and other filename substitutions in SQLITE_PS1 is now
"memory" if open on an in-memory database.

FossilOrigin-Name: 4aac1057eeaf6c29a4893e9c080497c780b0963e810c501532d79eba1b457f27
2026-04-30 18:23:58 +00:00
drh bd13573a96 Remove lots of code used to support legacy Windows version (WindowsXP and
before).  Use Slim Reader/Writer Locks on Windows for non-recursive mutexes,
since SRWLs are now available on all supported Windows platforms.

FossilOrigin-Name: 6f7a5ff22db10f889596239aae5f6a1130cbdfe72612ceee68cbeb3b86e40227
2026-04-30 16:52:56 +00:00
drh 0cadeecf6f Fix a harmless compiler warning in src/mutex_w32.c.
FossilOrigin-Name: 8de796ca459f2c996937fe1107838b217572636110c8c09e358343385bf17a1b
2026-04-30 15:41:01 +00:00
drh ad52288e0d Fix the memdb1.test test module so that it runs correctly on Windows.
FossilOrigin-Name: 9012f8ea7454bbb792b4361ed74d778e02b98ef44a443f9a23a27a4222fda747
2026-04-30 15:33:44 +00:00
drh d5f0e01593 Change the CLI warning that appears in the header about opening a
in-memory database, to be more readable.

FossilOrigin-Name: cc64cafdfe0b0965fabaf9d561d9a108c20a3643f71b36e6a6c51fc8f30b82cb
2026-04-30 15:19:09 +00:00
drh 3e663bd8c7 Add the /m escape to the CLI prompt string. Use it to show "memory"
in italic for the default prompt for in-memory databases.

FossilOrigin-Name: 1e3c95393044279997833145cb610b98926fb0c8f53ae4fb35e9fcc6c1ded1a2
2026-04-30 15:07:25 +00:00
dan 97901bbd69 Fix a crash that could occur if the destination database of a backup is
replaced using sqlite3_deserialize() between the call to sqlite3_backup_init()
and the first call to sqlite3_backup_step(). Forum post [forum:15d82885e2 | 15d82885e2].

FossilOrigin-Name: 1f940357f7bb160b583ac5b08ff4e32a9fef353255d032c5a18bcb04416c0f0b
2026-04-29 19:14:54 +00:00
drh c549e28c67 Reduce the number of system calls in the os_win.c thunk from 81 down
to 58, as well as other simplifications.

FossilOrigin-Name: c49521739c961ed5e38424bf26b2e34d8017a85122622ceac5af7398233fe343
2026-04-29 16:09:47 +00:00
drh 90dae0d01d Further simplifications to the interface to the Windows family of OSes.
An incremental check-in.

FossilOrigin-Name: f2aa6b66d2a1b5bb2dc8a44788a061a549a846244354df19b44398839578461e
2026-04-29 15:03:01 +00:00
drh 0a0a52ae93 Simplify the Windows interface by removing support for various WindowsXP
and WindowsCE.  This is a work-in-progress.  More to follow.

FossilOrigin-Name: 4dbc4d19c4f3b58d0bedd766cfba65d9624903a5ab0a340eb83ddeec058607ea
2026-04-29 14:02:23 +00:00
drh e1d4680fdd Updates and simplifications to the mutex implementation on Windows. Uses
Slim Reader/Writer Locks for performance, for non-reentrant mutexes.
Requires WindowsVista or later.

FossilOrigin-Name: a75aa5400f94531b8ffd00be4580b0578d8d81ba9681fd06b1d9d96a6180994c
2026-04-28 20:01:03 +00:00
drh 532e506d18 Attempt to align instances of the sqlite3_mutex object at 128-byte boundaries
to prevent false-sharing in multi-core machines. See the discussion at and
around [forum:/forumpost/2026-03-25T23:15:03Z|forum post 2026-03-25T23:15:03Z].

FossilOrigin-Name: 1786fcd5b4ee6cd9b4780f3687dfaec5b90ef0476e0da266a94e069b98e70514
2026-04-28 15:12:40 +00:00
drh c9bed48c3c Fix comment typo
FossilOrigin-Name: d64a1dbe0fb2d9286806d833a3146b21d5bf1636a650d5a64cf163c7f2356e98
2026-04-28 12:49:10 +00:00
drh 6b4eb6725f Improved detection of when the alternative windows-compatible main() is
needed in the sqldiff.exe utility.

FossilOrigin-Name: e25b849a603cb08ab888641ff324e9aa129391c4792de86a62c55e9caf84c16e
2026-04-27 14:01:23 +00:00
drh 6176034151 Relax arbitrary length restrictions on some error messages in the CLI.
FossilOrigin-Name: 52f5531ded8e0d3da3dc4d5c9b3d14573041b9446e2c45b5093c958b6c74e0de
2026-04-27 12:43:09 +00:00
stephan 7471b5d6c0 Increase a stack-local buffer size to resolve a test regression introduced in [ff084ae341eab5c], in which some tests fail a pattern match check if their absolute file names are too long. Resolves [forum:205f73db1b2806f5|forum post 205f73db1b2806f5].
FossilOrigin-Name: 286fc22c7ca882b0b09de2f1b2a7e0b382af6c498f2f8ad237fe064feaa70d7f
2026-04-27 12:05:56 +00:00
dan 1fc7341ad2 Fix a crash that could occur if sqlite3_deserialize() was used to overwrite a database with an open transaction on it. Bug introduced by [fc42d31d6fca21ab] on 2018-03-07 and first released in version 3.23.0. This is not a vulnerability as an attacker that can exploit this already has the ability to execute arbitrary code. Forum post [forum:39134ba029 | 39134ba029].
FossilOrigin-Name: 77662cce9aa452ba5820e5f1a864a802763bd83b937cdb16e7025219eff7bd08
2026-04-27 11:32:43 +00:00
stephan 6af10b0efd Refactor the uint128 type check to consolidate duplicated rules.
FossilOrigin-Name: 362ef7bc00eea180fb3458bd8887021aed54e321901483edc00ad6b23a33d8e5
2026-04-27 06:48:07 +00:00
stephan 70d1e3e75e Feature detection fix for uint128 on RISCV 32-bit, reported in [forum:f8d1417ce8eb2f22|forum post 2026-04-26T11:41:01Z] and validated by the OP.
FossilOrigin-Name: c4a2c20839ef75534d71d928a03ad276bdc488b0baa76c1505f48dc1ff0bcdd1
2026-04-27 05:55:38 +00:00
drh 74006fdcdb Improvements to temp-file cleanup on close in the CLI.
FossilOrigin-Name: 048c969c34eaaf8c203b996e999a7dbc94c47b4959719af9e6625052520f7135
2026-04-26 18:35:26 +00:00
drh 4b9f9d6794 In the CLI, eliminate the 2-second delay before getting the prompt back
after running a ".www" or ".excel".  Instead, remember the name of the
temporary file that is to be deleted and delete it later.

FossilOrigin-Name: 4e9ee211ca661fe8978b7f676f33ef962ff5c8177bc7c5ad42b19a2fa4482d90
2026-04-25 16:17:23 +00:00
drh 39b2fe7e5b Simplify the modePush()/modePop() implementation in the CLI.
FossilOrigin-Name: 92cad2cd7284d3a969b713336865007da2b0b2a8eef367d4185802174cbd027a
2026-04-25 15:05:46 +00:00
dan 01ec60bb87 Do not run expridx2.test as part of the "journaltest" permutation, as it requires wal mode.
FossilOrigin-Name: 11cfbae735669776c967522294b1606af90b4bd5379e2e1ed722520887b57757
2026-04-25 14:32:05 +00:00
dan e2dbd0a578 Fix a single-byte OOB read that could occur in the session module when concatenating patchsets.
FossilOrigin-Name: 60d7cd625a6160ba1bc60fd00fab2e91e0deff42034c6864107c19330b35ea7a
2026-04-25 14:00:29 +00:00
drh df7b22790e Minor code simplification in the CLI.
FossilOrigin-Name: 59795c71e5745e8a27dc596b9f1fc8f137df58a6ec8d8d0dab2b31cf8562796d
2026-04-25 10:45:17 +00:00
drh 50811f74e0 Fix a problem in the CLI in which the ".www" command followed by
".dbstat" does not restore the mode to its original setting afterwards.

FossilOrigin-Name: 4a5cac1d00e1fa287ab8ce3437c0152a9f362d72bdb9976889c93f6368b3fd66
2026-04-25 00:29:40 +00:00
drh d7bf8233ff Fix test cases due to recent CLI default prompt changes. Make sure ANSI
escape codes are recognized on Windows terminals.

FossilOrigin-Name: 22b791e404f0895b0f343b2ce0e169a7ada8578e46a39a9f4bd3a31f81c9853c
2026-04-24 20:27:42 +00:00
drh 455486bbc4 Improvements to the default prompt for the CLI.
FossilOrigin-Name: 9ab0bb487f78ba5a51cd3b4efcee23b11096e90ebf3add4da18aea657e8de0b6
2026-04-24 09:21:25 +00:00
drh ba9092e228 Improved default prompt in the CLI.
FossilOrigin-Name: 78193b60346dba304485241dd65f0eb6e971714397b76191b3bf7a5fdb44916b
2026-04-23 22:15:18 +00:00
drh 67d4e0226f Fix harmless compiler warnings. Enhance the CLI prompt mechanism to make
it more easily reusable by other projects, and to add the /h, /H, and /u
escape sequences.

FossilOrigin-Name: 354ce4f5e2a86b621b2058a6372495a5919cf3dc88ce1ed3637642f720c48002
2026-04-23 20:13:14 +00:00
drh 323b3fc121 Fix a bug in [dbc1d6f0a3452607] that disrupts the display when running
on a Windows console (not redirecting to a file).

FossilOrigin-Name: 75b5df2b0046827e985712b5725488b59667e2cfd171cde9f1194f2917165205
2026-04-23 20:06:16 +00:00
drh 78279e2550 Improvements to the #define mechanism in the CLI that allows other programs
that incorporate the shell.c source file to customize some of the
prompt expansions.

FossilOrigin-Name: e5f8840d11c1863cfc5c0b4a3d16c9ec9ab6ca6ecb7ff1a3a9a237715eed5d30
2026-04-23 16:40:34 +00:00
dan 4e4962f6b3 Have testrunner.tcl return a non-zero exit status if one or more tests have failed.
FossilOrigin-Name: 50ddc36d32540b6d98990b5c9a465beb5b68cc31ae3f0ed162f6fe07e7c74e2d
2026-04-23 15:54:00 +00:00
drh ed95a9d103 New CLI prompt escape sequences: /r, /A, /v, /V, and /D../D.
FossilOrigin-Name: e7c7acd1a4e5cb0f8e68f119352480c1aa9dd3c2b289c92f88e9e697a2e440e0
2026-04-23 15:05:46 +00:00
drh e791e7c7a0 Fix harmless compiler warning.
FossilOrigin-Name: 706373dcbe43752cf21604f278f96fb3015a36089ad64f069bb3a64bc526d137
2026-04-23 14:49:21 +00:00
stephan 2545d9c201 CLI shell: handle the special case of .prompt "" to not incorrectly report that as an OOM. Reported [https://fossil-scm.org/forum/forumpost/ca277be73a|in the Fossil SCM forum].
FossilOrigin-Name: 3fa0500b964869c45f7b49717680b791049f7cd8c47a06a337dd22351d2002f9
2026-04-23 14:05:36 +00:00
dan 2a07c6de2c When updating indexes on expressions, omit the update if the new indexed values are the same as the old.
FossilOrigin-Name: f0fc4e5ec334da3a1db8b0334e23d1911874c96675690da94210b2afb45f7307
2026-04-22 19:38:04 +00:00
dan 68b07ddd41 Add OOM test for the new code on this branch.
FossilOrigin-Name: 685be705a2a69e79de0d581e5bbe9d942133817342121786a551d95d59a4af6c
2026-04-22 19:25:12 +00:00
drh 4b69e7704b Mark branches that are believed to be unreachable.
FossilOrigin-Name: 18ed9736fbbea762e04b8ad156e83e577e60c5234a5e233540ad8664fe3b379c
2026-04-22 19:12:48 +00:00
dan e17ab401f0 Instead of adding a branch to OP_IdxInsert, use an extra OP_IfNull when updating indexes on expressions.
FossilOrigin-Name: 5112f96cb1428693614b91bcca78326fccf7289e395a920339676ceeba871e3f
2026-04-22 18:19:24 +00:00
dan 57ee077c5e Enable the optimization on this branch for indexes on expressions only.
FossilOrigin-Name: 3576b6930436b3149c5033476f70518e9b4adeaeec2538a68b7dc599eb854c47
2026-04-22 17:50:50 +00:00
dan c7edd22456 Fix P3/P5 confusion in the comment above OP_IdxDelete.
FossilOrigin-Name: 0fb6ca8e22f355838a02223dd24b34c0669a6cc0b7ac80931c721db72cf5c1c8
2026-04-22 17:31:19 +00:00
dan 8606a52934 Detect and omit cases where an index key is being replaced with an identical key.
FossilOrigin-Name: 7a01caf0d0864a462eb81b7643dcf89048f4ae56a29d762f0cfc38066218504f
2026-04-22 16:58:36 +00:00
drh 5c6404aa77 Fix a integer type bug in the previous check-in.
FossilOrigin-Name: 5e1b5ff1c170e94956bf77bd38afcad6369cb9f9333864711212af045281ad0e
2026-04-22 13:41:20 +00:00
drh 429369f4aa QRF and the CLI preserve zero bytes when outputing unformatted BLOB values.
FossilOrigin-Name: dbc1d6f0a3452607e4e92155df0fdb1c5ea4ea5ad1654664f86383faf6c105ef
2026-04-22 12:22:32 +00:00
drh 9529894a29 Fix harmless compiler warning in QRF.
FossilOrigin-Name: dcfb505ac7762f7a3102e1c3853a83dca1d1ef436cc8981949b63c7d7992cc5b
2026-04-21 22:19:38 +00:00
dan c4c47a49a8 Disable optimization of nested EXIST loops. Possible fix for [forum:/forumpost/077c02e8ed | forum post 77c02e8ed].
FossilOrigin-Name: d0d95a39bc211034071746395ee6dbcfbea9d573d27480655391ba9698f7e214
2026-04-21 20:40:22 +00:00
drh ee7f6f29fc Fix the BETWEEN operator so that it propagates the EP_Subquery,
EP_Collate, and EP_HasFunc flags in the expression tree, as it ought.
Fix for the problem reported at
[forum:/forumpost/2026-04-21T19:10:55Z|forum post 2026-04-21T19:10:55Z]
and probably a bunch of other problems too.  This has been incorrect
for a long time.

FossilOrigin-Name: 2d1d2947b28f5dcbf4c66b594e176038c4e71e61948a88db565c1cb1212657ce
2026-04-21 20:28:38 +00:00
dan c3b52dff53 Correctly dequote the constraint name passed to ALTER TABLE DROP CONSTRAINT. This improves upon the partial fix in [7f5afb12f4]. Forum post [forum:/forumpost/a746b08b87 | a746b08b87].
FossilOrigin-Name: 9387238cb0bb2651c64ecb229072df039577d71fd91546a2f0c94ca9755bf25d
2026-04-21 18:07:04 +00:00
dan 30af54043e Disable optimization of nested EXIST loops. Possible fix for [forum:/forumpost/077c02e8ed | forum post 77c02e8ed].
FossilOrigin-Name: 64f0d9eb63a351de12bb9643f1f6390a89f6d95dc81c07f1dc409ee31bae6f83
2026-04-21 16:40:08 +00:00
drh 4ebed2a4e5 Fix an off-by-one buffer size calculation in the decimal.c extension.
FossilOrigin-Name: 24df42104d5fd1cf974f2bf539fa7515808e21e68d64899c39f5fcf3bee49a48
2026-04-21 16:07:15 +00:00
drh 532ed30ab2 Do not unnecessarily delay opening the database file in the CLI.
FossilOrigin-Name: ab6ee76c1266b753d0749c63890f40db875536ceb4dd3252cc7a3386e386a0c1
2026-04-21 14:39:23 +00:00
drh 5e99eeb3d8 Fix another bug in [/info/e33da6d5dc964db8|EXISTS-to-JOIN] - this one
having to do with an OFFSET clause of a LIMIT.  Reported by
[forum:/forumpost/2026-04-21T10:57:09Z|forum post 2026-04-21T10:57:09Z].

FossilOrigin-Name: 1dd3c6a5e50ac3f617683678223e42f48636c17e58905506c5c74cc4bf05845c
2026-04-21 12:59:43 +00:00
stephan d3abfd77f5 Reformulate how the OPFS async proxy Worker is loaded for the bundler-friendly builds to work around a bug in Vite in which it incompatibly rewrites the Worker's URL arguments. Addresses the discussion at [https://github.com/sqlite/sqlite-wasm/pull/159|npm package PR 159] and patch validated by Jure Rotar.
FossilOrigin-Name: ec877a30f5c5db30b9154745140744c5cc80d89673d79e50901d7377599cf2b4
2026-04-21 10:19:38 +00:00
drh 63984b6ab7 Fix the fileio extension for Windows builds so that it does not depend on
the sqlite3_win32_utf8_to_unicode() and sqlite3_win32_unicode_to_utf()
routines that are found in the SQLite core.
[forum:/forumpost/2026-04-20T02:02:56Z|Forum post 2026-04-20T02:02:56Z].

FossilOrigin-Name: fe0414a9a3caf6af67f53a5f3534efd5d4bf4978ebce1c591ef62d6961e55701
2026-04-20 10:28:19 +00:00
drh 93082e5589 Fix a harmless compiler warning in test/speedtest1.c.
FossilOrigin-Name: 13f0fd1daaf787bff6eded4a01c2cf47c79e52cf8812bb344995e28c015a4ed1
2026-04-18 21:51:32 +00:00
drh f6b807a022 Performance improvement in the substr() and length() SQL functions.
Caution: The new code may give different results for malformed UTF8.
I do not consider that to be a problem by the GI/GO principle.

FossilOrigin-Name: 6124d27a33f4562f40777c2c6318d61709f7b481f23f9ade45064d8ad0700752
2026-04-18 12:31:53 +00:00
drh 8c6a6b85db Fix a test case that started failing due to a change in the help text
for the ".prompt" command of the CLI.

FossilOrigin-Name: bfe9df1bf4660ce6bdfd11a4f06d32694c93750c7bc0a6432459d9f1089eace4
2026-04-17 19:12:27 +00:00
dan 9f76fb019e Update interrupt2.test to avoid using Tcl_GetCommandInfo() from within calls to Tcl_DeleteCommand().
FossilOrigin-Name: 1979aa0902a43f20d4e396c5f9b9a49aaf0094d8520bf53ce058bb379a7720ab
2026-04-17 15:09:50 +00:00
drh 29997b4731 Help-text and comment fixes in the CLI. Add the output-redir-test.txt
testing script.

FossilOrigin-Name: ec58a133b4716d4f5a53c38853f8ecdb7a1275b931663ce07c8dc700d845e62e
2026-04-17 11:41:33 +00:00
drh f0c8e27670 Less error-prone parsing of ".once" options. Fix for the problem reported
by [forum:/info/2026-04-17T01:26:56Z|forum post 2026-04-17T01:26:56Z].

FossilOrigin-Name: b235a8093734f457c2731af017c99027510d04e5cd1060f5559afbec5409a472
2026-04-17 01:50:40 +00:00
drh d6c985ad0b Fix testrunner.tcl so that it does not create directories with names
ending in "sqlite3.o" or "sqlite3.lo".  Use "sqlite3obj" for those
directory names instead.  Otherwise "make clean" gets confused.

FossilOrigin-Name: a4bf9289c9cdb12b22bfb24e7e2b0243384e9edece12ae3fed14afbfe9b93260
2026-04-16 19:50:52 +00:00
drh 1696740fdc Improved comments explaining the logic, and improved diagnostic messages
when testrunner.tcl encounters trouble loading the sqlite3 extension.

FossilOrigin-Name: 8d820b0ccfccff94ed5b7297fa587ac27a74e990f233cfe229da7409ab2e3af8
2026-04-16 19:33:04 +00:00
drh 2cefd5954a Minor updates to testrunner documentation.
FossilOrigin-Name: f8507bd5e221783175be2bb7b907c098e0970b1cbcb01817df7217005eab9ab4
2026-04-16 17:07:23 +00:00
dan 8895c50403 Run C-language tests in tests/c/ as part of release test.
FossilOrigin-Name: e6929022b71c6bff7aa9cfbdb8a5e80499ca856b8c06d4211c55311b48704a08
2026-04-16 16:43:32 +00:00
drh a2116f86b0 The sqlite3_str_new() interface never returns NULL, even after an OOM.
Code that uses that interface should invoke sqlite3_str_errcode() to see
if an OOM has occurred.

FossilOrigin-Name: cb910047edc591102dd4ed0d57c863b366981b8aa1d3085d5f95b1fbbabf6c31
2026-04-15 14:41:25 +00:00
drh 1e472f2d32 Bug fix in sqlite3_str_free(): Do not crash if called on an sqlite3_str
object returned from sqlite3_str_new() following an OOM.

FossilOrigin-Name: 92d8ac0c4938e43b00111b43630ecfa91c30e5200ca03937a84f4b50bd1a13b3
2026-04-15 14:17:58 +00:00
drh e3dbf75160 Add support for the analyze() extension function to the fuzzcheck test
program.

FossilOrigin-Name: abd94554d24122f0e0c3b7b36e5846e8c7aa0dddbddd9aae35b3f6ae6ab283c0
2026-04-15 13:05:43 +00:00
drh ade9289540 Improve the analyze() extension so that it returns a simple error message
as text (it does not throw an error) if the database is empty or is "temp"
or does not exist.

FossilOrigin-Name: 35379f60922f14d4f6d231ae627df066ad4e4510208bcc244505b9afb279f2fa
2026-04-15 12:47:37 +00:00
drh dfba4eb34a Fix harmless compiler warnings seen by MSVC in the previous check-in.
Also add ext/misc/analyze.c to the makefile dependencies for the CLI.

FossilOrigin-Name: 5a0ee6e227042e41ac64869c75f961798b252458670c18662175fe5bfa8b87d3
2026-04-15 12:35:23 +00:00
drh b57d2a5a51 Add the analyze() SQL function implemented the ext/misc/analyze.c extension
(but not part of the amalgamation).  Make that function available in the
CLI and add a new ".dbinfo" command to the CLI using that function.

FossilOrigin-Name: 4c4988e56df3c668b8891e2a55887a6618f5b84e9111e562b93059ddb9a662dc
2026-04-15 12:20:11 +00:00
drh 84c1079220 Add a missing open_db() call in the new ".dbstat" command of the CLI.
FossilOrigin-Name: a138e44a243466f8679e9652421f8c893a4a1bc0addc86736588d9aee51cf090
2026-04-15 11:58:54 +00:00
drh c8d866294b Add the .dbstat command to the CLI.
FossilOrigin-Name: fdba76df2b3a5b4d56ba79f80fd8b16d5faebca1fb07a266262be2ea635e6f94
2026-04-15 11:41:50 +00:00
stephan f0baddb205 On platforms which support ./configure --with-icu-config, ensure that 'make tclextension' includes the ICU pieces in the tcl extension. Intended to resolve [forum:92a88de4b88929fe|forum post 92a88de4b88929fe].
FossilOrigin-Name: 404fde8bacc3f05254a2fcdb1531a7f53125a7ad45dc6b68a5065c1d0c73b670
2026-04-15 11:40:13 +00:00
dan ec2ea68d1f Avoid a potentially undefined left-shift in the fts5 porter tokenizer.
FossilOrigin-Name: 46a288e43e4c48fca6610bce6a2db418aaa3c8a1dcb115b7a0bfad2063355e58
2026-04-15 11:23:30 +00:00
dan c71e6dd054 Handle the case where the name of the constraint in an "ALTER TABLE DROP CONSTRAINT" command is quoted. [forum:8bfbaec404 | Forum post 8bfbaec404].
FossilOrigin-Name: 7f5afb12f4a5d35cfe6b95f17d85ce85ce62159515bfe26fb9c67d3ce26b6d4a
2026-04-15 11:07:58 +00:00
drh 9efde40a5d Compute the average fanout for b-trees of depth 2 or more.
FossilOrigin-Name: 2f8598bb09f32100f22dd1d9465f3fa0f7f8d81f5d67c34de9919708345f090b
2026-04-15 10:49:14 +00:00
stephan afef1f2923 Minor doc typo fixes contributed by BrickViking.
FossilOrigin-Name: c4660ce205919ce0d9262e7fd7879375a72ef65d9e5ac97f19caf5dc36e355aa
2026-04-14 23:53:38 +00:00
drh 09f37099a7 Code simplifications. Return NULL is the specified SCHEMA does not exist.
FossilOrigin-Name: 953969c88149ea2f589942b98a0a96d907956319e5aa09e2d5a3ae76d3e7d70a
2026-04-14 23:19:02 +00:00
dan 846fbd6653 Handle a special case of a corrupt changeset in sqlite3changegroup_add().
FossilOrigin-Name: eba625f917935437e3f366197df1c6717c7120ce0418a0cbac1d2024b2235091
2026-04-14 20:18:54 +00:00
dan 1b14a925dc Have the session module detect some corrupt changesets earlier.
FossilOrigin-Name: 0de91ff0d798cff21289d893cc441b89fc37b051d5cdf611d92d3ae2bc41cdf2
2026-04-14 20:17:41 +00:00
drh 526acc1834 Merge trunk enhancements and fixes into the analyze-sql-func branch.
FossilOrigin-Name: bb4a9beac87796b4186efce416bf03f840041bc588be6702c5a444d643df684e
2026-04-14 20:17:03 +00:00
drh d962afef2d Various minor tweaks and refinements to the analyze() function.
FossilOrigin-Name: 48d94e72eaec443011dd1f7a7264e5222c05bb515c84deaf20ed4195b74d45ff
2026-04-14 20:07:29 +00:00
dan 839433d457 Handle a special case of a corrupt changeset in sqlite3changegroup_add().
FossilOrigin-Name: 49b3bac482c831f503c7f90c35959e7ea731950e991baba86b2ab95987d2539b
2026-04-14 20:02:49 +00:00
drh 395ac6c1bc Implementation of the analyze() SQL function is now mostly complete.
FossilOrigin-Name: 1ca0386ab2df0d88ed52941469d459114f483ecf6b7e4691bcc32e909636cb7d
2026-04-14 19:36:33 +00:00
drh e9d0bc6b68 Much, but not all, of the report generation is added. An incremental check-in.
FossilOrigin-Name: 289fefc3edfeecb06dc11897d3ff24763fd9e25db44e369eeec29b9ed3de5ccc
2026-04-14 19:02:40 +00:00
dan 483f0ef13c Ensure c-tests use the locally built sqlite3.h file, not the system copy.
FossilOrigin-Name: 2d81ee65ffbed30fd98bdda96dc79c1929c73f806cea3c9e4c244b618980b202
2026-04-14 18:12:09 +00:00
dan ab6a63ec67 In RBU vacuum commands, do as SQLite does and ignore any trailing SQL statements in the sql column of the sqlite_schema table.
FossilOrigin-Name: cf7dad1b105ab35cd7180efec735b7cbeaf42b8d53dfec5582b63cd121c3425c
2026-04-14 18:08:30 +00:00
drh 57ed7f322f Check-in [495e4851d4296b49] breaks the build for Windows. Fixed here.
FossilOrigin-Name: 5b004348c3ec15a02dd657b3619502b6f8ba1c6f46918108b3de9534622076a0
2026-04-14 18:06:41 +00:00
drh 34c2c8dc47 Further fixes and clarifications. Now ready to start generating the
actual report.

FossilOrigin-Name: 037a0e586c4aa81a53aea164080e739f9d5b87197d04fdd68feb0ab5eb01020b
2026-04-14 13:18:04 +00:00
drh 3f9df1f5fb Further improvements to error messages and robustness.
FossilOrigin-Name: 45917c1124310fd77daca47865959d3261154f7b0c6771d3689e6d345a3fd153
2026-04-14 12:46:12 +00:00
drh 2eeac123c8 Improved error messages and robustness.
FossilOrigin-Name: c09ed9eb914bde96cdc5157e29b6384ce488262a2dadc7321c44941a1d08a187
2026-04-14 12:23:11 +00:00
drh 64a123a216 Initial prototype implementation of a new run-time loadable SQL function
to do approximately the same work as sqlite3_analyze.

FossilOrigin-Name: 03934b5a6c88a97117a4743a68ee36d30bcbdcebcf11342d30ac42daf9f10874
2026-04-14 11:25:22 +00:00
stephan a10e79d91a Minor README typo fix reported off-list by BrickViking.
FossilOrigin-Name: aa3432af90b2b9ab0b92f56a8e9c926930b9859e986500bd00d5600c1dd036bf
2026-04-14 02:09:43 +00:00
stephan 6e93d28950 Pass the ICU-related build flags through the 'tclextension' target, not just 'tclextension-install'.
FossilOrigin-Name: 499c89f8745fac7ee93ff79a340abd69b4f06b07983b4d50057fa5d0893b2f3b
2026-04-14 00:48:34 +00:00
stephan 008395614a Tweak 'make tclextension' to pass on any --with-icu-config build flags so that it can link with the various ICU libs. This works for me but needs testing on a wider selection of systems before being moved to trunk. Intended to resolve [forum:92a88de4b88929fe|forum post 92a88de4b88929fe].
FossilOrigin-Name: a8c022d7946e8a29114400c1321f36f03979a2277253f1dcd769d8f36e944ece
2026-04-14 00:11:23 +00:00
drh d20673a95f Fix typos and inaccuracies in comments. No changes to code.
FossilOrigin-Name: a6c2d7ce84f4f5f8a82cc566a27f98f5418f251e87f1f264ae57935fb10399f7
2026-04-13 17:33:34 +00:00
drh f02d100e08 ".prompt" command improvements in the CLI: Guard against mistakenly saying
".prompt show" without the "--" before "show".  Add the --hard-reset option
to .prompt to make it more easily testable.

FossilOrigin-Name: 495e4851d4296b49a37b963edd8410314de1510b2ae0b9dbe9dc0307c466c3b5
2026-04-13 12:22:16 +00:00
drh 4c8f0621fd Improvements to the prompt_filename() function in the CLI so that it finds
the database filename even if the connection is not yet fully open.

FossilOrigin-Name: efb3e808a0281014512a812920d526a4909467e925ea000956606318bb6f2e65
2026-04-13 11:34:15 +00:00
dan dd1e2c39bc Update test/c/snprintf1.c to test the result of the sqlite3_snprintf() call. Also add an SQLITE_OMIT_AUTOINIT configuration and update C tests to account for it.
FossilOrigin-Name: 30b597d797e737a2907b755706a37d63c37c6a06c4e037098a6d9c482bcde887
2026-04-13 11:20:51 +00:00
stephan 6abc21cfb8 Latest upstream jimsh0.c.
FossilOrigin-Name: 414ae4dd65182ce571a6abb1a1a2ba2c169b204156f4f8923c42f64805a3ef9f
2026-04-13 10:56:14 +00:00
stephan 20079bb358 Doc typo fix which broke the docsrc build, reported by BrickViking.
FossilOrigin-Name: 3c212b5d85338f90a5f1a2d1484e54c0bf699eedef19a16f4c0de76a76dd9d07
2026-04-12 17:47:57 +00:00
drh 3d6fa49c54 Bug fix in the revised ".prompt" command of the CLI, with test cases.
FossilOrigin-Name: 7583385593354f90a9818d1820543841109f253dffcec5ca5ed7629336e29fac
2026-04-12 10:46:35 +00:00
stephan 4df365e5a7 Fix a typo which causes .headers to not show up in the shell's .help.
FossilOrigin-Name: d379b14a48d331933240fb99ab43c3cc978638d7ad0a8d5975bb211a72eaef2b
2026-04-12 05:41:28 +00:00
drh 9d8bf6f04a Change the prompt escape design yet again, to use / as the escape character,
since &#37; and just about every other punctuation character is special to
cmd.exe, batch files, and nmake, on Windows.

FossilOrigin-Name: 79a8d3edf8207d72f0c4650272ee239a1c7783a07f907fbf0cf5a7ad99b27a2a
2026-04-11 23:58:15 +00:00
drh c0026ff7a6 CLI prompt design change: The escape character is changed from &#92; to
%#37;.  This avoids lots of quoting problems when trying to specify prompt
strings in various programming languages and shells.

FossilOrigin-Name: e7e6ecc45dfe1a163d259be26877bd7e528ce154e73b3ca8ab7edc5aa94d2d02
2026-04-11 22:58:25 +00:00
drh 1e3f888acf Two C-preprocessor macros SQLITE_PS1 and SQLITE_PS2 can be set to override
the default prompt strings in the CLI.

FossilOrigin-Name: 6fa0216a19c2f165110121227d3f9b9119369f8cd61f9c6d13eaa1ae42a60d60
2026-04-11 22:18:05 +00:00
drh 2d4dfbccdc Make sqlite3_incomplete() available to extensions.
FossilOrigin-Name: 50d81300ba0f021f388aab1e86e97d688ed762cee408c610cf70977f7b488803
2026-04-11 20:53:53 +00:00
stephan 6142310e08 When fiddle terminal mode is enabled, add a link to the jquery.terminal project in the About box.
FossilOrigin-Name: d64f0c8845104008d6c251f9a1406c6ff717a916c13b64014aa1d154501d5fab
2026-04-11 20:43:49 +00:00
drh 42ae7e7f34 Fix harmless UB in sqlite3_incomplete().
FossilOrigin-Name: 8dfdff559faefd943b97827dc3c7100fc4469e2f8353a264fb322e23af5cb669
2026-04-11 20:41:54 +00:00
stephan 57cf5c2dfc fiddle: disable jquery.terminal's pre-processing of user input, as discussed in [forum:c6665017c0dbba1f|forum post c6665017c0dbba1f], with many thanks to the jquery.terminal team for this workaround.
FossilOrigin-Name: ea7e121ab2a7b2fee5372ca12a2a53c7e98ffa1b49d85944f7ce4a7251a777c8
2026-04-11 20:31:03 +00:00
drh a212476ad2 Improvements to the interactive prompt in the CLI:
(1) CLI honors SQLITE_PS1 and SQLITE_PS2 envvars as prompt strings,
(2) CLI prompt strings expand various backslash escapes,
(3) No arbitrary length limits on CLI prompt strings,
(4) New default prompt shows the database filename using the &#92;f
escape,
(5) SQLite core adds the sqlite3_incomplate() API, used by
the &#92;H escape in prompt string rendering,
(6) Enhancements to the ".prompt" dot-command.

FossilOrigin-Name: 55af98054e073d6eee3e85fd7564c83eca935ae205da68f5e8f1b561e7f08c00
2026-04-11 18:38:54 +00:00
dan 0523cfda5a Fixes for running C tests on windows.
FossilOrigin-Name: 1fcacdc41ab1bb66a628acdac29412e66decdc2578dd9d084baaffb74679f984
2026-04-11 18:05:49 +00:00
drh d08caad3a5 Fix harmless compiler warnings.
FossilOrigin-Name: 3b4cc8d3beab8c910dd954bf8093f7ab499e4690b9cf882f981c4415dd7a7540
2026-04-11 17:47:31 +00:00
dan bc68ec78de Enhance testrunner.tcl to run individual tests written in C from the test/c/ directory.
FossilOrigin-Name: 6f140f76f47aadb10d3f35358503d91adb43e0c1802326f6e599effe1b08e7aa
2026-04-11 17:03:27 +00:00
drh 28456958ca Initial test cases for the CLI prompt enhancements.
FossilOrigin-Name: b7ecc84735d41e9cdb498020b86d8219efa18ca5b40aef1031a14809f1ac2d38
2026-04-11 16:12:12 +00:00
drh 3b27ffa534 Add --reset, --show, and -- options to the ".prompt" command of the CLI.
FossilOrigin-Name: 8075576ba2324a458440bae398baecc7872b6528574b7fe6681a3a30b62d58ef
2026-04-11 15:45:45 +00:00
drh fc2c730c87 Enhancements to shell_prompt_test() for better testing. Enhance the
".open" command so that it does ~/ expansion on filenames.

FossilOrigin-Name: ec6830fe60b73bc606d3c2a5d407a39db53f6dadee760829410abfa1df46389e
2026-04-11 14:11:56 +00:00
drh cd28797117 Remove arbitrary limits on the length of CLI prompts. Use environment
variables SQLITE_PS1 and SQLITE_PS2 (if they exist) as the default
CLI prompts.

FossilOrigin-Name: a46ceaeab968d8f376c5a225c23c0be8619fed4511b7e567baf3a8d7736c19d1
2026-04-11 12:35:53 +00:00
drh c8b130f255 Fix the &#92;B escape for prompts so that it uses wcwidth() instead of
strlen() to compute spacing.

FossilOrigin-Name: c6ff4f701d9cf963cf2472ed72ad4e201227560dde2ba8d48602af2e49170e89
2026-04-11 11:24:09 +00:00
stephan 7a0a0a22e7 Ensure that sqlite3-opfs-async-proxy.js is copied into the fiddle target dirs.
FossilOrigin-Name: 149200861e4690dab5f2e690b62f355b13a8370dccaab5546caa6842b4ff963a
2026-04-10 23:31:29 +00:00
stephan 504cfd5ec7 Ensure that sqlite3-opfs-async-proxy.js is copied into the fiddle target dirs.
FossilOrigin-Name: 7c9998de1b839cfbe12c4328ac5176f5fae981e139c5f8888b100752f5e4756b
2026-04-10 23:25:57 +00:00
stephan 9d950aa13b A protype of .prompt support in fiddle but its utility there is in doubt because .open does not work there, so there's very little dynamic info worth showing in a prompt. Also, ANSI colorization can't work there, nor can we colorize the prompts using HTML because of limitations in jquery.terminal.
FossilOrigin-Name: 3b17500dc6338df23d1ed0572cd71593da5a9b048731f73242e27b9a76553a27
2026-04-10 23:05:41 +00:00
stephan b709ba8108 Expose the main /fiddle object to the browser dev console as globalThis.fiddle for experimenting with a dynamic prompt.
FossilOrigin-Name: 8574e5c9da3b167384faafb8ec0d01953578676cc42536bb6f7d0e73408ced36
2026-04-10 21:58:13 +00:00
drh 01e1be854b Fix minor issues on Windows.
FossilOrigin-Name: 48e40d3f6a193d6c4d1b8deda36415a690602dbe33d49984a9d92c6d40d8da5c
2026-04-10 20:44:38 +00:00
drh 70868a5ae3 Fix prompt for in-memory databases. Fix the continuation mechanism so that
it looks at all accumulated lines, not just the most recent line.

FossilOrigin-Name: 166894725569cafa96c434aa14db0428db6791a8296fcc2990bec4ec819fd876
2026-04-10 20:29:35 +00:00
drh d0065c8118 Replace the former dynamic-continuation prompt logic with backslash-escape
prompt expansion, include some expansions that serve the same role as the
old dynamic-continuation prompts.  This allows greater user
configurability.

FossilOrigin-Name: 052631202e4dd930d93434b7003e73b23557934421ace5d2f382f041638d5518
2026-04-10 20:14:16 +00:00
drh bd574dbaee Add the &#92;B escape for CLI prompts. Change the default prompts to
use &#92;f, &#92;H, and &#92;B.

FossilOrigin-Name: 354325b6f396bda38bbb82e7d38aa50d3d6441e1ebb9b578aed8e0bcf62f9911
2026-04-10 20:06:34 +00:00
drh 7632922625 The &#92;H escape on a prompt string fills in with the characters needed
to make the input "complete".  Add the shell_expand_prompt() SQL function
for testing purposes.

FossilOrigin-Name: 6aafb76c74b73aafef74250dae9c8cbe73226c0efb606e8f80ea761b3293cf9d
2026-04-10 19:33:15 +00:00
drh 49998a6d25 Merge trunk fixes and enhancements into the cli-prompt-redo branch
FossilOrigin-Name: f3354ebf51e684ef680986bef9b606f63786c254f1c8774bcaf7a7f3d0d37056
2026-04-10 18:53:13 +00:00
drh 92c435cda7 Improve defenses in QRF against trying to run the same prepared statement
twice, concurrently.

FossilOrigin-Name: 6ab6f622be3e1ad93166d139b5fccf9628c86d1c14c6dfb4464cb8cf52c94785
2026-04-10 18:14:33 +00:00
stephan 35f8abcfd0 API doc correction for sqlite3_js_retry_busy(). No code changes.
FossilOrigin-Name: 749c537812b907164b7e7ad1fddc1aee8106c59875d2686fe83d602cd0e07611
2026-04-10 17:55:31 +00:00
drh 1a315c0d51 Use sqlite3_malloc() for memory allocation inside of sqlite3_str_vappendf(),
since it invokes sqlite3_initialize(), whereas sqlite3DbMallocRaw() does
not.

FossilOrigin-Name: a2f84c56316ea746c134aa6e5a2b46021f67c6642161beae8122f73daeddda92
2026-04-10 17:11:16 +00:00
drh 3a8d38ffc0 Fix the printf() optimization added at [ccb6b6c4ac21742d] so that
sqlite3_snprintf() does not incorrectly truncate floating-point
conversions that are close to filling the buffer, as reported in
[forum:/forumpost/2026-04-10T13:48:12z|forum post 2026-04-10T13:48:12z].

FossilOrigin-Name: a50521a16068e555aa08ee25726b081bb4cd33e3ea388b82dcbaa691c2576284
2026-04-10 15:55:08 +00:00
drh 693b15ac83 Prototype sqlite3_incomplete() - a variant of sqlite3_complete() that returns
additional information about what is needed to complete the statement.

FossilOrigin-Name: a698fbfb8bb256ee0d9802c01562c11492ca2800a45360b268ac6cf397a7fad7
2026-04-10 13:43:48 +00:00
drh 8cdc2abf07 Attempt to work around a bug in legacy Microsoft compilers.
[forum:/forumpost/2026-04-10T06:33:11z|Forum post 2026-04-10T06:33:11z].

FossilOrigin-Name: 661e1413625f55c37e2cd4d785074576d355e125231bbc1dd0a511a2b02c8e3b
2026-04-10 10:48:04 +00:00
drh 931fa90d74 Change a variable name to try to quash a compiler warning reported
by [forum:/forumpost/2026-04-10T09:33:27z|forum post 2026-04-10T09:33:27z].
This is just a guess, as we have no way of reproducing the warning,
and hence no way of knowing if it fixes the problem.

FossilOrigin-Name: e065c019d29d4e82a21a89984b86c1811c2b1bdd4663c792857cf89ea2cd91c3
2026-04-10 10:27:04 +00:00
stephan eb9a6a95ca Correct shell result code propagation regression introduced in [ff084ae341eab5c4] and reported in [forum:6fa3247e9724844c|forum post 6fa3247e9724844c].
FossilOrigin-Name: a76682a3b1d6c5e8ca16caf8afbe545c9ae39849fe21ba68d4cddae683a409b5
2026-04-10 08:36:55 +00:00
drh b37bf0b8b4 Improvements to the way &#92;x works so that it can be used to change
the prompt color.  This really messes with linenoise, though.

FossilOrigin-Name: bbee56f970ade40734c8a278f46d8a268b305fe349c3739c977fa9141d2c3b6a
2026-04-10 00:55:40 +00:00
drh 850104bbad A prototype of code that shows how to expand backslash escapes in the
CLI prompt.

FossilOrigin-Name: 9cf28959671920b4909521bb1db6f0cbbc85448fbf3594c43b4000505b4e055b
2026-04-09 23:37:48 +00:00
drh 6a6ebb0d06 Store the prompts as part of the ShellState object, not as global variables.
FossilOrigin-Name: 39f6c5a8a7d91e03f89b13496e333b9500977a2cbcc0c27ba14dfb87dc81e678
2026-04-09 22:14:58 +00:00
drh 30b824e432 Strip out the legacy dynamic prompt generation. It will go back in as I
add the user-defined prompt escapes.

FossilOrigin-Name: ab08b7a8ef518f96a549a41fe8ff11776abe5e83153c5f8d5d58694ecc476389
2026-04-09 20:21:25 +00:00
drh 3944e70677 Clean-ups in prompt generation in the CLI.
FossilOrigin-Name: e2c9d4c6b731ea9afbb9cb22f86a3db3670ca67968f15891dc46ae1fc9ba34dc
2026-04-09 18:51:09 +00:00
drh df0e915ad2 Use O_TMPFILE (on systems that support it) to security create a temporary
file that is inaccessible to any other process.

FossilOrigin-Name: 4609ba34b8b4a6df4cd28e39d19f96e59580db0e838f1aa605cc00ea003c2a85
2026-04-09 16:16:39 +00:00
drh b0d9039c8c Updates to testrunner.tcl: Shorten the prefix on created subdirectories from
"testrunner_bld_" to just "testrun_".  Do not append ".exe" to the names of
created subdirectories.  Add the "clean" command to recursively remove all
subdirectories and files created by a test run.

FossilOrigin-Name: 450c7edf1247024db4b66f38bf9561c5c6b0c4175c4df8de17019aea6cbde5cf
2026-04-09 16:08:29 +00:00
drh f1cc3c4be5 Version number to 3.54.0 to begin the next development cycle.
FossilOrigin-Name: 4c2a5c9bb40c63bb9d0f633f78d132bdd69b9d755d4e6d5e3cb534e63b383a4e
2026-04-09 16:03:56 +00:00
drh 3aed7dc446 Make use of O_TMPFILE for more secure temporary file creation, when that
option is available.

FossilOrigin-Name: 094fc6da0768ea0ec4b4d3dc020cd6025aab341550d6cea6be7487ac570f9171
2026-04-09 14:12:09 +00:00
drh 9a8732e44b Merge the 3.53.0 release changes into the cli-prompt branch
FossilOrigin-Name: 8fd48b9fe47d47b3eca31d187f1d98174c257daea220ae7be18e4c82764d9d5c
2026-04-09 13:21:09 +00:00
drh 4ebc7fdcf4 Version 3.53.0
FossilOrigin-Name: 4525003a53a7fc63ca75c59b22c79608659ca12f0131f52c18637f829977f20b
2026-04-09 11:41:38 +00:00
dan a5495355c4 Fix some buffer overreads that might occur in the session module when handling corrupt changesets.
FossilOrigin-Name: cda5dd9bcbef2135bb9855139a11d0e22a092f9498d82eb18e7d4401264b6eb8
2026-04-09 10:39:32 +00:00
dan df3e207501 When generating make.sh for testrunner, correctly quote the value of any options passed via environment variable OPTS.
FossilOrigin-Name: 0837933b49f5fc5590f2052808bc305aceccafbf5db65aae250c594ce48d4d32
2026-04-09 06:38:31 +00:00
dan 535b1f2875 Fix some buffer overreads that might occur in the session module when handling corrupt changesets.
FossilOrigin-Name: 8fcf92e15d87487703afc1129f3a89a8d4d72cb30d30a1a9151a5596473069bd
2026-04-09 05:33:19 +00:00
drh a7200804eb Fix a buffer overflow bug in a recent check-in, reported by unsolicted
email from OpenAI/Codex.

FossilOrigin-Name: be891a137af15897691250324e4d3d9c96f0c5fb414bca27d0c3bfdd3012a8a2
2026-04-08 17:00:33 +00:00
stephan 0d979c217f Fix a few doc typos and inconsistencies. No code changes.
FossilOrigin-Name: 025abd4cf409fb9938e116289f23dc5bcd6d14feb46066221e691b146ee9b354
2026-04-07 15:54:35 +00:00
drh e9af8caac0 Fix incorrect datatype on the auto_ext_leak_tester() function in the CLI.
FossilOrigin-Name: 4a36454904e1c5e7d25406713ab0125f11df66eabe0d378edcb837ef8dedc981
2026-04-07 12:51:52 +00:00
drh 606c64a543 Fix redundant typedef in qrf.c when that file is amalgamated into
tclsqlite3.c.

FossilOrigin-Name: b8f0c71b48953cb6d5a8b3d33d004a31b63c59d59d455f285bf8fa91c3b07129
2026-04-07 11:31:41 +00:00
stephan eefe3aa9ad Replace a doc reference to a renamed file, as reported by [forum:5d9d70c618|forum post 5d9d70c618]. No code changes.
FossilOrigin-Name: c8121593fa455cd43b3878f8b65ebac47c07dab4b8ce081aa34b14fc9440afbc
2026-04-07 09:15:21 +00:00
stephan fcef193a82 Add a dummy auto-extension to the shell in SQLITE_DEBUG builds to validate that [9d56df17b4ab49] does the right thing.
FossilOrigin-Name: 164af3703b8fb5d88612edcceeaae0ae5a230c34c7a0f2ac9b650f5a742b2787
2026-04-06 22:00:20 +00:00
stephan 8e7ffc09f5 Add a call to sqlite3_reset_auto_extension() near the end of shell.c.in:main() to squelch a leak message when SQLITE_EXTRA_INIT adds auto-extensions, as reported in [forum:310cb231b07c80d1|forum post 310cb231b07c80d1].
FossilOrigin-Name: c4dd7e8b36deced3ee9cc6b5f87d8b3cc9a752cad8d62c9b711c7b58db11834b
2026-04-06 20:24:02 +00:00
drh 9ad63c0f4e Appease static analyzers by masking the index to the
WalHashLoc.aPgno array to make it easy to prove that there
is never OOB read or write.

FossilOrigin-Name: 9d56df17b4ab4940f7bc24488a9df118f6172fcfbf3e5cb95bdcbd2db2a07911
2026-04-04 14:43:37 +00:00
stephan d4b74b9fac Add some comments to the OPFS async proxy about potential future experimentation. No code changes.
FossilOrigin-Name: 9c14ee74305a5db3be95dbd9ae8d1db0abf39b323001be4e2f02b7226e6ca0d3
2026-04-04 08:07:25 +00:00
drh 7ff8b558e8 Enhance testrunner.tcl so that a PATTERN argument that begins with "~" is
an "anti-pattern".  Only run tests that match one or more patterns if there
are any patterns *and* do not match any anti-pattern.

FossilOrigin-Name: c313d91bb67b56be2db46194c3baa5a72b469595de3b2abe249612838dc175e4
2026-04-03 19:48:01 +00:00
stephan bb6d2a5f07 configure script: replace two 'file normalize' calls with file-normalize (a tcl/jimsh compatibility issue) to fix --with-linenoise. Problem reported in [forum:ce688d13793bd78f|forum post ce688d13793bd78f].
FossilOrigin-Name: 2be1c5a3e47f1276b9f0a4771f2d5fb0bc1ccb907c855caa04d757b4145533f5
2026-04-03 13:54:48 +00:00
drh 217c590688 Fix Tcl9 compatibility issues in test_session.c.
FossilOrigin-Name: 1387b5819085146cafb0e8740410faaa48bfb5aefc78ff763aaa8e85744d48b3
2026-04-03 11:48:00 +00:00
drh fc19b2ca8a Minor patch to test/json/json-speed-check.sh. That script is not maintained,
but this fix at least gets it working for now.

FossilOrigin-Name: 9d92e371ca375776d251fe446f17a437823cc96e48a5c45f42cb0768d0a47f65
2026-04-02 16:21:47 +00:00
drh 939930db1e Improvements to the syntax hints in the continuation prompt of the CLI
FossilOrigin-Name: 5c544f169680804c9652b8f9fc843a4bac052706be6bac205baf13a8c83fc840
2026-04-02 11:43:04 +00:00
dan 62f3150204 Fix a potential 4-byte overread in the sessions module when processing a corrupt changeset.
FossilOrigin-Name: c1c7e024c34da8eb0258ce552f3f81921280ccf0f1fea59374f381c0c7b43b74
2026-04-01 17:43:22 +00:00
drh 34e139d3a3 Always use sqlite3_malloc64() in extensions, where possible.
FossilOrigin-Name: 6194f3b5314ef98b5d73060450de8e3497272494b47e6f96992453418894ded1
2026-04-01 16:56:48 +00:00
dan 6e6598c8ff Fix a problem in the sessions module allowing a NULL pointer to be passed to memcpy().
FossilOrigin-Name: 91ead3c62dd7b1db3fdfd318e3c35a42fb33e8fa2e347b682eecbff2f4e8677b
2026-04-01 16:11:47 +00:00
drh e230de2cbf Minor improvements to the documentation on how to compile for Unix.
No changes to code.

FossilOrigin-Name: 7bc1d0c4572f126cfe68fa51fe992d2bd46b1e57c04721991bd5fad36dd795c5
2026-04-01 11:54:20 +00:00
stephan eb8edc0bac Doc cleanups in opfs-wl. No code changes.
FossilOrigin-Name: 009b576dcd5fccaaa52459dbfaa1b2a6fcf6d372e4b8d63553dfa88aab9a759c
2026-04-01 11:39:13 +00:00
drh d6226a9c27 Add appropriate headers to ext/session/sqlite3session.h so that the
documentation generator will pick up the API documentation for the
new one-at-a-time changegroup APIs.

FossilOrigin-Name: da514f10b7804fd0affaf0fd4b8089012288ba99c165ef4ab78ab28edd331211
2026-03-31 18:49:23 +00:00
dan d9f047bd15 Add an API to the sessions module to add changes one at a time to an sqlite3_changegroup object.
FossilOrigin-Name: cf1122ea6409bcbd341b67ae45147abb8d5cd491ae95491c801d0621181da40b
2026-03-31 10:59:13 +00:00
dan 5e4fb95edf Update this branch with changes from trunk.
FossilOrigin-Name: 716e62e3d1d6ff96f6e4906175818439103e9534e89bec4a86776265a04954b9
2026-03-31 10:52:00 +00:00
drh 60b829e0db Turn an incorrect assert() into a testcase(). Fix over-length code lines
in the sqlite.h.in source file.  Fix the documentation on OOM conditions
in the sqlite3_value_text() family of APIs.

FossilOrigin-Name: 934582706109d2ebda26952c7c95f7a5095fa47ec837570a66c991866f7d08cf
2026-03-31 10:32:23 +00:00
stephan f92d107242 Move some build docs around for clarity. Move the TARGET_DEBUG flags from the end of T.cc to the beginning so that -Ox flags can be passed to make for specific binaries without having to reconfigure.
FossilOrigin-Name: 240294653ceb202b847699e9691140db4fe623a03d86fa3cf7495f8831576331
2026-03-30 15:44:20 +00:00
drh b060cecb2e Remove an unused variable in sqlite3Reindex(). Minor enhancements to the
header comment on sqlite3AtoF().

FossilOrigin-Name: fbba900728d444f6a0b428197ebb41fe039b235e18caa2243c9f8f04fce42595
2026-03-30 10:00:48 +00:00
drh 9660a4dec0 Enhance the printf() formatter to write floating point conversions directly
into the output buffer, rather than staging into an intermediate buffer.

FossilOrigin-Name: ccb6b6c4ac21742dbfc435cf3a2a0dc887075b3e0877aea7ed8eace08b7b5571
2026-03-29 23:37:16 +00:00
drh 0cb576f306 Fix harmless compiler warnings about unused variable assignments.
FossilOrigin-Name: afe7e9fd1c476c7cdcefab0adf0191a8dc3283811f72a685fff3eb6539b72dcc
2026-03-29 22:41:12 +00:00
drh 6d27844bbe Merge trunk performance enhancements and fixes into the direct-printf branch.
FossilOrigin-Name: 9fa9cd11f8f5f7591168870c6e41121221b58a4a3094e708e3fa5bab1502f190
2026-03-29 19:23:47 +00:00
drh 03f13d77a5 Avoid using unsigned 64-bit integer division on platforms that do not support
it in hardware.

FossilOrigin-Name: 2197677491dfc5ec87b57bbf807776875248a250f80ce9a5ce94ae385bb1d2bc
2026-03-29 19:06:36 +00:00
drh 445fbc61c8 The _umulh() intrinsic function is not available on 32-bit windows. So don't
use it there.

FossilOrigin-Name: e75f30c7e66e725a2f3f46c7d4d69a2ff925e2de9a86c3a6ec38897545b43a58
2026-03-29 10:32:25 +00:00
drh eb0cb3f53b In sqlite3_str_vappendf(), write floating-point renderings directly into
the output buffer, saving a memcpy().

FossilOrigin-Name: e4e040e7aaaf5bfccbf0414fee3d08c5fdc24e03d1118dce92d2dd16c614ce63
2026-03-28 20:24:47 +00:00
drh 5239e69fb1 Remove a harmless unused variable from the fp-speed-2.c benchmark.
FossilOrigin-Name: ff9008e7615d877e6cc852c60097777006b274971646d368eaa56b99a7acf6c7
2026-03-28 14:21:53 +00:00
drh 20d93e16d7 Enhancements to the fp-speed-N.c programs, suggested by Andreas Kupries.
FossilOrigin-Name: 7d81ff4c509d4039ef9e2f1066284ec560131422db0cbffa7e1826d71bb8f8e1
2026-03-28 14:17:53 +00:00
drh c409eaaf14 Reduce the compiled size of the quote() SQL function.
FossilOrigin-Name: 9ea980a35628f7d0741ab6c65840ab9dab8abb576c6c60109147336452f9637a
2026-03-28 13:59:34 +00:00
drh 2e01416762 Turn an sqlite3VMPrintf() into an sqlite3DbStrDup().
FossilOrigin-Name: 75e8703664ae94244284819d9021877a5fc33a268fb86f3e70de20875a766d80
2026-03-28 13:30:47 +00:00
drh ff8a0895d6 Fix up the floating-point speed tests so that they only need to be run once
to get a performance comparision.  Provide the fp-speed-test makefile target
to build and run them both.

FossilOrigin-Name: 09e0e78a8265c2e2bc36fef1fa88bd5bf414f9b776966c1c91a4ed4b7866331d
2026-03-27 20:18:06 +00:00
drh a2f78f665c Add a comment to test/fptest01.sql to remind us that failures in that
script might not be the fault of SQLite.

FossilOrigin-Name: 65efcb0a2ed49fa2fd747b5f034d976ed3cb4a01a185bcada70bf8a5208f3841
2026-03-27 19:25:25 +00:00
drh c4cedd7ffe New test cases for text&rarr;float conversions.
FossilOrigin-Name: bbf2d648376a965605d5c641a889ab7ef365bc53788d984c054468e9889deee6
2026-03-27 18:58:50 +00:00
drh 00c6eca32c Enable the use of intrinsic high-precision multiplies on Windows ARM.
Make the SQLITE_DISABLE_INTRINSIC option effective on high-precision
multiple subroutines, for testing purposes.

FossilOrigin-Name: efb6212de4ca998546329b06b43122f0fffa3759e4615ca3357ef9fa13606d44
2026-03-27 16:09:10 +00:00
drh be2242d2ee Change the print resolution the fp-speed-1.c test to 17 digits.
FossilOrigin-Name: c687b32a956315ddf4336df42deb4037c37d51b536b8a24c5cef4c5a0bc4c79b
2026-03-27 14:54:01 +00:00
drh 2dd3b4a646 Update fp-speed-1.c and fp-speed-2.c to include its own timers, so that it
works on platforms that lack the "time" command.

FossilOrigin-Name: 9b083070de2d782fe1db62652af8f3cd48abe16b55b974f3927b738e3d914887
2026-03-27 14:19:01 +00:00
drh 4570aeb7bc Add the fp-speed-2.c performance test program.
FossilOrigin-Name: b788256f1980531e7abb15c5fbcdd40ae166f091aea28f449c0407105ddf1aa4
2026-03-27 14:03:41 +00:00
drh 1283969f26 Add a comment showing reserved file-control numbers to sqlite3.h
FossilOrigin-Name: cd472d7c85f3fda54bba5166eae72b5f9b86861c4a1160583e8ee902ba992255
2026-03-27 11:46:11 +00:00
stephan 772ea2f01c Add SQLITE_STRICT_SUBTYPE to PRAGMA compile_options, an omission reported in [forum:3906a71526|forum post 3906a71526].
FossilOrigin-Name: c5af6a10245b6b847d30002806c1577b020c36ab27f7b1cf202ade136aa4779c
2026-03-26 19:11:57 +00:00
drh d4af925e34 Enhance the return value from sqlite3AtoF() so that it reports if the input
includes more than 19.25 significant digits.

FossilOrigin-Name: 1721c8da769816ca16104cd636299d84f682fc004938a50056b76b269e49e915
2026-03-26 18:19:47 +00:00
drh 61d3bc8ddc Revamp the return code from sqlite3AtoF() for additional information and
for small speed improvement and size reduction.

FossilOrigin-Name: f10a431eade20ecd4c4d501fc534e2dae6ab2fe67302ea7bb3cd6eba127848fc
2026-03-26 16:33:03 +00:00
drh f9a3b78561 Improvements to the sqlite3AtoF() interface. Add a test-control for
direct testing of sqlite3AtoF().

FossilOrigin-Name: 97ee48b6ef65fb55633196282c9e75b3b0a3b81ba9755f63493a38e3f1a5610c
2026-03-26 14:19:34 +00:00
drh f855727e45 Back out the sqlite3_atof() API, for now.
FossilOrigin-Name: 7568d264be3988df195401158d8d07105b8e9e018eccf98ac948219bee9388ac
2026-03-26 12:09:37 +00:00
drh 3d58f022a8 Fix an off-by-one error that cause a loop to (harmlessly) run more times
than necessary.  Performance optimization, not a bug fix.

FossilOrigin-Name: 58f4e058f1cbb798b8a48208c6310fd10ca9cd1fc7c550f3ed283cf38ae45c2f
2026-03-25 21:23:23 +00:00
drh 7e9eaf3c1f Performance optimization when zero-padding in printf().
FossilOrigin-Name: dbd81abdc6633124e72999321db6fc8640851fa5eb063e6317a4c3e57b48dbaa
2026-03-25 21:05:18 +00:00
drh 0944b3efad Small size reduction and performance increase in sqlite3Atoi64().
FossilOrigin-Name: c818165fd709b813ab07788662bf69205ece2dcea41346609b3439950f900057
2026-03-25 19:36:16 +00:00
drh f3f194c385 Signification optimizations to layout of text for floating point
conversions in sqlite3_str_vappendf().

FossilOrigin-Name: 6a74df6d6ecfda8e0ff72ca0f4167190e989973ad124412892f7d36f1666ccfc
2026-03-25 17:59:22 +00:00
dan 183a73c352 Handle the case where the compile-time default page-size is greater than 8192 bytes.
FossilOrigin-Name: 3aea251f238277c68d7a80a4fa643bb0f80b274cef77ef32c4eb833cfaf46740
2026-03-25 11:19:38 +00:00
drh 53197b7940 Prevent overly long JSON paths from using too much stack space.
FossilOrigin-Name: 82a0794814bbc095235f8158a4129a5d83f6af1b0c27cb56449ea32feb44faf5
2026-03-24 19:26:05 +00:00
drh f1f1784f4b Limit JSONB recursion depth in the json_patch() function.
FossilOrigin-Name: f8659b700c0088abe19ce65fec032c1005a1f750566488f4578256d41558770c
2026-03-24 12:39:05 +00:00
drh 814f592cf0 Improved error messages for JSONB nested too deep.
FossilOrigin-Name: 82036fafa175e798fd32b3dc4ad043fc2bbe2bb2af17781f12dcb4d23a233865
2026-03-24 11:54:55 +00:00
stephan 9b805c6248 Remove a stale reference to the long-removed SQLITE_MUTEX_APPDEF, as pointed out in [forum:348453389b|forum post 348453389b].
FossilOrigin-Name: cb8e55b59113d0102c50db0a43b1b59d531cdcb12a7cce4c4c9a428c7c6e1adf
2026-03-24 11:33:22 +00:00
drh 3c2ccd2903 Minor simplification to JSON path error reporting.
FossilOrigin-Name: 1cd30c4827e382861cf12af48579eedc9685b9612dedb6a2844f20355b910e7e
2026-03-24 11:25:44 +00:00
drh 7bf4d708dc Recognize artifical JSONB blobs with deep recursion as being ill-formed.
FossilOrigin-Name: adac4ed1f13a9a1c4a34c8f59438eac68867981748629ca3957055ad9f940299
2026-03-24 00:31:28 +00:00
drh 5239e821e8 Move datatype and structure definitions up near the top in the CLI source code,
to facilitate future changes.  No changes to the actual logic (yet).

FossilOrigin-Name: 6b3d84d34d1a84eb8ddff08cd85d9dff6e71099e7a4b2c19db8774d942d3a040
2026-03-23 21:03:34 +00:00
stephan a217a4af09 Require a button click to start the OPFS concurrency tester, rather than simply launching all N workers immediately on page load.
FossilOrigin-Name: 3342d6786e07d3d8dd4b1f2291edea9f8354d384ff21242cc513c218ce6f1630
2026-03-23 13:17:13 +00:00
drh 3e3c31ff0e Use sqlite3_atof() instead of atof() in the CLI. Dogfooding.
FossilOrigin-Name: 276c350313a1ac2ebc70c1e8e50ed4baecd4be4d4c93ba04cf5e0078da18700e
2026-03-23 13:00:56 +00:00
drh dc32016ee0 Move the definition of the new sqlite3_atof() function in sqlite3.h so
that it is adjacent to sqlite3_mprintf().

FossilOrigin-Name: 1553a60506fa29b5f00535ae0f7aeb8cc94ebe84015386b3248fd8491108fc60
2026-03-23 12:25:52 +00:00
drh 5700f8c471 Add the sqlite3_atof() interface.
FossilOrigin-Name: 52f76c59f27152dd62069bd833e2409d57d0cd36ccaa568b2ec4ec823e98cb44
2026-03-23 10:58:29 +00:00
drh 80b88b2482 Proposed new API routine: sqlite3_atof().
FossilOrigin-Name: db370f0f628895279a1c1db79ba7428cb4e31b56cafc191859c2f1a5a924435b
2026-03-22 20:52:23 +00:00
drh 8e7f122c7d Performance enhancements and improved documentation for sqlite3AtoF().
FossilOrigin-Name: 62f011509600ab8cda28888ebd32e5faa4e865702755bc32dee7a12bf2f4425d
2026-03-22 18:26:43 +00:00
drh dfd31e158c Additional performance improvements in sqlite3AtoF(). Also update the
header comments.

FossilOrigin-Name: 8c3a1b450d6d5778004b9fb0e92b4f3f90d3e06ff87276370d01a45b7d607d23
2026-03-22 17:50:48 +00:00
drh cc19c1dafd Further simplification and performance improvement
FossilOrigin-Name: 6c3dc2430adef061b458b6d9159628bb8debfd4d63876d5d5e7493afb799d97f
2026-03-22 02:51:18 +00:00
drh 99571bf3c3 Performance improvements in the floating-point number parser.
FossilOrigin-Name: aea648f3668219a2539160eb68c77ddd06aa8eac235c1326fe7b1547288b11ee
2026-03-22 02:26:38 +00:00
drh 3c1f727603 Because version 3.52.0 was withdrawn, that means QRF has never been
officially released.  Hence the new nMultiInsert field of the spec
can be moved out of the extensions area and into the main part of the
spec, and the version number can drop back from 2 to 1.

FossilOrigin-Name: cf19982241afb17e3db4148b8257f6737141935a291c340ab085c42ed946af1a
2026-03-21 19:49:38 +00:00
drh d9e70f2b90 Try to fix harmless compiler warnings from legacy C compilers in the CLI.
FossilOrigin-Name: 8e1d0c4eac303cd0834449f4792605c0ed983db1f360af42300f0048dadbbef8
2026-03-21 13:21:41 +00:00
drh 4c78799bb0 Add support for REINDEX EXPRESSIONS
FossilOrigin-Name: d56954146ce5eccd63b65242abe2e6556dbceda39a58eab39f5884884afea337
2026-03-21 13:05:54 +00:00
drh 958b6a52e5 Undo "indices"&rarr;"indexes" changes in comments, to avoid diff clutter.
Fix a couple of unreachable branches.

FossilOrigin-Name: 0042ff9afd00eca0a837e9bbe57540ff2810fcd58b4f7e3f4e3b83aad5699757
2026-03-21 12:55:57 +00:00
drh f62cff6a9e Fix harmless compiler warnings in the csv.c.
FossilOrigin-Name: 6ac701f89e2ac8dfd18d041eb8c36a0c2b9fedc5618d3a95be794aecce5c59cf
2026-03-20 20:35:21 +00:00
drh f163bfba4e If the argument to REINDEX is EXPRESSIONS (with no schema prefix) then it
updates both expression indexes, and any indexes named "expressions" or
all indexes of any tables name "expressions".

FossilOrigin-Name: 72650dc152279a6da1937f377b1e16b79f4cd664841e12222dc5459838408d22
2026-03-20 19:30:58 +00:00
drh b0a4b69b95 If there are not collating sequences, tables, or indexes named "EXPRESSIONS"
then the "REINDEX EXPRESSIONS" command rebuilds all expression indexes.

FossilOrigin-Name: df5c5aa26758e0dc00a9ccba29eac83071176d257e121207e0a13c54833b18c0
2026-03-20 14:37:39 +00:00
dan bd580270a5 Ensure that collation sequences on non-PK columns of a WITHOUT ROWID table are used correctly when they are part of a row value comparison. Fix for forum post [forum:7a308e933d | 7a308e933d].
FossilOrigin-Name: 078b3162d0d3d3035f4d3ad88664066d99c218a731ac481b9f1172529e26e4eb
2026-03-20 11:35:15 +00:00
drh de4ef2dc70 Ensure that sqlite3RCStr values returned by json_group_array() and
json_group_object() are zero-terminated.

FossilOrigin-Name: 88a931ea2ae734478928c2a6021b00b0f2be490328260630e176cf3cc7111472
2026-03-19 23:49:29 +00:00
dan 0cb7603d4c Update fts5 scan costs to take into account that a prefix query combined with a rowid equality constraint is still quite expensive.
FossilOrigin-Name: 539769b63e4044018be2993894b1962df6a6ae58636682b7fb7a2dd5aaf4075c
2026-03-19 17:56:10 +00:00
drh 28cfb1e4a7 Restructure some internal subroutine signatures for improved
performance of affinity type conversions.

FossilOrigin-Name: 2bc6ce87b39c6ae324c3641c5af60e000df7d7c6d5fd2dd1a318c94cbb4aef84
2026-03-19 17:08:08 +00:00
drh 915a55444b Use compiler intrinsics to improve the performance of
sqlite3Multiply160().

FossilOrigin-Name: 3c64f31392328f51e205fde52f19cf70c193e90897ccb7e93c685bad4f342cac
2026-03-19 13:40:40 +00:00
dan 58012b85b0 Do not assume that a recursive CTE emits rows in ORDER BY order. Fix for forum post [forum:deb1eadf4d677bd5 | deb1eadf4d677bd5].
FossilOrigin-Name: cadb6cdd32c3c9abd7e063f25acd39dddc9ff764a16019ffd5aa11063175326f
2026-03-19 10:51:40 +00:00
dan a2d80200b1 Reverse the if() condition added by this branch.
FossilOrigin-Name: a9a0dd521c7c24b0c8b22abf2a131028f4dc9cd233678dc1f658da81a4a70e4b
2026-03-19 10:39:24 +00:00
drh 08eb5e9e51 Continue enforcing the legacy declaration-before-statement C-language rule,
since some downstream still uses it.

FossilOrigin-Name: 5c237f1f863a32cf229010d2024d0d1e76a07a4d8b9492b26503b959f1c32485
2026-03-18 22:31:56 +00:00
drh b425ebdd4f Add logic to silently and transparently deal with stale expression index
values when deleting or update a table row, instead of reporting a corrupt
database.  Enhance PRAGMA integrity_check to identify non-serious
stale expression index entries as such, rather than proclaiming that the
indexes is broken.

FossilOrigin-Name: 0ed040128b7ebb5be438b1841607ed9c525b271cac81021bc356cf573d1cd516
2026-03-18 20:17:48 +00:00
drh ac53ce155a Minor optimization to error message generation in integrity_check.
FossilOrigin-Name: e0fa7c500052af9d36cb2d232131ef93361403187f4a60f53279b102c7a95860
2026-03-18 18:14:14 +00:00
drh 5a6772eaa5 Comment improvements. Ensure that tests in shellB.test that require
virtual tables do not run when compiling without virtual table support.

FossilOrigin-Name: a270c6cc0eea8a8a2cf1ce30d724b2f12b11a1c343cd8520bd7843f4e62878f8
2026-03-18 17:16:18 +00:00
drh acc213b42f Improve the integrity-check error message when floating point index values
are off by one or two ULPs.  Change the name of the eiib1.test test module
to expridx1.test.

FossilOrigin-Name: 4e996c183ea8d270b4448b471d4d032e13cef89f537674599d1e7c367cc2d0f8
2026-03-18 15:51:15 +00:00
dan 345bc91673 Do not assume that a recursive CTE emits rows in ORDER BY order. Forum [forum:deb1eadf4d677bd5 | deb1eadf4d677bd5].
FossilOrigin-Name: 971aa34b3fd86ba30fe170886d9f83c17159b1638c4bd4fb6cdef79b1c9a88e2
2026-03-18 15:40:26 +00:00
drh 1539575e05 Take care not to overread the record header when decoding the record
in vdbeIsMatchingIndexKey().

FossilOrigin-Name: 3a275b5848767b61011b9d1d3d1a62328a80906386375d1b1e13fd92b6983e05
2026-03-18 14:47:20 +00:00
dan f0648f6924 Pad the allocation in vdbeIsMatchingKey() a little to avoid undefined behaviour if the record is corrupt and getVarint32() reads past the end of it.
FossilOrigin-Name: 9b0671a4f58098948d530f5e238b483a0e9f1309021aff0d6b5ea90e6c8f4e7b
2026-03-18 14:01:21 +00:00
drh 15a3b2d4e1 Adjust the fix at [f7389cdb129d3386] so that integrity_check output still
appears prior to the SQLITE_CORRUPT return.

FossilOrigin-Name: efd9a7a6c862f778da9cd74e38f674e5d1094aa1c566ea3e68553e83f59502d3
2026-03-18 13:49:06 +00:00
drh 765ff2189a Simplification to the logic that decides whether or not an index
field matches when floating point values are close but not exact.

FossilOrigin-Name: 3897017c0e871c676d44786a6f11205fd4b7a947d9d1359109037a123eda6b9b
2026-03-18 12:36:01 +00:00
drh 3ca448dee5 Fix harmless signed/unsigned compiler warnings.
FossilOrigin-Name: aa211fa1d49b6734913e957f9e4b9825709a1493d275f7dfaf9123dc8c7232dc
2026-03-18 11:15:57 +00:00
dan 3f2d7d4aaa Fix some cases where integrity-check would fail to identify real values in indexed expressions that are with 2 ULPs of each other.
FossilOrigin-Name: 40c5966f7b784f181365c81fc559aee9463c374ee56677cf6e0aecaed39d2b28
2026-03-18 11:06:10 +00:00
drh 00989bcd9f Fix harmless "unused variable" compiler warning.
FossilOrigin-Name: 3380eb1ea71d6bf8325dbe49f4bac7623b3b6193f3b36dedd9411188cfc80b89
2026-03-18 11:04:15 +00:00
dan 362b9cecdb Modify integrity-check so that it is only tolerant of very small distortions of real values in indexed expression fields.
FossilOrigin-Name: 82e6de835bde306778425d18ab1a15ae80fdf01af7f577ead89c09f9d53b5b2f
2026-03-17 21:17:42 +00:00
drh f4e6483cda Improved error handling in OP_IFindKey and in vdbeIsMatchingIndexKey().
FossilOrigin-Name: f7389cdb129d3386b7dfb8acacf84816cf10864c6800a9bd9a61c6364b850a31
2026-03-17 18:55:24 +00:00
dan ae2820ab28 When integrity-check finds a missing index entry, search a small range (currently 10) of entries around the missing key for an entry that matches all non-virtual and non-expression fields.
FossilOrigin-Name: 978cedcbd33165dadc7dffc118bde359eff6751ec9842230880cb827d9f7845f
2026-03-17 17:05:45 +00:00
drh bdbad43f33 Do not run index healing on an invalid cursor.
FossilOrigin-Name: eb6403f02c113f58030c0b4143d91b6327ee21dcb324d3f235c2bf6bf3d6577c
2026-03-17 13:13:02 +00:00
drh d6965b1dab Merge recent trunk enhancements into the idxdelete-tolerance branch
FossilOrigin-Name: 9d84fdb7819a9850919e2c1977811bcf514b3baad29eb8cc9fc78451d500c8b6
2026-03-17 12:16:47 +00:00
drh ccf2babd42 Fix an assertion fault that could occur in RTree when given a corrupt
database.

FossilOrigin-Name: ed29fe973e6cbf291eff6fc582aeb34556ea4f8df105ec61b361e4cdda017e62
2026-03-17 12:07:49 +00:00
dan 2953e950c8 Fix display of P4_INDEX values in EXPLAIN output.
FossilOrigin-Name: e717017f0213441da2ef8a9e1f1e88ebfdefa26fc4773711968417c0bd6ebe5f
2026-03-17 11:26:57 +00:00
dan 8736da94bc Fix compiler warning an inefficiency introduced by previous commit.
FossilOrigin-Name: 03058d73d3a88ab30e874b4231cc5b263b874a577f8bf5189a452d7376e25a47
2026-03-17 11:22:51 +00:00
drh b302c4d39c Typo fix in sqlite3Multiply128(): The datatype should be *unsigned*.
FossilOrigin-Name: b459f6ff63325f71d4056dad2ebb536e0d414c973f3c6e167e8f67e94e6f0e2d
2026-03-17 11:19:16 +00:00
dan 022f2f96bc Change the sqlite3VdbeFindDeleteKey() routine so that all index fields that are not expressions or virtual columns must match the table for the delete to succeed.
FossilOrigin-Name: eccd9fcfa7e34ddcdeb671544c6afac7aa0d4665c5e1df7c8e53c41387ed0386
2026-03-17 11:17:54 +00:00
drh 5a73386511 Fix a harmless compiler warning.
FossilOrigin-Name: aa23d6cc69471eacb3fb0d789c34169e047e4a09a50beb430eb8e8e63b5bce78
2026-03-17 10:19:11 +00:00
drh 1c1f7c259e Merge trunk enhancements into the idxdelete-tolerance branch
FossilOrigin-Name: 5f5ab3eb3618b6a2799355df50bfdf94121161f7cadba6253963036d9f284f08
2026-03-17 09:53:02 +00:00
drh cf93c51790 Enhance text&rarr;float conversions for exact rounding in all cases.
FossilOrigin-Name: 704ddfd0df57c2b137af88264df20a540e3f8f114a58ae5e31b40ab8259bb63e
2026-03-17 09:49:07 +00:00
drh b50ce08591 Include the float-point table generator utility in the tools directory.
FossilOrigin-Name: 4ab10b251d870af8297b9e505452393f6000f83784c822ff128e7aec06f8c72f
2026-03-17 09:45:47 +00:00
drh e9018e5ff5 Reorder bounds checking in sqlite3Fp10Convert2()
FossilOrigin-Name: 23ad656edb3a63e7e6602770e1f2c4a5ef1f3d41565e7f13408b5305619dfa3d
2026-03-17 09:18:36 +00:00
dan 4cc023bd01 Remove a couple of unused variables.
FossilOrigin-Name: f66cb3dc275d3f31e57576466e697a6c7c5179144babab08d75b624e9846ecc3
2026-03-16 19:14:07 +00:00
dan f6308e68ff Further tests for the code on this branch.
FossilOrigin-Name: f928a38091977268aa6a096104797158883ed89b9e026b4e4b98b9b5da967de1
2026-03-16 16:44:14 +00:00
dan 066a5bcdd7 If OP_IdxDelete cannot find an index entry to delete, first search 10 entries in either direction of where the entry should be in the index. If that fails, search the entire index for an entry with matching PK fields.
FossilOrigin-Name: 2cb9f4e4178549144acd82e317a1646e71c9281ac9fc4aa26bf129f1068ded45
2026-03-16 16:21:43 +00:00
dan b2006499c7 Fix a problem with the find-delete-key method on this branch.
FossilOrigin-Name: 6f49b5ecad5d924999d045a1ade93d95e731182be1781aefa5bc763b6202e9c3
2026-03-16 15:49:58 +00:00
drh bf057073c3 Rework the ".indexes" command of the CLI. (1) The PATTERN now matches
the name of the index itself, not the name of the table containing
the index, thus making the pattern actually useful.  (2)  System-generated
indexes (for UNIQUE constraints and similar) are omitted unless
the -a|-all or --sys options are added.  (3) The --expr option causes
only expression indexes to be shown.

FossilOrigin-Name: 13e2cad810bfd59a9e18eb38bda1241715b76756ffec7d617e9ce99b89f19284
2026-03-16 15:35:41 +00:00
dan d21413adcb Make OP_IdxDelete tolerant of small variations in index key values.
FossilOrigin-Name: c4b0081f08bd0458dbcf269b43a4051941eec8067393aa8e6810d4b8422ce44a
2026-03-16 15:16:13 +00:00
dan 061459bf76 Properly fix temp triggers created as part of FK processing to their schemas. Otherwise they may become confused by similarly named child tables in other attached databases. Fix for forum post [forum:636bd0180a | 636bd0180a].
FossilOrigin-Name: 80bc5bc07e221f837c28066f0a438f11c8ab6be4c8ba93615439eb1667967003
2026-03-16 11:14:26 +00:00
drh a6640846dd Improve accuracy of text&rarr;floating-point conversions by moving
from 64-bit to 96-bit approximations to powers of ten.

FossilOrigin-Name: a19c0785dcfb9fb74963c45b161b12ac8f4379e2b990f6c5de0d7b959c5be98d
2026-03-16 09:40:12 +00:00
stephan 7539d2f1ba Add a missing return for the invalid arguments error case in sqlite3_test_control_fault_install. No current scripts trigger this error.
FossilOrigin-Name: dc78d258745a1350685b37da56f0a2ac2e437b422415d634522dc61d340d06eb
2026-03-14 16:30:13 +00:00
drh 0f08d9586c Changes some legacy testing targets in the makefiles into aliases for
"devtest" and "releasetest"

FossilOrigin-Name: 4c54f22f7abbf5403e554fbf3dd70ddee97352d7de1f7fe19f540bdf681f4e75
2026-03-13 15:03:55 +00:00
stephan 6c446015bd Update the canonical JimTcl home page link (it was moved earlier today).
FossilOrigin-Name: 568573f872733bf32c2fde6a3a43100bdac17fc762e5c9a6d7a47b988fdcea4e
2026-03-12 08:33:14 +00:00
stephan 9e572064f3 Replace several comment-based switch-fall-through notices with attribute based ones, as suggested in [forum:b6ab8dc547|forum post b6ab8dc547].
FossilOrigin-Name: 2b0209a3bd3fb19af424386dcd13ff49a0c86edfd5d283fd5e5c42c266872100
2026-03-11 15:17:14 +00:00
drh 169f68ed88 Improved defenses against mischief.
FossilOrigin-Name: 8bdc0d485e3ad0c7a1e818da66f106951d496b05cbe61d12c2c448f2f24b6d5d
2026-03-11 14:43:29 +00:00
drh c739d13217 Fix harmless compiler warnings.
FossilOrigin-Name: d7b4a4a3d3d6296a012cc14fc2d95fe810b5bdb625209a2d28bf2c7a026749bf
2026-03-10 22:43:39 +00:00
drh 3bd23b0d78 Fix the behavior dot-commands that appear as command line arguments to the
CLI so that their effect persists into subsequent commands on the command
line.  This fix also improves error messages caused by command line
arguments. 
[forum:/forumpost/2026-03-10T19:26:06z|Forum post 2026-03-10T19:26:06z].

FossilOrigin-Name: ff084ae341eab5c4ce9403defee03adc448c05f77648a954f0942a38f640080b
2026-03-10 21:01:59 +00:00
drh abc82c49c2 Revamp the QRF insert-mode optimization of [659ff6ab55802507]. The
control value is now nMultiInsert.  Multiple rows are added to each INSERT
statement until the number of bytes in that statement exceeds the
nMultiInsert value.  The CLI uses a default value of 3000, which provides
a good balance between speed and prepare-statement size.  The output
from ".dump" now loads nearly 2x faster in some cases.

FossilOrigin-Name: 55b0ce9f93d68b17a18423f0f751b778573127743a2bac67abfea074ac32d41a
2026-03-10 18:13:13 +00:00
drh bd10a18f00 Bug fix to the ".dump" command in the CLI: Temporarily disable character
limit to QRF so as not to truncate values in the generated output.

FossilOrigin-Name: f6787e4b50af50663d8fa00ebe0694440354a7ad0509837a6b249e090e6cffca
2026-03-10 15:43:57 +00:00
drh efa8633fd8 Enhance QRF with the mxTuple field, which if greater than 1 causes the
QRF_STYLE_Insert style to group as many as mxTuple adjacent rows into
a single INSERT statement.  The field is accessible using the -mxtuple
option in the TCL interface, and the --mxtuple option in ".mode".  The
output of the ".dump" and ".fullschema" commands responds to the current
--mxtuple setting.

FossilOrigin-Name: 659ff6ab5580250707908af003ecd093bd5313f03f21f0efd000a7aff6638b3c
2026-03-10 14:02:03 +00:00
drh 140cbff0d2 Remove an obsolete pragraph from the header comment on the fileio.c extension.
FossilOrigin-Name: 17613b72f34162ce22864621c519e883930c9f51a0a86afbf30ce664f95d7be1
2026-03-09 14:04:34 +00:00
drh e795890d7e In QRF, fix line-wrap indentation for "line" mode when using a
non-standard column separator.

FossilOrigin-Name: 00c96cca3de709e40207feb9c10a94e38e7857c9bc01938849c6c5daee7148c7
2026-03-09 13:53:58 +00:00
dan 5ed6e4ccd1 Fix a problem with RIGHT JOIN and expressions on indexes. [forum:e3dba5426a | Forum post e3dba5426a].
FossilOrigin-Name: f27d578edac06eb28739f23351ab1cf07531bc7b32f4077e4dc9c8166f551d95
2026-03-09 11:49:51 +00:00
drh 016a0ebedc Fix the completion.c TVF so that the xNext method reports errors it encounters
while running queries.

FossilOrigin-Name: eebcdcceef8a436e5fb1397cad6eb5bcf0722060fe1cd6acb26cdf1e86f07293
2026-03-08 19:31:40 +00:00
drh 456c7ea715 In the decimal.c extension, set a default MAX_DIGITS to 100 million.
Do not allow integer overflow of the N parameter to the internal
decimal_round() function.

FossilOrigin-Name: d0e23423d1bdd0482db4b74ef0fde2fbc2bbad02a7b92ba45a27ca57f4740e16
2026-03-08 18:50:35 +00:00
stephan 5236bad923 Consolidate the opfs and opfs-wl tester1 tests using the preprocessor.
FossilOrigin-Name: 77846c8c7aa4625729a5e113c12e7d16efc88c1306c01ba36f47240aac450b0f
2026-03-08 17:07:01 +00:00
stephan 46a692c08b Upgrade ext/wasm/c-pp-lite.c to its newer sibling because we've reached the older one's limits. This renames c-pp-lite.c to libcmpp.c to maintain both the SCM- and code lineage but that may end up looking a bit weird because the diff between the two is vast.
FossilOrigin-Name: 2e2339bd9e4293bad04ece7673a3048b99c2143cf9573ade2ec082d95744b981
2026-03-08 16:03:08 +00:00
stephan 02cbc96d09 JS doc updates.
FossilOrigin-Name: 699295f84ef2c4da363f13126abde6af07697d0959896cd868b14513d4278964
2026-03-08 12:42:34 +00:00
drh 1eb335e313 Increase the version number on trunk to 3.53.0
FossilOrigin-Name: 0152b445ff0cdf560fc028938e1d43a56685d7c046fad84fa90166cd01d71279
2026-03-08 10:51:47 +00:00
stephan 976b50620a Merge opfs-wl into trunk, not so much for the "opfs-wl" VFS, which is stil tentative (working fine but with little perceived benefit), but for the "opfs" VFS cleanups which necessarily happened around it.
FossilOrigin-Name: bcaa876c6dafee0995d239f59b6ce7810b6f5faa219b9c392966211ae3dec17a
2026-03-08 08:32:22 +00:00
stephan 303fad1f91 Update the tester1 SEE tests to account for opfs-wl.
FossilOrigin-Name: 616d32c8380ef47c5a7c2eb765e7b6fbec9500d4e16c837f4ee11d71c239a55f
2026-03-08 08:09:09 +00:00
stephan 03b0f8fc9c Refactor tester1 OPFS test to support both the "opfs" and "opfs-wl" VFSes.
FossilOrigin-Name: 17ac8d7bdfaf96510abea8c11019045c1703b7040655d9c4c8d7001636260b50
2026-03-08 07:58:02 +00:00
stephan 84ad6f302f Add parens around an expression in the CLI shell to account for operator precedence, as reported in [forum:856ff7a2f1|forum post 856ff7a2f1].
FossilOrigin-Name: da3ad170aebf57f2202e56673ac149bc51077d126ab5928f1db16492e403d5b9
2026-03-08 07:02:46 +00:00
stephan 9358070cb3 Expose sqlite3_bind_zeroblob() to JS/WASM.
FossilOrigin-Name: 0c5d4fe0bd322b4c8dbd0800001317a21cd511b00244de74b4db3fd051153879
2026-03-08 05:53:47 +00:00
drh eac7cd634d Use the UINT64_C() macro rather than the LLU suffix on integer literals
for portability to older Microsoft compilers.
[forum:/forumpost/0a9ffaff6fcdedb3|Forum thread 0a9ffaff6fcdedb3].

FossilOrigin-Name: 27be26566fdb4d01c44dc111f1c18c835797de0990d4fcc876e91edc216e9e93
2026-03-07 22:37:28 +00:00
drh 13a494fddd Give the fuzzcheck test program access to all the same extensions that
dbsqlfuzz has access to.

FossilOrigin-Name: d9c23b49e355233bbfcdc8305dcae21640e66a0bbf1daed0dd3f9d132c1ef69f
2026-03-07 21:07:18 +00:00
drh 85ee7e15e3 Fix harmless compiler warnings on Windows.
FossilOrigin-Name: 358d78da75033d4d1fcb27b5f95c940dcc306cdf34ef999262da901e71f2b306
2026-03-07 17:50:32 +00:00
stephan ac26170191 Minor typo fixes from [forum:8fc8bc34291d6f45|forum post 8fc8bc34291d6f45].
FossilOrigin-Name: c8fb88c19ed91dc5e205f719aedb895f7ceb62b113f61ec94cc6e435051da15c
2026-03-07 15:15:37 +00:00
drh cde22e8806 An attempt to get the CLI build to work with mingw32.
[forum:/forumpost/086cb1ef66|Forum post 086cb1ef66].

FossilOrigin-Name: d95b9e7c1746b9cbd067aa65806b1f74d0dfe77ab6084cb3da9ef2242cac9134
2026-03-07 12:00:56 +00:00
drh b4f257f5e0 Fix another memory leak following OOM in the decimal extension.
FossilOrigin-Name: 414f6dbc09c2a3cf04ccdfd8f11eecb7ef781facff979ae4236a452913001391
2026-03-07 11:23:11 +00:00
stephan 237fce8205 Extend the JS pre-bootstrapping configuration to include an option to disable inclusion of any given extension VFS (not the default VFSes, like memdb). The primary motivation for this is to give people who don't use OPFS to a way to keep the OPFS VFSes from loading their proxy workers, which are expensive.
FossilOrigin-Name: 9a07eb7a941479510891d1444aacbeb440efaad3e9a13f186833618d8b60a8da
2026-03-07 06:10:29 +00:00
stephan 78649bb421 Fix the mangling of the opfs async proxy script's URI caused by both OPFS VFSes modifying it to accound for sqlite3.dir. Add a link to speedtest1 with opfw-wl to index.html.
FossilOrigin-Name: c1cb61f473a11a325ef421ba8edfb20257203688565f7db62309044be183af5f
2026-03-07 04:19:08 +00:00
stephan 7d10030d75 Cleanups and docs in the opfs vfs and its concurrency tester. Experimentally add sqlite3.capi.sqlite3_js_retry_busy(), which runs a callback repeatedly until it _stops_ returning (or throwing) an SQLITE_BUSY error.
FossilOrigin-Name: 45c02ed21635f7ef45214ab5ec6230b6b8bd89e35ef5889db318523e1c679fea
2026-03-07 03:32:17 +00:00
stephan f20c4e650d Elide more of the 64-bit was stuff from the default build target.
FossilOrigin-Name: 3b74ad9081daee560bf9b400e69a75abcc62dae7c5f55dcf46de84daae50ed9f
2026-03-07 03:29:26 +00:00
drh a0851f1483 Enhancements and fixes to some of the extensions used in the CLI so that
they can be fuzzed using dbsqlfuzz.

FossilOrigin-Name: d800ea06d231957cf571327d9eaf81564d5439aeee099987101050a41f9676c0
2026-03-07 02:42:27 +00:00
stephan 9be458e611 Cleanups and docs in the new opfs code structure.
FossilOrigin-Name: 3b470c4c7a1fcc710e6b9eae32134c7f6c3f6008b24c7351257f66f5e8f70311
2026-03-07 02:19:23 +00:00
stephan 57d0fe254a For backwards compatibility, ensure that the "opfs" VFS does not specifically require Atomics.waitAsync() (a new requirement of "opfs-wl"), but make use of it if available. Only apply jitter to the concurrency test runs at random intervals.
FossilOrigin-Name: f2175f526c00cfe562e8f332eb197b5ef2c3d6be1fff2aab1566c2c533a293ac
2026-03-07 01:01:13 +00:00
stephan ac63b524ac Add some jitter and duration info to the opfs concurrency tester. Ensure that Atomics.waitAsync() is available for opfs-wl. Further testing has shown that Web opfs-wl is consistently fairer about doling out contested locks but it's dog slow compared to the original VFS under moderate concurrency. In single-connection use they're effectively on par.
FossilOrigin-Name: a9aecc987512d60f2663973f43c769cf086fc14149edfbcb18c0aec9f5aa3dbf
2026-03-06 23:50:44 +00:00
stephan 2251f0c4cc Get "opfs" and "opfs-wl" properly split. Speedtest1 and the concurrency tester are happy with opfs-wl but it is not yet plugged in to tester1.
FossilOrigin-Name: 12dcd5425967b6306f3e3178babeac130962edb78e6298d545a429a1a20457cc
2026-03-06 22:21:06 +00:00
stephan a85d09f1a4 Minor cleanups and docs. Teach the OPFS concurrency tester to deal with SQLITE_BUSY instead of failing.
FossilOrigin-Name: 247ffed141f66a6a5a396a3e002995a9f00c70333271199200530066e77956c4
2026-03-06 19:33:25 +00:00
stephan a98f278f58 This one reliably runs 5 workers. Checking in before subsequent cleanups and debug output removal break it.
FossilOrigin-Name: ba81d95febc5fd0f9bbb2685fef5b1b10f9991751f2bdfafba80c15877af1cef
2026-03-06 17:10:28 +00:00
stephan c008b8fe3e Correct an internal doc falsehood.
FossilOrigin-Name: 53aa080e357d7a2ffeab68a3584fda43d51ecef3dc8a1d46dd32392ae4f9740c
2026-03-06 16:15:32 +00:00
stephan 7b9cd03c0a This Web Lock impl can reliably run a single OPFS connection but rather unreliably 'loses' workers with higher counts, presumably due to deadlock or deadly embrace (how _all_ of them can deadlock at once is unclear, but clearly a bug).
FossilOrigin-Name: d4e8583e2e80665adfe4e814adb6c219936af1dcac4105795045cb1a7b1e4864
2026-03-06 16:04:21 +00:00
stephan 544ef18bbd Remove an extraneous OPFS metrics increment.
FossilOrigin-Name: bf3548a37712e848c7a9cadfdc1669a2be572ea0a0c28d84c157ab30f8c30c44
2026-03-06 11:49:36 +00:00
stephan 891f5a176b A slight simplification/optimization in the OPFS proxy's waitLoop().
FossilOrigin-Name: 521bb140b7ed237c118ac9094732d06907229a6ff385502e850c679bd623fd58
2026-03-06 09:11:47 +00:00
stephan 831e233202 Reimplement the OPFS async proxy's wait-forever loop to be more async-friendly for upcoming changes.
FossilOrigin-Name: fd775772fbb50b04c8c37977b90a708784eefed403e3668196c9d95559d3a5e1
2026-03-06 09:06:24 +00:00
stephan 14b5eadefe Strip the opfs-wl "back to formula", removing the current false starts so that this can be tried again without tripping over any cruft. The current impl is subject, with no obvious way out of it, to starvation in the async proxy.
FossilOrigin-Name: d022f1f5e74dedae044801330eb099022498f359f408e69b3574885641b312f5
2026-03-05 11:51:27 +00:00
stephan cef3ff74cd The opfs-wl lock hang has been traced to starvation between the WebLock and the tight wait-on-VFS-calls Atomics.wait() loop. This can reportedly be resolved with another level of indirection in which the WebLock takes over the wait-on-VFS-calls part until it's unlocked, returning to the global loop when it's done. That exceeds this morning's ambitions but is next to try out.
FossilOrigin-Name: 113bd910e12fea17f9f4a0a3baf706f15627c08cfa6b47a960a83eee761ef4dd
2026-03-05 06:30:57 +00:00
stephan 671a6f83f4 Add some debugging output to opfs and track down the breakage to the initial WebLock request, which is never reaching its callback. Still broken, but this is progress.
FossilOrigin-Name: 62fc8b35aeec75f5648b3daa24162c638999d447aa874bdfcbac1431c5c97b6f
2026-03-04 21:16:36 +00:00
stephan 232446b532 Get opfs-wl plugged in to the concurrency tester. Somewhat ironically, all competing workers fail with locking errors while worker 1 is busy running off the rails somewhere. Stashing for closer investigation later.
FossilOrigin-Name: 3b27310aa29ea84f459974981a600301abac5c705029a289d3872ecacf231da3
2026-03-04 20:33:21 +00:00
stephan b85067c568 Consolidate the last 200 lines of common OPFS VFS code. "opfs" still works, "opfs-wl" registers fine but is still otherwise untested.
FossilOrigin-Name: 5978ee4902e4223fed6b95bd2d8f489bb300af8b762650e7113d1f3e97519d88
2026-03-04 19:21:09 +00:00
stephan 080da5f56d Factor out about 300 lines of common OPFS VFS bootstrapping code.
FossilOrigin-Name: 57adecbab71795b62b1c2e4570ff504f35681e81dd8c94f78ad8e05ef39d36fd
2026-03-04 17:54:02 +00:00
stephan 691494a93b Consolidate the OPFS VFS's metrics-tracking code.
FossilOrigin-Name: b71c79ef9672c77a72a976ffcd7cbebfaf0ff314dff97b274f7d092de6a7773f
2026-03-04 16:30:51 +00:00
stephan 6ff9fcfad2 Baby steps in consolidating common OPFS VFS code.
FossilOrigin-Name: b0dd23299e97ff975f213cb3a8b051f4d7b785b29def82e01f53427fdf77ecb6
2026-03-04 14:33:33 +00:00
stephan 96daad10fa Consolidate much of the OPFS utility code into a new file for use by two of the OPFS VFSes.
FossilOrigin-Name: db19a6e9663c3a44996178cb8c35dc4ccd60f48cb4b81b6c214411a56c57def7
2026-03-04 11:37:39 +00:00
stephan 6d6bf30735 A potential fix for the probable breakage of bundler-friendly builds in the previous check-in. Pending review from someone who uses those tools.
FossilOrigin-Name: 8ea85776116521526d684f221d67e288126e62931d4a0ea7fc7f164cd2d5b2ec
2026-03-04 00:48:03 +00:00
stephan 9ac95d9ce1 opfs-wl is now loading and registering but it's still untested.
FossilOrigin-Name: 9a471f7491a371052bf1785098ba966dd0d03503e7d8b9fbcd65f07b038e5021
2026-03-04 00:37:55 +00:00
stephan a2d3a54f80 An initial attempt to plugging opfs-wl into the build but its initial handshake with the async half collides with the opfs VFS's handshake, causing bootstrapping to fail miserably. We'll need to either devise a handshake which can differentiate between the two instances or we'll need to preprocess sqlite3-opfs-async-proxy into two copies. Move the (now) three copies of some common code shared by the opfs pieces into a preprocessor #include.
FossilOrigin-Name: 1e0b72631aecb0bb72f4089116da221e6c4abf962db589de08132cd52c2be0e2
2026-03-03 23:43:40 +00:00
stephan 0b7b802d83 Add a missing reset of the lock handshake SharedArrayBuffer slot.
FossilOrigin-Name: 5910ed7ac843aa1fdb103ddcfaf6270d12cb39199205fc0b9f721fbf7fa2f851
2026-03-03 21:46:44 +00:00
stephan e2309eebd7 Implementations of WebLock-based opfs::xLock() and xUnlock(). Still completely untested and not yet integrated into the build.
FossilOrigin-Name: 3343e3aabe465f4ab91dd148dfc5a60346e9afb560c10d1f92aeae98763ec3ce
2026-03-03 21:07:46 +00:00
stephan d016fad5a8 Merge trunk into the opfs-wl branch.
FossilOrigin-Name: 81bc4b3b6abc19f98d1f3b1065c4b39a42620a0d7abebe98605dca62dd2d6f9a
2026-03-03 18:34:59 +00:00
stephan 5c4692b6a9 Add JS tests for sqlite3_bind_zeroblob().
FossilOrigin-Name: 0473eeb3cefa1d7882375e3f89d239d570649349c5a0a8ddd90b0a336a9bb493
2026-03-03 14:13:34 +00:00
stephan a2fef84b19 Expose sqlite3_bind_zeroblob() to JS/WASM, per request in [forum:e7acf225f9|forum post e7acf225f9]. This is currently missing tests and is not planned for merge until the 3.53 dev cycle starts.
FossilOrigin-Name: b0c2ef6046b53b6133fed6a890d2ab5e47eeebd7b0b32849b5f69ae54a03014c
2026-03-03 01:48:18 +00:00
stephan 8c6bf948b7 An initial copy/paste stub for experimenting with using WebLocks for a new copy of the OPFS vfs. This is not yet functional, or even loading, but needs stashing to avoid potential loss.
FossilOrigin-Name: 372f18ae909bafd7167b70051935832e3107ede72aaeccbf5c042db7ba791912
2026-02-27 03:11:40 +00:00
dan c1975b6a6f Improve some of the documentation comments for the new code on this branch.
FossilOrigin-Name: f352485db45a1280f91ec76f661b6dd50bb1d564b74bdff474c92e928860a47d
2026-01-14 17:02:22 +00:00
dan de88171c4c Merge latest trunk changes into this branch.
FossilOrigin-Name: fae9f376b74ae688dbdb5c0838a38427258d3d14c29c5346a3549e56db79961a
2026-01-14 16:01:28 +00:00
dan 613cf76c2f Add tests for edge cases in the new code on this branch.
FossilOrigin-Name: cd115f0f4437bf254058e40d70ba4e82e87227d2752695aa18f8431c3abc5c0b
2026-01-14 15:27:26 +00:00
dan c289cf57a7 Allow the APIs on this branch to be used to create patchsets as well as changesets.
FossilOrigin-Name: 8699fe5b24c8aeb5e552aa7f4995f2b50dd33d1febd23ec1c07c8fc72497da72
2026-01-13 19:59:47 +00:00
dan 817c509365 Add an API to the sessions module to add changes one at a time to an sqlite3_changegroup object.
FossilOrigin-Name: 27150a8c22dc5331efa9e97637eae3741682bc14ae993f0b7672ccc63c37f1f9
2026-01-12 16:39:27 +00:00
265 changed files with 34994 additions and 11183 deletions
+125
View File
@@ -0,0 +1,125 @@
# AGENTS.md
Guidance for AI coding agents working in this repository.
## Project nature
SQLite is a self-contained, serverless SQL database engine written in C. The
source is **public domain** — no copyright or license header should ever be
added to any file. The blessing comment that appears at the top of each source
file is intentional and should be preserved unchanged.
SQLite does not accept pull requests without prior agreement and/or
accompanying legal paperwork that places the pull request in the public domain.
However, the human SQLite developers will review a concise and well-written
pull request as a proof-of-concept prior to reimplementing the changes
themselves.
SQLite does not accept agentic code. However the project
will accept agentic bug reports that include a reproducible test case.
Patches or pull requests demonstrating a possible fix, for documentation
purposes, are welcomed.
SQLite uses the [Fossil](https://fossil-scm.org/) for version control,
not Git. The canonical repository is at <https://sqlite.org/src>.
## Build
The configure script uses [autosetup](https://msteveb.github.io/autosetup/),
not GNU Autoconf.
```bash
apt install gcc make tcl-dev # prerequisites (Debian/Ubuntu)
./configure --dev # debug build
make sqlite3 # CLI shell
make sqlite3d # Debugging variant of the CLI shell
make sqlite3.c # amalgamation (single-file distribution form)
make testfixture # test runner binary (requires tcl-dev)
make tclextension-install # install TCL extension before running tests
```
## Testing
Tests are TCL scripts run through the `testfixture` enhanced interpreter.
```bash
# From the build directory:
./testfixture test/main.test # single test file
test/testrunner.tcl # quick suite
test/testrunner.tcl full # full suite
test/testrunner.tcl fts5% # pattern match
# Check for failures:
grep '!' testrunner.log
```
`make devtest` is the fastest way to run a representative subset. Always run
at least `devtest` after any change to `src/`.
## Architecture
SQL text → **tokenizer** (`tokenize.c`) → **parser** (`parse.y` / Lemon) →
**code generator** (`build.c`, `select.c`, `insert.c`, `update.c`, `delete.c`,
`expr.c`) → **optimizer** (`where*.c`) → **VDBE** (`vdbe.c`) → **B-Tree**
(`btree.c`) → **Pager** (`pager.c`) → **WAL** (`wal.c`) → **VFS**
(`os_unix.c`, `os_win.c`).
The master internal header is `src/sqliteInt.h`. Major subsystems have private
headers: `vdbeInt.h`, `btreeInt.h`, `whereInt.h`. The public API is defined in
`src/sqlite.h.in` (template) which generates `sqlite3.h`.
## Do not edit generated files
These files are produced by scripts and must not be edited by hand:
| File | Regenerate with |
|---|---|
| `sqlite3.h` | `tool/mksqlite3h.tcl` |
| `parse.c`, `parse.h` | build lemon (`tool/lemon.c`) then run on `src/parse.y` |
| `opcodes.h` | `tool/mkopcodeh.tcl` (reads `src/vdbe.c`) |
| `opcodes.c` | `tool/mkopcodec.tcl` (reads `opcodes.h`) |
| `keywordhash.h` | `tool/mkkeywordhash.c` |
| `pragma.h` | `tool/mkpragmatab.tcl` |
| `sqlite3.c` | `tool/mksqlite3c.tcl` (the amalgamation) |
Editing rules:
- To add a PRAGMA: edit `tool/mkpragmatab.tcl`, then regenerate `pragma.h`.
- To add a VDBE opcode: add the `case OP_Xxx:` handler in `src/vdbe.c`; the
opcode number and name are extracted automatically by `mkopcodeh.tcl`.
- To change the SQL grammar: edit `src/parse.y`, not `parse.c`.
## Coding conventions
- C89/C99 compatible C only. No C++, no STL, no exceptions, no VLAs.
- All memory allocation goes through `sqlite3Malloc` / `sqlite3_malloc64`
(never raw `malloc`). The `sqlite3MallocZero` variant zero-initializes.
- Integer widths: use `i64` (`sqlite3_int64`) for 64-bit values, `u32`/`u64`
for unsigned. Avoid bare `long` or `int` for values that could exceed 2G.
- Error propagation: functions return `SQLITE_OK` (0) on success and a
`SQLITE_*` error code on failure. Many routines also set `db->mallocFailed`
on OOM, allowing deferred error checking.
- Assert liberally for invariants that must hold in correct code; use
`ALWAYS(x)` / `NEVER(x)` for conditions that are logically always
true/false but that the compiler cannot prove.
## Extensions (`ext/`)
Extensions are compiled separately from the core and are not part of the
amalgamation by default (except where explicitly included). Major subsystems:
- `ext/fts5/` — Full-Text Search 5 (current)
- `ext/rtree/` — R-Tree spatial indexing
- `ext/session/` — Changesets and sessions
- `ext/recover/` — Database file recovery
- `ext/misc/` — Single-file utility extensions (many included in the CLI)
- `ext/qrf/` — Query Result Formatter utility library
## Useful references
- Architecture: <https://sqlite.org/arch.html>
- File format: <https://sqlite.org/fileformat2.html>
- VDBE opcodes: <https://sqlite.org/opcode.html>
- Query planner: <https://sqlite.org/optoverview.html>
- Lemon parser generator: <https://sqlite.org/doc/trunk/doc/lemon.html>
- Compile-time options: <https://sqlite.org/compile.html>
+11 -3
View File
@@ -131,9 +131,15 @@ libsqlite3.DLL.install-rules = @SQLITE_DLL_INSTALL_RULES@
CFLAGS.fuzzcheck-asan.fsanitize = @CFLAGS_ASAN_FSANITIZE@
#
# Intended to either be empty or be set to -g -DSQLITE_DEBUG=1.
# TARGET_DEBUG is intended to either be empty or be set to -g
# -DSQLITE_DEBUG=1, plus any other flags relevant for debug-only
# builds. These get added near the front of $(T.cc) so that they can
# be overridden by CFLAGS passed directly to make. Historically (prior
# to 2026-03-30) these were at/near the end of the flags but that made
# it impossible to pass custom -O* flags to specific binaries without
# reconfiguring.
#
T.cc.TARGET_DEBUG = @TARGET_DEBUG@
T.cc += @TARGET_DEBUG@
#
# $(JIMSH) and $(CFLAGS.jimsh) are documented in main.mk. $(JIMSH)
@@ -164,7 +170,9 @@ OPT_FEATURE_FLAGS = @OPT_FEATURE_FLAGS@ $(OPTIONS)
PACKAGE_VERSION = @PACKAGE_VERSION@
#
# Filename extensions for binaries and libraries
# Filename extensions for binaries and libraries. B.* are for the
# being-built-on platform and T.* are for the build's target platform.
# i.e. B.* is for build-time tooling and T.* is for deliverables.
#
B.exe = @BUILD_EXEEXT@
T.exe = @TARGET_EXEEXT@
+40 -35
View File
@@ -1719,6 +1719,7 @@ FUZZERSHELL_COMPILE_OPTS =
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_DECIMAL_MAX_DIGIT=1000
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_BYTECODE_VTAB
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_CARRAY
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_DBPAGE_VTAB
@@ -1765,7 +1766,18 @@ 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\base64.c
FUZZCHECK_SRC = $(FUZZCHECK_SRC) $(TOP)\ext\misc\base85.c
FUZZCHECK_SRC = $(FUZZCHECK_SRC) $(TOP)\ext\misc\completion.c
FUZZCHECK_SRC = $(FUZZCHECK_SRC) $(TOP)\ext\misc\decimal.c
FUZZCHECK_SRC = $(FUZZCHECK_SRC) $(TOP)\ext\misc\diskused.c
FUZZCHECK_SRC = $(FUZZCHECK_SRC) $(TOP)\ext\misc\ieee754.c
FUZZCHECK_SRC = $(FUZZCHECK_SRC) $(TOP)\ext\misc\randomjson.c
FUZZCHECK_SRC = $(FUZZCHECK_SRC) $(TOP)\ext\misc\regexp.c
FUZZCHECK_SRC = $(FUZZCHECK_SRC) $(TOP)\ext\misc\series.c
FUZZCHECK_SRC = $(FUZZCHECK_SRC) $(TOP)\ext\misc\shathree.c
FUZZCHECK_SRC = $(FUZZCHECK_SRC) $(TOP)\ext\misc\sha1.c
FUZZCHECK_SRC = $(FUZZCHECK_SRC) $(TOP)\ext\misc\stmtrand.c
OSSSHELL_SRC = $(TOP)\test\ossshell.c $(TOP)\test\ossfuzz.c
DBFUZZ_COMPILE_OPTS = -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION
@@ -1885,9 +1897,6 @@ RSYNC_OPT = \
sqlite3_rsync.exe: $(RSYNC_SRC) $(LIBRESOBJS)
$(LTLINK) $(RSYNC_OPT) $(NO_WARN) $(RSYNC_SRC) /link $(LDFLAGS) $(LTLINKOPTS) $(LIBRESOBJS)
scrub.exe: $(TOP)\ext\misc\scrub.c $(SQLITE3C) $(SQLITE3H)
$(LTLINK) $(NO_WARN) -DSCRUB_STANDALONE=1 $(TOP)\ext\misc\scrub.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
srcck1.exe: $(TOP)\tool\srcck1.c
$(BCC) $(NO_WARN) -Fe$@ $(TOP)\tool\srcck1.c
@@ -2336,6 +2345,7 @@ SHELL_DEP = \
$(TOP)\ext\misc\base85.c \
$(TOP)\ext\misc\completion.c \
$(TOP)\ext\misc\decimal.c \
$(TOP)\ext\misc\diskused.c \
$(TOP)\ext\misc\fileio.c \
$(TOP)\ext\misc\ieee754.c \
$(TOP)\ext\misc\memtrace.c \
@@ -2540,43 +2550,19 @@ coretestprogs: testfixture.exe sqlite3.exe
testprogs: $(TESTPROGS) srcck1.exe fuzzcheck.exe sessionfuzz.exe
fulltest: alltest fuzztest
alltest: $(TESTPROGS)
@set PATH=$(LIBTCLPATH);$(PATH)
.\testfixture.exe $(TOP)\test\all.test $(TESTOPTS)
soaktest: $(TESTPROGS)
@set PATH=$(LIBTCLPATH);$(PATH)
.\testfixture.exe $(TOP)\test\all.test -soak=1 $(TESTOPTS)
fulltestonly: $(TESTPROGS) fuzztest
@set PATH=$(LIBTCLPATH);$(PATH)
.\testfixture.exe $(TOP)\test\full.test
queryplantest: testfixture.exe shell
@set PATH=$(LIBTCLPATH);$(PATH)
.\testfixture.exe $(TOP)\test\permutations.test queryplanner $(TESTOPTS)
fuzztest: fuzzcheck.exe
.\fuzzcheck.exe $(FUZZDATA)
# Legacy testing target for third-party integrators. The SQLite
# developers seldom use this target themselves. Instead
# they use "nmake /f Makefile.msc devtest" which runs tests on
# a standard set of options
#
test: $(TESTPROGS) sourcetest fuzztest tcltest
# Minimal testing that runs in less than 3 minutes (on a fast machine)
#
quicktest: testfixture.exe sourcetest
@set PATH=$(LIBTCLPATH);$(PATH)
.\testfixture.exe $(TOP)\test\extraquick.test $(TESTOPTS)
# This is the common case. Run many tests that do not take too long,
# including fuzzcheck, sqlite3_analyzer, and sqldiff tests.
# Legacy testing targets, no longer used by the developers and
# now aliased to one of the commonly used testing targets.
#
quicktest: devtest
test: devtest
fulltest: releasetest
alltest: releasetest
soaktest: releasetest
fulltestonly: releasetest
# The veryquick.test TCL tests.
#
@@ -2640,6 +2626,12 @@ smoketest: $(TESTPROGS)
@set PATH=$(LIBTCLPATH);$(PATH)
.\testfixture.exe $(TOP)\test\main.test $(TESTOPTS)
# Measure the performance of floating-point conversions.
#
fp-speed-test: fp-speed-1.exe fp-speed-2.exe
fp-speed-1 1000000
fp-speed-2 1000000
shelltest:
$(TCLSH_CMD) $(TOP)\test\testrunner.tcl release shell
@@ -2732,6 +2724,14 @@ speedtest1.exe: $(TOP)\test\speedtest1.c $(SQLITE3C) $(SQLITE3H)
$(LTLINK) $(NO_WARN) $(ST_COMPILE_OPTS) -DSQLITE_OMIT_LOAD_EXTENSION \
$(TOP)\test\speedtest1.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
fp-speed-1.exe: $(TOP)\test\fp-speed-1.c $(SQLITE3C) $(SQLITE3H)
$(LTLINK) $(NO_WARN) $(ST_COMPILE_OPTS) -DSQLITE_OMIT_LOAD_EXTENSION \
$(TOP)\test\fp-speed-1.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
fp-speed-2.exe: $(TOP)\test\fp-speed-2.c $(SQLITE3C) $(SQLITE3H)
$(LTLINK) $(NO_WARN) $(ST_COMPILE_OPTS) -DSQLITE_OMIT_LOAD_EXTENSION \
$(TOP)\test\fp-speed-2.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
kvtest.exe: $(TOP)\test\kvtest.c $(SQLITE3C) $(SQLITE3H)
$(LTLINK) $(NO_WARN) $(KV_COMPILE_OPTS) \
$(TOP)\test\kvtest.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
@@ -2740,6 +2740,9 @@ rbu.exe: $(TOP)\ext\rbu\rbu.c $(TOP)\ext\rbu\sqlite3rbu.c $(SQLITE3C) $(SQLITE3H
$(LTLINK) $(NO_WARN) -DSQLITE_ENABLE_RBU \
$(TOP)\ext\rbu\rbu.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
$(AUXTEST).exe: $(TOP)\test\c\$(AUXTEST).c
$(LTLINK) $(NO_WARN) $(TOP)\test\c\$(AUXTEST).c sqlite3.lo /link $(LDFLAGS) $(LTLINKOPTS)
THREADTEST3_SRC = \
$(TOP)\test\threadtest3.c \
$(TOP)\test\tt3_checkpoint.c \
@@ -2921,6 +2924,7 @@ clean:
del /Q LogEst.exe fts3view.exe rollback-test.exe showdb.exe dbdump.exe 2>NUL
del /Q changeset.exe 2>NUL
del /Q showjournal.exe showstat4.exe showwal.exe speedtest1.exe 2>NUL
del /Q fp-speed-1.exe fp-speed-2.exe 2>NUL
del /Q mptester.exe wordcount.exe rbu.exe srcck1.exe 2>NUL
del /Q sqlite3.c sqlite3-*.c sqlite3.h 2>NUL
del /Q sqlite3rc.h 2>NUL
@@ -2935,4 +2939,5 @@ clean:
del /Q fts5.* fts5parse.* 2>NUL
del /q src-verify.exe 2>NUL
del /q jimsh.exe jimsh0.exe 2>NUL
-$(TCLSH_CMD) test/testrunner.tcl clean
# <</mark>>
+9 -6
View File
@@ -33,10 +33,11 @@ verify its integrity, there are hints on how to do that in the
## Contacting The SQLite Developers
The preferred way to ask questions or make comments about SQLite or to
report bugs against SQLite is to visit the
[SQLite Forum](https://sqlite.org/forum) at <https://sqlite.org/forum/>.
Anonymous postings are permitted.
The preferred way to ask questions or make comments about SQLite is to
visit the [SQLite Forum](https://sqlite.org/forum) at
<https://sqlite.org/forum/>. Anonymous postings are permitted. For
bug reports, please use the [SQLite bugs
forum](https://sqlite.org/bugs) at <https://sqlite.org/bugs>.
If you think you have found a bug that has security implications and
you do not want to report it on the public forum, you can send a private
@@ -80,8 +81,8 @@ Then run commands like this:
fossil open https://sqlite.org/src
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:
you can do fast, bandwidth-efficient updates to whatever versions of SQLite you
like. Some examples:
fossil update trunk ;# latest trunk check-in
fossil update release ;# latest official release
@@ -97,6 +98,8 @@ the build products. It is recommended, but not required, that the
build directory be separate from the source directory. Cd into the
build directory and then from the build directory run the configure
script found at the root of the source tree. Then run "make".
See the [compile-for-unix.md](doc/compile-for-unix.md) document for
more detail.
For example:
+1 -1
View File
@@ -1 +1 @@
3.52.1
3.54.0
+1 -1
View File
@@ -461,4 +461,4 @@ all other significant processing.
[sqlite-config.tcl]: /file/autosetup/sqlite-config.tcl
[Makefile.in]: /file/Makefile.in
[main.mk]: /file/main.mk
[JimTCL]: https://jim.tcl.tk
[JimTCL]: https://msteveb.github.io/jimtcl/
+1657 -972
View File
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -2028,7 +2028,7 @@ array set proj__Cache {}
# Returns a cache key for the given argument:
#
# integer: relative call stack levels to get the scope name of for
# use as a key. [proj-scope [expr {1 + $arg + addLevel}]] is
# use as a key. [proj-scope [expr {1 + $arg + $addLevel}]] is
# then used to generate the key. i.e. the default of 0 uses the
# calling scope's name as the key.
#
@@ -2226,7 +2226,7 @@ proc proj-coalesce {args} {
#
# Pragmas:
#
# Passing :PRAGMAS to this function may modify how it works. The
# The prototype list may contain :PRAGMAS to modify how it works. The
# following pragmas are supported (note the leading ":"):
#
# :all-flags indicates that the whole input list should be scanned,
+45 -24
View File
@@ -743,12 +743,11 @@ proc sqlite-setup-default-cflags {} {
# compiling binaries for the target system (CC a.k.a. $(T.cc)).
# Normally they're the same, but they will differ when
# cross-compiling.
#
# When cross-compiling we default to not using the -g flag, based on a
# /chat discussion prompted by
# https://sqlite.org/forum/forumpost/9a67df63eda9925c
set defaultCFlags {-O2}
if {!$::sqliteConfig(is-cross-compiling)} {
# When cross-compiling we default to not using the -g flag, based
# on a /chat discussion prompted by
# https://sqlite.org/forum/forumpost/9a67df63eda9925c
lappend defaultCFlags -g
}
define CFLAGS [proj-get-env CFLAGS $defaultCFlags]
@@ -1068,7 +1067,7 @@ proc sqlite-get-readline-dir-list {} {
}
*-haiku {
lappend dirs /boot/system/develop/headers
if {[opt-val with-readline-ldflags] in {auto ""}} {
if {![opt-bool editline] && [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 Haiku OS installations.
@@ -1095,16 +1094,30 @@ proc sqlite-get-readline-dir-list {} {
# - HAVE_LINENOISE to 0, 1, or 2
# - HAVE_EDITLINE to 0 or 1
#
# Only one of ^^^ those will be set to non-0.
# Those will be set as follows:
#
# HAVE_LINENOISE=0, HAVE_EDITLINE=0, HAVE_READLINE=0: no line editing
#
# HAVE_LINENOISE>0: 1=antirez flavor, 2=msteveb flavor
#
# HAVE_EDITLINE=0, HAVE_READLINE=1: use GNU readline
#
# HAVE_EDITLINE=1, HAVE_READLINE=1: use BSD editline header
# <readline/readline.h>.
#
# HAVE_EDITLINE=1, HAVE_READLINE=0: use BSD editline header
# <editline/readline.h>.
#
# Other defines it sets:
#
# - LDFLAGS_READLINE = linker flags or empty string
#
# - CFLAGS_READLINE = compilation flags for clients or empty string.
#
# Note that LDFLAGS_READLINE and CFLAGS_READLINE may refer to
# linenoise or editline, not necessarily libreadline. In some cases
# it will set HAVE_READLINE=1 when it's really using editline, for
# reasons described in this function's comments.
# Both LDFLAGS_READLINE and CFLAGS_READLINE may refer to linenoise or
# editline, not necessarily libreadline. In some cases it will set
# HAVE_READLINE=1 when it's really using editline, for reasons
# described in this function's comments.
#
# Returns a string describing which line-editing approach to use, or
# "none" if no option is available.
@@ -1142,14 +1155,14 @@ proc sqlite-check-line-editing {} {
# If none of --with-linenoise, --enable-readline, or --enable-editline
# are provided, but there exists a directory "linenoise" at $HOME or
# a sibling of the build or source directory, then try to use that linenoise
# direcctory.
# directory.
#
if {"" eq $dirLn
&& ![proj-opt-was-provided readline]
&& ![proj-opt-was-provided editline]
} {
set dirlist ../linenoise
catch {lappend dirlist [file normalize $::autosetup(srcdir)/../linenoise]}
catch {lappend dirlist [file-normalize $::autosetup(srcdir)/../linenoise]}
catch {lappend dirlist $::env(HOME)/linenoise}
foreach d $dirlist {
if {[file exists $d/linenoise.c] && [file exists $d/linenoise.h]} {
@@ -1195,7 +1208,7 @@ proc sqlite-check-line-editing {} {
define-append CFLAGS_JIMSH -DUSE_LINENOISE [get-define CFLAGS_READLINE]
user-notice "Adding linenoise support to jimsh."
} else {
msg-result "Using linenoise at [file normalize $dirLn]"
msg-result "Using linenoise at [file-normalize $dirLn]"
}
return "linenoise ($flavor)"
} elseif {[opt-bool editline]} {
@@ -1306,14 +1319,18 @@ proc sqlite-check-line-editing {} {
# If we found a library, configure the build to use it...
if {"" ne $rlLib} {
if {"editline" eq $editLibName && "HAVE_READLINE" eq $editLibDef} {
# Alert the user that, despite outward appearances, we won't be
# linking to the GPL'd libreadline. Presumably that distinction is
# significant for those using --editline.
proj-indented-notice {
NOTE: the local libedit uses <readline/readline.h> so we
will compile with -DHAVE_READLINE=1 but will link with
libedit.
if {"editline" eq $editLibName} {
# sqlite-add-shell-opt -DEL_WIDECHAR=1;
if {"HAVE_READLINE" eq $editLibDef} {
sqlite-add-shell-opt -DHAVE_EDITLINE=1
# Alert the user that, despite outward appearances, we won't be
# linking to the GPL'd libreadline. Presumably that distinction is
# significant for those using --editline.
proj-indented-notice {
NOTE: the local libedit uses <readline/readline.h> so we
will compile with -DHAVE_READLINE=1 but will link with
libedit.
}
}
}
set rlLib [join $rlLib]
@@ -1746,8 +1763,12 @@ proc sqlite-handle-env-quirks {} {
set autoDll 0; # true if --out-implib/--dll-basename should be implied
set host [get-define host]
switch -glob -- $host {
*apple* -
*darwin* { set instName darwin }
*-*-darwin* {
set instName darwin
# We don't look for *apple* because:
# https://sqlite.org/forum/forumpost/7b218c3c9f207646
# There's at least one Linux out there which matches *apple*.
}
default {
set x [sqlite-env-is-unix-on-windows $host]
if {"" ne $x} {
@@ -2043,7 +2064,7 @@ proc sqlite-check-tcl {} {
}
}
if {![file-isexec $with_tclsh]} {
proj-warn "Cannot find a usable tclsh (tried: $tryThese)
proj-warn "Cannot find a usable tclsh (tried: $tryThese)"
}
}
define TCLSH_CMD $with_tclsh
+28 -9
View File
@@ -37,18 +37,35 @@ guidance on building for Windows.
4. Download the SQLite source tree and unpack it. CD into the
toplevel directory of the source tree.
5. Run: `./configure --enable-all --with-tclsh=$HOME/local/bin/tclsh9.0`
5. *(Optional):* Download Antirez's "linenoise" command-line editing
library to provide command-line editing in the CLI. You can find
a suitable copy of the linenoise sources at
<https://sqlite.org/linenoise.tar.gz> or at various other locations
on the internet. If you put the linenoise source tree in
a directory named $HOME/linenoise or a directory "linenoise" which
is a sibling of the SQLite source tree, then the SQLite ./configure
script will automatically find and use that source code to provide
command-line editing in the CLI. If you would rather use the readline
or editline libraries or a precompiled linenoise library, there are
./configure options to accommodate that choice. The SQLite developers
typically use $HOME/linenoise since linenoise is small, has no
external dependencies, "just works", and the ./configure script
will pick it up and use it automatically. But you do what works
best for you.
<p>
You are not required to have any command-line editing support in
order to use SQLite. But command-line editing does make the
interactive experience more enjoyable.
6. Run: `./configure --enable-all --with-tclsh=$HOME/local/bin/tclsh9.0`
You do not need to use --with-tclsh if the tclsh you want to use is the
first one on your PATH or if you are building without TCL.
The SQLite developers typically add the
&ensp; `--with-linenoise=$HOME/linenoise` &ensp; option
to provide command-line editing. "$HOME/linenoise" is a directory
that contains [linenoise](https://github.com/antirez/linenoise) source
code files, `linenoise.c` and `linenoise.h`.
Lots of other options to ./configure are available.
Run `./configure --help` for further guidance.
6. Run the "`Makefile`" makefile with an appropriate target.
7. Run the "`Makefile`" makefile with an appropriate target.
Examples:
<ul>
<li> `make sqlite3.c`
@@ -73,5 +90,7 @@ guidance on building for Windows.
of SQLite.
7. For a debugging build of the CLI, where the ".treetrace" and ".wheretrace"
commands work, add the the --with-debug argument to configure.
8. For a debugging build of the CLI, use `./configure --dev`. A debugging
build contains lots of extra debugging code, so it is slow and a lot
bigger. You probably do not want to deploy a debugging build. But if
you are working on the code, a debugging build works much better.
+6 -1
View File
@@ -33,7 +33,7 @@
The testrunner.tcl program is a Tcl script used to run multiple SQLite
tests in parallel, thus reducing testing time on multi-core machines.
The testrunner.tcl supports running tests that based on `testfixture`,
`sqlite3`, and `fuzzcheck`.
`sqlite3`, `fuzzcheck`, and C programs found in test/c.
<a name="runtr"></a>
## 1.1 Running testrunner.tcl
@@ -59,11 +59,16 @@ up front.
The standard Makefiles for SQLite include targets that invoke
testrunner.tcl. So the following commands also run testrunner.tcl:
* `make test`
* `make devtest`
* `make releasetest`
* `make sdevtest`
* `make testrunner`
Since SQLite 3.53.0, there is a "<tt>make.bat</tt>" script in the root
of the source tree that causes the "make" command to work on Windows.
There is no need to do something different using "nmake" on Windows.
<a name="outputs"></a>
## 1.3 Outputs from testrunner.tcl
+36
View File
@@ -606,4 +606,40 @@ ifcapable fts5 {
}
}
#-------------------------------------------------------------------------
reset_db
set ci {CREATE INDEX i1 ON t1(a COLLATE "binary,sqlite_expert_rem(999,0)");}
do_execsql_test 8.0 {
BEGIN TRANSACTION;
CREATE TABLE t1(a TEXT, b TEXT);
INSERT INTO t1 VALUES('v0','d0');
INSERT INTO t1 VALUES('v1','d1');
INSERT INTO t1 VALUES('v2','d2');
INSERT INTO t1 VALUES('v3','d3');
INSERT INTO t1 VALUES('v4','d4');
INSERT INTO t1 VALUES('v5','d5');
INSERT INTO t1 VALUES('v6','d6');
INSERT INTO t1 VALUES('v7','d7');
INSERT INTO t1 VALUES('v8','d8');
INSERT INTO t1 VALUES('v9','d9');
CREATE INDEX i1 ON t1(a);
COMMIT;
PRAGMA writable_schema = ON;
UPDATE sqlite_schema SET sql = $ci WHERE name = 'i1';
}
db close
sqlite3 db test.db
do_test 8.1 {
set expert [sqlite3_expert_new db]
$expert sql { SELECT 1234 }
list [catch { $expert analyze } msg] $msg
} {1 {no such collation sequence: binary,sqlite_expert_rem(999,0)}}
$expert destroy
finish_test
+2 -2
View File
@@ -1501,7 +1501,7 @@ static int idxCreateVtabSchema(sqlite3expert *p, char **pzErrmsg){
/* The statement the vtab will pass to sqlite3_declare_vtab() */
zInner = idxAppendText(&rc, 0, "CREATE TABLE x(");
for(i=0; i<pTab->nCol; i++){
zInner = idxAppendText(&rc, zInner, "%s%Q COLLATE %s",
zInner = idxAppendText(&rc, zInner, "%s%Q COLLATE %Q",
(i==0 ? "" : ", "), pTab->aCol[i].zName, pTab->aCol[i].zColl
);
}
@@ -1701,7 +1701,7 @@ static int idxPopulateOneStat1(
return sqlite3_reset(pIndexXInfo);
}
zCols = idxAppendText(&rc, zCols,
"%sx.%Q IS sqlite_expert_rem(%d, x.%Q) COLLATE %s",
"%sx.%Q IS sqlite_expert_rem(%d, x.%Q) COLLATE %Q",
zComma, zName, nCol, zName, zColl
);
zOrder = idxAppendText(&rc, zOrder, "%s%d", zComma, ++nCol);
+18 -3
View File
@@ -302,6 +302,12 @@
SQLITE_EXTENSION_INIT1
#endif
/*
** Assume any b-tree layer with more levels than this is corrupt.
*/
#define FTS3_MAX_BTREE_HEIGHT 48
typedef struct Fts3HashWrapper Fts3HashWrapper;
struct Fts3HashWrapper {
Fts3Hash hash; /* Hash table */
@@ -2018,7 +2024,11 @@ static int fts3SelectLeaf(
assert( piLeaf || piLeaf2 );
fts3GetVarint32(zNode, &iHeight);
rc = fts3ScanInteriorNode(zTerm, nTerm, zNode, nNode, piLeaf, piLeaf2);
if( iHeight>FTS3_MAX_BTREE_HEIGHT ){
rc = FTS_CORRUPT_VTAB;
}else{
rc = fts3ScanInteriorNode(zTerm, nTerm, zNode, nNode, piLeaf, piLeaf2);
}
assert_fts3_nc( !piLeaf2 || !piLeaf || rc!=SQLITE_OK || (*piLeaf<=*piLeaf2) );
if( rc==SQLITE_OK && iHeight>1 ){
@@ -2063,8 +2073,13 @@ static void fts3PutDeltaVarint(
sqlite3_int64 iVal /* Write this value to the list */
){
assert_fts3_nc( iVal-*piPrev > 0 || (*piPrev==0 && iVal==0) );
*pp += sqlite3Fts3PutVarint(*pp, iVal-*piPrev);
*piPrev = iVal;
if( iVal-(*piPrev)>=0 ){
/* Refuse to write a negative delta integer. This only happens with a
** corrupt db (see the assert above) and can cause buffer overwrites
** in some cases. */
*pp += sqlite3Fts3PutVarint(*pp, iVal-*piPrev);
*piPrev = iVal;
}
}
/*
+10 -1
View File
@@ -203,7 +203,16 @@ typedef sqlite3_int64 i64; /* 8-byte signed integer */
#define LARGEST_INT64 (0xffffffff|(((i64)0x7fffffff)<<32))
#define SMALLEST_INT64 (((i64)-1) - LARGEST_INT64)
#define deliberate_fall_through
#if !defined(deliberate_fall_through)
# if defined(__has_attribute)
# if __has_attribute(fallthrough)
# define deliberate_fall_through __attribute__((fallthrough));
# endif
# endif
#endif
#if !defined(deliberate_fall_through)
# define deliberate_fall_through
#endif
/*
** Macros needed to provide flexible arrays in a portable way
+2 -2
View File
@@ -325,7 +325,7 @@ static int fts3auxNextMethod(sqlite3_vtab_cursor *pCursor){
pCsr->aStat[1].nDoc++;
}
eState = 2;
/* fall through */
/* no break */ deliberate_fall_through
case 2:
if( v==0 ){ /* 0x00. Next integer will be a docid. */
@@ -341,7 +341,7 @@ static int fts3auxNextMethod(sqlite3_vtab_cursor *pCursor){
/* State 3. The integer just read is a column number. */
default: assert( eState==3 );
iCol = (int)v;
if( iCol<1 ){
if( iCol<1 || iCol>(pFts3->nColumn+1) ){
rc = SQLITE_CORRUPT_VTAB;
break;
}
+1
View File
@@ -471,6 +471,7 @@ static int getNextNode(
assert( nKey==4 );
if( zInput[4]=='/' && zInput[5]>='0' && zInput[5]<='9' ){
nKey += 1+sqlite3Fts3ReadInt(&zInput[nKey+1], &nNear);
if( nNear>=1000000000 ) nNear = 1000000000;
}
}
+10 -11
View File
@@ -132,10 +132,9 @@ struct StrBuffer {
/*
** Allocate a two-slot MatchinfoBuffer object.
*/
static MatchinfoBuffer *fts3MIBufferNew(size_t nElem, const char *zMatchinfo){
static MatchinfoBuffer *fts3MIBufferNew(i64 nElem, const char *zMatchinfo){
MatchinfoBuffer *pRet;
sqlite3_int64 nByte = sizeof(u32) * (2*(sqlite3_int64)nElem + 1)
+ SZ_MATCHINFOBUFFER(1);
sqlite3_int64 nByte = sizeof(u32) * (2*(i64)nElem+1) + SZ_MATCHINFOBUFFER(1);
sqlite3_int64 nStr = strlen(zMatchinfo);
pRet = sqlite3Fts3MallocZero(nByte + nStr+1);
@@ -887,7 +886,7 @@ static int fts3ExprLHits(
if( p->flag==FTS3_MATCHINFO_LHITS ){
p->aMatchinfo[iStart + iCol] = (u32)nHit;
}else if( nHit ){
p->aMatchinfo[iStart + (iCol+1)/32] |= (1 << (iCol&0x1F));
p->aMatchinfo[iStart + iCol/32] |= (1U << (iCol&0x1F));
}
}
assert( *pIter==0x00 || *pIter==0x01 );
@@ -1006,8 +1005,8 @@ static int fts3MatchinfoCheck(
return SQLITE_ERROR;
}
static size_t fts3MatchinfoSize(MatchInfo *pInfo, char cArg){
size_t nVal; /* Number of integers output by cArg */
static i64 fts3MatchinfoSize(MatchInfo *pInfo, char cArg){
i64 nVal; /* Number of integers output by cArg */
switch( cArg ){
case FTS3_MATCHINFO_NDOC:
@@ -1023,16 +1022,16 @@ static size_t fts3MatchinfoSize(MatchInfo *pInfo, char cArg){
break;
case FTS3_MATCHINFO_LHITS:
nVal = (size_t)pInfo->nCol * pInfo->nPhrase;
nVal = (i64)pInfo->nCol * pInfo->nPhrase;
break;
case FTS3_MATCHINFO_LHITS_BM:
nVal = (size_t)pInfo->nPhrase * ((pInfo->nCol + 31) / 32);
nVal = (i64)pInfo->nPhrase * ((pInfo->nCol + 31) / 32);
break;
default:
assert( cArg==FTS3_MATCHINFO_HITS );
nVal = (size_t)pInfo->nCol * pInfo->nPhrase * 3;
nVal = (i64)pInfo->nCol * pInfo->nPhrase * 3;
break;
}
@@ -1314,7 +1313,7 @@ static int fts3MatchinfoValues(
case FTS3_MATCHINFO_LHITS_BM:
case FTS3_MATCHINFO_LHITS: {
size_t nZero = fts3MatchinfoSize(pInfo, zArg[i]) * sizeof(u32);
i64 nZero = fts3MatchinfoSize(pInfo, zArg[i]) * sizeof(u32);
memset(pInfo->aMatchinfo, 0, nZero);
rc = fts3ExprLHitGather(pCsr->pExpr, pInfo);
break;
@@ -1383,7 +1382,7 @@ static void fts3GetMatchinfo(
** initialize those elements that are constant for every row.
*/
if( pCsr->pMIBuffer==0 ){
size_t nMatchinfo = 0; /* Number of u32 elements in match-info */
i64 nMatchinfo = 0; /* Number of u32 elements in match-info */
int i; /* Used to iterate through zArg */
/* Determine the number of phrases in the query */
+4
View File
@@ -3129,6 +3129,10 @@ static void fts3ReadEndBlockField(
for(/* no-op */; zText[i]>='0' && zText[i]<='9'; i++){
iVal = iVal*10 + (zText[i] - '0');
}
/* This if() clause is just to avoid an integer overflow. The record is
** corrupt in this case. */
if( (i64)iVal==SMALLEST_INT64 ) iMul = 1;
*pnByte = ((i64)iVal * (i64)iMul);
}
}
+2 -2
View File
@@ -426,7 +426,7 @@ static void fts5SnippetFunction(
int rc = SQLITE_OK; /* Return code */
int iCol; /* 1st argument to snippet() */
const char *zEllips; /* 4th argument to snippet() */
int nToken; /* 5th argument to snippet() */
i64 nToken; /* 5th argument to snippet() */
int nInst = 0; /* Number of instance matches this row */
int i; /* Used to iterate through instances */
int nPhrase; /* Number of phrases in query */
@@ -451,7 +451,7 @@ static void fts5SnippetFunction(
ctx.zClose = fts5ValueToText(apVal[2]);
ctx.iRangeEnd = -1;
zEllips = fts5ValueToText(apVal[3]);
nToken = sqlite3_value_int(apVal[4]);
nToken = (int)(MIN( MAX(sqlite3_value_int64(apVal[4]), 0), 64));
iBestCol = (iCol>=0 ? iCol : 0);
nPhrase = pApi->xPhraseCount(pFts);
+2 -2
View File
@@ -807,7 +807,7 @@ static int fts5ExprNearIsMatch(int *pRc, Fts5ExprNearset *pNear){
i64 iPos = a[i].reader.iPos;
Fts5PoslistWriter *pWriter = &a[i].writer;
if( a[i].pOut->n==0 || iPos!=pWriter->iPrev ){
sqlite3Fts5PoslistWriterAppend(a[i].pOut, pWriter, iPos);
sqlite3Fts5PoslistSafeAppend(a[i].pOut, &pWriter->iPrev, iPos);
}
}
@@ -1758,10 +1758,10 @@ static int fts5ParseTokenize(
memset(pSyn, 0, (size_t)nByte);
pSyn->pTerm = ((char*)pSyn) + sizeof(Fts5ExprTerm) + sizeof(Fts5Buffer);
pSyn->nFullTerm = pSyn->nQueryTerm = nToken;
memcpy(pSyn->pTerm, pToken, nToken);
if( pCtx->pConfig->bTokendata ){
pSyn->nQueryTerm = (int)strlen(pSyn->pTerm);
}
memcpy(pSyn->pTerm, pToken, nToken);
pSyn->pSynonym = pPhrase->aTerm[pPhrase->nTerm-1].pSynonym;
pPhrase->aTerm[pPhrase->nTerm-1].pSynonym = pSyn;
}
+1 -1
View File
@@ -323,7 +323,7 @@ int sqlite3Fts5HashWrite(
** + 5 bytes for the new position offset (32-bit max).
*/
if( (p->nAlloc - p->nData) < (9 + 4 + 1 + 3 + 5) ){
sqlite3_int64 nNew = p->nAlloc * 2;
sqlite3_int64 nNew = (i64)p->nAlloc * 2;
Fts5HashEntry *pNew;
Fts5HashEntry **pp;
pNew = (Fts5HashEntry*)sqlite3_realloc64(p, nNew);
+33 -18
View File
@@ -922,7 +922,7 @@ static void fts5DataRelease(Fts5Data *pData){
static Fts5Data *fts5LeafRead(Fts5Index *p, i64 iRowid){
Fts5Data *pRet = fts5DataRead(p, iRowid);
if( pRet ){
if( pRet->nn<4 || pRet->szLeaf>pRet->nn ){
if( pRet->szLeaf<4 || pRet->szLeaf>pRet->nn ){
FTS5_CORRUPT_ROWID(p, iRowid);
fts5DataRelease(pRet);
pRet = 0;
@@ -1695,6 +1695,7 @@ static int fts5DlidxLvlPrev(Fts5DlidxLvl *pLvl){
pLvl->bEof = 1;
}else{
u8 *a = pLvl->pData->p;
int nn = pLvl->pData->nn;
pLvl->iOff = 0;
fts5DlidxLvlNext(pLvl);
@@ -1703,7 +1704,7 @@ static int fts5DlidxLvlPrev(Fts5DlidxLvl *pLvl){
int ii = pLvl->iOff;
u64 delta = 0;
while( a[ii]==0 ){
while( ii<nn && a[ii]==0 ){
nZero++;
ii++;
}
@@ -2122,7 +2123,7 @@ static void fts5SegIterReverseNewPage(Fts5Index *p, Fts5SegIter *pIter){
while( p->rc==SQLITE_OK && pIter->iLeafPgno>pIter->iTermLeafPgno ){
Fts5Data *pNew;
pIter->iLeafPgno--;
pNew = fts5DataRead(p, FTS5_SEGMENT_ROWID(
pNew = fts5LeafRead(p, FTS5_SEGMENT_ROWID(
pIter->pSeg->iSegid, pIter->iLeafPgno
));
if( pNew ){
@@ -2576,6 +2577,10 @@ static void fts5LeafSeek(
if( nKeep<nMatch ){
goto search_failed;
}
if( (iOff+nNew)>n ){
FTS5_CORRUPT_ITER(p, pIter);
return;
}
assert( nKeep>=nMatch );
if( nKeep==nMatch ){
@@ -3552,8 +3557,7 @@ static void fts5PoslistFilterCallback(
do {
while( i<nChunk && pChunk[i]!=0x01 ){
while( pChunk[i] & 0x80 ) i++;
i++;
fts5IndexSkipVarint(pChunk, i);
}
if( pCtx->eState ){
fts5BufferSafeAppendBlob(pCtx->pBuf, &pChunk[iStart], i-iStart);
@@ -3702,7 +3706,7 @@ static void fts5IndexExtractColset(
/* Advance pointer p until it points to pEnd or an 0x01 byte that is
** not part of a varint */
while( p<pEnd && *p!=0x01 ){
while( *p++ & 0x80 );
while( p<pEnd && (*p++ & 0x80) );
}
if( pColset->aiCol[i]==iCurrent ){
@@ -3799,8 +3803,11 @@ static void fts5IterSetOutputs_Col100(Fts5Iter *pIter, Fts5SegIter *pSeg){
assert( pIter->pIndex->pConfig->eDetail==FTS5_DETAIL_COLUMNS );
assert( pIter->pColset );
assert( pIter->poslist.nSpace>=pIter->pIndex->pConfig->nCol );
if( pSeg->iLeafOffset+pSeg->nPos>pSeg->pLeaf->szLeaf ){
if( pSeg->iLeafOffset+pSeg->nPos>pSeg->pLeaf->szLeaf
|| pSeg->nPos>pIter->pIndex->pConfig->nCol
){
fts5IterSetOutputs_Col(pIter, pSeg);
}else{
u8 *a = (u8*)&pSeg->pLeaf->p[pSeg->iLeafOffset];
@@ -5294,6 +5301,11 @@ static void fts5DoSecureDelete(
}else{
iStart = fts5GetU16(&aPg[0]);
}
if( iStart>nPg ){
FTS5_CORRUPT_IDX(p);
sqlite3_free(aIdx);
return;
}
iSOP = iStart + fts5GetVarint(&aPg[iStart], &iDelta);
assert_nc( iSOP<=pSeg->iLeafOffset );
@@ -7979,8 +7991,8 @@ static void fts5IndexTombstoneRebuild(
){
const int MINSLOT = 32;
int nSlotPerPage = MAX(MINSLOT, (p->pConfig->pgsz - 8) / szKey);
int nSlot = 0; /* Number of slots in each output page */
int nOut = 0;
i64 nSlot = 0; /* Number of slots in each output page */
i64 nOut = 0;
/* Figure out how many output pages (nOut) and how many slots per
** page (nSlot). There are three possibilities:
@@ -8005,23 +8017,26 @@ static void fts5IndexTombstoneRebuild(
nSlot = MINSLOT;
}else if( pSeg->nPgTombstone==1 ){
/* Case 2. */
int nElem = (int)fts5GetU32(&pData1->p[4]);
u32 nElem = fts5GetU32(&pData1->p[4]);
assert( pData1 && iPg1==0 );
nOut = 1;
nSlot = MAX(nElem*4, MINSLOT);
if( nSlot>nSlotPerPage ) nOut = 0;
if( nElem>((u32)nSlotPerPage/4) ){
nOut = 0;
}else{
nOut = 1;
nSlot = MAX((i64)nElem*4, MINSLOT);
}
}
if( nOut==0 ){
/* Case 3. */
nOut = (pSeg->nPgTombstone * 2 + 1);
nOut = ((i64)pSeg->nPgTombstone * 2 + 1);
nSlot = nSlotPerPage;
}
/* Allocate the required array and output pages */
while( 1 ){
int res = 0;
int ii = 0;
int szPage = 0;
i64 ii = 0;
i64 szPage = 0;
Fts5Data **apOut = 0;
/* Allocate space for the new hash table */
@@ -8559,7 +8574,7 @@ static void fts5IndexIntegrityCheckSegment(
/* Check any rowid-less pages that occur before the current leaf. */
for(iPg=iPrevLeaf+1; iPg<fts5DlidxIterPgno(pDlidx); iPg++){
iKey = FTS5_SEGMENT_ROWID(iSegid, iPg);
pLeaf = fts5DataRead(p, iKey);
pLeaf = fts5LeafRead(p, iKey);
if( pLeaf ){
if( fts5LeafFirstRowidOff(pLeaf)!=0 ) FTS5_CORRUPT_ROWID(p, iKey);
fts5DataRelease(pLeaf);
@@ -8570,7 +8585,7 @@ static void fts5IndexIntegrityCheckSegment(
/* Check that the leaf page indicated by the iterator really does
** contain the rowid suggested by the same. */
iKey = FTS5_SEGMENT_ROWID(iSegid, iPrevLeaf);
pLeaf = fts5DataRead(p, iKey);
pLeaf = fts5LeafRead(p, iKey);
if( pLeaf ){
i64 iRowid;
int iRowidOff = fts5LeafFirstRowidOff(pLeaf);
+45 -20
View File
@@ -517,7 +517,7 @@ static void fts5SetEstimatedRows(sqlite3_index_info *pIdxInfo, i64 nRow){
if( sqlite3_libversion_number()>=3008002 )
#endif
{
pIdxInfo->estimatedRows = nRow;
pIdxInfo->estimatedRows = MAX(1, nRow);
}
#endif
}
@@ -586,19 +586,30 @@ static int fts5UsePatternMatch(
** a) If a MATCH operator is present, the cost depends on the other
** constraints also present. As follows:
**
** * No other constraints: cost=1000.0
** * One rowid range constraint: cost=750.0
** * Both rowid range constraints: cost=500.0
** * An == rowid constraint: cost=100.0
** * No other constraints: cost=50000.0
** * One rowid range constraint: cost=37500.0
** * Both rowid range constraints: cost=30000.0
** * An == rowid constraint: cost=25000.0
**
** b) Otherwise, if there is no MATCH:
**
** * No other constraints: cost=1000000.0
** * One rowid range constraint: cost=750000.0
** * Both rowid range constraints: cost=250000.0
** * An == rowid constraint: cost=10.0
** * No other constraints: cost=3000000.0
** * One rowid range constraints: cost=2250000.0
** * Both rowid range constraint: cost=750000.0
** * An == rowid constraint: cost=25.0
**
** Costs are not modified by the ORDER BY clause.
**
** The ratios used in case (a) are based on informal results obtained from
** the tool/fts5cost.tcl script. The "MATCH and ==" combination has the
** cost set quite high because the query may be a prefix query. Unless
** there is a prefix index, prefix queries with rowid constraints are much
** more expensive than non-prefix queries with rowid constraints.
**
** The estimated rows returned is set to the cost/40. For simple queries,
** experimental results show that cost/4 might be about right. But for
** more complex queries that use multiple terms the number of rows might
** be far fewer than this. So we compromise and use cost/40.
*/
static int fts5BestIndexMethod(sqlite3_vtab *pVTab, sqlite3_index_info *pInfo){
Fts5Table *pTab = (Fts5Table*)pVTab;
@@ -724,21 +735,35 @@ 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 : 25.0;
fts5SetUniqueFlag(pInfo);
pInfo->estimatedCost = nSeenMatch ? 25000.0 : 25.0;
fts5SetEstimatedRows(pInfo, 1);
fts5SetUniqueFlag(pInfo);
}else{
if( bSeenLt && bSeenGt ){
pInfo->estimatedCost = nSeenMatch ? 5000.0 : 750000.0;
}else if( bSeenLt || bSeenGt ){
pInfo->estimatedCost = nSeenMatch ? 7500.0 : 2250000.0;
i64 nEstRows;
if( nSeenMatch ){
if( bSeenLt && bSeenGt ){
pInfo->estimatedCost = 50000.0;
}else if( bSeenLt || bSeenGt ){
pInfo->estimatedCost = 37500.0;
}else{
pInfo->estimatedCost = 50000.0;
}
nEstRows = (i64)(pInfo->estimatedCost / 40.0);
for(i=1; i<nSeenMatch; i++){
pInfo->estimatedCost *= 2.5;
nEstRows = nEstRows / 2;
}
}else{
pInfo->estimatedCost = nSeenMatch ? 10000.0 : 3000000.0;
if( bSeenLt && bSeenGt ){
pInfo->estimatedCost = 750000.0;
}else if( bSeenLt || bSeenGt ){
pInfo->estimatedCost = 2250000.0;
}else{
pInfo->estimatedCost = 3000000.0;
}
nEstRows = (i64)(pInfo->estimatedCost / 4.0);
}
for(i=1; i<nSeenMatch; i++){
pInfo->estimatedCost *= 0.4;
}
fts5SetEstimatedRows(pInfo, (i64)(pInfo->estimatedCost / 4.0));
fts5SetEstimatedRows(pInfo, nEstRows);
}
pInfo->idxNum = idxFlags;
+10 -4
View File
@@ -586,8 +586,14 @@ static int fts5PorterCreate(
const char *zBase = "unicode61";
fts5_tokenizer_v2 *pV2 = 0;
if( nArg>0 ){
zBase = azArg[0];
while( nArg>0 ){
if( sqlite3_stricmp(azArg[0],"porter")==0 ){
nArg--;
azArg++;
}else{
zBase = azArg[0];
break;
}
}
pRet = (PorterTokenizer*)sqlite3_malloc64(sizeof(PorterTokenizer));
@@ -712,9 +718,9 @@ static int fts5Porter_Ostar(char *zStem, int nStem){
for(i=0; i<nStem; i++){
bCons = !fts5PorterIsVowel(zStem[i], bCons);
assert( bCons==0 || bCons==1 );
mask = (mask << 1) + bCons;
mask = ((mask << 1) + bCons) & 0x0007;
}
return ((mask & 0x0007)==0x0005);
return (mask==0x0005);
}
}
+23
View File
@@ -191,6 +191,29 @@ do_execsql_test 5.6 {
SELECT snippet(p1, 0, '[', NULL, '...', 6) FROM p1('x OR ' || x'DB');
} {{[x a a a a a...}}
do_execsql_test 5.7.1 {
SELECT snippet(p1, 0, '[', NULL, '...', -2147483647) FROM p1('x OR ' || x'DB')
} {{[x...}}
do_execsql_test 5.7.2 {
SELECT snippet(p1, 0, '[', NULL, '...', -2147483648) FROM p1('x OR ' || x'DB')
} {{[x...}}
do_execsql_test 5.7.3 {
SELECT snippet(p1, 0, '[', NULL, '...', -2147483649) FROM p1('x OR ' || x'DB')
} {{[x...}}
do_execsql_test 5.7.4 {
SELECT snippet(p1, 0, '[', NULL, '...', 0) FROM p1('x OR ' || x'DB')
} {{[x...}}
do_execsql_test 5.8.1 {
SELECT snippet(p1, 0, '[', NULL, '...', 2147483647) FROM p1('x OR ' || x'DB')
} {{[x a a a a a a a a a a}}
do_execsql_test 5.8.2 {
SELECT snippet(p1, 0, '[', NULL, '...', 2147483648) FROM p1('x OR ' || x'DB')
} {{[x a a a a a a a a a a}}
do_execsql_test 5.8.3 {
SELECT snippet(p1, 0, '[', NULL, '...', 2147483649) FROM p1('x OR ' || x'DB')
} {{[x a a a a a a a a a a}}
} ;# foreach_detail_mode
reset_db
+28
View File
@@ -0,0 +1,28 @@
# 2026 June 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.
#
#*************************************************************************
# 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 fts5bigtok2
return_if_no_fts5
set big [string repeat a 1080000000]
do_execsql_test 1.0 {
CREATE VIRTUAL TABLE t USING fts5(x);
}
do_catchsql_test 1.1 { INSERT INTO t VALUES($big); } {1 {out of memory}}
set big {}
finish_test
+2 -2
View File
@@ -15153,9 +15153,9 @@ do_execsql_test 78.1 {
CREATE VIRTUAL TABLE t3 USING fts5vocab('t1','col');
}
do_execsql_test 78.2 {
do_catchsql_test 78.2 {
SELECT count(rowid) FROM t3 WHERE term>='nsocse';
} 2
} {1 {database disk image is malformed}}
#-------------------------------------------------------------------------
reset_db
+217 -1
View File
@@ -1220,7 +1220,7 @@ do_test 8.0 {
do_catchsql_test 8.1 {
SELECT rowid FROM t1('a* NOT ý‘') ;
} {0 {1 2 3 4 5 6 7}}
} {1 {fts5: corruption on page 1, segment 1, table "t1"}}
#-------------------------------------------------------------------------
reset_db
@@ -1917,6 +1917,222 @@ do_catchsql_test 11.3 {
REPLACE INTO t1(rowid,b,a,rowid) VALUES(x'44023b9eb002d28b0ee90c',1,2,3);
} {1 {database disk image is malformed}}
#-------------------------------------------------------------------------
reset_db
do_test 12.0 {
sqlite3 db {}
db deserialize [decode_hexdb {
.open --hexdb
| size 24576 pagesize 4096 filename p.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 03 00 00 00 06 .....@ ........
| 32: 00 00 00 00 00 00 00 00 00 00 00 06 00 00 00 04 ................
| 48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 ................
| 80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 ................
| 96: 00 2e 76 89 0d 00 00 00 06 0d ed 00 0f bb 0f 64 ..v............d
| 112: 0e f9 0e a2 0e 45 0d ed 00 00 00 00 00 00 00 00 .....E..........
| 3552: 00 00 00 00 00 00 00 00 00 00 00 00 00 56 06 06 .............V..
| 3568: 17 1f 1f 01 7d 74 61 62 6c 65 66 74 5f 63 6f 6e .....tableft_con
| 3584: 66 69 67 66 74 5f 63 6f 6e 66 69 67 06 43 52 45 figft_config.CRE
| 3600: 41 54 45 20 54 41 42 4c 45 20 27 66 74 5f 63 6f ATE TABLE 'ft_co
| 3616: 6e 66 69 67 27 28 6b 20 50 52 49 4d 41 52 59 20 nfig'(k PRIMARY
| 3632: 4b 45 59 2c 20 76 29 20 57 49 54 48 4f 55 54 20 KEY, v) WITHOUT
| 3648: 52 4f 57 49 44 5b 05 07 17 21 21 01 81 01 74 61 ROWID[...!!...ta
| 3664: 62 6c 65 66 74 5f 64 6f 63 73 69 7a 65 66 74 5f bleft_docsizeft_
| 3680: 64 6f 63 73 69 7a 65 05 43 52 45 41 54 45 20 54 docsize.CREATE T
| 3696: 41 42 4c 45 20 27 66 74 5f 64 6f 63 73 69 7a 65 ABLE 'ft_docsize
| 3712: 27 28 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 '(id INTEGER PRI
| 3728: 4d 41 52 59 20 4b 45 59 2c 20 73 7a 20 42 4c 4f MARY KEY, sz BLO
| 3744: 42 29 55 04 06 17 21 21 01 77 74 61 62 6c 65 66 B)U...!!.wtablef
| 3760: 74 5f 63 6f 6e 74 65 6e 74 66 74 5f 63 6f 6e 74 t_contentft_cont
| 3776: 65 6e 74 04 43 52 45 41 54 45 20 54 41 42 4c 45 ent.CREATE TABLE
| 3792: 20 27 66 74 5f 63 6f 6e 74 65 6e 74 27 28 69 64 'ft_content'(id
| 3808: 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 INTEGER PRIMARY
| 3824: 20 4b 45 59 2c 20 63 30 29 69 03 07 17 19 19 01 KEY, c0)i......
| 3840: 81 2d 74 61 62 6c 65 66 74 5f 69 64 78 66 74 5f .-tableft_idxft_
| 3856: 69 64 78 03 43 52 45 41 54 45 20 54 41 42 4c 45 idx.CREATE TABLE
| 3872: 20 27 66 74 5f 69 64 78 27 28 73 65 67 69 64 2c 'ft_idx'(segid,
| 3888: 20 74 65 72 6d 2c 20 70 67 6e 6f 2c 20 50 52 49 term, pgno, PRI
| 3904: 4d 41 52 59 20 4b 45 59 28 73 65 67 69 64 2c 20 MARY KEY(segid,
| 3920: 74 65 72 6d 29 29 20 57 49 54 48 4f 55 54 20 52 term)) WITHOUT R
| 3936: 4f 57 49 44 55 02 07 17 1b 1b 01 81 01 74 61 62 OWIDU........tab
| 3952: 6c 65 66 74 5f 64 61 74 61 66 74 5f 64 61 74 61 left_dataft_data
| 3968: 02 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 66 .CREATE TABLE 'f
| 3984: 74 5f 64 61 74 61 27 28 69 64 20 49 4e 54 45 47 t_data'(id INTEG
| 4000: 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 ER PRIMARY KEY,
| 4016: 62 6c 6f 63 6b 20 42 4c 4f 42 29 43 01 06 17 11 block BLOB)C....
| 4032: 11 08 75 74 61 62 6c 65 66 74 66 74 43 52 45 41 ..utableftftCREA
| 4048: 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45 TE VIRTUAL TABLE
| 4064: 20 66 74 20 55 53 49 4e 47 20 66 74 73 35 28 61 ft USING fts5(a
| 4080: 2c 20 64 65 74 61 69 6c 3d 63 6f 6c 75 6d 6e 29 , detail=column)
| page 2 offset 4096
| 0: 0d 00 00 00 03 0f 7f 00 0f e8 0f ef 0f 7f 00 00 ................
| 3952: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 62 ...............b
| 3968: 84 80 80 80 80 01 04 00 81 48 00 00 00 54 04 30 .........H...T.0
| 3984: 61 61 61 01 81 02 02 02 02 02 02 02 02 02 02 02 aaa.............
| 4000: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................
| 4016: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................
| 4032: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................
| 4048: 02 02 02 02 02 02 02 03 6a 6a 6a 01 02 02 04 08 ........jjj.....
| 4064: 08 08 08 08 08 08 08 08 05 01 03 00 10 01 0a 0f ................
| 4080: 0a 03 00 24 00 00 00 00 01 01 01 00 01 01 01 01 ...$............
| page 3 offset 8192
| 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 4 offset 12288
| 0: 0d 00 00 00 01 0f d4 00 0f d4 00 00 00 00 00 00 ................
| 4048: 00 00 00 00 2a 01 03 00 5b 61 61 61 20 62 62 62 ....*...[aaa bbb
| 4064: 20 63 63 63 20 64 64 64 20 65 65 65 20 66 66 66 ccc ddd eee fff
| 4080: 20 67 67 67 20 68 68 68 20 69 69 69 20 6a 6a 6a ggg hhh iii jjj
| page 5 offset 16384
| 0: 0d 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 04 01 03 00 0e 0a ................
| page 6 offset 20480
| 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.
| end p.db
}]} {}
do_catchsql_test 12.1 {
SELECT rowid FROM ft('a:aaa')
} {0 1}
#-------------------------------------------------------------------------
reset_db
do_test 13.0 {
sqlite3 db {}
db deserialize [decode_hexdb {
.open --hexdb
| size 24576 pagesize 4096 filename vuln_001.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 03 00 00 00 06 .....@ ........
| 32: 00 00 00 00 00 00 00 00 00 00 00 06 00 00 00 04 ................
| 48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 ................
| 80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 ................
| 96: 00 2e 76 89 0d 00 00 00 06 0e 09 00 0f ca 0f 77 ..v............w
| 112: 0f 0f 0e b7 0e 5e 0e 09 00 00 00 00 00 00 00 00 .....^..........
| 3584: 00 00 00 00 00 00 00 00 00 53 06 06 17 1d 1d 01 .........S......
| 3600: 7b 74 61 62 6c 65 74 5f 63 6f 6e 66 69 67 74 5f .tablet_configt_
| 3616: 63 6f 6e 66 69 67 06 43 52 45 41 54 45 20 54 41 config.CREATE TA
| 3632: 42 4c 45 20 27 74 5f 63 6f 6e 66 69 67 27 28 6b BLE 't_config'(k
| 3648: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 76 29 PRIMARY KEY, v)
| 3664: 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 57 05 WITHOUT ROWIDW.
| 3680: 06 17 1f 1f 01 7f 74 61 62 6c 65 74 5f 64 6f 63 ......tablet_doc
| 3696: 73 69 7a 65 74 5f 64 6f 63 73 69 7a 65 05 43 52 sizet_docsize.CR
| 3712: 45 41 54 45 20 54 41 42 4c 45 20 27 74 5f 64 6f EATE TABLE 't_do
| 3728: 63 73 69 7a 65 27 28 69 64 20 49 4e 54 45 47 45 csize'(id INTEGE
| 3744: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 73 R PRIMARY KEY, s
| 3760: 7a 20 42 4c 4f 42 29 56 04 06 17 1f 1f 01 7d 74 z BLOB)V.......t
| 3776: 61 62 6c 65 74 5f 63 6f 6e 74 65 6e 74 74 5f 63 ablet_contentt_c
| 3792: 6f 6e 74 65 6e 74 04 43 52 45 41 54 45 20 54 41 ontent.CREATE TA
| 3808: 42 4c 45 20 27 74 5f 63 6f 6e 74 65 6e 74 27 28 BLE 't_content'(
| 3824: 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 id INTEGER PRIMA
| 3840: 52 59 20 4b 45 59 2c 20 63 30 2c 20 63 31 29 66 RY KEY, c0, c1)f
| 3856: 03 07 17 17 17 01 81 2b 74 61 62 6c 65 74 5f 69 .......+tablet_i
| 3872: 64 78 74 5f 69 64 78 03 43 52 45 41 54 45 20 54 dxt_idx.CREATE T
| 3888: 41 42 4c 45 20 27 74 5f 69 64 78 27 28 73 65 67 ABLE 't_idx'(seg
| 3904: 69 64 2c 20 74 65 72 6d 2c 20 70 67 6e 6f 2c 20 id, term, pgno,
| 3920: 50 52 49 4d 41 52 59 20 4b 45 59 28 73 65 67 69 PRIMARY KEY(segi
| 3936: 64 2c 20 74 65 72 6d 29 29 20 57 49 54 48 4f 55 d, term)) WITHOU
| 3952: 54 20 52 4f 57 49 44 51 02 06 17 19 19 01 7f 74 T ROWIDQ.......t
| 3968: 61 62 6c 65 74 5f 64 61 74 61 74 5f 64 61 74 61 ablet_datat_data
| 3984: 02 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74 .CREATE TABLE 't
| 4000: 5f 64 61 74 61 27 28 69 64 20 49 4e 54 45 47 45 _data'(id INTEGE
| 4016: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 62 R PRIMARY KEY, b
| 4032: 6c 6f 63 6b 20 42 4c 4f 42 29 34 01 06 17 0f 0f lock BLOB)4.....
| 4048: 08 5b 74 61 62 6c 65 74 74 43 52 45 41 54 45 20 .[tablettCREATE
| 4064: 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20 74 20 VIRTUAL TABLE t
| 4080: 55 53 49 4e 47 20 66 74 73 35 28 61 2c 20 62 29 USING fts5(a, b)
| page 2 offset 4096
| 0: 0d 00 00 00 04 0b da 00 0f e7 0f ef 0f ce 0b da ................
| 3024: 00 00 00 00 00 00 00 00 00 00 87 6c 84 80 80 80 ...........l....
| 3040: 80 02 04 00 8f 5c 00 00 03 e8 80 80 80 80 80 80 ................
| 3056: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3072: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3088: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3104: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3120: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3136: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3152: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3168: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3184: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3200: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3216: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3232: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3248: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3264: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3280: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3296: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3312: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3328: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3344: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3360: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3376: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3392: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3408: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3424: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3440: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3456: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3472: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3488: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3504: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3520: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3536: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3552: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3568: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3584: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3600: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3616: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3632: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3648: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3664: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3680: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3696: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3712: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3728: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3744: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3760: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3776: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3792: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3808: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3824: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3840: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3856: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3872: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3888: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3904: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3920: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3936: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3952: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3968: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 3984: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 4000: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 4016: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................
| 4032: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 12 84 ................
| 4048: 80 80 80 80 01 03 00 2a 00 0b 00 0e 06 30 68 65 .......*.....0he
| 4064: 6c 6c 6f 01 04 04 04 06 01 03 00 12 01 02 02 0f llo.............
| 4080: 0a 03 00 24 00 00 00 00 01 01 01 00 01 01 01 02 ...$............
| page 3 offset 8192
| 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 4 offset 12288
| 0: 0d 00 00 00 01 0f e8 00 0f e8 00 00 00 00 00 00 ................
| 4064: 00 00 00 00 00 00 00 00 16 01 04 00 23 1b 68 65 ............#.he
| 4080: 6c 6c 6f 20 77 6f 72 6c 64 66 6f 6f 20 62 61 72 llo worldfoo bar
| page 5 offset 16384
| 0: 0d 00 00 00 01 0f f9 00 0f f9 00 00 00 00 00 00 ................
| 4080: 00 00 00 00 00 00 00 00 00 05 01 03 00 10 02 02 ................
| page 6 offset 20480
| 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.
| end vuln_001.db
}]} {}
do_catchsql_test 13.1 {
SELECT * FROM t('a:hello')
} {0 {{hello world} {foo bar}}}
sqlite3_fts5_may_be_corrupt 0
finish_test
+36
View File
@@ -125,4 +125,40 @@ do_catchsql_test 2.3 {
DELETE FROM t1 WHERE rowid = 1
} {/.*fts5: corrupt.*/}
#-------------------------------------------------------------------------
reset_db
do_execsql_test 3.0 {
PRAGMA page_size=4096;
PRAGMA journal_mode=DELETE;
CREATE VIRTUAL TABLE t USING fts5(x, detail=none);
WITH s(i) AS (
VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<5000
)
INSERT INTO t(rowid, x) SELECT i, 'vulnerabilitytest' FROM s;
INSERT INTO t(t) VALUES('optimize');
INSERT INTO t(t, rank) VALUES('secure-delete', 1);
} {delete}
do_test 3.1 {
db eval { SELECT rowid AS rowid, block FROM t_data ORDER BY rowid } {
if {$rowid>=10 && [string length $block]>=4} {
binary scan $block Su first_rowid_off
set pgno [expr ($rowid & 0x7FFFFFFF)]
if {$pgno>=2 && $first_rowid_off>0} break
}
}
set bad [binary format a*a* "\xFF\xFF" [string range $block 2 end]]
db eval {
UPDATE t_data SET block = $bad WHERE rowid=$rowid
}
} {}
do_catchsql_test 3.2 {
DELETE FROM t WHERE rowid=4500;
} {1 {fts5: corruption in table "t"}}
finish_test
+273
View File
@@ -0,0 +1,273 @@
# 2026 May 11
#
# 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.
#
#***********************************************************************
#
source [file join [file dirname [info script]] fts5_common.tcl]
set testprefix fts5corruptA
# If SQLITE_ENABLE_FTS5 is not defined, omit this file.
ifcapable !fts5 {
finish_test
return
}
sqlite3_fts5_may_be_corrupt 1
do_execsql_test 1.0 {
CREATE VIRTUAL TABLE t USING fts5(x, detail='full');
INSERT INTO t(t, rank) VALUES('pgsz', 32);
}
set big [string repeat "a " 200]
do_execsql_test 1.1 {
INSERT INTO t(rowid, x) VALUES(1, $big)
}
do_test 1.2 {
db eval {
SELECT min(rowid) AS base_rowid, count(*) AS page_count FROM t_data
WHERE rowid>1000
} {}
} {}
do_test 1.3 {
for {set ii 0} {$ii < 5} {incr ii} {
db eval {
INSERT INTO t_data(rowid, block)
VALUES( $base_rowid + $page_count + $ii, zeroblob(4) );
}
}
db eval {
INSERT INTO t_data(rowid, block)
VALUES( $base_rowid + $page_count + 5,
unhex('00000080' || 'CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC') );
}
set {} {}
} {}
db close
do_test 1.4 {
set hex [hexio_read test.db 0 [file size test.db]]
set off [string first "023061018310" $hex]
set hex [string replace $hex $off [expr $off+11] 023061018370]
hexio_write test.db 0 $hex
} {6144}
sqlite3 db test.db
do_catchsql_test 1.5 {
SELECT rowid FROM t WHERE t MATCH 'a'
} {1 {fts5: corruption found reading blob 137438953481 from table "t"}}
#-------------------------------------------------------------------------
reset_db
do_execsql_test 2.0 {
CREATE VIRTUAL TABLE t1 USING fts5(a);
BEGIN;
INSERT INTO t1(rowid, a) VALUES(1, 'aaaa');
INSERT INTO t1(rowid, a) VALUES(2, 'bbbb');
INSERT INTO t1(rowid, a) VALUES(3, 'cccc');
COMMIT;
}
db close
do_test 2.1 {
set hex [hexio_read test.db 0 [file size test.db]]
set off [string first "010463636363" $hex]
set hex [string replace $hex $off [expr $off+11] 017F63636363]
hexio_write test.db 0 $hex
set {} {}
} {}
sqlite3 db test.db
do_catchsql_test 2.2 {
SELECT rowid FROM t1('cccccccccccccccccccccccccccccccccccccccccccccccc');
} {1 {fts5: corruption on page 1, segment 1, table "t1"}}
#-------------------------------------------------------------------------
reset_db
do_execsql_test 3.0 {
CREATE VIRTUAL TABLE t1 USING fts5(a, b, c);
INSERT INTO t1 VALUES(
'hello',
'alpha bravo charlie delta echo foxtrot golf hotel india juliet kilo lima mike november oscar papa quebec romeo sierra tango uniform victor whiskey xray yankee zulu',
'ant bear cat dog elephant fox gorilla hippo iguana jaguar kangaroo lion monkey newt octopus panda quail rabbit snake turtle unicorn vulture walrus xerus yak zebra'
);
UPDATE t1_data SET block = unhex(
-- Preserve bytes 0-168: header through hello's nSz field
hex(substr(block, 1, 169))
-- Inject 448 bytes of 0xFF: corrupted poslist + subsequent term data
|| replace(hex(zeroblob(448)), '00', 'FF')
-- Preserve 16 bytes of page index needed for hello lookup
|| hex(substr(block, 618, 16))
-- Corrupt remaining 37 footer bytes (not needed for hello lookup)
|| replace(hex(zeroblob(37)), '00', 'FF')
)
WHERE id = 137438953473;
}
do_test 3.1 {
execsql { SELECT * FROM t1 WHERE t1 MATCH '{a b}: hello' }
set {} {}
} {}
#-------------------------------------------------------------------------
reset_db
do_execsql_test 4.0 {
CREATE VIRTUAL TABLE t1 USING fts5(content);
INSERT INTO t1(t1, rank) VALUES('pgsz', 32);
BEGIN;
WITH s(i) AS (
SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<5000
)
INSERT INTO t1(content) SELECT 'xyzterm' FROM s;
COMMIT;
INSERT INTO t1(t1) VALUES('optimize');
}
do_test 4.1 {
db eval {
SELECT rowid AS a, hex(block) AS block FROM t1_data
WHERE ((rowid>>36) & 0x01)==1
AND ((rowid>>31) & 0x1F)==0
} {
set n [string length $block]
set block [string range $block 0 11]
append block [string repeat "00" [expr ($n/2)-7-2]]
append block "8080"
db eval {
UPDATE t1_data SET block = unhex($block) WHERE rowid = $a
}
}
} {}
do_catchsql_test 4.2 {
SELECT count(*) FROM (
SELECT rowid FROM t1 WHERE t1 MATCH 'xyzterm' ORDER BY rowid ASC
)
} {0 5000}
do_catchsql_test 4.3 {
SELECT count(*) FROM (
SELECT rowid FROM t1 WHERE t1 MATCH 'xyzterm' ORDER BY rowid DESC
)
} {0 4987}
do_test 4.4 {
db eval {
SELECT rowid AS a, hex(block) AS block FROM t1_data
WHERE ((rowid>>36) & 0x01)==1
AND ((rowid>>31) & 0x1F)==0
} {
set n [string length $block]
set block [string range $block 0 $n-5]
append block [string repeat "00" 2]
db eval {
UPDATE t1_data SET block = unhex($block) WHERE rowid = $a
}
}
} {}
do_catchsql_test 4.5 {
SELECT count(*) FROM (
SELECT rowid FROM t1 WHERE t1 MATCH 'xyzterm' ORDER BY rowid ASC
)
} {0 5000}
do_catchsql_test 4.6 {
SELECT count(*) FROM (
SELECT rowid FROM t1 WHERE t1 MATCH 'xyzterm' ORDER BY rowid DESC
)
} {0 4879}
#-------------------------------------------------------------------------
reset_db
do_execsql_test 5.0 {
CREATE VIRTUAL TABLE t USING fts5(x);
INSERT INTO t(t,rank) VALUES('pgsz', 64);
WITH s(i) AS (
SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<80
)
INSERT INTO t SELECT 'shared word' || (i%10) || ' shared shared' FROM s;
INSERT INTO t(t) VALUES('optimize');
}
set lLeaf [db eval { SELECT id FROM t_data }]
db_save_and_close
foreach leaf $lLeaf {
db_restore_and_reopen
set leaf [expr $leaf]
set hex [db one {
SELECT hex(block) FROM t_data WHERE id=$leaf
}]
# Replace the first 4 bytes of each leaf page with the size of the leaf in
# bytes plus 50 as a 2 byte integer, followed by 0x7FFF.
#
set nn [expr [string length $hex]/2]
set first "[format %.4x [expr $nn+50]]7FFF"
set hex [string replace $hex 0 7 $first]
db eval { UPDATE t_data SET block=unhex($hex) WHERE id=$leaf }
do_test 5.1.$leaf {
catchsql {
SELECT rowid FROM t WHERE t MATCH 'shared' ORDER BY rowid DESC;
}
set {} {}
} {}
do_test 5.1.$leaf.2 {
catchsql {
PRAGMA integrity_check;
}
set {} {}
} {}
}
#-------------------------------------------------------------------------
reset_db
do_execsql_test 6.0 {
CREATE VIRTUAL TABLE t USING fts5(x, content='', contentless_delete=1);
INSERT INTO t(rowid,x)
VALUES(1,'a b'), (2,'c d'), (3,'e f'), (4,'g h'), (5,'i j');
INSERT INTO t(t) VALUES('optimize');
DELETE FROM t WHERE rowid=2;
}
do_test 6.1 {
db eval {
SELECT rowid AS rid, hex(block) AS blk
FROM t_data WHERE rowid>1_000_000_000_000
} {}
set blk [string replace $blk 8 15 20000000]
execsql {
UPDATE t_data SET block = unhex($blk) WHERE rowid=$rid
}
} {}
do_execsql_test 6.2 {
DELETE FROM t WHERE rowid=3;
}
sqlite3_fts5_may_be_corrupt 0
finish_test
+9
View File
@@ -65,5 +65,14 @@ do_eqp_test 1.4 {
`--SCAN vt VIRTUAL TABLE INDEX 0:=
}
do_eqp_test 1.5 {
SELECT * FROM vt, t1
WHERE vt.rowid = t1.rowid AND vt MATCH ? AND b = ?
} {
QUERY PLAN
|--SCAN vt VIRTUAL TABLE INDEX 0:M1
`--SEARCH t1 USING INTEGER PRIMARY KEY (rowid=?)
}
finish_test
+13
View File
@@ -66,5 +66,18 @@ do_near_test 1.23 "a b c d e f g h i" { NEAR(a+b+c+d i b+c, 4) } 0
do_near_test 1.24 "a b c d e f g h i" { NEAR(i a+b+c+d b+c, 5) } 1
do_near_test 1.25 "a b c d e f g h i" { NEAR(i a+b+c+d b+c, 4) } 0
#-------------------------------------------------------------------------
# Check that https://sqlite.org/bugs/forumpost/16bb36f7e8 is fixed.
#
reset_db
do_execsql_test 2.0 {
CREATE VIRTUAL TABLE t USING fts5(x, tokenize=trigram);
INSERT INTO t
VALUES('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');
}
do_execsql_test 2.1 {
SELECT count(*) FROM t WHERE t MATCH 'NEAR(aaa aaa, 4)';
} {1}
finish_test
+8
View File
@@ -65,5 +65,13 @@ foreach {in out} $test_vocab {
incr i
}
#-------------------------------------------------------------------------
reset_db
do_execsql_test 2.0 {
CREATE VIRTUAL TABLE tbl USING fts5(t, tokenize='porter unicode61');
INSERT INTO tbl VALUES(' andeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee');
}
finish_test
+28
View File
@@ -418,6 +418,34 @@ do_execsql_test 7.1.2 {
INSERT INTO t2(t2) VALUES('integrity-check');
}
#-------------------------------------------------------------------------
reset_db
fts5_aux_test_functions db
proc tcl_create {args} { return "tcl_tokenize" }
sqlite3_fts5_create_tokenizer db tcl tcl_create
proc tcl_tokenize {tflags text} {
foreach {w iStart iEnd} [fts5_tokenize_split $text] {
sqlite3_fts5_token $w $iStart $iEnd
if {$w=="usa"} {
sqlite3_fts5_token -colo "united" $iStart $iEnd
}
}
}
do_execsql_test 8.0 {
CREATE VIRTUAL TABLE t1 USING fts5(x, tokenize='tcl', tokendata=1);
INSERT INTO t1 VALUES('usa is great');
INSERT INTO t1 VALUES('canada is cool');
INSERT INTO t1 VALUES('australia is what matters');
}
do_execsql_test 8.1 {
SELECT * FROM t1 WHERE t1 MATCH 'usa*';
} {{usa is great}}
} ;# foreach_detail_mode
finish_test
+10
View File
@@ -371,4 +371,14 @@ do_execsql_test 10.10 {
a 2 2 b 2 2 c 2 2 d 1 1 e 1 1 f 1 1
}
# Bug report 2026-05-18T05:19:01Z
#
set manyporters {porter Porter}
for {set i 0} {$i<18} {incr i} {
set manyporters "$manyporters $manyporters"
}
do_execsql_test 11.1 "
CREATE VIRTUAL TABLE t11 USING fts5(a,b,tokenize=\"$manyporters\");
" {}
finish_test
+153
View File
@@ -0,0 +1,153 @@
#
# 2026 March 20
#
# 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 script extracts the documentation for the API used by fts5 auxiliary
# functions from header file fts5.h. It outputs html text on stdout that
# is included in the documentation on the web.
#
sqlite3 db fts5cost.db
# Create an IPK table with 1,000,000 entries. Short records.
#
set res [list [catch { db eval {SELECT count(*) FROM t1} } msg] $msg]
if {$res!="0 1000000"} {
db eval {
PRAGMA mmap_size = 1000000000; -- 1GB
DROP TABLE IF EXISTS t1;
CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT);
WITH s(i) AS (
SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<1_000_000
)
INSERT INTO t1 SELECT i, hex(randomblob(8)) FROM s;
}
}
# Create an FTS5 table with 1,000,000 entries. Each row contains a single
# column containing a document of 100 terms chosen pseudo-randomly from
# a vocabularly of 2000.
set res [list [catch { db eval {SELECT count(*) FROM f1} } msg] $msg]
if {$res!="0 1000000"} {
set nVocab 2000
set nTerm 100
db eval {
BEGIN;
DROP TABLE IF EXISTS vocab1;
CREATE TABLE vocab1(w);
}
for {set ii 0} {$ii<$nVocab} {incr ii} {
set word [format %06x [expr {int(abs(rand()) * 0xFFFFFF)}]]
db eval { INSERT INTO vocab1 VALUES($word) }
lappend lVocab $word
}
db func doc doc
proc doc {} {
for {set ii 0} {$ii<$::nTerm} {incr ii} {
lappend ret [lindex $::lVocab [expr int(abs(rand())*$::nVocab)]]
}
set ret
}
db eval {
DROP TABLE IF EXISTS f1;
CREATE VIRTUAL TABLE f1 USING fts5(x);
WITH s(i) AS (
SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<1_000_000
)
INSERT INTO f1(rowid, x) SELECT i, doc() FROM s;
COMMIT;
}
} else {
set lVocab [db eval { SELECT * FROM vocab1 }]
set nVocab [llength $lVocab]
}
proc rowid_query {n} {
set rowid 654
for {set ii 0} {$ii<$n} {incr ii} {
db eval { SELECT b FROM t1 WHERE a = $rowid }
set rowid [expr {($rowid + 7717) % 1000000}]
}
}
proc rowid_query_fts {n} {
set rowid 654
for {set ii 0} {$ii<$n} {incr ii} {
db eval { SELECT * FROM f1 WHERE rowid = $rowid }
set rowid [expr {($rowid + 7717) % 1000000}]
}
}
proc match_query_fts {n} {
set idx 654
for {set ii 0} {$ii<$n} {incr ii} {
set match [lrange $::lVocab $idx $idx+1]
db eval { SELECT * FROM f1($match) }
set idx [expr {($idx + 7717) % $::nVocab}]
}
}
proc prefix_query_fts {n} {
set idx 654
for {set ii 0} {$ii<$n} {incr ii} {
set match "[lindex $::lVocab $idx]*"
db eval { SELECT * FROM f1($match) }
set idx [expr {($idx + 7717) % $::nVocab}]
}
}
proc match_rowid_query_fts {n} {
set idx 654
for {set ii 0} {$ii<$n} {incr ii} {
set match "[lindex $::lVocab $idx]"
db eval { SELECT * FROM f1($match) WHERE rowid=500000 }
set idx [expr {($idx + 7717) % $::nVocab}]
}
}
proc prefix_rowid_query_fts {n} {
set idx 654
for {set ii 0} {$ii<$n} {incr ii} {
set match "[lindex $::lVocab $idx]*"
db eval { SELECT * FROM f1($match) WHERE rowid=500000 }
set idx [expr {($idx + 7717) % $::nVocab}]
}
}
proc mytime {cmd div} {
set tm [time $cmd]
expr {[lindex $tm 0] / $div}
}
#set us [mytime { match_rowid_query_fts 1000 } 1000]
#puts "1000 match/rowid queries on fts5 table: ${us} per query"
set us [mytime { prefix_rowid_query_fts 1000 } 1000]
puts "1000 prefix/rowid queries on fts5 table: ${us} per query"
set us [mytime { match_query_fts 10 } 10]
puts "10 match queries on fts5 table: ${us} per query"
set us [mytime { prefix_query_fts 10 } 10]
puts "10 prefix queries on fts5 table: ${us} per query"
set us [mytime { prefix_rowid_query_fts 1000 } 1000]
puts "1000 prefix/rowid queries on fts5 table: ${us} per query"
set us [mytime { rowid_query 10000 } 10000]
puts "10000 by-rowid queries on normal table: ${us} per query"
set us [mytime { rowid_query_fts 10000 } 10000]
puts "10000 by-rowid queries on fts5 table: ${us} per query"
+8 -4
View File
@@ -105,6 +105,9 @@ static const unsigned char icuUtf8Trans1[] = {
while( (*zIn & 0xc0)==0x80 ){ \
c = (c<<6) + (0x3f & *(zIn++)); \
} \
if( c<0x80 \
|| (c&0xFFFFF800)==0xD800 \
|| (c&0xFFFFFFFE)==0xFFFE ){ c = 0xFFFD; } \
}
#define SQLITE_ICU_SKIP_UTF8(zIn) \
@@ -362,7 +365,7 @@ static void icuCaseFunc16(sqlite3_context *p, int nArg, sqlite3_value **apArg){
const UChar *zInput; /* Pointer to input string */
UChar *zOutput = 0; /* Pointer to output buffer */
int nInput; /* Size of utf-16 input string in bytes */
int nOut; /* Size of output buffer in bytes */
sqlite3_int64 nOut; /* Size of output buffer in bytes */
int cnt;
int bToUpper; /* True for toupper(), false for tolower() */
UErrorCode status;
@@ -385,7 +388,7 @@ static void icuCaseFunc16(sqlite3_context *p, int nArg, sqlite3_value **apArg){
}
for(cnt=0; cnt<2; cnt++){
UChar *zNew = sqlite3_realloc(zOutput, nOut);
UChar *zNew = sqlite3_realloc64(zOutput, nOut);
if( zNew==0 ){
sqlite3_free(zOutput);
sqlite3_result_error_nomem(p);
@@ -394,9 +397,9 @@ static void icuCaseFunc16(sqlite3_context *p, int nArg, sqlite3_value **apArg){
zOutput = zNew;
status = U_ZERO_ERROR;
if( bToUpper ){
nOut = 2*u_strToUpper(zOutput,nOut/2,zInput,nInput/2,zLocale,&status);
nOut = 2LL*u_strToUpper(zOutput,nOut/2,zInput,nInput/2,zLocale,&status);
}else{
nOut = 2*u_strToLower(zOutput,nOut/2,zInput,nInput/2,zLocale,&status);
nOut = 2LL*u_strToLower(zOutput,nOut/2,zInput,nInput/2,zLocale,&status);
}
if( U_SUCCESS(status) ){
@@ -516,6 +519,7 @@ static void icuLoadCollation(
}
sqlite3_result_error(p, sqlite3_str_value(pStr), -1);
sqlite3_free(sqlite3_str_finish(pStr));
ucol_close(pUCollator);
return;
}
}
+3 -3
View File
@@ -847,7 +847,7 @@ static int amatchConnect(
(void)pAux;
*ppVtab = 0;
pNew = sqlite3_malloc( sizeof(*pNew) );
pNew = sqlite3_malloc64( sizeof(*pNew) );
if( pNew==0 ) return SQLITE_NOMEM;
rc = SQLITE_NOMEM;
memset(pNew, 0, sizeof(*pNew));
@@ -928,7 +928,7 @@ amatchConnectError:
static int amatchOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){
amatch_vtab *p = (amatch_vtab*)pVTab;
amatch_cursor *pCur;
pCur = sqlite3_malloc( sizeof(*pCur) );
pCur = sqlite3_malloc64( sizeof(*pCur) );
if( pCur==0 ) return SQLITE_NOMEM;
memset(pCur, 0, sizeof(*pCur));
pCur->pVtab = p;
@@ -1157,7 +1157,7 @@ static int amatchNext(sqlite3_vtab_cursor *cur){
#endif
nWord = (int)strlen(pWord->zWord+2);
if( nWord+20>nBuf ){
nBuf = (char)(nWord+100);
nBuf = nWord+100;
zBuf = sqlite3_realloc64(zBuf, nBuf);
if( zBuf==0 ) return SQLITE_NOMEM;
}
+2 -2
View File
@@ -232,7 +232,7 @@ static void base64(sqlite3_context *context, int na, sqlite3_value *av[]){
sqlite3_result_text(context,"",-1,SQLITE_STATIC);
break;
}
cBuf = sqlite3_malloc(nc);
cBuf = sqlite3_malloc64(nc);
if( !cBuf ) goto memFail;
nc = (int)(toBase64(bBuf, nb, cBuf) - cBuf);
sqlite3_result_text(context, cBuf, nc, sqlite3_free);
@@ -254,7 +254,7 @@ static void base64(sqlite3_context *context, int na, sqlite3_value *av[]){
sqlite3_result_zeroblob(context, 0);
break;
}
bBuf = sqlite3_malloc(nb);
bBuf = sqlite3_malloc64(nb);
if( !bBuf ) goto memFail;
nb = (int)(fromBase64(cBuf, nc, bBuf) - bBuf);
sqlite3_result_blob(context, bBuf, nb, sqlite3_free);
+2 -2
View File
@@ -309,7 +309,7 @@ static void base85(sqlite3_context *context, int na, sqlite3_value *av[]){
sqlite3_result_text(context,"",-1,SQLITE_STATIC);
break;
}
cBuf = sqlite3_malloc(nc);
cBuf = sqlite3_malloc64(nc);
if( !cBuf ) goto memFail;
nc = (int)(toBase85(bBuf, nb, cBuf, "\n") - cBuf);
sqlite3_result_text(context, cBuf, nc, sqlite3_free);
@@ -331,7 +331,7 @@ static void base85(sqlite3_context *context, int na, sqlite3_value *av[]){
sqlite3_result_zeroblob(context, 0);
break;
}
bBuf = sqlite3_malloc(nb);
bBuf = sqlite3_malloc64(nb);
if( !bBuf ) goto memFail;
nb = (int)(fromBase85(cBuf, nc, bBuf) - bBuf);
sqlite3_result_blob(context, bBuf, nb, sqlite3_free);
-152
View File
@@ -1,152 +0,0 @@
/*
** 2019-03-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.
**
******************************************************************************
**
** An SQL function that uses the incremental BLOB I/O mechanism of SQLite
** to read or write part of a blob. This is intended for debugging use
** in the CLI.
**
** readblob(SCHEMA,TABLE,COLUMN,ROWID,OFFSET,N)
**
** Returns N bytes of the blob starting at OFFSET.
**
** writeblob(SCHEMA,TABLE,COLUMN,ROWID,OFFSET,NEWDATA)
**
** NEWDATA must be a blob. The content of NEWDATA overwrites the
** existing BLOB data at SCHEMA.TABLE.COLUMN for row ROWID beginning
** at OFFSET bytes into the blob.
*/
#include "sqlite3ext.h"
SQLITE_EXTENSION_INIT1
#include <assert.h>
#include <string.h>
static void readblobFunc(
sqlite3_context *context,
int argc,
sqlite3_value **argv
){
sqlite3_blob *pBlob = 0;
const char *zSchema;
const char *zTable;
const char *zColumn;
sqlite3_int64 iRowid;
int iOfst;
unsigned char *aData;
int nData;
sqlite3 *db;
int rc;
zSchema = (const char*)sqlite3_value_text(argv[0]);
zTable = (const char*)sqlite3_value_text(argv[1]);
if( zTable==0 ){
sqlite3_result_error(context, "bad table name", -1);
return;
}
zColumn = (const char*)sqlite3_value_text(argv[2]);
if( zTable==0 ){
sqlite3_result_error(context, "bad column name", -1);
return;
}
iRowid = sqlite3_value_int64(argv[3]);
iOfst = sqlite3_value_int(argv[4]);
nData = sqlite3_value_int(argv[5]);
if( nData<=0 ) return;
aData = sqlite3_malloc64( nData+1 );
if( aData==0 ){
sqlite3_result_error_nomem(context);
return;
}
db = sqlite3_context_db_handle(context);
rc = sqlite3_blob_open(db, zSchema, zTable, zColumn, iRowid, 0, &pBlob);
if( rc ){
sqlite3_free(aData);
sqlite3_result_error(context, "cannot open BLOB pointer", -1);
return;
}
rc = sqlite3_blob_read(pBlob, aData, nData, iOfst);
sqlite3_blob_close(pBlob);
if( rc ){
sqlite3_free(aData);
sqlite3_result_error(context, "BLOB read failed", -1);
}else{
sqlite3_result_blob(context, aData, nData, sqlite3_free);
}
}
static void writeblobFunc(
sqlite3_context *context,
int argc,
sqlite3_value **argv
){
sqlite3_blob *pBlob = 0;
const char *zSchema;
const char *zTable;
const char *zColumn;
sqlite3_int64 iRowid;
int iOfst;
unsigned char *aData;
int nData;
sqlite3 *db;
int rc;
zSchema = (const char*)sqlite3_value_text(argv[0]);
zTable = (const char*)sqlite3_value_text(argv[1]);
if( zTable==0 ){
sqlite3_result_error(context, "bad table name", -1);
return;
}
zColumn = (const char*)sqlite3_value_text(argv[2]);
if( zTable==0 ){
sqlite3_result_error(context, "bad column name", -1);
return;
}
iRowid = sqlite3_value_int64(argv[3]);
iOfst = sqlite3_value_int(argv[4]);
if( sqlite3_value_type(argv[5])!=SQLITE_BLOB ){
sqlite3_result_error(context, "6th argument must be a BLOB", -1);
return;
}
nData = sqlite3_value_bytes(argv[5]);
aData = (unsigned char *)sqlite3_value_blob(argv[5]);
db = sqlite3_context_db_handle(context);
rc = sqlite3_blob_open(db, zSchema, zTable, zColumn, iRowid, 1, &pBlob);
if( rc ){
sqlite3_result_error(context, "cannot open BLOB pointer", -1);
return;
}
rc = sqlite3_blob_write(pBlob, aData, nData, iOfst);
sqlite3_blob_close(pBlob);
if( rc ){
sqlite3_result_error(context, "BLOB write failed", -1);
}
}
#ifdef _WIN32
__declspec(dllexport)
#endif
int sqlite3_blobio_init(
sqlite3 *db,
char **pzErrMsg,
const sqlite3_api_routines *pApi
){
int rc = SQLITE_OK;
SQLITE_EXTENSION_INIT2(pApi);
(void)pzErrMsg; /* Unused parameter */
rc = sqlite3_create_function(db, "readblob", 6, SQLITE_UTF8, 0,
readblobFunc, 0, 0);
if( rc==SQLITE_OK ){
rc = sqlite3_create_function(db, "writeblob", 6, SQLITE_UTF8, 0,
writeblobFunc, 0, 0);
}
return rc;
}
+12
View File
@@ -60,6 +60,13 @@
**
** SELECT name FROM sqlite_btreeinfo
** WHERE type='table' AND NOT hasRowid;
**
** UNUSED, UNTESTED, UNSUPPORTED
**
** This extension exists for information and demonstration purposes
** only. The developers are not aware of any real-world use of this
** extension. The extension has no formal test cases. The developers
** do not actively support it.
*/
#if !defined(SQLITEINT_H)
#include "sqlite3ext.h"
@@ -286,6 +293,11 @@ static int binfoCompute(sqlite3 *db, int pgno, BinfoCursor *pCsr){
pCsr->depth = 1;
while(1){
sqlite3_bind_int(pStmt, 1, pgno);
if( pCsr->depth>25 ){
sqlite3_set_errmsg(db, SQLITE_CORRUPT, "btree nested too deep");
rc = SQLITE_ERROR;
break;
}
rc = sqlite3_step(pStmt);
if( rc!=SQLITE_ROW ){
rc = SQLITE_ERROR;
+3 -3
View File
@@ -516,7 +516,7 @@ static int closureConnect(
(void)pAux;
*ppVtab = 0;
pNew = sqlite3_malloc( sizeof(*pNew) );
pNew = sqlite3_malloc64( sizeof(*pNew) );
if( pNew==0 ) return SQLITE_NOMEM;
rc = SQLITE_NOMEM;
memset(pNew, 0, sizeof(*pNew));
@@ -579,7 +579,7 @@ closureConnectError:
static int closureOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){
closure_vtab *p = (closure_vtab*)pVTab;
closure_cursor *pCur;
pCur = sqlite3_malloc( sizeof(*pCur) );
pCur = sqlite3_malloc64( sizeof(*pCur) );
if( pCur==0 ) return SQLITE_NOMEM;
memset(pCur, 0, sizeof(*pCur));
pCur->pVtab = p;
@@ -638,7 +638,7 @@ static int closureInsertNode(
sqlite3_int64 id, /* The node ID */
int iGeneration /* The generation number for this node */
){
closure_avl *pNew = sqlite3_malloc( sizeof(*pNew) );
closure_avl *pNew = sqlite3_malloc64( sizeof(*pNew) );
if( pNew==0 ) return SQLITE_NOMEM;
memset(pNew, 0, sizeof(*pNew));
pNew->id = id;
+15 -7
View File
@@ -132,7 +132,7 @@ static int completionConnect(
" phase INT HIDDEN" /* Used for debugging only */
")");
if( rc==SQLITE_OK ){
pNew = sqlite3_malloc( sizeof(*pNew) );
pNew = sqlite3_malloc64( sizeof(*pNew) );
*ppVtab = (sqlite3_vtab*)pNew;
if( pNew==0 ) return SQLITE_NOMEM;
memset(pNew, 0, sizeof(*pNew));
@@ -154,7 +154,7 @@ static int completionDisconnect(sqlite3_vtab *pVtab){
*/
static int completionOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor){
completion_cursor *pCur;
pCur = sqlite3_malloc( sizeof(*pCur) );
pCur = sqlite3_malloc64( sizeof(*pCur) );
if( pCur==0 ) return SQLITE_NOMEM;
memset(pCur, 0, sizeof(*pCur));
pCur->db = ((completion_vtab*)p)->db;
@@ -199,6 +199,7 @@ static int completionNext(sqlite3_vtab_cursor *cur){
completion_cursor *pCur = (completion_cursor*)cur;
int eNextPhase = 0; /* Next phase to try if current phase reaches end */
int iCol = -1; /* If >=0, step pCur->pStmt and use the i-th column */
int rc;
pCur->iRowid++;
while( pCur->ePhase!=COMPLETION_EOF ){
switch( pCur->ePhase ){
@@ -237,11 +238,14 @@ static int completionNext(sqlite3_vtab_cursor *cur){
);
zSep = " UNION ";
}
sqlite3_finalize(pS2);
rc = sqlite3_finalize(pS2);
zSql = sqlite3_str_finish(pStr);
if( zSql==0 ) return SQLITE_NOMEM;
sqlite3_prepare_v2(pCur->db, zSql, -1, &pCur->pStmt, 0);
if( rc==SQLITE_OK ){
sqlite3_prepare_v2(pCur->db, zSql, -1, &pCur->pStmt, 0);
}
sqlite3_free(zSql);
if( rc ) return rc;
}
iCol = 0;
eNextPhase = COMPLETION_COLUMNS;
@@ -265,11 +269,14 @@ static int completionNext(sqlite3_vtab_cursor *cur){
);
zSep = " UNION ";
}
sqlite3_finalize(pS2);
rc = sqlite3_finalize(pS2);
zSql = sqlite3_str_finish(pStr);
if( zSql==0 ) return SQLITE_NOMEM;
sqlite3_prepare_v2(pCur->db, zSql, -1, &pCur->pStmt, 0);
if( rc==SQLITE_OK ){
sqlite3_prepare_v2(pCur->db, zSql, -1, &pCur->pStmt, 0);
}
sqlite3_free(zSql);
if( rc ) return rc;
}
iCol = 0;
eNextPhase = COMPLETION_EOF;
@@ -286,9 +293,10 @@ static int completionNext(sqlite3_vtab_cursor *cur){
pCur->szRow = sqlite3_column_bytes(pCur->pStmt, iCol);
}else{
/* When all rows are finished, advance to the next phase */
sqlite3_finalize(pCur->pStmt);
rc = sqlite3_finalize(pCur->pStmt);
pCur->pStmt = 0;
pCur->ePhase = eNextPhase;
if( rc ) return rc;
continue;
}
}
+8
View File
@@ -60,6 +60,10 @@ static void compressFunc(
nIn = sqlite3_value_bytes(argv[0]);
nOut = 13 + nIn + (nIn+999)/1000;
pOut = sqlite3_malloc64( nOut+5 );
if( pOut==0 ){
sqlite3_result_error_nomem(context);
return;
}
for(i=4; i>=0; i--){
x[i] = (nIn >> (7*(4-i)))&0x7f;
}
@@ -99,6 +103,10 @@ static void uncompressFunc(
if( (pIn[i]&0x80)!=0 ){ i++; break; }
}
pOut = sqlite3_malloc64( nOut+1 );
if( pOut==0 ){
sqlite3_result_error_nomem(context);
return;
}
rc = uncompress(pOut, &nOut, &pIn[i], nIn-i);
if( rc==Z_OK ){
sqlite3_result_blob(context, pOut, nOut, sqlite3_free);
+15 -9
View File
@@ -64,6 +64,7 @@ SQLITE_EXTENSION_INIT1
#ifndef SQLITEINT_H
typedef sqlite3_int64 i64;
typedef sqlite3_uint64 u64;
#endif
/* Max size of the error message in a CsvReader */
@@ -128,7 +129,7 @@ static int csv_reader_open(
const char *zData /* ... or use this data */
){
if( zFilename ){
p->zIn = sqlite3_malloc( CSV_INBUFSZ );
p->zIn = sqlite3_malloc64( CSV_INBUFSZ );
if( p->zIn==0 ){
csv_errmsg(p, "out of memory");
return 1;
@@ -221,7 +222,7 @@ static char *csv_read_one_field(CsvReader *p){
}
if( c=='"' ){
int pc, ppc;
int startLine = p->nLine;
i64 startLine = p->nLine;
pc = ppc = 0;
while( 1 ){
c = csv_getc(p);
@@ -325,7 +326,7 @@ typedef struct CsvCursor {
sqlite3_vtab_cursor base; /* Base class. Must be first */
CsvReader rdr; /* The CsvReader object */
char **azVal; /* Value of the current row */
int *aLen; /* Length of each entry */
i64 *aLen; /* Length of each entry */
sqlite3_int64 iRowid; /* The current rowid. Negative for EOF */
} CsvCursor;
@@ -497,7 +498,7 @@ static int csvtabConnect(
CsvTable *pNew = 0; /* The CsvTable object to construct */
int bHeader = -1; /* header= flags. -1 means not seen yet */
int rc = SQLITE_OK; /* Result code from this routine */
int i, j; /* Loop counters */
u64 i, j; /* Loop counters */
#ifdef SQLITE_TEST
int tstFlags = 0; /* Value for testflags=N parameter */
#endif
@@ -516,7 +517,7 @@ static int csvtabConnect(
assert( sizeof(azPValue)==sizeof(azParam) );
memset(&sRdr, 0, sizeof(sRdr));
memset(azPValue, 0, sizeof(azPValue));
for(i=3; i<argc; i++){
for(i=3; i<(u64)argc; i++){
const char *z = argv[i];
const char *zValue;
for(j=0; j<sizeof(azParam)/sizeof(azParam[0]); j++){
@@ -546,6 +547,10 @@ static int csvtabConnect(
if( nCol<=0 ){
csv_errmsg(&sRdr, "column= value must be positive");
goto csvtab_connect_error;
}else if( nCol>sqlite3_limit(db,SQLITE_LIMIT_COLUMN,-1) ){
csv_errmsg(&sRdr, "column= value too big, max %d",
sqlite3_limit(db, SQLITE_LIMIT_COLUMN,-1));
goto csvtab_connect_error;
}
}else
{
@@ -563,7 +568,7 @@ static int csvtabConnect(
){
goto csvtab_connect_error;
}
pNew = sqlite3_malloc( sizeof(*pNew) );
pNew = sqlite3_malloc64( sizeof(*pNew) );
*ppVtab = (sqlite3_vtab*)pNew;
if( pNew==0 ) goto csvtab_connect_oom;
memset(pNew, 0, sizeof(*pNew));
@@ -708,13 +713,14 @@ static int csvtabClose(sqlite3_vtab_cursor *cur){
static int csvtabOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor){
CsvTable *pTab = (CsvTable*)p;
CsvCursor *pCur;
size_t nByte;
nByte = sizeof(*pCur) + (sizeof(char*)+sizeof(int))*pTab->nCol;
sqlite3_int64 nByte = pTab->nCol;
assert( pTab->nCol<32768 );
nByte = sizeof(*pCur) + (sizeof(char*)+sizeof(i64))*nByte;
pCur = sqlite3_malloc64( nByte );
if( pCur==0 ) return SQLITE_NOMEM;
memset(pCur, 0, nByte);
pCur->azVal = (char**)&pCur[1];
pCur->aLen = (int*)&pCur->azVal[pTab->nCol];
pCur->aLen = (i64*)&pCur->azVal[pTab->nCol];
*ppCursor = &pCur->base;
if( csv_reader_open(&pCur->rdr, pTab->zFilename, pTab->zData) ){
csv_xfer_error(pTab, &pCur->rdr);
+27 -17
View File
@@ -31,6 +31,10 @@ SQLITE_EXTENSION_INIT1
#define IsSpace(X) isspace((unsigned char)X)
#endif
#ifndef SQLITE_DECIMAL_MAX_DIGIT
# define SQLITE_DECIMAL_MAX_DIGIT 10000000
#endif
/* A decimal object */
typedef struct Decimal Decimal;
struct Decimal {
@@ -70,7 +74,7 @@ static Decimal *decimalNewFromText(const char *zIn, int n){
int iExp = 0;
if( zIn==0 ) goto new_from_text_failed;
p = sqlite3_malloc( sizeof(*p) );
p = sqlite3_malloc64( sizeof(*p) );
if( p==0 ) goto new_from_text_failed;
p->sign = 0;
p->oom = 0;
@@ -164,9 +168,7 @@ static Decimal *decimalNewFromText(const char *zIn, int n){
for(i=0; i<p->nDigit && p->a[i]==0; i++){}
if( i>=p->nDigit ) p->sign = 0;
}
#if SQLITE_DECIMAL_MAX_DIGIT+0>10
if( p->nDigit>SQLITE_DECIMAL_MAX_DIGIT ) goto new_from_text_failed;
#endif
return p;
new_from_text_failed:
@@ -259,7 +261,7 @@ static void decimal_result(sqlite3_context *pCtx, Decimal *p){
sqlite3_result_null(pCtx);
return;
}
z = sqlite3_malloc64( (sqlite3_int64)p->nDigit+4 );
z = sqlite3_malloc64( (sqlite3_int64)p->nDigit+8 );
if( z==0 ){
sqlite3_result_error_nomem(pCtx);
return;
@@ -297,27 +299,37 @@ static void decimal_result(sqlite3_context *pCtx, Decimal *p){
sqlite3_result_text(pCtx, z, i, sqlite3_free);
}
/* Forward declaration */
static void decimal_expand(Decimal *p, int nDigit, int nFrac);
/*
** Round a decimal value to N significant digits. N must be positive.
*/
static void decimal_round(Decimal *p, int N){
int i;
int nZero;
int nZero; /* Number of leading zeros */
if( N<1 ) return;
if( p==0 ) return;
if( p->nDigit<=N ) return;
for(nZero=0; nZero<p->nDigit && p->a[nZero]==0; nZero++){}
N += nZero;
if( p->nDigit<=N ) return;
if( p->a[N]>4 ){
if( p->a[N]>=5 ){
/* If all leading digits are 9, increase the number of digits
** by adding a new 0 to the front */
for(i=0; i<N && p->a[i]==9; i++){}
if( i==N ){
decimal_expand(p, p->nDigit+1, 0);
if( p->oom ) return;
}
/* Do the rounding */
p->a[N-1]++;
for(i=N-1; i>0 && p->a[i]>9; i--){
p->a[i] = 0;
p->a[i-1]++;
}
if( p->a[0]>9 ){
p->a[0] = 1;
p->nFrac--;
}
assert( p->a[0]<=9 );
}
memset(&p->a[N], 0, p->nDigit - N);
}
@@ -462,18 +474,18 @@ cmp_done:
static void decimal_expand(Decimal *p, int nDigit, int nFrac){
int nAddSig;
int nAddFrac;
signed char *a;
if( p==0 ) return;
nAddFrac = nFrac - p->nFrac;
nAddSig = (nDigit - p->nDigit) - nAddFrac;
if( nAddFrac==0 && nAddSig==0 ) return;
#if SQLITE_DECIMAL_MAX_DIGIT+0>10
if( nDigit+1>SQLITE_DECIMAL_MAX_DIGIT ){ p->oom = 1; return; }
#endif
p->a = sqlite3_realloc64(p->a, nDigit+1);
if( p->a==0 ){
a = sqlite3_realloc64(p->a, nDigit+1);
if( a==0 ){
p->oom = 1;
return;
}
p->a = a;
if( nAddSig ){
memmove(p->a+nAddSig, p->a, p->nDigit);
memset(p->a, 0, nAddSig);
@@ -578,9 +590,7 @@ static void decimalMul(Decimal *pA, Decimal *pB){
sumDigit = pA->nDigit;
sumDigit += pB->nDigit;
sumDigit += 2;
#if SQLITE_DECIMAL_MAX_DIGIT+0>10
if( sumDigit>SQLITE_DECIMAL_MAX_DIGIT ){ pA->oom = 1; return; }
#endif
acc = sqlite3_malloc64( sumDigit );
if( acc==0 ){
pA->oom = 1;
@@ -813,7 +823,7 @@ static void decimalSumStep(
if( p==0 ) return;
if( !p->isInit ){
p->isInit = 1;
p->a = sqlite3_malloc(2);
p->a = sqlite3_malloc64(2);
if( p->a==0 ){
p->oom = 1;
}else{
+847
View File
@@ -0,0 +1,847 @@
/*
** 2026-04-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 extension implements an SQL function:
**
** diskused(X)
**
** Where X is the schema name (typically 'main'). The output is text
** that describes how much filesystem space the various tables and indexes
** of the database consume.
**
** This function is a replacement for the (now deprecated)
** "sqlite3_analyzer" utility program. This function is built
** into the CLI and is used to implement the ".diskused" command there.
*/
#include "sqlite3ext.h"
SQLITE_EXTENSION_INIT1
#include <assert.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
/*
** State information for the analysis
*/
typedef struct DiskUsed DiskUsed;
struct DiskUsed {
sqlite3 *db; /* Database connection */
sqlite3_context *context; /* SQL function context */
sqlite3_str *pOut; /* Write output here */
char *zSU; /* Name of the temp.space_used table */
const char *zSchema; /* Schema to be analyzed */
};
/*
** Free all resources that the DiskUsed object references and
** reset the DiskUsed object.
**
** Call this routine multiple times on the same DiskUsed object
** is a harmless no-op, as long as the memory for the object itself
** has not been freed.
*/
static void diskusedReset(DiskUsed *p){
if( p->zSU ){
char *zSql = sqlite3_mprintf("DROP TABLE temp.%s;", p->zSU);
if( zSql ){
sqlite3_exec(p->db, zSql, 0, 0, 0);
sqlite3_free(zSql);
}
}
sqlite3_str_free(p->pOut);
sqlite3_free(p->zSU);
memset(p, 0, sizeof(*p));
}
/*
** Report an error using formatted text. If zFormat==NULL then report
** an OOM error.
*/
static void diskusedError(DiskUsed *p, const char *zFormat, ...){
char *zErr;
if( zFormat ){
va_list ap;
va_start(ap, zFormat);
zErr = sqlite3_vmprintf(zFormat, ap);
va_end(ap);
}else{
zErr = 0;
}
if( zErr==0 ){
sqlite3_result_error_nomem(p->context);
}else{
sqlite3_result_error(p->context, zErr, -1);
sqlite3_free(zErr);
}
diskusedReset(p);
}
/*
** Prepare and return an SQL statement.
*/
static sqlite3_stmt *diskusedVPrep(DiskUsed *p, const char *zFmt, va_list ap){
char *zSql;
int rc;
sqlite3_stmt *pStmt = 0;
zSql = sqlite3_vmprintf(zFmt, ap);
if( zSql==0 ){ diskusedError(p,0); return 0; }
rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
if( rc ){
diskusedError(p, "SQL parse error: %s\nOriginal SQL: %s",
sqlite3_errmsg(p->db), zSql);
sqlite3_finalize(pStmt);
diskusedReset(p);
pStmt = 0;
}
sqlite3_free(zSql);
return pStmt;
}
static sqlite3_stmt *diskusedPrepare(DiskUsed *p, const char *zFormat, ...){
va_list ap;
sqlite3_stmt *pStmt = 0;
va_start(ap, zFormat);
pStmt = diskusedVPrep(p,zFormat,ap);
va_end(ap);
return pStmt;
}
/*
** If rc is something other than SQLITE_DONE or SQLITE_OK, then report
** an error and return true.
**
** If rc is SQLITE_DONE or SQLITE_OK, then return false.
**
** The prepared statement is closed in either case.
*/
static int diskusedStmtFinish(DiskUsed *p, int rc, sqlite3_stmt *pStmt){
if( rc==SQLITE_DONE ){
rc = SQLITE_OK;
}
if( rc!=SQLITE_OK || (rc = sqlite3_reset(pStmt))!=SQLITE_OK ){
diskusedError(p, "SQL run-time error: %s\nOriginal SQL: %s",
sqlite3_errmsg(p->db), sqlite3_sql(pStmt));
diskusedReset(p);
}
sqlite3_finalize(pStmt);
return rc;
}
/*
** Run SQL. Return the number of errors.
*/
static int diskusedSql(DiskUsed *p, const char *zFormat, ...){
va_list ap;
int rc;
sqlite3_stmt *pStmt = 0;
va_start(ap, zFormat);
pStmt = diskusedVPrep(p,zFormat,ap);
va_end(ap);
if( pStmt==0 ) return 1;
while( (rc = sqlite3_step(pStmt))==SQLITE_ROW ){}
if( rc==SQLITE_DONE ){
rc = SQLITE_OK;
}else{
diskusedError(p, "SQL run-time error: %s\nOriginal SQL: %s",
sqlite3_errmsg(p->db), sqlite3_sql(pStmt));
diskusedReset(p);
}
sqlite3_finalize(pStmt);
return rc;
}
/*
** Run an SQL query that returns an integer. Write that integer
** into *piRes. Return the number of errors.
*/
static int diskusedSqlInt(
DiskUsed *p,
sqlite3_int64 *piRes,
const char *zFormat, ...
){
va_list ap;
int rc;
sqlite3_stmt *pStmt = 0;
va_start(ap, zFormat);
pStmt = diskusedVPrep(p,zFormat,ap);
va_end(ap);
if( pStmt==0 ) return 1;
rc = sqlite3_step(pStmt);
if( rc==SQLITE_ROW ){
*piRes = sqlite3_column_int64(pStmt, 0);
rc = SQLITE_OK;
}else if( rc==SQLITE_DONE ){
rc = SQLITE_OK;
}else{
if( p->db ){
/* p->db is NULL if there was some prior error */
diskusedError(p, "SQL run-time error: %s\nOriginal SQL: %s",
sqlite3_errmsg(p->db), sqlite3_sql(pStmt));
}
diskusedReset(p);
}
sqlite3_finalize(pStmt);
return rc;
}
/*
** Add to the output a title line that contains the text determined
** by the format string. If the output is initially empty, begin
** the title line with "/" so that it forms the beginning of a C-style
** comment. Otherwise begin with a new-line. Always finish with a
** newline.
*/
static void diskusedTitle(DiskUsed *p, const char *zFormat, ...){
char *zFirst;
char *zTitle;
size_t nTitle;
va_list ap;
va_start(ap, zFormat);
zTitle = sqlite3_vmprintf(zFormat, ap);
va_end(ap);
if( zTitle==0 ){
diskusedError(p, 0);
return;
}
zFirst = sqlite3_str_length(p->pOut)==0 ? "/" : "\n*";
nTitle = strlen(zTitle);
if( nTitle>=75 ){
sqlite3_str_appendf(p->pOut, "%s** %z\n\n", zFirst, zTitle);
}else{
int nExtra = 74 - (int)nTitle;
sqlite3_str_appendf(p->pOut, "%s** %z %.*c\n\n", zFirst, zTitle,
nExtra, '*');
}
}
/*
** Add an output line that begins with the zDesc text extended out to
** 50 columns with "." characters, and followed by whatever text is
** described by zFormat.
*/
static void diskusedLine(
DiskUsed *p, /* DiskUsed context */
const char *zDesc, /* Description */
const char *zFormat, /* Argument to the description */
...
){
char *zTxt;
size_t nDesc;
va_list ap;
va_start(ap, zFormat);
zTxt = sqlite3_vmprintf(zFormat, ap);
va_end(ap);
if( zTxt==0 ){
diskusedError(p, 0);
return;
}
nDesc = zDesc ? strlen(zDesc) : 0;
if( nDesc>=50 ){
sqlite3_str_appendf(p->pOut, "%s %z", zDesc, zTxt);
}else{
int nExtra = 50 - (int)nDesc;
sqlite3_str_appendf(p->pOut, "%s%.*c %z", zDesc, nExtra, '.', zTxt);
}
}
/*
** Write a percentage into the output. The number written should show
** two or three significant digits, with the decimal point being the fourth
** character.
*/
static void diskusedPercent(DiskUsed *p, double r){
char zNum[100];
char *zDP;
int nLeadingDigit;
int sz;
sqlite3_snprintf(sizeof(zNum)-5, zNum, r>=10.0 ? "%.3g" :"%.2g", r);
sz = (int)strlen(zNum);
zDP = strchr(zNum, '.');
if( zDP==0 ){
memcpy(zNum+sz,".0",3);
nLeadingDigit = sz;
sz += 2;
}else{
nLeadingDigit = (int)(zDP - zNum);
}
if( nLeadingDigit<3 ){
sqlite3_str_appendchar(p->pOut, 3-nLeadingDigit, ' ');
}
sqlite3_str_append(p->pOut, zNum, sz);
sqlite3_str_append(p->pOut, "%\n", 2);
}
/*
** Create a subreport on a subset of tables and/or indexes.
**
** The title if the subreport is given by zTitle. zWhere is
** a boolean expression that can go in the WHERE clause to select
** the relevant rows of the s.zSU table.
*/
static int diskusedSubreport(
DiskUsed *p, /* DiskUsed context */
char *zTitle, /* Title for this subreport */
char *zWhere, /* WHERE clause for this subreport */
sqlite3_int64 pgsz, /* Database page size */
sqlite3_int64 nPage /* Number of pages in entire database */
){
sqlite3_stmt *pStmt; /* Statement to query p->zSU */
sqlite3_int64 nentry; /* Number of btree entires */
sqlite3_int64 payload; /* Payload in bytes */
sqlite3_int64 ovfl_payload; /* overflow payload in bytes */
sqlite3_int64 mx_payload; /* largest individual payload */
sqlite3_int64 ovfl_cnt; /* Number entries using overflow */
sqlite3_int64 leaf_pages; /* Leaf pages */
sqlite3_int64 int_pages; /* internal pages */
sqlite3_int64 ovfl_pages; /* overflow pages */
sqlite3_int64 leaf_unused; /* unused bytes on leaf pages */
sqlite3_int64 int_unused; /* unused bytes on internal pages */
sqlite3_int64 ovfl_unused; /* unused bytes on overflow pages */
sqlite3_int64 int_cell; /* B-tree entries on internal pages */
sqlite3_int64 depth; /* btree depth */
sqlite3_int64 cnt; /* Number of s.zSU entries that match */
sqlite3_int64 storage; /* Total bytes */
sqlite3_int64 total_pages; /* Total page count */
sqlite3_int64 total_unused; /* Total unused bytes */
sqlite3_int64 total_meta; /* Total metadata */
int rc;
if( zTitle==0 || zWhere==0 ){
diskusedError(p, 0);
return SQLITE_NOMEM;
}
pStmt = diskusedPrepare(p,
"SELECT\n"
" sum(if(is_without_rowid OR is_index,nentry,leaf_entries)),\n" /* 0 */
" sum(payload),\n" /* 1 */
" sum(ovfl_payload),\n" /* 2 */
" max(mx_payload),\n" /* 3 */
" sum(ovfl_cnt),\n" /* 4 */
" sum(leaf_pages),\n" /* 5 */
" sum(int_pages),\n" /* 6 */
" sum(ovfl_pages),\n" /* 7 */
" sum(leaf_unused),\n" /* 8 */
" sum(int_unused),\n" /* 9 */
" sum(ovfl_unused),\n" /* 10 */
" max(depth),\n" /* 11 */
" count(*),\n" /* 12 */
" sum(int_entries)\n" /* 13 */
" FROM temp.%s WHERE %s",
p->zSU, zWhere);
if( pStmt==0 ) return 1;
rc = sqlite3_step(pStmt);
if( rc==SQLITE_ROW ){
diskusedTitle(p, "%s", zTitle);
nentry = sqlite3_column_int64(pStmt, 0);
payload = sqlite3_column_int64(pStmt, 1);
ovfl_payload = sqlite3_column_int64(pStmt, 2);
mx_payload = sqlite3_column_int64(pStmt, 3);
ovfl_cnt = sqlite3_column_int64(pStmt, 4);
leaf_pages = sqlite3_column_int64(pStmt, 5);
int_pages = sqlite3_column_int64(pStmt, 6);
ovfl_pages = sqlite3_column_int64(pStmt, 7);
leaf_unused = sqlite3_column_int64(pStmt, 8);
int_unused = sqlite3_column_int64(pStmt, 9);
ovfl_unused = sqlite3_column_int64(pStmt, 10);
depth = sqlite3_column_int64(pStmt, 11);
cnt = sqlite3_column_int64(pStmt, 12);
int_cell = sqlite3_column_int64(pStmt, 13);
rc = SQLITE_DONE;
total_pages = leaf_pages + int_pages + ovfl_pages;
diskusedLine(p, "Percentage of total database", "%.3g%%\n",
(total_pages*100.0)/(double)nPage);
diskusedLine(p, "Number of entries", "%lld\n", nentry);
storage = total_pages*pgsz;
diskusedLine(p, "Bytes of storage consumed", "%lld\n", storage);
diskusedLine(p, "Bytes of payload", "%-11lld ", payload);
diskusedPercent(p, payload*100.0/(double)storage);
if( ovfl_cnt>0 ){
diskusedLine(p, "Bytes of payload in overflow","%-11lld ",ovfl_payload);
diskusedPercent(p, ovfl_payload*100.0/(double)payload);
}
total_unused = leaf_unused + int_unused + ovfl_unused;
total_meta = storage - payload - total_unused;
diskusedLine(p, "Bytes of metadata","%-11lld ", total_meta);
diskusedPercent(p, total_meta*100.0/(double)storage);
if( cnt==1 ){
diskusedLine(p, "B-tree depth", "%lld\n", depth);
if( int_cell>1 ){
diskusedLine(p, "Average fanout", "%.1f\n",
(double)(int_cell+int_pages)/(double)int_pages);
}
}
if( nentry>0 ){
diskusedLine(p, "Average payload per entry", "%.1f\n",
(double)payload/(double)nentry);
diskusedLine(p, "Average unused bytes per entry", "%.1f\n",
(double)total_unused/(double)nentry);
diskusedLine(p, "Average metadata per entry", "%.1f\n",
(double)total_meta/(double)nentry);
}
diskusedLine(p, "Maximum single-entry payload", "%lld\n", mx_payload);
if( nentry>0 ){
diskusedLine(p, "Entries that use overflow", "%-11lld ", ovfl_cnt);
diskusedPercent(p, ovfl_cnt*100.0/(double)nentry);
}
if( int_pages>0 ){
diskusedLine(p, "Index pages used", "%lld\n", int_pages);
}
diskusedLine(p, "Primary pages used", "%lld\n", leaf_pages);
if( ovfl_cnt ){
diskusedLine(p, "Overflow pages used", "%lld\n", ovfl_pages);
}
diskusedLine(p, "Total pages used", "%lld\n", total_pages);
if( int_pages>0 ){
diskusedLine(p, "Unused bytes on index pages", "%lld\n", int_unused);
}
diskusedLine(p, "Unused bytes on primary pages", "%lld\n", leaf_unused);
if( ovfl_cnt ){
diskusedLine(p, "Unused bytes on overflow pages", "%lld\n", ovfl_unused);
}
diskusedLine(p, "Unused bytes on all pages", "%-11lld ", total_unused);
diskusedPercent(p, total_unused*100.0/(double)storage);
}
return diskusedStmtFinish(p, rc, pStmt);
}
/*
** SQL Function: diskused(SCHEMA)
**
** Analyze the database schema named in the argument. Return text
** containing the space utilization stats.
*/
static void diskusedFunc(
sqlite3_context *context,
int argc,
sqlite3_value **argv
){
int rc;
sqlite3_stmt *pStmt;
int n;
sqlite3_int64 ii;
sqlite3_int64 pgsz;
sqlite3_int64 nPage;
sqlite3_int64 nPageInUse;
sqlite3_int64 nFreeList;
sqlite3_int64 nIndex;
sqlite3_int64 nWORowid;
DiskUsed s;
sqlite3_uint64 r[2];
(void)argc;
memset(&s, 0, sizeof(s));
s.db = sqlite3_context_db_handle(context);
s.context = context;
s.pOut = sqlite3_str_new(0);
if( sqlite3_str_errcode(s.pOut) ){
diskusedError(&s, 0);
return;
}
s.zSchema = (const char*)sqlite3_value_text(argv[0]);
if( s.zSchema==0 ){
s.zSchema = "main";
}else if( sqlite3_strlike("temp",s.zSchema,0)==0 ){
diskusedReset(&s);
sqlite3_result_text(context, "cannot analyze \"temp\"",-1,SQLITE_STATIC);
return;
}
ii = 0;
rc = diskusedSqlInt(&s,&ii,"SELECT 1 FROM pragma_database_list"
" WHERE name=%Q COLLATE nocase",s.zSchema);
if( rc || ii==0 ){
diskusedReset(&s);
sqlite3_result_text(context,"no such database",-1,SQLITE_STATIC);
return;
}
sqlite3_randomness(sizeof(r), &r);
s.zSU = sqlite3_mprintf("diskused%016llx%016llx", r[0], r[1]);
if( s.zSU==0 ){ diskusedError(&s, 0); return; }
/* The s.zSU table contains the data used for the analysis.
** The table name contains 128-bits of randomness to avoid
** collisions with preexisting tables in temp.
*/
rc = diskusedSql(&s,
"CREATE TABLE temp.%s(\n"
" name text, -- A table or index\n"
" tblname text, -- Table that owns name\n"
" is_index boolean, -- TRUE if it is an index\n"
" is_without_rowid boolean, -- TRUE if WITHOUT ROWID table\n"
" nentry int, -- Number of entries in the BTree\n"
" leaf_entries int, -- Number of leaf entries\n"
" depth int, -- Depth of the b-tree\n"
" payload int, -- Total data stored in this table/index\n"
" ovfl_payload int, -- Total data stored on overflow pages\n"
" ovfl_cnt int, -- Number of entries that use overflow\n"
" mx_payload int, -- Maximum payload size\n"
" int_pages int, -- Interior pages used\n"
" leaf_pages int, -- Leaf pages used\n"
" ovfl_pages int, -- Overflow pages used\n"
" int_unused int, -- Unused bytes on interior pages\n"
" leaf_unused int, -- Unused bytes on primary pages\n"
" ovfl_unused int, -- Unused bytes on overflow pages\n"
" int_entries int -- Btree cells on internal pages\n"
");",
s.zSU
);
if( rc ) return;
/* Populate the s.zSU table
*/
rc = diskusedSql(&s,
"WITH\n"
" allidx(idxname) AS (\n"
" SELECT name FROM \"%w\".sqlite_schema WHERE type='index'\n"
" ),\n"
" allobj(allname,tblname,isidx,isworowid) AS (\n"
" SELECT 'sqlite_schema',\n"
" 'sqlite_schema',\n"
" 0,\n"
" 0\n"
" UNION ALL\n"
" SELECT name,\n"
" tbl_name,\n"
" type='index',\n"
" EXISTS(SELECT 1\n"
" FROM pragma_index_list(sqlite_schema.name,%Q)\n"
" WHERE pragma_index_list.origin='pk'\n"
" AND pragma_index_list.name NOT IN allidx)\n"
" FROM \"%w\".sqlite_schema\n"
" )\n"
"INSERT INTO temp.%s\n"
" SELECT\n"
" allname,\n"
" tblname,\n"
" isidx,\n"
" isworowid,\n"
" sum(ncell),\n"
" sum((pagetype='leaf')*ncell),\n"
" max((length(if(path GLOB '*+*','',path))+3)/4),\n"
" sum(payload),\n"
" sum((pagetype='overflow')*payload),\n"
" sum(path GLOB '*+000000'),\n"
" max(mx_payload),\n"
" sum(pagetype='internal'),\n"
" sum(pagetype='leaf'),\n"
" sum(pagetype='overflow'),\n"
" sum((pagetype='internal')*unused),\n"
" sum((pagetype='leaf')*unused),\n"
" sum((pagetype='overflow')*unused),\n"
" sum(if(pagetype='internal',ncell))\n"
" FROM allobj CROSS JOIN dbstat(%Q) \n"
" WHERE dbstat.name=allobj.allname\n"
" GROUP BY allname;\n",
s.zSchema, /* %w.sqlite_schema -- in allidx */
s.zSchema, /* pragma_index_list(...,%Q) */
s.zSchema, /* %w.sqlite_schema */
s.zSU, /* INTO temp.%s */
s.zSchema /* JOIN dbstat(%Q) */
);
if( rc ) return;
nPage = 0;
rc = diskusedSqlInt(&s, &nPage, "PRAGMA \"%w\".page_count", s.zSchema);
if( rc ) return;
if( nPage<=0 ){
/* Very brief reply for an empty database */
diskusedReset(&s);
sqlite3_result_text(context, "empty database", -1, SQLITE_STATIC);
return;
}
/* Begin generating the report */
diskusedTitle(&s, "Database storage utilization report");
pgsz = 0;
rc = diskusedSqlInt(&s, &pgsz, "PRAGMA \"%w\".page_size", s.zSchema);
if( rc ) return;
diskusedLine(&s, "Page size in bytes","%lld\n",pgsz);
diskusedLine(&s, "Pages in the database", "%lld\n", nPage);
nPageInUse = 0;
rc = diskusedSqlInt(&s, &nPageInUse,
"SELECT sum(leaf_pages+int_pages+ovfl_pages) FROM temp.%s", s.zSU);
if( rc ) return;
diskusedLine(&s, "Pages that store data", "%-11lld ", nPageInUse);
diskusedPercent(&s, (nPageInUse*100.0)/(double)nPage);
nFreeList = 0;
rc = diskusedSqlInt(&s, &nFreeList, "PRAGMA \"%w\".freelist_count",s.zSchema);
if( rc ) return;
diskusedLine(&s, "Pages on the freelist", "%-11lld ", nFreeList);
diskusedPercent(&s, (nFreeList*100.0)/(double)nPage);
ii = 0;
rc = diskusedSqlInt(&s, &ii, "PRAGMA \"%w\".auto_vacuum", s.zSchema);
if( rc ) return;
if( ii==0 || nPage<=1 ){
ii = 0;
}else{
double rPtrsPerPage = pgsz/5;
double rAvPage = (nPage-1.0)/(rPtrsPerPage+1.0);
ii = (sqlite3_int64)ceil(rAvPage);
}
diskusedLine(&s, "Pages of auto-vacuum overhead", "%-11lld ", ii);
diskusedPercent(&s, (ii*100.0)/(double)nPage);
ii = 0;
rc = diskusedSqlInt(&s, &ii,
"SELECT count(*)+1 FROM \"%w\".sqlite_schema WHERE type='table'",
s.zSchema);
if( rc ) return;
diskusedLine(&s, "Number of tables", "%lld\n", ii);
nWORowid = 0;
rc = diskusedSqlInt(&s, &nWORowid,
"SELECT count(*) FROM \"%w\".pragma_table_list WHERE wr",
s.zSchema);
if( rc ) return;
if( nWORowid>0 ){
diskusedLine(&s, "Number of WITHOUT ROWID tables", "%lld\n", nWORowid);
diskusedLine(&s, "Number of rowid tables", "%lld\n", ii - nWORowid);
}
nIndex = 0;
rc = diskusedSqlInt(&s, &nIndex,
"SELECT count(*) FROM \"%w\".sqlite_schema WHERE type='index'",
s.zSchema);
if( rc ) return;
diskusedLine(&s, "Number of indexes", "%lld\n", nIndex);
ii = 0;
rc = diskusedSqlInt(&s, &ii,
"SELECT count(*) FROM \"%w\".sqlite_schema"
" WHERE name GLOB 'sqlite_autoindex_*' AND type='index'",
s.zSchema);
if( rc ) return;
diskusedLine(&s, "Number of defined indexes", "%lld\n", nIndex - ii);
diskusedLine(&s, "Number of implied indexes", "%lld\n", ii);
diskusedLine(&s, "Size of the database in bytes", "%lld\n", pgsz*nPage);
ii = 0;
rc = diskusedSqlInt(&s, &ii,
"SELECT sum(payload) FROM temp.%s"
" WHERE NOT is_index AND name NOT LIKE 'sqlite_schema'",
s.zSU);
if( rc ) return;
diskusedLine(&s, "Bytes of payload", "%-11lld ", ii);
diskusedPercent(&s, ii*100.0/(double)(pgsz*nPage));
diskusedTitle(&s, "Page counts for all tables with their indexes");
pStmt = diskusedPrepare(&s,
"SELECT upper(tblname),\n"
" sum(int_pages+leaf_pages+ovfl_pages)\n"
" FROM temp.%s\n"
" WHERE tblname IS NOT NULL\n"
" GROUP BY 1\n"
" ORDER BY 2 DESC, 1;",
s.zSU);
if( pStmt==0 ) return;
while( (rc = sqlite3_step(pStmt))==SQLITE_ROW ){
sqlite3_int64 nn = sqlite3_column_int64(pStmt,1);
diskusedLine(&s, (const char*)sqlite3_column_text(pStmt,0), "%-11lld ", nn);
diskusedPercent(&s, (nn*100.0)/(double)nPage);
}
if( diskusedStmtFinish(&s, rc, pStmt) ) return;
diskusedTitle(&s, "Page counts for all tables and indexes separately");
pStmt = diskusedPrepare(&s,
"SELECT upper(name),\n"
" sum(int_pages+leaf_pages+ovfl_pages)\n"
" FROM temp.%s\n"
" WHERE name IS NOT NULL\n"
" GROUP BY 1\n"
" ORDER BY 2 DESC, 1;",
s.zSU);
if( pStmt==0 ) return;
while( (rc = sqlite3_step(pStmt))==SQLITE_ROW ){
sqlite3_int64 nn = sqlite3_column_int64(pStmt,1);
diskusedLine(&s, (const char*)sqlite3_column_text(pStmt,0), "%-11lld ", nn);
diskusedPercent(&s, (nn*100.0)/(double)nPage);
}
if( diskusedStmtFinish(&s, rc, pStmt) ) return;
rc = diskusedSubreport(&s, "All tables and indexes", "1", pgsz, nPage);
if( rc ) return;
rc = diskusedSubreport(&s, "All tables", "NOT is_index", pgsz, nPage);
if( rc ) return;
if( nWORowid>0 ){
rc = diskusedSubreport(&s, "All WITHOUT ROWID tables", "is_without_rowid",
pgsz, nPage);
if( rc ) return;
rc = diskusedSubreport(&s, "All rowid tables",
"NOT is_without_rowid AND NOT is_index",
pgsz, nPage);
if( rc ) return;
}
rc = diskusedSubreport(&s, "All indexes", "is_index", pgsz, nPage);
if( rc ) return;
pStmt = diskusedPrepare(&s,
"SELECT upper(tblname), tblname, sum(is_index) FROM temp.%s"
" GROUP BY 1 ORDER BY 1",
s.zSU);
if( pStmt==0 ) return;
while( (rc = sqlite3_step(pStmt))==SQLITE_ROW ){
const char *zUpper = (const char*)sqlite3_column_text(pStmt, 0);
const char *zName = (const char*)sqlite3_column_text(pStmt, 1);
int nSubIndex = sqlite3_column_int(pStmt, 2);
if( nSubIndex==0 ){
char *zTitle = sqlite3_mprintf("Table %s", zUpper);
char *zWhere = sqlite3_mprintf("name=%Q", zName);
rc = diskusedSubreport(&s, zTitle, zWhere, pgsz, nPage);
sqlite3_free(zTitle);
sqlite3_free(zWhere);
if( rc ) break;
}else{
sqlite3_stmt *pS2;
char *zTitle = sqlite3_mprintf("Table %s and all its indexes", zUpper);
char *zWhere = sqlite3_mprintf("tblname=%Q", zName);
rc = diskusedSubreport(&s, zTitle, zWhere, pgsz, nPage);
sqlite3_free(zTitle);
sqlite3_free(zWhere);
if( rc ) break;
zTitle = sqlite3_mprintf("Table %s w/o any indexes", zUpper);
zWhere = sqlite3_mprintf("name=%Q", zName);
rc = diskusedSubreport(&s, zTitle, zWhere, pgsz, nPage);
sqlite3_free(zTitle);
sqlite3_free(zWhere);
if( rc ) break;
if( nSubIndex>1 ){
zTitle = sqlite3_mprintf("All indexes of table %s", zUpper);
zWhere = sqlite3_mprintf("tblname=%Q AND is_index", zName);
rc = diskusedSubreport(&s, zTitle, zWhere, pgsz, nPage);
sqlite3_free(zTitle);
sqlite3_free(zWhere);
if( rc ) break;
}
pS2 = diskusedPrepare(&s,
"SELECT name, upper(name) FROM temp.%s"
" WHERE is_index AND tblname=%Q",
s.zSU, zName);
if( pS2==0 ){
rc = SQLITE_NOMEM;
break;
}
while( (rc = sqlite3_step(pS2))==SQLITE_ROW ){
const char *zU = (const char*)sqlite3_column_text(pS2, 1);
const char *zN = (const char*)sqlite3_column_text(pS2, 0);
zTitle = sqlite3_mprintf("Index %s", zU);
zWhere = sqlite3_mprintf("name=%Q", zN);
rc = diskusedSubreport(&s, zTitle, zWhere, pgsz, nPage);
sqlite3_free(zTitle);
sqlite3_free(zWhere);
if( rc ) break;
}
rc = diskusedStmtFinish(&s, rc, pS2);
if( rc ) break;
}
}
if( diskusedStmtFinish(&s, rc, pStmt) ) return;
/* Append SQL statements that will recreate the raw data used for
** the analysis.
*/
diskusedTitle(&s, "Raw data used to generate this report");
sqlite3_str_appendf(s.pOut,
"The following SQL will create a table named \"space_used\" which\n"
"contains most of the information used to generate the report above.\n"
"*/\n"
);
sqlite3_str_appendf(s.pOut,
"BEGIN;\n"
"CREATE TABLE space_used(\n"
" name text, -- A table or index\n" /* 0 */
" tblname text, -- Table that owns name\n" /* 1 */
" is_index boolean, -- TRUE if it is an index\n" /* 2 */
" is_without_rowid boolean, -- TRUE if WITHOUT ROWID table\n" /* 3 */
" nentry int, -- Number of entries in the BTree\n" /* 4 */
" leaf_entries int, -- Number of leaf entries\n" /* 5 */
" depth int, -- Depth of the b-tree\n" /* 6 */
" payload int, -- Total data in this table/index\n" /* 7 */
" ovfl_payload int, -- Total data on overflow pages\n" /* 8 */
" ovfl_cnt int, -- Entries that use overflow\n" /* 9 */
" mx_payload int, -- Maximum payload size\n" /* 10 */
" int_pages int, -- Interior pages used\n" /* 11 */
" leaf_pages int, -- Leaf pages used\n" /* 12 */
" ovfl_pages int, -- Overflow pages used\n" /* 13 */
" int_unused int, -- Unused bytes on interior pages\n" /* 14 */
" leaf_unused int, -- Unused bytes on primary pages\n" /* 15 */
" ovfl_unused int, -- Unused bytes on overflow pages\n" /* 16 */
" int_entries int -- B-tree entries on internal pages\n"/* 17 */
");\n"
"INSERT INTO space_used VALUES\n"
);
pStmt = diskusedPrepare(&s,
"SELECT quote(name), quote(tblname),\n" /* 0..1 */
" is_index, is_without_rowid, nentry, leaf_entries,\n" /* 2..5 */
" depth, payload, ovfl_payload, ovfl_cnt, mx_payload,\n" /* 6..10 */
" int_pages, leaf_pages, ovfl_pages, int_unused,\n" /* 11..14 */
" leaf_unused, ovfl_unused, int_entries\n" /* 15..17 */
" FROM temp.%s;",
s.zSU);
if( pStmt==0 ) return;
n = 0;
while( (rc = sqlite3_step(pStmt))==SQLITE_ROW ){
if( n++ ) sqlite3_str_appendf(s.pOut,",\n");
sqlite3_str_appendf(s.pOut,
" (%s,%s,%lld,%lld,%lld,%lld,%lld,%lld,%lld,"
"%lld,%lld,%lld,%lld,%lld,%lld,%lld,%lld,%lld)",
sqlite3_column_text(pStmt, 0),
sqlite3_column_text(pStmt, 1),
sqlite3_column_int64(pStmt, 2),
sqlite3_column_int64(pStmt, 3),
sqlite3_column_int64(pStmt, 4),
sqlite3_column_int64(pStmt, 5),
sqlite3_column_int64(pStmt, 6),
sqlite3_column_int64(pStmt, 7),
sqlite3_column_int64(pStmt, 8),
sqlite3_column_int64(pStmt, 9),
sqlite3_column_int64(pStmt, 10),
sqlite3_column_int64(pStmt, 11),
sqlite3_column_int64(pStmt, 12),
sqlite3_column_int64(pStmt, 13),
sqlite3_column_int64(pStmt, 14),
sqlite3_column_int64(pStmt, 15),
sqlite3_column_int64(pStmt, 16),
sqlite3_column_int64(pStmt, 17));
}
if( rc!=SQLITE_DONE ){
diskusedError(&s, "SQL run-time error: %s\nSQL: %s",
sqlite3_errmsg(s.db), sqlite3_sql(pStmt));
sqlite3_finalize(pStmt);
return;
}
sqlite3_str_appendf(s.pOut,";\nCOMMIT;");
sqlite3_finalize(pStmt);
if( sqlite3_str_length(s.pOut) ){
sqlite3_result_text(context, sqlite3_str_finish(s.pOut), -1,
sqlite3_free);
s.pOut = 0;
}
diskusedReset(&s);
}
#ifdef _WIN32
__declspec(dllexport)
#endif
int sqlite3_diskused_init(
sqlite3 *db,
char **pzErrMsg,
const sqlite3_api_routines *pApi
){
int rc = SQLITE_OK;
SQLITE_EXTENSION_INIT2(pApi);
(void)pzErrMsg; /* Unused parameter */
rc = sqlite3_create_function(db, "diskused", 1,
SQLITE_UTF8|SQLITE_INNOCUOUS,
0, diskusedFunc, 0, 0);
return rc;
}
+2 -2
View File
@@ -92,7 +92,7 @@ static int explainConnect(
rc = sqlite3_declare_vtab(db,
"CREATE TABLE x(addr,opcode,p1,p2,p3,p4,p5,comment,sql HIDDEN)");
if( rc==SQLITE_OK ){
pNew = sqlite3_malloc( sizeof(*pNew) );
pNew = sqlite3_malloc64( sizeof(*pNew) );
*ppVtab = (sqlite3_vtab*)pNew;
if( pNew==0 ) return SQLITE_NOMEM;
memset(pNew, 0, sizeof(*pNew));
@@ -114,7 +114,7 @@ static int explainDisconnect(sqlite3_vtab *pVtab){
*/
static int explainOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor){
explain_cursor *pCur;
pCur = sqlite3_malloc( sizeof(*pCur) );
pCur = sqlite3_malloc64( sizeof(*pCur) );
if( pCur==0 ) return SQLITE_NOMEM;
memset(pCur, 0, sizeof(*pCur));
pCur->db = ((explain_vtab*)p)->db;
+68 -16
View File
@@ -73,11 +73,6 @@
** $path is a relative path, then $path is interpreted relative to $dir.
** And the paths returned in the "name" column of the table are also
** relative to directory $dir.
**
** Notes on building this extension for Windows:
** Unless linked statically with the SQLite library, a preprocessor
** symbol, FILEIO_WIN32_DLL, must be #define'd to create a stand-alone
** DLL form of this extension for WIN32. See its use below for details.
*/
#include "sqlite3ext.h"
SQLITE_EXTENSION_INIT1
@@ -102,8 +97,6 @@ SQLITE_EXTENSION_INIT1
# define STRUCT_STAT struct _stat
# define chmod(path,mode) fileio_chmod(path,mode)
# define mkdir(path,mode) fileio_mkdir(path)
extern LPWSTR sqlite3_win32_utf8_to_unicode(const char*);
extern char *sqlite3_win32_unicode_to_utf8(LPCWSTR);
#endif
#include <time.h>
#include <errno.h>
@@ -130,13 +123,69 @@ SQLITE_EXTENSION_INIT1
#define FSDIR_COLUMN_PATH 5 /* Path to top of search */
#define FSDIR_COLUMN_DIR 6 /* Path is relative to this directory */
#ifdef _WIN32
/*
** Convert a UTF-8 string to Microsoft Unicode.
**
** Space to hold the returned string is obtained from sqlite3_malloc().
*/
static wchar_t *winUtf8To16(const char *zText){
int nChar;
wchar_t *zWideText;
nChar = MultiByteToWideChar(CP_UTF8, 0, zText, -1, NULL, 0);
if( nChar==0 ){
return 0;
}
zWideText = sqlite3_malloc64(nChar*sizeof(WCHAR) );
if( zWideText==0 ){
return 0;
}
nChar = MultiByteToWideChar(CP_UTF8, 0, zText, -1, zWideText,
nChar);
if( nChar==0 ){
sqlite3_free(zWideText);
zWideText = 0;
}
return zWideText;
}
#endif /* _WIN32 */
#ifdef _WIN32
/*
** Convert a Microsoft Unicode string to UTF-8.
**
** Space to hold the returned string is obtained from sqlite3_malloc().
*/
static char *winUtf16To8(wchar_t *zWideText){
int nByte;
char *zText;
nByte = WideCharToMultiByte(CP_UTF8, 0, zWideText, -1, 0, 0, 0, 0);
if( nByte == 0 ){
return 0;
}
zText = sqlite3_malloc64( nByte );
if( zText==0 ){
return 0;
}
nByte = WideCharToMultiByte(CP_UTF8, 0, zWideText, -1, zText, nByte,
0, 0);
if( nByte == 0 ){
sqlite3_free(zText);
zText = 0;
}
return zText;
}
#endif /* _WIN32 */
/*
** UTF8 chmod() function for Windows
*/
#if defined(_WIN32) || defined(WIN32)
static int fileio_chmod(const char *zPath, int pmode){
int rc;
wchar_t *b1 = sqlite3_win32_utf8_to_unicode(zPath);
wchar_t *b1 = winUtf8To16(zPath);
if( b1==0 ) return -1;
rc = _wchmod(b1, pmode);
sqlite3_free(b1);
@@ -150,7 +199,7 @@ static int fileio_chmod(const char *zPath, int pmode){
#if defined(_WIN32) || defined(WIN32)
static int fileio_mkdir(const char *zPath){
int rc;
wchar_t *b1 = sqlite3_win32_utf8_to_unicode(zPath);
wchar_t *b1 = winUtf8To16(zPath);
if( b1==0 ) return -1;
rc = _wmkdir(b1);
sqlite3_free(b1);
@@ -277,7 +326,7 @@ static int fileStat(
){
#if defined(_WIN32)
int rc;
wchar_t *b1 = sqlite3_win32_utf8_to_unicode(zPath);
wchar_t *b1 = winUtf8To16(zPath);
if( b1==0 ) return 1;
rc = _wstat(b1, pStatBuf);
if( rc==0 ){
@@ -430,14 +479,13 @@ static int writeFile(
LONGLONG intervals;
HANDLE hFile;
LPWSTR zUnicodeName;
extern LPWSTR sqlite3_win32_utf8_to_unicode(const char*);
GetSystemTime(&currentTime);
SystemTimeToFileTime(&currentTime, &lastAccess);
intervals = (mtime*10000000) + 116444736000000000;
lastWrite.dwLowDateTime = (DWORD)intervals;
lastWrite.dwHighDateTime = intervals >> 32;
zUnicodeName = sqlite3_win32_utf8_to_unicode(zFile);
zUnicodeName = winUtf8To16(zFile);
if( zUnicodeName==0 ){
return 1;
}
@@ -618,7 +666,7 @@ static int fsdirConnect(
(void)pzErr;
rc = sqlite3_declare_vtab(db, "CREATE TABLE x" FSDIR_SCHEMA);
if( rc==SQLITE_OK ){
pNew = (fsdir_tab*)sqlite3_malloc( sizeof(*pNew) );
pNew = (fsdir_tab*)sqlite3_malloc64( sizeof(*pNew) );
if( pNew==0 ) return SQLITE_NOMEM;
memset(pNew, 0, sizeof(*pNew));
sqlite3_vtab_config(db, SQLITE_VTAB_DIRECTONLY);
@@ -641,7 +689,7 @@ static int fsdirDisconnect(sqlite3_vtab *pVtab){
static int fsdirOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor){
fsdir_cursor *pCur;
(void)p;
pCur = sqlite3_malloc( sizeof(*pCur) );
pCur = sqlite3_malloc64( sizeof(*pCur) );
if( pCur==0 ) return SQLITE_NOMEM;
memset(pCur, 0, sizeof(*pCur));
pCur->iLvl = -1;
@@ -1095,12 +1143,12 @@ static char *portable_realpath(const char *zPath){
if( zPath==0 ) return 0;
zPath16 = sqlite3_win32_utf8_to_unicode(zPath);
zPath16 = winUtf8To16(zPath);
if( zPath16==0 ) return 0;
z = _wfullpath(NULL, zPath16, 0);
sqlite3_free(zPath16);
if( z ){
zOut = sqlite3_win32_unicode_to_utf8(z);
zOut = winUtf16To8(z);
free(z);
}
return zOut;
@@ -1117,6 +1165,9 @@ static char *portable_realpath(const char *zPath){
** The file or directory X is not required to exist. The answer is formed
** by calling system realpath() on the prefix of X that does exist and
** appending the tail of X that does not (yet) exist.
**
** FIXME: This routine sometimes returns NULL rather than raising
** an SQLITE_NOMEM error if an OOM is encountered.
*/
static void realpathFunc(
sqlite3_context *context,
@@ -1139,6 +1190,7 @@ static void realpathFunc(
if( zPath==0 ) return;
if( zPath[0]==0 ) zPath = ".";
zCopy = sqlite3_mprintf("%s",zPath);
if( zCopy==0 ) return;
len = strlen(zCopy);
while( len>1 && (zCopy[len-1]=='/' || (isWin && zCopy[len-1]=='\\')) ){
len--;
+43 -18
View File
@@ -29,6 +29,17 @@
** RBU does not use this extension directly. Rather, this extension is
** provided as a convenience to developers who want to analyze RBU files
** that contain deltas.
**
** Typical build commands assuming
**
** DIR=ext/misc
* NAME=fossildelta
**
** First run "make sqlite3ext.h" then:
**
** linux: gcc -shared -I. -fPIC -o $NAME.so $DIR/$NAME.c
** OS-X: gcc -dynamiclib -fPIC -I. -o $NAME.dylib $DIR/$NAME.c
** Win11: cl -I. $DIR/$NAME.c -link -dll -out:$NAME.dll
*/
#include <string.h>
#include <assert.h>
@@ -43,6 +54,7 @@ SQLITE_EXTENSION_INIT1
*/
typedef unsigned int u32;
typedef sqlite3_uint64 u64;
typedef sqlite3_int64 i64;
/*
** Must be a 16-bit value
@@ -167,16 +179,26 @@ static unsigned int deltaGetInt(const char **pz, int *pLen){
25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, 36,
-1, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, -1, -1, -1, 63, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
};
unsigned int v = 0;
int c;
unsigned char *z = (unsigned char*)*pz;
unsigned char *zStart = z;
while( (c = zValue[0x7f&*(z++)])>=0 ){
v = (v<<6) + c;
unsigned char *zEnd = z + (*pLen);
while( z<zEnd && (c = zValue[*z])>=0 ){
v = (v<<6) + c;
z++;
}
z--;
*pLen -= z - zStart;
*pLen -= (int)(z - (unsigned char*)*pz);
*pz = (char*)z;
return v;
}
@@ -266,7 +288,8 @@ static unsigned int checksum(const char *zIn, size_t N){
** The delta string will be NUL-terminated, but it might also contain
** embedded NUL characters if either the zSrc or zOut files are
** binary. This function returns the length of the delta string
** in bytes, excluding the final NUL terminator character.
** in bytes, excluding the final NUL terminator character. It returns
** 0 if an OOM occurs.
**
** Output Format:
**
@@ -358,6 +381,7 @@ static int delta_create(
*/
nHash = lenSrc/NHASH;
collide = sqlite3_malloc64( (sqlite3_int64)nHash*2*sizeof(int) );
if( collide==0 ) return 0;
memset(collide, -1, nHash*2*sizeof(int));
landmark = &collide[nHash];
for(i=0; i<lenSrc-NHASH; i+=NHASH){
@@ -508,7 +532,7 @@ static int delta_create(
static int delta_output_size(const char *zDelta, int lenDelta){
int size;
size = deltaGetInt(&zDelta, &lenDelta);
if( *zDelta!='\n' ){
if( lenDelta<=0 || *zDelta!='\n' ){
/* ERROR: size integer not terminated by "\n" */
return -1;
}
@@ -550,7 +574,7 @@ static int delta_apply(
#endif
limit = deltaGetInt(&zDelta, &lenDelta);
if( *zDelta!='\n' ){
if( lenDelta<=0 || *zDelta!='\n' ){
/* ERROR: size integer not terminated by "\n" */
return -1;
}
@@ -558,6 +582,7 @@ static int delta_apply(
while( *zDelta && lenDelta>0 ){
unsigned int cnt, ofst;
cnt = deltaGetInt(&zDelta, &lenDelta);
if( lenDelta<=0 ) return -1;
switch( zDelta[0] ){
case '@': {
zDelta++; lenDelta--;
@@ -769,11 +794,11 @@ struct deltaparsevtab_vtab {
struct deltaparsevtab_cursor {
sqlite3_vtab_cursor base; /* Base class - must be first */
char *aDelta; /* The delta being parsed */
int nDelta; /* Number of bytes in the delta */
int iCursor; /* Current cursor location */
i64 iCursor; /* Current cursor location */
i64 iNext; /* Next cursor value */
i64 nDelta; /* Number of bytes in the delta */
int eOp; /* Name of current operator */
unsigned int a1, a2; /* Arguments to current operator */
int iNext; /* Next cursor value */
};
/* Operator names:
@@ -843,7 +868,7 @@ static int deltaparsevtabDisconnect(sqlite3_vtab *pVtab){
*/
static int deltaparsevtabOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor){
deltaparsevtab_cursor *pCur;
pCur = sqlite3_malloc( sizeof(*pCur) );
pCur = sqlite3_malloc64( sizeof(*pCur) );
if( pCur==0 ) return SQLITE_NOMEM;
memset(pCur, 0, sizeof(*pCur));
*ppCursor = &pCur->base;
@@ -877,7 +902,7 @@ static int deltaparsevtabNext(sqlite3_vtab_cursor *cur){
}
z = pCur->aDelta + pCur->iCursor;
pCur->a1 = deltaGetInt(&z, &i);
switch( z[0] ){
switch( i>0 ? z[0] : 0 ){
case '@': {
z++;
if( pCur->iNext>=pCur->nDelta ){
@@ -887,14 +912,14 @@ static int deltaparsevtabNext(sqlite3_vtab_cursor *cur){
}
pCur->a2 = deltaGetInt(&z, &i);
pCur->eOp = DELTAPARSE_OP_COPY;
pCur->iNext = (int)(&z[1] - pCur->aDelta);
pCur->iNext = (i64)(&z[1] - pCur->aDelta);
break;
}
case ':': {
z++;
pCur->a2 = (unsigned int)(z - pCur->aDelta);
pCur->eOp = DELTAPARSE_OP_INSERT;
pCur->iNext = (int)(&z[pCur->a1] - pCur->aDelta);
pCur->iNext = (i64)(&z[pCur->a1] - pCur->aDelta);
break;
}
case ';': {
@@ -938,7 +963,7 @@ static int deltaparsevtabColumn(
if( pCur->eOp==DELTAPARSE_OP_COPY ){
sqlite3_result_int(ctx, pCur->a2);
}else if( pCur->eOp==DELTAPARSE_OP_INSERT ){
if( pCur->a2 + pCur->a1 > pCur->nDelta ){
if( (i64)pCur->a2 + (i64)pCur->a1 > pCur->nDelta ){
sqlite3_result_zeroblob(ctx, pCur->a1);
}else{
sqlite3_result_blob(ctx, pCur->aDelta+pCur->a2, pCur->a1,
@@ -1007,14 +1032,14 @@ static int deltaparsevtabFilter(
a = pCur->aDelta;
pCur->eOp = DELTAPARSE_OP_SIZE;
pCur->a1 = deltaGetInt(&a, &i);
if( a[0]!='\n' ){
if( i<=0 || a[0]!='\n' ){
pCur->eOp = DELTAPARSE_OP_ERROR;
pCur->a1 = pCur->a2 = 0;
pCur->iNext = pCur->nDelta;
return SQLITE_OK;
}
a++;
pCur->iNext = (unsigned int)(a - pCur->aDelta);
pCur->iNext = (i64)(a - pCur->aDelta);
return SQLITE_OK;
}
+2 -2
View File
@@ -556,7 +556,7 @@ static int fuzzerConnect(
static int fuzzerOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){
fuzzer_vtab *p = (fuzzer_vtab*)pVTab;
fuzzer_cursor *pCur;
pCur = sqlite3_malloc( sizeof(*pCur) );
pCur = sqlite3_malloc64( sizeof(*pCur) );
if( pCur==0 ) return SQLITE_NOMEM;
memset(pCur, 0, sizeof(*pCur));
pCur->pVtab = p;
@@ -622,7 +622,7 @@ static int fuzzerRender(
n = pStem->nBasis + pRule->nTo - pRule->nFrom;
if( (*pnBuf)<n+1 ){
(*pzBuf) = sqlite3_realloc((*pzBuf), n+100);
(*pzBuf) = sqlite3_realloc64((*pzBuf), n+100);
if( (*pzBuf)==0 ) return SQLITE_NOMEM;
(*pnBuf) = n+100;
}
+2 -2
View File
@@ -85,7 +85,7 @@ static int memstatConnect(
rc = sqlite3_declare_vtab(db,"CREATE TABLE x(name,schema,value,hiwtr)");
if( rc==SQLITE_OK ){
pNew = sqlite3_malloc( sizeof(*pNew) );
pNew = sqlite3_malloc64( sizeof(*pNew) );
*ppVtab = (sqlite3_vtab*)pNew;
if( pNew==0 ) return SQLITE_NOMEM;
memset(pNew, 0, sizeof(*pNew));
@@ -107,7 +107,7 @@ static int memstatDisconnect(sqlite3_vtab *pVtab){
*/
static int memstatOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor){
memstat_cursor *pCur;
pCur = sqlite3_malloc( sizeof(*pCur) );
pCur = sqlite3_malloc64( sizeof(*pCur) );
if( pCur==0 ) return SQLITE_NOMEM;
memset(pCur, 0, sizeof(*pCur));
pCur->db = ((memstat_vtab*)p)->db;
+37 -37
View File
@@ -340,45 +340,45 @@ static void percentSort(double *a, unsigned int n){
int iGt; /* Entries at or after a[iGt] are greater than rPivot */
int i; /* Loop counter */
double rPivot; /* The pivot value */
assert( n>=2 );
if( a[0]>a[n-1] ){
SWAP_DOUBLE(a[0],a[n-1])
}
if( n==2 ) return;
iGt = n-1;
i = n/2;
if( a[0]>a[i] ){
SWAP_DOUBLE(a[0],a[i])
}else if( a[i]>a[iGt] ){
SWAP_DOUBLE(a[i],a[iGt])
}
if( n==3 ) return;
rPivot = a[i];
iLt = i = 1;
do{
if( a[i]<rPivot ){
if( i>iLt ) SWAP_DOUBLE(a[i],a[iLt])
iLt++;
i++;
}else if( a[i]>rPivot ){
do{
iGt--;
}while( iGt>i && a[iGt]>rPivot );
SWAP_DOUBLE(a[i],a[iGt])
}else{
i++;
while( n>=2 ){
if( a[0]>a[n-1] ){
SWAP_DOUBLE(a[0],a[n-1])
}
if( n==2 ) return;
iGt = n-1;
i = n/2;
if( a[0]>a[i] ){
SWAP_DOUBLE(a[0],a[i])
}else if( a[i]>a[iGt] ){
SWAP_DOUBLE(a[i],a[iGt])
}
if( n==3 ) return;
rPivot = a[i];
iLt = i = 1;
do{
if( a[i]<rPivot ){
if( i>iLt ) SWAP_DOUBLE(a[i],a[iLt])
iLt++;
i++;
}else if( a[i]>rPivot ){
do{
iGt--;
}while( iGt>i && a[iGt]>rPivot );
SWAP_DOUBLE(a[i],a[iGt])
}else{
i++;
}
}while( i<iGt );
if( iLt>n/2 ){
if( n-iGt>=2 ) percentSort(a+iGt, n-iGt);
n = iLt;
}else{
if( iLt>=2 ) percentSort(a, iLt);
a += iGt;
n -= iGt;
}
}while( i<iGt );
if( iLt>=2 ) percentSort(a, iLt);
if( n-iGt>=2 ) percentSort(a+iGt, n-iGt);
/* Uncomment for testing */
#if 0
for(i=0; i<n-1; i++){
assert( a[i]<=a[i+1] );
}
#endif
}
+7 -3
View File
@@ -75,7 +75,7 @@ static int prefixesConnect(
"CREATE TABLE prefixes(prefix TEXT, original_string TEXT HIDDEN)"
);
if( rc==SQLITE_OK ){
pNew = sqlite3_malloc( sizeof(*pNew) );
pNew = sqlite3_malloc64( sizeof(*pNew) );
*ppVtab = (sqlite3_vtab*)pNew;
if( pNew==0 ) return SQLITE_NOMEM;
memset(pNew, 0, sizeof(*pNew));
@@ -98,7 +98,7 @@ static int prefixesDisconnect(sqlite3_vtab *pVtab){
*/
static int prefixesOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor){
prefixes_cursor *pCur;
pCur = sqlite3_malloc( sizeof(*pCur) );
pCur = sqlite3_malloc64( sizeof(*pCur) );
if( pCur==0 ) return SQLITE_NOMEM;
memset(pCur, 0, sizeof(*pCur));
*ppCursor = &pCur->base;
@@ -289,10 +289,14 @@ static void prefixLengthFunc(
int nL = sqlite3_value_bytes(apVal[0]);
int nR = sqlite3_value_bytes(apVal[1]);
int i;
if( zL==0 || zR==0 ){
sqlite3_result_int(ctx, 0);
return;
}
nByte = (nL > nR ? nL : nR);
for(i=0; i<nByte; i++){
if( zL[i]!=zR[i] ) break;
if( zL[i]==0 || zL[i]!=zR[i] ) break;
if( (zL[i] & 0xC0)!=0x80 ) nRet++;
}
+3 -3
View File
@@ -152,7 +152,7 @@ static int qpvtabConnect(
#define QPVTAB_FLAGS 11
#define QPVTAB_NONE 12
if( rc==SQLITE_OK ){
pNew = sqlite3_malloc( sizeof(*pNew) );
pNew = sqlite3_malloc64( sizeof(*pNew) );
*ppVtab = (sqlite3_vtab*)pNew;
if( pNew==0 ) return SQLITE_NOMEM;
memset(pNew, 0, sizeof(*pNew));
@@ -174,7 +174,7 @@ static int qpvtabDisconnect(sqlite3_vtab *pVtab){
*/
static int qpvtabOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor){
qpvtab_cursor *pCur;
pCur = sqlite3_malloc( sizeof(*pCur) );
pCur = sqlite3_malloc64( sizeof(*pCur) );
if( pCur==0 ) return SQLITE_NOMEM;
memset(pCur, 0, sizeof(*pCur));
*ppCursor = &pCur->base;
@@ -363,7 +363,7 @@ static int qpvtabBestIndex(
}
sqlite3_str_appendf(pStr,"aConstraint,%d,%s,%d,%d,",
i,
azColname[iCol],
iCol>=0 ? azColname[iCol] : "rowid",
op,
pIdxInfo->aConstraint[i].usable);
pVal = 0;
+9 -10
View File
@@ -676,7 +676,7 @@ static const char *re_compile(
int i, j;
*ppRe = 0;
pRe = sqlite3_malloc( sizeof(*pRe) );
pRe = sqlite3_malloc64( sizeof(*pRe) );
if( pRe==0 ){
return "out of memory";
}
@@ -828,7 +828,6 @@ static void re_bytecode_func(
int i;
int n;
char *z;
(void)argc;
static const char *ReOpName[] = {
"EOF",
"MATCH",
@@ -851,6 +850,7 @@ static void re_bytecode_func(
"ATSTART",
};
(void)argc;
zPattern = (const char*)sqlite3_value_text(argv[0]);
if( zPattern==0 ) return;
zErr = re_compile(&pRe, zPattern, re_maxnfa(re_maxlen(context)),
@@ -865,7 +865,6 @@ static void re_bytecode_func(
return;
}
pStr = sqlite3_str_new(0);
if( pStr==0 ) goto re_bytecode_func_err;
if( pRe->nInit>0 ){
sqlite3_str_appendf(pStr, "INIT ");
for(i=0; i<pRe->nInit; i++){
@@ -877,15 +876,15 @@ static void re_bytecode_func(
sqlite3_str_appendf(pStr, "%-8s %4d\n",
ReOpName[(unsigned char)pRe->aOp[i]], pRe->aArg[i]);
}
if( sqlite3_str_errcode(pStr)==SQLITE_NOMEM ){
sqlite3_str_finish(pStr);
re_free(pRe);
sqlite3_result_error_nomem(context);
return;
}
n = sqlite3_str_length(pStr);
z = sqlite3_str_finish(pStr);
if( n==0 ){
sqlite3_free(z);
}else{
sqlite3_result_text(context, z, n-1, sqlite3_free);
}
re_bytecode_func_err:
sqlite3_result_text(context, z, n-1, sqlite3_free);
re_free(pRe);
}
-610
View File
@@ -1,610 +0,0 @@
/*
** 2016-05-05
**
** 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 a utility function (and a utility program) that
** makes a copy of an SQLite database while simultaneously zeroing out all
** deleted content.
**
** Normally (when PRAGMA secure_delete=OFF, which is the default) when SQLite
** deletes content, it does not overwrite the deleted content but rather marks
** the region of the file that held that content as being reusable. This can
** cause deleted content to recoverable from the database file. This stale
** content is removed by the VACUUM command, but VACUUM can be expensive for
** large databases. When in PRAGMA secure_delete=ON mode, the deleted content
** is zeroed, but secure_delete=ON has overhead as well.
**
** This utility attempts to make a copy of a complete SQLite database where
** all of the deleted content is zeroed out in the copy, and it attempts to
** do so while being faster than running VACUUM.
**
** Usage:
**
** int sqlite3_scrub_backup(
** const char *zSourceFile, // Source database filename
** const char *zDestFile, // Destination database filename
** char **pzErrMsg // Write error message here
** );
**
** Simply call the API above specifying the filename of the source database
** and the name of the backup copy. The source database must already exist
** and can be in active use. (A read lock is held during the backup.) The
** destination file should not previously exist. If the pzErrMsg parameter
** is non-NULL and if an error occurs, then an error message might be written
** into memory obtained from sqlite3_malloc() and *pzErrMsg made to point to
** that error message. But if the error is an OOM, the error might not be
** reported. The routine always returns non-zero if there is an error.
**
** If compiled with -DSCRUB_STANDALONE then a main() procedure is added and
** this file becomes a standalone program that can be run as follows:
**
** ./sqlite3scrub SOURCE DEST
*/
#include "sqlite3.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
typedef struct ScrubState ScrubState;
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned int u32;
/* State information for a scrub-and-backup operation */
struct ScrubState {
const char *zSrcFile; /* Name of the source file */
const char *zDestFile; /* Name of the destination file */
int rcErr; /* Error code */
char *zErr; /* Error message text */
sqlite3 *dbSrc; /* Source database connection */
sqlite3_file *pSrc; /* Source file handle */
sqlite3 *dbDest; /* Destination database connection */
sqlite3_file *pDest; /* Destination file handle */
u32 szPage; /* Page size */
u32 szUsable; /* Usable bytes on each page */
u32 nPage; /* Number of pages */
u32 iLastPage; /* Page number of last page written so far*/
u8 *page1; /* Content of page 1 */
};
/* Store an error message */
static void scrubBackupErr(ScrubState *p, const char *zFormat, ...){
va_list ap;
sqlite3_free(p->zErr);
va_start(ap, zFormat);
p->zErr = sqlite3_vmprintf(zFormat, ap);
va_end(ap);
if( p->rcErr==0 ) p->rcErr = SQLITE_ERROR;
}
/* Allocate memory to hold a single page of content */
static u8 *scrubBackupAllocPage(ScrubState *p){
u8 *pPage;
if( p->rcErr ) return 0;
pPage = sqlite3_malloc( p->szPage );
if( pPage==0 ) p->rcErr = SQLITE_NOMEM;
return pPage;
}
/* Read a page from the source database into memory. Use the memory
** provided by pBuf if not NULL or allocate a new page if pBuf==NULL.
*/
static u8 *scrubBackupRead(ScrubState *p, int pgno, u8 *pBuf){
int rc;
sqlite3_int64 iOff;
u8 *pOut = pBuf;
if( p->rcErr ) return 0;
if( pOut==0 ){
pOut = scrubBackupAllocPage(p);
if( pOut==0 ) return 0;
}
iOff = (pgno-1)*(sqlite3_int64)p->szPage;
rc = p->pSrc->pMethods->xRead(p->pSrc, pOut, p->szPage, iOff);
if( rc!=SQLITE_OK ){
if( pBuf==0 ) sqlite3_free(pOut);
pOut = 0;
scrubBackupErr(p, "read failed for page %d", pgno);
p->rcErr = SQLITE_IOERR;
}
return pOut;
}
/* Write a page to the destination database */
static void scrubBackupWrite(ScrubState *p, int pgno, const u8 *pData){
int rc;
sqlite3_int64 iOff;
if( p->rcErr ) return;
iOff = (pgno-1)*(sqlite3_int64)p->szPage;
rc = p->pDest->pMethods->xWrite(p->pDest, pData, p->szPage, iOff);
if( rc!=SQLITE_OK ){
scrubBackupErr(p, "write failed for page %d", pgno);
p->rcErr = SQLITE_IOERR;
}
if( (u32)pgno>p->iLastPage ) p->iLastPage = pgno;
}
/* Prepare a statement against the "db" database. */
static sqlite3_stmt *scrubBackupPrepare(
ScrubState *p, /* Backup context */
sqlite3 *db, /* Database to prepare against */
const char *zSql /* SQL statement */
){
sqlite3_stmt *pStmt;
if( p->rcErr ) return 0;
p->rcErr = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
if( p->rcErr ){
scrubBackupErr(p, "SQL error \"%s\" on \"%s\"",
sqlite3_errmsg(db), zSql);
sqlite3_finalize(pStmt);
return 0;
}
return pStmt;
}
/* Open the source database file */
static void scrubBackupOpenSrc(ScrubState *p){
sqlite3_stmt *pStmt;
int rc;
/* Open the source database file */
p->rcErr = sqlite3_open_v2(p->zSrcFile, &p->dbSrc,
SQLITE_OPEN_READWRITE |
SQLITE_OPEN_URI | SQLITE_OPEN_PRIVATECACHE, 0);
if( p->rcErr ){
scrubBackupErr(p, "cannot open source database: %s",
sqlite3_errmsg(p->dbSrc));
return;
}
p->rcErr = sqlite3_exec(p->dbSrc, "SELECT 1 FROM sqlite_schema; BEGIN;",
0, 0, 0);
if( p->rcErr ){
scrubBackupErr(p,
"cannot start a read transaction on the source database: %s",
sqlite3_errmsg(p->dbSrc));
return;
}
rc = sqlite3_wal_checkpoint_v2(p->dbSrc, "main", SQLITE_CHECKPOINT_FULL,
0, 0);
if( rc ){
scrubBackupErr(p, "cannot checkpoint the source database");
return;
}
pStmt = scrubBackupPrepare(p, p->dbSrc, "PRAGMA page_size");
if( pStmt==0 ) return;
rc = sqlite3_step(pStmt);
if( rc==SQLITE_ROW ){
p->szPage = sqlite3_column_int(pStmt, 0);
}else{
scrubBackupErr(p, "unable to determine the page size");
}
sqlite3_finalize(pStmt);
if( p->rcErr ) return;
pStmt = scrubBackupPrepare(p, p->dbSrc, "PRAGMA page_count");
if( pStmt==0 ) return;
rc = sqlite3_step(pStmt);
if( rc==SQLITE_ROW ){
p->nPage = sqlite3_column_int(pStmt, 0);
}else{
scrubBackupErr(p, "unable to determine the size of the source database");
}
sqlite3_finalize(pStmt);
sqlite3_file_control(p->dbSrc, "main", SQLITE_FCNTL_FILE_POINTER, &p->pSrc);
if( p->pSrc==0 || p->pSrc->pMethods==0 ){
scrubBackupErr(p, "cannot get the source file handle");
p->rcErr = SQLITE_ERROR;
}
}
/* Create and open the destination file */
static void scrubBackupOpenDest(ScrubState *p){
sqlite3_stmt *pStmt;
int rc;
char *zSql;
if( p->rcErr ) return;
p->rcErr = sqlite3_open_v2(p->zDestFile, &p->dbDest,
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE |
SQLITE_OPEN_URI | SQLITE_OPEN_PRIVATECACHE, 0);
if( p->rcErr ){
scrubBackupErr(p, "cannot open destination database: %s",
sqlite3_errmsg(p->dbDest));
return;
}
zSql = sqlite3_mprintf("PRAGMA page_size(%u);", p->szPage);
if( zSql==0 ){
p->rcErr = SQLITE_NOMEM;
return;
}
p->rcErr = sqlite3_exec(p->dbDest, zSql, 0, 0, 0);
sqlite3_free(zSql);
if( p->rcErr ){
scrubBackupErr(p,
"cannot set the page size on the destination database: %s",
sqlite3_errmsg(p->dbDest));
return;
}
sqlite3_exec(p->dbDest, "PRAGMA journal_mode=OFF;", 0, 0, 0);
p->rcErr = sqlite3_exec(p->dbDest, "BEGIN EXCLUSIVE;", 0, 0, 0);
if( p->rcErr ){
scrubBackupErr(p,
"cannot start a write transaction on the destination database: %s",
sqlite3_errmsg(p->dbDest));
return;
}
pStmt = scrubBackupPrepare(p, p->dbDest, "PRAGMA page_count;");
if( pStmt==0 ) return;
rc = sqlite3_step(pStmt);
if( rc!=SQLITE_ROW ){
scrubBackupErr(p, "cannot measure the size of the destination");
}else if( sqlite3_column_int(pStmt, 0)>1 ){
scrubBackupErr(p, "destination database is not empty - holds %d pages",
sqlite3_column_int(pStmt, 0));
}
sqlite3_finalize(pStmt);
sqlite3_file_control(p->dbDest, "main", SQLITE_FCNTL_FILE_POINTER, &p->pDest);
if( p->pDest==0 || p->pDest->pMethods==0 ){
scrubBackupErr(p, "cannot get the destination file handle");
p->rcErr = SQLITE_ERROR;
}
}
/* Read a 32-bit big-endian integer */
static u32 scrubBackupInt32(const u8 *a){
u32 v = a[3];
v += ((u32)a[2])<<8;
v += ((u32)a[1])<<16;
v += ((u32)a[0])<<24;
return v;
}
/* Read a 16-bit big-endian integer */
static u32 scrubBackupInt16(const u8 *a){
return (a[0]<<8) + a[1];
}
/*
** Read a varint. Put the value in *pVal and return the number of bytes.
*/
static int scrubBackupVarint(const u8 *z, sqlite3_int64 *pVal){
sqlite3_int64 v = 0;
int i;
for(i=0; i<8; i++){
v = (v<<7) + (z[i]&0x7f);
if( (z[i]&0x80)==0 ){ *pVal = v; return i+1; }
}
v = (v<<8) + (z[i]&0xff);
*pVal = v;
return 9;
}
/*
** Return the number of bytes in a varint.
*/
static int scrubBackupVarintSize(const u8 *z){
int i;
for(i=0; i<8; i++){
if( (z[i]&0x80)==0 ){ return i+1; }
}
return 9;
}
/*
** Copy the freelist trunk page given, and all its descendents,
** zeroing out as much as possible in the process.
*/
static void scrubBackupFreelist(ScrubState *p, int pgno, u32 nFree){
u8 *a, *aBuf;
u32 n, mx;
if( p->rcErr ) return;
aBuf = scrubBackupAllocPage(p);
if( aBuf==0 ) return;
while( pgno && nFree){
a = scrubBackupRead(p, pgno, aBuf);
if( a==0 ) break;
n = scrubBackupInt32(&a[4]);
mx = p->szUsable/4 - 2;
if( n<mx ){
memset(&a[n*4+8], 0, 4*(mx-n));
}
scrubBackupWrite(p, pgno, a);
pgno = scrubBackupInt32(a);
#if 0
/* There is really no point in copying the freelist leaf pages.
** Simply leave them uninitialized in the destination database. The
** OS filesystem should zero those pages for us automatically.
*/
for(i=0; i<n && nFree; i++){
u32 iLeaf = scrubBackupInt32(&a[i*4+8]);
if( aZero==0 ){
aZero = scrubBackupAllocPage(p);
if( aZero==0 ){ pgno = 0; break; }
memset(aZero, 0, p->szPage);
}
scrubBackupWrite(p, iLeaf, aZero);
nFree--;
}
#endif
}
sqlite3_free(aBuf);
}
/*
** Copy an overflow chain from source to destination. Zero out any
** unused tail at the end of the overflow chain.
*/
static void scrubBackupOverflow(ScrubState *p, int pgno, u32 nByte){
u8 *a, *aBuf;
aBuf = scrubBackupAllocPage(p);
if( aBuf==0 ) return;
while( nByte>0 && pgno!=0 ){
a = scrubBackupRead(p, pgno, aBuf);
if( a==0 ) break;
if( nByte >= (p->szUsable)-4 ){
nByte -= (p->szUsable) - 4;
}else{
u32 x = (p->szUsable - 4) - nByte;
u32 i = p->szUsable - x;
memset(&a[i], 0, x);
nByte = 0;
}
scrubBackupWrite(p, pgno, a);
pgno = scrubBackupInt32(a);
}
sqlite3_free(aBuf);
}
/*
** Copy B-Tree page pgno, and all of its children, from source to destination.
** Zero out deleted content during the copy.
*/
static void scrubBackupBtree(ScrubState *p, int pgno, int iDepth){
u8 *a;
u32 i, n, pc;
u32 nCell;
u32 nPrefix;
u32 szHdr;
u32 iChild;
u8 *aTop;
u8 *aCell;
u32 x, y;
int ln = 0;
if( p->rcErr ) return;
if( iDepth>50 ){
scrubBackupErr(p, "corrupt: b-tree too deep at page %d", pgno);
return;
}
if( pgno==1 ){
a = p->page1;
}else{
a = scrubBackupRead(p, pgno, 0);
if( a==0 ) return;
}
nPrefix = pgno==1 ? 100 : 0;
aTop = &a[nPrefix];
szHdr = 8 + 4*(aTop[0]==0x02 || aTop[0]==0x05);
aCell = aTop + szHdr;
nCell = scrubBackupInt16(&aTop[3]);
/* Zero out the gap between the cell index and the start of the
** cell content area */
x = scrubBackupInt16(&aTop[5]); /* First byte of cell content area */
if( x>p->szUsable ){ ln=__LINE__; goto btree_corrupt; }
y = szHdr + nPrefix + nCell*2;
if( y>x ){ ln=__LINE__; goto btree_corrupt; }
if( y<x ) memset(a+y, 0, x-y); /* Zero the gap */
/* Zero out all the free blocks */
pc = scrubBackupInt16(&aTop[1]);
if( pc>0 && pc<x ){ ln=__LINE__; goto btree_corrupt; }
while( pc ){
if( pc>(p->szUsable)-4 ){ ln=__LINE__; goto btree_corrupt; }
n = scrubBackupInt16(&a[pc+2]);
if( pc+n>(p->szUsable) ){ ln=__LINE__; goto btree_corrupt; }
if( n>4 ) memset(&a[pc+4], 0, n-4);
x = scrubBackupInt16(&a[pc]);
if( x<pc+4 && x>0 ){ ln=__LINE__; goto btree_corrupt; }
pc = x;
}
/* Write this one page */
scrubBackupWrite(p, pgno, a);
/* Walk the tree and process child pages */
for(i=0; i<nCell; i++){
u32 X, M, K, nLocal;
sqlite3_int64 P;
pc = scrubBackupInt16(&aCell[i*2]);
if( pc <= szHdr ){ ln=__LINE__; goto btree_corrupt; }
if( pc > p->szUsable-3 ){ ln=__LINE__; goto btree_corrupt; }
if( aTop[0]==0x05 || aTop[0]==0x02 ){
if( pc+4 > p->szUsable ){ ln=__LINE__; goto btree_corrupt; }
iChild = scrubBackupInt32(&a[pc]);
pc += 4;
scrubBackupBtree(p, iChild, iDepth+1);
if( aTop[0]==0x05 ) continue;
}
pc += scrubBackupVarint(&a[pc], &P);
if( pc >= p->szUsable ){ ln=__LINE__; goto btree_corrupt; }
if( aTop[0]==0x0d ){
X = p->szUsable - 35;
}else{
X = ((p->szUsable - 12)*64/255) - 23;
}
if( P<=X ){
/* All content is local. No overflow */
continue;
}
M = ((p->szUsable - 12)*32/255)-23;
K = M + ((P-M)%(p->szUsable-4));
if( aTop[0]==0x0d ){
pc += scrubBackupVarintSize(&a[pc]);
if( pc > (p->szUsable-4) ){ ln=__LINE__; goto btree_corrupt; }
}
nLocal = K<=X ? K : M;
if( pc+nLocal > p->szUsable-4 ){ ln=__LINE__; goto btree_corrupt; }
iChild = scrubBackupInt32(&a[pc+nLocal]);
scrubBackupOverflow(p, iChild, (u32)(P-nLocal));
}
/* Walk the right-most tree */
if( aTop[0]==0x05 || aTop[0]==0x02 ){
iChild = scrubBackupInt32(&aTop[8]);
scrubBackupBtree(p, iChild, iDepth+1);
}
/* All done */
if( pgno>1 ) sqlite3_free(a);
return;
btree_corrupt:
scrubBackupErr(p, "corruption on page %d of source database (errid=%d)",
pgno, ln);
if( pgno>1 ) sqlite3_free(a);
}
/*
** Copy all ptrmap pages from source to destination.
** This routine is only called if the source database is in autovacuum
** or incremental vacuum mode.
*/
static void scrubBackupPtrmap(ScrubState *p){
u32 pgno = 2;
u32 J = p->szUsable/5;
u32 iLock = (1073742335/p->szPage)+1;
u8 *a, *pBuf;
if( p->rcErr ) return;
pBuf = scrubBackupAllocPage(p);
if( pBuf==0 ) return;
while( pgno<=p->nPage ){
a = scrubBackupRead(p, pgno, pBuf);
if( a==0 ) break;
scrubBackupWrite(p, pgno, a);
pgno += J+1;
if( pgno==iLock ) pgno++;
}
sqlite3_free(pBuf);
}
int sqlite3_scrub_backup(
const char *zSrcFile, /* Source file */
const char *zDestFile, /* Destination file */
char **pzErr /* Write error here if non-NULL */
){
ScrubState s;
u32 n, i;
sqlite3_stmt *pStmt;
memset(&s, 0, sizeof(s));
s.zSrcFile = zSrcFile;
s.zDestFile = zDestFile;
/* Open both source and destination databases */
scrubBackupOpenSrc(&s);
scrubBackupOpenDest(&s);
/* Read in page 1 */
s.page1 = scrubBackupRead(&s, 1, 0);
if( s.page1==0 ) goto scrub_abort;
s.szUsable = s.szPage - s.page1[20];
/* Copy the freelist */
n = scrubBackupInt32(&s.page1[36]);
i = scrubBackupInt32(&s.page1[32]);
if( n ) scrubBackupFreelist(&s, i, n);
/* Copy ptrmap pages */
n = scrubBackupInt32(&s.page1[52]);
if( n ) scrubBackupPtrmap(&s);
/* Copy all of the btrees */
scrubBackupBtree(&s, 1, 0);
pStmt = scrubBackupPrepare(&s, s.dbSrc,
"SELECT rootpage FROM sqlite_schema WHERE coalesce(rootpage,0)>0");
if( pStmt==0 ) goto scrub_abort;
while( sqlite3_step(pStmt)==SQLITE_ROW ){
i = (u32)sqlite3_column_int(pStmt, 0);
scrubBackupBtree(&s, i, 0);
}
sqlite3_finalize(pStmt);
/* If the last page of the input db file is a free-list leaf, then the
** backup file on disk is still smaller than the size indicated within
** the database header. In this case, write a page of zeroes to the
** last page of the backup database so that SQLite does not mistakenly
** think the db is corrupt. */
if( s.iLastPage<s.nPage ){
u8 *aZero = scrubBackupAllocPage(&s);
if( aZero ){
memset(aZero, 0, s.szPage);
scrubBackupWrite(&s, s.nPage, aZero);
sqlite3_free(aZero);
}
}
scrub_abort:
/* Close the destination database without closing the transaction. If we
** commit, page zero will be overwritten. */
sqlite3_close(s.dbDest);
/* But do close out the read-transaction on the source database */
sqlite3_exec(s.dbSrc, "COMMIT;", 0, 0, 0);
sqlite3_close(s.dbSrc);
sqlite3_free(s.page1);
if( pzErr ){
*pzErr = s.zErr;
}else{
sqlite3_free(s.zErr);
}
return s.rcErr;
}
#ifdef SCRUB_STANDALONE
/* Error and warning log */
static void errorLogCallback(void *pNotUsed, int iErr, const char *zMsg){
const char *zType;
switch( iErr&0xff ){
case SQLITE_WARNING: zType = "WARNING"; break;
case SQLITE_NOTICE: zType = "NOTICE"; break;
default: zType = "ERROR"; break;
}
fprintf(stderr, "%s: %s\n", zType, zMsg);
}
/* The main() routine when this utility is run as a stand-alone program */
int main(int argc, char **argv){
char *zErr = 0;
int rc;
if( argc!=3 ){
fprintf(stderr,"Usage: %s SOURCE DESTINATION\n", argv[0]);
exit(1);
}
sqlite3_config(SQLITE_CONFIG_LOG, errorLogCallback, 0);
rc = sqlite3_scrub_backup(argv[1], argv[2], &zErr);
if( rc==SQLITE_NOMEM ){
fprintf(stderr, "%s: out of memory\n", argv[0]);
exit(1);
}
if( zErr ){
fprintf(stderr, "%s: %s\n", argv[0], zErr);
sqlite3_free(zErr);
exit(1);
}
return 0;
}
#endif
+4 -4
View File
@@ -239,7 +239,7 @@ static int seriesConnect(
rc = sqlite3_declare_vtab(db,
"CREATE TABLE x(value,start hidden,stop hidden,step hidden)");
if( rc==SQLITE_OK ){
pNew = *ppVtab = sqlite3_malloc( sizeof(*pNew) );
pNew = *ppVtab = sqlite3_malloc64( sizeof(*pNew) );
if( pNew==0 ) return SQLITE_NOMEM;
memset(pNew, 0, sizeof(*pNew));
sqlite3_vtab_config(db, SQLITE_VTAB_INNOCUOUS);
@@ -261,7 +261,7 @@ static int seriesDisconnect(sqlite3_vtab *pVtab){
static int seriesOpen(sqlite3_vtab *pUnused, sqlite3_vtab_cursor **ppCursor){
series_cursor *pCur;
(void)pUnused;
pCur = sqlite3_malloc( sizeof(*pCur) );
pCur = sqlite3_malloc64( sizeof(*pCur) );
if( pCur==0 ) return SQLITE_NOMEM;
memset(pCur, 0, sizeof(*pCur));
*ppCursor = &pCur->base;
@@ -536,7 +536,7 @@ static int seriesFilter(
if( r<(double)SMALLEST_INT64 ){
iMin = SMALLEST_INT64;
}else if( (idxNum & 0x0200)!=0 && r==seriesCeil(r) ){
iMin = (sqlite3_int64)seriesCeil(r+1.0);
iMin = (sqlite3_int64)seriesCeil(r)+1;
}else{
iMin = (sqlite3_int64)seriesCeil(r);
}
@@ -557,7 +557,7 @@ static int seriesFilter(
if( r>(double)LARGEST_INT64 ){
iMax = LARGEST_INT64;
}else if( (idxNum & 0x2000)!=0 && r==seriesFloor(r) ){
iMax = (sqlite3_int64)(r-1.0);
iMax = ((sqlite3_int64)r)-1;
}else{
iMax = (sqlite3_int64)seriesFloor(r);
}
+7
View File
@@ -31,6 +31,10 @@ SQLITE_EXTENSION_INIT1
/******************************************************************************
** The Hash Engine
*/
#if defined(__GNUC__) && __GNUC__>=11
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wstringop-overread"
#endif
/* Context for the SHA1 hash */
typedef struct SHA1Context SHA1Context;
struct SHA1Context {
@@ -226,6 +230,9 @@ static void hash_finish(
zOut[i*2]= 0;
}
}
#if defined(__GNUC__) && __GNUC__>=11
# pragma GCC diagnostic pop
#endif
/* End of the hashing logic
*****************************************************************************/
+21 -11
View File
@@ -32,6 +32,7 @@ SQLITE_EXTENSION_INIT1
# define NEVER(X) 0
typedef unsigned char u8;
typedef unsigned short u16;
typedef sqlite3_int64 i64;
#endif
#include <ctype.h>
@@ -192,7 +193,7 @@ static const unsigned char className[] = ".ABCDHLRMY9 ?";
** Return NULL if memory allocation fails.
*/
static unsigned char *phoneticHash(const unsigned char *zIn, int nIn){
unsigned char *zOut = sqlite3_malloc64( nIn + 1 );
unsigned char *zOut = sqlite3_malloc64( (i64)nIn + 1 );
int i;
int nOut = 0;
char cPrev = 0x77;
@@ -352,6 +353,7 @@ static int substituteCost(char cPrev, char cFrom, char cTo){
** -1 One of the inputs is NULL
** -2 Non-ASCII characters on input
** -3 Unable to allocate memory
** -4 Inputs too large
**
** If pnMatch is not NULL, then *pnMatch is set to the number of bytes
** of zB that matched the pattern in zA. If zA does not end with a '*',
@@ -390,9 +392,11 @@ static int editdist1(const char *zA, const char *zB, int *pnMatch){
for(nA=0; zA[nA]; nA++){
if( zA[nA]&0x80 ) return -2;
}
if( nA>=100000 ) return -4;
for(nB=0; zB[nB]; nB++){
if( zB[nB]&0x80 ) return -2;
}
if( nB>=100000 ) return -4;
/* Special processing if either string is empty */
if( nA==0 ){
@@ -419,7 +423,7 @@ static int editdist1(const char *zA, const char *zB, int *pnMatch){
if( nB<(sizeof(mStack)*4)/(sizeof(mStack[0])*5) ){
m = mStack;
}else{
m = toFree = sqlite3_malloc64( (nB+1)*5*sizeof(m[0])/4 );
m = toFree = sqlite3_malloc64( ((i64)nB+1)*5LL*sizeof(m[0])/4 );
if( m==0 ) return -3;
}
cx = (char*)&m[nB+1];
@@ -527,6 +531,8 @@ static void editdistSqlFunc(
if( res<0 ){
if( res==(-3) ){
sqlite3_result_error_nomem(context);
}else if( res==(-4) ){
sqlite3_result_error_toobig(context);
}else if( res==(-2) ){
sqlite3_result_error(context, "non-ASCII input to editdist()", -1);
}else{
@@ -767,7 +773,7 @@ static int editDist3ConfigLoad(
if( iCost>=10000 ) continue; /* Costs above 10K are considered infinite */
if( pLang==0 || iLang!=iLangPrev ){
EditDist3Lang *pNew;
pNew = sqlite3_realloc64(p->a, (p->nLang+1)*sizeof(p->a[0]));
pNew = sqlite3_realloc64(p->a, ((i64)p->nLang+1)*sizeof(p->a[0]));
if( pNew==0 ){ rc = SQLITE_NOMEM; break; }
p->a = pNew;
pLang = &p->a[p->nLang];
@@ -901,7 +907,7 @@ static EditDist3FromString *editDist3FromStringNew(
if( z==0 ) return 0;
if( n<0 ) n = (int)strlen(z);
pStr = sqlite3_malloc64( sizeof(*pStr) + sizeof(pStr->a[0])*n + n + 1 );
pStr = sqlite3_malloc64( sizeof(*pStr) + sizeof(pStr->a[0])*n + (i64)n + 1 );
if( pStr==0 ) return 0;
pStr->a = (EditDist3From*)&pStr[1];
memset(pStr->a, 0, sizeof(pStr->a[0])*n);
@@ -927,13 +933,13 @@ static EditDist3FromString *editDist3FromStringNew(
if( matchFrom(p, z+i, n-i)==0 ) continue;
if( p->nTo==0 ){
apNew = sqlite3_realloc64(pFrom->apDel,
sizeof(*apNew)*(pFrom->nDel+1));
sizeof(*apNew)*((i64)pFrom->nDel+1));
if( apNew==0 ) break;
pFrom->apDel = apNew;
apNew[pFrom->nDel++] = p;
}else{
apNew = sqlite3_realloc64(pFrom->apSubst,
sizeof(*apNew)*(pFrom->nSubst+1));
sizeof(*apNew)*((i64)pFrom->nSubst+1));
if( apNew==0 ) break;
pFrom->apSubst = apNew;
apNew[pFrom->nSubst++] = p;
@@ -1008,6 +1014,8 @@ static int editDist3Core(
unsigned int stackSpace[SQLITE_SPELLFIX_STACKALLOC_SZ/sizeof(unsigned int)];
/* allocate the Wagner matrix and the aTo[] array for the TO string */
if( n2>10000 ) return -2;
if( f.n>10000 ) return -2;
n = (f.n+1)*(n2+1);
n = (n+1)&~1;
nByte = n*sizeof(m[0]) + sizeof(a2[0])*n2;
@@ -1198,6 +1206,8 @@ static void editDist3SqlFunc(
editDist3FromStringDelete(pFrom);
if( dist==(-1) ){
sqlite3_result_error_nomem(context);
}else if( dist==(-2) ){
sqlite3_result_error_toobig(context);
}else{
sqlite3_result_int(context, dist);
}
@@ -1712,9 +1722,9 @@ static const Transliteration *spellfixFindTranslit(int c, int *pxTop){
*/
static unsigned char *transliterate(const unsigned char *zIn, int nIn){
#ifdef SQLITE_SPELLFIX_5BYTE_MAPPINGS
unsigned char *zOut = sqlite3_malloc64( nIn*5 + 1 );
unsigned char *zOut = sqlite3_malloc64( (i64)nIn*5 + 1 );
#else
unsigned char *zOut = sqlite3_malloc64( nIn*4 + 1 );
unsigned char *zOut = sqlite3_malloc64( (i64)nIn*4 + 1 );
#endif
int c, sz, nOut;
if( zOut==0 ) return 0;
@@ -2057,7 +2067,7 @@ static int spellfix1Init(
int i;
nDbName = (int)strlen(zDbName);
pNew = sqlite3_malloc64( sizeof(*pNew) + nDbName + 1);
pNew = sqlite3_malloc64( sizeof(*pNew) + (i64)nDbName + 1);
if( pNew==0 ){
rc = SQLITE_NOMEM;
}else{
@@ -2461,7 +2471,7 @@ static void spellfix1RunQuery(MatchQuery *p, const char *zQuery, int nQuery){
iDist = editdist1(p->zPattern, zK1, 0);
}
if( iDist<0 ){
p->rc = SQLITE_NOMEM;
p->rc = iDist==(-4) ? SQLITE_TOOBIG : SQLITE_NOMEM;
break;
}
pCur->nSearch++;
@@ -2773,7 +2783,7 @@ static int spellfix1Column(
if( !zTranslit ) return SQLITE_NOMEM;
res = editdist1(pCur->zPattern, zTranslit, &iMatchlen);
sqlite3_free(zTranslit);
if( res<0 ) return SQLITE_NOMEM;
if( res<0 ) return res==(-4) ? SQLITE_TOOBIG : SQLITE_NOMEM;
iMatchlen = translen_to_charlen(zWord, nWord, iMatchlen);
}else{
iMatchlen = utf8Charlen(zWord, nWord);
+3 -3
View File
@@ -46,7 +46,7 @@ static void sqlarCompressFunc(
uLongf nOut = compressBound(nData);
Bytef *pOut;
pOut = (Bytef*)sqlite3_malloc(nOut);
pOut = (Bytef*)sqlite3_malloc64(nOut);
if( pOut==0 ){
sqlite3_result_error_nomem(context);
return;
@@ -84,14 +84,14 @@ static void sqlarUncompressFunc(
sqlite3_int64 sz;
assert( argc==2 );
sz = sqlite3_value_int(argv[1]);
sz = sqlite3_value_int64(argv[1]);
if( sz<=0 || sz==(nData = sqlite3_value_bytes(argv[0])) ){
sqlite3_result_value(context, argv[0]);
}else{
uLongf szf = sz;
const Bytef *pData= sqlite3_value_blob(argv[0]);
Bytef *pOut = sqlite3_malloc(sz);
Bytef *pOut = sqlite3_malloc64(sz);
if( pOut==0 ){
sqlite3_result_error_nomem(context);
}else if( Z_OK!=uncompress(pOut, &szf, pData, nData) ){
+6 -6
View File
@@ -101,8 +101,8 @@ FILE *sqlite3_fopen(const char *zFilename, const char *zMode){
sz1 = (int)strlen(zFilename);
sz2 = (int)strlen(zMode);
b1 = sqlite3_malloc( (sz1+1)*sizeof(b1[0]) );
b2 = sqlite3_malloc( (sz2+1)*sizeof(b1[0]) );
b1 = sqlite3_malloc64( (sz1+1)*sizeof(b1[0]) );
b2 = sqlite3_malloc64( (sz2+1)*sizeof(b1[0]) );
if( b1 && b2 ){
sz1 = MultiByteToWideChar(CP_UTF8, 0, zFilename, sz1, b1, sz1);
b1[sz1] = 0;
@@ -127,8 +127,8 @@ FILE *sqlite3_popen(const char *zCommand, const char *zMode){
sz1 = (int)strlen(zCommand);
sz2 = (int)strlen(zMode);
b1 = sqlite3_malloc( (sz1+1)*sizeof(b1[0]) );
b2 = sqlite3_malloc( (sz2+1)*sizeof(b1[0]) );
b1 = sqlite3_malloc64( (sz1+1)*sizeof(b1[0]) );
b2 = sqlite3_malloc64( (sz2+1)*sizeof(b1[0]) );
if( b1 && b2 ){
sz1 = MultiByteToWideChar(CP_UTF8, 0, zCommand, sz1, b1, sz1);
b1[sz1] = 0;
@@ -151,7 +151,7 @@ char *sqlite3_fgets(char *buf, int sz, FILE *in){
** that into UTF-8. Otherwise, non-ASCII characters all get translated
** into '?'.
*/
wchar_t *b1 = sqlite3_malloc( sz*sizeof(wchar_t) );
wchar_t *b1 = sqlite3_malloc64( sz*sizeof(wchar_t) );
if( b1==0 ) return 0;
#ifdef SQLITE_USE_W32_FOR_CONSOLE_IO
DWORD nRead = 0;
@@ -226,7 +226,7 @@ int sqlite3_fputs(const char *z, FILE *out){
** to the console on Windows.
*/
int sz = (int)strlen(z);
wchar_t *b1 = sqlite3_malloc( (sz+1)*sizeof(wchar_t) );
wchar_t *b1 = sqlite3_malloc64( (sz+1)*sizeof(wchar_t) );
if( b1==0 ) return 0;
sz = MultiByteToWideChar(CP_UTF8, 0, z, sz, b1, sz);
b1[sz] = 0;
+1 -1
View File
@@ -52,7 +52,7 @@ static void stmtrandFunc(
p = (Stmtrand*)sqlite3_get_auxdata(context, STMTRAND_KEY);
if( p==0 ){
unsigned int seed;
p = sqlite3_malloc( sizeof(*p) );
p = sqlite3_malloc64( sizeof(*p) );
if( p==0 ){
sqlite3_result_error_nomem(context);
return;
+2 -2
View File
@@ -101,7 +101,7 @@ static int templatevtabConnect(
#define TEMPLATEVTAB_A 0
#define TEMPLATEVTAB_B 1
if( rc==SQLITE_OK ){
pNew = sqlite3_malloc( sizeof(*pNew) );
pNew = sqlite3_malloc64( sizeof(*pNew) );
*ppVtab = (sqlite3_vtab*)pNew;
if( pNew==0 ) return SQLITE_NOMEM;
memset(pNew, 0, sizeof(*pNew));
@@ -123,7 +123,7 @@ static int templatevtabDisconnect(sqlite3_vtab *pVtab){
*/
static int templatevtabOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor){
templatevtab_cursor *pCur;
pCur = sqlite3_malloc( sizeof(*pCur) );
pCur = sqlite3_malloc64( sizeof(*pCur) );
if( pCur==0 ) return SQLITE_NOMEM;
memset(pCur, 0, sizeof(*pCur));
*ppCursor = &pCur->base;
+1
View File
@@ -120,6 +120,7 @@ static int sqlite3UuidStrToBlob(
unsigned char *aBlob /* Write results here */
){
int i;
if( zStr==0 ) return 1;
if( zStr[0]=='{' ) zStr++;
for(i=0; i<16; i++){
if( zStr[0]=='-' ) zStr++;
+2 -2
View File
@@ -613,7 +613,7 @@ static int vstattabConnect(
rc = sqlite3_declare_vtab(db,"CREATE TABLE x(file,stat,count)");
if( rc==SQLITE_OK ){
pNew = *ppVtab = sqlite3_malloc( sizeof(*pNew) );
pNew = *ppVtab = sqlite3_malloc64( sizeof(*pNew) );
if( pNew==0 ) return SQLITE_NOMEM;
memset(pNew, 0, sizeof(*pNew));
}
@@ -633,7 +633,7 @@ static int vstattabDisconnect(sqlite3_vtab *pVtab){
*/
static int vstattabOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor){
VfsStatCursor *pCur;
pCur = sqlite3_malloc( sizeof(*pCur) );
pCur = sqlite3_malloc64( sizeof(*pCur) );
if( pCur==0 ) return SQLITE_NOMEM;
memset(pCur, 0, sizeof(*pCur));
*ppCursor = &pCur->base;
+1 -1
View File
@@ -892,7 +892,7 @@ static int vfstraceOpen(
vfstrace_printf(pInfo, "%s.xOpen(%s,flags=0x%x)",
pInfo->zVfsName, p->zFName, flags);
if( p->pReal->pMethods ){
sqlite3_io_methods *pNew = sqlite3_malloc( sizeof(*pNew) );
sqlite3_io_methods *pNew = sqlite3_malloc64( sizeof(*pNew) );
const sqlite3_io_methods *pSub = p->pReal->pMethods;
memset(pNew, 0, sizeof(*pNew));
pNew->iVersion = pSub->iVersion;
+2 -2
View File
@@ -240,7 +240,7 @@ static int vtablogConnectCreate(
printf(" schema = '%s'\n", zSchema);
rc = sqlite3_declare_vtab(db, zSchema);
if( rc==SQLITE_OK ){
pNew = sqlite3_malloc( sizeof(*pNew) );
pNew = sqlite3_malloc64( sizeof(*pNew) );
*ppVtab = (sqlite3_vtab*)pNew;
if( pNew==0 ) return SQLITE_NOMEM;
memset(pNew, 0, sizeof(*pNew));
@@ -313,7 +313,7 @@ static int vtablogOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor){
vtablog_cursor *pCur;
printf("%s.%s.xOpen(cursor=%d)\n", pTab->zDb, pTab->zName,
++pTab->nCursor);
pCur = sqlite3_malloc( sizeof(*pCur) );
pCur = sqlite3_malloc64( sizeof(*pCur) );
if( pCur==0 ) return SQLITE_NOMEM;
memset(pCur, 0, sizeof(*pCur));
pCur->iCursor = pTab->nCursor;
+5 -5
View File
@@ -86,7 +86,7 @@ static int vtshimCreate(
}
return SQLITE_ERROR;
}
pNew = sqlite3_malloc( sizeof(*pNew) );
pNew = sqlite3_malloc64( sizeof(*pNew) );
*ppVtab = (sqlite3_vtab*)pNew;
if( pNew==0 ) return SQLITE_NOMEM;
memset(pNew, 0, sizeof(*pNew));
@@ -125,7 +125,7 @@ static int vtshimConnect(
}
return SQLITE_ERROR;
}
pNew = sqlite3_malloc( sizeof(*pNew) );
pNew = sqlite3_malloc64( sizeof(*pNew) );
*ppVtab = (sqlite3_vtab*)pNew;
if( pNew==0 ) return SQLITE_NOMEM;
memset(pNew, 0, sizeof(*pNew));
@@ -192,7 +192,7 @@ static int vtshimOpen(sqlite3_vtab *pBase, sqlite3_vtab_cursor **ppCursor){
int rc;
*ppCursor = 0;
if( pAux->bDisposed ) return SQLITE_ERROR;
pCur = sqlite3_malloc( sizeof(*pCur) );
pCur = sqlite3_malloc64( sizeof(*pCur) );
if( pCur==0 ) return SQLITE_NOMEM;
memset(pCur, 0, sizeof(*pCur));
rc = pAux->pMod->xOpen(pVtab->pChild, &pCur->pChild);
@@ -444,7 +444,7 @@ static int vtshimCopyModule(
){
sqlite3_module *p;
if( !pMod || !ppMod ) return SQLITE_ERROR;
p = sqlite3_malloc( sizeof(*p) );
p = sqlite3_malloc64( sizeof(*p) );
if( p==0 ) return SQLITE_NOMEM;
memcpy(p, pMod, sizeof(*p));
*ppMod = p;
@@ -464,7 +464,7 @@ void *sqlite3_create_disposable_module(
vtshim_aux *pAux;
sqlite3_module *pMod;
int rc;
pAux = sqlite3_malloc( sizeof(*pAux) );
pAux = sqlite3_malloc64( sizeof(*pAux) );
if( pAux==0 ){
if( xDestroy ) xDestroy(pClientData);
return 0;
+11 -4
View File
@@ -13,6 +13,11 @@
** This file implements a virtual table that returns the whole numbers
** between 1 and 4294967295, inclusive.
**
** TESTING AND DEBUG USE ONLY -> This is not production code. This is
** not a deliverable. Use the generate_series() virtual table for
** real-world applications instead of this extension. THIS EXTENSION
** MAY CONTAIN BUGS.
**
** Example:
**
** CREATE VIRTUAL TABLE nums USING wholenumber;
@@ -47,7 +52,7 @@ static int wholenumberConnect(
char **pzErr
){
sqlite3_vtab *pNew;
pNew = *ppVtab = sqlite3_malloc( sizeof(*pNew) );
pNew = *ppVtab = sqlite3_malloc64( sizeof(*pNew) );
if( pNew==0 ) return SQLITE_NOMEM;
sqlite3_declare_vtab(db, "CREATE TABLE x(value)");
sqlite3_vtab_config(db, SQLITE_VTAB_INNOCUOUS);
@@ -69,7 +74,7 @@ static int wholenumberDisconnect(sqlite3_vtab *pVtab){
*/
static int wholenumberOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor){
wholenumber_cursor *pCur;
pCur = sqlite3_malloc( sizeof(*pCur) );
pCur = sqlite3_malloc64( sizeof(*pCur) );
if( pCur==0 ) return SQLITE_NOMEM;
memset(pCur, 0, sizeof(*pCur));
*ppCursor = &pCur->base;
@@ -154,12 +159,14 @@ static int wholenumberFilter(
pCur->iValue = 1;
pCur->mxValue = 0xffffffff; /* 4294967295 */
if( idxNum & 3 ){
v = sqlite3_value_int64(argv[0]) + (idxNum&1);
v = sqlite3_value_int64(argv[0]);
if( v<=pCur->mxValue && (idxNum&1)!=0 ) v++;
if( v>pCur->iValue && v<=pCur->mxValue ) pCur->iValue = v;
i++;
}
if( idxNum & 12 ){
v = sqlite3_value_int64(argv[i]) - ((idxNum>>2)&1);
v = sqlite3_value_int64(argv[i]);
if( v>0 && ((idxNum>>2)&1)!=0 ) v--;
if( v>=pCur->iValue && v<pCur->mxValue ) pCur->mxValue = v;
}
return SQLITE_OK;
+14 -7
View File
@@ -456,7 +456,7 @@ static int zipfileDisconnect(sqlite3_vtab *pVtab){
static int zipfileOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCsr){
ZipfileTab *pTab = (ZipfileTab*)p;
ZipfileCsr *pCsr;
pCsr = sqlite3_malloc(sizeof(*pCsr));
pCsr = sqlite3_malloc64(sizeof(*pCsr));
*ppCsr = (sqlite3_vtab_cursor*)pCsr;
if( pCsr==0 ){
return SQLITE_NOMEM;
@@ -488,6 +488,7 @@ static void zipfileResetCursor(ZipfileCsr *pCsr){
pNext = p->pNext;
zipfileEntryFree(p);
}
pCsr->pFreeEntry = 0;
}
/*
@@ -890,7 +891,13 @@ static int zipfileGetEntry(
if( rc==SQLITE_OK ){
u32 *pt = &pNew->mUnixTime;
pNew->cds.zFile = sqlite3_mprintf("%.*s", nFile, aRead);
/* aRead[0..nFile-1] might contain embedded \000 characters
** See Bug 2026-05-31T11:43:05Z */
pNew->cds.zFile = sqlite3_malloc64(nFile+1);
if( pNew->cds.zFile!=0 ){
memcpy(pNew->cds.zFile, aRead, nFile);
pNew->cds.zFile[nFile] = 0;
}
pNew->aExtra = (u8*)&pNew[1];
memcpy(pNew->aExtra, &aRead[nFile], nExtra);
if( pNew->cds.zFile==0 ){
@@ -995,7 +1002,7 @@ static void zipfileInflate(
int nIn, /* Size of buffer aIn[] in bytes */
int nOut /* Expected output size */
){
u8 *aRes = sqlite3_malloc(nOut);
u8 *aRes = sqlite3_malloc64(nOut);
if( aRes==0 ){
sqlite3_result_error_nomem(pCtx);
}else{
@@ -1392,7 +1399,7 @@ static int zipfileBestIndex(
static ZipfileEntry *zipfileNewEntry(const char *zPath){
ZipfileEntry *pNew;
pNew = sqlite3_malloc(sizeof(ZipfileEntry));
pNew = sqlite3_malloc64(sizeof(ZipfileEntry));
if( pNew ){
memset(pNew, 0, sizeof(ZipfileEntry));
pNew->cds.zFile = sqlite3_mprintf("%s", zPath);
@@ -1994,10 +2001,10 @@ struct ZipfileCtx {
};
static int zipfileBufferGrow(ZipfileBuffer *pBuf, i64 nByte){
if( pBuf->n+nByte>pBuf->nAlloc ){
if( (pBuf->nAlloc-pBuf->n)<nByte ){
u8 *aNew;
sqlite3_int64 nNew = pBuf->n ? pBuf->n*2 : 512;
int nReq = pBuf->n + nByte;
i64 nNew = pBuf->n ? (i64)pBuf->n*2 : 512;
i64 nReq = pBuf->n + nByte;
while( nNew<nReq ) nNew = nNew*2;
aNew = sqlite3_realloc64(pBuf->a, nNew);
+22 -9
View File
@@ -115,6 +115,7 @@ struct sqlite3_qrf_spec {
short int nScreenWidth; /* Maximum overall table width */
short int nLineLimit; /* Maximum number of lines for any row */
short int nTitleLimit; /* Maximum number of characters in a title */
unsigned int nMultiInsert; /* Add rows to one INSERT until size exceeds */
int nCharLimit; /* Maximum number of characters in a cell */
int nWidth; /* Number of entries in aWidth[] */
int nAlign; /* Number of entries in aAlignment[] */
@@ -381,7 +382,16 @@ can improve readability. The nTitleLimit setting currently only
works for **Box**, **Column**, **Line**, **Markdown**, and **Table**
styles, though that limitation might change in future releases.
### 2.9 Word Wrapping In Columnar Styles (nWrap, bWordWrap)
### 2.9 Multiple Tuples Per INSERT In QRF_STYLE_Insert (nMultiInsert)
If the sqlite3_qrf_spec.nMultiInsert value is positive, then the
QRF_STYLE_Insert output mode will generate multiple tuples in
each INSERT statement until the total number of bytes in the
statement exceeds nMultiInsert. A value of a few thousand is
recommended here, in order to generate SQL output that is parsed
and inserted at maximum speed by SQLite.
### 2.10 Word Wrapping In Columnar Styles (nWrap, bWordWrap)
When using columnar formatting modes (QRF_STYLE_Box, QRF_STYLE_Column,
QRF_STYLE_Markdown, or QRF_STYLE_Table), the formatter attempts to limit
@@ -400,7 +410,7 @@ anywhere, including in the middle of a word.
For narrow columns and wide words, it might sometimes be necessary to split
a column in the middle of a word, even when bWordWrap is QRF_Yes.
### 2.10 Helping The Output To Fit On The Terminal (nScreenWidth)
### 2.11 Helping The Output To Fit On The Terminal (nScreenWidth)
The sqlite3_qrf_spec.nScreenWidth field can be set the number of
characters that will fit on one line on the viewer output device.
@@ -420,7 +430,7 @@ The nScreenWidth field currently only makes a difference in
columnar styles (**Box**, **Column**, **Markdown**, and **Table**)
and in the **Line** style.
### 2.11 Individual Column Width (nWidth and aWidth)
### 2.12 Individual Column Width (nWidth and aWidth)
The sqlite3_qrf_spec.aWidth field is a pointer to an array of
signed 16-bit integers that control the width of individual columns
@@ -458,7 +468,7 @@ Again, negative values for aWidth\[\] entries are supported for
backwards compatibility only, and are not recommended for new
applications.
### 2.12 Alignment (nAlignment, aAlignment, eDfltAlign, eTitleAlign)
### 2.13 Alignment (nAlignment, aAlignment, eDfltAlign, eTitleAlign)
Some cells in a display table might contain a lot of text and thus
be wide, or they might contain newline characters or be wrapped by
@@ -537,7 +547,7 @@ specify a vertical alignment, then values are top-aligned
The vertical alignment settings are currently ignored and
the vertical alignment is always QRF_ALIGN_Top.*
### 2.13 Row and Column Separator Strings
### 2.14 Row and Column Separator Strings
The sqlite3_qrf_spec.zColumnSep and sqlite3_qrf_spec.zRowSep strings
are alternative column and row separator character sequences. If not
@@ -545,18 +555,18 @@ specified (if these pointers are left as NULL) then appropriate defaults
are used. Some output styles have hard-coded column and row separators
and these settings are ignored for those styles.
### 2.14 The Output Table Name
### 2.15 The Output Table Name
The sqlite3_qrf_spec.zTableName value is the name of the output table
when eStyle is QRF_STYLE_Insert.
### 2.15 The Rendering Of NULL (zNull)
### 2.16 The Rendering Of NULL (zNull)
If a value is NULL then show the NULL using the string
found in sqlite3_qrf_spec.zNull. If zNull is itself a NULL pointer
then NULL values are rendered as an empty string.
### 2.16 Optional Value Rendering Callback
### 2.17 Optional Value Rendering Callback
If the sqlite3_qrf_spec.xRender field is not NULL, then each
sqlite3_value coming out of the query is first passed to the
@@ -709,7 +719,10 @@ the `<TABLE>..</TABLE>` around the outside.
The **Insert** style generates a series of SQL "INSERT" statements
that will inserts the data that is output into a table whose name is defined
by the zTableName field of `sqlite3_qrf_spec`. If zTableName is NULL,
then a substitute name is used.
then a substitute name is used. If nMultiInsert is positive, then the
output will add multiple rows to each INSERT statement until the size
of the INSERT statement exceeds nMultiInsert bytes before starting
a new INSERT statement.
The **Json** and **JObject** styles generates JSON text for the query result.
The **Json** style produces a JSON array of structures with one
+106 -60
View File
@@ -9,8 +9,8 @@
** May you share freely, never taking more than you give.
**
*************************************************************************
** Implementation of the Result-Format or "qrf" utility library for SQLite.
** See the qrf.md documentation for additional information.
** Implementation of the Query Result-Format or "qrf" utility library for
** SQLite. See the README.md documentation for additional information.
*/
#ifndef SQLITE_QRF_H
#include "qrf.h"
@@ -19,7 +19,9 @@
#include <assert.h>
#include <stdint.h>
#ifndef SQLITE_AMALGAMATION
typedef sqlite3_int64 i64;
#endif
/* A single line in the EQP output */
typedef struct qrfEQPGraphRow qrfEQPGraphRow;
@@ -66,6 +68,7 @@ struct Qrf {
int iIndent; /* Current slot */
int *aiIndent; /* Indentation for each opcode */
} sExpln;
unsigned int nIns; /* Bytes used for current INSERT stmt */
} u;
sqlite3_int64 nRow; /* Number of rows handled so far */
int *actualWidth; /* Actual width of each column */
@@ -249,6 +252,10 @@ static void qrfApproxInt64(sqlite3_str *pOut, i64 N){
sqlite3_str_appendf(pOut, "%4lld ", N);
return;
}
if( N>=9223372036854775800LL ){
sqlite3_str_appendf(pOut, "%.2fE", 1e-18*(double)N);
return;
}
for(i=1; i<=18; i++){
N = (N+5)/10;
if( N<10000 ){
@@ -408,8 +415,8 @@ static void qrfEqpStats(Qrf *p){
sqlite3_str_reset(pStats);
if( nCycle>=0 && nTotal>0 ){
qrfApproxInt64(pStats, nCycle);
sqlite3_str_appendf(pStats, " %3d%%",
((nCycle*100)+nTotal/2) / nTotal
sqlite3_str_appendf(pStats, " %3.0f%%",
((100.0*(double)nCycle)+nTotal/2.0) / (double)nTotal
);
nSp = 2;
}
@@ -425,7 +432,6 @@ static void qrfEqpStats(Qrf *p){
if( nRow>=0 ){
if( nSp ) sqlite3_str_appendchar(pStats, nSp, ' ');
qrfApproxInt64(pStats, nRow);
nSp = 2;
if( p->spec.eStyle==QRF_STYLE_StatsEst ){
sqlite3_str_appendf(pStats, " ");
qrfApproxInt64(pStats, (i64)rEstCum);
@@ -715,19 +721,16 @@ static int qrfDisplayWidth(const char *zIn, sqlite3_int64 nByte, int *pnNL){
}
/*
** Escape the input string if it is needed and in accordance with
** eEsc, which is either QRF_ESC_Ascii or QRF_ESC_Symbol.
** Escape the text starting at byte iStart of pStr, if needed, using the
** escape encoding of eEsc, which is either QRF_ESC_Ascii or QRF_ESC_Symbol.
** The pStr string is modified appropriately.
**
** Escaping is needed if the string contains any control characters
** other than \t, \n, and \r\n
**
** If no escaping is needed (the common case) then set *ppOut to NULL
** and return 0. If escaping is needed, write the escaped string into
** memory obtained from sqlite3_malloc64() and make *ppOut point to that
** memory and return 0. If an error occurs, return non-zero.
**
** The caller is responsible for freeing *ppFree if it is non-NULL in order
** to reclaim memory.
** If no escaping is needed (the common case) then pStr is unchanged.
** If escaping is required, then pStr is expanded and modified to hold
** an escaped representation of the text.
*/
static void qrfEscape(
int eEsc, /* QRF_ESC_Ascii or QRF_ESC_Symbol */
@@ -735,20 +738,22 @@ static void qrfEscape(
int iStart /* Begin escapding on this byte of pStr */
){
sqlite3_int64 i, j; /* Loop counters */
sqlite3_int64 sz; /* Size of the string prior to escaping */
sqlite3_int64 nCtrl = 0;/* Number of control characters to escape */
unsigned char *zIn; /* Text to be escaped */
unsigned int nIn; /* Bytes of text to be escaped */
unsigned char c; /* A single character of the text */
unsigned char *zOut; /* Where to write the results */
/* Find the text to be escaped */
zIn = (unsigned char*)sqlite3_str_value(pStr);
nIn = sqlite3_str_length(pStr);
if( zIn==0 ) return;
zIn += iStart;
nIn -= iStart;
/* Count the control characters */
for(i=0; (c = zIn[i])!=0; i++){
if( c<=0x1f
for(i=0; i<nIn; i++){
if( (c = zIn[i])<=0x1f
&& c!='\t'
&& c!='\n'
&& (c!='\r' || zIn[i+1]!='\n')
@@ -760,18 +765,17 @@ static void qrfEscape(
/* Make space to hold the escapes. Copy the original text to the end
** of the available space. */
sz = sqlite3_str_length(pStr) - iStart;
if( eEsc==QRF_ESC_Symbol ) nCtrl *= 2;
sqlite3_str_appendchar(pStr, nCtrl, ' ');
zOut = (unsigned char*)sqlite3_str_value(pStr);
if( zOut==0 ) return;
zOut += iStart;
zIn = zOut + nCtrl;
memmove(zIn,zOut,sz);
memmove(zIn,zOut,nIn);
/* Convert the control characters */
for(i=j=0; (c = zIn[i])!=0; i++){
if( c>0x1f
for(i=j=0; i<nIn; i++){
if( (c = zIn[i])>0x1f
|| c=='\t'
|| c=='\n'
|| (c=='\r' && zIn[i+1]=='\n')
@@ -783,6 +787,7 @@ static void qrfEscape(
j += i;
}
zIn += i+1;
nIn -= i+1;
i = -1;
if( eEsc==QRF_ESC_Symbol ){
zOut[j++] = 0xe2;
@@ -908,7 +913,7 @@ static void qrfEncodeText(Qrf *p, sqlite3_str *pOut, const char *zTxt){
sqlite3_str_append(pOut, (const char*)z, i);
}
switch( z[i] ){
case '>': sqlite3_str_append(pOut, "&lt;", 4); break;
case '>': sqlite3_str_append(pOut, "&gt;", 4); break;
case '&': sqlite3_str_append(pOut, "&amp;", 5); break;
case '<': sqlite3_str_append(pOut, "&lt;", 4); break;
case '"': sqlite3_str_append(pOut, "&quot;", 6); break;
@@ -1185,8 +1190,22 @@ static void qrfRenderValue(Qrf *p, sqlite3_str *pOut, int iCol){
break;
}
default: {
const char *zTxt = (const char*)sqlite3_column_text(p->pStmt,iCol);
qrfEncodeText(p, pOut, zTxt);
const void *pBlob = sqlite3_column_blob(p->pStmt,iCol);
int nBlob = sqlite3_column_bytes(p->pStmt,iCol);
int rc;
qrfWrite(p);
if( nBlob==0 ){
/* no-op */
}else if( p->spec.eEsc==QRF_ESC_Off ){
rc = p->spec.xWrite(p->spec.pWriteArg,pBlob,nBlob);
if( rc ){
qrfError(p, rc, "Failed to write %d bytes of BLOB output", nBlob);
}
}else{
sqlite3_str_append(pOut, pBlob, nBlob);
qrfEscape(p->spec.eEsc, pOut, 0);
qrfWrite(p);
}
}
}
break;
@@ -1388,7 +1407,7 @@ static void qrfWrapLine(
for(k=i-1; k>=i/2; k--){
if( qrfSpace(z[k]) ) break;
}
if( k<i/2 ){
if( k<i/2 && i/2>0 ){
for(k=i; k>=i/2; k--){
if( qrfAlnum(z[k-1])!=qrfAlnum(z[k]) && (z[k]&0xc0)!=0x80 ) break;
}
@@ -1639,12 +1658,12 @@ static void qrfBoxLine(sqlite3_str *pOut, int N, int bDbl){
DBL_24 DBL_24 DBL_24 DBL_24 DBL_24 DBL_24 DBL_24 DBL_24 DBL_24 DBL_24
};/* 0 1 2 3 4 5 6 7 8 9 */
const int nDash = 30;
N *= 3;
while( N>nDash ){
i64 nn = 3*(i64)N;
while( nn>nDash ){
sqlite3_str_append(pOut, azDash[bDbl], nDash);
N -= nDash;
nn -= nDash;
}
sqlite3_str_append(pOut, azDash[bDbl], N);
sqlite3_str_append(pOut, azDash[bDbl], (int)nn);
}
/*
@@ -1717,7 +1736,7 @@ static int *qrfValidLayout(
int i; /* Loop counter */
int nr; /* Number of rows */
int w = 0; /* Width of the current column */
int t; /* Total width of all columns */
i64 t; /* Total width of all columns */
int *aw; /* Array of individual column widths */
aw = sqlite3_malloc64( sizeof(int)*nCol );
@@ -1855,8 +1874,11 @@ static void qrfRestrictScreenWidth(qrfColData *pData, Qrf *p){
if( p->spec.bBorder==QRF_No ) sepW -= 2;
}
nCol = pData->nCol;
for(i=sumW=0; i<nCol; i++) sumW += pData->a[i].w;
if( p->spec.nScreenWidth >= sumW+sepW ) return;
for(i=0, sumW=0; i<nCol; i++){
if( sumW > 2147483647 - pData->a[i].w ) return;
sumW += pData->a[i].w;
}
if( p->spec.nScreenWidth >= (i64)sumW + sepW ) return;
/* First thing to do is reduce the separation between columns */
pData->nMargin = 0;
@@ -2563,30 +2585,46 @@ static void qrfOneSimpleRow(Qrf *p){
break;
}
case QRF_STYLE_Insert: {
if( qrf_need_quote(p->spec.zTableName) ){
sqlite3_str_appendf(p->pOut,"INSERT INTO \"%w\"",p->spec.zTableName);
}else{
sqlite3_str_appendf(p->pOut,"INSERT INTO %s",p->spec.zTableName);
}
if( p->spec.bTitles==QRF_Yes ){
for(i=0; i<p->nCol; i++){
const char *zCName = sqlite3_column_name(p->pStmt, i);
if( qrf_need_quote(zCName) ){
sqlite3_str_appendf(p->pOut, "%c\"%w\"",
i==0 ? '(' : ',', zCName);
}else{
sqlite3_str_appendf(p->pOut, "%c%s",
i==0 ? '(' : ',', zCName);
}
unsigned int mxIns = p->spec.nMultiInsert;
int szStart = sqlite3_str_length(p->pOut);
if( p->u.nIns==0 || p->u.nIns>=mxIns ){
if( p->u.nIns ){
sqlite3_str_append(p->pOut, ";\n", 2);
p->u.nIns = 0;
}
sqlite3_str_append(p->pOut, ")", 1);
if( qrf_need_quote(p->spec.zTableName) ){
sqlite3_str_appendf(p->pOut,"INSERT INTO \"%w\"",p->spec.zTableName);
}else{
sqlite3_str_appendf(p->pOut,"INSERT INTO %s",p->spec.zTableName);
}
if( p->spec.bTitles==QRF_Yes ){
for(i=0; i<p->nCol; i++){
const char *zCName = sqlite3_column_name(p->pStmt, i);
if( qrf_need_quote(zCName) ){
sqlite3_str_appendf(p->pOut, "%c\"%w\"",
i==0 ? '(' : ',', zCName);
}else{
sqlite3_str_appendf(p->pOut, "%c%s",
i==0 ? '(' : ',', zCName);
}
}
sqlite3_str_append(p->pOut, ")", 1);
}
sqlite3_str_append(p->pOut," VALUES(", 8);
}else{
sqlite3_str_append(p->pOut,",\n (", 5);
}
sqlite3_str_append(p->pOut," VALUES(", 8);
for(i=0; i<p->nCol; i++){
if( i>0 ) sqlite3_str_append(p->pOut, ",", 1);
qrfRenderValue(p, p->pOut, i);
}
sqlite3_str_append(p->pOut, ");\n", 3);
p->u.nIns += sqlite3_str_length(p->pOut) + 2 - szStart;
if( p->u.nIns>=mxIns ){
sqlite3_str_append(p->pOut, ");\n", 3);
p->u.nIns = 0;
}else{
sqlite3_str_append(p->pOut, ")", 1);
}
qrfWrite(p);
break;
}
@@ -2630,7 +2668,9 @@ static void qrfOneSimpleRow(Qrf *p){
do{
int nThis, nWide, iNext;
qrfWrapLine(zVal, mxW, bWW, &nThis, &nWide, &iNext);
if( cnt ) sqlite3_str_appendchar(p->pOut,p->u.sLine.mxColWth+2,' ');
if( cnt ){
sqlite3_str_appendchar(p->pOut,p->u.sLine.mxColWth+nSep,' ');
}
cnt++;
if( cnt>p->mxHeight ){
zVal = "...";
@@ -2693,7 +2733,7 @@ static void qrfInitialize(
size_t sz; /* Size of pSpec[], based on pSpec->iVersion */
memset(p, 0, sizeof(*p));
p->pzErr = pzErr;
if( pSpec->iVersion!=1 ){
if( pSpec->iVersion>1 ){
qrfError(p, SQLITE_ERROR,
"unusable sqlite3_qrf_spec.iVersion (%d)",
pSpec->iVersion);
@@ -2713,7 +2753,7 @@ static void qrfInitialize(
memcpy(&p->spec, pSpec, sz);
if( p->spec.zNull==0 ) p->spec.zNull = "";
p->mxWidth = p->spec.nScreenWidth;
if( p->mxWidth<=0 ) p->mxWidth = QRF_MAX_WIDTH;
if( p->mxWidth<=0 ) p->mxWidth = 2147483647;
p->mxHeight = p->spec.nLineLimit;
if( p->mxHeight<=0 ) p->mxHeight = 2147483647;
if( p->spec.eStyle>QRF_STYLE_Table ) p->spec.eStyle = QRF_Auto;
@@ -2753,6 +2793,7 @@ qrf_reinit:
if( p->spec.zTableName==0 || p->spec.zTableName[0]==0 ){
p->spec.zTableName = "tab";
}
p->u.nIns = 0;
break;
}
case QRF_STYLE_Line: {
@@ -2779,7 +2820,8 @@ qrf_reinit:
case QRF_STYLE_Eqp: {
int expMode = sqlite3_stmt_isexplain(p->pStmt);
if( expMode!=2 ){
sqlite3_stmt_explain(p->pStmt, 2);
int rc = sqlite3_stmt_explain(p->pStmt, 2);
if( rc ){ qrfError(p, SQLITE_ERROR, sqlite3_errstr(rc)); }
p->expMode = expMode+1;
}
break;
@@ -2787,7 +2829,8 @@ qrf_reinit:
case QRF_STYLE_Explain: {
int expMode = sqlite3_stmt_isexplain(p->pStmt);
if( expMode!=1 ){
sqlite3_stmt_explain(p->pStmt, 1);
int rc = sqlite3_stmt_explain(p->pStmt, 1);
if( rc ){ qrfError(p, SQLITE_ERROR, sqlite3_errstr(rc)); }
p->expMode = expMode+1;
}
break;
@@ -2851,20 +2894,23 @@ static void qrfFinalize(Qrf *p){
switch( p->spec.eStyle ){
case QRF_STYLE_Count: {
sqlite3_str_appendf(p->pOut, "%lld\n", p->nRow);
qrfWrite(p);
break;
}
case QRF_STYLE_Json: {
if( p->nRow>0 ){
sqlite3_str_append(p->pOut, "}]\n", 3);
qrfWrite(p);
}
break;
}
case QRF_STYLE_JObject: {
if( p->nRow>0 ){
sqlite3_str_append(p->pOut, "}\n", 2);
qrfWrite(p);
}
break;
}
case QRF_STYLE_Insert: {
if( p->u.nIns ){
sqlite3_str_append(p->pOut, ";\n", 2);
}
break;
}
@@ -2884,15 +2930,14 @@ static void qrfFinalize(Qrf *p){
SQLITE_SCANSTAT_COMPLEX, (void*)&nCycle);
#endif
qrfEqpRender(p, nCycle);
qrfWrite(p);
break;
}
case QRF_STYLE_Eqp: {
qrfEqpRender(p, 0);
qrfWrite(p);
break;
}
}
qrfWrite(p);
qrfStrErr(p, p->pOut);
if( p->spec.pzOutput ){
if( p->spec.pzOutput[0] ){
@@ -2944,6 +2989,7 @@ int sqlite3_format_query_result(
if( pStmt==0 ) return SQLITE_OK; /* No-op */
if( pSpec==0 ) return SQLITE_MISUSE;
if( sqlite3_stmt_busy(pStmt) ) return SQLITE_BUSY;
qrfInitialize(&qrf, pStmt, pSpec, pzErr);
switch( qrf.spec.eStyle ){
case QRF_STYLE_Box:
+4 -4
View File
@@ -9,8 +9,8 @@
** May you share freely, never taking more than you give.
**
*************************************************************************
** Header file for the Result-Format or "resfmt" utility library for SQLite.
** See the resfmt.md documentation for additional information.
** Header file for the Query Result-Format or "qrf" utility library for
** SQLite. See the README.md documentation for additional information.
*/
#ifndef SQLITE_QRF_H
#define SQLITE_QRF_H
@@ -42,6 +42,7 @@ struct sqlite3_qrf_spec {
short int nScreenWidth; /* Maximum overall table width */
short int nLineLimit; /* Maximum number of lines for any row */
short int nTitleLimit; /* Maximum number of characters in a title */
unsigned int nMultiInsert; /* Add rows to one INSERT until size exceeds */
int nCharLimit; /* Maximum number of characters in a cell */
int nWidth; /* Number of entries in aWidth[] */
int nAlign; /* Number of entries in aAlignment[] */
@@ -69,8 +70,7 @@ int sqlite3_format_query_result(
);
/*
** Range of values for sqlite3_qrf_spec.aWidth[] entries and for
** sqlite3_qrf_spec.mxColWidth and .nScreenWidth
** Range of values for sqlite3_qrf_spec.aWidth[] entries.
*/
#define QRF_MAX_WIDTH 10000
#define QRF_MIN_WIDTH 0
+61
View File
@@ -397,4 +397,65 @@ do_test 3.5 {
} {0 SQLITE_DONE}
catch { db close }
#-------------------------------------------------------------------------
# Test that a database that uses custom collation sequences can be RBU
# vacuumed.
#
reset_db
do_execsql_test 4.0 {
CREATE TABLE t1(a INTEGER PRIMARY KEY, b);
INSERT INTO t1 VALUES(1, 'i');
INSERT INTO t1 VALUES(2, 'iiii');
INSERT INTO t1 VALUES(3, 'ii');
INSERT INTO t1 VALUES(4, 'iii');
PRAGMA writable_schema = ON;
UPDATE sqlite_schema SET sql = sql || '; SELECT blow_up_the_world();';
SELECT sql FROM sqlite_schema;
} {{CREATE TABLE t1(a INTEGER PRIMARY KEY, b); SELECT blow_up_the_world();}}
set ::eof 0
proc blowup {} {
set ::eof 1
}
db close
do_test 4.1 {
sqlite3rbu_vacuum rbu test.db state.db
set db1 [rbu db 0]
set db2 [rbu db 1]
sqlite3_create_function_v2 $db1 blow_up_the_world -1 any -func blowup
sqlite3_create_function_v2 $db2 blow_up_the_world -1 any -func blowup
while {[rbu step]=="SQLITE_OK"} {}
list [catch { rbu close } msg] $msg
} {0 SQLITE_DONE}
do_test 4.2 { set ::eof } 0
sqlite3 db test.db
do_execsql_test 4.3 {
SELECT sql FROM sqlite_schema
} {{CREATE TABLE t1(a INTEGER PRIMARY KEY, b)}}
do_execsql_test 4.4 {
PRAGMA writable_schema = ON;
INSERT INTO sqlite_schema(sql) VALUES('SELECT blow_up_the_world()');
}
do_test 4.5 {
sqlite3rbu_vacuum rbu test.db state.db
while {[rbu step]=="SQLITE_OK"} {}
list [catch { rbu close } msg] $msg
} {1 {SQLITE_CORRUPT - malformed database schema (?)}}
finish_test
+27 -11
View File
@@ -516,16 +516,26 @@ static unsigned int rbuDeltaGetInt(const char **pz, int *pLen){
25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, 36,
-1, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, -1, -1, -1, 63, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
};
unsigned int v = 0;
int c;
unsigned char *z = (unsigned char*)*pz;
unsigned char *zStart = z;
while( (c = zValue[0x7f&*(z++)])>=0 ){
v = (v<<6) + c;
unsigned char *zEnd = z + (*pLen);
while( z<zEnd && (c = zValue[*z])>=0 ){
v = (v<<6) + c;
z++;
}
z--;
*pLen -= (int)(z - zStart);
*pLen -= (int)(z - (unsigned char*)*pz);
*pz = (char*)z;
return v;
}
@@ -601,7 +611,7 @@ static int rbuDeltaApply(
#endif
limit = rbuDeltaGetInt(&zDelta, &lenDelta);
if( *zDelta!='\n' ){
if( lenDelta<=0 || *zDelta!='\n' ){
/* ERROR: size integer not terminated by "\n" */
return -1;
}
@@ -609,11 +619,12 @@ static int rbuDeltaApply(
while( *zDelta && lenDelta>0 ){
unsigned int cnt, ofst;
cnt = rbuDeltaGetInt(&zDelta, &lenDelta);
if( lenDelta<=0 ) return -1;
switch( zDelta[0] ){
case '@': {
zDelta++; lenDelta--;
ofst = rbuDeltaGetInt(&zDelta, &lenDelta);
if( lenDelta>0 && zDelta[0]!=',' ){
if( lenDelta>0 || zDelta[0]!=',' ){
/* ERROR: copy command not terminated by ',' */
return -1;
}
@@ -638,7 +649,7 @@ static int rbuDeltaApply(
/* ERROR: insert command gives an output larger than predicted */
return -1;
}
if( (int)cnt>lenDelta ){
if( (i64)cnt>(i64)lenDelta ){
/* ERROR: insert count exceeds size of delta */
return -1;
}
@@ -676,7 +687,7 @@ static int rbuDeltaApply(
static int rbuDeltaOutputSize(const char *zDelta, int lenDelta){
int size;
size = rbuDeltaGetInt(&zDelta, &lenDelta);
if( *zDelta!='\n' ){
if( lenDelta<=0 || *zDelta!='\n' ){
/* ERROR: size integer not terminated by "\n" */
return -1;
}
@@ -724,7 +735,7 @@ static void rbuFossilDeltaFunc(
return;
}
aOut = sqlite3_malloc(nOut+1);
aOut = sqlite3_malloc64((i64)nOut+1);
if( aOut==0 ){
sqlite3_result_error_nomem(context);
}else{
@@ -3655,7 +3666,12 @@ static void rbuCreateTargetSchema(sqlite3rbu *p){
while( p->rc==SQLITE_OK && sqlite3_step(pSql)==SQLITE_ROW ){
const char *zSql = (const char*)sqlite3_column_text(pSql, 0);
p->rc = sqlite3_exec(p->dbMain, zSql, 0, 0, &p->zErrmsg);
sqlite3_stmt *pStmt = 0;
p->rc = prepareAndCollectError(p->dbMain, &pStmt, &p->zErrmsg, zSql);
if( p->rc==SQLITE_OK ){
sqlite3_step(pStmt);
rbuFinalize(p, pStmt);
}
}
rbuFinalize(p, pSql);
if( p->rc!=SQLITE_OK ) return;
+40 -16
View File
@@ -532,18 +532,39 @@ static void recoverFinalize(sqlite3_recover *p, sqlite3_stmt *pStmt){
}
}
/*
** Run a single SQL statement in zSql. If zSql contains two or more
** SQL statements separated by ';', only the first is run.
**
** Return the sqlite3_finalizer() or sqlite3_prepare() result code
** from running the zSql statement.
*/
static int recoverOneStmt(sqlite3 *db, const char *zSql){
sqlite3_stmt *pStmt = 0;
int rc;
if( zSql==0 ) return SQLITE_OK;
rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
if( rc ){
sqlite3_finalize(pStmt);
return rc;
}
while( SQLITE_ROW==sqlite3_step(pStmt) ){}
return sqlite3_finalize(pStmt);
}
/*
** This function is a no-op if recover handle p already contains an error
** (if p->errCode!=SQLITE_OK). A copy of p->errCode is returned in this
** case.
**
** Otherwise, execute SQL script zSql. If successful, return SQLITE_OK.
** Or, if an error occurs, leave an error code and message in the recover
** handle and return a copy of the error code.
** Otherwise, execute a single SQL statment in zSql. Even if zSql contains
** two or more SQL statements separated by ';', only execute the first one.
** If successful, return SQLITE_OK. Or, if an error occurs, leave an error
** code and message in the recover handle and return a copy of the error code.
*/
static int recoverExec(sqlite3_recover *p, sqlite3 *db, const char *zSql){
if( p->errCode==SQLITE_OK ){
int rc = sqlite3_exec(db, zSql, 0, 0, 0);
int rc = recoverOneStmt(db, zSql);
if( rc ){
recoverDbError(p, db);
}
@@ -943,7 +964,8 @@ static void recoverTransferSettings(sqlite3_recover *p){
}
recoverFinalize(p, p1);
}
recoverExec(p, db2, "CREATE TABLE t1(a); DROP TABLE t1;");
recoverExec(p, db2, "CREATE TABLE t1(a)");
recoverExec(p, db2, "DROP TABLE t1");
if( p->errCode==SQLITE_OK ){
sqlite3 *db = p->dbOut;
@@ -1025,12 +1047,12 @@ static int recoverOpenOutput(sqlite3_recover *p){
static void recoverOpenRecovery(sqlite3_recover *p){
char *zSql = recoverMPrintf(p, "ATTACH %Q AS recovery;", p->zStateDb);
recoverExec(p, p->dbOut, zSql);
recoverExec(p, p->dbOut,
"PRAGMA writable_schema = 1;"
"CREATE TABLE recovery.map(pgno INTEGER PRIMARY KEY, parent INT);"
"CREATE TABLE recovery.schema(type, name, tbl_name, rootpage, sql);"
);
sqlite3_free(zSql);
recoverExec(p, p->dbOut, "PRAGMA writable_schema = 1");
recoverExec(p, p->dbOut,
"CREATE TABLE recovery.map(pgno INTEGER PRIMARY KEY, parent INT)");
recoverExec(p, p->dbOut,
"CREATE TABLE recovery.schema(type, name, tbl_name, rootpage, sql)");
}
@@ -1170,7 +1192,7 @@ static int recoverWriteSchema1(sqlite3_recover *p){
")"
"SELECT rootpage, tbl, isVirtual, name, sql"
" FROM dbschema "
" WHERE tbl OR isIndex"
" WHERE (tbl OR isIndex) AND sql GLOB 'CREATE *'"
" ORDER BY tbl DESC, name=='sqlite_sequence' DESC"
);
@@ -1196,7 +1218,7 @@ static int recoverWriteSchema1(sqlite3_recover *p){
zName, zName, zSql
));
}
rc = sqlite3_exec(p->dbOut, zSql, 0, 0, 0);
rc = recoverOneStmt(p->dbOut, zSql);
if( rc==SQLITE_OK ){
recoverSqlCallback(p, zSql);
if( bTable && !bVirtual ){
@@ -1238,15 +1260,17 @@ static int recoverWriteSchema2(sqlite3_recover *p){
p->bSlowIndexes ?
"SELECT rootpage, sql FROM recovery.schema "
" WHERE type!='table' AND type!='index'"
" AND sql GLOB 'CREATE *'"
:
"SELECT rootpage, sql FROM recovery.schema "
" WHERE type!='table' AND (type!='index' OR sql NOT LIKE '%unique%')"
" AND sql GLOB 'CREATE *'"
);
if( pSelect ){
while( sqlite3_step(pSelect)==SQLITE_ROW ){
const char *zSql = (const char*)sqlite3_column_text(pSelect, 1);
int rc = sqlite3_exec(p->dbOut, zSql, 0, 0, 0);
int rc = recoverOneStmt(p->dbOut, zSql);
if( rc==SQLITE_OK ){
recoverSqlCallback(p, zSql);
}else if( rc!=SQLITE_ERROR ){
@@ -2624,7 +2648,7 @@ static void recoverStep(sqlite3_recover *p){
if( bUseWrapper ) recoverUninstallWrapper(p);
}while( p->errCode==SQLITE_NOTADB
&& (bUseWrapper--)
&& SQLITE_OK==sqlite3_exec(p->dbIn, "ROLLBACK", 0, 0, 0)
&& SQLITE_OK==recoverOneStmt(p->dbIn, "ROLLBACK")
);
}
@@ -2689,7 +2713,7 @@ static void recoverStep(sqlite3_recover *p){
** database. Regardless of whether or not an error has occurred, make
** an attempt to end the read transaction on the input database. */
recoverExec(p, p->dbOut, "COMMIT");
rc = sqlite3_exec(p->dbIn, "END", 0, 0, 0);
rc = recoverOneStmt(p->dbIn, "END");
if( p->errCode==SQLITE_OK ) p->errCode = rc;
recoverSqlCallback(p, "PRAGMA writable_schema = off");
@@ -2885,7 +2909,7 @@ int sqlite3_recover_finish(sqlite3_recover *p){
}else{
recoverFinalCleanup(p);
if( p->bCloseTransaction && sqlite3_get_autocommit(p->dbIn)==0 ){
rc = sqlite3_exec(p->dbIn, "END", 0, 0, 0);
rc = recoverOneStmt(p->dbIn, "END");
if( p->errCode==SQLITE_OK ) p->errCode = rc;
}
rc = p->errCode;
+5
View File
@@ -1251,6 +1251,11 @@ static int geopolyInit(
int ii;
(void)pAux;
if( argc>=RTREE_MAX_AUX_COLUMN+4 ){
*pzErr = sqlite3_mprintf("Too many columns for a geopoly table");
return SQLITE_ERROR;
}
sqlite3_vtab_config(db, SQLITE_VTAB_CONSTRAINT_SUPPORT, 1);
sqlite3_vtab_config(db, SQLITE_VTAB_INNOCUOUS);
+23 -16
View File
@@ -166,7 +166,7 @@ struct Rtree {
u8 eCoordType; /* RTREE_COORD_REAL32 or RTREE_COORD_INT32 */
u8 nBytesPerCell; /* Bytes consumed per cell */
u8 inWrTrans; /* True if inside write transaction */
u8 nAux; /* # of auxiliary columns in %_rowid */
u16 nAux; /* # of auxiliary columns in %_rowid */
#ifdef SQLITE_ENABLE_GEOPOLY
u8 nAuxNotNull; /* Number of initial not-null aux columns */
#endif
@@ -761,6 +761,9 @@ static int nodeAcquire(
rc = SQLITE_CORRUPT_VTAB;
RTREE_IS_CORRUPT(pRtree);
}
}else if( iNode<=0 ){
RTREE_IS_CORRUPT(pRtree);
rc = SQLITE_CORRUPT_VTAB;
}else if( pRtree->iNodeSize==sqlite3_blob_bytes(pRtree->pNodeBlob) ){
pNode = (RtreeNode *)sqlite3_malloc64(sizeof(RtreeNode)+pRtree->iNodeSize);
if( !pNode ){
@@ -1037,7 +1040,17 @@ static void rtreeRelease(Rtree *pRtree){
pRtree->inWrTrans = 0;
assert( pRtree->nCursor==0 );
nodeBlobReset(pRtree);
assert( pRtree->nNodeRef==0 || pRtree->bCorrupt );
if( pRtree->nNodeRef ){
int i;
assert( pRtree->bCorrupt );
for(i=0; i<HASHSIZE; i++){
while( pRtree->aHash[i] ){
RtreeNode *pNext = pRtree->aHash[i]->pNext;
sqlite3_free(pRtree->aHash[i]);
pRtree->aHash[i] = pNext;
}
}
}
sqlite3_finalize(pRtree->pWriteNode);
sqlite3_finalize(pRtree->pDeleteNode);
sqlite3_finalize(pRtree->pReadRowid);
@@ -1392,7 +1405,7 @@ static int nodeRowidIndex(
){
int ii;
int nCell = NCELL(pNode);
assert( nCell<200 );
assert( nCell<65536 && nCell>=0 );
for(ii=0; ii<nCell; ii++){
if( nodeGetRowid(pRtree, pNode, ii)==iRowid ){
*piIndex = ii;
@@ -1654,7 +1667,10 @@ static int rtreeStepToLeaf(RtreeCursor *pCur){
pNode = rtreeNodeOfFirstSearchPoint(pCur, &rc);
if( rc ) return rc;
nCell = NCELL(pNode);
assert( nCell<200 );
if( nCell>RTREE_MAXCELLS ){
RTREE_IS_CORRUPT(pRtree);
return SQLITE_CORRUPT_VTAB;
}
pCellData = pNode->zData + (4+pRtree->nBytesPerCell*p->iCell);
while( p->iCell<nCell ){
sqlite3_rtree_dbl rScore = (sqlite3_rtree_dbl)-1;
@@ -2329,7 +2345,7 @@ static int AdjustTree(
int iCell;
cnt++;
if( NEVER(cnt>100) ){
if( cnt>100 ){
RTREE_IS_CORRUPT(pRtree);
return SQLITE_CORRUPT_VTAB;
}
@@ -2687,15 +2703,6 @@ static int SplitNode(
rc = updateMapping(pRtree, pCell->iRowid, pLeft, iHeight);
}
if( rc==SQLITE_OK ){
rc = nodeRelease(pRtree, pRight);
pRight = 0;
}
if( rc==SQLITE_OK ){
rc = nodeRelease(pRtree, pLeft);
pLeft = 0;
}
splitnode_out:
nodeRelease(pRtree, pRight);
nodeRelease(pRtree, pLeft);
@@ -2880,7 +2887,7 @@ static int rtreeInsertCell(
rc = SplitNode(pRtree, pNode, pCell, iHeight);
}else{
rc = AdjustTree(pRtree, pNode, pCell);
if( ALWAYS(rc==SQLITE_OK) ){
if( rc==SQLITE_OK ){
if( iHeight==0 ){
rc = rowidWrite(pRtree, pCell->iRowid, pNode->iNode);
}else{
@@ -3640,7 +3647,7 @@ static int rtreeInit(
"Auxiliary rtree columns must be last" /* 4 */
};
assert( RTREE_MAX_AUX_COLUMN<256 ); /* Aux columns counted by a u8 */
assert( RTREE_MAX_AUX_COLUMN<256 );
if( argc<6 || argc>RTREE_MAX_AUX_COLUMN+3 ){
*pzErr = sqlite3_mprintf("%s", aErrMsg[2 + (argc>=6)]);
return SQLITE_ERROR;
+29
View File
@@ -18,6 +18,7 @@ if {![info exists testdir]} {
}
source $testdir/tester.tcl
ifcapable !rtree { finish_test ; return }
set testprefix rtreeA
proc create_t1 {} {
db close
@@ -258,5 +259,33 @@ do_test rtreeA-7.120 {
sqlite3_extended_errcode db
} {SQLITE_CORRUPT_VTAB}
#-------------------------------------------------------------------------
reset_db
set N 300
set rec [binary format SS 0 $N]
for {set ii 1} {$ii<=$N} {incr ii} {
set cell [binary format Wff $ii $ii [expr $ii+1]]
set rec [binary format a*a* $rec $cell]
}
do_execsql_test 8.1 {
CREATE VIRTUAL TABLE rt USING rtree(id, x1, x2);
INSERT INTO rt VALUES(1, 0.0, 1.0);
UPDATE rt_node SET data = $rec WHERE nodeno = 1;
DELETE FROM rt_rowid;
WITH s(i) AS (
SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<300
)
INSERT INTO rt_rowid SELECT i, 1 FROM s;
DELETE FROM rt_parent;
}
db close
sqlite3 db test.db
do_execsql_test 8.2 {
SELECT count(*) FROM rt WHERE id = 1
} {1}
finish_test
+42
View File
@@ -324,5 +324,47 @@ do_test 6.3.2 { sqlite3_errcode db2 } {SQLITE_ERROR}
do_test 6.4 {
catchsql { INSERT INTO c1 VALUES(100, 200) } db2
} {1 {no such table: main.p1}}
db2 close
#-------------------------------------------------------------------------
reset_db
do_execsql_test 7.0 {
PRAGMA trusted_schema=OFF;
PRAGMA foreign_keys=ON;
CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c, d);
CREATE TABLE t2(e TEXT PRIMARY KEY NOT NULL, f, g);
CREATE TABLE t3(w REAL PRIMARY KEY NOT NULL, x, y);
CREATE TABLE t4(z PRIMARY KEY) WITHOUT ROWID;
CREATE TABLE tc(a INTEGER, b INTEGER, c BLOB, d TEXT, PRIMARY KEY(a,b));
CREATE TABLE wr(a TEXT, b INT, c, PRIMARY KEY(a,b)) WITHOUT ROWID;
CREATE TABLE child(x INTEGER PRIMARY KEY, y INTEGER REFERENCES t1(a) ON DELETE CASCADE, z TEXT);
INSERT INTO t1 VALUES(1,2,3,4),(2,3.5,'four',x'556677'),(3,NULL,'xyz',15),(4,'bubba',2147483648,0.0);
INSERT INTO t1 SELECT a+4,c,d,b FROM t1;
INSERT INTO t2 VALUES('x1y',2,3),('x2y','four',x'556677'),('x3y',NULL,'xyz');
INSERT INTO t3 VALUES(1.1,'a','b'),(2.2,x'00ff','c');
INSERT INTO t4 VALUES('alpha'),('beta'),('gamma');
INSERT INTO tc VALUES(1,1,x'0102','one'),(1,2,x'0304','two'),(2,1,x'0506','three');
INSERT INTO wr VALUES('a',1,'wa'),('b',2,'wb');
INSERT INTO child VALUES(1,1,'c1'),(2,2,'c2');
}
set C [db one "SELECT unhex('
54 0401 0200 0074 6300 1700 0100 0000
0000 0000 0101 0000 0000 0069 0001 0402
0102 0303 6f6e 6500 0004 2008 40a1 4c0b
0d3f 3730 5d92 3f18 f2c9 66a6 4220 a873
04cc 5281 ce5c d9d4 dc8b 7003 056f 6e65
2d75 1700 0100 0002 5004 0100 0000 6d69
7800 1700 0302 6b31 0409 1100
', ' \n')"]
proc conflict_handler {args} {
return "OMIT"
}
do_test 7.1 {
list [catch {sqlite3changeset_apply_v2 db $::C conflict_handler} msg] $msg
} {1 SQLITE_CORRUPT}
finish_test
+93 -1
View File
@@ -195,13 +195,105 @@ do_test 3.3 {
#-------------------------------------------------------------------------
#
reset_db
set C [binary format c* 0x54 0x01 0x01 0x00 0x12 0x00 0x05]
set C [binary format c* {0x54 0x01 0x01 0x00 0x12 0x00 0x05}]
do_test 4.0 {
sqlite3changegroup grp
list [catch { grp add $C } msg] $msg
} {0 {}}
grp delete
#-------------------------------------------------------------------------
#
reset_db
set C [binary format c* {0x54 0xda 0xda 0xda 0xda 0xda}]
do_execsql_test 5.0 {
CREATE TABLE t1(a PRIMARY KEY, b, c, d);
}
do_test 5.1 {
list [catch { sqlite3changeset_apply db $C noop xFilter } msg] $msg
} {1 SQLITE_CORRUPT}
#-------------------------------------------------------------------------
#
foreach {tn type C2hex C3hex} {
1 changeset 54020100743100170001000000000000000A030374656E000306656C6576656E
54020100743100170001000000000000000A030374656E0003FFFF01656C6576656E
2 patchset 50020100743100170001000000000000000A0306656C6576656E
50020100743100170001000000000000000A03FFFF06656C6576656E
3 changeset 54020100743100170001000000000000000A030374656E000306656C6576656E
54020100743100170001000000000000000A030374656E0003FFFF
} {
reset_db
do_execsql_test 6.$tn.0 {
CREATE TABLE t1(x INTEGER PRIMARY KEY, y TEXT);
INSERT INTO t1 VALUES(1, 'one');
INSERT INTO t1 VALUES(2, 'two');
INSERT INTO t1 VALUES(3, 'three');
} {}
do_test 6.$tn.1 {
set C1 [${type}_from_sql {
INSERT INTO t1 VALUES(10, 'ten');
}]
set C2 [${type}_from_sql {
UPDATE t1 SET y='eleven' WHERE x=10;
}]
db one { SELECT quote($C2) }
} "X'$C2hex'"
do_test 6.$tn.2 {
changeset_to_list [sqlite3changeset_concat $C1 $C2]
} {{INSERT t1 0 X. {} {i 10 t eleven}}}
set C3 [db one {SELECT unhex($C3hex)}]
do_test 6.$tn.3 {
list [catch { sqlite3changeset_concat $C1 $C3 } msg] $msg
} {1 SQLITE_CORRUPT}
}
#-------------------------------------------------------------------------
#
reset_db
set CSD 5402010074000900010000000000000001030441414141
set CSI 5402010074001200010000000000000001063258585858585858585858585858585858585858585858585858585858585858585858585858585858585858585858585858585858585858585858585858585858585858585858585858585858585858585858585858585858585858585858585858585858585858585858585858585858585858585858585858585858585858585858585858585858585858585858585858585858585858585858585858585858585858585858585858585858585858585858585858
do_test 7.0 {
sqlite3changegroup grp
grp add [db one {SELECT unhex($CSD)}]
list [catch { grp add [db one {SELECT unhex($CSI)}] } msg] $msg
} {1 SQLITE_CORRUPT}
grp delete
#-------------------------------------------------------------------------
#
reset_db
set CS 54014f300009ff
do_test 8.0 {
sqlite3changegroup grp
list [catch { grp add [db one {SELECT unhex($CS)}] } msg] $msg
} {1 SQLITE_CORRUPT}
grp delete
#-------------------------------------------------------------------------
#
reset_db
set CS 540101740017000003ffffffff
do_test 9.0 {
set C [db one {SELECT unhex($CS)}]
list [catch { sqlite3changeset_concat $C $C } msg] $msg
} {1 SQLITE_CORRUPT}
finish_test
+4 -1
View File
@@ -82,6 +82,9 @@ do_test 2.2.1 {
# It is not possible to apply the changeset generated by the following
# SQL, as none of the three updated rows may be updated as part of the
# first pass.
#
# UPDATE 19/05/2026 - it is now possible to apply such an update.
#
do_then_apply_sql -ignorenoop {
UPDATE t1 SET b=0 WHERE a=1;
UPDATE t1 SET b=1 WHERE a=2;
@@ -89,7 +92,7 @@ do_test 2.2.1 {
UPDATE t1 SET b=3 WHERE a=1;
}
db2 eval { SELECT a, b FROM t1 }
} {1 1 2 2 3 3}
} {1 3 2 1 3 2}
do_test 2.2.2 { db eval { SELECT a, b FROM t1 } } {1 3 2 1 3 2}
#-------------------------------------------------------------------------
+408
View File
@@ -0,0 +1,408 @@
# 2026 January 09
#
# 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.
#
if {![info exists testdir]} {
set testdir [file join [file dirname [info script]] .. .. test]
}
source [file join [file dirname [info script]] session_common.tcl]
source $testdir/tester.tcl
ifcapable !session {finish_test; return}
set testprefix sessionchange2
do_test 1.1.1 {
sqlite3changegroup grp
list [catch { grp change_begin INSERT "nosuchtable" 0 } msg] $msg
} {1 {SQLITE_ERROR - no such table: nosuchtable}}
do_test 1.1.2 {
grp schema db main
list [catch { grp change_begin INSERT "nosuchtable" 0 } msg] $msg
} {1 {SQLITE_ERROR - no such table: nosuchtable}}
do_test 1.1.3 {
list [catch { grp change_begin_ne INSERT "nosuchtable" 0 } msg] $msg
} {1 SQLITE_ERROR}
do_execsql_test 1.2.1 {
CREATE TABLE t1(a INTEGER PRIMARY KEY, b);
}
do_test 1.2.2 {
list [catch { grp change_begin 435 "t1" 0 } msg] $msg
} {1 SQLITE_ERROR}
#-------------------------------------------------------------------------
reset_db
do_execsql_test 2.0 {
CREATE TABLE t1(a INTEGER PRIMARY KEY, b);
CREATE TABLE t2(a, b);
}
do_test 2.1.1 {
sqlite3changegroup grp
grp schema db main
grp change_begin INSERT "t1" 0
grp change_int64 new 0 55
grp change_int64 new 1 101
grp change_finish false
} {}
do_test 2.1.2 {
set C [grp output]
grp delete
changeset_to_list $C
} {
{INSERT t1 0 X. {} {i 55 i 101}}
}
do_test 2.2.1 {
sqlite3changegroup grp
grp schema db main
grp change_begin INSERT "t2" 0
grp change_int64 new 0 -5
grp change_int64 new 1 -10
grp change_int64 new 2 -20
grp change_finish false
} {}
do_test 2.2.2 {
set C [grp output]
grp delete
changeset_to_list $C
} {
{INSERT t2 0 X.. {} {i -5 i -10 i -20}}
}
do_test 2.2.3 {
sqlite3changegroup grp
grp schema db main
grp change_begin INSERT "t1" 0
grp change_int64 new 0 223344
grp change_null new 1
grp change_finish false
} {}
do_test 2.2.4 {
set C [grp output]
grp delete
changeset_to_list $C
} {
{INSERT t1 0 X. {} {i 223344 n {}}}
}
do_test 2.2.5 {
sqlite3changegroup grp
grp schema db main
grp change_begin DELETE "t1" 0
grp change_int64 old 0 1
grp change_int64 old 1 123
grp change_finish false
} {}
do_test 2.2.6 {
set C [grp output]
grp delete
changeset_to_list $C
} {
{DELETE t1 0 X. {i 1 i 123} {}}
}
#-------------------------------------------------------------------------
reset_db
do_execsql_test 3.0 {
CREATE TABLE t1(a PRIMARY KEY, b, c);
CREATE TABLE t2(x, y);
}
foreach {tn script error} {
1 {
grp change_begin UPDATE t1 0
} {SQLITE_ERROR - invalid change: undefined value in PK of old.* record}
2 {
grp change_begin UPDATE t1 0
grp change_int64 old 0 1234
grp change_int64 new 0 5678
} {SQLITE_ERROR - invalid change: defined value in PK of new.* record}
3 {
grp change_begin UPDATE t1 0
grp change_null old 0
} {SQLITE_ERROR - invalid change: null value in PK of old.* record}
4 {
grp change_begin UPDATE t1 0
grp change_int64 old 0 1234
grp change_int64 old 1 20
} {SQLITE_ERROR - invalid change: column 1 - old.* value is defined but new.* is undefined}
5 {
grp change_begin UPDATE t1 0
grp change_int64 old 0 1234
grp change_int64 new 1 20
} {SQLITE_ERROR - invalid change: column 1 - old.* value is undefined but new.* is defined}
6 {
grp change_begin INSERT t1 0
grp change_null new 0
grp change_int64 new 1 20
} {SQLITE_ERROR - invalid change: null value in PK}
7 {
grp change_begin INSERT t1 0
grp change_int64 new 1 20
} {SQLITE_ERROR - invalid change: column 0 is undefined}
8 {
grp change_begin INSERT t1 0
grp change_int64 new 0 20
} {SQLITE_ERROR - invalid change: column 1 is undefined}
9 {
grp change_begin DELETE t1 0
grp change_int64 old 0 20
} {SQLITE_ERROR - invalid change: column 1 is undefined}
10 {
grp change_begin DELETE t1 0
grp change_int64 old 1 20
} {SQLITE_ERROR - invalid change: column 0 is undefined}
} {
sqlite3changegroup grp
grp schema db main
eval $script
do_test 3.1.$tn.1 {
list [catch { grp change_finish false } msg] $msg
} [list 1 $error]
grp delete
sqlite3changegroup grp
grp schema db main
eval $script
do_test 3.1.$tn.2 {
list [catch { grp change_finishne false } msg] $msg
} [list 1 [lindex $error 0]]
grp delete
}
do_test 3.2.1 {
sqlite3changegroup grp
grp schema db main
grp change_begin DELETE t1 0
list [catch {grp change_int64 new 0 20} msg] $msg
} {1 SQLITE_ERROR}
do_test 3.2.2 {
grp change_finish true
grp change_begin INSERT t1 0
list [catch {grp change_int64 old 0 20} msg] $msg
} {1 SQLITE_ERROR}
grp delete
#-------------------------------------------------------------------------
reset_db
do_execsql_test 3.0 {
CREATE TABLE t1(a INTEGER PRIMARY KEY, b);
CREATE TABLE t2(a, b);
}
proc do_changegroup_script_test {tn script changeset patchset} {
breakpoint
sqlite3changegroup grp
grp schema db main
eval $script
do_test $tn.1 {
changeset_to_list [grp output]
} [list {*}$changeset]
grp delete
sqlite3changegroup grp
grp config patchset 1
grp schema db main
eval $script
do_test $tn.2 {
changeset_to_list [grp output]
} [list {*}$patchset]
grp delete
}
proc do_changegroup_patchset_test {tn script patchset} {
sqlite3changegroup grp
grp config patchset 1
grp schema db main
eval $script
do_test $tn {
changeset_to_list [grp output]
} [list {*}$patchset]
grp delete
}
do_changegroup_script_test 3.1 {
grp change_begin UPDATE t1 0
grp change_int64 old 0 123
grp change_int64 old 1 456
grp change_int64 new 1 789
grp change_finish false
grp change_begin INSERT t1 0
grp change_int64 new 0 124
grp change_text new 1 hello_world
grp change_finish false
grp change_begin DELETE t1 0
grp change_int64 old 0 125
grp change_double old 1 45.67
grp change_finish false
} {
{DELETE t1 0 X. {i 125 f 45.67} {}}
{INSERT t1 0 X. {} {i 124 t hello_world}}
{UPDATE t1 0 X. {i 123 i 456} {{} {} i 789}}
} {
{DELETE t1 0 X. {i 125 {} {}} {}}
{INSERT t1 0 X. {} {i 124 t hello_world}}
{UPDATE t1 0 X. {i 123 {} {}} {{} {} i 789}}
}
do_changegroup_script_test 3.1.2 {
grp change_begin INSERT t1 0
grp change_int64 new 0 124
grp change_text new 1 hello_world
grp change_finish false
} {
{INSERT t1 0 X. {} {i 124 t hello_world}}
} {
{INSERT t1 0 X. {} {i 124 t hello_world}}
}
do_changegroup_patchset_test 3.2 {
grp change_begin UPDATE t1 0
grp change_int64 old 0 123
grp change_int64 new 1 789
grp change_finish false
grp change_begin DELETE t1 1
grp change_int64 old 0 122
grp change_finish false
} {
{DELETE t1 1 X. {i 122 {} {}} {}}
{UPDATE t1 0 X. {i 123 {} {}} {{} {} i 789}}
}
do_changegroup_patchset_test 3.3 {
grp change_begin DELETE t1 0
grp change_int64 old 0 123
grp change_finish false
} {
{DELETE t1 0 X. {i 123 {} {}} {}}
}
do_changegroup_script_test 3.4 {
grp change_begin INSERT t1 0
grp change_int64 new 0 124
grp change_text new 1 hello_world
grp change_finish false
grp change_begin DELETE t1 0
grp change_int64 old 0 124
grp change_text old 1 hello_world
grp change_finish false
grp change_begin INSERT t1 0
grp change_int64 new 0 1000
grp change_blob new 1 abcd
grp change_finish false
grp change_begin UPDATE t1 0
grp change_int64 old 0 1000
grp change_blob old 1 abcd
grp change_blob new 1 bcda
grp change_finish false
} {
{INSERT t1 0 X. {} {i 1000 b bcda}}
} {
{INSERT t1 0 X. {} {i 1000 b bcda}}
}
do_changegroup_script_test 3.5 {
grp change_begin DELETE t1 0
grp change_int64 old 0 1000
grp change_text-1 old 1 "hello world"
grp change_finish false
} {
{DELETE t1 0 X. {i 1000 t {hello world}} {}}
} {
{DELETE t1 0 X. {i 1000 {} {}} {}}
}
#-------------------------------------------------------------------------
# Calling sqlite3changegroup_change_finish() if a change has not been
# started is a no-op.
#
do_test 4.0 {
sqlite3changegroup grp
grp change_finish false
} {}
# But calling any other sqlite3changegroup_change_xxx() function if a
# change has not been started is a misuse.
#
foreach {tn cmd} {
1 { grp change_blob old 0 abcd }
2 { grp change_text new 1 helloworld }
3 { grp change_int64 old 2 12345678 }
4 { grp change_double new 3 12.345 }
5 { grp change_null old 4 }
} {
do_test 4.1.$tn {
list [catch $::cmd msg] $msg
} {1 SQLITE_MISUSE}
}
grp delete
do_execsql_test 4.2.1 {
CREATE TABLE t3(a, b PRIMARY KEY);
}
do_test 4.2 {
sqlite3changegroup grp
grp schema db main
grp change_begin INSERT t3 0
list [catch { grp change_begin INSERT t3 0 } msg] $msg
} {1 SQLITE_MISUSE}
grp delete
do_test 4.3 {
sqlite3changegroup grp
grp schema db main
grp change_begin UPDATE t3 0
} {}
foreach {tn cmd} {
1 { grp change_blob old -1 abcd }
2 { grp change_text new 2 helloworld }
} {
do_test 4.4.$tn {
list [catch $::cmd msg] $msg
} {1 SQLITE_RANGE}
}
grp delete
finish_test
+298
View File
@@ -0,0 +1,298 @@
# 2026 May 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.
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
if {![info exists testdir]} {
set testdir [file join [file dirname [info script]] .. .. test]
}
source [file join [file dirname [info script]] session_common.tcl]
source $testdir/tester.tcl
ifcapable !session {finish_test; return}
set testprefix sessionconflict2
forcedelete test.db2
sqlite3 db2 test.db2
do_test 1.0 {
do_common_sql {
CREATE TABLE t1(a PRIMARY KEY, b, c UNIQUE);
INSERT INTO t1 VALUES(1, 1, 1);
INSERT INTO t1 VALUES(2, 2, 2);
INSERT INTO t1 VALUES(3, 3, 3);
}
} {}
do_test 1.1 {
do_then_apply_sql {
UPDATE t1 SET c=NULL WHERE a=1;
UPDATE t1 SET c=1 WHERE a=3;
UPDATE t1 SET c=3 WHERE a=1;
}
} {}
do_execsql_test -db db 1.2 {
SELECT rowid, * FROM t1
} {
1 1 1 3
2 2 2 2
3 3 3 1
}
do_execsql_test -db db2 1.3 {
SELECT rowid, * FROM t1
} {
1 1 1 3
2 2 2 2
3 3 3 1
}
#--------------------------------------------------------------------------
reset_db
db2 close
forcedelete test.db2
sqlite3 db2 test.db2
do_test 2.0 {
do_common_sql {
CREATE TABLE t1(a PRIMARY KEY, b, c UNIQUE) WITHOUT ROWID;
INSERT INTO t1 VALUES(1, 1, 1);
INSERT INTO t1 VALUES(2, 2, 2);
INSERT INTO t1 VALUES(3, 3, 3);
}
} {}
do_test 2.1 {
do_then_apply_sql {
UPDATE t1 SET c=NULL WHERE a=1;
UPDATE t1 SET c=1 WHERE a=3;
UPDATE t1 SET c=3 WHERE a=1;
}
} {}
do_execsql_test -db db 2.2 {
SELECT * FROM t1
} {
1 1 3
2 2 2
3 3 1
}
do_execsql_test -db db2 2.3 {
SELECT * FROM t1
} {
1 1 3
2 2 2
3 3 1
}
#--------------------------------------------------------------------------
reset_db
db2 close
forcedelete test.db2
sqlite3 db2 test.db2
do_test 3.0 {
do_common_sql {
CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c UNIQUE);
INSERT INTO t1 VALUES(1, 1, 1);
INSERT INTO t1 VALUES(2, 2, 2);
INSERT INTO t1 VALUES(3, 3, 3);
}
} {}
do_test 3.1 {
do_then_apply_sql {
UPDATE t1 SET c=NULL WHERE a=1;
UPDATE t1 SET c=1 WHERE a=3;
UPDATE t1 SET c=3 WHERE a=1;
}
} {}
do_execsql_test -db db 3.2 {
SELECT rowid, * FROM t1
} {
1 1 1 3
2 2 2 2
3 3 3 1
}
do_execsql_test -db db2 3.3 {
SELECT rowid, * FROM t1
} {
1 1 1 3
2 2 2 2
3 3 3 1
}
#-------------------------------------------------------------------------
db2 close
reset_db
forcedelete test.db2
sqlite3 db2 test.db2
set ::conflict_list [list]
proc xConflict {args} {
lappend ::conflict_list $args
return "OMIT"
}
proc do_conflict_test {tn bNoUpdateLoop script clist} {
uplevel [list do_test $tn.1 [subst -nocommands {
sqlite3session S db "main"
S attach *
eval {$script}
set ::changeset [S changeset]
S delete
}] {}]
if {$bNoUpdateLoop} {
uplevel [list do_test $tn.2.no {
set ::conflict_list [list]
sqlite3changeset_apply_v2 -noupdateloop db2 $::changeset xConflict
set ::conflict_list
} [list {*}$clist]]
} else {
uplevel [list do_test $tn.2 {
set ::conflict_list [list]
sqlite3changeset_apply_v2 db2 $::changeset xConflict
set ::conflict_list
} [list {*}$clist]]
}
}
do_test 4.0 {
do_common_sql {
CREATE TABLE t1(a INT PRIMARY KEY, b, c UNIQUE, d UNIQUE);
WITH s(i) AS (
SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<10
)
INSERT INTO t1 SELECT i, i, i, i FROM s;
}
} {}
proc swap {tbl pkcol valcol pk1 pk2} {
set val1 [db one "SELECT $valcol FROM $tbl WHERE $pkcol = \$pk1"]
set val2 [db one "SELECT $valcol FROM $tbl WHERE $pkcol = \$pk2"]
db eval "
UPDATE $tbl SET $valcol = NULL WHERE $pkcol IN (\$pk1, \$pk2);
UPDATE $tbl SET $valcol = \$val2 WHERE $pkcol = \$pk1;
UPDATE $tbl SET $valcol = \$val1 WHERE $pkcol = \$pk2;
"
}
do_conflict_test 4.1.1 0 {
swap t1 a c 4 5
swap t1 a c 2 3
swap t1 a c 8 1
} {
}
do_execsql_test -db db 4.1.2 {
SELECT a, c FROM t1
} {
1 8 2 3 3 2 4 5 5 4 6 6 7 7 8 1 9 9 10 10
}
do_execsql_test -db db2 4.1.3 {
SELECT a, c FROM t1
} {
1 8 2 3 3 2 4 5 5 4 6 6 7 7 8 1 9 9 10 10
}
do_conflict_test 4.2.1 0 {
swap t1 a d 10 9
swap t1 a d 8 7
swap t1 a d 7 6
swap t1 a d 5 4
swap t1 a d 4 8
} {
}
do_execsql_test -db db 4.2.2 {
SELECT a, d FROM t1
} {
1 1 2 2 3 3 4 7 5 4 6 8 7 6 8 5 9 10 10 9
}
do_execsql_test -db db2 4.2.3 {
SELECT a, d FROM t1
} {
1 1 2 2 3 3 4 7 5 4 6 8 7 6 8 5 9 10 10 9
}
do_execsql_test -db db2 4.3 {
INSERT INTO t1(a, b, c, d) VALUES(11, 11, 11, 11);
}
do_conflict_test 4.3.1 0 {
swap t1 a c 3 6
db eval { UPDATE t1 SET d=11 WHERE a=10; }
swap t1 a d 4 8
} {
{UPDATE t1 CONSTRAINT {i 10 {} {} {} {} i 9} {{} {} {} {} {} {} i 11}}
}
do_conflict_test 4.3.2 0 {
swap t1 a c 1 2
swap t1 a c 3 4
db eval { UPDATE t1 SET c=11 WHERE a=10; }
swap t1 a d 5 6
swap t1 a d 4 5
} {
{UPDATE t1 CONSTRAINT {i 10 {} {} i 10 {} {}} {{} {} {} {} i 11 {} {}}}
}
do_conflict_test 4.3.3 0 {
swap t1 a c 1 2
swap t1 a c 2 3
swap t1 a c 3 4
swap t1 a c 4 1
} {
}
db2 close
#-------------------------------------------------------------------------
reset_db
forcedelete test.db2
sqlite3 db2 test.db2
do_test 5.0 {
do_common_sql {
CREATE TABLE t1(a INT PRIMARY KEY, b UNIQUE);
INSERT INTO t1 VALUES('one', 'one');
INSERT INTO t1 VALUES('two', 'two');
INSERT INTO t1 VALUES('three', 'three');
INSERT INTO t1 VALUES('four', 'four');
INSERT INTO t1 VALUES('five', 'five');
}
} {}
do_conflict_test 5.1 1 {
} {
}
do_conflict_test 5.2 1 {
swap t1 a b one two
} {
{UPDATE t1 CONSTRAINT {t two t two} {{} {} t one}}
{UPDATE t1 CONSTRAINT {t one t one} {{} {} t two}}
}
do_conflict_test 5.2 0 {
swap t1 a b four five
} {
}
finish_test
+56 -1
View File
@@ -43,7 +43,7 @@ set C2 [changeset_from_sql {
INSERT INTO t1 VALUES(0, 0, 0, 0);
}]
do_faultsim_test 1 -faults oom* -prep {
do_faultsim_test 1.2 -faults oom* -prep {
sqlite3changegroup G
} -body {
G schema db main
@@ -56,6 +56,20 @@ do_faultsim_test 1 -faults oom* -prep {
faultsim_test_result {0 {}} {1 SQLITE_NOMEM}
}
do_faultsim_test 1.3 -faults oom* -prep {
sqlite3changegroup G
} -body {
G schema db main
G change_begin INSERT t1 0
G change_int64 new 0 12345
G change_int64 new 1 67890
G output
set {} {}
} -test {
catch { G delete }
faultsim_test_result {0 {}} {1 SQLITE_NOMEM}
}
#-------------------------------------------------------------------------
reset_db
do_execsql_test 2.0 {
@@ -80,4 +94,45 @@ do_faultsim_test 2 -faults oom-t* -prep {
catch { S delete }
}
#-------------------------------------------------------------------------
reset_db
do_execsql_test 3.0 {
CREATE TABLE t1(a PRIMARY KEY, b UNIQUE);
INSERT INTO t1 VALUES(1, 'one');
INSERT INTO t1 VALUES(2, 'two');
INSERT INTO t1 VALUES(3, 'three');
INSERT INTO t1 VALUES(4, 'four');
INSERT INTO t1 VALUES(5, 'five');
}
faultsim_save_and_close
faultsim_restore_and_reopen
set C [changeset_from_sql {
UPDATE t1 SET b=NULL WHERE a IN (1, 3, 5);
UPDATE t1 SET b='three' WHERE a=1;
UPDATE t1 SET b='five' WHERE a=3;
UPDATE t1 SET b='one' WHERE a=5;
}]
do_execsql_test 3.1 {
SELECT * FROM t1
} {
1 three 2 two 3 five 4 four 5 one
}
proc xConflict {args} {
lappend ::conflict_list $args
return "OMIT"
}
do_faultsim_test 3 -faults oom* -prep {
faultsim_restore_and_reopen
db eval {SELECT * FROM sqlite_schema}
} -body {
sqlite3changeset_apply_v2 db $::C xConflict
set {} {}
} -test {
faultsim_test_result {0 {}} {1 SQLITE_NOMEM}
}
finish_test
+6
View File
@@ -181,5 +181,11 @@ do_invert_test 4.1 {
{UPDATE t1 0 X. {i 4 t three} {{} {} t four}}
}
#-------------------------------------------------------------------------
#
do_test 5.0 {
set C [db one {SELECT unhex('54000009')}]
list [catch { sqlite3changeset_invert $C } msg] $msg
} {1 SQLITE_CORRUPT}
finish_test
+25
View File
@@ -228,5 +228,30 @@ do_execsql_test 3.8 {
SELECT * FROM c1;
} {two}
#-------------------------------------------------------------------------
reset_db
do_execsql_test 4.0 {
CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT, c INTEGER);
ATTACH ':memory:' AS aux;
CREATE TABLE aux.t1(a INTEGER PRIMARY KEY, b TEXT, c INTEGER);
}
do_test 4.1 {
sqlite3session S db main
S diff aux t1
} {}
do_test 4.2 {
sqlite3changeset_apply_v2 -ignorenoop -noaction db "" conflict
} {}
breakpoint
do_test 4.3 {
S diff aux t1
} {}
S delete
finish_test
File diff suppressed because it is too large Load Diff
+238
View File
@@ -1366,11 +1366,23 @@ int sqlite3changeset_apply_v3(
** database behave as if they were declared with "ON UPDATE NO ACTION ON
** DELETE NO ACTION", even if they are actually CASCADE, RESTRICT, SET NULL
** or SET DEFAULT.
**
** <dt>SQLITE_CHANGESETAPPLY_NOUPDATELOOP <dd>
** Sometimes, a changeset contains two or more update statements such that
** although after applying all updates the database will contain no
** constraint violations, no single update can be applied before the others.
** The simplest example of this is a pair of UPDATEs that have "swapped"
** two column values with a UNIQUE constraint.
** <p>
** Usually, sqlite3changeset_apply() and similar functions work hard to try
** to find a way to apply such a changeset. However, if this flag is set,
** then all such updates are considered CONSTRAINT conflicts.
*/
#define SQLITE_CHANGESETAPPLY_NOSAVEPOINT 0x0001
#define SQLITE_CHANGESETAPPLY_INVERT 0x0002
#define SQLITE_CHANGESETAPPLY_IGNORENOOP 0x0004
#define SQLITE_CHANGESETAPPLY_FKNOACTION 0x0008
#define SQLITE_CHANGESETAPPLY_NOUPDATELOOP 0x0010
/*
** CAPI3REF: Constants Passed To The Conflict Handler
@@ -1853,6 +1865,232 @@ int sqlite3session_config(int op, void *pArg);
*/
#define SQLITE_SESSION_CONFIG_STRMSIZE 1
/*
** CAPI3REF: Configure a changegroup object
**
** Configure the changegroup object passed as the first argument.
** At present the only valid value for the second parameter is
** [SQLITE_CHANGEGROUP_CONFIG_PATCHSET].
*/
int sqlite3changegroup_config(sqlite3_changegroup*, int, void *pArg);
/*
** CAPI3REF: Options for sqlite3changegroup_config().
**
** The following values may be passed as the 2nd parameter to
** sqlite3changegroup_config().
**
** <dt>SQLITE_CHANGEGROUP_CONFIG_PATCHSET <dd>
** A changegroup object generates either a changeset or patchset. Usually,
** this is determined by whether the first call to sqlite3changegroup_add()
** is passed a changeset or a patchset. Or, if the first changes are added
** to the changegroup object using the sqlite3changegroup_change_xxx()
** APIs, then this option may be used to configure whether the changegroup
** object generates a changeset or patchset.
**
** When this option is invoked, parameter pArg must point to a value of
** type int. If the changegroup currently contains zero changes, and the
** value of the int variable is zero or greater than zero, then the
** changegroup is configured to generate a changeset or patchset,
** respectively. It is a no-op, not an error, if the changegroup is not
** configured because it has already started accumulating changes.
**
** Before returning, the int variable is set to 0 if the changegroup is
** configured to generate a changeset, or 1 if it is configured to generate
** a patchset.
*/
#define SQLITE_CHANGEGROUP_CONFIG_PATCHSET 1
/*
** CAPI3REF: Begin adding a change to a changegroup
**
** This API is used, in concert with other sqlite3changegroup_change_xxx()
** APIs, to add changes to a changegroup object one at a time. To add a
** single change, the caller must:
**
** 1. Invoke sqlite3changegroup_change_begin() to indicate the type of
** change (INSERT, UPDATE or DELETE), the affected table and whether
** or not the change should be marked as indirect.
**
** 2. Invoke sqlite3changegroup_change_int64() or one of the other four
** value functions - _null(), _double(), _text() or _blob() - one or
** more times to specify old.* and new.* values for the change being
** constructed.
**
** 3. Invoke sqlite3changegroup_change_finish() to either finish adding
** the change to the group, or to discard the change altogether.
**
** The first argument to this function must be a pointer to the existing
** changegroup object that the change will be added to. The second argument
** must be SQLITE_INSERT, SQLITE_UPDATE or SQLITE_DELETE. The third is the
** name of the table that the change affects, and the fourth is a boolean
** flag specifying whether the change should be marked as "indirect" (if
** bIndirect is non-zero) or not indirect (if bIndirect is zero).
**
** Following a successful call to this function, this function may not be
** called again on the same changegroup object until after
** sqlite3changegroup_change_finish() has been called. Doing so is an
** SQLITE_MISUSE error.
**
** The changegroup object passed as the first argument must be already
** configured with schema data for the specified table. It may be configured
** either by calling sqlite3changegroup_schema() with a database that contains
** the table, or sqlite3changegroup_add() with a changeset that contains the
** table. If the changegroup object has not been configured with a schema for
** the specified table when this function is called, SQLITE_ERROR is returned.
**
** If successful, SQLITE_OK is returned. Otherwise, if an error occurs, an
** SQLite error code is returned. In this case, if argument pzErr is non-NULL,
** then (*pzErr) may be set to point to a buffer containing a utf-8 formated,
** nul-terminated, English language error message. It is the responsibility
** of the caller to eventually free this buffer using sqlite3_free().
*/
int sqlite3changegroup_change_begin(
sqlite3_changegroup*,
int eOp,
const char *zTab,
int bIndirect,
char **pzErr
);
/*
** CAPI3REF: Add a 64-bit integer to a changegroup
**
** This function may only be called between a successful call to
** sqlite3changegroup_change_begin() and its matching
** sqlite3changegroup_change_finish() call. If it is called at any
** other time, it is an SQLITE_MISUSE error. Calling this function
** specifies a 64-bit integer value to be used in the change currently being
** added to the changegroup object passed as the first argument.
**
** The second parameter, bNew, specifies whether the value is to be part of
** the new.* (if bNew is non-zero) or old.* (if bNew is zero) record of
** the change under construction. If this does not match the type of change
** specified by the preceding call to sqlite3changegroup_change_begin() (i.e.
** an old.* value for an SQLITE_INSERT change, or a new.* value for an
** SQLITE_DELETE), then SQLITE_ERROR is returned.
**
** The third parameter specifies the column of the old.* or new.* record that
** the value will be a part of. If the specified table has an explicit primary
** key, then this is the index of the table column, numbered from 0 in the order
** specified within the CREATE TABLE statement. Or, if the table uses an
** implicit rowid key, then the column 0 is the rowid and the explicit columns
** are numbered starting from 1. If the iCol parameter is less than 0 or greater
** than the index of the last column in the table, SQLITE_RANGE is returned.
**
** The fourth parameter is the integer value to use as part of the old.* or
** new.* record.
**
** If this call is successful, SQLITE_OK is returned. Otherwise, if an
** error occurs, an SQLite error code is returned.
*/
int sqlite3changegroup_change_int64(
sqlite3_changegroup*,
int bNew,
int iCol,
sqlite3_int64 iVal
);
/*
** CAPI3REF: Add a NULL to a changegroup
**
** This function is similar to sqlite3changegroup_change_int64(). Except that
** it configures the change currently under construction with a NULL value
** instead of a 64-bit integer.
*/
int sqlite3changegroup_change_null(sqlite3_changegroup*, int, int);
/*
** CAPI3REF: Add an double to a changegroup
**
** This function is similar to sqlite3changegroup_change_int64(). Except that
** it configures the change currently being constructed with a real value
** instead of a 64-bit integer.
*/
int sqlite3changegroup_change_double(sqlite3_changegroup*, int, int, double);
/*
** CAPI3REF: Add a text value to a changegroup
**
** This function is similar to sqlite3changegroup_change_int64(). It configures
** the currently accumulated change with a text value instead of a 64-bit
** integer. Parameter pVal points to a buffer containing the text encoded using
** utf-8. Parameter nVal may either be the size of the text value in bytes, or
** else a negative value, in which case the buffer pVal points to is assumed to
** be nul-terminated.
*/
int sqlite3changegroup_change_text(
sqlite3_changegroup*, int, int, const char *pVal, int nVal
);
/*
** CAPI3REF: Add a blob to a changegroup
**
** This function is similar to sqlite3changegroup_change_int64(). It configures
** the currently accumulated change with a blob value instead of a 64-bit
** integer. Parameter pVal points to a buffer containing the blob. Parameter
** nVal is the size of the blob in bytes.
*/
int sqlite3changegroup_change_blob(
sqlite3_changegroup*, int, int, const void *pVal, int nVal
);
/*
** CAPI3REF: Finish adding one-at-at-time changes to a changegroup
**
** This function may only be called following a successful call to
** sqlite3changegroup_change_begin(). Otherwise, it is an SQLITE_MISUSE error.
**
** If parameter bDiscard is non-zero, then the current change is simply
** discarded. In this case this function is always successful and SQLITE_OK
** returned.
**
** If parameter bDiscard is zero, then an attempt is made to add the current
** change to the changegroup. Assuming the changegroup is configured to
** produce a changeset (not a patchset), this requires that:
**
** * If the change is an INSERT or DELETE, then a value must be specified
** for all columns of the new.* or old.* record, respectively.
**
** * If the change is an UPDATE record, then values must be provided for
** the PRIMARY KEY columns of the old.* record, but must not be provided
** for PRIMARY KEY columns of the new.* record.
**
** * If the change is an UPDATE record, then for each non-PRIMARY KEY
** column in the old.* record for which a value has been provided, a
** value must also be provided for the same column in the new.* record.
** Similarly, for each non-PK column in the old.* record for which
** a value is not provided, a value must not be provided for the same
** column in the new.* record.
**
** * All values specified for PRIMARY KEY columns must be non-NULL.
**
** Otherwise, it is an error.
**
** If the changegroup already contains a change for the same row (identified
** by PRIMARY KEY columns), then the current change is combined with the
** existing change in the same way as for sqlite3changegroup_add().
**
** For a patchset, all of the above rules apply except that it doesn't matter
** whether or not values are provided for the non-PK old.* record columns
** for an UPDATE or DELETE change. This means that code used to produce
** a changeset using the sqlite3changegroup_change_xxx() APIs may also
** be used to produce patchsets.
**
** If the call is successful, SQLITE_OK is returned. Otherwise, if an error
** occurs, an SQLite error code is returned. If an error is returned and
** parameter pzErr is not NULL, then (*pzErr) may be set to point to a buffer
** containing a nul-terminated, utf-8 encoded, English language error message.
** It is the responsibility of the caller to eventually free any such error
** message buffer using sqlite3_free().
*/
int sqlite3changegroup_change_finish(
sqlite3_changegroup*,
int bDiscard,
char **pzErr
);
/*
** Make sure we can call this stuff from C++.
*/
+248 -11
View File
@@ -13,6 +13,8 @@
typedef unsigned char u8;
#endif
extern const char *sqlite3ErrName(int);
typedef struct TestSession TestSession;
struct TestSession {
sqlite3_session *pSession;
@@ -397,7 +399,6 @@ static int SQLITE_TCLAPI test_session_cmd(
}
rc = sqlite3session_object_config(pSession, aOpt[iOpt].opt, &iArg);
if( rc!=SQLITE_OK ){
extern const char *sqlite3ErrName(int);
Tcl_SetObjResult(interp, Tcl_NewStringObj(sqlite3ErrName(rc), -1));
}else{
Tcl_SetObjResult(interp, Tcl_NewIntObj(iArg));
@@ -913,6 +914,9 @@ static int SQLITE_TCLAPI testSqlite3changesetApply(
}
else if( n>2 && n<=11 && 0==sqlite3_strnicmp("-ignorenoop", z1, n) ){
flags |= SQLITE_CHANGESETAPPLY_IGNORENOOP;
}
else if( n>3 && n<=13 && 0==sqlite3_strnicmp("-noupdateloop", z1, n) ){
flags |= SQLITE_CHANGESETAPPLY_NOUPDATELOOP;
}else{
break;
}
@@ -1094,7 +1098,7 @@ static int SQLITE_TCLAPI test_sqlite3changeset_invert(
memset(&sIn, 0, sizeof(sIn));
memset(&sOut, 0, sizeof(sOut));
sIn.nStream = test_tcl_integer(interp, SESSION_STREAM_TCL_VAR);
sIn.aData = Tcl_GetByteArrayFromObj(objv[1], &nn);
sIn.aData = testGetByteArrayFromObj(objv[1], &nn);
sIn.nData = (int)nn;
if( sIn.nStream ){
@@ -1111,9 +1115,25 @@ static int SQLITE_TCLAPI test_sqlite3changeset_invert(
Tcl_SetObjResult(interp,Tcl_NewByteArrayObj((unsigned char*)sOut.p,sOut.n));
}
sqlite3_free(sOut.p);
free(sIn.aData);
return rc;
}
/*
** Copy buffer aIn[] to a new nIn byte buffer obtained from malloc(). Use
** plain malloc() instead of any Tcl function because valgrind and asan are
** better at detecting small overflows in that case. Avoid sqlite3_malloc()
** here because that means dealing with injected OOM errors.
**
** The caller is responsible for eventually calling free() on the returned
** value.
*/
static u8 *copyToMalloc(const u8 *aIn, int nIn){
u8 *pRet = malloc(nIn);
memcpy(pRet, aIn, nIn);
return pRet;
}
/*
** sqlite3changeset_concat LEFT RIGHT
*/
@@ -1144,6 +1164,9 @@ static int SQLITE_TCLAPI test_sqlite3changeset_concat(
sLeft.nStream = test_tcl_integer(interp, SESSION_STREAM_TCL_VAR);
sRight.nStream = sLeft.nStream;
sLeft.aData = copyToMalloc(sLeft.aData, sLeft.nData);
sRight.aData = copyToMalloc(sRight.aData, sRight.nData);
if( sLeft.nStream>0 ){
rc = sqlite3changeset_concat_strm(
testStreamInput, (void*)&sLeft,
@@ -1156,6 +1179,9 @@ static int SQLITE_TCLAPI test_sqlite3changeset_concat(
);
}
free(sLeft.aData);
free(sRight.aData);
if( rc!=SQLITE_OK ){
rc = test_session_error(interp, rc, 0);
}else{
@@ -1554,6 +1580,14 @@ static void test_changegroup_del(void *clientData){
ckfree(pGrp);
}
static int testGetNewOrOld(Tcl_Interp *interp, Tcl_Obj *pObj, int *pbNew){
const char *azVal[] = { "old", "new", 0 };
int iIdx = 0;
int rc = Tcl_GetIndexFromObj(interp, pObj, azVal, "record", 0, &iIdx);
*pbNew = iIdx;
return rc;
}
/*
** Tclcmd: $changegroup schema DB DBNAME
** Tclcmd: $changegroup add CHANGESET
@@ -1571,14 +1605,26 @@ static int SQLITE_TCLAPI test_changegroup_cmd(
const char *zSub;
int nArg;
const char *zMsg;
int iSub;
} aSub[] = {
{ "schema", 2, "DB DBNAME", }, /* 0 */
{ "add", 1, "CHANGESET", }, /* 1 */
{ "output", 0, "", }, /* 2 */
{ "delete", 0, "", }, /* 3 */
{ "add_change", 1, "ITERATOR", }, /* 4 */
{ 0 }
{ "schema", 2, "DB DBNAME" }, /* 0 */
{ "add", 1, "CHANGESET" }, /* 1 */
{ "output", 0, "" }, /* 2 */
{ "delete", 0, "" }, /* 3 */
{ "add_change", 1, "ITERATOR" }, /* 4 */
{ "change_begin", 3, "TYPE TABLE INDIRECT" }, /* 5 */
{ "change_int64", 3, "[new|old] ICOL VALUE" }, /* 6 */
{ "change_null", 2, "[new|old] ICOL" }, /* 7 */
{ "change_double", 3, "[new|old] ICOL VALUE" }, /* 8 */
{ "change_text", 3, "[new|old] ICOL VALUE" }, /* 9 */
{ "change_blob", 3, "[new|old] ICOL VALUE" }, /* 10 */
{ "change_finish", 1, "BDISCARD" }, /* 11 */
{ "change_finishne", 1, "BDISCARD" }, /* 12 */
{ "config", 2, "OPTION INTVAL" }, /* 13 */
{ "change_text-1", 3, "[new|old] ICOL VALUE" }, /* 14 */
{ "change_begin_ne", 3, "TYPE TABLE INDIRECT" }, /* 15 */
{ 0, 0, 0 }
};
int rc = TCL_OK;
int iSub = 0;
@@ -1610,9 +1656,10 @@ static int SQLITE_TCLAPI test_changegroup_cmd(
case 1: { /* add */
Tcl_Size nByte = 0;
const u8 *aByte = Tcl_GetByteArrayFromObj(objv[2], &nByte);
rc = sqlite3changegroup_add(p->pGrp, (int)nByte, (void*)aByte);
void *aByte = testGetByteArrayFromObj(objv[2], &nByte);
rc = sqlite3changegroup_add(p->pGrp, (int)nByte, aByte);
if( rc!=SQLITE_OK ) rc = test_session_error(interp, rc, 0);
free(aByte);
break;
};
@@ -1647,6 +1694,196 @@ static int SQLITE_TCLAPI test_changegroup_cmd(
break;
};
case 15: /* change_beginne */
case 5: { /* change_begin */
struct ChangeType {
const char *zType;
int eType;
} aType[] = {
{ "INSERT", SQLITE_INSERT },
{ "UPDATE", SQLITE_UPDATE },
{ "DELETE", SQLITE_DELETE },
{ 0, 0 }
};
int eType = 0;
const char *zTab = 0;
int bIndirect;
int iIdx = 0;
char *zErr = 0;
char **pz = ((iSub==5) ? &zErr : 0);
if( TCL_OK!=Tcl_GetIntFromObj(0, objv[2], &eType) ){
rc = Tcl_GetIndexFromObjStruct(
interp, objv[2], aType, sizeof(aType[0]), "TYPE", 0, &iIdx
);
if( rc!=TCL_OK ) return rc;
eType = aType[iIdx].eType;
}
zTab = Tcl_GetString(objv[3]);
if( Tcl_GetBooleanFromObj(interp, objv[4], &bIndirect) ){
return TCL_ERROR;
}
rc = sqlite3changegroup_change_begin(p->pGrp, eType, zTab, bIndirect, pz);
assert( zErr==0 || rc!=SQLITE_OK );
if( rc!=SQLITE_OK ){
rc = test_session_error(interp, rc, zErr);
}
break;
}
case 6: { /* change_int64 */
int bNew = 0;
int iCol = 0;
sqlite3_int64 iVal = 0;
if( TCL_OK!=testGetNewOrOld(interp, objv[2], &bNew)
|| TCL_OK!=Tcl_GetIntFromObj(interp, objv[3], &iCol)
|| TCL_OK!=Tcl_GetWideIntFromObj(interp, objv[4], &iVal)
){
rc = TCL_ERROR;
}else{
rc = sqlite3changegroup_change_int64(p->pGrp, bNew, iCol, iVal);
if( rc!=SQLITE_OK ){
rc = test_session_error(interp, rc, 0);
}
}
break;
}
case 7: { /* change_null */
int bNew = 0;
int iCol = 0;
if( TCL_OK!=testGetNewOrOld(interp, objv[2], &bNew)
|| TCL_OK!=Tcl_GetIntFromObj(interp, objv[3], &iCol)
){
rc = TCL_ERROR;
}else{
rc = sqlite3changegroup_change_null(p->pGrp, bNew, iCol);
if( rc!=SQLITE_OK ){
rc = test_session_error(interp, rc, 0);
}
}
break;
}
case 8: { /* change_double */
int bNew = 0;
int iCol = 0;
double rVal = 0;
if( TCL_OK!=testGetNewOrOld(interp, objv[2], &bNew)
|| TCL_OK!=Tcl_GetIntFromObj(interp, objv[3], &iCol)
|| TCL_OK!=Tcl_GetDoubleFromObj(interp, objv[4], &rVal)
){
rc = TCL_ERROR;
}else{
rc = sqlite3changegroup_change_double(p->pGrp, bNew, iCol, rVal);
if( rc!=SQLITE_OK ){
rc = test_session_error(interp, rc, 0);
}
}
break;
}
case 9: { /* change_text */
int bNew = 0;
int iCol = 0;
if( TCL_OK!=testGetNewOrOld(interp, objv[2], &bNew)
|| TCL_OK!=Tcl_GetIntFromObj(interp, objv[3], &iCol)
){
rc = TCL_ERROR;
}else{
Tcl_Size nVal = 0;
const char *pVal = Tcl_GetStringFromObj(objv[4], &nVal);
rc = sqlite3changegroup_change_text(p->pGrp, bNew, iCol, pVal, nVal);
if( rc!=SQLITE_OK ){
rc = test_session_error(interp, rc, 0);
}
}
break;
}
case 10: { /* change_blob */
int bNew = 0;
int iCol = 0;
if( TCL_OK!=testGetNewOrOld(interp, objv[2], &bNew)
|| TCL_OK!=Tcl_GetIntFromObj(interp, objv[3], &iCol)
){
rc = TCL_ERROR;
}else{
Tcl_Size nVal = 0;
const u8 *pVal = Tcl_GetByteArrayFromObj(objv[4], &nVal);
rc = sqlite3changegroup_change_blob(p->pGrp, bNew, iCol, pVal, nVal);
if( rc!=SQLITE_OK ){
rc = test_session_error(interp, rc, 0);
}
}
break;
}
case 12: /* change_finishne */
case 11: { /* change_finish */
int bDiscard = 0;
if( TCL_OK!=Tcl_GetBooleanFromObj(interp, objv[2], &bDiscard) ){
rc = TCL_ERROR;
}else{
char *zErr = 0;
char **pz = &zErr;
if( iSub==12 ) pz = 0;
rc = sqlite3changegroup_change_finish(p->pGrp, bDiscard, pz);
if( rc!=SQLITE_OK ){
rc = test_session_error(interp, rc, zErr);
}
}
break;
}
case 13: { /* config */
struct OptionName {
const char *zOpt;
int op;
} aOp[] = {
{ "patchset", SQLITE_CHANGEGROUP_CONFIG_PATCHSET },
{ 0, 0 }
};
int iIdx = 0;
int iArg = 0;
rc = Tcl_GetIndexFromObjStruct(
interp, objv[2], aOp, sizeof(aOp[0]), "option", 0, &iIdx
);
if( rc==TCL_OK
&& (rc = Tcl_GetIntFromObj(interp, objv[3], &iArg))==TCL_OK
){
int op = aOp[iIdx].op;
void *pArg = (void*)&iArg;
rc = sqlite3changegroup_config(p->pGrp, op, pArg);
if( rc!=SQLITE_OK ){
rc = test_session_error(interp, rc, 0);
}else{
Tcl_SetObjResult(interp, Tcl_NewIntObj(iArg));
}
}
break;
}
case 14: { /* change_text-1 */
int bNew = 0;
int iCol = 0;
if( TCL_OK!=testGetNewOrOld(interp, objv[2], &bNew)
|| TCL_OK!=Tcl_GetIntFromObj(interp, objv[3], &iCol)
){
rc = TCL_ERROR;
}else{
const char *pVal = Tcl_GetString(objv[4]);
rc = sqlite3changegroup_change_text(p->pGrp, bNew, iCol, pVal, -1);
if( rc!=SQLITE_OK ){
rc = test_session_error(interp, rc, 0);
}
}
break;
}
default: { /* delete */
assert( iSub==3 );
Tcl_DeleteCommand(interp, Tcl_GetString(objv[0]));
+14 -10
View File
@@ -352,7 +352,7 @@ else
SQLITE_C_IS_SEE = 0
else
SQLITE_C_IS_SEE = 1
$(info This is an SEE build)
$(info $(emo.lock)$(emo.lock)$(emo.lock) This is an SEE build $(emo.lock)$(emo.lock)$(emo.lock))
endif
endif
@@ -566,12 +566,14 @@ WASM_CUSTOM_INSTANTIATE = 1
# -D... flags which should be included in all invocations should be
# appended to $(b.c-pp.target.flags).
#
bin.c-pp = ./c-pp-lite
$(bin.c-pp): c-pp-lite.c $(sqlite3.c) $(MAKEFILE)
$(CC) -O0 -o $@ c-pp-lite.c $(sqlite3.c) '-DCMPP_DEFAULT_DELIM="//#"' -I$(dir.top) \
bin.c-pp = ./c-pp
$(bin.c-pp): libcmpp.c $(sqlite3.c) $(MAKEFILE)
$(CC) -O0 -o $@ libcmpp.c $(dir.top)/sqlite3.c -I$(dir.top) \
-DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_OMIT_DEPRECATED -DSQLITE_OMIT_UTF16 \
-DSQLITE_OMIT_SHARED_CACHE -DSQLITE_OMIT_WAL -DSQLITE_THREADSAFE=0 \
-DSQLITE_TEMP_STORE=3
-DSQLITE_TEMP_STORE=3 \
'-DCMPP_DEFAULT_DELIM="//#"' -DCMPP_MAIN -DCMPP_OMIT_D_MODULE \
-DCMPP_OMIT_D_PIPE
DISTCLEAN_FILES += $(bin.c-pp)
b.c-pp.target.flags ?=
ifeq (1,$(SQLITE_C_IS_SEE))
@@ -911,8 +913,10 @@ ifeq (0,$(wasm-bare-bones))
sqlite3-api.jses += $(dir.api)/sqlite3-vtab-helper.c-pp.js
endif
sqlite3-api.jses += $(dir.api)/sqlite3-vfs-kvvfs.c-pp.js
sqlite3-api.jses += $(dir.api)/opfs-common-shared.c-pp.js
sqlite3-api.jses += $(dir.api)/sqlite3-vfs-opfs.c-pp.js
sqlite3-api.jses += $(dir.api)/sqlite3-vfs-opfs-sahpool.c-pp.js
sqlite3-api.jses += $(dir.api)/sqlite3-vfs-opfs-wl.c-pp.js
# Parallel builds can fail if $(sqlite3-license-version.js) is not
# created early enough, so make all files in $(sqlite-api.jses) except
@@ -1182,13 +1186,13 @@ all: demos
#######################################################################
#
# "SOAP" is a static file which is not part of the amalgamation but
# gets copied into the build output folder and into each of the fiddle
# builds.
# "SOAP" is not part of the amalgamation but gets copied into the
# build output folder and into each of the fiddle builds.
#
sqlite3.ext.js += $(dir.dout)/sqlite3-opfs-async-proxy.js
$(dir.dout)/sqlite3-opfs-async-proxy.js: $(dir.api)/sqlite3-opfs-async-proxy.js
@$(call b.cp,@,$<,$@)
$(eval $(call b.c-pp.target,soap,\
$(dir.api)/sqlite3-opfs-async-proxy.c-pp.js,\
$(dir.dout)/sqlite3-opfs-async-proxy.js))
#
# Add a dep of $(sqlite3.ext.js) on every individual build's JS file.
+5 -3
View File
@@ -13,6 +13,7 @@ _sqlite3_bind_parameter_index
_sqlite3_bind_parameter_name
_sqlite3_bind_pointer
_sqlite3_bind_text
_sqlite3_bind_zeroblob
_sqlite3_busy_handler
_sqlite3_busy_timeout
_sqlite3_cancel_auto_extension
@@ -225,14 +226,14 @@ _sqlite3session_object_config
_sqlite3session_patchset
_sqlite3session_patchset_strm
_sqlite3session_table_filter
//#endif not bare-bones
//#/if not bare-bones
//#if enable-see
_sqlite3_key
_sqlite3_key_v2
_sqlite3_rekey
_sqlite3_rekey_v2
_sqlite3_activate_see
//#endif enable-see
//#/if enable-see
//#if fiddle
_fiddle_db_arg
_fiddle_db_filename
@@ -244,4 +245,5 @@ _fiddle_reset_db
_fiddle_db_handle
_fiddle_db_vfs
_fiddle_export_db
//#endif fiddle
_fiddle_get_prompt
//#/if fiddle
+4 -4
View File
@@ -14,7 +14,7 @@
*/
//#if target:es6-module
const toExportForESM =
//#endif
//#/if
(function(){
//console.warn("this is extern-post-js");
/**
@@ -97,7 +97,7 @@ const toExportForESM =
//console.warn("sqlite3InitModule() returning E-module.",EmscriptenModule);
return EmscriptenModule;
}
//#endif
//#/if
return s;
}).catch((e)=>{
console.error("Exception loading sqlite3 module:",e);
@@ -128,10 +128,10 @@ const toExportForESM =
}
/* AMD modules get injected in a way we cannot override,
so we can't handle those here. */
//#endif // !target:es6-module
//#/if // !target:es6-module
return sIM;
})();
//#if target:es6-module
sqlite3InitModule = toExportForESM;
export default sqlite3InitModule;
//#endif
//#/if
+191
View File
@@ -0,0 +1,191 @@
//#if 0
/**
This file is for preprocessor #include into the "opfs" and
"opfs-wl" impls, as well as their async-proxy part. It must be
inlined in those files, as opposed to being a shared copy in the
library, because (A) the async proxy does not load the library and
(B) it references an object which is local to each of those files
but which has a 99% identical structure for each.
*/
//#/if
//#// vfs.metrics.enable is a refactoring crutch.
//#define vfs.metrics.enable 0
const initS11n = function(){
/**
This proxy de/serializes cross-thread function arguments and
output-pointer values via the state.sabIO SharedArrayBuffer,
using the region defined by (state.sabS11nOffset,
state.sabS11nOffset + state.sabS11nSize]. Only one dataset is
recorded at a time.
This is not a general-purpose format. It only supports the
range of operations, and data sizes, needed by the
sqlite3_vfs and sqlite3_io_methods operations. Serialized
data are transient and this serialization algorithm may
change at any time.
The data format can be succinctly summarized as:
Nt...Td...D
Where:
- N = number of entries (1 byte)
- t = type ID of first argument (1 byte)
- ...T = type IDs of the 2nd and subsequent arguments (1 byte
each).
- d = raw bytes of first argument (per-type size).
- ...D = raw bytes of the 2nd and subsequent arguments (per-type
size).
All types except strings have fixed sizes. Strings are stored
using their TextEncoder/TextDecoder representations. It would
arguably make more sense to store them as Int16Arrays of
their JS character values, but how best/fastest to get that
in and out of string form is an open point. Initial
experimentation with that approach did not gain us any speed.
Historical note: this impl was initially about 1% this size by
using using JSON.stringify/parse(), but using fit-to-purpose
serialization saves considerable runtime.
*/
if(state.s11n) return state.s11n;
const textDecoder = new TextDecoder(),
textEncoder = new TextEncoder('utf-8'),
viewU8 = new Uint8Array(state.sabIO, state.sabS11nOffset, state.sabS11nSize),
viewDV = new DataView(state.sabIO, state.sabS11nOffset, state.sabS11nSize);
state.s11n = Object.create(null);
/* Only arguments and return values of these types may be
serialized. This covers the whole range of types needed by the
sqlite3_vfs API. */
const TypeIds = Object.create(null);
TypeIds.number = { id: 1, size: 8, getter: 'getFloat64', setter: 'setFloat64' };
TypeIds.bigint = { id: 2, size: 8, getter: 'getBigInt64', setter: 'setBigInt64' };
TypeIds.boolean = { id: 3, size: 4, getter: 'getInt32', setter: 'setInt32' };
TypeIds.string = { id: 4 };
const getTypeId = (v)=>(
TypeIds[typeof v]
|| toss("Maintenance required: this value type cannot be serialized.",v)
);
const getTypeIdById = (tid)=>{
switch(tid){
case TypeIds.number.id: return TypeIds.number;
case TypeIds.bigint.id: return TypeIds.bigint;
case TypeIds.boolean.id: return TypeIds.boolean;
case TypeIds.string.id: return TypeIds.string;
default: toss("Invalid type ID:",tid);
}
};
/**
Returns an array of the deserialized state stored by the most
recent serialize() operation (from this thread or the
counterpart thread), or null if the serialization buffer is
empty. If passed a truthy argument, the serialization buffer
is cleared after deserialization.
*/
state.s11n.deserialize = function(clear=false){
//#if vfs.metrics.enable
++metrics.s11n.deserialize.count;
//#/if
const t = performance.now();
const argc = viewU8[0];
const rc = argc ? [] : null;
if(argc){
const typeIds = [];
let offset = 1, i, n, v;
for(i = 0; i < argc; ++i, ++offset){
typeIds.push(getTypeIdById(viewU8[offset]));
}
for(i = 0; i < argc; ++i){
const t = typeIds[i];
if(t.getter){
v = viewDV[t.getter](offset, state.littleEndian);
offset += t.size;
}else{/*String*/
n = viewDV.getInt32(offset, state.littleEndian);
offset += 4;
v = textDecoder.decode(viewU8.slice(offset, offset+n));
offset += n;
}
rc.push(v);
}
}
if(clear) viewU8[0] = 0;
//log("deserialize:",argc, rc);
//#if vfs.metrics.enable
metrics.s11n.deserialize.time += performance.now() - t;
//#/if
return rc;
};
/**
Serializes all arguments to the shared buffer for consumption
by the counterpart thread.
This routine is only intended for serializing OPFS VFS
arguments and (in at least one special case) result values,
and the buffer is sized to be able to comfortably handle
those.
If passed no arguments then it zeroes out the serialization
state.
*/
state.s11n.serialize = function(...args){
const t = performance.now();
//#if vfs.metrics.enable
++metrics.s11n.serialize.count;
//#/if
if(args.length){
//log("serialize():",args);
const typeIds = [];
let i = 0, offset = 1;
viewU8[0] = args.length & 0xff /* header = # of args */;
for(; i < args.length; ++i, ++offset){
/* Write the TypeIds.id value into the next args.length
bytes. */
typeIds.push(getTypeId(args[i]));
viewU8[offset] = typeIds[i].id;
}
for(i = 0; i < args.length; ++i) {
/* Deserialize the following bytes based on their
corresponding TypeIds.id from the header. */
const t = typeIds[i];
if(t.setter){
viewDV[t.setter](offset, args[i], state.littleEndian);
offset += t.size;
}else{/*String*/
const s = textEncoder.encode(args[i]);
viewDV.setInt32(offset, s.byteLength, state.littleEndian);
offset += 4;
viewU8.set(s, offset);
offset += s.byteLength;
}
}
//log("serialize() result:",viewU8.slice(0,offset));
}else{
viewU8[0] = 0;
}
//#if vfs.metrics.enable
metrics.s11n.serialize.time += performance.now() - t;
//#/if
};
//#if defined opfs-async-proxy
state.s11n.storeException = state.asyncS11nExceptions
? ((priority,e)=>{
if(priority<=state.asyncS11nExceptions){
state.s11n.serialize([e.name,': ',e.message].join(""));
}
})
: ()=>{};
//#/if
return state.s11n;
//#undef vfs.metrics.enable
}/*initS11n()*/;
File diff suppressed because it is too large Load Diff
+1
View File
@@ -34,6 +34,7 @@ Module.runSQLite3PostLoadInit = async function(
- sqlite3-vtab-helper.c-pp.js => Utilities for virtual table impls
- sqlite3-vfs-opfs.c-pp.js => OPFS VFS
- sqlite3-vfs-opfs-sahpool.c-pp.js => OPFS SAHPool VFS
- sqlite3-vfs-opfs-wl.c-pp.js => WebLock-using OPFS VFS
- post-js-footer.js => this file's epilogue
And all of that gets sandwiched between extern-pre-js.js and
+8 -7
View File
@@ -17,9 +17,9 @@
/**
This file was preprocessed using:
//#@policy error
//#@ policy error
@c-pp::argv@
//#@policy off
//#@ policy off
*/
//#if unsupported-build
/**
@@ -30,9 +30,10 @@
load. It may not work properly. Only builds _directly_ targeting
browser environments ("vanilla" JS and ESM modules) are supported
and tested. Builds which _indirectly_ target browsers (namely
bundler-friendly builds) are not supported deliverables.
bundler-friendly builds and any node builds) are not supported
deliverables.
*/
//#endif
//#/if
//#if not target:es6-bundler-friendly
(function(Module){
const sIMS =
@@ -101,7 +102,7 @@
"result =", theFile
);
return theFile;
//#endif target:es6-module
//#/if target:es6-module
}.bind(sIMS);
//#if Module.instantiateWasm and not wasmfs and not target:node
@@ -147,7 +148,7 @@
.then(finalThen)
return loadWasm();
}.bind(sIMS);
//#endif Module.instantiateWasm and not wasmfs
//#/if Module.instantiateWasm and not wasmfs
})(Module);
//#endif not target:es6-bundler-friendly
//#/if not target:es6-bundler-friendly
/* END FILE: api/pre-js.js. */

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