From 87ac2b043a663720c84d0b7d923b7d9dca5391c1 Mon Sep 17 00:00:00 2001 From: stephan Date: Sat, 2 Sep 2023 05:37:58 +0000 Subject: [PATCH 001/430] Add EXTRA_SRC build var. If set, it is treated like a list of files, each of which gets appended verbatim to sqlite3.c. The intent is to enable easily extending the amalgamation. Requested in/around [forum:3fcc655f0ac0efe8|forum post 3fcc655f0ac0efe8]. FossilOrigin-Name: 934b84339860fa84a6faa3507bdd3cc58199e2636a394fc93176c80da0ba6f1c --- Makefile.in | 6 ++++-- main.mk | 5 ++--- manifest | 19 +++++++++++-------- manifest.uuid | 2 +- tool/mksqlite3c.tcl | 12 +++++++++--- 5 files changed, 27 insertions(+), 17 deletions(-) diff --git a/Makefile.in b/Makefile.in index e3bf1c0e7a..16ebf098c6 100644 --- a/Makefile.in +++ b/Makefile.in @@ -782,7 +782,8 @@ mptest: mptester$(TEXE) touch .target_source sqlite3.c: .target_source $(TOP)/tool/mksqlite3c.tcl src-verify - $(TCLSH_CMD) $(TOP)/tool/mksqlite3c.tcl $(AMALGAMATION_LINE_MACROS) + $(TCLSH_CMD) $(TOP)/tool/mksqlite3c.tcl $(AMALGAMATION_LINE_MACROS) \ + $(EXTRA_SRC) cp tsrc/sqlite3ext.h . cp $(TOP)/ext/session/sqlite3session.h . @@ -793,7 +794,8 @@ sqlite3r.c: sqlite3.c sqlite3r.h cp $(TOP)/ext/recover/sqlite3recover.c tsrc/ cp $(TOP)/ext/recover/sqlite3recover.h tsrc/ cp $(TOP)/ext/recover/dbdata.c tsrc/ - $(TCLSH_CMD) $(TOP)/tool/mksqlite3c.tcl --enable-recover $(AMALGAMATION_LINE_MACROS) + $(TCLSH_CMD) $(TOP)/tool/mksqlite3c.tcl --enable-recover \ + $(AMALGAMATION_LINE_MACROS) $(EXTRA_SRC) sqlite3ext.h: .target_source cp tsrc/sqlite3ext.h . diff --git a/main.mk b/main.mk index d8c372430e..0efdec309c 100644 --- a/main.mk +++ b/main.mk @@ -230,7 +230,6 @@ SRC += \ SRC += \ $(TOP)/ext/misc/stmt.c - # FTS5 things # FTS5_HDR = \ @@ -645,7 +644,7 @@ target_source: $(SRC) $(TOP)/tool/vdbe-compress.tcl fts5.c touch target_source sqlite3.c: target_source $(TOP)/tool/mksqlite3c.tcl src-verify - tclsh $(TOP)/tool/mksqlite3c.tcl + tclsh $(TOP)/tool/mksqlite3c.tcl $(EXTRA_SRC) cp tsrc/sqlite3ext.h . cp $(TOP)/ext/session/sqlite3session.h . echo '#ifndef USE_SYSTEM_SQLITE' >tclsqlite3.c @@ -657,7 +656,7 @@ sqlite3ext.h: target_source cp tsrc/sqlite3ext.h . sqlite3.c-debug: target_source $(TOP)/tool/mksqlite3c.tcl src-verify - tclsh $(TOP)/tool/mksqlite3c.tcl --linemacros=1 + tclsh $(TOP)/tool/mksqlite3c.tcl --linemacros=1 $(EXTRA_SRC) echo '#ifndef USE_SYSTEM_SQLITE' >tclsqlite3.c cat sqlite3.c >>tclsqlite3.c echo '#endif /* USE_SYSTEM_SQLITE */' >>tclsqlite3.c diff --git a/manifest b/manifest index 09646366ed..902e4aba7d 100644 --- a/manifest +++ b/manifest @@ -1,9 +1,9 @@ -C Second\shalf\sof\s[1c532e80]. -D 2023-09-01T11:10:09.238 +C Add\sEXTRA_SRC\sbuild\svar.\sIf\sset,\sit\sis\streated\slike\sa\slist\sof\sfiles,\seach\sof\swhich\sgets\sappended\sverbatim\sto\ssqlite3.c.\sThe\sintent\sis\sto\senable\seasily\sextending\sthe\samalgamation.\sRequested\sin/around\s[forum:3fcc655f0ac0efe8|forum\spost\s3fcc655f0ac0efe8]. +D 2023-09-02T05:37:58.754 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 -F Makefile.in 345a8599cf8ff015db534cedad7af70a1a6c36e295b85d720966c18af836ed30 +F Makefile.in c0ee78a772a33c1b377eb8f8b6f456ca10ad4aee86de4c9fcd16490e7432bcdb F Makefile.linux-gcc f3842a0b1efbfbb74ac0ef60e56b301836d05b4d867d014f714fa750048f1ab6 F Makefile.msc 26c2d196391a285c279adb10fd6001774d9b243af94b700b681e4a49cd476684 F README.md 963d30019abf0cc06b263cd2824bce022893f3f93a531758f6f04ff2194a16a8 @@ -625,7 +625,7 @@ F ext/wasm/wasmfs.make 8a4955882aaa0783b3f60a9484a1f0f3d8b6f775c0fcd17c082f31966 F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8 F magic.txt 5ade0bc977aa135e79e3faaea894d5671b26107cc91e70783aa7dc83f22f3ba0 -F main.mk 5536159f62058714c972b5bd325c8d5ecd5c9b00b385dd2e1cbc17da70a711b2 +F main.mk 48632ee12ecb9157c8f662794051260933518b52c5b430c30c3852b6743a48bc F mptest/config01.test 3c6adcbc50b991866855f1977ff172eb6d901271 F mptest/config02.test 4415dfe36c48785f751e16e32c20b077c28ae504 F mptest/crash01.test 61e61469e257df0850df4293d7d4d6c2af301421 @@ -2048,7 +2048,7 @@ F tool/mkshellc.tcl b7adf08b82de60811d2cb6af05ff59fc17e5cd6f3e98743c14eaaa3f8971 F tool/mksourceid.c 36aa8020014aed0836fd13c51d6dc9219b0df1761d6b5f58ff5b616211b079b9 F tool/mkspeedsql.tcl a1a334d288f7adfe6e996f2e712becf076745c97 F tool/mksqlite3c-noext.tcl 4f7cfef5152b0c91920355cbfc1d608a4ad242cb819f1aea07f6d0274f584a7f -F tool/mksqlite3c.tcl 49e39b1e616abc92fd8c24445f2b0a38881825f764541e0026f72371f0d84b65 +F tool/mksqlite3c.tcl 4f366e3d1ddb28996a6763c847fa62e1452bb11ca702841485df77823ec94ea4 F tool/mksqlite3h.tcl d391cff7cad0a372ee1406faee9ccc7dad9cb80a0c95cae0f73d10dd26e06762 F tool/mksqlite3internalh.tcl eb994013e833359137eb53a55acdad0b5ae1049b F tool/mkvsix.tcl b9e0777a213c23156b6542842c238479e496ebf5 @@ -2115,8 +2115,11 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 1c532e807bf8466b67d9600ab9630a6736de77259e9a71ac435641715ee0e04b -R ea796b2653d720202144fba261cf7ada +P 8ca1d815a57be1fade59fb8ea5705c27b10294e4959c8a9c624f1623df6a5f63 +R 26961792cf57fe21537a8837bc1686c0 +T *branch * extra-src +T *sym-extra-src * +T -sym-trunk * Cancelled\sby\sbranch. U stephan -Z 3f0f478ea9581db06db30ac4b45877cc +Z 89876b5c6405dcc4d6d608637f43ad0e # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 2cefe103b6..f5b052c057 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8ca1d815a57be1fade59fb8ea5705c27b10294e4959c8a9c624f1623df6a5f63 \ No newline at end of file +934b84339860fa84a6faa3507bdd3cc58199e2636a394fc93176c80da0ba6f1c \ No newline at end of file diff --git a/tool/mksqlite3c.tcl b/tool/mksqlite3c.tcl index 6def8fa447..bdbc01e496 100644 --- a/tool/mksqlite3c.tcl +++ b/tool/mksqlite3c.tcl @@ -17,7 +17,7 @@ # After the "tsrc" directory has been created and populated, run # this script: # -# tclsh mksqlite3c.tcl +# tclsh mksqlite3c.tcl [flags] [extra source files] # # The amalgamated SQLite code will be written into sqlite3.c # @@ -42,6 +42,7 @@ set linemacros 0 set useapicall 0 set enable_recover 0 set srcdir tsrc +set extrasrc [list] for {set i 0} {$i<[llength $argv]} {incr i} { set x [lindex $argv $i] @@ -63,8 +64,10 @@ for {set i 0} {$i<[llength $argv]} {incr i} { } elseif {[regexp {^-?-((help)|\?)$} $x]} { puts $help exit 0 - } else { + } elseif {[regexp {^-?-} $x]} { error "unknown command-line option: $x" + } else { + lappend extrasrc $x } } set in [open $srcdir/sqlite3.h] @@ -470,13 +473,16 @@ set flist { sqlite3session.c fts5.c stmt.c -} +} if {$enable_recover} { lappend flist sqlite3recover.c dbdata.c } foreach file $flist { copy_file $srcdir/$file } +foreach file $extrasrc { + copy_file $file +} puts $out \ "/* Return the source-id for this library */ From 2065a9b7305e43bb84e003242431d7f859511dad Mon Sep 17 00:00:00 2001 From: mistachkin Date: Sat, 2 Sep 2023 21:55:10 +0000 Subject: [PATCH 002/430] Also add support for EXTRA_SRC in the Makefile for MSVC. FossilOrigin-Name: bfc18ef4323cd73fc63cb93f18bdd9c3add41bea83c1cbc1c20de5c1e4296a60 --- Makefile.msc | 6 +++++- manifest | 17 +++++++---------- manifest.uuid | 2 +- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/Makefile.msc b/Makefile.msc index 3179e301ce..9b0f8c412f 100644 --- a/Makefile.msc +++ b/Makefile.msc @@ -16,6 +16,10 @@ TOP = . !IFNDEF USE_AMALGAMATION USE_AMALGAMATION = 1 !ENDIF + +!IFNDEF EXTRA_SRC +EXTRA_SRC = +!ENDIF # <> # Set this non-0 to enable full warnings (-W4, etc) when compiling. @@ -1904,7 +1908,7 @@ mptest: mptester.exe echo > .target_source sqlite3.c: .target_source sqlite3ext.h sqlite3session.h $(MKSQLITE3C_TOOL) src-verify.exe - $(TCLSH_CMD) $(MKSQLITE3C_TOOL) $(MKSQLITE3C_ARGS) + $(TCLSH_CMD) $(MKSQLITE3C_TOOL) $(MKSQLITE3C_ARGS) $(EXTRA_SRC) sqlite3-all.c: sqlite3.c $(TOP)\tool\split-sqlite3c.tcl $(TCLSH_CMD) $(TOP)\tool\split-sqlite3c.tcl diff --git a/manifest b/manifest index 902e4aba7d..f2e0fcdcfc 100644 --- a/manifest +++ b/manifest @@ -1,11 +1,11 @@ -C Add\sEXTRA_SRC\sbuild\svar.\sIf\sset,\sit\sis\streated\slike\sa\slist\sof\sfiles,\seach\sof\swhich\sgets\sappended\sverbatim\sto\ssqlite3.c.\sThe\sintent\sis\sto\senable\seasily\sextending\sthe\samalgamation.\sRequested\sin/around\s[forum:3fcc655f0ac0efe8|forum\spost\s3fcc655f0ac0efe8]. -D 2023-09-02T05:37:58.754 +C Also\sadd\ssupport\sfor\sEXTRA_SRC\sin\sthe\sMakefile\sfor\sMSVC. +D 2023-09-02T21:55:10.922 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 F Makefile.in c0ee78a772a33c1b377eb8f8b6f456ca10ad4aee86de4c9fcd16490e7432bcdb F Makefile.linux-gcc f3842a0b1efbfbb74ac0ef60e56b301836d05b4d867d014f714fa750048f1ab6 -F Makefile.msc 26c2d196391a285c279adb10fd6001774d9b243af94b700b681e4a49cd476684 +F Makefile.msc 4d7da1cd760e595cf751f8b3220c0b20657b20969713803ea538f66950453828 F README.md 963d30019abf0cc06b263cd2824bce022893f3f93a531758f6f04ff2194a16a8 F VERSION 4c09b629c03b8ae32317cb336a32f3aa3252841d6dcd51184cecc4278d08f21e F aclocal.m4 a5c22d164aff7ed549d53a90fa56d56955281f50 @@ -2115,11 +2115,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 8ca1d815a57be1fade59fb8ea5705c27b10294e4959c8a9c624f1623df6a5f63 -R 26961792cf57fe21537a8837bc1686c0 -T *branch * extra-src -T *sym-extra-src * -T -sym-trunk * Cancelled\sby\sbranch. -U stephan -Z 89876b5c6405dcc4d6d608637f43ad0e +P 934b84339860fa84a6faa3507bdd3cc58199e2636a394fc93176c80da0ba6f1c +R c273c661c255a780f4edcaa61a31a00b +U mistachkin +Z 47e1eabb65e7f37ad8c0f6188be76f6d # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index f5b052c057..9687ff42b9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -934b84339860fa84a6faa3507bdd3cc58199e2636a394fc93176c80da0ba6f1c \ No newline at end of file +bfc18ef4323cd73fc63cb93f18bdd9c3add41bea83c1cbc1c20de5c1e4296a60 \ No newline at end of file From 45cf8ad02a30f76212f7b1c00fa45b00e8626eb6 Mon Sep 17 00:00:00 2001 From: stephan Date: Sun, 3 Sep 2023 15:01:11 +0000 Subject: [PATCH 003/430] In mksqlite3c.tcl, pass EXTRA_SRC files through verbatim instead of applying the post-processing needed for sqlite's own source files. FossilOrigin-Name: 44f3d7d054055fab4cca0ba753e75e237ca159ae868ffd1d13ed45a874a772f2 --- manifest | 14 +++++++------- manifest.uuid | 2 +- tool/mksqlite3c.tcl | 17 ++++++++++++++++- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index f2e0fcdcfc..2d41793356 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Also\sadd\ssupport\sfor\sEXTRA_SRC\sin\sthe\sMakefile\sfor\sMSVC. -D 2023-09-02T21:55:10.922 +C In\smksqlite3c.tcl,\spass\sEXTRA_SRC\sfiles\sthrough\sverbatim\sinstead\sof\sapplying\sthe\spost-processing\sneeded\sfor\ssqlite's\sown\ssource\sfiles. +D 2023-09-03T15:01:11.477 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -2048,7 +2048,7 @@ F tool/mkshellc.tcl b7adf08b82de60811d2cb6af05ff59fc17e5cd6f3e98743c14eaaa3f8971 F tool/mksourceid.c 36aa8020014aed0836fd13c51d6dc9219b0df1761d6b5f58ff5b616211b079b9 F tool/mkspeedsql.tcl a1a334d288f7adfe6e996f2e712becf076745c97 F tool/mksqlite3c-noext.tcl 4f7cfef5152b0c91920355cbfc1d608a4ad242cb819f1aea07f6d0274f584a7f -F tool/mksqlite3c.tcl 4f366e3d1ddb28996a6763c847fa62e1452bb11ca702841485df77823ec94ea4 +F tool/mksqlite3c.tcl 6d95b3317a7c51e76458c1d4b056b1791b4d9022570e2e23efbaf6a272b47de2 F tool/mksqlite3h.tcl d391cff7cad0a372ee1406faee9ccc7dad9cb80a0c95cae0f73d10dd26e06762 F tool/mksqlite3internalh.tcl eb994013e833359137eb53a55acdad0b5ae1049b F tool/mkvsix.tcl b9e0777a213c23156b6542842c238479e496ebf5 @@ -2115,8 +2115,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 934b84339860fa84a6faa3507bdd3cc58199e2636a394fc93176c80da0ba6f1c -R c273c661c255a780f4edcaa61a31a00b -U mistachkin -Z 47e1eabb65e7f37ad8c0f6188be76f6d +P bfc18ef4323cd73fc63cb93f18bdd9c3add41bea83c1cbc1c20de5c1e4296a60 +R 7d78e3217d362137366a609d99cdc8a6 +U stephan +Z c9456c989544e03851e269725c9f500c # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 9687ff42b9..ed0de42d69 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -bfc18ef4323cd73fc63cb93f18bdd9c3add41bea83c1cbc1c20de5c1e4296a60 \ No newline at end of file +44f3d7d054055fab4cca0ba753e75e237ca159ae868ffd1d13ed45a874a772f2 \ No newline at end of file diff --git a/tool/mksqlite3c.tcl b/tool/mksqlite3c.tcl index bdbc01e496..0ed96d2032 100644 --- a/tool/mksqlite3c.tcl +++ b/tool/mksqlite3c.tcl @@ -352,6 +352,21 @@ proc copy_file {filename} { section_comment "End of $tail" } +# Read the source file named $filename and write it into the +# sqlite3.c output file. The only transformation is the trimming +# of EOL whitespace. +# +proc copy_file_verbatim {filename} { + global out + set in [open $filename r] + set tail [file tail $filename] + section_comment "Begin EXTRA_SRC file $tail" + while {![eof $in]} { + set line [string trimright [gets $in]] + puts $out $line + } + section_comment "End of EXTRA_SRC $tail" +} # Process the source files. Process files containing commonly # used subroutines first in order to help the compiler find @@ -481,7 +496,7 @@ foreach file $flist { copy_file $srcdir/$file } foreach file $extrasrc { - copy_file $file + copy_file_verbatim $file } puts $out \ From 6b36d0b46189d217721d25ce475fad171ae0a227 Mon Sep 17 00:00:00 2001 From: stephan Date: Mon, 8 Jan 2024 07:52:47 +0000 Subject: [PATCH 004/430] Make explicit which JS APIs are for internal use only by moving the JS-bound internal-use-only functions out of client-visible reach and renaming the WASM-exported ones from sqlite3_wasm... to sqlite3__wasm... (with two underscores). These have always been documented as internal-use-only, so this is not a breaking change except for clients which have ignored the docs. FossilOrigin-Name: 0eddc20f37988df6bce5f407b69e4a315e5cca4af104586e6fe942f0d656cccd --- ext/wasm/GNUmakefile | 5 +- ext/wasm/api/sqlite3-api-glue.js | 68 +++++++------- ext/wasm/api/sqlite3-api-prologue.js | 30 +++---- ext/wasm/api/sqlite3-api-worker1.js | 9 +- ext/wasm/api/sqlite3-wasm.c | 129 +++++++++++++-------------- ext/wasm/fiddle/fiddle-worker.js | 4 +- ext/wasm/speedtest1-worker.js | 4 - ext/wasm/tester1.c-pp.js | 43 ++++----- manifest | 31 ++++--- manifest.uuid | 2 +- 10 files changed, 162 insertions(+), 163 deletions(-) diff --git a/ext/wasm/GNUmakefile b/ext/wasm/GNUmakefile index f0cff463a8..cbba48cc58 100644 --- a/ext/wasm/GNUmakefile +++ b/ext/wasm/GNUmakefile @@ -43,8 +43,9 @@ # which generates the makefile code, rather than using $(call) and # $(eval), or at least centralize the setup of the numerous vars # related to each build variant $(JS_BUILD_MODES). (Update: an -# external script was attempted but it's even less legible than the -# $(eval) indirection going on in this file. +# external script was attempted but generating properly-escaped +# makefile code from within a shell script is even less legible +# than the $(eval) indirection going on in this file.) # default: all #default: quick diff --git a/ext/wasm/api/sqlite3-api-glue.js b/ext/wasm/api/sqlite3-api-glue.js index 29efb3e07b..e12c5162c6 100644 --- a/ext/wasm/api/sqlite3-api-glue.js +++ b/ext/wasm/api/sqlite3-api-glue.js @@ -601,16 +601,16 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ /** Functions which are intended solely for API-internal use by the WASM components, not client code. These get installed into - sqlite3.wasm. Some of them get exposed to clients via variants - named sqlite3_js_...(). + sqlite3.util. Some of them get exposed to clients via variants + in wasm.sqlite3_js_...(). */ - wasm.bindingSignatures.wasm = [ - ["sqlite3_wasm_db_reset", "int", "sqlite3*"], - ["sqlite3_wasm_db_vfs", "sqlite3_vfs*", "sqlite3*","string"], - ["sqlite3_wasm_vfs_create_file", "int", + wasm.bindingSignatures.wasmInternal = [ + ["sqlite3__wasm_db_reset", "int", "sqlite3*"], + ["sqlite3__wasm_db_vfs", "sqlite3_vfs*", "sqlite3*","string"], + ["sqlite3__wasm_vfs_create_file", "int", "sqlite3_vfs*","string","*", "int"], - ["sqlite3_wasm_posix_create_file", "int", "string","*", "int"], - ["sqlite3_wasm_vfs_unlink", "int", "sqlite3_vfs*","string"] + ["sqlite3__wasm_posix_create_file", "int", "string","*", "int"], + ["sqlite3__wasm_vfs_unlink", "int", "sqlite3_vfs*","string"] ]; /** @@ -742,8 +742,8 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ for(const e of wasm.bindingSignatures){ capi[e[0]] = wasm.xWrap.apply(null, e); } - for(const e of wasm.bindingSignatures.wasm){ - wasm[e[0]] = wasm.xWrap.apply(null, e); + for(const e of wasm.bindingSignatures.wasmInternal){ + util[e[0]] = wasm.xWrap.apply(null, e); } /* For C API functions which cannot work properly unless @@ -765,9 +765,9 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ implicitly making it part of the public interface. */ delete wasm.bindingSignatures; - if(wasm.exports.sqlite3_wasm_db_error){ + if(wasm.exports.sqlite3__wasm_db_error){ const __db_err = wasm.xWrap( - 'sqlite3_wasm_db_error', 'int', 'sqlite3*', 'int', 'string' + 'sqlite3__wasm_db_error', 'int', 'sqlite3*', 'int', 'string' ); /** Sets the given db's error state. Accepts: @@ -785,7 +785,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ Returns the resulting code. Pass (pDb,0,0) to clear the error state. */ - util.sqlite3_wasm_db_error = function(pDb, resultCode, message){ + util.sqlite3__wasm_db_error = function(pDb, resultCode, message){ if(resultCode instanceof sqlite3.WasmAllocError){ resultCode = capi.SQLITE_NOMEM; message = 0 /*avoid allocating message string*/; @@ -796,17 +796,17 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ return pDb ? __db_err(pDb, resultCode, message) : resultCode; }; }else{ - util.sqlite3_wasm_db_error = function(pDb,errCode,msg){ - console.warn("sqlite3_wasm_db_error() is not exported.",arguments); + util.sqlite3__wasm_db_error = function(pDb,errCode,msg){ + console.warn("sqlite3__wasm_db_error() is not exported.",arguments); return errCode; }; } }/*xWrap() bindings*/ {/* Import C-level constants and structs... */ - const cJson = wasm.xCall('sqlite3_wasm_enum_json'); + const cJson = wasm.xCall('sqlite3__wasm_enum_json'); if(!cJson){ - toss("Maintenance required: increase sqlite3_wasm_enum_json()'s", + toss("Maintenance required: increase sqlite3__wasm_enum_json()'s", "static buffer size!"); } //console.debug('wasm.ctype length =',wasm.cstrlen(cJson)); @@ -877,7 +877,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ delete capi[k]; } capi.sqlite3_vtab_config = wasm.xWrap( - 'sqlite3_wasm_vtab_config','int',[ + 'sqlite3__wasm_vtab_config','int',[ 'sqlite3*', 'int', 'int'] ); }/* end vtab-related setup */ @@ -889,7 +889,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ consistency with non-special-case wrappings. */ const __dbArgcMismatch = (pDb,f,n)=>{ - return util.sqlite3_wasm_db_error(pDb, capi.SQLITE_MISUSE, + return util.sqlite3__wasm_db_error(pDb, capi.SQLITE_MISUSE, f+"() requires "+n+" argument"+ (1===n?"":'s')+"."); }; @@ -898,7 +898,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ argument and require SQLITE_UTF8. Sets the db error code to SQLITE_FORMAT and returns that code. */ const __errEncoding = (pDb)=>{ - return util.sqlite3_wasm_db_error( + return util.sqlite3__wasm_db_error( pDb, capi.SQLITE_FORMAT, "SQLITE_UTF8 is the only supported encoding." ); }; @@ -1128,7 +1128,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ } return rc; }catch(e){ - return util.sqlite3_wasm_db_error(pDb, e); + return util.sqlite3__wasm_db_error(pDb, e); } }; @@ -1254,7 +1254,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ return rc; }catch(e){ console.error("sqlite3_create_function_v2() setup threw:",e); - return util.sqlite3_wasm_db_error(pDb, e, "Creation of UDF threw: "+e); + return util.sqlite3__wasm_db_error(pDb, e, "Creation of UDF threw: "+e); } }; @@ -1299,7 +1299,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ return rc; }catch(e){ console.error("sqlite3_create_window_function() setup threw:",e); - return util.sqlite3_wasm_db_error(pDb, e, "Creation of UDF threw: "+e); + return util.sqlite3__wasm_db_error(pDb, e, "Creation of UDF threw: "+e); } }; /** @@ -1394,7 +1394,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ case 'string': return __prepare.basic(pDb, xSql, xSqlLen, prepFlags, ppStmt, null); case 'number': return __prepare.full(pDb, xSql, xSqlLen, prepFlags, ppStmt, pzTail); default: - return util.sqlite3_wasm_db_error( + return util.sqlite3__wasm_db_error( pDb, capi.SQLITE_MISUSE, "Invalid SQL argument type for sqlite3_prepare_v2/v3()." ); @@ -1438,7 +1438,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ }else if('string'===typeof text){ [p, n] = wasm.allocCString(text); }else{ - return util.sqlite3_wasm_db_error( + return util.sqlite3__wasm_db_error( capi.sqlite3_db_handle(pStmt), capi.SQLITE_MISUSE, "Invalid 3rd argument type for sqlite3_bind_text()." ); @@ -1446,7 +1446,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ return __bindText(pStmt, iCol, p, n, capi.SQLITE_WASM_DEALLOC); }catch(e){ wasm.dealloc(p); - return util.sqlite3_wasm_db_error( + return util.sqlite3__wasm_db_error( capi.sqlite3_db_handle(pStmt), e ); } @@ -1472,7 +1472,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ }else if('string'===typeof pMem){ [p, n] = wasm.allocCString(pMem); }else{ - return util.sqlite3_wasm_db_error( + return util.sqlite3__wasm_db_error( capi.sqlite3_db_handle(pStmt), capi.SQLITE_MISUSE, "Invalid 3rd argument type for sqlite3_bind_blob()." ); @@ -1480,7 +1480,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ return __bindBlob(pStmt, iCol, p, n, capi.SQLITE_WASM_DEALLOC); }catch(e){ wasm.dealloc(p); - return util.sqlite3_wasm_db_error( + return util.sqlite3__wasm_db_error( capi.sqlite3_db_handle(pStmt), e ); } @@ -1504,11 +1504,11 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ case capi.SQLITE_CONFIG_SORTERREF_SIZE: // 28 /* int nByte */ case capi.SQLITE_CONFIG_STMTJRNL_SPILL: // 26 /* int nByte */ case capi.SQLITE_CONFIG_URI:// 17 /* int */ - return wasm.exports.sqlite3_wasm_config_i(op, args[0]); + return wasm.exports.sqlite3__wasm_config_i(op, args[0]); case capi.SQLITE_CONFIG_LOOKASIDE: // 13 /* int int */ - return wasm.exports.sqlite3_wasm_config_ii(op, args[0], args[1]); + return wasm.exports.sqlite3__wasm_config_ii(op, args[0], args[1]); case capi.SQLITE_CONFIG_MEMDB_MAXSIZE: // 29 /* sqlite3_int64 */ - return wasm.exports.sqlite3_wasm_config_j(op, args[0]); + return wasm.exports.sqlite3__wasm_config_j(op, args[0]); case capi.SQLITE_CONFIG_GETMALLOC: // 5 /* sqlite3_mem_methods* */ case capi.SQLITE_CONFIG_GETMUTEX: // 11 /* sqlite3_mutex_methods* */ case capi.SQLITE_CONFIG_GETPCACHE2: // 19 /* sqlite3_pcache_methods2* */ @@ -1574,11 +1574,11 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ if( pKvvfs ){/* kvvfs-specific glue */ if(util.isUIThread()){ const kvvfsMethods = new capi.sqlite3_kvvfs_methods( - wasm.exports.sqlite3_wasm_kvvfs_methods() + wasm.exports.sqlite3__wasm_kvvfs_methods() ); delete capi.sqlite3_kvvfs_methods; - const kvvfsMakeKey = wasm.exports.sqlite3_wasm_kvvfsMakeKeyOnPstack, + const kvvfsMakeKey = wasm.exports.sqlite3__wasm_kvvfsMakeKeyOnPstack, pstack = wasm.pstack; const kvvfsStorage = (zClass)=> @@ -1587,7 +1587,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ /** Implementations for members of the object referred to by - sqlite3_wasm_kvvfs_methods(). We swap out the native + sqlite3__wasm_kvvfs_methods(). We swap out the native implementations with these, which use localStorage or sessionStorage for their backing store. */ diff --git a/ext/wasm/api/sqlite3-api-prologue.js b/ext/wasm/api/sqlite3-api-prologue.js index ef1154f6b6..c784b69909 100644 --- a/ext/wasm/api/sqlite3-api-prologue.js +++ b/ext/wasm/api/sqlite3-api-prologue.js @@ -1061,7 +1061,7 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap( are undefined if the passed-in value did not come from this.pointer. */ - restore: wasm.exports.sqlite3_wasm_pstack_restore, + restore: wasm.exports.sqlite3__wasm_pstack_restore, /** Attempts to allocate the given number of bytes from the pstack. On success, it zeroes out a block of memory of the @@ -1083,7 +1083,7 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap( if('string'===typeof n && !(n = wasm.sizeofIR(n))){ WasmAllocError.toss("Invalid value for pstack.alloc(",arguments[0],")"); } - return wasm.exports.sqlite3_wasm_pstack_alloc(n) + return wasm.exports.sqlite3__wasm_pstack_alloc(n) || WasmAllocError.toss("Could not allocate",n, "bytes from the pstack."); }, @@ -1163,10 +1163,10 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap( */ pointer: { configurable: false, iterable: true, writeable: false, - get: wasm.exports.sqlite3_wasm_pstack_ptr + get: wasm.exports.sqlite3__wasm_pstack_ptr //Whether or not a setter as an alternative to restore() is //clearer or would just lead to confusion is unclear. - //set: wasm.exports.sqlite3_wasm_pstack_restore + //set: wasm.exports.sqlite3__wasm_pstack_restore }, /** sqlite3.wasm.pstack.quota to the total number of bytes @@ -1175,7 +1175,7 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap( */ quota: { configurable: false, iterable: true, writeable: false, - get: wasm.exports.sqlite3_wasm_pstack_quota + get: wasm.exports.sqlite3__wasm_pstack_quota }, /** sqlite3.wasm.pstack.remaining resolves to the amount of space @@ -1183,7 +1183,7 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap( */ remaining: { configurable: false, iterable: true, writeable: false, - get: wasm.exports.sqlite3_wasm_pstack_remaining + get: wasm.exports.sqlite3__wasm_pstack_remaining } })/*wasm.pstack properties*/; @@ -1256,14 +1256,14 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap( } try{ if(pdir && 0===wasm.xCallWrapped( - 'sqlite3_wasm_init_wasmfs', 'i32', ['string'], pdir + 'sqlite3__wasm_init_wasmfs', 'i32', ['string'], pdir )){ return __wasmfsOpfsDir = pdir; }else{ return __wasmfsOpfsDir = ""; } }catch(e){ - // sqlite3_wasm_init_wasmfs() is not available + // sqlite3__wasm_init_wasmfs() is not available return __wasmfsOpfsDir = ""; } }; @@ -1365,7 +1365,7 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap( const zSchema = schema ? (wasm.isPtr(schema) ? schema : wasm.scopedAllocCString(''+schema)) : 0; - let rc = wasm.exports.sqlite3_wasm_db_serialize( + let rc = wasm.exports.sqlite3__wasm_db_serialize( pDb, zSchema, ppOut, pSize, 0 ); if(rc){ @@ -1391,7 +1391,7 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap( or not provided, then "main" is assumed. */ capi.sqlite3_js_db_vfs = - (dbPointer, dbName=0)=>wasm.sqlite3_wasm_db_vfs(dbPointer, dbName); + (dbPointer, dbName=0)=>util.sqlite3__wasm_db_vfs(dbPointer, dbName); /** A thin wrapper around capi.sqlite3_aggregate_context() which @@ -1449,7 +1449,7 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap( if(!util.isInt32(dataLen) || dataLen<0){ SQLite3Error.toss("Invalid 3rd argument for sqlite3_js_posix_create_file()."); } - const rc = wasm.sqlite3_wasm_posix_create_file(filename, pData, dataLen); + const rc = util.sqlite3__wasm_posix_create_file(filename, pData, dataLen); if(rc) SQLite3Error.toss("Creation of file failed with sqlite3 result code", capi.sqlite3_js_rc_str(rc)); }finally{ @@ -1551,7 +1551,7 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap( SQLite3Error.toss("Invalid 4th argument for sqlite3_js_vfs_create_file()."); } try{ - const rc = wasm.sqlite3_wasm_vfs_create_file(vfs, filename, pData, dataLen); + const rc = util.sqlite3__wasm_vfs_create_file(vfs, filename, pData, dataLen); if(rc) SQLite3Error.toss("Creation of file failed with sqlite3 result code", capi.sqlite3_js_rc_str(rc)); }finally{ @@ -1672,12 +1672,12 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap( */ capi.sqlite3_db_config = function(pDb, op, ...args){ if(!this.s){ - this.s = wasm.xWrap('sqlite3_wasm_db_config_s','int', + this.s = wasm.xWrap('sqlite3__wasm_db_config_s','int', ['sqlite3*', 'int', 'string:static'] /* MAINDBNAME requires a static string */); - this.pii = wasm.xWrap('sqlite3_wasm_db_config_pii', 'int', + this.pii = wasm.xWrap('sqlite3__wasm_db_config_pii', 'int', ['sqlite3*', 'int', '*','int', 'int']); - this.ip = wasm.xWrap('sqlite3_wasm_db_config_ip','int', + this.ip = wasm.xWrap('sqlite3__wasm_db_config_ip','int', ['sqlite3*', 'int', 'int','*']); } switch(op){ diff --git a/ext/wasm/api/sqlite3-api-worker1.js b/ext/wasm/api/sqlite3-api-worker1.js index 3099c19ec4..bd99f3ec8e 100644 --- a/ext/wasm/api/sqlite3-api-worker1.js +++ b/ext/wasm/api/sqlite3-api-worker1.js @@ -359,6 +359,7 @@ */ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ +const util = sqlite3.util; sqlite3.initWorker1API = function(){ 'use strict'; const toss = (...args)=>{throw new Error(args.join(' '))}; @@ -409,12 +410,12 @@ sqlite3.initWorker1API = function(){ if(db){ delete this.dbs[getDbId(db)]; const filename = db.filename; - const pVfs = sqlite3.wasm.sqlite3_wasm_db_vfs(db.pointer, 0); + const pVfs = util.sqlite3__wasm_db_vfs(db.pointer, 0); db.close(); const ddNdx = this.dbList.indexOf(db); if(ddNdx>=0) this.dbList.splice(ddNdx, 1); if(alsoUnlink && filename && pVfs){ - sqlite3.wasm.sqlite3_wasm_vfs_unlink(pVfs, filename); + util.sqlite3__wasm_vfs_unlink(pVfs, filename); } } }, @@ -495,12 +496,12 @@ sqlite3.initWorker1API = function(){ } if(pVfs){ /* 2022-11-02: this feature is as-yet untested except that - sqlite3_wasm_vfs_create_file() has been tested from the + sqlite3__wasm_vfs_create_file() has been tested from the browser dev console. */ let pMem; try{ pMem = sqlite3.wasm.allocFromTypedArray(byteArray); - const rc = sqlite3.wasm.sqlite3_wasm_vfs_create_file( + const rc = util.sqlite3__wasm_vfs_create_file( pVfs, oargs.filename, pMem, byteArray.byteLength ); if(rc) sqlite3.SQLite3Error.toss(rc); diff --git a/ext/wasm/api/sqlite3-wasm.c b/ext/wasm/api/sqlite3-wasm.c index 618d0f085a..bd0eb884c9 100644 --- a/ext/wasm/api/sqlite3-wasm.c +++ b/ext/wasm/api/sqlite3-wasm.c @@ -238,28 +238,28 @@ ** Another option is to malloc() a chunk of our own and call that our ** "stack". */ -SQLITE_WASM_EXPORT void * sqlite3_wasm_stack_end(void){ +SQLITE_WASM_EXPORT void * sqlite3__wasm_stack_end(void){ extern void __heap_base /* see https://stackoverflow.com/questions/10038964 */; return &__heap_base; } -SQLITE_WASM_EXPORT void * sqlite3_wasm_stack_begin(void){ +SQLITE_WASM_EXPORT void * sqlite3__wasm_stack_begin(void){ extern void __data_end; return &__data_end; } static void * pWasmStackPtr = 0; -SQLITE_WASM_EXPORT void * sqlite3_wasm_stack_ptr(void){ - if(!pWasmStackPtr) pWasmStackPtr = sqlite3_wasm_stack_end(); +SQLITE_WASM_EXPORT void * sqlite3__wasm_stack_ptr(void){ + if(!pWasmStackPtr) pWasmStackPtr = sqlite3__wasm_stack_end(); return pWasmStackPtr; } -SQLITE_WASM_EXPORT void sqlite3_wasm_stack_restore(void * p){ +SQLITE_WASM_EXPORT void sqlite3__wasm_stack_restore(void * p){ pWasmStackPtr = p; } -SQLITE_WASM_EXPORT void * sqlite3_wasm_stack_alloc(int n){ +SQLITE_WASM_EXPORT void * sqlite3__wasm_stack_alloc(int n){ if(n<=0) return 0; n = (n + 7) & ~7 /* align to 8-byte boundary */; - unsigned char * const p = (unsigned char *)sqlite3_wasm_stack_ptr(); - unsigned const char * const b = (unsigned const char *)sqlite3_wasm_stack_begin(); + unsigned char * const p = (unsigned char *)sqlite3__wasm_stack_ptr(); + unsigned const char * const b = (unsigned const char *)sqlite3__wasm_stack_begin(); if(b + n >= p || b + n < b/*overflow*/) return 0; return pWasmStackPtr = p - n; } @@ -267,7 +267,7 @@ SQLITE_WASM_EXPORT void * sqlite3_wasm_stack_alloc(int n){ /* ** State for the "pseudo-stack" allocator implemented in -** sqlite3_wasm_pstack_xyz(). In order to avoid colliding with +** sqlite3__wasm_pstack_xyz(). In order to avoid colliding with ** Emscripten-controled stack space, it carves out a bit of stack ** memory to use for that purpose. This memory ends up in the ** WASM-managed memory, such that routines which manipulate the wasm @@ -291,14 +291,14 @@ static struct { /* ** Returns the current pstack position. */ -SQLITE_WASM_EXPORT void * sqlite3_wasm_pstack_ptr(void){ +SQLITE_WASM_EXPORT void * sqlite3__wasm_pstack_ptr(void){ return PStack.pPos; } /* ** Sets the pstack position poitner to p. Results are undefined if the -** given value did not come from sqlite3_wasm_pstack_ptr(). +** given value did not come from sqlite3__wasm_pstack_ptr(). */ -SQLITE_WASM_EXPORT void sqlite3_wasm_pstack_restore(unsigned char * p){ +SQLITE_WASM_EXPORT void sqlite3__wasm_pstack_restore(unsigned char * p){ assert(p>=PStack.pBegin && p<=PStack.pEnd && p>=PStack.pPos); assert(0==((unsigned long long)p & 0x7)); if(p>=PStack.pBegin && p<=PStack.pEnd /*&& p>=PStack.pPos*/){ @@ -313,7 +313,7 @@ SQLITE_WASM_EXPORT void sqlite3_wasm_pstack_restore(unsigned char * p){ ** JS code from having to do so, and most uses of the pstack will ** call for doing so). */ -SQLITE_WASM_EXPORT void * sqlite3_wasm_pstack_alloc(int n){ +SQLITE_WASM_EXPORT void * sqlite3__wasm_pstack_alloc(int n){ if( n<=0 ) return 0; //if( n & 0x7 ) n += 8 - (n & 0x7) /* align to 8-byte boundary */; n = (n + 7) & ~7 /* align to 8-byte boundary */; @@ -324,9 +324,9 @@ SQLITE_WASM_EXPORT void * sqlite3_wasm_pstack_alloc(int n){ } /* ** Return the number of bytes left which can be -** sqlite3_wasm_pstack_alloc()'d. +** sqlite3__wasm_pstack_alloc()'d. */ -SQLITE_WASM_EXPORT int sqlite3_wasm_pstack_remaining(void){ +SQLITE_WASM_EXPORT int sqlite3__wasm_pstack_remaining(void){ assert(PStack.pPos >= PStack.pBegin); assert(PStack.pPos <= PStack.pEnd); return (int)(PStack.pPos - PStack.pBegin); @@ -337,7 +337,7 @@ SQLITE_WASM_EXPORT int sqlite3_wasm_pstack_remaining(void){ ** any space which is currently allocated. This value is a ** compile-time constant. */ -SQLITE_WASM_EXPORT int sqlite3_wasm_pstack_quota(void){ +SQLITE_WASM_EXPORT int sqlite3__wasm_pstack_quota(void){ return (int)(PStack.pEnd - PStack.pBegin); } @@ -356,7 +356,7 @@ SQLITE_WASM_EXPORT int sqlite3_wasm_pstack_quota(void){ ** Returns err_code. */ SQLITE_WASM_EXPORT -int sqlite3_wasm_db_error(sqlite3*db, int err_code, const char *zMsg){ +int sqlite3__wasm_db_error(sqlite3*db, int err_code, const char *zMsg){ if( db!=0 ){ if( 0!=zMsg ){ const int nMsg = sqlite3Strlen30(zMsg); @@ -380,7 +380,7 @@ struct WasmTestStruct { }; typedef struct WasmTestStruct WasmTestStruct; SQLITE_WASM_EXPORT -void sqlite3_wasm_test_struct(WasmTestStruct * s){ +void sqlite3__wasm_test_struct(WasmTestStruct * s){ if(s){ s->v4 *= 2; s->v8 = s->v4 * 2; @@ -408,7 +408,7 @@ void sqlite3_wasm_test_struct(WasmTestStruct * s){ ** increased. In debug builds that will trigger an assert(). */ SQLITE_WASM_EXPORT -const char * sqlite3_wasm_enum_json(void){ +const char * sqlite3__wasm_enum_json(void){ static char aBuffer[1024 * 20] = {0} /* where the JSON goes */; int n = 0, nChildren = 0, nStruct = 0 /* output counters for figuring out where commas go */; @@ -425,7 +425,7 @@ const char * sqlite3_wasm_enum_json(void){ /* Core output macros... */ #define lenCheck assert(zPos < zEnd - 128 \ - && "sqlite3_wasm_enum_json() buffer is too small."); \ + && "sqlite3__wasm_enum_json() buffer is too small."); \ if( zPos >= zEnd - 128 ) return 0 #define outf(format,...) \ zPos += snprintf(zPos, ((size_t)(zEnd - zPos)), format, __VA_ARGS__); \ @@ -1220,7 +1220,7 @@ const char * sqlite3_wasm_enum_json(void){ ** call is returned. */ SQLITE_WASM_EXPORT -int sqlite3_wasm_vfs_unlink(sqlite3_vfs *pVfs, const char *zName){ +int sqlite3__wasm_vfs_unlink(sqlite3_vfs *pVfs, const char *zName){ int rc = SQLITE_MISUSE /* ??? */; if( 0==pVfs && 0!=zName ) pVfs = sqlite3_vfs_find(0); if( zName && pVfs && pVfs->xDelete ){ @@ -1238,7 +1238,7 @@ int sqlite3_wasm_vfs_unlink(sqlite3_vfs *pVfs, const char *zName){ ** given name is open. */ SQLITE_WASM_EXPORT -sqlite3_vfs * sqlite3_wasm_db_vfs(sqlite3 *pDb, const char *zDbName){ +sqlite3_vfs * sqlite3__wasm_db_vfs(sqlite3 *pDb, const char *zDbName){ sqlite3_vfs * pVfs = 0; sqlite3_file_control(pDb, zDbName ? zDbName : "main", SQLITE_FCNTL_VFS_POINTER, &pVfs); @@ -1261,7 +1261,7 @@ sqlite3_vfs * sqlite3_wasm_db_vfs(sqlite3 *pDb, const char *zDbName){ ** SQLITE_MISUSE if pDb is NULL. */ SQLITE_WASM_EXPORT -int sqlite3_wasm_db_reset(sqlite3 *pDb){ +int sqlite3__wasm_db_reset(sqlite3 *pDb){ int rc = SQLITE_MISUSE; if( pDb ){ sqlite3_table_column_metadata(pDb, "main", 0, 0, 0, 0, 0, 0, 0); @@ -1288,11 +1288,11 @@ int sqlite3_wasm_db_reset(sqlite3 *pDb){ ** takes no measures to ensure that is the case. ** ** This implementation appears to work fine, but -** sqlite3_wasm_db_serialize() is arguably the better way to achieve +** sqlite3__wasm_db_serialize() is arguably the better way to achieve ** this. */ SQLITE_WASM_EXPORT -int sqlite3_wasm_db_export_chunked( sqlite3* pDb, +int sqlite3__wasm_db_export_chunked( sqlite3* pDb, int (*xCallback)(unsigned const char *zOut, int n) ){ sqlite3_int64 nSize = 0; sqlite3_int64 nPos = 0; @@ -1343,7 +1343,7 @@ int sqlite3_wasm_db_export_chunked( sqlite3* pDb, ** sqlite3_free() to free it. */ SQLITE_WASM_EXPORT -int sqlite3_wasm_db_serialize( sqlite3 *pDb, const char *zSchema, +int sqlite3__wasm_db_serialize( sqlite3 *pDb, const char *zSchema, unsigned char **pOut, sqlite3_int64 *nOut, unsigned int mFlags ){ unsigned char * z; @@ -1366,7 +1366,7 @@ int sqlite3_wasm_db_serialize( sqlite3 *pDb, const char *zSchema, ** this function's out-of-scope use of the sqlite3_vfs/file/io_methods ** APIs leads to triggering of assertions in the core library. Its use ** is now deprecated and VFS-specific APIs for importing files need to -** be found to replace it. sqlite3_wasm_posix_create_file() is +** be found to replace it. sqlite3__wasm_posix_create_file() is ** suitable for the "unix" family of VFSes. ** ** Creates a new file using the I/O API of the given VFS, containing @@ -1407,7 +1407,7 @@ int sqlite3_wasm_db_serialize( sqlite3 *pDb, const char *zSchema, ** support is disabled or unavailable. */ SQLITE_WASM_EXPORT -int sqlite3_wasm_vfs_create_file( sqlite3_vfs *pVfs, +int sqlite3__wasm_vfs_create_file( sqlite3_vfs *pVfs, const char *zFilename, const unsigned char * pData, int nData ){ @@ -1497,7 +1497,7 @@ int sqlite3_wasm_vfs_create_file( sqlite3_vfs *pVfs, ** SQLITE_IOERR on error. */ SQLITE_WASM_EXPORT -int sqlite3_wasm_posix_create_file( const char *zFilename, +int sqlite3__wasm_posix_create_file( const char *zFilename, const unsigned char * pData, int nData ){ int rc; @@ -1520,17 +1520,17 @@ int sqlite3_wasm_posix_create_file( const char *zFilename, ** for use by the sqlite project's own JS/WASM bindings. ** ** Allocates sqlite3KvvfsMethods.nKeySize bytes from -** sqlite3_wasm_pstack_alloc() and returns 0 if that allocation fails, +** sqlite3__wasm_pstack_alloc() and returns 0 if that allocation fails, ** else it passes that string to kvstorageMakeKey() and returns a ** NUL-terminated pointer to that string. It is up to the caller to -** use sqlite3_wasm_pstack_restore() to free the returned pointer. +** use sqlite3__wasm_pstack_restore() to free the returned pointer. */ SQLITE_WASM_EXPORT -char * sqlite3_wasm_kvvfsMakeKeyOnPstack(const char *zClass, +char * sqlite3__wasm_kvvfsMakeKeyOnPstack(const char *zClass, const char *zKeyIn){ assert(sqlite3KvvfsMethods.nKeySize>24); char *zKeyOut = - (char *)sqlite3_wasm_pstack_alloc(sqlite3KvvfsMethods.nKeySize); + (char *)sqlite3__wasm_pstack_alloc(sqlite3KvvfsMethods.nKeySize); if(zKeyOut){ kvstorageMakeKey(zClass, zKeyIn, zKeyOut); } @@ -1545,7 +1545,7 @@ char * sqlite3_wasm_kvvfsMakeKeyOnPstack(const char *zClass, ** I/O methods and associated state. */ SQLITE_WASM_EXPORT -sqlite3_kvvfs_methods * sqlite3_wasm_kvvfs_methods(void){ +sqlite3_kvvfs_methods * sqlite3__wasm_kvvfs_methods(void){ return &sqlite3KvvfsMethods; } @@ -1560,7 +1560,7 @@ sqlite3_kvvfs_methods * sqlite3_wasm_kvvfs_methods(void){ ** valid value. */ SQLITE_WASM_EXPORT -int sqlite3_wasm_vtab_config(sqlite3 *pDb, int op, int arg){ +int sqlite3__wasm_vtab_config(sqlite3 *pDb, int op, int arg){ switch(op){ case SQLITE_VTAB_DIRECTONLY: case SQLITE_VTAB_INNOCUOUS: @@ -1580,7 +1580,7 @@ int sqlite3_wasm_vtab_config(sqlite3 *pDb, int op, int arg){ ** (int,int*) variadic args. */ SQLITE_WASM_EXPORT -int sqlite3_wasm_db_config_ip(sqlite3 *pDb, int op, int arg1, int* pArg2){ +int sqlite3__wasm_db_config_ip(sqlite3 *pDb, int op, int arg1, int* pArg2){ switch(op){ case SQLITE_DBCONFIG_ENABLE_FKEY: case SQLITE_DBCONFIG_ENABLE_TRIGGER: @@ -1613,7 +1613,7 @@ int sqlite3_wasm_db_config_ip(sqlite3 *pDb, int op, int arg1, int* pArg2){ ** (void*,int,int) variadic args. */ SQLITE_WASM_EXPORT -int sqlite3_wasm_db_config_pii(sqlite3 *pDb, int op, void * pArg1, int arg2, int arg3){ +int sqlite3__wasm_db_config_pii(sqlite3 *pDb, int op, void * pArg1, int arg2, int arg3){ switch(op){ case SQLITE_DBCONFIG_LOOKASIDE: return sqlite3_db_config(pDb, op, pArg1, arg2, arg3); @@ -1629,7 +1629,7 @@ int sqlite3_wasm_db_config_pii(sqlite3 *pDb, int op, void * pArg1, int arg2, int ** (const char *) variadic args. */ SQLITE_WASM_EXPORT -int sqlite3_wasm_db_config_s(sqlite3 *pDb, int op, const char *zArg){ +int sqlite3__wasm_db_config_s(sqlite3 *pDb, int op, const char *zArg){ switch(op){ case SQLITE_DBCONFIG_MAINDBNAME: return sqlite3_db_config(pDb, op, zArg); @@ -1646,7 +1646,7 @@ int sqlite3_wasm_db_config_s(sqlite3 *pDb, int op, const char *zArg){ ** a single integer argument. */ SQLITE_WASM_EXPORT -int sqlite3_wasm_config_i(int op, int arg){ +int sqlite3__wasm_config_i(int op, int arg){ return sqlite3_config(op, arg); } @@ -1658,7 +1658,7 @@ int sqlite3_wasm_config_i(int op, int arg){ ** two int arguments. */ SQLITE_WASM_EXPORT -int sqlite3_wasm_config_ii(int op, int arg1, int arg2){ +int sqlite3__wasm_config_ii(int op, int arg1, int arg2){ return sqlite3_config(op, arg1, arg2); } @@ -1670,7 +1670,7 @@ int sqlite3_wasm_config_ii(int op, int arg1, int arg2){ ** a single i64 argument. */ SQLITE_WASM_EXPORT -int sqlite3_wasm_config_j(int op, sqlite3_int64 arg){ +int sqlite3__wasm_config_j(int op, sqlite3_int64 arg){ return sqlite3_config(op, arg); } @@ -1689,17 +1689,17 @@ int sqlite3_wasm_config_j(int op, sqlite3_int64 arg){ ** ** ``` ** sqlite3.wasm.functionEntry( -** sqlite3.wasm.exports.sqlite3_wasm_ptr_to_sqlite3_free() +** sqlite3.wasm.exports.sqlite3__wasm_ptr_to_sqlite3_free() ** ) === sqlite3.wasm.exports.sqlite3_free ** ``` ** ** Using a function to return this pointer, as opposed to exporting it -** via sqlite3_wasm_enum_json(), is an attempt to work around a +** via sqlite3__wasm_enum_json(), is an attempt to work around a ** Safari-specific quirk covered at ** https://sqlite.org/forum/info/e5b20e1feb37a19a. **/ SQLITE_WASM_EXPORT -void * sqlite3_wasm_ptr_to_sqlite3_free(void){ +void * sqlite3__wasm_ptr_to_sqlite3_free(void){ return (void*)sqlite3_free; } #endif @@ -1729,7 +1729,7 @@ void * sqlite3_wasm_ptr_to_sqlite3_free(void){ ** defined, SQLITE_NOTFOUND is returned without side effects. */ SQLITE_WASM_EXPORT -int sqlite3_wasm_init_wasmfs(const char *zMountPoint){ +int sqlite3__wasm_init_wasmfs(const char *zMountPoint){ static backend_t pOpfs = 0; if( !zMountPoint || !*zMountPoint ) zMountPoint = "/opfs"; if( !pOpfs ){ @@ -1749,7 +1749,7 @@ int sqlite3_wasm_init_wasmfs(const char *zMountPoint){ } #else SQLITE_WASM_EXPORT -int sqlite3_wasm_init_wasmfs(const char *zUnused){ +int sqlite3__wasm_init_wasmfs(const char *zUnused){ //emscripten_console_warn("WASMFS OPFS is not compiled in."); if(zUnused){/*unused*/} return SQLITE_NOTFOUND; @@ -1759,51 +1759,51 @@ int sqlite3_wasm_init_wasmfs(const char *zUnused){ #if SQLITE_WASM_TESTS SQLITE_WASM_EXPORT -int sqlite3_wasm_test_intptr(int * p){ +int sqlite3__wasm_test_intptr(int * p){ return *p = *p * 2; } SQLITE_WASM_EXPORT -void * sqlite3_wasm_test_voidptr(void * p){ +void * sqlite3__wasm_test_voidptr(void * p){ return p; } SQLITE_WASM_EXPORT -int64_t sqlite3_wasm_test_int64_max(void){ +int64_t sqlite3__wasm_test_int64_max(void){ return (int64_t)0x7fffffffffffffff; } SQLITE_WASM_EXPORT -int64_t sqlite3_wasm_test_int64_min(void){ - return ~sqlite3_wasm_test_int64_max(); +int64_t sqlite3__wasm_test_int64_min(void){ + return ~sqlite3__wasm_test_int64_max(); } SQLITE_WASM_EXPORT -int64_t sqlite3_wasm_test_int64_times2(int64_t x){ +int64_t sqlite3__wasm_test_int64_times2(int64_t x){ return x * 2; } SQLITE_WASM_EXPORT -void sqlite3_wasm_test_int64_minmax(int64_t * min, int64_t *max){ - *max = sqlite3_wasm_test_int64_max(); - *min = sqlite3_wasm_test_int64_min(); +void sqlite3__wasm_test_int64_minmax(int64_t * min, int64_t *max){ + *max = sqlite3__wasm_test_int64_max(); + *min = sqlite3__wasm_test_int64_min(); /*printf("minmax: min=%lld, max=%lld\n", *min, *max);*/ } SQLITE_WASM_EXPORT -int64_t sqlite3_wasm_test_int64ptr(int64_t * p){ - /*printf("sqlite3_wasm_test_int64ptr( @%lld = 0x%llx )\n", (int64_t)p, *p);*/ +int64_t sqlite3__wasm_test_int64ptr(int64_t * p){ + /*printf("sqlite3__wasm_test_int64ptr( @%lld = 0x%llx )\n", (int64_t)p, *p);*/ return *p = *p * 2; } SQLITE_WASM_EXPORT -void sqlite3_wasm_test_stack_overflow(int recurse){ - if(recurse) sqlite3_wasm_test_stack_overflow(recurse); +void sqlite3__wasm_test_stack_overflow(int recurse){ + if(recurse) sqlite3__wasm_test_stack_overflow(recurse); } /* For testing the 'string:dealloc' whwasmutil.xWrap() conversion. */ SQLITE_WASM_EXPORT -char * sqlite3_wasm_test_str_hello(int fail){ +char * sqlite3__wasm_test_str_hello(int fail){ char * s = fail ? 0 : (char *)sqlite3_malloc(6); if(s){ memcpy(s, "hello", 5); @@ -1838,12 +1838,12 @@ char * sqlite3_wasm_test_str_hello(int fail){ ** optional + or - sign in front, or a hexadecimal ** literal of the form 0x... */ -static int sqlite3_wasm_SQLTester_strnotglob(const char *zGlob, const char *z){ +static int sqlite3__wasm_SQLTester_strnotglob(const char *zGlob, const char *z){ int c, c2; int invert; int seen; typedef int (*recurse_f)(const char *,const char *); - static const recurse_f recurse = sqlite3_wasm_SQLTester_strnotglob; + static const recurse_f recurse = sqlite3__wasm_SQLTester_strnotglob; while( (c = (*(zGlob++)))!=0 ){ if( c=='*' ){ @@ -1918,11 +1918,10 @@ static int sqlite3_wasm_SQLTester_strnotglob(const char *zGlob, const char *z){ } SQLITE_WASM_EXPORT -int sqlite3_wasm_SQLTester_strglob(const char *zGlob, const char *z){ - return !sqlite3_wasm_SQLTester_strnotglob(zGlob, z); +int sqlite3__wasm_SQLTester_strglob(const char *zGlob, const char *z){ + return !sqlite3__wasm_SQLTester_strnotglob(zGlob, z); } - #endif /* SQLITE_WASM_TESTS */ #undef SQLITE_WASM_EXPORT diff --git a/ext/wasm/fiddle/fiddle-worker.js b/ext/wasm/fiddle/fiddle-worker.js index 67f61008fb..cf0aa1ca2c 100644 --- a/ext/wasm/fiddle/fiddle-worker.js +++ b/ext/wasm/fiddle/fiddle-worker.js @@ -374,9 +374,7 @@ "for use in the dev console.", sqlite3); globalThis.sqlite3 = sqlite3; const dbVfs = sqlite3.wasm.xWrap('fiddle_db_vfs', "*", ['string']); - fiddleModule.fsUnlink = (fn)=>{ - return sqlite3.wasm.sqlite3_wasm_vfs_unlink(dbVfs(0), fn); - }; + fiddleModule.fsUnlink = (fn)=>fiddleModule.FS.unlink(fn); wMsg('fiddle-ready'); }).catch(e=>{ console.error("Fiddle worker init failed:",e); diff --git a/ext/wasm/speedtest1-worker.js b/ext/wasm/speedtest1-worker.js index 3abc589b59..5261c83932 100644 --- a/ext/wasm/speedtest1-worker.js +++ b/ext/wasm/speedtest1-worker.js @@ -111,10 +111,6 @@ self.sqlite3InitModule(EmscriptenModule).then(async (sqlite3)=>{ const S = globalThis.S = App.sqlite3 = sqlite3; log("Loaded speedtest1 module. Setting up..."); - App.vfsUnlink = function(pDb, fname){ - const pVfs = S.wasm.sqlite3_wasm_db_vfs(pDb, 0); - if(pVfs) S.wasm.sqlite3_wasm_vfs_unlink(pVfs, fname||0); - }; App.pDir = wasmfsDir(S.wasm); App.wasm = S.wasm; //if(App.pDir) log("Persistent storage:",pDir); diff --git a/ext/wasm/tester1.c-pp.js b/ext/wasm/tester1.c-pp.js index 36ca4c976f..f8a0225234 100644 --- a/ext/wasm/tester1.c-pp.js +++ b/ext/wasm/tester1.c-pp.js @@ -63,7 +63,7 @@ globalThis.sqlite3InitModule = sqlite3InitModule; /* Predicate for tests/groups. */ const testIsTodo = ()=>false; const haveWasmCTests = ()=>{ - return !!wasm.exports.sqlite3_wasm_test_intptr; + return !!wasm.exports.sqlite3__wasm_test_intptr; }; const hasOpfs = ()=>{ return globalThis.FileSystemHandle @@ -722,7 +722,7 @@ globalThis.sqlite3InitModule = sqlite3InitModule; //log("xCall()..."); { - const pJson = w.xCall('sqlite3_wasm_enum_json'); + const pJson = w.xCall('sqlite3__wasm_enum_json'); T.assert(Number.isFinite(pJson)).assert(w.cstrlen(pJson)>300); } @@ -736,9 +736,9 @@ globalThis.sqlite3InitModule = sqlite3InitModule; T.mustThrowMatching(()=>fw(1), /requires 0 arg/); let rc = fw(); T.assert('string'===typeof rc).assert(rc.length>5); - rc = w.xCallWrapped('sqlite3_wasm_enum_json','*'); + rc = w.xCallWrapped('sqlite3__wasm_enum_json','*'); T.assert(rc>0 && Number.isFinite(rc)); - rc = w.xCallWrapped('sqlite3_wasm_enum_json','utf8'); + rc = w.xCallWrapped('sqlite3__wasm_enum_json','utf8'); T.assert('string'===typeof rc).assert(rc.length>300); @@ -821,7 +821,7 @@ globalThis.sqlite3InitModule = sqlite3InitModule; if(haveWasmCTests()){ if(!sqlite3.config.useStdAlloc){ - fw = w.xWrap('sqlite3_wasm_test_str_hello', 'utf8:dealloc',['i32']); + fw = w.xWrap('sqlite3__wasm_test_str_hello', 'utf8:dealloc',['i32']); rc = fw(0); T.assert('hello'===rc); rc = fw(1); @@ -831,14 +831,14 @@ globalThis.sqlite3InitModule = sqlite3InitModule; if(w.bigIntEnabled){ w.xWrap.resultAdapter('thrice', (v)=>3n*BigInt(v)); w.xWrap.argAdapter('twice', (v)=>2n*BigInt(v)); - fw = w.xWrap('sqlite3_wasm_test_int64_times2','thrice','twice'); + fw = w.xWrap('sqlite3__wasm_test_int64_times2','thrice','twice'); rc = fw(1); T.assert(12n===rc); w.scopedAllocCall(function(){ const pI1 = w.scopedAlloc(8), pI2 = pI1+4; w.pokePtr([pI1, pI2], 0); - const f = w.xWrap('sqlite3_wasm_test_int64_minmax',undefined,['i64*','i64*']); + const f = w.xWrap('sqlite3__wasm_test_int64_minmax',undefined,['i64*','i64*']); const [r1, r2] = w.peek64([pI1, pI2]); T.assert(!Number.isSafeInteger(r1)).assert(!Number.isSafeInteger(r2)); }); @@ -942,7 +942,7 @@ globalThis.sqlite3InitModule = sqlite3InitModule; assert(wts.pointer>0).assert(0===wts.$v4).assert(0n===wts.$v8). assert(0===wts.$ppV).assert(0===wts.$xFunc); const testFunc = - W.xGet('sqlite3_wasm_test_struct'/*name gets mangled in -O3 builds!*/); + W.xGet('sqlite3__wasm_test_struct'/*name gets mangled in -O3 builds!*/); let counter = 0; //log("wts.pointer =",wts.pointer); const wtsFunc = function(arg){ @@ -1128,7 +1128,7 @@ globalThis.sqlite3InitModule = sqlite3InitModule; T.g('sqlite3.oo1') .t('Create db', function(sqlite3){ const dbFile = '/tester1.db'; - wasm.sqlite3_wasm_vfs_unlink(0, dbFile); + sqlite3.util.sqlite3__wasm_vfs_unlink(0, dbFile); const db = this.db = new sqlite3.oo1.DB(dbFile, 0 ? 'ct' : 'c'); db.onclose = { disposeAfter: [], @@ -1459,7 +1459,7 @@ globalThis.sqlite3InitModule = sqlite3InitModule; rv = db.exec("SELECT 1 WHERE 0",{rowMode: 0}); T.assert(Array.isArray(rv)).assert(0===rv.length); if(wasm.bigIntEnabled && haveWasmCTests()){ - const mI = wasm.xCall('sqlite3_wasm_test_int64_max'); + const mI = wasm.xCall('sqlite3__wasm_test_int64_max'); const b = BigInt(Number.MAX_SAFE_INTEGER * 2); T.assert(b === db.selectValue("SELECT "+b)). assert(b === db.selectValue("SELECT ?", b)). @@ -1685,7 +1685,7 @@ globalThis.sqlite3InitModule = sqlite3InitModule; T.assert(n>0 && db2.selectValue(sql) === n); }finally{ db2.close(); - wasm.sqlite3_wasm_vfs_unlink(0, filename); + sqlite3.util.sqlite3__wasm_vfs_unlink(0, filename); } } }/*sqlite3_js_posix_create_file()*/) @@ -2075,7 +2075,7 @@ globalThis.sqlite3InitModule = sqlite3InitModule; try{ ptrInt = w.scopedAlloc(4); w.poke32(ptrInt,origValue); - const cf = w.xGet('sqlite3_wasm_test_intptr'); + const cf = w.xGet('sqlite3__wasm_test_intptr'); const oldPtrInt = ptrInt; T.assert(origValue === w.peek32(ptrInt)); const rc = cf(ptrInt); @@ -2090,13 +2090,13 @@ globalThis.sqlite3InitModule = sqlite3InitModule; const v64 = ()=>w.peek64(pi64) T.assert(v64() == o64); //T.assert(o64 === w.peek64(pi64)); - const cf64w = w.xGet('sqlite3_wasm_test_int64ptr'); + const cf64w = w.xGet('sqlite3__wasm_test_int64ptr'); cf64w(pi64); T.assert(v64() == BigInt(2 * o64)); cf64w(pi64); T.assert(v64() == BigInt(4 * o64)); - const biTimes2 = w.xGet('sqlite3_wasm_test_int64_times2'); + const biTimes2 = w.xGet('sqlite3__wasm_test_int64_times2'); T.assert(BigInt(2 * o64) === biTimes2(BigInt(o64)/*explicit conv. required to avoid TypeError in the call :/ */)); @@ -2106,13 +2106,13 @@ globalThis.sqlite3InitModule = sqlite3InitModule; const g64 = (p)=>w.peek64(p); w.poke64([pMin, pMax], 0); const minMaxI64 = [ - w.xCall('sqlite3_wasm_test_int64_min'), - w.xCall('sqlite3_wasm_test_int64_max') + w.xCall('sqlite3__wasm_test_int64_min'), + w.xCall('sqlite3__wasm_test_int64_max') ]; T.assert(minMaxI64[0] < BigInt(Number.MIN_SAFE_INTEGER)). assert(minMaxI64[1] > BigInt(Number.MAX_SAFE_INTEGER)); //log("int64_min/max() =",minMaxI64, typeof minMaxI64[0]); - w.xCall('sqlite3_wasm_test_int64_minmax', pMin, pMax); + w.xCall('sqlite3__wasm_test_int64_minmax', pMin, pMax); T.assert(g64(pMin) === minMaxI64[0], "int64 mismatch"). assert(g64(pMax) === minMaxI64[1], "int64 mismatch"); //log("pMin",g64(pMin), "pMax",g64(pMax)); @@ -2560,7 +2560,7 @@ globalThis.sqlite3InitModule = sqlite3InitModule; //////////////////////////////////////////////////////////////////////// .t('Close db', function(){ T.assert(this.db).assert(wasm.isPtr(this.db.pointer)); - //wasm.sqlite3_wasm_db_reset(this.db); // will leak virtual tables! + //wasm.sqlite3__wasm_db_reset(this.db); // will leak virtual tables! this.db.close(); T.assert(!this.db.pointer); }) @@ -2892,7 +2892,7 @@ globalThis.sqlite3InitModule = sqlite3InitModule; const pVfs = this.opfsVfs = capi.sqlite3_vfs_find('opfs'); T.assert(pVfs); const unlink = this.opfsUnlink = - (fn=filename)=>{wasm.sqlite3_wasm_vfs_unlink(pVfs,fn)}; + (fn=filename)=>{sqlite3.util.sqlite3__wasm_vfs_unlink(pVfs,fn)}; unlink(); let db = new sqlite3.oo1.OpfsDb(filename); try { @@ -3209,6 +3209,7 @@ globalThis.sqlite3InitModule = sqlite3InitModule; print: log, printErr: error }).then(async function(sqlite3){ + TestUtil.assert(!!sqlite3.util); log("Done initializing WASM/JS bits. Running tests..."); sqlite3.config.warn("Installing sqlite3 bits as global S for local dev/test purposes."); globalThis.S = sqlite3; @@ -3227,9 +3228,9 @@ globalThis.sqlite3InitModule = sqlite3InitModule; logClass('warning',"BigInt/int64 support is disabled."); } if(haveWasmCTests()){ - log("sqlite3_wasm_test_...() APIs are available."); + log("sqlite3__wasm_test_...() APIs are available."); }else{ - logClass('warning',"sqlite3_wasm_test_...() APIs unavailable."); + logClass('warning',"sqlite3__wasm_test_...() APIs unavailable."); } log("registered vfs list =",capi.sqlite3_js_vfs_list().join(', ')); TestUtil.runTests(sqlite3); diff --git a/manifest b/manifest index 30972b2b7b..3ae52dc786 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\san\sALWAYS()\sfrom\sRTREE.\s\sDbsqlfuzz\sfound\sa\sway\sto\smake\sit\sfalse. -D 2024-01-07T20:27:54.639 +C Make\sexplicit\swhich\sJS\sAPIs\sare\sfor\sinternal\suse\sonly\sby\smoving\sthe\sJS-bound\sinternal-use-only\sfunctions\sout\sof\sclient-visible\sreach\sand\srenaming\sthe\sWASM-exported\sones\sfrom\ssqlite3_wasm...\sto\ssqlite3__wasm...\s(with\stwo\sunderscores).\sThese\shave\salways\sbeen\sdocumented\sas\sinternal-use-only,\sso\sthis\sis\snot\sa\sbreaking\schange\sexcept\sfor\sclients\swhich\shave\signored\sthe\sdocs. +D 2024-01-08T07:52:47.965 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -575,7 +575,7 @@ F ext/userauth/sqlite3userauth.h 7f3ea8c4686db8e40b0a0e7a8e0b00fac13aa7a3 F ext/userauth/user-auth.txt e6641021a9210364665fe625d067617d03f27b04 F ext/userauth/userauth.c 7f00cded7dcaa5d47f54539b290a43d2e59f4b1eb5f447545fa865f002fc80cb F ext/wasm/EXPORTED_FUNCTIONS.fiddle.in 27450c8b8c70875a260aca55435ec927068b34cef801a96205adb81bdcefc65c -F ext/wasm/GNUmakefile 99aad6d6a28c43573f80825e986427c1a024a3298aaf0c69c56a0c6b336f12c8 +F ext/wasm/GNUmakefile 0f4ccfd350a9b0ebe60183fb4ad3b41c670eec62c88279f22e2627887b524b3c F ext/wasm/README-dist.txt 6382cb9548076fca472fb3330bbdba3a55c1ea0b180ff9253f084f07ff383576 F ext/wasm/README.md a8a2962c3aebdf8d2104a9102e336c5554e78fc6072746e5daf9c61514e7d193 F ext/wasm/SQLTester/GNUmakefile e0794f676d55819951bbfae45cc5e8d7818dc460492dc317ce7f0d2eca15caff @@ -593,16 +593,16 @@ F ext/wasm/api/post-js-footer.js cd0a8ec768501d9bd45d325ab0442037fb0e33d1f3b4f08 F ext/wasm/api/post-js-header.js 47b6b281f39ad59fa6e8b658308cd98ea292c286a68407b35ff3ed9cfd281a62 F ext/wasm/api/pre-js.c-pp.js ad906703f7429590f2fbf5e6498513bf727a1a4f0ebfa057afb08161d7511219 F ext/wasm/api/sqlite3-api-cleanup.js d235ad237df6954145404305040991c72ef8b1881715d2a650dda7b3c2576d0e -F ext/wasm/api/sqlite3-api-glue.js 119b91c8a7ce6648679eb66fcdd1ed07ef7fd892eb501d658fbfefcc962012d9 +F ext/wasm/api/sqlite3-api-glue.js 8f4478c927466245259478788c293810bc812ac8c49df38c62574966d836131a F ext/wasm/api/sqlite3-api-oo1.js 7f3bcf0549ac44cde4b9da0b642d771916738d3f6781fb8a1757c50a91e506c0 -F ext/wasm/api/sqlite3-api-prologue.js 9aeba7b45cf41b3a26d34d7fb2525633cd1adfc544888c1ea8dbb077496f4ce9 -F ext/wasm/api/sqlite3-api-worker1.js fd46628ef147dd5856c88f63a9a279a40f744f1fdfddd55251ad8fbc3d8200ae +F ext/wasm/api/sqlite3-api-prologue.js fffcee629bf020a8ccf5c367fbe6a169f5d5d73dfce1707a75c9fbf4aa21c7da +F ext/wasm/api/sqlite3-api-worker1.js 8d9c0562831f62218170a3373468d8a0b7a6503b5985e309b69bf71187b525cf F ext/wasm/api/sqlite3-license-version-header.js 0c807a421f0187e778dc1078f10d2994b915123c1223fe752b60afdcd1263f89 F ext/wasm/api/sqlite3-opfs-async-proxy.js 8cf8a897726f14071fae6be6648125162b256dfb4f96555b865dbb7a6b65e379 F ext/wasm/api/sqlite3-v-helper.js 7daa0eab0a513a25b05e9abae7b5beaaa39209b3ed12f86aeae9ef8d2719ed25 F ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js 595953994aa3ae2287c889c4da39ab3d6f17b6461ecf4bec334b7a3faafddb02 F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js 46c4afa6c50d7369252c104f274ad977a97e91ccfafc38b400fe36e90bdda88e -F ext/wasm/api/sqlite3-wasm.c dfd1f1a225b267e8fd641dcd6c7d579fbe2b731aeaa123324135efac830a2bcf +F ext/wasm/api/sqlite3-wasm.c d33a16495ca871781e78812d3a18fed78b797468fffee657b8d7199b277ff359 F ext/wasm/api/sqlite3-worker1-promiser.c-pp.js f234191fe6bf41a5a1e59c9f43ed816e74a522b3d60d3f556f66c3085c448503 F ext/wasm/api/sqlite3-worker1.c-pp.js 5e8706c2c4af2a57fbcdc02f4e7ef79869971bc21bb8ede777687786ce1c92d5 F ext/wasm/batch-runner-sahpool.html e9a38fdeb36a13eac7b50241dfe7ae066fe3f51f5c0b0151e7baee5fce0d07a7 @@ -627,7 +627,7 @@ F ext/wasm/dist.make 3a851858aad72e246a5d9c5aaf6b6a144305f1bf898ac1846760ea7bab9 F ext/wasm/example_extra_init.c 2347cd69d19d839ef4e5e77b7855103a7fe3ef2af86f2e8c95839afd8b05862f F ext/wasm/fiddle.make fa2ba6e90457ba2a71cb745f200d409caf773076df75ae5b177cc225d7627a11 F ext/wasm/fiddle/emscripten.css 3d253a6fdb8983a2ac983855bfbdd4b6fa1ff267c28d69513dd6ef1f289ada3f -F ext/wasm/fiddle/fiddle-worker.js e0153f9af6500805c6f09c0b3cfdb7d857e9d6863dbee9d50d1628fccf5f4b4d +F ext/wasm/fiddle/fiddle-worker.js 9be57887756c6854dbdcb5e7d8b7a26935d565491333a2f91dc4113598c659b5 F ext/wasm/fiddle/fiddle.js 974b995119ac443685d7d94d3b3c58c6a36540e9eb3fed7069d5653284071715 F ext/wasm/fiddle/index.html 5daf54e8f3d7777cbb1ca4f93affe28858dbfff25841cb4ab81d694efed28ec2 F ext/wasm/index-dist.html e91d76e4581185238fd3d42ed86ec600f7023ed3e3a944c5c356f25304bf1263 @@ -640,7 +640,7 @@ F ext/wasm/scratchpad-wasmfs.mjs 66034b9256b218de59248aad796760a1584c1dd84223150 F ext/wasm/speedtest1-wasmfs.html 0e9d335a9b5b5fafe6e1bc8dc0f0ca7e22e6eb916682a2d7c36218bb7d67379d F ext/wasm/speedtest1-wasmfs.mjs ac5cadbf4ffe69e9eaac8b45e8523f030521e02bb67d654c6eb5236d9c456cbe F ext/wasm/speedtest1-worker.html 864b65ed78ce24847a348c180e7f267621a02ca027068a1863ec1c90187c1852 -F ext/wasm/speedtest1-worker.js 4d2ea70a3c24e05bdca78025202841f33d298c4fa9541a0070c3228661f89ecd +F ext/wasm/speedtest1-worker.js 95e549e13a4d35863a9a7fc66122b5f546c0130d3be7b06dfcc556eb66d24bde F ext/wasm/speedtest1.html ff048b4a623aa192e83e143e48f1ce2a899846dd42c023fdedc8772b6e3f07da F ext/wasm/split-speedtest1-script.sh a3e271938d4d14ee49105eb05567c6a69ba4c1f1293583ad5af0cd3a3779e205 x F ext/wasm/sql/000-mandelbrot.sql 775337a4b80938ac8146aedf88808282f04d02d983d82675bd63d9c2d97a15f0 @@ -649,7 +649,7 @@ F ext/wasm/test-opfs-vfs.html 1f2d672f3f3fce810dfd48a8d56914aba22e45c6834e262555 F ext/wasm/test-opfs-vfs.js 1618670e466f424aa289859fe0ec8ded223e42e9e69b5c851f809baaaca1a00c F ext/wasm/tester1-worker.html ebc4b820a128963afce328ecf63ab200bd923309eb939f4110510ab449e9814c F ext/wasm/tester1.c-pp.html 1c1bc78b858af2019e663b1a31e76657b73dc24bede28ca92fbe917c3a972af2 -F ext/wasm/tester1.c-pp.js a92dc256738dbd1b50f142d1fd0c835294ba09b7bb6526650360e942f88cb63f +F ext/wasm/tester1.c-pp.js 7c51d19f3644904156a154ddedd7024539ffba1a4e2df5e1efe10333e5b91b8f F ext/wasm/tests/opfs/concurrency/index.html 0802373d57034d51835ff6041cda438c7a982deea6079efd98098d3e42fbcbc1 F ext/wasm/tests/opfs/concurrency/test.js a98016113eaf71e81ddbf71655aa29b0fed9a8b79a3cdd3620d1658eb1cc9a5d F ext/wasm/tests/opfs/concurrency/worker.js 0a8c1a3e6ebb38aabbee24f122693f1fb29d599948915c76906681bb7da1d3d2 @@ -2156,8 +2156,11 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 7a5b42ff74882c58493dc8b710fde73d4ff251f5d42271d84be73ceaabc01698 -R e24ddedf31de297bbf4b76d307641631 -U drh -Z ac5f82bfe64ed7224d42f062673e1893 +P 40f0a29e6dd90fcb969d7c0e49728ba0ee8f31d9e8f502b9a21469620a8ad283 +R 31be0596762218f8c1e89235c4c8d052 +T *branch * wasm-post-3.45 +T *sym-wasm-post-3.45 * +T -sym-trunk * Cancelled\sby\sbranch. +U stephan +Z 0af9fee02d812416e8b303fb5ea1a236 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 215afe7261..c473c95c40 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -40f0a29e6dd90fcb969d7c0e49728ba0ee8f31d9e8f502b9a21469620a8ad283 \ No newline at end of file +0eddc20f37988df6bce5f407b69e4a315e5cca4af104586e6fe942f0d656cccd \ No newline at end of file From 598328209f421d48e98115dd6816da5114403616 Mon Sep 17 00:00:00 2001 From: stephan Date: Thu, 11 Jan 2024 12:31:58 +0000 Subject: [PATCH 005/430] Split the JS vfs/vtab helper code into discreet units as a step towards a build which optionally elides those pieces. This is an internal restructuring change and does not affect the API. FossilOrigin-Name: ede945fd2360097d9961b8a4b8fb48fea57399cb9163534ed1c3c6b86588b0a5 --- ext/wasm/GNUmakefile | 6 +- ext/wasm/api/README.md | 10 +- ext/wasm/api/sqlite3-api-glue.js | 207 +++++++++++- ext/wasm/api/sqlite3-vfs-helper.c-pp.js | 103 ++++++ ...-helper.js => sqlite3-vtab-helper.c-pp.js} | 311 +----------------- manifest | 22 +- manifest.uuid | 2 +- 7 files changed, 334 insertions(+), 327 deletions(-) create mode 100644 ext/wasm/api/sqlite3-vfs-helper.c-pp.js rename ext/wasm/api/{sqlite3-v-helper.js => sqlite3-vtab-helper.c-pp.js} (57%) diff --git a/ext/wasm/GNUmakefile b/ext/wasm/GNUmakefile index cbba48cc58..ac4a9cf8dd 100644 --- a/ext/wasm/GNUmakefile +++ b/ext/wasm/GNUmakefile @@ -433,8 +433,10 @@ sqlite3-api.jses += $(sqlite3-api-build-version.js) sqlite3-api.jses += $(dir.api)/sqlite3-api-oo1.js # sqlite3-api-worker.js = the Worker1 API: sqlite3-api.jses += $(dir.api)/sqlite3-api-worker1.js -# sqlite3-v-helper = helper APIs for VFSes and VTABLEs: -sqlite3-api.jses += $(dir.api)/sqlite3-v-helper.js +# sqlite3-vfs-helper = helper APIs for VFSes: +sqlite3-api.jses += $(dir.api)/sqlite3-vfs-helper.c-pp.js +# sqlite3-vtab-helper = helper APIs for VTABLEs: +sqlite3-api.jses += $(dir.api)/sqlite3-vtab-helper.c-pp.js # sqlite3-vfs-opfs.c-pp.js = the first OPFS VFS: sqlite3-api.jses += $(dir.api)/sqlite3-vfs-opfs.c-pp.js # sqlite3-vfs-opfs-sahpool.c-pp.js = the second OPFS VFS: diff --git a/ext/wasm/api/README.md b/ext/wasm/api/README.md index eb0f073cf7..ebd4aaacb1 100644 --- a/ext/wasm/api/README.md +++ b/ext/wasm/api/README.md @@ -78,10 +78,12 @@ browser client: a Promise-based interface into the Worker #1 API. This is a far user-friendlier way to interface with databases running in a Worker thread. -- **`sqlite3-v-helper.js`**\ - Installs `sqlite3.vfs` and `sqlite3.vtab`, namespaces which contain - helpers for use by downstream code which creates `sqlite3_vfs` - and `sqlite3_module` implementations. +- **`sqlite3-vfs-helper.js`**\ + Installs the `sqlite3.vfs` namespace, which contain helpers for use + by downstream code which creates `sqlite3_vfs` implementations. +- **`sqlite3-vtab-helper.js`**\ + Installs the `sqlite3.vtab` namespace, which contain helpers for use + by downstream code which creates `sqlite3_module` implementations. - **`sqlite3-vfs-opfs.c-pp.js`**\ is an sqlite3 VFS implementation which supports the Origin-Private FileSystem (OPFS) as a storage layer to provide persistent storage diff --git a/ext/wasm/api/sqlite3-api-glue.js b/ext/wasm/api/sqlite3-api-glue.js index e12c5162c6..63fb3c739c 100644 --- a/ext/wasm/api/sqlite3-api-glue.js +++ b/ext/wasm/api/sqlite3-api-glue.js @@ -329,6 +329,14 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ } if(wasm.exports.sqlite3_activate_see instanceof Function){ + /** + This code is capable of using an SEE build but note that an SEE + WASM build is generally incompatible with SEE's license + conditions. It is permitted for use internally in organizations + which have licensed SEE, but not for public sites because + exposing an SEE build of sqlite3.wasm effectively provides all + clients with a working copy of the commercial SEE code. + */ wasm.bindingSignatures.push( ["sqlite3_key", "int", "sqlite3*", "string", "int"], ["sqlite3_key_v2","int","sqlite3*","string","*","int"], @@ -341,6 +349,8 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ Functions which require BigInt (int64) support are separated from the others because we need to conditionally bind them or apply dummy impls, depending on the capabilities of the environment. + (That said: we never actually build without BigInt support, + and such builds are untested.) Note that not all of these functions directly require int64 but are only for use with APIs which require int64. For example, @@ -359,7 +369,10 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ /* Careful! Short version: de/serialize() are problematic because they might use a different allocator than the user for managing the deserialized block. de/serialize() are ONLY safe to use with - sqlite3_malloc(), sqlite3_free(), and its 64-bit variants. */, + sqlite3_malloc(), sqlite3_free(), and its 64-bit variants. Because + of this, the canonical builds of sqlite3.wasm/js guarantee that + sqlite3.wasm.alloc() and friends use those allocators. Custom builds + may not guarantee that, however. */, ["sqlite3_drop_modules", "int", ["sqlite3*", "**"]], ["sqlite3_last_insert_rowid", "i64", ["sqlite3*"]], ["sqlite3_malloc64", "*","i64"], @@ -422,8 +435,6 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ // Add session/changeset APIs... if(wasm.bigIntEnabled && !!wasm.exports.sqlite3changegroup_add){ - /* ACHTUNG: 2022-12-23: the session/changeset API bindings are - COMPLETELY UNTESTED. */ /** FuncPtrAdapter options for session-related callbacks with the native signature "i(ps)". This proxy converts the 2nd argument @@ -602,7 +613,12 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ Functions which are intended solely for API-internal use by the WASM components, not client code. These get installed into sqlite3.util. Some of them get exposed to clients via variants - in wasm.sqlite3_js_...(). + in sqlite3_js_...(). + + 2024-01-11: these were renamed, with two underscores in the + prefix, to ensure that clients do not accidentally depend on + them. They have always been documented as internal-use-only, so + no clients "should" be depending on the old names. */ wasm.bindingSignatures.wasmInternal = [ ["sqlite3__wasm_db_reset", "int", "sqlite3*"], @@ -652,7 +668,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ Use case: sqlite3_bind_pointer() and sqlite3_result_pointer() call for "a static string and preferably a string - literal". This converter is used to ensure that the string + literal." This converter is used to ensure that the string value seen by those functions is long-lived and behaves as they need it to. */ @@ -674,14 +690,15 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ `sqlite3_vfs*` via capi.sqlite3_vfs.pointer. */ const __xArgPtr = wasm.xWrap.argAdapter('*'); - const nilType = function(){}/*a class no value can ever be an instance of*/; + const nilType = function(){ + /*a class which no value can ever be an instance of*/ + }; wasm.xWrap.argAdapter('sqlite3_filename', __xArgPtr) ('sqlite3_context*', __xArgPtr) ('sqlite3_value*', __xArgPtr) ('void*', __xArgPtr) ('sqlite3_changegroup*', __xArgPtr) ('sqlite3_changeset_iter*', __xArgPtr) - //('sqlite3_rebaser*', __xArgPtr) ('sqlite3_session*', __xArgPtr) ('sqlite3_stmt*', (v)=> __xArgPtr((v instanceof (sqlite3?.oo1?.Stmt || nilType)) @@ -1667,5 +1684,181 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ } }/*pKvvfs*/ + /* Warn if client-level code makes use of FuncPtrAdapter. */ wasm.xWrap.FuncPtrAdapter.warnOnUse = true; + + const StructBinder = sqlite3.StructBinder + /* we require a local alias b/c StructBinder is removed from the sqlite3 + object during the final steps of the API cleanup. */; + /** + Installs a StructBinder-bound function pointer member of the + given name and function in the given StructBinder.StructType + target object. + + It creates a WASM proxy for the given function and arranges for + that proxy to be cleaned up when tgt.dispose() is called. Throws + on the slightest hint of error, e.g. tgt is-not-a StructType, + name does not map to a struct-bound member, etc. + + As a special case, if the given function is a pointer, then + `wasm.functionEntry()` is used to validate that it is a known + function. If so, it is used as-is with no extra level of proxying + or cleanup, else an exception is thrown. It is legal to pass a + value of 0, indicating a NULL pointer, with the caveat that 0 + _is_ a legal function pointer in WASM but it will not be accepted + as such _here_. (Justification: the function at address zero must + be one which initially came from the WASM module, not a method we + want to bind to a virtual table or VFS.) + + This function returns a proxy for itself which is bound to tgt + and takes 2 args (name,func). That function returns the same + thing as this one, permitting calls to be chained. + + If called with only 1 arg, it has no side effects but returns a + func with the same signature as described above. + + ACHTUNG: because we cannot generically know how to transform JS + exceptions into result codes, the installed functions do no + automatic catching of exceptions. It is critical, to avoid + undefined behavior in the C layer, that methods mapped via + this function do not throw. The exception, as it were, to that + rule is... + + If applyArgcCheck is true then each JS function (as opposed to + function pointers) gets wrapped in a proxy which asserts that it + is passed the expected number of arguments, throwing if the + argument count does not match expectations. That is only intended + for dev-time usage for sanity checking, and may leave the C + environment in an undefined state. + */ + const installMethod = function callee( + tgt, name, func, applyArgcCheck = callee.installMethodArgcCheck + ){ + if(!(tgt instanceof StructBinder.StructType)){ + toss("Usage error: target object is-not-a StructType."); + }else if(!(func instanceof Function) && !wasm.isPtr(func)){ + toss("Usage errror: expecting a Function or WASM pointer to one."); + } + if(1===arguments.length){ + return (n,f)=>callee(tgt, n, f, applyArgcCheck); + } + if(!callee.argcProxy){ + callee.argcProxy = function(tgt, funcName, func,sig){ + return function(...args){ + if(func.length!==arguments.length){ + toss("Argument mismatch for", + tgt.structInfo.name+"::"+funcName + +": Native signature is:",sig); + } + return func.apply(this, args); + } + }; + /* An ondispose() callback for use with + StructBinder-created types. */ + callee.removeFuncList = function(){ + if(this.ondispose.__removeFuncList){ + this.ondispose.__removeFuncList.forEach( + (v,ndx)=>{ + if('number'===typeof v){ + try{wasm.uninstallFunction(v)} + catch(e){/*ignore*/} + } + /* else it's a descriptive label for the next number in + the list. */ + } + ); + delete this.ondispose.__removeFuncList; + } + }; + }/*static init*/ + const sigN = tgt.memberSignature(name); + if(sigN.length<2){ + toss("Member",name,"does not have a function pointer signature:",sigN); + } + const memKey = tgt.memberKey(name); + const fProxy = (applyArgcCheck && !wasm.isPtr(func)) + /** This middle-man proxy is only for use during development, to + confirm that we always pass the proper number of + arguments. We know that the C-level code will always use the + correct argument count. */ + ? callee.argcProxy(tgt, memKey, func, sigN) + : func; + if(wasm.isPtr(fProxy)){ + if(fProxy && !wasm.functionEntry(fProxy)){ + toss("Pointer",fProxy,"is not a WASM function table entry."); + } + tgt[memKey] = fProxy; + }else{ + const pFunc = wasm.installFunction(fProxy, tgt.memberSignature(name, true)); + tgt[memKey] = pFunc; + if(!tgt.ondispose || !tgt.ondispose.__removeFuncList){ + tgt.addOnDispose('ondispose.__removeFuncList handler', + callee.removeFuncList); + tgt.ondispose.__removeFuncList = []; + } + tgt.ondispose.__removeFuncList.push(memKey, pFunc); + } + return (n,f)=>callee(tgt, n, f, applyArgcCheck); + }/*installMethod*/; + installMethod.installMethodArgcCheck = false; + + /** + Installs methods into the given StructBinder.StructType-type + instance. Each entry in the given methods object must map to a + known member of the given StructType, else an exception will be + triggered. See installMethod() for more details, including the + semantics of the 3rd argument. + + As an exception to the above, if any two or more methods in the + 2nd argument are the exact same function, installMethod() is + _not_ called for the 2nd and subsequent instances, and instead + those instances get assigned the same method pointer which is + created for the first instance. This optimization is primarily to + accommodate special handling of sqlite3_module::xConnect and + xCreate methods. + + On success, returns its first argument. Throws on error. + */ + const installMethods = function( + structInstance, methods, applyArgcCheck = installMethod.installMethodArgcCheck + ){ + const seen = new Map /* map of */; + for(const k of Object.keys(methods)){ + const m = methods[k]; + const prior = seen.get(m); + if(prior){ + const mkey = structInstance.memberKey(k); + structInstance[mkey] = structInstance[structInstance.memberKey(prior)]; + }else{ + installMethod(structInstance, k, m, applyArgcCheck); + seen.set(m, k); + } + } + return structInstance; + }; + + /** + Equivalent to calling installMethod(this,...arguments) with a + first argument of this object. If called with 1 or 2 arguments + and the first is an object, it's instead equivalent to calling + installMethods(this,...arguments). + */ + StructBinder.StructType.prototype.installMethod = function callee( + name, func, applyArgcCheck = installMethod.installMethodArgcCheck + ){ + return (arguments.length < 3 && name && 'object'===typeof name) + ? installMethods(this, ...arguments) + : installMethod(this, ...arguments); + }; + + /** + Equivalent to calling installMethods() with a first argument + of this object. + */ + StructBinder.StructType.prototype.installMethods = function( + methods, applyArgcCheck = installMethod.installMethodArgcCheck + ){ + return installMethods(this, methods, applyArgcCheck); + }; + }); diff --git a/ext/wasm/api/sqlite3-vfs-helper.c-pp.js b/ext/wasm/api/sqlite3-vfs-helper.c-pp.js new file mode 100644 index 0000000000..0065d9547c --- /dev/null +++ b/ext/wasm/api/sqlite3-vfs-helper.c-pp.js @@ -0,0 +1,103 @@ +/* +** 2022-11-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. +*/ + +/** + This file installs sqlite3.vfs, an object which exists to assist + in the creation of JavaScript implementations of sqlite3_vfs. +*/ +'use strict'; +globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ + const wasm = sqlite3.wasm, capi = sqlite3.capi, toss = sqlite3.util.toss3; + const vfs = Object.create(null); + sqlite3.vfs = vfs; + + /** + Uses sqlite3_vfs_register() to register this + sqlite3.capi.sqlite3_vfs. This object must have already been + filled out properly. If the first argument is truthy, the VFS is + registered as the default VFS, else it is not. + + On success, returns this object. Throws on error. + */ + capi.sqlite3_vfs.prototype.registerVfs = function(asDefault=false){ + if(!(this instanceof sqlite3.capi.sqlite3_vfs)){ + toss("Expecting a sqlite3_vfs-type argument."); + } + const rc = capi.sqlite3_vfs_register(this, asDefault ? 1 : 0); + if(rc){ + toss("sqlite3_vfs_register(",this,") failed with rc",rc); + } + if(this.pointer !== capi.sqlite3_vfs_find(this.$zName)){ + toss("BUG: sqlite3_vfs_find(vfs.$zName) failed for just-installed VFS", + this); + } + return this; + }; + + /** + A wrapper for + sqlite3.StructBinder.StructType.prototype.installMethods() or + registerVfs() to reduce installation of a VFS and/or its I/O + methods to a single call. + + Accepts an object which contains the properties "io" and/or + "vfs", each of which is itself an object with following properties: + + - `struct`: an sqlite3.StructBinder.StructType-type struct. This + must be a populated (except for the methods) object of type + sqlite3_io_methods (for the "io" entry) or sqlite3_vfs (for the + "vfs" entry). + + - `methods`: an object mapping sqlite3_io_methods method names + (e.g. 'xClose') to JS implementations of those methods. The JS + implementations must be call-compatible with their native + counterparts. + + For each of those object, this function passes its (`struct`, + `methods`, (optional) `applyArgcCheck`) properties to + installMethods(). + + If the `vfs` entry is set then: + + - Its `struct` property's registerVfs() is called. The + `vfs` entry may optionally have an `asDefault` property, which + gets passed as the argument to registerVfs(). + + - If `struct.$zName` is falsy and the entry has a string-type + `name` property, `struct.$zName` is set to the C-string form of + that `name` value before registerVfs() is called. That string + gets added to the on-dispose state of the struct. + + On success returns this object. Throws on error. + */ + vfs.installVfs = function(opt){ + let count = 0; + const propList = ['io','vfs']; + for(const key of propList){ + const o = opt[key]; + if(o){ + ++count; + o.struct.installMethods(o.methods, !!o.applyArgcCheck); + if('vfs'===key){ + if(!o.struct.$zName && 'string'===typeof o.name){ + o.struct.addOnDispose( + o.struct.$zName = wasm.allocCString(o.name) + ); + } + o.struct.registerVfs(!!o.asDefault); + } + } + } + if(!count) toss("Misuse: installVfs() options object requires at least", + "one of:", propList); + return this; + }; +}/*sqlite3ApiBootstrap.initializers.push()*/); diff --git a/ext/wasm/api/sqlite3-v-helper.js b/ext/wasm/api/sqlite3-vtab-helper.c-pp.js similarity index 57% rename from ext/wasm/api/sqlite3-v-helper.js rename to ext/wasm/api/sqlite3-vtab-helper.c-pp.js index e63da8afc3..c069554a13 100644 --- a/ext/wasm/api/sqlite3-v-helper.js +++ b/ext/wasm/api/sqlite3-vtab-helper.c-pp.js @@ -10,19 +10,17 @@ */ /** - This file installs sqlite3.vfs, and object which exists to assist - in the creation of JavaScript implementations of sqlite3_vfs, along - with its virtual table counterpart, sqlite3.vtab. + This file installs sqlite3.vtab, an object which exists to assist + in the creation of JavaScript implementations virtual tables. + + Maintenance note: 2024-01-11: this file requires that StructBinder + has been extended with the installMethod(s)() methods, which + currently happens in sqlite3-api-glue.js. */ 'use strict'; globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ const wasm = sqlite3.wasm, capi = sqlite3.capi, toss = sqlite3.util.toss3; - const vfs = Object.create(null), vtab = Object.create(null); - - const StructBinder = sqlite3.StructBinder - /* we require a local alias b/c StructBinder is removed from the sqlite3 - object during the final steps of the API cleanup. */; - sqlite3.vfs = vfs; + const vtab = Object.create(null); sqlite3.vtab = vtab; const sii = capi.sqlite3_index_info; @@ -72,257 +70,6 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ return asPtr ? ptr : new sii.sqlite3_index_orderby(ptr); }; - /** - Installs a StructBinder-bound function pointer member of the - given name and function in the given StructType target object. - - It creates a WASM proxy for the given function and arranges for - that proxy to be cleaned up when tgt.dispose() is called. Throws - on the slightest hint of error, e.g. tgt is-not-a StructType, - name does not map to a struct-bound member, etc. - - As a special case, if the given function is a pointer, then - `wasm.functionEntry()` is used to validate that it is a known - function. If so, it is used as-is with no extra level of proxying - or cleanup, else an exception is thrown. It is legal to pass a - value of 0, indicating a NULL pointer, with the caveat that 0 - _is_ a legal function pointer in WASM but it will not be accepted - as such _here_. (Justification: the function at address zero must - be one which initially came from the WASM module, not a method we - want to bind to a virtual table or VFS.) - - This function returns a proxy for itself which is bound to tgt - and takes 2 args (name,func). That function returns the same - thing as this one, permitting calls to be chained. - - If called with only 1 arg, it has no side effects but returns a - func with the same signature as described above. - - ACHTUNG: because we cannot generically know how to transform JS - exceptions into result codes, the installed functions do no - automatic catching of exceptions. It is critical, to avoid - undefined behavior in the C layer, that methods mapped via - this function do not throw. The exception, as it were, to that - rule is... - - If applyArgcCheck is true then each JS function (as opposed to - function pointers) gets wrapped in a proxy which asserts that it - is passed the expected number of arguments, throwing if the - argument count does not match expectations. That is only intended - for dev-time usage for sanity checking, and will leave the C - environment in an undefined state. - */ - const installMethod = function callee( - tgt, name, func, applyArgcCheck = callee.installMethodArgcCheck - ){ - if(!(tgt instanceof StructBinder.StructType)){ - toss("Usage error: target object is-not-a StructType."); - }else if(!(func instanceof Function) && !wasm.isPtr(func)){ - toss("Usage errror: expecting a Function or WASM pointer to one."); - } - if(1===arguments.length){ - return (n,f)=>callee(tgt, n, f, applyArgcCheck); - } - if(!callee.argcProxy){ - callee.argcProxy = function(tgt, funcName, func,sig){ - return function(...args){ - if(func.length!==arguments.length){ - toss("Argument mismatch for", - tgt.structInfo.name+"::"+funcName - +": Native signature is:",sig); - } - return func.apply(this, args); - } - }; - /* An ondispose() callback for use with - StructBinder-created types. */ - callee.removeFuncList = function(){ - if(this.ondispose.__removeFuncList){ - this.ondispose.__removeFuncList.forEach( - (v,ndx)=>{ - if('number'===typeof v){ - try{wasm.uninstallFunction(v)} - catch(e){/*ignore*/} - } - /* else it's a descriptive label for the next number in - the list. */ - } - ); - delete this.ondispose.__removeFuncList; - } - }; - }/*static init*/ - const sigN = tgt.memberSignature(name); - if(sigN.length<2){ - toss("Member",name,"does not have a function pointer signature:",sigN); - } - const memKey = tgt.memberKey(name); - const fProxy = (applyArgcCheck && !wasm.isPtr(func)) - /** This middle-man proxy is only for use during development, to - confirm that we always pass the proper number of - arguments. We know that the C-level code will always use the - correct argument count. */ - ? callee.argcProxy(tgt, memKey, func, sigN) - : func; - if(wasm.isPtr(fProxy)){ - if(fProxy && !wasm.functionEntry(fProxy)){ - toss("Pointer",fProxy,"is not a WASM function table entry."); - } - tgt[memKey] = fProxy; - }else{ - const pFunc = wasm.installFunction(fProxy, tgt.memberSignature(name, true)); - tgt[memKey] = pFunc; - if(!tgt.ondispose || !tgt.ondispose.__removeFuncList){ - tgt.addOnDispose('ondispose.__removeFuncList handler', - callee.removeFuncList); - tgt.ondispose.__removeFuncList = []; - } - tgt.ondispose.__removeFuncList.push(memKey, pFunc); - } - return (n,f)=>callee(tgt, n, f, applyArgcCheck); - }/*installMethod*/; - installMethod.installMethodArgcCheck = false; - - /** - Installs methods into the given StructType-type instance. Each - entry in the given methods object must map to a known member of - the given StructType, else an exception will be triggered. See - installMethod() for more details, including the semantics of the - 3rd argument. - - As an exception to the above, if any two or more methods in the - 2nd argument are the exact same function, installMethod() is - _not_ called for the 2nd and subsequent instances, and instead - those instances get assigned the same method pointer which is - created for the first instance. This optimization is primarily to - accommodate special handling of sqlite3_module::xConnect and - xCreate methods. - - On success, returns its first argument. Throws on error. - */ - const installMethods = function( - structInstance, methods, applyArgcCheck = installMethod.installMethodArgcCheck - ){ - const seen = new Map /* map of */; - for(const k of Object.keys(methods)){ - const m = methods[k]; - const prior = seen.get(m); - if(prior){ - const mkey = structInstance.memberKey(k); - structInstance[mkey] = structInstance[structInstance.memberKey(prior)]; - }else{ - installMethod(structInstance, k, m, applyArgcCheck); - seen.set(m, k); - } - } - return structInstance; - }; - - /** - Equivalent to calling installMethod(this,...arguments) with a - first argument of this object. If called with 1 or 2 arguments - and the first is an object, it's instead equivalent to calling - installMethods(this,...arguments). - */ - StructBinder.StructType.prototype.installMethod = function callee( - name, func, applyArgcCheck = installMethod.installMethodArgcCheck - ){ - return (arguments.length < 3 && name && 'object'===typeof name) - ? installMethods(this, ...arguments) - : installMethod(this, ...arguments); - }; - - /** - Equivalent to calling installMethods() with a first argument - of this object. - */ - StructBinder.StructType.prototype.installMethods = function( - methods, applyArgcCheck = installMethod.installMethodArgcCheck - ){ - return installMethods(this, methods, applyArgcCheck); - }; - - /** - Uses sqlite3_vfs_register() to register this - sqlite3.capi.sqlite3_vfs. This object must have already been - filled out properly. If the first argument is truthy, the VFS is - registered as the default VFS, else it is not. - - On success, returns this object. Throws on error. - */ - capi.sqlite3_vfs.prototype.registerVfs = function(asDefault=false){ - if(!(this instanceof sqlite3.capi.sqlite3_vfs)){ - toss("Expecting a sqlite3_vfs-type argument."); - } - const rc = capi.sqlite3_vfs_register(this, asDefault ? 1 : 0); - if(rc){ - toss("sqlite3_vfs_register(",this,") failed with rc",rc); - } - if(this.pointer !== capi.sqlite3_vfs_find(this.$zName)){ - toss("BUG: sqlite3_vfs_find(vfs.$zName) failed for just-installed VFS", - this); - } - return this; - }; - - /** - A wrapper for installMethods() or registerVfs() to reduce - installation of a VFS and/or its I/O methods to a single - call. - - Accepts an object which contains the properties "io" and/or - "vfs", each of which is itself an object with following properties: - - - `struct`: an sqlite3.StructType-type struct. This must be a - populated (except for the methods) object of type - sqlite3_io_methods (for the "io" entry) or sqlite3_vfs (for the - "vfs" entry). - - - `methods`: an object mapping sqlite3_io_methods method names - (e.g. 'xClose') to JS implementations of those methods. The JS - implementations must be call-compatible with their native - counterparts. - - For each of those object, this function passes its (`struct`, - `methods`, (optional) `applyArgcCheck`) properties to - installMethods(). - - If the `vfs` entry is set then: - - - Its `struct` property's registerVfs() is called. The - `vfs` entry may optionally have an `asDefault` property, which - gets passed as the argument to registerVfs(). - - - If `struct.$zName` is falsy and the entry has a string-type - `name` property, `struct.$zName` is set to the C-string form of - that `name` value before registerVfs() is called. That string - gets added to the on-dispose state of the struct. - - On success returns this object. Throws on error. - */ - vfs.installVfs = function(opt){ - let count = 0; - const propList = ['io','vfs']; - for(const key of propList){ - const o = opt[key]; - if(o){ - ++count; - installMethods(o.struct, o.methods, !!o.applyArgcCheck); - if('vfs'===key){ - if(!o.struct.$zName && 'string'===typeof o.name){ - o.struct.addOnDispose( - o.struct.$zName = wasm.allocCString(o.name) - ); - } - o.struct.registerVfs(!!o.asDefault); - } - } - } - if(!count) toss("Misuse: installVfs() options object requires at least", - "one of:", propList); - return this; - }; - /** Internal factory function for xVtab and xCursor impls. */ @@ -456,30 +203,6 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ */ vtab.xIndexInfo = (pIdxInfo)=>new capi.sqlite3_index_info(pIdxInfo); - /** - Given an error object, this function returns - sqlite3.capi.SQLITE_NOMEM if (e instanceof - sqlite3.WasmAllocError), else it returns its - second argument. Its intended usage is in the methods - of a sqlite3_vfs or sqlite3_module: - - ``` - try{ - let rc = ... - return rc; - }catch(e){ - return sqlite3.vtab.exceptionToRc(e, sqlite3.capi.SQLITE_XYZ); - // where SQLITE_XYZ is some call-appropriate result code. - } - ``` - */ - /**vfs.exceptionToRc = vtab.exceptionToRc = - (e, defaultRc=capi.SQLITE_ERROR)=>( - (e instanceof sqlite3.WasmAllocError) - ? capi.SQLITE_NOMEM - : defaultRc - );*/ - /** Given an sqlite3_module method name and error object, this function returns sqlite3.capi.SQLITE_NOMEM if (e instanceof @@ -525,20 +248,6 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ }; vtab.xError.errorReporter = 1 ? console.error.bind(console) : false; - /** - "The problem" with this is that it introduces an outer function with - a different arity than the passed-in method callback. That means we - cannot do argc validation on these. Additionally, some methods (namely - xConnect) may have call-specific error handling. It would be a shame to - hard-coded that per-method support in this function. - */ - /** vtab.methodCatcher = function(methodName, method, defaultErrRc=capi.SQLITE_ERROR){ - return function(...args){ - try { method(...args); } - }catch(e){ return vtab.xError(methodName, e, defaultRc) } - }; - */ - /** A helper for sqlite3_vtab::xRowid() and xUpdate() implementations. It must be passed the final argument to one of @@ -685,12 +394,12 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ remethods[k] = fwrap(k, m); } } - installMethods(mod, remethods, false); + mod.installMethods(remethods, false); }else{ // No automatic exception handling. Trust the client // to not throw. - installMethods( - mod, methods, !!opt.applyArgcCheck/*undocumented option*/ + mod.installMethods( + methods, !!opt.applyArgcCheck/*undocumented option*/ ); } if(0===mod.$iVersion){ diff --git a/manifest b/manifest index 3ae52dc786..e50e307ac3 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Make\sexplicit\swhich\sJS\sAPIs\sare\sfor\sinternal\suse\sonly\sby\smoving\sthe\sJS-bound\sinternal-use-only\sfunctions\sout\sof\sclient-visible\sreach\sand\srenaming\sthe\sWASM-exported\sones\sfrom\ssqlite3_wasm...\sto\ssqlite3__wasm...\s(with\stwo\sunderscores).\sThese\shave\salways\sbeen\sdocumented\sas\sinternal-use-only,\sso\sthis\sis\snot\sa\sbreaking\schange\sexcept\sfor\sclients\swhich\shave\signored\sthe\sdocs. -D 2024-01-08T07:52:47.965 +C Split\sthe\sJS\svfs/vtab\shelper\scode\sinto\sdiscreet\sunits\sas\sa\sstep\stowards\sa\sbuild\swhich\soptionally\selides\sthose\spieces.\sThis\sis\san\sinternal\srestructuring\schange\sand\sdoes\snot\saffect\sthe\sAPI. +D 2024-01-11T12:31:58.929 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -575,7 +575,7 @@ F ext/userauth/sqlite3userauth.h 7f3ea8c4686db8e40b0a0e7a8e0b00fac13aa7a3 F ext/userauth/user-auth.txt e6641021a9210364665fe625d067617d03f27b04 F ext/userauth/userauth.c 7f00cded7dcaa5d47f54539b290a43d2e59f4b1eb5f447545fa865f002fc80cb F ext/wasm/EXPORTED_FUNCTIONS.fiddle.in 27450c8b8c70875a260aca55435ec927068b34cef801a96205adb81bdcefc65c -F ext/wasm/GNUmakefile 0f4ccfd350a9b0ebe60183fb4ad3b41c670eec62c88279f22e2627887b524b3c +F ext/wasm/GNUmakefile 693ff54a2710751a34ef4419a63eb7ea957f7e730f837fc1ef1dc475bdc5a6c8 F ext/wasm/README-dist.txt 6382cb9548076fca472fb3330bbdba3a55c1ea0b180ff9253f084f07ff383576 F ext/wasm/README.md a8a2962c3aebdf8d2104a9102e336c5554e78fc6072746e5daf9c61514e7d193 F ext/wasm/SQLTester/GNUmakefile e0794f676d55819951bbfae45cc5e8d7818dc460492dc317ce7f0d2eca15caff @@ -586,22 +586,23 @@ F ext/wasm/SQLTester/touint8array.c 2d5ece04ec1393a6a60c4bf96385bda5e1a10ad49f30 F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-api f442460ed9a109e637dd3ea1caa4489553ad9414e8988118b208bb7a4bbece6b F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-see fb29e62082a658f0d81102488414d422c393c4b20cc2f685b216bc566237957b F ext/wasm/api/EXPORTED_RUNTIME_METHODS.sqlite3-api 1ec3c73e7d66e95529c3c64ac3de2470b0e9e7fbf7a5b41261c367cf4f1b7287 -F ext/wasm/api/README.md 5eb44fa02e9c693a1884a3692428647894b0380b24bca120866b7a24c8786134 +F ext/wasm/api/README.md 34fe11466f9c1d81b10a0469e1114e5f1c5a6365c73d80a1a6ca639a1a358b73 F ext/wasm/api/extern-post-js.c-pp.js c4154a7f90c2d7e51fd6738273908152036c3457fdc0b6523f1be3ef51105aac F ext/wasm/api/extern-pre-js.js cc61c09c7a24a07dbecb4c352453c3985170cec12b4e7e7e7a4d11d43c5c8f41 F ext/wasm/api/post-js-footer.js cd0a8ec768501d9bd45d325ab0442037fb0e33d1f3b4f08902f15c34720ee4a1 F ext/wasm/api/post-js-header.js 47b6b281f39ad59fa6e8b658308cd98ea292c286a68407b35ff3ed9cfd281a62 F ext/wasm/api/pre-js.c-pp.js ad906703f7429590f2fbf5e6498513bf727a1a4f0ebfa057afb08161d7511219 F ext/wasm/api/sqlite3-api-cleanup.js d235ad237df6954145404305040991c72ef8b1881715d2a650dda7b3c2576d0e -F ext/wasm/api/sqlite3-api-glue.js 8f4478c927466245259478788c293810bc812ac8c49df38c62574966d836131a +F ext/wasm/api/sqlite3-api-glue.js 81ec1423e8c6dc8c26a3af470c993460d2f5137319ab1a00581203017e8b6b1f F ext/wasm/api/sqlite3-api-oo1.js 7f3bcf0549ac44cde4b9da0b642d771916738d3f6781fb8a1757c50a91e506c0 F ext/wasm/api/sqlite3-api-prologue.js fffcee629bf020a8ccf5c367fbe6a169f5d5d73dfce1707a75c9fbf4aa21c7da F ext/wasm/api/sqlite3-api-worker1.js 8d9c0562831f62218170a3373468d8a0b7a6503b5985e309b69bf71187b525cf F ext/wasm/api/sqlite3-license-version-header.js 0c807a421f0187e778dc1078f10d2994b915123c1223fe752b60afdcd1263f89 F ext/wasm/api/sqlite3-opfs-async-proxy.js 8cf8a897726f14071fae6be6648125162b256dfb4f96555b865dbb7a6b65e379 -F ext/wasm/api/sqlite3-v-helper.js 7daa0eab0a513a25b05e9abae7b5beaaa39209b3ed12f86aeae9ef8d2719ed25 +F ext/wasm/api/sqlite3-vfs-helper.c-pp.js 6c02e969ad988e083415221e84445711730a321c748d8555bb61aebec6b4a37c w ext/wasm/api/sqlite3-v-helper.js F ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js 595953994aa3ae2287c889c4da39ab3d6f17b6461ecf4bec334b7a3faafddb02 F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js 46c4afa6c50d7369252c104f274ad977a97e91ccfafc38b400fe36e90bdda88e +F ext/wasm/api/sqlite3-vtab-helper.c-pp.js ebbabbd33915904d3135680a0ea25f374adb60d6f39d664994bc48ac1673c280 F ext/wasm/api/sqlite3-wasm.c d33a16495ca871781e78812d3a18fed78b797468fffee657b8d7199b277ff359 F ext/wasm/api/sqlite3-worker1-promiser.c-pp.js f234191fe6bf41a5a1e59c9f43ed816e74a522b3d60d3f556f66c3085c448503 F ext/wasm/api/sqlite3-worker1.c-pp.js 5e8706c2c4af2a57fbcdc02f4e7ef79869971bc21bb8ede777687786ce1c92d5 @@ -2156,11 +2157,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 40f0a29e6dd90fcb969d7c0e49728ba0ee8f31d9e8f502b9a21469620a8ad283 -R 31be0596762218f8c1e89235c4c8d052 -T *branch * wasm-post-3.45 -T *sym-wasm-post-3.45 * -T -sym-trunk * Cancelled\sby\sbranch. +P 0eddc20f37988df6bce5f407b69e4a315e5cca4af104586e6fe942f0d656cccd +R 1d7e7db8e9c4453b4e333bcfcd1a037e U stephan -Z 0af9fee02d812416e8b303fb5ea1a236 +Z d03852f251d26d93c85f34544dbc6738 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index c473c95c40..e7c51869c8 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0eddc20f37988df6bce5f407b69e4a315e5cca4af104586e6fe942f0d656cccd \ No newline at end of file +ede945fd2360097d9961b8a4b8fb48fea57399cb9163534ed1c3c6b86588b0a5 \ No newline at end of file From bb9ab35ab14148cf28c3f7c8269d8af960ba7985 Mon Sep 17 00:00:00 2001 From: stephan Date: Thu, 11 Jan 2024 12:56:03 +0000 Subject: [PATCH 006/430] Remove some dead JS code. Minor doc cleanups. FossilOrigin-Name: bf23cf204976516651b1c4c39ced21cd858dea4ba88052d96fc4f5f11525f170 --- ext/wasm/api/sqlite3-vfs-helper.c-pp.js | 10 +++++----- ext/wasm/api/sqlite3-vfs-opfs.c-pp.js | 24 ++---------------------- ext/wasm/api/sqlite3-vtab-helper.c-pp.js | 8 ++------ manifest | 16 ++++++++-------- manifest.uuid | 2 +- 5 files changed, 18 insertions(+), 42 deletions(-) diff --git a/ext/wasm/api/sqlite3-vfs-helper.c-pp.js b/ext/wasm/api/sqlite3-vfs-helper.c-pp.js index 0065d9547c..4d29c7b91a 100644 --- a/ext/wasm/api/sqlite3-vfs-helper.c-pp.js +++ b/ext/wasm/api/sqlite3-vfs-helper.c-pp.js @@ -10,8 +10,8 @@ */ /** - This file installs sqlite3.vfs, an object which exists to assist - in the creation of JavaScript implementations of sqlite3_vfs. + This file installs sqlite3.vfs, a namespace of helpers for use in + the creation of JavaScript implementations of sqlite3_vfs. */ 'use strict'; globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ @@ -21,9 +21,9 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ /** Uses sqlite3_vfs_register() to register this - sqlite3.capi.sqlite3_vfs. This object must have already been - filled out properly. If the first argument is truthy, the VFS is - registered as the default VFS, else it is not. + sqlite3.capi.sqlite3_vfs instance. This object must have already + been filled out properly. If the first argument is truthy, the + VFS is registered as the default VFS, else it is not. On success, returns this object. Throws on error. */ diff --git a/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js b/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js index af89f216f7..f7c92100a0 100644 --- a/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js +++ b/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js @@ -245,7 +245,8 @@ const installOpfsVfs = function callee(options){ opfsIoMethods.$iVersion = 1; opfsVfs.$iVersion = 2/*yes, two*/; opfsVfs.$szOsFile = capi.sqlite3_file.structInfo.sizeof; - opfsVfs.$mxPathname = 1024/*sure, why not?*/; + opfsVfs.$mxPathname = 1024/* sure, why not? The OPFS name length limit + is undocumented/unspecified. */; opfsVfs.$zName = wasm.allocCString("opfs"); // All C-side memory of opfsVfs is zeroed out, but just to be explicit: opfsVfs.$xDlOpen = opfsVfs.$xDlError = opfsVfs.$xDlSym = opfsVfs.$xDlClose = null; @@ -993,27 +994,6 @@ const installOpfsVfs = function callee(options){ */ opfsUtil.randomFilename = randomFilename; - /** - Re-registers the OPFS VFS. This is intended only for odd use - cases which have to call sqlite3_shutdown() as part of their - initialization process, which will unregister the VFS - registered by installOpfsVfs(). If passed a truthy value, the - OPFS VFS is registered as the default VFS, else it is not made - the default. Returns the result of the the - sqlite3_vfs_register() call. - - Design note: the problem of having to re-register things after - a shutdown/initialize pair is more general. How to best plug - that in to the library is unclear. In particular, we cannot - hook in to any C-side calls to sqlite3_initialize(), so we - cannot add an after-initialize callback mechanism. - */ - opfsUtil.registerVfs = (asDefault=false)=>{ - return wasm.exports.sqlite3_vfs_register( - opfsVfs.pointer, asDefault ? 1 : 0 - ); - }; - /** Returns a promise which resolves to an object which represents all files and directories in the OPFS tree. The top-most object diff --git a/ext/wasm/api/sqlite3-vtab-helper.c-pp.js b/ext/wasm/api/sqlite3-vtab-helper.c-pp.js index c069554a13..7359ea39aa 100644 --- a/ext/wasm/api/sqlite3-vtab-helper.c-pp.js +++ b/ext/wasm/api/sqlite3-vtab-helper.c-pp.js @@ -10,12 +10,8 @@ */ /** - This file installs sqlite3.vtab, an object which exists to assist - in the creation of JavaScript implementations virtual tables. - - Maintenance note: 2024-01-11: this file requires that StructBinder - has been extended with the installMethod(s)() methods, which - currently happens in sqlite3-api-glue.js. + This file installs sqlite3.vtab, a namespace of helpers for use in + the creation of JavaScript implementations virtual tables. */ 'use strict'; globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ diff --git a/manifest b/manifest index e50e307ac3..087f72cc2a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Split\sthe\sJS\svfs/vtab\shelper\scode\sinto\sdiscreet\sunits\sas\sa\sstep\stowards\sa\sbuild\swhich\soptionally\selides\sthose\spieces.\sThis\sis\san\sinternal\srestructuring\schange\sand\sdoes\snot\saffect\sthe\sAPI. -D 2024-01-11T12:31:58.929 +C Remove\ssome\sdead\sJS\scode.\sMinor\sdoc\scleanups. +D 2024-01-11T12:56:03.352 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -599,10 +599,10 @@ F ext/wasm/api/sqlite3-api-prologue.js fffcee629bf020a8ccf5c367fbe6a169f5d5d73df F ext/wasm/api/sqlite3-api-worker1.js 8d9c0562831f62218170a3373468d8a0b7a6503b5985e309b69bf71187b525cf F ext/wasm/api/sqlite3-license-version-header.js 0c807a421f0187e778dc1078f10d2994b915123c1223fe752b60afdcd1263f89 F ext/wasm/api/sqlite3-opfs-async-proxy.js 8cf8a897726f14071fae6be6648125162b256dfb4f96555b865dbb7a6b65e379 -F ext/wasm/api/sqlite3-vfs-helper.c-pp.js 6c02e969ad988e083415221e84445711730a321c748d8555bb61aebec6b4a37c w ext/wasm/api/sqlite3-v-helper.js +F ext/wasm/api/sqlite3-vfs-helper.c-pp.js 3f828cc66758acb40e9c5b4dcfd87fd478a14c8fb7f0630264e6c7fa0e57515d F ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js 595953994aa3ae2287c889c4da39ab3d6f17b6461ecf4bec334b7a3faafddb02 -F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js 46c4afa6c50d7369252c104f274ad977a97e91ccfafc38b400fe36e90bdda88e -F ext/wasm/api/sqlite3-vtab-helper.c-pp.js ebbabbd33915904d3135680a0ea25f374adb60d6f39d664994bc48ac1673c280 +F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js ebf6c7e997cd8948b35b3afc550b0503dd53febd9d2b56354efd11d985e5f0f2 +F ext/wasm/api/sqlite3-vtab-helper.c-pp.js a2fcbc3fecdd0eea229283584ebc122f29d98194083675dbe5cb2cf3a17fe309 F ext/wasm/api/sqlite3-wasm.c d33a16495ca871781e78812d3a18fed78b797468fffee657b8d7199b277ff359 F ext/wasm/api/sqlite3-worker1-promiser.c-pp.js f234191fe6bf41a5a1e59c9f43ed816e74a522b3d60d3f556f66c3085c448503 F ext/wasm/api/sqlite3-worker1.c-pp.js 5e8706c2c4af2a57fbcdc02f4e7ef79869971bc21bb8ede777687786ce1c92d5 @@ -2157,8 +2157,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 0eddc20f37988df6bce5f407b69e4a315e5cca4af104586e6fe942f0d656cccd -R 1d7e7db8e9c4453b4e333bcfcd1a037e +P ede945fd2360097d9961b8a4b8fb48fea57399cb9163534ed1c3c6b86588b0a5 +R 3773101454a60b5af14ffec3a5e82fe8 U stephan -Z d03852f251d26d93c85f34544dbc6738 +Z 63b0feac805925513bf1a514b58f7275 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index e7c51869c8..9648d6e54f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ede945fd2360097d9961b8a4b8fb48fea57399cb9163534ed1c3c6b86588b0a5 \ No newline at end of file +bf23cf204976516651b1c4c39ced21cd858dea4ba88052d96fc4f5f11525f170 \ No newline at end of file From 7a543f6fbffabdf4f274c16f29604ec026641f09 Mon Sep 17 00:00:00 2001 From: stephan Date: Thu, 11 Jan 2024 14:21:15 +0000 Subject: [PATCH 007/430] Internal JS doc cleanups. FossilOrigin-Name: c8284170f66374fc528e9d6e5a03ee7321f27e80acf4360701a8b176497b7130 --- ext/wasm/api/post-js-header.js | 6 ++++-- ext/wasm/api/sqlite3-api-glue.js | 3 ++- manifest | 14 +++++++------- manifest.uuid | 2 +- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/ext/wasm/api/post-js-header.js b/ext/wasm/api/post-js-header.js index 0e27e1fd94..7fd82a7d6c 100644 --- a/ext/wasm/api/post-js-header.js +++ b/ext/wasm/api/post-js-header.js @@ -19,8 +19,10 @@ Module.postRun.push(function(Module/*the Emscripten-style module object*/){ - sqlite3-api-glue.js => glues previous parts together - sqlite3-api-oo.js => SQLite3 OO API #1 - sqlite3-api-worker1.js => Worker-based API - - sqlite3-vfs-helper.js => Internal-use utilities for... - - sqlite3-vfs-opfs.js => OPFS VFS + - sqlite3-vfs-helper.c-pp.js => Utilities for VFS impls + - 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-api-cleanup.js => final API cleanup - post-js-footer.js => closes this postRun() function */ diff --git a/ext/wasm/api/sqlite3-api-glue.js b/ext/wasm/api/sqlite3-api-glue.js index 63fb3c739c..2cb4c800d2 100644 --- a/ext/wasm/api/sqlite3-api-glue.js +++ b/ext/wasm/api/sqlite3-api-glue.js @@ -14,7 +14,8 @@ previous steps of the sqlite3-api.js bootstrapping process: sqlite3-api-prologue.js, whwasmutil.js, and jaccwabyt.js. It initializes the main API pieces so that the downstream components - (e.g. sqlite3-api-oo1.js) have all that they need. + (e.g. sqlite3-api-oo1.js) have all of the infrastructure that they + need. */ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ 'use strict'; diff --git a/manifest b/manifest index 087f72cc2a..3748fa6b01 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\ssome\sdead\sJS\scode.\sMinor\sdoc\scleanups. -D 2024-01-11T12:56:03.352 +C Internal\sJS\sdoc\scleanups. +D 2024-01-11T14:21:15.997 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -590,10 +590,10 @@ F ext/wasm/api/README.md 34fe11466f9c1d81b10a0469e1114e5f1c5a6365c73d80a1a6ca639 F ext/wasm/api/extern-post-js.c-pp.js c4154a7f90c2d7e51fd6738273908152036c3457fdc0b6523f1be3ef51105aac F ext/wasm/api/extern-pre-js.js cc61c09c7a24a07dbecb4c352453c3985170cec12b4e7e7e7a4d11d43c5c8f41 F ext/wasm/api/post-js-footer.js cd0a8ec768501d9bd45d325ab0442037fb0e33d1f3b4f08902f15c34720ee4a1 -F ext/wasm/api/post-js-header.js 47b6b281f39ad59fa6e8b658308cd98ea292c286a68407b35ff3ed9cfd281a62 +F ext/wasm/api/post-js-header.js 04dc12c3edd666b64a1b4ef3b6690c88dcc653f26451fd4734472d8e29c1c122 F ext/wasm/api/pre-js.c-pp.js ad906703f7429590f2fbf5e6498513bf727a1a4f0ebfa057afb08161d7511219 F ext/wasm/api/sqlite3-api-cleanup.js d235ad237df6954145404305040991c72ef8b1881715d2a650dda7b3c2576d0e -F ext/wasm/api/sqlite3-api-glue.js 81ec1423e8c6dc8c26a3af470c993460d2f5137319ab1a00581203017e8b6b1f +F ext/wasm/api/sqlite3-api-glue.js 587dc6db2d69329a5f4cb9635c377f516cf4a8e30f443f33380e5044889ec71b F ext/wasm/api/sqlite3-api-oo1.js 7f3bcf0549ac44cde4b9da0b642d771916738d3f6781fb8a1757c50a91e506c0 F ext/wasm/api/sqlite3-api-prologue.js fffcee629bf020a8ccf5c367fbe6a169f5d5d73dfce1707a75c9fbf4aa21c7da F ext/wasm/api/sqlite3-api-worker1.js 8d9c0562831f62218170a3373468d8a0b7a6503b5985e309b69bf71187b525cf @@ -2157,8 +2157,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P ede945fd2360097d9961b8a4b8fb48fea57399cb9163534ed1c3c6b86588b0a5 -R 3773101454a60b5af14ffec3a5e82fe8 +P bf23cf204976516651b1c4c39ced21cd858dea4ba88052d96fc4f5f11525f170 +R e6ab7f42561dbf7e5d9624bfb9b0bf26 U stephan -Z 63b0feac805925513bf1a514b58f7275 +Z 562f2a1dff86c554fee852503a03b96a # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 9648d6e54f..27445cc530 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -bf23cf204976516651b1c4c39ced21cd858dea4ba88052d96fc4f5f11525f170 \ No newline at end of file +c8284170f66374fc528e9d6e5a03ee7321f27e80acf4360701a8b176497b7130 \ No newline at end of file From 2fe917cfa5b44d2ef978216c1b5368f1297a3c4f Mon Sep 17 00:00:00 2001 From: stephan Date: Thu, 11 Jan 2024 16:10:22 +0000 Subject: [PATCH 008/430] wasm build: reformulate an awk invocation to account for awks which do not support the -e flag. Problem reported on the forum via a docker-hosted build. FossilOrigin-Name: 5836657929d7d6d3f0d5865c9f6de4e4c00edd53d15a246802b375fa15d0f255 --- ext/wasm/GNUmakefile | 7 +++++-- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/ext/wasm/GNUmakefile b/ext/wasm/GNUmakefile index ac4a9cf8dd..0865492cf5 100644 --- a/ext/wasm/GNUmakefile +++ b/ext/wasm/GNUmakefile @@ -655,6 +655,9 @@ $(sqlite3-api-build-version.js): $(bin.version-info) $(MAKEFILE) ######################################################################## # $(sqlite3-license-version.js) contains the license header and # in-comment build version info. +# +# Maintenance reminder: there are awk binaries out there which do not +# support -e SCRIPT. $(sqlite3-license-version.js): $(sqlite3.h) $(sqlite3-license-version-header.js) \ $(MAKEFILE) @echo "Making $@..."; { \ @@ -662,8 +665,8 @@ $(sqlite3-license-version.js): $(sqlite3.h) $(sqlite3-license-version-header.js) echo '/*'; \ echo '** This code was built from sqlite3 version...'; \ echo "**"; \ - awk -e '/define SQLITE_VERSION/{$$1=""; print "**" $$0}' \ - -e '/define SQLITE_SOURCE_ID/{$$1=""; print "**" $$0}' $(sqlite3.h); \ + awk '/define SQLITE_VERSION/{$$1=""; print "**" $$0}' $(sqlite3.h); \ + awk '/define SQLITE_SOURCE_ID/{$$1=""; print "**" $$0}' $(sqlite3.h); \ echo "**"; \ echo "** Using the Emscripten SDK version $(emcc.version)."; \ echo '*/'; \ diff --git a/manifest b/manifest index 3748fa6b01..cfc9843ec7 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Internal\sJS\sdoc\scleanups. -D 2024-01-11T14:21:15.997 +C wasm\sbuild:\sreformulate\san\sawk\sinvocation\sto\saccount\sfor\sawks\swhich\sdo\snot\ssupport\sthe\s-e\sflag.\sProblem\sreported\son\sthe\sforum\svia\sa\sdocker-hosted\sbuild. +D 2024-01-11T16:10:22.408 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -575,7 +575,7 @@ F ext/userauth/sqlite3userauth.h 7f3ea8c4686db8e40b0a0e7a8e0b00fac13aa7a3 F ext/userauth/user-auth.txt e6641021a9210364665fe625d067617d03f27b04 F ext/userauth/userauth.c 7f00cded7dcaa5d47f54539b290a43d2e59f4b1eb5f447545fa865f002fc80cb F ext/wasm/EXPORTED_FUNCTIONS.fiddle.in 27450c8b8c70875a260aca55435ec927068b34cef801a96205adb81bdcefc65c -F ext/wasm/GNUmakefile 693ff54a2710751a34ef4419a63eb7ea957f7e730f837fc1ef1dc475bdc5a6c8 +F ext/wasm/GNUmakefile 867c903a27fa0d53a3bf1b01d8c7bb713456f87e0939c3cac9f07faa68f58734 F ext/wasm/README-dist.txt 6382cb9548076fca472fb3330bbdba3a55c1ea0b180ff9253f084f07ff383576 F ext/wasm/README.md a8a2962c3aebdf8d2104a9102e336c5554e78fc6072746e5daf9c61514e7d193 F ext/wasm/SQLTester/GNUmakefile e0794f676d55819951bbfae45cc5e8d7818dc460492dc317ce7f0d2eca15caff @@ -2157,8 +2157,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P bf23cf204976516651b1c4c39ced21cd858dea4ba88052d96fc4f5f11525f170 -R e6ab7f42561dbf7e5d9624bfb9b0bf26 +P c8284170f66374fc528e9d6e5a03ee7321f27e80acf4360701a8b176497b7130 +R acd9470388512134bc217adbff86bef2 U stephan -Z 562f2a1dff86c554fee852503a03b96a +Z ccc05bb973966212e05811d87616f96f # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 27445cc530..68668e9e76 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c8284170f66374fc528e9d6e5a03ee7321f27e80acf4360701a8b176497b7130 \ No newline at end of file +5836657929d7d6d3f0d5865c9f6de4e4c00edd53d15a246802b375fa15d0f255 \ No newline at end of file From 9239fb59ad74b1fee03ea99e86dddf3726dd7bf4 Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 16 Jan 2024 14:54:54 +0000 Subject: [PATCH 009/430] Remove the LLONG_MAX preprocessor macro from the series.c extension as it is apparently only C99 and later. [forum:/forumpost/4af649419b|Forum post 4af649419b]. FossilOrigin-Name: f106bc0d21b7a815f0d23a97b6fd63c54d3f5353e965dfa550fa715e698ec6e3 --- ext/misc/series.c | 18 +++++++++++------- manifest | 17 ++++++++--------- manifest.uuid | 2 +- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/ext/misc/series.c b/ext/misc/series.c index abd6af7ad6..3e859a8f23 100644 --- a/ext/misc/series.c +++ b/ext/misc/series.c @@ -103,16 +103,20 @@ SQLITE_EXTENSION_INIT1 ** index is ix. The 0th member is given by smBase. The sequence members ** progress per ix increment by smStep. */ -static sqlite3_int64 genSeqMember(sqlite3_int64 smBase, - sqlite3_int64 smStep, - sqlite3_uint64 ix){ - if( ix>=(sqlite3_uint64)LLONG_MAX ){ +static sqlite3_int64 genSeqMember( + sqlite3_int64 smBase, + sqlite3_int64 smStep, + sqlite3_uint64 ix +){ + static const sqlite3_uint64 mxI64 = + ((sqlite3_uint64)0x7fffffff)<<32 | 0xffffffff; + if( ix>=mxI64 ){ /* Get ix into signed i64 range. */ - ix -= (sqlite3_uint64)LLONG_MAX; + ix -= mxI64; /* With 2's complement ALU, this next can be 1 step, but is split into * 2 for UBSAN's satisfaction (and hypothetical 1's complement ALUs.) */ - smBase += (LLONG_MAX/2) * smStep; - smBase += (LLONG_MAX - LLONG_MAX/2) * smStep; + smBase += (mxI64/2) * smStep; + smBase += (mxI64 - mxI64/2) * smStep; } /* Under UBSAN (or on 1's complement machines), must do this last term * in steps to avoid the dreaded (and harmless) signed multiply overlow. */ diff --git a/manifest b/manifest index 50904cc140..1dd0a39dcf 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Various\sbuild-\sand\scode-reorg\scleanups\sfor\sext/wasm.\sNo\sfunctional\schanges. -D 2024-01-16T14:24:35.067 +C Remove\sthe\sLLONG_MAX\spreprocessor\smacro\sfrom\sthe\sseries.c\sextension\sas\sit\nis\sapparently\sonly\sC99\sand\slater.\n[forum:/forumpost/4af649419b|Forum\spost\s4af649419b]. +D 2024-01-16T14:54:54.485 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -400,7 +400,7 @@ F ext/misc/regexp.c 4bdd0045912f81c84908bd535ec5ad3b1c8540b4287c70ab840709636240 F ext/misc/remember.c add730f0f7e7436cd15ea3fd6a90fd83c3f706ab44169f7f048438b7d6baa69c F ext/misc/rot13.c 51ac5f51e9d5fd811db58a9c23c628ad5f333c173f1fc53c8491a3603d38556c F ext/misc/scrub.c 2a44b0d44c69584c0580ad2553f6290a307a49df4668941d2812135bfb96a946 -F ext/misc/series.c 80692f675de989629ee20796f75010ce87ca826cb383131040e84f7e1bea5d7a +F ext/misc/series.c 384f93a8a09cf45e1aa6575660cb580ed61d372c590aad05cdcd4a84fbd8f6ab F ext/misc/sha1.c 4011aef176616872b2a0d5bccf0ecfb1f7ce3fe5c3d107f3a8e949d8e1e3f08d F ext/misc/shathree.c 543af7ce71d391cd3a9ab6924a6a1124efc63211fd0f2e240dc4b56077ba88ac F ext/misc/showauth.c 732578f0fe4ce42d577e1c86dc89dd14a006ab52 @@ -599,7 +599,7 @@ F ext/wasm/api/sqlite3-api-prologue.js fffcee629bf020a8ccf5c367fbe6a169f5d5d73df F ext/wasm/api/sqlite3-api-worker1.js 8d9c0562831f62218170a3373468d8a0b7a6503b5985e309b69bf71187b525cf F ext/wasm/api/sqlite3-license-version-header.js 0c807a421f0187e778dc1078f10d2994b915123c1223fe752b60afdcd1263f89 F ext/wasm/api/sqlite3-opfs-async-proxy.js 8cf8a897726f14071fae6be6648125162b256dfb4f96555b865dbb7a6b65e379 -F ext/wasm/api/sqlite3-vfs-helper.c-pp.js 3f828cc66758acb40e9c5b4dcfd87fd478a14c8fb7f0630264e6c7fa0e57515d w ext/wasm/api/sqlite3-v-helper.js +F ext/wasm/api/sqlite3-vfs-helper.c-pp.js 3f828cc66758acb40e9c5b4dcfd87fd478a14c8fb7f0630264e6c7fa0e57515d F ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js 595953994aa3ae2287c889c4da39ab3d6f17b6461ecf4bec334b7a3faafddb02 F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js ebf6c7e997cd8948b35b3afc550b0503dd53febd9d2b56354efd11d985e5f0f2 F ext/wasm/api/sqlite3-vtab-helper.c-pp.js a2fcbc3fecdd0eea229283584ebc122f29d98194083675dbe5cb2cf3a17fe309 @@ -2158,9 +2158,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 1066602b2b1976fe58b5150777cced894af17c803e068f5918390d6915b46e1d 5836657929d7d6d3f0d5865c9f6de4e4c00edd53d15a246802b375fa15d0f255 -R 59b52c4e344f8871547dae1c84cd4afc -T +closed 5836657929d7d6d3f0d5865c9f6de4e4c00edd53d15a246802b375fa15d0f255 Closed\sby\sintegrate-merge. -U stephan -Z 3deb67a608c540b8c97149e595f2800e +P 835bd4a11e56ede378235379604ac01350ee92433f952a23c761f7be492fd475 +R 637840d72f118d7c04eecbf407fe77d2 +U drh +Z 9da67d078ad71f5567c52e74dbe3905e # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index f6272410e1..ea50ef5daa 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -835bd4a11e56ede378235379604ac01350ee92433f952a23c761f7be492fd475 \ No newline at end of file +f106bc0d21b7a815f0d23a97b6fd63c54d3f5353e965dfa550fa715e698ec6e3 \ No newline at end of file From 6ad928d91d06d2738ffa2eecaea07a7477a88781 Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 16 Jan 2024 15:04:19 +0000 Subject: [PATCH 010/430] Clutter the code with "fall-through" comments in order to suppress nuisance compiler warnings. No logic changes. FossilOrigin-Name: 05d2cf5e90d2a6b8e7fbcdb9e12e7c1281db7cfbe212997bd63c8aa66797edda --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/json.c | 1 + src/vdbe.c | 5 +++++ 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 1dd0a39dcf..d9cc4defde 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\sthe\sLLONG_MAX\spreprocessor\smacro\sfrom\sthe\sseries.c\sextension\sas\sit\nis\sapparently\sonly\sC99\sand\slater.\n[forum:/forumpost/4af649419b|Forum\spost\s4af649419b]. -D 2024-01-16T14:54:54.485 +C Clutter\sthe\scode\swith\s"fall-through"\scomments\sin\sorder\sto\ssuppress\snuisance\ncompiler\swarnings.\s\sNo\slogic\schanges. +D 2024-01-16T15:04:19.943 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -698,7 +698,7 @@ F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 F src/insert.c 3f0a94082d978bbdd33c38fefea15346c6c6bffb70bc645a71dc0f1f87dd3276 -F src/json.c 4913fd22c4f0fa30643afb93a4d78d289cd490620e782b31016c3d4b2049b1cc +F src/json.c 624824b0c405dc64bb371107f21baf1d00a6b609cbdb16feaa2338a335bf981b F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 F src/main.c 438b95162acfa17b7d218f586f5bde11d6ae82bcf030c9611fc537556870ad6b @@ -808,7 +808,7 @@ F src/upsert.c fa125a8d3410ce9a97b02cb50f7ae68a2476c405c76aa692d3acf6b8586e9242 F src/utf.c f23165685a67b4caf8ec08fb274cb3f319103decfb2a980b7cfd55d18dfa855e F src/util.c 078f040366d5bd5f47658d045f901c768c1c636c6eaea121f3a1cbd63c3edb5b F src/vacuum.c 604fcdaebe76f3497c855afcbf91b8fa5046b32de3045bab89cc008d68e40104 -F src/vdbe.c 96ac876e57f480bd35ec8d74ed992bca6ae9deebe8b527a3a718e7b4714d6c2e +F src/vdbe.c 4a42916b14548112cb1ee9b9dea3c0ba6c21d08fa0c660cd1561c1871e25908f F src/vdbe.h 88e19a982df9027ec1c177c793d1a5d34dc23d8f06e3b2d997f43688b05ee0eb F src/vdbeInt.h 949669dfd8a41550d27dcb905b494f2ccde9a2e6c1b0b04daa1227e2e74c2b2c F src/vdbeapi.c 8f57d60c89da0b60e6d4e272358c511f6bae4e24330bdb11f8b42f986d1bf21b @@ -2158,8 +2158,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 835bd4a11e56ede378235379604ac01350ee92433f952a23c761f7be492fd475 -R 637840d72f118d7c04eecbf407fe77d2 +P f106bc0d21b7a815f0d23a97b6fd63c54d3f5353e965dfa550fa715e698ec6e3 +R da8805f28e584450d69243ce8bdddb6a U drh -Z 9da67d078ad71f5567c52e74dbe3905e +Z 0ea920a6e11610b2206c6aeee95b6afa # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index ea50ef5daa..3da3587b59 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f106bc0d21b7a815f0d23a97b6fd63c54d3f5353e965dfa550fa715e698ec6e3 \ No newline at end of file +05d2cf5e90d2a6b8e7fbcdb9e12e7c1281db7cfbe212997bd63c8aa66797edda \ No newline at end of file diff --git a/src/json.c b/src/json.c index 682f30597f..97cf5fe28c 100644 --- a/src/json.c +++ b/src/json.c @@ -1911,6 +1911,7 @@ static int jsonTranslateTextToBlob(JsonParse *pParse, u32 i){ return i+4; } /* fall-through into the default case that checks for NaN */ + /* no break */ deliberate_fall_through } default: { u32 k; diff --git a/src/vdbe.c b/src/vdbe.c index 6d45bbbbbd..2ae757b76e 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -3654,11 +3654,16 @@ case OP_MakeRecord: { switch( len ){ default: zPayload[7] = (u8)(v&0xff); v >>= 8; zPayload[6] = (u8)(v&0xff); v >>= 8; + /* no break */ deliberate_fall_through case 6: zPayload[5] = (u8)(v&0xff); v >>= 8; zPayload[4] = (u8)(v&0xff); v >>= 8; + /* no break */ deliberate_fall_through case 4: zPayload[3] = (u8)(v&0xff); v >>= 8; + /* no break */ deliberate_fall_through case 3: zPayload[2] = (u8)(v&0xff); v >>= 8; + /* no break */ deliberate_fall_through case 2: zPayload[1] = (u8)(v&0xff); v >>= 8; + /* no break */ deliberate_fall_through case 1: zPayload[0] = (u8)(v&0xff); } zPayload += len; From 75f9ba32bde3028cc8f6d4e8a86ab89d14e3eaf8 Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 16 Jan 2024 16:05:21 +0000 Subject: [PATCH 011/430] Ensure that the xIntegrity methods of fts3 and fts5 work on read-only databases. FossilOrigin-Name: b855886c4ccce0745af6957943e77be18949722f09821688725d546d3d79b4fb --- ext/fts3/fts3.c | 34 +++++++++++--------------------- ext/fts3/fts3Int.h | 2 ++ ext/fts3/fts3_write.c | 6 +++--- ext/fts5/fts5_main.c | 16 +++++---------- ext/fts5/test/fts5integrity.test | 26 ++++++++++++++++++++++++ manifest | 24 +++++++++++----------- manifest.uuid | 2 +- test/fts4intck1.test | 17 ++++++++++++++++ 8 files changed, 78 insertions(+), 49 deletions(-) diff --git a/ext/fts3/fts3.c b/ext/fts3/fts3.c index 65852804a1..c9d0eb25b1 100644 --- a/ext/fts3/fts3.c +++ b/ext/fts3/fts3.c @@ -4006,7 +4006,7 @@ static int fts3ShadowName(const char *zName){ ** Implementation of the xIntegrity() method on the FTS3/FTS4 virtual ** table. */ -static int fts3Integrity( +static int fts3IntegrityMethod( sqlite3_vtab *pVtab, /* The virtual table to be checked */ const char *zSchema, /* Name of schema in which pVtab lives */ const char *zTabname, /* Name of the pVTab table */ @@ -4014,30 +4014,20 @@ static int fts3Integrity( char **pzErr /* Write error message here */ ){ Fts3Table *p = (Fts3Table*)pVtab; - char *zSql; int rc; - char *zErr = 0; - - assert( pzErr!=0 ); - assert( *pzErr==0 ); - UNUSED_PARAMETER(isQuick); - zSql = sqlite3_mprintf( - "INSERT INTO \"%w\".\"%w\"(\"%w\") VALUES('integrity-check');", - zSchema, zTabname, zTabname); - if( zSql==0 ){ - return SQLITE_NOMEM; - } - rc = sqlite3_exec(p->db, zSql, 0, 0, &zErr); - sqlite3_free(zSql); - if( (rc&0xff)==SQLITE_CORRUPT ){ - *pzErr = sqlite3_mprintf("malformed inverted index for FTS%d table %s.%s", - p->bFts4 ? 4 : 3, zSchema, zTabname); - }else if( rc!=SQLITE_OK ){ + int bOk = 0; + + rc = sqlite3Fts3IntegrityCheck(p, &bOk); + assert( rc!=SQLITE_CORRUPT_VTAB || bOk==0 ); + if( rc!=SQLITE_OK && rc!=SQLITE_CORRUPT_VTAB ){ *pzErr = sqlite3_mprintf("unable to validate the inverted index for" " FTS%d table %s.%s: %s", - p->bFts4 ? 4 : 3, zSchema, zTabname, zErr); + p->bFts4 ? 4 : 3, zSchema, zTabname, sqlite3_errstr(rc)); + }else if( bOk==0 ){ + *pzErr = sqlite3_mprintf("malformed inverted index for FTS%d table %s.%s", + p->bFts4 ? 4 : 3, zSchema, zTabname); } - sqlite3_free(zErr); + sqlite3Fts3SegmentsClose(p); return SQLITE_OK; } @@ -4068,7 +4058,7 @@ static const sqlite3_module fts3Module = { /* xRelease */ fts3ReleaseMethod, /* xRollbackTo */ fts3RollbackToMethod, /* xShadowName */ fts3ShadowName, - /* xIntegrity */ fts3Integrity, + /* xIntegrity */ fts3IntegrityMethod, }; /* diff --git a/ext/fts3/fts3Int.h b/ext/fts3/fts3Int.h index 5a5b123b4c..3b236faf49 100644 --- a/ext/fts3/fts3Int.h +++ b/ext/fts3/fts3Int.h @@ -653,5 +653,7 @@ int sqlite3FtsUnicodeIsdiacritic(int); int sqlite3Fts3ExprIterate(Fts3Expr*, int (*x)(Fts3Expr*,int,void*), void*); +int sqlite3Fts3IntegrityCheck(Fts3Table *p, int *pbOk); + #endif /* !SQLITE_CORE || SQLITE_ENABLE_FTS3 */ #endif /* _FTSINT_H */ diff --git a/ext/fts3/fts3_write.c b/ext/fts3/fts3_write.c index 0f894943dd..2516a39083 100644 --- a/ext/fts3/fts3_write.c +++ b/ext/fts3/fts3_write.c @@ -5294,7 +5294,7 @@ static u64 fts3ChecksumIndex( ** If an error occurs (e.g. an OOM or IO error), return an SQLite error ** code. The final value of *pbOk is undefined in this case. */ -static int fts3IntegrityCheck(Fts3Table *p, int *pbOk){ +int sqlite3Fts3IntegrityCheck(Fts3Table *p, int *pbOk){ int rc = SQLITE_OK; /* Return code */ u64 cksum1 = 0; /* Checksum based on FTS index contents */ u64 cksum2 = 0; /* Checksum based on %_content contents */ @@ -5372,7 +5372,7 @@ static int fts3IntegrityCheck(Fts3Table *p, int *pbOk){ sqlite3_finalize(pStmt); } - *pbOk = (cksum1==cksum2); + *pbOk = (rc==SQLITE_OK && cksum1==cksum2); return rc; } @@ -5412,7 +5412,7 @@ static int fts3DoIntegrityCheck( ){ int rc; int bOk = 0; - rc = fts3IntegrityCheck(p, &bOk); + rc = sqlite3Fts3IntegrityCheck(p, &bOk); if( rc==SQLITE_OK && bOk==0 ) rc = FTS_CORRUPT_VTAB; return rc; } diff --git a/ext/fts5/fts5_main.c b/ext/fts5/fts5_main.c index eb7ee74087..7c818ce747 100644 --- a/ext/fts5/fts5_main.c +++ b/ext/fts5/fts5_main.c @@ -2971,27 +2971,21 @@ static int fts5IntegrityMethod( char **pzErr /* Write error message here */ ){ Fts5FullTable *pTab = (Fts5FullTable*)pVtab; - Fts5Config *pConfig = pTab->p.pConfig; - char *zSql; - char *zErr = 0; int rc; + assert( pzErr!=0 && *pzErr==0 ); UNUSED_PARAM(isQuick); - zSql = sqlite3_mprintf( - "INSERT INTO \"%w\".\"%w\"(\"%w\") VALUES('integrity-check');", - zSchema, zTabname, pConfig->zName); - if( zSql==0 ) return SQLITE_NOMEM; - rc = sqlite3_exec(pConfig->db, zSql, 0, 0, &zErr); - sqlite3_free(zSql); + rc = sqlite3Fts5StorageIntegrity(pTab->pStorage, 0); if( (rc&0xff)==SQLITE_CORRUPT ){ *pzErr = sqlite3_mprintf("malformed inverted index for FTS5 table %s.%s", zSchema, zTabname); }else if( rc!=SQLITE_OK ){ *pzErr = sqlite3_mprintf("unable to validate the inverted index for" " FTS5 table %s.%s: %s", - zSchema, zTabname, zErr); + zSchema, zTabname, sqlite3_errstr(rc)); } - sqlite3_free(zErr); + sqlite3Fts5IndexCloseReader(pTab->p.pIndex); + return SQLITE_OK; } diff --git a/ext/fts5/test/fts5integrity.test b/ext/fts5/test/fts5integrity.test index f9851dc15a..1bb367538d 100644 --- a/ext/fts5/test/fts5integrity.test +++ b/ext/fts5/test/fts5integrity.test @@ -355,4 +355,30 @@ do_execsql_test 11.4 { PRAGMA integrity_check(t2); } {ok} +#------------------------------------------------------------------- +reset_db + +do_execsql_test 12.1 { + CREATE VIRTUAL TABLE x1 USING fts5(a, b); + INSERT INTO x1 VALUES('one', 'two'); + INSERT INTO x1 VALUES('three', 'four'); + INSERT INTO x1 VALUES('five', 'six'); +} + +do_execsql_test 12.2 { + PRAGMA integrity_check +} {ok} + +db close +sqlite3 db test.db -readonly 1 + +explain_i { + PRAGMA integrity_check + } +do_execsql_test 12.3 { + PRAGMA integrity_check +} {ok} + + + finish_test diff --git a/manifest b/manifest index d9cc4defde..ee8f95c4c3 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Clutter\sthe\scode\swith\s"fall-through"\scomments\sin\sorder\sto\ssuppress\snuisance\ncompiler\swarnings.\s\sNo\slogic\schanges. -D 2024-01-16T15:04:19.943 +C Ensure\sthat\sthe\sxIntegrity\smethods\sof\sfts3\sand\sfts5\swork\son\sread-only\sdatabases. +D 2024-01-16T16:05:21.776 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -63,9 +63,9 @@ F ext/fts3/README.content b9078d0843a094d86af0d48dffbff13c906702b4c3558012e67b9c F ext/fts3/README.syntax a19711dc5458c20734b8e485e75fb1981ec2427a F ext/fts3/README.tokenizers b92bdeb8b46503f0dd301d364efc5ef59ef9fa8e2758b8e742f39fa93a2e422d F ext/fts3/README.txt 8c18f41574404623b76917b9da66fcb0ab38328d -F ext/fts3/fts3.c d01dfb641fc04efeeadcb94d7a8342eb07d71c1a3a3852ec8ab5e64c1fcdfff9 +F ext/fts3/fts3.c 16366d9e422be6022255fcb6bb2838387a0fe0a6afb12d14e21fe8f74386ab6a F ext/fts3/fts3.h 3a10a0af180d502cecc50df77b1b22df142817fe -F ext/fts3/fts3Int.h be688580701d41340de73384e3acc8c55be12a438583207444bd5e20f9ef426c +F ext/fts3/fts3Int.h 968f7d7cae541a6926146e9fd3fb2b2ccbd3845b7890a8ed03de0c06ac776682 F ext/fts3/fts3_aux.c 7eab82a9cf0830f6551ba3abfdbe73ed39e322a4d3940ee82fbf723674ecd9f3 F ext/fts3/fts3_expr.c 903bfb9433109fffb10e910d7066c49cbf8eeae316adc93f0499c4da7dfc932a F ext/fts3/fts3_hash.c 8b6e31bfb0844c27dc6092c2620bdb1fca17ed613072db057d96952c6bdb48b7 @@ -81,7 +81,7 @@ F ext/fts3/fts3_tokenizer.h 64c6ef6c5272c51ebe60fc607a896e84288fcbc3 F ext/fts3/fts3_tokenizer1.c c1de4ae28356ad98ccb8b2e3388a7fdcce7607b5523738c9afb6275dab765154 F ext/fts3/fts3_unicode.c de426ff05c1c2e7bce161cf6b706638419c3a1d9c2667de9cb9dc0458c18e226 F ext/fts3/fts3_unicode2.c 416eb7e1e81142703520d284b768ca2751d40e31fa912cae24ba74860532bf0f -F ext/fts3/fts3_write.c 5bb4721330ca589f906e72bb824dd4080b313c6d4c4231fa541e9db32dc67982 +F ext/fts3/fts3_write.c c2d7a8dfb6e7a00c6c88ce626785cf4c50ed18eba34b5fbd53cacd60af96d0f2 F ext/fts3/fts3speed.tcl b54caf6a18d38174f1a6e84219950d85e98bb1e9 F ext/fts3/tool/fts3cov.sh c331d006359456cf6f8f953e37f2b9c7d568f3863f00bb5f7eb87fea4ac01b73 F ext/fts3/tool/fts3view.c 413c346399159df81f86c4928b7c4a455caab73bfbc8cd68f950f632e5751674 @@ -98,7 +98,7 @@ F ext/fts5/fts5_config.c 8072a207034b51ae9b7694121d1b5715c794e94b275e088f70ae532 F ext/fts5/fts5_expr.c e91156ebdcc08d837f4f324168f69f3c0d7fdef0e521fd561efb48ef3297b696 F ext/fts5/fts5_hash.c adda4272be401566a6e0ba1acbe70ee5cb97fce944bc2e04dc707152a0ec91b1 F ext/fts5/fts5_index.c bb1965c3965f6fe5f64160bf1c0694a9684a790a783f293a76da1d38d319b258 -F ext/fts5/fts5_main.c 94a03dd431022d706290bb81b7f2180a0bb7c98f1397b5fbc90e18d3ed8d366c +F ext/fts5/fts5_main.c cd56ed9619e9bc55ae603ecafd5965c3684bb4c1de7dd00893c307ddf98afe88 F ext/fts5/fts5_storage.c f9e31b0d155e9b2c92d5d3a09ad7a56b937fbf1c7f962e10f4ca6281349f3934 F ext/fts5/fts5_tcl.c cf0fd0dbe64ec272491b749e0d594f563cda03336aeb60900129e6d18b0aefb8 F ext/fts5/fts5_test_mi.c 08c11ec968148d4cb4119d96d819f8c1f329812c568bac3684f5464be177d3ee @@ -176,7 +176,7 @@ F ext/fts5/test/fts5first.test 3fcf2365c00a15fc9704233674789a3b95131d12de18a9b99 F ext/fts5/test/fts5full.test e1701a112354e0ff9a1fdffb0c940c576530c33732ee20ac5e8361777070d717 F ext/fts5/test/fts5fuzz1.test 238d8c45f3b81342aa384de3e581ff2fa330bf922a7b69e484bbc06051a1080e F ext/fts5/test/fts5hash.test dc7bc7e0cdeb42cfce31294ad2f8fcf43192bfd0145bb7f3ecc5465d8c72696f -F ext/fts5/test/fts5integrity.test 0d249d351163e17e2227aa9850e68193f88a7813d16cc7d51287e554bf915b3d +F ext/fts5/test/fts5integrity.test f1723fe9fb9381b26c946ab4d7505041434df2c449d1cd53f45c7bf8c098dfa2 F ext/fts5/test/fts5interrupt.test 09613247b273a99889808ef852898177e671406fe71fdde7ea00e78ea283d227 F ext/fts5/test/fts5lastrowid.test be98fe3e03235296585b72daad7aed5717ba0062bae5e5c18dd6e04e194c6b28 F ext/fts5/test/fts5leftjoin.test c0b4cafb9661379e576dc4405c0891d8fcc2782680740513c4d1fc114b43d4ad @@ -1198,7 +1198,7 @@ F test/fts4docid.test e33c383cfbdff0284685604d256f347a18fdbf01 F test/fts4growth.test 289833c34ad45a5e6e6133b53b6a71647231fb89d36ddcb8d9c87211b6721d7f F test/fts4growth2.test 13ad4e76451af6e6906c95cdc725d01b00044269 F test/fts4incr.test 4e353a0bd886ea984e56fce9e77724fc923b8d0d -F test/fts4intck1.test 43774c641fdf6607c6ee90c3db8af065a37434d55d6eaf13bafe515e8b0c5729 +F test/fts4intck1.test 54e7f28e34b72fb0c614d414bb1f568154d463c5a00b20944e893df858372ed4 F test/fts4langid.test 4be912f42454998e239a2e877600263e0394afbaba03e06cedcc5a08693a345a F test/fts4lastrowid.test 185835895948d5325c7710649824042373b2203149abe8024a9319d25234dfd7 F test/fts4merge.test 57d093660a5093ae6e9fbd2d17592a88b45bbd66db2703c4b640b28828dbe38b @@ -2158,8 +2158,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P f106bc0d21b7a815f0d23a97b6fd63c54d3f5353e965dfa550fa715e698ec6e3 -R da8805f28e584450d69243ce8bdddb6a -U drh -Z 0ea920a6e11610b2206c6aeee95b6afa +P 05d2cf5e90d2a6b8e7fbcdb9e12e7c1281db7cfbe212997bd63c8aa66797edda +R 5cbf3bdeb8af5f75cdbf0493086676ae +U dan +Z 2db4aae4a26f0f9cf09b997cf1ada5be # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 3da3587b59..c922e4e7bf 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -05d2cf5e90d2a6b8e7fbcdb9e12e7c1281db7cfbe212997bd63c8aa66797edda \ No newline at end of file +b855886c4ccce0745af6957943e77be18949722f09821688725d546d3d79b4fb \ No newline at end of file diff --git a/test/fts4intck1.test b/test/fts4intck1.test index abdc46bf52..6596b2f997 100644 --- a/test/fts4intck1.test +++ b/test/fts4intck1.test @@ -54,5 +54,22 @@ do_execsql_test 2.3 { PRAGMA integrity_check(t2); } {{malformed inverted index for FTS4 table main.t2}} +#------------------------------------------------------------------------- +# Test that integrity-check works on a read-only database. +# +reset_db +do_execsql_test 3.0 { + CREATE VIRTUAL TABLE x1 USING fts4(a, b); + INSERT INTO x1 VALUES('one', 'two'); + INSERT INTO x1 VALUES('three', 'four'); +} +db close +sqlite3 db test.db -readonly 1 + +do_execsql_test 3.1 { + PRAGMA integrity_check; +} {ok} + + finish_test From 31ebe65b5ebe20a1871f3a27fa07ce24deca6b8e Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 16 Jan 2024 16:14:52 +0000 Subject: [PATCH 012/430] Fix harmless "unused parameter" compiler warning in the new fts3IntegrityMethod implementation. FossilOrigin-Name: bb1fe53a97672fc868e3f3897162ea0d714dc1da95187f9c7e35255049f2b0e7 --- ext/fts3/fts3.c | 1 + manifest | 14 +++++++------- manifest.uuid | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/ext/fts3/fts3.c b/ext/fts3/fts3.c index c9d0eb25b1..379590188d 100644 --- a/ext/fts3/fts3.c +++ b/ext/fts3/fts3.c @@ -4017,6 +4017,7 @@ static int fts3IntegrityMethod( int rc; int bOk = 0; + UNUSED_PARAMETER(isQuick); rc = sqlite3Fts3IntegrityCheck(p, &bOk); assert( rc!=SQLITE_CORRUPT_VTAB || bOk==0 ); if( rc!=SQLITE_OK && rc!=SQLITE_CORRUPT_VTAB ){ diff --git a/manifest b/manifest index ee8f95c4c3..b0ad7329f9 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Ensure\sthat\sthe\sxIntegrity\smethods\sof\sfts3\sand\sfts5\swork\son\sread-only\sdatabases. -D 2024-01-16T16:05:21.776 +C Fix\sharmless\s"unused\sparameter"\scompiler\swarning\sin\sthe\snew\sfts3IntegrityMethod\nimplementation. +D 2024-01-16T16:14:52.891 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -63,7 +63,7 @@ F ext/fts3/README.content b9078d0843a094d86af0d48dffbff13c906702b4c3558012e67b9c F ext/fts3/README.syntax a19711dc5458c20734b8e485e75fb1981ec2427a F ext/fts3/README.tokenizers b92bdeb8b46503f0dd301d364efc5ef59ef9fa8e2758b8e742f39fa93a2e422d F ext/fts3/README.txt 8c18f41574404623b76917b9da66fcb0ab38328d -F ext/fts3/fts3.c 16366d9e422be6022255fcb6bb2838387a0fe0a6afb12d14e21fe8f74386ab6a +F ext/fts3/fts3.c fd64a588471ce00b19da08acb0d6f904277a21ac1d15141d5913c83591afa027 F ext/fts3/fts3.h 3a10a0af180d502cecc50df77b1b22df142817fe F ext/fts3/fts3Int.h 968f7d7cae541a6926146e9fd3fb2b2ccbd3845b7890a8ed03de0c06ac776682 F ext/fts3/fts3_aux.c 7eab82a9cf0830f6551ba3abfdbe73ed39e322a4d3940ee82fbf723674ecd9f3 @@ -2158,8 +2158,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 05d2cf5e90d2a6b8e7fbcdb9e12e7c1281db7cfbe212997bd63c8aa66797edda -R 5cbf3bdeb8af5f75cdbf0493086676ae -U dan -Z 2db4aae4a26f0f9cf09b997cf1ada5be +P b855886c4ccce0745af6957943e77be18949722f09821688725d546d3d79b4fb +R e3234ce42cab7cdbc84f346ed1a36dc2 +U drh +Z 29787cb80c2a8f6910db50466343041a # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index c922e4e7bf..d671591dbf 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b855886c4ccce0745af6957943e77be18949722f09821688725d546d3d79b4fb \ No newline at end of file +bb1fe53a97672fc868e3f3897162ea0d714dc1da95187f9c7e35255049f2b0e7 \ No newline at end of file From d0603eda6cc64497cfb811a4538e8f24b4a373c4 Mon Sep 17 00:00:00 2001 From: drh <> Date: Thu, 18 Jan 2024 16:50:25 +0000 Subject: [PATCH 013/430] Add support in the strftime() SQL function for conversion letters %G, %g, %U, and %V. FossilOrigin-Name: e1155d6aa4b960ecfd14fa3467f28672af3327699c547f5b9e75da3ac1348ff7 --- manifest | 16 +++--- manifest.uuid | 2 +- src/date.c | 146 ++++++++++++++++++++++++++++++++++++++++-------- test/date.test | 4 +- test/date4.test | 2 +- 5 files changed, 134 insertions(+), 36 deletions(-) diff --git a/manifest b/manifest index b0ad7329f9..2ef2bf10a8 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sharmless\s"unused\sparameter"\scompiler\swarning\sin\sthe\snew\sfts3IntegrityMethod\nimplementation. -D 2024-01-16T16:14:52.891 +C Add\ssupport\sin\sthe\sstrftime()\sSQL\sfunction\sfor\sconversion\sletters\s%G,\s%g,\n%U,\sand\s%V. +D 2024-01-18T16:50:25.492 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -684,7 +684,7 @@ F src/build.c e7d9044592eeeea8e78d8ae53ca8d31fd6e92ca0d4f53e2f2e8ccf7352e0b04b F src/callback.c db3a45e376deff6a16c0058163fe0ae2b73a2945f3f408ca32cf74960b28d490 F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e F src/ctime.c 23331529e654be40ca97d171cbbffe9b3d4c71cc53b78fe5501230675952da8b -F src/date.c 3b8d02977d160e128469de38493b4085f7c5cf4073193459909a6af3cf6d7c91 +F src/date.c 7ed194fee09bc3aa2129cfe74ebf5daca6fc24c0995dd28cf2a2feacf4d8d44f F src/dbpage.c 80e46e1df623ec40486da7a5086cb723b0275a6e2a7b01d9f9b5da0f04ba2782 F src/dbstat.c 3b677254d512fcafd4d0b341bf267b38b235ccfddbef24f9154e19360fa22e43 F src/delete.c cb766727c78e715f9fb7ec8a7d03658ed2a3016343ca687acfcec9083cdca500 @@ -1030,10 +1030,10 @@ F test/ctime.test 340f362f41f92972bbd71f44e10569a5cc694062b692231bd08aa6fe6c1c47 F test/cursorhint.test 05cf0febe5c5f8a31f199401fd1c9322249e753950d55f26f9d5aca61408a270 F test/cursorhint2.test 6f3aa9cb19e7418967a10ec6905209bcbb5968054da855fc36c8beee9ae9c42f F test/dataversion1.test 6e5e86ac681f0782e766ebcb56c019ae001522d114e0e111e5ebf68ccf2a7bb8 -F test/date.test ff2341a1ef71b9a27979494d299222f9a293aa22cb9ff6e9c38d88a895317ebf +F test/date.test b1a5208e6a9c390cf1d1fa4e38a910386b427b0e27046901c6b0fb995d19800e F test/date2.test 7e12ec14aaf4d5e6294b4ba140445b0eca06ea50062a9c3a69c4ee13d0b6f8b1 F test/date3.test a1b77abf05c6772fe5ca2337cac1398892f2a41e62bce7e6be0f4a08a0e64ae5 -F test/date4.test 8aeb3de5b5e9fda968baa9357e4c0fae573724b7904943410195a19e96e31b6a +F test/date4.test 77b3781c28d3a5e181c6474315aa58e1f6cf79f5171a4e46e248837b506e7adf F test/dbdata.test 042f49acff3438f940eeba5868d3af080ae64ddf26ae78f80c92bec3ca7d8603 F test/dbfuzz.c 73047c920d6210e5912c87cdffd9a1c281d4252e F test/dbfuzz001.test 6c9a4622029d69dc38926f115864b055cb2f39badd25ec22cbfb130c8ba8e9c3 @@ -2158,8 +2158,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P b855886c4ccce0745af6957943e77be18949722f09821688725d546d3d79b4fb -R e3234ce42cab7cdbc84f346ed1a36dc2 +P bb1fe53a97672fc868e3f3897162ea0d714dc1da95187f9c7e35255049f2b0e7 +R 600b04759487eea2e950d6a6bdd54077 U drh -Z 29787cb80c2a8f6910db50466343041a +Z fe80399e6509893ac8c8ba9e1f44bd65 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index d671591dbf..e751fb38dc 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -bb1fe53a97672fc868e3f3897162ea0d714dc1da95187f9c7e35255049f2b0e7 \ No newline at end of file +e1155d6aa4b960ecfd14fa3467f28672af3327699c547f5b9e75da3ac1348ff7 \ No newline at end of file diff --git a/src/date.c b/src/date.c index e493542db9..059d4c88a6 100644 --- a/src/date.c +++ b/src/date.c @@ -1236,22 +1236,98 @@ static void dateFunc( } } +/* +** Compute the one-based day of the year for the DateTime pDate. +** Jan01 = 1, Jan02 = 2, ... Dec31 = 356 or 366. +*/ +static int dayOfYear(DateTime *pDate){ + DateTime jan01 = *pDate; + assert( jan01.validYMD ); + assert( jan01.validHMS ); + assert( pDate->validJD ); + jan01.validJD = 0; + jan01.M = 1; + jan01.D = 1; + computeJD(&jan01); + return (int)((pDate->iJD-jan01.iJD+45300000)/86400000) + 1; +} + +/* +** Return the day of the week. 1==Monday, 2=Tues, ..., 7=Sunday. +*/ +static int dayOfWeek(DateTime *pDate){ + int w; + assert( pDate->validJD ); + w = ((pDate->iJD+129600000)/86400000) % 7; + if( w==0 ) w = 7; + return w; +} + +/* +** Compute the day-of-week (0=Sunday, 1=Monday, ..., 6=Saturday) for +** the last day of the calendar year Y. +*/ +static int lastDayOfYear(int Y){ + return (Y + (Y/4) - (Y/100) + (Y/400))%7; +} + +/* +** Return the number of ISO weeks in calendar year Y. The answer is +** either 52 or 53. +*/ +static int weeksInYear(int Y){ + if( lastDayOfYear(Y)==4 || lastDayOfYear(Y-1)==3 ){ + return 53; + }else{ + return 52; + } +} + +/* +** Compute the number days since the start of the ISO-week year for pDate. +** The ISO-week year starts on the first day of the week (always a Monday) +** that contains the first Thursday on or after January 1. +*/ +static int isoWeekNumber(DateTime *pDate){ + int wn = (10 + dayOfYear(pDate) - dayOfWeek(pDate))/7; + if( wn<1 ){ + wn = weeksInYear(pDate->Y-1); + }else if( wn>weeksInYear(pDate->Y) ){ + wn = 1; + } + return wn; +} + /* ** strftime( FORMAT, TIMESTRING, MOD, MOD, ...) ** ** Return a string described by FORMAT. Conversions as follows: ** -** %d day of month +** %d day of month 01-31 +** %e day of month 1-31 ** %f ** fractional seconds SS.SSS +** %F ISO date. YYYY-MM-DD +** %G ISO year corresponding to %V 0000-9999. +** %g 2-digit ISO year corresponding to %V 00-99 ** %H hour 00-24 -** %j day of year 000-366 +** %k hour 0-24 (leading zero converted to space) +** %I hour 01-12 +** %j day of year 001-366 ** %J ** julian day number +** %l hour 1-12 (leading zero converted to space) ** %m month 01-12 ** %M minute 00-59 +** %p "am" or "pm" +** %P "AM" or "PM" +** %R time as HH:MM ** %s seconds since 1970-01-01 ** %S seconds 00-59 -** %w day of week 0-6 Sunday==0 -** %W week of year 00-53 +** %T time as HH:MM:SS +** %u day of week 1-7 Monday==1, Sunday==7 +** %w day of week 0-6 Sunday==0, Monday==1 +** %U week of year 00-53 (First Sunday is start of week 01) +** %V week of year 01-53 (First week containing Thursday is week 01) +** %W week of year 00-53 (First Monday is start of week 01) ** %Y year 0000-9999 ** %% % */ @@ -1288,7 +1364,7 @@ static void strftimeFunc( sqlite3_str_appendf(&sRes, cf=='d' ? "%02d" : "%2d", x.D); break; } - case 'f': { + case 'f': { /* Fractional seconds. (Non-standard) */ double s = x.s; if( s>59.999 ) s = 59.999; sqlite3_str_appendf(&sRes, "%06.3f", s); @@ -1298,6 +1374,21 @@ static void strftimeFunc( sqlite3_str_appendf(&sRes, "%04d-%02d-%02d", x.Y, x.M, x.D); break; } + case 'G': /* Fall thru */ + case 'g': { + int Y = x.Y; + if( x.M==12 && isoWeekNumber(&x)==1 ){ + Y++; + }else if( x.M==1 && isoWeekNumber(&x)>=52 ){ + Y--; + } + if( cf=='g' ){ + sqlite3_str_appendf(&sRes, "%02d", Y%100); + }else{ + sqlite3_str_appendf(&sRes, "%04d", Y); + } + break; + } case 'H': case 'k': { sqlite3_str_appendf(&sRes, cf=='H' ? "%02d" : "%2d", x.h); @@ -1311,25 +1402,12 @@ static void strftimeFunc( sqlite3_str_appendf(&sRes, cf=='I' ? "%02d" : "%2d", h); break; } - case 'W': /* Fall thru */ - case 'j': { - int nDay; /* Number of days since 1st day of year */ - DateTime y = x; - y.validJD = 0; - y.M = 1; - y.D = 1; - computeJD(&y); - nDay = (int)((x.iJD-y.iJD+43200000)/86400000); - if( cf=='W' ){ - int wd; /* 0=Monday, 1=Tuesday, ... 6=Sunday */ - wd = (int)(((x.iJD+43200000)/86400000)%7); - sqlite3_str_appendf(&sRes,"%02d",(nDay+7-wd)/7); - }else{ - sqlite3_str_appendf(&sRes,"%03d",nDay+1); - } + case 'j': { /* Day of year. Jan01==1, Jan02==2, and so forth */ + int nDay = dayOfYear(&x); + sqlite3_str_appendf(&sRes,"%03d",nDay); break; } - case 'J': { + case 'J': { /* Julian day number. (Non-standard) */ sqlite3_str_appendf(&sRes,"%.16g",x.iJD/86400000.0); break; } @@ -1372,13 +1450,33 @@ static void strftimeFunc( sqlite3_str_appendf(&sRes,"%02d:%02d:%02d", x.h, x.m, (int)x.s); break; } - case 'u': /* Fall thru */ - case 'w': { + case 'u': /* Day of week. 1 to 7. Monday==1, Sunday==7 */ + case 'w': { /* Day of week. 0 to 6. Sunday==0, Monday==1 */ char c = (char)(((x.iJD+129600000)/86400000) % 7) + '0'; if( c=='0' && cf=='u' ) c = '7'; sqlite3_str_appendchar(&sRes, 1, c); break; } + case 'U': { /* Week num. 00-53. First Sun of the year is week 01 */ + int wd; /* 0=Sunday, 1=Monday, 2=Tuesday, ... 7=Saturday */ + int nDay; /* Day of the year. 0..364 or 0..365 for leapyears */ + nDay = dayOfYear(&x); + wd = (int)(((x.iJD+43200000)/86400000 + 1)%7); + sqlite3_str_appendf(&sRes,"%02d",(nDay+6-wd)/7); + break; + } + case 'V': { /* Week num. 01-53. First week with a Thur is week 01 */ + sqlite3_str_appendf(&sRes,"%02d", isoWeekNumber(&x)); + break; + } + case 'W': { /* Week num. 00-53. First Mon of the year is week 01 */ + int wd; /* 0=Monday, 1=Tuesday, ... 6=Sunday */ + int nDay; /* Day of the year. 0..364 or 0..365 for leapyears */ + nDay = dayOfYear(&x); + wd = (int)(((x.iJD+43200000)/86400000)%7); + sqlite3_str_appendf(&sRes,"%02d",(nDay+6-wd)/7); + break; + } case 'Y': { sqlite3_str_appendf(&sRes,"%04d",x.Y); break; diff --git a/test/date.test b/test/date.test index 19cecc2db3..d536c65fce 100644 --- a/test/date.test +++ b/test/date.test @@ -209,8 +209,8 @@ datetest 3.16 "strftime('[repeat 200 %Y]','2003-10-31')" [repeat 200 2003] datetest 3.17 "strftime('[repeat 200 abc%m123]','2003-10-31')" \ [repeat 200 abc10123] -foreach c {a b c g h i n o q r t v x y z - A B C D E G K L N O Q V Z +foreach c {a b c h i n o q r t v x y z + A B C D E K L N O Q Z 0 1 2 3 4 5 6 6 7 9 _} { datetest 3.18.$c "strftime('%$c','2003-10-31')" NULL } diff --git a/test/date4.test b/test/date4.test index 0d820a0a40..0dd06debb7 100644 --- a/test/date4.test +++ b/test/date4.test @@ -24,7 +24,7 @@ ifcapable {!datetime} { } if {$tcl_platform(os)=="Linux"} { - set FMT {%d,%e,%F,%H,%k,%I,%l,%j,%m,%M,%u,%w,%W,%Y,%%,%P,%p} + set FMT {%d,%e,%F,%H,%k,%I,%l,%j,%m,%M,%u,%w,%W,%Y,%%,%P,%p,%U,%V,%G,%g} } else { set FMT {%d,%e,%F,%H,%I,%j,%p,%R,%u,%w,%W,%%} } From 0a626b2b52b58137e00b3d7c25a1a4047fc12d51 Mon Sep 17 00:00:00 2001 From: drh <> Date: Thu, 18 Jan 2024 16:52:11 +0000 Subject: [PATCH 014/430] Increase the version number to 3.46.0 to begin the next development cycle. FossilOrigin-Name: 1481baf3d55effcc117f2097e2d49a6f60f5f74b21190c3be943fd785b8a4c5b --- VERSION | 2 +- configure | 18 +++++++++--------- manifest | 14 +++++++------- manifest.uuid | 2 +- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/VERSION b/VERSION index ff3ff28f6b..850ac8f28c 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.45.0 +3.46.0 diff --git a/configure b/configure index 6a47c4dcc8..f6717f96fb 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for sqlite 3.45.0. +# Generated by GNU Autoconf 2.69 for sqlite 3.46.0. # # # Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc. @@ -726,8 +726,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='sqlite' PACKAGE_TARNAME='sqlite' -PACKAGE_VERSION='3.45.0' -PACKAGE_STRING='sqlite 3.45.0' +PACKAGE_VERSION='3.46.0' +PACKAGE_STRING='sqlite 3.46.0' PACKAGE_BUGREPORT='' PACKAGE_URL='' @@ -1472,7 +1472,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures sqlite 3.45.0 to adapt to many kinds of systems. +\`configure' configures sqlite 3.46.0 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1537,7 +1537,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of sqlite 3.45.0:";; + short | recursive ) echo "Configuration of sqlite 3.46.0:";; esac cat <<\_ACEOF @@ -1668,7 +1668,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -sqlite configure 3.45.0 +sqlite configure 3.46.0 generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. @@ -2087,7 +2087,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by sqlite $as_me 3.45.0, which was +It was created by sqlite $as_me 3.46.0, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ @@ -12481,7 +12481,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by sqlite $as_me 3.45.0, which was +This file was extended by sqlite $as_me 3.46.0, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -12547,7 +12547,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -sqlite config.status 3.45.0 +sqlite config.status 3.46.0 configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" diff --git a/manifest b/manifest index 2ef2bf10a8..2d1eb4053d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\ssupport\sin\sthe\sstrftime()\sSQL\sfunction\sfor\sconversion\sletters\s%G,\s%g,\n%U,\sand\s%V. -D 2024-01-18T16:50:25.492 +C Increase\sthe\sversion\snumber\sto\s3.46.0\sto\sbegin\sthe\snext\sdevelopment\scycle. +D 2024-01-18T16:52:11.788 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -7,7 +7,7 @@ F Makefile.in 24be65ae641c5727bbc247d60286a15ecc24fb80f14f8fb2d32533bf0ec96e79 F Makefile.linux-gcc f3842a0b1efbfbb74ac0ef60e56b301836d05b4d867d014f714fa750048f1ab6 F Makefile.msc df56c06ef05add5ebcdcc9d4823fb2ec66ac16b06acb6971a7420859025886fa F README.md 6358805260a03ebead84e168bbf3740ddf3f683b477e478567186aa7afb490d3 -F VERSION 73573d4545343f001bf5dc5461173a7c78c203dd046cabcf99153878cf25d3a6 +F VERSION c84541c6a9e8426462176fbb1f9ecb5cfd7d1bb56228053ff7eeba8841673eb6 F aclocal.m4 a5c22d164aff7ed549d53a90fa56d56955281f50 F art/sqlite370.eps aa97a671332b432a54e1d74ff5e8775be34200c2 F art/sqlite370.ico af56c1d00fee7cd4753e8631ed60703ed0fc6e90 @@ -33,7 +33,7 @@ F autoconf/tea/win/nmakehlp.c b01f822eabbe1ed2b64e70882d97d48402b42d2689a1ea0034 F autoconf/tea/win/rules.vc c511f222b80064096b705dbeb97060ee1d6b6d63 F config.guess 883205ddf25b46f10c181818bf42c09da9888884af96f79e1719264345053bd6 F config.sub c2d0260f17f3e4bc0b6808fccf1b291cb5e9126c14fc5890efc77b9fd0175559 -F configure bcb1042e92775424a1021d2f4c89c78a699a6225df01fa8c593df7df0be6ad10 x +F configure 40f7af9ed5ca0d44a4b9bc7ad34f1ee4867bb4eeb19e75036be6bed66193a498 x F configure.ac f25bd7843120f2c2b8bc9db5a92b0502bbdd28e68907415c3d42fc8e57c657b9 F contrib/sqlitecon.tcl 210a913ad63f9f991070821e599d600bd913e0ad F doc/F2FS.txt c1d4a0ae9711cfe0e1d8b019d154f1c29e0d3abfe820787ba1e9ed7691160fcd @@ -2158,8 +2158,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P bb1fe53a97672fc868e3f3897162ea0d714dc1da95187f9c7e35255049f2b0e7 -R 600b04759487eea2e950d6a6bdd54077 +P e1155d6aa4b960ecfd14fa3467f28672af3327699c547f5b9e75da3ac1348ff7 +R 9689bd329de0e140711926288014ba0a U drh -Z fe80399e6509893ac8c8ba9e1f44bd65 +Z 0a03ba584bfec4968cbf95a431d1a244 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index e751fb38dc..04b005239f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e1155d6aa4b960ecfd14fa3467f28672af3327699c547f5b9e75da3ac1348ff7 \ No newline at end of file +1481baf3d55effcc117f2097e2d49a6f60f5f74b21190c3be943fd785b8a4c5b \ No newline at end of file From a4802720a1fe1d51c4e35a2e85c8c09ade420a93 Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 19 Jan 2024 16:51:34 +0000 Subject: [PATCH 015/430] Allow large hexadecimal literals to be used as DEFAULT values. FossilOrigin-Name: 8cccc1f27d7470d3cdd3c9c6d74f6a5ac49ec6eaa7002bcf96f4842fb8c79e1a --- manifest | 15 ++++++++------- manifest.uuid | 2 +- src/vdbemem.c | 33 ++++++++++++++++++++++----------- test/literal.test | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 78 insertions(+), 19 deletions(-) create mode 100644 test/literal.test diff --git a/manifest b/manifest index 2d1eb4053d..149c0f4a50 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Increase\sthe\sversion\snumber\sto\s3.46.0\sto\sbegin\sthe\snext\sdevelopment\scycle. -D 2024-01-18T16:52:11.788 +C Allow\slarge\shexadecimal\sliterals\sto\sbe\sused\sas\sDEFAULT\svalues. +D 2024-01-19T16:51:34.042 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -814,7 +814,7 @@ F src/vdbeInt.h 949669dfd8a41550d27dcb905b494f2ccde9a2e6c1b0b04daa1227e2e74c2b2c F src/vdbeapi.c 8f57d60c89da0b60e6d4e272358c511f6bae4e24330bdb11f8b42f986d1bf21b F src/vdbeaux.c c5a471b34e9c4cfc0295a3e10734fd197670ffaebcb742f284c8e17e8026ceea F src/vdbeblob.c 13f9287b55b6356b4b1845410382d6bede203ceb29ef69388a4a3d007ffacbe5 -F src/vdbemem.c 0012d5f01cc866833847c2f3ae4c318ac53a1cb3d28acad9c35e688039464cf0 +F src/vdbemem.c bbe87b3e851bcc5cad2a9329ad0387432e41ddf2f98f2682c524ad676b739987 F src/vdbesort.c 237840ca1947511fa59bd4e18b9eeae93f2af2468c34d2427b059f896230a547 F src/vdbetrace.c fe0bc29ebd4e02c8bc5c1945f1d2e6be5927ec12c06d89b03ef2a4def34bf823 F src/vdbevtab.c 2143db7db0ceed69b21422581f434baffc507a08d831565193a7a02882a1b6a7 @@ -1355,6 +1355,7 @@ F test/like2.test d3be15fefee3e02fc88942a9b98f26c5339bbdef7783c90023c092c4955fe3 F test/like3.test a76e5938fadbe6d32807284c796bafd869974a961057bc5fc5a28e06de98745c F test/limit.test 350f5d03c29e7dff9a2cde016f84f8d368d40bcd02fa2b2a52fa10c4bf3cbfaf F test/limit2.test 9409b033284642a859fafc95f29a5a6a557bd57c1f0d7c3f554bd64ed69df77e +F test/literal.test 31ef70d425c39b993d0dd61b3f4c65d30b7491e8b3dbbd2d8a23b78b1e8931ca F test/loadext.test faa4f6eed07a5aac35d57fdd7bc07f8fc82464cfd327567c10cf0ba3c86cde04 F test/loadext2.test 0408380b57adca04004247179837a18e866a74f7 F test/lock.test be4fe08118fb988fed741f429b7dd5d65e1c90db @@ -2158,8 +2159,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P e1155d6aa4b960ecfd14fa3467f28672af3327699c547f5b9e75da3ac1348ff7 -R 9689bd329de0e140711926288014ba0a -U drh -Z 0a03ba584bfec4968cbf95a431d1a244 +P 1481baf3d55effcc117f2097e2d49a6f60f5f74b21190c3be943fd785b8a4c5b +R 7a04f28ab4102a53adff1c3861de4c59 +U dan +Z de8bd7b1420ad71ea0d7cb25c6eae88b # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 04b005239f..e0ae0c40c2 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1481baf3d55effcc117f2097e2d49a6f60f5f74b21190c3be943fd785b8a4c5b \ No newline at end of file +8cccc1f27d7470d3cdd3c9c6d74f6a5ac49ec6eaa7002bcf96f4842fb8c79e1a \ No newline at end of file diff --git a/src/vdbemem.c b/src/vdbemem.c index d527164685..2d10cda8d5 100644 --- a/src/vdbemem.c +++ b/src/vdbemem.c @@ -1631,14 +1631,20 @@ static int valueFromExpr( } /* Handle negative integers in a single step. This is needed in the - ** case when the value is -9223372036854775808. - */ - if( op==TK_UMINUS - && (pExpr->pLeft->op==TK_INTEGER || pExpr->pLeft->op==TK_FLOAT) ){ - pExpr = pExpr->pLeft; - op = pExpr->op; - negInt = -1; - zNeg = "-"; + ** case when the value is -9223372036854775808. Except - do not do this + ** for hexadecimal literals. */ + if( op==TK_UMINUS ){ + Expr *pLeft = pExpr->pLeft; + if( (pLeft->op==TK_INTEGER || pLeft->op==TK_FLOAT) ){ + if( ExprHasProperty(pLeft, EP_IntValue) + || pLeft->u.zToken[0]!='0' || (pLeft->u.zToken[1] & ~0x20)!='X' + ){ + pExpr = pLeft; + op = pExpr->op; + negInt = -1; + zNeg = "-"; + } + } } if( op==TK_STRING || op==TK_FLOAT || op==TK_INTEGER ){ @@ -1647,9 +1653,14 @@ static int valueFromExpr( if( ExprHasProperty(pExpr, EP_IntValue) ){ sqlite3VdbeMemSetInt64(pVal, (i64)pExpr->u.iValue*negInt); }else{ - zVal = sqlite3MPrintf(db, "%s%s", zNeg, pExpr->u.zToken); - if( zVal==0 ) goto no_mem; - sqlite3ValueSetStr(pVal, -1, zVal, SQLITE_UTF8, SQLITE_DYNAMIC); + i64 iVal; + if( op==TK_INTEGER && 0==sqlite3DecOrHexToI64(pExpr->u.zToken, &iVal) ){ + sqlite3VdbeMemSetInt64(pVal, iVal*negInt); + }else{ + zVal = sqlite3MPrintf(db, "%s%s", zNeg, pExpr->u.zToken); + if( zVal==0 ) goto no_mem; + sqlite3ValueSetStr(pVal, -1, zVal, SQLITE_UTF8, SQLITE_DYNAMIC); + } } if( (op==TK_INTEGER || op==TK_FLOAT ) && affinity==SQLITE_AFF_BLOB ){ sqlite3ValueApplyAffinity(pVal, SQLITE_AFF_NUMERIC, SQLITE_UTF8); diff --git a/test/literal.test b/test/literal.test new file mode 100644 index 0000000000..7bbb8f0f7a --- /dev/null +++ b/test/literal.test @@ -0,0 +1,47 @@ +# 2024-01-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 tests for SQL literals + + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set ::testprefix literal + +proc test_literal {tn lit type val} { + do_execsql_test $tn.1 "SELECT typeof( $lit ), $lit" [list $type $val] + + do_execsql_test $tn.2 " + DROP TABLE IF EXISTS x1; + CREATE TABLE x1(a); + INSERT INTO x1 VALUES(123); + ALTER TABLE x1 ADD COLUMN b DEFAULT $lit ; + SELECT typeof(b), b FROM x1; + " [list $type $val] +} + + +test_literal 1.0 45 integer 45 +test_literal 1.1 0xFF integer 255 +test_literal 1.2 0xFFFFFFFF integer [expr 0xFFFFFFFF] +test_literal 1.3 0x123FFFFFFFF integer [expr 0x123FFFFFFFF] +test_literal 1.4 -0x123FFFFFFFF integer [expr -1 * 0x123FFFFFFFF] +test_literal 1.5 0xFFFFFFFFFFFFFFFF integer -1 +test_literal 1.7 0x7FFFFFFFFFFFFFFF integer [expr 0x7FFFFFFFFFFFFFFF] +test_literal 1.8 -0x7FFFFFFFFFFFFFFF integer [expr -0x7FFFFFFFFFFFFFFF] +test_literal 1.9 +0x7FFFFFFFFFFFFFFF integer [expr +0x7FFFFFFFFFFFFFFF] +test_literal 1.10 -45 integer -45 +test_literal 1.11 '0xFF' text 0xFF +test_literal 1.12 '-0xFF' text -0xFF +test_literal 1.13 -'0xFF' integer 0 + + +finish_test From f08287cc1243ff220d2a7f001809b37752b1bcd6 Mon Sep 17 00:00:00 2001 From: drh <> Date: Sat, 20 Jan 2024 00:31:44 +0000 Subject: [PATCH 016/430] Implement a new algorithm for computing ISO week values in strftime() based on the idea (from [forum/forumpost/3681cb1bcd|Nuno Cruces]) of shifting the date being tested to the Thursday of the same week. FossilOrigin-Name: b06ab46a9ee98719159ed3e05cdfbf26281353d781206f56ed7cb12859210fed --- manifest | 14 ++++++------ manifest.uuid | 2 +- src/date.c | 61 ++++++++++++++------------------------------------- 3 files changed, 24 insertions(+), 53 deletions(-) diff --git a/manifest b/manifest index 149c0f4a50..f3a5bcbb8d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Allow\slarge\shexadecimal\sliterals\sto\sbe\sused\sas\sDEFAULT\svalues. -D 2024-01-19T16:51:34.042 +C Implement\sa\snew\salgorithm\sfor\scomputing\sISO\sweek\svalues\sin\sstrftime()\sbased\non\sthe\sidea\s(from\s[forum/forumpost/3681cb1bcd|Nuno\sCruces])\sof\sshifting\sthe\ndate\sbeing\stested\sto\sthe\sThursday\sof\sthe\ssame\sweek. +D 2024-01-20T00:31:44.563 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -684,7 +684,7 @@ F src/build.c e7d9044592eeeea8e78d8ae53ca8d31fd6e92ca0d4f53e2f2e8ccf7352e0b04b F src/callback.c db3a45e376deff6a16c0058163fe0ae2b73a2945f3f408ca32cf74960b28d490 F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e F src/ctime.c 23331529e654be40ca97d171cbbffe9b3d4c71cc53b78fe5501230675952da8b -F src/date.c 7ed194fee09bc3aa2129cfe74ebf5daca6fc24c0995dd28cf2a2feacf4d8d44f +F src/date.c 35ea61eb7ab5b918db7a96725346234bf8fb5bc161c7b868c20a7f24f351a2da F src/dbpage.c 80e46e1df623ec40486da7a5086cb723b0275a6e2a7b01d9f9b5da0f04ba2782 F src/dbstat.c 3b677254d512fcafd4d0b341bf267b38b235ccfddbef24f9154e19360fa22e43 F src/delete.c cb766727c78e715f9fb7ec8a7d03658ed2a3016343ca687acfcec9083cdca500 @@ -2159,8 +2159,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 1481baf3d55effcc117f2097e2d49a6f60f5f74b21190c3be943fd785b8a4c5b -R 7a04f28ab4102a53adff1c3861de4c59 -U dan -Z de8bd7b1420ad71ea0d7cb25c6eae88b +P 8cccc1f27d7470d3cdd3c9c6d74f6a5ac49ec6eaa7002bcf96f4842fb8c79e1a +R 6109198c01da554c8b8cc1d558fbd53e +U drh +Z ae5f14e34bf5701b2021ec4920aa096b # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index e0ae0c40c2..c05237a31f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8cccc1f27d7470d3cdd3c9c6d74f6a5ac49ec6eaa7002bcf96f4842fb8c79e1a \ No newline at end of file +b06ab46a9ee98719159ed3e05cdfbf26281353d781206f56ed7cb12859210fed \ No newline at end of file diff --git a/src/date.c b/src/date.c index 059d4c88a6..76e1894f8d 100644 --- a/src/date.c +++ b/src/date.c @@ -1249,7 +1249,7 @@ static int dayOfYear(DateTime *pDate){ jan01.M = 1; jan01.D = 1; computeJD(&jan01); - return (int)((pDate->iJD-jan01.iJD+45300000)/86400000) + 1; + return (int)((pDate->iJD-jan01.iJD+43200000)/86400000) + 1; } /* @@ -1263,41 +1263,6 @@ static int dayOfWeek(DateTime *pDate){ return w; } -/* -** Compute the day-of-week (0=Sunday, 1=Monday, ..., 6=Saturday) for -** the last day of the calendar year Y. -*/ -static int lastDayOfYear(int Y){ - return (Y + (Y/4) - (Y/100) + (Y/400))%7; -} - -/* -** Return the number of ISO weeks in calendar year Y. The answer is -** either 52 or 53. -*/ -static int weeksInYear(int Y){ - if( lastDayOfYear(Y)==4 || lastDayOfYear(Y-1)==3 ){ - return 53; - }else{ - return 52; - } -} - -/* -** Compute the number days since the start of the ISO-week year for pDate. -** The ISO-week year starts on the first day of the week (always a Monday) -** that contains the first Thursday on or after January 1. -*/ -static int isoWeekNumber(DateTime *pDate){ - int wn = (10 + dayOfYear(pDate) - dayOfWeek(pDate))/7; - if( wn<1 ){ - wn = weeksInYear(pDate->Y-1); - }else if( wn>weeksInYear(pDate->Y) ){ - wn = 1; - } - return wn; -} - /* ** strftime( FORMAT, TIMESTRING, MOD, MOD, ...) ** @@ -1376,16 +1341,16 @@ static void strftimeFunc( } case 'G': /* Fall thru */ case 'g': { - int Y = x.Y; - if( x.M==12 && isoWeekNumber(&x)==1 ){ - Y++; - }else if( x.M==1 && isoWeekNumber(&x)>=52 ){ - Y--; - } + DateTime y = x; + assert( y.validJD ); + /* Move y so that it is the Thursday in the same week as x */ + y.iJD += (4 - dayOfWeek(&x))*86400000; + y.validYMD = 0; + computeYMD(&y); if( cf=='g' ){ - sqlite3_str_appendf(&sRes, "%02d", Y%100); + sqlite3_str_appendf(&sRes, "%02d", y.Y%100); }else{ - sqlite3_str_appendf(&sRes, "%04d", Y); + sqlite3_str_appendf(&sRes, "%04d", y.Y); } break; } @@ -1466,7 +1431,13 @@ static void strftimeFunc( break; } case 'V': { /* Week num. 01-53. First week with a Thur is week 01 */ - sqlite3_str_appendf(&sRes,"%02d", isoWeekNumber(&x)); + DateTime y = x; + /* Adjust y so that is the Thursday in the same week as x */ + assert( y.validJD ); + y.iJD += (4 - dayOfWeek(&x))*86400000; + y.validYMD = 0; + computeYMD(&y); + sqlite3_str_appendf(&sRes,"%02d", (dayOfYear(&y)-1)/7+1); break; } case 'W': { /* Week num. 00-53. First Mon of the year is week 01 */ From a74a7f5b9e6e9beaf69ae23ff90296d3948d7dd7 Mon Sep 17 00:00:00 2001 From: drh <> Date: Sat, 20 Jan 2024 12:00:20 +0000 Subject: [PATCH 017/430] Fix the version number in the TEA configure script. This should have been changed by [1481baf3d55effcc] three check-ins ago. It is unclear how testing missed this. FossilOrigin-Name: eaf2cf73fca3355edd05fef5b0d0262a6555633908794068805d12b1948beedc --- autoconf/tea/configure.ac | 2 +- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/autoconf/tea/configure.ac b/autoconf/tea/configure.ac index 4df57344be..f188f22039 100644 --- a/autoconf/tea/configure.ac +++ b/autoconf/tea/configure.ac @@ -19,7 +19,7 @@ dnl to configure the system for the local environment. # so that we create the export library with the dll. #----------------------------------------------------------------------- -AC_INIT([sqlite],[3.45.0]) +AC_INIT([sqlite],[3.46.0]) #-------------------------------------------------------------------- # Call TEA_INIT as the first TEA_ macro to set up initial vars. diff --git a/manifest b/manifest index f3a5bcbb8d..94f8ff8ff4 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Implement\sa\snew\salgorithm\sfor\scomputing\sISO\sweek\svalues\sin\sstrftime()\sbased\non\sthe\sidea\s(from\s[forum/forumpost/3681cb1bcd|Nuno\sCruces])\sof\sshifting\sthe\ndate\sbeing\stested\sto\sthe\sThursday\sof\sthe\ssame\sweek. -D 2024-01-20T00:31:44.563 +C Fix\sthe\sversion\snumber\sin\sthe\sTEA\sconfigure\sscript.\s\sThis\sshould\shave\nbeen\schanged\sby\s[1481baf3d55effcc]\sthree\scheck-ins\sago.\nIt\sis\sunclear\show\stesting\smissed\sthis. +D 2024-01-20T12:00:20.372 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -22,7 +22,7 @@ F autoconf/configure.ac ec7fa914c5e74ff212fe879f9bb6918e1234497e05facfb641f30c4d F autoconf/tea/Makefile.in 106a96f2f745d41a0f6193f1de98d7355830b65d45032c18cd7c90295ec24196 F autoconf/tea/README 3e9a3c060f29a44344ab50aec506f4db903fb873 F autoconf/tea/aclocal.m4 52c47aac44ce0ddb1f918b6993e8beb8eee88f43 -F autoconf/tea/configure.ac 4c32b08691a5b296206b38422b53b92b65be3d3f6b3dd6552a50981a61f5acda +F autoconf/tea/configure.ac 9e74135563a901d9b1a019bad1c9d73a6659fa32325f6a565bef72bfb0ec7297 F autoconf/tea/doc/sqlite3.n e1fe45d4f5286ee3d0ccc877aca2a0def488e9bb F autoconf/tea/license.terms 13bd403c9610fd2b76ece0ab50c4c5eda933d523 F autoconf/tea/pkgIndex.tcl.in b9eb6dd37f64e08e637d576b3c83259814b9cddd78bec4af2e5abfc6c5c750ce @@ -2159,8 +2159,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 8cccc1f27d7470d3cdd3c9c6d74f6a5ac49ec6eaa7002bcf96f4842fb8c79e1a -R 6109198c01da554c8b8cc1d558fbd53e +P b06ab46a9ee98719159ed3e05cdfbf26281353d781206f56ed7cb12859210fed +R 9501c38a1e8bd841e94256d593af54ad U drh -Z ae5f14e34bf5701b2021ec4920aa096b +Z 968fbfadacc13465ad30d7b8182c0acc # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index c05237a31f..93934bab25 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b06ab46a9ee98719159ed3e05cdfbf26281353d781206f56ed7cb12859210fed \ No newline at end of file +eaf2cf73fca3355edd05fef5b0d0262a6555633908794068805d12b1948beedc \ No newline at end of file From 777a08893bd08bfed6fc09e498912fb63d974d83 Mon Sep 17 00:00:00 2001 From: drh <> Date: Sat, 20 Jan 2024 12:13:00 +0000 Subject: [PATCH 018/430] When backing out a character in a constructed string in JSON, first make sure the string has not been reset by on OOM. dbsqlfuzz 2fffbea91a5376526ea118d4fe4188c8dd35e317. FossilOrigin-Name: 666690eb433fe38fa527ccbbb8e2c00041a33939da4f6b8bfb737d664f28f0d8 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/json.c | 24 +++++++++++++++++------- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/manifest b/manifest index 94f8ff8ff4..5a4e7fd711 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\sversion\snumber\sin\sthe\sTEA\sconfigure\sscript.\s\sThis\sshould\shave\nbeen\schanged\sby\s[1481baf3d55effcc]\sthree\scheck-ins\sago.\nIt\sis\sunclear\show\stesting\smissed\sthis. -D 2024-01-20T12:00:20.372 +C When\sbacking\sout\sa\scharacter\sin\sa\sconstructed\sstring\sin\sJSON,\sfirst\smake\ssure\nthe\sstring\shas\snot\sbeen\sreset\sby\son\sOOM.\ndbsqlfuzz\s2fffbea91a5376526ea118d4fe4188c8dd35e317. +D 2024-01-20T12:13:00.530 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -698,7 +698,7 @@ F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 F src/insert.c 3f0a94082d978bbdd33c38fefea15346c6c6bffb70bc645a71dc0f1f87dd3276 -F src/json.c 624824b0c405dc64bb371107f21baf1d00a6b609cbdb16feaa2338a335bf981b +F src/json.c 5405e50cf0d7aeae12ac5b46e0fc9b3757b3b9cb4885f1a73ec7afeac99b9759 F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 F src/main.c 438b95162acfa17b7d218f586f5bde11d6ae82bcf030c9611fc537556870ad6b @@ -2159,8 +2159,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P b06ab46a9ee98719159ed3e05cdfbf26281353d781206f56ed7cb12859210fed -R 9501c38a1e8bd841e94256d593af54ad +P eaf2cf73fca3355edd05fef5b0d0262a6555633908794068805d12b1948beedc +R 8f8b8c466d5567f67ab6487c681d59e2 U drh -Z 968fbfadacc13465ad30d7b8182c0acc +Z fda57e08b93251c93aba9abc8bd9967a # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 93934bab25..75aed94f83 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -eaf2cf73fca3355edd05fef5b0d0262a6555633908794068805d12b1948beedc \ No newline at end of file +666690eb433fe38fa527ccbbb8e2c00041a33939da4f6b8bfb737d664f28f0d8 \ No newline at end of file diff --git a/src/json.c b/src/json.c index 97cf5fe28c..d33692466b 100644 --- a/src/json.c +++ b/src/json.c @@ -589,6 +589,16 @@ static void jsonAppendChar(JsonString *p, char c){ } } +/* Remove a single character from the end of the string +*/ +static void jsonStringTrimOneChar(JsonString *p){ + if( p->eErr==0 ){ + assert( p->nUsed>0 ); + p->nUsed--; + } +} + + /* Make sure there is a zero terminator on p->zBuf[] ** ** Return true on success. Return false if an OOM prevents this @@ -596,7 +606,7 @@ static void jsonAppendChar(JsonString *p, char c){ */ static int jsonStringTerminate(JsonString *p){ jsonAppendChar(p, 0); - p->nUsed--; + jsonStringTrimOneChar(p); return p->eErr==0; } @@ -2261,7 +2271,7 @@ static u32 jsonTranslateBlobToText( j = jsonTranslateBlobToText(pParse, j, pOut); jsonAppendChar(pOut, ','); } - if( sz>0 ) pOut->nUsed--; + if( sz>0 ) jsonStringTrimOneChar(pOut); jsonAppendChar(pOut, ']'); break; } @@ -2275,7 +2285,7 @@ static u32 jsonTranslateBlobToText( jsonAppendChar(pOut, (x++ & 1) ? ',' : ':'); } if( x & 1 ) pOut->eErr |= JSTRING_MALFORMED; - if( sz>0 ) pOut->nUsed--; + if( sz>0 ) jsonStringTrimOneChar(pOut); jsonAppendChar(pOut, '}'); break; } @@ -4403,7 +4413,7 @@ static void jsonArrayCompute(sqlite3_context *ctx, int isFinal){ if( isFinal ){ if( !pStr->bStatic ) sqlite3RCStrUnref(pStr->zBuf); }else{ - pStr->nUsed--; + jsonStringTrimOneChar(pStr); } return; }else if( isFinal ){ @@ -4413,7 +4423,7 @@ static void jsonArrayCompute(sqlite3_context *ctx, int isFinal){ pStr->bStatic = 1; }else{ sqlite3_result_text(ctx, pStr->zBuf, (int)pStr->nUsed, SQLITE_TRANSIENT); - pStr->nUsed--; + jsonStringTrimOneChar(pStr); } }else{ sqlite3_result_text(ctx, "[]", 2, SQLITE_STATIC); @@ -4523,7 +4533,7 @@ static void jsonObjectCompute(sqlite3_context *ctx, int isFinal){ if( isFinal ){ if( !pStr->bStatic ) sqlite3RCStrUnref(pStr->zBuf); }else{ - pStr->nUsed--; + jsonStringTrimOneChar(pStr); } return; }else if( isFinal ){ @@ -4533,7 +4543,7 @@ static void jsonObjectCompute(sqlite3_context *ctx, int isFinal){ pStr->bStatic = 1; }else{ sqlite3_result_text(ctx, pStr->zBuf, (int)pStr->nUsed, SQLITE_TRANSIENT); - pStr->nUsed--; + jsonStringTrimOneChar(pStr); } }else{ sqlite3_result_text(ctx, "{}", 2, SQLITE_STATIC); From 8dca1905edbfb064b8bd99d3ffb07deeb370f8f8 Mon Sep 17 00:00:00 2001 From: drh <> Date: Sat, 20 Jan 2024 13:18:22 +0000 Subject: [PATCH 019/430] Ensure that the replace() SQL function always returns a TEXT value even when its first argument is numeric and its second argument is an empty string. Fix for the issue reported by [forum:/forumpost/3776b48e71|forum post 3776b48e71]. FossilOrigin-Name: 01868ebcd25fadb2034da234c0636e82d07c5abc902ef66493cadfc988e74d7b --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/func.c | 2 +- test/func.test | 3 +++ 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 5a4e7fd711..87e3d53958 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C When\sbacking\sout\sa\scharacter\sin\sa\sconstructed\sstring\sin\sJSON,\sfirst\smake\ssure\nthe\sstring\shas\snot\sbeen\sreset\sby\son\sOOM.\ndbsqlfuzz\s2fffbea91a5376526ea118d4fe4188c8dd35e317. -D 2024-01-20T12:13:00.530 +C Ensure\sthat\sthe\sreplace()\sSQL\sfunction\salways\sreturns\sa\sTEXT\svalue\seven\nwhen\sits\sfirst\sargument\sis\snumeric\sand\sits\ssecond\sargument\sis\san\sempty\sstring.\nFix\sfor\sthe\sissue\sreported\sby\n[forum:/forumpost/3776b48e71|forum\spost\s3776b48e71]. +D 2024-01-20T13:18:22.409 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -691,7 +691,7 @@ F src/delete.c cb766727c78e715f9fb7ec8a7d03658ed2a3016343ca687acfcec9083cdca500 F src/expr.c 3381ee4c9aa7ccde22a2a7f35ce343925a7a25d96bdc943649131f9decdebad2 F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c a47610f0a5c6cb0ad79f8fcef039c01833dec0c751bb695f28dc0ec6a4c3ba00 -F src/func.c 472f6dcfa39cf54f89a6aec76c79c225fb880a6c14469c15d361331662b9bf43 +F src/func.c c71b81223e165722cd81fa71fb869a235de5998c4c5142a5dfa2725d6331f539 F src/global.c 765a0656d6cbf043cb272ff0ae38f39cc46713539ffe6793258ed3eb4b188b52 F src/hash.c 9ee4269fb1d6632a6fecfb9479c93a1f29271bddbbaf215dd60420bcb80c7220 F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 @@ -1216,7 +1216,7 @@ F test/fts4umlaut.test fcaca4471de7e78c9d1f7e8976e3e8704d7d8ad979d57a739d00f3f75 F test/fts4unicode.test 82a9c16b68ba2f358a856226bb2ee02f81583797bc4744061c54401bf1a0f4c9 F test/fts4upfrom.test f25835162c989dffd5e2ef91ec24c4848cc9973093e2d492d1c7b32afac1b49d F test/full.test 6b3c8fb43c6beab6b95438c1675374b95fab245d -F test/func.test 3a29323b640c0552f6e9f1577407ced3a68e7d8c0bc04b61dd6040fa593a3a02 +F test/func.test da1332f6ab70338b83f5e2d594e72c7aa438c9b68406915e5a54618d601c09ee F test/func2.test 772d66227e4e6684b86053302e2d74a2500e1e0f F test/func3.test 600a632c305a88f3946d38f9a51efe145c989b2e13bd2b2a488db47fe76bab6a F test/func4.test e8ef9b2bd6a192a213cbd5cf31a3b35e25cd6ff2fdaeea0b58d63be31b03d220 @@ -2159,8 +2159,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P eaf2cf73fca3355edd05fef5b0d0262a6555633908794068805d12b1948beedc -R 8f8b8c466d5567f67ab6487c681d59e2 +P 666690eb433fe38fa527ccbbb8e2c00041a33939da4f6b8bfb737d664f28f0d8 +R 5c8274fb3e9d5dd9f1b4d6e28e9c5cce U drh -Z fda57e08b93251c93aba9abc8bd9967a +Z 5fa26dddb0e1de9dbc03b74686820e2f # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 75aed94f83..7cab8868f6 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -666690eb433fe38fa527ccbbb8e2c00041a33939da4f6b8bfb737d664f28f0d8 \ No newline at end of file +01868ebcd25fadb2034da234c0636e82d07c5abc902ef66493cadfc988e74d7b \ No newline at end of file diff --git a/src/func.c b/src/func.c index 58ef4fef9c..249c17857e 100644 --- a/src/func.c +++ b/src/func.c @@ -1409,7 +1409,7 @@ static void replaceFunc( } if( zPattern[0]==0 ){ assert( sqlite3_value_type(argv[1])!=SQLITE_NULL ); - sqlite3_result_value(context, argv[0]); + sqlite3_result_text(context, (const char*)zStr, nStr, SQLITE_TRANSIENT); return; } nPattern = sqlite3_value_bytes(argv[1]); diff --git a/test/func.test b/test/func.test index 883950a0c4..82f51b857d 100644 --- a/test/func.test +++ b/test/func.test @@ -1042,6 +1042,9 @@ do_test func-21.8 { SELECT replace('aaaaaaa', 'a', '0123456789'); } } {0123456789012345678901234567890123456789012345678901234567890123456789} +do_execsql_test func-21.9 { + SELECT typeof(replace(1,'',0)); +} {text} ifcapable tclvar { do_test func-21.9 { From 4c43f1881e86893c22ead7a72be6b14bbcd051eb Mon Sep 17 00:00:00 2001 From: drh <> Date: Sat, 20 Jan 2024 15:13:13 +0000 Subject: [PATCH 020/430] When doing a text-affinity comparison between two values where one or both have both a text and a numeric type, make sure the numeric type does not confuse the answer. This is a deeper fix to the problem observed by [forum:/forumpost/3776b48e71|forum pose 3776b48e71]. The problem bisects to [25f2246be404f38b] on 2014-08-24, prior to version 3.8.7. FossilOrigin-Name: 709841f88c77276f09701bf38e25503c64b3a0afbe2fbf878136db12f31cbe21 --- ext/misc/noop.c | 22 ++++++++++++++++++++++ manifest | 18 +++++++++--------- manifest.uuid | 2 +- src/test1.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ src/vdbe.c | 8 ++++++-- test/types3.test | 30 +++++++++++++++++++++++++++-- 6 files changed, 115 insertions(+), 14 deletions(-) diff --git a/ext/misc/noop.c b/ext/misc/noop.c index d3a58670c4..18c25e10f7 100644 --- a/ext/misc/noop.c +++ b/ext/misc/noop.c @@ -38,6 +38,24 @@ static void noopfunc( sqlite3_result_value(context, argv[0]); } +/* +** Implementation of the multitype_text() function. +** +** The function returns its argument. The result will always have a +** TEXT value. But if the original input is numeric, it will also +** have that numeric value. +*/ +static void multitypeTextFunc( + sqlite3_context *context, + int argc, + sqlite3_value **argv +){ + assert( argc==1 ); + (void)argc; + (void)sqlite3_value_text(argv[0]); + sqlite3_result_value(context, argv[0]); +} + #ifdef _WIN32 __declspec(dllexport) #endif @@ -64,5 +82,9 @@ int sqlite3_noop_init( rc = sqlite3_create_function(db, "noop_nd", 1, SQLITE_UTF8, 0, noopfunc, 0, 0); + if( rc ) return rc; + rc = sqlite3_create_function(db, "multitype_text", 1, + SQLITE_UTF8, + 0, multitypeTextFunc, 0, 0); return rc; } diff --git a/manifest b/manifest index 87e3d53958..320c5bbcb4 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Ensure\sthat\sthe\sreplace()\sSQL\sfunction\salways\sreturns\sa\sTEXT\svalue\seven\nwhen\sits\sfirst\sargument\sis\snumeric\sand\sits\ssecond\sargument\sis\san\sempty\sstring.\nFix\sfor\sthe\sissue\sreported\sby\n[forum:/forumpost/3776b48e71|forum\spost\s3776b48e71]. -D 2024-01-20T13:18:22.409 +C When\sdoing\sa\stext-affinity\scomparison\sbetween\stwo\svalues\swhere\sone\sor\sboth\nhave\sboth\sa\stext\sand\sa\snumeric\stype,\smake\ssure\sthe\snumeric\stype\sdoes\snot\nconfuse\sthe\sanswer.\s\sThis\sis\sa\sdeeper\sfix\sto\sthe\sproblem\sobserved\sby\n[forum:/forumpost/3776b48e71|forum\spose\s3776b48e71].\s\sThe\sproblem\sbisects\nto\s[25f2246be404f38b]\son\s2014-08-24,\sprior\sto\sversion\s3.8.7. +D 2024-01-20T15:13:13.896 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -389,7 +389,7 @@ F ext/misc/memtrace.c 7c0d115d2ef716ad0ba632c91e05bd119cb16c1aedf3bec9f06196ead2 F ext/misc/memvfs.c 7dffa8cc89c7f2d73da4bd4ccea1bcbd2bd283e3bb4cea398df7c372a197291b F ext/misc/mmapwarm.c a81af4aaec00f24f308e2f4c19bf1d88f3ac3ce848c36daa7a4cd38145c4080d F ext/misc/nextchar.c 7877914c2a80c2f181dd04c3dbef550dfb54c93495dc03da2403b5dd58f34edd -F ext/misc/noop.c 81efe4cad9ec740e64388b14281cb983e6e2c223fed43eb77ab3e34946e0c1ab +F ext/misc/noop.c f1a21cc9b7a4e667e5c8458d80ba680b8bd4315a003f256006046879f679c5a0 F ext/misc/normalize.c bd84355c118e297522aba74de34a4fd286fc775524e0499b14473918d09ea61f F ext/misc/pcachetrace.c f4227ce03fb16aa8d6f321b72dd051097419d7a028a9853af048bee7645cb405 F ext/misc/percentile.c b9086e223d583bdaf8cb73c98a6539d501a2fc4282654adbfea576453d82e691 @@ -748,7 +748,7 @@ F src/sqliteLimit.h 6878ab64bdeb8c24a1d762d45635e34b96da21132179023338c93f820eee F src/status.c cb11f8589a6912af2da3bb1ec509a94dd8ef27df4d4c1a97e0bcf2309ece972b F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1 F src/tclsqlite.c ecbc3c99c0d0c3ed122a913f143026c26d38d57f33e06bb71185dd5c1efe37cd -F src/test1.c ac6542cddd1f405e332d869946b977b2ce8b4dc28b9f7cc61df38abe1fe49bc3 +F src/test1.c 310f43eb17a9252a7790726ca652e4ea3197da17c19eec93b8578863a49dc7b4 F src/test2.c 54520d0565ef2b9bf0f8f1dcac43dc4d06baf4ffe13d10905f8d8c3ad3e4b9ab F src/test3.c e5178558c41ff53236ae0271e9acb3d6885a94981d2eb939536ee6474598840e F src/test4.c 4533b76419e7feb41b40582554663ed3cd77aaa54e135cf76b3205098cd6e664 @@ -808,7 +808,7 @@ F src/upsert.c fa125a8d3410ce9a97b02cb50f7ae68a2476c405c76aa692d3acf6b8586e9242 F src/utf.c f23165685a67b4caf8ec08fb274cb3f319103decfb2a980b7cfd55d18dfa855e F src/util.c 078f040366d5bd5f47658d045f901c768c1c636c6eaea121f3a1cbd63c3edb5b F src/vacuum.c 604fcdaebe76f3497c855afcbf91b8fa5046b32de3045bab89cc008d68e40104 -F src/vdbe.c 4a42916b14548112cb1ee9b9dea3c0ba6c21d08fa0c660cd1561c1871e25908f +F src/vdbe.c 92910d536e0b77505599cd6ae5d9d449e4a5d31ada61da4c0bb84f6ccb2c3189 F src/vdbe.h 88e19a982df9027ec1c177c793d1a5d34dc23d8f06e3b2d997f43688b05ee0eb F src/vdbeInt.h 949669dfd8a41550d27dcb905b494f2ccde9a2e6c1b0b04daa1227e2e74c2b2c F src/vdbeapi.c 8f57d60c89da0b60e6d4e272358c511f6bae4e24330bdb11f8b42f986d1bf21b @@ -1866,7 +1866,7 @@ F test/tt3_stress.c f9a769ca8b026ecc76ee93ca8c9700a5619f8e51c581107c4053ba6ac97f F test/tt3_vacuum.c 71b254cde1fc49d6c8c44efd54f4668f3e57d7b3a8f4601ade069f75a999ba39 F test/types.test bf816ce73c7dfcfe26b700c19f97ef4050d194ff F test/types2.test 1aeb81976841a91eef292723649b5c4fe3bc3cac -F test/types3.test 99e009491a54f4dc02c06bdbc0c5eea56ae3e25a +F test/types3.test c9db8f9e80309edfa4252585cf16bcab7ed31f39eeb904d21e831199a3613fb0 F test/unhex.test b7f1b806207cb77fa31c3e434fe92fba524464e3e9356809bfcc28f15af1a8b7 F test/unionall.test 5b1c4186a661e4bf762875caf4c61d8fda3dd04a6fa9005187f6ba8900c2913f F test/unionall2.test 71e8fa08d5699d50dc9f9dc0c9799c2e7a6bb7931a330d369307a4df7f157fa1 @@ -2159,8 +2159,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 666690eb433fe38fa527ccbbb8e2c00041a33939da4f6b8bfb737d664f28f0d8 -R 5c8274fb3e9d5dd9f1b4d6e28e9c5cce +P 01868ebcd25fadb2034da234c0636e82d07c5abc902ef66493cadfc988e74d7b +R c017e3ff6a3cf5fef0c29004a344e6f7 U drh -Z 5fa26dddb0e1de9dbc03b74686820e2f +Z f4a73b0af78f34dd85f781f1eb7187c3 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 7cab8868f6..d23f19cb29 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -01868ebcd25fadb2034da234c0636e82d07c5abc902ef66493cadfc988e74d7b \ No newline at end of file +709841f88c77276f09701bf38e25503c64b3a0afbe2fbf878136db12f31cbe21 \ No newline at end of file diff --git a/src/test1.c b/src/test1.c index 9c28259b41..8faf5a397b 100644 --- a/src/test1.c +++ b/src/test1.c @@ -991,6 +991,39 @@ static void intrealFunction( sqlite3_test_control(SQLITE_TESTCTRL_RESULT_INTREAL, context); } +/* +** These SQL functions attempt to return a value (their first argument) +** that has been modified to have multiple datatypes. For example both +** TEXT and INTEGER. +*/ +static void addTextTypeFunction( + sqlite3_context *context, + int argc, + sqlite3_value **argv +){ + (void)sqlite3_value_text(argv[0]); + (void)argc; + sqlite3_result_value(context, argv[0]); +} +static void addIntTypeFunction( + sqlite3_context *context, + int argc, + sqlite3_value **argv +){ + (void)sqlite3_value_int64(argv[0]); + (void)argc; + sqlite3_result_value(context, argv[0]); +} +static void addRealTypeFunction( + sqlite3_context *context, + int argc, + sqlite3_value **argv +){ + (void)sqlite3_value_double(argv[0]); + (void)argc; + sqlite3_result_value(context, argv[0]); +} + /* ** SQL function: strtod(X) ** @@ -1103,6 +1136,22 @@ static int SQLITE_TCLAPI test_create_function( 0, intrealFunction, 0, 0); } + /* The add_text_type(), add_int_type(), and add_real_type() functions + ** attempt to return a value that has multiple datatypes. + */ + if( rc==SQLITE_OK ){ + rc = sqlite3_create_function(db, "add_text_type", 1, SQLITE_UTF8, + 0, addTextTypeFunction, 0, 0); + } + if( rc==SQLITE_OK ){ + rc = sqlite3_create_function(db, "add_int_type", 1, SQLITE_UTF8, + 0, addIntTypeFunction, 0, 0); + } + if( rc==SQLITE_OK ){ + rc = sqlite3_create_function(db, "add_real_type", 1, SQLITE_UTF8, + 0, addRealTypeFunction, 0, 0); + } + /* Functions strtod() and dtostr() work as in the shell. These routines ** use the standard C library to convert between floating point and ** text. This is used to compare SQLite's internal conversion routines diff --git a/src/vdbe.c b/src/vdbe.c index 2ae757b76e..84eccf5334 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -2301,7 +2301,9 @@ case OP_Ge: { /* same as TK_GE, jump, in1, in3 */ } } }else if( affinity==SQLITE_AFF_TEXT && ((flags1 | flags3) & MEM_Str)!=0 ){ - if( (flags1 & MEM_Str)==0 && (flags1&(MEM_Int|MEM_Real|MEM_IntReal))!=0 ){ + if( (flags1 & MEM_Str)!=0 ){ + pIn1->flags &= ~(MEM_Int|MEM_Real|MEM_IntReal); + }else if( (flags1&(MEM_Int|MEM_Real|MEM_IntReal))!=0 ){ testcase( pIn1->flags & MEM_Int ); testcase( pIn1->flags & MEM_Real ); testcase( pIn1->flags & MEM_IntReal ); @@ -2310,7 +2312,9 @@ case OP_Ge: { /* same as TK_GE, jump, in1, in3 */ flags1 = (pIn1->flags & ~MEM_TypeMask) | (flags1 & MEM_TypeMask); if( NEVER(pIn1==pIn3) ) flags3 = flags1 | MEM_Str; } - if( (flags3 & MEM_Str)==0 && (flags3&(MEM_Int|MEM_Real|MEM_IntReal))!=0 ){ + if( (flags3 & MEM_Str)!=0 ){ + pIn3->flags &= ~(MEM_Int|MEM_Real|MEM_IntReal); + }else if( (flags3&(MEM_Int|MEM_Real|MEM_IntReal))!=0 ){ testcase( pIn3->flags & MEM_Int ); testcase( pIn3->flags & MEM_Real ); testcase( pIn3->flags & MEM_IntReal ); diff --git a/test/types3.test b/test/types3.test index 807ae84f9d..0ff346ce28 100644 --- a/test/types3.test +++ b/test/types3.test @@ -12,8 +12,6 @@ # of this file is testing the interaction of SQLite manifest types # with Tcl dual-representations. # -# $Id: types3.test,v 1.8 2008/04/28 13:02:58 drh Exp $ -# set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -96,4 +94,32 @@ do_test types3-2.6 { tcl_variable_type V } {} +# See https://sqlite.org/forum/forumpost/3776b48e71 +# +# On a text-affinity comparison of two values where one of +# the values has both MEM_Str and a numeric type like MEM_Int, +# make sure that only the MEM_Str representation is used. +# +sqlite3_create_function db +do_execsql_test types3-3.1 { + DROP TABLE IF EXISTS t1; + CREATE TABLE t1(x TEXT PRIMARY KEY); + INSERT INTO t1 VALUES('1'); + SELECT * FROM t1 WHERE NOT x=upper(1); +} {} +do_execsql_test types3-3.2 { + SELECT * FROM t1 WHERE NOT x=add_text_type(1); +} {} +do_execsql_test types3-3.3 { + SELECT * FROM t1 WHERE NOT x=add_int_type('1'); +} {} +do_execsql_test types3-3.4 { + DELETE FROM t1; + INSERT INTO t1 VALUES(1.25); + SELECT * FROM t1 WHERE NOT x=add_real_type('1.25'); +} {} +do_execsql_test types3-3.5 { + SELECT * FROM t1 WHERE NOT x=add_text_type(1.25); +} {} + finish_test From 3eae6664a00961baf3d011229794cd98371aa9cf Mon Sep 17 00:00:00 2001 From: dan Date: Sat, 20 Jan 2024 16:18:04 +0000 Subject: [PATCH 021/430] Allow "_" characters to appear following any digit in an integer or real SQL literal. FossilOrigin-Name: 401650aaccbc99246bd4e1ff37a28b78f528178aee2f294d87b9f7fecd7432bb --- manifest | 29 +++++++++++++++------------- manifest.uuid | 2 +- src/parse.y | 6 ++++++ src/sqliteInt.h | 3 +++ src/tokenize.c | 27 +++++++++++++++++++------- src/util.c | 21 +++++++++++++++++++++ test/literal.test | 3 +++ test/speedtest1.c | 46 +++++++++++++++++++++++++++++++++++++++++++++ tool/speed-check.sh | 3 +++ 9 files changed, 119 insertions(+), 21 deletions(-) diff --git a/manifest b/manifest index 320c5bbcb4..f2673bb861 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C When\sdoing\sa\stext-affinity\scomparison\sbetween\stwo\svalues\swhere\sone\sor\sboth\nhave\sboth\sa\stext\sand\sa\snumeric\stype,\smake\ssure\sthe\snumeric\stype\sdoes\snot\nconfuse\sthe\sanswer.\s\sThis\sis\sa\sdeeper\sfix\sto\sthe\sproblem\sobserved\sby\n[forum:/forumpost/3776b48e71|forum\spose\s3776b48e71].\s\sThe\sproblem\sbisects\nto\s[25f2246be404f38b]\son\s2014-08-24,\sprior\sto\sversion\s3.8.7. -D 2024-01-20T15:13:13.896 +C Allow\s"_"\scharacters\sto\sappear\sfollowing\sany\sdigit\sin\san\sinteger\sor\sreal\sSQL\sliteral. +D 2024-01-20T16:18:04.854 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -727,7 +727,7 @@ F src/os_win.c 4a50a154aeebc66a1f8fb79c1ff6dd5fe3d005556533361e0d460d41cb6a45a8 F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a F src/pager.c ff60e98138d2499082ac6230f01ac508aba545315debccfca2fd6042f5f10fcd F src/pager.h 4b1140d691860de0be1347474c51fee07d5420bd7f802d38cbab8ea4ab9f538a -F src/parse.y 020d80386eb216ec9520549106353c517d2bbc89be28752ffdca649a9eaf56ec +F src/parse.y 2354aaf964e7c4154a9dbe56ea55a797a0fa3021c38b50afe491ea4a387bf971 F src/pcache.c 040b165f30622a21b7a9a77c6f2e4877a32fb7f22d4c7f0d2a6fa6833a156a75 F src/pcache.h 1497ce1b823cf00094bb0cf3bac37b345937e6f910890c626b16512316d3abf5 F src/pcache1.c 602acb23c471bb8d557a6f0083cc2be641d6cafcafa19e481eba7ef4c9ca0f00 @@ -743,7 +743,7 @@ F src/shell.c.in d1ed426aae2d547932971e8019939cacb4dfda8258e45b8924b250e488e2d53 F src/sqlite.h.in 61a60b4ea04db8ead15e1579b20b64cb56e9f55d52c5f9f9694de630110593a3 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 -F src/sqliteInt.h 73800d73e21180e6b3df8d0fe7d11758dc24367fd2b0b0075b48fc116de406bb +F src/sqliteInt.h 6e5e330d84b4ace70e3163721601f01df84566e6db21e1fc45bd00636e3d6640 F src/sqliteLimit.h 6878ab64bdeb8c24a1d762d45635e34b96da21132179023338c93f820eee6728 F src/status.c cb11f8589a6912af2da3bb1ec509a94dd8ef27df4d4c1a97e0bcf2309ece972b F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1 @@ -800,13 +800,13 @@ F src/test_windirent.h da2e5b73c32d09905fbdd00f27cd802212a32a58ead882736fe4f5eb7 F src/test_window.c cdae419fdcea5bad6dcd9368c685abdad6deb59e9fc8b84b153de513d394ba3f F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9 F src/threads.c 4ae07fa022a3dc7c5beb373cf744a85d3c5c6c3c -F src/tokenize.c 23d9f4539880b40226254ad9072f4ecf12eb1902e62aea47aac29928afafcfd5 +F src/tokenize.c b3ab5ee644f3ac54e6a6a856cfb78bdb285e634fae39b38ce0f6e848305ca32e F src/treeview.c c6fc972683fd00f975d8b32a81c1f25d2fb7d4035366bf45c9f5622d3ccd70ee F src/trigger.c 0905b96b04bb6658509f711a8207287f1315cdbc3df1a1b13ba6483c8e341c81 F src/update.c 6904814dd62a7a93bbb86d9f1419c7f134a9119582645854ab02b36b676d9f92 F src/upsert.c fa125a8d3410ce9a97b02cb50f7ae68a2476c405c76aa692d3acf6b8586e9242 F src/utf.c f23165685a67b4caf8ec08fb274cb3f319103decfb2a980b7cfd55d18dfa855e -F src/util.c 078f040366d5bd5f47658d045f901c768c1c636c6eaea121f3a1cbd63c3edb5b +F src/util.c 2b274b03f0d4fd1bf253f160d6b399bc5265338b043c078045c5e32298891ec8 F src/vacuum.c 604fcdaebe76f3497c855afcbf91b8fa5046b32de3045bab89cc008d68e40104 F src/vdbe.c 92910d536e0b77505599cd6ae5d9d449e4a5d31ada61da4c0bb84f6ccb2c3189 F src/vdbe.h 88e19a982df9027ec1c177c793d1a5d34dc23d8f06e3b2d997f43688b05ee0eb @@ -1355,7 +1355,7 @@ F test/like2.test d3be15fefee3e02fc88942a9b98f26c5339bbdef7783c90023c092c4955fe3 F test/like3.test a76e5938fadbe6d32807284c796bafd869974a961057bc5fc5a28e06de98745c F test/limit.test 350f5d03c29e7dff9a2cde016f84f8d368d40bcd02fa2b2a52fa10c4bf3cbfaf F test/limit2.test 9409b033284642a859fafc95f29a5a6a557bd57c1f0d7c3f554bd64ed69df77e -F test/literal.test 31ef70d425c39b993d0dd61b3f4c65d30b7491e8b3dbbd2d8a23b78b1e8931ca +F test/literal.test 9bf0ce5ca1034e3c6f83d5dff82abdedcfa1596cd843b2e4f93f58828e123046 F test/loadext.test faa4f6eed07a5aac35d57fdd7bc07f8fc82464cfd327567c10cf0ba3c86cde04 F test/loadext2.test 0408380b57adca04004247179837a18e866a74f7 F test/lock.test be4fe08118fb988fed741f429b7dd5d65e1c90db @@ -1624,7 +1624,7 @@ F test/speed3.test 694affeb9100526007436334cf7d08f3d74b85ef F test/speed4.test abc0ad3399dcf9703abed2fff8705e4f8e416715 F test/speed4p.explain 6b5f104ebeb34a038b2f714150f51d01143e59aa F test/speed4p.test 377a0c48e5a92e0b11c1c5ebb1bc9d83a7312c922bc0cb05970ef5d6a96d1f0c -F test/speedtest1.c f9505ad6f9c2c3c488a370a2d193e9603a030e51126ef3ecfeb056d21f0e7ad5 +F test/speedtest1.c 19c9b60908d25502d2831f97efee8b81006c356ab8c08327e25d24a4144f2131 F test/spellfix.test 951a6405d49d1a23d6b78027d3877b4a33eeb8221dcab5704b499755bb4f552e F test/spellfix2.test dfc8f519a3fc204cb2dfa8b4f29821ae90f6f8c3 F test/spellfix3.test 0f9efaaa502a0e0a09848028518a6fb096c8ad33 @@ -2112,7 +2112,7 @@ F tool/showstat4.c 0682ebea7abf4d3657f53c4a243f2e7eab48eab344ed36a94bb75dcd19a5c F tool/showwal.c 11eca547980a066b081f512636151233350ac679f29ecf4ebfce7f4530230b3d F tool/soak1.tcl 8d407956e1a45b485a8e072470a3e629a27037fe F tool/spaceanal.tcl 70c87c04cfd2e77b3e6f21c33ca768296aa8f67d4ab4874786ac8fbb28433477 -F tool/speed-check.sh 72dc85b2c0484af971ee3e7d10775f72b4e771e27e162c2099b3bf25517c25fb +F tool/speed-check.sh e8d20cc2eb9c85ec1ba562226de144435456dcdff4ee618de49603c6958f6116 F tool/speedtest.tcl 06c76698485ccf597b9e7dbb1ac70706eb873355 F tool/speedtest16.c ecb6542862151c3e6509bbc00509b234562ae81e F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff @@ -2159,8 +2159,11 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 01868ebcd25fadb2034da234c0636e82d07c5abc902ef66493cadfc988e74d7b -R c017e3ff6a3cf5fef0c29004a344e6f7 -U drh -Z f4a73b0af78f34dd85f781f1eb7187c3 +P 709841f88c77276f09701bf38e25503c64b3a0afbe2fbf878136db12f31cbe21 +R 25ab10e7bacd9206b22870bd4ed39a9a +T *branch * digit-separators +T *sym-digit-separators * +T -sym-trunk * +U dan +Z ce3fc1dbdae9b70fcb4dc10489ba2fab # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index d23f19cb29..e6ba736181 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -709841f88c77276f09701bf38e25503c64b3a0afbe2fbf878136db12f31cbe21 \ No newline at end of file +401650aaccbc99246bd4e1ff37a28b78f528178aee2f294d87b9f7fecd7432bb \ No newline at end of file diff --git a/src/parse.y b/src/parse.y index 19491192e3..b0d03a04ee 100644 --- a/src/parse.y +++ b/src/parse.y @@ -1923,6 +1923,12 @@ filter_clause(A) ::= FILTER LP WHERE expr(X) RP. { A = X; } SPAN /* The span operator */ ERROR /* An expression containing an error */ . + +term(A) ::= QNUMBER(X). { + A=tokenExpr(pParse,@X,X); + sqlite3DequoteNumber(A); +} + /* There must be no more than 255 tokens defined above. If this grammar ** is extended with new rules and tokens, they must either be so few in ** number that TK_SPAN is no more than 255, or else the new tokens must diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 79a36e060e..c4aaf9d203 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -609,6 +609,8 @@ # define SQLITE_OMIT_ALTERTABLE #endif +#define SQLITE_DIGIT_SEPARATOR '_' + /* ** Return true (non-zero) if the input is an integer that is too large ** to fit in 32-bits. This macro is used inside of various testcase() @@ -4792,6 +4794,7 @@ int sqlite3ErrorToParser(sqlite3*,int); void sqlite3Dequote(char*); void sqlite3DequoteExpr(Expr*); void sqlite3DequoteToken(Token*); +void sqlite3DequoteNumber(Expr*); void sqlite3TokenInit(Token*,char*); int sqlite3KeywordCode(const unsigned char*, int); int sqlite3RunParser(Parse*, const char*); diff --git a/src/tokenize.c b/src/tokenize.c index f4d013deea..ae1f6da3f1 100644 --- a/src/tokenize.c +++ b/src/tokenize.c @@ -441,21 +441,34 @@ int sqlite3GetToken(const unsigned char *z, int *tokenType){ return i; } #endif - for(i=0; sqlite3Isdigit(z[i]); i++){} + for(i=0; 1; i++){ + if( sqlite3Isdigit(z[i])==0 ){ + if( z[i]==SQLITE_DIGIT_SEPARATOR ){ *tokenType = TK_QNUMBER; } + else{ break; } + } + } #ifndef SQLITE_OMIT_FLOATING_POINT if( z[i]=='.' ){ - i++; - while( sqlite3Isdigit(z[i]) ){ i++; } - *tokenType = TK_FLOAT; + if( *tokenType==TK_INTEGER ) *tokenType = TK_FLOAT; + for(i++; 1; i++){ + if( sqlite3Isdigit(z[i])==0 ){ + if( z[i]==SQLITE_DIGIT_SEPARATOR ){ *tokenType = TK_QNUMBER; } + else{ break; } + } + } } if( (z[i]=='e' || z[i]=='E') && ( sqlite3Isdigit(z[i+1]) || ((z[i+1]=='+' || z[i+1]=='-') && sqlite3Isdigit(z[i+2])) ) ){ - i += 2; - while( sqlite3Isdigit(z[i]) ){ i++; } - *tokenType = TK_FLOAT; + if( *tokenType==TK_INTEGER ) *tokenType = TK_FLOAT; + for(i+=2; 1; i++){ + if( sqlite3Isdigit(z[i])==0 ){ + if( z[i]==SQLITE_DIGIT_SEPARATOR ){ *tokenType = TK_QNUMBER; } + else{ break; } + } + } } #endif while( IdChar(z[i]) ){ diff --git a/src/util.c b/src/util.c index 207b901bad..24eff14e9f 100644 --- a/src/util.c +++ b/src/util.c @@ -311,6 +311,27 @@ void sqlite3DequoteExpr(Expr *p){ sqlite3Dequote(p->u.zToken); } +/* +** Expression p is a QINTEGER or QFLOAT (quoted integer or float). Dequote +** the value in p->u.zToken and set the type to INTEGER or FLOAT. "Quoted" +** integers or floats are those that contain '_' characters that must +** be removed before further processing. +*/ +void sqlite3DequoteNumber(Expr *p){ + if( p ){ + const char *pIn = p->u.zToken; + char *pOut = p->u.zToken; + assert( p->op==TK_QNUMBER ); + p->op = TK_INTEGER; + do { + if( *pIn!=SQLITE_DIGIT_SEPARATOR ){ + *pOut++ = *pIn; + if( *pIn=='e' || *pIn=='E' || *pIn=='.' ) p->op = TK_FLOAT; + } + }while( *pIn++ ); + } +} + /* ** If the input token p is quoted, try to adjust the token to remove ** the quotes. This is not always possible: diff --git a/test/literal.test b/test/literal.test index 7bbb8f0f7a..8537ab5935 100644 --- a/test/literal.test +++ b/test/literal.test @@ -44,4 +44,7 @@ test_literal 1.12 '-0xFF' text -0xFF test_literal 1.13 -'0xFF' integer 0 +test_literal 2.1 1_000 integer 1000 + + finish_test diff --git a/test/speedtest1.c b/test/speedtest1.c index 4f32580987..5709423818 100644 --- a/test/speedtest1.c +++ b/test/speedtest1.c @@ -2150,6 +2150,50 @@ void testset_debug1(void){ } } +/* +** This testset focuses on the speed of parsing numeric literals (integers +** and real numbers). This was added to test the impact of allowing "_" +** characters to appear in numeric SQL literals to make them easier to read. +** For example, "SELECT 1_000_000;" instead of "SELECT 1000000;". +*/ +void testset_parsenumber(void){ + const char *zSql1 = "SELECT 1, 12, 123, 1234, 12345, 123456"; + const char *zSql2 = "SELECT 8227256643844975616, 7932208612563860480, " + "2010730661871032832, 9138463067404021760, " + "2557616153664746496, 2557616153664746496"; + const char *zSql3 = "SELECT 1.0, 1.2, 1.23, 123.4, 1.2345, 1.23456"; + const char *zSql4 = "SELECT 8.227256643844975616, 7.932208612563860480, " + "2.010730661871032832, 9.138463067404021760, " + "2.557616153664746496, 2.557616153664746496"; + + const int NROW = 100*g.szTest; + int ii; + + speedtest1_begin_test(100, "parsing small integers"); + for(ii=0; ii #include @@ -2557,6 +2601,8 @@ int main(int argc, char **argv){ testset_fp(); }else if( strcmp(zThisTest,"trigger")==0 ){ testset_trigger(); + }else if( strcmp(zThisTest,"parsenumber")==0 ){ + testset_parsenumber(); }else if( strcmp(zThisTest,"rtree")==0 ){ #ifdef SQLITE_ENABLE_RTREE testset_rtree(6, 147); diff --git a/tool/speed-check.sh b/tool/speed-check.sh index 4cc25794a2..5d425c3b37 100644 --- a/tool/speed-check.sh +++ b/tool/speed-check.sh @@ -161,6 +161,9 @@ while test "$1" != ""; do --fp) SPEEDTEST_OPTS="$SPEEDTEST_OPTS --testset fp" ;; + --parsenumber) + SPEEDTEST_OPTS="$SPEEDTEST_OPTS --testset parsenumber" + ;; --stmtscanstatus) SPEEDTEST_OPTS="$SPEEDTEST_OPTS --stmtscanstatus" ;; From b23f61b73fcbb9e3e369b222c7c3559280a4f720 Mon Sep 17 00:00:00 2001 From: drh <> Date: Sat, 20 Jan 2024 16:29:19 +0000 Subject: [PATCH 022/430] Rig sqlite3_serialize() so that it will initialize a previously uninitialized database prior to serializing it, so that it does not have a zero-byte size and does not return NULL (except for OOM). [forum:/forumpost/498777780e16880a|Forum thread 498777780e16880a]. FossilOrigin-Name: e638d5e408ea2e189b6771d16bbc2e42c606e88e05fbea78079b6e39e41f344c --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/memdb.c | 8 ++++++++ test/memdb1.test | 12 ++++++++++++ 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 320c5bbcb4..a4427cb088 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C When\sdoing\sa\stext-affinity\scomparison\sbetween\stwo\svalues\swhere\sone\sor\sboth\nhave\sboth\sa\stext\sand\sa\snumeric\stype,\smake\ssure\sthe\snumeric\stype\sdoes\snot\nconfuse\sthe\sanswer.\s\sThis\sis\sa\sdeeper\sfix\sto\sthe\sproblem\sobserved\sby\n[forum:/forumpost/3776b48e71|forum\spose\s3776b48e71].\s\sThe\sproblem\sbisects\nto\s[25f2246be404f38b]\son\s2014-08-24,\sprior\sto\sversion\s3.8.7. -D 2024-01-20T15:13:13.896 +C Rig\ssqlite3_serialize()\sso\sthat\sit\swill\sinitialize\sa\spreviously\suninitialized\ndatabase\sprior\sto\sserializing\sit,\sso\sthat\sit\sdoes\snot\shave\sa\szero-byte\ssize\nand\sdoes\snot\sreturn\sNULL\s(except\sfor\sOOM).\n[forum:/forumpost/498777780e16880a|Forum\sthread\s498777780e16880a]. +D 2024-01-20T16:29:19.033 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -708,7 +708,7 @@ F src/mem1.c 3bb59158c38e05f6270e761a9f435bf19827a264c13d1631c58b84bdc96d73b2 F src/mem2.c c8bfc9446fd0798bddd495eb5d9dbafa7d4b7287d8c22d50a83ac9daa26d8a75 F src/mem3.c 30301196cace2a085cbedee1326a49f4b26deff0af68774ca82c1f7c06fda4f6 F src/mem5.c b7da5c10a726aacacc9ad7cdcb0667deec643e117591cc69cf9b4b9e7f3e96ff -F src/memdb.c 559c42e61eb70cd6d4bc692b042497133c6d96c09a3d514d92f3dac72268e223 +F src/memdb.c 16679def118b5fd75292a253166d3feba3ec9c6189205bf209643ecdb2174ecc F src/memjournal.c c283c6c95d940eb9dc70f1863eef3ee40382dbd35e5a1108026e7817c206e8a0 F src/msvc.h 80b35f95d93bf996ccb3e498535255f2ef1118c78764719a7cd15ab4106ccac9 F src/mutex.c 1b4c7e5e3621b510e0c18397210be27cd54c8084141144fbbafd003fde948e88 @@ -1396,7 +1396,7 @@ F test/malloctraceviewer.tcl 3e3ddf11e30d2b20f53aa16aa6615082fb24a100bea61cca721 F test/manydb.test 28385ae2087967aa05c38624cec7d96ec74feb3e F test/mem5.test c6460fba403c5703141348cd90de1c294188c68f F test/memdb.test c1f2a343ad14398d5d6debda6ea33e80d0dafcc7 -F test/memdb1.test 2c4e9cc10d21c6bf4e217d72b7f6b8ba9b2605971bb2c5e6df76018e189f98f5 +F test/memdb1.test bef8623da0c0c2d8d4e0426dee5a52008a5714860901f8bca7638830b2645dbe F test/memdb2.test 4ba1fc09e2f51df80d148a540e4a3fa66d0462e91167b27497084de4d1f6b5b4 F test/memjournal.test 70f3a00c7f84ee2978ad14e831231caa1e7f23915a2c54b4f775a021d5740c6c F test/memjournal2.test dbc2c5cb5f7b38950f4f6dc3e73fcecf0fcbed3fc32c7ce913bba164d288da1e @@ -2159,8 +2159,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 01868ebcd25fadb2034da234c0636e82d07c5abc902ef66493cadfc988e74d7b -R c017e3ff6a3cf5fef0c29004a344e6f7 +P 709841f88c77276f09701bf38e25503c64b3a0afbe2fbf878136db12f31cbe21 +R 6b35ed1d4541fe33e619d0defc51d4d4 U drh -Z f4a73b0af78f34dd85f781f1eb7187c3 +Z 0850c6fe7ffc6bdccabb75e3570a33ee # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index d23f19cb29..2ff1ab4571 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -709841f88c77276f09701bf38e25503c64b3a0afbe2fbf878136db12f31cbe21 \ No newline at end of file +e638d5e408ea2e189b6771d16bbc2e42c606e88e05fbea78079b6e39e41f344c \ No newline at end of file diff --git a/src/memdb.c b/src/memdb.c index 657cb9ca65..d83a51d54d 100644 --- a/src/memdb.c +++ b/src/memdb.c @@ -799,6 +799,14 @@ unsigned char *sqlite3_serialize( pOut = 0; }else{ sz = sqlite3_column_int64(pStmt, 0)*szPage; + if( sz==0 ){ + sqlite3_reset(pStmt); + sqlite3_exec(db, "BEGIN IMMEDIATE; COMMIT;", 0, 0, 0); + rc = sqlite3_step(pStmt); + if( rc==SQLITE_ROW ){ + sz = sqlite3_column_int64(pStmt, 0)*szPage; + } + } if( piSize ) *piSize = sz; if( mFlags & SQLITE_SERIALIZE_NOCOPY ){ pOut = 0; diff --git a/test/memdb1.test b/test/memdb1.test index 5e219a4c01..05d9fa04ed 100644 --- a/test/memdb1.test +++ b/test/memdb1.test @@ -267,4 +267,16 @@ if {[wal_is_capable]} { } {1 {database disk image is malformed}} } +# 2024-01-20 +# https://sqlite.org/forum/forumpost/498777780e16880a +# +# Make sure a database is initialized before serializing it. +# +reset_db +sqlite3 dbempty :memory: +do_test 900 { + set len [string length [dbempty serialize]] + expr {$len>0} +} 1 + finish_test From 2e12890732f8c23719a46e56175323cf7d1daccb Mon Sep 17 00:00:00 2001 From: drh <> Date: Sat, 20 Jan 2024 16:38:00 +0000 Subject: [PATCH 023/430] Make sure that %V and %G are testing for every since day in between 1970-01-01 and 2023-01-19. FossilOrigin-Name: 39c475f5fb86526622a715860385f0a3a4b2c18d8ef209779c423527e0639385 --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/date4.test | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index a4427cb088..a8079c2744 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Rig\ssqlite3_serialize()\sso\sthat\sit\swill\sinitialize\sa\spreviously\suninitialized\ndatabase\sprior\sto\sserializing\sit,\sso\sthat\sit\sdoes\snot\shave\sa\szero-byte\ssize\nand\sdoes\snot\sreturn\sNULL\s(except\sfor\sOOM).\n[forum:/forumpost/498777780e16880a|Forum\sthread\s498777780e16880a]. -D 2024-01-20T16:29:19.033 +C Make\ssure\sthat\s%V\sand\s%G\sare\stesting\sfor\severy\ssince\sday\sin\sbetween\s1970-01-01\nand\s2023-01-19. +D 2024-01-20T16:38:00.290 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -1033,7 +1033,7 @@ F test/dataversion1.test 6e5e86ac681f0782e766ebcb56c019ae001522d114e0e111e5ebf68 F test/date.test b1a5208e6a9c390cf1d1fa4e38a910386b427b0e27046901c6b0fb995d19800e F test/date2.test 7e12ec14aaf4d5e6294b4ba140445b0eca06ea50062a9c3a69c4ee13d0b6f8b1 F test/date3.test a1b77abf05c6772fe5ca2337cac1398892f2a41e62bce7e6be0f4a08a0e64ae5 -F test/date4.test 77b3781c28d3a5e181c6474315aa58e1f6cf79f5171a4e46e248837b506e7adf +F test/date4.test 75dc8401e8c0639a228cd26a6eaa4ff5ea8ccda912b9853d1c9462c476670e17 F test/dbdata.test 042f49acff3438f940eeba5868d3af080ae64ddf26ae78f80c92bec3ca7d8603 F test/dbfuzz.c 73047c920d6210e5912c87cdffd9a1c281d4252e F test/dbfuzz001.test 6c9a4622029d69dc38926f115864b055cb2f39badd25ec22cbfb130c8ba8e9c3 @@ -2159,8 +2159,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 709841f88c77276f09701bf38e25503c64b3a0afbe2fbf878136db12f31cbe21 -R 6b35ed1d4541fe33e619d0defc51d4d4 +P e638d5e408ea2e189b6771d16bbc2e42c606e88e05fbea78079b6e39e41f344c +R def255443f75553b73e601b4d3401144 U drh -Z 0850c6fe7ffc6bdccabb75e3570a33ee +Z f250ebbbb7ead57b6a863fb7b3b9221e # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 2ff1ab4571..d3659e6025 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e638d5e408ea2e189b6771d16bbc2e42c606e88e05fbea78079b6e39e41f344c \ No newline at end of file +39c475f5fb86526622a715860385f0a3a4b2c18d8ef209779c423527e0639385 \ No newline at end of file diff --git a/test/date4.test b/test/date4.test index 0dd06debb7..56a9090b1b 100644 --- a/test/date4.test +++ b/test/date4.test @@ -28,8 +28,8 @@ if {$tcl_platform(os)=="Linux"} { } else { set FMT {%d,%e,%F,%H,%I,%j,%p,%R,%u,%w,%W,%%} } -for {set i 0} {$i<=24854} {incr i} { - set TS [expr {$i*86401}] +for {set i 0} {$i<=24858} {incr i} { + set TS [expr {$i*86390}] do_execsql_test date4-$i { SELECT strftime($::FMT,$::TS,'unixepoch'); } [list [strftime $FMT $TS]] From 95295a7e9b59e90029ae7a90ebee1667c51a3139 Mon Sep 17 00:00:00 2001 From: dan Date: Sat, 20 Jan 2024 16:46:25 +0000 Subject: [PATCH 024/430] Add test cases for the new code on this branch. FossilOrigin-Name: 49f29a7b4f44f691ecf7a57b26477971e6ffaf2a0b1690b4926ffbb43fa3929b --- manifest | 17 +++++++---------- manifest.uuid | 2 +- src/tokenize.c | 7 +++++-- test/literal.test | 13 ++++++++++--- 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/manifest b/manifest index f2673bb861..85784dcc72 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Allow\s"_"\scharacters\sto\sappear\sfollowing\sany\sdigit\sin\san\sinteger\sor\sreal\sSQL\sliteral. -D 2024-01-20T16:18:04.854 +C Add\stest\scases\sfor\sthe\snew\scode\son\sthis\sbranch. +D 2024-01-20T16:46:25.186 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -800,7 +800,7 @@ F src/test_windirent.h da2e5b73c32d09905fbdd00f27cd802212a32a58ead882736fe4f5eb7 F src/test_window.c cdae419fdcea5bad6dcd9368c685abdad6deb59e9fc8b84b153de513d394ba3f F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9 F src/threads.c 4ae07fa022a3dc7c5beb373cf744a85d3c5c6c3c -F src/tokenize.c b3ab5ee644f3ac54e6a6a856cfb78bdb285e634fae39b38ce0f6e848305ca32e +F src/tokenize.c e0cdd971ebf7225cd617661d8198fc90a49559e21210af03bdf440e2fcba6b88 F src/treeview.c c6fc972683fd00f975d8b32a81c1f25d2fb7d4035366bf45c9f5622d3ccd70ee F src/trigger.c 0905b96b04bb6658509f711a8207287f1315cdbc3df1a1b13ba6483c8e341c81 F src/update.c 6904814dd62a7a93bbb86d9f1419c7f134a9119582645854ab02b36b676d9f92 @@ -1355,7 +1355,7 @@ F test/like2.test d3be15fefee3e02fc88942a9b98f26c5339bbdef7783c90023c092c4955fe3 F test/like3.test a76e5938fadbe6d32807284c796bafd869974a961057bc5fc5a28e06de98745c F test/limit.test 350f5d03c29e7dff9a2cde016f84f8d368d40bcd02fa2b2a52fa10c4bf3cbfaf F test/limit2.test 9409b033284642a859fafc95f29a5a6a557bd57c1f0d7c3f554bd64ed69df77e -F test/literal.test 9bf0ce5ca1034e3c6f83d5dff82abdedcfa1596cd843b2e4f93f58828e123046 +F test/literal.test 62415688179c0d586f3633482e6c8e441edb805cd73c306964cf39912a6bff0e F test/loadext.test faa4f6eed07a5aac35d57fdd7bc07f8fc82464cfd327567c10cf0ba3c86cde04 F test/loadext2.test 0408380b57adca04004247179837a18e866a74f7 F test/lock.test be4fe08118fb988fed741f429b7dd5d65e1c90db @@ -2159,11 +2159,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 709841f88c77276f09701bf38e25503c64b3a0afbe2fbf878136db12f31cbe21 -R 25ab10e7bacd9206b22870bd4ed39a9a -T *branch * digit-separators -T *sym-digit-separators * -T -sym-trunk * +P 401650aaccbc99246bd4e1ff37a28b78f528178aee2f294d87b9f7fecd7432bb +R f613ae2f01e87601e8fa7113cad6d125 U dan -Z ce3fc1dbdae9b70fcb4dc10489ba2fab +Z 0deb0f7f0bb54434edd39b41a13f24b4 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index e6ba736181..a510d65faa 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -401650aaccbc99246bd4e1ff37a28b78f528178aee2f294d87b9f7fecd7432bb \ No newline at end of file +49f29a7b4f44f691ecf7a57b26477971e6ffaf2a0b1690b4926ffbb43fa3929b \ No newline at end of file diff --git a/src/tokenize.c b/src/tokenize.c index ae1f6da3f1..592d6b8d8d 100644 --- a/src/tokenize.c +++ b/src/tokenize.c @@ -635,10 +635,13 @@ int sqlite3RunParser(Parse *pParse, const char *zSql){ if( tokenType>=TK_WINDOW ){ assert( tokenType==TK_SPACE || tokenType==TK_OVER || tokenType==TK_FILTER || tokenType==TK_ILLEGAL || tokenType==TK_WINDOW + || tokenType==TK_QNUMBER ); #else if( tokenType>=TK_SPACE ){ - assert( tokenType==TK_SPACE || tokenType==TK_ILLEGAL ); + assert( tokenType==TK_SPACE || tokenType==TK_ILLEGAL + || tokenType==TK_QNUMBER + ); #endif /* SQLITE_OMIT_WINDOWFUNC */ if( AtomicLoad(&db->u1.isInterrupted) ){ pParse->rc = SQLITE_INTERRUPT; @@ -671,7 +674,7 @@ int sqlite3RunParser(Parse *pParse, const char *zSql){ assert( n==6 ); tokenType = analyzeFilterKeyword((const u8*)&zSql[6], lastTokenParsed); #endif /* SQLITE_OMIT_WINDOWFUNC */ - }else{ + }else if( tokenType!=TK_QNUMBER ){ Token x; x.z = zSql; x.n = n; diff --git a/test/literal.test b/test/literal.test index 8537ab5935..01ea7b954c 100644 --- a/test/literal.test +++ b/test/literal.test @@ -43,8 +43,15 @@ test_literal 1.11 '0xFF' text 0xFF test_literal 1.12 '-0xFF' text -0xFF test_literal 1.13 -'0xFF' integer 0 - -test_literal 2.1 1_000 integer 1000 - +test_literal 2.1 1_000 integer 1000 +test_literal 2.2 1.1_1 real 1.11 +test_literal 2.3 1_0.1_1 real 10.11 +test_literal 2.4 1e1_000 real Inf +test_literal 2.5 123______456.7_8__9_ real 123456.789 +test_literal 2.6 9_223_372_036_854_775_807 integer 9223372036854775807 +test_literal 2.7 9_223_372_036_854_775_808 real 9.22337203685478e+18 +test_literal 2.8 -9_223_372_036_854_775_808 integer -9223372036854775808 + +test_literal 3.3 1e12 real 1000000000000.0 finish_test From 6c64e24f9d0675095a2c67a025e3db7bf4636821 Mon Sep 17 00:00:00 2001 From: drh <> Date: Sat, 20 Jan 2024 18:21:50 +0000 Subject: [PATCH 025/430] Fix a memory leak in new memdb1.test test cases that were added by [e638d5e408ea2e18]. No changes to SQLite itself. FossilOrigin-Name: bb2b7a658e0186d8b09199170db17744536602d8282b83c71ed969494d2ca465 --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/memdb1.test | 1 + 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index a8079c2744..165799a685 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Make\ssure\sthat\s%V\sand\s%G\sare\stesting\sfor\severy\ssince\sday\sin\sbetween\s1970-01-01\nand\s2023-01-19. -D 2024-01-20T16:38:00.290 +C Fix\sa\smemory\sleak\sin\snew\smemdb1.test\stest\scases\sthat\swere\sadded\sby\n[e638d5e408ea2e18].\s\sNo\schanges\sto\sSQLite\sitself. +D 2024-01-20T18:21:50.590 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -1396,7 +1396,7 @@ F test/malloctraceviewer.tcl 3e3ddf11e30d2b20f53aa16aa6615082fb24a100bea61cca721 F test/manydb.test 28385ae2087967aa05c38624cec7d96ec74feb3e F test/mem5.test c6460fba403c5703141348cd90de1c294188c68f F test/memdb.test c1f2a343ad14398d5d6debda6ea33e80d0dafcc7 -F test/memdb1.test bef8623da0c0c2d8d4e0426dee5a52008a5714860901f8bca7638830b2645dbe +F test/memdb1.test cd6b6b1632cf2f76c8a6f35be013f4011f3ab2c8d74d3d1424576f29bfa4a9a1 F test/memdb2.test 4ba1fc09e2f51df80d148a540e4a3fa66d0462e91167b27497084de4d1f6b5b4 F test/memjournal.test 70f3a00c7f84ee2978ad14e831231caa1e7f23915a2c54b4f775a021d5740c6c F test/memjournal2.test dbc2c5cb5f7b38950f4f6dc3e73fcecf0fcbed3fc32c7ce913bba164d288da1e @@ -2159,8 +2159,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P e638d5e408ea2e189b6771d16bbc2e42c606e88e05fbea78079b6e39e41f344c -R def255443f75553b73e601b4d3401144 +P 39c475f5fb86526622a715860385f0a3a4b2c18d8ef209779c423527e0639385 +R 74384040736e0977d7c5dfb4dce5d968 U drh -Z f250ebbbb7ead57b6a863fb7b3b9221e +Z 312b96149522d237d108c8a3641b64b6 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index d3659e6025..0ffeb5f5fe 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -39c475f5fb86526622a715860385f0a3a4b2c18d8ef209779c423527e0639385 \ No newline at end of file +bb2b7a658e0186d8b09199170db17744536602d8282b83c71ed969494d2ca465 \ No newline at end of file diff --git a/test/memdb1.test b/test/memdb1.test index 05d9fa04ed..e6820da4a2 100644 --- a/test/memdb1.test +++ b/test/memdb1.test @@ -278,5 +278,6 @@ do_test 900 { set len [string length [dbempty serialize]] expr {$len>0} } 1 +dbempty close finish_test From 514bf99b6aa18f05f78d02b9b3afddc51d006eca Mon Sep 17 00:00:00 2001 From: drh <> Date: Sat, 20 Jan 2024 18:26:28 +0000 Subject: [PATCH 026/430] Simplifications to the strftime() logic. FossilOrigin-Name: aaa5a044d8a4942278eb4269fa8c7252f9f1dc161408e618e7c97c55a12283ff --- manifest | 12 +++++----- manifest.uuid | 2 +- src/date.c | 64 ++++++++++++++++++++++++++++++--------------------- 3 files changed, 45 insertions(+), 33 deletions(-) diff --git a/manifest b/manifest index 165799a685..821d38be63 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\smemory\sleak\sin\snew\smemdb1.test\stest\scases\sthat\swere\sadded\sby\n[e638d5e408ea2e18].\s\sNo\schanges\sto\sSQLite\sitself. -D 2024-01-20T18:21:50.590 +C Simplifications\sto\sthe\sstrftime()\slogic. +D 2024-01-20T18:26:28.712 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -684,7 +684,7 @@ F src/build.c e7d9044592eeeea8e78d8ae53ca8d31fd6e92ca0d4f53e2f2e8ccf7352e0b04b F src/callback.c db3a45e376deff6a16c0058163fe0ae2b73a2945f3f408ca32cf74960b28d490 F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e F src/ctime.c 23331529e654be40ca97d171cbbffe9b3d4c71cc53b78fe5501230675952da8b -F src/date.c 35ea61eb7ab5b918db7a96725346234bf8fb5bc161c7b868c20a7f24f351a2da +F src/date.c 48a110a2a267398ad9b04fe3db69dfa194f91719f94fa55cd560e03510f963e6 F src/dbpage.c 80e46e1df623ec40486da7a5086cb723b0275a6e2a7b01d9f9b5da0f04ba2782 F src/dbstat.c 3b677254d512fcafd4d0b341bf267b38b235ccfddbef24f9154e19360fa22e43 F src/delete.c cb766727c78e715f9fb7ec8a7d03658ed2a3016343ca687acfcec9083cdca500 @@ -2159,8 +2159,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 39c475f5fb86526622a715860385f0a3a4b2c18d8ef209779c423527e0639385 -R 74384040736e0977d7c5dfb4dce5d968 +P bb2b7a658e0186d8b09199170db17744536602d8282b83c71ed969494d2ca465 +R 8518c96f5a8faebc2a9945073340f70a U drh -Z 312b96149522d237d108c8a3641b64b6 +Z f670e53a135b10311c59f478b3527211 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 0ffeb5f5fe..e3a0693990 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -bb2b7a658e0186d8b09199170db17744536602d8282b83c71ed969494d2ca465 \ No newline at end of file +aaa5a044d8a4942278eb4269fa8c7252f9f1dc161408e618e7c97c55a12283ff \ No newline at end of file diff --git a/src/date.c b/src/date.c index 76e1894f8d..e468925d5e 100644 --- a/src/date.c +++ b/src/date.c @@ -1237,10 +1237,14 @@ static void dateFunc( } /* -** Compute the one-based day of the year for the DateTime pDate. -** Jan01 = 1, Jan02 = 2, ... Dec31 = 356 or 366. +** Compute the number of days after the most recent January 1. +** +** In other words, compute the zero-based day number for the +** current year: +** +** Jan01 = 0, Jan02 = 2, ... Dec31 = 364 or 365. */ -static int dayOfYear(DateTime *pDate){ +static int daysAfterJan01(DateTime *pDate){ DateTime jan01 = *pDate; assert( jan01.validYMD ); assert( jan01.validHMS ); @@ -1249,18 +1253,33 @@ static int dayOfYear(DateTime *pDate){ jan01.M = 1; jan01.D = 1; computeJD(&jan01); - return (int)((pDate->iJD-jan01.iJD+43200000)/86400000) + 1; + return (int)((pDate->iJD-jan01.iJD+43200000)/86400000); } /* -** Return the day of the week. 1==Monday, 2=Tues, ..., 7=Sunday. +** Return the number of days after the most recent Monday. +** +** In other words, return the day of the week according +** to this code: +** +** 0=Monday, 1=Tuesday, 2=Wednesday, ..., 6=Sunday. +*/ +static int daysAfterMonday(DateTime *pDate){ + assert( pDate->validJD ); + return (int)((pDate->iJD+43200000)/86400000) % 7; +} + +/* +** Return the number of days after the most recent Sunday. +** +** In other words, return the day of the week according +** to this code: +** +** 0=Sunday, 1=Monday, 2=Tues, ..., 6=Saturday */ -static int dayOfWeek(DateTime *pDate){ - int w; +static int daysAfterSunday(DateTime *pDate){ assert( pDate->validJD ); - w = ((pDate->iJD+129600000)/86400000) % 7; - if( w==0 ) w = 7; - return w; + return (int)((pDate->iJD+129600000)/86400000) % 7; } /* @@ -1344,7 +1363,7 @@ static void strftimeFunc( DateTime y = x; assert( y.validJD ); /* Move y so that it is the Thursday in the same week as x */ - y.iJD += (4 - dayOfWeek(&x))*86400000; + y.iJD += (3 - daysAfterMonday(&x))*86400000; y.validYMD = 0; computeYMD(&y); if( cf=='g' ){ @@ -1368,8 +1387,7 @@ static void strftimeFunc( break; } case 'j': { /* Day of year. Jan01==1, Jan02==2, and so forth */ - int nDay = dayOfYear(&x); - sqlite3_str_appendf(&sRes,"%03d",nDay); + sqlite3_str_appendf(&sRes,"%03d",daysAfterJan01(&x)+1); break; } case 'J': { /* Julian day number. (Non-standard) */ @@ -1417,35 +1435,29 @@ static void strftimeFunc( } case 'u': /* Day of week. 1 to 7. Monday==1, Sunday==7 */ case 'w': { /* Day of week. 0 to 6. Sunday==0, Monday==1 */ - char c = (char)(((x.iJD+129600000)/86400000) % 7) + '0'; + char c = (char)daysAfterSunday(&x) + '0'; if( c=='0' && cf=='u' ) c = '7'; sqlite3_str_appendchar(&sRes, 1, c); break; } case 'U': { /* Week num. 00-53. First Sun of the year is week 01 */ - int wd; /* 0=Sunday, 1=Monday, 2=Tuesday, ... 7=Saturday */ - int nDay; /* Day of the year. 0..364 or 0..365 for leapyears */ - nDay = dayOfYear(&x); - wd = (int)(((x.iJD+43200000)/86400000 + 1)%7); - sqlite3_str_appendf(&sRes,"%02d",(nDay+6-wd)/7); + sqlite3_str_appendf(&sRes,"%02d", + (daysAfterJan01(&x)-daysAfterSunday(&x)+7)/7); break; } case 'V': { /* Week num. 01-53. First week with a Thur is week 01 */ DateTime y = x; /* Adjust y so that is the Thursday in the same week as x */ assert( y.validJD ); - y.iJD += (4 - dayOfWeek(&x))*86400000; + y.iJD += (3 - daysAfterMonday(&x))*86400000; y.validYMD = 0; computeYMD(&y); - sqlite3_str_appendf(&sRes,"%02d", (dayOfYear(&y)-1)/7+1); + sqlite3_str_appendf(&sRes,"%02d", daysAfterJan01(&y)/7+1); break; } case 'W': { /* Week num. 00-53. First Mon of the year is week 01 */ - int wd; /* 0=Monday, 1=Tuesday, ... 6=Sunday */ - int nDay; /* Day of the year. 0..364 or 0..365 for leapyears */ - nDay = dayOfYear(&x); - wd = (int)(((x.iJD+43200000)/86400000)%7); - sqlite3_str_appendf(&sRes,"%02d",(nDay+6-wd)/7); + sqlite3_str_appendf(&sRes,"%02d", + (daysAfterJan01(&x)-daysAfterMonday(&x)+7)/7); break; } case 'Y': { From f28bff745c778598ef1740e4cbb1a44b176aac83 Mon Sep 17 00:00:00 2001 From: dan Date: Sat, 20 Jan 2024 18:41:13 +0000 Subject: [PATCH 027/430] Ensure that values generated by DEFAULT clauses that specify real numbers that can be expressed as 64-bit integers (e.g. -1234.0) are not silently converted to integers. FossilOrigin-Name: 298d6977285c71be917896bc875a8a26d985dcf0a74069b7c4d290e8ff0ac618 --- manifest | 20 ++++++++++---------- manifest.uuid | 2 +- src/vdbemem.c | 13 +++++++++++-- test/alter2.test | 8 ++++---- test/literal.test | 6 ++++++ test/tkt-8454a207b9.test | 2 +- 6 files changed, 33 insertions(+), 18 deletions(-) diff --git a/manifest b/manifest index 821d38be63..eec8b0a2e9 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Simplifications\sto\sthe\sstrftime()\slogic. -D 2024-01-20T18:26:28.712 +C Ensure\sthat\svalues\sgenerated\sby\sDEFAULT\sclauses\sthat\sspecify\sreal\snumbers\sthat\scan\sbe\sexpressed\sas\s64-bit\sintegers\s(e.g.\s-1234.0)\sare\snot\ssilently\sconverted\sto\sintegers. +D 2024-01-20T18:41:13.528 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -814,7 +814,7 @@ F src/vdbeInt.h 949669dfd8a41550d27dcb905b494f2ccde9a2e6c1b0b04daa1227e2e74c2b2c F src/vdbeapi.c 8f57d60c89da0b60e6d4e272358c511f6bae4e24330bdb11f8b42f986d1bf21b F src/vdbeaux.c c5a471b34e9c4cfc0295a3e10734fd197670ffaebcb742f284c8e17e8026ceea F src/vdbeblob.c 13f9287b55b6356b4b1845410382d6bede203ceb29ef69388a4a3d007ffacbe5 -F src/vdbemem.c bbe87b3e851bcc5cad2a9329ad0387432e41ddf2f98f2682c524ad676b739987 +F src/vdbemem.c 3e37dab421b74e9ce55c1e88fbc7bc6fead590b5ab258bc684f8b70abb1d6e71 F src/vdbesort.c 237840ca1947511fa59bd4e18b9eeae93f2af2468c34d2427b059f896230a547 F src/vdbetrace.c fe0bc29ebd4e02c8bc5c1945f1d2e6be5927ec12c06d89b03ef2a4def34bf823 F src/vdbevtab.c 2143db7db0ceed69b21422581f434baffc507a08d831565193a7a02882a1b6a7 @@ -838,7 +838,7 @@ F test/aggorderby.test cc3abf5de64d46ff66395ca8c2346b66c2576d5aedb7bffc5b0742508 F test/alias.test 4529fbc152f190268a15f9384a5651bbbabc9d87 F test/all.test 2ecb8bbd52416642e41c9081182a8df05d42c75637afd4488aace78cc4b69e13 F test/alter.test 3c00eff1e2036b9f93e9cd0f3d3e63750ac87ecb5bc71b9d7bd07cbf2ac4c494 -F test/alter2.test a966ccfcddf9ce0a4e0e6ff1aca9e6e7948e0e242cd7e43fc091948521807687 +F test/alter2.test 7e3d26ab409df52df887b366a63902c3429b935c41cb962fd58ffc25784f2f19 F test/alter3.test ffc4ab29ce78a3517a66afd69b2730667e3471622509c283b2bd4c46f680fba3 F test/alter4.test 716caa071dd8a3c6d57225778d15d3c3cbf5e34b2e84ae44199aeb2bbf50a707 F test/alterauth.test 63442ba61ceb0c1eeb63aac1f4f5cebfa509d352276059d27106ae256bafc959 @@ -1355,7 +1355,7 @@ F test/like2.test d3be15fefee3e02fc88942a9b98f26c5339bbdef7783c90023c092c4955fe3 F test/like3.test a76e5938fadbe6d32807284c796bafd869974a961057bc5fc5a28e06de98745c F test/limit.test 350f5d03c29e7dff9a2cde016f84f8d368d40bcd02fa2b2a52fa10c4bf3cbfaf F test/limit2.test 9409b033284642a859fafc95f29a5a6a557bd57c1f0d7c3f554bd64ed69df77e -F test/literal.test 31ef70d425c39b993d0dd61b3f4c65d30b7491e8b3dbbd2d8a23b78b1e8931ca +F test/literal.test 12e3c865a9e20f984240dbfb362be2a53ad5ca4ee25a6d429cf059115a9ac48f F test/loadext.test faa4f6eed07a5aac35d57fdd7bc07f8fc82464cfd327567c10cf0ba3c86cde04 F test/loadext2.test 0408380b57adca04004247179837a18e866a74f7 F test/lock.test be4fe08118fb988fed741f429b7dd5d65e1c90db @@ -1715,7 +1715,7 @@ F test/tkt-7a31705a7e6.test 9e9c057b6a9497c8f7ba7b16871029414ccf6550e7345d9085d6 F test/tkt-7bbfb7d442.test e87b59e620700b5a52ecd92f05d56686c1cad9e1aa17456eada55e0bb821b698 F test/tkt-80ba201079.test 105a721e6aad0ae3c5946d7615d1e4d03f6145b8 F test/tkt-80e031a00f.test 7c93af53f43527f50020983a4bcc39b077e77c7362d7af8e04a5fd155fe5e829 -F test/tkt-8454a207b9.test aff2e76143cfa443ddce6f7d85968a2e9b57a3deb0b881b730120740555f9e2f +F test/tkt-8454a207b9.test ead80b7a01438ca1436cee029694a96c821346cf1e24f06de12f8172e139ddbb F test/tkt-868145d012.test a5f941107ece6a64410ca4755c6329b7eb57a356 F test/tkt-8c63ff0ec.test 258b7fc8d7e4e1cb5362c7d65c143528b9c4cbed F test/tkt-91e2e8ba6f.test 08c4f94ae07696b05c9b822da0b4e5337a2f54c5 @@ -2159,8 +2159,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P bb2b7a658e0186d8b09199170db17744536602d8282b83c71ed969494d2ca465 -R 8518c96f5a8faebc2a9945073340f70a -U drh -Z f670e53a135b10311c59f478b3527211 +P aaa5a044d8a4942278eb4269fa8c7252f9f1dc161408e618e7c97c55a12283ff +R 363a8d4d24bb7774a5f7eceb24c4f650 +U dan +Z ee966b48b47570fa6886cd7583990b8c # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index e3a0693990..3883df6b7b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -aaa5a044d8a4942278eb4269fa8c7252f9f1dc161408e618e7c97c55a12283ff \ No newline at end of file +298d6977285c71be917896bc875a8a26d985dcf0a74069b7c4d290e8ff0ac618 \ No newline at end of file diff --git a/src/vdbemem.c b/src/vdbemem.c index 2d10cda8d5..cbc6712bfd 100644 --- a/src/vdbemem.c +++ b/src/vdbemem.c @@ -1662,8 +1662,17 @@ static int valueFromExpr( sqlite3ValueSetStr(pVal, -1, zVal, SQLITE_UTF8, SQLITE_DYNAMIC); } } - if( (op==TK_INTEGER || op==TK_FLOAT ) && affinity==SQLITE_AFF_BLOB ){ - sqlite3ValueApplyAffinity(pVal, SQLITE_AFF_NUMERIC, SQLITE_UTF8); + if( affinity==SQLITE_AFF_BLOB ){ + if( op==TK_FLOAT ){ + assert( pVal && pVal->z && pVal->flags==(MEM_Str|MEM_Term) ); + sqlite3AtoF(pVal->z, &pVal->u.r, pVal->n, SQLITE_UTF8); + pVal->flags = MEM_Real; + }else if( op==TK_INTEGER ){ + /* This case is required by -9223372036854775808 and other strings + ** that look like integers but cannot be handled by the + ** sqlite3DecOrHexToI64() call above. */ + sqlite3ValueApplyAffinity(pVal, SQLITE_AFF_NUMERIC, SQLITE_UTF8); + } }else{ sqlite3ValueApplyAffinity(pVal, affinity, SQLITE_UTF8); } diff --git a/test/alter2.test b/test/alter2.test index aae0061ad4..20b75b59ee 100644 --- a/test/alter2.test +++ b/test/alter2.test @@ -371,7 +371,7 @@ do_test alter2-7.5 { execsql { SELECT a, typeof(a), b, typeof(b), c, typeof(c) FROM t1 LIMIT 1; } -} {1 integer -123 integer 5 text} +} {1 integer -123.0 real 5 text} #----------------------------------------------------------------------- # Test that UPDATE trigger tables work with default values, and that when @@ -397,11 +397,11 @@ do_test alter2-8.2 { UPDATE t1 SET c = 10 WHERE a = 1; SELECT a, typeof(a), b, typeof(b), c, typeof(c) FROM t1 LIMIT 1; } -} {1 integer -123 integer 10 text} +} {1 integer -123.0 real 10 text} ifcapable trigger { do_test alter2-8.3 { set ::val - } {-123 integer 5 text -123 integer 10 text} + } {-123.0 real 5 text -123.0 real 10 text} } #----------------------------------------------------------------------- @@ -425,7 +425,7 @@ ifcapable trigger { DELETE FROM t1 WHERE a = 2; } set ::val - } {-123 integer 5 text} + } {-123.0 real 5 text} } #----------------------------------------------------------------------- diff --git a/test/literal.test b/test/literal.test index 7bbb8f0f7a..4e957c05db 100644 --- a/test/literal.test +++ b/test/literal.test @@ -43,5 +43,11 @@ test_literal 1.11 '0xFF' text 0xFF test_literal 1.12 '-0xFF' text -0xFF test_literal 1.13 -'0xFF' integer 0 +test_literal 1.14 -9223372036854775808 integer -9223372036854775808 + +test_literal 2.1 1e12 real 1000000000000.0 +test_literal 2.2 1.0 real 1.0 +test_literal 2.3 1e1000 real Inf +test_literal 2.4 -1e1000 real -Inf finish_test diff --git a/test/tkt-8454a207b9.test b/test/tkt-8454a207b9.test index 20e142057d..42b95c8f53 100644 --- a/test/tkt-8454a207b9.test +++ b/test/tkt-8454a207b9.test @@ -49,7 +49,7 @@ do_test tkt-8454a207b9.4 { ALTER TABLE t1 ADD COLUMN e DEFAULT -123.0; SELECT e, typeof(e) FROM t1; } -} {-123 integer} +} {-123.0 real} do_test tkt-8454a207b9.5 { db eval { ALTER TABLE t1 ADD COLUMN f DEFAULT -123.5; From 199b0b2d6ef338a444ad85c39ea79012a8740369 Mon Sep 17 00:00:00 2001 From: drh <> Date: Sun, 21 Jan 2024 21:20:33 +0000 Subject: [PATCH 028/430] Fix a harmless typo in a comment. FossilOrigin-Name: 382a8f94bffef3e5f715116e363a30e21e2c53cd42d4959dfbe90c4624143e6d --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/date.c | 3 ++- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index eec8b0a2e9..517067f287 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Ensure\sthat\svalues\sgenerated\sby\sDEFAULT\sclauses\sthat\sspecify\sreal\snumbers\sthat\scan\sbe\sexpressed\sas\s64-bit\sintegers\s(e.g.\s-1234.0)\sare\snot\ssilently\sconverted\sto\sintegers. -D 2024-01-20T18:41:13.528 +C Fix\sa\sharmless\stypo\sin\sa\scomment. +D 2024-01-21T21:20:33.306 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -684,7 +684,7 @@ F src/build.c e7d9044592eeeea8e78d8ae53ca8d31fd6e92ca0d4f53e2f2e8ccf7352e0b04b F src/callback.c db3a45e376deff6a16c0058163fe0ae2b73a2945f3f408ca32cf74960b28d490 F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e F src/ctime.c 23331529e654be40ca97d171cbbffe9b3d4c71cc53b78fe5501230675952da8b -F src/date.c 48a110a2a267398ad9b04fe3db69dfa194f91719f94fa55cd560e03510f963e6 +F src/date.c 90df32c2d8b2a38dd2e83d32e47802629305c4882fb2ec75c9ecdcd75b68bcb2 F src/dbpage.c 80e46e1df623ec40486da7a5086cb723b0275a6e2a7b01d9f9b5da0f04ba2782 F src/dbstat.c 3b677254d512fcafd4d0b341bf267b38b235ccfddbef24f9154e19360fa22e43 F src/delete.c cb766727c78e715f9fb7ec8a7d03658ed2a3016343ca687acfcec9083cdca500 @@ -2159,8 +2159,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P aaa5a044d8a4942278eb4269fa8c7252f9f1dc161408e618e7c97c55a12283ff -R 363a8d4d24bb7774a5f7eceb24c4f650 -U dan -Z ee966b48b47570fa6886cd7583990b8c +P 298d6977285c71be917896bc875a8a26d985dcf0a74069b7c4d290e8ff0ac618 +R 6efa1c82cfa2e7d17b14637b7f3e1900 +U drh +Z 096bcae3083b69021bc23dacf629858d # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 3883df6b7b..91dcb94d92 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -298d6977285c71be917896bc875a8a26d985dcf0a74069b7c4d290e8ff0ac618 \ No newline at end of file +382a8f94bffef3e5f715116e363a30e21e2c53cd42d4959dfbe90c4624143e6d \ No newline at end of file diff --git a/src/date.c b/src/date.c index e468925d5e..026d83391a 100644 --- a/src/date.c +++ b/src/date.c @@ -1242,7 +1242,8 @@ static void dateFunc( ** In other words, compute the zero-based day number for the ** current year: ** -** Jan01 = 0, Jan02 = 2, ... Dec31 = 364 or 365. +** Jan01 = 0, Jan02 = 1, ..., Jan31 = 30, Feb01 = 31, ... +** Dec31 = 364 or 365. */ static int daysAfterJan01(DateTime *pDate){ DateTime jan01 = *pDate; From 05ab0f72c34e705ee10097ac243abb11d52c3a5e Mon Sep 17 00:00:00 2001 From: larrybr Date: Mon, 22 Jan 2024 01:11:24 +0000 Subject: [PATCH 029/430] Make CLI .dump immune to pragma reverse_unordered_selects, as reported in [forum:/forumpost/c42be01880e961eb|Forum thread "Missing ORDER BY in .dump?"] FossilOrigin-Name: 488caed24453fcef6fddcf40353e3b44cf37fb9d21e0ed743d39d60cbff020a7 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/shell.c.in | 3 ++- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 517067f287..280e8dc3bd 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sharmless\stypo\sin\sa\scomment. -D 2024-01-21T21:20:33.306 +C Make\sCLI\s.dump\simmune\sto\spragma\sreverse_unordered_selects,\sas\sreported\sin\s[forum:/forumpost/c42be01880e961eb|Forum\sthread\s"Missing\sORDER\sBY\sin\s.dump?"] +D 2024-01-22T01:11:24.847 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -739,7 +739,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c e25f51a473a5f30a0d978e4df2aaa98aeec84eac29ecae1ad4708a6c3e669345 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c f1a81ff4f8e9e76c224e2ab3a4baa799add0db22158c7fcede65d8cc4a6fa2da -F src/shell.c.in d1ed426aae2d547932971e8019939cacb4dfda8258e45b8924b250e488e2d53d +F src/shell.c.in 5ea8c6b0057bfe3bcdff31949fe72aa231ae429047c421ea1b168af6825a4890 F src/sqlite.h.in 61a60b4ea04db8ead15e1579b20b64cb56e9f55d52c5f9f9694de630110593a3 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 @@ -2159,8 +2159,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 298d6977285c71be917896bc875a8a26d985dcf0a74069b7c4d290e8ff0ac618 -R 6efa1c82cfa2e7d17b14637b7f3e1900 -U drh -Z 096bcae3083b69021bc23dacf629858d +P 382a8f94bffef3e5f715116e363a30e21e2c53cd42d4959dfbe90c4624143e6d +R 0c3ae1bf61b2c5523c6e506b1fe8b74c +U larrybr +Z df2931d680c73052f2016399cfecfafe # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 91dcb94d92..d376c3e270 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -382a8f94bffef3e5f715116e363a30e21e2c53cd42d4959dfbe90c4624143e6d \ No newline at end of file +488caed24453fcef6fddcf40353e3b44cf37fb9d21e0ed743d39d60cbff020a7 \ No newline at end of file diff --git a/src/shell.c.in b/src/shell.c.in index da3b9f8706..02850691d9 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -8375,7 +8375,8 @@ static int do_meta_command(char *zLine, ShellState *p){ zSql = sqlite3_mprintf( "SELECT sql FROM sqlite_schema AS o " "WHERE (%s) AND sql NOT NULL" - " AND type IN ('index','trigger','view')", + " AND type IN ('index','trigger','view') " + "ORDER BY type COLLATE NOCASE DESC", zLike ); run_table_dump_query(p, zSql); From 17589f781142afbe9ccb00fb6912270a50e2f710 Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 22 Jan 2024 11:12:38 +0000 Subject: [PATCH 030/430] Fix test script literal.test so that it works with SQLITE_OMIT_ALTER_TABLE builds. FossilOrigin-Name: b57327be4be9638f5ee834a6c9e06135aaef9e499516f8b53f927ffe81033f61 --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/literal.test | 19 ++++++++++++++----- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/manifest b/manifest index 6c05005d18..d5565a35b7 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Merge\strunk\schanges\sinto\sthis\sbranch. -D 2024-01-20T18:45:30.244 +C Fix\stest\sscript\sliteral.test\sso\sthat\sit\sworks\swith\sSQLITE_OMIT_ALTER_TABLE\sbuilds. +D 2024-01-22T11:12:38.218 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -1355,7 +1355,7 @@ F test/like2.test d3be15fefee3e02fc88942a9b98f26c5339bbdef7783c90023c092c4955fe3 F test/like3.test a76e5938fadbe6d32807284c796bafd869974a961057bc5fc5a28e06de98745c F test/limit.test 350f5d03c29e7dff9a2cde016f84f8d368d40bcd02fa2b2a52fa10c4bf3cbfaf F test/limit2.test 9409b033284642a859fafc95f29a5a6a557bd57c1f0d7c3f554bd64ed69df77e -F test/literal.test 17d21dda2f877018a02c28e2a85947b82ed638f2ca5ef3fa47c92359f02520a3 +F test/literal.test db71a7616dc027badf8d8f7ac6e23e8655915eb51b187c40a0a6e667aed495b7 F test/loadext.test faa4f6eed07a5aac35d57fdd7bc07f8fc82464cfd327567c10cf0ba3c86cde04 F test/loadext2.test 0408380b57adca04004247179837a18e866a74f7 F test/lock.test be4fe08118fb988fed741f429b7dd5d65e1c90db @@ -2159,8 +2159,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 49f29a7b4f44f691ecf7a57b26477971e6ffaf2a0b1690b4926ffbb43fa3929b 298d6977285c71be917896bc875a8a26d985dcf0a74069b7c4d290e8ff0ac618 -R d4f77c6633329aa6323323954676adb8 +P 03ade4a810516ff84bc5c1a716b0e454cc8a89374100415ff21a82449112811b +R 4dc96dbb63712d691b87fb65e2e995c9 U dan -Z 02dbf9257e243f2009f448d2d8147299 +Z 060bde75456debf514e23a793c3f90b5 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 5f5c21e2d7..902662ca4b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -03ade4a810516ff84bc5c1a716b0e454cc8a89374100415ff21a82449112811b \ No newline at end of file +b57327be4be9638f5ee834a6c9e06135aaef9e499516f8b53f927ffe81033f61 \ No newline at end of file diff --git a/test/literal.test b/test/literal.test index e29789d37d..3140eedf2a 100644 --- a/test/literal.test +++ b/test/literal.test @@ -19,12 +19,21 @@ set ::testprefix literal proc test_literal {tn lit type val} { do_execsql_test $tn.1 "SELECT typeof( $lit ), $lit" [list $type $val] - do_execsql_test $tn.2 " + ifcapable altertable { + do_execsql_test $tn.2 " + DROP TABLE IF EXISTS x1; + CREATE TABLE x1(a); + INSERT INTO x1 VALUES(123); + ALTER TABLE x1 ADD COLUMN b DEFAULT $lit ; + SELECT typeof(b), b FROM x1; + " [list $type $val] + } + + do_execsql_test $tn.3 " DROP TABLE IF EXISTS x1; - CREATE TABLE x1(a); - INSERT INTO x1 VALUES(123); - ALTER TABLE x1 ADD COLUMN b DEFAULT $lit ; - SELECT typeof(b), b FROM x1; + CREATE TABLE x1(a DEFAULT $lit); + INSERT INTO x1 DEFAULT VALUES; + SELECT typeof(a), a FROM x1; " [list $type $val] } From 3b799b0fca14c36b0c2c62a699fea08b05013718 Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 22 Jan 2024 12:30:17 +0000 Subject: [PATCH 031/430] Add a notice to the user-authentication documentation to say that the extension is deprecated and may disappear in the future. FossilOrigin-Name: fe6fc7b91ad1771a2d2d4e3d9d60831b3056d528a700932bf11a336c7e3414a2 --- ext/userauth/user-auth.txt | 12 ++++++++++++ manifest | 14 +++++++------- manifest.uuid | 2 +- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/ext/userauth/user-auth.txt b/ext/userauth/user-auth.txt index ba4eabc137..66caca3e1e 100644 --- a/ext/userauth/user-auth.txt +++ b/ext/userauth/user-auth.txt @@ -1,3 +1,15 @@ +*********************************** NOTICE ************************************ +* This extension is deprecated. The SQLite developers do not maintain this * +* extension. At some point in the future, it might disappear from the source * +* tree. * +* * +* If you are using this extension and think it should be supported moving * +* forward, visit the SQLite Forum (https://sqlite.org/forum) and make your * +* case. * +* * +* This deprecation notice was added on 2024-01-22. * +******************************************************************************* + Activate the user authentication logic by including the ext/userauth/userauth.c source code file in the build and adding the -DSQLITE_USER_AUTHENTICATION compile-time option. diff --git a/manifest b/manifest index 280e8dc3bd..ff616768bd 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Make\sCLI\s.dump\simmune\sto\spragma\sreverse_unordered_selects,\sas\sreported\sin\s[forum:/forumpost/c42be01880e961eb|Forum\sthread\s"Missing\sORDER\sBY\sin\s.dump?"] -D 2024-01-22T01:11:24.847 +C Add\sa\snotice\sto\sthe\suser-authentication\sdocumentation\sto\ssay\sthat\sthe\nextension\sis\sdeprecated\sand\smay\sdisappear\sin\sthe\sfuture. +D 2024-01-22T12:30:17.497 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -572,7 +572,7 @@ F ext/session/sqlite3session.c 829d468f0f3d2710aace56b0116a7ca3f414683ce78e3125a F ext/session/sqlite3session.h 4cf19a51975746d7cff2fdd74db8b769c570958e1c3639ac150d824ac1553b3e F ext/session/test_session.c 7b94ad945cd4afe6c73ee935aeb3d44b4446186e1729362af616c7695a5283d9 F ext/userauth/sqlite3userauth.h 7f3ea8c4686db8e40b0a0e7a8e0b00fac13aa7a3 -F ext/userauth/user-auth.txt e6641021a9210364665fe625d067617d03f27b04 +F ext/userauth/user-auth.txt 9a3bdae6b5d2746056d7611ae1d81fa888772ef716b05d20497cdb4f7992e997 F ext/userauth/userauth.c 7f00cded7dcaa5d47f54539b290a43d2e59f4b1eb5f447545fa865f002fc80cb F ext/wasm/EXPORTED_FUNCTIONS.fiddle.in 27450c8b8c70875a260aca55435ec927068b34cef801a96205adb81bdcefc65c F ext/wasm/GNUmakefile 867c903a27fa0d53a3bf1b01d8c7bb713456f87e0939c3cac9f07faa68f58734 @@ -2159,8 +2159,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 382a8f94bffef3e5f715116e363a30e21e2c53cd42d4959dfbe90c4624143e6d -R 0c3ae1bf61b2c5523c6e506b1fe8b74c -U larrybr -Z df2931d680c73052f2016399cfecfafe +P 488caed24453fcef6fddcf40353e3b44cf37fb9d21e0ed743d39d60cbff020a7 +R ea5433aac763e6ce8bcfabec2e6890c2 +U drh +Z 559db82f0095218d6f000421c012f60a # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index d376c3e270..54eab787fa 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -488caed24453fcef6fddcf40353e3b44cf37fb9d21e0ed743d39d60cbff020a7 \ No newline at end of file +fe6fc7b91ad1771a2d2d4e3d9d60831b3056d528a700932bf11a336c7e3414a2 \ No newline at end of file From 776fe42c70fac79657496020b235a9e67fceeec8 Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 22 Jan 2024 12:56:58 +0000 Subject: [PATCH 032/430] Fix userauth so that it works together with SQLITE_OMIT_SHARED_CACHE. ([forum:/forumpost/0bfc5888a384d430|Forum post 0bfc5888a384d430]). However, also change to code to issue a deprecation warning whenever SQLITE_USER_AUTHENTICATION is used. FossilOrigin-Name: 249048b0cbc37058c229a785182e07b46029584aff9c385269b0b93503153476 --- ext/userauth/user-auth.txt | 4 ++-- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/build.c | 2 +- src/sqliteInt.h | 4 ++++ 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/ext/userauth/user-auth.txt b/ext/userauth/user-auth.txt index 66caca3e1e..9d6ba23336 100644 --- a/ext/userauth/user-auth.txt +++ b/ext/userauth/user-auth.txt @@ -4,8 +4,8 @@ * tree. * * * * If you are using this extension and think it should be supported moving * -* forward, visit the SQLite Forum (https://sqlite.org/forum) and make your * -* case. * +* forward, visit the SQLite Forum (https://sqlite.org/forum) and argue your * +* case there. * * * * This deprecation notice was added on 2024-01-22. * ******************************************************************************* diff --git a/manifest b/manifest index ff616768bd..d84135d1bc 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sa\snotice\sto\sthe\suser-authentication\sdocumentation\sto\ssay\sthat\sthe\nextension\sis\sdeprecated\sand\smay\sdisappear\sin\sthe\sfuture. -D 2024-01-22T12:30:17.497 +C Fix\suserauth\sso\sthat\sit\sworks\stogether\swith\sSQLITE_OMIT_SHARED_CACHE.\n([forum:/forumpost/0bfc5888a384d430|Forum\spost\s0bfc5888a384d430]).\nHowever,\salso\schange\sto\scode\sto\sissue\sa\sdeprecation\swarning\swhenever\nSQLITE_USER_AUTHENTICATION\sis\sused. +D 2024-01-22T12:56:58.708 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -572,7 +572,7 @@ F ext/session/sqlite3session.c 829d468f0f3d2710aace56b0116a7ca3f414683ce78e3125a F ext/session/sqlite3session.h 4cf19a51975746d7cff2fdd74db8b769c570958e1c3639ac150d824ac1553b3e F ext/session/test_session.c 7b94ad945cd4afe6c73ee935aeb3d44b4446186e1729362af616c7695a5283d9 F ext/userauth/sqlite3userauth.h 7f3ea8c4686db8e40b0a0e7a8e0b00fac13aa7a3 -F ext/userauth/user-auth.txt 9a3bdae6b5d2746056d7611ae1d81fa888772ef716b05d20497cdb4f7992e997 +F ext/userauth/user-auth.txt ca7e9ee82ca4e1c1744295f8184dd70edfae1992865d26c64303f539eb6c084c F ext/userauth/userauth.c 7f00cded7dcaa5d47f54539b290a43d2e59f4b1eb5f447545fa865f002fc80cb F ext/wasm/EXPORTED_FUNCTIONS.fiddle.in 27450c8b8c70875a260aca55435ec927068b34cef801a96205adb81bdcefc65c F ext/wasm/GNUmakefile 867c903a27fa0d53a3bf1b01d8c7bb713456f87e0939c3cac9f07faa68f58734 @@ -680,7 +680,7 @@ F src/btmutex.c 79a43670447eacc651519a429f6ece9fd638563cf95b469d6891185ddae2b522 F src/btree.c dee25e097b749275333b55d64a5ffc079249576f8e88a2ee476468cf67510f4b F src/btree.h 03e3356f5208bcab8eed4e094240fdac4a7f9f5ddf5e91045ce589f67d47c240 F src/btreeInt.h 3e2589726c4f105e653461814f65857465da68be1fac688de340c43b873f4062 -F src/build.c e7d9044592eeeea8e78d8ae53ca8d31fd6e92ca0d4f53e2f2e8ccf7352e0b04b +F src/build.c 05c9eb387638982092988d2ef4c00a91b0c29baa1b85923f082ce0cf2903ea7e F src/callback.c db3a45e376deff6a16c0058163fe0ae2b73a2945f3f408ca32cf74960b28d490 F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e F src/ctime.c 23331529e654be40ca97d171cbbffe9b3d4c71cc53b78fe5501230675952da8b @@ -743,7 +743,7 @@ F src/shell.c.in 5ea8c6b0057bfe3bcdff31949fe72aa231ae429047c421ea1b168af6825a489 F src/sqlite.h.in 61a60b4ea04db8ead15e1579b20b64cb56e9f55d52c5f9f9694de630110593a3 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 -F src/sqliteInt.h 73800d73e21180e6b3df8d0fe7d11758dc24367fd2b0b0075b48fc116de406bb +F src/sqliteInt.h 03e64e4a973f56035772421e94be7bf092ceceeb3dc91a74a2147030a822c392 F src/sqliteLimit.h 6878ab64bdeb8c24a1d762d45635e34b96da21132179023338c93f820eee6728 F src/status.c cb11f8589a6912af2da3bb1ec509a94dd8ef27df4d4c1a97e0bcf2309ece972b F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1 @@ -2159,8 +2159,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 488caed24453fcef6fddcf40353e3b44cf37fb9d21e0ed743d39d60cbff020a7 -R ea5433aac763e6ce8bcfabec2e6890c2 +P fe6fc7b91ad1771a2d2d4e3d9d60831b3056d528a700932bf11a336c7e3414a2 +R c9a2f047c14d9ac32442399617ab89a7 U drh -Z 559db82f0095218d6f000421c012f60a +Z 8584c8666b4931dfcdafd4fc01ba8536 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 54eab787fa..86154680d5 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -fe6fc7b91ad1771a2d2d4e3d9d60831b3056d528a700932bf11a336c7e3414a2 \ No newline at end of file +249048b0cbc37058c229a785182e07b46029584aff9c385269b0b93503153476 \ No newline at end of file diff --git a/src/build.c b/src/build.c index a2553da9fd..cfa2c886c5 100644 --- a/src/build.c +++ b/src/build.c @@ -189,7 +189,7 @@ void sqlite3FinishCoding(Parse *pParse){ } sqlite3VdbeAddOp0(v, OP_Halt); -#if SQLITE_USER_AUTHENTICATION +#if SQLITE_USER_AUTHENTICATION && !defined(SQLITE_OMIT_SHARED_CACHE) if( pParse->nTableLock>0 && db->init.busy==0 ){ sqlite3UserAuthInit(db); if( db->auth.authLevel Date: Mon, 22 Jan 2024 14:01:07 +0000 Subject: [PATCH 033/430] Fix test script literal.test so that it works with SQLITE_OMIT_ALTER_TABLE builds. FossilOrigin-Name: 4dc00f577632c7b13135505007804d42a12f81a9ebd58d4c380727256b054b7e --- manifest | 15 ++++++++------- manifest.uuid | 2 +- test/literal.test | 19 ++++++++++++++----- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/manifest b/manifest index d84135d1bc..105fdc6b4b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\suserauth\sso\sthat\sit\sworks\stogether\swith\sSQLITE_OMIT_SHARED_CACHE.\n([forum:/forumpost/0bfc5888a384d430|Forum\spost\s0bfc5888a384d430]).\nHowever,\salso\schange\sto\scode\sto\sissue\sa\sdeprecation\swarning\swhenever\nSQLITE_USER_AUTHENTICATION\sis\sused. -D 2024-01-22T12:56:58.708 +C Fix\stest\sscript\sliteral.test\sso\sthat\sit\sworks\swith\sSQLITE_OMIT_ALTER_TABLE\sbuilds. +D 2024-01-22T14:01:07.189 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -1355,7 +1355,7 @@ F test/like2.test d3be15fefee3e02fc88942a9b98f26c5339bbdef7783c90023c092c4955fe3 F test/like3.test a76e5938fadbe6d32807284c796bafd869974a961057bc5fc5a28e06de98745c F test/limit.test 350f5d03c29e7dff9a2cde016f84f8d368d40bcd02fa2b2a52fa10c4bf3cbfaf F test/limit2.test 9409b033284642a859fafc95f29a5a6a557bd57c1f0d7c3f554bd64ed69df77e -F test/literal.test 12e3c865a9e20f984240dbfb362be2a53ad5ca4ee25a6d429cf059115a9ac48f +F test/literal.test d0a72ab5afe525da7b5f0d2e11df7a369e8021f98de90da4352b8634dba9ccaf F test/loadext.test faa4f6eed07a5aac35d57fdd7bc07f8fc82464cfd327567c10cf0ba3c86cde04 F test/loadext2.test 0408380b57adca04004247179837a18e866a74f7 F test/lock.test be4fe08118fb988fed741f429b7dd5d65e1c90db @@ -2159,8 +2159,9 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P fe6fc7b91ad1771a2d2d4e3d9d60831b3056d528a700932bf11a336c7e3414a2 -R c9a2f047c14d9ac32442399617ab89a7 -U drh -Z 8584c8666b4931dfcdafd4fc01ba8536 +P 249048b0cbc37058c229a785182e07b46029584aff9c385269b0b93503153476 +Q +b57327be4be9638f5ee834a6c9e06135aaef9e499516f8b53f927ffe81033f61 +R 30b53374dcbd0df72ff4a36d2f8af72e +U dan +Z 80e756b96db0b6ae94203f53b2e0b98b # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 86154680d5..cbd31ca380 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -249048b0cbc37058c229a785182e07b46029584aff9c385269b0b93503153476 \ No newline at end of file +4dc00f577632c7b13135505007804d42a12f81a9ebd58d4c380727256b054b7e \ No newline at end of file diff --git a/test/literal.test b/test/literal.test index 4e957c05db..c617b0642c 100644 --- a/test/literal.test +++ b/test/literal.test @@ -19,12 +19,21 @@ set ::testprefix literal proc test_literal {tn lit type val} { do_execsql_test $tn.1 "SELECT typeof( $lit ), $lit" [list $type $val] - do_execsql_test $tn.2 " + ifcapable altertable { + do_execsql_test $tn.2 " + DROP TABLE IF EXISTS x1; + CREATE TABLE x1(a); + INSERT INTO x1 VALUES(123); + ALTER TABLE x1 ADD COLUMN b DEFAULT $lit ; + SELECT typeof(b), b FROM x1; + " [list $type $val] + } + + do_execsql_test $tn.3 " DROP TABLE IF EXISTS x1; - CREATE TABLE x1(a); - INSERT INTO x1 VALUES(123); - ALTER TABLE x1 ADD COLUMN b DEFAULT $lit ; - SELECT typeof(b), b FROM x1; + CREATE TABLE x1(a DEFAULT $lit); + INSERT INTO x1 DEFAULT VALUES; + SELECT typeof(a), a FROM x1; " [list $type $val] } From 41fb2eed07d109c5bf452d443562ec154dc3b78a Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 22 Jan 2024 14:16:10 +0000 Subject: [PATCH 034/430] The -DSQLITE_JSON_BLOB_INPUT_BUG_COMPATIBLE compile-time option causes blob inputs to JSON functions that are not JSONB to be processed as if they where text, immulating historical bugging behavior which some applications have come to rely upon. See [forum:/forumpost/012136abd5292b8d|forum thread 012136abd5292b8d] for discussion. FossilOrigin-Name: 65572223583d43e1d61ec029641f9d3ff340e68ecfba8342c8d1b0a91a680f2a --- manifest | 15 +++++------ manifest.uuid | 2 +- src/json.c | 73 +++++++++++++++++++++++++++++++++++---------------- 3 files changed, 59 insertions(+), 31 deletions(-) diff --git a/manifest b/manifest index 105fdc6b4b..ddd60a6df8 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\stest\sscript\sliteral.test\sso\sthat\sit\sworks\swith\sSQLITE_OMIT_ALTER_TABLE\sbuilds. -D 2024-01-22T14:01:07.189 +C The\s-DSQLITE_JSON_BLOB_INPUT_BUG_COMPATIBLE\scompile-time\soption\scauses\sblob\ninputs\sto\sJSON\sfunctions\sthat\sare\snot\sJSONB\sto\sbe\sprocessed\sas\sif\sthey\nwhere\stext,\simmulating\shistorical\sbugging\sbehavior\swhich\ssome\sapplications\nhave\scome\sto\srely\supon.\s\sSee\n[forum:/forumpost/012136abd5292b8d|forum\sthread\s012136abd5292b8d]\sfor\ndiscussion. +D 2024-01-22T14:16:10.354 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -698,7 +698,7 @@ F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 F src/insert.c 3f0a94082d978bbdd33c38fefea15346c6c6bffb70bc645a71dc0f1f87dd3276 -F src/json.c 5405e50cf0d7aeae12ac5b46e0fc9b3757b3b9cb4885f1a73ec7afeac99b9759 +F src/json.c 99f2825b44327811bdf47808e57077388b83bcc6a253c1269d13fd1b3237138d F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 F src/main.c 438b95162acfa17b7d218f586f5bde11d6ae82bcf030c9611fc537556870ad6b @@ -2159,9 +2159,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 249048b0cbc37058c229a785182e07b46029584aff9c385269b0b93503153476 -Q +b57327be4be9638f5ee834a6c9e06135aaef9e499516f8b53f927ffe81033f61 -R 30b53374dcbd0df72ff4a36d2f8af72e -U dan -Z 80e756b96db0b6ae94203f53b2e0b98b +P 4dc00f577632c7b13135505007804d42a12f81a9ebd58d4c380727256b054b7e +R 59af26cba445671768ccc033868954ad +U drh +Z 9f8b0dd9fdc4264b889c936f6659e28d # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index cbd31ca380..25bb88a0e7 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4dc00f577632c7b13135505007804d42a12f81a9ebd58d4c380727256b054b7e \ No newline at end of file +65572223583d43e1d61ec029641f9d3ff340e68ecfba8342c8d1b0a91a680f2a \ No newline at end of file diff --git a/src/json.c b/src/json.c index d33692466b..b9a88822e0 100644 --- a/src/json.c +++ b/src/json.c @@ -3217,6 +3217,38 @@ static void jsonInsertIntoBlob( return; } +/* +** If pArg is a blob that seems like a JSONB blob, then initialize +** p to point to that JSONB and return TRUE. If pArg does not seem like +** a JSONB blob, then return FALSE; +** +** This routine is only called if it is already known that pArg is a +** blob. The only open question is whether or not the blob appears +** to be a JSONB blob. +*/ +static int jsonArgIsJsonb(sqlite3_value *pArg, JsonParse *p){ + u32 n, sz = 0; + p->aBlob = (u8*)sqlite3_value_blob(pArg); + p->nBlob = (u32)sqlite3_value_bytes(pArg); + if( p->nBlob==0 ){ + p->aBlob = 0; + return 0; + } + if( NEVER(p->aBlob==0) ){ + return 0; + } + if( (p->aBlob[0] & 0x0f)<=JSONB_OBJECT + && (n = jsonbPayloadSize(p, 0, &sz))>0 + && sz+n==p->nBlob + && ((p->aBlob[0] & 0x0f)>JSONB_FALSE || sz==0) + ){ + return 1; + } + p->aBlob = 0; + p->nBlob = 0; + return 0; +} + /* ** Generate a JsonParse object, containing valid JSONB in aBlob and nBlob, ** from the SQL function argument pArg. Return a pointer to the new @@ -3273,29 +3305,26 @@ static JsonParse *jsonParseFuncArg( return p; } if( eType==SQLITE_BLOB ){ - u32 n, sz = 0; - p->aBlob = (u8*)sqlite3_value_blob(pArg); - p->nBlob = (u32)sqlite3_value_bytes(pArg); - if( p->nBlob==0 ){ - goto json_pfa_malformed; - } - if( NEVER(p->aBlob==0) ){ - goto json_pfa_oom; - } - if( (p->aBlob[0] & 0x0f)>JSONB_OBJECT ){ - goto json_pfa_malformed; - } - n = jsonbPayloadSize(p, 0, &sz); - if( n==0 - || sz+n!=p->nBlob - || ((p->aBlob[0] & 0x0f)<=JSONB_FALSE && sz>0) - ){ - goto json_pfa_malformed; - } - if( (flgs & JSON_EDITABLE)!=0 && jsonBlobMakeEditable(p, 0)==0 ){ - goto json_pfa_oom; + if( jsonArgIsJsonb(pArg,p) ){ + if( (flgs & JSON_EDITABLE)!=0 && jsonBlobMakeEditable(p, 0)==0 ){ + goto json_pfa_oom; + } + return p; } - return p; +#if defined(SQLITE_JSON_BLOB_INPUT_BUG_COMPATIBLE) + /* If the input is a BLOB that is not JSONB, fall through into trying + ** to process that BLOB as if it where text. This goes against all + ** historical documentation about how the SQLite JSON functions are + ** suppose to work. Nevertheless, many SQLite implementations prior to + ** version 3.45.0 contained a bug such that they did behave this way + ** and some applications came to depend upon this buggy behavior. The + ** SQLITE_JSON_BLOB_INPUT_BUG_COMPATIBLE compile-time option provides + ** a mechanism for those applications to continue working even after + ** the bug was fixed. See + ** https://sqlite.org/forum/forumpost/012136abd5292b8d */ +#else + goto json_pfa_malformed; +#endif } p->zJson = (char*)sqlite3_value_text(pArg); p->nJson = sqlite3_value_bytes(pArg); From a67d63b4816979b5bd8c123d0d2e332047502e06 Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 22 Jan 2024 15:26:33 +0000 Subject: [PATCH 035/430] Improved error message when a double-quoted string is used and it seems likely that the user wanted a single-quoted string literal. FossilOrigin-Name: 0a834bd81122b6e9c34c8253f9e45d53dab3274be28df60968366fa42237617b --- manifest | 17 ++++++++++------- manifest.uuid | 2 +- src/resolve.c | 13 ++++++++----- test/quote.test | 10 +++++----- 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/manifest b/manifest index ddd60a6df8..7a89979994 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C The\s-DSQLITE_JSON_BLOB_INPUT_BUG_COMPATIBLE\scompile-time\soption\scauses\sblob\ninputs\sto\sJSON\sfunctions\sthat\sare\snot\sJSONB\sto\sbe\sprocessed\sas\sif\sthey\nwhere\stext,\simmulating\shistorical\sbugging\sbehavior\swhich\ssome\sapplications\nhave\scome\sto\srely\supon.\s\sSee\n[forum:/forumpost/012136abd5292b8d|forum\sthread\s012136abd5292b8d]\sfor\ndiscussion. -D 2024-01-22T14:16:10.354 +C Improved\serror\smessage\swhen\sa\sdouble-quoted\sstring\sis\sused\sand\sit\sseems\slikely\nthat\sthe\suser\swanted\sa\ssingle-quoted\sstring\sliteral. +D 2024-01-22T15:26:33.828 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -736,7 +736,7 @@ F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7 F src/prepare.c 371f6115cb69286ebc12c6f2d7511279c2e47d9f54f475d46a554d687a3b312c F src/printf.c 18fbdf028345c8fbe6044f5f5bfda5a10d48d6287afef088cc21b0ca57985640 F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c -F src/resolve.c e25f51a473a5f30a0d978e4df2aaa98aeec84eac29ecae1ad4708a6c3e669345 +F src/resolve.c 6221ea6fa0f4767b051bae74a2c967c4ca411fc46512a7f6f1ec97555114ea6b F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c f1a81ff4f8e9e76c224e2ab3a4baa799add0db22158c7fcede65d8cc4a6fa2da F src/shell.c.in 5ea8c6b0057bfe3bcdff31949fe72aa231ae429047c421ea1b168af6825a4890 @@ -1497,7 +1497,7 @@ F test/quickcheck.test a4b7e878cd97e46108291c409b0bf8214f29e18fddd68a42bc5c1375a F test/quota-glob.test 32901e9eed6705d68ca3faee2a06b73b57cb3c26 F test/quota.test bfb269ce81ea52f593f9648316cd5013d766dd2a F test/quota2.test 7dc12e08b11cbc4c16c9ba2aa2e040ea8d8ab4b8 -F test/quote.test ffb40f0eb7a25c1d8cfe11ee2fe67f8e85fbf3fed348810834114be1fdada142 +F test/quote.test 7b01b2a261bc26d9821aea9f4941ce1e08191d62fc55ba8862440fb3a59197a4 F test/randexpr1.tcl 40dec52119ed3a2b8b2a773bce24b63a3a746459 F test/randexpr1.test eda062a97e60f9c38ae8d806b03b0ddf23d796df F test/rbu.test 168573d353cd0fd10196b87b0caa322c144ef736 @@ -2159,8 +2159,11 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 4dc00f577632c7b13135505007804d42a12f81a9ebd58d4c380727256b054b7e -R 59af26cba445671768ccc033868954ad +P 65572223583d43e1d61ec029641f9d3ff340e68ecfba8342c8d1b0a91a680f2a +R 7e3b76756c0a4c8c51526beb20e2ad21 +T *branch * improved-dqs-error-msg +T *sym-improved-dqs-error-msg * +T -sym-trunk * U drh -Z 9f8b0dd9fdc4264b889c936f6659e28d +Z eea53958dbf5ca2fad33a06e593a1f98 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 25bb88a0e7..5936974ca1 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -65572223583d43e1d61ec029641f9d3ff340e68ecfba8342c8d1b0a91a680f2a \ No newline at end of file +0a834bd81122b6e9c34c8253f9e45d53dab3274be28df60968366fa42237617b \ No newline at end of file diff --git a/src/resolve.c b/src/resolve.c index b4f03fe7e6..fde5506f9c 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -277,7 +277,7 @@ static int lookupName( Parse *pParse, /* The parsing context */ const char *zDb, /* Name of the database containing table, or NULL */ const char *zTab, /* Name of table containing column, or NULL */ - const char *zCol, /* Name of the column. */ + const Expr *pRight, /* Name of the column. */ NameContext *pNC, /* The name context used to resolve the name */ Expr *pExpr /* Make this EXPR node point to the selected column */ ){ @@ -294,6 +294,7 @@ static int lookupName( Table *pTab = 0; /* Table holding the row */ Column *pCol; /* A column of pTab */ ExprList *pFJMatch = 0; /* Matches for FULL JOIN .. USING */ + const char *zCol = pRight->u.zToken; assert( pNC ); /* the name context cannot be NULL. */ assert( zCol ); /* The Z in X.Y.Z cannot be NULL */ @@ -753,6 +754,10 @@ static int lookupName( sqlite3ErrorMsg(pParse, "%s: %s.%s.%s", zErr, zDb, zTab, zCol); }else if( zTab ){ sqlite3ErrorMsg(pParse, "%s: %s.%s", zErr, zTab, zCol); + }else if( cnt==0 && ExprHasProperty(pRight,EP_DblQuoted) ){ + sqlite3ErrorMsg(pParse, "no such column: \"%s\" - should this be a" + " string literal in single-quotes?", + zCol); }else{ sqlite3ErrorMsg(pParse, "%s: %s", zErr, zCol); } @@ -1000,7 +1005,6 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){ */ case TK_ID: case TK_DOT: { - const char *zColumn; const char *zTable; const char *zDb; Expr *pRight; @@ -1009,7 +1013,7 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){ zDb = 0; zTable = 0; assert( !ExprHasProperty(pExpr, EP_IntValue) ); - zColumn = pExpr->u.zToken; + pRight = pExpr; }else{ Expr *pLeft = pExpr->pLeft; testcase( pNC->ncFlags & NC_IdxExpr ); @@ -1028,14 +1032,13 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){ } assert( ExprUseUToken(pLeft) && ExprUseUToken(pRight) ); zTable = pLeft->u.zToken; - zColumn = pRight->u.zToken; assert( ExprUseYTab(pExpr) ); if( IN_RENAME_OBJECT ){ sqlite3RenameTokenRemap(pParse, (void*)pExpr, (void*)pRight); sqlite3RenameTokenRemap(pParse, (void*)&pExpr->y.pTab, (void*)pLeft); } } - return lookupName(pParse, zDb, zTable, zColumn, pNC, pExpr); + return lookupName(pParse, zDb, zTable, pRight, pNC, pExpr); } /* Resolve function names diff --git a/test/quote.test b/test/quote.test index 6d7b317ea1..4e40a9e57f 100644 --- a/test/quote.test +++ b/test/quote.test @@ -103,7 +103,7 @@ foreach {tn sql errname} { 3 { CREATE INDEX i3 ON t1("w") } w 4 { CREATE INDEX i4 ON t1(x) WHERE z="w" } w } { - do_catchsql_test 2.1.$tn $sql [list 1 "no such column: $errname"] + do_catchsql_test 2.1.$tn $sql [list 1 "no such column: \"$errname\" - should this be a string literal in single-quotes?"] } do_execsql_test 2.2 { @@ -147,19 +147,19 @@ ifcapable altertable { CREATE TABLE t1(a,b); CREATE INDEX x1 on t1("b"); ALTER TABLE t1 DROP COLUMN b; - } {1 {error in index x1 after drop column: no such column: b}} + } {1 {error in index x1 after drop column: no such column: "b" - should this be a string literal in single-quotes?}} do_catchsql_test 3.1 { DROP TABLE t1; CREATE TABLE t1(a,"b"); CREATE INDEX x1 on t1("b"); ALTER TABLE t1 DROP COLUMN b; - } {1 {error in index x1 after drop column: no such column: b}} + } {1 {error in index x1 after drop column: no such column: "b" - should this be a string literal in single-quotes?}} do_catchsql_test 3.2 { DROP TABLE t1; CREATE TABLE t1(a,'b'); CREATE INDEX x1 on t1("b"); ALTER TABLE t1 DROP COLUMN b; - } {1 {error in index x1 after drop column: no such column: b}} + } {1 {error in index x1 after drop column: no such column: "b" - should this be a string literal in single-quotes?}} do_catchsql_test 3.3 { DROP TABLE t1; CREATE TABLE t1(a,"b"); @@ -172,7 +172,7 @@ ifcapable altertable { CREATE INDEX x1 ON t1("a"||"b"); INSERT INTO t1 VALUES(1,2,3),(1,4,5); ALTER TABLE t1 DROP COLUMN b; - } {1 {error in index x1 after drop column: no such column: b}} + } {1 {error in index x1 after drop column: no such column: "b" - should this be a string literal in single-quotes?}} sqlite3_db_config db SQLITE_DBCONFIG_DQS_DDL 1 do_catchsql_test 3.5 { DROP TABLE t1; From 87ad06ed997a505b60d2ca9c9751c0d0e83cfbd4 Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 22 Jan 2024 17:18:41 +0000 Subject: [PATCH 036/430] Do not allow digit separators that are not surrounded on both sides by digits. FossilOrigin-Name: 5bbc378a3022e2013048c8e296d95de21d15a8d7c1b62e8ffb64782f952cfe12 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/tokenize.c | 20 ++++++++++++++++---- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/manifest b/manifest index d5565a35b7..b43db80a8c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\stest\sscript\sliteral.test\sso\sthat\sit\sworks\swith\sSQLITE_OMIT_ALTER_TABLE\sbuilds. -D 2024-01-22T11:12:38.218 +C Do\snot\sallow\sdigit\sseparators\sthat\sare\snot\ssurrounded\son\sboth\ssides\sby\sdigits. +D 2024-01-22T17:18:41.963 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -800,7 +800,7 @@ F src/test_windirent.h da2e5b73c32d09905fbdd00f27cd802212a32a58ead882736fe4f5eb7 F src/test_window.c cdae419fdcea5bad6dcd9368c685abdad6deb59e9fc8b84b153de513d394ba3f F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9 F src/threads.c 4ae07fa022a3dc7c5beb373cf744a85d3c5c6c3c -F src/tokenize.c e0cdd971ebf7225cd617661d8198fc90a49559e21210af03bdf440e2fcba6b88 +F src/tokenize.c 1664cd0d9224bf63e7471d892074f580933c0e85a3b77f98e016dce2d5fed4a5 F src/treeview.c c6fc972683fd00f975d8b32a81c1f25d2fb7d4035366bf45c9f5622d3ccd70ee F src/trigger.c 0905b96b04bb6658509f711a8207287f1315cdbc3df1a1b13ba6483c8e341c81 F src/update.c 6904814dd62a7a93bbb86d9f1419c7f134a9119582645854ab02b36b676d9f92 @@ -2159,8 +2159,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 03ade4a810516ff84bc5c1a716b0e454cc8a89374100415ff21a82449112811b -R 4dc96dbb63712d691b87fb65e2e995c9 -U dan -Z 060bde75456debf514e23a793c3f90b5 +P b57327be4be9638f5ee834a6c9e06135aaef9e499516f8b53f927ffe81033f61 +R dc78fe3596a95d4e421310d3dc095c60 +U drh +Z 8ae254187429ecb3341b495c0d5f92df # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 902662ca4b..40427080bf 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b57327be4be9638f5ee834a6c9e06135aaef9e499516f8b53f927ffe81033f61 \ No newline at end of file +5bbc378a3022e2013048c8e296d95de21d15a8d7c1b62e8ffb64782f952cfe12 \ No newline at end of file diff --git a/src/tokenize.c b/src/tokenize.c index 592d6b8d8d..37254da70d 100644 --- a/src/tokenize.c +++ b/src/tokenize.c @@ -443,8 +443,14 @@ int sqlite3GetToken(const unsigned char *z, int *tokenType){ #endif for(i=0; 1; i++){ if( sqlite3Isdigit(z[i])==0 ){ - if( z[i]==SQLITE_DIGIT_SEPARATOR ){ *tokenType = TK_QNUMBER; } - else{ break; } + if( z[i]==SQLITE_DIGIT_SEPARATOR + && sqlite3Isdigit(z[i-1]) + && sqlite3Isdigit(z[i+1]) + ){ + *tokenType = TK_QNUMBER; + }else{ + break; + } } } #ifndef SQLITE_OMIT_FLOATING_POINT @@ -452,8 +458,14 @@ int sqlite3GetToken(const unsigned char *z, int *tokenType){ if( *tokenType==TK_INTEGER ) *tokenType = TK_FLOAT; for(i++; 1; i++){ if( sqlite3Isdigit(z[i])==0 ){ - if( z[i]==SQLITE_DIGIT_SEPARATOR ){ *tokenType = TK_QNUMBER; } - else{ break; } + if( z[i]==SQLITE_DIGIT_SEPARATOR + && sqlite3Isdigit(z[i-1]) + && sqlite3Isdigit(z[i+1]) + ){ + *tokenType = TK_QNUMBER; + }else{ + break; + } } } } From fbb72fae8ff79bdc1308f70c64a8093c9d605ce8 Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 22 Jan 2024 19:00:50 +0000 Subject: [PATCH 037/430] Add extra tests for the code on this branch. FossilOrigin-Name: b15bbb201a7727806b9fd6c02f2579b01e0e38155a8f9e24c5d6f487fe3e8b6c --- manifest | 18 +++++++++-------- manifest.uuid | 2 +- src/tokenize.c | 10 ++++++++-- test/literal.test | 28 ++++++++++++++++++++++++++- test/literal2.tcl | 27 ++++++++++++++++++++++++++ test/literal2.test | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 121 insertions(+), 12 deletions(-) create mode 100644 test/literal2.tcl create mode 100644 test/literal2.test diff --git a/manifest b/manifest index b43db80a8c..c1b974d23a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Do\snot\sallow\sdigit\sseparators\sthat\sare\snot\ssurrounded\son\sboth\ssides\sby\sdigits. -D 2024-01-22T17:18:41.963 +C Add\sextra\stests\sfor\sthe\scode\son\sthis\sbranch. +D 2024-01-22T19:00:50.821 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -800,7 +800,7 @@ F src/test_windirent.h da2e5b73c32d09905fbdd00f27cd802212a32a58ead882736fe4f5eb7 F src/test_window.c cdae419fdcea5bad6dcd9368c685abdad6deb59e9fc8b84b153de513d394ba3f F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9 F src/threads.c 4ae07fa022a3dc7c5beb373cf744a85d3c5c6c3c -F src/tokenize.c 1664cd0d9224bf63e7471d892074f580933c0e85a3b77f98e016dce2d5fed4a5 +F src/tokenize.c f283d8017b57d8be74218f6a820fb72f72ee7e05267083b4ac3b1ed456e0a290 F src/treeview.c c6fc972683fd00f975d8b32a81c1f25d2fb7d4035366bf45c9f5622d3ccd70ee F src/trigger.c 0905b96b04bb6658509f711a8207287f1315cdbc3df1a1b13ba6483c8e341c81 F src/update.c 6904814dd62a7a93bbb86d9f1419c7f134a9119582645854ab02b36b676d9f92 @@ -1355,7 +1355,9 @@ F test/like2.test d3be15fefee3e02fc88942a9b98f26c5339bbdef7783c90023c092c4955fe3 F test/like3.test a76e5938fadbe6d32807284c796bafd869974a961057bc5fc5a28e06de98745c F test/limit.test 350f5d03c29e7dff9a2cde016f84f8d368d40bcd02fa2b2a52fa10c4bf3cbfaf F test/limit2.test 9409b033284642a859fafc95f29a5a6a557bd57c1f0d7c3f554bd64ed69df77e -F test/literal.test db71a7616dc027badf8d8f7ac6e23e8655915eb51b187c40a0a6e667aed495b7 +F test/literal.test e3d65d4091126cb008f31f57a324364511a83dd9461df31f60b5df6bd1f1f846 +F test/literal2.tcl 10713fed76885d43ada4161c0edf18fdc06e4405094e7baad888c6a1a29141b9 +F test/literal2.test 2e3ad4bc8cb019169d4f43400658fdc35acdcde7f79322c952b61ca07ac27ba6 F test/loadext.test faa4f6eed07a5aac35d57fdd7bc07f8fc82464cfd327567c10cf0ba3c86cde04 F test/loadext2.test 0408380b57adca04004247179837a18e866a74f7 F test/lock.test be4fe08118fb988fed741f429b7dd5d65e1c90db @@ -2159,8 +2161,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P b57327be4be9638f5ee834a6c9e06135aaef9e499516f8b53f927ffe81033f61 -R dc78fe3596a95d4e421310d3dc095c60 -U drh -Z 8ae254187429ecb3341b495c0d5f92df +P 5bbc378a3022e2013048c8e296d95de21d15a8d7c1b62e8ffb64782f952cfe12 +R 5ae47ec02f1c44e5b63d2c7bab26a43e +U dan +Z 067422c390415b433adad2a7d339896e # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 40427080bf..0b49600412 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5bbc378a3022e2013048c8e296d95de21d15a8d7c1b62e8ffb64782f952cfe12 \ No newline at end of file +b15bbb201a7727806b9fd6c02f2579b01e0e38155a8f9e24c5d6f487fe3e8b6c \ No newline at end of file diff --git a/src/tokenize.c b/src/tokenize.c index 37254da70d..7a30512ec6 100644 --- a/src/tokenize.c +++ b/src/tokenize.c @@ -477,8 +477,14 @@ int sqlite3GetToken(const unsigned char *z, int *tokenType){ if( *tokenType==TK_INTEGER ) *tokenType = TK_FLOAT; for(i+=2; 1; i++){ if( sqlite3Isdigit(z[i])==0 ){ - if( z[i]==SQLITE_DIGIT_SEPARATOR ){ *tokenType = TK_QNUMBER; } - else{ break; } + if( z[i]==SQLITE_DIGIT_SEPARATOR + && sqlite3Isdigit(z[i-1]) + && sqlite3Isdigit(z[i+1]) + ){ + *tokenType = TK_QNUMBER; + }else{ + break; + } } } } diff --git a/test/literal.test b/test/literal.test index 3140eedf2a..fe6b70acf7 100644 --- a/test/literal.test +++ b/test/literal.test @@ -37,6 +37,10 @@ proc test_literal {tn lit type val} { " [list $type $val] } +proc test_literal_error {tn lit unrec} { + do_catchsql_test $tn "SELECT $lit" "1 {unrecognized token: \"$unrec\"}" +} + test_literal 1.0 45 integer 45 test_literal 1.1 0xFF integer 255 @@ -62,9 +66,31 @@ test_literal 3.1 1_000 integer 1000 test_literal 3.2 1.1_1 real 1.11 test_literal 3.3 1_0.1_1 real 10.11 test_literal 3.4 1e1_000 real Inf -test_literal 3.5 123______456.7_8__9_ real 123456.789 +test_literal 3.5 12_3_456.7_8_9 real 123456.789 test_literal 3.6 9_223_372_036_854_775_807 integer 9223372036854775807 test_literal 3.7 9_223_372_036_854_775_808 real 9.22337203685478e+18 test_literal 3.8 -9_223_372_036_854_775_808 integer -9223372036854775808 +foreach {tn lit unrec} { + 0 123a456 123a456 + 1 1_ 1_ + 2 1_.4 1_ + 3 1e_4 1e_4 + 4 1_e4 1_e4 + 5 1.4_e4 1.4_e4 + 6 1.4e+_4 1.4e + 7 1.4e-_4 1.4e + 8 1.4e4_ 1.4e4_ + 9 1.4_e4 1.4_e4 + 10 1.4e_4 1.4e_4 + 11 12__34 12__34 + 12 1234_ 1234_ + 13 12._34 12._34 + 14 12_.34 12_ + 15 12.34_ 12.34_ + 16 1.0e1_______2 1.0e1_______2 +} { + test_literal_error 4.$tn $lit $unrec +} + finish_test diff --git a/test/literal2.tcl b/test/literal2.tcl new file mode 100644 index 0000000000..2c97150b0c --- /dev/null +++ b/test/literal2.tcl @@ -0,0 +1,27 @@ +# 2018 May 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. +# +#*********************************************************************** +# + +source [file join [file dirname $argv0] pg_common.tcl] + +#========================================================================= + + +start_test literal2 "2024 Jan 23" + +execsql_test 1.0 { SELECT 123_456 } +errorsql_test 1.1 { SELECT 123__456 } + +execsql_float_test 2.1 { SELECT 1.0e1_2 } + +finish_test + + diff --git a/test/literal2.test b/test/literal2.test new file mode 100644 index 0000000000..743df44eb7 --- /dev/null +++ b/test/literal2.test @@ -0,0 +1,48 @@ +# 2024 Jan 23 +# +# 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. +# + +#################################################### +# DO NOT EDIT! THIS FILE IS AUTOMATICALLY GENERATED! +#################################################### + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix literal2 + +do_execsql_test 1.0 { + SELECT 123_456 +} {123456} + +# PG says ERROR: trailing junk after numeric literal at or near "123_" +do_test 1.1 { catch { execsql { + SELECT 123__456 +} } } 1 + + +do_test 2.1 { + set myres {} + foreach r [db eval {SELECT 1.0e1_2}] { + lappend myres [format %.4f [set r]] + } + set res2 {1000000000000.0000} + set i 0 + foreach r [set myres] r2 [set res2] { + if {[set r]<([set r2]-0.0001) || [set r]>([set r2]+0.0001)} { + error "list element [set i] does not match: got=[set r] expected=[set r2]" + } + incr i + } + set {} {} +} {} + +finish_test From 8374f7dfaf1106f01205e874b8b7e86a14f9d6cf Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 22 Jan 2024 19:38:55 +0000 Subject: [PATCH 038/430] Allow underscores to occur in hex literals. FossilOrigin-Name: 81a56229460cc5b6acfd3c3729fcf89ea3cccb546ca2b4f4035b140c60911e18 --- manifest | 20 ++++++------ manifest.uuid | 2 +- src/tokenize.c | 76 +++++++++++++++++++++++++++------------------- src/util.c | 10 +++--- test/literal2.tcl | 8 +++++ test/literal2.test | 18 +++++++++++ test/misc1.test | 2 +- 7 files changed, 88 insertions(+), 48 deletions(-) diff --git a/manifest b/manifest index c1b974d23a..77f3ca0ff6 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sextra\stests\sfor\sthe\scode\son\sthis\sbranch. -D 2024-01-22T19:00:50.821 +C Allow\sunderscores\sto\soccur\sin\shex\sliterals. +D 2024-01-22T19:38:55.172 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -800,13 +800,13 @@ F src/test_windirent.h da2e5b73c32d09905fbdd00f27cd802212a32a58ead882736fe4f5eb7 F src/test_window.c cdae419fdcea5bad6dcd9368c685abdad6deb59e9fc8b84b153de513d394ba3f F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9 F src/threads.c 4ae07fa022a3dc7c5beb373cf744a85d3c5c6c3c -F src/tokenize.c f283d8017b57d8be74218f6a820fb72f72ee7e05267083b4ac3b1ed456e0a290 +F src/tokenize.c 3ea60fcd98a0eb1391592a080fb8871b0026eaffbdb5795ef3b19bb7d48e702a F src/treeview.c c6fc972683fd00f975d8b32a81c1f25d2fb7d4035366bf45c9f5622d3ccd70ee F src/trigger.c 0905b96b04bb6658509f711a8207287f1315cdbc3df1a1b13ba6483c8e341c81 F src/update.c 6904814dd62a7a93bbb86d9f1419c7f134a9119582645854ab02b36b676d9f92 F src/upsert.c fa125a8d3410ce9a97b02cb50f7ae68a2476c405c76aa692d3acf6b8586e9242 F src/utf.c f23165685a67b4caf8ec08fb274cb3f319103decfb2a980b7cfd55d18dfa855e -F src/util.c 2b274b03f0d4fd1bf253f160d6b399bc5265338b043c078045c5e32298891ec8 +F src/util.c 25e0b776d5bb326d6009fbd8705c5ab332318b0f1c213dab4a717524defb9a7d F src/vacuum.c 604fcdaebe76f3497c855afcbf91b8fa5046b32de3045bab89cc008d68e40104 F src/vdbe.c 92910d536e0b77505599cd6ae5d9d449e4a5d31ada61da4c0bb84f6ccb2c3189 F src/vdbe.h 88e19a982df9027ec1c177c793d1a5d34dc23d8f06e3b2d997f43688b05ee0eb @@ -1356,8 +1356,8 @@ F test/like3.test a76e5938fadbe6d32807284c796bafd869974a961057bc5fc5a28e06de9874 F test/limit.test 350f5d03c29e7dff9a2cde016f84f8d368d40bcd02fa2b2a52fa10c4bf3cbfaf F test/limit2.test 9409b033284642a859fafc95f29a5a6a557bd57c1f0d7c3f554bd64ed69df77e F test/literal.test e3d65d4091126cb008f31f57a324364511a83dd9461df31f60b5df6bd1f1f846 -F test/literal2.tcl 10713fed76885d43ada4161c0edf18fdc06e4405094e7baad888c6a1a29141b9 -F test/literal2.test 2e3ad4bc8cb019169d4f43400658fdc35acdcde7f79322c952b61ca07ac27ba6 +F test/literal2.tcl 70cf73b43f09396a4ba3ba7462b107a32866bb77deaa991c3296aa978edcdfdd +F test/literal2.test dd6b763feb086fa34b4229c527b35099020e7f5d588089fff9e4434c71695f60 F test/loadext.test faa4f6eed07a5aac35d57fdd7bc07f8fc82464cfd327567c10cf0ba3c86cde04 F test/loadext2.test 0408380b57adca04004247179837a18e866a74f7 F test/lock.test be4fe08118fb988fed741f429b7dd5d65e1c90db @@ -1410,7 +1410,7 @@ F test/minmax.test fe638b55d77d2375531a8f549b338eafcd9adfbd2f72df37ed77d9b26ca0a F test/minmax2.test cf9311babb6f0518d04e42fd6a42c619531c4309a9dd790a2c4e9b3bc595e0de F test/minmax3.test cc1e8b010136db0d01a6f2a29ba5a9f321034354 F test/minmax4.test 272ca395257f05937dc96441c9dde4bc9fbf116a8d4fa02baeb0d13d50e36c87 -F test/misc1.test 8d138a4926ab90617c1aa29ce26e7785ae2b83a4d3a195d543b7374e05589dd1 +F test/misc1.test e3e36262aff1bd9b8b9bf1eeb3af04adb3fc1e23f0a92dbff708bba9e939ace1 F test/misc2.test 71e746af479119386ac2ed7ab7d81d99970e75b49ffd3e8efffee100b4b5f350 F test/misc3.test cf3dda47d5dda3e53fc5804a100d3c82be736c9d F test/misc4.test 10cd6addb2fa9093df4751a1b92b50440175dd5468a6ec84d0386e78f087db0e @@ -2161,8 +2161,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 5bbc378a3022e2013048c8e296d95de21d15a8d7c1b62e8ffb64782f952cfe12 -R 5ae47ec02f1c44e5b63d2c7bab26a43e +P b15bbb201a7727806b9fd6c02f2579b01e0e38155a8f9e24c5d6f487fe3e8b6c +R d0d892d569c1b9650e2494b0fb9379db U dan -Z 067422c390415b433adad2a7d339896e +Z 87a049db1576d41d80b78f3d72e95d0a # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 0b49600412..bec89eba1b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b15bbb201a7727806b9fd6c02f2579b01e0e38155a8f9e24c5d6f487fe3e8b6c \ No newline at end of file +81a56229460cc5b6acfd3c3729fcf89ea3cccb546ca2b4f4035b140c60911e18 \ No newline at end of file diff --git a/src/tokenize.c b/src/tokenize.c index 7a30512ec6..f01548d4cb 100644 --- a/src/tokenize.c +++ b/src/tokenize.c @@ -437,30 +437,11 @@ int sqlite3GetToken(const unsigned char *z, int *tokenType){ *tokenType = TK_INTEGER; #ifndef SQLITE_OMIT_HEX_INTEGER if( z[0]=='0' && (z[1]=='x' || z[1]=='X') && sqlite3Isxdigit(z[2]) ){ - for(i=3; sqlite3Isxdigit(z[i]); i++){} - return i; - } -#endif - for(i=0; 1; i++){ - if( sqlite3Isdigit(z[i])==0 ){ - if( z[i]==SQLITE_DIGIT_SEPARATOR - && sqlite3Isdigit(z[i-1]) - && sqlite3Isdigit(z[i+1]) - ){ - *tokenType = TK_QNUMBER; - }else{ - break; - } - } - } -#ifndef SQLITE_OMIT_FLOATING_POINT - if( z[i]=='.' ){ - if( *tokenType==TK_INTEGER ) *tokenType = TK_FLOAT; - for(i++; 1; i++){ - if( sqlite3Isdigit(z[i])==0 ){ + for(i=3; 1; i++){ + if( sqlite3Isxdigit(z[i])==0 ){ if( z[i]==SQLITE_DIGIT_SEPARATOR - && sqlite3Isdigit(z[i-1]) - && sqlite3Isdigit(z[i+1]) + && sqlite3Isxdigit(z[i-1]) + && sqlite3Isxdigit(z[i+1]) ){ *tokenType = TK_QNUMBER; }else{ @@ -468,14 +449,10 @@ int sqlite3GetToken(const unsigned char *z, int *tokenType){ } } } - } - if( (z[i]=='e' || z[i]=='E') && - ( sqlite3Isdigit(z[i+1]) - || ((z[i+1]=='+' || z[i+1]=='-') && sqlite3Isdigit(z[i+2])) - ) - ){ - if( *tokenType==TK_INTEGER ) *tokenType = TK_FLOAT; - for(i+=2; 1; i++){ + }else +#endif + { + for(i=0; 1; i++){ if( sqlite3Isdigit(z[i])==0 ){ if( z[i]==SQLITE_DIGIT_SEPARATOR && sqlite3Isdigit(z[i-1]) @@ -487,8 +464,43 @@ int sqlite3GetToken(const unsigned char *z, int *tokenType){ } } } - } +#ifndef SQLITE_OMIT_FLOATING_POINT + if( z[i]=='.' ){ + if( *tokenType==TK_INTEGER ) *tokenType = TK_FLOAT; + for(i++; 1; i++){ + if( sqlite3Isdigit(z[i])==0 ){ + if( z[i]==SQLITE_DIGIT_SEPARATOR + && sqlite3Isdigit(z[i-1]) + && sqlite3Isdigit(z[i+1]) + ){ + *tokenType = TK_QNUMBER; + }else{ + break; + } + } + } + } + if( (z[i]=='e' || z[i]=='E') && + ( sqlite3Isdigit(z[i+1]) + || ((z[i+1]=='+' || z[i+1]=='-') && sqlite3Isdigit(z[i+2])) + ) + ){ + if( *tokenType==TK_INTEGER ) *tokenType = TK_FLOAT; + for(i+=2; 1; i++){ + if( sqlite3Isdigit(z[i])==0 ){ + if( z[i]==SQLITE_DIGIT_SEPARATOR + && sqlite3Isdigit(z[i-1]) + && sqlite3Isdigit(z[i+1]) + ){ + *tokenType = TK_QNUMBER; + }else{ + break; + } + } + } + } #endif + } while( IdChar(z[i]) ){ *tokenType = TK_ILLEGAL; i++; diff --git a/src/util.c b/src/util.c index 24eff14e9f..9a2ea9e901 100644 --- a/src/util.c +++ b/src/util.c @@ -312,10 +312,9 @@ void sqlite3DequoteExpr(Expr *p){ } /* -** Expression p is a QINTEGER or QFLOAT (quoted integer or float). Dequote -** the value in p->u.zToken and set the type to INTEGER or FLOAT. "Quoted" -** integers or floats are those that contain '_' characters that must -** be removed before further processing. +** Expression p is a QNUMBER (quoted number). Dequote the value in p->u.zToken +** and set the type to INTEGER or FLOAT. "Quoted" integers or floats are those +** that contain '_' characters that must be removed before further processing. */ void sqlite3DequoteNumber(Expr *p){ if( p ){ @@ -329,6 +328,9 @@ void sqlite3DequoteNumber(Expr *p){ if( *pIn=='e' || *pIn=='E' || *pIn=='.' ) p->op = TK_FLOAT; } }while( *pIn++ ); + if( p->u.zToken[0]=='0' && p->u.zToken[1]=='x' ){ + p->op = TK_INTEGER; + } } } diff --git a/test/literal2.tcl b/test/literal2.tcl index 2c97150b0c..029d33f51a 100644 --- a/test/literal2.tcl +++ b/test/literal2.tcl @@ -22,6 +22,14 @@ errorsql_test 1.1 { SELECT 123__456 } execsql_float_test 2.1 { SELECT 1.0e1_2 } + +execsql_test 3.0 { SELECT 0xFF_FF } +execsql_test 3.1 { SELECT 0xFF_EF } + +errorsql_test 3.2 { SELECT 0xFF__EF } +# errorsql_test 3.3 { SELECT 0x_FFEF } +errorsql_test 3.4 { SELECT 0xFFEF_ } + finish_test diff --git a/test/literal2.test b/test/literal2.test index 743df44eb7..eda526fcef 100644 --- a/test/literal2.test +++ b/test/literal2.test @@ -45,4 +45,22 @@ do_test 2.1 { set {} {} } {} +do_execsql_test 3.0 { + SELECT 0xFF_FF +} {65535} + +do_execsql_test 3.1 { + SELECT 0xFF_EF +} {65519} + +# PG says ERROR: trailing junk after numeric literal at or near "0xFF_" +do_test 3.2 { catch { execsql { + SELECT 0xFF__EF +} } } 1 + +# PG says ERROR: trailing junk after numeric literal at or near "0xFFEF_" +do_test 3.4 { catch { execsql { + SELECT 0xFFEF_ +} } } 1 + finish_test diff --git a/test/misc1.test b/test/misc1.test index 83acc752af..8110d38678 100644 --- a/test/misc1.test +++ b/test/misc1.test @@ -654,7 +654,7 @@ do_catchsql_test misc1-21.1 { } {1 {near "#0": syntax error}} do_catchsql_test misc1-21.2 { VALUES(0,0x0MATCH#0; -} {1 {near ";": syntax error}} +} {1 {unrecognized token: "0x0MATCH"}} # 2015-04-15 do_execsql_test misc1-22.1 { From a545de6827e9839da413f52e800f8184eedc6060 Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 22 Jan 2024 19:42:56 +0000 Subject: [PATCH 039/430] Fix a problem in the previous commit with hex literals that start with "0X" instead of "0x". FossilOrigin-Name: c063c89b11487e6e712b97de604db316fa97bcf91ed810bb2dcbbcb54c68dbf4 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/util.c | 2 +- test/literal2.tcl | 17 +++++++++++------ test/literal2.test | 26 ++++++++++++++++++++++---- 5 files changed, 43 insertions(+), 20 deletions(-) diff --git a/manifest b/manifest index 77f3ca0ff6..f48cebcf73 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Allow\sunderscores\sto\soccur\sin\shex\sliterals. -D 2024-01-22T19:38:55.172 +C Fix\sa\sproblem\sin\sthe\sprevious\scommit\swith\shex\sliterals\sthat\sstart\swith\s"0X"\sinstead\sof\s"0x". +D 2024-01-22T19:42:56.220 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -806,7 +806,7 @@ F src/trigger.c 0905b96b04bb6658509f711a8207287f1315cdbc3df1a1b13ba6483c8e341c81 F src/update.c 6904814dd62a7a93bbb86d9f1419c7f134a9119582645854ab02b36b676d9f92 F src/upsert.c fa125a8d3410ce9a97b02cb50f7ae68a2476c405c76aa692d3acf6b8586e9242 F src/utf.c f23165685a67b4caf8ec08fb274cb3f319103decfb2a980b7cfd55d18dfa855e -F src/util.c 25e0b776d5bb326d6009fbd8705c5ab332318b0f1c213dab4a717524defb9a7d +F src/util.c ef37d377684d6f725773c15bfc1ef5b75483b4f3b6b6198d4b8b969831623be0 F src/vacuum.c 604fcdaebe76f3497c855afcbf91b8fa5046b32de3045bab89cc008d68e40104 F src/vdbe.c 92910d536e0b77505599cd6ae5d9d449e4a5d31ada61da4c0bb84f6ccb2c3189 F src/vdbe.h 88e19a982df9027ec1c177c793d1a5d34dc23d8f06e3b2d997f43688b05ee0eb @@ -1356,8 +1356,8 @@ F test/like3.test a76e5938fadbe6d32807284c796bafd869974a961057bc5fc5a28e06de9874 F test/limit.test 350f5d03c29e7dff9a2cde016f84f8d368d40bcd02fa2b2a52fa10c4bf3cbfaf F test/limit2.test 9409b033284642a859fafc95f29a5a6a557bd57c1f0d7c3f554bd64ed69df77e F test/literal.test e3d65d4091126cb008f31f57a324364511a83dd9461df31f60b5df6bd1f1f846 -F test/literal2.tcl 70cf73b43f09396a4ba3ba7462b107a32866bb77deaa991c3296aa978edcdfdd -F test/literal2.test dd6b763feb086fa34b4229c527b35099020e7f5d588089fff9e4434c71695f60 +F test/literal2.tcl 1499037beaf661aeecdbe48801220a181d805372a64c6128d5f26bb6a4a8f0ce +F test/literal2.test b149e16b5fc9ee6249069a8858ed41052f222014fe0ba7ad43c2fb989c2dada2 F test/loadext.test faa4f6eed07a5aac35d57fdd7bc07f8fc82464cfd327567c10cf0ba3c86cde04 F test/loadext2.test 0408380b57adca04004247179837a18e866a74f7 F test/lock.test be4fe08118fb988fed741f429b7dd5d65e1c90db @@ -2161,8 +2161,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P b15bbb201a7727806b9fd6c02f2579b01e0e38155a8f9e24c5d6f487fe3e8b6c -R d0d892d569c1b9650e2494b0fb9379db +P 81a56229460cc5b6acfd3c3729fcf89ea3cccb546ca2b4f4035b140c60911e18 +R 8fee7748a406cec8844b4286c6b28b8f U dan -Z 87a049db1576d41d80b78f3d72e95d0a +Z 6bae334234c9987a328b3a9421e4a531 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index bec89eba1b..de37a7858c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -81a56229460cc5b6acfd3c3729fcf89ea3cccb546ca2b4f4035b140c60911e18 \ No newline at end of file +c063c89b11487e6e712b97de604db316fa97bcf91ed810bb2dcbbcb54c68dbf4 \ No newline at end of file diff --git a/src/util.c b/src/util.c index 9a2ea9e901..ed7789591b 100644 --- a/src/util.c +++ b/src/util.c @@ -328,7 +328,7 @@ void sqlite3DequoteNumber(Expr *p){ if( *pIn=='e' || *pIn=='E' || *pIn=='.' ) p->op = TK_FLOAT; } }while( *pIn++ ); - if( p->u.zToken[0]=='0' && p->u.zToken[1]=='x' ){ + if( p->u.zToken[0]=='0' && (p->u.zToken[1]=='x' || p->u.zToken[1]=='X') ){ p->op = TK_INTEGER; } } diff --git a/test/literal2.tcl b/test/literal2.tcl index 029d33f51a..e14a03587b 100644 --- a/test/literal2.tcl +++ b/test/literal2.tcl @@ -23,12 +23,17 @@ errorsql_test 1.1 { SELECT 123__456 } execsql_float_test 2.1 { SELECT 1.0e1_2 } -execsql_test 3.0 { SELECT 0xFF_FF } -execsql_test 3.1 { SELECT 0xFF_EF } - -errorsql_test 3.2 { SELECT 0xFF__EF } -# errorsql_test 3.3 { SELECT 0x_FFEF } -errorsql_test 3.4 { SELECT 0xFFEF_ } +execsql_test 3.0.0 { SELECT 0xFF_FF } +execsql_test 3.0.1 { SELECT 0xFF_EF } +errorsql_test 3.0.2 { SELECT 0xFF__EF } +# errorsql_test 3.0.3 { SELECT 0x_FFEF } +errorsql_test 3.0.4 { SELECT 0xFFEF_ } + +execsql_test 3.1.0 { SELECT 0XFF_FF } +execsql_test 3.1.1 { SELECT 0XFF_EF } +errorsql_test 3.1.2 { SELECT 0XFF__EF } +# errorsql_test 3.1.3 { SELECT 0X_FFEF } +errorsql_test 3.1.4 { SELECT 0XFFEF_ } finish_test diff --git a/test/literal2.test b/test/literal2.test index eda526fcef..ed177ca261 100644 --- a/test/literal2.test +++ b/test/literal2.test @@ -45,22 +45,40 @@ do_test 2.1 { set {} {} } {} -do_execsql_test 3.0 { +do_execsql_test 3.0.0 { SELECT 0xFF_FF } {65535} -do_execsql_test 3.1 { +do_execsql_test 3.0.1 { SELECT 0xFF_EF } {65519} # PG says ERROR: trailing junk after numeric literal at or near "0xFF_" -do_test 3.2 { catch { execsql { +do_test 3.0.2 { catch { execsql { SELECT 0xFF__EF } } } 1 # PG says ERROR: trailing junk after numeric literal at or near "0xFFEF_" -do_test 3.4 { catch { execsql { +do_test 3.0.4 { catch { execsql { SELECT 0xFFEF_ } } } 1 +do_execsql_test 3.1.0 { + SELECT 0XFF_FF +} {65535} + +do_execsql_test 3.1.1 { + SELECT 0XFF_EF +} {65519} + +# PG says ERROR: trailing junk after numeric literal at or near "0XFF_" +do_test 3.1.2 { catch { execsql { + SELECT 0XFF__EF +} } } 1 + +# PG says ERROR: trailing junk after numeric literal at or near "0XFFEF_" +do_test 3.1.4 { catch { execsql { + SELECT 0XFFEF_ +} } } 1 + finish_test From 727b35cbfcdaa1009e00f525c9e37bee584e4890 Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 22 Jan 2024 20:49:47 +0000 Subject: [PATCH 040/430] Simplification of the error reporting logic. FossilOrigin-Name: 59eb9d29e796886db17a578b64e75fd2797aebf969cbeeda70ecf2fda378c98f --- manifest | 15 ++++++--------- manifest.uuid | 2 +- src/resolve.c | 4 ++-- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/manifest b/manifest index 7a89979994..e117fbd0bb 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improved\serror\smessage\swhen\sa\sdouble-quoted\sstring\sis\sused\sand\sit\sseems\slikely\nthat\sthe\suser\swanted\sa\ssingle-quoted\sstring\sliteral. -D 2024-01-22T15:26:33.828 +C Simplification\sof\sthe\serror\sreporting\slogic. +D 2024-01-22T20:49:47.506 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -736,7 +736,7 @@ F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7 F src/prepare.c 371f6115cb69286ebc12c6f2d7511279c2e47d9f54f475d46a554d687a3b312c F src/printf.c 18fbdf028345c8fbe6044f5f5bfda5a10d48d6287afef088cc21b0ca57985640 F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c -F src/resolve.c 6221ea6fa0f4767b051bae74a2c967c4ca411fc46512a7f6f1ec97555114ea6b +F src/resolve.c 0ed10ebb70d15dcf3f1882051931ccfaf9c3f4debe67dbd114047d9e2adb9523 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c f1a81ff4f8e9e76c224e2ab3a4baa799add0db22158c7fcede65d8cc4a6fa2da F src/shell.c.in 5ea8c6b0057bfe3bcdff31949fe72aa231ae429047c421ea1b168af6825a4890 @@ -2159,11 +2159,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 65572223583d43e1d61ec029641f9d3ff340e68ecfba8342c8d1b0a91a680f2a -R 7e3b76756c0a4c8c51526beb20e2ad21 -T *branch * improved-dqs-error-msg -T *sym-improved-dqs-error-msg * -T -sym-trunk * +P 0a834bd81122b6e9c34c8253f9e45d53dab3274be28df60968366fa42237617b +R 55b4daf0d623afe21abf6d430f07654f U drh -Z eea53958dbf5ca2fad33a06e593a1f98 +Z 28de270bfc8a17f68f447b4061913785 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 5936974ca1..f001d964d3 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0a834bd81122b6e9c34c8253f9e45d53dab3274be28df60968366fa42237617b \ No newline at end of file +59eb9d29e796886db17a578b64e75fd2797aebf969cbeeda70ecf2fda378c98f \ No newline at end of file diff --git a/src/resolve.c b/src/resolve.c index fde5506f9c..29975f385a 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -755,9 +755,9 @@ static int lookupName( }else if( zTab ){ sqlite3ErrorMsg(pParse, "%s: %s.%s", zErr, zTab, zCol); }else if( cnt==0 && ExprHasProperty(pRight,EP_DblQuoted) ){ - sqlite3ErrorMsg(pParse, "no such column: \"%s\" - should this be a" + sqlite3ErrorMsg(pParse, "%s: \"%s\" - should this be a" " string literal in single-quotes?", - zCol); + zErr, zCol); }else{ sqlite3ErrorMsg(pParse, "%s: %s", zErr, zCol); } From 406eb5a146e06c29a5f1d8b8e25c10d125945a20 Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 23 Jan 2024 11:20:58 +0000 Subject: [PATCH 041/430] Add extra checks for the validity of a numeric literal to sqlite3DequoteNumber(). FossilOrigin-Name: d57407ef59baf699b72c8c4859abfaa7977dd41f6f16eb8fe1d53a68806eb966 --- manifest | 20 ++++++++++---------- manifest.uuid | 2 +- src/parse.y | 2 +- src/sqliteInt.h | 2 +- src/tokenize.c | 20 ++++---------------- src/util.c | 13 +++++++++---- test/literal.test | 4 ++-- 7 files changed, 28 insertions(+), 35 deletions(-) diff --git a/manifest b/manifest index f48cebcf73..0470957ccf 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sproblem\sin\sthe\sprevious\scommit\swith\shex\sliterals\sthat\sstart\swith\s"0X"\sinstead\sof\s"0x". -D 2024-01-22T19:42:56.220 +C Add\sextra\schecks\sfor\sthe\svalidity\sof\sa\snumeric\sliteral\sto\ssqlite3DequoteNumber(). +D 2024-01-23T11:20:58.812 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -727,7 +727,7 @@ F src/os_win.c 4a50a154aeebc66a1f8fb79c1ff6dd5fe3d005556533361e0d460d41cb6a45a8 F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a F src/pager.c ff60e98138d2499082ac6230f01ac508aba545315debccfca2fd6042f5f10fcd F src/pager.h 4b1140d691860de0be1347474c51fee07d5420bd7f802d38cbab8ea4ab9f538a -F src/parse.y 2354aaf964e7c4154a9dbe56ea55a797a0fa3021c38b50afe491ea4a387bf971 +F src/parse.y d2823ae4a503f83b3e8629c31470686624e46851d576c1f2b7bbec2e7328bb05 F src/pcache.c 040b165f30622a21b7a9a77c6f2e4877a32fb7f22d4c7f0d2a6fa6833a156a75 F src/pcache.h 1497ce1b823cf00094bb0cf3bac37b345937e6f910890c626b16512316d3abf5 F src/pcache1.c 602acb23c471bb8d557a6f0083cc2be641d6cafcafa19e481eba7ef4c9ca0f00 @@ -743,7 +743,7 @@ F src/shell.c.in d1ed426aae2d547932971e8019939cacb4dfda8258e45b8924b250e488e2d53 F src/sqlite.h.in 61a60b4ea04db8ead15e1579b20b64cb56e9f55d52c5f9f9694de630110593a3 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 -F src/sqliteInt.h 6e5e330d84b4ace70e3163721601f01df84566e6db21e1fc45bd00636e3d6640 +F src/sqliteInt.h a1367a4cd90c90e5eb2e5ca7d1be96823507f63b43030deb394f90f4f8d9ac10 F src/sqliteLimit.h 6878ab64bdeb8c24a1d762d45635e34b96da21132179023338c93f820eee6728 F src/status.c cb11f8589a6912af2da3bb1ec509a94dd8ef27df4d4c1a97e0bcf2309ece972b F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1 @@ -800,13 +800,13 @@ F src/test_windirent.h da2e5b73c32d09905fbdd00f27cd802212a32a58ead882736fe4f5eb7 F src/test_window.c cdae419fdcea5bad6dcd9368c685abdad6deb59e9fc8b84b153de513d394ba3f F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9 F src/threads.c 4ae07fa022a3dc7c5beb373cf744a85d3c5c6c3c -F src/tokenize.c 3ea60fcd98a0eb1391592a080fb8871b0026eaffbdb5795ef3b19bb7d48e702a +F src/tokenize.c 3f703cacdab728d7741e5a6ac242006d74fe1c2754d4f03ed889d7253259bd68 F src/treeview.c c6fc972683fd00f975d8b32a81c1f25d2fb7d4035366bf45c9f5622d3ccd70ee F src/trigger.c 0905b96b04bb6658509f711a8207287f1315cdbc3df1a1b13ba6483c8e341c81 F src/update.c 6904814dd62a7a93bbb86d9f1419c7f134a9119582645854ab02b36b676d9f92 F src/upsert.c fa125a8d3410ce9a97b02cb50f7ae68a2476c405c76aa692d3acf6b8586e9242 F src/utf.c f23165685a67b4caf8ec08fb274cb3f319103decfb2a980b7cfd55d18dfa855e -F src/util.c ef37d377684d6f725773c15bfc1ef5b75483b4f3b6b6198d4b8b969831623be0 +F src/util.c 88484a62e2465728288ca6e5b10f30489058e66266f52c70e87663310298793b F src/vacuum.c 604fcdaebe76f3497c855afcbf91b8fa5046b32de3045bab89cc008d68e40104 F src/vdbe.c 92910d536e0b77505599cd6ae5d9d449e4a5d31ada61da4c0bb84f6ccb2c3189 F src/vdbe.h 88e19a982df9027ec1c177c793d1a5d34dc23d8f06e3b2d997f43688b05ee0eb @@ -1355,7 +1355,7 @@ F test/like2.test d3be15fefee3e02fc88942a9b98f26c5339bbdef7783c90023c092c4955fe3 F test/like3.test a76e5938fadbe6d32807284c796bafd869974a961057bc5fc5a28e06de98745c F test/limit.test 350f5d03c29e7dff9a2cde016f84f8d368d40bcd02fa2b2a52fa10c4bf3cbfaf F test/limit2.test 9409b033284642a859fafc95f29a5a6a557bd57c1f0d7c3f554bd64ed69df77e -F test/literal.test e3d65d4091126cb008f31f57a324364511a83dd9461df31f60b5df6bd1f1f846 +F test/literal.test c4f6f281964ac5ab48a32bd978e80644affac822664879d7558762b2fad7aff5 F test/literal2.tcl 1499037beaf661aeecdbe48801220a181d805372a64c6128d5f26bb6a4a8f0ce F test/literal2.test b149e16b5fc9ee6249069a8858ed41052f222014fe0ba7ad43c2fb989c2dada2 F test/loadext.test faa4f6eed07a5aac35d57fdd7bc07f8fc82464cfd327567c10cf0ba3c86cde04 @@ -2161,8 +2161,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 81a56229460cc5b6acfd3c3729fcf89ea3cccb546ca2b4f4035b140c60911e18 -R 8fee7748a406cec8844b4286c6b28b8f +P c063c89b11487e6e712b97de604db316fa97bcf91ed810bb2dcbbcb54c68dbf4 +R 92b3c6e9a0a36e247ccad3d6a5b99b6c U dan -Z 6bae334234c9987a328b3a9421e4a531 +Z 62284248efaccf35cb9923c551aa2ba1 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index de37a7858c..66162263f5 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c063c89b11487e6e712b97de604db316fa97bcf91ed810bb2dcbbcb54c68dbf4 \ No newline at end of file +d57407ef59baf699b72c8c4859abfaa7977dd41f6f16eb8fe1d53a68806eb966 \ No newline at end of file diff --git a/src/parse.y b/src/parse.y index b0d03a04ee..c26a9bccc2 100644 --- a/src/parse.y +++ b/src/parse.y @@ -1926,7 +1926,7 @@ filter_clause(A) ::= FILTER LP WHERE expr(X) RP. { A = X; } term(A) ::= QNUMBER(X). { A=tokenExpr(pParse,@X,X); - sqlite3DequoteNumber(A); + sqlite3DequoteNumber(pParse, A); } /* There must be no more than 255 tokens defined above. If this grammar diff --git a/src/sqliteInt.h b/src/sqliteInt.h index c4aaf9d203..2db491fc81 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -4794,7 +4794,7 @@ int sqlite3ErrorToParser(sqlite3*,int); void sqlite3Dequote(char*); void sqlite3DequoteExpr(Expr*); void sqlite3DequoteToken(Token*); -void sqlite3DequoteNumber(Expr*); +void sqlite3DequoteNumber(Parse*, Expr*); void sqlite3TokenInit(Token*,char*); int sqlite3KeywordCode(const unsigned char*, int); int sqlite3RunParser(Parse*, const char*); diff --git a/src/tokenize.c b/src/tokenize.c index f01548d4cb..65d1fbf350 100644 --- a/src/tokenize.c +++ b/src/tokenize.c @@ -439,10 +439,7 @@ int sqlite3GetToken(const unsigned char *z, int *tokenType){ if( z[0]=='0' && (z[1]=='x' || z[1]=='X') && sqlite3Isxdigit(z[2]) ){ for(i=3; 1; i++){ if( sqlite3Isxdigit(z[i])==0 ){ - if( z[i]==SQLITE_DIGIT_SEPARATOR - && sqlite3Isxdigit(z[i-1]) - && sqlite3Isxdigit(z[i+1]) - ){ + if( z[i]==SQLITE_DIGIT_SEPARATOR ){ *tokenType = TK_QNUMBER; }else{ break; @@ -454,10 +451,7 @@ int sqlite3GetToken(const unsigned char *z, int *tokenType){ { for(i=0; 1; i++){ if( sqlite3Isdigit(z[i])==0 ){ - if( z[i]==SQLITE_DIGIT_SEPARATOR - && sqlite3Isdigit(z[i-1]) - && sqlite3Isdigit(z[i+1]) - ){ + if( z[i]==SQLITE_DIGIT_SEPARATOR ){ *tokenType = TK_QNUMBER; }else{ break; @@ -469,10 +463,7 @@ int sqlite3GetToken(const unsigned char *z, int *tokenType){ if( *tokenType==TK_INTEGER ) *tokenType = TK_FLOAT; for(i++; 1; i++){ if( sqlite3Isdigit(z[i])==0 ){ - if( z[i]==SQLITE_DIGIT_SEPARATOR - && sqlite3Isdigit(z[i-1]) - && sqlite3Isdigit(z[i+1]) - ){ + if( z[i]==SQLITE_DIGIT_SEPARATOR ){ *tokenType = TK_QNUMBER; }else{ break; @@ -488,10 +479,7 @@ int sqlite3GetToken(const unsigned char *z, int *tokenType){ if( *tokenType==TK_INTEGER ) *tokenType = TK_FLOAT; for(i+=2; 1; i++){ if( sqlite3Isdigit(z[i])==0 ){ - if( z[i]==SQLITE_DIGIT_SEPARATOR - && sqlite3Isdigit(z[i-1]) - && sqlite3Isdigit(z[i+1]) - ){ + if( z[i]==SQLITE_DIGIT_SEPARATOR ){ *tokenType = TK_QNUMBER; }else{ break; diff --git a/src/util.c b/src/util.c index ed7789591b..5a88979fe4 100644 --- a/src/util.c +++ b/src/util.c @@ -316,21 +316,26 @@ void sqlite3DequoteExpr(Expr *p){ ** and set the type to INTEGER or FLOAT. "Quoted" integers or floats are those ** that contain '_' characters that must be removed before further processing. */ -void sqlite3DequoteNumber(Expr *p){ +void sqlite3DequoteNumber(Parse *pParse, Expr *p){ if( p ){ const char *pIn = p->u.zToken; char *pOut = p->u.zToken; + int bHex = (pIn[0]=='0' && (pIn[1]=='x' || pIn[1]=='X')); assert( p->op==TK_QNUMBER ); p->op = TK_INTEGER; do { if( *pIn!=SQLITE_DIGIT_SEPARATOR ){ *pOut++ = *pIn; if( *pIn=='e' || *pIn=='E' || *pIn=='.' ) p->op = TK_FLOAT; + }else{ + if( (bHex==0 && (!sqlite3Isdigit(pIn[-1]) || !sqlite3Isdigit(pIn[1]))) + || (bHex==1 && (!sqlite3Isxdigit(pIn[-1]) || !sqlite3Isxdigit(pIn[1]))) + ){ + sqlite3ErrorMsg(pParse, "unrecognized token: \"%s\"", p->u.zToken); + } } }while( *pIn++ ); - if( p->u.zToken[0]=='0' && (p->u.zToken[1]=='x' || p->u.zToken[1]=='X') ){ - p->op = TK_INTEGER; - } + if( bHex ) p->op = TK_INTEGER; } } diff --git a/test/literal.test b/test/literal.test index fe6b70acf7..30205692c9 100644 --- a/test/literal.test +++ b/test/literal.test @@ -74,7 +74,7 @@ test_literal 3.8 -9_223_372_036_854_775_808 integer -9223372036854775808 foreach {tn lit unrec} { 0 123a456 123a456 1 1_ 1_ - 2 1_.4 1_ + 2 1_.4 1_.4 3 1e_4 1e_4 4 1_e4 1_e4 5 1.4_e4 1.4_e4 @@ -86,7 +86,7 @@ foreach {tn lit unrec} { 11 12__34 12__34 12 1234_ 1234_ 13 12._34 12._34 - 14 12_.34 12_ + 14 12_.34 12_.34 15 12.34_ 12.34_ 16 1.0e1_______2 1.0e1_______2 } { From 91cee17d8334c91cad1919230c1ba61812f86317 Mon Sep 17 00:00:00 2001 From: stephan Date: Tue, 23 Jan 2024 12:51:17 +0000 Subject: [PATCH 042/430] Change the shell's --help flag to exit with code 0 instead of 1, per /forum and /chat discussions. FossilOrigin-Name: df563a18578c5cf1aaecf5818c93967aaa70475598d3c099779622ac8911f926 --- manifest | 15 +++++++-------- manifest.uuid | 2 +- src/shell.c.in | 2 +- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 105fdc6b4b..0080b0dd01 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\stest\sscript\sliteral.test\sso\sthat\sit\sworks\swith\sSQLITE_OMIT_ALTER_TABLE\sbuilds. -D 2024-01-22T14:01:07.189 +C Change\sthe\sshell's\s--help\sflag\sto\sexit\swith\scode\s0\sinstead\sof\s1,\sper\s/forum\sand\s/chat\sdiscussions. +D 2024-01-23T12:51:17.111 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -739,7 +739,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c e25f51a473a5f30a0d978e4df2aaa98aeec84eac29ecae1ad4708a6c3e669345 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c f1a81ff4f8e9e76c224e2ab3a4baa799add0db22158c7fcede65d8cc4a6fa2da -F src/shell.c.in 5ea8c6b0057bfe3bcdff31949fe72aa231ae429047c421ea1b168af6825a4890 +F src/shell.c.in c6cb773b7703d76677529de19d1c40584520701966422c33da3e9334498a7099 F src/sqlite.h.in 61a60b4ea04db8ead15e1579b20b64cb56e9f55d52c5f9f9694de630110593a3 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 @@ -2159,9 +2159,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 249048b0cbc37058c229a785182e07b46029584aff9c385269b0b93503153476 -Q +b57327be4be9638f5ee834a6c9e06135aaef9e499516f8b53f927ffe81033f61 -R 30b53374dcbd0df72ff4a36d2f8af72e -U dan -Z 80e756b96db0b6ae94203f53b2e0b98b +P 4dc00f577632c7b13135505007804d42a12f81a9ebd58d4c380727256b054b7e +R 7d04a318d80ba08d1692be25eacaeef6 +U stephan +Z b8daa0711959586873a5caee05ab1e56 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index cbd31ca380..eebd6825b5 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4dc00f577632c7b13135505007804d42a12f81a9ebd58d4c380727256b054b7e \ No newline at end of file +df563a18578c5cf1aaecf5818c93967aaa70475598d3c099779622ac8911f926 \ No newline at end of file diff --git a/src/shell.c.in b/src/shell.c.in index 02850691d9..353db72ede 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -11926,7 +11926,7 @@ static void usage(int showDetail){ }else{ eputz("Use the -help option for additional information\n"); } - exit(1); + exit(0); } /* From e318f10ce25f2c36ce3bcbca71688c1060546dd8 Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 23 Jan 2024 13:21:40 +0000 Subject: [PATCH 043/430] If a BLOB looks like JSON when cast to text, then treat it as if it really were JSON. This replicates a long-standing bug in the JSON processing routines, and thereby avoids breaking legacy. FossilOrigin-Name: d79a37690ce7ebb91df203170d73511da44546328043c2b3fe1786b2f0087093 --- manifest | 13 +++---- manifest.uuid | 2 +- src/json.c | 45 ++++++++++++------------- test/json107.test | 86 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 115 insertions(+), 31 deletions(-) create mode 100644 test/json107.test diff --git a/manifest b/manifest index ddd60a6df8..3a5eb3c4a6 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C The\s-DSQLITE_JSON_BLOB_INPUT_BUG_COMPATIBLE\scompile-time\soption\scauses\sblob\ninputs\sto\sJSON\sfunctions\sthat\sare\snot\sJSONB\sto\sbe\sprocessed\sas\sif\sthey\nwhere\stext,\simmulating\shistorical\sbugging\sbehavior\swhich\ssome\sapplications\nhave\scome\sto\srely\supon.\s\sSee\n[forum:/forumpost/012136abd5292b8d|forum\sthread\s012136abd5292b8d]\sfor\ndiscussion. -D 2024-01-22T14:16:10.354 +C If\sa\sBLOB\slooks\slike\sJSON\swhen\scast\sto\stext,\sthen\streat\sit\sas\sif\sit\sreally\nwere\sJSON.\s\sThis\sreplicates\sa\slong-standing\sbug\sin\sthe\sJSON\sprocessing\nroutines,\sand\sthereby\savoids\sbreaking\slegacy. +D 2024-01-23T13:21:40.846 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -698,7 +698,7 @@ F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 F src/insert.c 3f0a94082d978bbdd33c38fefea15346c6c6bffb70bc645a71dc0f1f87dd3276 -F src/json.c 99f2825b44327811bdf47808e57077388b83bcc6a253c1269d13fd1b3237138d +F src/json.c 14563eed12fdf0753eb8df2a72480a626335ab4467bc4dfdf15f9652f11ae1b8 F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 F src/main.c 438b95162acfa17b7d218f586f5bde11d6ae82bcf030c9611fc537556870ad6b @@ -1342,6 +1342,7 @@ F test/json103.test 53df87f83a4e5fa0c0a56eb29ff6c94055c6eb919f33316d62161a888011 F test/json104.test 1b844a70cddcfa2e4cd81a5db0657b2e61e7f00868310f24f56a9ba0114348c1 F test/json105.test 043838b56e68f3252a0dcf5be1689016f6f3f05056f8dcfcdc9d074f4d932988 F test/json106.test 1d46a9294e2ced35c7f87cebbcb9626d01abab04f1969d7ded7b6f6a1d9be0f2 +F test/json107.test 59054e815c8f6b67d634d44ace421cf975828fb5651c4460aa66015c8e19d562 F test/json501.test ab168a12eb6eb14d479f8c1cdae3ac062fd5a4679f17f976e96f1af518408330 F test/json502.test 84634d3dbb521d2814e43624025b760c6198456c8197bbec6c977c0236648f5b F test/jsonb01.test cace70765b36a36aec9a85a41ea65667d3bbf647d4400ddc3ac76f8fe7d94f90 @@ -2159,8 +2160,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 4dc00f577632c7b13135505007804d42a12f81a9ebd58d4c380727256b054b7e -R 59af26cba445671768ccc033868954ad +P 65572223583d43e1d61ec029641f9d3ff340e68ecfba8342c8d1b0a91a680f2a +R d924d06eebab83ae665aafd4e67b28da U drh -Z 9f8b0dd9fdc4264b889c936f6659e28d +Z 70b17e73c0bc74c502f8785eed06d844 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 25bb88a0e7..916c951931 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -65572223583d43e1d61ec029641f9d3ff340e68ecfba8342c8d1b0a91a680f2a \ No newline at end of file +d79a37690ce7ebb91df203170d73511da44546328043c2b3fe1786b2f0087093 \ No newline at end of file diff --git a/src/json.c b/src/json.c index b9a88822e0..69995bbdfb 100644 --- a/src/json.c +++ b/src/json.c @@ -3311,20 +3311,18 @@ static JsonParse *jsonParseFuncArg( } return p; } -#if defined(SQLITE_JSON_BLOB_INPUT_BUG_COMPATIBLE) - /* If the input is a BLOB that is not JSONB, fall through into trying - ** to process that BLOB as if it where text. This goes against all - ** historical documentation about how the SQLite JSON functions are - ** suppose to work. Nevertheless, many SQLite implementations prior to - ** version 3.45.0 contained a bug such that they did behave this way - ** and some applications came to depend upon this buggy behavior. The - ** SQLITE_JSON_BLOB_INPUT_BUG_COMPATIBLE compile-time option provides - ** a mechanism for those applications to continue working even after - ** the bug was fixed. See - ** https://sqlite.org/forum/forumpost/012136abd5292b8d */ -#else - goto json_pfa_malformed; -#endif + /* If the blob is not valid JSONB, fall through into trying to cast + ** the blob into text which is then interpreted as JSON. (tag-20240123-a) + ** + ** This goes against all historical documentation about how the SQLite + ** JSON functions were suppose to work. From the beginning, blob was + ** reserved for expansion and a blob value should have raised an error. + ** But it did not, due to a bug. And many applications came to depend + ** upon this buggy behavior, espeically when using the CLI and reading + ** JSON text using readfile(), which returns a blob. For this reason + ** we will continue to support the bug moving forward. + ** See for example https://sqlite.org/forum/forumpost/012136abd5292b8d + */ } p->zJson = (char*)sqlite3_value_text(pArg); p->nJson = sqlite3_value_bytes(pArg); @@ -4300,12 +4298,12 @@ static void jsonValidFunc( return; } case SQLITE_BLOB: { - if( (flags & 0x0c)!=0 && jsonFuncArgMightBeBinary(argv[0]) ){ + if( jsonFuncArgMightBeBinary(argv[0]) ){ if( flags & 0x04 ){ /* Superficial checking only - accomplished by the ** jsonFuncArgMightBeBinary() call above. */ res = 1; - }else{ + }else if( flags & 0x08 ){ /* Strict checking. Check by translating BLOB->TEXT->BLOB. If ** no errors occur, call that a "strict check". */ JsonParse px; @@ -4316,8 +4314,11 @@ static void jsonValidFunc( iErr = jsonbValidityCheck(&px, 0, px.nBlob, 1); res = iErr==0; } + break; } - break; + /* Fall through into interpreting the input as text. See note + ** above at tag-20240124-a. */ + /* no break */ deliberate_fall_through } default: { JsonParse px; @@ -5053,13 +5054,9 @@ static int jsonEachFilter( memset(&p->sParse, 0, sizeof(p->sParse)); p->sParse.nJPRef = 1; p->sParse.db = p->db; - if( sqlite3_value_type(argv[0])==SQLITE_BLOB ){ - if( jsonFuncArgMightBeBinary(argv[0]) ){ - p->sParse.nBlob = sqlite3_value_bytes(argv[0]); - p->sParse.aBlob = (u8*)sqlite3_value_blob(argv[0]); - }else{ - goto json_each_malformed_input; - } + if( jsonFuncArgMightBeBinary(argv[0]) ){ + p->sParse.nBlob = sqlite3_value_bytes(argv[0]); + p->sParse.aBlob = (u8*)sqlite3_value_blob(argv[0]); }else{ p->sParse.zJson = (char*)sqlite3_value_text(argv[0]); p->sParse.nJson = sqlite3_value_bytes(argv[0]); diff --git a/test/json107.test b/test/json107.test new file mode 100644 index 0000000000..779b557fba --- /dev/null +++ b/test/json107.test @@ -0,0 +1,86 @@ +# 2024-01-23 +# +# 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. +# +#*********************************************************************** +# +# Legacy JSON bug: If the input is a BLOB that when cast into TEXT looks +# like valid JSON, then treat it as valid JSON. +# +# The original intent of the JSON functions was to raise an error on any +# BLOB input. That intent was clearly documented, but the code failed to +# to implement it. Subsequently, many applications began to depend on the +# incorrect behavior, especially apps that used readfile() to read JSON +# content, since readfile() returns a BLOB. So we need to support the +# bug moving forward. +# +# The tests in this fail verify that the original buggy behavior is +# preserved. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix json107 + +if {[db one {PRAGMA encoding}]!="UTF-8"} { + # These tests only work for a UTF-8 encoding. + finish_test + return +} + +do_execsql_test 1.1 { + SELECT json_valid( CAST('{"a":1}' AS BLOB) ); +} 1 +do_execsql_test 1.1.1 { + SELECT json_valid( CAST('{"a":1}' AS BLOB), 1); +} 1 +do_execsql_test 1.1.2 { + SELECT json_valid( CAST('{"a":1}' AS BLOB), 2); +} 1 +do_execsql_test 1.1.4 { + SELECT json_valid( CAST('{"a":1}' AS BLOB), 4); +} 0 +do_execsql_test 1.1.8 { + SELECT json_valid( CAST('{"a":1}' AS BLOB), 8); +} 0 + +do_execsql_test 1.2.1 { + SELECT CAST('{"a":123}' AS blob) -> 'a'; +} 123 +do_execsql_test 1.2.2 { + SELECT CAST('{"a":123}' AS blob) ->> 'a'; +} 123 +do_execsql_test 1.2.3 { + SELECT json_extract(CAST('{"a":123}' AS blob), '$.a'); +} 123 +do_execsql_test 1.3 { + SELECT json_insert(CAST('{"a":123}' AS blob),'$.b',456); +} {{{"a":123,"b":456}}} +do_execsql_test 1.4 { + SELECT json_remove(CAST('{"a":123,"b":456}' AS blob),'$.a'); +} {{{"b":456}}} +do_execsql_test 1.5 { + SELECT json_set(CAST('{"a":123,"b":456}' AS blob),'$.a',789); +} {{{"a":789,"b":456}}} +do_execsql_test 1.6 { + SELECT json_replace(CAST('{"a":123,"b":456}' AS blob),'$.a',789); +} {{{"a":789,"b":456}}} +do_execsql_test 1.7 { + SELECT json_type(CAST('{"a":123,"b":456}' AS blob)); +} object +do_execsql_test 1.8 { + SELECT json(CAST('{"a":123,"b":456}' AS blob)); +} {{{"a":123,"b":456}}} + +ifcapable vtab { + do_execsql_test 2.1 { + SELECT key, value FROM json_tree( CAST('{"a":123,"b":456}' AS blob) ) + WHERE atom; + } {a 123 b 456} +} +finish_test From 6bb8ce6375f9f2586821c02b646d701e7ca64aaa Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 23 Jan 2024 13:28:21 +0000 Subject: [PATCH 044/430] Fix typo in the tag-20240123-a in a comment. FossilOrigin-Name: 1f09541eb4203ccce476f6040ff134353850f22f07fb84f96a1d2c27b304a91b --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/json.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 3a5eb3c4a6..bd360840cf 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C If\sa\sBLOB\slooks\slike\sJSON\swhen\scast\sto\stext,\sthen\streat\sit\sas\sif\sit\sreally\nwere\sJSON.\s\sThis\sreplicates\sa\slong-standing\sbug\sin\sthe\sJSON\sprocessing\nroutines,\sand\sthereby\savoids\sbreaking\slegacy. -D 2024-01-23T13:21:40.846 +C Fix\stypo\sin\sthe\stag-20240123-a\sin\sa\scomment. +D 2024-01-23T13:28:21.325 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -698,7 +698,7 @@ F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 F src/insert.c 3f0a94082d978bbdd33c38fefea15346c6c6bffb70bc645a71dc0f1f87dd3276 -F src/json.c 14563eed12fdf0753eb8df2a72480a626335ab4467bc4dfdf15f9652f11ae1b8 +F src/json.c b2189995bb2f5eeac20a0282983cc82198fc77f9429708468ba360bbacb6fa80 F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 F src/main.c 438b95162acfa17b7d218f586f5bde11d6ae82bcf030c9611fc537556870ad6b @@ -2160,8 +2160,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 65572223583d43e1d61ec029641f9d3ff340e68ecfba8342c8d1b0a91a680f2a -R d924d06eebab83ae665aafd4e67b28da +P d79a37690ce7ebb91df203170d73511da44546328043c2b3fe1786b2f0087093 +R daf98ef3cd5515173b41dfefd789b29a U drh -Z 70b17e73c0bc74c502f8785eed06d844 +Z 73f4e47cde19088f6970a061f009bfef # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 916c951931..60064befb3 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d79a37690ce7ebb91df203170d73511da44546328043c2b3fe1786b2f0087093 \ No newline at end of file +1f09541eb4203ccce476f6040ff134353850f22f07fb84f96a1d2c27b304a91b \ No newline at end of file diff --git a/src/json.c b/src/json.c index 69995bbdfb..c7412d3c78 100644 --- a/src/json.c +++ b/src/json.c @@ -4317,7 +4317,7 @@ static void jsonValidFunc( break; } /* Fall through into interpreting the input as text. See note - ** above at tag-20240124-a. */ + ** above at tag-20240123-a. */ /* no break */ deliberate_fall_through } default: { From bcf3df01928257644f91ead9a28b7b8487104508 Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 23 Jan 2024 16:09:22 +0000 Subject: [PATCH 045/430] In os_unix.c and os_win.c, do not allow xFetch() to return a pointer to a page buffer that is right at the end of the mapped region - if the database is corrupted in a specific way such a page buffer might be overread by several bytes. FossilOrigin-Name: 2684feac3bc9c5463604900d72710be861527614f4957224c74a16a3b3c702f5 --- manifest | 20 ++++++++--------- manifest.uuid | 2 +- src/os_unix.c | 7 +++++- src/os_win.c | 7 +++++- test/mmap1.test | 12 +++++----- test/mmapcorrupt.test | 51 +++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 80 insertions(+), 19 deletions(-) create mode 100644 test/mmapcorrupt.test diff --git a/manifest b/manifest index 116ab1ad12..c4f57831bb 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improved\serror\smessage\swhen\sa\sdouble-quoted\sidentifier\sname\scannot\sbe\nresolved\s-\sask\sthe\suser\sif\sthey\sintended\sto\suse\sa\sstring\sliteral. -D 2024-01-23T14:45:22.468 +C In\sos_unix.c\sand\sos_win.c,\sdo\snot\sallow\sxFetch()\sto\sreturn\sa\spointer\sto\sa\spage\sbuffer\sthat\sis\sright\sat\sthe\send\sof\sthe\smapped\sregion\s-\sif\sthe\sdatabase\sis\scorrupted\sin\sa\sspecific\sway\ssuch\sa\spage\sbuffer\smight\sbe\soverread\sby\sseveral\sbytes. +D 2024-01-23T16:09:22.291 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -722,8 +722,8 @@ F src/os.h 1ff5ae51d339d0e30d8a9d814f4b8f8e448169304d83a7ed9db66a65732f3e63 F src/os_common.h 6c0eb8dd40ef3e12fe585a13e709710267a258e2c8dd1c40b1948a1d14582e06 F src/os_kv.c 4d39e1f1c180b11162c6dc4aa8ad34053873a639bac6baae23272fc03349986a F src/os_setup.h 6011ad7af5db4e05155f385eb3a9b4470688de6f65d6166b8956e58a3d872107 -F src/os_unix.c 5dc41030cd5dfd99b907976b1725a4ed695566405d33744e4824c3d6aff245a3 -F src/os_win.c 4a50a154aeebc66a1f8fb79c1ff6dd5fe3d005556533361e0d460d41cb6a45a8 +F src/os_unix.c fa9b81b642e60e77ffaf98bd1a2e5fde16c1c2317614ec178bf3bd5864772356 +F src/os_win.c 6ff43bac175bd9ed79e7c0f96840b139f2f51d01689a638fd05128becf94908a F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a F src/pager.c ff60e98138d2499082ac6230f01ac508aba545315debccfca2fd6042f5f10fcd F src/pager.h 4b1140d691860de0be1347474c51fee07d5420bd7f802d38cbab8ea4ab9f538a @@ -1419,10 +1419,11 @@ F test/misc7.test d912f3d45c2989191b797504a220ca225d6be80b21acad22ba0d35f4a9ee45 F test/misc8.test 4db9f8be59834cea08c87e9658014080efa02678ef54a088f84fa5647e81fee0 F test/misuse.test 9e7f78402005e833af71dcab32d048003869eca5abcaccc985d4f8dc1d86bcc7 F test/mjournal.test 28a08d5cb5fb5b5702a46e19176e45e964e0800d1f894677169e79f34030e152 -F test/mmap1.test 5c1f768828094b0dd94e55ae7f10489a1ded74772682be2c4c78679d0acaf7ef +F test/mmap1.test e154d0442c9b43646f86b8ddc38b656bb8bc79284209a9367076473cec5d0eef F test/mmap2.test 9d6dd9ddb4ad2379f29cc78f38ce1e63ed418022 F test/mmap3.test b3c297e78e6a8520aafcc1a8f140535594c9086e F test/mmap4.test 2e2b4e32555b58da15176e6fe750f17c9dcf7f93 +F test/mmapcorrupt.test 0d89724591f22a376019f3df60d075b838dd2ba6dae6effb0be465c49cf86d4a F test/mmapfault.test d4c9eff9cd8c2dc14bc43e71e042f175b0a26fe3 F test/mmapwarm.test 2272005969cd17a910077bd5082f70bc1fefad9a875afec7fc9af483898ecaf3 F test/multiplex.test d74c034e52805f6de8cc5432cef8c9eb774bb64ec29b83a22effc8ca4dac1f08 @@ -2160,9 +2161,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P e5dc81d5c7ee97866feb688dfa9b6fc225dabff2b020b9b96b49a8fea5640aec 59eb9d29e796886db17a578b64e75fd2797aebf969cbeeda70ecf2fda378c98f -R c6b194554d1ef13c7fd9b0cfa6d21ae1 -T +closed 59eb9d29e796886db17a578b64e75fd2797aebf969cbeeda70ecf2fda378c98f -U drh -Z e1ae068dffaf45ea92f1b3624e579582 +P efc5c3c5e6ae1f9f0be61ea4ce7b3e34f3dc318791c78e0f4bebebeaccf6951e +R d2fac210a7e93b5529ce586e57a37021 +U dan +Z 75c6fc2c30c7c083cae329bbdba750e2 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index cfd6af6d29..104eee66ea 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -efc5c3c5e6ae1f9f0be61ea4ce7b3e34f3dc318791c78e0f4bebebeaccf6951e \ No newline at end of file +2684feac3bc9c5463604900d72710be861527614f4957224c74a16a3b3c702f5 \ No newline at end of file diff --git a/src/os_unix.c b/src/os_unix.c index 80e6f6ad9a..4b3d63c2c1 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -5441,11 +5441,16 @@ static int unixFetch(sqlite3_file *fd, i64 iOff, int nAmt, void **pp){ #if SQLITE_MAX_MMAP_SIZE>0 if( pFd->mmapSizeMax>0 ){ + /* Ensure that there is always at least a 256 byte buffer of addressable + ** memory following the returned page. If the database is corrupt, + ** SQLite may overread the page slightly (in practice only a few bytes, + ** but 256 is safe, round, number). */ + const int nEofBuffer = 256; if( pFd->pMapRegion==0 ){ int rc = unixMapfile(pFd, -1); if( rc!=SQLITE_OK ) return rc; } - if( pFd->mmapSize >= iOff+nAmt ){ + if( pFd->mmapSize >= (iOff+nAmt+nEofBuffer) ){ *pp = &((u8 *)pFd->pMapRegion)[iOff]; pFd->nFetchOut++; } diff --git a/src/os_win.c b/src/os_win.c index dc16c08b51..442c108e9d 100644 --- a/src/os_win.c +++ b/src/os_win.c @@ -4521,6 +4521,11 @@ static int winFetch(sqlite3_file *fd, i64 iOff, int nAmt, void **pp){ #if SQLITE_MAX_MMAP_SIZE>0 if( pFd->mmapSizeMax>0 ){ + /* Ensure that there is always at least a 256 byte buffer of addressable + ** memory following the returned page. If the database is corrupt, + ** SQLite may overread the page slightly (in practice only a few bytes, + ** but 256 is safe, round, number). */ + const int nEofBuffer = 256; if( pFd->pMapRegion==0 ){ int rc = winMapfile(pFd, -1); if( rc!=SQLITE_OK ){ @@ -4529,7 +4534,7 @@ static int winFetch(sqlite3_file *fd, i64 iOff, int nAmt, void **pp){ return rc; } } - if( pFd->mmapSize >= iOff+nAmt ){ + if( pFd->mmapSize >= (iOff+nAmt+nEofBuffer) ){ assert( pFd->pMapRegion!=0 ); *pp = &((u8 *)pFd->pMapRegion)[iOff]; pFd->nFetchOut++; diff --git a/test/mmap1.test b/test/mmap1.test index 3362f7187f..01cb4bddb9 100644 --- a/test/mmap1.test +++ b/test/mmap1.test @@ -45,17 +45,17 @@ proc register_rblob_code {dbname seed} { } -# For cases 1.1 and 1.4, the number of pages read using xRead() is 4 on -# unix and 9 on windows. The difference is that windows only ever maps +# For cases 1.1 and 1.4, the number of pages read using xRead() is 8 on +# unix and 12 on windows. The difference is that windows only ever maps # an integer number of OS pages (i.e. creates mappings that are a multiple # of 4KB in size). Whereas on unix any sized mapping may be created. # foreach {t mmap_size nRead c2init} { - 1.1 { PRAGMA mmap_size = 67108864 } /[49]/ {PRAGMA mmap_size = 0} - 1.2 { PRAGMA mmap_size = 53248 } 150 {PRAGMA mmap_size = 0} + 1.1 { PRAGMA mmap_size = 67108864 } /8|12/ {PRAGMA mmap_size = 0} + 1.2 { PRAGMA mmap_size = 53248 } 154 {PRAGMA mmap_size = 0} 1.3 { PRAGMA mmap_size = 0 } 344 {PRAGMA mmap_size = 0} - 1.4 { PRAGMA mmap_size = 67108864 } /[49]/ {PRAGMA mmap_size = 67108864 } - 1.5 { PRAGMA mmap_size = 53248 } 150 {PRAGMA mmap_size = 67108864 } + 1.4 { PRAGMA mmap_size = 67108864 } /12|8/ {PRAGMA mmap_size = 67108864 } + 1.5 { PRAGMA mmap_size = 53248 } 154 {PRAGMA mmap_size = 67108864 } 1.6 { PRAGMA mmap_size = 0 } 344 {PRAGMA mmap_size = 67108864 } } { diff --git a/test/mmapcorrupt.test b/test/mmapcorrupt.test new file mode 100644 index 0000000000..70dbe84647 --- /dev/null +++ b/test/mmapcorrupt.test @@ -0,0 +1,51 @@ +# 2024 January 23 +# +# 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. +# +#*********************************************************************** +# +# Test special cases of corrupt database handling in mmap-mode. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix mmapcorrupt + +database_may_be_corrupt + +db close +sqlite3_shutdown +sqlite3_config_lookaside 0 0 +sqlite3_initialize + +reset_db +do_execsql_test 1.0 { + PRAGMA page_size = 16384; + CREATE TABLE tn1(a PRIMARY KEY) WITHOUT ROWID; + CREATE TABLE t0(a PRIMARY KEY) WITHOUT ROWID; + CREATE TABLE t1(a PRIMARY KEY) WITHOUT ROWID; + INSERT INTO t1 VALUES('B'); +} +db close + +set sz [file size test.db] +hexio_write test.db [expr $sz-3] 800380 + +sqlite3 db test.db +do_execsql_test 2.1 { + PRAGMA mmap_size = 1000000; + SELECT sql FROM sqlite_schema LIMIT 1; + SELECT * FROM t0; +} {1000000 {CREATE TABLE tn1(a PRIMARY KEY) WITHOUT ROWID}} + +do_execsql_test 2.2 { + INSERT INTO t0 SELECT * FROM t1; +} + +finish_test + From fa079680f1c2d6cc254ece7a76fd44ebfa28673c Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 23 Jan 2024 21:10:01 +0000 Subject: [PATCH 046/430] Slight adjustment to test results for Windows in mmap1.test due to the previous check-in. FossilOrigin-Name: 5cf9ea9b1fff4625a50a2343d0fd3812da6612d6b24c07e10edb6c1ff03ca2df --- manifest | 14 +++++++------- manifest.uuid | 2 +- test/mmap1.test | 12 ++++++------ 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/manifest b/manifest index c4f57831bb..6b179c3f9c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C In\sos_unix.c\sand\sos_win.c,\sdo\snot\sallow\sxFetch()\sto\sreturn\sa\spointer\sto\sa\spage\sbuffer\sthat\sis\sright\sat\sthe\send\sof\sthe\smapped\sregion\s-\sif\sthe\sdatabase\sis\scorrupted\sin\sa\sspecific\sway\ssuch\sa\spage\sbuffer\smight\sbe\soverread\sby\sseveral\sbytes. -D 2024-01-23T16:09:22.291 +C Slight\sadjustment\sto\stest\sresults\sfor\sWindows\sin\smmap1.test\sdue\sto\nthe\sprevious\scheck-in. +D 2024-01-23T21:10:01.121 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -1419,7 +1419,7 @@ F test/misc7.test d912f3d45c2989191b797504a220ca225d6be80b21acad22ba0d35f4a9ee45 F test/misc8.test 4db9f8be59834cea08c87e9658014080efa02678ef54a088f84fa5647e81fee0 F test/misuse.test 9e7f78402005e833af71dcab32d048003869eca5abcaccc985d4f8dc1d86bcc7 F test/mjournal.test 28a08d5cb5fb5b5702a46e19176e45e964e0800d1f894677169e79f34030e152 -F test/mmap1.test e154d0442c9b43646f86b8ddc38b656bb8bc79284209a9367076473cec5d0eef +F test/mmap1.test 18de3fd7b70a777af6004ca2feecfcdd3d0be17fa04058e808baf530c94b1a1d F test/mmap2.test 9d6dd9ddb4ad2379f29cc78f38ce1e63ed418022 F test/mmap3.test b3c297e78e6a8520aafcc1a8f140535594c9086e F test/mmap4.test 2e2b4e32555b58da15176e6fe750f17c9dcf7f93 @@ -2161,8 +2161,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P efc5c3c5e6ae1f9f0be61ea4ce7b3e34f3dc318791c78e0f4bebebeaccf6951e -R d2fac210a7e93b5529ce586e57a37021 -U dan -Z 75c6fc2c30c7c083cae329bbdba750e2 +P 2684feac3bc9c5463604900d72710be861527614f4957224c74a16a3b3c702f5 +R 914fcc8566f9cd381eed502f3475f2e9 +U drh +Z 4b9eeb9a5957633229a8e3aa9d4bef67 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 104eee66ea..19d180bb45 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2684feac3bc9c5463604900d72710be861527614f4957224c74a16a3b3c702f5 \ No newline at end of file +5cf9ea9b1fff4625a50a2343d0fd3812da6612d6b24c07e10edb6c1ff03ca2df \ No newline at end of file diff --git a/test/mmap1.test b/test/mmap1.test index 01cb4bddb9..6a9625427a 100644 --- a/test/mmap1.test +++ b/test/mmap1.test @@ -51,12 +51,12 @@ proc register_rblob_code {dbname seed} { # of 4KB in size). Whereas on unix any sized mapping may be created. # foreach {t mmap_size nRead c2init} { - 1.1 { PRAGMA mmap_size = 67108864 } /8|12/ {PRAGMA mmap_size = 0} - 1.2 { PRAGMA mmap_size = 53248 } 154 {PRAGMA mmap_size = 0} - 1.3 { PRAGMA mmap_size = 0 } 344 {PRAGMA mmap_size = 0} - 1.4 { PRAGMA mmap_size = 67108864 } /12|8/ {PRAGMA mmap_size = 67108864 } - 1.5 { PRAGMA mmap_size = 53248 } 154 {PRAGMA mmap_size = 67108864 } - 1.6 { PRAGMA mmap_size = 0 } 344 {PRAGMA mmap_size = 67108864 } + 1.1 { PRAGMA mmap_size = 67108864 } /8|12/ {PRAGMA mmap_size = 0} + 1.2 { PRAGMA mmap_size = 53248 } /15[34]/ {PRAGMA mmap_size = 0} + 1.3 { PRAGMA mmap_size = 0 } 344 {PRAGMA mmap_size = 0} + 1.4 { PRAGMA mmap_size = 67108864 } /12|8/ {PRAGMA mmap_size = 67108864 } + 1.5 { PRAGMA mmap_size = 53248 } /15[34]/ {PRAGMA mmap_size = 67108864 } + 1.6 { PRAGMA mmap_size = 0 } 344 {PRAGMA mmap_size = 67108864 } } { do_multiclient_test tn { From 4821b15dca234d86d1042f652a045796fc92c16e Mon Sep 17 00:00:00 2001 From: stephan Date: Wed, 24 Jan 2024 19:54:49 +0000 Subject: [PATCH 047/430] Update ext/wasm/SQLTester for recent internal-API reorgs. FossilOrigin-Name: 996cfdf9b5f70408faeaa68ba2ea9494e419be8f2c59d89ab702419056e3569c --- ext/wasm/SQLTester/SQLTester.mjs | 12 +++++++++--- manifest | 14 +++++++------- manifest.uuid | 2 +- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/ext/wasm/SQLTester/SQLTester.mjs b/ext/wasm/SQLTester/SQLTester.mjs index a72399aefc..71c5d4c538 100644 --- a/ext/wasm/SQLTester/SQLTester.mjs +++ b/ext/wasm/SQLTester/SQLTester.mjs @@ -174,11 +174,17 @@ const Rx = newObj({ squiggly: /[{}]/ }); + + const Util = newObj({ toss, - unlink: function(fn){ - return 0==sqlite3.wasm.sqlite3_wasm_vfs_unlink(0,fn); + unlink: function f(fn){ + if(!f.unlink){ + f.unlink = sqlite3.wasm.xWrap('sqlite3__wasm_vfs_unlink','int', + ['*','string']); + } + return 0==f.unlink(0,fn); }, argvToString: (list)=>{ @@ -197,7 +203,7 @@ const Util = newObj({ utf8Encode: (str)=>__utf8Encoder.encode(str), - strglob: sqlite3.wasm.xWrap('sqlite3_wasm_SQLTester_strglob','int', + strglob: sqlite3.wasm.xWrap('sqlite3__wasm_SQLTester_strglob','int', ['string','string']) })/*Util*/; diff --git a/manifest b/manifest index 6b179c3f9c..b129f28e22 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Slight\sadjustment\sto\stest\sresults\sfor\sWindows\sin\smmap1.test\sdue\sto\nthe\sprevious\scheck-in. -D 2024-01-23T21:10:01.121 +C Update\sext/wasm/SQLTester\sfor\srecent\sinternal-API\sreorgs. +D 2024-01-24T19:54:49.304 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -579,7 +579,7 @@ F ext/wasm/GNUmakefile 867c903a27fa0d53a3bf1b01d8c7bb713456f87e0939c3cac9f07faa6 F ext/wasm/README-dist.txt 6382cb9548076fca472fb3330bbdba3a55c1ea0b180ff9253f084f07ff383576 F ext/wasm/README.md a8a2962c3aebdf8d2104a9102e336c5554e78fc6072746e5daf9c61514e7d193 F ext/wasm/SQLTester/GNUmakefile e0794f676d55819951bbfae45cc5e8d7818dc460492dc317ce7f0d2eca15caff -F ext/wasm/SQLTester/SQLTester.mjs ec2f6ba63a0f2f0562941a0fb8e46b7dc55589711513f1952349785966edfe50 +F ext/wasm/SQLTester/SQLTester.mjs ce765c0ad7d57f93553d12ef4dca574deb00300134a26d472daacab49031e1fb F ext/wasm/SQLTester/SQLTester.run.mjs c72b7fe2072d05992f7a3d8c6a1d34e95712513ceabe40849784e24e41c84638 F ext/wasm/SQLTester/index.html 3f8a016df0776be76605abf20e815ecaafbe055abac0e1fe5ea080e7846b760d F ext/wasm/SQLTester/touint8array.c 2d5ece04ec1393a6a60c4bf96385bda5e1a10ad49f3038b96460fc5e5aa7e536 @@ -2161,8 +2161,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 2684feac3bc9c5463604900d72710be861527614f4957224c74a16a3b3c702f5 -R 914fcc8566f9cd381eed502f3475f2e9 -U drh -Z 4b9eeb9a5957633229a8e3aa9d4bef67 +P 5cf9ea9b1fff4625a50a2343d0fd3812da6612d6b24c07e10edb6c1ff03ca2df +R e306e6e13da3ca6b74df7f0d8d78804a +U stephan +Z be34d47cda2dc0f9c45c17c4b0edc6bd # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 19d180bb45..7541c5d7e1 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5cf9ea9b1fff4625a50a2343d0fd3812da6612d6b24c07e10edb6c1ff03ca2df \ No newline at end of file +996cfdf9b5f70408faeaa68ba2ea9494e419be8f2c59d89ab702419056e3569c \ No newline at end of file From 539085ddf5d575e3be4ace469551d4d7ff92b975 Mon Sep 17 00:00:00 2001 From: drh <> Date: Wed, 24 Jan 2024 21:08:57 +0000 Subject: [PATCH 048/430] Add NEVER() to a branch that is no longer reachable. FossilOrigin-Name: 9411337a7b3237366768fc708396da53d67a7a17b6cdc5c6f8932c5ab32217a9 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/vdbesort.c | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index b129f28e22..d546c7f2d5 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Update\sext/wasm/SQLTester\sfor\srecent\sinternal-API\sreorgs. -D 2024-01-24T19:54:49.304 +C Add\sNEVER()\sto\sa\sbranch\sthat\sis\sno\slonger\sreachable. +D 2024-01-24T21:08:57.555 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -815,7 +815,7 @@ F src/vdbeapi.c 8f57d60c89da0b60e6d4e272358c511f6bae4e24330bdb11f8b42f986d1bf21b F src/vdbeaux.c c5a471b34e9c4cfc0295a3e10734fd197670ffaebcb742f284c8e17e8026ceea F src/vdbeblob.c 13f9287b55b6356b4b1845410382d6bede203ceb29ef69388a4a3d007ffacbe5 F src/vdbemem.c 3e37dab421b74e9ce55c1e88fbc7bc6fead590b5ab258bc684f8b70abb1d6e71 -F src/vdbesort.c 237840ca1947511fa59bd4e18b9eeae93f2af2468c34d2427b059f896230a547 +F src/vdbesort.c 00c1fb15171205063556c2f1cf454e24c0b41c1effb0c876b850dce91f21bc64 F src/vdbetrace.c fe0bc29ebd4e02c8bc5c1945f1d2e6be5927ec12c06d89b03ef2a4def34bf823 F src/vdbevtab.c 2143db7db0ceed69b21422581f434baffc507a08d831565193a7a02882a1b6a7 F src/vtab.c 11948e105f56e84099ca17f1f434b1944539ea84de26d0d767eadfbc670ce1ea @@ -2161,8 +2161,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 5cf9ea9b1fff4625a50a2343d0fd3812da6612d6b24c07e10edb6c1ff03ca2df -R e306e6e13da3ca6b74df7f0d8d78804a -U stephan -Z be34d47cda2dc0f9c45c17c4b0edc6bd +P 996cfdf9b5f70408faeaa68ba2ea9494e419be8f2c59d89ab702419056e3569c +R cc29f59aa57a1c6bea20c14e055ec6a4 +U drh +Z 22d3dca63255cbf92f3e39d6096754f7 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 7541c5d7e1..48c5e7a6da 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -996cfdf9b5f70408faeaa68ba2ea9494e419be8f2c59d89ab702419056e3569c \ No newline at end of file +9411337a7b3237366768fc708396da53d67a7a17b6cdc5c6f8932c5ab32217a9 \ No newline at end of file diff --git a/src/vdbesort.c b/src/vdbesort.c index 0083690308..324c7c43e3 100644 --- a/src/vdbesort.c +++ b/src/vdbesort.c @@ -1290,7 +1290,7 @@ static void vdbeSorterExtendFile(sqlite3 *db, sqlite3_file *pFd, i64 nByte){ sqlite3OsFileControlHint(pFd, SQLITE_FCNTL_CHUNK_SIZE, &chunksize); sqlite3OsFileControlHint(pFd, SQLITE_FCNTL_SIZE_HINT, &nByte); sqlite3OsFetch(pFd, 0, (int)nByte, &p); - if( p ) sqlite3OsUnfetch(pFd, 0, p); + if( NEVER(p) ) sqlite3OsUnfetch(pFd, 0, p); } } #else From 82bf13796adf380c70badde482e1e05c5d151128 Mon Sep 17 00:00:00 2001 From: drh <> Date: Fri, 26 Jan 2024 20:34:48 +0000 Subject: [PATCH 049/430] Experimental changes that prevent parser stack overflows by growing the parser stack with heap memory when it reaches its limit. FossilOrigin-Name: 3fd062905fc20507b7cfc97fa976ac5b57c5b68926bf9136bd5ea4265d2d6528 --- doc/lemon.html | 18 ++++++++ manifest | 21 ++++++---- manifest.uuid | 2 +- src/parse.y | 4 ++ tool/lemon.c | 23 +++++++++++ tool/lempar.c | 109 ++++++++++++++++++++++++------------------------- 6 files changed, 112 insertions(+), 65 deletions(-) diff --git a/doc/lemon.html b/doc/lemon.html index 66665f46f3..4147d9b31e 100644 --- a/doc/lemon.html +++ b/doc/lemon.html @@ -683,6 +683,7 @@

4.4 Special Directives

  • %endif
  • %extra_argument
  • %fallback +
  • %free
  • %if
  • %ifdef
  • %ifndef @@ -693,6 +694,7 @@

    4.4 Special Directives

  • %parse_accept
  • %parse_failure
  • %right +
  • %realloc
  • %stack_overflow
  • %stack_size
  • %start_symbol @@ -1200,6 +1202,21 @@

    4.4.25 The %wildcard directive

    the wildcard token and some other token, the other token is always used. The wildcard token is only matched if there are no alternatives.

    + +

    4.4.26 The %realloc and %free directives

    + +

    The %realloc and %free directives defines function +that allocate and free heap memory. The signatures of these functions +should be the same as the realloc() and free() functions from the standard +C library. + +

    If both of these functions are defined +then these functions are used to allocate and free +memory for supplemental parser stack space, if the initial +parse stack space is exceeded. The initial parser stack size +is specified by either %stack_size or the +-DYYSTACKDEPTH compile-time flag. +

    5.0 Error Processing

    @@ -1224,6 +1241,7 @@

    5.0 Error Processing

    first syntax error, of course, if there are no instances of the "error" non-terminal in your grammar.

    +

    6.0 History of Lemon

    diff --git a/manifest b/manifest index d546c7f2d5..42fb3ce813 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sNEVER()\sto\sa\sbranch\sthat\sis\sno\slonger\sreachable. -D 2024-01-24T21:08:57.555 +C Experimental\schanges\sthat\sprevent\sparser\sstack\soverflows\sby\sgrowing\sthe\nparser\sstack\swith\sheap\smemory\swhen\sit\sreaches\sits\slimit. +D 2024-01-26T20:34:48.241 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -40,7 +40,7 @@ F doc/F2FS.txt c1d4a0ae9711cfe0e1d8b019d154f1c29e0d3abfe820787ba1e9ed7691160fcd F doc/compile-for-windows.md 50b27d77be96195c66031a3181cb8684ed822327ea834e07f9c014213e5e3bcf F doc/json-enhancements.md e356fc834781f1f1aa22ee300027a270b2c960122468499bf347bb123ce1ea4f F doc/jsonb.md 5fab4b8613aa9153fbeb6259297bd4697988af8b3d23900deba588fa7841456b -F doc/lemon.html 44a53a1d2b42d7751f7b2f478efb23c978e258d794bfd172442307a755b9fa44 +F doc/lemon.html 8b266ff711d2ec7f867c3dca37634963f48a630329908cc282beebfa8c708706 F doc/pager-invariants.txt 27fed9a70ddad2088750c4a2b493b63853da2710 F doc/testrunner.md 8d36ec692cf4994bb66d84a4645b9afa1ce9d47dc12cbf8d437c5a5fb6ddeedb F doc/trusted-schema.md 33625008620e879c7bcfbbfa079587612c434fa094d338b08242288d358c3e8a @@ -727,7 +727,7 @@ F src/os_win.c 6ff43bac175bd9ed79e7c0f96840b139f2f51d01689a638fd05128becf94908a F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a F src/pager.c ff60e98138d2499082ac6230f01ac508aba545315debccfca2fd6042f5f10fcd F src/pager.h 4b1140d691860de0be1347474c51fee07d5420bd7f802d38cbab8ea4ab9f538a -F src/parse.y 020d80386eb216ec9520549106353c517d2bbc89be28752ffdca649a9eaf56ec +F src/parse.y 41926c507955f2c13b10bb344883874cde82ea3ed16cb3b7867a43298d040d79 F src/pcache.c 040b165f30622a21b7a9a77c6f2e4877a32fb7f22d4c7f0d2a6fa6833a156a75 F src/pcache.h 1497ce1b823cf00094bb0cf3bac37b345937e6f910890c626b16512316d3abf5 F src/pcache1.c 602acb23c471bb8d557a6f0083cc2be641d6cafcafa19e481eba7ef4c9ca0f00 @@ -2072,8 +2072,8 @@ F tool/genfkey.test b6afd7b825d797a1e1274f519ab5695373552ecad5cd373530c63533638a F tool/getlock.c f4c39b651370156cae979501a7b156bdba50e7ce F tool/index_usage.c f62a0c701b2c7ff2f3e21d206f093c123f222dbf07136a10ffd1ca15a5c706c5 F tool/kvtest-speed.sh 4761a9c4b3530907562314d7757995787f7aef8f -F tool/lemon.c 19e368bc8e97ff4071115119a7911ca3b0c56eba7926d8ada8b4a86fcc69a176 -F tool/lempar.c 57478ea48420da05faa873c6d1616321caa5464644588c97fbe8e0ea04450748 +F tool/lemon.c 7e5c3c27062c94a40b73a980b8045a4201cb3335165b72ae476040dc513aa533 +F tool/lempar.c fa7ab4dd5bc069ffa276cbd85bea767e6472f4163106b94edd5ad01dd4babdc8 F tool/libvers.c caafc3b689638a1d88d44bc5f526c2278760d9b9 F tool/loadfts.c c3c64e4d5e90e8ba41159232c2189dba4be7b862 F tool/logest.c c34e5944318415de513d29a6098df247a9618c96d83c38d4abd88641fe46e669 @@ -2161,8 +2161,11 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 996cfdf9b5f70408faeaa68ba2ea9494e419be8f2c59d89ab702419056e3569c -R cc29f59aa57a1c6bea20c14e055ec6a4 +P 9411337a7b3237366768fc708396da53d67a7a17b6cdc5c6f8932c5ab32217a9 +R de3584eaf5d75ac532effc39455b51de +T *branch * growable-parser-stack +T *sym-growable-parser-stack * +T -sym-trunk * U drh -Z 22d3dca63255cbf92f3e39d6096754f7 +Z 64ba7e2f532c5b55e706d3959cc36418 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 48c5e7a6da..acfd13cd30 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9411337a7b3237366768fc708396da53d67a7a17b6cdc5c6f8932c5ab32217a9 \ No newline at end of file +3fd062905fc20507b7cfc97fa976ac5b57c5b68926bf9136bd5ea4265d2d6528 \ No newline at end of file diff --git a/src/parse.y b/src/parse.y index 19491192e3..0e41f54cf1 100644 --- a/src/parse.y +++ b/src/parse.y @@ -21,6 +21,10 @@ */ } +// Function used to enlarge the parser stack, if needed +%realloc sqlite3_realloc64 +%free sqlite3_free + // All token codes are small integers with #defines that begin with "TK_" %token_prefix TK_ diff --git a/tool/lemon.c b/tool/lemon.c index 7804837a06..c578b44bab 100644 --- a/tool/lemon.c +++ b/tool/lemon.c @@ -418,6 +418,8 @@ struct lemon { char *filename; /* Name of the input file */ char *outname; /* Name of the current output file */ char *tokenprefix; /* A prefix added to token names in the .h file */ + char *reallocFunc; /* Function to use to allocate stack space */ + char *freeFunc; /* Function to use to free stack space */ int nconflict; /* Number of parsing conflicts */ int nactiontab; /* Number of entries in the yy_action[] table */ int nlookaheadtab; /* Number of entries in yy_lookahead[] */ @@ -2531,6 +2533,12 @@ static void parseonetoken(struct pstate *psp) }else if( strcmp(x,"default_type")==0 ){ psp->declargslot = &(psp->gp->vartype); psp->insertLineMacro = 0; + }else if( strcmp(x,"realloc")==0 ){ + psp->declargslot = &(psp->gp->reallocFunc); + psp->insertLineMacro = 0; + }else if( strcmp(x,"free")==0 ){ + psp->declargslot = &(psp->gp->freeFunc); + psp->insertLineMacro = 0; }else if( strcmp(x,"stack_size")==0 ){ psp->declargslot = &(psp->gp->stacksize); psp->insertLineMacro = 0; @@ -4501,6 +4509,21 @@ void ReportTable( fprintf(out,"#define %sARG_FETCH\n",name); lineno++; fprintf(out,"#define %sARG_STORE\n",name); lineno++; } + if( lemp->reallocFunc ){ + fprintf(out,"#define YYREALLOC %s\n", lemp->reallocFunc); lineno++; + }else{ + fprintf(out,"#define YYREALLOC realloc\n"); lineno++; + } + if( lemp->freeFunc ){ + fprintf(out,"#define YYFREE %s\n", lemp->freeFunc); lineno++; + }else{ + fprintf(out,"#define YYFREE free\n"); lineno++; + } + if( lemp->reallocFunc && lemp->freeFunc ){ + fprintf(out,"#define YYDYNSTACK 1\n"); lineno++; + }else{ + fprintf(out,"#define YYDYNSTACK 0\n"); lineno++; + } if( lemp->ctx && lemp->ctx[0] ){ i = lemonStrlen(lemp->ctx); while( i>=1 && ISSPACE(lemp->ctx[i-1]) ) i--; diff --git a/tool/lempar.c b/tool/lempar.c index 8cc57897db..d8e64c40dd 100644 --- a/tool/lempar.c +++ b/tool/lempar.c @@ -67,6 +67,9 @@ ** ParseARG_STORE Code to store %extra_argument into yypParser ** ParseARG_FETCH Code to extract %extra_argument from yypParser ** ParseCTX_* As ParseARG_ except for %extra_context +** YYREALLOC Name of the realloc() function to use +** YYFREE Name of the free() function to use +** YYDYNSTACK True if stack space should be extended on heap ** YYERRORSYMBOL is the code number of the error symbol. If not ** defined, then do no error processing. ** YYNSTATE the combined number of states. @@ -101,6 +104,22 @@ # define yytestcase(X) #endif +/* Macro to determine if stack space has the ability to grow using +** heap memory. +*/ +#if YYSTACKDEPTH<=0 || YYDYNSTACK +# define YYGROWABLESTACK 1 +#else +# define YYGROWABLESTACK 0 +#endif + +/* Guarantee a minimum number of initial stack slots. +*/ +#if YYSTACKDEPTH<=0 +# undef YYSTACKDEPTH +# define YYSTACKDEPTH 2 /* Need a minimum stack size */ +#endif + /* Next are the tables used to determine what action to take based on the ** current state and lookahead token. These tables are used to implement @@ -212,14 +231,9 @@ struct yyParser { #endif ParseARG_SDECL /* A place to hold %extra_argument */ ParseCTX_SDECL /* A place to hold %extra_context */ -#if YYSTACKDEPTH<=0 - int yystksz; /* Current side of the stack */ - yyStackEntry *yystack; /* The parser's stack */ - yyStackEntry yystk0; /* First stack entry */ -#else - yyStackEntry yystack[YYSTACKDEPTH]; /* The parser's stack */ - yyStackEntry *yystackEnd; /* Last entry in the stack */ -#endif + yyStackEntry *yystackEnd; /* Last entry in the stack */ + yyStackEntry *yystack; /* The parser stack */ + yyStackEntry yystk0[YYSTACKDEPTH]; /* Initial stack space */ }; typedef struct yyParser yyParser; @@ -273,37 +287,45 @@ static const char *const yyRuleName[] = { #endif /* NDEBUG */ -#if YYSTACKDEPTH<=0 +#if YYGROWABLESTACK /* ** Try to increase the size of the parser stack. Return the number ** of errors. Return 0 on success. */ static int yyGrowStack(yyParser *p){ + int oldSize = 1 + (int)(p->yystackEnd - p->yystack)/sizeof(p->yystack[0]); int newSize; int idx; yyStackEntry *pNew; - newSize = p->yystksz*2 + 100; + newSize = oldSize*2 + 100; idx = p->yytos ? (int)(p->yytos - p->yystack) : 0; - if( p->yystack==&p->yystk0 ){ - pNew = malloc(newSize*sizeof(pNew[0])); - if( pNew ) pNew[0] = p->yystk0; + if( p->yystack==p->yystk0 ){ + pNew = YYREALLOC(0, newSize*sizeof(pNew[0])); + if( pNew==0 ) return 1; + memcpy(pNew, p->yystk0, sizeof(p->yystk0)); }else{ - pNew = realloc(p->yystack, newSize*sizeof(pNew[0])); + pNew = YYREALLOC(p->yystack, newSize*sizeof(pNew[0])); + if( pNew==0 ) return 1; } - if( pNew ){ - p->yystack = pNew; - p->yytos = &p->yystack[idx]; + p->yystack = pNew; + p->yytos = &p->yystack[idx]; #ifndef NDEBUG - if( yyTraceFILE ){ - fprintf(yyTraceFILE,"%sStack grows from %d to %d entries.\n", - yyTracePrompt, p->yystksz, newSize); - } -#endif - p->yystksz = newSize; + if( yyTraceFILE ){ + fprintf(yyTraceFILE,"%sStack grows from %d to %d entries.\n", + yyTracePrompt, oldSize, newSize); } - return pNew==0; +#endif + p->yystackEnd = &p->yystack[newSize-1]; + return 0; } +#endif /* YYGROWABLESTACK */ + +#if !YYGROWABLESTACK +/* For builds that do no have a growable stack, yyGrowStack always +** returns an error. +*/ +# define yyGrowStack(X) 1 #endif /* Datatype of the argument to the memory allocated passed as the @@ -323,24 +345,14 @@ void ParseInit(void *yypRawParser ParseCTX_PDECL){ #ifdef YYTRACKMAXSTACKDEPTH yypParser->yyhwm = 0; #endif -#if YYSTACKDEPTH<=0 - yypParser->yytos = NULL; - yypParser->yystack = NULL; - yypParser->yystksz = 0; - if( yyGrowStack(yypParser) ){ - yypParser->yystack = &yypParser->yystk0; - yypParser->yystksz = 1; - } -#endif + yypParser->yystack = yypParser->yystk0; + yypParser->yystackEnd = &yypParser->yystack[YYSTACKDEPTH-1]; #ifndef YYNOERRORRECOVERY yypParser->yyerrcnt = -1; #endif yypParser->yytos = yypParser->yystack; yypParser->yystack[0].stateno = 0; yypParser->yystack[0].major = 0; -#if YYSTACKDEPTH>0 - yypParser->yystackEnd = &yypParser->yystack[YYSTACKDEPTH-1]; -#endif } #ifndef Parse_ENGINEALWAYSONSTACK @@ -427,8 +439,8 @@ static void yy_pop_parser_stack(yyParser *pParser){ void ParseFinalize(void *p){ yyParser *pParser = (yyParser*)p; while( pParser->yytos>pParser->yystack ) yy_pop_parser_stack(pParser); -#if YYSTACKDEPTH<=0 - if( pParser->yystack!=&pParser->yystk0 ) free(pParser->yystack); +#if YYGROWABLESTACK + if( pParser->yystack!=pParser->yystk0 ) YYFREE(pParser->yystack); #endif } @@ -654,25 +666,19 @@ static void yy_shift( assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack) ); } #endif -#if YYSTACKDEPTH>0 - if( yypParser->yytos>yypParser->yystackEnd ){ - yypParser->yytos--; - yyStackOverflow(yypParser); - return; - } -#else - if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz] ){ + yytos = yypParser->yytos; + if( yytos>yypParser->yystackEnd ){ if( yyGrowStack(yypParser) ){ yypParser->yytos--; yyStackOverflow(yypParser); return; } + yytos = yypParser->yytos; + assert( yytos <= yypParser->yystackEnd ); } -#endif if( yyNewState > YY_MAX_SHIFT ){ yyNewState += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE; } - yytos = yypParser->yytos; yytos->stateno = yyNewState; yytos->major = yyMajor; yytos->minor.yy0 = yyMinor; @@ -911,19 +917,12 @@ void Parse( (int)(yypParser->yytos - yypParser->yystack)); } #endif -#if YYSTACKDEPTH>0 if( yypParser->yytos>=yypParser->yystackEnd ){ - yyStackOverflow(yypParser); - break; - } -#else - if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz-1] ){ if( yyGrowStack(yypParser) ){ yyStackOverflow(yypParser); break; } } -#endif } yyact = yy_reduce(yypParser,yyruleno,yymajor,yyminor ParseCTX_PARAM); }else if( yyact <= YY_MAX_SHIFTREDUCE ){ From 51f652de10fa5fdc28b990ec4ed60ff54233750b Mon Sep 17 00:00:00 2001 From: drh <> Date: Fri, 26 Jan 2024 20:57:19 +0000 Subject: [PATCH 050/430] Bug fixes in the function that expands the parser stack. FossilOrigin-Name: e91179fe849760771c3508b1e7d75325183e5c3b029752d0a97dbdbd57188b97 --- manifest | 17 +++++++---------- manifest.uuid | 2 +- test/misc5.test | 4 ++-- tool/lempar.c | 4 ++-- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/manifest b/manifest index 42fb3ce813..e783626ab4 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Experimental\schanges\sthat\sprevent\sparser\sstack\soverflows\sby\sgrowing\sthe\nparser\sstack\swith\sheap\smemory\swhen\sit\sreaches\sits\slimit. -D 2024-01-26T20:34:48.241 +C Bug\sfixes\sin\sthe\sfunction\sthat\sexpands\sthe\sparser\sstack. +D 2024-01-26T20:57:19.823 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -1413,7 +1413,7 @@ F test/misc1.test 8d138a4926ab90617c1aa29ce26e7785ae2b83a4d3a195d543b7374e05589d F test/misc2.test 71e746af479119386ac2ed7ab7d81d99970e75b49ffd3e8efffee100b4b5f350 F test/misc3.test cf3dda47d5dda3e53fc5804a100d3c82be736c9d F test/misc4.test 10cd6addb2fa9093df4751a1b92b50440175dd5468a6ec84d0386e78f087db0e -F test/misc5.test c4aeaa0fa28faa08f2485309c38db4719e6cd1364215d5687a5b96d340a3fa58 +F test/misc5.test 48de5f4220ff1a27922b14b8cf1b977f73c5a49f82b2ccd66bd86c0e53c447d4 F test/misc6.test 953cc693924d88e6117aeba16f46f0bf5abede91 F test/misc7.test d912f3d45c2989191b797504a220ca225d6be80b21acad22ba0d35f4a9ee4579 F test/misc8.test 4db9f8be59834cea08c87e9658014080efa02678ef54a088f84fa5647e81fee0 @@ -2073,7 +2073,7 @@ F tool/getlock.c f4c39b651370156cae979501a7b156bdba50e7ce F tool/index_usage.c f62a0c701b2c7ff2f3e21d206f093c123f222dbf07136a10ffd1ca15a5c706c5 F tool/kvtest-speed.sh 4761a9c4b3530907562314d7757995787f7aef8f F tool/lemon.c 7e5c3c27062c94a40b73a980b8045a4201cb3335165b72ae476040dc513aa533 -F tool/lempar.c fa7ab4dd5bc069ffa276cbd85bea767e6472f4163106b94edd5ad01dd4babdc8 +F tool/lempar.c e560057d6e0f578be64894e70e3d86beee6ae26f4aa5a6fb74fdfff8e75ccb35 F tool/libvers.c caafc3b689638a1d88d44bc5f526c2278760d9b9 F tool/loadfts.c c3c64e4d5e90e8ba41159232c2189dba4be7b862 F tool/logest.c c34e5944318415de513d29a6098df247a9618c96d83c38d4abd88641fe46e669 @@ -2161,11 +2161,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 9411337a7b3237366768fc708396da53d67a7a17b6cdc5c6f8932c5ab32217a9 -R de3584eaf5d75ac532effc39455b51de -T *branch * growable-parser-stack -T *sym-growable-parser-stack * -T -sym-trunk * +P 3fd062905fc20507b7cfc97fa976ac5b57c5b68926bf9136bd5ea4265d2d6528 +R 201c8ebb7c943c92d1f840025296ad42 U drh -Z 64ba7e2f532c5b55e706d3959cc36418 +Z 19d016796a5696ebb7583ab93b83b409 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index acfd13cd30..d41ff74d95 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -3fd062905fc20507b7cfc97fa976ac5b57c5b68926bf9136bd5ea4265d2d6528 \ No newline at end of file +e91179fe849760771c3508b1e7d75325183e5c3b029752d0a97dbdbd57188b97 \ No newline at end of file diff --git a/test/misc5.test b/test/misc5.test index f7c6048d97..0307c3bb07 100644 --- a/test/misc5.test +++ b/test/misc5.test @@ -581,9 +581,9 @@ do_test misc5-7.1 { append sql "(1+" append tail ")" } - append sql 2$tail + append sql 2$tail) catchsql $sql -} {1 {parser stack overflow}} +} {0 {}} # Parser stack overflow is silently ignored when it occurs while parsing the # schema and PRAGMA writable_schema is turned on. diff --git a/tool/lempar.c b/tool/lempar.c index d8e64c40dd..1ea66e8402 100644 --- a/tool/lempar.c +++ b/tool/lempar.c @@ -293,7 +293,7 @@ static const char *const yyRuleName[] = { ** of errors. Return 0 on success. */ static int yyGrowStack(yyParser *p){ - int oldSize = 1 + (int)(p->yystackEnd - p->yystack)/sizeof(p->yystack[0]); + int oldSize = 1 + (int)(p->yystackEnd - p->yystack); int newSize; int idx; yyStackEntry *pNew; @@ -303,7 +303,7 @@ static int yyGrowStack(yyParser *p){ if( p->yystack==p->yystk0 ){ pNew = YYREALLOC(0, newSize*sizeof(pNew[0])); if( pNew==0 ) return 1; - memcpy(pNew, p->yystk0, sizeof(p->yystk0)); + memcpy(pNew, p->yystack, oldSize*sizeof(pNew[0])); }else{ pNew = YYREALLOC(p->yystack, newSize*sizeof(pNew[0])); if( pNew==0 ) return 1; From 3467698000de73695f7eee8473a16d0981fdd5a6 Mon Sep 17 00:00:00 2001 From: drh <> Date: Sat, 27 Jan 2024 01:35:07 +0000 Subject: [PATCH 051/430] Omit the "parser stack overflow" error message, since it no longer occurs. Replace it with an ordinary "out of memory". FossilOrigin-Name: 33f17ec24880937892d47a5a321c43785ca18e03dde28a9a0d50ae86edb29679 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/parse.y | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index e783626ab4..d83d65b92d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Bug\sfixes\sin\sthe\sfunction\sthat\sexpands\sthe\sparser\sstack. -D 2024-01-26T20:57:19.823 +C Omit\sthe\s"parser\sstack\soverflow"\serror\smessage,\ssince\sit\sno\slonger\soccurs.\nReplace\sit\swith\san\sordinary\s"out\sof\smemory". +D 2024-01-27T01:35:07.422 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -727,7 +727,7 @@ F src/os_win.c 6ff43bac175bd9ed79e7c0f96840b139f2f51d01689a638fd05128becf94908a F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a F src/pager.c ff60e98138d2499082ac6230f01ac508aba545315debccfca2fd6042f5f10fcd F src/pager.h 4b1140d691860de0be1347474c51fee07d5420bd7f802d38cbab8ea4ab9f538a -F src/parse.y 41926c507955f2c13b10bb344883874cde82ea3ed16cb3b7867a43298d040d79 +F src/parse.y 7505b34ab81f17c5af10cc2c4c40e94ece3035ef151fe544e21b9a3b0e4e8531 F src/pcache.c 040b165f30622a21b7a9a77c6f2e4877a32fb7f22d4c7f0d2a6fa6833a156a75 F src/pcache.h 1497ce1b823cf00094bb0cf3bac37b345937e6f910890c626b16512316d3abf5 F src/pcache1.c 602acb23c471bb8d557a6f0083cc2be641d6cafcafa19e481eba7ef4c9ca0f00 @@ -2161,8 +2161,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 3fd062905fc20507b7cfc97fa976ac5b57c5b68926bf9136bd5ea4265d2d6528 -R 201c8ebb7c943c92d1f840025296ad42 +P e91179fe849760771c3508b1e7d75325183e5c3b029752d0a97dbdbd57188b97 +R a326e9a9ce6869e2191b567c898735a6 U drh -Z 19d016796a5696ebb7583ab93b83b409 +Z 3729898b234031ff25c57e8984e9d7de # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index d41ff74d95..7ea834c5c4 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e91179fe849760771c3508b1e7d75325183e5c3b029752d0a97dbdbd57188b97 \ No newline at end of file +33f17ec24880937892d47a5a321c43785ca18e03dde28a9a0d50ae86edb29679 \ No newline at end of file diff --git a/src/parse.y b/src/parse.y index 0e41f54cf1..2d5dc8ee38 100644 --- a/src/parse.y +++ b/src/parse.y @@ -49,7 +49,7 @@ } } %stack_overflow { - sqlite3ErrorMsg(pParse, "parser stack overflow"); + sqlite3OomFault(pParse->db); } // The name of the generated procedure that implements the parser From 7659ce22c50d526fcd4c115b79ac6ff667ee70f0 Mon Sep 17 00:00:00 2001 From: drh <> Date: Sat, 27 Jan 2024 02:21:25 +0000 Subject: [PATCH 052/430] Optimizations to ParseFinalize() to make up for the extra cleanup associated with the allocated parser stack. This branch now runs faster than trunk and is less than 300 bytes larger. FossilOrigin-Name: f7290db63cc2568090c14dffc4ea4eadfacb5b94b50a1852ef6eefd9e2e32533 --- manifest | 14 +++++++------- manifest.uuid | 2 +- tool/lemon.c | 18 +++++++++++++++++- tool/lempar.c | 21 ++++++++++++++++++++- 4 files changed, 45 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index d83d65b92d..a87dfc1f4e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Omit\sthe\s"parser\sstack\soverflow"\serror\smessage,\ssince\sit\sno\slonger\soccurs.\nReplace\sit\swith\san\sordinary\s"out\sof\smemory". -D 2024-01-27T01:35:07.422 +C Optimizations\sto\sParseFinalize()\sto\smake\sup\sfor\sthe\sextra\scleanup\sassociated\nwith\sthe\sallocated\sparser\sstack.\s\sThis\sbranch\snow\sruns\sfaster\sthan\strunk\nand\sis\sless\sthan\s300\sbytes\slarger. +D 2024-01-27T02:21:25.832 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -2072,8 +2072,8 @@ F tool/genfkey.test b6afd7b825d797a1e1274f519ab5695373552ecad5cd373530c63533638a F tool/getlock.c f4c39b651370156cae979501a7b156bdba50e7ce F tool/index_usage.c f62a0c701b2c7ff2f3e21d206f093c123f222dbf07136a10ffd1ca15a5c706c5 F tool/kvtest-speed.sh 4761a9c4b3530907562314d7757995787f7aef8f -F tool/lemon.c 7e5c3c27062c94a40b73a980b8045a4201cb3335165b72ae476040dc513aa533 -F tool/lempar.c e560057d6e0f578be64894e70e3d86beee6ae26f4aa5a6fb74fdfff8e75ccb35 +F tool/lemon.c db6c77d899f565ab42217d924e5daee5b267724433c7747fb6d3329b3c919fa1 +F tool/lempar.c c85839df516cf3cee74829df59e968646275d327763c64c9e776bac92671f0ac F tool/libvers.c caafc3b689638a1d88d44bc5f526c2278760d9b9 F tool/loadfts.c c3c64e4d5e90e8ba41159232c2189dba4be7b862 F tool/logest.c c34e5944318415de513d29a6098df247a9618c96d83c38d4abd88641fe46e669 @@ -2161,8 +2161,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P e91179fe849760771c3508b1e7d75325183e5c3b029752d0a97dbdbd57188b97 -R a326e9a9ce6869e2191b567c898735a6 +P 33f17ec24880937892d47a5a321c43785ca18e03dde28a9a0d50ae86edb29679 +R 20cc75bdc335ec49c6e2f7e4614d84da U drh -Z 3729898b234031ff25c57e8984e9d7de +Z 297b67eb6c1efaf54d4488f8dcd81ddc # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 7ea834c5c4..6f41fa279d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -33f17ec24880937892d47a5a321c43785ca18e03dde28a9a0d50ae86edb29679 \ No newline at end of file +f7290db63cc2568090c14dffc4ea4eadfacb5b94b50a1852ef6eefd9e2e32533 \ No newline at end of file diff --git a/tool/lemon.c b/tool/lemon.c index c578b44bab..5b1702f4ee 100644 --- a/tool/lemon.c +++ b/tool/lemon.c @@ -4317,7 +4317,7 @@ void ReportTable( struct action *ap; struct rule *rp; struct acttab *pActtab; - int i, j, n, sz; + int i, j, n, sz, mn, mx; int nLookAhead; int szActionType; /* sizeof(YYACTIONTYPE) */ int szCodeType; /* sizeof(YYCODETYPE) */ @@ -4647,6 +4647,22 @@ void ReportTable( fprintf(out,"#define YY_MIN_REDUCE %d\n", lemp->minReduce); lineno++; i = lemp->minReduce + lemp->nrule; fprintf(out,"#define YY_MAX_REDUCE %d\n", i-1); lineno++; + + /* Minimum and maximum token values that have a destructor */ + mn = mx = 0; + for(i=0; insymbol; i++){ + struct symbol *sp = lemp->symbols[i]; + + if( sp && sp->type!=TERMINAL && sp->destructor ){ + if( mn==0 || sp->indexindex; + if( sp->index>mx ) mx = sp->index; + } + } + if( lemp->tokendest ) mn = 0; + if( lemp->vardest ) mx = lemp->nsymbol-1; + fprintf(out,"#define YY_MIN_DSTRCTR %d\n", mn); lineno++; + fprintf(out,"#define YY_MAX_DSTRCTR %d\n", mx); lineno++; + tplt_xfer(lemp->name,in,out,&lineno); /* Now output the action table and its associates: diff --git a/tool/lempar.c b/tool/lempar.c index 1ea66e8402..9be2d409ed 100644 --- a/tool/lempar.c +++ b/tool/lempar.c @@ -83,6 +83,8 @@ ** YY_NO_ACTION The yy_action[] code for no-op ** YY_MIN_REDUCE Minimum value for reduce actions ** YY_MAX_REDUCE Maximum value for reduce actions +** YY_MIN_DSTRCTR Minimum symbol value that has a destructor +** YY_MAX_DSTRCTR Maximum symbol value that has a destructor */ #ifndef INTERFACE # define INTERFACE 1 @@ -438,7 +440,24 @@ static void yy_pop_parser_stack(yyParser *pParser){ */ void ParseFinalize(void *p){ yyParser *pParser = (yyParser*)p; - while( pParser->yytos>pParser->yystack ) yy_pop_parser_stack(pParser); + + /* In-lined version of calling yy_pop_parser_stack() for each + ** element left in the stack */ + yyStackEntry *yytos = pParser->yytos; + while( yytos>pParser->yystack ){ +#ifndef NDEBUG + if( yyTraceFILE ){ + fprintf(yyTraceFILE,"%sPopping %s\n", + yyTracePrompt, + yyTokenName[yytos->major]); + } +#endif + if( yytos->major>=YY_MIN_DSTRCTR && yytos->major<=YY_MAX_DSTRCTR ){ + yy_destructor(pParser, yytos->major, &yytos->minor); + } + yytos--; + } + #if YYGROWABLESTACK if( pParser->yystack!=pParser->yystk0 ) YYFREE(pParser->yystack); #endif From 48e899a86e9a009fb0f7f32858f65c4adeebb073 Mon Sep 17 00:00:00 2001 From: drh <> Date: Sat, 27 Jan 2024 12:25:07 +0000 Subject: [PATCH 053/430] Use an alternative memory allocator for parser stack space that includes a call to sqlite3FaultSim() to facilitate testing. FossilOrigin-Name: 7c36d560ff4e8e1b3f8fad972ec7f07837e4fa4e6861fafde970ffccfda5a2f1 --- manifest | 13 ++++++------- manifest.uuid | 2 +- src/parse.y | 10 +++++++++- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 58d782416d..85a898e370 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Allocate\snew\sparser\sstack\sspace\sfrom\sthe\sheap\sif\sneeded,\seliminating\sthe\npossibility\sof\sa\s"parser\sstack\soverflow"\serror\sas\slong\sas\sheap\smemory\sis\navailable. -D 2024-01-27T11:35:35.516 +C Use\san\salternative\smemory\sallocator\sfor\sparser\sstack\sspace\sthat\sincludes\na\scall\sto\ssqlite3FaultSim()\sto\sfacilitate\stesting. +D 2024-01-27T12:25:07.473 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -727,7 +727,7 @@ F src/os_win.c 6ff43bac175bd9ed79e7c0f96840b139f2f51d01689a638fd05128becf94908a F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a F src/pager.c ff60e98138d2499082ac6230f01ac508aba545315debccfca2fd6042f5f10fcd F src/pager.h 4b1140d691860de0be1347474c51fee07d5420bd7f802d38cbab8ea4ab9f538a -F src/parse.y 7505b34ab81f17c5af10cc2c4c40e94ece3035ef151fe544e21b9a3b0e4e8531 +F src/parse.y bfd6da46fc895cd8237400ff485d04ab0b32e47eb56de20982bb7f53e56c1f42 F src/pcache.c 040b165f30622a21b7a9a77c6f2e4877a32fb7f22d4c7f0d2a6fa6833a156a75 F src/pcache.h 1497ce1b823cf00094bb0cf3bac37b345937e6f910890c626b16512316d3abf5 F src/pcache1.c 602acb23c471bb8d557a6f0083cc2be641d6cafcafa19e481eba7ef4c9ca0f00 @@ -2161,9 +2161,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 9411337a7b3237366768fc708396da53d67a7a17b6cdc5c6f8932c5ab32217a9 f7290db63cc2568090c14dffc4ea4eadfacb5b94b50a1852ef6eefd9e2e32533 -R 20cc75bdc335ec49c6e2f7e4614d84da -T +closed f7290db63cc2568090c14dffc4ea4eadfacb5b94b50a1852ef6eefd9e2e32533 +P d87a2054774aa6ce54d9ccd78899b638f1eaf4f9a1d847bf22500018049c9f8d +R c777a6ad74adc955afb0be27604d5bbb U drh -Z c2cb0e9c7b04a3911872c4a743c7e226 +Z 010b198501e478def188acd882fee6aa # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index ae968423a2..77b98b4841 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d87a2054774aa6ce54d9ccd78899b638f1eaf4f9a1d847bf22500018049c9f8d \ No newline at end of file +7c36d560ff4e8e1b3f8fad972ec7f07837e4fa4e6861fafde970ffccfda5a2f1 \ No newline at end of file diff --git a/src/parse.y b/src/parse.y index 2d5dc8ee38..12621b4348 100644 --- a/src/parse.y +++ b/src/parse.y @@ -22,7 +22,7 @@ } // Function used to enlarge the parser stack, if needed -%realloc sqlite3_realloc64 +%realloc parserStackRealloc %free sqlite3_free // All token codes are small integers with #defines that begin with "TK_" @@ -551,6 +551,14 @@ cmd ::= select(X). { } return pSelect; } + + /* Memory allocator for parser stack resizing. This is a thin wrapper around + ** sqlite3_realloc() that includes a call to sqlite3FaultSim() to facilitate + ** testing. + */ + static void *parserStackRealloc(void *pOld, sqlite3_uint64 newSize){ + return sqlite3FaultSim(700) ? 0 : sqlite3_realloc(pOld, newSize); + } } %ifndef SQLITE_OMIT_CTE From 21bdfe5884b2c3f05c6b73f2166ee3e6c121281b Mon Sep 17 00:00:00 2001 From: drh <> Date: Sat, 27 Jan 2024 12:47:51 +0000 Subject: [PATCH 054/430] Performance enhancements to the parser template. FossilOrigin-Name: 2db8b30acdeaeaf7ec92dc0382a25f96bca4561fb68a72713ff963e27f39c63b --- manifest | 12 ++++++------ manifest.uuid | 2 +- tool/lempar.c | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 85a898e370..cd38b38091 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Use\san\salternative\smemory\sallocator\sfor\sparser\sstack\sspace\sthat\sincludes\na\scall\sto\ssqlite3FaultSim()\sto\sfacilitate\stesting. -D 2024-01-27T12:25:07.473 +C Performance\senhancements\sto\sthe\sparser\stemplate. +D 2024-01-27T12:47:51.250 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -2073,7 +2073,7 @@ F tool/getlock.c f4c39b651370156cae979501a7b156bdba50e7ce F tool/index_usage.c f62a0c701b2c7ff2f3e21d206f093c123f222dbf07136a10ffd1ca15a5c706c5 F tool/kvtest-speed.sh 4761a9c4b3530907562314d7757995787f7aef8f F tool/lemon.c db6c77d899f565ab42217d924e5daee5b267724433c7747fb6d3329b3c919fa1 -F tool/lempar.c c85839df516cf3cee74829df59e968646275d327763c64c9e776bac92671f0ac +F tool/lempar.c e6b649778e5c027c8365ff01d7ef39297cd7285fa1f881cce31792689541e79f F tool/libvers.c caafc3b689638a1d88d44bc5f526c2278760d9b9 F tool/loadfts.c c3c64e4d5e90e8ba41159232c2189dba4be7b862 F tool/logest.c c34e5944318415de513d29a6098df247a9618c96d83c38d4abd88641fe46e669 @@ -2161,8 +2161,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P d87a2054774aa6ce54d9ccd78899b638f1eaf4f9a1d847bf22500018049c9f8d -R c777a6ad74adc955afb0be27604d5bbb +P 7c36d560ff4e8e1b3f8fad972ec7f07837e4fa4e6861fafde970ffccfda5a2f1 +R 04bb01319eb99c590d86659f5806b074 U drh -Z 010b198501e478def188acd882fee6aa +Z cbc91e2ee0fe61a39c4ed5ed8e1fb955 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 77b98b4841..0dbb2b454b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7c36d560ff4e8e1b3f8fad972ec7f07837e4fa4e6861fafde970ffccfda5a2f1 \ No newline at end of file +2db8b30acdeaeaf7ec92dc0382a25f96bca4561fb68a72713ff963e27f39c63b \ No newline at end of file diff --git a/tool/lempar.c b/tool/lempar.c index 9be2d409ed..851a0e2e54 100644 --- a/tool/lempar.c +++ b/tool/lempar.c @@ -301,7 +301,7 @@ static int yyGrowStack(yyParser *p){ yyStackEntry *pNew; newSize = oldSize*2 + 100; - idx = p->yytos ? (int)(p->yytos - p->yystack) : 0; + idx = (int)(p->yytos - p->yystack); if( p->yystack==p->yystk0 ){ pNew = YYREALLOC(0, newSize*sizeof(pNew[0])); if( pNew==0 ) return 1; @@ -452,7 +452,7 @@ void ParseFinalize(void *p){ yyTokenName[yytos->major]); } #endif - if( yytos->major>=YY_MIN_DSTRCTR && yytos->major<=YY_MAX_DSTRCTR ){ + if( yytos->major>=YY_MIN_DSTRCTR ){ yy_destructor(pParser, yytos->major, &yytos->minor); } yytos--; From 052f0a95d07062749836569fbf8f686d0d153203 Mon Sep 17 00:00:00 2001 From: drh <> Date: Sat, 27 Jan 2024 20:17:05 +0000 Subject: [PATCH 055/430] Improvements to parser stack overflow testing. [forum:/forumpost/99e181b5bf|Forum post 99e181b5bf]. FossilOrigin-Name: 556c43a937f1d1c19117da24e6d892852241189f4e47e1c86aa1e8c36461c5de --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/misc5.test | 24 ++++++++++++++++++------ 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/manifest b/manifest index cd38b38091..e5e4ee4b4c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Performance\senhancements\sto\sthe\sparser\stemplate. -D 2024-01-27T12:47:51.250 +C Improvements\sto\sparser\sstack\soverflow\stesting.\n[forum:/forumpost/99e181b5bf|Forum\spost\s99e181b5bf]. +D 2024-01-27T20:17:05.552 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -1413,7 +1413,7 @@ F test/misc1.test 8d138a4926ab90617c1aa29ce26e7785ae2b83a4d3a195d543b7374e05589d F test/misc2.test 71e746af479119386ac2ed7ab7d81d99970e75b49ffd3e8efffee100b4b5f350 F test/misc3.test cf3dda47d5dda3e53fc5804a100d3c82be736c9d F test/misc4.test 10cd6addb2fa9093df4751a1b92b50440175dd5468a6ec84d0386e78f087db0e -F test/misc5.test 48de5f4220ff1a27922b14b8cf1b977f73c5a49f82b2ccd66bd86c0e53c447d4 +F test/misc5.test 027cf0ac10314ea534173f335a33bb4059907ddabbac2c16786766d6f26c8923 F test/misc6.test 953cc693924d88e6117aeba16f46f0bf5abede91 F test/misc7.test d912f3d45c2989191b797504a220ca225d6be80b21acad22ba0d35f4a9ee4579 F test/misc8.test 4db9f8be59834cea08c87e9658014080efa02678ef54a088f84fa5647e81fee0 @@ -2161,8 +2161,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 7c36d560ff4e8e1b3f8fad972ec7f07837e4fa4e6861fafde970ffccfda5a2f1 -R 04bb01319eb99c590d86659f5806b074 +P 2db8b30acdeaeaf7ec92dc0382a25f96bca4561fb68a72713ff963e27f39c63b +R 605333aa92af75374c12db2870558f0c U drh -Z cbc91e2ee0fe61a39c4ed5ed8e1fb955 +Z 624bf4ea7db4f65352370ddfed55f7bd # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 0dbb2b454b..dc3d7b8571 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2db8b30acdeaeaf7ec92dc0382a25f96bca4561fb68a72713ff963e27f39c63b \ No newline at end of file +556c43a937f1d1c19117da24e6d892852241189f4e47e1c86aa1e8c36461c5de \ No newline at end of file diff --git a/test/misc5.test b/test/misc5.test index 0307c3bb07..84aa9586d3 100644 --- a/test/misc5.test +++ b/test/misc5.test @@ -569,11 +569,11 @@ ifcapable subquery&&compound { } # Overflow the lemon parser stack by providing an overly complex -# expression. Make sure that the overflow is detected and reported. +# expression. Make sure that the overflow is detected and the +# stack is grown automatically such that the application calling +# SQLite never notices. # -# This test fails when building with -DYYSTACKDEPTH=0 -# -do_test misc5-7.1 { +do_test misc5-7.1.1 { execsql {CREATE TABLE t1(x)} set sql "INSERT INTO t1 VALUES(" set tail "" @@ -581,9 +581,21 @@ do_test misc5-7.1 { append sql "(1+" append tail ")" } - append sql 2$tail) + append sql "0$tail); SELECT * FROM t1;" catchsql $sql -} {0 {}} +} {0 200} +do_test misc5-7.1.2 { + execsql {DELETE FROM t1} + set sql "INSERT INTO t1 VALUES(" + set tail "" + for {set i 0} {$i<900} {incr i} { + append sql "(1+" + append tail ")" + } + append sql "0$tail); SELECT * FROM t1;" + catchsql $sql +} {0 900} + # Parser stack overflow is silently ignored when it occurs while parsing the # schema and PRAGMA writable_schema is turned on. From d921533954deeea925b73e3f5fe9d6e2aff194ef Mon Sep 17 00:00:00 2001 From: drh <> Date: Sun, 28 Jan 2024 00:31:47 +0000 Subject: [PATCH 056/430] Apply the same fix found in [99057383acc8f920] to descending scans. dbsqlfuzz afd1d61fc27d14938a0d78a50970fa1e9fbfee5. FossilOrigin-Name: e1d463c2d6e93e0ae0a60a05a79cd346bd07142de2fe631b370a9b946763b5d6 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/btree.c | 5 ++++- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index e5e4ee4b4c..75cb44bb83 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improvements\sto\sparser\sstack\soverflow\stesting.\n[forum:/forumpost/99e181b5bf|Forum\spost\s99e181b5bf]. -D 2024-01-27T20:17:05.552 +C Apply\sthe\ssame\sfix\sfound\sin\s[99057383acc8f920]\sto\sdescending\sscans.\ndbsqlfuzz\safd1d61fc27d14938a0d78a50970fa1e9fbfee5. +D 2024-01-28T00:31:47.406 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -677,7 +677,7 @@ F src/auth.c 19b7ccacae3dfba23fc6f1d0af68134fa216e9040e53b0681b4715445ea030b4 F src/backup.c 5c97e8023aab1ce14a42387eb3ae00ba5a0644569e3476f38661fa6f824c3523 F src/bitvec.c 9eac5f42c11914d5ef00a75605bb205e934f435c579687f985f1f8b0995c8645 F src/btmutex.c 79a43670447eacc651519a429f6ece9fd638563cf95b469d6891185ddae2b522 -F src/btree.c dee25e097b749275333b55d64a5ffc079249576f8e88a2ee476468cf67510f4b +F src/btree.c c64df2b1623501e397128261de58d3ab44c301e4eb993a4055aa971444420200 F src/btree.h 03e3356f5208bcab8eed4e094240fdac4a7f9f5ddf5e91045ce589f67d47c240 F src/btreeInt.h 3e2589726c4f105e653461814f65857465da68be1fac688de340c43b873f4062 F src/build.c 05c9eb387638982092988d2ef4c00a91b0c29baa1b85923f082ce0cf2903ea7e @@ -2161,8 +2161,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 2db8b30acdeaeaf7ec92dc0382a25f96bca4561fb68a72713ff963e27f39c63b -R 605333aa92af75374c12db2870558f0c +P 556c43a937f1d1c19117da24e6d892852241189f4e47e1c86aa1e8c36461c5de +R e3e119e442083642e5cebf8de0f05474 U drh -Z 624bf4ea7db4f65352370ddfed55f7bd +Z fd7b7cdec324b3b49688cdf78a121ede # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index dc3d7b8571..640a499850 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -556c43a937f1d1c19117da24e6d892852241189f4e47e1c86aa1e8c36461c5de \ No newline at end of file +e1d463c2d6e93e0ae0a60a05a79cd346bd07142de2fe631b370a9b946763b5d6 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 907e37f1ea..c41fb811ab 100644 --- a/src/btree.c +++ b/src/btree.c @@ -6280,7 +6280,10 @@ static SQLITE_NOINLINE int btreePrevious(BtCursor *pCur){ } pPage = pCur->pPage; - assert( pPage->isInit ); + if( sqlite3FaultSim(412) ) pPage->isInit = 0; + if( !pPage->isInit ){ + return SQLITE_CORRUPT_BKPT; + } if( !pPage->leaf ){ int idx = pCur->ix; rc = moveToChild(pCur, get4byte(findCell(pPage, idx))); From 5b480ead99fdc720f28fc0d6e32f1f0d3be22626 Mon Sep 17 00:00:00 2001 From: drh <> Date: Sun, 28 Jan 2024 17:39:31 +0000 Subject: [PATCH 057/430] Automatically disable the DISTINCT optimization during query planning if the ORDER BY clause exceeds 63 terms. dbsqlfuzz afd1d61fc27d14938a0d78a50970fa1e9fbfee58. FossilOrigin-Name: d4c193f0b49f4950b20c2f0e6aa037d2ed7d8c0b4687c14923b3a0d0d4a1b3fd --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/where.c | 5 ++++- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 75cb44bb83..28c1a5ea28 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Apply\sthe\ssame\sfix\sfound\sin\s[99057383acc8f920]\sto\sdescending\sscans.\ndbsqlfuzz\safd1d61fc27d14938a0d78a50970fa1e9fbfee5. -D 2024-01-28T00:31:47.406 +C Automatically\sdisable\sthe\sDISTINCT\soptimization\sduring\squery\splanning\sif\sthe\nORDER\sBY\sclause\sexceeds\s63\sterms.\ndbsqlfuzz\safd1d61fc27d14938a0d78a50970fa1e9fbfee58. +D 2024-01-28T17:39:31.983 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -823,7 +823,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c 887fc4ca3f020ebb2e376f222069570834ac63bf50111ef0cbf3ae417048ed89 F src/wal.h ba252daaa94f889f4b2c17c027e823d9be47ce39da1d3799886bbd51f0490452 F src/walker.c 7c7ea0115345851c3da4e04e2e239a29983b61fb5b038b94eede6aba462640e2 -F src/where.c 217fe82a26c0fb6a3c7fd01865d821e752f9c01fb72f114af3f0b77ce234d1fb +F src/where.c 56277e7110e6c81918434908bb7d597b917adfa9a176f5d95eb954b93dbc57b8 F src/whereInt.h 82a13766f13d1a53b05387c2e60726289ef26404bc7b9b1f7770204d97357fb8 F src/wherecode.c 5d77db30a2a3dd532492ae882de114edba2fae672622056b1c7fd61f5917a8f1 F src/whereexpr.c dc5096eca5ed503999be3bdee8a90c51361289a678d396a220912e9cb73b3c00 @@ -2161,8 +2161,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 556c43a937f1d1c19117da24e6d892852241189f4e47e1c86aa1e8c36461c5de -R e3e119e442083642e5cebf8de0f05474 +P e1d463c2d6e93e0ae0a60a05a79cd346bd07142de2fe631b370a9b946763b5d6 +R 1851f2761162021fbdb85251d9cef861 U drh -Z fd7b7cdec324b3b49688cdf78a121ede +Z 6fb9920f7dfa3ef526a5d4c61ad97c08 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 640a499850..db47f3ca2c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e1d463c2d6e93e0ae0a60a05a79cd346bd07142de2fe631b370a9b946763b5d6 \ No newline at end of file +d4c193f0b49f4950b20c2f0e6aa037d2ed7d8c0b4687c14923b3a0d0d4a1b3fd \ No newline at end of file diff --git a/src/where.c b/src/where.c index 4ff2815ba8..77813666e6 100644 --- a/src/where.c +++ b/src/where.c @@ -6056,7 +6056,10 @@ WhereInfo *sqlite3WhereBegin( /* An ORDER/GROUP BY clause of more than 63 terms cannot be optimized */ testcase( pOrderBy && pOrderBy->nExpr==BMS-1 ); - if( pOrderBy && pOrderBy->nExpr>=BMS ) pOrderBy = 0; + if( pOrderBy && pOrderBy->nExpr>=BMS ){ + pOrderBy = 0; + wctrlFlags &= ~WHERE_WANT_DISTINCT; + } /* The number of tables in the FROM clause is limited by the number of ** bits in a Bitmask From 4c11a5251a084d307ab11a458749408a5623fd9e Mon Sep 17 00:00:00 2001 From: drh <> Date: Sun, 28 Jan 2024 20:42:12 +0000 Subject: [PATCH 058/430] Use __ppc__ instead of __POWERPC__ to identify 32-bit PowerPC processors. [forum:/forumpost/34794846ce|Forum post 34794846ce]. FossilOrigin-Name: c974d9313b60591bcd554c3ec652a8040d382930e30778e6be8a875145b0b3da --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/sqliteInt.h | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 28c1a5ea28..83633961ec 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Automatically\sdisable\sthe\sDISTINCT\soptimization\sduring\squery\splanning\sif\sthe\nORDER\sBY\sclause\sexceeds\s63\sterms.\ndbsqlfuzz\safd1d61fc27d14938a0d78a50970fa1e9fbfee58. -D 2024-01-28T17:39:31.983 +C Use\s__ppc__\sinstead\sof\s__POWERPC__\sto\sidentify\s32-bit\sPowerPC\sprocessors.\n[forum:/forumpost/34794846ce|Forum\spost\s34794846ce]. +D 2024-01-28T20:42:12.641 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -743,7 +743,7 @@ F src/shell.c.in c6cb773b7703d76677529de19d1c40584520701966422c33da3e9334498a709 F src/sqlite.h.in 61a60b4ea04db8ead15e1579b20b64cb56e9f55d52c5f9f9694de630110593a3 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 -F src/sqliteInt.h 03e64e4a973f56035772421e94be7bf092ceceeb3dc91a74a2147030a822c392 +F src/sqliteInt.h 5013ac1f5642df4c0b76314f507f4c7b6f8efee0e1d7c2e93bf8b445ceea29bb F src/sqliteLimit.h 6878ab64bdeb8c24a1d762d45635e34b96da21132179023338c93f820eee6728 F src/status.c cb11f8589a6912af2da3bb1ec509a94dd8ef27df4d4c1a97e0bcf2309ece972b F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1 @@ -2161,8 +2161,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P e1d463c2d6e93e0ae0a60a05a79cd346bd07142de2fe631b370a9b946763b5d6 -R 1851f2761162021fbdb85251d9cef861 +P d4c193f0b49f4950b20c2f0e6aa037d2ed7d8c0b4687c14923b3a0d0d4a1b3fd +R 46f9da2da907badd19298ace66a20031 U drh -Z 6fb9920f7dfa3ef526a5d4c61ad97c08 +Z c2041b302fcfe4f462cbcda587ab473e # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index db47f3ca2c..f8126df887 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d4c193f0b49f4950b20c2f0e6aa037d2ed7d8c0b4687c14923b3a0d0d4a1b3fd \ No newline at end of file +c974d9313b60591bcd554c3ec652a8040d382930e30778e6be8a875145b0b3da \ No newline at end of file diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 06253cdd23..9d9657f3cc 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -886,7 +886,7 @@ typedef INT16_TYPE LogEst; # define SQLITE_PTRSIZE __SIZEOF_POINTER__ # elif defined(i386) || defined(__i386__) || defined(_M_IX86) || \ defined(_M_ARM) || defined(__arm__) || defined(__x86) || \ - (defined(__APPLE__) && defined(__POWERPC__)) || \ + (defined(__APPLE__) && defined(__ppc__)) || \ (defined(__TOS_AIX__) && !defined(__64BIT__)) # define SQLITE_PTRSIZE 4 # else From 3fc7a34efc5b840c069a4d55f61f14b3d68df85b Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 29 Jan 2024 12:50:32 +0000 Subject: [PATCH 059/430] When rendering JSONB back into text JSON, report an error if a zero-length integer or floating-point node is encountered. Otherwise, if the node occurs at the very end of the JSONB, the rendering logic might read one byte past the end of the initialized part of the BLOB byte array. OSSFuzz 66284. FossilOrigin-Name: b0eb279ea83c1c788c39fb90e178ec99fa4c782195c376a420c661fedf4545a7 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/json.c | 4 ++++ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index 83633961ec..e575ca5555 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Use\s__ppc__\sinstead\sof\s__POWERPC__\sto\sidentify\s32-bit\sPowerPC\sprocessors.\n[forum:/forumpost/34794846ce|Forum\spost\s34794846ce]. -D 2024-01-28T20:42:12.641 +C When\srendering\sJSONB\sback\sinto\stext\sJSON,\sreport\san\serror\sif\sa\szero-length\ninteger\sor\sfloating-point\snode\sis\sencountered.\s\sOtherwise,\sif\sthe\snode\soccurs\nat\sthe\svery\send\sof\sthe\sJSONB,\sthe\srendering\slogic\smight\sread\sone\sbyte\spast\nthe\send\sof\sthe\sinitialized\spart\sof\sthe\sBLOB\sbyte\sarray.\s\sOSSFuzz\s66284. +D 2024-01-29T12:50:32.533 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -698,7 +698,7 @@ F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 F src/insert.c 3f0a94082d978bbdd33c38fefea15346c6c6bffb70bc645a71dc0f1f87dd3276 -F src/json.c b2189995bb2f5eeac20a0282983cc82198fc77f9429708468ba360bbacb6fa80 +F src/json.c bf20b47d110aa0ea316e0ab77ccb407bd9c73eac2604e8d238823ceedd270d5b F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 F src/main.c 438b95162acfa17b7d218f586f5bde11d6ae82bcf030c9611fc537556870ad6b @@ -2161,8 +2161,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P d4c193f0b49f4950b20c2f0e6aa037d2ed7d8c0b4687c14923b3a0d0d4a1b3fd -R 46f9da2da907badd19298ace66a20031 +P c974d9313b60591bcd554c3ec652a8040d382930e30778e6be8a875145b0b3da +R 0207b7627e17db2286de3e2f665c21a5 U drh -Z c2041b302fcfe4f462cbcda587ab473e +Z b94072d2a610a36c15c6ae7e7c61c766 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index f8126df887..d6e164585f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c974d9313b60591bcd554c3ec652a8040d382930e30778e6be8a875145b0b3da \ No newline at end of file +b0eb279ea83c1c788c39fb90e178ec99fa4c782195c376a420c661fedf4545a7 \ No newline at end of file diff --git a/src/json.c b/src/json.c index c7412d3c78..d69d967934 100644 --- a/src/json.c +++ b/src/json.c @@ -2124,6 +2124,7 @@ static u32 jsonTranslateBlobToText( } case JSONB_INT: case JSONB_FLOAT: { + if( sz==0 ) goto malformed_jsonb; jsonAppendRaw(pOut, (const char*)&pParse->aBlob[i+n], sz); break; } @@ -2132,6 +2133,7 @@ static u32 jsonTranslateBlobToText( sqlite3_uint64 u = 0; const char *zIn = (const char*)&pParse->aBlob[i+n]; int bOverflow = 0; + if( sz==0 ) goto malformed_jsonb; if( zIn[0]=='-' ){ jsonAppendChar(pOut, '-'); k++; @@ -2154,6 +2156,7 @@ static u32 jsonTranslateBlobToText( case JSONB_FLOAT5: { /* Float literal missing digits beside "." */ u32 k = 0; const char *zIn = (const char*)&pParse->aBlob[i+n]; + if( sz==0 ) goto malformed_jsonb; if( zIn[0]=='-' ){ jsonAppendChar(pOut, '-'); k++; @@ -2291,6 +2294,7 @@ static u32 jsonTranslateBlobToText( } default: { + malformed_jsonb: pOut->eErr |= JSTRING_MALFORMED; break; } From 7f9a1ff3f2f909773ea7861425046fc0286508f2 Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 29 Jan 2024 15:30:35 +0000 Subject: [PATCH 060/430] Avoid a potential buffer overread when handling corrupt json blobs. FossilOrigin-Name: 738473dc0ac353731080d0785cc7dc9810b564906c176916bd91d6cfbb1a7b18 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/json.c | 4 ++-- test/jsonb01.test | 4 ++++ 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index e575ca5555..60e0deb91e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C When\srendering\sJSONB\sback\sinto\stext\sJSON,\sreport\san\serror\sif\sa\szero-length\ninteger\sor\sfloating-point\snode\sis\sencountered.\s\sOtherwise,\sif\sthe\snode\soccurs\nat\sthe\svery\send\sof\sthe\sJSONB,\sthe\srendering\slogic\smight\sread\sone\sbyte\spast\nthe\send\sof\sthe\sinitialized\spart\sof\sthe\sBLOB\sbyte\sarray.\s\sOSSFuzz\s66284. -D 2024-01-29T12:50:32.533 +C Avoid\sa\spotential\sbuffer\soverread\swhen\shandling\scorrupt\sjson\sblobs. +D 2024-01-29T15:30:35.428 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -698,7 +698,7 @@ F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 F src/insert.c 3f0a94082d978bbdd33c38fefea15346c6c6bffb70bc645a71dc0f1f87dd3276 -F src/json.c bf20b47d110aa0ea316e0ab77ccb407bd9c73eac2604e8d238823ceedd270d5b +F src/json.c 1658ff90bc260a5dbbfcbfafa0b18f34076d3dbf1ac84e31dc4a1cd0c569e7e8 F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 F src/main.c 438b95162acfa17b7d218f586f5bde11d6ae82bcf030c9611fc537556870ad6b @@ -1345,7 +1345,7 @@ F test/json106.test 1d46a9294e2ced35c7f87cebbcb9626d01abab04f1969d7ded7b6f6a1d9b F test/json107.test 59054e815c8f6b67d634d44ace421cf975828fb5651c4460aa66015c8e19d562 F test/json501.test ab168a12eb6eb14d479f8c1cdae3ac062fd5a4679f17f976e96f1af518408330 F test/json502.test 84634d3dbb521d2814e43624025b760c6198456c8197bbec6c977c0236648f5b -F test/jsonb01.test cace70765b36a36aec9a85a41ea65667d3bbf647d4400ddc3ac76f8fe7d94f90 +F test/jsonb01.test f4cdfb4cf5a0c940091b17675ed9583f45add0c938f07d65b0de0e19d3a9a101 F test/keyword1.test 37ef6bba5d2ed5b07ecdd6810571de2956599dff F test/kvtest.c 6e0228409ea7ca0497dad503fbd109badb5e59545d131014b6aaac68b56f484a F test/lastinsert.test 42e948fd6442f07d60acbd15d33fb86473e0ef63 @@ -2161,8 +2161,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P c974d9313b60591bcd554c3ec652a8040d382930e30778e6be8a875145b0b3da -R 0207b7627e17db2286de3e2f665c21a5 -U drh -Z b94072d2a610a36c15c6ae7e7c61c766 +P b0eb279ea83c1c788c39fb90e178ec99fa4c782195c376a420c661fedf4545a7 +R 3e003ebc54133c42f113fbce024a5a22 +U dan +Z b1da7a8f3b87229f95a14c44f483cdeb # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index d6e164585f..60d0910ce9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b0eb279ea83c1c788c39fb90e178ec99fa4c782195c376a420c661fedf4545a7 \ No newline at end of file +738473dc0ac353731080d0785cc7dc9810b564906c176916bd91d6cfbb1a7b18 \ No newline at end of file diff --git a/src/json.c b/src/json.c index d69d967934..94f5a3ef93 100644 --- a/src/json.c +++ b/src/json.c @@ -2073,8 +2073,8 @@ static u32 jsonbPayloadSize(const JsonParse *pParse, u32 i, u32 *pSz){ (pParse->aBlob[i+7]<<8) + pParse->aBlob[i+8]; n = 9; } - if( i+sz+n > pParse->nBlob - && i+sz+n > pParse->nBlob-pParse->delta + if( (i64)i+sz+n > pParse->nBlob + && (i64)i+sz+n > pParse->nBlob-pParse->delta ){ sz = 0; n = 0; diff --git a/test/jsonb01.test b/test/jsonb01.test index d1b53ae6cc..8f16428dcc 100644 --- a/test/jsonb01.test +++ b/test/jsonb01.test @@ -46,4 +46,8 @@ foreach {id path res} { } $res } +do_catchsql_test jsonb01-2.0 { + SELECT x'8ce6ffffffff171333' -> '$'; +} {1 {malformed JSON}} + finish_test From 581bf002ce9c979bce7b994de6e29746509c89be Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 29 Jan 2024 19:30:16 +0000 Subject: [PATCH 061/430] Consider an index for queries like "SELECT count(DISTINCT col) FROM ...", even if the index records are not smaller than the table records. FossilOrigin-Name: ad06868807a27f0c96fa5649ebd981e07909eb2c5e03781377c876fdec49abdc --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/where.c | 4 +++- test/distinctagg.test | 9 ++++++++- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 60e0deb91e..bd32d81585 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Avoid\sa\spotential\sbuffer\soverread\swhen\shandling\scorrupt\sjson\sblobs. -D 2024-01-29T15:30:35.428 +C Consider\san\sindex\sfor\squeries\slike\s"SELECT\scount(DISTINCT\scol)\sFROM\s...",\seven\sif\sthe\sindex\srecords\sare\snot\ssmaller\sthan\sthe\stable\srecords. +D 2024-01-29T19:30:16.573 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -823,7 +823,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c 887fc4ca3f020ebb2e376f222069570834ac63bf50111ef0cbf3ae417048ed89 F src/wal.h ba252daaa94f889f4b2c17c027e823d9be47ce39da1d3799886bbd51f0490452 F src/walker.c 7c7ea0115345851c3da4e04e2e239a29983b61fb5b038b94eede6aba462640e2 -F src/where.c 56277e7110e6c81918434908bb7d597b917adfa9a176f5d95eb954b93dbc57b8 +F src/where.c e38e37677884d644b825fe0ab72379a24a9a74f89d8add5eb134d61fea2358a3 F src/whereInt.h 82a13766f13d1a53b05387c2e60726289ef26404bc7b9b1f7770204d97357fb8 F src/wherecode.c 5d77db30a2a3dd532492ae882de114edba2fae672622056b1c7fd61f5917a8f1 F src/whereexpr.c dc5096eca5ed503999be3bdee8a90c51361289a678d396a220912e9cb73b3c00 @@ -1056,7 +1056,7 @@ F test/descidx3.test 953c831df7ea219c73826dfbf2f6ee02d95040725aa88ccb4fa43d1a199 F test/diskfull.test 106391384780753ea6896b7b4f005d10e9866b6e F test/distinct.test 691c9e850b0d0b56b66e7e235453198cb4cf0760e324b7403d3c5abbeab0a014 F test/distinct2.test bb71cc7b5e58e895787f9910a788c254f679928d324732d063fe9bc202ecbe71 -F test/distinctagg.test ad2b4cf1483cd4cf24867dfafbfa0abb61184d92085fcc9784cea0592b278d64 +F test/distinctagg.test 40d7169ae5846caaf62c6e307d2ca3c333daf9b6f7cde888956a339a97afe85f F test/e_blobbytes.test 4c01dfe4f12087b92b20705a3fdfded45dc4ed16d5a211fed4e1d2786ba68a52 F test/e_blobclose.test 692fc02a058476c2222a63d97e3f3b2b809c1842e5525ded7f854d540ac2e075 F test/e_blobopen.test 29f6055ee453b8e679fe9570c4d3acfedbef821622c5dad16875148c5952ef50 @@ -2161,8 +2161,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P b0eb279ea83c1c788c39fb90e178ec99fa4c782195c376a420c661fedf4545a7 -R 3e003ebc54133c42f113fbce024a5a22 +P 738473dc0ac353731080d0785cc7dc9810b564906c176916bd91d6cfbb1a7b18 +R f1c37c0e5edda3118ed05f6a7a2d3df0 U dan -Z b1da7a8f3b87229f95a14c44f483cdeb +Z 6c6c135247ccb8a93d3af9a3896ff5b2 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 60d0910ce9..1ec528d5a1 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -738473dc0ac353731080d0785cc7dc9810b564906c176916bd91d6cfbb1a7b18 \ No newline at end of file +ad06868807a27f0c96fa5649ebd981e07909eb2c5e03781377c876fdec49abdc \ No newline at end of file diff --git a/src/where.c b/src/where.c index 77813666e6..b0fe12e52b 100644 --- a/src/where.c +++ b/src/where.c @@ -3362,7 +3362,9 @@ static int indexMightHelpWithOrderBy( for(ii=0; iinExpr; ii++){ Expr *pExpr = sqlite3ExprSkipCollateAndLikely(pOB->a[ii].pExpr); if( NEVER(pExpr==0) ) continue; - if( pExpr->op==TK_COLUMN && pExpr->iTable==iCursor ){ + if( (pExpr->op==TK_COLUMN || pExpr->op==TK_AGG_COLUMN) + && pExpr->iTable==iCursor + ){ if( pExpr->iColumn<0 ) return 1; for(jj=0; jjnKeyCol; jj++){ if( pExpr->iColumn==pIndex->aiColumn[jj] ) return 1; diff --git a/test/distinctagg.test b/test/distinctagg.test index 199ca0666e..9eedd35bd2 100644 --- a/test/distinctagg.test +++ b/test/distinctagg.test @@ -95,7 +95,7 @@ foreach {tn use_eph sql res} { 7 0 "SELECT count(DISTINCT a) FROM t2, t1" 5 8 1 "SELECT count(DISTINCT a+b) FROM t1, t2, t2, t2" 6 9 0 "SELECT count(DISTINCT c) FROM t1 WHERE c=2" 1 - 10 1 "SELECT count(DISTINCT t1.rowid) FROM t1, t2" 10 + 10 0 "SELECT count(DISTINCT t1.rowid) FROM t1, t2" 10 } { do_test 3.$tn.1 { set prg [db eval "EXPLAIN $sql"] @@ -148,6 +148,10 @@ do_execsql_test 3.0 { CREATE TABLE t3(x, y, z); INSERT INTO t3 VALUES(1,1,1); INSERT INTO t3 VALUES(2,2,2); + + CREATE TABLE t4(a); + CREATE INDEX t4a ON t4(a); + INSERT INTO t4 VALUES(1), (2), (2), (3), (1); } foreach {tn use_eph sql res} { @@ -158,6 +162,9 @@ foreach {tn use_eph sql res} { 4 0 "SELECT count(DISTINCT f) FROM t2 GROUP BY d, e" {1 2 2 3} 5 1 "SELECT count(DISTINCT f) FROM t2 GROUP BY d" {2 3} 6 0 "SELECT count(DISTINCT f) FROM t2 WHERE d IS 1 GROUP BY e" {1 2 2} + + 7 0 "SELECT count(DISTINCT a) FROM t1" {4} + 8 0 "SELECT count(DISTINCT a) FROM t4" {3} } { do_test 4.$tn.1 { set prg [db eval "EXPLAIN $sql"] From af3824d5fa56c7ab892dda7f929940a6eaa66b35 Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 29 Jan 2024 20:36:17 +0000 Subject: [PATCH 062/430] When generated text JSON from JSONB, do not continue descending into nested structures after an error is seen. This avoids long loops and wait times. FossilOrigin-Name: 97666ec052ebaceab002874d7ca5c5e6883c3d04fb7d3992235a8c4c8d08407a --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/json.c | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index bd32d81585..5fcb117e2b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Consider\san\sindex\sfor\squeries\slike\s"SELECT\scount(DISTINCT\scol)\sFROM\s...",\seven\sif\sthe\sindex\srecords\sare\snot\ssmaller\sthan\sthe\stable\srecords. -D 2024-01-29T19:30:16.573 +C When\sgenerated\stext\sJSON\sfrom\sJSONB,\sdo\snot\scontinue\sdescending\sinto\nnested\sstructures\safter\san\serror\sis\sseen.\s\sThis\savoids\slong\sloops\sand\swait\ntimes. +D 2024-01-29T20:36:17.909 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -698,7 +698,7 @@ F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 F src/insert.c 3f0a94082d978bbdd33c38fefea15346c6c6bffb70bc645a71dc0f1f87dd3276 -F src/json.c 1658ff90bc260a5dbbfcbfafa0b18f34076d3dbf1ac84e31dc4a1cd0c569e7e8 +F src/json.c 25472b53ce9a07f2fd1388714596ab0a1cf626c9af8829fe1d9f6e2040a8d6f5 F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 F src/main.c 438b95162acfa17b7d218f586f5bde11d6ae82bcf030c9611fc537556870ad6b @@ -2161,8 +2161,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 738473dc0ac353731080d0785cc7dc9810b564906c176916bd91d6cfbb1a7b18 -R f1c37c0e5edda3118ed05f6a7a2d3df0 -U dan -Z 6c6c135247ccb8a93d3af9a3896ff5b2 +P ad06868807a27f0c96fa5649ebd981e07909eb2c5e03781377c876fdec49abdc +R 62cbadfc42bb4fb45ef8f78c92a43c6e +U drh +Z 909c63b99a1f269d1aa20de0ece0fbe3 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 1ec528d5a1..4794e80ce4 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ad06868807a27f0c96fa5649ebd981e07909eb2c5e03781377c876fdec49abdc \ No newline at end of file +97666ec052ebaceab002874d7ca5c5e6883c3d04fb7d3992235a8c4c8d08407a \ No newline at end of file diff --git a/src/json.c b/src/json.c index 94f5a3ef93..2f0243651c 100644 --- a/src/json.c +++ b/src/json.c @@ -2270,7 +2270,7 @@ static u32 jsonTranslateBlobToText( jsonAppendChar(pOut, '['); j = i+n; iEnd = j+sz; - while( jeErr==0 ){ j = jsonTranslateBlobToText(pParse, j, pOut); jsonAppendChar(pOut, ','); } @@ -2283,7 +2283,7 @@ static u32 jsonTranslateBlobToText( jsonAppendChar(pOut, '{'); j = i+n; iEnd = j+sz; - while( jeErr==0 ){ j = jsonTranslateBlobToText(pParse, j, pOut); jsonAppendChar(pOut, (x++ & 1) ? ',' : ':'); } From 91981fe74e223f3fec2b354535e9fac437868765 Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 29 Jan 2024 21:09:56 +0000 Subject: [PATCH 063/430] Detect malformed nested JSONB earlier and stop rendering to avoid long delays. FossilOrigin-Name: 72f3e1d0eca2b9ebd7c4b4cdccc6d7a0173b2fdb204cb1aa207917aedab6098a --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/json.c | 3 ++- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 5fcb117e2b..4733a4c7ee 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C When\sgenerated\stext\sJSON\sfrom\sJSONB,\sdo\snot\scontinue\sdescending\sinto\nnested\sstructures\safter\san\serror\sis\sseen.\s\sThis\savoids\slong\sloops\sand\swait\ntimes. -D 2024-01-29T20:36:17.909 +C Detect\smalformed\snested\sJSONB\searlier\sand\sstop\srendering\sto\savoid\slong\ndelays. +D 2024-01-29T21:09:56.917 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -698,7 +698,7 @@ F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 F src/insert.c 3f0a94082d978bbdd33c38fefea15346c6c6bffb70bc645a71dc0f1f87dd3276 -F src/json.c 25472b53ce9a07f2fd1388714596ab0a1cf626c9af8829fe1d9f6e2040a8d6f5 +F src/json.c 4f824b70a65c426f4ff518f99adb9b4fb97d6c8692e59c4525cae453972853f5 F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 F src/main.c 438b95162acfa17b7d218f586f5bde11d6ae82bcf030c9611fc537556870ad6b @@ -2161,8 +2161,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P ad06868807a27f0c96fa5649ebd981e07909eb2c5e03781377c876fdec49abdc -R 62cbadfc42bb4fb45ef8f78c92a43c6e +P 97666ec052ebaceab002874d7ca5c5e6883c3d04fb7d3992235a8c4c8d08407a +R 95e4cc745d61f1468c48968bf1c52952 U drh -Z 909c63b99a1f269d1aa20de0ece0fbe3 +Z e9314520b095df0616cee88d0104a95d # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 4794e80ce4..093286cae5 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -97666ec052ebaceab002874d7ca5c5e6883c3d04fb7d3992235a8c4c8d08407a \ No newline at end of file +72f3e1d0eca2b9ebd7c4b4cdccc6d7a0173b2fdb204cb1aa207917aedab6098a \ No newline at end of file diff --git a/src/json.c b/src/json.c index 2f0243651c..b683e65a9d 100644 --- a/src/json.c +++ b/src/json.c @@ -2274,6 +2274,7 @@ static u32 jsonTranslateBlobToText( j = jsonTranslateBlobToText(pParse, j, pOut); jsonAppendChar(pOut, ','); } + if( j>iEnd ) pOut->eErr |= JSTRING_MALFORMED; if( sz>0 ) jsonStringTrimOneChar(pOut); jsonAppendChar(pOut, ']'); break; @@ -2287,7 +2288,7 @@ static u32 jsonTranslateBlobToText( j = jsonTranslateBlobToText(pParse, j, pOut); jsonAppendChar(pOut, (x++ & 1) ? ',' : ':'); } - if( x & 1 ) pOut->eErr |= JSTRING_MALFORMED; + if( (x & 1)!=0 || j>iEnd ) pOut->eErr |= JSTRING_MALFORMED; if( sz>0 ) jsonStringTrimOneChar(pOut); jsonAppendChar(pOut, '}'); break; From b202a452ad2fd66430dd7d1375ed611cf753f982 Mon Sep 17 00:00:00 2001 From: drh <> Date: Wed, 31 Jan 2024 12:15:57 +0000 Subject: [PATCH 064/430] Fix a memory allocation bug in the (debug-use-only) json_parse() SQL function. FossilOrigin-Name: 32ce7dacf58bbf35cf70da8b03fa25f97fcea970edbc1f8aa12739ac4c8608fb --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/json.c | 3 ++- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 4733a4c7ee..2604713c72 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Detect\smalformed\snested\sJSONB\searlier\sand\sstop\srendering\sto\savoid\slong\ndelays. -D 2024-01-29T21:09:56.917 +C Fix\sa\smemory\sallocation\sbug\sin\sthe\s(debug-use-only)\sjson_parse()\sSQL\sfunction. +D 2024-01-31T12:15:57.302 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -698,7 +698,7 @@ F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 F src/insert.c 3f0a94082d978bbdd33c38fefea15346c6c6bffb70bc645a71dc0f1f87dd3276 -F src/json.c 4f824b70a65c426f4ff518f99adb9b4fb97d6c8692e59c4525cae453972853f5 +F src/json.c 192c5e5013607b14441a738f0bd73e9df057b13eeac4060b679b32021a25e018 F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 F src/main.c 438b95162acfa17b7d218f586f5bde11d6ae82bcf030c9611fc537556870ad6b @@ -2161,8 +2161,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 97666ec052ebaceab002874d7ca5c5e6883c3d04fb7d3992235a8c4c8d08407a -R 95e4cc745d61f1468c48968bf1c52952 +P 72f3e1d0eca2b9ebd7c4b4cdccc6d7a0173b2fdb204cb1aa207917aedab6098a +R 1df2c3fb322d8908152fe23b99fe1f47 U drh -Z e9314520b095df0616cee88d0104a95d +Z d967a8cc96a8b8a2072c7fb0795b6f21 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 093286cae5..048895706f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -72f3e1d0eca2b9ebd7c4b4cdccc6d7a0173b2fdb204cb1aa207917aedab6098a \ No newline at end of file +32ce7dacf58bbf35cf70da8b03fa25f97fcea970edbc1f8aa12739ac4c8608fb \ No newline at end of file diff --git a/src/json.c b/src/json.c index b683e65a9d..8f8196bd75 100644 --- a/src/json.c +++ b/src/json.c @@ -3552,11 +3552,12 @@ static void jsonParseFunc( if( p==0 ) return; if( argc==1 ){ jsonDebugPrintBlob(p, 0, p->nBlob, 0, &out); - sqlite3_result_text64(ctx, out.zText, out.nChar, SQLITE_DYNAMIC, SQLITE_UTF8); + sqlite3_result_text64(ctx,out.zText,out.nChar,SQLITE_TRANSIENT,SQLITE_UTF8); }else{ jsonShowParse(p); } jsonParseFree(p); + sqlite3_str_reset(&out); } #endif /* SQLITE_DEBUG */ From c24f53635c3b17f732119a224255c61edc90a089 Mon Sep 17 00:00:00 2001 From: drh <> Date: Wed, 31 Jan 2024 13:46:44 +0000 Subject: [PATCH 065/430] Allow control characters in JSON5 string literals. [forum:/forumpost/05182119f69c3a92|Forum thread 05182119f69c3a92]. FossilOrigin-Name: 34709c7cc910539e23a830ad8b589a97a88be25e924a59670c1017fb51447dad --- manifest | 14 ++++----- manifest.uuid | 2 +- src/json.c | 78 +++++++++++++++++++++++++++++++---------------- test/json501.test | 27 ++++++++++++++++ 4 files changed, 86 insertions(+), 35 deletions(-) diff --git a/manifest b/manifest index 2604713c72..e88859a0db 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\smemory\sallocation\sbug\sin\sthe\s(debug-use-only)\sjson_parse()\sSQL\sfunction. -D 2024-01-31T12:15:57.302 +C Allow\scontrol\scharacters\sin\sJSON5\sstring\sliterals.\n[forum:/forumpost/05182119f69c3a92|Forum\sthread\s05182119f69c3a92]. +D 2024-01-31T13:46:44.886 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -698,7 +698,7 @@ F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 F src/insert.c 3f0a94082d978bbdd33c38fefea15346c6c6bffb70bc645a71dc0f1f87dd3276 -F src/json.c 192c5e5013607b14441a738f0bd73e9df057b13eeac4060b679b32021a25e018 +F src/json.c 366c4502167672d9ded0d45b1a955acb487ddabb531e889a7b8901fd3e46d013 F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 F src/main.c 438b95162acfa17b7d218f586f5bde11d6ae82bcf030c9611fc537556870ad6b @@ -1343,7 +1343,7 @@ F test/json104.test 1b844a70cddcfa2e4cd81a5db0657b2e61e7f00868310f24f56a9ba01143 F test/json105.test 043838b56e68f3252a0dcf5be1689016f6f3f05056f8dcfcdc9d074f4d932988 F test/json106.test 1d46a9294e2ced35c7f87cebbcb9626d01abab04f1969d7ded7b6f6a1d9be0f2 F test/json107.test 59054e815c8f6b67d634d44ace421cf975828fb5651c4460aa66015c8e19d562 -F test/json501.test ab168a12eb6eb14d479f8c1cdae3ac062fd5a4679f17f976e96f1af518408330 +F test/json501.test b95e2d14988b682a5cadf079dd6162f0f85fb74cd59c6b1f1624110104a974eb F test/json502.test 84634d3dbb521d2814e43624025b760c6198456c8197bbec6c977c0236648f5b F test/jsonb01.test f4cdfb4cf5a0c940091b17675ed9583f45add0c938f07d65b0de0e19d3a9a101 F test/keyword1.test 37ef6bba5d2ed5b07ecdd6810571de2956599dff @@ -2161,8 +2161,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 72f3e1d0eca2b9ebd7c4b4cdccc6d7a0173b2fdb204cb1aa207917aedab6098a -R 1df2c3fb322d8908152fe23b99fe1f47 +P 32ce7dacf58bbf35cf70da8b03fa25f97fcea970edbc1f8aa12739ac4c8608fb +R c7867d5f34f471f1c203d9ecfab6ff98 U drh -Z d967a8cc96a8b8a2072c7fb0795b6f21 +Z a250ac8f403a1bdc996f04e6b4453df0 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 048895706f..aea1dec179 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -32ce7dacf58bbf35cf70da8b03fa25f97fcea970edbc1f8aa12739ac4c8608fb \ No newline at end of file +34709c7cc910539e23a830ad8b589a97a88be25e924a59670c1017fb51447dad \ No newline at end of file diff --git a/src/json.c b/src/json.c index 8f8196bd75..d585189902 100644 --- a/src/json.c +++ b/src/json.c @@ -621,6 +621,40 @@ static void jsonAppendSeparator(JsonString *p){ jsonAppendChar(p, ','); } +/* c is a control character. Append the canonical JSON representation +** of that control character to p. +** +** This routine assumes that the output buffer has already been enlarged +** sufficiently to hold the worst-case encoding plus a nul terminator. +*/ +static void jsonAppendControlChar(JsonString *p, u8 c){ + static const char aSpecial[] = { + 0, 0, 0, 0, 0, 0, 0, 0, 'b', 't', 'n', 0, 'f', 'r', 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + }; + assert( sizeof(aSpecial)==32 ); + assert( aSpecial['\b']=='b' ); + assert( aSpecial['\f']=='f' ); + assert( aSpecial['\n']=='n' ); + assert( aSpecial['\r']=='r' ); + assert( aSpecial['\t']=='t' ); + assert( c>=0 && cnUsed+7 <= p->nAlloc ); + if( aSpecial[c] ){ + p->zBuf[p->nUsed] = '\\'; + p->zBuf[p->nUsed+1] = aSpecial[c]; + p->nUsed += 2; + }else{ + p->zBuf[p->nUsed] = '\\'; + p->zBuf[p->nUsed+1] = 'u'; + p->zBuf[p->nUsed+2] = '0'; + p->zBuf[p->nUsed+3] = '0'; + p->zBuf[p->nUsed+4] = "0123456789abcdef"[c>>4]; + p->zBuf[p->nUsed+5] = "0123456789abcdef"[c&0xf]; + p->nUsed += 6; + } +} + /* Append the N-byte string in zIn to the end of the JsonString string ** under construction. Enclose the string in double-quotes ("...") and ** escape any double-quotes or backslash characters contained within the @@ -680,35 +714,14 @@ static void jsonAppendString(JsonString *p, const char *zIn, u32 N){ } c = z[0]; if( c=='"' || c=='\\' ){ - json_simple_escape: if( (p->nUsed+N+3 > p->nAlloc) && jsonStringGrow(p,N+3)!=0 ) return; p->zBuf[p->nUsed++] = '\\'; p->zBuf[p->nUsed++] = c; }else if( c=='\'' ){ p->zBuf[p->nUsed++] = c; }else{ - static const char aSpecial[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 'b', 't', 'n', 0, 'f', 'r', 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 - }; - assert( sizeof(aSpecial)==32 ); - assert( aSpecial['\b']=='b' ); - assert( aSpecial['\f']=='f' ); - assert( aSpecial['\n']=='n' ); - assert( aSpecial['\r']=='r' ); - assert( aSpecial['\t']=='t' ); - assert( c>=0 && cnUsed+N+7 > p->nAlloc) && jsonStringGrow(p,N+7)!=0 ) return; - p->zBuf[p->nUsed++] = '\\'; - p->zBuf[p->nUsed++] = 'u'; - p->zBuf[p->nUsed++] = '0'; - p->zBuf[p->nUsed++] = '0'; - p->zBuf[p->nUsed++] = "0123456789abcdef"[c>>4]; - p->zBuf[p->nUsed++] = "0123456789abcdef"[c&0xf]; + jsonAppendControlChar(p, c); } z++; N--; @@ -1409,6 +1422,9 @@ static u32 jsonbValidityCheck( if( !jsonIsOk[z[j]] && z[j]!='\'' ){ if( z[j]=='"' ){ if( x==JSONB_TEXTJ ) return j+1; + }else if( z[j]<=0x1f ){ + /* Control characters in JSON5 string literals are ok */ + if( x==JSONB_TEXTJ ) return j+1; }else if( z[j]!='\\' || j+1>=k ){ return j+1; }else if( strchr("\"\\/bfnrt",z[j+1])!=0 ){ @@ -1703,9 +1719,10 @@ static int jsonTranslateTextToBlob(JsonParse *pParse, u32 i){ return -1; } }else if( c<=0x1f ){ - /* Control characters are not allowed in strings */ - pParse->iErr = j; - return -1; + /* Control characters are not allowed in canonical JSON string + ** literals, but are allowed in JSON5 string literals. */ + opcode = JSONB_TEXT5; + pParse->hasNonstd = 1; }else if( c=='"' ){ opcode = JSONB_TEXT5; } @@ -2186,7 +2203,7 @@ static u32 jsonTranslateBlobToText( zIn = (const char*)&pParse->aBlob[i+n]; jsonAppendChar(pOut, '"'); while( sz2>0 ){ - for(k=0; k0 ){ jsonAppendRawNZ(pOut, zIn, k); if( k>=sz2 ){ @@ -2201,6 +2218,13 @@ static u32 jsonTranslateBlobToText( sz2--; continue; } + if( zIn[0]<=0x1f ){ + if( pOut->nUsed+7nAlloc && jsonStringGrow(pOut,7) ) break; + jsonAppendControlChar(pOut, zIn[0]); + zIn++; + sz2--; + continue; + } assert( zIn[0]=='\\' ); assert( sz2>=1 ); if( sz2<2 ){ @@ -4391,7 +4415,7 @@ static void jsonErrorFunc( /* Convert byte-offset s.iErr into a character offset */ u32 k; assert( s.zJson!=0 ); /* Because s.oom is false */ - for(k=0; k '$'; + } "{{\"label\":\"abc${e}xyz\"}}" +} + + finish_test From 9486178f39fe31e24ead8a196cf158829f78daf3 Mon Sep 17 00:00:00 2001 From: drh <> Date: Wed, 31 Jan 2024 14:44:59 +0000 Subject: [PATCH 066/430] Fix failure to detect unterminated string literals in json_valid() in the previous check-in. FossilOrigin-Name: 5d725644621cf640fb743d59ccf89dac777540410e67501eb00b83638c8c857f --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/json.c | 4 ++++ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index e88859a0db..33bf52c0d0 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Allow\scontrol\scharacters\sin\sJSON5\sstring\sliterals.\n[forum:/forumpost/05182119f69c3a92|Forum\sthread\s05182119f69c3a92]. -D 2024-01-31T13:46:44.886 +C Fix\sfailure\sto\sdetect\sunterminated\sstring\sliterals\sin\sjson_valid()\sin\sthe\nprevious\scheck-in. +D 2024-01-31T14:44:59.052 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -698,7 +698,7 @@ F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 F src/insert.c 3f0a94082d978bbdd33c38fefea15346c6c6bffb70bc645a71dc0f1f87dd3276 -F src/json.c 366c4502167672d9ded0d45b1a955acb487ddabb531e889a7b8901fd3e46d013 +F src/json.c 24f2517b5dc7e678ee3006eaa0c0e6b13ff90e71849f8c4064134eb28a97f618 F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 F src/main.c 438b95162acfa17b7d218f586f5bde11d6ae82bcf030c9611fc537556870ad6b @@ -2161,8 +2161,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 32ce7dacf58bbf35cf70da8b03fa25f97fcea970edbc1f8aa12739ac4c8608fb -R c7867d5f34f471f1c203d9ecfab6ff98 +P 34709c7cc910539e23a830ad8b589a97a88be25e924a59670c1017fb51447dad +R b63eb752943f01d1de6f4800dabd8585 U drh -Z a250ac8f403a1bdc996f04e6b4453df0 +Z f52460ed1f18979ad0fa2f0cc99e3abc # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index aea1dec179..8b6f282a08 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -34709c7cc910539e23a830ad8b589a97a88be25e924a59670c1017fb51447dad \ No newline at end of file +5d725644621cf640fb743d59ccf89dac777540410e67501eb00b83638c8c857f \ No newline at end of file diff --git a/src/json.c b/src/json.c index d585189902..2d6195b797 100644 --- a/src/json.c +++ b/src/json.c @@ -1719,6 +1719,10 @@ static int jsonTranslateTextToBlob(JsonParse *pParse, u32 i){ return -1; } }else if( c<=0x1f ){ + if( c==0 ){ + pParse->iErr = j; + return -1; + } /* Control characters are not allowed in canonical JSON string ** literals, but are allowed in JSON5 string literals. */ opcode = JSONB_TEXT5; From 744581d3d63e653023de977d6375ededaa090014 Mon Sep 17 00:00:00 2001 From: drh <> Date: Wed, 31 Jan 2024 15:20:13 +0000 Subject: [PATCH 067/430] Add NEVER() and ALWAYS() macros for the JSON5-control-character change. Also fix an incorrect comparison used to determine if a buffer needed to be resized. FossilOrigin-Name: e3c0c0e686f3b7710f79587cf465b5aac52d8f2f2986a3de885a656f652cbfd3 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/json.c | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 33bf52c0d0..685e93704d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sfailure\sto\sdetect\sunterminated\sstring\sliterals\sin\sjson_valid()\sin\sthe\nprevious\scheck-in. -D 2024-01-31T14:44:59.052 +C Add\sNEVER()\sand\sALWAYS()\smacros\sfor\sthe\sJSON5-control-character\schange.\nAlso\sfix\san\sincorrect\scomparison\sused\sto\sdetermine\sif\sa\sbuffer\sneeded\sto\nbe\sresized. +D 2024-01-31T15:20:13.599 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -698,7 +698,7 @@ F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 F src/insert.c 3f0a94082d978bbdd33c38fefea15346c6c6bffb70bc645a71dc0f1f87dd3276 -F src/json.c 24f2517b5dc7e678ee3006eaa0c0e6b13ff90e71849f8c4064134eb28a97f618 +F src/json.c e4e5f70b602c1dc9592b798166697bedeb84c61ffe857c9302ded54d5024603d F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 F src/main.c 438b95162acfa17b7d218f586f5bde11d6ae82bcf030c9611fc537556870ad6b @@ -2161,8 +2161,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 34709c7cc910539e23a830ad8b589a97a88be25e924a59670c1017fb51447dad -R b63eb752943f01d1de6f4800dabd8585 +P 5d725644621cf640fb743d59ccf89dac777540410e67501eb00b83638c8c857f +R 877424d5c7313c59d7195755bacacb98 U drh -Z f52460ed1f18979ad0fa2f0cc99e3abc +Z b4bc4db54d1dcd1788bd56fd303b8ecb # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 8b6f282a08..29b4de9228 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5d725644621cf640fb743d59ccf89dac777540410e67501eb00b83638c8c857f \ No newline at end of file +e3c0c0e686f3b7710f79587cf465b5aac52d8f2f2986a3de885a656f652cbfd3 \ No newline at end of file diff --git a/src/json.c b/src/json.c index 2d6195b797..47b83f1815 100644 --- a/src/json.c +++ b/src/json.c @@ -1425,7 +1425,7 @@ static u32 jsonbValidityCheck( }else if( z[j]<=0x1f ){ /* Control characters in JSON5 string literals are ok */ if( x==JSONB_TEXTJ ) return j+1; - }else if( z[j]!='\\' || j+1>=k ){ + }else if( NEVER(z[j]!='\\') || j+1>=k ){ return j+1; }else if( strchr("\"\\/bfnrt",z[j+1])!=0 ){ j++; @@ -2223,7 +2223,7 @@ static u32 jsonTranslateBlobToText( continue; } if( zIn[0]<=0x1f ){ - if( pOut->nUsed+7nAlloc && jsonStringGrow(pOut,7) ) break; + if( pOut->nUsed+7>pOut->nAlloc && jsonStringGrow(pOut,7) ) break; jsonAppendControlChar(pOut, zIn[0]); zIn++; sz2--; @@ -4419,7 +4419,7 @@ static void jsonErrorFunc( /* Convert byte-offset s.iErr into a character offset */ u32 k; assert( s.zJson!=0 ); /* Because s.oom is false */ - for(k=0; k Date: Wed, 31 Jan 2024 20:11:54 +0000 Subject: [PATCH 068/430] Replace an conditional assignment that was made obsolete by [d4c193f0b49f4950] with an assert(). The conditional was added by [d6fd512f50513ab7] as a fix for tickets [c36cdb4afd504dc1], [4051a7f931d9ba24], and [d6fd512f50513ab7] which means now [d4c193f0b49f4950] is the correct fix for those tickets. that check-in FossilOrigin-Name: 44b5524d522e749ad6bf76c94d754ff16c309c32439ec46802924663f64e8b09 --- manifest | 13 ++++++------- manifest.uuid | 2 +- src/where.c | 7 +++---- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/manifest b/manifest index b46eb60302..b5659ca180 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Allow\scontrol\scharacters\sin\sJSON5\sstring\sliterals.\n[forum:/forumpost/05182119f69c3a92|Forum\sthread\s05182119f69c3a92]. -D 2024-01-31T15:29:29.912 +C Replace\san\sconditional\sassignment\sthat\swas\smade\sobsolete\sby\s[d4c193f0b49f4950]\nwith\san\sassert().\s\sThe\sconditional\swas\sadded\sby\s[d6fd512f50513ab7]\sas\na\sfix\sfor\stickets\s[c36cdb4afd504dc1],\s[4051a7f931d9ba24],\sand\n[d6fd512f50513ab7]\swhich\smeans\snow\s[d4c193f0b49f4950]\sis\sthe\scorrect\sfix\nfor\sthose\stickets.\nthat\scheck-in +D 2024-01-31T20:11:54.024 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -823,7 +823,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c 887fc4ca3f020ebb2e376f222069570834ac63bf50111ef0cbf3ae417048ed89 F src/wal.h ba252daaa94f889f4b2c17c027e823d9be47ce39da1d3799886bbd51f0490452 F src/walker.c 7c7ea0115345851c3da4e04e2e239a29983b61fb5b038b94eede6aba462640e2 -F src/where.c e38e37677884d644b825fe0ab72379a24a9a74f89d8add5eb134d61fea2358a3 +F src/where.c 0a6492afeb75f8d2a50e26b993eb78e9623b142e637cd3f2cdb85e896931d51d F src/whereInt.h 82a13766f13d1a53b05387c2e60726289ef26404bc7b9b1f7770204d97357fb8 F src/wherecode.c 5d77db30a2a3dd532492ae882de114edba2fae672622056b1c7fd61f5917a8f1 F src/whereexpr.c dc5096eca5ed503999be3bdee8a90c51361289a678d396a220912e9cb73b3c00 @@ -2161,9 +2161,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 32ce7dacf58bbf35cf70da8b03fa25f97fcea970edbc1f8aa12739ac4c8608fb e3c0c0e686f3b7710f79587cf465b5aac52d8f2f2986a3de885a656f652cbfd3 -R 877424d5c7313c59d7195755bacacb98 -T +closed e3c0c0e686f3b7710f79587cf465b5aac52d8f2f2986a3de885a656f652cbfd3 +P 380f09c194caff557640692d2f255f8cdc1dcfed5976711686466692f4d7a60d +R 2ab0e5cc506f3fb919b7f44b2ff0cd53 U drh -Z 2c071c25594479aa12bff0fe9b315417 +Z 85535a5e43d2635944e90f9135f7853b # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 70f3a70154..dcc6a1a493 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -380f09c194caff557640692d2f255f8cdc1dcfed5976711686466692f4d7a60d \ No newline at end of file +44b5524d522e749ad6bf76c94d754ff16c309c32439ec46802924663f64e8b09 \ No newline at end of file diff --git a/src/where.c b/src/where.c index b0fe12e52b..65022a65bb 100644 --- a/src/where.c +++ b/src/where.c @@ -5464,10 +5464,9 @@ static int wherePathSolver(WhereInfo *pWInfo, LogEst nRowEst){ if( pFrom->isOrdered==pWInfo->pOrderBy->nExpr ){ pWInfo->eDistinct = WHERE_DISTINCT_ORDERED; } - if( pWInfo->pSelect->pOrderBy - && pWInfo->nOBSat > pWInfo->pSelect->pOrderBy->nExpr ){ - pWInfo->nOBSat = pWInfo->pSelect->pOrderBy->nExpr; - } + /* vvv--- See check-in [12ad822d9b827777] on 2023-03-16 ---vvv */ + assert( pWInfo->pSelect->pOrderBy==0 + || pWInfo->nOBSat <= pWInfo->pSelect->pOrderBy->nExpr ); }else{ pWInfo->revMask = pFrom->revLoop; if( pWInfo->nOBSat<=0 ){ From d87299cece175fe92418a8f3a11d14dd56cd9e6a Mon Sep 17 00:00:00 2001 From: drh <> Date: Thu, 1 Feb 2024 11:38:58 +0000 Subject: [PATCH 069/430] Add the test_oom_breakpoint() routine on debug builds, to serve as a convenient breakpoint to intercept OOM conditions. FossilOrigin-Name: e45df7dcd6b5766d7593ee87e59dd422a217cce0a1a8d369c03144bb21859428 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/malloc.c | 20 ++++++++++++++++++++ 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index b5659ca180..ace9856f05 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Replace\san\sconditional\sassignment\sthat\swas\smade\sobsolete\sby\s[d4c193f0b49f4950]\nwith\san\sassert().\s\sThe\sconditional\swas\sadded\sby\s[d6fd512f50513ab7]\sas\na\sfix\sfor\stickets\s[c36cdb4afd504dc1],\s[4051a7f931d9ba24],\sand\n[d6fd512f50513ab7]\swhich\smeans\snow\s[d4c193f0b49f4950]\sis\sthe\scorrect\sfix\nfor\sthose\stickets.\nthat\scheck-in -D 2024-01-31T20:11:54.024 +C Add\sthe\stest_oom_breakpoint()\sroutine\son\sdebug\sbuilds,\sto\sserve\sas\sa\nconvenient\sbreakpoint\sto\sintercept\sOOM\sconditions. +D 2024-02-01T11:38:58.054 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -702,7 +702,7 @@ F src/json.c e4e5f70b602c1dc9592b798166697bedeb84c61ffe857c9302ded54d5024603d F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 F src/main.c 438b95162acfa17b7d218f586f5bde11d6ae82bcf030c9611fc537556870ad6b -F src/malloc.c f016922435dc7d1f1f5083a03338a3e91f8c67ce2c5bdcfa4cdef62e612f5fcc +F src/malloc.c c31472af77e3421d993b69c93f07890277afd94247da4290e1b290ffc0d1f404 F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c 3bb59158c38e05f6270e761a9f435bf19827a264c13d1631c58b84bdc96d73b2 F src/mem2.c c8bfc9446fd0798bddd495eb5d9dbafa7d4b7287d8c22d50a83ac9daa26d8a75 @@ -2161,8 +2161,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 380f09c194caff557640692d2f255f8cdc1dcfed5976711686466692f4d7a60d -R 2ab0e5cc506f3fb919b7f44b2ff0cd53 +P 44b5524d522e749ad6bf76c94d754ff16c309c32439ec46802924663f64e8b09 +R cf60142a32287adf1c10b35b8571b6b1 U drh -Z 85535a5e43d2635944e90f9135f7853b +Z 5e6025aea61024ad1af737cfb95ff572 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index dcc6a1a493..9376937a9e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -44b5524d522e749ad6bf76c94d754ff16c309c32439ec46802924663f64e8b09 \ No newline at end of file +e45df7dcd6b5766d7593ee87e59dd422a217cce0a1a8d369c03144bb21859428 \ No newline at end of file diff --git a/src/malloc.c b/src/malloc.c index 356750682e..ef7d2e1edd 100644 --- a/src/malloc.c +++ b/src/malloc.c @@ -221,6 +221,24 @@ static void sqlite3MallocAlarm(int nByte){ sqlite3_mutex_enter(mem0.mutex); } +#ifdef SQLITE_DEBUG +/* +** This routine is called whenever an out-of-memory condition is seen, +** It's only purpose to to serve as a breakpoint for gdb or similar +** code debuggers when working on out-of-memory conditions, for example +** caused by PRAGMA hard_heap_limit=N. +*/ +static SQLITE_NOINLINE void test_oom_breakpoint(void){ + static u64 nOomFault = 0; + nOomFault++; + /* The assert() is never reached in a human lifetime. It is here mostly + ** to prevent code optimizers from optimizing out this function. */ + assert( (nOomFault>>32) < 0xffffffff ); +} +#else +# define test_oom_breakpoint(X) /* No-op for production builds */ +#endif + /* ** Do a memory allocation with statistics and alarms. Assume the ** lock is already held. @@ -247,6 +265,7 @@ static void mallocWithAlarm(int n, void **pp){ if( mem0.hardLimit ){ nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED); if( nUsed >= mem0.hardLimit - nFull ){ + test_oom_breakpoint(); *pp = 0; return; } @@ -535,6 +554,7 @@ void *sqlite3Realloc(void *pOld, u64 nBytes){ sqlite3MallocAlarm(nDiff); if( mem0.hardLimit>0 && nUsed >= mem0.hardLimit - nDiff ){ sqlite3_mutex_leave(mem0.mutex); + test_oom_breakpoint(); return 0; } } From 1d09f4d01858e248bd6bbdc469e39245e2436ffb Mon Sep 17 00:00:00 2001 From: drh <> Date: Thu, 1 Feb 2024 14:17:01 +0000 Subject: [PATCH 070/430] Add tracing logic to the shared-cache locks in btree.c. The tracing is off by default. Enable by changing a single "#if 0" into "#if 1" and recompiling. Debugging code only - no changes to release builds. FossilOrigin-Name: f2b943f97ad7e47848ac6df3a3a1eba134b9e63c4a631f8eaf8bda77cc02ba7b --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/btree.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index ace9856f05..0a2814cf9b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\stest_oom_breakpoint()\sroutine\son\sdebug\sbuilds,\sto\sserve\sas\sa\nconvenient\sbreakpoint\sto\sintercept\sOOM\sconditions. -D 2024-02-01T11:38:58.054 +C Add\stracing\slogic\sto\sthe\sshared-cache\slocks\sin\sbtree.c.\s\sThe\stracing\sis\noff\sby\sdefault.\s\sEnable\sby\schanging\sa\ssingle\s"#if\s0"\sinto\s"#if\s1"\sand\nrecompiling.\s\sDebugging\scode\sonly\s-\sno\schanges\sto\srelease\sbuilds. +D 2024-02-01T14:17:01.624 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -677,7 +677,7 @@ F src/auth.c 19b7ccacae3dfba23fc6f1d0af68134fa216e9040e53b0681b4715445ea030b4 F src/backup.c 5c97e8023aab1ce14a42387eb3ae00ba5a0644569e3476f38661fa6f824c3523 F src/bitvec.c 9eac5f42c11914d5ef00a75605bb205e934f435c579687f985f1f8b0995c8645 F src/btmutex.c 79a43670447eacc651519a429f6ece9fd638563cf95b469d6891185ddae2b522 -F src/btree.c c64df2b1623501e397128261de58d3ab44c301e4eb993a4055aa971444420200 +F src/btree.c 186359bd695150d22b9f385ffb487b9a029ecea158658eed3a0268ee63ecbf9c F src/btree.h 03e3356f5208bcab8eed4e094240fdac4a7f9f5ddf5e91045ce589f67d47c240 F src/btreeInt.h 3e2589726c4f105e653461814f65857465da68be1fac688de340c43b873f4062 F src/build.c 05c9eb387638982092988d2ef4c00a91b0c29baa1b85923f082ce0cf2903ea7e @@ -2161,8 +2161,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 44b5524d522e749ad6bf76c94d754ff16c309c32439ec46802924663f64e8b09 -R cf60142a32287adf1c10b35b8571b6b1 +P e45df7dcd6b5766d7593ee87e59dd422a217cce0a1a8d369c03144bb21859428 +R 1c4d155f92c2e065cfacf61f3e9f41bd U drh -Z 5e6025aea61024ad1af737cfb95ff572 +Z 977fd1472c72116436cf99418d5cf571 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 9376937a9e..f055fdee92 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e45df7dcd6b5766d7593ee87e59dd422a217cce0a1a8d369c03144bb21859428 \ No newline at end of file +f2b943f97ad7e47848ac6df3a3a1eba134b9e63c4a631f8eaf8bda77cc02ba7b \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index c41fb811ab..57b2efc9e0 100644 --- a/src/btree.c +++ b/src/btree.c @@ -151,8 +151,47 @@ int corruptPageError(int lineno, MemPage *p){ # define SQLITE_CORRUPT_PAGE(pMemPage) SQLITE_CORRUPT_PGNO(pMemPage->pgno) #endif +/* Default value for SHARED_LOCK_TRACE macro if shared-cache is disabled +** or if the lock tracking is disabled. This is always the value for +** release builds. +*/ +#define SHARED_LOCK_TRACE(X,MSG,TAB,TYPE) /*no-op*/ + #ifndef SQLITE_OMIT_SHARED_CACHE +#if 0 +/* ^---- Change to 1 and recompile to enable shared-lock tracing +** for debugging purposes. +** +** Print all shared-cache locks on a BtShared. Debugging use only. +*/ +static void sharedLockTrace( + BtShared *pBt, + const char *zMsg, + int iRoot, + int eLockType +){ + BtLock *pLock; + if( iRoot>0 ){ + printf("%s-%p %u%s:", zMsg, pBt, iRoot, eLockType==READ_LOCK?"R":"W"); + }else{ + printf("%s-%p:", zMsg, pBt); + } + for(pLock=pBt->pLock; pLock; pLock=pLock->pNext){ + printf(" %p/%u%s", pLock->pBtree, pLock->iTable, + pLock->eLock==READ_LOCK ? "R" : "W"); + while( pLock->pNext && pLock->pBtree==pLock->pNext->pBtree ){ + pLock = pLock->pNext; + printf(",%u%s", pLock->iTable, pLock->eLock==READ_LOCK ? "R" : "W"); + } + } + printf("\n"); + fflush(stdout); +} +#undef SHARED_LOCK_TRACE +#define SHARED_LOCK_TRACE(X,MSG,TAB,TYPE) sharedLockTrace(X,MSG,TAB,TYPE) +#endif /* Shared-lock tracing */ + #ifdef SQLITE_DEBUG /* **** This function is only used as part of an assert() statement. *** @@ -229,6 +268,8 @@ static int hasSharedCacheTableLock( iTab = iRoot; } + SHARED_LOCK_TRACE(pBtree->pBt,"hasLock",iRoot,eLockType); + /* Search for the required lock. Either a write-lock on root-page iTab, a ** write-lock on the schema table, or (if the client is reading) a ** read-lock on iTab will suffice. Return 1 if any of these are found. */ @@ -362,6 +403,8 @@ static int setSharedCacheTableLock(Btree *p, Pgno iTable, u8 eLock){ BtLock *pLock = 0; BtLock *pIter; + SHARED_LOCK_TRACE(pBt,"setLock", iTable, eLock); + assert( sqlite3BtreeHoldsMutex(p) ); assert( eLock==READ_LOCK || eLock==WRITE_LOCK ); assert( p->db!=0 ); @@ -429,6 +472,8 @@ static void clearAllSharedCacheTableLocks(Btree *p){ assert( p->sharable || 0==*ppIter ); assert( p->inTrans>0 ); + SHARED_LOCK_TRACE(pBt, "clearAllLocks", 0, 0); + while( *ppIter ){ BtLock *pLock = *ppIter; assert( (pBt->btsFlags & BTS_EXCLUSIVE)==0 || pBt->pWriter==pLock->pBtree ); @@ -467,6 +512,9 @@ static void clearAllSharedCacheTableLocks(Btree *p){ */ static void downgradeAllSharedCacheTableLocks(Btree *p){ BtShared *pBt = p->pBt; + + SHARED_LOCK_TRACE(pBt, "downgradeLocks", 0, 0); + if( pBt->pWriter==p ){ BtLock *pLock; pBt->pWriter = 0; From 64b76c0ed4ad645e4b4d5db86fe37ef00a56b55a Mon Sep 17 00:00:00 2001 From: drh <> Date: Thu, 1 Feb 2024 14:57:24 +0000 Subject: [PATCH 071/430] In PRAGMA integrity_check, defer running xIntegrity on virtual tables until after all ordinary tables have been checked. FossilOrigin-Name: 8f4b1ceafe4a271b23e17493a244a34c1732a3d35c5533c37394b9f3dc158435 --- manifest | 12 +++++------ manifest.uuid | 2 +- src/pragma.c | 59 +++++++++++++++++++++++++++++---------------------- 3 files changed, 41 insertions(+), 32 deletions(-) diff --git a/manifest b/manifest index 0a2814cf9b..9040a87866 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\stracing\slogic\sto\sthe\sshared-cache\slocks\sin\sbtree.c.\s\sThe\stracing\sis\noff\sby\sdefault.\s\sEnable\sby\schanging\sa\ssingle\s"#if\s0"\sinto\s"#if\s1"\sand\nrecompiling.\s\sDebugging\scode\sonly\s-\sno\schanges\sto\srelease\sbuilds. -D 2024-02-01T14:17:01.624 +C In\sPRAGMA\sintegrity_check,\sdefer\srunning\sxIntegrity\son\svirtual\stables\suntil\nafter\sall\sordinary\stables\shave\sbeen\schecked. +D 2024-02-01T14:57:24.429 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -731,7 +731,7 @@ F src/parse.y bfd6da46fc895cd8237400ff485d04ab0b32e47eb56de20982bb7f53e56c1f42 F src/pcache.c 040b165f30622a21b7a9a77c6f2e4877a32fb7f22d4c7f0d2a6fa6833a156a75 F src/pcache.h 1497ce1b823cf00094bb0cf3bac37b345937e6f910890c626b16512316d3abf5 F src/pcache1.c 602acb23c471bb8d557a6f0083cc2be641d6cafcafa19e481eba7ef4c9ca0f00 -F src/pragma.c b5b4cff830575e6188cd56a295a57448d2b9dbc53f0dae58e22b97354cda3781 +F src/pragma.c f9b6bb9a044a0dfda1f31c2d1523c7970f850688b450f06e61e23672d70adac0 F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7 F src/prepare.c 371f6115cb69286ebc12c6f2d7511279c2e47d9f54f475d46a554d687a3b312c F src/printf.c 18fbdf028345c8fbe6044f5f5bfda5a10d48d6287afef088cc21b0ca57985640 @@ -2161,8 +2161,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P e45df7dcd6b5766d7593ee87e59dd422a217cce0a1a8d369c03144bb21859428 -R 1c4d155f92c2e065cfacf61f3e9f41bd +P f2b943f97ad7e47848ac6df3a3a1eba134b9e63c4a631f8eaf8bda77cc02ba7b +R 570d0c161255e22a4bbedff4048d62e5 U drh -Z 977fd1472c72116436cf99418d5cf571 +Z bbe0d55da8a6fc00ff4106f6aecfdfa4 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index f055fdee92..d50c977ea9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f2b943f97ad7e47848ac6df3a3a1eba134b9e63c4a631f8eaf8bda77cc02ba7b \ No newline at end of file +8f4b1ceafe4a271b23e17493a244a34c1732a3d35c5533c37394b9f3dc158435 \ No newline at end of file diff --git a/src/pragma.c b/src/pragma.c index 4c90574182..79c4e0ae84 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -1762,31 +1762,7 @@ void sqlite3Pragma( int mxCol; /* Maximum non-virtual column number */ if( pObjTab && pObjTab!=pTab ) continue; - if( !IsOrdinaryTable(pTab) ){ -#ifndef SQLITE_OMIT_VIRTUALTABLE - sqlite3_vtab *pVTab; - int a1; - if( !IsVirtual(pTab) ) continue; - if( pTab->nCol<=0 ){ - const char *zMod = pTab->u.vtab.azArg[0]; - if( sqlite3HashFind(&db->aModule, zMod)==0 ) continue; - } - sqlite3ViewGetColumnNames(pParse, pTab); - if( pTab->u.vtab.p==0 ) continue; - pVTab = pTab->u.vtab.p->pVtab; - if( NEVER(pVTab==0) ) continue; - if( NEVER(pVTab->pModule==0) ) continue; - if( pVTab->pModule->iVersion<4 ) continue; - if( pVTab->pModule->xIntegrity==0 ) continue; - sqlite3VdbeAddOp3(v, OP_VCheck, i, 3, isQuick); - pTab->nTabRef++; - sqlite3VdbeAppendP4(v, pTab, P4_TABLEREF); - a1 = sqlite3VdbeAddOp1(v, OP_IsNull, 3); VdbeCoverage(v); - integrityCheckResultRow(v); - sqlite3VdbeJumpHere(v, a1); -#endif - continue; - } + if( !IsOrdinaryTable(pTab) ) continue; if( isQuick || HasRowid(pTab) ){ pPk = 0; r2 = 0; @@ -2111,6 +2087,39 @@ void sqlite3Pragma( } } } + +#ifndef SQLITE_OMIT_VIRTUALTABLE + /* Second pass to invoke the xIntegrity method on all virtual + ** tables. + */ + for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){ + Table *pTab = sqliteHashData(x); + sqlite3_vtab *pVTab; + int a1; + if( pObjTab && pObjTab!=pTab ) continue; + if( IsOrdinaryTable(pTab) ) continue; + if( !IsVirtual(pTab) ) continue; + if( pTab->nCol<=0 ){ + const char *zMod = pTab->u.vtab.azArg[0]; + if( sqlite3HashFind(&db->aModule, zMod)==0 ) continue; + } + sqlite3ViewGetColumnNames(pParse, pTab); + if( pTab->u.vtab.p==0 ) continue; + pVTab = pTab->u.vtab.p->pVtab; + if( NEVER(pVTab==0) ) continue; + if( NEVER(pVTab->pModule==0) ) continue; + if( pVTab->pModule->iVersion<4 ) continue; + if( pVTab->pModule->xIntegrity==0 ) continue; + sqlite3VdbeAddOp3(v, OP_VCheck, i, 3, isQuick); + pTab->nTabRef++; + sqlite3VdbeAppendP4(v, pTab, P4_TABLEREF); + a1 = sqlite3VdbeAddOp1(v, OP_IsNull, 3); VdbeCoverage(v); + integrityCheckResultRow(v); + sqlite3VdbeJumpHere(v, a1); +#endif + continue; + } + } { static const int iLn = VDBE_OFFSET_LINENO(2); From adea051707fc225ba61772278b3288d002738382 Mon Sep 17 00:00:00 2001 From: dan Date: Thu, 1 Feb 2024 15:21:55 +0000 Subject: [PATCH 072/430] Ensure the fts3 xIntegrity method correctly returns error codes unrelated to corruption or missing SQL elements. FossilOrigin-Name: 1bdb8cbaf7e733e0731de2ecd7a05ddf44db5d8595dcc7aaf0927ed0aa5b33d3 --- ext/fts3/fts3.c | 12 +++++++----- ext/fts3/fts3_write.c | 7 ++++++- manifest | 18 +++++++++--------- manifest.uuid | 2 +- test/fts3fault3.test | 28 ++++++++++++++++++++++++++++ 5 files changed, 51 insertions(+), 16 deletions(-) diff --git a/ext/fts3/fts3.c b/ext/fts3/fts3.c index 379590188d..f977aabfbc 100644 --- a/ext/fts3/fts3.c +++ b/ext/fts3/fts3.c @@ -4014,22 +4014,24 @@ static int fts3IntegrityMethod( char **pzErr /* Write error message here */ ){ Fts3Table *p = (Fts3Table*)pVtab; - int rc; + int rc = SQLITE_OK; int bOk = 0; UNUSED_PARAMETER(isQuick); rc = sqlite3Fts3IntegrityCheck(p, &bOk); - assert( rc!=SQLITE_CORRUPT_VTAB || bOk==0 ); - if( rc!=SQLITE_OK && rc!=SQLITE_CORRUPT_VTAB ){ + assert( rc!=SQLITE_CORRUPT_VTAB ); + if( rc==SQLITE_ERROR || (rc&0xFF)==SQLITE_CORRUPT ){ *pzErr = sqlite3_mprintf("unable to validate the inverted index for" " FTS%d table %s.%s: %s", p->bFts4 ? 4 : 3, zSchema, zTabname, sqlite3_errstr(rc)); - }else if( bOk==0 ){ + if( *pzErr ) rc = SQLITE_OK; + }else if( rc==SQLITE_OK && bOk==0 ){ *pzErr = sqlite3_mprintf("malformed inverted index for FTS%d table %s.%s", p->bFts4 ? 4 : 3, zSchema, zTabname); + if( *pzErr==0 ) rc = SQLITE_NOMEM; } sqlite3Fts3SegmentsClose(p); - return SQLITE_OK; + return rc; } diff --git a/ext/fts3/fts3_write.c b/ext/fts3/fts3_write.c index 2516a39083..5a449dec1e 100644 --- a/ext/fts3/fts3_write.c +++ b/ext/fts3/fts3_write.c @@ -5372,7 +5372,12 @@ int sqlite3Fts3IntegrityCheck(Fts3Table *p, int *pbOk){ sqlite3_finalize(pStmt); } - *pbOk = (rc==SQLITE_OK && cksum1==cksum2); + if( rc==SQLITE_CORRUPT_VTAB ){ + rc = SQLITE_OK; + *pbOk = 0; + }else{ + *pbOk = (rc==SQLITE_OK && cksum1==cksum2); + } return rc; } diff --git a/manifest b/manifest index 9040a87866..c5b03d78bd 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C In\sPRAGMA\sintegrity_check,\sdefer\srunning\sxIntegrity\son\svirtual\stables\suntil\nafter\sall\sordinary\stables\shave\sbeen\schecked. -D 2024-02-01T14:57:24.429 +C Ensure\sthe\sfts3\sxIntegrity\smethod\scorrectly\sreturns\serror\scodes\sunrelated\sto\scorruption\sor\smissing\sSQL\selements. +D 2024-02-01T15:21:55.952 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -63,7 +63,7 @@ F ext/fts3/README.content b9078d0843a094d86af0d48dffbff13c906702b4c3558012e67b9c F ext/fts3/README.syntax a19711dc5458c20734b8e485e75fb1981ec2427a F ext/fts3/README.tokenizers b92bdeb8b46503f0dd301d364efc5ef59ef9fa8e2758b8e742f39fa93a2e422d F ext/fts3/README.txt 8c18f41574404623b76917b9da66fcb0ab38328d -F ext/fts3/fts3.c fd64a588471ce00b19da08acb0d6f904277a21ac1d15141d5913c83591afa027 +F ext/fts3/fts3.c c922380b62bd15bce953dae3350337acbd0fff07c10cdc805819409791eb480a F ext/fts3/fts3.h 3a10a0af180d502cecc50df77b1b22df142817fe F ext/fts3/fts3Int.h 968f7d7cae541a6926146e9fd3fb2b2ccbd3845b7890a8ed03de0c06ac776682 F ext/fts3/fts3_aux.c 7eab82a9cf0830f6551ba3abfdbe73ed39e322a4d3940ee82fbf723674ecd9f3 @@ -81,7 +81,7 @@ F ext/fts3/fts3_tokenizer.h 64c6ef6c5272c51ebe60fc607a896e84288fcbc3 F ext/fts3/fts3_tokenizer1.c c1de4ae28356ad98ccb8b2e3388a7fdcce7607b5523738c9afb6275dab765154 F ext/fts3/fts3_unicode.c de426ff05c1c2e7bce161cf6b706638419c3a1d9c2667de9cb9dc0458c18e226 F ext/fts3/fts3_unicode2.c 416eb7e1e81142703520d284b768ca2751d40e31fa912cae24ba74860532bf0f -F ext/fts3/fts3_write.c c2d7a8dfb6e7a00c6c88ce626785cf4c50ed18eba34b5fbd53cacd60af96d0f2 +F ext/fts3/fts3_write.c 81cd8f7e8003e427a1801e04842776b731af26dd93af206e4e66ea5ae319cad1 F ext/fts3/fts3speed.tcl b54caf6a18d38174f1a6e84219950d85e98bb1e9 F ext/fts3/tool/fts3cov.sh c331d006359456cf6f8f953e37f2b9c7d568f3863f00bb5f7eb87fea4ac01b73 F ext/fts3/tool/fts3view.c 413c346399159df81f86c4928b7c4a455caab73bfbc8cd68f950f632e5751674 @@ -1168,7 +1168,7 @@ F test/fts3expr5.test a5b9a053becbdb8e973fbf4d6d3abaabeb42d511d1848bd57931f3e0a1 F test/fts3f.test 8c438d5e1cab526b0021988fb1dc70cf3597b006a33ffd6c955ee89929077fe3 F test/fts3fault.test f4e1342acfe6d216a001490e8cd52afac1f9ffe4a11bbcdcb296129a45c5df45 F test/fts3fault2.test 7b2741e5095367238380b0fcdb837f36c24484c7a5f353659b387df63cf039ec -F test/fts3fault3.test 4a39a1618546776255dc1de306213b600aef87eca589ca8428a70c00fd11961b +F test/fts3fault3.test ccdd2292dd2d4e21e30fc5f4c8e064f79e516087eec5ff57ab6bc4f6a7714097 F test/fts3first.test dbdedd20914c8d539aa3206c9b34a23775644641 F test/fts3fuzz001.test c78afcd8ad712ea0b8d2ed50851a8aab3bc9dc52c64a536291e07112f519357c F test/fts3integrity.test 0c6fe7353d7b24d78862f4272ee9df4da2f32b3ff30fa3396945cda8119580a8 @@ -2161,8 +2161,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P f2b943f97ad7e47848ac6df3a3a1eba134b9e63c4a631f8eaf8bda77cc02ba7b -R 570d0c161255e22a4bbedff4048d62e5 -U drh -Z bbe0d55da8a6fc00ff4106f6aecfdfa4 +P 8f4b1ceafe4a271b23e17493a244a34c1732a3d35c5533c37394b9f3dc158435 +R 5c2528728c1ae6f17248d6aeeec1d716 +U dan +Z 9a20d0bd91d2ec45e34040ddfece9f98 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index d50c977ea9..69cd49c094 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8f4b1ceafe4a271b23e17493a244a34c1732a3d35c5533c37394b9f3dc158435 \ No newline at end of file +1bdb8cbaf7e733e0731de2ecd7a05ddf44db5d8595dcc7aaf0927ed0aa5b33d3 \ No newline at end of file diff --git a/test/fts3fault3.test b/test/fts3fault3.test index 6e1c0cd672..ae204718b4 100644 --- a/test/fts3fault3.test +++ b/test/fts3fault3.test @@ -50,5 +50,33 @@ do_faultsim_test 1 -faults oom* -prep { faultsim_test_result {0 {}} } +#------------------------------------------------------------------- +reset_db + +do_execsql_test 2.0 { + BEGIN; + CREATE VIRTUAL TABLE t1 USING fts3(a); + WITH s(i) AS ( + SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<50 + ) + INSERT INTO t1 SELECT 'abc def ghi jkl mno pqr' FROM s; + COMMIT; +} + +faultsim_save_and_close +do_faultsim_test 2 -faults oom-t* -prep { + faultsim_restore_and_reopen + execsql { + BEGIN; + CREATE TABLE x1(a PRIMARY KEY); + } +} -body { + execsql { + PRAGMA integrity_check; + } +} -test { + faultsim_test_result {0 ok} $::TMPDBERROR +} + finish_test From 09768559b68951149fdb00f3b3462262c0090127 Mon Sep 17 00:00:00 2001 From: dan Date: Thu, 1 Feb 2024 15:42:22 +0000 Subject: [PATCH 073/430] Ensure the fts5 xIntegrity method correctly returns error codes unrelated to corruption or missing SQL elements. FossilOrigin-Name: d18d9a05c2d6f290d7b16eafced0cde4eb8dd3f869778a49103812d35a0cee65 --- ext/fts5/fts5_main.c | 3 ++- ext/fts5/test/fts5fault8.test | 14 +++++++++++++- manifest | 14 +++++++------- manifest.uuid | 2 +- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/ext/fts5/fts5_main.c b/ext/fts5/fts5_main.c index 7c818ce747..f609f7f34a 100644 --- a/ext/fts5/fts5_main.c +++ b/ext/fts5/fts5_main.c @@ -2979,6 +2979,7 @@ static int fts5IntegrityMethod( if( (rc&0xff)==SQLITE_CORRUPT ){ *pzErr = sqlite3_mprintf("malformed inverted index for FTS5 table %s.%s", zSchema, zTabname); + rc = (*pzErr) ? SQLITE_OK : SQLITE_NOMEM; }else if( rc!=SQLITE_OK ){ *pzErr = sqlite3_mprintf("unable to validate the inverted index for" " FTS5 table %s.%s: %s", @@ -2986,7 +2987,7 @@ static int fts5IntegrityMethod( } sqlite3Fts5IndexCloseReader(pTab->p.pIndex); - return SQLITE_OK; + return rc; } static int fts5Init(sqlite3 *db){ diff --git a/ext/fts5/test/fts5fault8.test b/ext/fts5/test/fts5fault8.test index 5afab77541..dc060a1592 100644 --- a/ext/fts5/test/fts5fault8.test +++ b/ext/fts5/test/fts5fault8.test @@ -57,7 +57,6 @@ foreach_detail_mode $testprefix { } ;# foreach_detail_mode... - do_execsql_test 4.0 { CREATE VIRTUAL TABLE x2 USING fts5(a); INSERT INTO x2(x2, rank) VALUES('crisismerge', 2); @@ -80,5 +79,18 @@ do_faultsim_test 4 -faults oom-* -prep { faultsim_test_result {0 {}} {1 SQLITE_NOMEM} } +set TMPDBERROR {1 {unable to open a temporary database file for storing temporary tables}} + +do_faultsim_test 5 -faults oom-t* -prep { + faultsim_restore_and_reopen + execsql { PRAGMA temp_store = memory } +} -body { + execsql { PRAGMA integrity_check } +} -test { + if {[string match {*error code=7*} $testresult]==0} { + faultsim_test_result {0 ok} {1 SQLITE_NOMEM} $::TMPDBERROR + } +} + finish_test diff --git a/manifest b/manifest index c5b03d78bd..576583dc9c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Ensure\sthe\sfts3\sxIntegrity\smethod\scorrectly\sreturns\serror\scodes\sunrelated\sto\scorruption\sor\smissing\sSQL\selements. -D 2024-02-01T15:21:55.952 +C Ensure\sthe\sfts5\sxIntegrity\smethod\scorrectly\sreturns\serror\scodes\sunrelated\sto\scorruption\sor\smissing\sSQL\selements. +D 2024-02-01T15:42:22.671 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -98,7 +98,7 @@ F ext/fts5/fts5_config.c 8072a207034b51ae9b7694121d1b5715c794e94b275e088f70ae532 F ext/fts5/fts5_expr.c e91156ebdcc08d837f4f324168f69f3c0d7fdef0e521fd561efb48ef3297b696 F ext/fts5/fts5_hash.c adda4272be401566a6e0ba1acbe70ee5cb97fce944bc2e04dc707152a0ec91b1 F ext/fts5/fts5_index.c bb1965c3965f6fe5f64160bf1c0694a9684a790a783f293a76da1d38d319b258 -F ext/fts5/fts5_main.c cd56ed9619e9bc55ae603ecafd5965c3684bb4c1de7dd00893c307ddf98afe88 +F ext/fts5/fts5_main.c d68bd9533d5a638b7f6fae61c3cb0a15257dcdcccedaf3d0b3c9f55940c85048 F ext/fts5/fts5_storage.c f9e31b0d155e9b2c92d5d3a09ad7a56b937fbf1c7f962e10f4ca6281349f3934 F ext/fts5/fts5_tcl.c cf0fd0dbe64ec272491b749e0d594f563cda03336aeb60900129e6d18b0aefb8 F ext/fts5/fts5_test_mi.c 08c11ec968148d4cb4119d96d819f8c1f329812c568bac3684f5464be177d3ee @@ -163,7 +163,7 @@ F ext/fts5/test/fts5fault4.test 87a10d0caee57da587c7588b0c8d25d2930197399b4812ad F ext/fts5/test/fts5fault5.test a336e4e11847de24c9497f80cce18e00bb3fab7fb11f97d04eb9af898900a762 F ext/fts5/test/fts5fault6.test a0fc0a8f99e4b16500c31dfc7e38e1defe0f1693ac47650517ac7b723b1956f8 F ext/fts5/test/fts5fault7.test 0acbec416edb24b8881f154e99c31e9ccf73f539cfcd164090be139e9e97ed4c -F ext/fts5/test/fts5fault8.test 318238659d35f82ad215ecb57ca4c87486ea85d45dbeedaee42f148ff5105ee2 +F ext/fts5/test/fts5fault8.test 9353fe6a2a993c3231e09c49b0f4a12c8d306319555ff2ca6672b5b86fe9b0dd F ext/fts5/test/fts5fault9.test 098e6b894bbdf9b2192f994a30f4043673fb3f338b6b8ab1624c704422f39119 F ext/fts5/test/fts5faultA.test be4487576bff8c22cee6597d1893b312f306504a8c6ccd3c53ca85af12290c8c F ext/fts5/test/fts5faultB.test d606bdb8e81aaeb6f41de3fc9fc7ae315733f0903fbff05cf54f5b045b729ab5 @@ -2161,8 +2161,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 8f4b1ceafe4a271b23e17493a244a34c1732a3d35c5533c37394b9f3dc158435 -R 5c2528728c1ae6f17248d6aeeec1d716 +P 1bdb8cbaf7e733e0731de2ecd7a05ddf44db5d8595dcc7aaf0927ed0aa5b33d3 +R 1556903ce72520c2bcec86245b58e4bf U dan -Z 9a20d0bd91d2ec45e34040ddfece9f98 +Z ab6b3bfbcf0d40402d16029c30c5525d # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 69cd49c094..0a82b7b6e9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1bdb8cbaf7e733e0731de2ecd7a05ddf44db5d8595dcc7aaf0927ed0aa5b33d3 \ No newline at end of file +d18d9a05c2d6f290d7b16eafced0cde4eb8dd3f869778a49103812d35a0cee65 \ No newline at end of file From 3a32690a5519f7927947076bf17f64f4243c4396 Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 2 Feb 2024 11:37:03 +0000 Subject: [PATCH 074/430] Fix typo in vdbe.c comment. No changes to code. FossilOrigin-Name: 62010ba488f65aec3c6bd17b05f64c5b3e885dee4221e6016c4eb1053e19284d --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/vdbe.c | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 576583dc9c..a24b4aa0b9 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Ensure\sthe\sfts5\sxIntegrity\smethod\scorrectly\sreturns\serror\scodes\sunrelated\sto\scorruption\sor\smissing\sSQL\selements. -D 2024-02-01T15:42:22.671 +C Fix\stypo\sin\svdbe.c\scomment.\sNo\schanges\sto\scode. +D 2024-02-02T11:37:03.045 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -808,7 +808,7 @@ F src/upsert.c fa125a8d3410ce9a97b02cb50f7ae68a2476c405c76aa692d3acf6b8586e9242 F src/utf.c f23165685a67b4caf8ec08fb274cb3f319103decfb2a980b7cfd55d18dfa855e F src/util.c 078f040366d5bd5f47658d045f901c768c1c636c6eaea121f3a1cbd63c3edb5b F src/vacuum.c 604fcdaebe76f3497c855afcbf91b8fa5046b32de3045bab89cc008d68e40104 -F src/vdbe.c 92910d536e0b77505599cd6ae5d9d449e4a5d31ada61da4c0bb84f6ccb2c3189 +F src/vdbe.c dd340f5add924a8397401f7fe4faf2304ffd49ab5853d32ffc1736093b9c5080 F src/vdbe.h 88e19a982df9027ec1c177c793d1a5d34dc23d8f06e3b2d997f43688b05ee0eb F src/vdbeInt.h 949669dfd8a41550d27dcb905b494f2ccde9a2e6c1b0b04daa1227e2e74c2b2c F src/vdbeapi.c 8f57d60c89da0b60e6d4e272358c511f6bae4e24330bdb11f8b42f986d1bf21b @@ -2161,8 +2161,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 1bdb8cbaf7e733e0731de2ecd7a05ddf44db5d8595dcc7aaf0927ed0aa5b33d3 -R 1556903ce72520c2bcec86245b58e4bf +P d18d9a05c2d6f290d7b16eafced0cde4eb8dd3f869778a49103812d35a0cee65 +R aba3b7802d437f5dcd3a746bf90a6079 U dan -Z ab6b3bfbcf0d40402d16029c30c5525d +Z 006ae05388cb62c50458a12f4ef45e94 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 0a82b7b6e9..c4830dab2b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d18d9a05c2d6f290d7b16eafced0cde4eb8dd3f869778a49103812d35a0cee65 \ No newline at end of file +62010ba488f65aec3c6bd17b05f64c5b3e885dee4221e6016c4eb1053e19284d \ No newline at end of file diff --git a/src/vdbe.c b/src/vdbe.c index 84eccf5334..1e0d776536 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -7101,8 +7101,8 @@ case OP_DropTrigger: { ** ** The register P3 contains one less than the maximum number of allowed errors. ** At most reg(P3) errors will be reported. -** In other words, the analysis stops as soon as reg(P1) errors are -** seen. Reg(P1) is updated with the number of errors remaining. +** In other words, the analysis stops as soon as reg(P3) errors are +** seen. Reg(P3) is updated with the number of errors remaining. ** ** The root page numbers of all tables in the database are integers ** stored in P4_INTARRAY argument. From d90ecb5d6e10682548045f3ff72e3e670c0436ee Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 2 Feb 2024 16:51:24 +0000 Subject: [PATCH 075/430] Have "PRAGMA quick_check" compare the number of entries in tables and indexes. FossilOrigin-Name: cc294c041b4c7a044ff344989f872415ced5263a0b654112371b2da7c852a688 --- manifest | 35 +++++++++++++++-------------- manifest.uuid | 2 +- src/btree.c | 23 +++++++++++++------ src/btree.h | 1 + src/btreeInt.h | 1 + src/pragma.c | 54 +++++++++++++++++++++++++++++---------------- src/vdbe.c | 22 +++++++++--------- src/vdbe.h | 2 ++ src/vdbemem.c | 5 +++++ test/corruptD.test | 2 +- test/e_reindex.test | 6 ++--- test/pragma.test | 32 +++++++++++++-------------- test/pragma4.test | 2 +- 13 files changed, 112 insertions(+), 75 deletions(-) diff --git a/manifest b/manifest index a24b4aa0b9..fc70cdcfa3 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\stypo\sin\svdbe.c\scomment.\sNo\schanges\sto\scode. -D 2024-02-02T11:37:03.045 +C Have\s"PRAGMA\squick_check"\scompare\sthe\snumber\sof\sentries\sin\stables\sand\sindexes. +D 2024-02-02T16:51:24.901 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -677,9 +677,9 @@ F src/auth.c 19b7ccacae3dfba23fc6f1d0af68134fa216e9040e53b0681b4715445ea030b4 F src/backup.c 5c97e8023aab1ce14a42387eb3ae00ba5a0644569e3476f38661fa6f824c3523 F src/bitvec.c 9eac5f42c11914d5ef00a75605bb205e934f435c579687f985f1f8b0995c8645 F src/btmutex.c 79a43670447eacc651519a429f6ece9fd638563cf95b469d6891185ddae2b522 -F src/btree.c 186359bd695150d22b9f385ffb487b9a029ecea158658eed3a0268ee63ecbf9c -F src/btree.h 03e3356f5208bcab8eed4e094240fdac4a7f9f5ddf5e91045ce589f67d47c240 -F src/btreeInt.h 3e2589726c4f105e653461814f65857465da68be1fac688de340c43b873f4062 +F src/btree.c d49ecac72d677faa9ef604ea67248847acb1599579204c4f3b108b2ee1ca7037 +F src/btree.h 55066f513eb095db935169dab1dc2f7c7a747ef223c533f5d4ad4dfed346cbd0 +F src/btreeInt.h 98aadb6dcb77b012cab2574d6a728fad56b337fc946839b9898c4b4c969e30b6 F src/build.c 05c9eb387638982092988d2ef4c00a91b0c29baa1b85923f082ce0cf2903ea7e F src/callback.c db3a45e376deff6a16c0058163fe0ae2b73a2945f3f408ca32cf74960b28d490 F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e @@ -731,7 +731,7 @@ F src/parse.y bfd6da46fc895cd8237400ff485d04ab0b32e47eb56de20982bb7f53e56c1f42 F src/pcache.c 040b165f30622a21b7a9a77c6f2e4877a32fb7f22d4c7f0d2a6fa6833a156a75 F src/pcache.h 1497ce1b823cf00094bb0cf3bac37b345937e6f910890c626b16512316d3abf5 F src/pcache1.c 602acb23c471bb8d557a6f0083cc2be641d6cafcafa19e481eba7ef4c9ca0f00 -F src/pragma.c f9b6bb9a044a0dfda1f31c2d1523c7970f850688b450f06e61e23672d70adac0 +F src/pragma.c cf46ab7d7d4c9ea53edfff52412215538b1ac96e52718b3e1279458e26b6f26e F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7 F src/prepare.c 371f6115cb69286ebc12c6f2d7511279c2e47d9f54f475d46a554d687a3b312c F src/printf.c 18fbdf028345c8fbe6044f5f5bfda5a10d48d6287afef088cc21b0ca57985640 @@ -808,13 +808,13 @@ F src/upsert.c fa125a8d3410ce9a97b02cb50f7ae68a2476c405c76aa692d3acf6b8586e9242 F src/utf.c f23165685a67b4caf8ec08fb274cb3f319103decfb2a980b7cfd55d18dfa855e F src/util.c 078f040366d5bd5f47658d045f901c768c1c636c6eaea121f3a1cbd63c3edb5b F src/vacuum.c 604fcdaebe76f3497c855afcbf91b8fa5046b32de3045bab89cc008d68e40104 -F src/vdbe.c dd340f5add924a8397401f7fe4faf2304ffd49ab5853d32ffc1736093b9c5080 -F src/vdbe.h 88e19a982df9027ec1c177c793d1a5d34dc23d8f06e3b2d997f43688b05ee0eb +F src/vdbe.c c91a1555921f1573ef267210c8a5eeb91d28d83a1059d43a9a850c52a9bf6e39 +F src/vdbe.h c2d78d15112c3fc5ab87f5e8e0b75d2db1c624409de2e858c3d1aafb1650bb4f F src/vdbeInt.h 949669dfd8a41550d27dcb905b494f2ccde9a2e6c1b0b04daa1227e2e74c2b2c F src/vdbeapi.c 8f57d60c89da0b60e6d4e272358c511f6bae4e24330bdb11f8b42f986d1bf21b F src/vdbeaux.c c5a471b34e9c4cfc0295a3e10734fd197670ffaebcb742f284c8e17e8026ceea F src/vdbeblob.c 13f9287b55b6356b4b1845410382d6bede203ceb29ef69388a4a3d007ffacbe5 -F src/vdbemem.c 3e37dab421b74e9ce55c1e88fbc7bc6fead590b5ab258bc684f8b70abb1d6e71 +F src/vdbemem.c 6f1728ea70d9523cc446567d3bf1cca3f26515d15160dd9f540fc549cdfbe2a6 F src/vdbesort.c 00c1fb15171205063556c2f1cf454e24c0b41c1effb0c876b850dce91f21bc64 F src/vdbetrace.c fe0bc29ebd4e02c8bc5c1945f1d2e6be5927ec12c06d89b03ef2a4def34bf823 F src/vdbevtab.c 2143db7db0ceed69b21422581f434baffc507a08d831565193a7a02882a1b6a7 @@ -998,7 +998,7 @@ F test/corrupt9.test 730a3db08d4ab9aa43392ea30d9c2b4879cbff85 F test/corruptA.test 112f4b2ae0b95ebf3ea63718642fb969a93acea557ace3a307234d19c245989b F test/corruptB.test 73a8d6c0b9833697ecf16b63e3c5c05c945b5dec F test/corruptC.test 9cf32275dae3ca33f645afe5d1d3f5ba5ac2af2b0833dfb5282f9dccb6fb81bb -F test/corruptD.test a828c788535946a372a56a750b242cd96287cd823657abe5a73c5e51b91bdd28 +F test/corruptD.test 614320aa519f6bf6c7dd2f581f9513ff7b6826954180cca1a606d0e25ea084a3 F test/corruptE.test 4143791f2dfb443aec5b7fabfa5821e6063eccc3b49b06f212c2f014715fd476 F test/corruptF.test be9fde98e4c93648f1ba52b74e5318edc8f59fe4 F test/corruptG.test adf79b669cbfd19e28c8191a610d083ae53a6d51 @@ -1070,7 +1070,7 @@ F test/e_expr.test b950818a48269506d75a41c819003bd77a0893bc4a4f2fdee191bc74109c1 F test/e_fkey.test feeba6238aeff9d809fb6236b351da8df4ae9bda89e088e54526b31a0cbfeec5 F test/e_fts3.test 17ba7c373aba4d4f5696ba147ee23fd1a1ef70782af050e03e262ca187c5ee07 F test/e_insert.test f02f7f17852b2163732c6611d193f84fc67bc641fb4882c77a464076e5eba80e -F test/e_reindex.test 2b0e29344497d9a8a999453a003cb476b6b1d2eef2d6c120f83c2d3a429f3164 +F test/e_reindex.test 027bb13d2c7e9e865886eed6349f126a273f8037899b636bf5fb53c7fc815921 F test/e_resolve.test a61751c368b109db73df0f20fc75fb47e166b1d8 F test/e_select.test 327a15f14068bbd6f647cedc67210f8680fcb2f05e481a0a855fccd2abfa1292 F test/e_select2.test aceb80ab927d46fba5ce7586ebabf23e2bb0604f @@ -1481,10 +1481,10 @@ F test/pendingrace.test 6aa33756b950c4529f79c4f3817a9a1e4025bd0d9961571a05c0279b F test/percentile.test 4243af26b8f3f4555abe166f723715a1f74c77ff F test/permutations.test f7caf8dd5c7b1da74842a48df116f7f193399c656d4ffc805cd0d9658568c675 F test/pg_common.tcl 3b27542224db1e713ae387459b5d117c836a5f6e328846922993b6d2b7640d9f -F test/pragma.test 57a36226218c03cfb381019fe43234b2cefbd8a1f12825514f906a17ccf7991e +F test/pragma.test 6e0bb3277d7293328a0cec417b967db62beb1700ae8e4e3cdb52be585705cbdd F test/pragma2.test e5d5c176360c321344249354c0c16aec46214c9f F test/pragma3.test 92a46bbea12322dd94a404f49edcfbfc913a2c98115f0d030a7459bb4712ef31 -F test/pragma4.test ca5e4dfc46adfe490f75d73734f70349d95a199e6510973899e502eef2c8b1f8 +F test/pragma4.test 9559cf5173864bf47c0431873d158fbeb72f920a59905b1f46069d8543eccdab F test/pragma5.test 7b33fc43e2e41abf17f35fb73f71b49671a380ea92a6c94b6ce530a25f8d9102 F test/pragmafault.test 275edaf3161771d37de60e5c2b412627ac94cef11739236bec12ed1258b240f8 F test/prefixes.test b524a1c44bffec225b9aec98bd728480352aa8532ac4c15771fb85e8beef65d9 @@ -2161,8 +2161,11 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P d18d9a05c2d6f290d7b16eafced0cde4eb8dd3f869778a49103812d35a0cee65 -R aba3b7802d437f5dcd3a746bf90a6079 +P 62010ba488f65aec3c6bd17b05f64c5b3e885dee4221e6016c4eb1053e19284d +R f7f56a51df263c734cbee718d29c6a34 +T *branch * quick-check-counts +T *sym-quick-check-counts * +T -sym-trunk * U dan -Z 006ae05388cb62c50458a12f4ef45e94 +Z 3682eb48d291ba0b263b9d8bf9a6accb # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index c4830dab2b..a1cc104156 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -62010ba488f65aec3c6bd17b05f64c5b3e885dee4221e6016c4eb1053e19284d \ No newline at end of file +cc294c041b4c7a044ff344989f872415ced5263a0b654112371b2da7c852a688 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 57b2efc9e0..c21736e49c 100644 --- a/src/btree.c +++ b/src/btree.c @@ -10791,6 +10791,9 @@ static int checkTreePage( ** number of cells on the page. */ nCell = get2byte(&data[hdr+3]); assert( pPage->nCell==nCell ); + if( pPage->leaf || pPage->intKey==0 ){ + pCheck->nRow += nCell; + } /* EVIDENCE-OF: R-23882-45353 The cell pointer array of a b-tree page ** immediately follows the b-tree page header. */ @@ -11001,6 +11004,7 @@ int sqlite3BtreeIntegrityCheck( sqlite3 *db, /* Database connection that is running the check */ Btree *p, /* The btree to be checked */ Pgno *aRoot, /* An array of root pages numbers for individual trees */ + Mem *aCnt, /* Memory cells to write counts for each tree to */ int nRoot, /* Number of entries in aRoot[] */ int mxErr, /* Stop reporting errors after this many */ int *pnErr, /* OUT: Write number of errors seen to this variable */ @@ -11087,15 +11091,20 @@ int sqlite3BtreeIntegrityCheck( testcase( pBt->db->flags & SQLITE_CellSizeCk ); pBt->db->flags &= ~(u64)SQLITE_CellSizeCk; for(i=0; (int)iautoVacuum && aRoot[i]>1 && !bPartial ){ - checkPtrmap(&sCheck, aRoot[i], PTRMAP_ROOTPAGE, 0); - } + if( pBt->autoVacuum && aRoot[i]>1 && !bPartial ){ + checkPtrmap(&sCheck, aRoot[i], PTRMAP_ROOTPAGE, 0); + } #endif - sCheck.v0 = aRoot[i]; - checkTreePage(&sCheck, aRoot[i], ¬Used, LARGEST_INT64); + sCheck.v0 = aRoot[i]; + checkTreePage(&sCheck, aRoot[i], ¬Used, LARGEST_INT64); + } + if( aCnt ){ + sqlite3MemSetArrayInt64(aCnt, i, sCheck.nRow); + } } pBt->db->flags = savedDbFlags; diff --git a/src/btree.h b/src/btree.h index b45ace7e1d..9731b8f2dc 100644 --- a/src/btree.h +++ b/src/btree.h @@ -331,6 +331,7 @@ int sqlite3BtreeIntegrityCheck( sqlite3 *db, /* Database connection that is running the check */ Btree *p, /* The btree to be checked */ Pgno *aRoot, /* An array of root pages numbers for individual trees */ + sqlite3_value *aCnt, /* OUT: entry counts for each btree in aRoot[] */ int nRoot, /* Number of entries in aRoot[] */ int mxErr, /* Stop reporting errors after this many */ int *pnErr, /* OUT: Write number of errors seen to this variable */ diff --git a/src/btreeInt.h b/src/btreeInt.h index 67a7db25c2..1213297253 100644 --- a/src/btreeInt.h +++ b/src/btreeInt.h @@ -707,6 +707,7 @@ struct IntegrityCk { StrAccum errMsg; /* Accumulate the error message text here */ u32 *heap; /* Min-heap used for analyzing cell coverage */ sqlite3 *db; /* Database connection running the check */ + i64 nRow; /* Number of rows visited in current tree */ }; /* diff --git a/src/pragma.c b/src/pragma.c index 79c4e0ae84..7f5ccef61d 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -1692,7 +1692,6 @@ void sqlite3Pragma( Hash *pTbls; /* Set of all tables in the schema */ int *aRoot; /* Array of root page numbers of all btrees */ int cnt = 0; /* Number of entries in aRoot[] */ - int mxIdx = 0; /* Maximum number of indexes for any table */ if( OMIT_TEMPDB && i==1 ) continue; if( iDb>=0 && i!=iDb ) continue; @@ -1714,7 +1713,6 @@ void sqlite3Pragma( if( pObjTab && pObjTab!=pTab ) continue; if( HasRowid(pTab) ) cnt++; for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){ cnt++; } - if( nIdx>mxIdx ) mxIdx = nIdx; } if( cnt==0 ) continue; if( pObjTab ) cnt++; @@ -1734,11 +1732,11 @@ void sqlite3Pragma( aRoot[0] = cnt; /* Make sure sufficient number of registers have been allocated */ - sqlite3TouchRegister(pParse, 8+mxIdx); + sqlite3TouchRegister(pParse, 8+cnt); sqlite3ClearTempRegCache(pParse); /* Do the b-tree integrity checks */ - sqlite3VdbeAddOp4(v, OP_IntegrityCk, 2, cnt, 1, (char*)aRoot,P4_INTARRAY); + sqlite3VdbeAddOp4(v, OP_IntegrityCk, 1, cnt, 8, (char*)aRoot,P4_INTARRAY); sqlite3VdbeChangeP5(v, (u8)i); addr = sqlite3VdbeAddOp1(v, OP_IsNull, 2); VdbeCoverage(v); sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, @@ -1748,6 +1746,36 @@ void sqlite3Pragma( integrityCheckResultRow(v); sqlite3VdbeJumpHere(v, addr); + /* Check that the indexes all have the right number of rows */ + cnt = pObjTab ? 1 : 0; + sqlite3VdbeLoadString(v, 2, "wrong # of entries in index "); + for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){ + int iTab = 0; + Table *pTab = sqliteHashData(x); + Index *pIdx; + if( pObjTab && pObjTab!=pTab ) continue; + if( HasRowid(pTab) ){ + iTab = cnt++; + }else{ + iTab = cnt; + for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ + if( IsPrimaryKeyIndex(pIdx) ) break; + iTab++; + } + } + for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ + if( pIdx->pPartIdxWhere==0 ){ + addr = sqlite3VdbeAddOp3(v, OP_Eq, 8+cnt, 0, 8+iTab); + VdbeCoverage(v); + sqlite3VdbeLoadString(v, 4, pIdx->zName); + sqlite3VdbeAddOp3(v, OP_Concat, 4, 2, 3); + integrityCheckResultRow(v); + sqlite3VdbeJumpHere(v, addr); + } + cnt++; + } + } + /* Make sure all the indices are constructed correctly. */ for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){ @@ -2070,21 +2098,9 @@ void sqlite3Pragma( } sqlite3VdbeAddOp2(v, OP_Next, iDataCur, loopTop); VdbeCoverage(v); sqlite3VdbeJumpHere(v, loopTop-1); - if( !isQuick ){ - sqlite3VdbeLoadString(v, 2, "wrong # of entries in index "); - for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){ - if( pPk==pIdx ) continue; - sqlite3VdbeAddOp2(v, OP_Count, iIdxCur+j, 3); - addr = sqlite3VdbeAddOp3(v, OP_Eq, 8+j, 0, 3); VdbeCoverage(v); - sqlite3VdbeChangeP5(v, SQLITE_NOTNULL); - sqlite3VdbeLoadString(v, 4, pIdx->zName); - sqlite3VdbeAddOp3(v, OP_Concat, 4, 2, 3); - integrityCheckResultRow(v); - sqlite3VdbeJumpHere(v, addr); - } - if( pPk ){ - sqlite3ReleaseTempRange(pParse, r2, pPk->nKeyCol); - } + if( pPk ){ + assert( !isQuick ); + sqlite3ReleaseTempRange(pParse, r2, pPk->nKeyCol); } } diff --git a/src/vdbe.c b/src/vdbe.c index 1e0d776536..f810bc5182 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -7096,13 +7096,13 @@ case OP_DropTrigger: { /* Opcode: IntegrityCk P1 P2 P3 P4 P5 ** ** Do an analysis of the currently open database. Store in -** register P1 the text of an error message describing any problems. -** If no problems are found, store a NULL in register P1. +** register (P1+1) the text of an error message describing any problems. +** If no problems are found, store a NULL in register (P1+1). ** -** The register P3 contains one less than the maximum number of allowed errors. -** At most reg(P3) errors will be reported. -** In other words, the analysis stops as soon as reg(P3) errors are -** seen. Reg(P3) is updated with the number of errors remaining. +** The register (P1) contains one less than the maximum number of allowed +** errors. At most reg(P1) errors will be reported. +** In other words, the analysis stops as soon as reg(P1) errors are +** seen. Reg(P1) is updated with the number of errors remaining. ** ** The root page numbers of all tables in the database are integers ** stored in P4_INTARRAY argument. @@ -7124,15 +7124,15 @@ case OP_IntegrityCk: { aRoot = pOp->p4.ai; assert( nRoot>0 ); assert( aRoot[0]==(Pgno)nRoot ); - assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) ); - pnErr = &aMem[pOp->p3]; + assert( pOp->p1>0 && (pOp->p1+1)<=(p->nMem+1 - p->nCursor) ); + pnErr = &aMem[pOp->p1]; assert( (pnErr->flags & MEM_Int)!=0 ); assert( (pnErr->flags & (MEM_Str|MEM_Blob))==0 ); - pIn1 = &aMem[pOp->p1]; + pIn1 = &aMem[pOp->p1+1]; assert( pOp->p5nDb ); assert( DbMaskTest(p->btreeMask, pOp->p5) ); - rc = sqlite3BtreeIntegrityCheck(db, db->aDb[pOp->p5].pBt, &aRoot[1], nRoot, - (int)pnErr->u.i+1, &nErr, &z); + rc = sqlite3BtreeIntegrityCheck(db, db->aDb[pOp->p5].pBt, &aRoot[1], + &aMem[pOp->p3], nRoot, (int)pnErr->u.i+1, &nErr, &z); sqlite3VdbeMemSetNull(pIn1); if( nErr==0 ){ assert( z==0 ); diff --git a/src/vdbe.h b/src/vdbe.h index 25bda6be7a..9001ace2ee 100644 --- a/src/vdbe.h +++ b/src/vdbe.h @@ -296,6 +296,8 @@ RecordCompare sqlite3VdbeFindCompare(UnpackedRecord*); void sqlite3VdbeLinkSubProgram(Vdbe *, SubProgram *); int sqlite3VdbeHasSubProgram(Vdbe*); +void sqlite3MemSetArrayInt64(sqlite3_value *aMem, int iIdx, i64 val); + int sqlite3NotPureFunc(sqlite3_context*); #ifdef SQLITE_ENABLE_BYTECODE_VTAB int sqlite3VdbeBytecodeVtabInit(sqlite3*); diff --git a/src/vdbemem.c b/src/vdbemem.c index cbc6712bfd..03c58f3024 100644 --- a/src/vdbemem.c +++ b/src/vdbemem.c @@ -943,6 +943,11 @@ void sqlite3VdbeMemSetInt64(Mem *pMem, i64 val){ } } +void sqlite3MemSetArrayInt64(sqlite3_value *aMem, int iIdx, i64 val){ + aMem[iIdx].u.i = val; + aMem[iIdx].flags = MEM_Int; +} + /* A no-op destructor */ void sqlite3NoopDestructor(void *p){ UNUSED_PARAMETER(p); } diff --git a/test/corruptD.test b/test/corruptD.test index c35388adfb..381e52c808 100644 --- a/test/corruptD.test +++ b/test/corruptD.test @@ -113,7 +113,7 @@ do_test corruptD-1.1.1 { hexio_write test.db [expr 1024+1] FFFF catchsql { PRAGMA quick_check } } {0 {{*** in database main *** -Tree 2 page 2: free space corruption}}} +Tree 2 page 2: free space corruption} {wrong # of entries in index i1}}} do_test corruptD-1.1.2 { incr_change_counter hexio_write test.db [expr 1024+1] [hexio_render_int32 1021] diff --git a/test/e_reindex.test b/test/e_reindex.test index 00291b76a6..50d2e7d516 100644 --- a/test/e_reindex.test +++ b/test/e_reindex.test @@ -73,12 +73,12 @@ sqlite3 db test.db do_execsql_test e_reindex-1.3 { PRAGMA integrity_check; } [list \ + {wrong # of entries in index i2} \ + {wrong # of entries in index i1} \ {row 3 missing from index i2} \ {row 3 missing from index i1} \ {row 4 missing from index i2} \ - {row 4 missing from index i1} \ - {wrong # of entries in index i2} \ - {wrong # of entries in index i1} + {row 4 missing from index i1} ] do_execsql_test e_reindex-1.4 { diff --git a/test/pragma.test b/test/pragma.test index 5b45a74400..2853e5afe7 100644 --- a/test/pragma.test +++ b/test/pragma.test @@ -372,27 +372,27 @@ ifcapable attach { db close sqlite3 db test.db execsql {PRAGMA integrity_check} - } {{row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}} + } {{wrong # of entries in index i2} {row 1 missing from index i2} {row 2 missing from index i2}} do_test pragma-3.3 { execsql {PRAGMA integrity_check=1} - } {{row 1 missing from index i2}} + } {{wrong # of entries in index i2}} do_test pragma-3.4 { execsql { ATTACH DATABASE 'test.db' AS t2; PRAGMA integrity_check } - } {{row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}} + } {{wrong # of entries in index i2} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2} {row 1 missing from index i2} {row 2 missing from index i2}} do_test pragma-3.5 { execsql { PRAGMA integrity_check=4 } - } {{row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2} {row 1 missing from index i2}} + } {{wrong # of entries in index i2} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}} do_catchsql_test pragma-3.6 { PRAGMA integrity_check=xyz } {1 {no such table: xyz}} do_catchsql_test pragma-3.6b { PRAGMA integrity_check=t2 - } {0 {{row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}}} + } {0 {{wrong # of entries in index i2} {row 1 missing from index i2} {row 2 missing from index i2}}} do_catchsql_test pragma-3.6c { PRAGMA integrity_check=sqlite_schema } {0 ok} @@ -400,7 +400,7 @@ ifcapable attach { execsql { PRAGMA integrity_check=0 } - } {{row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}} + } {{wrong # of entries in index i2} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2} {row 1 missing from index i2} {row 2 missing from index i2}} # Add additional corruption by appending unused pages to the end of # the database file testerr.db @@ -435,10 +435,10 @@ ifcapable attach { } {{*** in database t2 *** Page 4: never used Page 5: never used -Page 6: never used} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}} +Page 6: never used} {wrong # of entries in index i2} {row 1 missing from index i2} {row 2 missing from index i2}} do_execsql_test pragma-3.9b { PRAGMA t2.integrity_check=t2; - } {{row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}} + } {{wrong # of entries in index i2} {row 1 missing from index i2} {row 2 missing from index i2}} do_execsql_test pragma-3.9c { PRAGMA t2.integrity_check=sqlite_schema; } {ok} @@ -455,7 +455,7 @@ Page 4: never used}} } {{*** in database t2 *** Page 4: never used Page 5: never used -Page 6: never used} {row 1 missing from index i2} {row 2 missing from index i2}} +Page 6: never used} {wrong # of entries in index i2} {row 1 missing from index i2}} do_test pragma-3.12 { execsql { PRAGMA integrity_check=4 @@ -463,7 +463,7 @@ Page 6: never used} {row 1 missing from index i2} {row 2 missing from index i2}} } {{*** in database t2 *** Page 4: never used Page 5: never used -Page 6: never used} {row 1 missing from index i2}} +Page 6: never used} {wrong # of entries in index i2}} do_test pragma-3.13 { execsql { PRAGMA integrity_check=3 @@ -487,10 +487,10 @@ Page 5: never used}} } {{*** in database t2 *** Page 4: never used Page 5: never used -Page 6: never used} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2} {*** in database t3 *** +Page 6: never used} {wrong # of entries in index i2} {row 1 missing from index i2} {row 2 missing from index i2} {*** in database t3 *** Page 4: never used Page 5: never used -Page 6: never used} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}} +Page 6: never used} {wrong # of entries in index i2} {row 1 missing from index i2} {row 2 missing from index i2}} do_test pragma-3.16 { execsql { PRAGMA integrity_check(10) @@ -498,10 +498,10 @@ Page 6: never used} {row 1 missing from index i2} {row 2 missing from index i2} } {{*** in database t2 *** Page 4: never used Page 5: never used -Page 6: never used} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2} {*** in database t3 *** +Page 6: never used} {wrong # of entries in index i2} {row 1 missing from index i2} {row 2 missing from index i2} {*** in database t3 *** Page 4: never used Page 5: never used -Page 6: never used} {row 1 missing from index i2}} +Page 6: never used} {wrong # of entries in index i2}} do_test pragma-3.17 { execsql { PRAGMA integrity_check=8 @@ -509,7 +509,7 @@ Page 6: never used} {row 1 missing from index i2}} } {{*** in database t2 *** Page 4: never used Page 5: never used -Page 6: never used} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2} {*** in database t3 *** +Page 6: never used} {wrong # of entries in index i2} {row 1 missing from index i2} {row 2 missing from index i2} {*** in database t3 *** Page 4: never used Page 5: never used}} do_test pragma-3.18 { @@ -519,7 +519,7 @@ Page 5: never used}} } {{*** in database t2 *** Page 4: never used Page 5: never used -Page 6: never used} {row 1 missing from index i2}} +Page 6: never used} {wrong # of entries in index i2}} } do_test pragma-3.19 { catch {db close} diff --git a/test/pragma4.test b/test/pragma4.test index b82df81cbd..9d5a363d65 100644 --- a/test/pragma4.test +++ b/test/pragma4.test @@ -97,7 +97,7 @@ do_test pragma4-2.100 { } string map {\[ x \] x \173 {} \175 {}} \ [db eval {EXPLAIN PRAGMA integrity_check}] -} {/ IntegrityCk 2 2 1 x[0-9]+,1x /} +} {/ IntegrityCk 1 2 8 x[0-9]+,1x /} #-------------------------------------------------------------------------- From 50f9caf2707d7e64fd17bcaf424b35d3093cf4e6 Mon Sep 17 00:00:00 2001 From: drh <> Date: Fri, 2 Feb 2024 18:42:09 +0000 Subject: [PATCH 076/430] More extensive use of SQLITE_CORRUPT_PGNO. FossilOrigin-Name: 3838332cffb87f77a7c6b357066a59b9dc4f65ef4b3496767ad7ad7c14a77be2 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/btree.c | 46 +++++++++++++++++++++++----------------------- 3 files changed, 31 insertions(+), 31 deletions(-) diff --git a/manifest b/manifest index a24b4aa0b9..6bfc7a2a61 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\stypo\sin\svdbe.c\scomment.\sNo\schanges\sto\scode. -D 2024-02-02T11:37:03.045 +C More\sextensive\suse\sof\sSQLITE_CORRUPT_PGNO. +D 2024-02-02T18:42:09.735 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -677,7 +677,7 @@ F src/auth.c 19b7ccacae3dfba23fc6f1d0af68134fa216e9040e53b0681b4715445ea030b4 F src/backup.c 5c97e8023aab1ce14a42387eb3ae00ba5a0644569e3476f38661fa6f824c3523 F src/bitvec.c 9eac5f42c11914d5ef00a75605bb205e934f435c579687f985f1f8b0995c8645 F src/btmutex.c 79a43670447eacc651519a429f6ece9fd638563cf95b469d6891185ddae2b522 -F src/btree.c 186359bd695150d22b9f385ffb487b9a029ecea158658eed3a0268ee63ecbf9c +F src/btree.c bf659f4b1622c120ec6a863ba96c63f1861595ca21124950d977cec1477dd922 F src/btree.h 03e3356f5208bcab8eed4e094240fdac4a7f9f5ddf5e91045ce589f67d47c240 F src/btreeInt.h 3e2589726c4f105e653461814f65857465da68be1fac688de340c43b873f4062 F src/build.c 05c9eb387638982092988d2ef4c00a91b0c29baa1b85923f082ce0cf2903ea7e @@ -2161,8 +2161,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P d18d9a05c2d6f290d7b16eafced0cde4eb8dd3f869778a49103812d35a0cee65 -R aba3b7802d437f5dcd3a746bf90a6079 -U dan -Z 006ae05388cb62c50458a12f4ef45e94 +P 62010ba488f65aec3c6bd17b05f64c5b3e885dee4221e6016c4eb1053e19284d +R ce828c7f8969aa9dd36f079e0d3d1a31 +U drh +Z a60787a93d78c5cb2066cabdbdc63c36 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index c4830dab2b..29bf8b3ac3 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -62010ba488f65aec3c6bd17b05f64c5b3e885dee4221e6016c4eb1053e19284d \ No newline at end of file +3838332cffb87f77a7c6b357066a59b9dc4f65ef4b3496767ad7ad7c14a77be2 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 57b2efc9e0..058f246701 100644 --- a/src/btree.c +++ b/src/btree.c @@ -8310,7 +8310,7 @@ static int balance_nonroot( ** table-interior, index-leaf, or index-interior). */ if( pOld->aData[0]!=apOld[0]->aData[0] ){ - rc = SQLITE_CORRUPT_BKPT; + rc = SQLITE_CORRUPT_PAGE(pOld); goto balance_cleanup; } @@ -8334,7 +8334,7 @@ static int balance_nonroot( memset(&b.szCell[b.nCell], 0, sizeof(b.szCell[0])*(limit+pOld->nOverflow)); if( pOld->nOverflow>0 ){ if( NEVER(limitaiOvfl[0]) ){ - rc = SQLITE_CORRUPT_BKPT; + rc = SQLITE_CORRUPT_PAGE(pOld); goto balance_cleanup; } limit = pOld->aiOvfl[0]; @@ -8977,7 +8977,7 @@ static int anotherValidCursor(BtCursor *pCur){ && pOther->eState==CURSOR_VALID && pOther->pPage==pCur->pPage ){ - return SQLITE_CORRUPT_BKPT; + return SQLITE_CORRUPT_PAGE(pCur->pPage); } } return SQLITE_OK; @@ -9037,7 +9037,7 @@ static int balance(BtCursor *pCur){ /* The page being written is not a root page, and there is currently ** more than one reference to it. This only happens if the page is one ** of its own ancestor pages. Corruption. */ - rc = SQLITE_CORRUPT_BKPT; + rc = SQLITE_CORRUPT_PAGE(pPage); }else{ MemPage * const pParent = pCur->apPage[iPage-1]; int const iIdx = pCur->aiIdx[iPage-1]; @@ -9201,7 +9201,7 @@ static SQLITE_NOINLINE int btreeOverwriteOverflowCell( rc = btreeGetPage(pBt, ovflPgno, &pPage, 0); if( rc ) return rc; if( sqlite3PagerPageRefcount(pPage->pDbPage)!=1 || pPage->isInit ){ - rc = SQLITE_CORRUPT_BKPT; + rc = SQLITE_CORRUPT_PAGE(pPage); }else{ if( iOffset+ovflPageSize<(u32)nTotal ){ ovflPgno = get4byte(pPage->aData); @@ -9229,7 +9229,7 @@ static int btreeOverwriteCell(BtCursor *pCur, const BtreePayload *pX){ if( pCur->info.pPayload + pCur->info.nLocal > pPage->aDataEnd || pCur->info.pPayload < pPage->aData + pPage->cellOffset ){ - return SQLITE_CORRUPT_BKPT; + return SQLITE_CORRUPT_PAGE(pPage); } if( pCur->info.nLocal==nTotal ){ /* The entire cell is local */ @@ -9310,7 +9310,7 @@ int sqlite3BtreeInsert( ** Which can only happen if the SQLITE_NoSchemaError flag was set when ** the schema was loaded. This cannot be asserted though, as a user might ** set the flag, load the schema, and then unset the flag. */ - return SQLITE_CORRUPT_BKPT; + return SQLITE_CORRUPT_PGNO(pCur->pgnoRoot); } } @@ -9433,7 +9433,7 @@ int sqlite3BtreeInsert( if( pPage->nFree<0 ){ if( NEVER(pCur->eState>CURSOR_INVALID) ){ /* ^^^^^--- due to the moveToRoot() call above */ - rc = SQLITE_CORRUPT_BKPT; + rc = SQLITE_CORRUPT_PAGE(pPage); }else{ rc = btreeComputeFreeSpace(pPage); } @@ -9472,7 +9472,7 @@ int sqlite3BtreeInsert( CellInfo info; assert( idx>=0 ); if( idx>=pPage->nCell ){ - return SQLITE_CORRUPT_BKPT; + return SQLITE_CORRUPT_PAGE(pPage); } rc = sqlite3PagerWrite(pPage->pDbPage); if( rc ){ @@ -9499,10 +9499,10 @@ int sqlite3BtreeInsert( ** necessary to add the PTRMAP_OVERFLOW1 pointer-map entry. */ assert( rc==SQLITE_OK ); /* clearCell never fails when nLocal==nPayload */ if( oldCell < pPage->aData+pPage->hdrOffset+10 ){ - return SQLITE_CORRUPT_BKPT; + return SQLITE_CORRUPT_PAGE(pPage); } if( oldCell+szNew > pPage->aDataEnd ){ - return SQLITE_CORRUPT_BKPT; + return SQLITE_CORRUPT_PAGE(pPage); } memcpy(oldCell, newCell, szNew); return SQLITE_OK; @@ -9604,7 +9604,7 @@ int sqlite3BtreeTransferRow(BtCursor *pDest, BtCursor *pSrc, i64 iKey){ nIn = pSrc->info.nLocal; aIn = pSrc->info.pPayload; if( aIn+nIn>pSrc->pPage->aDataEnd ){ - return SQLITE_CORRUPT_BKPT; + return SQLITE_CORRUPT_PAGE(pSrc->pPage); } nRem = pSrc->info.nPayload; if( nIn==nRem && nInpPage->maxLocal ){ @@ -9629,7 +9629,7 @@ int sqlite3BtreeTransferRow(BtCursor *pDest, BtCursor *pSrc, i64 iKey){ if( nRem>nIn ){ if( aIn+nIn+4>pSrc->pPage->aDataEnd ){ - return SQLITE_CORRUPT_BKPT; + return SQLITE_CORRUPT_PAGE(pSrc->pPage); } ovflIn = get4byte(&pSrc->info.pPayload[nIn]); } @@ -9725,7 +9725,7 @@ int sqlite3BtreeDelete(BtCursor *pCur, u8 flags){ assert( rc!=SQLITE_OK || CORRUPT_DB || pCur->eState==CURSOR_VALID ); if( rc || pCur->eState!=CURSOR_VALID ) return rc; }else{ - return SQLITE_CORRUPT_BKPT; + return SQLITE_CORRUPT_PGNO(pCur->pgnoRoot); } } assert( pCur->eState==CURSOR_VALID ); @@ -9734,14 +9734,14 @@ int sqlite3BtreeDelete(BtCursor *pCur, u8 flags){ iCellIdx = pCur->ix; pPage = pCur->pPage; if( pPage->nCell<=iCellIdx ){ - return SQLITE_CORRUPT_BKPT; + return SQLITE_CORRUPT_PAGE(pPage); } pCell = findCell(pPage, iCellIdx); if( pPage->nFree<0 && btreeComputeFreeSpace(pPage) ){ - return SQLITE_CORRUPT_BKPT; + return SQLITE_CORRUPT_PAGE(pPage); } if( pCell<&pPage->aCellIdx[pPage->nCell] ){ - return SQLITE_CORRUPT_BKPT; + return SQLITE_CORRUPT_PAGE(pPage); } /* If the BTREE_SAVEPOSITION bit is on, then the cursor position must @@ -9832,7 +9832,7 @@ int sqlite3BtreeDelete(BtCursor *pCur, u8 flags){ n = pCur->pPage->pgno; } pCell = findCell(pLeaf, pLeaf->nCell-1); - if( pCell<&pLeaf->aData[4] ) return SQLITE_CORRUPT_BKPT; + if( pCell<&pLeaf->aData[4] ) return SQLITE_CORRUPT_PAGE(pLeaf); nCell = pLeaf->xCellSize(pLeaf, pCell); assert( MX_CELL_SIZE(pBt) >= nCell ); pTmp = pBt->pTmpSpace; @@ -9948,7 +9948,7 @@ static int btreeCreateTable(Btree *p, Pgno *piTable, int createTabFlags){ */ sqlite3BtreeGetMeta(p, BTREE_LARGEST_ROOT_PAGE, &pgnoRoot); if( pgnoRoot>btreePagecount(pBt) ){ - return SQLITE_CORRUPT_BKPT; + return SQLITE_CORRUPT_PGNO(pgnoRoot); } pgnoRoot++; @@ -9996,7 +9996,7 @@ static int btreeCreateTable(Btree *p, Pgno *piTable, int createTabFlags){ } rc = ptrmapGet(pBt, pgnoRoot, &eType, &iPtrPage); if( eType==PTRMAP_ROOTPAGE || eType==PTRMAP_FREEPAGE ){ - rc = SQLITE_CORRUPT_BKPT; + rc = SQLITE_CORRUPT_PGNO(pgnoRoot); } if( rc!=SQLITE_OK ){ releasePage(pRoot); @@ -10086,14 +10086,14 @@ static int clearDatabasePage( assert( sqlite3_mutex_held(pBt->mutex) ); if( pgno>btreePagecount(pBt) ){ - return SQLITE_CORRUPT_BKPT; + return SQLITE_CORRUPT_PGNO(pgno); } rc = getAndInitPage(pBt, pgno, &pPage, 0); if( rc ) return rc; if( (pBt->openFlags & BTREE_SINGLE)==0 && sqlite3PagerPageRefcount(pPage->pDbPage) != (1 + (pgno==1)) ){ - rc = SQLITE_CORRUPT_BKPT; + rc = SQLITE_CORRUPT_PAGE(pPage); goto cleardatabasepage_out; } hdr = pPage->hdrOffset; @@ -10197,7 +10197,7 @@ static int btreeDropTable(Btree *p, Pgno iTable, int *piMoved){ assert( p->inTrans==TRANS_WRITE ); assert( iTable>=2 ); if( iTable>btreePagecount(pBt) ){ - return SQLITE_CORRUPT_BKPT; + return SQLITE_CORRUPT_PGNO(iTable); } rc = sqlite3BtreeClearTable(p, iTable, 0); From 7d6f33046f6c52b308d58ed89e894cb37ad5a18b Mon Sep 17 00:00:00 2001 From: drh <> Date: Sat, 3 Feb 2024 19:19:18 +0000 Subject: [PATCH 077/430] Following a ROLLBACK that reverts changes to an RTREE, any pending queries against that same RTREE abort with code SQLITE_ABORT_ROLLBACK. dbsqlfuzz de7d17b72d0e842352c998dd86a47b7d0f707be9. FossilOrigin-Name: af5c425114f32c2f84aea20edd4fa46eb1bfdeb3747fce357540e15978a070c8 --- ext/rtree/rtree.c | 21 +++++- ext/rtree/rtreeJ.test | 159 ++++++++++++++++++++++++++++++++++++++++++ manifest | 13 ++-- manifest.uuid | 2 +- 4 files changed, 186 insertions(+), 9 deletions(-) create mode 100644 ext/rtree/rtreeJ.test diff --git a/ext/rtree/rtree.c b/ext/rtree/rtree.c index 013bb0b5b8..93a849cf0f 100644 --- a/ext/rtree/rtree.c +++ b/ext/rtree/rtree.c @@ -170,6 +170,7 @@ struct Rtree { u32 nBusy; /* Current number of users of this structure */ i64 nRowEst; /* Estimated number of rows in this table */ u32 nCursor; /* Number of open cursors */ + u32 iGeneration; /* Cursors with smaller iGeneration are stale */ u32 nNodeRef; /* Number RtreeNodes with positive nRef */ char *zReadAuxSql; /* SQL for statement to read aux data */ @@ -286,6 +287,7 @@ struct RtreeCursor { u8 atEOF; /* True if at end of search */ u8 bPoint; /* True if sPoint is valid */ u8 bAuxValid; /* True if pReadAux is valid */ + u32 iGeneration; /* Stale if too small */ int iStrategy; /* Copy of idxNum search parameter */ int nConstraint; /* Number of entries in aConstraint */ RtreeConstraint *aConstraint; /* Search constraints. */ @@ -1087,6 +1089,7 @@ static int rtreeOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){ if( pCsr ){ memset(pCsr, 0, sizeof(RtreeCursor)); pCsr->base.pVtab = pVTab; + pCsr->iGeneration = pRtree->iGeneration; rc = SQLITE_OK; pRtree->nCursor++; } @@ -1627,6 +1630,9 @@ static int rtreeStepToLeaf(RtreeCursor *pCur){ int eInt; RtreeSearchPoint x; + if( pCur->iGenerationiGeneration ){ + return SQLITE_ABORT_ROLLBACK; + } eInt = pRtree->eCoordType==RTREE_COORD_INT32; while( (p = rtreeSearchPointFirst(pCur))!=0 && p->iLevel>0 ){ u8 *pCellData; @@ -1854,6 +1860,7 @@ static int rtreeFilter( /* Reset the cursor to the same state as rtreeOpen() leaves it in. */ resetCursor(pCsr); + pCsr->iGeneration = pRtree->iGeneration; pCsr->iStrategy = idxNum; if( idxNum==1 ){ @@ -3234,6 +3241,16 @@ static int rtreeEndTransaction(sqlite3_vtab *pVtab){ nodeBlobReset(pRtree); return SQLITE_OK; } +static int rtreeRollback(sqlite3_vtab *pVtab){ + Rtree *pRtree = (Rtree *)pVtab; + pRtree->iGeneration++; + return rtreeEndTransaction(pVtab); +} +static int rtreeRollbackTo(sqlite3_vtab *pVtab, int notUsed){ + Rtree *pRtree = (Rtree *)pVtab; + pRtree->iGeneration++; + return SQLITE_OK; +} /* ** The xRename method for rtree module virtual tables. @@ -3352,12 +3369,12 @@ static sqlite3_module rtreeModule = { rtreeBeginTransaction, /* xBegin - begin transaction */ rtreeEndTransaction, /* xSync - sync transaction */ rtreeEndTransaction, /* xCommit - commit transaction */ - rtreeEndTransaction, /* xRollback - rollback transaction */ + rtreeRollback, /* xRollback - rollback transaction */ 0, /* xFindFunction - function overloading */ rtreeRename, /* xRename - rename the table */ rtreeSavepoint, /* xSavepoint */ 0, /* xRelease */ - 0, /* xRollbackTo */ + rtreeRollbackTo, /* xRollbackTo */ rtreeShadowName, /* xShadowName */ rtreeIntegrity /* xIntegrity */ }; diff --git a/ext/rtree/rtreeJ.test b/ext/rtree/rtreeJ.test new file mode 100644 index 0000000000..4d9c01d29b --- /dev/null +++ b/ext/rtree/rtreeJ.test @@ -0,0 +1,159 @@ +# 2024-02-03 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# ROLLBACK in the middle of an RTREE query +# +if {![info exists testdir]} { + set testdir [file join [file dirname [info script]] .. .. test] +} +source $testdir/tester.tcl +set testprefix rtreeJ + +do_execsql_test 1.0 { + CREATE VIRTUAL TABLE t1 USING rtree(id, x1, x2); + INSERT INTO t1 VALUES(1, 1, 1), (2, 2, 2); +} {} + +do_execsql_test 1.1 { + SELECT * FROM t1 +} {1 1.0 1.0 2 2.0 2.0} + +# If a ROLLBACK occurs that backs out changes to the RTREE, then +# all pending queries to the RTREE are aborted. +# +do_test 1.2 { + db eval { + BEGIN; + INSERT INTO t1 VALUES(3, 3, 3); + INSERT INTO t1 VALUES(4, 4, 4); + } + set rc [catch { + db eval { SELECT * FROM t1 } { + if {$id==1} { + db eval { ROLLBACK } + } + lappend res $id $x1 $x2 + } + } msg] + list $rc $msg +} {1 {abort due to ROLLBACK}} + +do_execsql_test 1.3 { + SELECT * FROM t1; +} {1 1.0 1.0 2 2.0 2.0} + +# A COMMIT of changes to the RTREE does not affect pending queries +# +do_test 1.4 { + set res {} + db eval { + BEGIN; + INSERT INTO t1 VALUES(5, 5, 5); + INSERT INTO t1 VALUES(6, 6, 6); + } + db eval { SELECT * FROM t1 } { + if {$id==1} { + db eval { COMMIT } + } + lappend res $id $x1 $x2 + } + set res +} {1 1.0 1.0 2 2.0 2.0 5 5.0 5.0 6 6.0 6.0} + +do_execsql_test 1.5 { + SELECT * FROM t1; +} {1 1.0 1.0 2 2.0 2.0 5 5.0 5.0 6 6.0 6.0} + +do_execsql_test 1.6 { + DELETE FROM t1; + INSERT INTO t1 VALUES(1,1,1),(2,2,2),(3,3,3),(4,4,4); + CREATE TABLE t2(x); + SELECT * FROM t1; +} {1 1.0 1.0 2 2.0 2.0 3 3.0 3.0 4 4.0 4.0} + +# A rollback that does not affect the rtree table because +# the rtree table has not been written to does not cause +# a query abort. +# +do_test 1.7 { + set res {} + db eval { + BEGIN; + INSERT INTO t2(x) VALUES(12345); + } + db eval { SELECT * FROM t1 } { + if {$id==1} { + db eval { ROLLBACK } + } + lappend res $id $x1 $x2 + } + set res +} {1 1.0 1.0 2 2.0 2.0 3 3.0 3.0 4 4.0 4.0} + +# ROLLBACK TO that affects the RTREE does cause a query abort. +# +do_test 1.8 { + db eval { + DELETE FROM t1 WHERE rowid>1; + BEGIN; + DELETE FROM t2; + INSERT INTO t2(x) VALUES(23456); + SAVEPOINT 'one'; + INSERT INTO t1 VALUES(2,2,2),(3,3,3); + } + set rc [catch { + db eval { SELECT * FROM t1 } { + if {$id==1} { + db eval { ROLLBACK TO 'one'; } + } + lappend res $id $x1 $x2 + } + } msg] + list $rc $msg +} {1 {abort due to ROLLBACK}} + +do_execsql_test 1.9 { + COMMIT; + SELECT * FROM t1; +} {1 1.0 1.0} + +# ROLLBACK TO that does not affect the RTREE does not cause a query abort. +# +do_execsql_test 1.10 { + DELETE FROM t1; + INSERT INTO t1 VALUES(1,1,1),(2,2,2),(3,3,3); + BEGIN; + DELETE FROM t2; + INSERT INTO t2(x) VALUES(34567); + SAVEPOINT 'one'; + INSERT INTO t2(x) VALUES('a string'); + SELECT * FROM t1; +} {1 1.0 1.0 2 2.0 2.0 3 3.0 3.0} +do_test 1.11 { + set rc [catch { + set res {} + db eval { SELECT * FROM t1 } { + if {$id==2} { + # db eval { ROLLBACK TO 'one'; } + } + lappend res $id $x1 $x2 + } + set res + } msg] + list $rc $msg +} {0 {1 1.0 1.0 2 2.0 2.0 3 3.0 3.0}} + +do_execsql_test 1.12 { + COMMIT; + SELECT * FROM t1; +} {1 1.0 1.0 2 2.0 2.0 3 3.0 3.0} + +finish_test diff --git a/manifest b/manifest index 6bfc7a2a61..df44228dfa 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C More\sextensive\suse\sof\sSQLITE_CORRUPT_PGNO. -D 2024-02-02T18:42:09.735 +C Following\sa\sROLLBACK\sthat\sreverts\schanges\sto\san\sRTREE,\sany\spending\squeries\nagainst\sthat\ssame\sRTREE\sabort\swith\scode\sSQLITE_ABORT_ROLLBACK.\ndbsqlfuzz\sde7d17b72d0e842352c998dd86a47b7d0f707be9. +D 2024-02-03T19:19:18.306 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -495,7 +495,7 @@ F ext/repair/test/checkindex01.test b530f141413b587c9eb78ff734de6bb79bc3515c3350 F ext/repair/test/test.tcl 686d76d888dffd021f64260abf29a55c57b2cedfa7fc69150b42b1d6119aac3c F ext/rtree/README 6315c0d73ebf0ec40dedb5aa0e942bc8b54e3761 F ext/rtree/geopoly.c 0dd4775e896cee6067979d67aff7c998e75c2c9d9cd8d62a1a790c09cde7adca -F ext/rtree/rtree.c d0134bb75bc92b18a1dc011ec10419642f055c67af8ff44fc4a07c5fa9f189cb +F ext/rtree/rtree.c 32e67b122e37138694d9f499cdc72241e372058560ac2d4577cfd68ccd692953 F ext/rtree/rtree.h 4a690463901cb5e6127cf05eb8e642f127012fd5003830dbc974eca5802d9412 F ext/rtree/rtree1.test 2b5b8c719c6a4abe377f57766f428a49af36a93061cb146cccfdc3b30000c0a4 F ext/rtree/rtree2.test 9d9deddbb16fd0c30c36e6b4fdc3ee3132d765567f0f9432ee71e1303d32603d @@ -515,6 +515,7 @@ F ext/rtree/rtreeF.test 81ffa7ef51c4e4618d497a57328c265bf576990c7070633b623b23cd F ext/rtree/rtreeG.test 1b9ca6e3effb48f4161edaa463ddeaa8fca4b2526d084f9cbf5dbe4e0184939c F ext/rtree/rtreeH.test 0885151ee8429242625600ae47142cca935332c70a06737f35af53a7bd7aaf90 F ext/rtree/rtreeI.test 608e77f7fde9be5a12eae316baef640fffaafcfa90a3d67443e78123e19c4ca4 +F ext/rtree/rtreeJ.test bafa7616d6b29448bf19132ce4963a69b629b9ca6ab29f4b76889c8d542b8dfc F ext/rtree/rtree_perf.tcl 6c18c1f23cd48e0f948930c98dfdd37dfccb5195 F ext/rtree/rtree_util.tcl 202ca70df1f0645ef9d5a2170e62d378a28098d9407f0569e85c9c1cf1bd020a F ext/rtree/rtreecheck.test 934546ad9b563e090ee0c5cbdc69ad014189ad76e5df7320526797a9a345661f @@ -2161,8 +2162,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 62010ba488f65aec3c6bd17b05f64c5b3e885dee4221e6016c4eb1053e19284d -R ce828c7f8969aa9dd36f079e0d3d1a31 +P 3838332cffb87f77a7c6b357066a59b9dc4f65ef4b3496767ad7ad7c14a77be2 +R 11b673cea59b4f2c437d0cc603cd3823 U drh -Z a60787a93d78c5cb2066cabdbdc63c36 +Z 6e995078df88af9da02ef42e8af5819d # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 29bf8b3ac3..11d5e14d8d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -3838332cffb87f77a7c6b357066a59b9dc4f65ef4b3496767ad7ad7c14a77be2 \ No newline at end of file +af5c425114f32c2f84aea20edd4fa46eb1bfdeb3747fce357540e15978a070c8 \ No newline at end of file From 3ab9c021ff7076dd8c942b67b658ad013587d132 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Sun, 4 Feb 2024 04:01:11 +0000 Subject: [PATCH 078/430] Fix harmless compiler warnings seen with MSVC. FossilOrigin-Name: e52c87420b072fa68d921eda66069542d50accbfaf1110ac4cc1543a4162200d --- ext/consio/console_io.c | 11 +++++++++++ ext/fts5/fts5_tcl.c | 2 +- ext/recover/test_recover.c | 2 +- manifest | 22 +++++++++++----------- manifest.uuid | 2 +- src/json.c | 6 +++--- tool/lemon.c | 2 +- 7 files changed, 29 insertions(+), 18 deletions(-) diff --git a/ext/consio/console_io.c b/ext/consio/console_io.c index 3acb0daa27..3e2f556f52 100755 --- a/ext/consio/console_io.c +++ b/ext/consio/console_io.c @@ -29,6 +29,9 @@ #ifndef HAVE_CONSOLE_IO_H # include "console_io.h" #endif +#if defined(_MSC_VER) +# pragma warning(disable : 4204) +#endif #ifndef SQLITE_CIO_NO_TRANSLATE # if (defined(_WIN32) || defined(WIN32)) && !SQLITE_OS_WINRT @@ -127,6 +130,10 @@ static short streamOfConsole(FILE *pf, /* out */ PerStreamTags *ppst){ # endif } +# ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING +# define ENABLE_VIRTUAL_TERMINAL_PROCESSING (0x4) +# endif + # if CIO_WIN_WC_XLATE /* Define console modes for use with the Windows Console API. */ # define SHELL_CONI_MODE \ @@ -677,4 +684,8 @@ SQLITE_INTERNAL_LINKAGE char* fGetsUtf8(char *cBuf, int ncMax, FILE *pfIn){ } #endif /* !defined(SQLITE_CIO_NO_TRANSLATE) */ +#if defined(_MSC_VER) +# pragma warning(default : 4204) +#endif + #undef SHELL_INVALID_FILE_PTR diff --git a/ext/fts5/fts5_tcl.c b/ext/fts5/fts5_tcl.c index 853a41865e..c5b5f41f83 100644 --- a/ext/fts5/fts5_tcl.c +++ b/ext/fts5/fts5_tcl.c @@ -1169,7 +1169,7 @@ struct OriginTextTokenizer { */ static void f5tOrigintextTokenizerDelete(void *pCtx){ OriginTextCtx *p = (OriginTextCtx*)pCtx; - ckfree(p); + ckfree((char*)p); } static int f5tOrigintextCreate( diff --git a/ext/recover/test_recover.c b/ext/recover/test_recover.c index 1c333df8e0..ba8ef6da11 100644 --- a/ext/recover/test_recover.c +++ b/ext/recover/test_recover.c @@ -236,7 +236,7 @@ static int test_sqlite3_recover_init( zDb = Tcl_GetString(objv[2]); if( zDb[0]=='\0' ) zDb = 0; - pNew = ckalloc(sizeof(TestRecover)); + pNew = (TestRecover*)ckalloc(sizeof(TestRecover)); if( bSql==0 ){ zUri = Tcl_GetString(objv[3]); pNew->p = sqlite3_recover_init(db, zDb, zUri); diff --git a/manifest b/manifest index df44228dfa..58e123f71a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Following\sa\sROLLBACK\sthat\sreverts\schanges\sto\san\sRTREE,\sany\spending\squeries\nagainst\sthat\ssame\sRTREE\sabort\swith\scode\sSQLITE_ABORT_ROLLBACK.\ndbsqlfuzz\sde7d17b72d0e842352c998dd86a47b7d0f707be9. -D 2024-02-03T19:19:18.306 +C Fix\sharmless\scompiler\swarnings\sseen\swith\sMSVC. +D 2024-02-04T04:01:11.343 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -51,7 +51,7 @@ F ext/README.md fd5f78013b0a2bc6f0067afb19e6ad040e89a10179b4f6f03eee58fac5f169bd F ext/async/README.txt e12275968f6fde133a80e04387d0e839b0c51f91 F ext/async/sqlite3async.c 6f247666b495c477628dd19364d279c78ea48cd90c72d9f9b98ad1aff3294f94 F ext/async/sqlite3async.h 46b47c79357b97ad85d20d2795942c0020dc20c532114a49808287f04aa5309a -F ext/consio/console_io.c e1be639e79e54264b3ae97ca291728987a9aa82e6a4526458e6400f5e083e524 x +F ext/consio/console_io.c f32b757c9ee7fdf68e7586bee306f8368759e7cd12febb2a6839199b1c1af395 x F ext/consio/console_io.h 0548b83d7c4b7270ad544a67f2bb90cebc519637fa39b1838df4744cf0d87646 F ext/expert/README.md b321c2762bb93c18ea102d5a5f7753a4b8bac646cb392b3b437f633caf2020c3 F ext/expert/expert.c d548d603a4cc9e61f446cc179c120c6713511c413f82a4a32b1e1e69d3f086a4 @@ -100,7 +100,7 @@ F ext/fts5/fts5_hash.c adda4272be401566a6e0ba1acbe70ee5cb97fce944bc2e04dc707152a F ext/fts5/fts5_index.c bb1965c3965f6fe5f64160bf1c0694a9684a790a783f293a76da1d38d319b258 F ext/fts5/fts5_main.c d68bd9533d5a638b7f6fae61c3cb0a15257dcdcccedaf3d0b3c9f55940c85048 F ext/fts5/fts5_storage.c f9e31b0d155e9b2c92d5d3a09ad7a56b937fbf1c7f962e10f4ca6281349f3934 -F ext/fts5/fts5_tcl.c cf0fd0dbe64ec272491b749e0d594f563cda03336aeb60900129e6d18b0aefb8 +F ext/fts5/fts5_tcl.c fdf7e2bb9a9186cfcaf2d2ce11d338309342b7a7593c2812bc54455db53da5d2 F ext/fts5/fts5_test_mi.c 08c11ec968148d4cb4119d96d819f8c1f329812c568bac3684f5464be177d3ee F ext/fts5/fts5_test_tok.c 3cb0a9b508b30d17ef025ccddd26ae3dc8ddffbe76c057616e59a9aa85d36f3b F ext/fts5/fts5_tokenize.c 83cfcede3898001cab84432a36ce1503e3080cf9b1c682b022ec82e267ea4c13 @@ -483,7 +483,7 @@ F ext/recover/recoverslowidx.test 5205a9742dd9490ee99950dabb622307355ef1662dea6a F ext/recover/recoversql.test e66d01f95302a223bcd3fd42b5ee58dc2b53d70afa90b0d00e41e4b8eab20486 F ext/recover/sqlite3recover.c e6eb20c469bcdb96f297f2241860bccabf9f036bfa7f3d47bcc6ca1191b108dc F ext/recover/sqlite3recover.h 011c799f02deb70ab685916f6f538e6bb32c4e0025e79bfd0e24ff9c74820959 -F ext/recover/test_recover.c 1a34e2d04533d919a30ae4d5caeb1643f6684e9ccd7597ca27721d8af81f4ade +F ext/recover/test_recover.c fd871a40f2238022bedcbdf3cb493b91225edaa94d6ae8892af97a10e7ccc4ba F ext/repair/README.md 92f5e8aae749a4dae14f02eea8e1bb42d4db2b6ce5e83dbcdd6b1446997e0c15 F ext/repair/checkfreelist.c e21f06995ff4efdc1622dcceaea4dcba2caa83ca2f31a1607b98a8509168a996 F ext/repair/checkindex.c af5c66463f51462d8a6f796b2c44ef8cfa1116bbdc35a15da07c67a705388bfd @@ -699,7 +699,7 @@ F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 F src/insert.c 3f0a94082d978bbdd33c38fefea15346c6c6bffb70bc645a71dc0f1f87dd3276 -F src/json.c e4e5f70b602c1dc9592b798166697bedeb84c61ffe857c9302ded54d5024603d +F src/json.c ae8847ccf8e212650d8a79277750f2123a03ae040d21d96ff5010114bd5b1040 F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 F src/main.c 438b95162acfa17b7d218f586f5bde11d6ae82bcf030c9611fc537556870ad6b @@ -2073,7 +2073,7 @@ F tool/genfkey.test b6afd7b825d797a1e1274f519ab5695373552ecad5cd373530c63533638a F tool/getlock.c f4c39b651370156cae979501a7b156bdba50e7ce F tool/index_usage.c f62a0c701b2c7ff2f3e21d206f093c123f222dbf07136a10ffd1ca15a5c706c5 F tool/kvtest-speed.sh 4761a9c4b3530907562314d7757995787f7aef8f -F tool/lemon.c db6c77d899f565ab42217d924e5daee5b267724433c7747fb6d3329b3c919fa1 +F tool/lemon.c 7f264d5d06450f929a20fa63a1b7e8f2df47dfaa6d7f80e4afef3639157497a4 F tool/lempar.c e6b649778e5c027c8365ff01d7ef39297cd7285fa1f881cce31792689541e79f F tool/libvers.c caafc3b689638a1d88d44bc5f526c2278760d9b9 F tool/loadfts.c c3c64e4d5e90e8ba41159232c2189dba4be7b862 @@ -2162,8 +2162,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 3838332cffb87f77a7c6b357066a59b9dc4f65ef4b3496767ad7ad7c14a77be2 -R 11b673cea59b4f2c437d0cc603cd3823 -U drh -Z 6e995078df88af9da02ef42e8af5819d +P af5c425114f32c2f84aea20edd4fa46eb1bfdeb3747fce357540e15978a070c8 +R a9037c628a989a39c2fbbc040b232de2 +U mistachkin +Z 153e5721794f58c625079135ecdb0115 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 11d5e14d8d..e1dca3b4f3 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -af5c425114f32c2f84aea20edd4fa46eb1bfdeb3747fce357540e15978a070c8 \ No newline at end of file +e52c87420b072fa68d921eda66069542d50accbfaf1110ac4cc1543a4162200d \ No newline at end of file diff --git a/src/json.c b/src/json.c index 47b83f1815..c50ded3135 100644 --- a/src/json.c +++ b/src/json.c @@ -3526,10 +3526,10 @@ static void jsonDebugPrintBlob( if( sz==0 && x<=JSONB_FALSE ){ sqlite3_str_append(pOut, "\n", 1); }else{ - u32 i; + u32 j; sqlite3_str_appendall(pOut, ": \""); - for(i=iStart+n; iaBlob[i]; + for(j=iStart+n; jaBlob[j]; if( c<0x20 || c>=0x7f ) c = '.'; sqlite3_str_append(pOut, (char*)&c, 1); } diff --git a/tool/lemon.c b/tool/lemon.c index 5b1702f4ee..0239b2d86f 100644 --- a/tool/lemon.c +++ b/tool/lemon.c @@ -4806,7 +4806,7 @@ void ReportTable( /* Generate the table of fallback tokens. */ if( lemp->has_fallback ){ - int mx = lemp->nterminal - 1; + mx = lemp->nterminal - 1; /* 2019-08-28: Generate fallback entries for every token to avoid ** having to do a range check on the index */ /* while( mx>0 && lemp->symbols[mx]->fallback==0 ){ mx--; } */ From 7718c866e156a99320c829475ff3c29ca4b4dada Mon Sep 17 00:00:00 2001 From: mistachkin Date: Sun, 4 Feb 2024 04:18:29 +0000 Subject: [PATCH 079/430] Fix a minor test file locking issue on Windows. FossilOrigin-Name: 6cd70b71df5c0d45412081590316bced302ec4403d565250b56e611882204821 --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/memdb1.test | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 58e123f71a..09817ef57c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sharmless\scompiler\swarnings\sseen\swith\sMSVC. -D 2024-02-04T04:01:11.343 +C Fix\sa\sminor\stest\sfile\slocking\sissue\son\sWindows. +D 2024-02-04T04:18:29.898 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -1398,7 +1398,7 @@ F test/malloctraceviewer.tcl 3e3ddf11e30d2b20f53aa16aa6615082fb24a100bea61cca721 F test/manydb.test 28385ae2087967aa05c38624cec7d96ec74feb3e F test/mem5.test c6460fba403c5703141348cd90de1c294188c68f F test/memdb.test c1f2a343ad14398d5d6debda6ea33e80d0dafcc7 -F test/memdb1.test cd6b6b1632cf2f76c8a6f35be013f4011f3ab2c8d74d3d1424576f29bfa4a9a1 +F test/memdb1.test 2fb27d5dadd4e7784d2229e570f6368b059fc0b7fe88ca25e46e17150ba8ad4c F test/memdb2.test 4ba1fc09e2f51df80d148a540e4a3fa66d0462e91167b27497084de4d1f6b5b4 F test/memjournal.test 70f3a00c7f84ee2978ad14e831231caa1e7f23915a2c54b4f775a021d5740c6c F test/memjournal2.test dbc2c5cb5f7b38950f4f6dc3e73fcecf0fcbed3fc32c7ce913bba164d288da1e @@ -2162,8 +2162,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P af5c425114f32c2f84aea20edd4fa46eb1bfdeb3747fce357540e15978a070c8 -R a9037c628a989a39c2fbbc040b232de2 +P e52c87420b072fa68d921eda66069542d50accbfaf1110ac4cc1543a4162200d +R b26d5bf3c069446abfcc515c5650300e U mistachkin -Z 153e5721794f58c625079135ecdb0115 +Z 46cb4b90611f7a098915a0eaa15bb642 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index e1dca3b4f3..1a3e9f0d33 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e52c87420b072fa68d921eda66069542d50accbfaf1110ac4cc1543a4162200d \ No newline at end of file +6cd70b71df5c0d45412081590316bced302ec4403d565250b56e611882204821 \ No newline at end of file diff --git a/test/memdb1.test b/test/memdb1.test index e6820da4a2..3a31c8e284 100644 --- a/test/memdb1.test +++ b/test/memdb1.test @@ -84,7 +84,6 @@ do_test 152 { catchsql {INSERT INTO t1 VALUES(3,4);} } {1 {attempt to write a readonly database}} -breakpoint do_test 160 { db deserialize -maxsize 32768 $db1 db eval {SELECT * FROM t1} @@ -248,6 +247,7 @@ if {[wal_is_capable]} { set fd [open test.db] fconfigure $fd -translation binary -encoding binary set data [read $fd [expr 20*1024]] + close $fd sqlite3 db "" db deserialize $data From 0009d40325bf63ede33ae74a4c653e25ac95d0e3 Mon Sep 17 00:00:00 2001 From: stephan Date: Mon, 5 Feb 2024 02:36:10 +0000 Subject: [PATCH 080/430] wasm: squelch a new (and, in our case, invalid) warning from emcc 3.1.52. FossilOrigin-Name: d294a23ed6d1d2b567a02552b8a2e4921cd21891ee86e63f8f9945569e3262d3 --- ext/wasm/GNUmakefile | 3 +++ manifest | 14 +++++++------- manifest.uuid | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/ext/wasm/GNUmakefile b/ext/wasm/GNUmakefile index 0865492cf5..226010ba8f 100644 --- a/ext/wasm/GNUmakefile +++ b/ext/wasm/GNUmakefile @@ -981,6 +981,9 @@ emcc.speedtest1.common += -sABORTING_MALLOC emcc.speedtest1.common += -sSTRICT_JS=0 emcc.speedtest1.common += -sMODULARIZE emcc.speedtest1.common += -Wno-limited-postlink-optimizations +emcc.speedtest1 += -Wno-unused-main +# ^^^^ -Wno-unused-main is for emcc 3.1.52+. speedtest1 has a wasm_main() which is +# exported and called by the JS code. EXPORTED_FUNCTIONS.speedtest1 := $(abspath $(dir.tmp)/EXPORTED_FUNCTIONS.speedtest1) emcc.speedtest1.common += -sSTACK_SIZE=512KB emcc.speedtest1.common += -sEXPORTED_FUNCTIONS=@$(EXPORTED_FUNCTIONS.speedtest1) diff --git a/manifest b/manifest index 09817ef57c..a67cb1e328 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sminor\stest\sfile\slocking\sissue\son\sWindows. -D 2024-02-04T04:18:29.898 +C wasm:\ssquelch\sa\snew\s(and,\sin\sour\scase,\sinvalid)\swarning\sfrom\semcc\s3.1.52. +D 2024-02-05T02:36:10.589 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -576,7 +576,7 @@ F ext/userauth/sqlite3userauth.h 7f3ea8c4686db8e40b0a0e7a8e0b00fac13aa7a3 F ext/userauth/user-auth.txt ca7e9ee82ca4e1c1744295f8184dd70edfae1992865d26c64303f539eb6c084c F ext/userauth/userauth.c 7f00cded7dcaa5d47f54539b290a43d2e59f4b1eb5f447545fa865f002fc80cb F ext/wasm/EXPORTED_FUNCTIONS.fiddle.in 27450c8b8c70875a260aca55435ec927068b34cef801a96205adb81bdcefc65c -F ext/wasm/GNUmakefile 867c903a27fa0d53a3bf1b01d8c7bb713456f87e0939c3cac9f07faa68f58734 +F ext/wasm/GNUmakefile a0de0b77d6e75c819c25999e738a7505e2c41ac3d8d283c8d1b55053690702ce F ext/wasm/README-dist.txt 6382cb9548076fca472fb3330bbdba3a55c1ea0b180ff9253f084f07ff383576 F ext/wasm/README.md a8a2962c3aebdf8d2104a9102e336c5554e78fc6072746e5daf9c61514e7d193 F ext/wasm/SQLTester/GNUmakefile e0794f676d55819951bbfae45cc5e8d7818dc460492dc317ce7f0d2eca15caff @@ -2162,8 +2162,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P e52c87420b072fa68d921eda66069542d50accbfaf1110ac4cc1543a4162200d -R b26d5bf3c069446abfcc515c5650300e -U mistachkin -Z 46cb4b90611f7a098915a0eaa15bb642 +P 6cd70b71df5c0d45412081590316bced302ec4403d565250b56e611882204821 +R 0ab4464af386acb25db258a324b067da +U stephan +Z c0b47723711993434189903dacb2adb6 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 1a3e9f0d33..441b22d3e8 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6cd70b71df5c0d45412081590316bced302ec4403d565250b56e611882204821 \ No newline at end of file +d294a23ed6d1d2b567a02552b8a2e4921cd21891ee86e63f8f9945569e3262d3 \ No newline at end of file From 7d3cd38034fc9cd8c322900287bf11d7bdd79f6e Mon Sep 17 00:00:00 2001 From: stephan Date: Mon, 5 Feb 2024 03:37:54 +0000 Subject: [PATCH 081/430] wasm: pass the promiser function to the promiser onready() callback to simplify access to it in certain usage patterns. FossilOrigin-Name: f8a8b9ee2eddf5f875c7c4399e750ccf1941f767560ebc2c88c083560f5aaae0 --- ext/wasm/api/sqlite3-worker1-promiser.c-pp.js | 5 +++-- ext/wasm/demo-worker1-promiser.js | 2 ++ manifest | 14 +++++++------- manifest.uuid | 2 +- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/ext/wasm/api/sqlite3-worker1-promiser.c-pp.js b/ext/wasm/api/sqlite3-worker1-promiser.c-pp.js index cd78ed4bcf..68846209e5 100644 --- a/ext/wasm/api/sqlite3-worker1-promiser.c-pp.js +++ b/ext/wasm/api/sqlite3-worker1-promiser.c-pp.js @@ -156,6 +156,7 @@ globalThis.sqlite3Worker1Promiser = function callee(config = callee.defaultConfi if(!config.worker) config.worker = callee.defaultConfig.worker; if('function'===typeof config.worker) config.worker = config.worker(); let dbId; + let promiserFunc; config.worker.onmessage = function(ev){ ev = ev.data; debug('worker1.onmessage',ev); @@ -163,7 +164,7 @@ globalThis.sqlite3Worker1Promiser = function callee(config = callee.defaultConfi if(!msgHandler){ if(ev && 'sqlite3-api'===ev.type && 'worker1-ready'===ev.result) { /*fired one time when the Worker1 API initializes*/ - if(config.onready) config.onready(); + if(config.onready) config.onready(promiserFunc); return; } msgHandler = handlerMap[ev.type] /* check for exec per-row callback */; @@ -192,7 +193,7 @@ globalThis.sqlite3Worker1Promiser = function callee(config = callee.defaultConfi try {msgHandler.resolve(ev)} catch(e){msgHandler.reject(e)} }/*worker.onmessage()*/; - return function(/*(msgType, msgArgs) || (msgEnvelope)*/){ + return promiserFunc = function(/*(msgType, msgArgs) || (msgEnvelope)*/){ let msg; if(1===arguments.length){ msg = arguments[0]; diff --git a/ext/wasm/demo-worker1-promiser.js b/ext/wasm/demo-worker1-promiser.js index c2d24623a3..4327f7487d 100644 --- a/ext/wasm/demo-worker1-promiser.js +++ b/ext/wasm/demo-worker1-promiser.js @@ -49,6 +49,8 @@ error("Unhandled worker message:",ev.data); }, onready: function(){ + T.affirm(arguments[0] === workerPromise + /* as of version 3.46. Prior to that this callback had no arguments */); self.sqlite3TestModule.setStatus(null)/*hide the HTML-side is-loading spinner*/; runTests(); }, diff --git a/manifest b/manifest index a67cb1e328..484160968f 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C wasm:\ssquelch\sa\snew\s(and,\sin\sour\scase,\sinvalid)\swarning\sfrom\semcc\s3.1.52. -D 2024-02-05T02:36:10.589 +C wasm:\spass\sthe\spromiser\sfunction\sto\sthe\spromiser\sonready()\scallback\sto\ssimplify\saccess\sto\sit\sin\scertain\susage\spatterns. +D 2024-02-05T03:37:54.834 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -605,7 +605,7 @@ F ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js 595953994aa3ae2287c889c4da39ab3d F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js ebf6c7e997cd8948b35b3afc550b0503dd53febd9d2b56354efd11d985e5f0f2 F ext/wasm/api/sqlite3-vtab-helper.c-pp.js a2fcbc3fecdd0eea229283584ebc122f29d98194083675dbe5cb2cf3a17fe309 F ext/wasm/api/sqlite3-wasm.c d33a16495ca871781e78812d3a18fed78b797468fffee657b8d7199b277ff359 -F ext/wasm/api/sqlite3-worker1-promiser.c-pp.js f234191fe6bf41a5a1e59c9f43ed816e74a522b3d60d3f556f66c3085c448503 +F ext/wasm/api/sqlite3-worker1-promiser.c-pp.js e8135b44a568badfe197e2379f6b42899f2240b5c3a77fa044331110f7ce8e50 F ext/wasm/api/sqlite3-worker1.c-pp.js 5e8706c2c4af2a57fbcdc02f4e7ef79869971bc21bb8ede777687786ce1c92d5 F ext/wasm/batch-runner-sahpool.html e9a38fdeb36a13eac7b50241dfe7ae066fe3f51f5c0b0151e7baee5fce0d07a7 F ext/wasm/batch-runner-sahpool.js 54a3ac228e6c4703fe72fb65c897e19156263a51fe9b7e21d2834a45e876aabd @@ -622,7 +622,7 @@ F ext/wasm/demo-123.js c7b3cca50c55841c381a9ca4f9396e5bbdc6114273d0b10a43e378e32 F ext/wasm/demo-jsstorage.html 409c4be4af5f207fb2877160724b91b33ea36a3cd8c204e8da1acb828ffe588e F ext/wasm/demo-jsstorage.js 44e3ae7ec2483b6c511384c3c290beb6f305c721186bcf5398ca4e00004a06b8 F ext/wasm/demo-worker1-promiser.html 1de7c248c7c2cfd4a5783d2aa154bce62d74c6de98ab22f5786620b3354ed15f -F ext/wasm/demo-worker1-promiser.js 5e5c7d7c91cd7aae9cc733afd02569ba9c6928292db413b550e8b842f4b75e87 +F ext/wasm/demo-worker1-promiser.js 786ae8a3214c2a29f6fb2c80eb4f90cc401fcc5b524d95c35fdc66a454e32bad F ext/wasm/demo-worker1.html 2c178c1890a2beb5a5fecb1453e796d067a4b8d3d2a04d65ca2eb1ab2c68ef5d F ext/wasm/demo-worker1.js 836bece8615b17b1b572584f7b15912236a5947fe8c68b98d2737d7e287447ef F ext/wasm/dist.make 3a851858aad72e246a5d9c5aaf6b6a144305f1bf898ac1846760ea7bab95c9a3 @@ -2162,8 +2162,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 6cd70b71df5c0d45412081590316bced302ec4403d565250b56e611882204821 -R 0ab4464af386acb25db258a324b067da +P d294a23ed6d1d2b567a02552b8a2e4921cd21891ee86e63f8f9945569e3262d3 +R d80b32c2d930bb7fce3089d7ed46767b U stephan -Z c0b47723711993434189903dacb2adb6 +Z 14a50a83c75676e662aa799b27f4eeff # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 441b22d3e8..e1a1e2a3b3 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d294a23ed6d1d2b567a02552b8a2e4921cd21891ee86e63f8f9945569e3262d3 \ No newline at end of file +f8a8b9ee2eddf5f875c7c4399e750ccf1941f767560ebc2c88c083560f5aaae0 \ No newline at end of file From 21ded98df5182fce4c20eb0338f4c92db529cadd Mon Sep 17 00:00:00 2001 From: stephan Date: Mon, 5 Feb 2024 03:56:02 +0000 Subject: [PATCH 082/430] Extend [d294a23ed6d] to apply to all wasm speedtest1 builds. FossilOrigin-Name: 26f848e5e0ac34e545d2f27cf33abc46eac13e04ed9cd71084b0f7d47136ff97 --- ext/wasm/GNUmakefile | 2 +- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ext/wasm/GNUmakefile b/ext/wasm/GNUmakefile index 226010ba8f..75fc785182 100644 --- a/ext/wasm/GNUmakefile +++ b/ext/wasm/GNUmakefile @@ -981,7 +981,7 @@ emcc.speedtest1.common += -sABORTING_MALLOC emcc.speedtest1.common += -sSTRICT_JS=0 emcc.speedtest1.common += -sMODULARIZE emcc.speedtest1.common += -Wno-limited-postlink-optimizations -emcc.speedtest1 += -Wno-unused-main +emcc.speedtest1.common += -Wno-unused-main # ^^^^ -Wno-unused-main is for emcc 3.1.52+. speedtest1 has a wasm_main() which is # exported and called by the JS code. EXPORTED_FUNCTIONS.speedtest1 := $(abspath $(dir.tmp)/EXPORTED_FUNCTIONS.speedtest1) diff --git a/manifest b/manifest index 484160968f..ff359ab048 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C wasm:\spass\sthe\spromiser\sfunction\sto\sthe\spromiser\sonready()\scallback\sto\ssimplify\saccess\sto\sit\sin\scertain\susage\spatterns. -D 2024-02-05T03:37:54.834 +C Extend\s[d294a23ed6d]\sto\sapply\sto\sall\swasm\sspeedtest1\sbuilds. +D 2024-02-05T03:56:02.476 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -576,7 +576,7 @@ F ext/userauth/sqlite3userauth.h 7f3ea8c4686db8e40b0a0e7a8e0b00fac13aa7a3 F ext/userauth/user-auth.txt ca7e9ee82ca4e1c1744295f8184dd70edfae1992865d26c64303f539eb6c084c F ext/userauth/userauth.c 7f00cded7dcaa5d47f54539b290a43d2e59f4b1eb5f447545fa865f002fc80cb F ext/wasm/EXPORTED_FUNCTIONS.fiddle.in 27450c8b8c70875a260aca55435ec927068b34cef801a96205adb81bdcefc65c -F ext/wasm/GNUmakefile a0de0b77d6e75c819c25999e738a7505e2c41ac3d8d283c8d1b55053690702ce +F ext/wasm/GNUmakefile 316349101671037a30311fbb40bd0b8702d9a223b5205a6a5eae8bac7b8dc1a0 F ext/wasm/README-dist.txt 6382cb9548076fca472fb3330bbdba3a55c1ea0b180ff9253f084f07ff383576 F ext/wasm/README.md a8a2962c3aebdf8d2104a9102e336c5554e78fc6072746e5daf9c61514e7d193 F ext/wasm/SQLTester/GNUmakefile e0794f676d55819951bbfae45cc5e8d7818dc460492dc317ce7f0d2eca15caff @@ -2162,8 +2162,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P d294a23ed6d1d2b567a02552b8a2e4921cd21891ee86e63f8f9945569e3262d3 -R d80b32c2d930bb7fce3089d7ed46767b +P f8a8b9ee2eddf5f875c7c4399e750ccf1941f767560ebc2c88c083560f5aaae0 +R 8054a7da52bc11a97b67caaa9fc96227 U stephan -Z 14a50a83c75676e662aa799b27f4eeff +Z 47b7f55b1ab54c273898a455c5270730 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index e1a1e2a3b3..16ae9edaa3 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f8a8b9ee2eddf5f875c7c4399e750ccf1941f767560ebc2c88c083560f5aaae0 \ No newline at end of file +26f848e5e0ac34e545d2f27cf33abc46eac13e04ed9cd71084b0f7d47136ff97 \ No newline at end of file From 8e4d004ba197a17da4780bc140a780c8b297abec Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 5 Feb 2024 17:35:36 +0000 Subject: [PATCH 083/430] Return SQLITE_ABORT if the underlying shadow tables change in the middle of an rtree query in such a way as to invalidate an rtree internal priority queue entry. FossilOrigin-Name: 478280ef67efed854988ab4f740a38ae1937204c0434ad8da11f1869a12a6d06 --- ext/rtree/rtree.c | 23 +++------ ext/rtree/rtreeJ.test | 117 +++++++++++++++++++++++++++++++++++++++++- manifest | 19 ++++--- manifest.uuid | 2 +- 4 files changed, 135 insertions(+), 26 deletions(-) diff --git a/ext/rtree/rtree.c b/ext/rtree/rtree.c index 93a849cf0f..3b26878c9e 100644 --- a/ext/rtree/rtree.c +++ b/ext/rtree/rtree.c @@ -170,7 +170,6 @@ struct Rtree { u32 nBusy; /* Current number of users of this structure */ i64 nRowEst; /* Estimated number of rows in this table */ u32 nCursor; /* Number of open cursors */ - u32 iGeneration; /* Cursors with smaller iGeneration are stale */ u32 nNodeRef; /* Number RtreeNodes with positive nRef */ char *zReadAuxSql; /* SQL for statement to read aux data */ @@ -287,7 +286,6 @@ struct RtreeCursor { u8 atEOF; /* True if at end of search */ u8 bPoint; /* True if sPoint is valid */ u8 bAuxValid; /* True if pReadAux is valid */ - u32 iGeneration; /* Stale if too small */ int iStrategy; /* Copy of idxNum search parameter */ int nConstraint; /* Number of entries in aConstraint */ RtreeConstraint *aConstraint; /* Search constraints. */ @@ -948,6 +946,7 @@ static void nodeGetCoord( int iCoord, /* Which coordinate to extract */ RtreeCoord *pCoord /* OUT: Space to write result to */ ){ + assert( iCellzData[12 + pRtree->nBytesPerCell*iCell + 4*iCoord], pCoord); } @@ -1089,7 +1088,6 @@ static int rtreeOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){ if( pCsr ){ memset(pCsr, 0, sizeof(RtreeCursor)); pCsr->base.pVtab = pVTab; - pCsr->iGeneration = pRtree->iGeneration; rc = SQLITE_OK; pRtree->nCursor++; } @@ -1630,9 +1628,6 @@ static int rtreeStepToLeaf(RtreeCursor *pCur){ int eInt; RtreeSearchPoint x; - if( pCur->iGenerationiGeneration ){ - return SQLITE_ABORT_ROLLBACK; - } eInt = pRtree->eCoordType==RTREE_COORD_INT32; while( (p = rtreeSearchPointFirst(pCur))!=0 && p->iLevel>0 ){ u8 *pCellData; @@ -1726,7 +1721,11 @@ static int rtreeRowid(sqlite3_vtab_cursor *pVtabCursor, sqlite_int64 *pRowid){ int rc = SQLITE_OK; RtreeNode *pNode = rtreeNodeOfFirstSearchPoint(pCsr, &rc); if( rc==SQLITE_OK && ALWAYS(p) ){ - *pRowid = nodeGetRowid(RTREE_OF_CURSOR(pCsr), pNode, p->iCell); + if( p->iCell>=NCELL(pNode) ){ + rc = SQLITE_ABORT; + }else{ + *pRowid = nodeGetRowid(RTREE_OF_CURSOR(pCsr), pNode, p->iCell); + } } return rc; } @@ -1744,6 +1743,7 @@ static int rtreeColumn(sqlite3_vtab_cursor *cur, sqlite3_context *ctx, int i){ if( rc ) return rc; if( NEVER(p==0) ) return SQLITE_OK; + if( p->iCell>=NCELL(pNode) ) return SQLITE_ABORT; if( i==0 ){ sqlite3_result_int64(ctx, nodeGetRowid(pRtree, pNode, p->iCell)); }else if( i<=pRtree->nDim2 ){ @@ -1860,7 +1860,6 @@ static int rtreeFilter( /* Reset the cursor to the same state as rtreeOpen() leaves it in. */ resetCursor(pCsr); - pCsr->iGeneration = pRtree->iGeneration; pCsr->iStrategy = idxNum; if( idxNum==1 ){ @@ -3243,14 +3242,8 @@ static int rtreeEndTransaction(sqlite3_vtab *pVtab){ } static int rtreeRollback(sqlite3_vtab *pVtab){ Rtree *pRtree = (Rtree *)pVtab; - pRtree->iGeneration++; return rtreeEndTransaction(pVtab); } -static int rtreeRollbackTo(sqlite3_vtab *pVtab, int notUsed){ - Rtree *pRtree = (Rtree *)pVtab; - pRtree->iGeneration++; - return SQLITE_OK; -} /* ** The xRename method for rtree module virtual tables. @@ -3374,7 +3367,7 @@ static sqlite3_module rtreeModule = { rtreeRename, /* xRename - rename the table */ rtreeSavepoint, /* xSavepoint */ 0, /* xRelease */ - rtreeRollbackTo, /* xRollbackTo */ + 0, /* xRollbackTo */ rtreeShadowName, /* xShadowName */ rtreeIntegrity /* xIntegrity */ }; diff --git a/ext/rtree/rtreeJ.test b/ext/rtree/rtreeJ.test index 4d9c01d29b..cff77857c7 100644 --- a/ext/rtree/rtreeJ.test +++ b/ext/rtree/rtreeJ.test @@ -44,7 +44,7 @@ do_test 1.2 { } } msg] list $rc $msg -} {1 {abort due to ROLLBACK}} +} {1 {query aborted}} do_execsql_test 1.3 { SELECT * FROM t1; @@ -118,7 +118,7 @@ do_test 1.8 { } } msg] list $rc $msg -} {1 {abort due to ROLLBACK}} +} {1 {query aborted}} do_execsql_test 1.9 { COMMIT; @@ -156,4 +156,117 @@ do_execsql_test 1.12 { SELECT * FROM t1; } {1 1.0 1.0 2 2.0 2.0 3 3.0 3.0} +#---------------------------------------------------------------------- + +reset_db +do_execsql_test 2.0 { + CREATE VIRTUAL TABLE t1 USING rtree(id, x1, x2); + INSERT INTO t1 VALUES(1, 1, 1), (2, 2, 2); + CREATE TABLE t2(x); +} {} + +do_test 2.1 { + db eval { + BEGIN; + INSERT INTO t1 VALUES(3, 3, 3); + PRAGMA writable_schema = RESET; + } + + set rc [catch { + db eval { SELECT x1, x2 FROM t1 } { + if {$x1==1} { + db eval { ROLLBACK } + } + lappend res $x1 $x2 + } + } msg] + list $rc $msg +} {1 {query aborted}} + +do_execsql_test 2.1 { + CREATE TABLE bak_node(nodeno, data); + CREATE TABLE bak_parent(nodeno, parentnode); + CREATE TABLE bak_rowid(rowid, nodeno); +} +proc save_t1 {} { + db eval { + DELETE FROM bak_node; + DELETE FROM bak_parent; + DELETE FROM bak_rowid; + INSERT INTO bak_node SELECT * FROM t1_node; + INSERT INTO bak_parent SELECT * FROM t1_parent; + INSERT INTO bak_rowid SELECT * FROM t1_rowid; + } +} +proc restore_t1 {} { + db eval { + DELETE FROM t1_node; + DELETE FROM t1_parent; + DELETE FROM t1_rowid; + INSERT INTO t1_node SELECT * FROM bak_node; + INSERT INTO t1_parent SELECT * FROM bak_parent; + INSERT INTO t1_rowid SELECT * FROM bak_rowid; + } +} + +do_test 2.3 { + save_t1 + db eval { + INSERT INTO t1 VALUES(3, 3, 3); + } + set rc [catch { + db eval { SELECT rowid, x1, x2 FROM t1 } { + if {$x1==1} { + restore_t1 + } + lappend res $x1 $x2 + } + } msg] + list $rc $msg +} {1 {query aborted}} +do_execsql_test 2.4 { + SELECT * FROM t1 +} {1 1.0 1.0 2 2.0 2.0} + +do_test 2.5 { + save_t1 + db eval { + INSERT INTO t1 VALUES(3, 3, 3); + } + set rc [catch { + db eval { SELECT x1 FROM t1 } { + if {$x1==1} { + restore_t1 + } + lappend res $x1 $x2 + } + } msg] + list $rc $msg +} {1 {query aborted}} +do_execsql_test 2.6 { + SELECT * FROM t1 +} {1 1.0 1.0 2 2.0 2.0} + +do_test 2.7 { + save_t1 + db eval { + INSERT INTO t1 VALUES(3, 3, 3); + } + set ::res [list] + set rc [catch { + db eval { SELECT 'abc' FROM t1 } { + if {$::res==[list]} { + restore_t1 + set ::bDone 1 + } + lappend res abc + } + } msg] + set res +} {abc abc abc} +do_execsql_test 2.6 { + SELECT * FROM t1 +} {1 1.0 1.0 2 2.0 2.0} + + finish_test diff --git a/manifest b/manifest index ff359ab048..b07bcfff0d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Extend\s[d294a23ed6d]\sto\sapply\sto\sall\swasm\sspeedtest1\sbuilds. -D 2024-02-05T03:56:02.476 +C Return\sSQLITE_ABORT\sif\sthe\sunderlying\sshadow\stables\schange\sin\sthe\smiddle\sof\san\srtree\squery\sin\ssuch\sa\sway\sas\sto\sinvalidate\san\srtree\sinternal\spriority\squeue\sentry. +D 2024-02-05T17:35:36.153 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -495,7 +495,7 @@ F ext/repair/test/checkindex01.test b530f141413b587c9eb78ff734de6bb79bc3515c3350 F ext/repair/test/test.tcl 686d76d888dffd021f64260abf29a55c57b2cedfa7fc69150b42b1d6119aac3c F ext/rtree/README 6315c0d73ebf0ec40dedb5aa0e942bc8b54e3761 F ext/rtree/geopoly.c 0dd4775e896cee6067979d67aff7c998e75c2c9d9cd8d62a1a790c09cde7adca -F ext/rtree/rtree.c 32e67b122e37138694d9f499cdc72241e372058560ac2d4577cfd68ccd692953 +F ext/rtree/rtree.c d96c5d34eafcd46bc4b7645c26a4bcc3169d9e70e9df707ef91c2e90870d00d9 F ext/rtree/rtree.h 4a690463901cb5e6127cf05eb8e642f127012fd5003830dbc974eca5802d9412 F ext/rtree/rtree1.test 2b5b8c719c6a4abe377f57766f428a49af36a93061cb146cccfdc3b30000c0a4 F ext/rtree/rtree2.test 9d9deddbb16fd0c30c36e6b4fdc3ee3132d765567f0f9432ee71e1303d32603d @@ -515,7 +515,7 @@ F ext/rtree/rtreeF.test 81ffa7ef51c4e4618d497a57328c265bf576990c7070633b623b23cd F ext/rtree/rtreeG.test 1b9ca6e3effb48f4161edaa463ddeaa8fca4b2526d084f9cbf5dbe4e0184939c F ext/rtree/rtreeH.test 0885151ee8429242625600ae47142cca935332c70a06737f35af53a7bd7aaf90 F ext/rtree/rtreeI.test 608e77f7fde9be5a12eae316baef640fffaafcfa90a3d67443e78123e19c4ca4 -F ext/rtree/rtreeJ.test bafa7616d6b29448bf19132ce4963a69b629b9ca6ab29f4b76889c8d542b8dfc +F ext/rtree/rtreeJ.test ba4e25c409ebed4b96bf1270e72760c1344d0a464478d221dbe91e8471ac9ac6 F ext/rtree/rtree_perf.tcl 6c18c1f23cd48e0f948930c98dfdd37dfccb5195 F ext/rtree/rtree_util.tcl 202ca70df1f0645ef9d5a2170e62d378a28098d9407f0569e85c9c1cf1bd020a F ext/rtree/rtreecheck.test 934546ad9b563e090ee0c5cbdc69ad014189ad76e5df7320526797a9a345661f @@ -2162,8 +2162,11 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P f8a8b9ee2eddf5f875c7c4399e750ccf1941f767560ebc2c88c083560f5aaae0 -R 8054a7da52bc11a97b67caaa9fc96227 -U stephan -Z 47b7f55b1ab54c273898a455c5270730 +P 26f848e5e0ac34e545d2f27cf33abc46eac13e04ed9cd71084b0f7d47136ff97 +R ac07ea666046dd35038bc77784e8d419 +T *branch * rtree-fix +T *sym-rtree-fix * +T -sym-trunk * +U dan +Z 6f11e0396699443c7473bed77f9c3651 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 16ae9edaa3..19b20648c9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -26f848e5e0ac34e545d2f27cf33abc46eac13e04ed9cd71084b0f7d47136ff97 \ No newline at end of file +478280ef67efed854988ab4f740a38ae1937204c0434ad8da11f1869a12a6d06 \ No newline at end of file From db9cc74c9ce786947c34497d778216b3acd9b373 Mon Sep 17 00:00:00 2001 From: stephan Date: Tue, 6 Feb 2024 08:25:23 +0000 Subject: [PATCH 084/430] Make explicit that using the importDb() methods of the OPFS VFSes has undefined results if the being-imported db is currently open. Doc changes only. FossilOrigin-Name: f28b9924b401b359e59a73918a34b29cde719164a6b4ac5a9d23da6294b701bd --- ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js | 5 +++-- ext/wasm/api/sqlite3-vfs-opfs.c-pp.js | 3 +++ manifest | 17 ++++++++--------- manifest.uuid | 2 +- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js b/ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js index 870073cc09..f3664fd4b8 100644 --- a/ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js +++ b/ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js @@ -1137,8 +1137,9 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ existing content. Throws if the pool has no available file slots, on I/O error, or if the input does not appear to be a database. In the latter case, only a cursory examination is made. - Note that this routine is _only_ for importing database files, - not arbitrary files, the reason being that this VFS will + Results are undefined if the given db name refers to an opened + db. Note that this routine is _only_ for importing database + files, not arbitrary files, the reason being that this VFS will automatically clean up any non-database files so importing them is pointless. diff --git a/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js b/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js index f7c92100a0..0d695e524e 100644 --- a/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js +++ b/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js @@ -1193,6 +1193,9 @@ const installOpfsVfs = function callee(options){ Asynchronously imports the given bytes (a byte array or ArrayBuffer) into the given database file. + Results are undefined if the given db name refers to an opened + db. + If passed a function for its second argument, its behaviour changes to async and it imports its data in chunks fed to it by the given callback function. It calls the callback (which may diff --git a/manifest b/manifest index 1639f718b8..c31056920d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Return\sSQLITE_ABORT\sif\sthe\sunderlying\sshadow\stables\schange\sin\sthe\smiddle\sof\san\srtree\squery\sin\ssuch\sa\sway\sas\sto\sinvalidate\san\srtree\sinternal\spriority\squeue\sentry.\sThis\sreplaces\sthe\sSQLITE_ABORT_ROLLBACK\smechanism\sadded\sin\s[af5c4251]. -D 2024-02-05T17:54:03.662 +C Make\sexplicit\sthat\susing\sthe\simportDb()\smethods\sof\sthe\sOPFS\sVFSes\shas\sundefined\sresults\sif\sthe\sbeing-imported\sdb\sis\scurrently\sopen.\sDoc\schanges\sonly. +D 2024-02-06T08:25:23.546 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -601,8 +601,8 @@ F ext/wasm/api/sqlite3-api-worker1.js 8d9c0562831f62218170a3373468d8a0b7a6503b59 F ext/wasm/api/sqlite3-license-version-header.js 0c807a421f0187e778dc1078f10d2994b915123c1223fe752b60afdcd1263f89 F ext/wasm/api/sqlite3-opfs-async-proxy.js 8cf8a897726f14071fae6be6648125162b256dfb4f96555b865dbb7a6b65e379 F ext/wasm/api/sqlite3-vfs-helper.c-pp.js 3f828cc66758acb40e9c5b4dcfd87fd478a14c8fb7f0630264e6c7fa0e57515d -F ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js 595953994aa3ae2287c889c4da39ab3d6f17b6461ecf4bec334b7a3faafddb02 -F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js ebf6c7e997cd8948b35b3afc550b0503dd53febd9d2b56354efd11d985e5f0f2 +F ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js 5a430874906ff3f4a6ca69aadf0c2aaedc1bb45489b8365bff7e955a83a8d42a +F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js 87b947b25ffa0c8f661092564c7491b8eea96964f1a5e8e530a3c67c91715e3e F ext/wasm/api/sqlite3-vtab-helper.c-pp.js a2fcbc3fecdd0eea229283584ebc122f29d98194083675dbe5cb2cf3a17fe309 F ext/wasm/api/sqlite3-wasm.c d33a16495ca871781e78812d3a18fed78b797468fffee657b8d7199b277ff359 F ext/wasm/api/sqlite3-worker1-promiser.c-pp.js e8135b44a568badfe197e2379f6b42899f2240b5c3a77fa044331110f7ce8e50 @@ -2162,9 +2162,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 26f848e5e0ac34e545d2f27cf33abc46eac13e04ed9cd71084b0f7d47136ff97 478280ef67efed854988ab4f740a38ae1937204c0434ad8da11f1869a12a6d06 -R 23677f173f1ac581895d1554488f83a5 -T +closed 478280ef67efed854988ab4f740a38ae1937204c0434ad8da11f1869a12a6d06 -U dan -Z 1c1abeb44ec4a55c053a1bd1e00c844a +P 32f85a5ce8e32506ad0cf309c86589958f38d924b4b3de532bec8bdb8e385fad +R f5c99d8b43326c6a4a8c0c192ca7fcea +U stephan +Z 3bdb798c91ad2510474753c9351d5d94 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 4f37fd460d..e16cd7286d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -32f85a5ce8e32506ad0cf309c86589958f38d924b4b3de532bec8bdb8e385fad \ No newline at end of file +f28b9924b401b359e59a73918a34b29cde719164a6b4ac5a9d23da6294b701bd \ No newline at end of file From 72c7bb3e1afd4f542eb74da834ff66092f3d972c Mon Sep 17 00:00:00 2001 From: stephan Date: Tue, 6 Feb 2024 08:59:59 +0000 Subject: [PATCH 085/430] Correct docs about the first OFPS VFS's importDb() method being synchronous (it's not, whereas the second VFS's importDb() is). FossilOrigin-Name: ae7505fa5e112f39a329befb35eff6ddf46a53f5deb610906550bf67f56fc157 --- ext/wasm/api/sqlite3-vfs-opfs.c-pp.js | 17 ++++++++--------- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js b/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js index 0d695e524e..f7fd951a40 100644 --- a/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js +++ b/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js @@ -1197,15 +1197,14 @@ const installOpfsVfs = function callee(options){ db. If passed a function for its second argument, its behaviour - changes to async and it imports its data in chunks fed to it by - the given callback function. It calls the callback (which may - be async) repeatedly, expecting either a Uint8Array or - ArrayBuffer (to denote new input) or undefined (to denote - EOF). For so long as the callback continues to return - non-undefined, it will append incoming data to the given - VFS-hosted database file. When called this way, the resolved - value of the returned Promise is the number of bytes written to - the target file. + changes: imports its data in chunks fed to it by the given + callback function. It calls the callback (which may be async) + repeatedly, expecting either a Uint8Array or ArrayBuffer (to + denote new input) or undefined (to denote EOF). For so long as + the callback continues to return non-undefined, it will append + incoming data to the given VFS-hosted database file. When + called this way, the resolved value of the returned Promise is + the number of bytes written to the target file. It very specifically requires the input to be an SQLite3 database and throws if that's not the case. It does so in diff --git a/manifest b/manifest index c31056920d..492071588e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Make\sexplicit\sthat\susing\sthe\simportDb()\smethods\sof\sthe\sOPFS\sVFSes\shas\sundefined\sresults\sif\sthe\sbeing-imported\sdb\sis\scurrently\sopen.\sDoc\schanges\sonly. -D 2024-02-06T08:25:23.546 +C Correct\sdocs\sabout\sthe\sfirst\sOFPS\sVFS's\simportDb()\smethod\sbeing\ssynchronous\s(it's\snot,\swhereas\sthe\ssecond\sVFS's\simportDb()\sis). +D 2024-02-06T08:59:59.394 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -602,7 +602,7 @@ F ext/wasm/api/sqlite3-license-version-header.js 0c807a421f0187e778dc1078f10d299 F ext/wasm/api/sqlite3-opfs-async-proxy.js 8cf8a897726f14071fae6be6648125162b256dfb4f96555b865dbb7a6b65e379 F ext/wasm/api/sqlite3-vfs-helper.c-pp.js 3f828cc66758acb40e9c5b4dcfd87fd478a14c8fb7f0630264e6c7fa0e57515d F ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js 5a430874906ff3f4a6ca69aadf0c2aaedc1bb45489b8365bff7e955a83a8d42a -F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js 87b947b25ffa0c8f661092564c7491b8eea96964f1a5e8e530a3c67c91715e3e +F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js fe427645e1499618f5fa7bc670af850577d8bcc132df982078690c9bf8400baa F ext/wasm/api/sqlite3-vtab-helper.c-pp.js a2fcbc3fecdd0eea229283584ebc122f29d98194083675dbe5cb2cf3a17fe309 F ext/wasm/api/sqlite3-wasm.c d33a16495ca871781e78812d3a18fed78b797468fffee657b8d7199b277ff359 F ext/wasm/api/sqlite3-worker1-promiser.c-pp.js e8135b44a568badfe197e2379f6b42899f2240b5c3a77fa044331110f7ce8e50 @@ -2162,8 +2162,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 32f85a5ce8e32506ad0cf309c86589958f38d924b4b3de532bec8bdb8e385fad -R f5c99d8b43326c6a4a8c0c192ca7fcea +P f28b9924b401b359e59a73918a34b29cde719164a6b4ac5a9d23da6294b701bd +R d8475422eb55a236e4813bd575b83968 U stephan -Z 3bdb798c91ad2510474753c9351d5d94 +Z 87c60489a9bd431cc3758cc39138e437 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index e16cd7286d..71b6a414d3 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f28b9924b401b359e59a73918a34b29cde719164a6b4ac5a9d23da6294b701bd \ No newline at end of file +ae7505fa5e112f39a329befb35eff6ddf46a53f5deb610906550bf67f56fc157 \ No newline at end of file From 8babc0189224773fc41aed95ee603d056385908f Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 6 Feb 2024 18:33:01 +0000 Subject: [PATCH 086/430] Slight change to OOM handling in JSON to catch a corner case found by dbsqlfuzz. FossilOrigin-Name: 6a2b3266c586d12b51e11fe63cda5881be9373207aa16671ab77f547830eb790 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/json.c | 3 ++- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 492071588e..e10d300129 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Correct\sdocs\sabout\sthe\sfirst\sOFPS\sVFS's\simportDb()\smethod\sbeing\ssynchronous\s(it's\snot,\swhereas\sthe\ssecond\sVFS's\simportDb()\sis). -D 2024-02-06T08:59:59.394 +C Slight\schange\sto\sOOM\shandling\sin\sJSON\sto\scatch\sa\scorner\scase\sfound\sby\ndbsqlfuzz. +D 2024-02-06T18:33:01.726 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -699,7 +699,7 @@ F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 F src/insert.c 3f0a94082d978bbdd33c38fefea15346c6c6bffb70bc645a71dc0f1f87dd3276 -F src/json.c ae8847ccf8e212650d8a79277750f2123a03ae040d21d96ff5010114bd5b1040 +F src/json.c 0c98979fac084ea5055738fb3467cd431543aaa94acf374d412cac4b89b1acbf F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 F src/main.c 438b95162acfa17b7d218f586f5bde11d6ae82bcf030c9611fc537556870ad6b @@ -2162,8 +2162,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P f28b9924b401b359e59a73918a34b29cde719164a6b4ac5a9d23da6294b701bd -R d8475422eb55a236e4813bd575b83968 -U stephan -Z 87c60489a9bd431cc3758cc39138e437 +P ae7505fa5e112f39a329befb35eff6ddf46a53f5deb610906550bf67f56fc157 +R bb17ade8dce33fbd8ddcb5bbd3943bbd +U drh +Z 8a6aaa8f9831a5f71eadc202a02ba963 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 71b6a414d3..278abcfe72 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ae7505fa5e112f39a329befb35eff6ddf46a53f5deb610906550bf67f56fc157 \ No newline at end of file +6a2b3266c586d12b51e11fe63cda5881be9373207aa16671ab77f547830eb790 \ No newline at end of file diff --git a/src/json.c b/src/json.c index c50ded3135..1a4ce3af19 100644 --- a/src/json.c +++ b/src/json.c @@ -3359,8 +3359,9 @@ static JsonParse *jsonParseFuncArg( } p->zJson = (char*)sqlite3_value_text(pArg); p->nJson = sqlite3_value_bytes(pArg); + if( db->mallocFailed ) goto json_pfa_oom; if( p->nJson==0 ) goto json_pfa_malformed; - if( NEVER(p->zJson==0) ) goto json_pfa_oom; + assert( p->zJson!=0 ); if( jsonConvertTextToBlob(p, (flgs & JSON_KEEPERROR) ? 0 : ctx) ){ if( flgs & JSON_KEEPERROR ){ p->nErr = 1; From 71cdea8f5f0551e1a77a11705ad65ce4b583db2c Mon Sep 17 00:00:00 2001 From: drh <> Date: Wed, 7 Feb 2024 14:05:38 +0000 Subject: [PATCH 087/430] Detect and respond to an OOM on the jsonStringTerminate() call of jsonReturnStringAsBlob() routine. FossilOrigin-Name: 881f814c09b6896a448a2360b0b43dc99592ea3a1d72ac359770cbb0a2c7d38a --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/json.c | 5 +++++ 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index e10d300129..33b0966c6b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Slight\schange\sto\sOOM\shandling\sin\sJSON\sto\scatch\sa\scorner\scase\sfound\sby\ndbsqlfuzz. -D 2024-02-06T18:33:01.726 +C Detect\sand\srespond\sto\san\sOOM\son\sthe\sjsonStringTerminate()\scall\sof\njsonReturnStringAsBlob()\sroutine. +D 2024-02-07T14:05:38.048 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -699,7 +699,7 @@ F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 F src/insert.c 3f0a94082d978bbdd33c38fefea15346c6c6bffb70bc645a71dc0f1f87dd3276 -F src/json.c 0c98979fac084ea5055738fb3467cd431543aaa94acf374d412cac4b89b1acbf +F src/json.c a0346bef35804e468b9ea0c34a08960f4f543a61683182a3ec1fe30df3b98140 F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 F src/main.c 438b95162acfa17b7d218f586f5bde11d6ae82bcf030c9611fc537556870ad6b @@ -2162,8 +2162,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P ae7505fa5e112f39a329befb35eff6ddf46a53f5deb610906550bf67f56fc157 -R bb17ade8dce33fbd8ddcb5bbd3943bbd +P 6a2b3266c586d12b51e11fe63cda5881be9373207aa16671ab77f547830eb790 +R f921e7ed48eb9865e88c87b2fd0e4d7e U drh -Z 8a6aaa8f9831a5f71eadc202a02ba963 +Z 643b9a87bc06a07fb41a72f9a7566e9f # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 278abcfe72..a559efd0b5 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6a2b3266c586d12b51e11fe63cda5881be9373207aa16671ab77f547830eb790 \ No newline at end of file +881f814c09b6896a448a2360b0b43dc99592ea3a1d72ac359770cbb0a2c7d38a \ No newline at end of file diff --git a/src/json.c b/src/json.c index 1a4ce3af19..3aa4b4e500 100644 --- a/src/json.c +++ b/src/json.c @@ -1623,6 +1623,7 @@ static int jsonTranslateTextToBlob(JsonParse *pParse, u32 i){ case '[': { /* Parse array */ iThis = pParse->nBlob; + assert( i<=pParse->nJson ); jsonBlobAppendNode(pParse, JSONB_ARRAY, pParse->nJson - i, 0); iStart = pParse->nBlob; if( pParse->oom ) return -1; @@ -2027,6 +2028,10 @@ static void jsonReturnStringAsBlob(JsonString *pStr){ JsonParse px; memset(&px, 0, sizeof(px)); jsonStringTerminate(pStr); + if( pStr->eErr ){ + sqlite3_result_error_nomem(pStr->pCtx); + return; + } px.zJson = pStr->zBuf; px.nJson = pStr->nUsed; px.db = sqlite3_context_db_handle(pStr->pCtx); From 204b41955ee3d3784dc4ee12f09085a2fd6af80d Mon Sep 17 00:00:00 2001 From: drh <> Date: Wed, 7 Feb 2024 19:17:44 +0000 Subject: [PATCH 088/430] Turns out the branch is reachable, so back out the NEVER(). FossilOrigin-Name: 0af36a3223d2dabda887830390a603ab4781baca7e2f1698ec6c5f2cf03faf04 --- manifest | 13 +++++++------ manifest.uuid | 2 +- src/vdbesort.c | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 33b0966c6b..5689557247 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Detect\sand\srespond\sto\san\sOOM\son\sthe\sjsonStringTerminate()\scall\sof\njsonReturnStringAsBlob()\sroutine. -D 2024-02-07T14:05:38.048 +C Turns\sout\sthe\sbranch\sis\sreachable,\sso\sback\sout\sthe\sNEVER(). +D 2024-02-07T19:17:44.741 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -816,7 +816,7 @@ F src/vdbeapi.c 8f57d60c89da0b60e6d4e272358c511f6bae4e24330bdb11f8b42f986d1bf21b F src/vdbeaux.c c5a471b34e9c4cfc0295a3e10734fd197670ffaebcb742f284c8e17e8026ceea F src/vdbeblob.c 13f9287b55b6356b4b1845410382d6bede203ceb29ef69388a4a3d007ffacbe5 F src/vdbemem.c 3e37dab421b74e9ce55c1e88fbc7bc6fead590b5ab258bc684f8b70abb1d6e71 -F src/vdbesort.c 00c1fb15171205063556c2f1cf454e24c0b41c1effb0c876b850dce91f21bc64 +F src/vdbesort.c 237840ca1947511fa59bd4e18b9eeae93f2af2468c34d2427b059f896230a547 F src/vdbetrace.c fe0bc29ebd4e02c8bc5c1945f1d2e6be5927ec12c06d89b03ef2a4def34bf823 F src/vdbevtab.c 2143db7db0ceed69b21422581f434baffc507a08d831565193a7a02882a1b6a7 F src/vtab.c 11948e105f56e84099ca17f1f434b1944539ea84de26d0d767eadfbc670ce1ea @@ -2162,8 +2162,9 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 6a2b3266c586d12b51e11fe63cda5881be9373207aa16671ab77f547830eb790 -R f921e7ed48eb9865e88c87b2fd0e4d7e +P 881f814c09b6896a448a2360b0b43dc99592ea3a1d72ac359770cbb0a2c7d38a +Q -9411337a7b3237366768fc708396da53d67a7a17b6cdc5c6f8932c5ab32217a9 +R f3327a0935c4e5c636d36e7e0586529c U drh -Z 643b9a87bc06a07fb41a72f9a7566e9f +Z a7ed96a42f4b8ee08a15aed5a446fbe9 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index a559efd0b5..32dea90bc5 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -881f814c09b6896a448a2360b0b43dc99592ea3a1d72ac359770cbb0a2c7d38a \ No newline at end of file +0af36a3223d2dabda887830390a603ab4781baca7e2f1698ec6c5f2cf03faf04 \ No newline at end of file diff --git a/src/vdbesort.c b/src/vdbesort.c index 324c7c43e3..0083690308 100644 --- a/src/vdbesort.c +++ b/src/vdbesort.c @@ -1290,7 +1290,7 @@ static void vdbeSorterExtendFile(sqlite3 *db, sqlite3_file *pFd, i64 nByte){ sqlite3OsFileControlHint(pFd, SQLITE_FCNTL_CHUNK_SIZE, &chunksize); sqlite3OsFileControlHint(pFd, SQLITE_FCNTL_SIZE_HINT, &nByte); sqlite3OsFetch(pFd, 0, (int)nByte, &p); - if( NEVER(p) ) sqlite3OsUnfetch(pFd, 0, p); + if( p ) sqlite3OsUnfetch(pFd, 0, p); } } #else From 722bd1fe89da923720fcaab13fb4498c5e00575d Mon Sep 17 00:00:00 2001 From: drh <> Date: Wed, 7 Feb 2024 19:52:03 +0000 Subject: [PATCH 089/430] Bring test cases into alignment with the latest enhancements. FossilOrigin-Name: cd017c28d516399e25b5ee9e8fcd7390ca2be9128c7c41f1007f37bc01a35717 --- ext/rtree/rtreeJ.test | 1 + manifest | 16 ++++++++-------- manifest.uuid | 2 +- test/sqllimits1.test | 2 +- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/ext/rtree/rtreeJ.test b/ext/rtree/rtreeJ.test index cff77857c7..b091d2c686 100644 --- a/ext/rtree/rtreeJ.test +++ b/ext/rtree/rtreeJ.test @@ -16,6 +16,7 @@ if {![info exists testdir]} { } source $testdir/tester.tcl set testprefix rtreeJ +ifcapable !rtree { finish_test ; return } do_execsql_test 1.0 { CREATE VIRTUAL TABLE t1 USING rtree(id, x1, x2); diff --git a/manifest b/manifest index 5689557247..f1c4317f1e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Turns\sout\sthe\sbranch\sis\sreachable,\sso\sback\sout\sthe\sNEVER(). -D 2024-02-07T19:17:44.741 +C Bring\stest\scases\sinto\salignment\swith\sthe\slatest\senhancements. +D 2024-02-07T19:52:03.118 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -515,7 +515,7 @@ F ext/rtree/rtreeF.test 81ffa7ef51c4e4618d497a57328c265bf576990c7070633b623b23cd F ext/rtree/rtreeG.test 1b9ca6e3effb48f4161edaa463ddeaa8fca4b2526d084f9cbf5dbe4e0184939c F ext/rtree/rtreeH.test 0885151ee8429242625600ae47142cca935332c70a06737f35af53a7bd7aaf90 F ext/rtree/rtreeI.test 608e77f7fde9be5a12eae316baef640fffaafcfa90a3d67443e78123e19c4ca4 -F ext/rtree/rtreeJ.test ba4e25c409ebed4b96bf1270e72760c1344d0a464478d221dbe91e8471ac9ac6 +F ext/rtree/rtreeJ.test 93227ccd4d6c328f5ac46a902b8880041509dd2d68f6ce71560f0d8ab5bb507a F ext/rtree/rtree_perf.tcl 6c18c1f23cd48e0f948930c98dfdd37dfccb5195 F ext/rtree/rtree_util.tcl 202ca70df1f0645ef9d5a2170e62d378a28098d9407f0569e85c9c1cf1bd020a F ext/rtree/rtreecheck.test 934546ad9b563e090ee0c5cbdc69ad014189ad76e5df7320526797a9a345661f @@ -1633,7 +1633,7 @@ F test/spellfix2.test dfc8f519a3fc204cb2dfa8b4f29821ae90f6f8c3 F test/spellfix3.test 0f9efaaa502a0e0a09848028518a6fb096c8ad33 F test/spellfix4.test 51c7c26514ade169855c66bcf130bd5acfb4d7fd090cc624645ab275ae6a41fb F test/sqldiff1.test 1b7ab4f312442c5cc6b3a5f299fa8ca051416d1dd173cb1126fd51bf64f2c3fb -F test/sqllimits1.test b28e5cc8d337aaf290614d96a47e8fbfb720bb7ad35620c9d5432996fd413ac4 +F test/sqllimits1.test 5880a2f107185744ba4d93637f44c78d17706a9899a38b694d50f209735c81cc F test/sqllog.test 6af6cb0b09f4e44e1917e06ce85be7670302517a F test/startup.c 1beb5ca66fcc0fce95c3444db9d1674f90fc605499a574ae2434dcfc10d22805 F test/stat.test 123212a20ceb496893d5254a5f6c76442ce549fdc08d1702d8288a2bbaac8408 @@ -2162,9 +2162,9 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 881f814c09b6896a448a2360b0b43dc99592ea3a1d72ac359770cbb0a2c7d38a -Q -9411337a7b3237366768fc708396da53d67a7a17b6cdc5c6f8932c5ab32217a9 -R f3327a0935c4e5c636d36e7e0586529c +P 0af36a3223d2dabda887830390a603ab4781baca7e2f1698ec6c5f2cf03faf04 +Q +81bd7aee093ddb7405bf12e9c9a915d410fb3103d3b19cce21be63d97256904c +R 8fc57b3ff811df04d2f88b3e6328966f U drh -Z a7ed96a42f4b8ee08a15aed5a446fbe9 +Z e908575b96347b2a10ba2f1656de4a56 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 32dea90bc5..33a20b533f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0af36a3223d2dabda887830390a603ab4781baca7e2f1698ec6c5f2cf03faf04 \ No newline at end of file +cd017c28d516399e25b5ee9e8fcd7390ca2be9128c7c41f1007f37bc01a35717 \ No newline at end of file diff --git a/test/sqllimits1.test b/test/sqllimits1.test index f16208f234..e9e20f40cc 100644 --- a/test/sqllimits1.test +++ b/test/sqllimits1.test @@ -707,6 +707,7 @@ if {$SQLITE_MAX_EXPR_DEPTH==0} { }] } "1 {Expression tree is too large (maximum depth $::SQLITE_MAX_EXPR_DEPTH)}" +if 0 { # Attempting to beat the expression depth limit using nested SELECT # queries causes a parser stack overflow. do_test sqllimits1-9.2 { @@ -718,7 +719,6 @@ if {$SQLITE_MAX_EXPR_DEPTH==0} { catchsql [subst { $expr }] } "1 {parser stack overflow}" -if 0 { do_test sqllimits1-9.3 { execsql { PRAGMA max_page_count = 1000000; -- 1 GB From 0f777cd622d19a5112a58ada3ff67af4c4af831d Mon Sep 17 00:00:00 2001 From: drh <> Date: Wed, 7 Feb 2024 20:45:38 +0000 Subject: [PATCH 090/430] Fix an #endif (added in the wrong place by [8f4b1ceafe4a271b]) so that the build works with SQLITE_OMIT_VIRTUAL_TABLE. FossilOrigin-Name: 7070924eebce1d089fde911dc0427ab8f3764d57ace24caff2b79954b42d1b51 --- manifest | 13 ++++++------- manifest.uuid | 2 +- src/pragma.c | 3 +-- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index f1c4317f1e..33cb6032bb 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Bring\stest\scases\sinto\salignment\swith\sthe\slatest\senhancements. -D 2024-02-07T19:52:03.118 +C Fix\san\s#endif\s(added\sin\sthe\swrong\splace\sby\s[8f4b1ceafe4a271b])\sso\sthat\nthe\sbuild\sworks\swith\sSQLITE_OMIT_VIRTUAL_TABLE. +D 2024-02-07T20:45:38.362 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -732,7 +732,7 @@ F src/parse.y bfd6da46fc895cd8237400ff485d04ab0b32e47eb56de20982bb7f53e56c1f42 F src/pcache.c 040b165f30622a21b7a9a77c6f2e4877a32fb7f22d4c7f0d2a6fa6833a156a75 F src/pcache.h 1497ce1b823cf00094bb0cf3bac37b345937e6f910890c626b16512316d3abf5 F src/pcache1.c 602acb23c471bb8d557a6f0083cc2be641d6cafcafa19e481eba7ef4c9ca0f00 -F src/pragma.c f9b6bb9a044a0dfda1f31c2d1523c7970f850688b450f06e61e23672d70adac0 +F src/pragma.c 017c04c842da70c04f31df5163d139e01693fdaa48a9058843fd520eee0ad426 F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7 F src/prepare.c 371f6115cb69286ebc12c6f2d7511279c2e47d9f54f475d46a554d687a3b312c F src/printf.c 18fbdf028345c8fbe6044f5f5bfda5a10d48d6287afef088cc21b0ca57985640 @@ -2162,9 +2162,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 0af36a3223d2dabda887830390a603ab4781baca7e2f1698ec6c5f2cf03faf04 -Q +81bd7aee093ddb7405bf12e9c9a915d410fb3103d3b19cce21be63d97256904c -R 8fc57b3ff811df04d2f88b3e6328966f +P cd017c28d516399e25b5ee9e8fcd7390ca2be9128c7c41f1007f37bc01a35717 +R 2d9fa4a2af3419f8f53f008b15026f33 U drh -Z e908575b96347b2a10ba2f1656de4a56 +Z e59ddf9aaf84b24c6fc5197c4cee87c1 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 33a20b533f..a7c1376605 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -cd017c28d516399e25b5ee9e8fcd7390ca2be9128c7c41f1007f37bc01a35717 \ No newline at end of file +7070924eebce1d089fde911dc0427ab8f3764d57ace24caff2b79954b42d1b51 \ No newline at end of file diff --git a/src/pragma.c b/src/pragma.c index 79c4e0ae84..775c990f98 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -2116,10 +2116,9 @@ void sqlite3Pragma( a1 = sqlite3VdbeAddOp1(v, OP_IsNull, 3); VdbeCoverage(v); integrityCheckResultRow(v); sqlite3VdbeJumpHere(v, a1); -#endif continue; } - +#endif } { static const int iLn = VDBE_OFFSET_LINENO(2); From 25e172d429e2f549b148024ef75470db871b93e3 Mon Sep 17 00:00:00 2001 From: larrybr Date: Thu, 8 Feb 2024 01:19:46 +0000 Subject: [PATCH 091/430] Mention limited lifetime of string arrays passed to sqlite3_exec() callback. FossilOrigin-Name: 717f67f3189a59842f5c17a25e8db0e24ec4405886fc22ab6eeb3954fba5a964 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/sqlite.h.in | 2 ++ 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 33cb6032bb..9aa176bf1f 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\san\s#endif\s(added\sin\sthe\swrong\splace\sby\s[8f4b1ceafe4a271b])\sso\sthat\nthe\sbuild\sworks\swith\sSQLITE_OMIT_VIRTUAL_TABLE. -D 2024-02-07T20:45:38.362 +C Mention\slimited\slifetime\sof\sstring\sarrays\spassed\sto\ssqlite3_exec()\scallback. +D 2024-02-08T01:19:46.361 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -741,7 +741,7 @@ F src/resolve.c 0ed10ebb70d15dcf3f1882051931ccfaf9c3f4debe67dbd114047d9e2adb9523 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c f1a81ff4f8e9e76c224e2ab3a4baa799add0db22158c7fcede65d8cc4a6fa2da F src/shell.c.in c6cb773b7703d76677529de19d1c40584520701966422c33da3e9334498a7099 -F src/sqlite.h.in 61a60b4ea04db8ead15e1579b20b64cb56e9f55d52c5f9f9694de630110593a3 +F src/sqlite.h.in ebb9636c0e99d692bdc22e70df3766dc615120aeddde81214547f51998bbd21d F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 F src/sqliteInt.h 5013ac1f5642df4c0b76314f507f4c7b6f8efee0e1d7c2e93bf8b445ceea29bb @@ -2162,8 +2162,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P cd017c28d516399e25b5ee9e8fcd7390ca2be9128c7c41f1007f37bc01a35717 -R 2d9fa4a2af3419f8f53f008b15026f33 -U drh -Z e59ddf9aaf84b24c6fc5197c4cee87c1 +P 7070924eebce1d089fde911dc0427ab8f3764d57ace24caff2b79954b42d1b51 +R 2754c4cd5c9c2d2fe3f97bd6f57b4998 +U larrybr +Z bdbab30aa887dd5009861f5b93382dca # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index a7c1376605..da391229d2 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7070924eebce1d089fde911dc0427ab8f3764d57ace24caff2b79954b42d1b51 \ No newline at end of file +717f67f3189a59842f5c17a25e8db0e24ec4405886fc22ab6eeb3954fba5a964 \ No newline at end of file diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 4a19fe918a..ddd8fc6939 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -420,6 +420,8 @@ typedef int (*sqlite3_callback)(void*,int,char**, char**); ** the 1st parameter to sqlite3_exec() while sqlite3_exec() is running. **
  • The application must not modify the SQL statement text passed into ** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running. +**
  • The application must not dereference the arrays or string pointers +** passed as the 3rd and 4th parameters after the callback returns. ** */ int sqlite3_exec( From 589c407f1257d8fa4a13da753b15d72eb282cbcf Mon Sep 17 00:00:00 2001 From: larrybr Date: Sat, 10 Feb 2024 03:11:42 +0000 Subject: [PATCH 092/430] Further clarify sqlite3_exec() callback parameter lifetime. FossilOrigin-Name: 993a1a843177b19a9cb5598f57d1e05c01e1695f164faaa9ae22810ad4533eba --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/sqlite.h.in | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 9aa176bf1f..7fa4237cf2 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Mention\slimited\slifetime\sof\sstring\sarrays\spassed\sto\ssqlite3_exec()\scallback. -D 2024-02-08T01:19:46.361 +C Further\sclarify\ssqlite3_exec()\scallback\sparameter\slifetime. +D 2024-02-10T03:11:42.492 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -741,7 +741,7 @@ F src/resolve.c 0ed10ebb70d15dcf3f1882051931ccfaf9c3f4debe67dbd114047d9e2adb9523 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c f1a81ff4f8e9e76c224e2ab3a4baa799add0db22158c7fcede65d8cc4a6fa2da F src/shell.c.in c6cb773b7703d76677529de19d1c40584520701966422c33da3e9334498a7099 -F src/sqlite.h.in ebb9636c0e99d692bdc22e70df3766dc615120aeddde81214547f51998bbd21d +F src/sqlite.h.in 020d7b7307dda51420dc48b47e5334eaface77baba6bd9818375d392eb3ab5b5 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 F src/sqliteInt.h 5013ac1f5642df4c0b76314f507f4c7b6f8efee0e1d7c2e93bf8b445ceea29bb @@ -2162,8 +2162,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 7070924eebce1d089fde911dc0427ab8f3764d57ace24caff2b79954b42d1b51 -R 2754c4cd5c9c2d2fe3f97bd6f57b4998 +P 717f67f3189a59842f5c17a25e8db0e24ec4405886fc22ab6eeb3954fba5a964 +R 64f77dbf6c9a67d1a6681b063264b76b U larrybr -Z bdbab30aa887dd5009861f5b93382dca +Z 925b1d0fbc30e91dd097edf85eb7f5c3 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index da391229d2..153c997809 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -717f67f3189a59842f5c17a25e8db0e24ec4405886fc22ab6eeb3954fba5a964 \ No newline at end of file +993a1a843177b19a9cb5598f57d1e05c01e1695f164faaa9ae22810ad4533eba \ No newline at end of file diff --git a/src/sqlite.h.in b/src/sqlite.h.in index ddd8fc6939..f21cffd51a 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -421,7 +421,7 @@ typedef int (*sqlite3_callback)(void*,int,char**, char**); **
  • The application must not modify the SQL statement text passed into ** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running. **
  • The application must not dereference the arrays or string pointers -** passed as the 3rd and 4th parameters after the callback returns. +** passed as the 3rd and 4th callback parameters after it returns. ** */ int sqlite3_exec( From ece3567aec217b9e302e56295968966d8d7a3782 Mon Sep 17 00:00:00 2001 From: drh <> Date: Sun, 11 Feb 2024 18:53:48 +0000 Subject: [PATCH 093/430] Improved AggInfo tracing in debug builds. No changes to deliverable code. FossilOrigin-Name: bb31f9c44794e02a46ed3edbcc96eb48c5870d3f82cb404586ded9a3efa7a859 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/select.c | 8 ++++++++ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 7fa4237cf2..4216332915 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Further\sclarify\ssqlite3_exec()\scallback\sparameter\slifetime. -D 2024-02-10T03:11:42.492 +C Improved\sAggInfo\stracing\sin\sdebug\sbuilds.\s\sNo\schanges\sto\sdeliverable\scode. +D 2024-02-11T18:53:48.466 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -739,7 +739,7 @@ F src/printf.c 18fbdf028345c8fbe6044f5f5bfda5a10d48d6287afef088cc21b0ca57985640 F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c 0ed10ebb70d15dcf3f1882051931ccfaf9c3f4debe67dbd114047d9e2adb9523 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 -F src/select.c f1a81ff4f8e9e76c224e2ab3a4baa799add0db22158c7fcede65d8cc4a6fa2da +F src/select.c 43fabfc01bf87addd15e39f112f1e2ade15b19594835ab8a9e5bd50839d4e1b1 F src/shell.c.in c6cb773b7703d76677529de19d1c40584520701966422c33da3e9334498a7099 F src/sqlite.h.in 020d7b7307dda51420dc48b47e5334eaface77baba6bd9818375d392eb3ab5b5 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 @@ -2162,8 +2162,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 717f67f3189a59842f5c17a25e8db0e24ec4405886fc22ab6eeb3954fba5a964 -R 64f77dbf6c9a67d1a6681b063264b76b -U larrybr -Z 925b1d0fbc30e91dd097edf85eb7f5c3 +P 993a1a843177b19a9cb5598f57d1e05c01e1695f164faaa9ae22810ad4533eba +R b08d58139ab071fec772aaa3f5cfa8ae +U drh +Z 8c006f746e6086c64fa306e943cc82cc # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 153c997809..764a7523c6 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -993a1a843177b19a9cb5598f57d1e05c01e1695f164faaa9ae22810ad4533eba \ No newline at end of file +bb31f9c44794e02a46ed3edbcc96eb48c5870d3f82cb404586ded9a3efa7a859 \ No newline at end of file diff --git a/src/select.c b/src/select.c index 1215727791..81e802d6e4 100644 --- a/src/select.c +++ b/src/select.c @@ -6444,6 +6444,8 @@ void sqlite3SelectPrep( */ static void printAggInfo(AggInfo *pAggInfo){ int ii; + sqlite3DebugPrintf("AggInfo %d/%p:\n", + pAggInfo->selId, pAggInfo); for(ii=0; iinColumn; ii++){ struct AggInfo_col *pCol = &pAggInfo->aCol[ii]; sqlite3DebugPrintf( @@ -8546,6 +8548,12 @@ int sqlite3Select( sqlite3ExprListDelete(db, pMinMaxOrderBy); #ifdef SQLITE_DEBUG if( pAggInfo && !db->mallocFailed ){ +#if TREETRACE_ENABLED + if( sqlite3TreeTrace & 0x20 ){ + TREETRACE(0x20,pParse,p,("Finished with AggInfo\n")); + printAggInfo(pAggInfo); + } +#endif for(i=0; inColumn; i++){ Expr *pExpr = pAggInfo->aCol[i].pCExpr; if( pExpr==0 ) continue; From 3c5a810646a060aeb3019942bf66278168df8f3b Mon Sep 17 00:00:00 2001 From: drh <> Date: Sun, 11 Feb 2024 20:53:14 +0000 Subject: [PATCH 094/430] If a term of an ORDER BY or GROUP BY contains an aggregate function or column, then it is not an alias that needs to be resolved, so don't try to. This fixes a harmless assertion found by dbsqlfuzz. This yet another problem that orginated at check-in [6e6b3729e0549de0]. FossilOrigin-Name: d4ec2a5d2297cd9ead0a8768dcf003ea76c74d8d68d88c40f62363f484a4a4d3 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/resolve.c | 2 ++ 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index 4216332915..2940231722 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improved\sAggInfo\stracing\sin\sdebug\sbuilds.\s\sNo\schanges\sto\sdeliverable\scode. -D 2024-02-11T18:53:48.466 +C If\sa\sterm\sof\san\sORDER\sBY\sor\sGROUP\sBY\scontains\san\saggregate\sfunction\sor\scolumn,\nthen\sit\sis\snot\san\salias\sthat\sneeds\sto\sbe\sresolved,\sso\sdon't\stry\sto.\s\sThis\sfixes\na\sharmless\sassertion\sfound\sby\sdbsqlfuzz.\s\sThis\syet\sanother\sproblem\sthat\norginated\sat\scheck-in\s[6e6b3729e0549de0]. +D 2024-02-11T20:53:14.723 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -737,7 +737,7 @@ F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7 F src/prepare.c 371f6115cb69286ebc12c6f2d7511279c2e47d9f54f475d46a554d687a3b312c F src/printf.c 18fbdf028345c8fbe6044f5f5bfda5a10d48d6287afef088cc21b0ca57985640 F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c -F src/resolve.c 0ed10ebb70d15dcf3f1882051931ccfaf9c3f4debe67dbd114047d9e2adb9523 +F src/resolve.c d77c6160bc8f249c2196fdd3e75f66a1dd70e37aa25c39aedc7b1f93c42b7c6d F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c 43fabfc01bf87addd15e39f112f1e2ade15b19594835ab8a9e5bd50839d4e1b1 F src/shell.c.in c6cb773b7703d76677529de19d1c40584520701966422c33da3e9334498a7099 @@ -2162,8 +2162,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 993a1a843177b19a9cb5598f57d1e05c01e1695f164faaa9ae22810ad4533eba -R b08d58139ab071fec772aaa3f5cfa8ae +P bb31f9c44794e02a46ed3edbcc96eb48c5870d3f82cb404586ded9a3efa7a859 +R 420903d8a166efd58090018027845648 U drh -Z 8c006f746e6086c64fa306e943cc82cc +Z 77dfb496104764f5c2dcbb370d30ed43 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 764a7523c6..bbcaf95855 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -bb31f9c44794e02a46ed3edbcc96eb48c5870d3f82cb404586ded9a3efa7a859 \ No newline at end of file +d4ec2a5d2297cd9ead0a8768dcf003ea76c74d8d68d88c40f62363f484a4a4d3 \ No newline at end of file diff --git a/src/resolve.c b/src/resolve.c index 29975f385a..5d0801e82e 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -79,6 +79,8 @@ static void resolveAlias( assert( iCol>=0 && iColnExpr ); pOrig = pEList->a[iCol].pExpr; assert( pOrig!=0 ); + assert( !ExprHasProperty(pExpr, EP_Reduced|EP_TokenOnly) ); + if( pExpr->pAggInfo ) return; db = pParse->db; pDup = sqlite3ExprDup(db, pOrig, 0); if( db->mallocFailed ){ From 18b6019cdd2e036496b91c764b2b953b167545d5 Mon Sep 17 00:00:00 2001 From: drh <> Date: Sun, 11 Feb 2024 22:56:12 +0000 Subject: [PATCH 095/430] In the RTREE extension, allow the xBeginTransaction() entry point to be invoked multiple times without intervening calls to xEndTransaction(). FossilOrigin-Name: f023cb541b5dd72c996f0574210344179217666a2229bc8d3fe057fdbc5c2245 --- ext/rtree/rtree.c | 3 +-- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/ext/rtree/rtree.c b/ext/rtree/rtree.c index 578e6e8623..2b3adc842e 100644 --- a/ext/rtree/rtree.c +++ b/ext/rtree/rtree.c @@ -3225,8 +3225,7 @@ static int rtreeUpdate( */ static int rtreeBeginTransaction(sqlite3_vtab *pVtab){ Rtree *pRtree = (Rtree *)pVtab; - assert( pRtree->inWrTrans==0 ); - pRtree->inWrTrans++; + pRtree->inWrTrans = 1; return SQLITE_OK; } diff --git a/manifest b/manifest index 2940231722..8796f34b8c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C If\sa\sterm\sof\san\sORDER\sBY\sor\sGROUP\sBY\scontains\san\saggregate\sfunction\sor\scolumn,\nthen\sit\sis\snot\san\salias\sthat\sneeds\sto\sbe\sresolved,\sso\sdon't\stry\sto.\s\sThis\sfixes\na\sharmless\sassertion\sfound\sby\sdbsqlfuzz.\s\sThis\syet\sanother\sproblem\sthat\norginated\sat\scheck-in\s[6e6b3729e0549de0]. -D 2024-02-11T20:53:14.723 +C In\sthe\sRTREE\sextension,\sallow\sthe\sxBeginTransaction()\sentry\spoint\sto\sbe\ninvoked\smultiple\stimes\swithout\sintervening\scalls\sto\sxEndTransaction(). +D 2024-02-11T22:56:12.780 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -495,7 +495,7 @@ F ext/repair/test/checkindex01.test b530f141413b587c9eb78ff734de6bb79bc3515c3350 F ext/repair/test/test.tcl 686d76d888dffd021f64260abf29a55c57b2cedfa7fc69150b42b1d6119aac3c F ext/rtree/README 6315c0d73ebf0ec40dedb5aa0e942bc8b54e3761 F ext/rtree/geopoly.c 0dd4775e896cee6067979d67aff7c998e75c2c9d9cd8d62a1a790c09cde7adca -F ext/rtree/rtree.c 920884cfeb88e8a77ef23d70bc696c1a59f2de03b8e877c0966ae81ea61aa41a +F ext/rtree/rtree.c 1b6422e7b9aff51583477bf8c49b51655b19bd9905b4d8fe48f4c1f0c95b2359 F ext/rtree/rtree.h 4a690463901cb5e6127cf05eb8e642f127012fd5003830dbc974eca5802d9412 F ext/rtree/rtree1.test 2b5b8c719c6a4abe377f57766f428a49af36a93061cb146cccfdc3b30000c0a4 F ext/rtree/rtree2.test 9d9deddbb16fd0c30c36e6b4fdc3ee3132d765567f0f9432ee71e1303d32603d @@ -2162,8 +2162,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P bb31f9c44794e02a46ed3edbcc96eb48c5870d3f82cb404586ded9a3efa7a859 -R 420903d8a166efd58090018027845648 +P d4ec2a5d2297cd9ead0a8768dcf003ea76c74d8d68d88c40f62363f484a4a4d3 +R ee61d12c62e00e1e12755723a284535a U drh -Z 77dfb496104764f5c2dcbb370d30ed43 +Z 02dccfc637ae0768eeec52f6adfd1264 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index bbcaf95855..2acfec195a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d4ec2a5d2297cd9ead0a8768dcf003ea76c74d8d68d88c40f62363f484a4a4d3 \ No newline at end of file +f023cb541b5dd72c996f0574210344179217666a2229bc8d3fe057fdbc5c2245 \ No newline at end of file From b29047838d7b8de39467800944b3d169cf1f495b Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 12 Feb 2024 13:28:10 +0000 Subject: [PATCH 096/430] Add support for the ".testctrl fault_install" dot-command in the CLI when launched with the --unsafe-testing option. FossilOrigin-Name: 5ba7fee1a9b49df82387e355d2ab7de58663d3fa824e50717608b27e0f7ac874 --- manifest | 12 +++---- manifest.uuid | 2 +- src/shell.c.in | 92 +++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 98 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 8796f34b8c..4a3f57ce5e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C In\sthe\sRTREE\sextension,\sallow\sthe\sxBeginTransaction()\sentry\spoint\sto\sbe\ninvoked\smultiple\stimes\swithout\sintervening\scalls\sto\sxEndTransaction(). -D 2024-02-11T22:56:12.780 +C Add\ssupport\sfor\sthe\s".testctrl\sfault_install"\sdot-command\sin\sthe\sCLI\swhen\nlaunched\swith\sthe\s--unsafe-testing\soption. +D 2024-02-12T13:28:10.404 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -740,7 +740,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c d77c6160bc8f249c2196fdd3e75f66a1dd70e37aa25c39aedc7b1f93c42b7c6d F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c 43fabfc01bf87addd15e39f112f1e2ade15b19594835ab8a9e5bd50839d4e1b1 -F src/shell.c.in c6cb773b7703d76677529de19d1c40584520701966422c33da3e9334498a7099 +F src/shell.c.in 2382dc2327e47af76b37a7a468152a509dc0a8e72dad887fb868102ecbd94fe8 F src/sqlite.h.in 020d7b7307dda51420dc48b47e5334eaface77baba6bd9818375d392eb3ab5b5 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 @@ -2162,8 +2162,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P d4ec2a5d2297cd9ead0a8768dcf003ea76c74d8d68d88c40f62363f484a4a4d3 -R ee61d12c62e00e1e12755723a284535a +P f023cb541b5dd72c996f0574210344179217666a2229bc8d3fe057fdbc5c2245 +R c8236513dfcf0ef943c428e779c4a525 U drh -Z 02dccfc637ae0768eeec52f6adfd1264 +Z 58d2be401311d1f16e9ad87e4e189606 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 2acfec195a..ed3511505f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f023cb541b5dd72c996f0574210344179217666a2229bc8d3fe057fdbc5c2245 \ No newline at end of file +5ba7fee1a9b49df82387e355d2ab7de58663d3fa824e50717608b27e0f7ac874 \ No newline at end of file diff --git a/src/shell.c.in b/src/shell.c.in index 353db72ede..6bd81a0470 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -7884,6 +7884,38 @@ static int outputDumpWarning(ShellState *p, const char *zLike){ return rc; } +/* +** Fault-Simulator state and logic. +*/ +static struct { + int iId; /* ID that triggers a simulated fault. -1 means "any" */ + int iErr; /* The error code to return on a fault */ + int iCnt; /* Trigger the fault only if iCnt is already zero */ + int iInterval; /* Reset iCnt to this value after each fault */ + int eVerbose; /* When to print output */ +} faultsim_state = {-1, 0, 0, 0, 0}; + +/* +** This is the fault-sim callback +*/ +static int faultsim_callback(int iArg){ + if( faultsim_state.iId>0 && faultsim_state.iId!=iArg ){ + return SQLITE_OK; + } + if( faultsim_state.iCnt>0 ){ + faultsim_state.iCnt--; + if( faultsim_state.eVerbose>=2 ){ + oputf("FAULT-SIM id=%d no-fault (cnt=%d)\n", iArg, faultsim_state.iCnt); + } + return SQLITE_OK; + } + if( faultsim_state.eVerbose>=1 ){ + oputf("FAULT-SIM id=%d returns %d\n", iArg, faultsim_state.iErr); + } + faultsim_state.iCnt = faultsim_state.iInterval; + return faultsim_state.iErr; +} + /* ** If an input line begins with "." then invoke this routine to ** process that line. @@ -10772,7 +10804,7 @@ static int do_meta_command(char *zLine, ShellState *p){ /*{"bitvec_test", SQLITE_TESTCTRL_BITVEC_TEST, 1, "" },*/ {"byteorder", SQLITE_TESTCTRL_BYTEORDER, 0, "" }, {"extra_schema_checks",SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS,0,"BOOLEAN" }, - /*{"fault_install", SQLITE_TESTCTRL_FAULT_INSTALL, 1,"" },*/ + {"fault_install", SQLITE_TESTCTRL_FAULT_INSTALL, 1,"args..." }, {"fk_no_action", SQLITE_TESTCTRL_FK_NO_ACTION, 0, "BOOLEAN" }, {"imposter", SQLITE_TESTCTRL_IMPOSTER,1,"SCHEMA ON/OFF ROOTPAGE"}, {"internal_functions", SQLITE_TESTCTRL_INTERNAL_FUNCTIONS,0,"" }, @@ -11005,6 +11037,64 @@ static int do_meta_command(char *zLine, ShellState *p){ } sqlite3_test_control(testctrl, &rc2); break; + case SQLITE_TESTCTRL_FAULT_INSTALL: { + int kk; + int bShowHelp = nArg<=2; + isOk = 3; + for(kk=2; kk0 ) faultsim_state.eVerbose--; + }else if( cli_strcmp(z,"-id")==0 && kk+1=0 ){ From 84dea8264b783dcfe780633ddae1e57b5f37be57 Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 12 Feb 2024 13:51:08 +0000 Subject: [PATCH 097/430] Add a new sqlite3FaultSim() call in the btree logic, for testing. FossilOrigin-Name: e0558f79b8184ea6741fb20b710dab854f5bdb71aa47d5a6701eeb7389540c8c --- manifest | 15 +++++++++------ manifest.uuid | 2 +- src/btree.c | 9 ++++++--- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 4a3f57ce5e..22930876aa 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\ssupport\sfor\sthe\s".testctrl\sfault_install"\sdot-command\sin\sthe\sCLI\swhen\nlaunched\swith\sthe\s--unsafe-testing\soption. -D 2024-02-12T13:28:10.404 +C Add\sa\snew\ssqlite3FaultSim()\scall\sin\sthe\sbtree\slogic,\sfor\stesting. +D 2024-02-12T13:51:08.316 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -678,7 +678,7 @@ F src/auth.c 19b7ccacae3dfba23fc6f1d0af68134fa216e9040e53b0681b4715445ea030b4 F src/backup.c 5c97e8023aab1ce14a42387eb3ae00ba5a0644569e3476f38661fa6f824c3523 F src/bitvec.c 9eac5f42c11914d5ef00a75605bb205e934f435c579687f985f1f8b0995c8645 F src/btmutex.c 79a43670447eacc651519a429f6ece9fd638563cf95b469d6891185ddae2b522 -F src/btree.c bf659f4b1622c120ec6a863ba96c63f1861595ca21124950d977cec1477dd922 +F src/btree.c dfd351decf9f819393dae8fb7294cae69c3818069d27f47fee34d5b505e37b47 F src/btree.h 03e3356f5208bcab8eed4e094240fdac4a7f9f5ddf5e91045ce589f67d47c240 F src/btreeInt.h 3e2589726c4f105e653461814f65857465da68be1fac688de340c43b873f4062 F src/build.c 05c9eb387638982092988d2ef4c00a91b0c29baa1b85923f082ce0cf2903ea7e @@ -2162,8 +2162,11 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P f023cb541b5dd72c996f0574210344179217666a2229bc8d3fe057fdbc5c2245 -R c8236513dfcf0ef943c428e779c4a525 +P 5ba7fee1a9b49df82387e355d2ab7de58663d3fa824e50717608b27e0f7ac874 +R 0edcf4f3ab18268eaee9147c5810abce +T *branch * new-btree-faultsim +T *sym-new-btree-faultsim * +T -sym-trunk * U drh -Z 58d2be401311d1f16e9ad87e4e189606 +Z 917d838d939c74582a89abdf802d5804 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index ed3511505f..d1246e8e86 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5ba7fee1a9b49df82387e355d2ab7de58663d3fa824e50717608b27e0f7ac874 \ No newline at end of file +e0558f79b8184ea6741fb20b710dab854f5bdb71aa47d5a6701eeb7389540c8c \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 058f246701..49c07c81a6 100644 --- a/src/btree.c +++ b/src/btree.c @@ -5128,9 +5128,12 @@ static int accessPayload( if( pCur->aOverflow==0 || nOvfl*(int)sizeof(Pgno) > sqlite3MallocSize(pCur->aOverflow) ){ - Pgno *aNew = (Pgno*)sqlite3Realloc( - pCur->aOverflow, nOvfl*2*sizeof(Pgno) - ); + Pgno *aNew; + if( sqlite3FaultSim(413) ){ + aNew = 0; + }else{ + aNew = (Pgno*)sqlite3Realloc(pCur->aOverflow, nOvfl*2*sizeof(Pgno)); + } if( aNew==0 ){ return SQLITE_NOMEM_BKPT; }else{ From 98a8ffb3b3592cdf16a5bee21f15aa2a7f5bb584 Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 12 Feb 2024 16:12:25 +0000 Subject: [PATCH 098/430] Have rtree avoid keeping a blob handle open following an error. FossilOrigin-Name: 1cd5d4623f44af25ab4f5af580354b3ae22cf5de4109e008ca41055125bb708d --- ext/rtree/rtree.c | 14 +++++++------- manifest | 15 +++++++-------- manifest.uuid | 2 +- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/ext/rtree/rtree.c b/ext/rtree/rtree.c index 2b3adc842e..02127fa117 100644 --- a/ext/rtree/rtree.c +++ b/ext/rtree/rtree.c @@ -694,11 +694,9 @@ static RtreeNode *nodeNew(Rtree *pRtree, RtreeNode *pParent){ ** Clear the Rtree.pNodeBlob object */ static void nodeBlobReset(Rtree *pRtree){ - if( pRtree->pNodeBlob && pRtree->inWrTrans==0 && pRtree->nCursor==0 ){ - sqlite3_blob *pBlob = pRtree->pNodeBlob; - pRtree->pNodeBlob = 0; - sqlite3_blob_close(pBlob); - } + sqlite3_blob *pBlob = pRtree->pNodeBlob; + pRtree->pNodeBlob = 0; + sqlite3_blob_close(pBlob); } /* @@ -742,7 +740,6 @@ static int nodeAcquire( &pRtree->pNodeBlob); } if( rc ){ - nodeBlobReset(pRtree); *ppNode = 0; /* If unable to open an sqlite3_blob on the desired row, that can only ** be because the shadow tables hold erroneous data. */ @@ -802,6 +799,7 @@ static int nodeAcquire( } *ppNode = pNode; }else{ + nodeBlobReset(pRtree); if( pNode ){ pRtree->nNodeRef--; sqlite3_free(pNode); @@ -1136,7 +1134,9 @@ static int rtreeClose(sqlite3_vtab_cursor *cur){ sqlite3_finalize(pCsr->pReadAux); sqlite3_free(pCsr); pRtree->nCursor--; - nodeBlobReset(pRtree); + if( pRtree->nCursor==0 && pRtree->inWrTrans==0 ){ + nodeBlobReset(pRtree); + } return SQLITE_OK; } diff --git a/manifest b/manifest index dd40f4c05a..aec907f877 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sa\snew\ssqlite3FaultSim()\sto\sbtree\sfor\sbetter\sfault\sanalysis. -D 2024-02-12T14:44:35.288 +C Have\srtree\savoid\skeeping\sa\sblob\shandle\sopen\sfollowing\san\serror. +D 2024-02-12T16:12:25.013 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -495,7 +495,7 @@ F ext/repair/test/checkindex01.test b530f141413b587c9eb78ff734de6bb79bc3515c3350 F ext/repair/test/test.tcl 686d76d888dffd021f64260abf29a55c57b2cedfa7fc69150b42b1d6119aac3c F ext/rtree/README 6315c0d73ebf0ec40dedb5aa0e942bc8b54e3761 F ext/rtree/geopoly.c 0dd4775e896cee6067979d67aff7c998e75c2c9d9cd8d62a1a790c09cde7adca -F ext/rtree/rtree.c 1b6422e7b9aff51583477bf8c49b51655b19bd9905b4d8fe48f4c1f0c95b2359 +F ext/rtree/rtree.c bdf97fac91b37b3a6041ab4a0dd06e81c7ba1541601733b40f97fb51e76e79ce F ext/rtree/rtree.h 4a690463901cb5e6127cf05eb8e642f127012fd5003830dbc974eca5802d9412 F ext/rtree/rtree1.test 2b5b8c719c6a4abe377f57766f428a49af36a93061cb146cccfdc3b30000c0a4 F ext/rtree/rtree2.test 9d9deddbb16fd0c30c36e6b4fdc3ee3132d765567f0f9432ee71e1303d32603d @@ -2162,9 +2162,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 5ba7fee1a9b49df82387e355d2ab7de58663d3fa824e50717608b27e0f7ac874 e0558f79b8184ea6741fb20b710dab854f5bdb71aa47d5a6701eeb7389540c8c -R 0edcf4f3ab18268eaee9147c5810abce -T +closed e0558f79b8184ea6741fb20b710dab854f5bdb71aa47d5a6701eeb7389540c8c -U drh -Z b0ed70b83eb4a1ec81d9b2beb169bda8 +P 2c675bd30568d3c530300beb3fcfaa17c9f063cdcb9a39ac68b9902100f641a6 +R 7630f9e2445b646399b67a3fa625e210 +U dan +Z 2ae954926487fe7e892424e070aafe51 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 882750191a..4a963ad93e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2c675bd30568d3c530300beb3fcfaa17c9f063cdcb9a39ac68b9902100f641a6 \ No newline at end of file +1cd5d4623f44af25ab4f5af580354b3ae22cf5de4109e008ca41055125bb708d \ No newline at end of file From 8e821c251d27816352f3330e9992dcc3b5dceeaa Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 12 Feb 2024 19:12:30 +0000 Subject: [PATCH 099/430] Replace the assert() that was removed by [f023cb541b5dd72c] because [1cd5d4623f44af25] made it true again. FossilOrigin-Name: 189a49f165dfc348a8730ad2b2288b9b2b2089b1de99fa2d515f2a90c9e7bd4e --- ext/rtree/rtree.c | 1 + manifest | 15 ++++++++------- manifest.uuid | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/ext/rtree/rtree.c b/ext/rtree/rtree.c index 02127fa117..11996d110c 100644 --- a/ext/rtree/rtree.c +++ b/ext/rtree/rtree.c @@ -3225,6 +3225,7 @@ static int rtreeUpdate( */ static int rtreeBeginTransaction(sqlite3_vtab *pVtab){ Rtree *pRtree = (Rtree *)pVtab; + assert( pRtree->inWrTrans==0 ); pRtree->inWrTrans = 1; return SQLITE_OK; } diff --git a/manifest b/manifest index aec907f877..92c04c0d06 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Have\srtree\savoid\skeeping\sa\sblob\shandle\sopen\sfollowing\san\serror. -D 2024-02-12T16:12:25.013 +C Replace\sthe\sassert()\sthat\swas\sremoved\sby\s[f023cb541b5dd72c]\sbecause\n[1cd5d4623f44af25]\smade\sit\strue\sagain. +D 2024-02-12T19:12:30.456 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -495,7 +495,7 @@ F ext/repair/test/checkindex01.test b530f141413b587c9eb78ff734de6bb79bc3515c3350 F ext/repair/test/test.tcl 686d76d888dffd021f64260abf29a55c57b2cedfa7fc69150b42b1d6119aac3c F ext/rtree/README 6315c0d73ebf0ec40dedb5aa0e942bc8b54e3761 F ext/rtree/geopoly.c 0dd4775e896cee6067979d67aff7c998e75c2c9d9cd8d62a1a790c09cde7adca -F ext/rtree/rtree.c bdf97fac91b37b3a6041ab4a0dd06e81c7ba1541601733b40f97fb51e76e79ce +F ext/rtree/rtree.c 1baf9f6aa7251ddecdb019d914df4db46eb227720c00f89c485c66dbfdc7863d F ext/rtree/rtree.h 4a690463901cb5e6127cf05eb8e642f127012fd5003830dbc974eca5802d9412 F ext/rtree/rtree1.test 2b5b8c719c6a4abe377f57766f428a49af36a93061cb146cccfdc3b30000c0a4 F ext/rtree/rtree2.test 9d9deddbb16fd0c30c36e6b4fdc3ee3132d765567f0f9432ee71e1303d32603d @@ -2162,8 +2162,9 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 2c675bd30568d3c530300beb3fcfaa17c9f063cdcb9a39ac68b9902100f641a6 -R 7630f9e2445b646399b67a3fa625e210 -U dan -Z 2ae954926487fe7e892424e070aafe51 +P 1cd5d4623f44af25ab4f5af580354b3ae22cf5de4109e008ca41055125bb708d +Q -f023cb541b5dd72c996f0574210344179217666a2229bc8d3fe057fdbc5c2245 +R d8d7ed01b0a724bd44cf51cd5b54db00 +U drh +Z 301c11d3df27d865badec38ed88ff9b4 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 4a963ad93e..aac78a6d6d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1cd5d4623f44af25ab4f5af580354b3ae22cf5de4109e008ca41055125bb708d \ No newline at end of file +189a49f165dfc348a8730ad2b2288b9b2b2089b1de99fa2d515f2a90c9e7bd4e \ No newline at end of file From 54eb54c7de06e050023d97dc521e77308bf3df64 Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 13 Feb 2024 17:11:19 +0000 Subject: [PATCH 100/430] Changes to vtabCallConstructor() to avoid a harmless static analyzer warning and to help prove that the UAF reported by [forum:/forumpost/cafbe582e8|forum post cafbe582e8] is a false-positive. FossilOrigin-Name: 4892440b93306e5a245f18c0d3d295d851e6712260e420016c0d70e12abf8901 --- manifest | 13 ++++++------- manifest.uuid | 2 +- src/vtab.c | 4 +++- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 92c04c0d06..a1a83bb1fe 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Replace\sthe\sassert()\sthat\swas\sremoved\sby\s[f023cb541b5dd72c]\sbecause\n[1cd5d4623f44af25]\smade\sit\strue\sagain. -D 2024-02-12T19:12:30.456 +C Changes\sto\svtabCallConstructor()\sto\savoid\sa\sharmless\sstatic\sanalyzer\swarning\nand\sto\shelp\sprove\sthat\sthe\sUAF\sreported\sby\n[forum:/forumpost/cafbe582e8|forum\spost\scafbe582e8]\sis\sa\sfalse-positive. +D 2024-02-13T17:11:19.402 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -819,7 +819,7 @@ F src/vdbemem.c 3e37dab421b74e9ce55c1e88fbc7bc6fead590b5ab258bc684f8b70abb1d6e71 F src/vdbesort.c 237840ca1947511fa59bd4e18b9eeae93f2af2468c34d2427b059f896230a547 F src/vdbetrace.c fe0bc29ebd4e02c8bc5c1945f1d2e6be5927ec12c06d89b03ef2a4def34bf823 F src/vdbevtab.c 2143db7db0ceed69b21422581f434baffc507a08d831565193a7a02882a1b6a7 -F src/vtab.c 11948e105f56e84099ca17f1f434b1944539ea84de26d0d767eadfbc670ce1ea +F src/vtab.c 38fcf63832f7e606755fa47b028c2eb6d6cd5facb40e280d66fbda4ed9a52188 F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c 887fc4ca3f020ebb2e376f222069570834ac63bf50111ef0cbf3ae417048ed89 F src/wal.h ba252daaa94f889f4b2c17c027e823d9be47ce39da1d3799886bbd51f0490452 @@ -2162,9 +2162,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 1cd5d4623f44af25ab4f5af580354b3ae22cf5de4109e008ca41055125bb708d -Q -f023cb541b5dd72c996f0574210344179217666a2229bc8d3fe057fdbc5c2245 -R d8d7ed01b0a724bd44cf51cd5b54db00 +P 189a49f165dfc348a8730ad2b2288b9b2b2089b1de99fa2d515f2a90c9e7bd4e +R c17ff8a1420ebd333737eedeb07f4b72 U drh -Z 301c11d3df27d865badec38ed88ff9b4 +Z 905b73f73ae952da68046cffedfa5860 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index aac78a6d6d..c332564904 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -189a49f165dfc348a8730ad2b2288b9b2b2089b1de99fa2d515f2a90c9e7bd4e \ No newline at end of file +4892440b93306e5a245f18c0d3d295d851e6712260e420016c0d70e12abf8901 \ No newline at end of file diff --git a/src/vtab.c b/src/vtab.c index f839216787..67226c63c8 100644 --- a/src/vtab.c +++ b/src/vtab.c @@ -611,6 +611,8 @@ static int vtabCallConstructor( db->pVtabCtx = &sCtx; pTab->nTabRef++; rc = xConstruct(db, pMod->pAux, nArg, azArg, &pVTable->pVtab, &zErr); + assert( pTab!=0 ); + assert( pTab->nTabRef>1 || rc!=SQLITE_OK ); sqlite3DeleteTable(db, pTab); db->pVtabCtx = sCtx.pPrior; if( rc==SQLITE_NOMEM ) sqlite3OomFault(db); @@ -633,7 +635,7 @@ static int vtabCallConstructor( pVTable->nRef = 1; if( sCtx.bDeclared==0 ){ const char *zFormat = "vtable constructor did not declare schema: %s"; - *pzErr = sqlite3MPrintf(db, zFormat, pTab->zName); + *pzErr = sqlite3MPrintf(db, zFormat, zModuleName); sqlite3VtabUnlock(pVTable); rc = SQLITE_ERROR; }else{ From 95b5295f52a5db0d09b1ace8a6854f7d53fc0cfa Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 13 Feb 2024 18:41:46 +0000 Subject: [PATCH 101/430] Fix a bug in PRAGMA integrity_check introduced by enhancement (8a) in [https://sqlite.org/releaselog/3_42_0.html|release 3.42.0] and first reported by [forum:/forumpost/ee4f6fa5ab|forum post ee4f6fa5ab]. FossilOrigin-Name: 460353dfff8f2fb03f9c8666d0c367ec7be4cfa96dfcb0cea10f144d043223bb --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/pragma.c | 1 + test/pragma.test | 15 +++++++++++++++ 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index a1a83bb1fe..5a67d9340c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Changes\sto\svtabCallConstructor()\sto\savoid\sa\sharmless\sstatic\sanalyzer\swarning\nand\sto\shelp\sprove\sthat\sthe\sUAF\sreported\sby\n[forum:/forumpost/cafbe582e8|forum\spost\scafbe582e8]\sis\sa\sfalse-positive. -D 2024-02-13T17:11:19.402 +C Fix\sa\sbug\sin\sPRAGMA\sintegrity_check\sintroduced\sby\senhancement\s(8a)\sin\n[https://sqlite.org/releaselog/3_42_0.html|release\s3.42.0]\sand\sfirst\sreported\sby\n[forum:/forumpost/ee4f6fa5ab|forum\spost\see4f6fa5ab]. +D 2024-02-13T18:41:46.416 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -732,7 +732,7 @@ F src/parse.y bfd6da46fc895cd8237400ff485d04ab0b32e47eb56de20982bb7f53e56c1f42 F src/pcache.c 040b165f30622a21b7a9a77c6f2e4877a32fb7f22d4c7f0d2a6fa6833a156a75 F src/pcache.h 1497ce1b823cf00094bb0cf3bac37b345937e6f910890c626b16512316d3abf5 F src/pcache1.c 602acb23c471bb8d557a6f0083cc2be641d6cafcafa19e481eba7ef4c9ca0f00 -F src/pragma.c 017c04c842da70c04f31df5163d139e01693fdaa48a9058843fd520eee0ad426 +F src/pragma.c b61a1a1801befe6763e787b96988deb156a56e82a2b4dea004bc78e4551c9d5c F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7 F src/prepare.c 371f6115cb69286ebc12c6f2d7511279c2e47d9f54f475d46a554d687a3b312c F src/printf.c 18fbdf028345c8fbe6044f5f5bfda5a10d48d6287afef088cc21b0ca57985640 @@ -1482,7 +1482,7 @@ F test/pendingrace.test 6aa33756b950c4529f79c4f3817a9a1e4025bd0d9961571a05c0279b F test/percentile.test 4243af26b8f3f4555abe166f723715a1f74c77ff F test/permutations.test f7caf8dd5c7b1da74842a48df116f7f193399c656d4ffc805cd0d9658568c675 F test/pg_common.tcl 3b27542224db1e713ae387459b5d117c836a5f6e328846922993b6d2b7640d9f -F test/pragma.test 57a36226218c03cfb381019fe43234b2cefbd8a1f12825514f906a17ccf7991e +F test/pragma.test cddd4b534d7fb5cf113d1308dea4231f3548e8a7f3a65d7d1cf4810c87090b5a F test/pragma2.test e5d5c176360c321344249354c0c16aec46214c9f F test/pragma3.test 92a46bbea12322dd94a404f49edcfbfc913a2c98115f0d030a7459bb4712ef31 F test/pragma4.test ca5e4dfc46adfe490f75d73734f70349d95a199e6510973899e502eef2c8b1f8 @@ -2162,8 +2162,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 189a49f165dfc348a8730ad2b2288b9b2b2089b1de99fa2d515f2a90c9e7bd4e -R c17ff8a1420ebd333737eedeb07f4b72 +P 4892440b93306e5a245f18c0d3d295d851e6712260e420016c0d70e12abf8901 +R 6caa0669ab38f9f6a39aaa796ed2bee2 U drh -Z 905b73f73ae952da68046cffedfa5860 +Z f4541a674d73c1bd74cd3c989d7c9de5 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index c332564904..a6e3849faf 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4892440b93306e5a245f18c0d3d295d851e6712260e420016c0d70e12abf8901 \ No newline at end of file +460353dfff8f2fb03f9c8666d0c367ec7be4cfa96dfcb0cea10f144d043223bb \ No newline at end of file diff --git a/src/pragma.c b/src/pragma.c index 775c990f98..a1243acc16 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -1897,6 +1897,7 @@ void sqlite3Pragma( ** is REAL, we have to load the actual data using OP_Column ** to reliably determine if the value is a NULL. */ sqlite3VdbeAddOp3(v, OP_Column, p1, p3, 3); + sqlite3ColumnDefault(v, pTab, j, 3); jmp3 = sqlite3VdbeAddOp2(v, OP_NotNull, 3, labelOk); VdbeCoverage(v); } diff --git a/test/pragma.test b/test/pragma.test index 5b45a74400..8f78a7e026 100644 --- a/test/pragma.test +++ b/test/pragma.test @@ -556,6 +556,21 @@ ifcapable altertable { do_execsql_test pragma-3.23 { PRAGMA integrity_check(1); } {{non-unique entry in index t1a}} + + # forum post https://sqlite.org/forum/forumpost/ee4f6fa5ab + do_execsql_test pragma-3.24 { + DROP TABLE IF EXISTS t1; + CREATE TABLE t1(a); + INSERT INTO t1 VALUES (1); + ALTER TABLE t1 ADD COLUMN b NOT NULL DEFAULT 0.25; + SELECT * FROM t1; + PRAGMA integrity_check(t1); + } {1 0.25 ok} + do_execsql_test pragma-3.25 { + ALTER TABLE t1 ADD COLUMN c CHECK (1); + SELECT * FROM t1; + PRAGMA integrity_check(t1); + } {1 0.25 {} ok} } # PRAGMA integrity check (or more specifically the sqlite3BtreeCount() From 5e5831a760e066318f0a63e0665dae7aa39afe6c Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 16 Feb 2024 11:41:47 +0000 Subject: [PATCH 102/430] Handle an OOM case in fts5 code to query tokendata=1 tables. FossilOrigin-Name: 01222d96b9ab24c7013a2587544304ba32c1f039b08c06a04d8d58ec9c790db0 --- ext/fts5/fts5_index.c | 11 +++++++---- ext/fts5/test/fts5faultH.test | 11 ++++++++++- manifest | 16 ++++++++-------- manifest.uuid | 2 +- 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/ext/fts5/fts5_index.c b/ext/fts5/fts5_index.c index 8eb8f328f6..333fefa2d3 100644 --- a/ext/fts5/fts5_index.c +++ b/ext/fts5/fts5_index.c @@ -6837,23 +6837,26 @@ static void fts5IterSetOutputsTokendata(Fts5Iter *pIter){ static void fts5TokendataIterNext(Fts5Iter *pIter, int bFrom, i64 iFrom){ int ii; Fts5TokenDataIter *pT = pIter->pTokenDataIter; + Fts5Index *pIndex = pIter->pIndex; for(ii=0; iinIter; ii++){ Fts5Iter *p = pT->apIter[ii]; if( p->base.bEof==0 && (p->base.iRowid==pIter->base.iRowid || (bFrom && p->base.iRowidpIndex, p, bFrom, iFrom); + fts5MultiIterNext(pIndex, p, bFrom, iFrom); while( bFrom && p->base.bEof==0 && p->base.iRowidpIndex->rc==SQLITE_OK + && pIndex->rc==SQLITE_OK ){ - fts5MultiIterNext(p->pIndex, p, 0, 0); + fts5MultiIterNext(pIndex, p, 0, 0); } } } - fts5IterSetOutputsTokendata(pIter); + if( pIndex->rc==SQLITE_OK ){ + fts5IterSetOutputsTokendata(pIter); + } } /* diff --git a/ext/fts5/test/fts5faultH.test b/ext/fts5/test/fts5faultH.test index 540b889f37..df430f20fa 100644 --- a/ext/fts5/test/fts5faultH.test +++ b/ext/fts5/test/fts5faultH.test @@ -127,7 +127,7 @@ do_execsql_test 3.0 { COMMIT; } -do_faultsim_test 3 -faults oom* -prep { +do_faultsim_test 3.1 -faults oom* -prep { } -body { execsql { SELECT rowid FROM t1('BBB AND AAA'); @@ -136,6 +136,15 @@ do_faultsim_test 3 -faults oom* -prep { faultsim_integrity_check faultsim_test_result {0 {10 35}} } +do_faultsim_test 3.2 -faults oom* -prep { +} -body { + execsql { + SELECT count(*) FROM t1('BBB'); + } +} -test { + faultsim_integrity_check + faultsim_test_result {0 27} +} finish_test diff --git a/manifest b/manifest index 5a67d9340c..af610a8e0e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sbug\sin\sPRAGMA\sintegrity_check\sintroduced\sby\senhancement\s(8a)\sin\n[https://sqlite.org/releaselog/3_42_0.html|release\s3.42.0]\sand\sfirst\sreported\sby\n[forum:/forumpost/ee4f6fa5ab|forum\spost\see4f6fa5ab]. -D 2024-02-13T18:41:46.416 +C Handle\san\sOOM\scase\sin\sfts5\scode\sto\squery\stokendata=1\stables. +D 2024-02-16T11:41:47.064 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -97,7 +97,7 @@ F ext/fts5/fts5_buffer.c 0eec58bff585f1a44ea9147eae5da2447292080ea435957f7488c70 F ext/fts5/fts5_config.c 8072a207034b51ae9b7694121d1b5715c794e94b275e088f70ae532378ca5cdf F ext/fts5/fts5_expr.c e91156ebdcc08d837f4f324168f69f3c0d7fdef0e521fd561efb48ef3297b696 F ext/fts5/fts5_hash.c adda4272be401566a6e0ba1acbe70ee5cb97fce944bc2e04dc707152a0ec91b1 -F ext/fts5/fts5_index.c bb1965c3965f6fe5f64160bf1c0694a9684a790a783f293a76da1d38d319b258 +F ext/fts5/fts5_index.c ee0f4d50bc0c58a7c5ef7d645e7e38e1e59315b8ea9d722ae00c5f949ee65379 F ext/fts5/fts5_main.c d68bd9533d5a638b7f6fae61c3cb0a15257dcdcccedaf3d0b3c9f55940c85048 F ext/fts5/fts5_storage.c f9e31b0d155e9b2c92d5d3a09ad7a56b937fbf1c7f962e10f4ca6281349f3934 F ext/fts5/fts5_tcl.c fdf7e2bb9a9186cfcaf2d2ce11d338309342b7a7593c2812bc54455db53da5d2 @@ -171,7 +171,7 @@ F ext/fts5/test/fts5faultD.test e7ed7895abfe6bc98a5e853826f6b74956e7ba7f594f1860 F ext/fts5/test/fts5faultE.test 844586ce71dab4be85bb86880e87b624d089f851654cd22e4710c77eb8ce7075 F ext/fts5/test/fts5faultF.test 4abef99f86e99d9f0c6460dd68c586a766b6b9f1f660ada55bf2e8266bd1bbc1 F ext/fts5/test/fts5faultG.test d2e5a4d9a34e08dcaadcaeafef74d10cbc2abdd11aa2659a18af0294bf2812d3 -F ext/fts5/test/fts5faultH.test 57f53c87ffd59be0265840f2b54a16811f9cb9012db86aad9b41d0d14d85dfe3 +F ext/fts5/test/fts5faultH.test b5c3b62642b7d321504a0a4f424eb80b4f6927969173334c8ca20df388557622 F ext/fts5/test/fts5first.test 3fcf2365c00a15fc9704233674789a3b95131d12de18a9b996159f6909dc8079 F ext/fts5/test/fts5full.test e1701a112354e0ff9a1fdffb0c940c576530c33732ee20ac5e8361777070d717 F ext/fts5/test/fts5fuzz1.test 238d8c45f3b81342aa384de3e581ff2fa330bf922a7b69e484bbc06051a1080e @@ -2162,8 +2162,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 4892440b93306e5a245f18c0d3d295d851e6712260e420016c0d70e12abf8901 -R 6caa0669ab38f9f6a39aaa796ed2bee2 -U drh -Z f4541a674d73c1bd74cd3c989d7c9de5 +P 460353dfff8f2fb03f9c8666d0c367ec7be4cfa96dfcb0cea10f144d043223bb +R f8da140c9660a1305ed16f2a20382e32 +U dan +Z 434c4140de6f11763b5cde367e07b573 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index a6e3849faf..376869bc29 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -460353dfff8f2fb03f9c8666d0c367ec7be4cfa96dfcb0cea10f144d043223bb \ No newline at end of file +01222d96b9ab24c7013a2587544304ba32c1f039b08c06a04d8d58ec9c790db0 \ No newline at end of file From 9d00aba8959abc5ea57360d43e8160fb6136c663 Mon Sep 17 00:00:00 2001 From: drh <> Date: Fri, 16 Feb 2024 12:57:04 +0000 Subject: [PATCH 103/430] Rename the TF_StatsUsed flag to TF_MaybeReanalyze, to more accurately reflect its usage. No logic changes. FossilOrigin-Name: b4790da5e0d6f0f617e6c3a17fc2606842e41cab14339392abd335410fec0aa3 --- manifest | 18 +++++++++--------- manifest.uuid | 2 +- src/pragma.c | 2 +- src/sqliteInt.h | 3 +-- src/where.c | 4 ++-- 5 files changed, 14 insertions(+), 15 deletions(-) diff --git a/manifest b/manifest index af610a8e0e..4b23b6788b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Handle\san\sOOM\scase\sin\sfts5\scode\sto\squery\stokendata=1\stables. -D 2024-02-16T11:41:47.064 +C Rename\sthe\sTF_StatsUsed\sflag\sto\sTF_MaybeReanalyze,\sto\smore\saccurately\nreflect\sits\susage.\s\sNo\slogic\schanges. +D 2024-02-16T12:57:04.964 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -732,7 +732,7 @@ F src/parse.y bfd6da46fc895cd8237400ff485d04ab0b32e47eb56de20982bb7f53e56c1f42 F src/pcache.c 040b165f30622a21b7a9a77c6f2e4877a32fb7f22d4c7f0d2a6fa6833a156a75 F src/pcache.h 1497ce1b823cf00094bb0cf3bac37b345937e6f910890c626b16512316d3abf5 F src/pcache1.c 602acb23c471bb8d557a6f0083cc2be641d6cafcafa19e481eba7ef4c9ca0f00 -F src/pragma.c b61a1a1801befe6763e787b96988deb156a56e82a2b4dea004bc78e4551c9d5c +F src/pragma.c 24584cc928538426e047db670f21f3816286812e48dfd391a40e788f14d3cea2 F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7 F src/prepare.c 371f6115cb69286ebc12c6f2d7511279c2e47d9f54f475d46a554d687a3b312c F src/printf.c 18fbdf028345c8fbe6044f5f5bfda5a10d48d6287afef088cc21b0ca57985640 @@ -744,7 +744,7 @@ F src/shell.c.in 2382dc2327e47af76b37a7a468152a509dc0a8e72dad887fb868102ecbd94fe F src/sqlite.h.in 020d7b7307dda51420dc48b47e5334eaface77baba6bd9818375d392eb3ab5b5 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 -F src/sqliteInt.h 5013ac1f5642df4c0b76314f507f4c7b6f8efee0e1d7c2e93bf8b445ceea29bb +F src/sqliteInt.h 2f3a38c3e0470b6152ec14f698e6f3310831e3c09b6e56f046a12c3e3bdd5cd4 F src/sqliteLimit.h 6878ab64bdeb8c24a1d762d45635e34b96da21132179023338c93f820eee6728 F src/status.c cb11f8589a6912af2da3bb1ec509a94dd8ef27df4d4c1a97e0bcf2309ece972b F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1 @@ -824,7 +824,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c 887fc4ca3f020ebb2e376f222069570834ac63bf50111ef0cbf3ae417048ed89 F src/wal.h ba252daaa94f889f4b2c17c027e823d9be47ce39da1d3799886bbd51f0490452 F src/walker.c 7c7ea0115345851c3da4e04e2e239a29983b61fb5b038b94eede6aba462640e2 -F src/where.c 0a6492afeb75f8d2a50e26b993eb78e9623b142e637cd3f2cdb85e896931d51d +F src/where.c 0e7bf004a578eb70d54300503fdbcaaea857de6ba0204aae1adf572edb79c2c6 F src/whereInt.h 82a13766f13d1a53b05387c2e60726289ef26404bc7b9b1f7770204d97357fb8 F src/wherecode.c 5d77db30a2a3dd532492ae882de114edba2fae672622056b1c7fd61f5917a8f1 F src/whereexpr.c dc5096eca5ed503999be3bdee8a90c51361289a678d396a220912e9cb73b3c00 @@ -2162,8 +2162,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 460353dfff8f2fb03f9c8666d0c367ec7be4cfa96dfcb0cea10f144d043223bb -R f8da140c9660a1305ed16f2a20382e32 -U dan -Z 434c4140de6f11763b5cde367e07b573 +P 01222d96b9ab24c7013a2587544304ba32c1f039b08c06a04d8d58ec9c790db0 +R 5e5b0ae5c12dce6d73ff009cddfe3c44 +U drh +Z a8dd3bda9012a6e778f3b0295c3fea74 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 376869bc29..a222b41c70 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -01222d96b9ab24c7013a2587544304ba32c1f039b08c06a04d8d58ec9c790db0 \ No newline at end of file +b4790da5e0d6f0f617e6c3a17fc2606842e41cab14339392abd335410fec0aa3 \ No newline at end of file diff --git a/src/pragma.c b/src/pragma.c index a1243acc16..872177e131 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -2450,7 +2450,7 @@ void sqlite3Pragma( /* If table pTab has not been used in a way that would benefit from ** having analysis statistics during the current session, then skip it. ** This also has the effect of skipping virtual tables and views */ - if( (pTab->tabFlags & TF_StatsUsed)==0 ) continue; + if( (pTab->tabFlags & TF_MaybeReanalyze)==0 ) continue; /* Reanalyze if the table is 25 times larger than the last analysis */ szThreshold = pTab->nRowLogEst + 46; assert( sqlite3LogEst(25)==46 ); diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 9d9657f3cc..1c1055f42f 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -2476,8 +2476,7 @@ struct Table { #define TF_HasStored 0x00000040 /* Has one or more STORED columns */ #define TF_HasGenerated 0x00000060 /* Combo: HasVirtual + HasStored */ #define TF_WithoutRowid 0x00000080 /* No rowid. PRIMARY KEY is the key */ -#define TF_StatsUsed 0x00000100 /* Query planner decisions affected by - ** Index.aiRowLogEst[] values */ +#define TF_MaybeReanalyze 0x00000100 /* Maybe run ANALYZE on this table */ #define TF_NoVisibleRowid 0x00000200 /* No user-visible "rowid" column */ #define TF_OOOHidden 0x00000400 /* Out-of-Order hidden columns */ #define TF_HasNotNull 0x00000800 /* Contains NOT NULL constraints */ diff --git a/src/where.c b/src/where.c index 65022a65bb..0e526b3372 100644 --- a/src/where.c +++ b/src/where.c @@ -3970,7 +3970,7 @@ static int whereLoopAddBtree( ** unique index is used (making the index functionally non-unique) ** then the sqlite_stat1 data becomes important for scoring the ** plan */ - pTab->tabFlags |= TF_StatsUsed; + pTab->tabFlags |= TF_MaybeReanalyze; } #ifdef SQLITE_ENABLE_STAT4 sqlite3Stat4ProbeFree(pBuilder->pRec); @@ -5805,7 +5805,7 @@ static SQLITE_NOINLINE void whereCheckIfBloomFilterIsUseful( SrcItem *pItem = &pWInfo->pTabList->a[pLoop->iTab]; Table *pTab = pItem->pTab; if( (pTab->tabFlags & TF_HasStat1)==0 ) break; - pTab->tabFlags |= TF_StatsUsed; + pTab->tabFlags |= TF_MaybeReanalyze; if( i>=1 && (pLoop->wsFlags & reqFlags)==reqFlags /* vvvvvv--- Always the case if WHERE_COLUMN_EQ is defined */ From 816f677c1c2ec9d3331c9c329a6176bedca4178e Mon Sep 17 00:00:00 2001 From: stephan Date: Fri, 16 Feb 2024 16:04:31 +0000 Subject: [PATCH 104/430] Work around a __VA_ARGS__ complaint in fiddle builds. FossilOrigin-Name: 7d750248c58ccbf87036ea7db053def1c83c7a8ed428a5c47895756302b36200 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/shell.c.in | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 4b23b6788b..e93487a996 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Rename\sthe\sTF_StatsUsed\sflag\sto\sTF_MaybeReanalyze,\sto\smore\saccurately\nreflect\sits\susage.\s\sNo\slogic\schanges. -D 2024-02-16T12:57:04.964 +C Work\saround\sa\s__VA_ARGS__\scomplaint\sin\sfiddle\sbuilds. +D 2024-02-16T16:04:31.416 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -740,7 +740,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c d77c6160bc8f249c2196fdd3e75f66a1dd70e37aa25c39aedc7b1f93c42b7c6d F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c 43fabfc01bf87addd15e39f112f1e2ade15b19594835ab8a9e5bd50839d4e1b1 -F src/shell.c.in 2382dc2327e47af76b37a7a468152a509dc0a8e72dad887fb868102ecbd94fe8 +F src/shell.c.in d0092ec6794ea162f0b1553d7be8d1275726cb504f170035a4e0742a1a3fba75 F src/sqlite.h.in 020d7b7307dda51420dc48b47e5334eaface77baba6bd9818375d392eb3ab5b5 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 @@ -2162,8 +2162,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 01222d96b9ab24c7013a2587544304ba32c1f039b08c06a04d8d58ec9c790db0 -R 5e5b0ae5c12dce6d73ff009cddfe3c44 -U drh -Z a8dd3bda9012a6e778f3b0295c3fea74 +P b4790da5e0d6f0f617e6c3a17fc2606842e41cab14339392abd335410fec0aa3 +R 759fda60be6ab3de32b04d89f6276871 +U stephan +Z d154d8c6872615f4f0b58afcdd6f17b3 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index a222b41c70..170ef3c3b7 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b4790da5e0d6f0f617e6c3a17fc2606842e41cab14339392abd335410fec0aa3 \ No newline at end of file +7d750248c58ccbf87036ea7db053def1c83c7a8ed428a5c47895756302b36200 \ No newline at end of file diff --git a/src/shell.c.in b/src/shell.c.in index 6bd81a0470..780cdb925b 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -280,9 +280,9 @@ INCLUDE ../ext/consio/console_io.c #else /* For Fiddle, all console handling and emit redirection is omitted. */ # define sputz(fp,z) fputs(z,fp) -# define sputf(fp,fmt, ...) fprintf(fp,fmt,__VA_ARGS__) +# define sputf fprintf # define oputz(z) fputs(z,stdout) -# define oputf(fmt, ...) printf(fmt,__VA_ARGS__) +# define oputf printf # define eputz(z) fputs(z,stderr) # define eputf(fmt, ...) fprintf(stderr,fmt,__VA_ARGS__) # define oputb(buf,na) fwrite(buf,1,na,stdout) From fd2500f98b3c385953a3de83545aa6ddcfcadce0 Mon Sep 17 00:00:00 2001 From: larrybr Date: Fri, 16 Feb 2024 18:34:21 +0000 Subject: [PATCH 105/430] Retweak last check-in to retain compile-time checking of xprintf() arguments. FossilOrigin-Name: 670174916c660b24ba70e96a42984eb65ee52da50e9828bdeca4c9ff4bf92e20 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/shell.c.in | 19 ++++++++++++++----- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/manifest b/manifest index e93487a996..2c5c35e07a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Work\saround\sa\s__VA_ARGS__\scomplaint\sin\sfiddle\sbuilds. -D 2024-02-16T16:04:31.416 +C Retweak\slast\scheck-in\sto\sretain\scompile-time\schecking\sof\sxprintf()\sarguments. +D 2024-02-16T18:34:21.033 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -740,7 +740,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c d77c6160bc8f249c2196fdd3e75f66a1dd70e37aa25c39aedc7b1f93c42b7c6d F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c 43fabfc01bf87addd15e39f112f1e2ade15b19594835ab8a9e5bd50839d4e1b1 -F src/shell.c.in d0092ec6794ea162f0b1553d7be8d1275726cb504f170035a4e0742a1a3fba75 +F src/shell.c.in e4a38496290d3979ea3d953fba0bc187d350d6e80f8e33c2e37b9a924850439b F src/sqlite.h.in 020d7b7307dda51420dc48b47e5334eaface77baba6bd9818375d392eb3ab5b5 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 @@ -2162,8 +2162,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P b4790da5e0d6f0f617e6c3a17fc2606842e41cab14339392abd335410fec0aa3 -R 759fda60be6ab3de32b04d89f6276871 -U stephan -Z d154d8c6872615f4f0b58afcdd6f17b3 +P 7d750248c58ccbf87036ea7db053def1c83c7a8ed428a5c47895756302b36200 +R 6ea6e9f84387bdd065f35367386a097e +U larrybr +Z 849b6ec66e03430774f8a485b79fa305 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 170ef3c3b7..7e879107f6 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7d750248c58ccbf87036ea7db053def1c83c7a8ed428a5c47895756302b36200 \ No newline at end of file +670174916c660b24ba70e96a42984eb65ee52da50e9828bdeca4c9ff4bf92e20 \ No newline at end of file diff --git a/src/shell.c.in b/src/shell.c.in index 780cdb925b..da377982e1 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -268,6 +268,9 @@ INCLUDE ../ext/consio/console_io.c * setOutputStream(FILE *pf) * This is normally the stream that CLI normal output goes to. * For the stand-alone CLI, it is stdout with no .output redirect. + * + * The ?putz(z) forms are required for the Fiddle builds for string literal + * output, in aid of enforcing format string to argument correspondence. */ # define sputz(s,z) fPutsUtf8(z,s) # define sputf fPrintfUtf8 @@ -279,12 +282,18 @@ INCLUDE ../ext/consio/console_io.c #else /* For Fiddle, all console handling and emit redirection is omitted. */ -# define sputz(fp,z) fputs(z,fp) -# define sputf fprintf +/* These next 3 macros are for emitting formatted output. When complaints + * from the WASM build are issued for non-formatted output, (when a mere + * string literal is to be emitted, the ?putz(z) forms should be used. + * (This permits compile-time checking of format string / argument mismatch.) + */ +# define oputf(fmt, ...) printf(fmt,__VA_ARGS__) +# define eputf(fmt, ...) fprintf(stderr,fmt,__VA_ARGS__) +# define sputf(fp,fmt, ...) fprintf(fp,fmt,__VA_ARGS__) +/* These next 3 macros are for emitting simple string literals. */ # define oputz(z) fputs(z,stdout) -# define oputf printf # define eputz(z) fputs(z,stderr) -# define eputf(fmt, ...) fprintf(stderr,fmt,__VA_ARGS__) +# define sputz(fp,z) fputs(z,fp) # define oputb(buf,na) fwrite(buf,1,na,stdout) #endif @@ -11079,7 +11088,7 @@ static int do_meta_command(char *zLine, ShellState *p){ } } if( bShowHelp ){ - oputf( + oputz( "Usage: .testctrl fault_install ARGS\n" "Possible arguments:\n" " off Disable faultsim\n" From 4dd59fd997fbee21fc83384b3bd3f7635523739d Mon Sep 17 00:00:00 2001 From: drh <> Date: Fri, 16 Feb 2024 21:30:08 +0000 Subject: [PATCH 106/430] Fix the subtype on the value column from json_each/json_tree for cases when the value is an array or object. Fix for the bug reported by [forum:/forumpost/ecb94cd210|forum post ecb94cd210]. FossilOrigin-Name: 1c33c5db2e05019d1a375109f79ad8588a3c17f81e4f4b8d66c880c3c860e87e --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/json.c | 3 +++ test/json101.test | 14 ++++++++++++++ 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 2c5c35e07a..8a1169a17b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Retweak\slast\scheck-in\sto\sretain\scompile-time\schecking\sof\sxprintf()\sarguments. -D 2024-02-16T18:34:21.033 +C Fix\sthe\ssubtype\son\sthe\svalue\scolumn\sfrom\sjson_each/json_tree\sfor\scases\nwhen\sthe\svalue\sis\san\sarray\sor\sobject.\s\sFix\sfor\sthe\sbug\sreported\sby\n[forum:/forumpost/ecb94cd210|forum\spost\secb94cd210]. +D 2024-02-16T21:30:08.580 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -699,7 +699,7 @@ F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 F src/insert.c 3f0a94082d978bbdd33c38fefea15346c6c6bffb70bc645a71dc0f1f87dd3276 -F src/json.c a0346bef35804e468b9ea0c34a08960f4f543a61683182a3ec1fe30df3b98140 +F src/json.c a412d7f1550a8597470d30e1d9f8d3dcf111b96ef3877b74bb1c363086bcfb51 F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 F src/main.c 438b95162acfa17b7d218f586f5bde11d6ae82bcf030c9611fc537556870ad6b @@ -1337,7 +1337,7 @@ F test/json/json-generator.tcl dc0dd0f393800c98658fc4c47eaa6af29d4e17527380cd286 F test/json/json-q1.txt 65f9d1cdcc4cffa9823fb73ed936aae5658700cd001fde448f68bfb91c807307 F test/json/json-speed-check.sh 912ee03e700a65c827ee0c7b4752c21ec5ef69cf7679d2f482ca817042bead52 x F test/json/jsonb-q1.txt 1e180fe6491efab307e318b22879e3a736ac9a96539bbde7911a13ee5b33abc7 -F test/json101.test 70587d7d35ef9e2126364ba70f0c951f70827cfbd28649d779ff3df7e8f87547 +F test/json101.test 30db5b055b103ccabc53a29cfe6cda3345d07e171aeb25403dafa04f19e98b19 F test/json102.test 557a46e16df1aa9bdbc4076a71a45814ea0e7503d6621d87d42a8c04cbc2b0ef F test/json103.test 53df87f83a4e5fa0c0a56eb29ff6c94055c6eb919f33316d62161a8880112dbe F test/json104.test 1b844a70cddcfa2e4cd81a5db0657b2e61e7f00868310f24f56a9ba0114348c1 @@ -2162,8 +2162,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 7d750248c58ccbf87036ea7db053def1c83c7a8ed428a5c47895756302b36200 -R 6ea6e9f84387bdd065f35367386a097e -U larrybr -Z 849b6ec66e03430774f8a485b79fa305 +P 670174916c660b24ba70e96a42984eb65ee52da50e9828bdeca4c9ff4bf92e20 +R e9613550f9ab9d1defe8fcc96e4778a1 +U drh +Z a380dd04602de7f2ac17d4bbe29cc262 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 7e879107f6..b30f95cb8a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -670174916c660b24ba70e96a42984eb65ee52da50e9828bdeca4c9ff4bf92e20 \ No newline at end of file +1c33c5db2e05019d1a375109f79ad8588a3c17f81e4f4b8d66c880c3c860e87e \ No newline at end of file diff --git a/src/json.c b/src/json.c index 3aa4b4e500..c33b63556a 100644 --- a/src/json.c +++ b/src/json.c @@ -4944,6 +4944,9 @@ static int jsonEachColumn( case JEACH_VALUE: { u32 i = jsonSkipLabel(p); jsonReturnFromBlob(&p->sParse, i, ctx, 1); + if( (p->sParse.aBlob[i] & 0x0f)>=JSONB_ARRAY ){ + sqlite3_result_subtype(ctx, JSON_SUBTYPE); + } break; } case JEACH_TYPE: { diff --git a/test/json101.test b/test/json101.test index bae68e7344..3963ffbb6b 100644 --- a/test/json101.test +++ b/test/json101.test @@ -378,6 +378,20 @@ do_execsql_test json101-5.8 { WHERE jx.value<>jx.atom AND type NOT IN ('array','object'); } {} +# 2024-02-16 https://sqlite.org/forum/forumpost/ecb94cd210 +# Regression in json_tree()/json_each(). The value column +# should have the "J" subtype if the value is an array or +# object. +# +do_execsql_test json101-5.10 { + SELECT json_insert('{}','$.a',value) FROM json_tree('[1,2,3]') WHERE atom IS NULL; +} {{{"a":[1,2,3]}}} +# ^^^^^^^--- In double-quotes, a string literal, prior to bug fix + +do_execsql_test json101-5.11 { + SELECT json_insert('{}','$.a',value) FROM json_tree('"[1,2,3]"'); +} {{{"a":"[1,2,3]"}}} + do_execsql_test json101-6.1 { SELECT json_valid('{"a":55,"b":72,}'); } {0} From 837efb4cbe1fa71b991f42efa9f9057fcf4a7c6b Mon Sep 17 00:00:00 2001 From: drh <> Date: Sat, 17 Feb 2024 01:12:58 +0000 Subject: [PATCH 107/430] The PRAGMA optimize command invokes ANALYZE if a table shrinks by 25 times in addition to if it grows by 25 times. FossilOrigin-Name: 40532ffba91cf332c1ea4add80184031a9d6e10514d2d9b9a6cfd613091b81f7 --- manifest | 17 ++++++++++------- manifest.uuid | 2 +- src/pragma.c | 13 ++++++++----- src/vdbe.c | 21 +++++++++++++++------ 4 files changed, 34 insertions(+), 19 deletions(-) diff --git a/manifest b/manifest index 8a1169a17b..3582a19a3e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\ssubtype\son\sthe\svalue\scolumn\sfrom\sjson_each/json_tree\sfor\scases\nwhen\sthe\svalue\sis\san\sarray\sor\sobject.\s\sFix\sfor\sthe\sbug\sreported\sby\n[forum:/forumpost/ecb94cd210|forum\spost\secb94cd210]. -D 2024-02-16T21:30:08.580 +C The\sPRAGMA\soptimize\scommand\sinvokes\sANALYZE\sif\sa\stable\sshrinks\sby\s25\stimes\nin\saddition\sto\sif\sit\sgrows\sby\s25\stimes. +D 2024-02-17T01:12:58.951 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -732,7 +732,7 @@ F src/parse.y bfd6da46fc895cd8237400ff485d04ab0b32e47eb56de20982bb7f53e56c1f42 F src/pcache.c 040b165f30622a21b7a9a77c6f2e4877a32fb7f22d4c7f0d2a6fa6833a156a75 F src/pcache.h 1497ce1b823cf00094bb0cf3bac37b345937e6f910890c626b16512316d3abf5 F src/pcache1.c 602acb23c471bb8d557a6f0083cc2be641d6cafcafa19e481eba7ef4c9ca0f00 -F src/pragma.c 24584cc928538426e047db670f21f3816286812e48dfd391a40e788f14d3cea2 +F src/pragma.c 2a49dd92e9f14eb7433c06d02f5d02b7e2890b05117e7c5be103a9da1251ba0d F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7 F src/prepare.c 371f6115cb69286ebc12c6f2d7511279c2e47d9f54f475d46a554d687a3b312c F src/printf.c 18fbdf028345c8fbe6044f5f5bfda5a10d48d6287afef088cc21b0ca57985640 @@ -809,7 +809,7 @@ F src/upsert.c fa125a8d3410ce9a97b02cb50f7ae68a2476c405c76aa692d3acf6b8586e9242 F src/utf.c f23165685a67b4caf8ec08fb274cb3f319103decfb2a980b7cfd55d18dfa855e F src/util.c 078f040366d5bd5f47658d045f901c768c1c636c6eaea121f3a1cbd63c3edb5b F src/vacuum.c 604fcdaebe76f3497c855afcbf91b8fa5046b32de3045bab89cc008d68e40104 -F src/vdbe.c dd340f5add924a8397401f7fe4faf2304ffd49ab5853d32ffc1736093b9c5080 +F src/vdbe.c a9b83d5ecd34d7e9d50dc7b643351541ddac74b5e2b19770cb3f2686cb815066 F src/vdbe.h 88e19a982df9027ec1c177c793d1a5d34dc23d8f06e3b2d997f43688b05ee0eb F src/vdbeInt.h 949669dfd8a41550d27dcb905b494f2ccde9a2e6c1b0b04daa1227e2e74c2b2c F src/vdbeapi.c 8f57d60c89da0b60e6d4e272358c511f6bae4e24330bdb11f8b42f986d1bf21b @@ -2162,8 +2162,11 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 670174916c660b24ba70e96a42984eb65ee52da50e9828bdeca4c9ff4bf92e20 -R e9613550f9ab9d1defe8fcc96e4778a1 +P 1c33c5db2e05019d1a375109f79ad8588a3c17f81e4f4b8d66c880c3c860e87e +R 56c40cfd7fd1a612586d6162b2f4f953 +T *branch * optimize-after-shrink +T *sym-optimize-after-shrink * +T -sym-trunk * U drh -Z a380dd04602de7f2ac17d4bbe29cc262 +Z ebc951629700e2b49319b3c4b80fffe0 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index b30f95cb8a..942fd1732c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1c33c5db2e05019d1a375109f79ad8588a3c17f81e4f4b8d66c880c3c860e87e \ No newline at end of file +40532ffba91cf332c1ea4add80184031a9d6e10514d2d9b9a6cfd613091b81f7 \ No newline at end of file diff --git a/src/pragma.c b/src/pragma.c index 872177e131..367c9fba2f 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -2453,17 +2453,20 @@ void sqlite3Pragma( if( (pTab->tabFlags & TF_MaybeReanalyze)==0 ) continue; /* Reanalyze if the table is 25 times larger than the last analysis */ - szThreshold = pTab->nRowLogEst + 46; assert( sqlite3LogEst(25)==46 ); + szThreshold = pTab->nRowLogEst; for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ if( !pIdx->hasStat1 ){ - szThreshold = 0; /* Always analyze if any index lacks statistics */ + szThreshold = -1; /* Always analyze if any index lacks statistics */ break; } } - if( szThreshold ){ + if( szThreshold>=0 ){ sqlite3OpenTable(pParse, iTabCur, iDb, pTab, OP_OpenRead); - sqlite3VdbeAddOp3(v, OP_IfSmaller, iTabCur, - sqlite3VdbeCurrentAddr(v)+2+(opMask&1), szThreshold); + sqlite3VdbeAddOp4Int(v, OP_IfSizeBetween, iTabCur, + sqlite3VdbeCurrentAddr(v)+3+(opMask&1), + szThreshold>=46 ? szThreshold-46 : -1, + szThreshold+46); + sqlite3VdbeAddOp1(v, OP_Close, iTabCur); VdbeCoverage(v); } zSubSql = sqlite3MPrintf(db, "ANALYZE \"%w\".\"%w\"", diff --git a/src/vdbe.c b/src/vdbe.c index 1e0d776536..da3eeeae91 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -6192,28 +6192,37 @@ case OP_Last: { /* jump, ncycle */ break; } -/* Opcode: IfSmaller P1 P2 P3 * * +/* Opcode: IfSizeBetween P1 P2 P3 P4 * ** -** Estimate the number of rows in the table P1. Jump to P2 if that -** estimate is less than approximately 2**(0.1*P3). +** Let N be the approximate number of rows in the table or index +** with cursor P1 and let X be 10*log2(N) if N is positive or -1 +** if N is zero. Thus X will be within the range of -1 to 640, inclusive +** Jump to P2 if X is in between P3 and P4, inclusive. */ -case OP_IfSmaller: { /* jump */ +case OP_IfSizeBetween: { /* jump */ VdbeCursor *pC; BtCursor *pCrsr; int res; i64 sz; assert( pOp->p1>=0 && pOp->p1nCursor ); + assert( pOp->p4type==P4_INT32 ); + assert( pOp->p3>=-1 && pOp->p3<=640 ); + assert( pOp->p4.i>=-1 && pOp->p4.i<=640 ); pC = p->apCsr[pOp->p1]; assert( pC!=0 ); pCrsr = pC->uc.pCursor; assert( pCrsr ); rc = sqlite3BtreeFirst(pCrsr, &res); if( rc ) goto abort_due_to_error; - if( res==0 ){ + if( res!=0 ){ + sz = -1; /* -Infinity encoding */ + }else{ sz = sqlite3BtreeRowCountEst(pCrsr); - if( ALWAYS(sz>=0) && sqlite3LogEst((u64)sz)p3 ) res = 1; + assert( sz>0 ); + sz = sqlite3LogEst((u64)sz); } + res = sz>=pOp->p3 && sz<=pOp->p4.i; VdbeBranchTaken(res!=0,2); if( res ) goto jump_to_p2; break; From 6161cdd446eec170f7c0edf58d0d72a2cd3c5f85 Mon Sep 17 00:00:00 2001 From: drh <> Date: Sat, 17 Feb 2024 03:32:31 +0000 Subject: [PATCH 108/430] Fix rounding in zero-precision %f and %g printf conversions. [forum:/info/393708f4a8|Forum post 393708f4a8]. This bug was introduced by check-in [32befb224b254639] and first appeared in version 3.43.0. FossilOrigin-Name: 7fca1bc482fc2456d75392eb42f768fda72631c9070de46b8123b1126e78306f --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/printf.c | 1 + src/util.c | 2 +- test/printf.test | 17 +++++++++++++++++ 5 files changed, 28 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 8a1169a17b..ab0f22bde5 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\ssubtype\son\sthe\svalue\scolumn\sfrom\sjson_each/json_tree\sfor\scases\nwhen\sthe\svalue\sis\san\sarray\sor\sobject.\s\sFix\sfor\sthe\sbug\sreported\sby\n[forum:/forumpost/ecb94cd210|forum\spost\secb94cd210]. -D 2024-02-16T21:30:08.580 +C Fix\srounding\sin\szero-precision\s%f\sand\s%g\sprintf\sconversions.\n[forum:/info/393708f4a8|Forum\spost\s393708f4a8].\s\sThis\sbug\swas\nintroduced\sby\scheck-in\s[32befb224b254639]\sand\sfirst\sappeared\sin\sversion\s3.43.0. +D 2024-02-17T03:32:31.878 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -735,7 +735,7 @@ F src/pcache1.c 602acb23c471bb8d557a6f0083cc2be641d6cafcafa19e481eba7ef4c9ca0f00 F src/pragma.c 24584cc928538426e047db670f21f3816286812e48dfd391a40e788f14d3cea2 F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7 F src/prepare.c 371f6115cb69286ebc12c6f2d7511279c2e47d9f54f475d46a554d687a3b312c -F src/printf.c 18fbdf028345c8fbe6044f5f5bfda5a10d48d6287afef088cc21b0ca57985640 +F src/printf.c d3392b2a20ee314ddeef34fb43c904bf4619eb20ff9a9e07e3950a7e4dcd6912 F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c d77c6160bc8f249c2196fdd3e75f66a1dd70e37aa25c39aedc7b1f93c42b7c6d F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 @@ -807,7 +807,7 @@ F src/trigger.c 0905b96b04bb6658509f711a8207287f1315cdbc3df1a1b13ba6483c8e341c81 F src/update.c 6904814dd62a7a93bbb86d9f1419c7f134a9119582645854ab02b36b676d9f92 F src/upsert.c fa125a8d3410ce9a97b02cb50f7ae68a2476c405c76aa692d3acf6b8586e9242 F src/utf.c f23165685a67b4caf8ec08fb274cb3f319103decfb2a980b7cfd55d18dfa855e -F src/util.c 078f040366d5bd5f47658d045f901c768c1c636c6eaea121f3a1cbd63c3edb5b +F src/util.c 3ed7ded64ecc8670acdcbb72e8df9b0a58845cb0c36639573eb0d5155121901a F src/vacuum.c 604fcdaebe76f3497c855afcbf91b8fa5046b32de3045bab89cc008d68e40104 F src/vdbe.c dd340f5add924a8397401f7fe4faf2304ffd49ab5853d32ffc1736093b9c5080 F src/vdbe.h 88e19a982df9027ec1c177c793d1a5d34dc23d8f06e3b2d997f43688b05ee0eb @@ -1489,7 +1489,7 @@ F test/pragma4.test ca5e4dfc46adfe490f75d73734f70349d95a199e6510973899e502eef2c8 F test/pragma5.test 7b33fc43e2e41abf17f35fb73f71b49671a380ea92a6c94b6ce530a25f8d9102 F test/pragmafault.test 275edaf3161771d37de60e5c2b412627ac94cef11739236bec12ed1258b240f8 F test/prefixes.test b524a1c44bffec225b9aec98bd728480352aa8532ac4c15771fb85e8beef65d9 -F test/printf.test 512152dca7f2f578f045a5a732e7bee08e4f47a8a212f83ce46791b518eba70f +F test/printf.test 685fec5a0c5af2490ab0632775a301554361d674211d690f5bee0a97b05333de F test/printf2.test 3f55c1871a5a65507416076f6eb97e738d5210aeda7595a74ee895f2224cce60 F test/progress.test ebab27f670bd0d4eb9d20d49cef96e68141d92fb F test/ptrchng.test ef1aa72d6cf35a2bbd0869a649b744e9d84977fc @@ -2162,8 +2162,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 670174916c660b24ba70e96a42984eb65ee52da50e9828bdeca4c9ff4bf92e20 -R e9613550f9ab9d1defe8fcc96e4778a1 +P 1c33c5db2e05019d1a375109f79ad8588a3c17f81e4f4b8d66c880c3c860e87e +R e3e534a124d08ab0760f858683268942 U drh -Z a380dd04602de7f2ac17d4bbe29cc262 +Z 25ef9b1be0189ee473aa53bd8732a56c # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index b30f95cb8a..1e28ec46dd 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1c33c5db2e05019d1a375109f79ad8588a3c17f81e4f4b8d66c880c3c860e87e \ No newline at end of file +7fca1bc482fc2456d75392eb42f768fda72631c9070de46b8123b1126e78306f \ No newline at end of file diff --git a/src/printf.c b/src/printf.c index c6b3803ca9..2e09431bf2 100644 --- a/src/printf.c +++ b/src/printf.c @@ -498,6 +498,7 @@ void sqlite3_str_vappendf( if( xtype==etFLOAT ){ iRound = -precision; }else if( xtype==etGENERIC ){ + if( precision==0 ) precision = 1; iRound = precision; }else{ iRound = precision+1; diff --git a/src/util.c b/src/util.c index 207b901bad..4aa82d0636 100644 --- a/src/util.c +++ b/src/util.c @@ -1069,7 +1069,7 @@ void sqlite3FpDecode(FpDecode *p, double r, int iRound, int mxRound){ assert( p->n>0 ); assert( p->nzBuf) ); p->iDP = p->n + exp; - if( iRound<0 ){ + if( iRound<=0 ){ iRound = p->iDP - iRound; if( iRound==0 && p->zBuf[i+1]>='5' ){ iRound = 1; diff --git a/test/printf.test b/test/printf.test index 6d4ad71d28..cc439e6172 100644 --- a/test/printf.test +++ b/test/printf.test @@ -3833,4 +3833,21 @@ do_execsql_test printf-18.1 { SELECT length( format('%,.249f', -5.0e-300) ); } {252} +# 2024-02-16 +# https://sqlite.org/forum/info/393708f4a8 +# +# The problem introduced by on 2023-07-03 by +# https://sqlite.org/src/info/32befb224b254639 +# +do_execsql_test printf-19.1 { + SELECT format('%0.0f %0.0g %0.0g', 0.9, 0.09, 1.9); +} {{1 0.09 2}} +do_execsql_test printf-19.2 { + SELECT format('%0.0f %#0.0f',0.0, 0.0); +} {{0 0.}} +do_execsql_test printf-19.3 { + SELECT format('%,.0f %,.0f',12345e+10, 12345e+11); +} {{123,450,000,000,000 1,234,500,000,000,000}} + + finish_test From 42eb6a91cdb5fe221171e7a0e588abd73d50542d Mon Sep 17 00:00:00 2001 From: drh <> Date: Sat, 17 Feb 2024 16:39:52 +0000 Subject: [PATCH 109/430] Add new MASK bits to PRAGMA optimize: 0x70000. FossilOrigin-Name: dd4497062569eec9ddfdaa7d6394c83ff40a7a59c6697a161bc4ff6d8af3bb29 --- manifest | 19 +++++------ manifest.uuid | 2 +- src/build.c | 4 +-- src/pragma.c | 94 ++++++++++++++++++++++++++++++++++++--------------- src/vdbe.c | 21 +++++++++--- 5 files changed, 94 insertions(+), 46 deletions(-) diff --git a/manifest b/manifest index 3582a19a3e..18e8630874 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C The\sPRAGMA\soptimize\scommand\sinvokes\sANALYZE\sif\sa\stable\sshrinks\sby\s25\stimes\nin\saddition\sto\sif\sit\sgrows\sby\s25\stimes. -D 2024-02-17T01:12:58.951 +C Add\snew\sMASK\sbits\sto\sPRAGMA\soptimize:\s\s0x70000. +D 2024-02-17T16:39:52.117 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -681,7 +681,7 @@ F src/btmutex.c 79a43670447eacc651519a429f6ece9fd638563cf95b469d6891185ddae2b522 F src/btree.c dfd351decf9f819393dae8fb7294cae69c3818069d27f47fee34d5b505e37b47 F src/btree.h 03e3356f5208bcab8eed4e094240fdac4a7f9f5ddf5e91045ce589f67d47c240 F src/btreeInt.h 3e2589726c4f105e653461814f65857465da68be1fac688de340c43b873f4062 -F src/build.c 05c9eb387638982092988d2ef4c00a91b0c29baa1b85923f082ce0cf2903ea7e +F src/build.c 04f1bcee189f045ab086d84fee95db42cb49df82ff8e84af8136309ff3c8a75f F src/callback.c db3a45e376deff6a16c0058163fe0ae2b73a2945f3f408ca32cf74960b28d490 F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e F src/ctime.c 23331529e654be40ca97d171cbbffe9b3d4c71cc53b78fe5501230675952da8b @@ -732,7 +732,7 @@ F src/parse.y bfd6da46fc895cd8237400ff485d04ab0b32e47eb56de20982bb7f53e56c1f42 F src/pcache.c 040b165f30622a21b7a9a77c6f2e4877a32fb7f22d4c7f0d2a6fa6833a156a75 F src/pcache.h 1497ce1b823cf00094bb0cf3bac37b345937e6f910890c626b16512316d3abf5 F src/pcache1.c 602acb23c471bb8d557a6f0083cc2be641d6cafcafa19e481eba7ef4c9ca0f00 -F src/pragma.c 2a49dd92e9f14eb7433c06d02f5d02b7e2890b05117e7c5be103a9da1251ba0d +F src/pragma.c c5b767e7538a808fac4f17f8891acb1f14b4eed3458d971ddea4dd82f7623e0c F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7 F src/prepare.c 371f6115cb69286ebc12c6f2d7511279c2e47d9f54f475d46a554d687a3b312c F src/printf.c 18fbdf028345c8fbe6044f5f5bfda5a10d48d6287afef088cc21b0ca57985640 @@ -809,7 +809,7 @@ F src/upsert.c fa125a8d3410ce9a97b02cb50f7ae68a2476c405c76aa692d3acf6b8586e9242 F src/utf.c f23165685a67b4caf8ec08fb274cb3f319103decfb2a980b7cfd55d18dfa855e F src/util.c 078f040366d5bd5f47658d045f901c768c1c636c6eaea121f3a1cbd63c3edb5b F src/vacuum.c 604fcdaebe76f3497c855afcbf91b8fa5046b32de3045bab89cc008d68e40104 -F src/vdbe.c a9b83d5ecd34d7e9d50dc7b643351541ddac74b5e2b19770cb3f2686cb815066 +F src/vdbe.c 6d2aecc9ab2f9db557b4841775d016e2697ff6312242e9a492cdf3e2529dffa6 F src/vdbe.h 88e19a982df9027ec1c177c793d1a5d34dc23d8f06e3b2d997f43688b05ee0eb F src/vdbeInt.h 949669dfd8a41550d27dcb905b494f2ccde9a2e6c1b0b04daa1227e2e74c2b2c F src/vdbeapi.c 8f57d60c89da0b60e6d4e272358c511f6bae4e24330bdb11f8b42f986d1bf21b @@ -2162,11 +2162,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 1c33c5db2e05019d1a375109f79ad8588a3c17f81e4f4b8d66c880c3c860e87e -R 56c40cfd7fd1a612586d6162b2f4f953 -T *branch * optimize-after-shrink -T *sym-optimize-after-shrink * -T -sym-trunk * +P 40532ffba91cf332c1ea4add80184031a9d6e10514d2d9b9a6cfd613091b81f7 +R 518017150456f4f932816e90c763b561 U drh -Z ebc951629700e2b49319b3c4b80fffe0 +Z 4ff4c253b76c891ec5769cfa9bfe8766 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 942fd1732c..c4b9f73820 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -40532ffba91cf332c1ea4add80184031a9d6e10514d2d9b9a6cfd613091b81f7 \ No newline at end of file +dd4497062569eec9ddfdaa7d6394c83ff40a7a59c6697a161bc4ff6d8af3bb29 \ No newline at end of file diff --git a/src/build.c b/src/build.c index cfa2c886c5..15f8fe1d24 100644 --- a/src/build.c +++ b/src/build.c @@ -2923,11 +2923,11 @@ void sqlite3EndTable( /* Test for cycles in generated columns and illegal expressions ** in CHECK constraints and in DEFAULT clauses. */ if( p->tabFlags & TF_HasGenerated ){ - sqlite3VdbeAddOp4(v, OP_SqlExec, 1, 0, 0, + sqlite3VdbeAddOp4(v, OP_SqlExec, 0x0001, 0, 0, sqlite3MPrintf(db, "SELECT*FROM\"%w\".\"%w\"", db->aDb[iDb].zDbSName, p->zName), P4_DYNAMIC); } - sqlite3VdbeAddOp4(v, OP_SqlExec, 1, 0, 0, + sqlite3VdbeAddOp4(v, OP_SqlExec, 0x0001, 0, 0, sqlite3MPrintf(db, "PRAGMA \"%w\".integrity_check(%Q)", db->aDb[iDb].zDbSName, p->zName), P4_DYNAMIC); } diff --git a/src/pragma.c b/src/pragma.c index 367c9fba2f..40a31846bb 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -2383,44 +2383,57 @@ void sqlite3Pragma( ** ** The optional argument is a bitmask of optimizations to perform: ** - ** 0x0001 Debugging mode. Do not actually perform any optimizations - ** but instead return one line of text for each optimization - ** that would have been done. Off by default. + ** 0x00001 Debugging mode. Do not actually perform any optimizations + ** but instead return one line of text for each optimization + ** that would have been done. Off by default. ** - ** 0x0002 Run ANALYZE on tables that might benefit. On by default. - ** See below for additional information. + ** 0x00002 Run ANALYZE on tables that might benefit. On by default. + ** See below for additional information. ** - ** 0x0004 (Not yet implemented) Record usage and performance - ** information from the current session in the - ** database file so that it will be available to "optimize" - ** pragmas run by future database connections. + ** 0x10000 Look at tables to see if they need to be reanalyzed + ** even if they have not been queried during the current + ** connection. Off by default. ** - ** 0x0008 (Not yet implemented) Create indexes that might have - ** been helpful to recent queries + ** 0x20000 Run all ANALYZE operations using an analysis_limit that + ** is the lessor of the current analysis_limit and the + ** SQLITE_DEFAULT_OPTIMIZE_LIMIT compile-time option, + ** nominally 400. Off by default. ** - ** The default MASK is and always shall be 0xfffe. 0xfffe means perform all - ** of the optimizations listed above except Debug Mode, including new - ** optimizations that have not yet been invented. If new optimizations are - ** ever added that should be off by default, those off-by-default - ** optimizations will have bitmasks of 0x10000 or larger. + ** 0x40000 Tables become candidates for reanalysis if their size + ** grows or shrinks by 10x. Without this option, they + ** become candidates for reanalysis if their size grows + ** or shrinks by 25x. Off (25x mode) by default. + ** + ** The default MASK is and always shall be 0x0fffe. In the current + ** implementation, the default mask only covers the 0x00002 optimization, + ** though additional optimizations that are covered by 0x0fffe might be + ** added in the future. Optimizations that are off by default and must + ** be explicitly requested have masks of 0x10000 or greater. ** ** DETERMINATION OF WHEN TO RUN ANALYZE ** ** In the current implementation, a table is analyzed if only if all of ** the following are true: ** - ** (1) MASK bit 0x02 is set. + ** (1) MASK bit 0x00002 is set. ** - ** (2) The query planner used sqlite_stat1-style statistics for one or - ** more indexes of the table at some point during the lifetime of - ** the current connection. + ** (2) Either the 0x10000 MASK bit is set or else the query planner used + ** sqlite_stat1-style statistics for one or more indexes of the table + ** at some point during the lifetime of the current connection. ** ** (3) One or more indexes of the table are currently unanalyzed OR - ** the number of rows in the table has increased by 25 times or more + ** the number of rows in the table has increased or decreased + ** 25 times or more (10 times or more if the 0x40000 bit is set) ** since the last time ANALYZE was run. ** + ** (4) The table is an ordinary table, not a virtual table or view. + ** + ** (5) The table name does not begin with "sqlite_". + ** ** The rules for when tables are analyzed are likely to change in - ** future releases. + ** future releases. Future versions of SQLite might accept a string + ** literal argument to this pragma that contains a mnemonic description + ** of the options rather than a bitmap. */ case PragTyp_OPTIMIZE: { int iDbLast; /* Loop termination point for the schema loop */ @@ -2432,6 +2445,11 @@ void sqlite3Pragma( LogEst szThreshold; /* Size threshold above which reanalysis needed */ char *zSubSql; /* SQL statement for the OP_SqlExec opcode */ u32 opMask; /* Mask of operations to perform */ + int nLimit; /* Analysis limit to use */ + +#ifndef SQLITE_DEFAULT_OPTIMIZE_LIMIT +# define SQLITE_DEFAULT_OPTIMIZE_LIMIT 400 +#endif if( zRight ){ opMask = (u32)sqlite3Atoi(zRight); @@ -2439,6 +2457,14 @@ void sqlite3Pragma( }else{ opMask = 0xfffe; } + if( (opMask & 0x20000)==0 ){ + nLimit = 0; + }else if( db->nAnalysisLimit>0 + && db->nAnalysisLimitnTab++; for(iDbLast = zDb?iDb:db->nDb-1; iDb<=iDbLast; iDb++){ if( iDb==1 ) continue; @@ -2447,10 +2473,20 @@ void sqlite3Pragma( for(k=sqliteHashFirst(&pSchema->tblHash); k; k=sqliteHashNext(k)){ pTab = (Table*)sqliteHashData(k); + /* This only works for ordinary tables */ + if( !IsOrdinaryTable(pTab) ) continue; + + /* Do not scan system tables */ + if( 0==sqlite3StrNICmp(pTab->zName, "sqlite_", 7) ) continue; + /* If table pTab has not been used in a way that would benefit from - ** having analysis statistics during the current session, then skip it. - ** This also has the effect of skipping virtual tables and views */ - if( (pTab->tabFlags & TF_MaybeReanalyze)==0 ) continue; + ** having analysis statistics during the current session, then skip it, + ** unless the 0x10000 MASK bit is set. */ + if( (pTab->tabFlags & TF_MaybeReanalyze)==0 + && (opMask & 0x10000)==0 + ){ + continue; + } /* Reanalyze if the table is 25 times larger than the last analysis */ szThreshold = pTab->nRowLogEst; @@ -2461,11 +2497,12 @@ void sqlite3Pragma( } } if( szThreshold>=0 ){ + LogEst iRange = (opMask & 0x40000) ? 33 : 46; sqlite3OpenTable(pParse, iTabCur, iDb, pTab, OP_OpenRead); sqlite3VdbeAddOp4Int(v, OP_IfSizeBetween, iTabCur, sqlite3VdbeCurrentAddr(v)+3+(opMask&1), - szThreshold>=46 ? szThreshold-46 : -1, - szThreshold+46); + szThreshold>=iRange ? szThreshold-iRange : -1, + szThreshold+iRange); sqlite3VdbeAddOp1(v, OP_Close, iTabCur); VdbeCoverage(v); } @@ -2476,7 +2513,8 @@ void sqlite3Pragma( sqlite3VdbeAddOp4(v, OP_String8, 0, r1, 0, zSubSql, P4_DYNAMIC); sqlite3VdbeAddOp2(v, OP_ResultRow, r1, 1); }else{ - sqlite3VdbeAddOp4(v, OP_SqlExec, 0, 0, 0, zSubSql, P4_DYNAMIC); + sqlite3VdbeAddOp4(v, OP_SqlExec, nLimit ? 0x02 : 00, nLimit, 0, + zSubSql, P4_DYNAMIC); } } } diff --git a/src/vdbe.c b/src/vdbe.c index da3eeeae91..3b52c13fa7 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -6922,11 +6922,18 @@ case OP_CreateBtree: { /* out2 */ break; } -/* Opcode: SqlExec * * * P4 * +/* Opcode: SqlExec P1 P2 * P4 * ** ** Run the SQL statement or statements specified in the P4 string. -** Disable Auth and Trace callbacks while those statements are running if -** P1 is true. +** +** The P1 parameter is a bitmask of options: +** +** 0x0001 Disable Auth and Trace callbacks while the statements +** in P4 are running. +** +** 0x0002 Set db->nAnalysisLimit to P2 while the statements in +** P4 are running. +** */ case OP_SqlExec: { char *zErr; @@ -6934,6 +6941,7 @@ case OP_SqlExec: { sqlite3_xauth xAuth; #endif u8 mTrace; + int savedAnalysisLimit; sqlite3VdbeIncrWriteCounter(p, 0); db->nSqlExec++; @@ -6942,18 +6950,23 @@ case OP_SqlExec: { xAuth = db->xAuth; #endif mTrace = db->mTrace; - if( pOp->p1 ){ + savedAnalysisLimit = db->nAnalysisLimit; + if( pOp->p1 & 0x0001 ){ #ifndef SQLITE_OMIT_AUTHORIZATION db->xAuth = 0; #endif db->mTrace = 0; } + if( pOp->p1 & 0x0002 ){ + db->nAnalysisLimit = pOp->p2; + } rc = sqlite3_exec(db, pOp->p4.z, 0, 0, &zErr); db->nSqlExec--; #ifndef SQLITE_OMIT_AUTHORIZATION db->xAuth = xAuth; #endif db->mTrace = mTrace; + db->nAnalysisLimit = savedAnalysisLimit; if( zErr || rc ){ sqlite3VdbeError(p, "%s", zErr); sqlite3_free(zErr); From 99a94a124c6ff0b0428fa6ff7e880443edef8dcb Mon Sep 17 00:00:00 2001 From: dan Date: Sat, 17 Feb 2024 20:55:01 +0000 Subject: [PATCH 110/430] Add start of extension for incremental integrity-checks to ext/intck/. FossilOrigin-Name: 444e3c9210026da7eae1ed98850722e002433aa2cc77dbc6b6f80327a6b7a390 --- Makefile.in | 2 + Makefile.msc | 2 + ext/intck/intck1.test | 192 +++++++++++ ext/intck/intck2.test | 70 ++++ ext/intck/intck_common.tcl | 49 +++ ext/intck/sqlite3intck.c | 647 +++++++++++++++++++++++++++++++++++++ ext/intck/sqlite3intck.h | 55 ++++ ext/intck/test_intck.c | 185 +++++++++++ main.mk | 4 +- manifest | 29 +- manifest.uuid | 2 +- src/test_tclsh.c | 2 + 12 files changed, 1227 insertions(+), 12 deletions(-) create mode 100644 ext/intck/intck1.test create mode 100644 ext/intck/intck2.test create mode 100644 ext/intck/intck_common.tcl create mode 100644 ext/intck/sqlite3intck.c create mode 100644 ext/intck/sqlite3intck.h create mode 100644 ext/intck/test_intck.c diff --git a/Makefile.in b/Makefile.in index cb894666d9..509ad4884f 100644 --- a/Makefile.in +++ b/Makefile.in @@ -418,6 +418,8 @@ TESTSRC = \ $(TOP)/ext/recover/sqlite3recover.c \ $(TOP)/ext/recover/dbdata.c \ $(TOP)/ext/recover/test_recover.c \ + $(TOP)/ext/intck/test_intck.c \ + $(TOP)/ext/intck/sqlite3intck.c \ $(TOP)/ext/rbu/test_rbu.c # Statically linked extensions diff --git a/Makefile.msc b/Makefile.msc index 19bfe2f386..7d9dbd2c2b 100644 --- a/Makefile.msc +++ b/Makefile.msc @@ -1595,6 +1595,8 @@ TESTEXT = \ $(TOP)\ext\rtree\test_rtreedoc.c \ $(TOP)\ext\recover\sqlite3recover.c \ $(TOP)\ext\recover\test_recover.c \ + $(TOP)\ext\intck\test_intck.c \ + $(TOP)\ext\intck\sqlite3intck.c \ $(TOP)\ext\recover\dbdata.c # If use of zlib is enabled, add the "zipfile.c" source file. diff --git a/ext/intck/intck1.test b/ext/intck/intck1.test new file mode 100644 index 0000000000..c46a7d6b2d --- /dev/null +++ b/ext/intck/intck1.test @@ -0,0 +1,192 @@ +# 2008 Feb 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. +# +#*********************************************************************** +# +# The focus of this file is testing the r-tree extension. +# + +source [file join [file dirname [info script]] intck_common.tcl] +set testprefix intck1 + +foreach {tn sql} { + 1 "CREATE TABLE t1(a PRIMARY KEY, b)" + 2 "CREATE TABLE t2(a PRIMARY KEY, b) WITHOUT ROWID " + 3 "CREATE TABLE t3(a PRIMARY KEY, b) WITHOUT rowID;" + 4 "CREATE TABLE t4(a PRIMARY KEY, ROWID)" + 5 {CREATE TABLE t5(a PRIMARY KEY, ROWID) WITHOUT ROWID + } +} { + do_test 1.1.$tn { + db eval $sql + set {} {} + } {} +} + +set space " \n\v\t\r\f" + +do_execsql_test 1.2 { + SELECT name, (rtrim(sql, $space) LIKE '%rowid') + FROM sqlite_schema WHERE type='table' + ORDER BY 1 +} { + t1 0 + t2 1 + t3 1 + t4 0 + t5 1 +} + +do_execsql_test 1.3 { + CREATE TABLE x1(a COLLATE nocase, b INTEGER, c BLOB); + INSERT INTO x1 VALUES('lEtTeRs', 1234, 1234); +} +do_execsql_test 1.3.1 { + WITH wrapper(c1, c2, c3) AS ( + SELECT a, b, c FROM x1 + ) + SELECT * FROM wrapper WHERE c1='letters'; +} {lEtTeRs 1234 1234} +do_execsql_test 1.3.2 { + WITH wrapper(c1, c2, c3) AS ( + SELECT a, b, c FROM x1 + ) + SELECT * FROM wrapper WHERE c2='1234'; +} {lEtTeRs 1234 1234} +do_execsql_test 1.3.2 { + WITH wrapper(c1, c2, c3) AS ( + SELECT a, b, c FROM x1 + ) + SELECT * FROM wrapper WHERE c3='1234'; +} {} + +do_execsql_test 1.4 { + CREATE TABLE z1(a, b); + CREATE INDEX z1ab ON z1(a+b COLLATE nocase); +} +do_execsql_test 1.4.1 { + SELECT * FROM z1 INDEXED BY z1ab +} + +do_catchsql_test 1.5.1 { + CREATE INDEX z1b ON z1(b ASC NULLS LAST); +} {1 {unsupported use of NULLS LAST}} +do_catchsql_test 1.5.2 { + CREATE INDEX z1b ON z1(b DESC NULLS LAST); +} {1 {unsupported use of NULLS LAST}} +do_catchsql_test 1.5.3 { + CREATE INDEX z1b ON z1(b ASC NULLS FIRST); +} {1 {unsupported use of NULLS FIRST}} +do_catchsql_test 1.5.4 { + CREATE INDEX z1b ON z1(b DESC NULLS FIRST); +} {1 {unsupported use of NULLS FIRST}} + + +#------------------------------------------------------------------------- +reset_db + +do_test 2.0 { + set ic [sqlite3_intck db main ""] + $ic close +} {} + +do_execsql_test 2.1 { + CREATE TABLE t1(a, b); + INSERT INTO t1 VALUES(1, 2); + INSERT INTO t1 VALUES(3, 4); + + CREATE INDEX i1 ON t1(a COLLATE nocase); + CREATE INDEX i2 ON t1(b, a); + CREATE INDEX i3 ON t1(b + a COLLATE nocase) WHERE a!=1; +} + +do_intck_test 2.2 { +} + +# Delete a row from each of the i1 and i2 indexes using the imposter +# table interface. +# +do_test 2.3 { + db eval {SELECT name, rootpage FROM sqlite_schema} { + set R($name) $rootpage + } + sqlite3_test_control SQLITE_TESTCTRL_IMPOSTER db main 1 $R(i1) + db eval { CREATE TABLE imp1(a PRIMARY KEY, rowid) WITHOUT ROWID; } + sqlite3_test_control SQLITE_TESTCTRL_IMPOSTER db main 1 $R(i2) + db eval { CREATE TABLE imp2(b, a, rowid, PRIMARY KEY(b, a)) WITHOUT ROWID; } + sqlite3_test_control SQLITE_TESTCTRL_IMPOSTER db main 0 0 + + db eval { + DELETE FROM imp1 WHERE rowid=1; + DELETE FROM imp2 WHERE rowid=2; + } + + db close + sqlite3 db test.db +} {} + +do_intck_test 2.4 { + {entry (1,1) missing from index i1} + {entry (4,3,2) missing from index i2} +} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 3.0 { + CREATE TABLE x1(a, b, c, PRIMARY KEY(c, b)) WITHOUT ROWID; + CREATE INDEX x1a ON x1(a COLLATE nocase); + + INSERT INTO x1 VALUES(1, 2, 'three'); + INSERT INTO x1 VALUES(4, 5, 'six'); + INSERT INTO x1 VALUES(7, 8, 'nine'); +} + +do_intck_test 3.1 { } + +do_test 3.2 { + db eval {SELECT name, rootpage FROM sqlite_schema} { + set R($name) $rootpage + } + sqlite3_test_control SQLITE_TESTCTRL_IMPOSTER db main 1 $R(x1a) + db eval { CREATE TABLE imp1(c, b, a, PRIMARY KEY(c, b)) WITHOUT ROWID } + sqlite3_test_control SQLITE_TESTCTRL_IMPOSTER db main 0 0 + + db eval { + DELETE FROM imp1 WHERE a=5; + } + execsql_pp { + } + + db close + sqlite3 db test.db +} {} + +puts "[intck_sql db x1a]" +execsql_pp "EXPLAIN QUERY PLAN [intck_sql db x1a]" +do_intck_test 3.3 { + {entry (4,'six',5) missing from index x1a} +} + +#explain_i [intck_sql db x1] +#puts [intck_sql db x1] +#puts [intck_sql db x1a] + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 4.0 { + CREATE TABLE www(x, y, z); + CREATE INDEX w1 ON www( (x+1), z ); + INSERT INTO www VALUES(1, 1, 1), (2, 2, 2); +} + +do_intck_test 4.1 { } + +finish_test + + diff --git a/ext/intck/intck2.test b/ext/intck/intck2.test new file mode 100644 index 0000000000..bc9aebeea8 --- /dev/null +++ b/ext/intck/intck2.test @@ -0,0 +1,70 @@ +# 2008 Feb 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. +# +#*********************************************************************** +# +# The focus of this file is testing the r-tree extension. +# + +source [file join [file dirname [info script]] intck_common.tcl] +set testprefix intck2 + + +do_execsql_test 1.0 { + CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT); + INSERT INTO t1 VALUES(1, 'one'); + INSERT INTO t1 VALUES(2, 'two'); + INSERT INTO t1 VALUES(3, 'three'); + CREATE INDEX i1 ON t1(b); +} + +proc imposter_edit {obj create sql} { + sqlite3 xdb test.db + set pgno [xdb one {SELECT rootpage FROM sqlite_schema WHERE name=$obj}] + + sqlite3_test_control SQLITE_TESTCTRL_IMPOSTER xdb main 1 $pgno + xdb eval $create + sqlite3_test_control SQLITE_TESTCTRL_IMPOSTER xdb main 0 0 + xdb eval $sql + xdb close +} + +imposter_edit i1 { + CREATE TABLE imp(b, a, PRIMARY KEY(b)) WITHOUT ROWID; +} { + DELETE FROM imp WHERE b='two'; + INSERT INTO imp(b, a) VALUES('four', 4); +} + +do_intck_test 1.1 { + {entry ('two',2) missing from index i1} + {surplus entry ('four',4) in index i1} +} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 2.0 { + CREATE TABLE x1(a, b, "c d"); + CREATE INDEX x1a ON x1(a COLLATE nocase DESC , b ASC); + CREATE INDEX x1b ON x1( a || b || ' "''" ' COLLATE binary ASC ); + CREATE INDEX x1c ON x1( format('%s', a)ASC, format('%d', "c d" ) ); + INSERT INTO x1 VALUES('one', 2, 3); + INSERT INTO x1 VALUES('One', 4, 5); + INSERT INTO x1 VALUES('ONE', 6, 7); + INSERT INTO x1 VALUES(NULL, NULL, NULL); +} + +do_intck_test 2.1 {} +puts [intck_sql db x1] + + + +finish_test + + diff --git a/ext/intck/intck_common.tcl b/ext/intck/intck_common.tcl new file mode 100644 index 0000000000..0763d13266 --- /dev/null +++ b/ext/intck/intck_common.tcl @@ -0,0 +1,49 @@ +# 2024 Feb 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. +# +#*********************************************************************** +# + +if {![info exists testdir]} { + set testdir [file join [file dirname [info script]] .. .. test] +} +source $testdir/tester.tcl + +proc do_intck {db} { + set ic [sqlite3_intck $db main ""] + + set ret [list] + while {"SQLITE_OK"==[$ic step]} { + set msg [$ic message] + if {$msg!=""} { + lappend ret $msg + } + } + + set err [$ic error] + if {[lindex $err 0]!="SQLITE_OK"} { + error $err + } + $ic close + + return $ret +} + +proc intck_sql {db tbl} { + set ic [sqlite3_intck $db main ""] + set sql [$ic test_sql $tbl] + $ic close + return $sql +} + +proc do_intck_test {tn expect} { + uplevel [list do_test $tn [list do_intck db] [list {*}$expect]] +} + + diff --git a/ext/intck/sqlite3intck.c b/ext/intck/sqlite3intck.c new file mode 100644 index 0000000000..7610d44a9b --- /dev/null +++ b/ext/intck/sqlite3intck.c @@ -0,0 +1,647 @@ +/* +** 2024-02-08 +** +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: +** +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. +** +************************************************************************* +*/ + +#include "sqlite3intck.h" +#include +#include +#include + +struct sqlite3_intck { + sqlite3 *db; + const char *zDb; /* Copy of zDb parameter to _open() */ + + sqlite3_stmt *pListTables; + + sqlite3_stmt *pCheck; + int nCheck; + + int rc; /* SQLite error code */ + char *zErr; /* Error message */ + + char *zTestSql; /* Returned by sqlite3_intck_test_sql() */ +}; + + +/* +** Some error has occurred while using database p->db. Save the error message +** and error code currently held by the database handle in p->rc and p->zErr. +*/ +static void intckSaveErrmsg(sqlite3_intck *p){ + const char *zDberr = sqlite3_errmsg(p->db); + p->rc = sqlite3_errcode(p->db); + if( zDberr ){ + sqlite3_free(p->zErr); + p->zErr = sqlite3_mprintf("%s", zDberr); + } +} + +static sqlite3_stmt *intckPrepare(sqlite3_intck *p, const char *zFmt, ...){ + sqlite3_stmt *pRet = 0; + va_list ap; + char *zSql = 0; + va_start(ap, zFmt); + zSql = sqlite3_vmprintf(zFmt, ap); + if( p->rc==SQLITE_OK ){ + if( zSql==0 ){ + p->rc = SQLITE_NOMEM; + }else{ + p->rc = sqlite3_prepare_v2(p->db, zSql, -1, &pRet, 0); + fflush(stdout); + if( p->rc!=SQLITE_OK ){ + printf("ERROR: %s\n", zSql); + printf("MSG: %s\n", sqlite3_errmsg(p->db)); + if( sqlite3_error_offset(p->db)>=0 ){ + int iOff = sqlite3_error_offset(p->db); + printf("AT: %.40s\n", &zSql[iOff]); + } + fflush(stdout); + intckSaveErrmsg(p); + assert( pRet==0 ); + } + } + } + sqlite3_free(zSql); + va_end(ap); + return pRet; +} + +static void intckFinalize(sqlite3_intck *p, sqlite3_stmt *pStmt){ + int rc = sqlite3_finalize(pStmt); + if( p->rc==SQLITE_OK && rc!=SQLITE_OK ){ + intckSaveErrmsg(p); + } +} + +/* +** Return an SQL statement that will itself return a single row for each +** table in the target schema. The row contains two columns: +** +** 0: table_name - name of table +** 1: without_rowid - true for WITHOUT ROWID tables, false otherwise. +** +*/ +static sqlite3_stmt *intckListTables(sqlite3_intck *p){ + return intckPrepare(p, + "WITH tables(table_name) AS (" + " SELECT name" + " FROM %Q.sqlite_schema WHERE type='table' OR type='index'" + " UNION ALL " + " SELECT 'sqlite_schema'" + ")" + "SELECT * FROM tables" + , p->zDb + ); +} + +static char *intckStrdup(sqlite3_intck *p, const char *zIn){ + char *zOut = 0; + if( p->rc==SQLITE_OK ){ + int nIn = strlen(zIn); + zOut = sqlite3_malloc(nIn+1); + if( zOut==0 ){ + p->rc = SQLITE_NOMEM; + }else{ + memcpy(zOut, zIn, nIn+1); + } + } + return zOut; +} + +/* +** Return the size in bytes of the first token in nul-terminated buffer z. +** For the purposes of this call, a token is either: +** +** * a quoted SQL string, +* * a contiguous series of ascii alphabet characters, or +* * any other single byte. +*/ +static int intckGetToken(const char *z){ + char c = z[0]; + int iRet = 1; + if( c=='\'' || c=='"' || c=='`' ){ + while( 1 ){ + if( z[iRet]==c ){ + iRet++; + if( z[iRet+1]!=c ) break; + } + iRet++; + } + } + else if( c=='[' ){ + while( z[iRet++]!=']' && z[iRet] ); + } + else if( (c>='A' && c<='Z') || (c>='a' && c<='z') ){ + while( (z[iRet]>='A' && z[iRet]<='Z') || (z[iRet]>='a' && z[iRet]<='z') ){ + iRet++; + } + } + + return iRet; +} + +static int intckIsSpace(char c){ + return (c==' ' || c=='\t' || c=='\n' || c=='\r'); +} + +static int intckTokenMatch( + const char *zToken, + int nToken, + const char *z1, + const char *z2 +){ + return ( + (strlen(z1)==nToken && 0==sqlite3_strnicmp(zToken, z1, nToken)) + || (z2 && strlen(z2)==nToken && 0==sqlite3_strnicmp(zToken, z2, nToken)) + ); +} + +/* +** Argument z points to the text of a CREATE INDEX statement. This function +** identifies the part of the text that contains either the index WHERE +** clause (if iCol<0) or the iCol'th column of the index. +** +** If (iCol<0), the identified fragment does not include the "WHERE" keyword, +** only the expression that follows it. If (iCol>=0) then the identified +** fragment does not include any trailing sort-order keywords - "ASC" or +** "DESC". +** +** If the CREATE INDEX statement does not contain the requested field or +** clause, NULL is returned and (*pnByte) is set to 0. Otherwise, a pointer to +** the identified fragment is returned and output parameter (*pnByte) set +** to its size in bytes. +*/ +static const char *intckParseCreateIndex(const char *z, int iCol, int *pnByte){ + int iOff = 0; + int iThisCol = 0; + int iStart = 0; + int nOpen = 0; + + const char *zRet = 0; + int nRet = 0; + + int iEndOfCol = 0; + + /* Skip forward until the first "(" token */ + while( z[iOff]!='(' ){ + iOff += intckGetToken(&z[iOff]); + if( z[iOff]=='\0' ) return 0; + } + assert( z[iOff]=='(' ); + + nOpen = 1; + iOff++; + iStart = iOff; + while( z[iOff] ){ + const char *zToken = &z[iOff]; + int nToken = 0; + + /* Check if this is the end of the current column - either a "," or ")" + ** when nOpen==1. */ + if( nOpen==1 ){ + if( z[iOff]==',' || z[iOff]==')' ){ + if( iCol==iThisCol ){ + int iEnd = iEndOfCol ? iEndOfCol : iOff; + nRet = (iEnd - iStart); + zRet = &z[iStart]; + break; + } + iStart = iOff+1; + while( intckIsSpace(z[iStart]) ) iStart++; + iThisCol++; + } + if( z[iOff]==')' ) break; + } + if( z[iOff]=='(' ) nOpen++; + if( z[iOff]==')' ) nOpen--; + nToken = intckGetToken(zToken); + + if( intckTokenMatch(zToken, nToken, "ASC", "DESC") ){ + iEndOfCol = iOff; + }else if( 0==intckIsSpace(zToken[0]) ){ + iEndOfCol = 0; + } + + iOff += nToken; + } + + /* iStart is now the byte offset of 1 byte passed the final ')' in the + ** CREATE INDEX statement. Try to find a WHERE clause to return. */ + while( zRet==0 && z[iOff] ){ + int n = intckGetToken(&z[iOff]); + if( n==5 && 0==sqlite3_strnicmp(&z[iOff], "where", 5) ){ + zRet = &z[iOff+5]; + nRet = strlen(zRet); + } + iOff += n; + } + + /* Trim any whitespace from the start and end of the returned string. */ + if( zRet ){ + while( intckIsSpace(zRet[0]) ){ + nRet--; + zRet++; + } + while( nRet>0 && intckIsSpace(zRet[nRet-1]) ) nRet--; + } + + *pnByte = nRet; + return zRet; +} + +static void parseCreateIndexFunc( + sqlite3_context *pCtx, + int nVal, + sqlite3_value **apVal +){ + const char *zSql = (const char*)sqlite3_value_text(apVal[0]); + int idx = sqlite3_value_int(apVal[1]); + const char *zRes = 0; + int nRes = 0; + + assert( nVal==2 ); + if( zSql ){ + zRes = intckParseCreateIndex(zSql, idx, &nRes); + } + sqlite3_result_text(pCtx, zRes, nRes, SQLITE_TRANSIENT); +} + +/* +** Return true if sqlite3_intck.db has automatic indexes enabled, false +** otherwise. +*/ +static int intckGetAutoIndex(sqlite3_intck *p){ + int bRet = 0; + sqlite3_stmt *pStmt = 0; + pStmt = intckPrepare(p, "PRAGMA automatic_index"); + if( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){ + bRet = sqlite3_column_int(pStmt, 0); + } + intckFinalize(p, pStmt); + return bRet; +} + +/* +** Return true if zObj is an index, or false otherwise. +*/ +static int intckIsIndex(sqlite3_intck *p, const char *zObj){ + int bRet = 0; + sqlite3_stmt *pStmt = 0; + pStmt = intckPrepare(p, + "SELECT 1 FROM %Q.sqlite_schema WHERE name=%Q AND type='index'", + p->zDb, zObj + ); + if( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){ + bRet = 1; + } + intckFinalize(p, pStmt); + return bRet; +} + +static void intckExec(sqlite3_intck *p, const char *zSql){ + sqlite3_stmt *pStmt = 0; + pStmt = intckPrepare(p, "%s", zSql); + while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ); + intckFinalize(p, pStmt); +} + +static char *intckCheckObjectSql(sqlite3_intck *p, const char *zObj){ + char *zRet = 0; + sqlite3_stmt *pStmt = 0; + int bAutoIndex = 0; + int bIsIndex = 0; + + const char *zCommon = + /* Relation without_rowid also contains just one row. Column "b" is + ** set to true if the table being examined is a WITHOUT ROWID table, + ** or false otherwise. */ + ", without_rowid(b) AS (" + " SELECT EXISTS (" + " SELECT 1 FROM tabname, pragma_index_list(tab, db) AS l" + " WHERE origin='pk' " + " AND NOT EXISTS (SELECT 1 FROM sqlite_schema WHERE name=l.name)" + " )" + ")" + "" + /* Table idx_cols contains 1 row for each column in each index on the + ** table being checked. Columns are: + ** + ** idx_name: Name of the index. + ** idx_ispk: True if this index is the PK of a WITHOUT ROWID table. + ** col_name: Name of indexed column, or NULL for index on expression. + ** col_expr: Indexed expression, including COLLATE clause. + ** col_alias: Alias used for column in 'intck_wrapper' table. + */ + ", idx_cols(idx_name, idx_ispk, col_name, col_expr, col_alias) AS (" + " SELECT l.name, (l.origin=='pk' AND w.b), i.name, COALESCE((" + " SELECT parse_create_index(sql, i.seqno) FROM " + " sqlite_schema WHERE name = l.name" + " ), format('\"%w\"', i.name) || ' COLLATE ' || quote(i.coll))," + " 'c' || row_number() OVER ()" + " FROM " + " tabname t," + " without_rowid w," + " pragma_index_list(t.tab, t.db) l," + " pragma_index_xinfo(l.name) i" + " WHERE i.key" + " UNION ALL" + " SELECT '', 1, '_rowid_', '_rowid_', 'r1' FROM without_rowid WHERE b=0" + ")" + "" + "" + ", tabpk(db, tab, idx, o_pk, i_pk, q_pk, eq_pk, ps_pk, pk_pk) AS (" + " WITH pkfields(f, a) AS (" + " SELECT i.col_name, i.col_alias FROM idx_cols i WHERE i.idx_ispk" + " )" + " SELECT t.db, t.tab, t.idx, " + " group_concat('o.'||a, ', '), " + " group_concat('i.'||quote(f), ', '), " + " group_concat('quote(o.'||a||')', ' || '','' || '), " + " format('(%s)==(%s)'," + " group_concat('o.'||a, ', '), " + " group_concat(format('\"%w\"', f), ', ')" + " )," + " group_concat('%s', ',')," + " group_concat('quote('||a||')', ', ') " + " FROM tabname t, pkfields" + ")" + "" + ", idx(name, match_expr, partial, partial_alias, idx_ps, idx_idx) AS (" + " SELECT idx_name," + " format('(%s) IS (%s)', " + " group_concat(i.col_expr, ', ')," + " group_concat('o.'||i.col_alias, ', ')" + " ), " + " parse_create_index(" + " (SELECT sql FROM sqlite_schema WHERE name=idx_name), -1" + " )," + " 'cond' || row_number() OVER ()" + " , group_concat('%s', ',')" + " , group_concat('quote('||i.col_alias||')', ', ')" + " FROM tabpk t, " + " without_rowid w," + " idx_cols i" + " WHERE i.idx_ispk==0 " + " GROUP BY idx_name" + ")" + "" + ", wrapper_with(s) AS (" + " SELECT 'intck_wrapper AS (\n SELECT\n ' || (" + " WITH f(a, b) AS (" + " SELECT col_expr, col_alias FROM idx_cols" + " UNION ALL " + " SELECT partial, partial_alias FROM idx WHERE partial IS NOT NULL" + " )" + " SELECT group_concat(format('%s AS %s', a, b), ',\n ') FROM f" + " )" + " || format('\n FROM %Q.%Q ', t.db, t.tab)" + /* If the object being checked is a table, append "NOT INDEXED". + ** Otherwise, append "INDEXED BY ", and then, if the index + ** is a partial index " WHERE ". */ + " || CASE WHEN t.idx IS NULL THEN " + " 'NOT INDEXED'" + " ELSE" + " format('INDEXED BY %Q%s', t.idx, ' WHERE '||i.partial)" + " END" + " || '\n)'" + " FROM tabname t LEFT JOIN idx i ON (i.name=t.idx)" + ")" + "" + ; + + bAutoIndex = intckGetAutoIndex(p); + if( bAutoIndex ) intckExec(p, "PRAGMA automatic_index = 0"); + + bIsIndex = intckIsIndex(p, zObj); + if( bIsIndex ){ + pStmt = intckPrepare(p, + /* Table idxname contains a single row. The first column, "db", contains + ** the name of the db containing the table (e.g. "main") and the second, + ** "tab", the name of the table itself. */ + "WITH tabname(db, tab, idx) AS (" + " SELECT %Q, (SELECT tbl_name FROM %Q.sqlite_schema WHERE name=%Q), %Q " + ")" + "%s" /* zCommon */ + "" + ", case_statement(c) AS (" + " SELECT " + " 'CASE WHEN (' || group_concat(col_alias, ', ') || ') IS (\n ' " + " || 'SELECT ' || group_concat(col_expr, ', ') || ' FROM '" + " || format('%%Q.%%Q NOT INDEXED WHERE %%s\n)', t.db, t.tab, p.eq_pk)" + " || '\nTHEN NULL\n'" + " || 'ELSE format(''surplus entry ('" + " || group_concat('%%s', ',') || ',' || p.ps_pk" + " || ') in index ' || t.idx || ''', ' " + " || group_concat('quote('||i.col_alias||')', ', ') || ', ' || p.pk_pk" + " || ')'" + " || '\nEND'" + " FROM tabname t, tabpk p, idx_cols i WHERE i.idx_name=t.idx" + "" + ")" + "" + ", main_select(m) AS (" + " SELECT format(" + " 'WITH %%s\nSELECT %%s\nFROM intck_wrapper AS o'," + " ww.s, c" + " )" + " FROM case_statement, wrapper_with ww" + ")" + + "SELECT m FROM main_select" + , p->zDb, p->zDb, zObj, zObj + , zCommon + ); + }else{ + pStmt = intckPrepare(p, + /* Table tabname contains a single row. The first column, "db", contains + ** the name of the db containing the table (e.g. "main") and the second, + ** "tab", the name of the table itself. */ + "WITH tabname(db, tab, idx) AS (SELECT %Q, %Q, NULL)" + "" + "%s" /* zCommon */ + + /* expr(e) contains one row for each index on table zObj. Value e + ** is set to an expression that evaluates to NULL if the required + ** entry is present in the index, or an error message otherwise. */ + ", expr(e, p) AS (" + " SELECT format('CASE WHEN (%%s) IN\n" + " (SELECT %%s FROM %%Q.%%Q AS i INDEXED BY %%Q WHERE %%s%%s)\n" + " THEN NULL\n" + " ELSE format(''entry (%%s,%%s) missing from index %%s'', %%s, %%s)\n" + " END\n'" + " , t.o_pk, t.i_pk, t.db, t.tab, i.name, i.match_expr, " + " ' AND (' || partial || ')'," + " i.idx_ps, t.ps_pk, i.name, i.idx_idx, t.pk_pk)," + " CASE WHEN partial IS NULL THEN NULL ELSE i.partial_alias END" + " FROM tabpk t, idx i" + ")" + + ", numbered(ii, cond, e) AS (" + " SELECT 0, 'n.ii=0', 'NULL'" + " UNION ALL " + " SELECT row_number() OVER ()," + " '(n.ii='||row_number() OVER ()||COALESCE(' AND '||p||')', ')'), e" + " FROM expr" + ")" + + ", counter_with(w) AS (" + " SELECT 'WITH intck_counter(ii) AS (\n ' || " + " group_concat('SELECT '||ii, ' UNION ALL\n ') " + " || '\n)' FROM numbered" + ")" + "" + ", case_statement(c) AS (" + " SELECT 'CASE ' || " + " group_concat(format('\n WHEN %%s THEN (%%s)', cond, e), '') ||" + " '\nEND AS error_message'" + " FROM numbered" + ")" + + ", main_select(m) AS (" + " SELECT format(" + " '%%s, %%s\nSELECT %%s\nFROM intck_wrapper AS o" + ", intck_counter AS n ORDER BY %%s', " + " w, ww.s, c, t.o_pk" + " )" + " FROM case_statement, tabpk t, counter_with, wrapper_with ww" + ")" + + "SELECT m FROM main_select", + p->zDb, zObj, zCommon + ); + } + + while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){ +#if 0 + int nField = sqlite3_column_count(pStmt); + int ii; + for(ii=0; iipListTables, 0); + char *zSql = intckCheckObjectSql(p, zTab); + p->pCheck = intckPrepare(p, "%s", zSql); + sqlite3_free(zSql); +} + +int sqlite3_intck_open( + sqlite3 *db, /* Database handle to operate on */ + const char *zDbArg, /* "main", "temp" etc. */ + const char *zFile, /* Path to save-state db on disk (or NULL) */ + sqlite3_intck **ppOut /* OUT: New integrity-check handle */ +){ + sqlite3_intck *pNew = 0; + int rc = SQLITE_OK; + const char *zDb = zDbArg ? zDbArg : "main"; + int nDb = strlen(zDb); + + pNew = (sqlite3_intck*)sqlite3_malloc(sizeof(*pNew) + nDb + 1); + if( pNew==0 ){ + rc = SQLITE_NOMEM; + }else{ + memset(pNew, 0, sizeof(*pNew)); + pNew->db = db; + pNew->zDb = (const char*)&pNew[1]; + memcpy(&pNew[1], zDb, nDb+1); + sqlite3_create_function(db, "parse_create_index", + 2, SQLITE_UTF8, 0, parseCreateIndexFunc, 0, 0 + ); + } + + *ppOut = pNew; + return rc; +} + +void sqlite3_intck_close(sqlite3_intck *p){ + if( p && p->db ){ + sqlite3_create_function( + p->db, "parse_create_index", 1, SQLITE_UTF8, 0, 0, 0, 0 + ); + } + sqlite3_free(p->zTestSql); + sqlite3_free(p->zErr); + sqlite3_free(p); +} + +int sqlite3_intck_step(sqlite3_intck *p){ + if( p->rc==SQLITE_OK ){ + if( p->pListTables==0 ){ + p->pListTables = intckListTables(p); + } + assert( p->pListTables || p->rc!=SQLITE_OK ); + + if( p->rc==SQLITE_OK && p->pCheck==0 ){ + if( sqlite3_step(p->pListTables)==SQLITE_ROW ){ + intckCheckObject(p); + }else{ + int rc = sqlite3_finalize(p->pListTables); + if( rc==SQLITE_OK ){ + p->rc = SQLITE_DONE; + }else{ + intckSaveErrmsg(p); + } + p->pListTables = 0; + } + } + + if( p->rc==SQLITE_OK ){ + if( sqlite3_step(p->pCheck)==SQLITE_ROW ){ + /* Fine, whatever... */ + }else{ + if( sqlite3_finalize(p->pCheck)!=SQLITE_OK ){ + intckSaveErrmsg(p); + } + p->pCheck = 0; + } + } + } + + return p->rc; +} + +const char *sqlite3_intck_message(sqlite3_intck *p){ + if( p->pCheck ){ + return (const char*)sqlite3_column_text(p->pCheck, 0); + } + return 0; +} + +int sqlite3_intck_error(sqlite3_intck *p, const char **pzErr){ + *pzErr = p->zErr; + return (p->rc==SQLITE_DONE ? SQLITE_OK : p->rc); +} + +int sqlite3_intck_suspend(sqlite3_intck *pCk){ + return SQLITE_OK; +} + +const char *sqlite3_intck_test_sql(sqlite3_intck *p, const char *zObj){ + sqlite3_free(p->zTestSql); + p->zTestSql = intckCheckObjectSql(p, zObj); + return p->zTestSql; +} + diff --git a/ext/intck/sqlite3intck.h b/ext/intck/sqlite3intck.h new file mode 100644 index 0000000000..8846812e75 --- /dev/null +++ b/ext/intck/sqlite3intck.h @@ -0,0 +1,55 @@ +/* +** 2024-02-08 +** +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: +** +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. +** +************************************************************************* +*/ + +#ifndef _SQLITE_INTCK_H +#define _SQLITE_INTCK_H + +#include "sqlite3.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct sqlite3_intck sqlite3_intck; + +int sqlite3_intck_open( + sqlite3 *db, + const char *zDb, + const char *zFile, + sqlite3_intck **ppOut +); + +void sqlite3_intck_close(sqlite3_intck*); + +int sqlite3_intck_step(sqlite3_intck *pCk); + +const char *sqlite3_intck_message(sqlite3_intck *pCk); + +int sqlite3_intck_error(sqlite3_intck *pCk, const char **pzErr); + +int sqlite3_intck_suspend(sqlite3_intck *pCk); + +/* +** This API is used for testing only. It returns the full-text of an SQL +** statement used to test object zObj, which may be a table or index. +** The returned buffer is valid until the next call to either this function +** or sqlite3_intck_close() on the same sqlite3_intck handle. +*/ +const char *sqlite3_intck_test_sql(sqlite3_intck *pCk, const char *zObj); + + +#ifdef __cplusplus +} /* end of the 'extern "C"' block */ +#endif + +#endif /* ifndef _SQLITE_INTCK_H */ diff --git a/ext/intck/test_intck.c b/ext/intck/test_intck.c new file mode 100644 index 0000000000..33129ec275 --- /dev/null +++ b/ext/intck/test_intck.c @@ -0,0 +1,185 @@ +/* +** 2010 August 28 +** +** 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. +** +************************************************************************* +** Code for testing all sorts of SQLite interfaces. This code +** is not included in the SQLite library. +*/ + +#include "sqlite3.h" +#include "sqlite3intck.h" + +#if defined(INCLUDE_SQLITE_TCL_H) +# include "sqlite_tcl.h" +#else +# include "tcl.h" +#endif + +#include +#include + +/* In test1.c */ +int getDbPointer(Tcl_Interp *interp, const char *zA, sqlite3 **ppDb); +const char *sqlite3ErrName(int); + +typedef struct TestIntck TestIntck; +struct TestIntck { + sqlite3_intck *intck; +}; + +static int testIntckCmd( + void * clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *CONST objv[] +){ + struct Subcmd { + const char *zName; + int nArg; + const char *zExpect; + } aCmd[] = { + {"close", 0, ""}, /* 0 */ + {"step", 0, ""}, /* 1 */ + {"message", 0, ""}, /* 2 */ + {"error", 0, ""}, /* 3 */ + {"suspend", 0, ""}, /* 4 */ + {"test_sql", 1, ""}, /* 5 */ + {0 , 0} + }; + int rc = TCL_OK; + int iIdx = -1; + TestIntck *p = (TestIntck*)clientData; + + if( objc<2 ){ + Tcl_WrongNumArgs(interp, 1, objv, "SUB-COMMAND ..."); + return TCL_ERROR; + } + + rc = Tcl_GetIndexFromObjStruct( + interp, objv[1], aCmd, sizeof(aCmd[0]), "SUB-COMMAND", 0, &iIdx + ); + if( rc ) return rc; + + if( objc!=2+aCmd[iIdx].nArg ){ + Tcl_WrongNumArgs(interp, 2, objv, aCmd[iIdx].zExpect); + return TCL_ERROR; + } + + switch( iIdx ){ + case 0: assert( 0==strcmp("close", aCmd[iIdx].zName) ); { + Tcl_DeleteCommand(interp, Tcl_GetStringFromObj(objv[0], 0)); + break; + } + + case 1: assert( 0==strcmp("step", aCmd[iIdx].zName) ); { + int rc = sqlite3_intck_step(p->intck); + Tcl_SetObjResult(interp, Tcl_NewStringObj(sqlite3ErrName(rc), -1)); + break; + } + + case 2: assert( 0==strcmp("message", aCmd[iIdx].zName) ); { + const char *z = sqlite3_intck_message(p->intck); + Tcl_SetObjResult(interp, Tcl_NewStringObj(z ? z : "", -1)); + break; + } + + case 3: assert( 0==strcmp("error", aCmd[iIdx].zName) ); { + const char *zErr = 0; + int rc = sqlite3_intck_error(p->intck, &zErr); + Tcl_Obj *pRes = Tcl_NewObj(); + + Tcl_ListObjAppendElement( + interp, pRes, Tcl_NewStringObj(sqlite3ErrName(rc), -1) + ); + Tcl_ListObjAppendElement( + interp, pRes, Tcl_NewStringObj(zErr ? zErr : 0, -1) + ); + Tcl_SetObjResult(interp, pRes); + break; + } + + case 4: assert( 0==strcmp("suspend", aCmd[iIdx].zName) ); { + int rc = sqlite3_intck_suspend(p->intck); + Tcl_SetObjResult(interp, Tcl_NewStringObj(sqlite3ErrName(rc), -1)); + break; + } + + case 5: assert( 0==strcmp("test_sql", aCmd[iIdx].zName) ); { + const char *zObj = Tcl_GetString(objv[2]); + const char *zSql = sqlite3_intck_test_sql(p->intck, zObj); + Tcl_SetObjResult(interp, Tcl_NewStringObj(zSql, -1)); + break; + } + } + + return TCL_OK; +} + +/* +** Destructor for commands created by test_sqlite3_intck(). +*/ +static void testIntckFree(void *clientData){ + TestIntck *p = (TestIntck*)clientData; + sqlite3_intck_close(p->intck); + ckfree(p); +} + +/* +** tclcmd: sqlite3_intck DB DBNAME PATH +*/ +static int test_sqlite3_intck( + void * clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *CONST objv[] +){ + char zName[64]; + int iName = 0; + Tcl_CmdInfo info; + TestIntck *p = 0; + sqlite3 *db = 0; + const char *zDb = 0; + const char *zFile = 0; + int rc = SQLITE_OK; + + if( objc!=4 ){ + Tcl_WrongNumArgs(interp, 1, objv, "DB DBNAME PATH"); + return TCL_ERROR; + } + + p = (TestIntck*)ckalloc(sizeof(TestIntck)); + memset(p, 0, sizeof(TestIntck)); + + if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ){ + return TCL_ERROR; + } + zDb = Tcl_GetString(objv[2]); + zFile = Tcl_GetString(objv[3]); + + rc = sqlite3_intck_open(db, zDb, zFile, &p->intck); + if( rc!=SQLITE_OK ){ + ckfree(p); + Tcl_SetObjResult(interp, Tcl_NewStringObj(sqlite3_errstr(rc), -1)); + return TCL_ERROR; + } + + do { + sprintf(zName, "intck%d", iName); + }while( Tcl_GetCommandInfo(interp, zName, &info)!=0 ); + Tcl_CreateObjCommand(interp, zName, testIntckCmd, (void*)p, testIntckFree); + Tcl_SetObjResult(interp, Tcl_NewStringObj(zName, -1)); + + return TCL_OK; +} + +int Sqlitetestintck_Init(Tcl_Interp *interp){ + Tcl_CreateObjCommand(interp, "sqlite3_intck", test_sqlite3_intck, 0, 0); + return TCL_OK; +} diff --git a/main.mk b/main.mk index 081e0cd3b5..0a0af725d0 100644 --- a/main.mk +++ b/main.mk @@ -375,7 +375,9 @@ TESTSRC += \ $(TOP)/ext/rtree/test_rtreedoc.c \ $(TOP)/ext/recover/sqlite3recover.c \ $(TOP)/ext/recover/dbdata.c \ - $(TOP)/ext/recover/test_recover.c + $(TOP)/ext/recover/test_recover.c \ + $(TOP)/ext/intck/test_intck.c \ + $(TOP)/ext/intck/sqlite3intck.c #TESTSRC += $(TOP)/ext/fts3/fts3_tokenizer.c diff --git a/manifest b/manifest index ab0f22bde5..a378ab14eb 100644 --- a/manifest +++ b/manifest @@ -1,11 +1,11 @@ -C Fix\srounding\sin\szero-precision\s%f\sand\s%g\sprintf\sconversions.\n[forum:/info/393708f4a8|Forum\spost\s393708f4a8].\s\sThis\sbug\swas\nintroduced\sby\scheck-in\s[32befb224b254639]\sand\sfirst\sappeared\sin\sversion\s3.43.0. -D 2024-02-17T03:32:31.878 +C Add\sstart\sof\sextension\sfor\sincremental\sintegrity-checks\sto\sext/intck/. +D 2024-02-17T20:55:01.343 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 -F Makefile.in 24be65ae641c5727bbc247d60286a15ecc24fb80f14f8fb2d32533bf0ec96e79 +F Makefile.in 216eea0cc5a9613d9f4f21402a4b759c2fce2a0cb9567513933562b65e30670b F Makefile.linux-gcc f3842a0b1efbfbb74ac0ef60e56b301836d05b4d867d014f714fa750048f1ab6 -F Makefile.msc df56c06ef05add5ebcdcc9d4823fb2ec66ac16b06acb6971a7420859025886fa +F Makefile.msc a496ca640052c1e102daaa6e2d2216ae482f22995498c7c9492fd7f841481400 F README.md 6358805260a03ebead84e168bbf3740ddf3f683b477e478567186aa7afb490d3 F VERSION c84541c6a9e8426462176fbb1f9ecb5cfd7d1bb56228053ff7eeba8841673eb6 F aclocal.m4 a5c22d164aff7ed549d53a90fa56d56955281f50 @@ -248,6 +248,12 @@ F ext/fts5/tool/showfts5.tcl d54da0e067306663e2d5d523965ca487698e722c F ext/icu/README.txt 7ab7ced8ae78e3a645b57e78570ff589d4c672b71370f5aa9e1cd7024f400fc9 F ext/icu/icu.c c074519b46baa484bb5396c7e01e051034da8884bad1a1cb7f09bbe6be3f0282 F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a32075a8 +F ext/intck/intck1.test 0fcf3696b59aff6c344553647d612921dd529600796ff7172c02679955cecdcf +F ext/intck/intck2.test dd06719eca145b317ae380c81f04cd8a096a7cfdb71074cc6b6e7f195058b0d0 +F ext/intck/intck_common.tcl 1f2599d50033d21d5df89f5ed54cc29af472d86e3927e116db50c5ba94d903b9 +F ext/intck/sqlite3intck.c 14300998e91cd8788f483d97e53be9406f2c0be8af1867f399b80fef5e3721fb +F ext/intck/sqlite3intck.h 342ee2e2c7636b4daf29fa195d0a3a658272b76b283d586fba50f6bc80fc143d +F ext/intck/test_intck.c 3f9a950978842340df7492f0a4190022979f23ff904e90873a5e262adf30b78c F ext/jni/GNUmakefile 59eb05f2a363bdfac8d15d66bed624bfe1ff289229184f3861b95f98a19cf4b2 F ext/jni/README.md d899789a9082a07b99bf30b1bbb6204ae57c060efcaa634536fa669323918f42 F ext/jni/jar-dist.make 030aaa4ae71dd86e4ec5e7c1e6cd86f9dfa47c4592c070d2e35157e42498e1fa @@ -659,7 +665,7 @@ F ext/wasm/wasmfs.make 8a4955882aaa0783b3f60a9484a1f0f3d8b6f775c0fcd17c082f31966 F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8 F magic.txt 5ade0bc977aa135e79e3faaea894d5671b26107cc91e70783aa7dc83f22f3ba0 -F main.mk ef8d6b0e76b27d2b32d7b71ea30a2b2626b668f998a4f32f6171c9623a310a53 +F main.mk 678f023e03c5dca755570ed964a8355e44a6435f679e3763a6f9fe3d309f9986 F mptest/config01.test 3c6adcbc50b991866855f1977ff172eb6d901271 F mptest/config02.test 4415dfe36c48785f751e16e32c20b077c28ae504 F mptest/crash01.test 61e61469e257df0850df4293d7d4d6c2af301421 @@ -790,7 +796,7 @@ F src/test_schema.c cbfd7a9a9b6b40d4377d0c76a6c5b2a58387385977f26edab4e77eb5f90a F src/test_sqllog.c 540feaea7280cd5f926168aee9deb1065ae136d0bbbe7361e2ef3541783e187a F src/test_superlock.c 4839644b9201da822f181c5bc406c0b2385f672e F src/test_syscall.c 9fdb13b1df05e639808d44fcb8f6064aaded32b6565c00b215cfd05a060d1aca -F src/test_tclsh.c 3ff5d188a72f00807425954ea3b493dfd3a4b890ecc6700ea83bad2fd1332ecf +F src/test_tclsh.c aaf0d1de4a518a8db5ad38e5262be3e48b4a74ad1909f2dba753cecb30979d5d F src/test_tclvar.c 3273f9d59395b336e381b53cfc68ec6ebdaada4e93106a2e976ffb0550504e1c F src/test_thread.c 7ddcf0c8b79fa3c1d172f82f322302c963d923cdb503c6171f3c8081586d0b01 F src/test_vdbecov.c f60c6f135ec42c0de013a1d5136777aa328a776d33277f92abac648930453d43 @@ -2162,8 +2168,11 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 1c33c5db2e05019d1a375109f79ad8588a3c17f81e4f4b8d66c880c3c860e87e -R e3e534a124d08ab0760f858683268942 -U drh -Z 25ef9b1be0189ee473aa53bd8732a56c +P 7fca1bc482fc2456d75392eb42f768fda72631c9070de46b8123b1126e78306f +R f8dccfe308ed2507020014beca90ae47 +T *branch * incr-integrity-check +T *sym-incr-integrity-check * +T -sym-trunk * +U dan +Z 8b8b6eda2ec7249d41ba58db982258fb # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 1e28ec46dd..7ea8d90d42 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7fca1bc482fc2456d75392eb42f768fda72631c9070de46b8123b1126e78306f \ No newline at end of file +444e3c9210026da7eae1ed98850722e002433aa2cc77dbc6b6f80327a6b7a390 \ No newline at end of file diff --git a/src/test_tclsh.c b/src/test_tclsh.c index 32aee42675..4697c3b856 100644 --- a/src/test_tclsh.c +++ b/src/test_tclsh.c @@ -108,6 +108,7 @@ const char *sqlite3TestInit(Tcl_Interp *interp){ extern int Sqlitetest_window_Init(Tcl_Interp *); extern int Sqlitetestvdbecov_Init(Tcl_Interp *); extern int TestRecover_Init(Tcl_Interp*); + extern int Sqlitetestintck_Init(Tcl_Interp*); Tcl_CmdInfo cmdInfo; @@ -175,6 +176,7 @@ const char *sqlite3TestInit(Tcl_Interp *interp){ Sqlitetest_window_Init(interp); Sqlitetestvdbecov_Init(interp); TestRecover_Init(interp); + Sqlitetestintck_Init(interp); Tcl_CreateObjCommand( interp, "load_testfixture_extensions", load_testfixture_extensions,0,0 From d43e7adca7eb5d8c1ac6b345aa2470ed0f8b2c06 Mon Sep 17 00:00:00 2001 From: drh <> Date: Sun, 18 Feb 2024 01:12:22 +0000 Subject: [PATCH 111/430] Hold a transaction during PRAGMA optimize, for performance. FossilOrigin-Name: d13b79eae6df7f9d1f3b8062ddc75a12ff038196b3d752d2672a9925fa45ca56 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/pragma.c | 7 +++++++ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index 18e8630874..e3c3328eb1 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\snew\sMASK\sbits\sto\sPRAGMA\soptimize:\s\s0x70000. -D 2024-02-17T16:39:52.117 +C Hold\sa\stransaction\sduring\sPRAGMA\soptimize,\sfor\sperformance. +D 2024-02-18T01:12:22.988 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -732,7 +732,7 @@ F src/parse.y bfd6da46fc895cd8237400ff485d04ab0b32e47eb56de20982bb7f53e56c1f42 F src/pcache.c 040b165f30622a21b7a9a77c6f2e4877a32fb7f22d4c7f0d2a6fa6833a156a75 F src/pcache.h 1497ce1b823cf00094bb0cf3bac37b345937e6f910890c626b16512316d3abf5 F src/pcache1.c 602acb23c471bb8d557a6f0083cc2be641d6cafcafa19e481eba7ef4c9ca0f00 -F src/pragma.c c5b767e7538a808fac4f17f8891acb1f14b4eed3458d971ddea4dd82f7623e0c +F src/pragma.c c7ef49d3332badd6e17ac46e0aca762d7973c1e28156bc480c47aa3e56ae4d03 F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7 F src/prepare.c 371f6115cb69286ebc12c6f2d7511279c2e47d9f54f475d46a554d687a3b312c F src/printf.c 18fbdf028345c8fbe6044f5f5bfda5a10d48d6287afef088cc21b0ca57985640 @@ -2162,8 +2162,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 40532ffba91cf332c1ea4add80184031a9d6e10514d2d9b9a6cfd613091b81f7 -R 518017150456f4f932816e90c763b561 +P dd4497062569eec9ddfdaa7d6394c83ff40a7a59c6697a161bc4ff6d8af3bb29 +R 5aca31e5331abdce830c908f0aade7ae U drh -Z 4ff4c253b76c891ec5769cfa9bfe8766 +Z 497aafa2ad4da05132856bc0e0f3518f # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index c4b9f73820..0aec312a78 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -dd4497062569eec9ddfdaa7d6394c83ff40a7a59c6697a161bc4ff6d8af3bb29 \ No newline at end of file +d13b79eae6df7f9d1f3b8062ddc75a12ff038196b3d752d2672a9925fa45ca56 \ No newline at end of file diff --git a/src/pragma.c b/src/pragma.c index 40a31846bb..9bb971ed77 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -2446,6 +2446,7 @@ void sqlite3Pragma( char *zSubSql; /* SQL statement for the OP_SqlExec opcode */ u32 opMask; /* Mask of operations to perform */ int nLimit; /* Analysis limit to use */ + int once = 0; /* One-time initialization done */ #ifndef SQLITE_DEFAULT_OPTIMIZE_LIMIT # define SQLITE_DEFAULT_OPTIMIZE_LIMIT 400 @@ -2488,6 +2489,12 @@ void sqlite3Pragma( continue; } + /* Hold a write transaction open for efficiency */ + if( !once ){ + sqlite3BeginWriteOperation(pParse, 0, iDb); + once = 1; + } + /* Reanalyze if the table is 25 times larger than the last analysis */ szThreshold = pTab->nRowLogEst; for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ From e0a9935be1c506646566f6b7845eb381bb219e16 Mon Sep 17 00:00:00 2001 From: stephan Date: Mon, 19 Feb 2024 12:20:46 +0000 Subject: [PATCH 112/430] Extend the strerror_r() result type discrepancy check in os_unix.c to include the Android NDK, as reported in [forum post 3f13857fa4062301|forum:3f13857fa4062301]. The NDK's strerror_r() signature is version-dependent, whereas this change assumes int return (POSIX semantic) across all versions. FossilOrigin-Name: f18b2524da6bbbcf372b292df52fbe6efa49fd6e1f1f13ef2447279d559f7a08 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/os_unix.c | 6 +++++- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index ab0f22bde5..1fd935940c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\srounding\sin\szero-precision\s%f\sand\s%g\sprintf\sconversions.\n[forum:/info/393708f4a8|Forum\spost\s393708f4a8].\s\sThis\sbug\swas\nintroduced\sby\scheck-in\s[32befb224b254639]\sand\sfirst\sappeared\sin\sversion\s3.43.0. -D 2024-02-17T03:32:31.878 +C Extend\sthe\sstrerror_r()\sresult\stype\sdiscrepancy\scheck\sin\sos_unix.c\sto\sinclude\sthe\sAndroid\sNDK,\sas\sreported\sin\s[forum\spost\s3f13857fa4062301|forum:3f13857fa4062301].\sThe\sNDK's\sstrerror_r()\ssignature\sis\sversion-dependent,\swhereas\sthis\schange\sassumes\sint\sreturn\s(POSIX\ssemantic)\sacross\sall\sversions. +D 2024-02-19T12:20:46.413 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -723,7 +723,7 @@ F src/os.h 1ff5ae51d339d0e30d8a9d814f4b8f8e448169304d83a7ed9db66a65732f3e63 F src/os_common.h 6c0eb8dd40ef3e12fe585a13e709710267a258e2c8dd1c40b1948a1d14582e06 F src/os_kv.c 4d39e1f1c180b11162c6dc4aa8ad34053873a639bac6baae23272fc03349986a F src/os_setup.h 6011ad7af5db4e05155f385eb3a9b4470688de6f65d6166b8956e58a3d872107 -F src/os_unix.c fa9b81b642e60e77ffaf98bd1a2e5fde16c1c2317614ec178bf3bd5864772356 +F src/os_unix.c 8d7533b3b4d0d2d6ddd34d1ebc92f50a91f04e722a3a9295a000bc3c25128e2f F src/os_win.c 6ff43bac175bd9ed79e7c0f96840b139f2f51d01689a638fd05128becf94908a F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a F src/pager.c ff60e98138d2499082ac6230f01ac508aba545315debccfca2fd6042f5f10fcd @@ -2162,8 +2162,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 1c33c5db2e05019d1a375109f79ad8588a3c17f81e4f4b8d66c880c3c860e87e -R e3e534a124d08ab0760f858683268942 -U drh -Z 25ef9b1be0189ee473aa53bd8732a56c +P 7fca1bc482fc2456d75392eb42f768fda72631c9070de46b8123b1126e78306f +R a2e48d1032c74dc590366e533d9ce522 +U stephan +Z f46d908a23e6be0d034c20949f0d6956 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 1e28ec46dd..ed8ee25bd1 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7fca1bc482fc2456d75392eb42f768fda72631c9070de46b8123b1126e78306f \ No newline at end of file +f18b2524da6bbbcf372b292df52fbe6efa49fd6e1f1f13ef2447279d559f7a08 \ No newline at end of file diff --git a/src/os_unix.c b/src/os_unix.c index 4b3d63c2c1..4663c22d94 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -1295,8 +1295,12 @@ static int unixLogErrorAtLine( ** available, the error message will often be an empty string. Not a ** huge problem. Incorrectly concluding that the GNU version is available ** could lead to a segfault though. + ** + ** Forum post 3f13857fa4062301 reports that the Android SDK may use + ** int-type return, depending on its version. */ -#if defined(STRERROR_R_CHAR_P) || defined(__USE_GNU) +#if (defined(STRERROR_R_CHAR_P) || defined(__USE_GNU)) \ + && !defined(ANDROID) && !defined(__ANDROID__) zErr = # endif strerror_r(iErrno, aErr, sizeof(aErr)-1); From 9f34a05e98c3cffe48d935979bf745cc267efe4e Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 19 Feb 2024 13:06:27 +0000 Subject: [PATCH 113/430] Change the 0x20000 bit (use analysis limit) to 0x10, meaning that this feature is on by default. The default analysis limit is changed to 2000 which is almost always sufficient for accurate analysis results. FossilOrigin-Name: 4abd47b5917099a2f74e53e12c987da0722304a5e9a93b6d43015c1f45c48444 --- manifest | 14 +++++------ manifest.uuid | 2 +- src/pragma.c | 66 ++++++++++++++++++++++++++++++++++---------------- test/busy.test | 2 +- 4 files changed, 54 insertions(+), 30 deletions(-) diff --git a/manifest b/manifest index e3c3328eb1..54ba56837e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Hold\sa\stransaction\sduring\sPRAGMA\soptimize,\sfor\sperformance. -D 2024-02-18T01:12:22.988 +C Change\sthe\s0x20000\sbit\s(use\sanalysis\slimit)\sto\s0x10,\smeaning\sthat\sthis\sfeature\nis\son\sby\sdefault.\s\sThe\sdefault\sanalysis\slimit\sis\schanged\sto\s2000\swhich\sis\nalmost\salways\ssufficient\sfor\saccurate\sanalysis\sresults. +D 2024-02-19T13:06:27.586 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -732,7 +732,7 @@ F src/parse.y bfd6da46fc895cd8237400ff485d04ab0b32e47eb56de20982bb7f53e56c1f42 F src/pcache.c 040b165f30622a21b7a9a77c6f2e4877a32fb7f22d4c7f0d2a6fa6833a156a75 F src/pcache.h 1497ce1b823cf00094bb0cf3bac37b345937e6f910890c626b16512316d3abf5 F src/pcache1.c 602acb23c471bb8d557a6f0083cc2be641d6cafcafa19e481eba7ef4c9ca0f00 -F src/pragma.c c7ef49d3332badd6e17ac46e0aca762d7973c1e28156bc480c47aa3e56ae4d03 +F src/pragma.c b877efa88ea41560ee5dd95daa30c8cadb743381c59b8921a5143bf0792c6e3b F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7 F src/prepare.c 371f6115cb69286ebc12c6f2d7511279c2e47d9f54f475d46a554d687a3b312c F src/printf.c 18fbdf028345c8fbe6044f5f5bfda5a10d48d6287afef088cc21b0ca57985640 @@ -947,7 +947,7 @@ F test/boundary4.test 89e02fa66397b8a325d5eb102b5806f961f8ec4b F test/btree01.test fef17d9e999ac4f04095948e3438fbe674f4e07bb2c63bb1cad41d87baee077f F test/btree02.test 7555a5440453d900410160a52554fe6478af4faf53098f7235f1f443d5a1d6cc F test/btreefault.test a82a23b0578bc587afbf9a622c8f54a54f63762f062ba8a35613cfee38ab42f9 -F test/busy.test 510dc6daaad18bcbbc085bcc6217d6dc418def5e73f72ce1475eea0cb7834727 +F test/busy.test caff7164c16ce06a53af51f9e4c2753d4cc64250e00790a5e48b9c4f4be37597 F test/busy2.test 20823a5d7c42fb257d9f108c66312d90b1bb4ec3d80ba6b4e371073727560f98 F test/cache.test 13bc046b26210471ca6f2889aceb1ea52dc717de F test/cacheflush.test af25bb1509df04c1da10e38d8f322d66eceedf61 @@ -2162,8 +2162,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P dd4497062569eec9ddfdaa7d6394c83ff40a7a59c6697a161bc4ff6d8af3bb29 -R 5aca31e5331abdce830c908f0aade7ae +P d13b79eae6df7f9d1f3b8062ddc75a12ff038196b3d752d2672a9925fa45ca56 +R e258fa6228ef566d2b5670b2822a20d1 U drh -Z 497aafa2ad4da05132856bc0e0f3518f +Z e864b92d6fb5e0c6f09ca55fa83dd960 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 0aec312a78..9cda73c43e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d13b79eae6df7f9d1f3b8062ddc75a12ff038196b3d752d2672a9925fa45ca56 \ No newline at end of file +4abd47b5917099a2f74e53e12c987da0722304a5e9a93b6d43015c1f45c48444 \ No newline at end of file diff --git a/src/pragma.c b/src/pragma.c index 9bb971ed77..6e1fc8bc00 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -30,6 +30,34 @@ ** ../tool/mkpragmatab.tcl. */ #include "pragma.h" +/* +** When the 0x10 bit of PRAGMA optimize is set, any ANALYZE commands +** will be run with an analysis_limit set to the lessor of the value of +** the following macro or to the actual analysis_limit if it is non-zero, +** in order to prevent PRAGMA optimize from running for too long. +** +** The value of 2000 is chosen emperically so that the worst-case run-time +** for PRAGMA optimize does not exceed 100 milliseconds against a variety +** of test databases on a RaspberryPI-4 compiled using -Os and without +** -DSQLITE_DEBUG. Of course, your mileage may vary. For the purpose of +** his paragraph, "worst-case" means that ANALYZE ends up being +** run on every table in the database. The worst case typically only +** happens if PRAGMA optimize is run on a database file for which ANALYZE +** has not been previously run and the 0x10000 flag is included so that +** all tables are analyzed. The usual case for PRAGMA optimize is that +** no ANALYZE commands will be run at all, or if any ANALYZE happens it +** will be against a single table, so that expected timing for PRAGMA +** optimize on a PI-4 is more like 1 millisecond or less with the 0x10000 +** flag or less than 100 microseconds without the 0x10000 flag. +** +** An analysis limit of 2000 is almost always sufficient for the query +** planner to fully characterize an index. The additional accuracy from +** a larger analysis is not usually helpful. +*/ +#ifndef SQLITE_DEFAULT_OPTIMIZE_LIMIT +# define SQLITE_DEFAULT_OPTIMIZE_LIMIT 2000 +#endif + /* ** Interpret the given string as a safety level. Return 0 for OFF, ** 1 for ON or NORMAL, 2 for FULL, and 3 for EXTRA. Return 1 for an empty or @@ -2390,20 +2418,19 @@ void sqlite3Pragma( ** 0x00002 Run ANALYZE on tables that might benefit. On by default. ** See below for additional information. ** + ** 0x00010 Run all ANALYZE operations using an analysis_limit that + ** is the lessor of the current analysis_limit and the + ** SQLITE_DEFAULT_OPTIMIZE_LIMIT compile-time option. + ** The default value of SQLITE_DEFAULT_OPTIMIZE_LIMIT is + ** currently (2024-02-19) set to 2000, which is such that + ** the worst case run-time for PRAGMA optimize on a 100MB + ** database will usually be less than 100 milliseconds on + ** a RaspberryPI-4 class machine. Off by default. + ** ** 0x10000 Look at tables to see if they need to be reanalyzed ** even if they have not been queried during the current ** connection. Off by default. ** - ** 0x20000 Run all ANALYZE operations using an analysis_limit that - ** is the lessor of the current analysis_limit and the - ** SQLITE_DEFAULT_OPTIMIZE_LIMIT compile-time option, - ** nominally 400. Off by default. - ** - ** 0x40000 Tables become candidates for reanalysis if their size - ** grows or shrinks by 10x. Without this option, they - ** become candidates for reanalysis if their size grows - ** or shrinks by 25x. Off (25x mode) by default. - ** ** The default MASK is and always shall be 0x0fffe. In the current ** implementation, the default mask only covers the 0x00002 optimization, ** though additional optimizations that are covered by 0x0fffe might be @@ -2422,9 +2449,9 @@ void sqlite3Pragma( ** at some point during the lifetime of the current connection. ** ** (3) One or more indexes of the table are currently unanalyzed OR - ** the number of rows in the table has increased or decreased - ** 25 times or more (10 times or more if the 0x40000 bit is set) - ** since the last time ANALYZE was run. + ** the number of rows in the table has increased or decreased by + ** 10-fold (the new size is either greater than 10 times the old + ** size or less than 1/10th of the old size). ** ** (4) The table is an ordinary table, not a virtual table or view. ** @@ -2448,17 +2475,13 @@ void sqlite3Pragma( int nLimit; /* Analysis limit to use */ int once = 0; /* One-time initialization done */ -#ifndef SQLITE_DEFAULT_OPTIMIZE_LIMIT -# define SQLITE_DEFAULT_OPTIMIZE_LIMIT 400 -#endif - if( zRight ){ opMask = (u32)sqlite3Atoi(zRight); if( (opMask & 0x02)==0 ) break; }else{ opMask = 0xfffe; } - if( (opMask & 0x20000)==0 ){ + if( (opMask & 0x10)==0 ){ nLimit = 0; }else if( db->nAnalysisLimit>0 && db->nAnalysisLimitnRowLogEst; for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ if( !pIdx->hasStat1 ){ @@ -2504,7 +2528,7 @@ void sqlite3Pragma( } } if( szThreshold>=0 ){ - LogEst iRange = (opMask & 0x40000) ? 33 : 46; + LogEst iRange = 33; /* 10x size change */ sqlite3OpenTable(pParse, iTabCur, iDb, pTab, OP_OpenRead); sqlite3VdbeAddOp4Int(v, OP_IfSizeBetween, iTabCur, sqlite3VdbeCurrentAddr(v)+3+(opMask&1), diff --git a/test/busy.test b/test/busy.test index be0515b013..896c7fa651 100644 --- a/test/busy.test +++ b/test/busy.test @@ -106,7 +106,7 @@ do_test 3.4 { proc busy_handler {n} { return 1 } do_test 3.5 { catchsql { PRAGMA optimize } -} {0 {}} +} {1 {database is locked}} do_test 3.6 { execsql { COMMIT } db2 From 6c6356f7f2f3c6e717d445d117407e2edecccac5 Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 19 Feb 2024 13:50:09 +0000 Subject: [PATCH 114/430] Simplifications to PRAGMA optimize to make it easier to use. It always tries to ANALYZE unanalyzed indexes. The 0x10000 flag just makes it check for size changes in all tables. FossilOrigin-Name: 44ed7f4cd07a88a2fdd303a2c78e6babe01d7344b399bd2b80ed68d75a77aaa2 --- manifest | 12 ++++---- manifest.uuid | 2 +- src/pragma.c | 77 +++++++++++++++++++++++++++++++++------------------ 3 files changed, 57 insertions(+), 34 deletions(-) diff --git a/manifest b/manifest index 54ba56837e..fdb16737f1 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Change\sthe\s0x20000\sbit\s(use\sanalysis\slimit)\sto\s0x10,\smeaning\sthat\sthis\sfeature\nis\son\sby\sdefault.\s\sThe\sdefault\sanalysis\slimit\sis\schanged\sto\s2000\swhich\sis\nalmost\salways\ssufficient\sfor\saccurate\sanalysis\sresults. -D 2024-02-19T13:06:27.586 +C Simplifications\sto\sPRAGMA\soptimize\sto\smake\sit\seasier\sto\suse.\s\sIt\salways\ntries\sto\sANALYZE\sunanalyzed\sindexes.\s\sThe\s0x10000\sflag\sjust\smakes\sit\scheck\nfor\ssize\schanges\sin\sall\stables. +D 2024-02-19T13:50:09.987 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -732,7 +732,7 @@ F src/parse.y bfd6da46fc895cd8237400ff485d04ab0b32e47eb56de20982bb7f53e56c1f42 F src/pcache.c 040b165f30622a21b7a9a77c6f2e4877a32fb7f22d4c7f0d2a6fa6833a156a75 F src/pcache.h 1497ce1b823cf00094bb0cf3bac37b345937e6f910890c626b16512316d3abf5 F src/pcache1.c 602acb23c471bb8d557a6f0083cc2be641d6cafcafa19e481eba7ef4c9ca0f00 -F src/pragma.c b877efa88ea41560ee5dd95daa30c8cadb743381c59b8921a5143bf0792c6e3b +F src/pragma.c 9197331dd283a6010bb4e2c129a9015f854203d27fa6fbe89e1aea742b78351c F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7 F src/prepare.c 371f6115cb69286ebc12c6f2d7511279c2e47d9f54f475d46a554d687a3b312c F src/printf.c 18fbdf028345c8fbe6044f5f5bfda5a10d48d6287afef088cc21b0ca57985640 @@ -2162,8 +2162,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P d13b79eae6df7f9d1f3b8062ddc75a12ff038196b3d752d2672a9925fa45ca56 -R e258fa6228ef566d2b5670b2822a20d1 +P 4abd47b5917099a2f74e53e12c987da0722304a5e9a93b6d43015c1f45c48444 +R 39db09ba2f5384fee677814cc2cbe4fe U drh -Z e864b92d6fb5e0c6f09ca55fa83dd960 +Z cf23276671f3baaf4e4f3579488af586 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 9cda73c43e..f1cc73e3f0 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4abd47b5917099a2f74e53e12c987da0722304a5e9a93b6d43015c1f45c48444 \ No newline at end of file +44ed7f4cd07a88a2fdd303a2c78e6babe01d7344b399bd2b80ed68d75a77aaa2 \ No newline at end of file diff --git a/src/pragma.c b/src/pragma.c index 6e1fc8bc00..53dc9ced30 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -2425,11 +2425,15 @@ void sqlite3Pragma( ** currently (2024-02-19) set to 2000, which is such that ** the worst case run-time for PRAGMA optimize on a 100MB ** database will usually be less than 100 milliseconds on - ** a RaspberryPI-4 class machine. Off by default. + ** a RaspberryPI-4 class machine. On by default. + ** + ** 0x00020 Run ANALYZE on any table that has a complete index + ** (an index without a WHERE clause) that lacks an entry + ** in the sqlite_stat1 table. On by default. ** ** 0x10000 Look at tables to see if they need to be reanalyzed - ** even if they have not been queried during the current - ** connection. Off by default. + ** due to growth or shrinkage even if they have not been + ** queried during the current connection. Off by default. ** ** The default MASK is and always shall be 0x0fffe. In the current ** implementation, the default mask only covers the 0x00002 optimization, @@ -2444,18 +2448,25 @@ void sqlite3Pragma( ** ** (1) MASK bit 0x00002 is set. ** - ** (2) Either the 0x10000 MASK bit is set or else the query planner used - ** sqlite_stat1-style statistics for one or more indexes of the table - ** at some point during the lifetime of the current connection. + ** (2) The table is an ordinary table, not a virtual table or view. ** - ** (3) One or more indexes of the table are currently unanalyzed OR - ** the number of rows in the table has increased or decreased by - ** 10-fold (the new size is either greater than 10 times the old - ** size or less than 1/10th of the old size). + ** (3) The table name does not begin with "sqlite_". ** - ** (4) The table is an ordinary table, not a virtual table or view. + ** (4) One or more of the following is true: + ** (4a) The 0x10000 MASK bit is set. + ** (4b) One or more complete indexes on the table lacks an entry + ** in the sqlite_stat1 table. + ** (4c) The query planner used sqlite_stat1-style statistics for one + ** or more indexes of the tableat some point during the lifetime + ** of the current connection. ** - ** (5) The table name does not begin with "sqlite_". + ** (5) One or more of the following is true: + ** (5a) One or mroe complete indexes on the table lacks an entry + ** in the sqlite_stat1 table. (Same as 4a) + ** (5b) The number of rows in the table has increased or decreased by + ** 10-fold. In other words, the current size of the table is + ** 10 times larger than the size in sqlite_stat1 or else the + ** current size is less than 1/10th the size in sqlite_stat1. ** ** The rules for when tables are analyzed are likely to change in ** future releases. Future versions of SQLite might accept a string @@ -2473,7 +2484,7 @@ void sqlite3Pragma( char *zSubSql; /* SQL statement for the OP_SqlExec opcode */ u32 opMask; /* Mask of operations to perform */ int nLimit; /* Analysis limit to use */ - int once = 0; /* One-time initialization done */ + int nCheck = 0; /* Number of tables to be optimized */ if( zRight ){ opMask = (u32)sqlite3Atoi(zRight); @@ -2503,30 +2514,42 @@ void sqlite3Pragma( /* Do not scan system tables */ if( 0==sqlite3StrNICmp(pTab->zName, "sqlite_", 7) ) continue; + /* Find the size of the table as last recorded in sqlite_stat1. + ** If any complete index (index without a WHERE clause) is unanalyzed, + ** then the threshold is -1 to indicate a new, unanalyzed index + */ + szThreshold = pTab->nRowLogEst; + for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ + if( !pIdx->hasStat1 && pIdx->pPartIdxWhere==0 ){ + szThreshold = -1; /* Always analyze if any index lacks statistics */ + break; + } + } + /* If table pTab has not been used in a way that would benefit from ** having analysis statistics during the current session, then skip it, ** unless the 0x10000 MASK bit is set. */ - if( (pTab->tabFlags & TF_MaybeReanalyze)==0 - && (opMask & 0x10000)==0 - ){ + if( (pTab->tabFlags & TF_MaybeReanalyze)!=0 ){ + /* Check for size change if stat1 has been used for a query */ + }else if( opMask & 0x10000 ){ + /* Check for size change if 0x10000 is set */ + }else if( pTab->pIndex!=0 && szThreshold<0 ){ + /* Do analysis if unanalyzed complete indexes exists */ + }else{ + /* Otherwise, we can skip this table */ continue; } - /* Hold a write transaction open for efficiency */ - if( !once || 1 ){ + nCheck++; + if( nCheck==2 ){ + /* If ANALYZE might be invoked two or more times, hold a write + ** transaction for efficiency */ sqlite3BeginWriteOperation(pParse, 0, iDb); - once = 1; } /* Reanalyze if the table is 10 times larger or smaller than - ** the last analysis */ - szThreshold = pTab->nRowLogEst; - for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ - if( !pIdx->hasStat1 ){ - szThreshold = -1; /* Always analyze if any index lacks statistics */ - break; - } - } + ** the last analysis. Unconditional reanalysis if there are + ** unanalyzed complete indexes. */ if( szThreshold>=0 ){ LogEst iRange = 33; /* 10x size change */ sqlite3OpenTable(pParse, iTabCur, iDb, pTab, OP_OpenRead); From e7bdb2172c717f7ba64e15fb65b930524e759d71 Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 19 Feb 2024 16:22:58 +0000 Subject: [PATCH 115/430] If a table has one or more rows and it has a partial index has zero rows, still make an entry in the sqlite_stat1 table for the partial index, so that we know that "PRAGMA optimize" does not need to redo the whole table. FossilOrigin-Name: e147b18991dd462fff367442acb0504fdf193a31843ed34ec8c1ced30747bf8a --- ext/session/sessionstat1.test | 4 +- manifest | 20 +++++----- manifest.uuid | 2 +- src/analyze.c | 74 ++++++++++++++++++++--------------- src/btree.c | 8 ++-- src/pragma.c | 19 +++++---- src/vdbe.c | 2 +- 7 files changed, 70 insertions(+), 59 deletions(-) diff --git a/ext/session/sessionstat1.test b/ext/session/sessionstat1.test index 2757d60440..16dc4e2727 100644 --- a/ext/session/sessionstat1.test +++ b/ext/session/sessionstat1.test @@ -92,7 +92,7 @@ do_test 2.1 { } {} do_execsql_test -db db2 2.2 { - SELECT * FROM sqlite_stat1 + SELECT * FROM sqlite_stat1 ORDER BY tbl, idx } { t1 sqlite_autoindex_t1_1 {32 1} t1 t1b {32 4} @@ -104,7 +104,7 @@ do_test 2.3 { } {} do_execsql_test -db db2 2.4 { - SELECT * FROM sqlite_stat1 + SELECT * FROM sqlite_stat1 ORDER BY tbl, idx; } { t1 sqlite_autoindex_t1_1 {32 1} t1 t1b {32 4} diff --git a/manifest b/manifest index fdb16737f1..c12c473dca 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Simplifications\sto\sPRAGMA\soptimize\sto\smake\sit\seasier\sto\suse.\s\sIt\salways\ntries\sto\sANALYZE\sunanalyzed\sindexes.\s\sThe\s0x10000\sflag\sjust\smakes\sit\scheck\nfor\ssize\schanges\sin\sall\stables. -D 2024-02-19T13:50:09.987 +C If\sa\stable\shas\sone\sor\smore\srows\sand\sit\shas\sa\spartial\sindex\shas\szero\srows,\nstill\smake\san\sentry\sin\sthe\ssqlite_stat1\stable\sfor\sthe\spartial\sindex,\sso\sthat\nwe\sknow\sthat\s"PRAGMA\soptimize"\sdoes\snot\sneed\sto\sredo\sthe\swhole\stable. +D 2024-02-19T16:22:58.040 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -567,7 +567,7 @@ F ext/session/sessionnoop2.test de4672dce88464396ec9f30ed08c6c01643a69c53ae540fa F ext/session/sessionrebase.test 702378bdcb5062f1106e74457beca8797d09c113a81768734a58b197b5b334e2 F ext/session/sessionrowid.test 85187c2f1b38861a5844868126f69f9ec62223a03449a98a80600a44396f7363 F ext/session/sessionsize.test 8fcf4685993c3dbaa46a24183940ab9f5aa9ed0d23e5fb63bfffbdb56134b795 -F ext/session/sessionstat1.test b039e38e2ba83767b464baf39b297cc0b1cc6f3292255cb467ea7e12d0d0280c +F ext/session/sessionstat1.test 5e718d5888c0c49bbb33a7a4f816366db85f59f6a4f97544a806421b85dc2dec F ext/session/sessionwor.test 6fd9a2256442cebde5b2284936ae9e0d54bde692d0f5fd009ecef8511f4cf3fc F ext/session/sqlite3session.c 829d468f0f3d2710aace56b0116a7ca3f414683ce78e3125ae5e21547a895078 F ext/session/sqlite3session.h 4cf19a51975746d7cff2fdd74db8b769c570958e1c3639ac150d824ac1553b3e @@ -672,13 +672,13 @@ F sqlite3.1 acdff36db796e2d00225b911d3047d580cd136547298435426ce9d40347973cc F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a F sqlite_cfg.h.in baf2e409c63d4e7a765e17769b6ff17c5a82bbd9cbf1e284fd2e4cefaff3fcf2 F src/alter.c 30c2333b8bb3af71e4eb9adeadee8aa20edb15917ed44b8422e5cd15f3dfcddc -F src/analyze.c 0f15753308c3bca7674f31fa7e0807ffcb8b120c36eef7d00b62b33079ddc854 +F src/analyze.c dacc8f062bbda02c8ed3bbca0ab6122de010d094101d568df266a7b0d665d74f F src/attach.c cc9d00d30da916ff656038211410ccf04ed784b7564639b9b61d1839ed69fd39 F src/auth.c 19b7ccacae3dfba23fc6f1d0af68134fa216e9040e53b0681b4715445ea030b4 F src/backup.c 5c97e8023aab1ce14a42387eb3ae00ba5a0644569e3476f38661fa6f824c3523 F src/bitvec.c 9eac5f42c11914d5ef00a75605bb205e934f435c579687f985f1f8b0995c8645 F src/btmutex.c 79a43670447eacc651519a429f6ece9fd638563cf95b469d6891185ddae2b522 -F src/btree.c dfd351decf9f819393dae8fb7294cae69c3818069d27f47fee34d5b505e37b47 +F src/btree.c 2f9dcf7c27879edb7897354029343bcab0c5a3dd2bde3bf3fd8f814b71344d22 F src/btree.h 03e3356f5208bcab8eed4e094240fdac4a7f9f5ddf5e91045ce589f67d47c240 F src/btreeInt.h 3e2589726c4f105e653461814f65857465da68be1fac688de340c43b873f4062 F src/build.c 04f1bcee189f045ab086d84fee95db42cb49df82ff8e84af8136309ff3c8a75f @@ -732,7 +732,7 @@ F src/parse.y bfd6da46fc895cd8237400ff485d04ab0b32e47eb56de20982bb7f53e56c1f42 F src/pcache.c 040b165f30622a21b7a9a77c6f2e4877a32fb7f22d4c7f0d2a6fa6833a156a75 F src/pcache.h 1497ce1b823cf00094bb0cf3bac37b345937e6f910890c626b16512316d3abf5 F src/pcache1.c 602acb23c471bb8d557a6f0083cc2be641d6cafcafa19e481eba7ef4c9ca0f00 -F src/pragma.c 9197331dd283a6010bb4e2c129a9015f854203d27fa6fbe89e1aea742b78351c +F src/pragma.c 0bd3737acf69282fb1733e170a88a5caf3dba088092665e603ee5a6d651c0e2f F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7 F src/prepare.c 371f6115cb69286ebc12c6f2d7511279c2e47d9f54f475d46a554d687a3b312c F src/printf.c 18fbdf028345c8fbe6044f5f5bfda5a10d48d6287afef088cc21b0ca57985640 @@ -809,7 +809,7 @@ F src/upsert.c fa125a8d3410ce9a97b02cb50f7ae68a2476c405c76aa692d3acf6b8586e9242 F src/utf.c f23165685a67b4caf8ec08fb274cb3f319103decfb2a980b7cfd55d18dfa855e F src/util.c 078f040366d5bd5f47658d045f901c768c1c636c6eaea121f3a1cbd63c3edb5b F src/vacuum.c 604fcdaebe76f3497c855afcbf91b8fa5046b32de3045bab89cc008d68e40104 -F src/vdbe.c 6d2aecc9ab2f9db557b4841775d016e2697ff6312242e9a492cdf3e2529dffa6 +F src/vdbe.c 805af8bec9cae76a873b0ec4c91c3d1bd49b38e86c1c533ed87ec7a07a5042a5 F src/vdbe.h 88e19a982df9027ec1c177c793d1a5d34dc23d8f06e3b2d997f43688b05ee0eb F src/vdbeInt.h 949669dfd8a41550d27dcb905b494f2ccde9a2e6c1b0b04daa1227e2e74c2b2c F src/vdbeapi.c 8f57d60c89da0b60e6d4e272358c511f6bae4e24330bdb11f8b42f986d1bf21b @@ -2162,8 +2162,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 4abd47b5917099a2f74e53e12c987da0722304a5e9a93b6d43015c1f45c48444 -R 39db09ba2f5384fee677814cc2cbe4fe +P 44ed7f4cd07a88a2fdd303a2c78e6babe01d7344b399bd2b80ed68d75a77aaa2 +R 425f4513952a4b2a7a3cf3f40b480a46 U drh -Z cf23276671f3baaf4e4f3579488af586 +Z 08209902059a589603329b04ece67a70 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index f1cc73e3f0..5ae06f96c4 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -44ed7f4cd07a88a2fdd303a2c78e6babe01d7344b399bd2b80ed68d75a77aaa2 \ No newline at end of file +e147b18991dd462fff367442acb0504fdf193a31843ed34ec8c1ced30747bf8a \ No newline at end of file diff --git a/src/analyze.c b/src/analyze.c index 59e3d98377..e7c1068ae0 100644 --- a/src/analyze.c +++ b/src/analyze.c @@ -872,7 +872,7 @@ static void statGet( if( iVal==2 && p->nRow*10 <= nDistinct*11 ) iVal = 1; sqlite3_str_appendf(&sStat, " %llu", iVal); #ifdef SQLITE_ENABLE_STAT4 - assert( p->current.anEq[i] ); + assert( p->current.anEq[i] || p->nRow==0 ); #endif } sqlite3ResultStrAccum(context, &sStat); @@ -1057,7 +1057,7 @@ static void analyzeOneTable( for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ int nCol; /* Number of columns in pIdx. "N" */ - int addrRewind; /* Address of "OP_Rewind iIdxCur" */ + int addrGotoEnd; /* Address of "OP_Rewind iIdxCur" */ int addrNextRow; /* Address of "next_row:" */ const char *zIdxName; /* Name of the index */ int nColTest; /* Number of columns to test for changes */ @@ -1081,9 +1081,14 @@ static void analyzeOneTable( /* ** Pseudo-code for loop that calls stat_push(): ** - ** Rewind csr - ** if eof(csr) goto end_of_scan; ** regChng = 0 + ** Rewind csr + ** if eof(csr){ + ** stat_init() with count = 0; + ** goto end_of_scan; + ** } + ** count() + ** stat_init() ** goto chng_addr_0; ** ** next_row: @@ -1122,41 +1127,36 @@ static void analyzeOneTable( sqlite3VdbeSetP4KeyInfo(pParse, pIdx); VdbeComment((v, "%s", pIdx->zName)); - /* Invoke the stat_init() function. The arguments are: - ** + /* Implementation of the following: + ** + ** regChng = 0 + ** Rewind csr + ** if eof(csr){ + ** stat_init() with count = 0; + ** goto end_of_scan; + ** } + ** count() + ** stat_init() + ** goto chng_addr_0; + */ + assert( regTemp2==regStat+4 ); + sqlite3VdbeAddOp2(v, OP_Integer, db->nAnalysisLimit, regTemp2); + + /* Arguments to stat_init(): ** (1) the number of columns in the index including the rowid ** (or for a WITHOUT ROWID table, the number of PK columns), ** (2) the number of columns in the key without the rowid/pk - ** (3) estimated number of rows in the index, - */ + ** (3) estimated number of rows in the index. */ sqlite3VdbeAddOp2(v, OP_Integer, nCol, regStat+1); assert( regRowid==regStat+2 ); sqlite3VdbeAddOp2(v, OP_Integer, pIdx->nKeyCol, regRowid); -#ifdef SQLITE_ENABLE_STAT4 - if( OptimizationEnabled(db, SQLITE_Stat4) ){ - sqlite3VdbeAddOp2(v, OP_Count, iIdxCur, regTemp); - addrRewind = sqlite3VdbeAddOp1(v, OP_Rewind, iIdxCur); - VdbeCoverage(v); - }else -#endif - { - addrRewind = sqlite3VdbeAddOp1(v, OP_Rewind, iIdxCur); - VdbeCoverage(v); - sqlite3VdbeAddOp3(v, OP_Count, iIdxCur, regTemp, 1); - } - assert( regTemp2==regStat+4 ); - sqlite3VdbeAddOp2(v, OP_Integer, db->nAnalysisLimit, regTemp2); + sqlite3VdbeAddOp3(v, OP_Count, iIdxCur, regTemp, + OptimizationDisabled(db, SQLITE_Stat4)); sqlite3VdbeAddFunctionCall(pParse, 0, regStat+1, regStat, 4, &statInitFuncdef, 0); + addrGotoEnd = sqlite3VdbeAddOp1(v, OP_Rewind, iIdxCur); + VdbeCoverage(v); - /* Implementation of the following: - ** - ** Rewind csr - ** if eof(csr) goto end_of_scan; - ** regChng = 0 - ** goto next_push_0; - ** - */ sqlite3VdbeAddOp2(v, OP_Integer, 0, regChng); addrNextRow = sqlite3VdbeCurrentAddr(v); @@ -1263,6 +1263,12 @@ static void analyzeOneTable( } /* Add the entry to the stat1 table. */ + if( pIdx->pPartIdxWhere ){ + /* Partial indexes might get a zero-entry in sqlite_stat1. But + ** an empty table is omitted from sqlite_stat1. */ + sqlite3VdbeJumpHere(v, addrGotoEnd); + addrGotoEnd = 0; + } callStatGet(pParse, regStat, STAT_GET_STAT1, regStat1); assert( "BBB"[0]==SQLITE_AFF_TEXT ); sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regTemp, "BBB", 0); @@ -1286,6 +1292,12 @@ static void analyzeOneTable( int addrIsNull; u8 seekOp = HasRowid(pTab) ? OP_NotExists : OP_NotFound; + /* No STAT4 data is generated if the number of rows is zero */ + if( addrGotoEnd==0 ){ + sqlite3VdbeAddOp2(v, OP_Cast, regStat1, SQLITE_AFF_INTEGER); + addrGotoEnd = sqlite3VdbeAddOp1(v, OP_IfNot, regStat1); + } + if( doOnce ){ int mxCol = nCol; Index *pX; @@ -1338,7 +1350,7 @@ static void analyzeOneTable( #endif /* SQLITE_ENABLE_STAT4 */ /* End of analysis */ - sqlite3VdbeJumpHere(v, addrRewind); + if( addrGotoEnd ) sqlite3VdbeJumpHere(v, addrGotoEnd); } diff --git a/src/btree.c b/src/btree.c index 49c07c81a6..16b683abe7 100644 --- a/src/btree.c +++ b/src/btree.c @@ -6182,10 +6182,10 @@ i64 sqlite3BtreeRowCountEst(BtCursor *pCur){ assert( cursorOwnsBtShared(pCur) ); assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) ); - /* Currently this interface is only called by the OP_IfSmaller - ** opcode, and it that case the cursor will always be valid and - ** will always point to a leaf node. */ - if( NEVER(pCur->eState!=CURSOR_VALID) ) return -1; + /* Currently this interface is only called by the OP_IfSizeBetween + ** opcode and the OP_Count opcode with P3=1. In either case, + ** the cursor will always be valid unless the btree is empty. */ + if( pCur->eState!=CURSOR_VALID ) return 0; if( NEVER(pCur->pPage->leaf==0) ) return -1; n = pCur->pPage->nCell; diff --git a/src/pragma.c b/src/pragma.c index 53dc9ced30..77ec9a57e2 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -2427,9 +2427,8 @@ void sqlite3Pragma( ** database will usually be less than 100 milliseconds on ** a RaspberryPI-4 class machine. On by default. ** - ** 0x00020 Run ANALYZE on any table that has a complete index - ** (an index without a WHERE clause) that lacks an entry - ** in the sqlite_stat1 table. On by default. + ** 0x00020 Run ANALYZE on any table that has a index that lacks an + ** entry in the sqlite_stat1 table. On by default. ** ** 0x10000 Look at tables to see if they need to be reanalyzed ** due to growth or shrinkage even if they have not been @@ -2454,14 +2453,14 @@ void sqlite3Pragma( ** ** (4) One or more of the following is true: ** (4a) The 0x10000 MASK bit is set. - ** (4b) One or more complete indexes on the table lacks an entry + ** (4b) One or more indexes on the table lacks an entry ** in the sqlite_stat1 table. ** (4c) The query planner used sqlite_stat1-style statistics for one ** or more indexes of the tableat some point during the lifetime ** of the current connection. ** ** (5) One or more of the following is true: - ** (5a) One or mroe complete indexes on the table lacks an entry + ** (5a) One or mroe indexes on the table lacks an entry ** in the sqlite_stat1 table. (Same as 4a) ** (5b) The number of rows in the table has increased or decreased by ** 10-fold. In other words, the current size of the table is @@ -2515,12 +2514,12 @@ void sqlite3Pragma( if( 0==sqlite3StrNICmp(pTab->zName, "sqlite_", 7) ) continue; /* Find the size of the table as last recorded in sqlite_stat1. - ** If any complete index (index without a WHERE clause) is unanalyzed, - ** then the threshold is -1 to indicate a new, unanalyzed index + ** If any index is unanalyzed, then the threshold is -1 to + ** indicate a new, unanalyzed index */ szThreshold = pTab->nRowLogEst; for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ - if( !pIdx->hasStat1 && pIdx->pPartIdxWhere==0 ){ + if( !pIdx->hasStat1 ){ szThreshold = -1; /* Always analyze if any index lacks statistics */ break; } @@ -2534,7 +2533,7 @@ void sqlite3Pragma( }else if( opMask & 0x10000 ){ /* Check for size change if 0x10000 is set */ }else if( pTab->pIndex!=0 && szThreshold<0 ){ - /* Do analysis if unanalyzed complete indexes exists */ + /* Do analysis if unanalyzed indexes exists */ }else{ /* Otherwise, we can skip this table */ continue; @@ -2549,7 +2548,7 @@ void sqlite3Pragma( /* Reanalyze if the table is 10 times larger or smaller than ** the last analysis. Unconditional reanalysis if there are - ** unanalyzed complete indexes. */ + ** unanalyzed indexes. */ if( szThreshold>=0 ){ LogEst iRange = 33; /* 10x size change */ sqlite3OpenTable(pParse, iTabCur, iDb, pTab, OP_OpenRead); diff --git a/src/vdbe.c b/src/vdbe.c index 3b52c13fa7..48a029dbf8 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -2086,7 +2086,7 @@ case OP_RealAffinity: { /* in1 */ } #endif -#ifndef SQLITE_OMIT_CAST +#if !defined(SQLITE_OMIT_CAST) && !defined(SQLITE_OMIT_ANALYZE) /* Opcode: Cast P1 P2 * * * ** Synopsis: affinity(r[P1]) ** From cfc62ceefdfb19ed162b725cdca30fdea6a055e0 Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 19 Feb 2024 18:03:53 +0000 Subject: [PATCH 116/430] Add implementation of sqlite3_intck_suspend(). FossilOrigin-Name: c36ada868da74e030ff5002de1f3b31b639b0c43714b91c2e5ca0eda16bb6bc2 --- ext/intck/intck1.test | 9 +- ext/intck/intck2.test | 6 +- ext/intck/intck_common.tcl | 6 +- ext/intck/sqlite3intck.c | 191 +++++++++++++++++++++++++------------ ext/intck/test_intck.c | 2 +- manifest | 23 ++--- manifest.uuid | 2 +- 7 files changed, 157 insertions(+), 82 deletions(-) diff --git a/ext/intck/intck1.test b/ext/intck/intck1.test index c46a7d6b2d..e5a25dda8e 100644 --- a/ext/intck/intck1.test +++ b/ext/intck/intck1.test @@ -167,8 +167,8 @@ do_test 3.2 { sqlite3 db test.db } {} -puts "[intck_sql db x1a]" -execsql_pp "EXPLAIN QUERY PLAN [intck_sql db x1a]" +#puts "[intck_sql db x1a]" +#execsql_pp "EXPLAIN QUERY PLAN [intck_sql db x1a]" do_intck_test 3.3 { {entry (4,'six',5) missing from index x1a} } @@ -185,6 +185,11 @@ do_execsql_test 4.0 { INSERT INTO www VALUES(1, 1, 1), (2, 2, 2); } +#puts [intck_sql db w1] +#execsql_pp [intck_sql db www] +#execsql_pp [intck_sql db w1] +#puts [intck_sql db w1] + do_intck_test 4.1 { } finish_test diff --git a/ext/intck/intck2.test b/ext/intck/intck2.test index bc9aebeea8..90f263f880 100644 --- a/ext/intck/intck2.test +++ b/ext/intck/intck2.test @@ -43,8 +43,8 @@ imposter_edit i1 { } do_intck_test 1.1 { - {entry ('two',2) missing from index i1} {surplus entry ('four',4) in index i1} + {entry ('two',2) missing from index i1} } #------------------------------------------------------------------------- @@ -61,9 +61,7 @@ do_execsql_test 2.0 { } do_intck_test 2.1 {} -puts [intck_sql db x1] - - +#puts [intck_sql db x1] finish_test diff --git a/ext/intck/intck_common.tcl b/ext/intck/intck_common.tcl index 0763d13266..757ca82b3f 100644 --- a/ext/intck/intck_common.tcl +++ b/ext/intck/intck_common.tcl @@ -15,7 +15,7 @@ if {![info exists testdir]} { } source $testdir/tester.tcl -proc do_intck {db} { +proc do_intck {db {bSuspend 0}} { set ic [sqlite3_intck $db main ""] set ret [list] @@ -24,6 +24,7 @@ proc do_intck {db} { if {$msg!=""} { lappend ret $msg } + if {$bSuspend} { $ic suspend } } set err [$ic error] @@ -43,7 +44,8 @@ proc intck_sql {db tbl} { } proc do_intck_test {tn expect} { - uplevel [list do_test $tn [list do_intck db] [list {*}$expect]] + uplevel [list do_test $tn.a [list do_intck db] [list {*}$expect]] + uplevel [list do_test $tn.b [list do_intck db 1] [list {*}$expect]] } diff --git a/ext/intck/sqlite3intck.c b/ext/intck/sqlite3intck.c index 7610d44a9b..b08b499a43 100644 --- a/ext/intck/sqlite3intck.c +++ b/ext/intck/sqlite3intck.c @@ -20,10 +20,10 @@ struct sqlite3_intck { sqlite3 *db; const char *zDb; /* Copy of zDb parameter to _open() */ - sqlite3_stmt *pListTables; + char *zObj; /* Current object. Or NULL. */ + char *zKey; /* Key saved by _suspect() call. */ sqlite3_stmt *pCheck; - int nCheck; int rc; /* SQLite error code */ char *zErr; /* Error message */ @@ -58,11 +58,15 @@ static sqlite3_stmt *intckPrepare(sqlite3_intck *p, const char *zFmt, ...){ p->rc = sqlite3_prepare_v2(p->db, zSql, -1, &pRet, 0); fflush(stdout); if( p->rc!=SQLITE_OK ){ +#if 1 printf("ERROR: %s\n", zSql); printf("MSG: %s\n", sqlite3_errmsg(p->db)); +#endif if( sqlite3_error_offset(p->db)>=0 ){ +#if 1 int iOff = sqlite3_error_offset(p->db); printf("AT: %.40s\n", &zSql[iOff]); +#endif } fflush(stdout); intckSaveErrmsg(p); @@ -82,27 +86,6 @@ static void intckFinalize(sqlite3_intck *p, sqlite3_stmt *pStmt){ } } -/* -** Return an SQL statement that will itself return a single row for each -** table in the target schema. The row contains two columns: -** -** 0: table_name - name of table -** 1: without_rowid - true for WITHOUT ROWID tables, false otherwise. -** -*/ -static sqlite3_stmt *intckListTables(sqlite3_intck *p){ - return intckPrepare(p, - "WITH tables(table_name) AS (" - " SELECT name" - " FROM %Q.sqlite_schema WHERE type='table' OR type='index'" - " UNION ALL " - " SELECT 'sqlite_schema'" - ")" - "SELECT * FROM tables" - , p->zDb - ); -} - static char *intckStrdup(sqlite3_intck *p, const char *zIn){ char *zOut = 0; if( p->rc==SQLITE_OK ){ @@ -117,6 +100,42 @@ static char *intckStrdup(sqlite3_intck *p, const char *zIn){ return zOut; } +static void intckFindObject(sqlite3_intck *p){ + sqlite3_stmt *pStmt = 0; + char *zPrev = p->zObj; + p->zObj = 0; + + assert( p->rc==SQLITE_OK ); + pStmt = intckPrepare(p, + "WITH tables(table_name) AS (" + " SELECT name" + " FROM %Q.sqlite_schema WHERE type='table' OR type='index'" + " UNION ALL " + " SELECT 'sqlite_schema'" + ")" + "SELECT table_name FROM tables " + "WHERE ?1 IS NULL OR table_name%s?1 " + "ORDER BY 1" + , p->zDb, (p->zKey ? ">=" : ">") + ); + + if( p->rc==SQLITE_OK ){ + sqlite3_bind_text(pStmt, 1, zPrev, -1, SQLITE_TRANSIENT); + if( sqlite3_step(pStmt)==SQLITE_ROW ){ + p->zObj = intckStrdup(p, (const char*)sqlite3_column_text(pStmt, 0)); + } + } + intckFinalize(p, pStmt); + + /* If this is a new object, ensure the previous key value is cleared. */ + if( sqlite3_stricmp(p->zObj, zPrev) ){ + sqlite3_free(p->zKey); + p->zKey = 0; + } + + sqlite3_free(zPrev); +} + /* ** Return the size in bytes of the first token in nul-terminated buffer z. ** For the purposes of this call, a token is either: @@ -314,7 +333,11 @@ static void intckExec(sqlite3_intck *p, const char *zSql){ intckFinalize(p, pStmt); } -static char *intckCheckObjectSql(sqlite3_intck *p, const char *zObj){ +static char *intckCheckObjectSql( + sqlite3_intck *p, + const char *zObj, + const char *zPrev +){ char *zRet = 0; sqlite3_stmt *pStmt = 0; int bAutoIndex = 0; @@ -427,45 +450,61 @@ static char *intckCheckObjectSql(sqlite3_intck *p, const char *zObj){ /* Table idxname contains a single row. The first column, "db", contains ** the name of the db containing the table (e.g. "main") and the second, ** "tab", the name of the table itself. */ - "WITH tabname(db, tab, idx) AS (" - " SELECT %Q, (SELECT tbl_name FROM %Q.sqlite_schema WHERE name=%Q), %Q " + "WITH tabname(db, tab, idx, prev) AS (" + " SELECT %Q, (SELECT tbl_name FROM %Q.sqlite_schema WHERE name=%Q), " + " %Q, %Q " ")" "%s" /* zCommon */ "" ", case_statement(c) AS (" " SELECT " - " 'CASE WHEN (' || group_concat(col_alias, ', ') || ') IS (\n ' " + " 'CASE WHEN (' || group_concat(col_alias, ', ') || ') IS (\n ' " " || 'SELECT ' || group_concat(col_expr, ', ') || ' FROM '" - " || format('%%Q.%%Q NOT INDEXED WHERE %%s\n)', t.db, t.tab, p.eq_pk)" - " || '\nTHEN NULL\n'" + " || format('%%Q.%%Q NOT INDEXED WHERE %%s\n', t.db, t.tab, p.eq_pk)" + " || ' )\n THEN NULL\n '" " || 'ELSE format(''surplus entry ('" " || group_concat('%%s', ',') || ',' || p.ps_pk" " || ') in index ' || t.idx || ''', ' " " || group_concat('quote('||i.col_alias||')', ', ') || ', ' || p.pk_pk" " || ')'" - " || '\nEND'" + " || '\nEND AS error_message'" " FROM tabname t, tabpk p, idx_cols i WHERE i.idx_name=t.idx" + ")" "" + ", thiskey(k) AS (" + " SELECT format('format(''(%%s,%%s)'', %%s, %%s) AS thiskey', " + " group_concat('%%s', ','), p.ps_pk, " + " group_concat('quote('||i.col_alias||')',', '), p.pk_pk" + " ) FROM tabpk p, idx_cols i WHERE i.idx_name=p.idx" + ")" + "" + ", whereclause(w_c) AS (" + " SELECT CASE WHEN prev!='' THEN " + " '\nWHERE (' || group_concat(i.col_alias, ',') || ',' " + " || o_pk || ') > ' || prev" + " ELSE ''" + " END" + " FROM tabpk, tabname, idx_cols i WHERE i.idx_name=tabpk.idx" ")" "" ", main_select(m) AS (" " SELECT format(" - " 'WITH %%s\nSELECT %%s\nFROM intck_wrapper AS o'," - " ww.s, c" + " 'WITH %%s\nSELECT %%s,\n%%s\nFROM intck_wrapper AS o%%s'," + " ww.s, c, t.k, whereclause.w_c" " )" - " FROM case_statement, wrapper_with ww" + " FROM case_statement, wrapper_with ww, thiskey t, whereclause" ")" "SELECT m FROM main_select" , p->zDb, p->zDb, zObj, zObj - , zCommon + , zPrev, zCommon ); }else{ pStmt = intckPrepare(p, /* Table tabname contains a single row. The first column, "db", contains ** the name of the db containing the table (e.g. "main") and the second, ** "tab", the name of the table itself. */ - "WITH tabname(db, tab, idx) AS (SELECT %Q, %Q, NULL)" + "WITH tabname(db, tab, idx, prev) AS (SELECT %Q, %Q, NULL, %Q)" "" "%s" /* zCommon */ @@ -505,18 +544,41 @@ static char *intckCheckObjectSql(sqlite3_intck *p, const char *zObj){ " '\nEND AS error_message'" " FROM numbered" ")" + "" + /* This table contains a single row consisting of a single value - + ** the text of an SQL expression that may be used by the main SQL + ** statement to output an SQL literal that can be used to resume + ** the scan if it is suspended. e.g. for a rowid table, an expression + ** like: + ** + ** format('(%d,%d)', _rowid_, n.ii) + */ + ", thiskey(k) AS (" + " SELECT 'format(''(' || ps_pk || ',%%d)'', ' || pk_pk || ', n.ii)'" + " FROM tabpk" + ")" + "" + ", whereclause(w_c) AS (" + " SELECT CASE WHEN prev!='' THEN " + " '\nWHERE (' || o_pk ||', n.ii) > ' || prev" + " ELSE ''" + " END" + " FROM tabpk, tabname" + ")" + "" ", main_select(m) AS (" " SELECT format(" - " '%%s, %%s\nSELECT %%s\nFROM intck_wrapper AS o" - ", intck_counter AS n ORDER BY %%s', " - " w, ww.s, c, t.o_pk" + " '%%s, %%s\nSELECT %%s,\n%%s AS thiskey\nFROM intck_wrapper AS o" + ", intck_counter AS n%%s\nORDER BY %%s', " + " w, ww.s, c, thiskey.k, whereclause.w_c, t.o_pk" " )" - " FROM case_statement, tabpk t, counter_with, wrapper_with ww" + " FROM case_statement, tabpk t, counter_with, " + " wrapper_with ww, thiskey, whereclause" ")" "SELECT m FROM main_select", - p->zDb, zObj, zCommon + p->zDb, zObj, zPrev, zCommon ); } @@ -542,10 +604,11 @@ static char *intckCheckObjectSql(sqlite3_intck *p, const char *zObj){ } static void intckCheckObject(sqlite3_intck *p){ - const char *zTab = (const char*)sqlite3_column_text(p->pListTables, 0); - char *zSql = intckCheckObjectSql(p, zTab); + char *zSql = intckCheckObjectSql(p, p->zObj, p->zKey); p->pCheck = intckPrepare(p, "%s", zSql); sqlite3_free(zSql); + sqlite3_free(p->zKey); + p->zKey = 0; } int sqlite3_intck_open( @@ -582,6 +645,8 @@ void sqlite3_intck_close(sqlite3_intck *p){ p->db, "parse_create_index", 1, SQLITE_UTF8, 0, 0, 0, 0 ); } + sqlite3_free(p->zObj); + sqlite3_free(p->zKey); sqlite3_free(p->zTestSql); sqlite3_free(p->zErr); sqlite3_free(p); @@ -589,26 +654,19 @@ void sqlite3_intck_close(sqlite3_intck *p){ int sqlite3_intck_step(sqlite3_intck *p){ if( p->rc==SQLITE_OK ){ - if( p->pListTables==0 ){ - p->pListTables = intckListTables(p); - } - assert( p->pListTables || p->rc!=SQLITE_OK ); - - if( p->rc==SQLITE_OK && p->pCheck==0 ){ - if( sqlite3_step(p->pListTables)==SQLITE_ROW ){ - intckCheckObject(p); - }else{ - int rc = sqlite3_finalize(p->pListTables); - if( rc==SQLITE_OK ){ - p->rc = SQLITE_DONE; + if( p->pCheck==0 ){ + intckFindObject(p); + if( p->rc==SQLITE_OK ){ + if( p->zObj ){ + intckCheckObject(p); }else{ - intckSaveErrmsg(p); + p->rc = SQLITE_DONE; } - p->pListTables = 0; } } if( p->rc==SQLITE_OK ){ + assert( p->pCheck ); if( sqlite3_step(p->pCheck)==SQLITE_ROW ){ /* Fine, whatever... */ }else{ @@ -635,13 +693,28 @@ int sqlite3_intck_error(sqlite3_intck *p, const char **pzErr){ return (p->rc==SQLITE_DONE ? SQLITE_OK : p->rc); } -int sqlite3_intck_suspend(sqlite3_intck *pCk){ - return SQLITE_OK; +int sqlite3_intck_suspend(sqlite3_intck *p){ + if( p->pCheck && p->rc==SQLITE_OK ){ + assert( p->zKey==0 ); + p->zKey = intckStrdup(p, (const char*)sqlite3_column_text(p->pCheck, 1)); + intckFinalize(p, p->pCheck); + p->pCheck = 0; + } + return p->rc; } const char *sqlite3_intck_test_sql(sqlite3_intck *p, const char *zObj){ sqlite3_free(p->zTestSql); - p->zTestSql = intckCheckObjectSql(p, zObj); + if( zObj ){ + p->zTestSql = intckCheckObjectSql(p, zObj, 0); + }else{ + if( p->zObj ){ + p->zTestSql = intckCheckObjectSql(p, p->zObj, p->zKey); + }else{ + sqlite3_free(p->zTestSql); + p->zTestSql = 0; + } + } return p->zTestSql; } diff --git a/ext/intck/test_intck.c b/ext/intck/test_intck.c index 33129ec275..d14fc92a6c 100644 --- a/ext/intck/test_intck.c +++ b/ext/intck/test_intck.c @@ -113,7 +113,7 @@ static int testIntckCmd( case 5: assert( 0==strcmp("test_sql", aCmd[iIdx].zName) ); { const char *zObj = Tcl_GetString(objv[2]); - const char *zSql = sqlite3_intck_test_sql(p->intck, zObj); + const char *zSql = sqlite3_intck_test_sql(p->intck, zObj[0] ? zObj : 0); Tcl_SetObjResult(interp, Tcl_NewStringObj(zSql, -1)); break; } diff --git a/manifest b/manifest index a378ab14eb..bb8e46b123 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sstart\sof\sextension\sfor\sincremental\sintegrity-checks\sto\sext/intck/. -D 2024-02-17T20:55:01.343 +C Add\simplementation\sof\ssqlite3_intck_suspend(). +D 2024-02-19T18:03:53.963 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -248,12 +248,12 @@ F ext/fts5/tool/showfts5.tcl d54da0e067306663e2d5d523965ca487698e722c F ext/icu/README.txt 7ab7ced8ae78e3a645b57e78570ff589d4c672b71370f5aa9e1cd7024f400fc9 F ext/icu/icu.c c074519b46baa484bb5396c7e01e051034da8884bad1a1cb7f09bbe6be3f0282 F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a32075a8 -F ext/intck/intck1.test 0fcf3696b59aff6c344553647d612921dd529600796ff7172c02679955cecdcf -F ext/intck/intck2.test dd06719eca145b317ae380c81f04cd8a096a7cfdb71074cc6b6e7f195058b0d0 -F ext/intck/intck_common.tcl 1f2599d50033d21d5df89f5ed54cc29af472d86e3927e116db50c5ba94d903b9 -F ext/intck/sqlite3intck.c 14300998e91cd8788f483d97e53be9406f2c0be8af1867f399b80fef5e3721fb +F ext/intck/intck1.test c831bc6ff67da3c5b6c9568640f87ad0442d4fc98ef97bc837133b94bcc645b3 +F ext/intck/intck2.test b65d7f627342f767e1d2c447d25619666cec36f516786dd56568bd741e5d7e67 +F ext/intck/intck_common.tcl 2895854e7aaf5e199a15f6f82538a00999fd8fc55553bc1f04619af7aa86c0d0 +F ext/intck/sqlite3intck.c 703ff16bc936192cff20d06b015d66279f4594e88371c00b18d17fec4f01ff5c F ext/intck/sqlite3intck.h 342ee2e2c7636b4daf29fa195d0a3a658272b76b283d586fba50f6bc80fc143d -F ext/intck/test_intck.c 3f9a950978842340df7492f0a4190022979f23ff904e90873a5e262adf30b78c +F ext/intck/test_intck.c eb596269c4a690a9b8ee689b1e52ff6e3306013ec706e319d5b97af05a08f0b9 F ext/jni/GNUmakefile 59eb05f2a363bdfac8d15d66bed624bfe1ff289229184f3861b95f98a19cf4b2 F ext/jni/README.md d899789a9082a07b99bf30b1bbb6204ae57c060efcaa634536fa669323918f42 F ext/jni/jar-dist.make 030aaa4ae71dd86e4ec5e7c1e6cd86f9dfa47c4592c070d2e35157e42498e1fa @@ -2168,11 +2168,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 7fca1bc482fc2456d75392eb42f768fda72631c9070de46b8123b1126e78306f -R f8dccfe308ed2507020014beca90ae47 -T *branch * incr-integrity-check -T *sym-incr-integrity-check * -T -sym-trunk * +P 444e3c9210026da7eae1ed98850722e002433aa2cc77dbc6b6f80327a6b7a390 +R 6b69910b5d388b58f98078e173b37781 U dan -Z 8b8b6eda2ec7249d41ba58db982258fb +Z 3045521be4122627d743cbd6c4ab9b9c # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 7ea8d90d42..fa3faa50cd 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -444e3c9210026da7eae1ed98850722e002433aa2cc77dbc6b6f80327a6b7a390 \ No newline at end of file +c36ada868da74e030ff5002de1f3b31b639b0c43714b91c2e5ca0eda16bb6bc2 \ No newline at end of file From 74b0aad09f0931c6645a1c43a0290ab1ee6ab4ff Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 19 Feb 2024 19:56:40 +0000 Subject: [PATCH 117/430] In PRAGMA optimize, scale back the analysis_limit when many different tables and indexes must be scanned. FossilOrigin-Name: 636615358aebfef80a657d09f15f608df9e64882b2aaa5574ce31a4f1c71fd70 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/pragma.c | 22 +++++++++++++++++++++- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 690d3adac6..aef3dc3eee 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Merge\strunk\sfixes\sinto\sthe\sbetter-optimize\sbranch. -D 2024-02-19T18:55:32.241 +C In\sPRAGMA\soptimize,\sscale\sback\sthe\sanalysis_limit\swhen\smany\sdifferent\stables\nand\sindexes\smust\sbe\sscanned. +D 2024-02-19T19:56:40.420 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -732,7 +732,7 @@ F src/parse.y bfd6da46fc895cd8237400ff485d04ab0b32e47eb56de20982bb7f53e56c1f42 F src/pcache.c 040b165f30622a21b7a9a77c6f2e4877a32fb7f22d4c7f0d2a6fa6833a156a75 F src/pcache.h 1497ce1b823cf00094bb0cf3bac37b345937e6f910890c626b16512316d3abf5 F src/pcache1.c 602acb23c471bb8d557a6f0083cc2be641d6cafcafa19e481eba7ef4c9ca0f00 -F src/pragma.c 0bd3737acf69282fb1733e170a88a5caf3dba088092665e603ee5a6d651c0e2f +F src/pragma.c c72ba9c8b300d713a318e7d199bc1d3f717f961c75de403f8db291841f2f58aa F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7 F src/prepare.c 371f6115cb69286ebc12c6f2d7511279c2e47d9f54f475d46a554d687a3b312c F src/printf.c d3392b2a20ee314ddeef34fb43c904bf4619eb20ff9a9e07e3950a7e4dcd6912 @@ -2162,8 +2162,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P e147b18991dd462fff367442acb0504fdf193a31843ed34ec8c1ced30747bf8a f18b2524da6bbbcf372b292df52fbe6efa49fd6e1f1f13ef2447279d559f7a08 -R fada2b9bf9b286f261a00cb9eda0fee2 +P 2cf78a5b5fce7f2d49ce185d27f50722c91a1d6c91bbcecebd4bb5244a76769f +R c2c83408fc346dde3baee32faaf6bad7 U drh -Z 513df274231a3535cbd843c1569f620b +Z ec6824937a1b6fb54f3b9fdcf77219f7 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index b04ec72a34..aa9236de91 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2cf78a5b5fce7f2d49ce185d27f50722c91a1d6c91bbcecebd4bb5244a76769f \ No newline at end of file +636615358aebfef80a657d09f15f608df9e64882b2aaa5574ce31a4f1c71fd70 \ No newline at end of file diff --git a/src/pragma.c b/src/pragma.c index 77ec9a57e2..18fc88aceb 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -2460,7 +2460,7 @@ void sqlite3Pragma( ** of the current connection. ** ** (5) One or more of the following is true: - ** (5a) One or mroe indexes on the table lacks an entry + ** (5a) One or more indexes on the table lacks an entry ** in the sqlite_stat1 table. (Same as 4a) ** (5b) The number of rows in the table has increased or decreased by ** 10-fold. In other words, the current size of the table is @@ -2484,6 +2484,8 @@ void sqlite3Pragma( u32 opMask; /* Mask of operations to perform */ int nLimit; /* Analysis limit to use */ int nCheck = 0; /* Number of tables to be optimized */ + int nBtree = 0; /* Number of btrees to scan */ + int nIndex; /* Number of indexes on the current table */ if( zRight ){ opMask = (u32)sqlite3Atoi(zRight); @@ -2518,7 +2520,9 @@ void sqlite3Pragma( ** indicate a new, unanalyzed index */ szThreshold = pTab->nRowLogEst; + nIndex = 0; for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ + nIndex++; if( !pIdx->hasStat1 ){ szThreshold = -1; /* Always analyze if any index lacks statistics */ break; @@ -2545,6 +2549,7 @@ void sqlite3Pragma( ** transaction for efficiency */ sqlite3BeginWriteOperation(pParse, 0, iDb); } + nBtree += nIndex+1; /* Reanalyze if the table is 10 times larger or smaller than ** the last analysis. Unconditional reanalysis if there are @@ -2572,6 +2577,21 @@ void sqlite3Pragma( } } sqlite3VdbeAddOp0(v, OP_Expire); + + /* In a schema with a large number of tables and indexes, scale back + ** the analysis_limit to avoid excess run-time in the worst case. + */ + if( !db->mallocFailed && nBtree>100 ){ + int iAddr, iEnd; + VdbeOp *aOp; + int nLimit = 100*SQLITE_DEFAULT_OPTIMIZE_LIMIT/nBtree; + if( nLimit<100 ) nLimit = 100; + aOp = sqlite3VdbeGetOp(v, 0); + iEnd = sqlite3VdbeCurrentAddr(v); + for(iAddr=0; iAddr Date: Mon, 19 Feb 2024 20:12:30 +0000 Subject: [PATCH 118/430] If there is no mention of a table in sqlite_stat1, use OP_Rewind to see if the table is empty prior to invoking ANALYZE. FossilOrigin-Name: 0cc93b19de597866292e0696f89fbd0e22a6cbb374678f5cc096fb889210fe3c --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/pragma.c | 15 +++++++++++---- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index aef3dc3eee..0449436b9d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C In\sPRAGMA\soptimize,\sscale\sback\sthe\sanalysis_limit\swhen\smany\sdifferent\stables\nand\sindexes\smust\sbe\sscanned. -D 2024-02-19T19:56:40.420 +C If\sthere\sis\sno\smention\sof\sa\stable\sin\ssqlite_stat1,\suse\sOP_Rewind\sto\ssee\sif\nthe\stable\sis\sempty\sprior\sto\sinvoking\sANALYZE. +D 2024-02-19T20:12:30.657 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -732,7 +732,7 @@ F src/parse.y bfd6da46fc895cd8237400ff485d04ab0b32e47eb56de20982bb7f53e56c1f42 F src/pcache.c 040b165f30622a21b7a9a77c6f2e4877a32fb7f22d4c7f0d2a6fa6833a156a75 F src/pcache.h 1497ce1b823cf00094bb0cf3bac37b345937e6f910890c626b16512316d3abf5 F src/pcache1.c 602acb23c471bb8d557a6f0083cc2be641d6cafcafa19e481eba7ef4c9ca0f00 -F src/pragma.c c72ba9c8b300d713a318e7d199bc1d3f717f961c75de403f8db291841f2f58aa +F src/pragma.c 280945eb4a7b78c82cd1b4d0bdefbb69af685a654f8fbfeb3bfd7dc8fede5fda F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7 F src/prepare.c 371f6115cb69286ebc12c6f2d7511279c2e47d9f54f475d46a554d687a3b312c F src/printf.c d3392b2a20ee314ddeef34fb43c904bf4619eb20ff9a9e07e3950a7e4dcd6912 @@ -2162,8 +2162,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 2cf78a5b5fce7f2d49ce185d27f50722c91a1d6c91bbcecebd4bb5244a76769f -R c2c83408fc346dde3baee32faaf6bad7 +P 636615358aebfef80a657d09f15f608df9e64882b2aaa5574ce31a4f1c71fd70 +R 98db8daafbcb183bee3a0d5c6d6f3dec U drh -Z ec6824937a1b6fb54f3b9fdcf77219f7 +Z 53d562a05375d893c6e8245ccbe9b40a # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index aa9236de91..b4d235c325 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -636615358aebfef80a657d09f15f608df9e64882b2aaa5574ce31a4f1c71fd70 \ No newline at end of file +0cc93b19de597866292e0696f89fbd0e22a6cbb374678f5cc096fb889210fe3c \ No newline at end of file diff --git a/src/pragma.c b/src/pragma.c index 18fc88aceb..e65233389e 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -2486,6 +2486,7 @@ void sqlite3Pragma( int nCheck = 0; /* Number of tables to be optimized */ int nBtree = 0; /* Number of btrees to scan */ int nIndex; /* Number of indexes on the current table */ + int hasStat1; /* True if any STAT1 info available for the table */ if( zRight ){ opMask = (u32)sqlite3Atoi(zRight); @@ -2520,10 +2521,13 @@ void sqlite3Pragma( ** indicate a new, unanalyzed index */ szThreshold = pTab->nRowLogEst; + hasStat1 = (pTab->tabFlags & TF_HasStat1)!=0; nIndex = 0; for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ nIndex++; - if( !pIdx->hasStat1 ){ + if( pIdx->hasStat1 ){ + hasStat1 = 1; + }else{ szThreshold = -1; /* Always analyze if any index lacks statistics */ break; } @@ -2555,14 +2559,17 @@ void sqlite3Pragma( ** the last analysis. Unconditional reanalysis if there are ** unanalyzed indexes. */ if( szThreshold>=0 ){ - LogEst iRange = 33; /* 10x size change */ + const LogEst iRange = 33; /* 10x size change */ sqlite3OpenTable(pParse, iTabCur, iDb, pTab, OP_OpenRead); sqlite3VdbeAddOp4Int(v, OP_IfSizeBetween, iTabCur, - sqlite3VdbeCurrentAddr(v)+3+(opMask&1), + sqlite3VdbeCurrentAddr(v)+2+(opMask&1), szThreshold>=iRange ? szThreshold-iRange : -1, szThreshold+iRange); - sqlite3VdbeAddOp1(v, OP_Close, iTabCur); VdbeCoverage(v); + }else if( !hasStat1 ){ + sqlite3OpenTable(pParse, iTabCur, iDb, pTab, OP_OpenRead); + sqlite3VdbeAddOp2(v, OP_Rewind, iTabCur, + sqlite3VdbeCurrentAddr(v)+2+(opMask&1)); } zSubSql = sqlite3MPrintf(db, "ANALYZE \"%w\".\"%w\"", db->aDb[iDb].zDbSName, pTab->zName); From ebea8458e2a00e7564986d05a0ce91c8613fefd7 Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 19 Feb 2024 20:15:44 +0000 Subject: [PATCH 119/430] Use more efficient SQL to verify that indexes contain entries that match their tables. FossilOrigin-Name: c01e008c28895e50b14531b2a1f3f1110aab3b54df41ebdbd416fbac7b1bba94 --- ext/intck/sqlite3intck.c | 56 ++++++++++++++++++++-------------------- ext/intck/sqlite3intck.h | 2 +- ext/intck/test_intck.c | 53 +++++++++++++++++++++++++++++++++++++ manifest | 16 ++++++------ manifest.uuid | 2 +- 5 files changed, 91 insertions(+), 38 deletions(-) diff --git a/ext/intck/sqlite3intck.c b/ext/intck/sqlite3intck.c index b08b499a43..05eaa81a93 100644 --- a/ext/intck/sqlite3intck.c +++ b/ext/intck/sqlite3intck.c @@ -19,15 +19,11 @@ struct sqlite3_intck { sqlite3 *db; const char *zDb; /* Copy of zDb parameter to _open() */ - char *zObj; /* Current object. Or NULL. */ - char *zKey; /* Key saved by _suspect() call. */ - - sqlite3_stmt *pCheck; - - int rc; /* SQLite error code */ + char *zKey; /* Key saved by _intck_suspend() call. */ + sqlite3_stmt *pCheck; /* Current check statement */ + int rc; /* Error code */ char *zErr; /* Error message */ - char *zTestSql; /* Returned by sqlite3_intck_test_sql() */ }; @@ -109,7 +105,7 @@ static void intckFindObject(sqlite3_intck *p){ pStmt = intckPrepare(p, "WITH tables(table_name) AS (" " SELECT name" - " FROM %Q.sqlite_schema WHERE type='table' OR type='index'" + " FROM %Q.sqlite_schema WHERE (type='table' OR type='index') AND rootpage" " UNION ALL " " SELECT 'sqlite_schema'" ")" @@ -400,9 +396,9 @@ static char *intckCheckObjectSql( "" ", idx(name, match_expr, partial, partial_alias, idx_ps, idx_idx) AS (" " SELECT idx_name," - " format('(%s) IS (%s)', " - " group_concat(i.col_expr, ', ')," - " group_concat('o.'||i.col_alias, ', ')" + " format('(%s,%s) IS (%s,%s)', " + " group_concat(i.col_expr, ', '), i_pk," + " group_concat('o.'||i.col_alias, ', '), o_pk" " ), " " parse_create_index(" " (SELECT sql FROM sqlite_schema WHERE name=idx_name), -1" @@ -512,13 +508,12 @@ static char *intckCheckObjectSql( ** is set to an expression that evaluates to NULL if the required ** entry is present in the index, or an error message otherwise. */ ", expr(e, p) AS (" - " SELECT format('CASE WHEN (%%s) IN\n" - " (SELECT %%s FROM %%Q.%%Q AS i INDEXED BY %%Q WHERE %%s%%s)\n" + " SELECT format('CASE WHEN EXISTS \n" + " (SELECT 1 FROM %%Q.%%Q AS i INDEXED BY %%Q WHERE %%s%%s)\n" " THEN NULL\n" " ELSE format(''entry (%%s,%%s) missing from index %%s'', %%s, %%s)\n" " END\n'" - " , t.o_pk, t.i_pk, t.db, t.tab, i.name, i.match_expr, " - " ' AND (' || partial || ')'," + " , t.db, t.tab, i.name, i.match_expr, ' AND (' || partial || ')'," " i.idx_ps, t.ps_pk, i.name, i.idx_idx, t.pk_pk)," " CASE WHEN partial IS NULL THEN NULL ELSE i.partial_alias END" " FROM tabpk t, idx i" @@ -626,30 +621,35 @@ int sqlite3_intck_open( if( pNew==0 ){ rc = SQLITE_NOMEM; }else{ + sqlite3_create_function(db, "parse_create_index", + 2, SQLITE_UTF8, 0, parseCreateIndexFunc, 0, 0 + ); memset(pNew, 0, sizeof(*pNew)); pNew->db = db; pNew->zDb = (const char*)&pNew[1]; memcpy(&pNew[1], zDb, nDb+1); - sqlite3_create_function(db, "parse_create_index", - 2, SQLITE_UTF8, 0, parseCreateIndexFunc, 0, 0 - ); } *ppOut = pNew; return rc; } -void sqlite3_intck_close(sqlite3_intck *p){ - if( p && p->db ){ - sqlite3_create_function( - p->db, "parse_create_index", 1, SQLITE_UTF8, 0, 0, 0, 0 - ); +int sqlite3_intck_close(sqlite3_intck *p){ + int rc = SQLITE_OK; + if( p ){ + rc = (p->rc==SQLITE_DONE ? SQLITE_OK : p->rc); + if( p->db ){ + sqlite3_create_function( + p->db, "parse_create_index", 1, SQLITE_UTF8, 0, 0, 0, 0 + ); + } + sqlite3_free(p->zObj); + sqlite3_free(p->zKey); + sqlite3_free(p->zTestSql); + sqlite3_free(p->zErr); + sqlite3_free(p); } - sqlite3_free(p->zObj); - sqlite3_free(p->zKey); - sqlite3_free(p->zTestSql); - sqlite3_free(p->zErr); - sqlite3_free(p); + return rc; } int sqlite3_intck_step(sqlite3_intck *p){ diff --git a/ext/intck/sqlite3intck.h b/ext/intck/sqlite3intck.h index 8846812e75..c7c24e42c9 100644 --- a/ext/intck/sqlite3intck.h +++ b/ext/intck/sqlite3intck.h @@ -29,7 +29,7 @@ int sqlite3_intck_open( sqlite3_intck **ppOut ); -void sqlite3_intck_close(sqlite3_intck*); +int sqlite3_intck_close(sqlite3_intck*); int sqlite3_intck_step(sqlite3_intck *pCk); diff --git a/ext/intck/test_intck.c b/ext/intck/test_intck.c index d14fc92a6c..75bcfa298a 100644 --- a/ext/intck/test_intck.c +++ b/ext/intck/test_intck.c @@ -179,7 +179,60 @@ static int test_sqlite3_intck( return TCL_OK; } +/* +** tclcmd: test_do_intck DB DBNAME +*/ +static int test_do_intck( + void * clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *CONST objv[] +){ + sqlite3 *db = 0; + const char *zDb = 0; + int rc = SQLITE_OK; + sqlite3_intck *pCk = 0; + Tcl_Obj *pRet = 0; + const char *zErr = 0; + + if( objc!=3 ){ + Tcl_WrongNumArgs(interp, 1, objv, "DB DBNAME"); + return TCL_ERROR; + } + if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ){ + return TCL_ERROR; + } + zDb = Tcl_GetString(objv[2]); + + pRet = Tcl_NewObj(); + Tcl_IncrRefCount(pRet); + + rc = sqlite3_intck_open(db, zDb, 0, &pCk); + if( rc==SQLITE_OK ){ + while( sqlite3_intck_step(pCk)==SQLITE_OK ){ + const char *zMsg = sqlite3_intck_message(pCk); + if( zMsg ){ + Tcl_ListObjAppendElement(interp, pRet, Tcl_NewStringObj(zMsg, -1)); + } + } + rc = sqlite3_intck_error(pCk, &zErr); + } + if( rc!=SQLITE_OK ){ + if( zErr ){ + Tcl_SetObjResult(interp, Tcl_NewStringObj(zErr, -1)); + }else{ + Tcl_SetObjResult(interp, Tcl_NewStringObj(sqlite3ErrName(rc), -1)); + } + }else{ + Tcl_SetObjResult(interp, pRet); + } + Tcl_DecrRefCount(pRet); + sqlite3_intck_close(pCk); + return rc ? TCL_ERROR : TCL_OK; +} + int Sqlitetestintck_Init(Tcl_Interp *interp){ Tcl_CreateObjCommand(interp, "sqlite3_intck", test_sqlite3_intck, 0, 0); + Tcl_CreateObjCommand(interp, "test_do_intck", test_do_intck, 0, 0); return TCL_OK; } diff --git a/manifest b/manifest index bb8e46b123..cf37766470 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\simplementation\sof\ssqlite3_intck_suspend(). -D 2024-02-19T18:03:53.963 +C Use\smore\sefficient\sSQL\sto\sverify\sthat\sindexes\scontain\sentries\sthat\smatch\stheir\stables. +D 2024-02-19T20:15:44.802 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -251,9 +251,9 @@ F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a3 F ext/intck/intck1.test c831bc6ff67da3c5b6c9568640f87ad0442d4fc98ef97bc837133b94bcc645b3 F ext/intck/intck2.test b65d7f627342f767e1d2c447d25619666cec36f516786dd56568bd741e5d7e67 F ext/intck/intck_common.tcl 2895854e7aaf5e199a15f6f82538a00999fd8fc55553bc1f04619af7aa86c0d0 -F ext/intck/sqlite3intck.c 703ff16bc936192cff20d06b015d66279f4594e88371c00b18d17fec4f01ff5c -F ext/intck/sqlite3intck.h 342ee2e2c7636b4daf29fa195d0a3a658272b76b283d586fba50f6bc80fc143d -F ext/intck/test_intck.c eb596269c4a690a9b8ee689b1e52ff6e3306013ec706e319d5b97af05a08f0b9 +F ext/intck/sqlite3intck.c 5f319b7c72b0c01cfa28bb5fdd19be5781eb11f5a5216af2a0870dc7e001414d +F ext/intck/sqlite3intck.h d9501ea480b7c41c0555f39f4f1b7c3e8d54fc1ea6d115de5e1211e0bc11d3e7 +F ext/intck/test_intck.c 06206b35f1428961015c060dd35201246c849625cfdff461e0eeaaf76bda545c F ext/jni/GNUmakefile 59eb05f2a363bdfac8d15d66bed624bfe1ff289229184f3861b95f98a19cf4b2 F ext/jni/README.md d899789a9082a07b99bf30b1bbb6204ae57c060efcaa634536fa669323918f42 F ext/jni/jar-dist.make 030aaa4ae71dd86e4ec5e7c1e6cd86f9dfa47c4592c070d2e35157e42498e1fa @@ -2168,8 +2168,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 444e3c9210026da7eae1ed98850722e002433aa2cc77dbc6b6f80327a6b7a390 -R 6b69910b5d388b58f98078e173b37781 +P c36ada868da74e030ff5002de1f3b31b639b0c43714b91c2e5ca0eda16bb6bc2 +R 830041ceb0564db12655be53580aeb6a U dan -Z 3045521be4122627d743cbd6c4ab9b9c +Z f8e44044aacffa331f677c80763fe8b6 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index fa3faa50cd..eb805d0954 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c36ada868da74e030ff5002de1f3b31b639b0c43714b91c2e5ca0eda16bb6bc2 \ No newline at end of file +c01e008c28895e50b14531b2a1f3f1110aab3b54df41ebdbd416fbac7b1bba94 \ No newline at end of file From a1507a3fa02b8789665e326c8c014f1e58fcd80d Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 19 Feb 2024 20:47:59 +0000 Subject: [PATCH 120/430] Fix a minor hiccup in the computation of the number of btrees to be scanned. FossilOrigin-Name: 91302d9b2720d6b5184e1c24db55d351544adfde4b3d2ddcdc1561f79f11985a --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/pragma.c | 1 - 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 0449436b9d..0ef40d6de1 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C If\sthere\sis\sno\smention\sof\sa\stable\sin\ssqlite_stat1,\suse\sOP_Rewind\sto\ssee\sif\nthe\stable\sis\sempty\sprior\sto\sinvoking\sANALYZE. -D 2024-02-19T20:12:30.657 +C Fix\sa\sminor\shiccup\sin\sthe\scomputation\sof\sthe\snumber\sof\sbtrees\sto\sbe\sscanned. +D 2024-02-19T20:47:59.472 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -732,7 +732,7 @@ F src/parse.y bfd6da46fc895cd8237400ff485d04ab0b32e47eb56de20982bb7f53e56c1f42 F src/pcache.c 040b165f30622a21b7a9a77c6f2e4877a32fb7f22d4c7f0d2a6fa6833a156a75 F src/pcache.h 1497ce1b823cf00094bb0cf3bac37b345937e6f910890c626b16512316d3abf5 F src/pcache1.c 602acb23c471bb8d557a6f0083cc2be641d6cafcafa19e481eba7ef4c9ca0f00 -F src/pragma.c 280945eb4a7b78c82cd1b4d0bdefbb69af685a654f8fbfeb3bfd7dc8fede5fda +F src/pragma.c d0e7832bd99ea1c2695466894401f59fd4589ad98f93285a1d600877d0420070 F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7 F src/prepare.c 371f6115cb69286ebc12c6f2d7511279c2e47d9f54f475d46a554d687a3b312c F src/printf.c d3392b2a20ee314ddeef34fb43c904bf4619eb20ff9a9e07e3950a7e4dcd6912 @@ -2162,8 +2162,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 636615358aebfef80a657d09f15f608df9e64882b2aaa5574ce31a4f1c71fd70 -R 98db8daafbcb183bee3a0d5c6d6f3dec +P 0cc93b19de597866292e0696f89fbd0e22a6cbb374678f5cc096fb889210fe3c +R d2d796f1af82f58905d69562436e5dd5 U drh -Z 53d562a05375d893c6e8245ccbe9b40a +Z d7a267289f8d852622ceaa2fe9f0686a # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index b4d235c325..71cf5e34f0 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0cc93b19de597866292e0696f89fbd0e22a6cbb374678f5cc096fb889210fe3c \ No newline at end of file +91302d9b2720d6b5184e1c24db55d351544adfde4b3d2ddcdc1561f79f11985a \ No newline at end of file diff --git a/src/pragma.c b/src/pragma.c index e65233389e..571d993714 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -2529,7 +2529,6 @@ void sqlite3Pragma( hasStat1 = 1; }else{ szThreshold = -1; /* Always analyze if any index lacks statistics */ - break; } } From ae71fa5d59fa9da292770ec3d14b1f330c079e79 Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 19 Feb 2024 23:58:26 +0000 Subject: [PATCH 121/430] Minor fixes. FossilOrigin-Name: ed5afebc410e3d430e2428d35f027bffb218e5f11036a42f97b080153e89016e --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/pragma.c | 5 +++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 0ef40d6de1..007c09ab9b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sminor\shiccup\sin\sthe\scomputation\sof\sthe\snumber\sof\sbtrees\sto\sbe\sscanned. -D 2024-02-19T20:47:59.472 +C Minor\sfixes. +D 2024-02-19T23:58:26.332 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -732,7 +732,7 @@ F src/parse.y bfd6da46fc895cd8237400ff485d04ab0b32e47eb56de20982bb7f53e56c1f42 F src/pcache.c 040b165f30622a21b7a9a77c6f2e4877a32fb7f22d4c7f0d2a6fa6833a156a75 F src/pcache.h 1497ce1b823cf00094bb0cf3bac37b345937e6f910890c626b16512316d3abf5 F src/pcache1.c 602acb23c471bb8d557a6f0083cc2be641d6cafcafa19e481eba7ef4c9ca0f00 -F src/pragma.c d0e7832bd99ea1c2695466894401f59fd4589ad98f93285a1d600877d0420070 +F src/pragma.c 613d27816d26e9db585fd4a34a627cfb436dc5b63edd73546b0fdaacdfa33772 F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7 F src/prepare.c 371f6115cb69286ebc12c6f2d7511279c2e47d9f54f475d46a554d687a3b312c F src/printf.c d3392b2a20ee314ddeef34fb43c904bf4619eb20ff9a9e07e3950a7e4dcd6912 @@ -2162,8 +2162,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 0cc93b19de597866292e0696f89fbd0e22a6cbb374678f5cc096fb889210fe3c -R d2d796f1af82f58905d69562436e5dd5 +P 91302d9b2720d6b5184e1c24db55d351544adfde4b3d2ddcdc1561f79f11985a +R f5703f8a3a60803127fbc9cadd6a43fe U drh -Z d7a267289f8d852622ceaa2fe9f0686a +Z 926161dae17b79fd58ce2e39147c492e # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 71cf5e34f0..51dda07214 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -91302d9b2720d6b5184e1c24db55d351544adfde4b3d2ddcdc1561f79f11985a \ No newline at end of file +ed5afebc410e3d430e2428d35f027bffb218e5f11036a42f97b080153e89016e \ No newline at end of file diff --git a/src/pragma.c b/src/pragma.c index 571d993714..ca34e80af0 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -2569,6 +2569,7 @@ void sqlite3Pragma( sqlite3OpenTable(pParse, iTabCur, iDb, pTab, OP_OpenRead); sqlite3VdbeAddOp2(v, OP_Rewind, iTabCur, sqlite3VdbeCurrentAddr(v)+2+(opMask&1)); + VdbeCoverage(v); } zSubSql = sqlite3MPrintf(db, "ANALYZE \"%w\".\"%w\"", db->aDb[iDb].zDbSName, pTab->zName); @@ -2587,10 +2588,10 @@ void sqlite3Pragma( /* In a schema with a large number of tables and indexes, scale back ** the analysis_limit to avoid excess run-time in the worst case. */ - if( !db->mallocFailed && nBtree>100 ){ + if( !db->mallocFailed && nLimit>0 && nBtree>100 ){ int iAddr, iEnd; VdbeOp *aOp; - int nLimit = 100*SQLITE_DEFAULT_OPTIMIZE_LIMIT/nBtree; + nLimit = 100*nLimit/nBtree; if( nLimit<100 ) nLimit = 100; aOp = sqlite3VdbeGetOp(v, 0); iEnd = sqlite3VdbeCurrentAddr(v); From 4189c44cff384341fb2a7780a7b5b35c734db9af Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 20 Feb 2024 12:14:07 +0000 Subject: [PATCH 122/430] Another simplification of the PRAGMA optimize logic for improved coverage. FossilOrigin-Name: 6c5a0c85454e3c658e51fab611c169c034447174022eebc52fd8619b528a4765 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/pragma.c | 5 ++--- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 007c09ab9b..e83a2aea80 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Minor\sfixes. -D 2024-02-19T23:58:26.332 +C Another\ssimplification\sof\sthe\sPRAGMA\soptimize\slogic\sfor\simproved\scoverage. +D 2024-02-20T12:14:07.075 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -732,7 +732,7 @@ F src/parse.y bfd6da46fc895cd8237400ff485d04ab0b32e47eb56de20982bb7f53e56c1f42 F src/pcache.c 040b165f30622a21b7a9a77c6f2e4877a32fb7f22d4c7f0d2a6fa6833a156a75 F src/pcache.h 1497ce1b823cf00094bb0cf3bac37b345937e6f910890c626b16512316d3abf5 F src/pcache1.c 602acb23c471bb8d557a6f0083cc2be641d6cafcafa19e481eba7ef4c9ca0f00 -F src/pragma.c 613d27816d26e9db585fd4a34a627cfb436dc5b63edd73546b0fdaacdfa33772 +F src/pragma.c cc9ccfde12caf4db782332dc7edd6c0aaf0bfa9bb8c0bff86a3f138521f11b27 F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7 F src/prepare.c 371f6115cb69286ebc12c6f2d7511279c2e47d9f54f475d46a554d687a3b312c F src/printf.c d3392b2a20ee314ddeef34fb43c904bf4619eb20ff9a9e07e3950a7e4dcd6912 @@ -2162,8 +2162,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 91302d9b2720d6b5184e1c24db55d351544adfde4b3d2ddcdc1561f79f11985a -R f5703f8a3a60803127fbc9cadd6a43fe +P ed5afebc410e3d430e2428d35f027bffb218e5f11036a42f97b080153e89016e +R 1d7e6aefb784a3b060fc17ebc00f9588 U drh -Z 926161dae17b79fd58ce2e39147c492e +Z 39fd458c30bb322f77d1633b20055bca # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 51dda07214..a30b6b2081 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ed5afebc410e3d430e2428d35f027bffb218e5f11036a42f97b080153e89016e \ No newline at end of file +6c5a0c85454e3c658e51fab611c169c034447174022eebc52fd8619b528a4765 \ No newline at end of file diff --git a/src/pragma.c b/src/pragma.c index ca34e80af0..877fb3f721 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -2557,16 +2557,15 @@ void sqlite3Pragma( /* Reanalyze if the table is 10 times larger or smaller than ** the last analysis. Unconditional reanalysis if there are ** unanalyzed indexes. */ + sqlite3OpenTable(pParse, iTabCur, iDb, pTab, OP_OpenRead); if( szThreshold>=0 ){ const LogEst iRange = 33; /* 10x size change */ - sqlite3OpenTable(pParse, iTabCur, iDb, pTab, OP_OpenRead); sqlite3VdbeAddOp4Int(v, OP_IfSizeBetween, iTabCur, sqlite3VdbeCurrentAddr(v)+2+(opMask&1), szThreshold>=iRange ? szThreshold-iRange : -1, szThreshold+iRange); VdbeCoverage(v); - }else if( !hasStat1 ){ - sqlite3OpenTable(pParse, iTabCur, iDb, pTab, OP_OpenRead); + }else{ sqlite3VdbeAddOp2(v, OP_Rewind, iTabCur, sqlite3VdbeCurrentAddr(v)+2+(opMask&1)); VdbeCoverage(v); From 4b2eeb289bef1735ab56aa4867f2c3b69550b9c2 Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 20 Feb 2024 13:10:46 +0000 Subject: [PATCH 123/430] Remove an unused variable from the merge in the previous check-in. FossilOrigin-Name: 5c26bf379e18e28d800525bd03e2d5597e2f37674979302f351b99abfc064749 --- manifest | 13 ++++++------- manifest.uuid | 2 +- src/pragma.c | 6 +----- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/manifest b/manifest index c071235824..abca404cf5 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Enhancements\sto\sPRAGMA\soptimize\sand\sANALYZE.\s\sAdd\sthe\s0x10000\sflag\sto\nPRAGMA\soptimize.\s\sANALYZE\snow\srecords\szero-size\spartial\sindexes\sin\sthe\nsqlite_stat1\stable.\s\sPRAGMA\soptimize\slooks\sfor\sboth\sgrowth\sand\sshrinkage\nin\stable\ssizes,\sand\suses\stighter\sbounds\s(10x\srather\sthan\s25x)\sto\strigger\na\sre-analyze.\s\sPRAGMA\soptimize\sautomatically\suses\sare\sreasonable\nanalysis_limit\sto\sprevent\sexcessive\sruntimes. -D 2024-02-20T12:48:00.737 +C Remove\san\sunused\svariable\sfrom\sthe\smerge\sin\sthe\sprevious\scheck-in. +D 2024-02-20T13:10:46.615 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -732,7 +732,7 @@ F src/parse.y bfd6da46fc895cd8237400ff485d04ab0b32e47eb56de20982bb7f53e56c1f42 F src/pcache.c 040b165f30622a21b7a9a77c6f2e4877a32fb7f22d4c7f0d2a6fa6833a156a75 F src/pcache.h 1497ce1b823cf00094bb0cf3bac37b345937e6f910890c626b16512316d3abf5 F src/pcache1.c 602acb23c471bb8d557a6f0083cc2be641d6cafcafa19e481eba7ef4c9ca0f00 -F src/pragma.c cc9ccfde12caf4db782332dc7edd6c0aaf0bfa9bb8c0bff86a3f138521f11b27 +F src/pragma.c f35ba8fb0b3782ef671cc38b3cdaa457e82befe022558f343240344e57d5f5f4 F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7 F src/prepare.c 371f6115cb69286ebc12c6f2d7511279c2e47d9f54f475d46a554d687a3b312c F src/printf.c d3392b2a20ee314ddeef34fb43c904bf4619eb20ff9a9e07e3950a7e4dcd6912 @@ -2162,9 +2162,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P f18b2524da6bbbcf372b292df52fbe6efa49fd6e1f1f13ef2447279d559f7a08 6c5a0c85454e3c658e51fab611c169c034447174022eebc52fd8619b528a4765 -R 1d7e6aefb784a3b060fc17ebc00f9588 -T +closed 6c5a0c85454e3c658e51fab611c169c034447174022eebc52fd8619b528a4765 +P 63ef234e88857a653fa3541e80d59802ceccb806ac8296e8bae79a385b7086f7 +R a21cfe7fc11d4cc3af701137f92d89ba U drh -Z b62a3cf41afb08b6428ca7c918282668 +Z d6568f521192ee23916aac9c92a235a6 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 54028cc0d8..262b24e277 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -63ef234e88857a653fa3541e80d59802ceccb806ac8296e8bae79a385b7086f7 \ No newline at end of file +5c26bf379e18e28d800525bd03e2d5597e2f37674979302f351b99abfc064749 \ No newline at end of file diff --git a/src/pragma.c b/src/pragma.c index 877fb3f721..af51d18657 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -2486,7 +2486,6 @@ void sqlite3Pragma( int nCheck = 0; /* Number of tables to be optimized */ int nBtree = 0; /* Number of btrees to scan */ int nIndex; /* Number of indexes on the current table */ - int hasStat1; /* True if any STAT1 info available for the table */ if( zRight ){ opMask = (u32)sqlite3Atoi(zRight); @@ -2521,13 +2520,10 @@ void sqlite3Pragma( ** indicate a new, unanalyzed index */ szThreshold = pTab->nRowLogEst; - hasStat1 = (pTab->tabFlags & TF_HasStat1)!=0; nIndex = 0; for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ nIndex++; - if( pIdx->hasStat1 ){ - hasStat1 = 1; - }else{ + if( !pIdx->hasStat1 ){ szThreshold = -1; /* Always analyze if any index lacks statistics */ } } From b468e6832288292695ff5dc6782dd1e5334ee8f6 Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 20 Feb 2024 13:11:27 +0000 Subject: [PATCH 124/430] Remove an unreachable branch from printf(). Change it into an assert(). FossilOrigin-Name: 4c9886b692706723f4b68f58dfef07ab19b192fd19b953917f23b55655af3e02 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/printf.c | 3 ++- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index abca404cf5..40152b32a7 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\san\sunused\svariable\sfrom\sthe\smerge\sin\sthe\sprevious\scheck-in. -D 2024-02-20T13:10:46.615 +C Remove\san\sunreachable\sbranch\sfrom\sprintf().\s\sChange\sit\sinto\san\sassert(). +D 2024-02-20T13:11:27.626 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -735,7 +735,7 @@ F src/pcache1.c 602acb23c471bb8d557a6f0083cc2be641d6cafcafa19e481eba7ef4c9ca0f00 F src/pragma.c f35ba8fb0b3782ef671cc38b3cdaa457e82befe022558f343240344e57d5f5f4 F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7 F src/prepare.c 371f6115cb69286ebc12c6f2d7511279c2e47d9f54f475d46a554d687a3b312c -F src/printf.c d3392b2a20ee314ddeef34fb43c904bf4619eb20ff9a9e07e3950a7e4dcd6912 +F src/printf.c 10e8bad30042f8bd6114a013b4afc229ec8ad255ab27518d7d9f52e8cbc5cd0a F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c d77c6160bc8f249c2196fdd3e75f66a1dd70e37aa25c39aedc7b1f93c42b7c6d F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 @@ -2162,8 +2162,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 63ef234e88857a653fa3541e80d59802ceccb806ac8296e8bae79a385b7086f7 -R a21cfe7fc11d4cc3af701137f92d89ba +P 5c26bf379e18e28d800525bd03e2d5597e2f37674979302f351b99abfc064749 +R 521cc3374b233ca8db7b57619e6235d0 U drh -Z d6568f521192ee23916aac9c92a235a6 +Z f1be525f7ee6098da75f01bd7c5e0ac8 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 262b24e277..a714b19d22 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5c26bf379e18e28d800525bd03e2d5597e2f37674979302f351b99abfc064749 \ No newline at end of file +4c9886b692706723f4b68f58dfef07ab19b192fd19b953917f23b55655af3e02 \ No newline at end of file diff --git a/src/printf.c b/src/printf.c index 2e09431bf2..186e95bb85 100644 --- a/src/printf.c +++ b/src/printf.c @@ -534,13 +534,14 @@ void sqlite3_str_vappendf( } exp = s.iDP-1; - if( xtype==etGENERIC && precision>0 ) precision--; /* ** If the field type is etGENERIC, then convert to either etEXP ** or etFLOAT, as appropriate. */ if( xtype==etGENERIC ){ + assert( precision>0 ); + precision--; flag_rtz = !flag_alternateform; if( exp<-4 || exp>precision ){ xtype = etEXP; From 21eda699d7154c045c72e8c848ebe2ade011165f Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 20 Feb 2024 15:38:36 +0000 Subject: [PATCH 125/430] Fixes to comments associated with the recent PRAGMA optimize enhancements. No changes to code. FossilOrigin-Name: 27a2113d78b35e324e9aedda7403c96c56ad0bed8c6b139fc5a179e8800b9109 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/pragma.c | 5 +---- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 40152b32a7..8ad3679fb6 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\san\sunreachable\sbranch\sfrom\sprintf().\s\sChange\sit\sinto\san\sassert(). -D 2024-02-20T13:11:27.626 +C Fixes\sto\scomments\sassociated\swith\sthe\srecent\sPRAGMA\soptimize\senhancements.\nNo\schanges\sto\scode. +D 2024-02-20T15:38:36.661 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -732,7 +732,7 @@ F src/parse.y bfd6da46fc895cd8237400ff485d04ab0b32e47eb56de20982bb7f53e56c1f42 F src/pcache.c 040b165f30622a21b7a9a77c6f2e4877a32fb7f22d4c7f0d2a6fa6833a156a75 F src/pcache.h 1497ce1b823cf00094bb0cf3bac37b345937e6f910890c626b16512316d3abf5 F src/pcache1.c 602acb23c471bb8d557a6f0083cc2be641d6cafcafa19e481eba7ef4c9ca0f00 -F src/pragma.c f35ba8fb0b3782ef671cc38b3cdaa457e82befe022558f343240344e57d5f5f4 +F src/pragma.c f5cb82c15b7455d42e748cad8a6c367db18ada0fadc9b4adba03de953a81d46a F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7 F src/prepare.c 371f6115cb69286ebc12c6f2d7511279c2e47d9f54f475d46a554d687a3b312c F src/printf.c 10e8bad30042f8bd6114a013b4afc229ec8ad255ab27518d7d9f52e8cbc5cd0a @@ -2162,8 +2162,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 5c26bf379e18e28d800525bd03e2d5597e2f37674979302f351b99abfc064749 -R 521cc3374b233ca8db7b57619e6235d0 +P 4c9886b692706723f4b68f58dfef07ab19b192fd19b953917f23b55655af3e02 +R 40f50207938b86842b8686e871138379 U drh -Z f1be525f7ee6098da75f01bd7c5e0ac8 +Z 751534f3f8e8461179e5c9344b944b7a # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index a714b19d22..a82c127f34 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4c9886b692706723f4b68f58dfef07ab19b192fd19b953917f23b55655af3e02 \ No newline at end of file +27a2113d78b35e324e9aedda7403c96c56ad0bed8c6b139fc5a179e8800b9109 \ No newline at end of file diff --git a/src/pragma.c b/src/pragma.c index af51d18657..62fd17911a 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -2427,9 +2427,6 @@ void sqlite3Pragma( ** database will usually be less than 100 milliseconds on ** a RaspberryPI-4 class machine. On by default. ** - ** 0x00020 Run ANALYZE on any table that has a index that lacks an - ** entry in the sqlite_stat1 table. On by default. - ** ** 0x10000 Look at tables to see if they need to be reanalyzed ** due to growth or shrinkage even if they have not been ** queried during the current connection. Off by default. @@ -2456,7 +2453,7 @@ void sqlite3Pragma( ** (4b) One or more indexes on the table lacks an entry ** in the sqlite_stat1 table. ** (4c) The query planner used sqlite_stat1-style statistics for one - ** or more indexes of the tableat some point during the lifetime + ** or more indexes of the table at some point during the lifetime ** of the current connection. ** ** (5) One or more of the following is true: From 626d6192185c33a047966144392d5d3b6b3597ed Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 20 Feb 2024 16:04:27 +0000 Subject: [PATCH 126/430] Consider using "=" and IS operators with even low-quality indexes in cases where they are selected explicitly using an INDEXED BY clause. FossilOrigin-Name: 43cbbea82132db2d0ddb4f34cc2b6910b3a1243ae6d4e837b1b27bfe91b84834 --- ext/intck/intck1.test | 14 ++++++++++++++ manifest | 14 +++++++------- manifest.uuid | 2 +- src/where.c | 4 +++- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/ext/intck/intck1.test b/ext/intck/intck1.test index e5a25dda8e..7f60f1fdc6 100644 --- a/ext/intck/intck1.test +++ b/ext/intck/intck1.test @@ -88,6 +88,20 @@ do_catchsql_test 1.5.4 { } {1 {unsupported use of NULLS FIRST}} +reset_db +do_execsql_test 1.6.1 { + CREATE TABLE t1(i INTEGER PRIMARY KEY, b, c); + CREATE INDEX i1 ON t1(b); + ANALYZE; + INSERT INTO sqlite_stat1 VALUES('t1', 'i1', '10000 10000'); + ANALYZE sqlite_schema; +} {} +do_eqp_test 1.6.2 { + SELECT 1 FROM t1 INDEXED BY i1 WHERE (b, i) IS (?, ?); +} {SEARCH} + + + #------------------------------------------------------------------------- reset_db diff --git a/manifest b/manifest index cf37766470..e254a597a2 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Use\smore\sefficient\sSQL\sto\sverify\sthat\sindexes\scontain\sentries\sthat\smatch\stheir\stables. -D 2024-02-19T20:15:44.802 +C Consider\susing\s"="\sand\sIS\soperators\swith\seven\slow-quality\sindexes\sin\scases\swhere\sthey\sare\sselected\sexplicitly\susing\san\sINDEXED\sBY\sclause. +D 2024-02-20T16:04:27.694 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -248,7 +248,7 @@ F ext/fts5/tool/showfts5.tcl d54da0e067306663e2d5d523965ca487698e722c F ext/icu/README.txt 7ab7ced8ae78e3a645b57e78570ff589d4c672b71370f5aa9e1cd7024f400fc9 F ext/icu/icu.c c074519b46baa484bb5396c7e01e051034da8884bad1a1cb7f09bbe6be3f0282 F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a32075a8 -F ext/intck/intck1.test c831bc6ff67da3c5b6c9568640f87ad0442d4fc98ef97bc837133b94bcc645b3 +F ext/intck/intck1.test 5b3c9800e119b4dd50a381974f34cee6cfd5b7434286fb8da83b7c8ff1d6bb3c F ext/intck/intck2.test b65d7f627342f767e1d2c447d25619666cec36f516786dd56568bd741e5d7e67 F ext/intck/intck_common.tcl 2895854e7aaf5e199a15f6f82538a00999fd8fc55553bc1f04619af7aa86c0d0 F ext/intck/sqlite3intck.c 5f319b7c72b0c01cfa28bb5fdd19be5781eb11f5a5216af2a0870dc7e001414d @@ -830,7 +830,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c 887fc4ca3f020ebb2e376f222069570834ac63bf50111ef0cbf3ae417048ed89 F src/wal.h ba252daaa94f889f4b2c17c027e823d9be47ce39da1d3799886bbd51f0490452 F src/walker.c 7c7ea0115345851c3da4e04e2e239a29983b61fb5b038b94eede6aba462640e2 -F src/where.c 0e7bf004a578eb70d54300503fdbcaaea857de6ba0204aae1adf572edb79c2c6 +F src/where.c 33eaaeef3aef10c2b9e82096e70a174d6636e35cb0b180321b8ddf804590e5cd F src/whereInt.h 82a13766f13d1a53b05387c2e60726289ef26404bc7b9b1f7770204d97357fb8 F src/wherecode.c 5d77db30a2a3dd532492ae882de114edba2fae672622056b1c7fd61f5917a8f1 F src/whereexpr.c dc5096eca5ed503999be3bdee8a90c51361289a678d396a220912e9cb73b3c00 @@ -2168,8 +2168,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P c36ada868da74e030ff5002de1f3b31b639b0c43714b91c2e5ca0eda16bb6bc2 -R 830041ceb0564db12655be53580aeb6a +P c01e008c28895e50b14531b2a1f3f1110aab3b54df41ebdbd416fbac7b1bba94 +R 8db173421c176ccb487011bd9440e123 U dan -Z f8e44044aacffa331f677c80763fe8b6 +Z d4e70ffeb295fbc1a103b9adca306ecc # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index eb805d0954..4565b3d528 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c01e008c28895e50b14531b2a1f3f1110aab3b54df41ebdbd416fbac7b1bba94 \ No newline at end of file +43cbbea82132db2d0ddb4f34cc2b6910b3a1243ae6d4e837b1b27bfe91b84834 \ No newline at end of file diff --git a/src/where.c b/src/where.c index 0e526b3372..9850d22cc3 100644 --- a/src/where.c +++ b/src/where.c @@ -2975,7 +2975,9 @@ static int whereLoopAddBtreeIndex( } if( pProbe->bUnordered || pProbe->bLowQual ){ if( pProbe->bUnordered ) opMask &= ~(WO_GT|WO_GE|WO_LT|WO_LE); - if( pProbe->bLowQual ) opMask &= ~(WO_EQ|WO_IN|WO_IS); + if( pProbe->bLowQual && pSrc->fg.isIndexedBy==0 ){ + opMask &= ~(WO_EQ|WO_IN|WO_IS); + } } assert( pNew->u.btree.nEqnColumn ); From cfcb3b9208236e6d40633bf574de2b7559ad4c9f Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 20 Feb 2024 18:17:06 +0000 Subject: [PATCH 127/430] Use fewer cycles to generate the "next key" value used by sqlite3_intck_suspend() function in the intck extension. FossilOrigin-Name: 95f01426f948cf435d0b400dc7ae06fa699eee32cff498fe77e74a1257a4e09b --- ext/intck/sqlite3intck.c | 218 ++++++++++++++++++++++++++++++++------- manifest | 12 +-- manifest.uuid | 2 +- 3 files changed, 189 insertions(+), 43 deletions(-) diff --git a/ext/intck/sqlite3intck.c b/ext/intck/sqlite3intck.c index 05eaa81a93..6d54526928 100644 --- a/ext/intck/sqlite3intck.c +++ b/ext/intck/sqlite3intck.c @@ -16,12 +16,25 @@ #include #include +/* +** apKeyVal: +** If sqlite3_intck_suspend() is called when there is a running pCheck +** statement, this array is allocated and populated with the key values +** required to restart the check. If the intck object has not been +** suspended, this is set to NULL. +** +** nKeyVal: +** The size of the apKeyVal[] array, if it is allocated. +*/ struct sqlite3_intck { sqlite3 *db; const char *zDb; /* Copy of zDb parameter to _open() */ char *zObj; /* Current object. Or NULL. */ - char *zKey; /* Key saved by _intck_suspend() call. */ + sqlite3_stmt *pCheck; /* Current check statement */ + int nKeyVal; + sqlite3_value **apKeyVal; + int rc; /* Error code */ char *zErr; /* Error message */ char *zTestSql; /* Returned by sqlite3_intck_test_sql() */ @@ -82,18 +95,117 @@ static void intckFinalize(sqlite3_intck *p, sqlite3_stmt *pStmt){ } } +/* +** Wrapper around sqlite3_malloc64() that uses the sqlite3_intck error +** code convention. +*/ +static void *intckMalloc(sqlite3_intck *p, sqlite3_int64 nByte){ + void *pRet = 0; + assert( nByte>0 ); + if( p->rc==SQLITE_OK ){ + pRet = sqlite3_malloc64(nByte); + if( pRet==0 ){ + p->rc = SQLITE_NOMEM; + } + } + return pRet; +} + +/* +** If p->rc is other than SQLITE_OK when this function is called, it +** immediately returns NULL. Otherwise, it attempts to create a copy of +** nul-terminated string zIn in a buffer obtained from sqlite3_malloc(). +** If successful, a pointer to this buffer is returned and it becomes +** the responsibility of the caller to release it using sqlite3_free() +** at some point in the future. +** +** Or, if an allocation fails within this function, p->rc is set to +** SQLITE_NOMEM and NULL is returned. +*/ static char *intckStrdup(sqlite3_intck *p, const char *zIn){ char *zOut = 0; + int nIn = strlen(zIn); + zOut = (char*)intckMalloc(p, nIn+1); + if( zOut ){ + memcpy(zOut, zIn, nIn+1); + } + return zOut; +} + +/* +** A wrapper around sqlite3_mprintf() that: +** +** + Always returns 0 if p->rc is other than SQLITE_OK when it is called, and +** + Sets p->rc to SQLITE_NOMEM if an allocation fails. +*/ +static char *intckMprintf(sqlite3_intck *p, const char *zFmt, ...){ + va_list ap; + char *zRet = 0; + va_start(ap, zFmt); + zRet = sqlite3_vmprintf(zFmt, ap); if( p->rc==SQLITE_OK ){ - int nIn = strlen(zIn); - zOut = sqlite3_malloc(nIn+1); - if( zOut==0 ){ + if( zRet==0 ){ p->rc = SQLITE_NOMEM; - }else{ - memcpy(zOut, zIn, nIn+1); } + }else{ + sqlite3_free(zRet); + zRet = 0; + } + return zRet; +} + +/* +** Free the sqlite3_intck.apKeyVal, if it is allocated and populated. +*/ +static void intckSavedKeyClear(sqlite3_intck *p){ + if( p->apKeyVal ){ + int ii; + for(ii=0; iinKeyVal; ii++){ + sqlite3_value_free(p->apKeyVal[ii]); + } + sqlite3_free(p->apKeyVal); + p->apKeyVal = 0; } - return zOut; +} + +/* +** If the apKeyVal array is currently allocated and populated, return +** a pointer to a buffer containing a nul-terminated string representing +** the values as an SQL vector. e.g. +** +** "('abc', NULL, 2)" +** +** If apKeyVal is not allocated, return NULL. Or, if an error (e.g. OOM) +** occurs within this function, set sqlite3_intck.rc before returning +** and return NULL. +*/ +static char *intckSavedKeyToText(sqlite3_intck *p){ + char *zRet = 0; + if( p->apKeyVal ){ + int ii; + const char *zSep = "SELECT '(' || "; + char *zSql = 0; + sqlite3_stmt *pStmt = 0; + + for(ii=0; iinKeyVal; ii++){ + zSql = intckMprintf(p, "%z%squote(?)", zSql, zSep); + zSep = " || ', ' || "; + } + zSql = intckMprintf(p, "%z || ')'", zSql); + + pStmt = intckPrepare(p, "%s", zSql); + if( p->rc==SQLITE_OK ){ + for(ii=0; iinKeyVal; ii++){ + sqlite3_bind_value(pStmt, ii+1, p->apKeyVal[ii]); + } + if( SQLITE_ROW==sqlite3_step(pStmt) ){ + zRet = intckStrdup(p, (const char*)sqlite3_column_text(pStmt, 0)); + } + intckFinalize(p, pStmt); + } + sqlite3_free(zSql); + } + return zRet; } static void intckFindObject(sqlite3_intck *p){ @@ -112,7 +224,7 @@ static void intckFindObject(sqlite3_intck *p){ "SELECT table_name FROM tables " "WHERE ?1 IS NULL OR table_name%s?1 " "ORDER BY 1" - , p->zDb, (p->zKey ? ">=" : ">") + , p->zDb, (p->apKeyVal ? ">=" : ">") ); if( p->rc==SQLITE_OK ){ @@ -125,8 +237,7 @@ static void intckFindObject(sqlite3_intck *p){ /* If this is a new object, ensure the previous key value is cleared. */ if( sqlite3_stricmp(p->zObj, zPrev) ){ - sqlite3_free(p->zKey); - p->zKey = 0; + intckSavedKeyClear(p); } sqlite3_free(zPrev); @@ -332,7 +443,8 @@ static void intckExec(sqlite3_intck *p, const char *zSql){ static char *intckCheckObjectSql( sqlite3_intck *p, const char *zObj, - const char *zPrev + const char *zPrev, + int *pnKeyVal /* OUT: Number of key-values for this scan */ ){ char *zRet = 0; sqlite3_stmt *pStmt = 0; @@ -377,7 +489,16 @@ static char *intckCheckObjectSql( ")" "" "" - ", tabpk(db, tab, idx, o_pk, i_pk, q_pk, eq_pk, ps_pk, pk_pk) AS (" + /* + ** For a PK declared as "PRIMARY KEY(a, b) ... WITHOUT ROWID", where + ** the intck_wrapper aliases of "a" and "b" are "c1" and "c2": + ** + ** o_pk: "o.c1, o.c2" + ** i_pk: "i.'a', i.'b'" + ** ... + ** n_pk: 2 + */ + ", tabpk(db, tab, idx, o_pk, i_pk, q_pk, eq_pk, ps_pk, pk_pk, n_pk) AS (" " WITH pkfields(f, a) AS (" " SELECT i.col_name, i.col_alias FROM idx_cols i WHERE i.idx_ispk" " )" @@ -390,7 +511,8 @@ static char *intckCheckObjectSql( " group_concat(format('\"%w\"', f), ', ')" " )," " group_concat('%s', ',')," - " group_concat('quote('||a||')', ', ') " + " group_concat('quote('||a||')', ', '), " + " count(*)" " FROM tabname t, pkfields" ")" "" @@ -467,11 +589,10 @@ static char *intckCheckObjectSql( " FROM tabname t, tabpk p, idx_cols i WHERE i.idx_name=t.idx" ")" "" - ", thiskey(k) AS (" - " SELECT format('format(''(%%s,%%s)'', %%s, %%s) AS thiskey', " - " group_concat('%%s', ','), p.ps_pk, " - " group_concat('quote('||i.col_alias||')',', '), p.pk_pk" - " ) FROM tabpk p, idx_cols i WHERE i.idx_name=p.idx" + ", thiskey(k, n) AS (" + " SELECT group_concat(i.col_alias, ', ') || ', ' || p.o_pk, " + " count(*) + p.n_pk " + " FROM tabpk p, idx_cols i WHERE i.idx_name=p.idx" ")" "" ", whereclause(w_c) AS (" @@ -483,15 +604,15 @@ static char *intckCheckObjectSql( " FROM tabpk, tabname, idx_cols i WHERE i.idx_name=tabpk.idx" ")" "" - ", main_select(m) AS (" + ", main_select(m, n) AS (" " SELECT format(" " 'WITH %%s\nSELECT %%s,\n%%s\nFROM intck_wrapper AS o%%s'," " ww.s, c, t.k, whereclause.w_c" - " )" + " ), t.n" " FROM case_statement, wrapper_with ww, thiskey t, whereclause" ")" - "SELECT m FROM main_select" + "SELECT m, n FROM main_select" , p->zDb, p->zDb, zObj, zObj , zPrev, zCommon ); @@ -549,9 +670,8 @@ static char *intckCheckObjectSql( ** ** format('(%d,%d)', _rowid_, n.ii) */ - ", thiskey(k) AS (" - " SELECT 'format(''(' || ps_pk || ',%%d)'', ' || pk_pk || ', n.ii)'" - " FROM tabpk" + ", thiskey(k, n) AS (" + " SELECT o_pk || ', n.ii', n_pk+1 FROM tabpk" ")" "" ", whereclause(w_c) AS (" @@ -562,17 +682,17 @@ static char *intckCheckObjectSql( " FROM tabpk, tabname" ")" "" - ", main_select(m) AS (" + ", main_select(m, n) AS (" " SELECT format(" " '%%s, %%s\nSELECT %%s,\n%%s AS thiskey\nFROM intck_wrapper AS o" ", intck_counter AS n%%s\nORDER BY %%s', " " w, ww.s, c, thiskey.k, whereclause.w_c, t.o_pk" - " )" + " ), thiskey.n" " FROM case_statement, tabpk t, counter_with, " " wrapper_with ww, thiskey, whereclause" ")" - "SELECT m FROM main_select", + "SELECT m, n FROM main_select", p->zDb, zObj, zPrev, zCommon ); } @@ -590,6 +710,9 @@ static char *intckCheckObjectSql( fflush(stdout); #else zRet = intckStrdup(p, (const char*)sqlite3_column_text(pStmt, 0)); + if( pnKeyVal ){ + *pnKeyVal = sqlite3_column_int(pStmt, 1); + } #endif } intckFinalize(p, pStmt); @@ -599,11 +722,14 @@ static char *intckCheckObjectSql( } static void intckCheckObject(sqlite3_intck *p){ - char *zSql = intckCheckObjectSql(p, p->zObj, p->zKey); + char *zSql = 0; + char *zKey = 0; + zKey = intckSavedKeyToText(p); + zSql = intckCheckObjectSql(p, p->zObj, zKey, &p->nKeyVal); p->pCheck = intckPrepare(p, "%s", zSql); sqlite3_free(zSql); - sqlite3_free(p->zKey); - p->zKey = 0; + sqlite3_free(zKey); + intckSavedKeyClear(p); } int sqlite3_intck_open( @@ -644,7 +770,7 @@ int sqlite3_intck_close(sqlite3_intck *p){ ); } sqlite3_free(p->zObj); - sqlite3_free(p->zKey); + intckSavedKeyClear(p); sqlite3_free(p->zTestSql); sqlite3_free(p->zErr); sqlite3_free(p); @@ -668,12 +794,13 @@ int sqlite3_intck_step(sqlite3_intck *p){ if( p->rc==SQLITE_OK ){ assert( p->pCheck ); if( sqlite3_step(p->pCheck)==SQLITE_ROW ){ - /* Fine, whatever... */ + /* Normal case, do nothing. */ }else{ if( sqlite3_finalize(p->pCheck)!=SQLITE_OK ){ intckSaveErrmsg(p); } p->pCheck = 0; + p->nKeyVal = 0; } } } @@ -693,10 +820,27 @@ int sqlite3_intck_error(sqlite3_intck *p, const char **pzErr){ return (p->rc==SQLITE_DONE ? SQLITE_OK : p->rc); } + +static sqlite3_value *intckValueDup(sqlite3_intck *p, sqlite3_value *pIn){ + sqlite3_value *pRet = 0; + if( p->rc==SQLITE_OK ){ + pRet = sqlite3_value_dup(pIn); + if( pRet==0 ){ + p->rc = SQLITE_NOMEM; + } + } + return pRet; +} + int sqlite3_intck_suspend(sqlite3_intck *p){ if( p->pCheck && p->rc==SQLITE_OK ){ - assert( p->zKey==0 ); - p->zKey = intckStrdup(p, (const char*)sqlite3_column_text(p->pCheck, 1)); + const int nByte = sizeof(sqlite3_value*) * p->nKeyVal; + int ii; + assert( p->apKeyVal==0 && p->nKeyVal>0 ); + p->apKeyVal = (sqlite3_value**)intckMalloc(p, nByte); + for(ii=0; p->rc==SQLITE_OK && iinKeyVal; ii++){ + p->apKeyVal[ii] = intckValueDup(p, sqlite3_column_value(p->pCheck, ii+1)); + } intckFinalize(p, p->pCheck); p->pCheck = 0; } @@ -706,10 +850,12 @@ int sqlite3_intck_suspend(sqlite3_intck *p){ const char *sqlite3_intck_test_sql(sqlite3_intck *p, const char *zObj){ sqlite3_free(p->zTestSql); if( zObj ){ - p->zTestSql = intckCheckObjectSql(p, zObj, 0); + p->zTestSql = intckCheckObjectSql(p, zObj, 0, 0); }else{ if( p->zObj ){ - p->zTestSql = intckCheckObjectSql(p, p->zObj, p->zKey); + char *zKey = intckSavedKeyToText(p); + p->zTestSql = intckCheckObjectSql(p, p->zObj, zKey, 0); + sqlite3_free(zKey); }else{ sqlite3_free(p->zTestSql); p->zTestSql = 0; diff --git a/manifest b/manifest index e254a597a2..39fc17cfc5 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Consider\susing\s"="\sand\sIS\soperators\swith\seven\slow-quality\sindexes\sin\scases\swhere\sthey\sare\sselected\sexplicitly\susing\san\sINDEXED\sBY\sclause. -D 2024-02-20T16:04:27.694 +C Use\sfewer\scycles\sto\sgenerate\sthe\s"next\skey"\svalue\sused\sby\ssqlite3_intck_suspend()\sfunction\sin\sthe\sintck\sextension. +D 2024-02-20T18:17:06.096 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -251,7 +251,7 @@ F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a3 F ext/intck/intck1.test 5b3c9800e119b4dd50a381974f34cee6cfd5b7434286fb8da83b7c8ff1d6bb3c F ext/intck/intck2.test b65d7f627342f767e1d2c447d25619666cec36f516786dd56568bd741e5d7e67 F ext/intck/intck_common.tcl 2895854e7aaf5e199a15f6f82538a00999fd8fc55553bc1f04619af7aa86c0d0 -F ext/intck/sqlite3intck.c 5f319b7c72b0c01cfa28bb5fdd19be5781eb11f5a5216af2a0870dc7e001414d +F ext/intck/sqlite3intck.c 7a795f23424a29f656f3d4c7b83d23484746b57cdc25d3fb98ec805d017fc935 F ext/intck/sqlite3intck.h d9501ea480b7c41c0555f39f4f1b7c3e8d54fc1ea6d115de5e1211e0bc11d3e7 F ext/intck/test_intck.c 06206b35f1428961015c060dd35201246c849625cfdff461e0eeaaf76bda545c F ext/jni/GNUmakefile 59eb05f2a363bdfac8d15d66bed624bfe1ff289229184f3861b95f98a19cf4b2 @@ -2168,8 +2168,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P c01e008c28895e50b14531b2a1f3f1110aab3b54df41ebdbd416fbac7b1bba94 -R 8db173421c176ccb487011bd9440e123 +P 43cbbea82132db2d0ddb4f34cc2b6910b3a1243ae6d4e837b1b27bfe91b84834 +R 9dcf98c64d0302d62dce4c3c1b529641 U dan -Z d4e70ffeb295fbc1a103b9adca306ecc +Z c2dbf2f2090bfeaba66446a197f3ad62 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 4565b3d528..69d33b6938 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -43cbbea82132db2d0ddb4f34cc2b6910b3a1243ae6d4e837b1b27bfe91b84834 \ No newline at end of file +95f01426f948cf435d0b400dc7ae06fa699eee32cff498fe77e74a1257a4e09b \ No newline at end of file From eb715f022f71d912e11b51ba7ab68f77d92e0234 Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 20 Feb 2024 20:18:02 +0000 Subject: [PATCH 128/430] Have the intck extension better handle corruption at the b-tree layer. FossilOrigin-Name: ecd775d108f77d39a1303316c1e0f0b0ae3ffc5218222e1ebfe2ef6783829b85 --- ext/intck/intck1.test | 2 +- ext/intck/intck_common.tcl | 4 +- ext/intck/intckcorrupt.test | 235 ++++++++++++++++++++++++++++++++++++ ext/intck/sqlite3intck.c | 53 ++++++-- ext/intck/sqlite3intck.h | 3 +- ext/intck/test_intck.c | 11 +- manifest | 21 ++-- manifest.uuid | 2 +- 8 files changed, 297 insertions(+), 34 deletions(-) create mode 100644 ext/intck/intckcorrupt.test diff --git a/ext/intck/intck1.test b/ext/intck/intck1.test index 7f60f1fdc6..4110ece049 100644 --- a/ext/intck/intck1.test +++ b/ext/intck/intck1.test @@ -106,7 +106,7 @@ do_eqp_test 1.6.2 { reset_db do_test 2.0 { - set ic [sqlite3_intck db main ""] + set ic [sqlite3_intck db main] $ic close } {} diff --git a/ext/intck/intck_common.tcl b/ext/intck/intck_common.tcl index 757ca82b3f..f00a465b3c 100644 --- a/ext/intck/intck_common.tcl +++ b/ext/intck/intck_common.tcl @@ -16,7 +16,7 @@ if {![info exists testdir]} { source $testdir/tester.tcl proc do_intck {db {bSuspend 0}} { - set ic [sqlite3_intck $db main ""] + set ic [sqlite3_intck $db main] set ret [list] while {"SQLITE_OK"==[$ic step]} { @@ -37,7 +37,7 @@ proc do_intck {db {bSuspend 0}} { } proc intck_sql {db tbl} { - set ic [sqlite3_intck $db main ""] + set ic [sqlite3_intck $db main] set sql [$ic test_sql $tbl] $ic close return $sql diff --git a/ext/intck/intckcorrupt.test b/ext/intck/intckcorrupt.test new file mode 100644 index 0000000000..40f009f9c2 --- /dev/null +++ b/ext/intck/intckcorrupt.test @@ -0,0 +1,235 @@ +# 2024 Feb 21 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# The focus of this file is testing the intck extensions response +# to corruption at the b-tree level. +# + +source [file join [file dirname [info script]] intck_common.tcl] +set testprefix intckcorrupt + +#------------------------------------------------------------------------- +reset_db +do_test 1.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +| size 356352 pagesize 4096 filename crash-acaae0347204ae.db +| page 1 offset 0 +| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. +| 16: 10 00 01 01 00 40 20 20 00 00 00 00 d0 00 00 00 .....@ ........ +| 32: 40 00 ea 00 00 00 00 00 00 40 00 00 00 40 00 00 @........@...@.. +| 96: 00 00 00 00 0d 00 00 00 04 0e 9c 00 0f ad 0f 4f ...............O +| 112: 0e fc 0e 9c 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 3728: 00 00 00 00 00 00 00 00 00 00 00 00 5e 04 07 17 ............^... +| 3744: 1f 1f 01 81 0b 74 61 62 6c 65 74 31 5f 70 61 72 .....tablet1_par +| 3760: 65 6e 74 74 31 5f 70 61 72 65 6e 74 04 43 52 45 entt1_parent.CRE +| 3776: 41 54 45 20 54 41 42 4c 45 20 22 74 31 5f 70 61 ATE TABLE .t1_pa +| 3792: 72 65 6e 74 22 28 6e 6f 64 65 6e 6f 20 49 4e 54 rent.(nodeno INT +| 3808: 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 EGER PRIMARY KEY +| 3824: 2c 70 61 72 65 6e 74 6e 6f 64 65 29 51 03 06 17 ,parentnode)Q... +| 3840: 1b 1b 01 7b 74 61 62 6c 65 74 31 5f 6e 6f 64 65 ....tablet1_node +| 3856: 74 31 5f 6e 6f 64 65 03 43 52 45 41 54 45 20 54 t1_node.CREATE T +| 3872: 41 42 4c 45 20 22 74 31 5f 6e 6f 64 65 22 28 6e ABLE .t1_node.(n +| 3888: 6f 64 65 6e 6f 20 49 4e 54 45 47 45 52 20 50 52 odeno INTEGER PR +| 3904: 49 4d 41 52 59 20 4b 45 59 2c 64 61 74 61 29 5c IMARY KEY,data). +| 3920: 02 07 17 1d 1d 01 81 0b 74 61 62 6c 65 74 31 5f ........tablet1_ +| 3936: 72 6f 77 69 64 74 31 5f 72 6f 77 69 64 02 43 52 rowidt1_rowid.CR +| 3952: 45 41 54 45 20 54 41 42 4c 45 20 22 74 31 5f 72 EATE TABLE .t1_r +| 3968: 6f 77 69 64 22 28 72 6f 77 69 64 20 49 4e 54 45 owid.(rowid INTE +| 3984: 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c GER PRIMARY KEY, +| 4000: 6e 6f 64 65 6e 6f 2c 61 30 2c 61 31 29 51 01 07 nodeno,a0,a1)Q.. +| 4016: 17 11 11 08 81 0f 74 61 62 6c 65 74 31 74 31 43 ......tablet1t1C +| 4032: 52 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 REATE VIRTUAL TA +| 4048: 42 4c 45 20 74 31 20 55 53 49 4e 47 20 72 74 72 BLE t1 USING rtr +| 4064: 65 65 28 69 64 2c 78 30 20 50 52 49 4d 41 52 59 ee(id,x0 PRIMARY +| 4080: 20 4b 45 59 2c 70 61 72 65 6e 74 6e 6f 64 65 29 KEY,parentnode) +| page 2 offset 4096 +| 0: 51 03 06 17 1b 1b 01 7b 74 61 62 6c 65 74 31 5f Q.......tablet1_ +| 16: 6e 6f 64 65 74 31 5f 6e 6f 64 65 03 43 52 45 41 nodet1_node.CREA +| 32: 54 45 20 54 41 42 4c 45 20 22 74 31 5f 6e 6f 64 TE TABLE .t1_nod +| 48: 65 22 28 6e 6f 64 65 6e 6f 20 49 4e 54 45 47 45 e.(nodeno INTEGE +| 64: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 64 61 R PRIMARY KEY,da +| 80: 74 61 29 5c 02 07 17 1d 1d 01 81 0b 74 61 62 6c ta).........tabl +| 96: 65 74 31 5f 72 6f 77 69 64 74 31 5f 72 6f 77 69 et1_rowidt1_rowi +| 112: 64 02 43 52 45 41 54 45 20 54 41 42 4c 45 00 00 d.CREATE TABLE.. +| 128: 01 0a 02 00 00 00 01 0e 0d 00 00 00 00 24 0e 0d .............$.. +| 144: 0c 1a 06 85 50 46 60 27 70 08 00 00 00 00 00 00 ....PF`'p....... +| 3824: 00 00 00 00 00 00 00 0d 0e 05 00 09 1d 00 74 6f ..............to +| 3840: 79 20 68 61 6c 66 10 0d 05 00 09 23 00 62 6f 74 y half.....#.bot +| 3856: 74 6f 6d 20 68 61 6c 66 0f 0c 05 00 09 21 00 72 tom half.....!.r +| 3872: 69 67 68 74 20 68 61 6c 66 0e 0b 05 00 09 1f 00 ight half....... +| 3888: 6c 65 66 74 20 43 15 f6 e6 f6 46 50 34 35 24 54 left C....FP45$T +| 3904: 15 44 52 05 44 14 24 c4 52 02 27 43 15 f6 e6 f6 .DR.D.$.R.'C.... +| 3920: 46 52 22 8e 6f 64 65 6e 6f 20 49 4e 54 45 47 45 FR..odeno INTEGE +| 3936: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 64 61 R PRIMARY KEY,da +| 3952: 74 61 29 5c 02 07 17 1d 1d 01 81 0b 74 61 62 6c ta).........tabl +| 3968: 65 74 31 5f 72 6f 74 74 6f 6d 20 65 64 67 65 0f et1_rottom edge. +| 3984: 07 05 00 09 21 00 72 69 67 68 74 20 65 64 67 65 ....!.right edge +| 4000: 0e 06 05 00 09 1f 00 6c 65 66 74 20 65 64 67 65 .......left edge +| 4016: 0b 05 05 00 09 19 00 63 65 6e 74 65 72 17 04 05 .......center... +| 4032: 00 09 31 00 75 70 70 65 72 2d 72 69 67 68 74 20 ..1.upper-right +| 4048: 63 6f 72 6e 65 72 17 03 05 00 09 31 00 6c 6f 77 corner.....1.low +| 4064: 65 72 2d 72 69 67 68 74 20 63 6f 72 6e 65 72 16 er-right corner. +| 4080: 02 05 00 09 2f 00 75 70 70 65 72 2d 6c 65 66 74 ..../.upper-left +| page 3 offset 8192 +| 0: 20 63 6f 72 6e 65 72 16 01 05 00 09 2f 01 8c 6f corner...../..o +| 16: 77 65 72 2d 6c 53 51 4c 69 74 65 20 66 6f 72 6d wer-lSQLite form +| 32: 61 74 20 33 00 10 00 01 01 00 40 20 20 00 00 00 at 3......@ ... +| 48: 00 00 00 00 2f 00 00 0d eb 13 00 00 00 03 00 00 ..../........... +| 64: 00 04 00 00 00 00 00 00 00 06 00 00 00 01 00 00 ................ +| 80: 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 ................ +| page 6 offset 20480 +| 128: 00 00 00 00 00 00 00 00 97 3d 04 ae 7c 01 00 00 .........=..|... +| 624: 00 00 00 00 00 00 21 97 3d 04 ae 7c 01 00 00 00 ......!.=..|.... +| 1120: 00 00 00 00 00 20 97 3d 04 ae 7c 01 00 00 00 00 ..... .=..|..... +| 1616: 00 00 00 00 1f 97 3d 04 ae 7c 01 00 00 00 00 00 ......=..|...... +| 2112: 00 00 00 1e 97 3d 04 ae 7c 01 00 00 00 00 00 00 .....=..|....... +| 2608: 00 00 1d 97 d3 d0 4a e7 c0 00 00 00 00 00 00 00 ......J......... +| 3088: 00 00 00 00 00 00 00 00 00 00 00 00 01 f3 00 00 ................ +| 3600: 23 97 3d 04 ae 7c 01 00 00 00 00 00 00 00 00 00 #.=..|.......... +| 4080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 26 ...............& +| page 8 offset 28672 +| 0: 0d 00 00 00 01 04 30 00 04 30 00 00 00 00 00 00 ......0..0...... +| 1072: 97 4d 1e 14 00 ae 7c 00 00 00 00 00 00 00 00 00 .M....|......... +| 1088: 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 ................ +| 4080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 ................ +| page 10 offset 36864 +| 0: 0d 00 00 00 01 04 30 00 04 30 00 00 00 00 00 00 ......0..0...... +| 1072: 9a ee c1 80 fd 78 1f ce 1b ae eb b4 00 00 00 00 .....x.......... +| 1088: 13 20 ff 20 00 70 00 00 00 60 50 00 00 00 11 e0 . . .p...`P..... +| 1104: 00 00 00 70 00 00 00 60 50 05 35 14 c6 97 46 52 ...p...`P.5...FR +| 1120: 06 66 f7 26 d6 17 42 03 30 01 00 00 10 10 04 02 .f.&..B.0....... +| 1136: 02 00 00 00 00 00 00 00 00 40 00 00 00 00 00 00 .........@...... +| 1152: 00 00 00 00 00 40 00 00 00 40 00 00 00 00 00 00 .....@...@...... +| 4080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 05 ................ +| page 12 offset 45056 +| 0: 0d 00 00 00 01 04 30 00 04 30 e1 b4 30 97 4d 46 ......0..0..0.MF +| 16: 14 00 ae 7c 00 00 00 00 00 00 00 03 00 00 43 00 ...|..........C. +| page 47 offset 188416 +| 2512: 00 00 00 00 00 00 00 00 be 00 00 00 00 00 00 00 ................ +| page 87 offset 352256 +| 2512: 00 00 00 00 00 00 00 00 aa 00 00 00 00 00 00 00 ................ +| end crash-acaae0347204ae.db +}]} {} + +do_intck_test 1.1 { + {corruption found while reading database schema} +} + +#------------------------------------------------------------------------- +reset_db +do_test 2.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +| size 28672 pagesize 4096 filename crash-3afa1ca9e9c1bd.db +| page 1 offset 0 +| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. +| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 07 .....@ ........ +| 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 ................ +| 96: 00 00 00 00 0d 00 00 00 06 0e 88 00 0f b8 0f 6d ...............m +| 112: 0f 3a 0f 0b 0e d5 0e 88 01 00 00 00 00 00 00 00 .:.............. +| 3712: 00 00 00 00 00 00 00 00 4b 06 06 17 25 25 01 5b ........K...%%.[ +| 3728: 74 61 62 6c 65 73 71 6c 69 74 65 5f 73 74 61 74 tablesqlite_stat +| 3744: 31 73 71 6c 69 74 65 5f 73 74 61 74 31 07 43 52 1sqlite_stat1.CR +| 3760: 45 41 54 45 20 54 41 42 4c 45 20 73 71 6c 69 74 EATE TABLE sqlit +| 3776: 65 5f 73 74 61 74 31 28 74 62 6c 2c 69 64 78 2c e_stat1(tbl,idx, +| 3792: 73 74 61 74 29 34 05 06 17 13 11 01 53 69 6e 64 stat)4......Sind +| 3808: 65 78 63 31 63 63 31 06 43 52 45 41 54 45 20 55 exc1cc1.CREATE U +| 3824: 4e 49 51 55 45 20 49 4e 44 45 58 20 63 31 63 20 NIQUE INDEX c1c +| 3840: 4f 4e 20 63 31 28 63 2c 20 62 29 2d 04 06 17 13 ON c1(c, b)-.... +| 3856: 11 01 45 69 6e 64 65 78 63 31 64 63 31 05 43 52 ..Eindexc1dc1.CR +| 3872: 45 41 54 45 20 49 4e 44 45 58 20 63 31 64 20 4f EATE INDEX c1d O +| 3888: 4e 20 63 31 28 64 2c 20 62 29 31 03 06 17 13 11 N c1(d, b)1..... +| 3904: 01 4d 69 6e 64 65 78 62 31 63 62 31 05 43 52 45 .Mindexb1cb1.CRE +| 3920: 41 54 45 20 55 4e 49 51 55 45 20 49 4e 44 45 58 ATE UNIQUE INDEX +| 3936: 20 62 31 63 20 4f 4e 20 62 31 28 63 29 49 02 06 b1c ON b1(c)I.. +| 3952: 17 11 11 0f 7f 74 61 62 6c 65 63 31 63 31 03 43 .....tablec1c1.C +| 3968: 52 45 41 54 45 20 54 41 42 4c 45 20 63 31 28 61 REATE TABLE c1(a +| 3984: 20 49 4e 54 20 50 52 49 4d 41 52 59 20 4b 45 59 INT PRIMARY KEY +| 4000: 2c 20 62 2c 20 63 2c 20 64 29 20 57 49 54 48 4f , b, c, d) WITHO +| 4016: 55 54 20 52 4f 57 49 44 46 01 06 17 11 11 01 79 UT ROWIDF......y +| 4032: 74 61 62 6c 65 62 31 62 31 02 43 52 45 41 54 45 tableb1b1.CREATE +| 4048: 20 54 41 42 4c 45 20 62 31 28 61 20 49 4e 54 20 TABLE b1(a INT +| 4064: 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 62 2c 20 PRIMARY KEY, b, +| 4080: 63 29 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 c) WITHOUT ROWID +| page 2 offset 4096 +| 0: 0a 00 00 00 07 0f ca 00 0f fa 0f f2 0f ea 0f e2 ................ +| 16: 0f da 00 00 00 01 00 00 00 00 00 00 00 00 00 00 ................ +| 4032: 00 00 00 00 00 00 00 00 00 00 07 04 01 0f 01 06 ................ +| 4048: 67 07 07 04 01 0f 01 06 66 06 07 04 01 0f 01 05 g.......f....... +| 4064: 65 05 07 04 01 0f 01 04 64 04 07 04 01 0f 01 03 e.......d....... +| 4080: 63 03 07 04 01 0f 01 02 62 0f 05 04 09 0f 09 61 c.......b......a +| page 3 offset 8192 +| 0: 0a 00 00 00 07 0f bd 00 0f f9 0f ef 0f e5 0f db ................ +| 16: 0f d1 0f c7 0f bd 00 00 00 00 01 00 00 00 00 00 ................ +| 4016: 00 00 00 00 00 00 00 00 00 00 00 00 00 09 05 01 ................ +| 4032: 0f 01 01 07 61 07 07 09 05 01 0f 01 01 06 61 06 ....a.........a. +| 4048: 06 09 05 01 0f 01 01 05 61 05 05 09 05 01 0f 01 ........a....... +| 4064: 01 04 61 04 04 09 05 01 0f 01 01 03 61 03 03 09 ..a.........a... +| 4080: 05 01 0f 01 01 02 61 0f 02 06 05 09 0f 09 09 61 ......a........a +| page 4 offset 12288 +| 0: 0a 00 00 00 07 0f d8 00 0f fc 0f f0 0f ea 0f e4 ................ +| 16: 0f de 0f d8 0f f6 00 00 00 00 00 00 00 00 00 00 ................ +| 4048: 00 00 00 00 00 00 00 00 05 03 01 01 07 07 05 03 ................ +| 4064: 01 01 06 06 05 03 01 01 05 05 05 03 01 01 04 04 ................ +| 4080: 05 03 01 01 03 03 05 03 01 01 0f 02 03 03 09 09 ................ +| page 5 offset 16384 +| 0: 0a 00 00 00 07 0f ca 00 0f fa 0f f2 0f ea 0f 00 ................ +| 4032: 00 00 00 00 00 00 00 00 00 00 07 04 01 0f 01 07 ................ +| 4048: 61 07 07 04 01 0f 01 06 61 06 07 04 01 0f 01 05 a.......a....... +| 4064: 61 05 07 04 01 1f 01 04 61 04 07 04 01 0f 01 03 a.......a....... +| 4080: 61 03 07 04 01 0f 01 02 61 02 05 04 09 0f 09 61 a.......a......a +| page 6 offset 20480 +| 0: 0a 00 00 00 07 0f ca 00 0f fa 0f ea 0f e2 00 00 ................ +| 4032: 00 00 00 00 00 00 00 00 00 00 07 04 01 0f 01 07 ................ +| 4048: 61 07 07 04 01 0f 01 06 61 06 07 04 01 0f 01 05 a.......a....... +| 4064: 61 05 07 04 01 0f 01 04 61 04 07 04 01 0f 01 03 a.......a....... +| 4080: 61 03 07 04 01 0f 01 0f 61 02 05 04 09 0f 09 61 a.......a......a +| page 7 offset 24576 +| 0: 0d 00 00 00 05 0f 1c 00 0f f0 0f e0 0f d3 0f c5 ................ +| 16: 0f b8 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 4016: 00 00 00 00 00 00 00 00 0b 05 04 11 11 13 62 31 ..............b1 +| 4032: 62 31 37 20 31 0c 04 04 11 13 13 62 31 62 31 63 b17 1......b1b1c +| 4048: 37 20 31 0b 03 04 11 11 13 63 31 63 31 37 20 31 7 1......c1c17 1 +| 4064: 0e 02 04 11 13 07 63 31 63 31 64 37 20 31 20 31 ......c1c1d7 1 1 +| 4080: 0e 01 04 11 13 17 63 31 63 31 63 37 20 31 00 00 ......c1c1c7 1.. +| end crash-3afa1ca9e9c1bd.db +}]} {} + +do_intck_test 2.1 { + {corruption found while reading database schema} +} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 3.0 { + PRAGMA page_size = 1024; + CREATE TABLE t1(a, b); + CREATE INDEX i1 ON t1(a); + INSERT INTO t1 VALUES(1, 1), (2, 2), (3, 3); +} + +do_test 3.1 { + set pgno [db one {SELECT rootpage FROM sqlite_schema WHERE name='t1'}] + db close + hexio_write test.db [expr ($pgno-1)*1024] 0000 +} {2} + +sqlite3 db test.db +do_intck_test 3.2 { + {corruption found while scanning database object i1} + {corruption found while scanning database object t1} +} + +finish_test + + diff --git a/ext/intck/sqlite3intck.c b/ext/intck/sqlite3intck.c index 6d54526928..f23dbbd1d7 100644 --- a/ext/intck/sqlite3intck.c +++ b/ext/intck/sqlite3intck.c @@ -35,6 +35,9 @@ struct sqlite3_intck { int nKeyVal; sqlite3_value **apKeyVal; + char *zMessage; + int bCorruptSchema; + int rc; /* Error code */ char *zErr; /* Error message */ char *zTestSql; /* Returned by sqlite3_intck_test_sql() */ @@ -67,12 +70,12 @@ static sqlite3_stmt *intckPrepare(sqlite3_intck *p, const char *zFmt, ...){ p->rc = sqlite3_prepare_v2(p->db, zSql, -1, &pRet, 0); fflush(stdout); if( p->rc!=SQLITE_OK ){ -#if 1 +#if 0 printf("ERROR: %s\n", zSql); printf("MSG: %s\n", sqlite3_errmsg(p->db)); #endif if( sqlite3_error_offset(p->db)>=0 ){ -#if 1 +#if 0 int iOff = sqlite3_error_offset(p->db); printf("AT: %.40s\n", &zSql[iOff]); #endif @@ -208,12 +211,19 @@ static char *intckSavedKeyToText(sqlite3_intck *p){ return zRet; } +/* +** Find the next database object (table or index) to check. If successful, +** set sqlite3_intck.zObj to point to a nul-terminated buffer containing +** the object's name before returning. +*/ static void intckFindObject(sqlite3_intck *p){ sqlite3_stmt *pStmt = 0; char *zPrev = p->zObj; p->zObj = 0; assert( p->rc==SQLITE_OK ); + assert( p->pCheck==0 ); + pStmt = intckPrepare(p, "WITH tables(table_name) AS (" " SELECT name" @@ -735,7 +745,6 @@ static void intckCheckObject(sqlite3_intck *p){ int sqlite3_intck_open( sqlite3 *db, /* Database handle to operate on */ const char *zDbArg, /* "main", "temp" etc. */ - const char *zFile, /* Path to save-state db on disk (or NULL) */ sqlite3_intck **ppOut /* OUT: New integrity-check handle */ ){ sqlite3_intck *pNew = 0; @@ -760,10 +769,8 @@ int sqlite3_intck_open( return rc; } -int sqlite3_intck_close(sqlite3_intck *p){ - int rc = SQLITE_OK; +void sqlite3_intck_close(sqlite3_intck *p){ if( p ){ - rc = (p->rc==SQLITE_DONE ? SQLITE_OK : p->rc); if( p->db ){ sqlite3_create_function( p->db, "parse_create_index", 1, SQLITE_UTF8, 0, 0, 0, 0 @@ -775,11 +782,19 @@ int sqlite3_intck_close(sqlite3_intck *p){ sqlite3_free(p->zErr); sqlite3_free(p); } - return rc; } int sqlite3_intck_step(sqlite3_intck *p){ if( p->rc==SQLITE_OK ){ + + if( p->zMessage ){ + sqlite3_free(p->zMessage); + p->zMessage = 0; + } + + if( p->bCorruptSchema ){ + p->rc = SQLITE_DONE; + }else if( p->pCheck==0 ){ intckFindObject(p); if( p->rc==SQLITE_OK ){ @@ -788,19 +803,29 @@ int sqlite3_intck_step(sqlite3_intck *p){ }else{ p->rc = SQLITE_DONE; } + }else if( p->rc==SQLITE_CORRUPT ){ + p->rc = SQLITE_OK; + p->zMessage = intckStrdup(p, + "corruption found while reading database schema" + ); + p->bCorruptSchema = 1; } } - if( p->rc==SQLITE_OK ){ - assert( p->pCheck ); + if( p->pCheck ){ + assert( p->rc==SQLITE_OK ); if( sqlite3_step(p->pCheck)==SQLITE_ROW ){ /* Normal case, do nothing. */ }else{ - if( sqlite3_finalize(p->pCheck)!=SQLITE_OK ){ - intckSaveErrmsg(p); - } + intckFinalize(p, p->pCheck); p->pCheck = 0; p->nKeyVal = 0; + if( p->rc==SQLITE_CORRUPT ){ + p->rc = SQLITE_OK; + p->zMessage = intckMprintf(p, + "corruption found while scanning database object %s", p->zObj + ); + } } } } @@ -809,6 +834,10 @@ int sqlite3_intck_step(sqlite3_intck *p){ } const char *sqlite3_intck_message(sqlite3_intck *p){ + assert( p->pCheck==0 || p->zMessage==0 ); + if( p->zMessage ){ + return p->zMessage; + } if( p->pCheck ){ return (const char*)sqlite3_column_text(p->pCheck, 0); } diff --git a/ext/intck/sqlite3intck.h b/ext/intck/sqlite3intck.h index c7c24e42c9..e39825fc7e 100644 --- a/ext/intck/sqlite3intck.h +++ b/ext/intck/sqlite3intck.h @@ -25,11 +25,10 @@ typedef struct sqlite3_intck sqlite3_intck; int sqlite3_intck_open( sqlite3 *db, const char *zDb, - const char *zFile, sqlite3_intck **ppOut ); -int sqlite3_intck_close(sqlite3_intck*); +void sqlite3_intck_close(sqlite3_intck*); int sqlite3_intck_step(sqlite3_intck *pCk); diff --git a/ext/intck/test_intck.c b/ext/intck/test_intck.c index 75bcfa298a..0e2aebf056 100644 --- a/ext/intck/test_intck.c +++ b/ext/intck/test_intck.c @@ -132,7 +132,7 @@ static void testIntckFree(void *clientData){ } /* -** tclcmd: sqlite3_intck DB DBNAME PATH +** tclcmd: sqlite3_intck DB DBNAME */ static int test_sqlite3_intck( void * clientData, @@ -149,8 +149,8 @@ static int test_sqlite3_intck( const char *zFile = 0; int rc = SQLITE_OK; - if( objc!=4 ){ - Tcl_WrongNumArgs(interp, 1, objv, "DB DBNAME PATH"); + if( objc!=3 ){ + Tcl_WrongNumArgs(interp, 1, objv, "DB DBNAME"); return TCL_ERROR; } @@ -161,9 +161,8 @@ static int test_sqlite3_intck( return TCL_ERROR; } zDb = Tcl_GetString(objv[2]); - zFile = Tcl_GetString(objv[3]); - rc = sqlite3_intck_open(db, zDb, zFile, &p->intck); + rc = sqlite3_intck_open(db, zDb, &p->intck); if( rc!=SQLITE_OK ){ ckfree(p); Tcl_SetObjResult(interp, Tcl_NewStringObj(sqlite3_errstr(rc), -1)); @@ -207,7 +206,7 @@ static int test_do_intck( pRet = Tcl_NewObj(); Tcl_IncrRefCount(pRet); - rc = sqlite3_intck_open(db, zDb, 0, &pCk); + rc = sqlite3_intck_open(db, zDb, &pCk); if( rc==SQLITE_OK ){ while( sqlite3_intck_step(pCk)==SQLITE_OK ){ const char *zMsg = sqlite3_intck_message(pCk); diff --git a/manifest b/manifest index 39fc17cfc5..6b38631176 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Use\sfewer\scycles\sto\sgenerate\sthe\s"next\skey"\svalue\sused\sby\ssqlite3_intck_suspend()\sfunction\sin\sthe\sintck\sextension. -D 2024-02-20T18:17:06.096 +C Have\sthe\sintck\sextension\sbetter\shandle\scorruption\sat\sthe\sb-tree\slayer. +D 2024-02-20T20:18:02.615 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -248,12 +248,13 @@ F ext/fts5/tool/showfts5.tcl d54da0e067306663e2d5d523965ca487698e722c F ext/icu/README.txt 7ab7ced8ae78e3a645b57e78570ff589d4c672b71370f5aa9e1cd7024f400fc9 F ext/icu/icu.c c074519b46baa484bb5396c7e01e051034da8884bad1a1cb7f09bbe6be3f0282 F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a32075a8 -F ext/intck/intck1.test 5b3c9800e119b4dd50a381974f34cee6cfd5b7434286fb8da83b7c8ff1d6bb3c +F ext/intck/intck1.test 15e94ee868e939c6d3aef6884c5652d969b28d3eac940a15585511cf8aec71ad F ext/intck/intck2.test b65d7f627342f767e1d2c447d25619666cec36f516786dd56568bd741e5d7e67 -F ext/intck/intck_common.tcl 2895854e7aaf5e199a15f6f82538a00999fd8fc55553bc1f04619af7aa86c0d0 -F ext/intck/sqlite3intck.c 7a795f23424a29f656f3d4c7b83d23484746b57cdc25d3fb98ec805d017fc935 -F ext/intck/sqlite3intck.h d9501ea480b7c41c0555f39f4f1b7c3e8d54fc1ea6d115de5e1211e0bc11d3e7 -F ext/intck/test_intck.c 06206b35f1428961015c060dd35201246c849625cfdff461e0eeaaf76bda545c +F ext/intck/intck_common.tcl 6e5df126e55d6a0d7e3be9757400d5fb87bd291726d01b72a9fe77a7201967e4 +F ext/intck/intckcorrupt.test 3211ef68ac53e83951b6c8f6a8d2396506d123fe5898f97f848a25837744ec56 +F ext/intck/sqlite3intck.c 0f9674952f84084741eb4e945d7532b02996ba8ea938b060228d7874f15557f9 +F ext/intck/sqlite3intck.h dec4a37584024154ad5734cf6ee98dc484ce25c26af88652a096be402fe51833 +F ext/intck/test_intck.c eb84e825a3a0fd43ae1e4280305280a19c9ef42c2bdef3110b282b115de60463 F ext/jni/GNUmakefile 59eb05f2a363bdfac8d15d66bed624bfe1ff289229184f3861b95f98a19cf4b2 F ext/jni/README.md d899789a9082a07b99bf30b1bbb6204ae57c060efcaa634536fa669323918f42 F ext/jni/jar-dist.make 030aaa4ae71dd86e4ec5e7c1e6cd86f9dfa47c4592c070d2e35157e42498e1fa @@ -2168,8 +2169,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 43cbbea82132db2d0ddb4f34cc2b6910b3a1243ae6d4e837b1b27bfe91b84834 -R 9dcf98c64d0302d62dce4c3c1b529641 +P 95f01426f948cf435d0b400dc7ae06fa699eee32cff498fe77e74a1257a4e09b +R 2f81579b76b29691695c15522ce87fed U dan -Z c2dbf2f2090bfeaba66446a197f3ad62 +Z 5af5831e9af2fce3b2d0c2673f03eefa # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 69d33b6938..f905e93b9b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -95f01426f948cf435d0b400dc7ae06fa699eee32cff498fe77e74a1257a4e09b \ No newline at end of file +ecd775d108f77d39a1303316c1e0f0b0ae3ffc5218222e1ebfe2ef6783829b85 \ No newline at end of file From b2897c221da108280e88b1abcd9858c96dca4d99 Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 21 Feb 2024 16:15:50 +0000 Subject: [PATCH 129/430] Ensure intck tests are run by testrunner.tcl. FossilOrigin-Name: 11d6816c060b6edb9cd61f29297ab95e75e2b46f29c0a796820d94fc13586f6d --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/permutations.test | 1 + 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index 7a0b8e41ea..43263453a2 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Merge\strunk\schanges\sinto\sthis\sbranch. -D 2024-02-21T16:12:23.138 +C Ensure\sintck\stests\sare\srun\sby\stestrunner.tcl. +D 2024-02-21T16:15:50.181 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -1487,7 +1487,7 @@ F test/pcache.test c8acbedd3b6fd0f9a7ca887a83b11d24a007972b F test/pcache2.test af7f3deb1a819f77a6d0d81534e97d1cf62cd442 F test/pendingrace.test 6aa33756b950c4529f79c4f3817a9a1e4025bd0d9961571a05c0279bd183d9c6 F test/percentile.test 4243af26b8f3f4555abe166f723715a1f74c77ff -F test/permutations.test f7caf8dd5c7b1da74842a48df116f7f193399c656d4ffc805cd0d9658568c675 +F test/permutations.test 405542f1d659942994a6b38a9e024cf5cfd23eaa68c806aeb24a72d7c9186e80 F test/pg_common.tcl 3b27542224db1e713ae387459b5d117c836a5f6e328846922993b6d2b7640d9f F test/pragma.test cddd4b534d7fb5cf113d1308dea4231f3548e8a7f3a65d7d1cf4810c87090b5a F test/pragma2.test e5d5c176360c321344249354c0c16aec46214c9f @@ -2169,8 +2169,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P ecd775d108f77d39a1303316c1e0f0b0ae3ffc5218222e1ebfe2ef6783829b85 27a2113d78b35e324e9aedda7403c96c56ad0bed8c6b139fc5a179e8800b9109 -R 73b41ee05e607fc52a1cc8e54ddf3838 +P 63e8846ac1dc1cf1f7071c4634ccbfec3c13560db6afec376cd91515b62430d3 +R f5edb7901b3b1288ef6973d26c0dbe97 U dan -Z 458475bfe24db2c8e52b55b2e9078f6a +Z 5466cb7224bcaecbaa43fd497cf85347 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index fc124a8b54..1a133ba48f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -63e8846ac1dc1cf1f7071c4634ccbfec3c13560db6afec376cd91515b62430d3 \ No newline at end of file +11d6816c060b6edb9cd61f29297ab95e75e2b46f29c0a796820d94fc13586f6d \ No newline at end of file diff --git a/test/permutations.test b/test/permutations.test index 25aa7de018..c26d6ead14 100644 --- a/test/permutations.test +++ b/test/permutations.test @@ -95,6 +95,7 @@ foreach f [glob -nocomplain \ $testdir/../ext/lsm1/test/*.test \ $testdir/../ext/recover/*.test \ $testdir/../ext/rbu/*.test \ + $testdir/../ext/intck/*.test \ ] { lappend alltests $f } From b783f56c587304d57702580ec8aff11d8d67641f Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 21 Feb 2024 19:17:45 +0000 Subject: [PATCH 130/430] Add documentation to ext/intck/sqlite3intck.h. FossilOrigin-Name: 4cc19bd74f05fe92658cc392a1d1afa173d93181a77303af6bc5684436ae832e --- ext/intck/intck_common.tcl | 2 +- ext/intck/sqlite3intck.c | 6 +- ext/intck/sqlite3intck.h | 129 +++++++++++++++++++++++++++++++++++-- ext/intck/test_intck.c | 7 +- manifest | 18 +++--- manifest.uuid | 2 +- 6 files changed, 140 insertions(+), 24 deletions(-) diff --git a/ext/intck/intck_common.tcl b/ext/intck/intck_common.tcl index f00a465b3c..cea1a247a3 100644 --- a/ext/intck/intck_common.tcl +++ b/ext/intck/intck_common.tcl @@ -24,7 +24,7 @@ proc do_intck {db {bSuspend 0}} { if {$msg!=""} { lappend ret $msg } - if {$bSuspend} { $ic suspend } + if {$bSuspend} { $ic unlock } } set err [$ic error] diff --git a/ext/intck/sqlite3intck.c b/ext/intck/sqlite3intck.c index f23dbbd1d7..d00b5ef529 100644 --- a/ext/intck/sqlite3intck.c +++ b/ext/intck/sqlite3intck.c @@ -18,7 +18,7 @@ /* ** apKeyVal: -** If sqlite3_intck_suspend() is called when there is a running pCheck +** If sqlite3_intck_unlock() is called when there is a running pCheck ** statement, this array is allocated and populated with the key values ** required to restart the check. If the intck object has not been ** suspended, this is set to NULL. @@ -845,7 +845,7 @@ const char *sqlite3_intck_message(sqlite3_intck *p){ } int sqlite3_intck_error(sqlite3_intck *p, const char **pzErr){ - *pzErr = p->zErr; + if( pzErr ) *pzErr = p->zErr; return (p->rc==SQLITE_DONE ? SQLITE_OK : p->rc); } @@ -861,7 +861,7 @@ static sqlite3_value *intckValueDup(sqlite3_intck *p, sqlite3_value *pIn){ return pRet; } -int sqlite3_intck_suspend(sqlite3_intck *p){ +int sqlite3_intck_unlock(sqlite3_intck *p){ if( p->pCheck && p->rc==SQLITE_OK ){ const int nByte = sizeof(sqlite3_value*) * p->nKeyVal; int ii; diff --git a/ext/intck/sqlite3intck.h b/ext/intck/sqlite3intck.h index e39825fc7e..e08a86f289 100644 --- a/ext/intck/sqlite3intck.h +++ b/ext/intck/sqlite3intck.h @@ -11,6 +11,50 @@ ************************************************************************* */ +/* +** Incremental Integrity-Check Extension +** ------------------------------------- +** +** This module contains code to check whether or not an SQLite database +** is well-formed or corrupt. This is the same task as performed by SQLite's +** built-in "PRAGMA integrity_check" command. This module differs from +** "PRAGMA integrity_check" in that: +** +** + It is less thorough - this module does not detect certain types +** of corruption that are detected by the PRAGMA command. However, +** it does detect all kinds of corruption that are likely to cause +** errors in SQLite applications. +** +** + It is slower. Sometimes up to three times slower. +** +** + It allows integrity-check operations to be split into multiple +** transactions, so that the database does not need to be read-locked +** for the duration of the integrity-check. +** +** One way to use the API to run integrity-check on the "main" database +** of handle db is: +** +** int rc = SQLITE_OK; +** sqlite3_intck *p = 0; +** +** sqlite3_intck_open(db, "main", &p); +** while( SQLITE_OK==sqlite3_intck_step(p) ){ +** const char *zMsg = sqlite3_intck_message(p); +** if( zMsg ) printf("corruption: %s\n", zMsg); +** } +** rc = sqlite3_intck_error(p, &zErr); +** if( rc!=SQLITE_OK ){ +** printf("error occured (rc=%d), (errmsg=%s)\n", rc, zErr); +** } +** sqlite3_intck_close(p); +** +** Usually, the sqlite3_intck object opens a read transaction within the +** first call to sqlite3_intck_step() and holds it open until the +** integrity-check is complete. However, if sqlite3_intck_unlock() is +** called, the read transaction is ended and a new read transaction opened +** by the subsequent call to sqlite3_intck_step(). +*/ + #ifndef _SQLITE_INTCK_H #define _SQLITE_INTCK_H @@ -20,23 +64,96 @@ extern "C" { #endif +/* +** An ongoing incremental integrity-check operation is represented by an +** opaque pointer of the following type. +*/ typedef struct sqlite3_intck sqlite3_intck; +/* +** Open a new incremental integrity-check object. If successful, populate +** output variable (*ppOut) with the new object handle and return SQLITE_OK. +** Or, if an error occurs, set (*ppOut) to NULL and return an SQLite error +** code (e.g. SQLITE_NOMEM). +** +** The integrity-check will be conducted on database zDb (which must be "main", +** "temp", or the name of an attached database) of database handle db. Once +** this function has been called successfully, the caller should not use +** database handle db until the integrity-check object has been destroyed +** using sqlite3_intck_close(). +*/ int sqlite3_intck_open( - sqlite3 *db, - const char *zDb, - sqlite3_intck **ppOut + sqlite3 *db, /* Database handle */ + const char *zDb, /* Database name ("main", "temp" etc.) */ + sqlite3_intck **ppOut /* OUT: New sqlite3_intck handle */ ); -void sqlite3_intck_close(sqlite3_intck*); +/* +** Close and release all resources associated with a handle opened by an +** earlier call to sqlite3_intck_open(). The results of using an +** integrity-check handle after it has been passed to this function are +** undefined. +*/ +void sqlite3_intck_close(sqlite3_intck *pCk); +/* +** Do the next step of the integrity-check operation specified by the handle +** passed as the only argument. This function returns SQLITE_DONE if the +** integrity-check operation is finished, or an SQLite error code if +** an error occurs, or SQLITE_OK if no error occurs but the integrity-check +** is not finished. It is not considered an error if database corruption +** is encountered. +** +** Following a successful call to sqlite3_intck_step() (one that returns +** SQLITE_OK), sqlite3_intck_message() returns a non-NULL value if +** corruption was detected in the db. +** +** If an error occurs and a value other than SQLITE_OK or SQLITE_DONE is +** returned, then the integrity-check handle is placed in an error state. +** In this state all subsequent calls to sqlite3_intck_step() or +** sqlite3_intck_unlock() will immediately return the same error. The +** sqlite3_intck_error() method may be used to obtain an English language +** error message in this case. +*/ int sqlite3_intck_step(sqlite3_intck *pCk); +/* +** If the previous call to sqlite3_intck_step() encountered corruption +** within the database, then this function returns a pointer to a buffer +** containing a nul-terminated string describing the corruption in +** English. If the previous call to sqlite3_intck_step() did not encounter +** corruption, or if there was no previous call, this function returns +** NULL. +*/ const char *sqlite3_intck_message(sqlite3_intck *pCk); -int sqlite3_intck_error(sqlite3_intck *pCk, const char **pzErr); +/* +** Close any read-transaction opened by an earlier call to +** sqlite3_intck_step(). Any subsequent call to sqlite3_intck_step() will +** open a new transaction. Return SQLITE_OK if successful, or an SQLite error +** code otherwise. +** +** If an error occurs, then the integrity-check handle is placed in an error +** state. In this state all subsequent calls to sqlite3_intck_step() or +** sqlite3_intck_unlock() will immediately return the same error. The +** sqlite3_intck_error() method may be used to obtain an English language +** error message in this case. +*/ +int sqlite3_intck_unlock(sqlite3_intck *pCk); -int sqlite3_intck_suspend(sqlite3_intck *pCk); +/* +** If an error has occurred in an earlier call to sqlite3_intck_step() +** or sqlite3_intck_unlock(), then this method returns the associated +** SQLite error code. Additionally, if pzErr is not NULL, then (*pzErr) +** may be set to point to a nul-terminated string containing an English +** language error message. Or, if no error message is available, to +** NULL. +** +** If no error has occurred within sqlite3_intck_step() or +** sqlite_intck_unlock() calls on the handle passed as the first argument, +** then SQLITE_OK is returned and (*pzErr) set to NULL. +*/ +int sqlite3_intck_error(sqlite3_intck *pCk, const char **pzErr); /* ** This API is used for testing only. It returns the full-text of an SQL diff --git a/ext/intck/test_intck.c b/ext/intck/test_intck.c index 0e2aebf056..4c34e2fd26 100644 --- a/ext/intck/test_intck.c +++ b/ext/intck/test_intck.c @@ -49,7 +49,7 @@ static int testIntckCmd( {"step", 0, ""}, /* 1 */ {"message", 0, ""}, /* 2 */ {"error", 0, ""}, /* 3 */ - {"suspend", 0, ""}, /* 4 */ + {"unlock", 0, ""}, /* 4 */ {"test_sql", 1, ""}, /* 5 */ {0 , 0} }; @@ -105,8 +105,8 @@ static int testIntckCmd( break; } - case 4: assert( 0==strcmp("suspend", aCmd[iIdx].zName) ); { - int rc = sqlite3_intck_suspend(p->intck); + case 4: assert( 0==strcmp("unlock", aCmd[iIdx].zName) ); { + int rc = sqlite3_intck_unlock(p->intck); Tcl_SetObjResult(interp, Tcl_NewStringObj(sqlite3ErrName(rc), -1)); break; } @@ -146,7 +146,6 @@ static int test_sqlite3_intck( TestIntck *p = 0; sqlite3 *db = 0; const char *zDb = 0; - const char *zFile = 0; int rc = SQLITE_OK; if( objc!=3 ){ diff --git a/manifest b/manifest index 43263453a2..32648946aa 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Ensure\sintck\stests\sare\srun\sby\stestrunner.tcl. -D 2024-02-21T16:15:50.181 +C Add\sdocumentation\sto\sext/intck/sqlite3intck.h. +D 2024-02-21T19:17:45.632 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -250,11 +250,11 @@ F ext/icu/icu.c c074519b46baa484bb5396c7e01e051034da8884bad1a1cb7f09bbe6be3f0282 F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a32075a8 F ext/intck/intck1.test 15e94ee868e939c6d3aef6884c5652d969b28d3eac940a15585511cf8aec71ad F ext/intck/intck2.test b65d7f627342f767e1d2c447d25619666cec36f516786dd56568bd741e5d7e67 -F ext/intck/intck_common.tcl 6e5df126e55d6a0d7e3be9757400d5fb87bd291726d01b72a9fe77a7201967e4 +F ext/intck/intck_common.tcl b8a63ae820dbcdf50ddaba474f130b43c26ba81f4b7720ff1d8b9a6592bdd420 F ext/intck/intckcorrupt.test 3211ef68ac53e83951b6c8f6a8d2396506d123fe5898f97f848a25837744ec56 -F ext/intck/sqlite3intck.c 0f9674952f84084741eb4e945d7532b02996ba8ea938b060228d7874f15557f9 -F ext/intck/sqlite3intck.h dec4a37584024154ad5734cf6ee98dc484ce25c26af88652a096be402fe51833 -F ext/intck/test_intck.c eb84e825a3a0fd43ae1e4280305280a19c9ef42c2bdef3110b282b115de60463 +F ext/intck/sqlite3intck.c edc93065be0e16394891bb6ad7d279cb54220db65cc66228ac6d6e0bc3919a63 +F ext/intck/sqlite3intck.h 2b40c38e7063ab822c974c0bd4aed97dabb579ccfe2e180a4639bb3bbef0f1c9 +F ext/intck/test_intck.c dec07fc82e2626a1450e58be474e351643627b04ee08ce8fae6495a533b87e85 F ext/jni/GNUmakefile 59eb05f2a363bdfac8d15d66bed624bfe1ff289229184f3861b95f98a19cf4b2 F ext/jni/README.md d899789a9082a07b99bf30b1bbb6204ae57c060efcaa634536fa669323918f42 F ext/jni/jar-dist.make 030aaa4ae71dd86e4ec5e7c1e6cd86f9dfa47c4592c070d2e35157e42498e1fa @@ -2169,8 +2169,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 63e8846ac1dc1cf1f7071c4634ccbfec3c13560db6afec376cd91515b62430d3 -R f5edb7901b3b1288ef6973d26c0dbe97 +P 11d6816c060b6edb9cd61f29297ab95e75e2b46f29c0a796820d94fc13586f6d +R f33ba3131334feff25011177f18e259c U dan -Z 5466cb7224bcaecbaa43fd497cf85347 +Z fc231a0a5c69f02b295f0b4d4c9d9f6a # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 1a133ba48f..12f0b62ab8 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -11d6816c060b6edb9cd61f29297ab95e75e2b46f29c0a796820d94fc13586f6d \ No newline at end of file +4cc19bd74f05fe92658cc392a1d1afa173d93181a77303af6bc5684436ae832e \ No newline at end of file From 6a00f707e8dab995f652470283b7d766575210f1 Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 21 Feb 2024 19:31:00 +0000 Subject: [PATCH 131/430] Simplify the way the restart key is saved internally by the intck extension. FossilOrigin-Name: 0e39962baae8a82a3021077676b792ac30c79426bcd8c075b5e92bee55e8c3a5 --- ext/intck/sqlite3intck.c | 97 +++++++++++++--------------------------- manifest | 12 ++--- manifest.uuid | 2 +- 3 files changed, 39 insertions(+), 72 deletions(-) diff --git a/ext/intck/sqlite3intck.c b/ext/intck/sqlite3intck.c index d00b5ef529..24bceb27d0 100644 --- a/ext/intck/sqlite3intck.c +++ b/ext/intck/sqlite3intck.c @@ -17,14 +17,9 @@ #include /* -** apKeyVal: -** If sqlite3_intck_unlock() is called when there is a running pCheck -** statement, this array is allocated and populated with the key values -** required to restart the check. If the intck object has not been -** suspended, this is set to NULL. -** ** nKeyVal: -** The size of the apKeyVal[] array, if it is allocated. +** The number of values that make up the 'key' for the current pCheck +** statement. */ struct sqlite3_intck { sqlite3 *db; @@ -32,8 +27,8 @@ struct sqlite3_intck { char *zObj; /* Current object. Or NULL. */ sqlite3_stmt *pCheck; /* Current check statement */ + char *zKey; int nKeyVal; - sqlite3_value **apKeyVal; char *zMessage; int bCorruptSchema; @@ -161,14 +156,8 @@ static char *intckMprintf(sqlite3_intck *p, const char *zFmt, ...){ ** Free the sqlite3_intck.apKeyVal, if it is allocated and populated. */ static void intckSavedKeyClear(sqlite3_intck *p){ - if( p->apKeyVal ){ - int ii; - for(ii=0; iinKeyVal; ii++){ - sqlite3_value_free(p->apKeyVal[ii]); - } - sqlite3_free(p->apKeyVal); - p->apKeyVal = 0; - } + sqlite3_free(p->zKey); + p->zKey = 0; } /* @@ -182,33 +171,33 @@ static void intckSavedKeyClear(sqlite3_intck *p){ ** occurs within this function, set sqlite3_intck.rc before returning ** and return NULL. */ -static char *intckSavedKeyToText(sqlite3_intck *p){ - char *zRet = 0; - if( p->apKeyVal ){ - int ii; - const char *zSep = "SELECT '(' || "; - char *zSql = 0; - sqlite3_stmt *pStmt = 0; +static void intckSavedKeySave(sqlite3_intck *p){ + int ii; + const char *zSep = "SELECT '(' || "; + char *zSql = 0; + sqlite3_stmt *pStmt = 0; + + assert( p->pCheck ); + assert( p->zKey==0 ); + + + for(ii=0; iinKeyVal; ii++){ + zSql = intckMprintf(p, "%z%squote(?)", zSql, zSep); + zSep = " || ', ' || "; + } + zSql = intckMprintf(p, "%z || ')'", zSql); + pStmt = intckPrepare(p, "%s", zSql); + if( p->rc==SQLITE_OK ){ for(ii=0; iinKeyVal; ii++){ - zSql = intckMprintf(p, "%z%squote(?)", zSql, zSep); - zSep = " || ', ' || "; + sqlite3_bind_value(pStmt, ii+1, sqlite3_column_value(p->pCheck, ii+1)); } - zSql = intckMprintf(p, "%z || ')'", zSql); - - pStmt = intckPrepare(p, "%s", zSql); - if( p->rc==SQLITE_OK ){ - for(ii=0; iinKeyVal; ii++){ - sqlite3_bind_value(pStmt, ii+1, p->apKeyVal[ii]); - } - if( SQLITE_ROW==sqlite3_step(pStmt) ){ - zRet = intckStrdup(p, (const char*)sqlite3_column_text(pStmt, 0)); - } - intckFinalize(p, pStmt); + if( SQLITE_ROW==sqlite3_step(pStmt) ){ + p->zKey = intckStrdup(p, (const char*)sqlite3_column_text(pStmt, 0)); } - sqlite3_free(zSql); + intckFinalize(p, pStmt); } - return zRet; + sqlite3_free(zSql); } /* @@ -234,7 +223,7 @@ static void intckFindObject(sqlite3_intck *p){ "SELECT table_name FROM tables " "WHERE ?1 IS NULL OR table_name%s?1 " "ORDER BY 1" - , p->zDb, (p->apKeyVal ? ">=" : ">") + , p->zDb, (p->zKey ? ">=" : ">") ); if( p->rc==SQLITE_OK ){ @@ -733,12 +722,9 @@ static char *intckCheckObjectSql( static void intckCheckObject(sqlite3_intck *p){ char *zSql = 0; - char *zKey = 0; - zKey = intckSavedKeyToText(p); - zSql = intckCheckObjectSql(p, p->zObj, zKey, &p->nKeyVal); + zSql = intckCheckObjectSql(p, p->zObj, p->zKey, &p->nKeyVal); p->pCheck = intckPrepare(p, "%s", zSql); sqlite3_free(zSql); - sqlite3_free(zKey); intckSavedKeyClear(p); } @@ -849,27 +835,10 @@ int sqlite3_intck_error(sqlite3_intck *p, const char **pzErr){ return (p->rc==SQLITE_DONE ? SQLITE_OK : p->rc); } - -static sqlite3_value *intckValueDup(sqlite3_intck *p, sqlite3_value *pIn){ - sqlite3_value *pRet = 0; - if( p->rc==SQLITE_OK ){ - pRet = sqlite3_value_dup(pIn); - if( pRet==0 ){ - p->rc = SQLITE_NOMEM; - } - } - return pRet; -} - int sqlite3_intck_unlock(sqlite3_intck *p){ if( p->pCheck && p->rc==SQLITE_OK ){ - const int nByte = sizeof(sqlite3_value*) * p->nKeyVal; - int ii; - assert( p->apKeyVal==0 && p->nKeyVal>0 ); - p->apKeyVal = (sqlite3_value**)intckMalloc(p, nByte); - for(ii=0; p->rc==SQLITE_OK && iinKeyVal; ii++){ - p->apKeyVal[ii] = intckValueDup(p, sqlite3_column_value(p->pCheck, ii+1)); - } + assert( p->zKey==0 && p->nKeyVal>0 ); + intckSavedKeySave(p); intckFinalize(p, p->pCheck); p->pCheck = 0; } @@ -882,9 +851,7 @@ const char *sqlite3_intck_test_sql(sqlite3_intck *p, const char *zObj){ p->zTestSql = intckCheckObjectSql(p, zObj, 0, 0); }else{ if( p->zObj ){ - char *zKey = intckSavedKeyToText(p); - p->zTestSql = intckCheckObjectSql(p, p->zObj, zKey, 0); - sqlite3_free(zKey); + p->zTestSql = intckCheckObjectSql(p, p->zObj, p->zKey, 0); }else{ sqlite3_free(p->zTestSql); p->zTestSql = 0; diff --git a/manifest b/manifest index 32648946aa..172f8e8435 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sdocumentation\sto\sext/intck/sqlite3intck.h. -D 2024-02-21T19:17:45.632 +C Simplify\sthe\sway\sthe\srestart\skey\sis\ssaved\sinternally\sby\sthe\sintck\sextension. +D 2024-02-21T19:31:00.293 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -252,7 +252,7 @@ F ext/intck/intck1.test 15e94ee868e939c6d3aef6884c5652d969b28d3eac940a15585511cf F ext/intck/intck2.test b65d7f627342f767e1d2c447d25619666cec36f516786dd56568bd741e5d7e67 F ext/intck/intck_common.tcl b8a63ae820dbcdf50ddaba474f130b43c26ba81f4b7720ff1d8b9a6592bdd420 F ext/intck/intckcorrupt.test 3211ef68ac53e83951b6c8f6a8d2396506d123fe5898f97f848a25837744ec56 -F ext/intck/sqlite3intck.c edc93065be0e16394891bb6ad7d279cb54220db65cc66228ac6d6e0bc3919a63 +F ext/intck/sqlite3intck.c c437aaa1f4af77621ba984718a62c57722ad9d071151be79335fd87f2c2c2dde F ext/intck/sqlite3intck.h 2b40c38e7063ab822c974c0bd4aed97dabb579ccfe2e180a4639bb3bbef0f1c9 F ext/intck/test_intck.c dec07fc82e2626a1450e58be474e351643627b04ee08ce8fae6495a533b87e85 F ext/jni/GNUmakefile 59eb05f2a363bdfac8d15d66bed624bfe1ff289229184f3861b95f98a19cf4b2 @@ -2169,8 +2169,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 11d6816c060b6edb9cd61f29297ab95e75e2b46f29c0a796820d94fc13586f6d -R f33ba3131334feff25011177f18e259c +P 4cc19bd74f05fe92658cc392a1d1afa173d93181a77303af6bc5684436ae832e +R 735ea6d5058bc579028d0f5e808c7418 U dan -Z fc231a0a5c69f02b295f0b4d4c9d9f6a +Z b84fa961179c349189e714cd49d2cd34 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 12f0b62ab8..4d5fa2bca4 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4cc19bd74f05fe92658cc392a1d1afa173d93181a77303af6bc5684436ae832e \ No newline at end of file +0e39962baae8a82a3021077676b792ac30c79426bcd8c075b5e92bee55e8c3a5 \ No newline at end of file From 9591a9f0699b50dc4dab84ff48b10d3b65bb2ee7 Mon Sep 17 00:00:00 2001 From: drh <> Date: Wed, 21 Feb 2024 20:21:46 +0000 Subject: [PATCH 132/430] Fix typo in comment. [https://fossil-scm.org/forum/forumpost/cc20266bf2|Fossil forum post cc20266bf2]. FossilOrigin-Name: 7e3c46eed1290964a3e25662686c6ba1149bf8687d05719b684772e65d660c09 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/pragma.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 8ad3679fb6..67ee4024d3 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fixes\sto\scomments\sassociated\swith\sthe\srecent\sPRAGMA\soptimize\senhancements.\nNo\schanges\sto\scode. -D 2024-02-20T15:38:36.661 +C Fix\stypo\sin\scomment.\s[https://fossil-scm.org/forum/forumpost/cc20266bf2|Fossil\sforum\spost\scc20266bf2]. +D 2024-02-21T20:21:46.267 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -732,7 +732,7 @@ F src/parse.y bfd6da46fc895cd8237400ff485d04ab0b32e47eb56de20982bb7f53e56c1f42 F src/pcache.c 040b165f30622a21b7a9a77c6f2e4877a32fb7f22d4c7f0d2a6fa6833a156a75 F src/pcache.h 1497ce1b823cf00094bb0cf3bac37b345937e6f910890c626b16512316d3abf5 F src/pcache1.c 602acb23c471bb8d557a6f0083cc2be641d6cafcafa19e481eba7ef4c9ca0f00 -F src/pragma.c f5cb82c15b7455d42e748cad8a6c367db18ada0fadc9b4adba03de953a81d46a +F src/pragma.c 65ec09bbe7322ebbe2ca3a77405ae8df3c85d2c58c122f544a173813940ce3fc F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7 F src/prepare.c 371f6115cb69286ebc12c6f2d7511279c2e47d9f54f475d46a554d687a3b312c F src/printf.c 10e8bad30042f8bd6114a013b4afc229ec8ad255ab27518d7d9f52e8cbc5cd0a @@ -2162,8 +2162,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 4c9886b692706723f4b68f58dfef07ab19b192fd19b953917f23b55655af3e02 -R 40f50207938b86842b8686e871138379 +P 27a2113d78b35e324e9aedda7403c96c56ad0bed8c6b139fc5a179e8800b9109 +R 1a616a32dc6ef4389da85028142db3e7 U drh -Z 751534f3f8e8461179e5c9344b944b7a +Z 046bb5ba6f502774560061e8a489ed3b # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index a82c127f34..b20144c9e0 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -27a2113d78b35e324e9aedda7403c96c56ad0bed8c6b139fc5a179e8800b9109 \ No newline at end of file +7e3c46eed1290964a3e25662686c6ba1149bf8687d05719b684772e65d660c09 \ No newline at end of file diff --git a/src/pragma.c b/src/pragma.c index 62fd17911a..4ff640a657 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -40,7 +40,7 @@ ** for PRAGMA optimize does not exceed 100 milliseconds against a variety ** of test databases on a RaspberryPI-4 compiled using -Os and without ** -DSQLITE_DEBUG. Of course, your mileage may vary. For the purpose of -** his paragraph, "worst-case" means that ANALYZE ends up being +** this paragraph, "worst-case" means that ANALYZE ends up being ** run on every table in the database. The worst case typically only ** happens if PRAGMA optimize is run on a database file for which ANALYZE ** has not been previously run and the 0x10000 flag is included so that From 639db50a026fb019cf08c167bd6534ddcf8d9033 Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 21 Feb 2024 20:58:48 +0000 Subject: [PATCH 133/430] Fix various issues in sqlite3intck.c. FossilOrigin-Name: 8a7bfa74525a495f45b1ea212b1718633b637295090d514dd777f9263477d514 --- ext/intck/sqlite3intck.c | 248 ++++++++++++++++++++++----------------- manifest | 12 +- manifest.uuid | 2 +- 3 files changed, 145 insertions(+), 117 deletions(-) diff --git a/ext/intck/sqlite3intck.c b/ext/intck/sqlite3intck.c index 24bceb27d0..e683577bb7 100644 --- a/ext/intck/sqlite3intck.c +++ b/ext/intck/sqlite3intck.c @@ -14,12 +14,25 @@ #include "sqlite3intck.h" #include #include -#include /* ** nKeyVal: ** The number of values that make up the 'key' for the current pCheck ** statement. +** +** rc: +** Error code returned by most recent sqlite3_intck_step() or +** sqlite3_intck_unlock() call. This is set to SQLITE_DONE when +** the integrity-check operation is finished. +** +** zErr: +** If the object has entered the error state, this is the error message. +** Is freed using sqlite3_free() when the object is deleted. +** +** zTestSql: +** The value returned by the most recent call to sqlite3_intck_testsql(). +** Each call to testsql() frees the previous zTestSql value (using +** sqlite3_free()) and replaces it with the new value it will return. */ struct sqlite3_intck { sqlite3 *db; @@ -52,40 +65,56 @@ static void intckSaveErrmsg(sqlite3_intck *p){ } } -static sqlite3_stmt *intckPrepare(sqlite3_intck *p, const char *zFmt, ...){ +/* +** If the handle passed as the first argument is already in the error state, +** then this function is a no-op (returns NULL immediately). Otherwise, if an +** error occurs within this function, it leaves an error in said handle. +** +** Otherwise, this function attempts to prepare SQL statement zSql and +** return the resulting statement handle to the user. +*/ +static sqlite3_stmt *intckPrepare(sqlite3_intck *p, const char *zSql){ + sqlite3_stmt *pRet = 0; + if( p->rc==SQLITE_OK ){ + p->rc = sqlite3_prepare_v2(p->db, zSql, -1, &pRet, 0); + if( p->rc!=SQLITE_OK ){ + intckSaveErrmsg(p); + assert( pRet==0 ); + } + } + return pRet; +} + +/* +** If the handle passed as the first argument is already in the error state, +** then this function is a no-op (returns NULL immediately). Otherwise, if an +** error occurs within this function, it leaves an error in said handle. +** +** Otherwise, this function treats argument zFmt as a printf() style format +** string. It formats it according to the trailing arguments and then +** attempts to prepare the results and return the resulting prepared +** statement. +*/ +static sqlite3_stmt *intckPrepareFmt(sqlite3_intck *p, const char *zFmt, ...){ sqlite3_stmt *pRet = 0; va_list ap; char *zSql = 0; va_start(ap, zFmt); zSql = sqlite3_vmprintf(zFmt, ap); - if( p->rc==SQLITE_OK ){ - if( zSql==0 ){ - p->rc = SQLITE_NOMEM; - }else{ - p->rc = sqlite3_prepare_v2(p->db, zSql, -1, &pRet, 0); - fflush(stdout); - if( p->rc!=SQLITE_OK ){ -#if 0 - printf("ERROR: %s\n", zSql); - printf("MSG: %s\n", sqlite3_errmsg(p->db)); -#endif - if( sqlite3_error_offset(p->db)>=0 ){ -#if 0 - int iOff = sqlite3_error_offset(p->db); - printf("AT: %.40s\n", &zSql[iOff]); -#endif - } - fflush(stdout); - intckSaveErrmsg(p); - assert( pRet==0 ); - } - } + if( p->rc==SQLITE_OK && zSql==0 ){ + p->rc = SQLITE_NOMEM; } + pRet = intckPrepare(p, zSql); sqlite3_free(zSql); va_end(ap); return pRet; } +/* +** Finalize SQL statement pStmt. If an error occurs and the handle passed +** as the first argument does not already contain an error, store the +** error in the handle. +*/ static void intckFinalize(sqlite3_intck *p, sqlite3_stmt *pStmt){ int rc = sqlite3_finalize(pStmt); if( p->rc==SQLITE_OK && rc!=SQLITE_OK ){ @@ -93,6 +122,18 @@ static void intckFinalize(sqlite3_intck *p, sqlite3_stmt *pStmt){ } } +/* +** Execute SQL statement zSql. There is no way to obtain any results +** returned by the statement. This function uses the sqlite3_intck error +** code convention. +*/ +static void intckExec(sqlite3_intck *p, const char *zSql){ + sqlite3_stmt *pStmt = 0; + pStmt = intckPrepare(p, zSql); + while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ); + intckFinalize(p, pStmt); +} + /* ** Wrapper around sqlite3_malloc64() that uses the sqlite3_intck error ** code convention. @@ -110,15 +151,8 @@ static void *intckMalloc(sqlite3_intck *p, sqlite3_int64 nByte){ } /* -** If p->rc is other than SQLITE_OK when this function is called, it -** immediately returns NULL. Otherwise, it attempts to create a copy of -** nul-terminated string zIn in a buffer obtained from sqlite3_malloc(). -** If successful, a pointer to this buffer is returned and it becomes -** the responsibility of the caller to release it using sqlite3_free() -** at some point in the future. -** -** Or, if an allocation fails within this function, p->rc is set to -** SQLITE_NOMEM and NULL is returned. +** Like strdup(), but uses the sqlite3_intck error code convention. Any +** returned buffer should eventually be freed using sqlite3_free(). */ static char *intckStrdup(sqlite3_intck *p, const char *zIn){ char *zOut = 0; @@ -131,10 +165,8 @@ static char *intckStrdup(sqlite3_intck *p, const char *zIn){ } /* -** A wrapper around sqlite3_mprintf() that: -** -** + Always returns 0 if p->rc is other than SQLITE_OK when it is called, and -** + Sets p->rc to SQLITE_NOMEM if an allocation fails. +** A wrapper around sqlite3_mprintf() that uses the sqlite3_intck error +** code convention. */ static char *intckMprintf(sqlite3_intck *p, const char *zFmt, ...){ va_list ap; @@ -153,25 +185,11 @@ static char *intckMprintf(sqlite3_intck *p, const char *zFmt, ...){ } /* -** Free the sqlite3_intck.apKeyVal, if it is allocated and populated. -*/ -static void intckSavedKeyClear(sqlite3_intck *p){ - sqlite3_free(p->zKey); - p->zKey = 0; -} - -/* -** If the apKeyVal array is currently allocated and populated, return -** a pointer to a buffer containing a nul-terminated string representing -** the values as an SQL vector. e.g. -** -** "('abc', NULL, 2)" -** -** If apKeyVal is not allocated, return NULL. Or, if an error (e.g. OOM) -** occurs within this function, set sqlite3_intck.rc before returning -** and return NULL. +** This is used by sqlite3_intck_unlock() to save the vector key value +** required to restart the current pCheck query as a nul-terminated string +** in p->zKey. */ -static void intckSavedKeySave(sqlite3_intck *p){ +static void intckSaveKey(sqlite3_intck *p){ int ii; const char *zSep = "SELECT '(' || "; char *zSql = 0; @@ -180,14 +198,13 @@ static void intckSavedKeySave(sqlite3_intck *p){ assert( p->pCheck ); assert( p->zKey==0 ); - for(ii=0; iinKeyVal; ii++){ zSql = intckMprintf(p, "%z%squote(?)", zSql, zSep); zSep = " || ', ' || "; } zSql = intckMprintf(p, "%z || ')'", zSql); - pStmt = intckPrepare(p, "%s", zSql); + pStmt = intckPrepare(p, zSql); if( p->rc==SQLITE_OK ){ for(ii=0; iinKeyVal; ii++){ sqlite3_bind_value(pStmt, ii+1, sqlite3_column_value(p->pCheck, ii+1)); @@ -213,7 +230,7 @@ static void intckFindObject(sqlite3_intck *p){ assert( p->rc==SQLITE_OK ); assert( p->pCheck==0 ); - pStmt = intckPrepare(p, + pStmt = intckPrepareFmt(p, "WITH tables(table_name) AS (" " SELECT name" " FROM %Q.sqlite_schema WHERE (type='table' OR type='index') AND rootpage" @@ -236,7 +253,8 @@ static void intckFindObject(sqlite3_intck *p){ /* If this is a new object, ensure the previous key value is cleared. */ if( sqlite3_stricmp(p->zObj, zPrev) ){ - intckSavedKeyClear(p); + sqlite3_free(p->zKey); + p->zKey = 0; } sqlite3_free(zPrev); @@ -274,22 +292,13 @@ static int intckGetToken(const char *z){ return iRet; } +/* +** Return true if argument c is an ascii whitespace character. +*/ static int intckIsSpace(char c){ return (c==' ' || c=='\t' || c=='\n' || c=='\r'); } -static int intckTokenMatch( - const char *zToken, - int nToken, - const char *z1, - const char *z2 -){ - return ( - (strlen(z1)==nToken && 0==sqlite3_strnicmp(zToken, z1, nToken)) - || (z2 && strlen(z2)==nToken && 0==sqlite3_strnicmp(zToken, z2, nToken)) - ); -} - /* ** Argument z points to the text of a CREATE INDEX statement. This function ** identifies the part of the text that contains either the index WHERE @@ -350,7 +359,9 @@ static const char *intckParseCreateIndex(const char *z, int iCol, int *pnByte){ if( z[iOff]==')' ) nOpen--; nToken = intckGetToken(zToken); - if( intckTokenMatch(zToken, nToken, "ASC", "DESC") ){ + if( (nToken==3 && 0==sqlite3_strnicmp(zToken, "ASC", nToken)) + || (nToken==4 && 0==sqlite3_strnicmp(zToken, "DESC", nToken)) + ){ iEndOfCol = iOff; }else if( 0==intckIsSpace(zToken[0]) ){ iEndOfCol = 0; @@ -383,7 +394,12 @@ static const char *intckParseCreateIndex(const char *z, int iCol, int *pnByte){ return zRet; } -static void parseCreateIndexFunc( +/* +** User-defined SQL function wrapper for intckParseCreateIndex(): +** +** SELECT parse_create_index(, ); +*/ +static void intckParseCreateIndexFunc( sqlite3_context *pCtx, int nVal, sqlite3_value **apVal @@ -421,7 +437,7 @@ static int intckGetAutoIndex(sqlite3_intck *p){ static int intckIsIndex(sqlite3_intck *p, const char *zObj){ int bRet = 0; sqlite3_stmt *pStmt = 0; - pStmt = intckPrepare(p, + pStmt = intckPrepareFmt(p, "SELECT 1 FROM %Q.sqlite_schema WHERE name=%Q AND type='index'", p->zDb, zObj ); @@ -432,17 +448,20 @@ static int intckIsIndex(sqlite3_intck *p, const char *zObj){ return bRet; } -static void intckExec(sqlite3_intck *p, const char *zSql){ - sqlite3_stmt *pStmt = 0; - pStmt = intckPrepare(p, "%s", zSql); - while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ); - intckFinalize(p, pStmt); -} - +/* +** Return a pointer to a nul-terminated buffer containing the SQL statement +** used to check database object zObj (a table or index) for corruption. +** If parameter zPrev is not NULL, then it must be a string containing the +** vector key required to restart the check where it left off last time. +** If pnKeyVal is not NULL, then (*pnKeyVal) is set to the number of +** columns in the vector key value for the specified object. +** +** This function uses the sqlite3_intck error code convention. +*/ static char *intckCheckObjectSql( - sqlite3_intck *p, - const char *zObj, - const char *zPrev, + sqlite3_intck *p, /* Integrity check object */ + const char *zObj, /* Object (table or index) to scan */ + const char *zPrev, /* Restart key vector, if any */ int *pnKeyVal /* OUT: Number of key-values for this scan */ ){ char *zRet = 0; @@ -563,7 +582,7 @@ static char *intckCheckObjectSql( bIsIndex = intckIsIndex(p, zObj); if( bIsIndex ){ - pStmt = intckPrepare(p, + pStmt = intckPrepareFmt(p, /* Table idxname contains a single row. The first column, "db", contains ** the name of the db containing the table (e.g. "main") and the second, ** "tab", the name of the table itself. */ @@ -616,7 +635,7 @@ static char *intckCheckObjectSql( , zPrev, zCommon ); }else{ - pStmt = intckPrepare(p, + pStmt = intckPrepareFmt(p, /* Table tabname contains a single row. The first column, "db", contains ** the name of the db containing the table (e.g. "main") and the second, ** "tab", the name of the table itself. */ @@ -697,22 +716,10 @@ static char *intckCheckObjectSql( } while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){ -#if 0 - int nField = sqlite3_column_count(pStmt); - int ii; - for(ii=0; iizObj, p->zKey, &p->nKeyVal); - p->pCheck = intckPrepare(p, "%s", zSql); - sqlite3_free(zSql); - intckSavedKeyClear(p); -} - +/* +** Open a new integrity-check object. +*/ int sqlite3_intck_open( sqlite3 *db, /* Database handle to operate on */ const char *zDbArg, /* "main", "temp" etc. */ @@ -743,7 +745,7 @@ int sqlite3_intck_open( rc = SQLITE_NOMEM; }else{ sqlite3_create_function(db, "parse_create_index", - 2, SQLITE_UTF8, 0, parseCreateIndexFunc, 0, 0 + 2, SQLITE_UTF8, 0, intckParseCreateIndexFunc, 0, 0 ); memset(pNew, 0, sizeof(*pNew)); pNew->db = db; @@ -755,6 +757,9 @@ int sqlite3_intck_open( return rc; } +/* +** Free the integrity-check object. +*/ void sqlite3_intck_close(sqlite3_intck *p){ if( p ){ if( p->db ){ @@ -763,13 +768,16 @@ void sqlite3_intck_close(sqlite3_intck *p){ ); } sqlite3_free(p->zObj); - intckSavedKeyClear(p); + sqlite3_free(p->zKey); sqlite3_free(p->zTestSql); sqlite3_free(p->zErr); sqlite3_free(p); } } +/* +** Step the integrity-check object. +*/ int sqlite3_intck_step(sqlite3_intck *p){ if( p->rc==SQLITE_OK ){ @@ -785,7 +793,12 @@ int sqlite3_intck_step(sqlite3_intck *p){ intckFindObject(p); if( p->rc==SQLITE_OK ){ if( p->zObj ){ - intckCheckObject(p); + char *zSql = 0; + zSql = intckCheckObjectSql(p, p->zObj, p->zKey, &p->nKeyVal); + p->pCheck = intckPrepare(p, zSql); + sqlite3_free(zSql); + sqlite3_free(p->zKey); + p->zKey = 0; }else{ p->rc = SQLITE_DONE; } @@ -819,6 +832,10 @@ int sqlite3_intck_step(sqlite3_intck *p){ return p->rc; } +/* +** Return a message describing the corruption encountered by the most recent +** call to sqlite3_intck_step(), or NULL if no corruption was encountered. +*/ const char *sqlite3_intck_message(sqlite3_intck *p){ assert( p->pCheck==0 || p->zMessage==0 ); if( p->zMessage ){ @@ -830,21 +847,32 @@ const char *sqlite3_intck_message(sqlite3_intck *p){ return 0; } +/* +** Return the error code and message. +*/ int sqlite3_intck_error(sqlite3_intck *p, const char **pzErr){ if( pzErr ) *pzErr = p->zErr; return (p->rc==SQLITE_DONE ? SQLITE_OK : p->rc); } +/* +** Close any read transaction the integrity-check object is holding open +** on the database. +*/ int sqlite3_intck_unlock(sqlite3_intck *p){ if( p->pCheck && p->rc==SQLITE_OK ){ assert( p->zKey==0 && p->nKeyVal>0 ); - intckSavedKeySave(p); + intckSaveKey(p); intckFinalize(p, p->pCheck); p->pCheck = 0; } return p->rc; } +/* +** Return the SQL statement used to check object zObj. Or, if zObj is +** NULL, the current SQL statement. +*/ const char *sqlite3_intck_test_sql(sqlite3_intck *p, const char *zObj){ sqlite3_free(p->zTestSql); if( zObj ){ diff --git a/manifest b/manifest index 172f8e8435..316837de51 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Simplify\sthe\sway\sthe\srestart\skey\sis\ssaved\sinternally\sby\sthe\sintck\sextension. -D 2024-02-21T19:31:00.293 +C Fix\svarious\sissues\sin\ssqlite3intck.c. +D 2024-02-21T20:58:48.924 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -252,7 +252,7 @@ F ext/intck/intck1.test 15e94ee868e939c6d3aef6884c5652d969b28d3eac940a15585511cf F ext/intck/intck2.test b65d7f627342f767e1d2c447d25619666cec36f516786dd56568bd741e5d7e67 F ext/intck/intck_common.tcl b8a63ae820dbcdf50ddaba474f130b43c26ba81f4b7720ff1d8b9a6592bdd420 F ext/intck/intckcorrupt.test 3211ef68ac53e83951b6c8f6a8d2396506d123fe5898f97f848a25837744ec56 -F ext/intck/sqlite3intck.c c437aaa1f4af77621ba984718a62c57722ad9d071151be79335fd87f2c2c2dde +F ext/intck/sqlite3intck.c 3fa96647dde4c719a477f7dbdd1edf76b2f245549b1a4de7f7d60447b24a14df F ext/intck/sqlite3intck.h 2b40c38e7063ab822c974c0bd4aed97dabb579ccfe2e180a4639bb3bbef0f1c9 F ext/intck/test_intck.c dec07fc82e2626a1450e58be474e351643627b04ee08ce8fae6495a533b87e85 F ext/jni/GNUmakefile 59eb05f2a363bdfac8d15d66bed624bfe1ff289229184f3861b95f98a19cf4b2 @@ -2169,8 +2169,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 4cc19bd74f05fe92658cc392a1d1afa173d93181a77303af6bc5684436ae832e -R 735ea6d5058bc579028d0f5e808c7418 +P 0e39962baae8a82a3021077676b792ac30c79426bcd8c075b5e92bee55e8c3a5 +R 2d481f6c889817bf845056ed7696633c U dan -Z b84fa961179c349189e714cd49d2cd34 +Z 13c318cbe203f9a86dd5c12df0ee017f # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 4d5fa2bca4..092b5c01d4 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0e39962baae8a82a3021077676b792ac30c79426bcd8c075b5e92bee55e8c3a5 \ No newline at end of file +8a7bfa74525a495f45b1ea212b1718633b637295090d514dd777f9263477d514 \ No newline at end of file From 0b8c3126f4ac61a1e8cb4aeee19396f4e2b3862e Mon Sep 17 00:00:00 2001 From: drh <> Date: Thu, 22 Feb 2024 00:50:54 +0000 Subject: [PATCH 134/430] Fix debugging code so that it compiles on MSVC. FossilOrigin-Name: ce5df19dc4aff3fde03ef62261a5e095a16a8f4e46e2924becea4fed56ce49e3 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/malloc.c | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 67ee4024d3..50c2f0e0af 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\stypo\sin\scomment.\s[https://fossil-scm.org/forum/forumpost/cc20266bf2|Fossil\sforum\spost\scc20266bf2]. -D 2024-02-21T20:21:46.267 +C Fix\sdebugging\scode\sso\sthat\sit\scompiles\son\sMSVC. +D 2024-02-22T00:50:54.956 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -703,7 +703,7 @@ F src/json.c a412d7f1550a8597470d30e1d9f8d3dcf111b96ef3877b74bb1c363086bcfb51 F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 F src/main.c 438b95162acfa17b7d218f586f5bde11d6ae82bcf030c9611fc537556870ad6b -F src/malloc.c c31472af77e3421d993b69c93f07890277afd94247da4290e1b290ffc0d1f404 +F src/malloc.c 410e570b30c26cc36e3372577df50f7a96ee3eed5b2b161c6b6b48773c650c5e F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c 3bb59158c38e05f6270e761a9f435bf19827a264c13d1631c58b84bdc96d73b2 F src/mem2.c c8bfc9446fd0798bddd495eb5d9dbafa7d4b7287d8c22d50a83ac9daa26d8a75 @@ -2162,8 +2162,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 27a2113d78b35e324e9aedda7403c96c56ad0bed8c6b139fc5a179e8800b9109 -R 1a616a32dc6ef4389da85028142db3e7 +P 7e3c46eed1290964a3e25662686c6ba1149bf8687d05719b684772e65d660c09 +R 365ecee93146612474dc5afdd7dbd0ae U drh -Z 046bb5ba6f502774560061e8a489ed3b +Z a2e66d96e9a847508f80a325e0644c11 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index b20144c9e0..6da1bb3887 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7e3c46eed1290964a3e25662686c6ba1149bf8687d05719b684772e65d660c09 \ No newline at end of file +ce5df19dc4aff3fde03ef62261a5e095a16a8f4e46e2924becea4fed56ce49e3 \ No newline at end of file diff --git a/src/malloc.c b/src/malloc.c index ef7d2e1edd..9a635e7162 100644 --- a/src/malloc.c +++ b/src/malloc.c @@ -228,9 +228,9 @@ static void sqlite3MallocAlarm(int nByte){ ** code debuggers when working on out-of-memory conditions, for example ** caused by PRAGMA hard_heap_limit=N. */ -static SQLITE_NOINLINE void test_oom_breakpoint(void){ +static SQLITE_NOINLINE void test_oom_breakpoint(u64 n){ static u64 nOomFault = 0; - nOomFault++; + nOomFault += n; /* The assert() is never reached in a human lifetime. It is here mostly ** to prevent code optimizers from optimizing out this function. */ assert( (nOomFault>>32) < 0xffffffff ); @@ -265,7 +265,7 @@ static void mallocWithAlarm(int n, void **pp){ if( mem0.hardLimit ){ nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED); if( nUsed >= mem0.hardLimit - nFull ){ - test_oom_breakpoint(); + test_oom_breakpoint(1); *pp = 0; return; } @@ -554,7 +554,7 @@ void *sqlite3Realloc(void *pOld, u64 nBytes){ sqlite3MallocAlarm(nDiff); if( mem0.hardLimit>0 && nUsed >= mem0.hardLimit - nDiff ){ sqlite3_mutex_leave(mem0.mutex); - test_oom_breakpoint(); + test_oom_breakpoint(1); return 0; } } From f7ad684c5a3f79565e8d9e4ba0706fcdc80507da Mon Sep 17 00:00:00 2001 From: mistachkin Date: Thu, 22 Feb 2024 18:15:08 +0000 Subject: [PATCH 135/430] Fix harmless compiler warning seen with MSVC. FossilOrigin-Name: e5db08993127dfc18cc2b621a13cbfef52974f0f504f4d8208093bfad1ffdcc5 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/json.c | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 50c2f0e0af..a2ef0141ff 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sdebugging\scode\sso\sthat\sit\scompiles\son\sMSVC. -D 2024-02-22T00:50:54.956 +C Fix\sharmless\scompiler\swarning\sseen\swith\sMSVC. +D 2024-02-22T18:15:08.241 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -699,7 +699,7 @@ F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 F src/insert.c 3f0a94082d978bbdd33c38fefea15346c6c6bffb70bc645a71dc0f1f87dd3276 -F src/json.c a412d7f1550a8597470d30e1d9f8d3dcf111b96ef3877b74bb1c363086bcfb51 +F src/json.c 3b4e2778d95d923d6d77e8a5efd51a6265017b466782d597303f5f094fcd68af F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 F src/main.c 438b95162acfa17b7d218f586f5bde11d6ae82bcf030c9611fc537556870ad6b @@ -2162,8 +2162,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 7e3c46eed1290964a3e25662686c6ba1149bf8687d05719b684772e65d660c09 -R 365ecee93146612474dc5afdd7dbd0ae -U drh -Z a2e66d96e9a847508f80a325e0644c11 +P ce5df19dc4aff3fde03ef62261a5e095a16a8f4e46e2924becea4fed56ce49e3 +R 63d9d369c3456decb924739dc3e48ce6 +U mistachkin +Z 5c46c4e87cc4943d1671979de864e7c2 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 6da1bb3887..37d995b0c3 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ce5df19dc4aff3fde03ef62261a5e095a16a8f4e46e2924becea4fed56ce49e3 \ No newline at end of file +e5db08993127dfc18cc2b621a13cbfef52974f0f504f4d8208093bfad1ffdcc5 \ No newline at end of file diff --git a/src/json.c b/src/json.c index c33b63556a..1227ada78e 100644 --- a/src/json.c +++ b/src/json.c @@ -1623,7 +1623,7 @@ static int jsonTranslateTextToBlob(JsonParse *pParse, u32 i){ case '[': { /* Parse array */ iThis = pParse->nBlob; - assert( i<=pParse->nJson ); + assert( i<=(u32)pParse->nJson ); jsonBlobAppendNode(pParse, JSONB_ARRAY, pParse->nJson - i, 0); iStart = pParse->nBlob; if( pParse->oom ) return -1; From 1545243368a908367f357dbf4e3c705574d645db Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 23 Feb 2024 15:13:53 +0000 Subject: [PATCH 136/430] Fix problems with resuming integrity-check operations on indexes with mixed ASC and DESC columns, and on indexes that contain NULL values. FossilOrigin-Name: 0f68b35a000ef9f4691c59797c66ed6c3435fc5c503e9d24f891afec6aceeada --- ext/intck/intck1.test | 20 +++--- ext/intck/intck2.test | 52 +++++++++++++++ ext/intck/intck_common.tcl | 7 +- ext/intck/sqlite3intck.c | 129 ++++++++++++++++++++++++++++--------- manifest | 18 +++--- manifest.uuid | 2 +- 6 files changed, 177 insertions(+), 51 deletions(-) diff --git a/ext/intck/intck1.test b/ext/intck/intck1.test index 4110ece049..4e86e4f2fc 100644 --- a/ext/intck/intck1.test +++ b/ext/intck/intck1.test @@ -181,16 +181,10 @@ do_test 3.2 { sqlite3 db test.db } {} -#puts "[intck_sql db x1a]" -#execsql_pp "EXPLAIN QUERY PLAN [intck_sql db x1a]" do_intck_test 3.3 { {entry (4,'six',5) missing from index x1a} } -#explain_i [intck_sql db x1] -#puts [intck_sql db x1] -#puts [intck_sql db x1a] - #------------------------------------------------------------------------- reset_db do_execsql_test 4.0 { @@ -199,13 +193,17 @@ do_execsql_test 4.0 { INSERT INTO www VALUES(1, 1, 1), (2, 2, 2); } -#puts [intck_sql db w1] -#execsql_pp [intck_sql db www] -#execsql_pp [intck_sql db w1] -#puts [intck_sql db w1] - do_intck_test 4.1 { } +#------------------------------------------------------------------------- +reset_db +do_execsql_test 5.0 { + CREATE TABLE t1(a, b); + CREATE INDEX i1 ON t1(a COLLATE NOCASE); +} + +#puts [intck_sql db i1] + finish_test diff --git a/ext/intck/intck2.test b/ext/intck/intck2.test index 90f263f880..bb57886968 100644 --- a/ext/intck/intck2.test +++ b/ext/intck/intck2.test @@ -61,6 +61,58 @@ do_execsql_test 2.0 { } do_intck_test 2.1 {} + +imposter_edit x1 { + CREATE TABLE imp(a, b, c); +} { + DELETE FROM imp WHERE c=7; +} +puts [intck_sql db x1b] +do_intck_test 2.2 { + {surplus entry ('ONE',6,3) in index x1a} + {surplus entry ('ONE6 "''" ',3) in index x1b} + {surplus entry ('ONE','7',3) in index x1c} +} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 3.0 { + CREATE TABLE x1(a, b, c); + CREATE INDEX x1all ON x1(a DESC, b ASC, c DESC); + INSERT INTO x1 VALUES(2, 1, 2); + INSERT INTO x1 VALUES(2, 1, 1); + INSERT INTO x1 VALUES(2, 2, 2); + INSERT INTO x1 VALUES(2, 2, 1); + INSERT INTO x1 VALUES(1, 1, 2); + INSERT INTO x1 VALUES(1, 1, 1); + INSERT INTO x1 VALUES(1, 2, 2); + INSERT INTO x1 VALUES(1, 2, 1); +} + +do_intck_test 3.1 { +} + +imposter_edit x1 { + CREATE TABLE imp(a, b, c); +} { + DELETE FROM imp WHERE 1; +} + +db close +sqlite3 db test.db + +do_intck_test 3.2 { + {surplus entry (2,1,2,1) in index x1all} + {surplus entry (2,1,1,2) in index x1all} + {surplus entry (2,2,2,3) in index x1all} + {surplus entry (2,2,1,4) in index x1all} + {surplus entry (1,1,2,5) in index x1all} + {surplus entry (1,1,1,6) in index x1all} + {surplus entry (1,2,2,7) in index x1all} + {surplus entry (1,2,1,8) in index x1all} +} + +#puts [intck_sql db x1all] #puts [intck_sql db x1] finish_test diff --git a/ext/intck/intck_common.tcl b/ext/intck/intck_common.tcl index cea1a247a3..7d6579ae03 100644 --- a/ext/intck/intck_common.tcl +++ b/ext/intck/intck_common.tcl @@ -24,7 +24,12 @@ proc do_intck {db {bSuspend 0}} { if {$msg!=""} { lappend ret $msg } - if {$bSuspend} { $ic unlock } + if {$bSuspend} { + $ic unlock + #puts "SQL: [$ic test_sql {}]" + #execsql_pp "EXPLAIN query plan [$ic test_sql {}]" + #explain_i [$ic test_sql {}] + } } set err [$ic error] diff --git a/ext/intck/sqlite3intck.c b/ext/intck/sqlite3intck.c index e683577bb7..287ec157c3 100644 --- a/ext/intck/sqlite3intck.c +++ b/ext/intck/sqlite3intck.c @@ -15,6 +15,9 @@ #include #include +#include +#include + /* ** nKeyVal: ** The number of values that make up the 'key' for the current pCheck @@ -187,22 +190,87 @@ static char *intckMprintf(sqlite3_intck *p, const char *zFmt, ...){ /* ** This is used by sqlite3_intck_unlock() to save the vector key value ** required to restart the current pCheck query as a nul-terminated string -** in p->zKey. +** in p->zKey. */ static void intckSaveKey(sqlite3_intck *p){ int ii; - const char *zSep = "SELECT '(' || "; char *zSql = 0; sqlite3_stmt *pStmt = 0; + sqlite3_stmt *pXinfo = 0; + const char *zDir = 0; assert( p->pCheck ); assert( p->zKey==0 ); - for(ii=0; iinKeyVal; ii++){ - zSql = intckMprintf(p, "%z%squote(?)", zSql, zSep); - zSep = " || ', ' || "; + pXinfo = intckPrepareFmt(p, + "SELECT group_concat(desc, '') FROM %Q.sqlite_schema s, " + "pragma_index_xinfo(%Q, %Q) " + "WHERE s.type='index' AND s.name=%Q", + p->zDb, p->zObj, p->zDb, p->zObj + ); + if( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pXinfo) ){ + zDir = (const char*)sqlite3_column_text(pXinfo, 0); + } + + if( zDir==0 ){ + /* Object is a table, not an index. This is the easy case,as there are + ** no DESC columns or NULL values in a primary key. */ + const char *zSep = "SELECT '(' || "; + for(ii=0; iinKeyVal; ii++){ + zSql = intckMprintf(p, "%z%squote(?)", zSql, zSep); + zSep = " || ', ' || "; + } + zSql = intckMprintf(p, "%z || ')'", zSql); + }else{ + + /* Object is an index. */ + assert( p->nKeyVal>1 ); + for(ii=p->nKeyVal; ii>0; ii--){ + int bLastIsDesc = zDir[ii-1]=='1'; + int bLastIsNull = sqlite3_column_type(p->pCheck, ii)==SQLITE_NULL; + const char *zLast = sqlite3_column_name(p->pCheck, ii); + char *zLhs = 0; + char *zRhs = 0; + char *zWhere = 0; + + if( bLastIsNull ){ + if( bLastIsDesc ) continue; + zWhere = intckMprintf(p, "'%s IS NOT NULL'", zLast); + }else{ + const char *zOp = bLastIsDesc ? "<" : ">"; + zWhere = intckMprintf(p, "'%s %s ' || quote(?%d)", zLast, zOp, ii); + } + + if( ii>1 ){ + const char *zLhsSep = ""; + const char *zRhsSep = ""; + int jj; + for(jj=0; jjpCheck,jj+1); + zLhs = intckMprintf(p, "%z%s%s", zLhs, zLhsSep, zAlias); + zRhs = intckMprintf(p, "%z%squote(?%d)", zRhs, zRhsSep, jj+1); + zLhsSep = ","; + zRhsSep = " || ',' || "; + } + + zWhere = intckMprintf(p, + "'(%z) IS (' || %z || ') AND ' || %z", + zLhs, zRhs, zWhere); + } + zWhere = intckMprintf(p, "'WHERE ' || %z", zWhere); + + zSql = intckMprintf(p, "%z%s(quote( %z ) )", + zSql, + (zSql==0 ? "VALUES" : ",\n "), + zWhere + ); + } + zSql = intckMprintf(p, + "WITH wc(q) AS (\n%z\n)" + "SELECT 'VALUES' || group_concat('(' || q || ')', ',\n ') FROM wc" + , zSql + ); } - zSql = intckMprintf(p, "%z || ')'", zSql); pStmt = intckPrepare(p, zSql); if( p->rc==SQLITE_OK ){ @@ -214,7 +282,9 @@ static void intckSaveKey(sqlite3_intck *p){ } intckFinalize(p, pStmt); } + sqlite3_free(zSql); + intckFinalize(p, pXinfo); } /* @@ -521,7 +591,7 @@ static char *intckCheckObjectSql( " SELECT i.col_name, i.col_alias FROM idx_cols i WHERE i.idx_ispk" " )" " SELECT t.db, t.tab, t.idx, " - " group_concat('o.'||a, ', '), " + " group_concat(a, ', '), " " group_concat('i.'||quote(f), ', '), " " group_concat('quote(o.'||a||')', ' || '','' || '), " " format('(%s)==(%s)'," @@ -586,24 +656,26 @@ static char *intckCheckObjectSql( /* Table idxname contains a single row. The first column, "db", contains ** the name of the db containing the table (e.g. "main") and the second, ** "tab", the name of the table itself. */ - "WITH tabname(db, tab, idx, prev) AS (" - " SELECT %Q, (SELECT tbl_name FROM %Q.sqlite_schema WHERE name=%Q), " - " %Q, %Q " + "WITH tabname(db, tab, idx) AS (" + " SELECT %Q, (SELECT tbl_name FROM %Q.sqlite_schema WHERE name=%Q), %Q " ")" + "" + ", whereclause(w_c) AS (%s)" + "" "%s" /* zCommon */ "" ", case_statement(c) AS (" " SELECT " - " 'CASE WHEN (' || group_concat(col_alias, ', ') || ') IS (\n ' " + " 'CASE WHEN (' || group_concat(col_alias, ', ') || ') IS (\n ' " " || 'SELECT ' || group_concat(col_expr, ', ') || ' FROM '" " || format('%%Q.%%Q NOT INDEXED WHERE %%s\n', t.db, t.tab, p.eq_pk)" - " || ' )\n THEN NULL\n '" + " || ' )\n THEN NULL\n '" " || 'ELSE format(''surplus entry ('" " || group_concat('%%s', ',') || ',' || p.ps_pk" " || ') in index ' || t.idx || ''', ' " " || group_concat('quote('||i.col_alias||')', ', ') || ', ' || p.pk_pk" " || ')'" - " || '\nEND AS error_message'" + " || '\n END AS error_message'" " FROM tabname t, tabpk p, idx_cols i WHERE i.idx_name=t.idx" ")" "" @@ -613,26 +685,25 @@ static char *intckCheckObjectSql( " FROM tabpk p, idx_cols i WHERE i.idx_name=p.idx" ")" "" - ", whereclause(w_c) AS (" - " SELECT CASE WHEN prev!='' THEN " - " '\nWHERE (' || group_concat(i.col_alias, ',') || ',' " - " || o_pk || ') > ' || prev" - " ELSE ''" - " END" - " FROM tabpk, tabname, idx_cols i WHERE i.idx_name=tabpk.idx" - ")" - "" ", main_select(m, n) AS (" " SELECT format(" - " 'WITH %%s\nSELECT %%s,\n%%s\nFROM intck_wrapper AS o%%s'," - " ww.s, c, t.k, whereclause.w_c" + " 'WITH %%s\n' ||" + " ', idx_checker AS (\n' ||" + " ' SELECT %%s,\n' ||" + " ' %%s\n' || " + " ' FROM intck_wrapper AS o\n' ||" + " ')\n'," + " ww.s, c, t.k" " ), t.n" - " FROM case_statement, wrapper_with ww, thiskey t, whereclause" + " FROM case_statement, wrapper_with ww, thiskey t" ")" - "SELECT m, n FROM main_select" + "SELECT m || " + " group_concat('SELECT * FROM idx_checker ' || w_c, ' UNION ALL '), n" + " FROM " + "main_select, whereclause " , p->zDb, p->zDb, zObj, zObj - , zPrev, zCommon + , zPrev ? zPrev : "VALUES('')", zCommon ); }else{ pStmt = intckPrepareFmt(p, @@ -689,7 +760,7 @@ static char *intckCheckObjectSql( ** format('(%d,%d)', _rowid_, n.ii) */ ", thiskey(k, n) AS (" - " SELECT o_pk || ', n.ii', n_pk+1 FROM tabpk" + " SELECT o_pk || ', ii', n_pk+1 FROM tabpk" ")" "" ", whereclause(w_c) AS (" @@ -702,7 +773,7 @@ static char *intckCheckObjectSql( "" ", main_select(m, n) AS (" " SELECT format(" - " '%%s, %%s\nSELECT %%s,\n%%s AS thiskey\nFROM intck_wrapper AS o" + " '%%s, %%s\nSELECT %%s,\n%%s\nFROM intck_wrapper AS o" ", intck_counter AS n%%s\nORDER BY %%s', " " w, ww.s, c, thiskey.k, whereclause.w_c, t.o_pk" " ), thiskey.n" diff --git a/manifest b/manifest index 316837de51..7508c5a2f6 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\svarious\sissues\sin\ssqlite3intck.c. -D 2024-02-21T20:58:48.924 +C Fix\sproblems\swith\sresuming\sintegrity-check\soperations\son\sindexes\swith\smixed\sASC\sand\sDESC\scolumns,\sand\son\sindexes\sthat\scontain\sNULL\svalues. +D 2024-02-23T15:13:53.489 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -248,11 +248,11 @@ F ext/fts5/tool/showfts5.tcl d54da0e067306663e2d5d523965ca487698e722c F ext/icu/README.txt 7ab7ced8ae78e3a645b57e78570ff589d4c672b71370f5aa9e1cd7024f400fc9 F ext/icu/icu.c c074519b46baa484bb5396c7e01e051034da8884bad1a1cb7f09bbe6be3f0282 F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a32075a8 -F ext/intck/intck1.test 15e94ee868e939c6d3aef6884c5652d969b28d3eac940a15585511cf8aec71ad -F ext/intck/intck2.test b65d7f627342f767e1d2c447d25619666cec36f516786dd56568bd741e5d7e67 -F ext/intck/intck_common.tcl b8a63ae820dbcdf50ddaba474f130b43c26ba81f4b7720ff1d8b9a6592bdd420 +F ext/intck/intck1.test e73c4f87b54176291b9a01b52dbc9dd88f42f3ec8aea48c8e0bd7f87a1440a40 +F ext/intck/intck2.test 9d083ccb06c9239400569846b077fb9867a19b12233ce9dcbc124540e12d38df +F ext/intck/intck_common.tcl 9e51458126576783f11051ac0fd25bea3f6b17f570a55884223737f3200b214b F ext/intck/intckcorrupt.test 3211ef68ac53e83951b6c8f6a8d2396506d123fe5898f97f848a25837744ec56 -F ext/intck/sqlite3intck.c 3fa96647dde4c719a477f7dbdd1edf76b2f245549b1a4de7f7d60447b24a14df +F ext/intck/sqlite3intck.c b7dd8354b4c3255cecc8cc190f7f980a667d3aec7409900703248296472b358f F ext/intck/sqlite3intck.h 2b40c38e7063ab822c974c0bd4aed97dabb579ccfe2e180a4639bb3bbef0f1c9 F ext/intck/test_intck.c dec07fc82e2626a1450e58be474e351643627b04ee08ce8fae6495a533b87e85 F ext/jni/GNUmakefile 59eb05f2a363bdfac8d15d66bed624bfe1ff289229184f3861b95f98a19cf4b2 @@ -2169,8 +2169,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 0e39962baae8a82a3021077676b792ac30c79426bcd8c075b5e92bee55e8c3a5 -R 2d481f6c889817bf845056ed7696633c +P 8a7bfa74525a495f45b1ea212b1718633b637295090d514dd777f9263477d514 +R afa6cae1c52ecb818ac1cff0c8856821 U dan -Z 13c318cbe203f9a86dd5c12df0ee017f +Z d57af7b6bfe17ed12101d02b696a832f # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 092b5c01d4..391414ddf6 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8a7bfa74525a495f45b1ea212b1718633b637295090d514dd777f9263477d514 \ No newline at end of file +0f68b35a000ef9f4691c59797c66ed6c3435fc5c503e9d24f891afec6aceeada \ No newline at end of file From 5956d1d94288cd816af1f1c1c667be472fdccdbd Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 23 Feb 2024 17:10:39 +0000 Subject: [PATCH 137/430] Fix detection of surplus index entries when all indexed fields are NULL. FossilOrigin-Name: 5f310fb7be450c96f01c21e6fd1377d4a274784377d0bd811922ab63e612bd11 --- ext/intck/intck2.test | 33 ++++++++++++++++++++++++++++++--- ext/intck/sqlite3intck.c | 4 ++-- manifest | 14 +++++++------- manifest.uuid | 2 +- 4 files changed, 40 insertions(+), 13 deletions(-) diff --git a/ext/intck/intck2.test b/ext/intck/intck2.test index bb57886968..54c392b0f5 100644 --- a/ext/intck/intck2.test +++ b/ext/intck/intck2.test @@ -67,7 +67,6 @@ imposter_edit x1 { } { DELETE FROM imp WHERE c=7; } -puts [intck_sql db x1b] do_intck_test 2.2 { {surplus entry ('ONE',6,3) in index x1a} {surplus entry ('ONE6 "''" ',3) in index x1b} @@ -112,8 +111,36 @@ do_intck_test 3.2 { {surplus entry (1,2,1,8) in index x1all} } -#puts [intck_sql db x1all] -#puts [intck_sql db x1] +do_execsql_test 3.3 { + DELETE FROM x1; + INSERT INTO x1 VALUES(NULL, NULL, NULL); + INSERT INTO x1 VALUES(NULL, NULL, NULL); + INSERT INTO x1 VALUES(NULL, NULL, NULL); + INSERT INTO x1 VALUES(NULL, NULL, NULL); +} + +do_intck_test 3.4 { +} + +imposter_edit x1 { + CREATE TABLE imp(a, b, c); +} { + DELETE FROM imp WHERE 1; + INSERT INTO imp(rowid) VALUES(-123); + INSERT INTO imp(rowid) VALUES(456); +} + +db close +sqlite3 db test.db + +do_intck_test 3.5 { + {entry (NULL,NULL,NULL,-123) missing from index x1all} + {entry (NULL,NULL,NULL,456) missing from index x1all} + {surplus entry (NULL,NULL,NULL,1) in index x1all} + {surplus entry (NULL,NULL,NULL,2) in index x1all} + {surplus entry (NULL,NULL,NULL,3) in index x1all} + {surplus entry (NULL,NULL,NULL,4) in index x1all} +} finish_test diff --git a/ext/intck/sqlite3intck.c b/ext/intck/sqlite3intck.c index 287ec157c3..23f93eb318 100644 --- a/ext/intck/sqlite3intck.c +++ b/ext/intck/sqlite3intck.c @@ -666,8 +666,8 @@ static char *intckCheckObjectSql( "" ", case_statement(c) AS (" " SELECT " - " 'CASE WHEN (' || group_concat(col_alias, ', ') || ') IS (\n ' " - " || 'SELECT ' || group_concat(col_expr, ', ') || ' FROM '" + " 'CASE WHEN (' || group_concat(col_alias, ', ') || ', 1) IS (\n' " + " || ' SELECT ' || group_concat(col_expr, ', ') || ', 1 FROM '" " || format('%%Q.%%Q NOT INDEXED WHERE %%s\n', t.db, t.tab, p.eq_pk)" " || ' )\n THEN NULL\n '" " || 'ELSE format(''surplus entry ('" diff --git a/manifest b/manifest index 7508c5a2f6..f702e591f9 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sproblems\swith\sresuming\sintegrity-check\soperations\son\sindexes\swith\smixed\sASC\sand\sDESC\scolumns,\sand\son\sindexes\sthat\scontain\sNULL\svalues. -D 2024-02-23T15:13:53.489 +C Fix\sdetection\sof\ssurplus\sindex\sentries\swhen\sall\sindexed\sfields\sare\sNULL. +D 2024-02-23T17:10:39.995 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -249,10 +249,10 @@ F ext/icu/README.txt 7ab7ced8ae78e3a645b57e78570ff589d4c672b71370f5aa9e1cd7024f4 F ext/icu/icu.c c074519b46baa484bb5396c7e01e051034da8884bad1a1cb7f09bbe6be3f0282 F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a32075a8 F ext/intck/intck1.test e73c4f87b54176291b9a01b52dbc9dd88f42f3ec8aea48c8e0bd7f87a1440a40 -F ext/intck/intck2.test 9d083ccb06c9239400569846b077fb9867a19b12233ce9dcbc124540e12d38df +F ext/intck/intck2.test 348a8c505bfe843eceaedd911f91ba4516b5e9c2d4aa83a300a6e84de6ff0955 F ext/intck/intck_common.tcl 9e51458126576783f11051ac0fd25bea3f6b17f570a55884223737f3200b214b F ext/intck/intckcorrupt.test 3211ef68ac53e83951b6c8f6a8d2396506d123fe5898f97f848a25837744ec56 -F ext/intck/sqlite3intck.c b7dd8354b4c3255cecc8cc190f7f980a667d3aec7409900703248296472b358f +F ext/intck/sqlite3intck.c c8515c1ed1bc725e156fc5053e8f9c8cff3c440f3bca47a8309e76d2411fc73d F ext/intck/sqlite3intck.h 2b40c38e7063ab822c974c0bd4aed97dabb579ccfe2e180a4639bb3bbef0f1c9 F ext/intck/test_intck.c dec07fc82e2626a1450e58be474e351643627b04ee08ce8fae6495a533b87e85 F ext/jni/GNUmakefile 59eb05f2a363bdfac8d15d66bed624bfe1ff289229184f3861b95f98a19cf4b2 @@ -2169,8 +2169,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 8a7bfa74525a495f45b1ea212b1718633b637295090d514dd777f9263477d514 -R afa6cae1c52ecb818ac1cff0c8856821 +P 0f68b35a000ef9f4691c59797c66ed6c3435fc5c503e9d24f891afec6aceeada +R 67e774420e8bc9ef111ef98dbd2b2abc U dan -Z d57af7b6bfe17ed12101d02b696a832f +Z f383f29167401158528bd4b4e88fca49 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 391414ddf6..1b5128f2f2 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0f68b35a000ef9f4691c59797c66ed6c3435fc5c503e9d24f891afec6aceeada \ No newline at end of file +5f310fb7be450c96f01c21e6fd1377d4a274784377d0bd811922ab63e612bd11 \ No newline at end of file From b088e892a09a95b6929e87a4cc7091644d75fa47 Mon Sep 17 00:00:00 2001 From: stephan Date: Fri, 23 Feb 2024 18:02:31 +0000 Subject: [PATCH 138/430] Typo fixes [forum:c19bbf245d|reported in the forum]. No code changes. FossilOrigin-Name: 67d8bae0f695c0839e724c1aadea0a22f736fdd9664d40a29b4d82c91fb89ab3 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/sqlite.h.in | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index a2ef0141ff..0dcfda40aa 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sharmless\scompiler\swarning\sseen\swith\sMSVC. -D 2024-02-22T18:15:08.241 +C Typo\sfixes\s[forum:c19bbf245d|reported\sin\sthe\sforum].\sNo\scode\schanges. +D 2024-02-23T18:02:31.402 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -741,7 +741,7 @@ F src/resolve.c d77c6160bc8f249c2196fdd3e75f66a1dd70e37aa25c39aedc7b1f93c42b7c6d F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c 43fabfc01bf87addd15e39f112f1e2ade15b19594835ab8a9e5bd50839d4e1b1 F src/shell.c.in e4a38496290d3979ea3d953fba0bc187d350d6e80f8e33c2e37b9a924850439b -F src/sqlite.h.in 020d7b7307dda51420dc48b47e5334eaface77baba6bd9818375d392eb3ab5b5 +F src/sqlite.h.in 19a2db3995a699bd7f6dfb423856242bfceb7ec849a93c91d241d19fc28d9f0f F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 F src/sqliteInt.h 2f3a38c3e0470b6152ec14f698e6f3310831e3c09b6e56f046a12c3e3bdd5cd4 @@ -2162,8 +2162,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P ce5df19dc4aff3fde03ef62261a5e095a16a8f4e46e2924becea4fed56ce49e3 -R 63d9d369c3456decb924739dc3e48ce6 -U mistachkin -Z 5c46c4e87cc4943d1671979de864e7c2 +P e5db08993127dfc18cc2b621a13cbfef52974f0f504f4d8208093bfad1ffdcc5 +R fbd01c060093cc83561018ffcc839787 +U stephan +Z 3309f779a4e95b40300e717423266d54 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 37d995b0c3..75ab08df22 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e5db08993127dfc18cc2b621a13cbfef52974f0f504f4d8208093bfad1ffdcc5 \ No newline at end of file +67d8bae0f695c0839e724c1aadea0a22f736fdd9664d40a29b4d82c91fb89ab3 \ No newline at end of file diff --git a/src/sqlite.h.in b/src/sqlite.h.in index f21cffd51a..e05d7b231a 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -764,11 +764,11 @@ struct sqlite3_file { ** ** xLock() upgrades the database file lock. In other words, xLock() moves the ** database file lock in the direction NONE toward EXCLUSIVE. The argument to -** xLock() is always on of SHARED, RESERVED, PENDING, or EXCLUSIVE, never +** xLock() is always one of SHARED, RESERVED, PENDING, or EXCLUSIVE, never ** SQLITE_LOCK_NONE. If the database file lock is already at or above the ** requested lock, then the call to xLock() is a no-op. ** xUnlock() downgrades the database file lock to either SHARED or NONE. -* If the lock is already at or below the requested lock state, then the call +** If the lock is already at or below the requested lock state, then the call ** to xUnlock() is a no-op. ** The xCheckReservedLock() method checks whether any database connection, ** either in this process or in some other process, is holding a RESERVED, From 645f21f15baf64486ac4c81543aa19476e10869e Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 23 Feb 2024 18:21:51 +0000 Subject: [PATCH 139/430] Add the ".intck ?STEPS_PER_UNLOCK?" command to the shell tool. FossilOrigin-Name: cfd051836b72f7d4e38cc9614f6ae5c003de4ce377359fd391adf06fe1ddf6b9 --- ext/intck/intck2.test | 33 +++++++++++++++++++++++++-- manifest | 14 ++++++------ manifest.uuid | 2 +- src/shell.c.in | 53 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 92 insertions(+), 10 deletions(-) diff --git a/ext/intck/intck2.test b/ext/intck/intck2.test index 54c392b0f5..c168118535 100644 --- a/ext/intck/intck2.test +++ b/ext/intck/intck2.test @@ -1,4 +1,4 @@ -# 2008 Feb 19 +# 2024 Feb 19 # # The author disclaims copyright to this source code. In place of # a legal notice, here is a blessing: @@ -142,6 +142,35 @@ do_intck_test 3.5 { {surplus entry (NULL,NULL,NULL,4) in index x1all} } -finish_test +reset_db + +do_execsql_test 3.6 { + CREATE TABLE w1(a PRIMARY KEY, b, c); + INSERT INTO w1 VALUES(1.0, NULL, NULL); + INSERT INTO w1 VALUES(33.0, NULL, NULL); + INSERT INTO w1 VALUES(100.0, NULL, NULL); + CREATE INDEX w1bc ON w1(b, c); +} +do_intck_test 3.7 { +} + +imposter_edit w1 { + CREATE TABLE imp(a, b, c); +} { + DELETE FROM imp WHERE a=33; + INSERT INTO imp(a) VALUES(1234.5); + INSERT INTO imp(a) VALUES(-1234.5); +} + +do_intck_test 3.8 { + {surplus entry (33.0,2) in index sqlite_autoindex_w1_1} + {entry (1234.5,4) missing from index sqlite_autoindex_w1_1} + {entry (NULL,NULL,4) missing from index w1bc} + {entry (-1234.5,5) missing from index sqlite_autoindex_w1_1} + {entry (NULL,NULL,5) missing from index w1bc} + {surplus entry (NULL,NULL,2) in index w1bc} +} + +finish_test diff --git a/manifest b/manifest index f702e591f9..266c84bd6a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sdetection\sof\ssurplus\sindex\sentries\swhen\sall\sindexed\sfields\sare\sNULL. -D 2024-02-23T17:10:39.995 +C Add\sthe\s".intck\s?STEPS_PER_UNLOCK?"\scommand\sto\sthe\sshell\stool. +D 2024-02-23T18:21:51.131 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -249,7 +249,7 @@ F ext/icu/README.txt 7ab7ced8ae78e3a645b57e78570ff589d4c672b71370f5aa9e1cd7024f4 F ext/icu/icu.c c074519b46baa484bb5396c7e01e051034da8884bad1a1cb7f09bbe6be3f0282 F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a32075a8 F ext/intck/intck1.test e73c4f87b54176291b9a01b52dbc9dd88f42f3ec8aea48c8e0bd7f87a1440a40 -F ext/intck/intck2.test 348a8c505bfe843eceaedd911f91ba4516b5e9c2d4aa83a300a6e84de6ff0955 +F ext/intck/intck2.test 97daaf43b8a3c870ba7c2fd421dc1887053f5b30188896fa64677ce8174c206f F ext/intck/intck_common.tcl 9e51458126576783f11051ac0fd25bea3f6b17f570a55884223737f3200b214b F ext/intck/intckcorrupt.test 3211ef68ac53e83951b6c8f6a8d2396506d123fe5898f97f848a25837744ec56 F ext/intck/sqlite3intck.c c8515c1ed1bc725e156fc5053e8f9c8cff3c440f3bca47a8309e76d2411fc73d @@ -747,7 +747,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c d77c6160bc8f249c2196fdd3e75f66a1dd70e37aa25c39aedc7b1f93c42b7c6d F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c 43fabfc01bf87addd15e39f112f1e2ade15b19594835ab8a9e5bd50839d4e1b1 -F src/shell.c.in e4a38496290d3979ea3d953fba0bc187d350d6e80f8e33c2e37b9a924850439b +F src/shell.c.in 0c13f7cc3bb8c31190efbd96f5c1d8f2fafdbcad549424b7e7850cb5617b115a F src/sqlite.h.in 020d7b7307dda51420dc48b47e5334eaface77baba6bd9818375d392eb3ab5b5 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 @@ -2169,8 +2169,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 0f68b35a000ef9f4691c59797c66ed6c3435fc5c503e9d24f891afec6aceeada -R 67e774420e8bc9ef111ef98dbd2b2abc +P 5f310fb7be450c96f01c21e6fd1377d4a274784377d0bd811922ab63e612bd11 +R 86a36a81ccd4a5a3ded74d8234b0250a U dan -Z f383f29167401158528bd4b4e88fca49 +Z 39f7083bcdb0c03c315a581938028ce8 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 1b5128f2f2..ff9880a342 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5f310fb7be450c96f01c21e6fd1377d4a274784377d0bd811922ab63e612bd11 \ No newline at end of file +cfd051836b72f7d4e38cc9614f6ae5c003de4ce377359fd391adf06fe1ddf6b9 \ No newline at end of file diff --git a/src/shell.c.in b/src/shell.c.in index da377982e1..07e4b201ce 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -1222,6 +1222,9 @@ INCLUDE ../ext/misc/sqlar.c INCLUDE ../ext/expert/sqlite3expert.h INCLUDE ../ext/expert/sqlite3expert.c +INCLUDE ../ext/intck/sqlite3intck.h +INCLUDE ../ext/intck/sqlite3intck.c + #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB) #define SQLITE_SHELL_HAVE_RECOVER 1 #else @@ -4741,6 +4744,7 @@ static const char *(azHelp[]) = { ".indexes ?TABLE? Show names of indexes", " If TABLE is specified, only show indexes for", " tables matching TABLE using the LIKE operator.", + ".intck ?STEPS_PER_UNLOCK? Run an incremental integrity check on the db", #ifdef SQLITE_ENABLE_IOTRACE ",iotrace FILE Enable I/O diagnostic logging to FILE", #endif @@ -7650,6 +7654,40 @@ static int recoverDatabaseCmd(ShellState *pState, int nArg, char **azArg){ } #endif /* SQLITE_SHELL_HAVE_RECOVER */ +/* +** Implementation of ".intck STEPS_PER_UNLOCK" command. +*/ +static int intckDatabaseCmd(ShellState *pState, i64 nStepPerUnlock){ + sqlite3_intck *p = 0; + int rc = SQLITE_OK; + + rc = sqlite3_intck_open(pState->db, "main", &p); + if( rc==SQLITE_OK ){ + i64 nStep = 0; + i64 nError = 0; + const char *zErr = 0; + while( SQLITE_OK==sqlite3_intck_step(p) ){ + const char *zMsg = sqlite3_intck_message(p); + if( zMsg ){ + oputf("%s\n", zMsg); + nError++; + } + nStep++; + if( nStepPerUnlock && (nStep % nStepPerUnlock)==0 ){ + sqlite3_intck_unlock(p); + } + } + rc = sqlite3_intck_error(p, &zErr); + if( zErr ){ + eputf("%s\n", zErr); + } + sqlite3_intck_close(p); + + oputf("%lld steps, %lld errors\n", nStep, nError); + } + + return rc; +} /* * zAutoColumn(zCol, &db, ?) => Maybe init db, add column zCol to it. @@ -9140,6 +9178,21 @@ static int do_meta_command(char *zLine, ShellState *p){ }else #endif /* !defined(SQLITE_OMIT_TEST_CONTROL) */ + if( c=='i' && cli_strncmp(azArg[0], "intck", n)==0 ){ + i64 iArg = 0; + if( nArg==2 ){ + iArg = integerValue(azArg[1]); + if( iArg==0 ) iArg = -1; + } + if( (nArg!=1 && nArg!=2) || iArg<0 ){ + eputf("Usage: .intck STEPS_PER_UNLOCK\n"); + rc = 1; + goto meta_command_exit; + } + open_db(p, 0); + rc = intckDatabaseCmd(p, iArg); + }else + #ifdef SQLITE_ENABLE_IOTRACE if( c=='i' && cli_strncmp(azArg[0], "iotrace", n)==0 ){ SQLITE_API extern void (SQLITE_CDECL *sqlite3IoTrace)(const char*, ...); From ee299cc7d4c5d72cf25cf59478212c3731848f5a Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 23 Feb 2024 20:51:06 +0000 Subject: [PATCH 140/430] Add tests for the new code on this branch. FossilOrigin-Name: 351d46b2373f08bc8033d0902d9f67cd6c8bcc16c0d9f787e4fb279c0a76da87 --- ext/intck/intckfault.test | 45 +++++++++++++++++++++++++++++++++++++++ ext/intck/sqlite3intck.c | 20 +++++++++++------ manifest | 13 +++++------ manifest.uuid | 2 +- 4 files changed, 66 insertions(+), 14 deletions(-) create mode 100644 ext/intck/intckfault.test diff --git a/ext/intck/intckfault.test b/ext/intck/intckfault.test new file mode 100644 index 0000000000..5c383681ac --- /dev/null +++ b/ext/intck/intckfault.test @@ -0,0 +1,45 @@ +# 2024 February 24 +# +# 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]] intck_common.tcl] +set testprefix intckfault + + + +do_execsql_test 1.0 { + CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c); + INSERT INTO t1 VALUES(1, 2, 3); + INSERT INTO t1 VALUES(2, 'two', 'three'); + INSERT INTO t1 VALUES(3, NULL, NULL); + CREATE INDEX i1 ON t1(b, c); +} + +do_faultsim_test 1 -faults oom-t* -prep { +} -body { + set ::ic [sqlite3_intck db main] + set nStep 0 + while {"SQLITE_OK"==[$::ic step]} { + incr nStep + if {$nStep==3} { $::ic unlock } + } + set res [$::ic error] + $::ic close + set res +} -test { + catch { $::ic close } +puts $testresult +puts $testnfail + faultsim_test_result {0 {SQLITE_OK {}}} {0 {SQLITE_NOMEM {}}} {0 {SQLITE_NOMEM {out of memory}}} +} + +finish_test + diff --git a/ext/intck/sqlite3intck.c b/ext/intck/sqlite3intck.c index 23f93eb318..b61035f157 100644 --- a/ext/intck/sqlite3intck.c +++ b/ext/intck/sqlite3intck.c @@ -159,10 +159,12 @@ static void *intckMalloc(sqlite3_intck *p, sqlite3_int64 nByte){ */ static char *intckStrdup(sqlite3_intck *p, const char *zIn){ char *zOut = 0; - int nIn = strlen(zIn); - zOut = (char*)intckMalloc(p, nIn+1); - if( zOut ){ - memcpy(zOut, zIn, nIn+1); + if( zIn ){ + int nIn = strlen(zIn); + zOut = (char*)intckMalloc(p, nIn+1); + if( zOut ){ + memcpy(zOut, zIn, nIn+1); + } } return zOut; } @@ -815,13 +817,17 @@ int sqlite3_intck_open( if( pNew==0 ){ rc = SQLITE_NOMEM; }else{ - sqlite3_create_function(db, "parse_create_index", - 2, SQLITE_UTF8, 0, intckParseCreateIndexFunc, 0, 0 - ); memset(pNew, 0, sizeof(*pNew)); pNew->db = db; pNew->zDb = (const char*)&pNew[1]; memcpy(&pNew[1], zDb, nDb+1); + rc = sqlite3_create_function(db, "parse_create_index", + 2, SQLITE_UTF8, 0, intckParseCreateIndexFunc, 0, 0 + ); + if( rc!=SQLITE_OK ){ + sqlite3_intck_close(pNew); + pNew = 0; + } } *ppOut = pNew; diff --git a/manifest b/manifest index 266c84bd6a..068e592cd0 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\s".intck\s?STEPS_PER_UNLOCK?"\scommand\sto\sthe\sshell\stool. -D 2024-02-23T18:21:51.131 +C Add\stests\sfor\sthe\snew\scode\son\sthis\sbranch. +D 2024-02-23T20:51:06.837 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -252,7 +252,8 @@ F ext/intck/intck1.test e73c4f87b54176291b9a01b52dbc9dd88f42f3ec8aea48c8e0bd7f87 F ext/intck/intck2.test 97daaf43b8a3c870ba7c2fd421dc1887053f5b30188896fa64677ce8174c206f F ext/intck/intck_common.tcl 9e51458126576783f11051ac0fd25bea3f6b17f570a55884223737f3200b214b F ext/intck/intckcorrupt.test 3211ef68ac53e83951b6c8f6a8d2396506d123fe5898f97f848a25837744ec56 -F ext/intck/sqlite3intck.c c8515c1ed1bc725e156fc5053e8f9c8cff3c440f3bca47a8309e76d2411fc73d +F ext/intck/intckfault.test ba0213c9c8dce08d519d5251268a3bab076a184b4d07acdea23b65e89c9ae03c +F ext/intck/sqlite3intck.c 642f57a4604580513547df9d8489cdb49b8f5f3af1981c7ffb87bc37e5ce1439 F ext/intck/sqlite3intck.h 2b40c38e7063ab822c974c0bd4aed97dabb579ccfe2e180a4639bb3bbef0f1c9 F ext/intck/test_intck.c dec07fc82e2626a1450e58be474e351643627b04ee08ce8fae6495a533b87e85 F ext/jni/GNUmakefile 59eb05f2a363bdfac8d15d66bed624bfe1ff289229184f3861b95f98a19cf4b2 @@ -2169,8 +2170,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 5f310fb7be450c96f01c21e6fd1377d4a274784377d0bd811922ab63e612bd11 -R 86a36a81ccd4a5a3ded74d8234b0250a +P cfd051836b72f7d4e38cc9614f6ae5c003de4ce377359fd391adf06fe1ddf6b9 +R aa9167c841a6524a2987fc0088c3a9be U dan -Z 39f7083bcdb0c03c315a581938028ce8 +Z 2a1b98d11090580141aae0cbd3e3021e # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index ff9880a342..c043830657 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -cfd051836b72f7d4e38cc9614f6ae5c003de4ce377359fd391adf06fe1ddf6b9 \ No newline at end of file +351d46b2373f08bc8033d0902d9f67cd6c8bcc16c0d9f787e4fb279c0a76da87 \ No newline at end of file From 9c59c87448c2c8a7411bb65b4a163a1f634db8ab Mon Sep 17 00:00:00 2001 From: dan Date: Sat, 24 Feb 2024 16:26:15 +0000 Subject: [PATCH 141/430] Add further tests for the intck module. FossilOrigin-Name: c253e276b29de28a18270d01b60d95157ce3fc4b37e246d991f9119d26e718d7 --- ext/intck/intck1.test | 125 ++++++++++++++++++++++++++++++++++++++- ext/intck/intckbusy.test | 48 +++++++++++++++ ext/intck/sqlite3intck.c | 74 ++++++++--------------- ext/intck/test_intck.c | 8 ++- manifest | 17 +++--- manifest.uuid | 2 +- 6 files changed, 211 insertions(+), 63 deletions(-) create mode 100644 ext/intck/intckbusy.test diff --git a/ext/intck/intck1.test b/ext/intck/intck1.test index 4e86e4f2fc..e05ae06166 100644 --- a/ext/intck/intck1.test +++ b/ext/intck/intck1.test @@ -200,9 +200,132 @@ reset_db do_execsql_test 5.0 { CREATE TABLE t1(a, b); CREATE INDEX i1 ON t1(a COLLATE NOCASE); + INSERT INTO t1 VALUES(1, 1); + INSERT INTO t1 VALUES(2, 2); } -#puts [intck_sql db i1] +do_test 5.1 { + set ic [sqlite3_intck db nosuchdb] + $ic step +} {SQLITE_ERROR} + +do_test 5.2 { + $ic close + set ic [sqlite3_intck db {}] + while {[$ic step]=="SQLITE_OK"} {} + set res [$ic error] + $ic close + set res +} {SQLITE_OK {}} + +do_test 5.3 { test_do_intck db "main" } {} + +do_test 5.4 { + set ret {} + set ic [sqlite3_intck db main] + db eval [$ic test_sql t1] { + if {$error_message!=""} { lappend ret $error_message } + } + $ic close + set ret +} {} + +do_test 5.5 { + set ret {} + set ic [sqlite3_intck db main] + db eval [$ic test_sql {}] { + if {$error_message!=""} { lappend ret $error_message } + } + $ic close + set ret +} {} + +db cache flush + +do_test 5.6 { + set ret {} + set ic [sqlite3_intck db main] + $ic step + db eval [$ic test_sql {}] { + if {$error_message!=""} { lappend ret $error_message } + } + $ic close + set ret +} {} + +#------------------------------------------------------------------------- +reset_db + +do_execsql_test 6.0 { + CREATE TABLE t1(x, y, PRIMARY KEY(x)) WITHOUT ROWID; + CREATE INDEX i1 ON t1(y, x); + INSERT INTO t1 VALUES(X'0000', X'1111'); +} + +do_intck_test 6.1 {} + +do_execsql_test 6.2.1 { + PRAGMA writable_schema = 1; + UPDATE sqlite_schema SET sql = 'CREATE INDEX i1' WHERE name='i1'; +} {} +do_intck_test 6.2.2 {} + +do_execsql_test 6.3.1 { + UPDATE sqlite_schema SET sql = 'CREATE INDEX i1(y' WHERE name='i1'; +} {} +do_intck_test 6.3.2 {} + +do_execsql_test 6.4.1 { + UPDATE sqlite_schema + SET sql = 'CREATE INDEX i1(y) hello world' + WHERE name='i1'; +} {} +do_intck_test 6.4.2 {} + +do_execsql_test 6.5.1 { + UPDATE sqlite_schema + SET sql = 'CREATE INDEX i1(y, x) WHERE 1 ' + WHERE name='i1'; +} {} +do_intck_test 6.5.2 {} + +do_execsql_test 6.6.1 { + UPDATE sqlite_schema + SET sql = 'CREATE INDEX i1( , ) WHERE 1 ' + WHERE name='i1'; +} {} + +do_test 6.7.2 { + set ic [sqlite3_intck db main] + $ic step +} {SQLITE_ERROR} +do_test 6.5.3 { + $ic error +} {SQLITE_ERROR {near "AS": syntax error}} +$ic close + +do_execsql_test 6.6.1 { + UPDATE sqlite_schema + SET sql = 'CREATE INDEX i1([y' + WHERE name='i1'; +} {} +do_intck_test 6.6.2 {} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 7.0 { + CREATE TABLE x1("1", "22", "3333", four); + CREATE INDEX i1 ON x1( "1" , "22", NULL); + INSERT INTO x1 VALUES(1, 22, 3333, NULL); + INSERT INTO x1 VALUES(1, 22, 3333, NULL); +} +do_execsql_test 7.1 " CREATE INDEX i2 ON x1( \"1\"\r\n\t ) " +do_execsql_test 7.2 { CREATE INDEX i3 ON x1( "22" || 'abc''def' || `1` ) } +do_execsql_test 7.3 { CREATE INDEX i4 ON x1( [22] + [1] ) } +do_execsql_test 7.4 { CREATE INDEX i5 ON x1( four||'hello' ) } + +do_intck_test 7.5 {} + finish_test diff --git a/ext/intck/intckbusy.test b/ext/intck/intckbusy.test new file mode 100644 index 0000000000..edfedf5ae8 --- /dev/null +++ b/ext/intck/intckbusy.test @@ -0,0 +1,48 @@ +# 2024 February 24 +# +# 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]] intck_common.tcl] +set testprefix intckbusy + + + +do_execsql_test 1.0 { + CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c); + INSERT INTO t1 VALUES(1, 2, 3); + INSERT INTO t1 VALUES(2, 'two', 'three'); + INSERT INTO t1 VALUES(3, NULL, NULL); + CREATE INDEX i1 ON t1(b, c); +} + +sqlite3 db2 test.db + +do_execsql_test -db db2 1.1 { + BEGIN EXCLUSIVE; + INSERT INTO t1 VALUES(4, 5, 6); +} + +do_test 1.2 { + set ic [sqlite3_intck db main] + $ic step +} {SQLITE_BUSY} +do_test 1.3 { + $ic unlock +} {SQLITE_BUSY} +do_test 1.4 { + $ic error +} {SQLITE_BUSY {database is locked}} +do_test 1.4 { + $ic close +} {} + +finish_test + diff --git a/ext/intck/sqlite3intck.c b/ext/intck/sqlite3intck.c index b61035f157..12d205e4d9 100644 --- a/ext/intck/sqlite3intck.c +++ b/ext/intck/sqlite3intck.c @@ -60,12 +60,9 @@ struct sqlite3_intck { ** and error code currently held by the database handle in p->rc and p->zErr. */ static void intckSaveErrmsg(sqlite3_intck *p){ - const char *zDberr = sqlite3_errmsg(p->db); p->rc = sqlite3_errcode(p->db); - if( zDberr ){ - sqlite3_free(p->zErr); - p->zErr = sqlite3_mprintf("%s", zDberr); - } + sqlite3_free(p->zErr); + p->zErr = sqlite3_mprintf("%s", sqlite3_errmsg(p->db)); } /* @@ -125,6 +122,15 @@ static void intckFinalize(sqlite3_intck *p, sqlite3_stmt *pStmt){ } } +/* +** If there is already an error in handle p, return it. Otherwise, call +** sqlite3_step() on the statement handle and return that value. +*/ +static int intckStep(sqlite3_intck *p, sqlite3_stmt *pStmt){ + if( p->rc ) return p->rc; + return sqlite3_step(pStmt); +} + /* ** Execute SQL statement zSql. There is no way to obtain any results ** returned by the statement. This function uses the sqlite3_intck error @@ -133,42 +139,10 @@ static void intckFinalize(sqlite3_intck *p, sqlite3_stmt *pStmt){ static void intckExec(sqlite3_intck *p, const char *zSql){ sqlite3_stmt *pStmt = 0; pStmt = intckPrepare(p, zSql); - while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ); + intckStep(p, pStmt); intckFinalize(p, pStmt); } -/* -** Wrapper around sqlite3_malloc64() that uses the sqlite3_intck error -** code convention. -*/ -static void *intckMalloc(sqlite3_intck *p, sqlite3_int64 nByte){ - void *pRet = 0; - assert( nByte>0 ); - if( p->rc==SQLITE_OK ){ - pRet = sqlite3_malloc64(nByte); - if( pRet==0 ){ - p->rc = SQLITE_NOMEM; - } - } - return pRet; -} - -/* -** Like strdup(), but uses the sqlite3_intck error code convention. Any -** returned buffer should eventually be freed using sqlite3_free(). -*/ -static char *intckStrdup(sqlite3_intck *p, const char *zIn){ - char *zOut = 0; - if( zIn ){ - int nIn = strlen(zIn); - zOut = (char*)intckMalloc(p, nIn+1); - if( zOut ){ - memcpy(zOut, zIn, nIn+1); - } - } - return zOut; -} - /* ** A wrapper around sqlite3_mprintf() that uses the sqlite3_intck error ** code convention. @@ -280,7 +254,7 @@ static void intckSaveKey(sqlite3_intck *p){ sqlite3_bind_value(pStmt, ii+1, sqlite3_column_value(p->pCheck, ii+1)); } if( SQLITE_ROW==sqlite3_step(pStmt) ){ - p->zKey = intckStrdup(p, (const char*)sqlite3_column_text(pStmt, 0)); + p->zKey = intckMprintf(p,"%s",(const char*)sqlite3_column_text(pStmt, 0)); } intckFinalize(p, pStmt); } @@ -318,7 +292,7 @@ static void intckFindObject(sqlite3_intck *p){ if( p->rc==SQLITE_OK ){ sqlite3_bind_text(pStmt, 1, zPrev, -1, SQLITE_TRANSIENT); if( sqlite3_step(pStmt)==SQLITE_ROW ){ - p->zObj = intckStrdup(p, (const char*)sqlite3_column_text(pStmt, 0)); + p->zObj = intckMprintf(p,"%s",(const char*)sqlite3_column_text(pStmt, 0)); } } intckFinalize(p, pStmt); @@ -347,7 +321,7 @@ static int intckGetToken(const char *z){ while( 1 ){ if( z[iRet]==c ){ iRet++; - if( z[iRet+1]!=c ) break; + if( z[iRet]!=c ) break; } iRet++; } @@ -496,7 +470,7 @@ static int intckGetAutoIndex(sqlite3_intck *p){ int bRet = 0; sqlite3_stmt *pStmt = 0; pStmt = intckPrepare(p, "PRAGMA automatic_index"); - if( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){ + if( SQLITE_ROW==intckStep(p, pStmt) ){ bRet = sqlite3_column_int(pStmt, 0); } intckFinalize(p, pStmt); @@ -789,7 +763,7 @@ static char *intckCheckObjectSql( } while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){ - zRet = intckStrdup(p, (const char*)sqlite3_column_text(pStmt, 0)); + zRet = intckMprintf(p, "%s", (const char*)sqlite3_column_text(pStmt, 0)); if( pnKeyVal ){ *pnKeyVal = sqlite3_column_int(pStmt, 1); } @@ -839,15 +813,15 @@ int sqlite3_intck_open( */ void sqlite3_intck_close(sqlite3_intck *p){ if( p ){ - if( p->db ){ - sqlite3_create_function( - p->db, "parse_create_index", 1, SQLITE_UTF8, 0, 0, 0, 0 - ); - } + sqlite3_finalize(p->pCheck); + sqlite3_create_function( + p->db, "parse_create_index", 1, SQLITE_UTF8, 0, 0, 0, 0 + ); sqlite3_free(p->zObj); sqlite3_free(p->zKey); sqlite3_free(p->zTestSql); sqlite3_free(p->zErr); + sqlite3_free(p->zMessage); sqlite3_free(p); } } @@ -881,7 +855,7 @@ int sqlite3_intck_step(sqlite3_intck *p){ } }else if( p->rc==SQLITE_CORRUPT ){ p->rc = SQLITE_OK; - p->zMessage = intckStrdup(p, + p->zMessage = intckMprintf(p, "%s", "corruption found while reading database schema" ); p->bCorruptSchema = 1; @@ -937,7 +911,7 @@ int sqlite3_intck_error(sqlite3_intck *p, const char **pzErr){ ** on the database. */ int sqlite3_intck_unlock(sqlite3_intck *p){ - if( p->pCheck && p->rc==SQLITE_OK ){ + if( p->rc==SQLITE_OK && p->pCheck ){ assert( p->zKey==0 && p->nKeyVal>0 ); intckSaveKey(p); intckFinalize(p, p->pCheck); diff --git a/ext/intck/test_intck.c b/ext/intck/test_intck.c index 4c34e2fd26..72f72d8c13 100644 --- a/ext/intck/test_intck.c +++ b/ext/intck/test_intck.c @@ -92,12 +92,12 @@ static int testIntckCmd( case 3: assert( 0==strcmp("error", aCmd[iIdx].zName) ); { const char *zErr = 0; - int rc = sqlite3_intck_error(p->intck, &zErr); + int rc = sqlite3_intck_error(p->intck, 0); Tcl_Obj *pRes = Tcl_NewObj(); - Tcl_ListObjAppendElement( interp, pRes, Tcl_NewStringObj(sqlite3ErrName(rc), -1) ); + sqlite3_intck_error(p->intck, &zErr); Tcl_ListObjAppendElement( interp, pRes, Tcl_NewStringObj(zErr ? zErr : 0, -1) ); @@ -160,6 +160,7 @@ static int test_sqlite3_intck( return TCL_ERROR; } zDb = Tcl_GetString(objv[2]); + if( zDb[0]=='\0' ) zDb = 0; rc = sqlite3_intck_open(db, zDb, &p->intck); if( rc!=SQLITE_OK ){ @@ -169,7 +170,7 @@ static int test_sqlite3_intck( } do { - sprintf(zName, "intck%d", iName); + sprintf(zName, "intck%d", iName++); }while( Tcl_GetCommandInfo(interp, zName, &info)!=0 ); Tcl_CreateObjCommand(interp, zName, testIntckCmd, (void*)p, testIntckFree); Tcl_SetObjResult(interp, Tcl_NewStringObj(zName, -1)); @@ -226,6 +227,7 @@ static int test_do_intck( } Tcl_DecrRefCount(pRet); sqlite3_intck_close(pCk); + sqlite3_intck_close(0); return rc ? TCL_ERROR : TCL_OK; } diff --git a/manifest b/manifest index 068e592cd0..732ad1f72c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\stests\sfor\sthe\snew\scode\son\sthis\sbranch. -D 2024-02-23T20:51:06.837 +C Add\sfurther\stests\sfor\sthe\sintck\smodule. +D 2024-02-24T16:26:15.674 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -248,14 +248,15 @@ F ext/fts5/tool/showfts5.tcl d54da0e067306663e2d5d523965ca487698e722c F ext/icu/README.txt 7ab7ced8ae78e3a645b57e78570ff589d4c672b71370f5aa9e1cd7024f400fc9 F ext/icu/icu.c c074519b46baa484bb5396c7e01e051034da8884bad1a1cb7f09bbe6be3f0282 F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a32075a8 -F ext/intck/intck1.test e73c4f87b54176291b9a01b52dbc9dd88f42f3ec8aea48c8e0bd7f87a1440a40 +F ext/intck/intck1.test 866f0937911bf3a10491af6ce319b75bcd587c39dc8decf2444746b946aa4f3e F ext/intck/intck2.test 97daaf43b8a3c870ba7c2fd421dc1887053f5b30188896fa64677ce8174c206f F ext/intck/intck_common.tcl 9e51458126576783f11051ac0fd25bea3f6b17f570a55884223737f3200b214b +F ext/intck/intckbusy.test 0732fe3efbb9e0a53ffdcc240073f6ff2777ea82c3e08812b16494f650763fe1 F ext/intck/intckcorrupt.test 3211ef68ac53e83951b6c8f6a8d2396506d123fe5898f97f848a25837744ec56 F ext/intck/intckfault.test ba0213c9c8dce08d519d5251268a3bab076a184b4d07acdea23b65e89c9ae03c -F ext/intck/sqlite3intck.c 642f57a4604580513547df9d8489cdb49b8f5f3af1981c7ffb87bc37e5ce1439 +F ext/intck/sqlite3intck.c 52381a627637504a49e93400814b36e99afa0b972a9a24ef1732b8268bb27fa8 F ext/intck/sqlite3intck.h 2b40c38e7063ab822c974c0bd4aed97dabb579ccfe2e180a4639bb3bbef0f1c9 -F ext/intck/test_intck.c dec07fc82e2626a1450e58be474e351643627b04ee08ce8fae6495a533b87e85 +F ext/intck/test_intck.c d63f1707432802f5db125ee40b794923af77d4686869bd8d3a7eb43332344267 F ext/jni/GNUmakefile 59eb05f2a363bdfac8d15d66bed624bfe1ff289229184f3861b95f98a19cf4b2 F ext/jni/README.md d899789a9082a07b99bf30b1bbb6204ae57c060efcaa634536fa669323918f42 F ext/jni/jar-dist.make 030aaa4ae71dd86e4ec5e7c1e6cd86f9dfa47c4592c070d2e35157e42498e1fa @@ -2170,8 +2171,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P cfd051836b72f7d4e38cc9614f6ae5c003de4ce377359fd391adf06fe1ddf6b9 -R aa9167c841a6524a2987fc0088c3a9be +P 351d46b2373f08bc8033d0902d9f67cd6c8bcc16c0d9f787e4fb279c0a76da87 +R 38b420c887519ac9a48b5a886e5c9758 U dan -Z 2a1b98d11090580141aae0cbd3e3021e +Z 449a9c9353165606d5987b5f74af35a1 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index c043830657..af08de7704 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -351d46b2373f08bc8033d0902d9f67cd6c8bcc16c0d9f787e4fb279c0a76da87 \ No newline at end of file +c253e276b29de28a18270d01b60d95157ce3fc4b37e246d991f9119d26e718d7 \ No newline at end of file From 7598e7d70e30d963b172ef5902e2e51cf161fef5 Mon Sep 17 00:00:00 2001 From: drh <> Date: Sat, 24 Feb 2024 19:58:15 +0000 Subject: [PATCH 142/430] Add two GIFs that contain the feather logo. FossilOrigin-Name: 5f21e6a8ee709d8c5ec12c45e8dc702a7d0bb041f31b5715e28cd904dfd566b0 --- art/icon-243x273.gif | Bin 0 -> 24689 bytes art/icon-80x90.gif | Bin 0 -> 3392 bytes manifest | 14 ++++++++------ manifest.uuid | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) create mode 100644 art/icon-243x273.gif create mode 100644 art/icon-80x90.gif diff --git a/art/icon-243x273.gif b/art/icon-243x273.gif new file mode 100644 index 0000000000000000000000000000000000000000..e1cdfd0b5142092b56108852d86776a7da5366ee GIT binary patch literal 24689 zcmZ@;^;gu-*MD!pvP&%8uyo792XP5?=|;LyT2fIEDP z5CjBK;qm(iJagv9nKLuz&YgM1)zDJM%GncV8z>2K;XDX4>P zngF+~5Q>I~>stIb)j_xH$yM~2Rdm5Brj#lsU^N?rnl)JKE~T~&xt1xtstKE_37wi1 zy^alst~HC6Da6Q{&B#VT$3n=^T3pKjtnPqNa|CHQAatD|YVIH%cci`>Le-s4&w)kH z32Nv>Y2*ww^gtSW&{%mfnz#abkD*#mz(ziRNf6xPDWlaB5px$A>-$2cZnDmgSsk9L zyFb-`=CYuI9}f@VZUVQC$DYdI`?D(W!$Q6%xdMUtB7p_hpXKWMhnWS0>x3jZ zKaT)C?*cs^pm^2^JRgG*S`ndb@X%U@&}P=KdWNtHf#`@YIAhbg9)ENKLhG(!LS6Wg0l z9BD(K@NrP=IC<<8<*U!IS6>*C$5~UyIo?h%zn!Ivo#apG;ZNunebp=Wx}QH~fG=ZG zEOSaIV^%tQS|MjjCTB)IdmfuUs6d>)`EK?)aZd8xvRv+(bk3@JR=-N_v`X%*PQjdh z@q*6#NyEYg)8ZxTvL(}^NwcEQP9J96s^_0H&byZmY80-Tm9E&7uNW4t*i>)ass8Ht zVZ*6%&9ipHy>aJJ{l=5VuK_Jvfvr2fO}qZ>hru0N&pUVg`%i<%{|3!n`AuGV_MA9% zokW(@zNu@CEvZU;SCH1&^P+7kvVA6|zAv}6KfH4`yyHuH?|5PFP|@I2-PBywr!R!w zZ{Y(6QG?$ihmT@Mjzas6Vm}{;PyUIX_#HWU_G_++WuMabufL{UMDL6DMh#fEB^rANX z74NztQGD8&nw7adu`K_&FZ5UD^}R%^#BgX;-Ry7!j;g=|9pU6)sH=thi})J6(m7JDCJELoy!)z$LIKBEDV;M}&@R zF@s%s_h29-+2k1DO~2wR9M`+Bd<_Guo%d;?QekwjMWqU< z#XQlwWT-TQ&S+l$bDoE^*fTx~wC~l=bqaOaLOZe<%ME?GVoIeR1{Z_XFnZlIo}S8n z!P32|J|iVq)o4n`UZuXS$A0aMwxLAzeb=A}dMC|F)mnY=cl#AxDXXgWQ?DuynkGX_ z%bUJyAMH0Uzj`Fu@O}5&L4{M;d^f9}Op-cEdV!3M0ut!55=iyiV(l*aL%sDwc!kPm zxiXoKZZ5k89%;_IimNbAA3Ugcz!#q+Jt&exNyd3+*sz)z`@*n#Krm1In8RWCbJY;0 zUXgt4zt?*|hLz|gWH=?n;;TRVMuBRFZu}0eVRnGp_D$P`aQcqn+Jj|gm3(f>PHWWL z*3El$1=r1o%_v54Ig5V|L*e?bh_m;pA=Ka%s?tL6>aB!^X($5&3kd9~+pSBdY5-DW zxT8w=#bPia)w`7wbRf5#|MX@reU8ebi(P}LO8K37Mi~SoHetP{I(E`tppPe z)#ZW83AahBqQY-X5FS~f!Vq-@tMks zQi;q$T*-$Yxaw`M`IvH0`o2^fiUsu`z&scnY_|(#2JN7c- zTy1%xbEz#Sa(2+qkv-)!!ddFubaT^Gb*ljc*=b^W3Yz?{B=DX%h4xs;MG>@88UzR9 z@U>U`svK&hP}W>;@}+`P=J~@2@AAs{H3T#J5-H+QEA7IXym{lN_zynu-)uI`p0bbC z9{3gpS?(;8)9T`@GsQ1lC^xEUNB%-xdFyP~clKhb3y7hf74tbX6GZ;X&@I{R$S3 z!UQd-DT7>lFuPXE7hr7bWw;c6tNGq(-AwQCoA1H%8B|}_{F^TqCF3J0*S${8T49?X zUpZ%P{9a?`z+94HUy0wlWWx^Lxm)$BG>OW);T;+J+$fD(5VW01tC~abPPM_{nZs7D zG*I3I3UR(r+TcxZ0bW9q2|%Fvj^_D_QKom%jL?PWvCkw*V{I1h2{S+aEcyH>@2$i{c0H=&}si87gKH;z4Qo*2y z=ob|bqzTZ)94LmgWBJ84MXGP5Xgl_IoZHeNlYcJR>T_DhzWv?wfE2K>PEh!}4cwJ) zdQW|7$Zo-?jm4$ei>*!|l2wYcW-2|rLxFyKDnTqBvb)E_m?j7HrU6~tdO-lStfE&~ zz$|1(;Yxc-EK7$yxgi~Qb-Mg_Oj6~2sY2XK>N9q~VE;^f-9HbT585gCpeQT*(zaWH zvvF%Nc%8m2;9);YV-AgXAm5d5@p?LGP7?z!$zr9&5@DSY6&{B36_81sBv0ZCj=Q8( zi`m9CV)X9}C5$NO5I1iI*s*kyDD1se7MIRl9xFWz_^Q5i2)Xm%YP_;zX*4qDD0`Ib z+rXW`J%{OW?S~;7ACoRV&0k&WeQ(*$x_tf{d4BmjGUV)jAYg&ls}G3!;u{r#pRuEw zBT}tzlHEp$eUidfoSGcb`vobP7BPamBcWe`U_Jxzh}oktS`ZHkB)H~BJqB=jqaNGA zCT_s(ag<#vRLkB}9;e6w=Ky4sZ9(e2?0Tv%IQ->P{4Mq8<>rAf*XKI*c+G|YHF!9x zKO`nHif|ALj8$rqC|{B2 z(F+%54PL7gW;i2=3?Sda1!Fszi>J7}g}nZlFtHH<@~cNM6FX`D2}3H2z%OI?FQ@<% zoY3G$MFS^jVjpB^gzTEfKr}-Lg)ep^sHRttU_bY_Y0T>HZw91mq2HlaX&5K<$~t?o9DPb3?NY!J;bw%NQ^#i#o7_I(y3m*^!YFZ78r0yU%0h zR-)$sYVrWQeUwLke@y#KSXr7)D?Bhm*lxKmFyB0;>O90S$|LnWq|G9Re%5h}B^GKK zcRn4PFC5F=7@}AB{E|6BEA?*p4ZEpCn9vmf%Bxg^b`q#nr07U4-Q=J)br1tS!3LK= zeyF`)q{c(1&POzWqNrhysMT>W*=llEfU-k4aGLZA7Vrw}5?6qYGqQ;3p9z@ni>Opo(S zMRes;F!>>?qO|9I1}O%WWCR_z@ED`#3ia>`Kw}4F9hsP#vLDQFV2xh>QbBEDpue%? zPGj(P@96kwpSS(duz`#~x5PBfkU4xtOIoxMOB}srU|U6|ys#bRuZ-4#*e6N73fwf|Ue9}3Veh8^IkIq)FR7?|~OI-!e|PM!Bi*!tAf8e&haZbue?A$MGXx33@@ z2D0w`N~LU!&i2n9)(ly+jIP|KvZcU3Xv`dD%w5>Y+?C5q*Ua0TjmwV8^ZOHp3lC^G@IE9X%F`%MMMOqe`DhvcgRmWRim%5GtuqZ$z5wdkiEr$V7 zuRPLW6+_i=RsP^%+UB9gfvCnF)4Ri}e?j9(Z+@C5R$_B$u(?|US(9@4s@ky~X)*HK zDdkvi`{LB+(Ya|?McMw^`Fp<#L+0W(8w)eB54MV*W6$2iYv&~eqz++=r|hVfSMrdQ;8G)i7j|a;i{z@6zDewP^B(p3R zjx9X8a?4L{syY$P8kfrz3QByPUbrV;qT`-7OGM7pBIfb&Lf+sY9+q@RdFdBe%RIRbeKK083uOGj@d_$CoVnDTDY@4m5!@A!ft-kKm$zvX&1}0S-gf&>*X|djrVYeb zR?0QyE$EGv50lGD!($H&3X5hqP)c?+BSopyHP{0ZhX5O?1#C}kf$o%b%$Or0mH%{k z*>q1~x<*!7i&-c~3>swrbPf^gy%+kPw={_DAxFHs%6@lw%_5iZP@$^|R{9C6BR(C_ z^_Kzwnt=$SNQ6K@

    %cs;vAR!eVq7mii7mJ|csO7HSO-yQb2~*7WX&R(D%P-vqKh z;alG{ic)hpQ(CNlX+B1^rSoA~SNL#!`(EFK*if%xYtvyD#~^~;^*-vjpS7>YUI@aq z1u&98FmK2#85Pukp~^If{&(r&dXMNBhkPi&wnFXsthC({LlYzwCF_Q=6{;6uXY1kpZz|Q~1&9#QG*o|InY#|H?W`SH{GKN2f5z?4iD& z9DQ6_!#e3mFD*z7xc3`Rf=!u~seqTz*rOE?(7}V^N(8rD^(JftPkdkRX_psZB!bA4 zsCoXt2nL-kL@Kp%BI8v2~P7q7C+Js%;E;Jq{Vvf<$I@$(2!2 z-E3_%=wDM9)@-3{BXzNSY8u+39J2XbivJuqKgr73CmYx8Uyf8A9&JT^rr96;Gdw!9 zLq-nNj>Q#R`4+t0;XnZpK@>==s`6}%i~V`fA&#|?{{770f@ofvUMs5C0j9((7sbK!y~#zY;q4XkLM?O1ztMV}Id}Bt zW9G-GY!|n_H8vbpK|js&{cg-bu6_+_d%EAicrAzFT5Hp%g`q#w!+)!Wh@W%BRs)+U zB@Y@~Znhm+uE&b4H4v$8w)HVSgFdmiUorSv0M*P>#m+|r=N&OiQ~aCpSt)LI{&8_pnRO^!2qu%;$GD~Azmy=W@QzO^f7XFS7HSXsK z&!=45!!PVv?jwVrtvcE+e$H-dNThn(hL8t9t24}z)we>Dz7imx>K|dr55W}PW#CF` zP7FX#V*cP>dA`*1G5gWIyDz0~uIPA^-!tfJA|gvZA)6|YG6#({dh=C#N00UQeux|} zF0D82QT|u95E9?*`KQswYscZr_Q$IS(+*zKQrB`CDz+Byera7f*33libM3!AIND-A z2}+n8qh7t9{dv3e^UaZ|h6;pb#cMX%_lj>t5p%ny-&pS(^?+$Mt||s%KAU0w-rOF^!+S& z@x1+D{gd~RzT|PWL~D)SnqhnIcEZ6>@KNK+S%%~)o8G}I>Qx7cU(BPwq^|ABwD;Li ztxt`uGwxG9#z8Z%tK2z} zM$L6NV`-Y1B=EFN(akA#`h)Ggr>0%+CEj*~a?_5?omb4Mha>4nl;?*IN=#cx`W&tX z*0W)Ah>^f%+BNHN>Qq{N-LpMhXe0lf6mjn#%XOagWR#xy3T6PWtA}*+4m=1+gyeVq09ERv9 z-DQaE86Zj;usthh@|&(o2>HAl7~62NR{M~fj;Rcp`r&TC{y~oB>~jqOIau^=gzbkX zPaR4*R+@}`72?G}*!`MkN373%&Oc zUVom*k{J;+45E%zf-*+T;hUJVN=NGGGII~QX)APG6tadZm1E@gqH@LVBG#O%etWwK z;(lL#d)(H}YxDiq&y+{oE$$EAd8Q6Di5IcnK=Qu6IS&5MRsSb8<7gt6ApuhL5<*rB@&|EK-j{o*Z9Uw z@tf}QDY(Q_O$wYh8VpX`7=a77r8#O_|GYpjhi>e-ww|sj(~!i!PllJ*dpCxUBEKu9 z=-gmE_LOoWcPtzI{im9S_wiT96s7)tus7>18WScyxFtm{6cVbsTW2L^YgoW^s}+xT zC`l&+F&JRcH+IcF`Sviny?)Z9s}r>n%I@15$-zfVeymvGS9zyOPQ}m9MtMlSZs@h# zI=$g_A0D%+)(=z_mU7qAE81S~TNm9_sSJ~=9vP$8OtpTG6o+4ziPwDQi<$R&vFSuGQr@Ca)Ui8)YBkqt5iR>Bu_;x6&d!HDj22~K zWFGhayfZ=Q$F&RBytk+05Br)W^&UeCC47B8b8A@sZudIinzLjQ(6J3=nDSw*Na+br zO^qkB^m$pgSm!kGBnpWv>Hx5>EH`3B#fyo#Ej-G`8a}fcgohS;I>2vS49`JHt zyyB;b>j&`_0Se*~QbM{f#p-~u)21_J7H|~bp;o_ygTG2&M`;k7*6Y6<8fmWkoe_&Z zJk{qiMe&*mmf6<5G)&&1FdU%yL7uk2s;ZcKF#%*kn=oVKAe-W9aHH6W_}g^3~(RHkvj{B4rR^-szBOk)J=r91`4G?jlc z^bnp*CXf03wgg%F=TfVhcjI%y8ig08QS!cw<^tQe0mK(;z=XNpphq;ACo)-F4W{;% zx_j43tVKBvB<~-MBqI@MbR8AsqJW#>gG%eBUh+m8NeB}FOo>{#@~Ce?+}_7Uh8%#2 z9q!wfl~x9$x!2#BQ|-Hcb~g)4VXC2EbdWGXj$2vC)J+L@g51I2J|?x-G^HMU$!82? z4LC44ssqA?kK5ZFO3<+ann;?;A6Gq_4<{Do6`=ep(EhY~4JM9;>0T364$N3|UTw!LlxN^qx*}%ox$(LMa zt2g@rNUPKI zf}BjZ{aXnx9!b;e%PL}WV-VBuSlBbyi(7%8^94@w97`R`5o~Qowl&XLz1&n^)=yMA zmnIljB4bNJ85=>`td0odR2Nob`Un7mAVutVL&%AtwlNC}O0w%y0@vKjp0L~L-?&RC z*0+Vm+9JnvUd)Y0q{!wg>FvAUx1OKFL2J0@&1J~#y?U5kDNxGt82a7u9{xk2uuMIveiD3Yg$-uP={woH z$?eB!e3Ow+4@Tt#5GPF-`ZNV$C_9E!3d0-@!D^78mR{ZIT&kA3M<4)d(pBI<2V1>Bm zHjY#)iD$NppR`O>cU(YjL%TaChm_S+yTvD!r>s?PAGcT+bx*M?Yl^E@yy%4LiYW&x ztG6gY`Bkrilue_;lO97*-XKUC#xn4_eUON4@*AWk9zK_FEea38fK0T|qI1k*>6{Pg z2rvwRJ`GP^l-AcJARZN}cn-$6)^Y2SaMr3<$G64z+BG+Bt3vzqpc>va-D=6I8kylH z=sumA4)x4#EzfRk-P-|_eJUsIy1E+T`K{dkw-y`N;K3q(vCYAaBw#F*Za&%#jc35( z+2Hu?#{xP8&Z`;AXckxXKxCSmOr#hdeCRK)v!M~Bd-KGn{fUXzW6$p3nvRIq8nw;x zL19X!-dZe9v2T*K{;iZbsbz}m4$4%0Vxo~btZeEHp^u`rPQJbrlxFebhW$`8B9TmR z77WILP-yiXJm;oDSzZ*OJQ(0`?SH`+iQ|Au`Zwui-ewiouA5N}P}KGhQ=0bCN~i1# zU>JOQqNUN@$9kgUE3To_JrG!Tbw3^$ru5yethUt>_KCNtgvRwI;$#3{{@6+;z zL5{CRCUnFkN`E&$d^^mL@fpklI@0Z%+>;4IT!&el7@GQrTNyxTz46<2TuY_tQtmOA zVHh%uJh?vs>i?;PC6XGQ)?gpa{i}XknjKTZxPxOKQ3XL~6lV6Q$xp%RM1w2D6Ag=C zL)KbDixz#Z+Oe-3`YR`$6r9E87+7C0jQx5zy4Dc+Nx#2E-y&G;_P#z>JPciKz|pG3 zeL7*T3FEHSFVcZ23YaYX89`8uo9l)%?~n9!>#3fOt*VBzVG$dy1Rne9%S>uUIG$<- z50C&3(rDHSXe|o3&Yn#rjo6{1vwBPViUVFM8jBM{F%1y-8<<>{fw6a=d4;|WW*WBUI5qQczI|?t<_7O49tuo8E&D>dZ!Bpt zt^LfHyWGSpYmDlB_$_CXZ)IO7Zo)JqMrG3C-_V1YP+$D3;!%lju66=rC^Yd-i_zXF zJmSz)Y)!YqWV}0&Jr%Fcjv4CfVwr7uQ5b55coMD+oAjNU^wl#@ubs`PHPLCce6&CD zebNNCKankAMclW{DWCSuf@PY{WxSuw`ega&boN{KY#)bJmZ_C`ILyOz#u#p4lE$2Z zp-p2ikyngCvh`cj;@P9f1y>2=uGBfA+2a4~bbF%rV6x6T0EmLjEKmp~=`lJ&&7)xE z!r=(mT)yo>zVlqZnpJQ7Lb|EVK-L#yEUd45q5nyEdb~{$r`4dE)rTyYg)pp6IQ)kU z%mig}Lzuv15KW6h^onM8mljeh^CgRc5dL^5mQ0X>{0bo9HxqMFRn&`f`7k=;H$|Lt z&Ui9|**CS|*~w~+M3}KR%repPQ@o9Zh0WmNQbty|QPjc_?B4O;kt2zFqp-Q}J(j^= ztt|Y*jkcG3)nJC#!Nx`zFUojRQF&6za&R07JOipHa&y@I3tU zSF4FyLqmf_lfy84cX^%Ve_c4%e||SHb_hiXziO!DZV@uy)CQO&Jaw)3^ z60nI@d*Z1hmdtj7aoJsOnf=!Ke+LtCDV9twPPnh@CRj)FG}v1;n1&k6#Nfqr{B`d^ z=5Tv)vlzVe6yx7uypZXeh8K5eq+4d>VkmR*ROlt0M|eah@cy^8jdp`4<+{wlim&Oi zhW^}jeMh$JFF({a%+nkdn9N7?HZ#83+-ke)%w@$SxM+DkH_m8(E5U{JuG8B^mm|Fm zZ!W7Ny}AD`ziM0y*F121XlCn0Wi4%FB$8k~S0MuKcgS)jV@KgB@IXm%R)a{{$K>}C zPokr!5abv@#MHrN$>Cu9Ka4ueaK-WJ?$YKjiA67c$M}TJqaN2=OsidQ?m3OD%PhGV zt!!SuweU^C&3I{TT*EB(xG1e`qVB_KQaARC}zT$iI&&HCs zz?E$@T=O4#kLE1G|6?RDt`grLgPYCPn|5XCq4CUVcpwdM>vql}u^b>?>?XmYQ^KP! ztOzqXufoAxCS%A?ig2ikP=*ydOcKry0$ER)6{oyK3FnG@A6?; zcId|56wQ>>QA4)@cRM=wG5kwY0dQ7=ZwWP-GP*`CkG6`MRYa(2iK0gLosvHo!vvd+ zfPH9PIOuU@+jKO-+T7aQzw(mZJ3n<UGAsoug}XKtZ^L>3%ruZ zCePn2zpLHOKG)zZq^ta$>_|+)ybaIvUNKCsDHDkxLY^{s3hZ-guy& zPbzO>`1{gOGaLobuzZ_(u&)4zN@5^}4K{|v{h=oh8n`@{4!-^R>#CaV^y_qUJK}(H z>tM+*d@FmoHT!V$=OHEcgES_$IQ^s81dr{_{p{yQo)O`OM3{*tgf5Y=36YicK%CrV z%pBa44JH8o_)GrYnm6xrjS&CIqf<2J-v;4Bv;ZeQ4+f)mH&NjR+a40P!`lkHByPJ| zoIjQlf=S+XlQw^FMR8+i@you{9UshnA8Br%w#y$&`p3UuK8%I?(vm(Bkv>uywzsY= zj^A|i*KZs*Y0KB-N(sUvqP_=3MatR%5d0_{t&Y;X!GDFO?qXiB%Vtpmkf=k@L-2G$ zs2F#+IL-0U*B`ReKa_Hg&1jA#X^s_M9-EQ-{Fmcn(f;J_mWR@`SC^U3-9n%L&bEyY z!;FPNtOg?Ys+qmz2^+L)wa`>N+%E5g*a&}Fj4S{}sM$uin8`AP?;6vMYlHYJ~ zbW$@f{2zw<(}WMHJt<5LtbZ9;{QZ2aJ#a$u?}X&DG4sC_cb-kXd{%xHIQ22G^65o2 z&AAck?^P3xkIB6Y89XStv}d+;SVt)-*Mb1S0UGU*4lMYSOM7UbfQ3(VmU-bU@jaq~ zFi37AhK3AJ2O9z~L)UPF{@-7?VFuW%h0(ydvvUJsSfj?X+0^|nsega>g?t&kIwp@Y z0F%>+W3|yDgj{6_&mwPoVS@^?1ZiieDg`adOcMoCR@I>8QhUX}Lkf?gU?vM|-umIJ z$PVHS=4X}WA9%^5q=^TN`1L6m_)!uRt37xJ$y8~tx#R^#A)h@(Dafw77$L8YDR}11 zDybC8^IX6mGbwBUo}x1;{fX|r<2+Bz@FcMu*NCVc+1Gi*Aj&2nU4q9bJAHZ;6LRHl zlhpBI!T}<9zL$0`xITnS`&4_hXjNg7f=#HxX zIMU1c`9o1X*^`j*j39}*jfeMXCau{6Eau$8L*}0S!7i;dsW`*bv=7YgVC*PeXn~^p z@kF&`Z`2wHd;O1L(=TeFBd2afd1qLy9Rs1P}WG6;hEzvo#k82nEFM? zTFZPPjA&<(8NqV5XZ699?RD+&A%X>Gw1Bn+r$3$k^lB83(adU?xLKM*42KIWTd2r_ zM@5~tXa(miS02ft&Ihe{Vf>l$P+9NS(S3S@%Tx1Y4IUdD;6@hsmW{!$?RTbPXD+g8;-iyQX?`tU*Zja5=t2=D`TmI zKvj(GI4B*->^h(tR&e&3&LpQ&vh@E{S$!szJOooLIw?L-^M3Pul;#O9ugu{u;}Pgp zE-i?lxPct(8fA;I&!7?dGtf0C`i&=|gNfWLviDkWkuXh()J!cW=i95-hU6`1l9ayJ z5ec-}S@yXIjho9!RB2jlCz;HTTzQzx(-co_}w=g;I*k}}bW_OdagxgRIQgnZ=oV~n^x25< zJ77Og^yREUNS#s6Rle&vOW>ep4VXUlP?gPs6#6H4GvoIvYv50M(4>R_D+R6t#6g4r z-abgN*%3S762lG+I8!ueIp;N zMB{7VE|7UK`RqaM2h*=&W{tajEuBA0?G{DdAC;Qk4y~aNpD_O#B;OU(SK zhxz+8pX`kOEe#J;zIO^kjOrs2;$J;1hi-z%KtF&8lpe``e4u^pH9$vYT|z~Pe@}Eq z7-o5!Oo*D+W+bYb@=4h==&yZzep+tsr8U(qT1%>ngAzJ+rvUPqdh&zsAwkWPtrw;Z zI;Mx7mGU-!tt?1?I6vIGzG`CHWKT9B5Pen5UqQGe#eymQL10m0a)IYNFbxr>r*Frd znLBj*%8)RGu5d`i0{^Oa$AYq6vE>C4+Td;9jZf#7m$ZL%QXhCdrwX<+@l>1P5NUDI_ow&f8HH`eHWNJ``84?t1K#;|TQ$hU!!}C4b z95r{798eZkfJ7iGa~#*FjbtQV*+ssOx2I2P_{i_z_09MxE8X7nv*J&GA83%+muf%U zXgecGqg7PUSD~( z^c=yok+CBrX&Prl2I1hhS_C(qsr327AMc&9=eM*@Ab z;`s8k4n(etTm9^W+)QWynyUnwzH{~Jqe2JuJraa7ec5ALEa!aa z>NY?|1gO!V%jE@IFe-CMpFqmX?+%gq437gKia5xmu5m>N1U2A-*Wa}3eeS6rsFtb8 z5CLt#L!meX5vS9?Y=pP|TfW3ey30FE3&F^lG1vD=>|?!ULC9_RX3O}Ttzhoa`$ z|4T$6-qBpx(Q#ezpxAh5*H-4fqInfN`LLnUUK3jOBRpQ}d3Fg93=V?fFfLPp*a0vD z(w3M0jknW~Io10pJ#aS&8JNY`g1(dj^O5dSfjjy3&~#ipjMThn-c>Xi5APokJuesy z=jAct;g#p*q=Rrf}01-$Mkp3DQit-7hsIcLuhro^(c%+tR@slUb(>Oh^aCM>x-PqkzQN{j-F^Lr6(8D(m!GIaPZ^ODj??gt8TID+?LR$8<_HE%EsCVy*bp zUGmkH*JW<4^SC++JkG=NhH|@ZXaw@f8LbM-^2&=QsAEZ5JC<nqvl;+0LsF1Y zlX1lt;7D|{8x-5D>|AtBd*uJkhCxYAFa{iruoJQ*Vwb9uLpYSLA)A-KlLynOZnYts zy@8I%y^*k?nY&?rmv7&mPtecN(ji|nRDdzT@xPJ{z6&0<%nmynYljv`E&H%hG>mhc z1%e@w;Q$Jbf&}~dAv+2q<;>ATRzm|4loC(w%Wl%tJ*`C8oh1~AD4UI-Z6dA&gc4kA zA_}y}xon>2*{H8uQRiaY3atI|EX~%1ukmVFt?>~FV{ZV2E`D@@CU66K2W$3JLQTPy zWM>5AQaHo$s*}$U!`+U#?~C*|||yg(;+Fn_?SEsKP&{wZ4? zodtpELIDN$gHpBv+U^HceGN=kG3pIPtvx(hk8F zTUsNo!Bt-^>V$$Xm7ez&#kV=fhdRfR74vX}@_0IiG;LEd?eHaE@e#)Hc2PK}E-o~p zdo2^kxWfPgaR15lC~S}*nmhlnxuIu~y@0br8lEDI1Qy4oJB%2Sksx+>U;%h#f8WoD zu=}ZlUdEA^p_3AF@}K@q6yso_j4i&{hx0n>Wc>4`qw>bxH|KwMQeE71E`C+u^u&d#gZbv z6=qteHv=WUmNg1XZ?!KKoZBP=!Xf9st2u8!SbTl$)f^<{6X?sA)q+t^r422U{hA6^4Oxn<~ulW7xz&tFS)uG}^g2lCLqWv*@ z16Cdb>EgK&o%nqv8TXj@@}<|>xcG|t zgXIem^a&y1lJIVX$oq%Dm`$Jrt~yXe5F1>H0_zn+AW?7#!c|`-O5sYR!(|i)01h$( zQR54YdY*1-j3JJNcY$n$#ICCH=!2KZ+79!f66c23zfDwuKkx`EuZ4=QXN#Yxe>}bQ zaK-B3>0QY)7s-CJ?|teIc~3f;FFTe3%Xs!W_|gcdei9|1M4wOCO2KvIPDjZKK@;s* z0y&Hqbm1)OdYQ-|#m`tCiXx``@J$>CCEHO-@3fv0moBUdti1V?z`e2m)9)eKQ^|fh zH=efhjpV^qR=X=dohcNn`KEY64Ae1kYKvO{?P@i0UhJC9Fcja>pQY}RzbHOEpM9QdeAK(7{2*-Y` z!tJBPEYr_bh3xtv^}U085`$7bvg;=?n&?Dd%tksSZ0GYpEcSKERQ?H90`c^6Fg&CN zx2^{uC<~Odg%uUl6bw{oYE%@>tyIWDIr%@T|1L%|`~JH=DqD|vWKNW>j+Mk@ROnA| z3Qr^@WiT|p#t)yUIG(Cr`Iw|i@hty`{07>R1yLQc=IlG7FkaEOK0hzR!?6IHAI_=& zj_z?B5>G-H3_@FQKv6YGK3twfg3N4pHChW9YsCbHZ%7&FNeGkRYapDS7A zpfcl^r^a_`TweaXfBV!F>C5w{nmhTC$7@NR?GCQE13N=NBdms&MQMogEj`~NT=x8LD?cvB#I1qp%_r-%LA3{=JxQoYUx5;vERC8}DaXHnI zXZWdk)bgHyxMgb0@?=%&pIS8Euo$ZE>-2lpSLx9%+y9ebl|i6!3WG2dz%hd~MID6Q zw>iK3SiZRFh)L;g=0Ycd1{p5E8=o)HgC&93eQ{)HA+QaAXaPXMKxy~!%@%EyIVCaU zI_G=d+%@%PuOD(v-tatD3LLG%oq@PEK!NS&fgf+gcggvG&GafxW@uHlhZdLkMUeK&fiUv?RZxEC?Ke5G0}KEv$N5W#KnZM4 zXF$LKxIr~I!y24`0iZxYj=WGrW&m(R0Jwm}Tl&f9!c zTXw#ivChMLzUTYA=lqYy^3YedzPEe7zdO-0I?fM#83V!@RG$otKc(?Nb zxZAvXH+{VmzTpqP;eYp$FTKv!eBwVo(wn<$o58E|Fi5bYWgM*fjQ;=y>;QJ(!wp=( zl`alQlt2sAKoC$|5}5#^jlKB+1$Id$15|*Sv%EPp0X+};9K`(0XFBBne&R2F)8hf~ z7ysiAzPXP9AS}YvJM9O?B;#?$I7uMhH@6bowN4?%2&@2<{N@21KnR$C1XLVQG#(1X z>5;MgpR2}HsCXXafgp7IAPmCe6Tk68ejVJuW!u000|Xy|eCiAon5U1QF=Q5*5h82KYBimGPP(p$T2@*<-s0aZUB$kjE zf&qpGZ$=h1dK76=rAtMcGcx6i9XoUM@DWs~&>*XP@Zb^H)&C$@u3p7{9azwy*MeTj z5)`<0AltWY4Z`i(Hf`CjZPA7uNC;2DGGwZlL9+yiPl*y-j@Zapr3erX9^62BgM)#I ziWg(t8RF)F5j9q3yeILxl6;247bW-j534(LI^a>Xaa`*I2$1Z5Xk!}f()2B>i>-g99TgjnBwDUB?m6j$RZOY z&<{1qDoTNYV+@>fN^z`k0*^27z^$r61Q7(eyTbepLowZA&O)$?BXch?)pCxwGRN90 zPP^3V>pDU7ND+t`d{|R5pj^Gg zV^1l3m|+GW&_Dw`7BEuDM*S8AfwiN;>3{(h;uFEW$R>gbQ;tCBh)4%on81J=+94I* z*T})*)GzX=BM&|Bz)Fw_hm{l9Ib#+0I$D1XR{vM&1S+^hw!l=*#JCFj601P;_-+Om z{A3~xBMR-Wq7lZkw4w*%;L%6-T8J;D8z&NZr;J=;%mD~q2tWg4;@w#(a;%VIkS_wM zW7RLe#KSi*$6UJCFym6QE2U$Fnrbtx{f(iyS>IMcVP=V3|c)Caev{JZ#mRd#rm6y=jBHAD{g4w>LVE zGR|m$vHoK4;fgC*XCYAt+Rg|y2}CvO7y>BRASER@KnVC&z>1(oG!mG=05~wW=poKj zL9@dh^ng7<1Og9txC;iO#<>n2?Q$IS;IE_x!V!wFD;NZm3NI%nrJ=Bc2V0?->|m=w zL}(CrAj1%3AcB*WfCR5QgAe)>xZ1f)0y{Da4+t=Um6RX^Q5+t)#5FF9pypf@@IWyh z7(H>&t9nGMLm;k#LF|Rlg)qb*3TNo13%0O?E*v4|#Kgi8#t;uIoFN@ID2N*lB7H(& z!3Yd6DH6zl21-bqMjT_iy-^?}MgOTs0V;4K5~KhDmm=Ooj0b__QGfwF=wkF}Lj|GD zVGeY#U?3)FhptHFm3VOFEO8}ESIUxxxXh*IwpKpvaqpG~3+6AyfITmzFENx^2@47p zgds?P1=kAF1SpV!qa=d>Iiq>Xx6hJnCcnJTmCbb_N-|?uNP2V z5)_y=)!a?pL`zuGGnm&C!~enraR)OHQGxJ5jS6U>0~&k_i#D3T19WDT4j^D98(2(E zGD3pA1!4qPo(83*PzAbIT-wu@ZkhuwYx+yW=CYr= zv?VUbFp!0o!3QMx9eJe1OdZ%~GZtYR1|m5UY9t^9E19SWA`k(dkU*0`f&d9<^nd}Z z0j|(1xT}Xm?1eD+?RXSo#y6V!B@Wg6W&g4fmcrt>sa5nbhIJa}Pd%!MQ9Y zE!5NitHzr^0BoSUqO<`47Z{HS#A;dsUdlb;lFtYzAb=aNBerpcDP8UQrNR2Oxyk)& z4e`m`-~Q65_B5z(@c%nLsmv0mH{Iu#>M#W%Om`yI^+^lFRZ))!0Je1N0F%PC5+?CY z1(xav1PtJTXv9~(P+_Mk$#}t@7PY@Py$f%Ty1iNMGq12buy69f%HR4|m_N?%D-nF- z+kPn!cc8-(h`1TlC}ssB!xViUU;!nLL>&akfCGqEnzLRCCL$|j3b=^k!_j66bDc_E zt@EV`?w6i3w(*Sr`&Swob)LU9ZXOV9OC8g)xBN|TbLXtR^W}>UXGjcZ-X;PAxWG~+ zfItf(@Bj@sP$bDn00x|R){!k{A}WZc0v|xmjGB38^Ewq6?vP3iwmFu@z3EAXACUI&uL5h_Wd0utB(Y!jfyJBq9>18QvU#0S0W` z9qm3d7O1DCIk5SzHB9VsrQ%b24^`QEMw%=cbYP$7hLx`LG0%(b^MKw`g9kP?9&$L9 z!6KKSWGKTDK4qhc--t*k2mmsS5)A@ifCA;(n`kYff)+$X1p&~302ok!uBv=zR&v4@ zT>jh(9{-%qyq$+z)3eFt|LSc?<+A^PN*2 z+gaf?XYQ?yUC%jq;l6~o!yt;BK|b$%_=K0`f)eiM0|Qc)Kvk;4eINr6m;fd=8t+65 zaDfKAt0+6Lo3~C&q;g}#0R}kN1Q^f&0GN~ZJo};);B7rRcy0mKiTH*i@0RKi} z9se`{117~H%*vZY4u4AE1wtSID&PjzKpygsXXd5lTCJF*A^?Z$0D-UZa?Aj8%#|Le z<`OFpw1W9&=??13_!cYars6hw?s|SNua>RV7Gx0a;MZF14tNih9;YD4z~NX&1Sr5G zMkXcfgEG*gD2$s*nzhZTBLtx$x`=kB;Af zPwAX)3nOoPbW0Pzpbp3om8vk=tgpxfPq%PoL2TvKGN_dbun)w549tLaG@>+a#86n^ z0V<%(NWy<8;84cKtcC{yazg7O01n&%9tyGce&+V-VBVyn5ns(2?H~~3%^7XU*#D-& z&UEd*7|-W)&H7Nu0S7A&PVrvw<@sJI*cOE8S`8ePO)8>LdoT!=2+H5Kgb>8w45$uM zEafy*!UY(B0o1{(5Fi3xzyVyM1nB1gN+1S8-~ucz0eB$vkP(9DB@m+G3l>rLCMfw1 zOdi)L=zgyw@oez6L6m`Fy$BjhXFLe+wOrKI)DH!00kZ@B1(Wh7Qh4$fB zrO_E#Y4@bDBQH=be-GH2@Th!a3?C;Aoo_Cy5c!g?3cI4!reX|rOAD3m8~-tJE@esH zcE}CI1+^q?13)PUjDi`oj6Faua7y3=qG$jJpbI)nD-XwKr~uyTAS3^8_wWELLsA-p zE+m6a*MRK#9EFEIb|<$8)4XEP6y4iqi%4w&yHd(P)j3FrjxE>TGg9B~dDE-@|z z1W=2-Kq0w&<0Fk&VQAOJi72bclnWwST=lkT2i4vJF@?otcK;0%OdTE0ml*ed{_ z!6-bS0;baeq-6nUAOsvB1qfgV#=$!uXnN@G4!)8OPIG8{lY>mN8~+tAC$X{FI?~@B z5F261K0h&o=3qhU3MOqOKAn#4d^7Um6P3Jx?iR!e|FburfDDM>VKH)Pbfz&sb?>=?(_=wa- zI}t~XbSjKAK5J7*k?#vM$cE}bK;<$>3H1z^;4m@8Gbm%-iXs^(0PHG)1#Y4S3?Kut z5=Hb<)sqqc(LEQ125*wFgIWGz)u^ z6HRhRzu*Z3R6y_YBI_Uu%0O9SLKBP8GfDns<_hO!_41^))X23TrSALty6z?9$( z44$Ak=YXBU@B^7K5WJvD-G*5BV=@yYx#g&zwAPS^F2u#2y7E~oZV)lx{1}K12YQh0PuIayV0E z4vw`7V&uz2V0juK7w@4REWjX#QR{L5TR%2>$l)ovat^>1l~(LOzX17c_W17Q4!q!O zQML+ml}E!CSA|py!2n5d_CI~JH+Ay(j1*Onk0$vO`Ts~1V9`?Qm@Hz4Cju@20VYx; znjruTasY5305aePt`=*d$7gJ#3hQe3Mze46%?m&?Hx|STJ{3p#l}ODrE)CW4Hv_ zX#X`(eYS(u6o2jXN5wV`HAsvD6*PsGdy$lldsIlmN>UqXY*8y!Fg^&_;jM-3?hW~VncXLu~WBMgSSSNG(Kk4?CY&utwv`__GqL+Dw z^HrMn^=6k~21p>Jeun`nRwRz$0{~zh>^gdoIVxHWEXh)b3-uD;xPyH<4Qm=4A=*`C zct_b-ux;D5)pv%UfXUj~MmB%};2`|~z;Hy{q^;L0pP-*9@C$Ufc5Rw_aW-E^IkxYX zjqw&&S9@Pc7@NJijmudK3RShcRtgSy0e+hSG*u)Nz%q>cuA|z7OH>-gmJVFq?AT-hd^Tx&neTFTiL;cgdA}jL#*eQ!z4*%OfDD+7 z1gNt9iUJunyvTp>$P;my^Jq`$fch5ure(>>uY5>#d$DuXKLyWE4VzAV+OQ9sIN4AJ zPCx`qjsuFK2YT?#4YB1QSwQUo-kLkWd(`-#oH&`WrvH3yKUaPCG(B@RNuS`h6}pH0R6DVU_mliEqJ$6vqLcjoDBL zP5_h`;O*vJ|7bnl=s*n4aK*G*9W5Q$b-b);8qWh<@U$CWMLoAOJ*ew;q4SmDE1azm zS>kyH&1fqlJ(xeib!=}GUICl#(3yKn8(qm*)crJE<+ZG*!a(nwb?-8!J9x5*6SiM2 zovT`_#o55?z!imH1`dFEFfHcc#T>8zDryT1hA@v({ICC$40WJ+{U90mT+w zzuLNAa?gnt@3WlpdvhTK$$lCD@OkE>X-mt)wQ&mAPH`1pU#+3*^b~7z98>-Y-d5oA zwr|_@XaAS!#d+v!{LvFW%5N0KZN3iZV4YE7%u7FBPQP(7GF(|Hh+&%8pTJdNTJS7? zuy)q*pPtlnb9%Kmdp+t-fzlfPQ z=Viz`1phOFgjtZKL^@7{$Pn>h$GxFMiyA$OG^x_1Oq)7=TC|*zGG7jQf%3#lRXbp6 zHarQFWYvRp@L0t7! z!M+4-1diZ098D*>oq~9QZkY?({1i_Pzs!5HN^PK^)EQF{dv0a{HC<#$kpj8!@jB}9pA$onTHdjU%1=<-{ zW(DV!tM;k6Wu*ntF$EDMgit{=p)MPwJ8m!m#utj@I3XTP!emukEV>pYSf{0A2mg8| z+HsLg!scX0W_L&?tFOX-L{hl4`c)7Z#0o(|2?$WbY`+S!0<9NdL?I!CgoYq?zQ~oCCtgeDaQ<^zpx&#R(R1l88COdZx7MR`vhFhtMpY96WCb8UPf*%JvP2vG9LRx9RC5L1NlMId1W z65>FBN=x=2p}7W^M`;aLF@`g`&CzK%G1_)Ta@$SOp_*xR2YOXvHe5#)X-7EAQGg-D z0t*lz&DD-0<^~l}gh9D>U7bn?%VBKx1;mchw(e#EPh@Y3DQ0`AYY!$|+5d14p7!LE zUqmLFk$-Y0Qf;-*0okxKvMjLa+ocG`g-;F(1{H~)(7`m1KmXJ>R&2+$evm=N^1xkX zk5KF}A&KM@NVW`_y<&_1gq{hl&;I&i*jrirV#MEm{qrYT|MddR583?*fiVX7r7wI0 ze8P5$^#ccZARf?bAf4Qh1u5(y5KMZM!b%sd;Rvrbmgx$T{_+Hx?B)*h8&2<@G!PUT zt%N76106)jJKh<|g~Wl3lVm8v*o7}EeM`vvI-)=9A;g1S5g4YbumA^Wz=2Fm3OJI$ z1Sim8Nr4zd<%Gth3O!0_OWIAtP1P_8> z4I3Y(lDeR=Dp07x3=U9%CJNFhtT=)Yp74b*SaA?u>l_&M*f}PBtwPtTAlT4YK`>gY zGnVWkCo9-FH0lwQRKy|{DaghyqSBP0q@XKZ$x1JQVF^9}fdB@H%X_fH4M%W-7pmwr zEpDVjG_yc+j1R-)!N8&&Kbjx`xx}S3 z+|UF%P_B_+D2o{KV4E+@CzR$n$k_1mg^hp+TXR{FGo>W459u*AUqXrLUSgK+)a52Y z+b5O?6&n`{AqFkDWjP0ljw=*NE0#;2gd`*eGUNyf<@2BzPXCJ1l#*e75)z0&o*>dB zjR7(sP3fryl2S2zbblv>f=}G zQI0eSp$vO~!W7{5(I`0eItJ`Y6s~uww5HXCNg}G)+{)6WvJ`VXb&^usiqw!Ib)`xD zXdQG~Q?W@%d>}x}F zy3>{h^`Bo2>sbGJ7reNI4l2+9W#xI-yav@8G|&J%_j=gGM$j7?5bRrZiZ{K_0R$apf3c&Ax;}RJSD8PONj_?LX1KGk(xWlbh?gm8r;S@g^02+|(iff!% z9&q=@KMpD$G~fduFL|8a-~k1geB}x<#s?IDW0uQ&IqFb=0z5VIoGa$#=+?Q<4YLCU z)cfZ|ZwfL1@B!i$ed$N3xdL>}^r#Od9yvEqfO4dc^&TkT-B^!$G!*awd2~JM^7sI@ k#~yX9XB_QCrv@^_&i1&=eeQIxyWQ`O_q+#b9svOWJ3OQjr2qf` literal 0 HcmV?d00001 diff --git a/art/icon-80x90.gif b/art/icon-80x90.gif new file mode 100644 index 0000000000000000000000000000000000000000..ebb2390005ce48bf41e6db5b428a18ad7a9bdc5e GIT binary patch literal 3392 zcmV-G4Zre7Nk%w1VNd{C0QUd@3^F_eJ4_5bOa(SZ6Fp28J4OLLQ~*9&3OrE?HAy5r zMgcxy2SZI4LrelgRSZK^0!3U3MOy+%UJOcH2T4^EL{u6?R1!s66H8niOj{U9RRdC6 z8d6*(OIRmSTP#UX0!CsAMPmU;VhT)T14U{9OKJ;FX$nMY5=~+lO=JX7WDHVe1W{`X zQ)>@eZ532#08MfPNp%8Ja{yF(2v~O&T6HN`W;9!8Csk=SWpWu}cSdS=PH%WP7P6KJ-5q9uByDSDl!vTKD34Ou< ze$WMhy$XW92!gc~g1Z@nw-ki1C5gB-iLg6?o>qjCW{H<9GJ@ih0+0w(g%yx z43g0WlGYTI(ixZ19GTM>nb{JH)Fh6@B#y``lEy2O$Rw7@Bb(GKoYg0r*)pEjJD=4w zpV&H{+c=uaJD}G+q1iQ{+ApEsIilh+pW#NG$U~ynL!#MBrrJ)a+)Jg@QK#Hhsoq2bH@ zb-Cqvyytqo>2$j4c)##`!RLO$>3GQXeA4}U+W&Uc|7^wdWW)4_sinqt2y~u^a*@eN@n#R(n#>=S6)wb2zvdz|k#_NU2?ug3khs^Pd&hdiB z@r%*(h1C3s)BA_i_mb52mCow9+2pO?`L5XJt>pWy=>DiG5T_CX>@2HM@dak03rDV0RRB^04x9i002+`S^xkD{{Zg^ z97wRB!Gj1BDqP60p~Hs|6~5`R<;D#jZz5{k7?B#A3lc<#6ait!F^(ux7JOp^q(})c zVcKY;vgSrM6GX%e38H6-5;vM1T;+)jm7_?LDqYI7sZ*s=q%<*7BjiY!BYVQ!Qczi% zCu0^hT12+2*t2HSsx8~7ty;Ha$Ht9|#z%>fc(Y=?fQ(?8Igy5O8%(&c;lqd%D@N=s z%U!E^^Ns+)W*{pmn7n1nwvF?)&zwDf9!;9G=+2u>gZ3;sbT&62bV9~EqQyuOBRmKk zH|5T+&A@{TA5Ofu@#5R$jEJ0d1Q**dLx`Y2Qw|tQ*tTKYzC9Z@@7=+3{~u4jy!rFl zv8`gUJTF!WaJ0OX5S#ivWn)flw?>{nHvjvX$De-#7T6zp*!U8}YBqh8$}6UxpcWDB_4D7N~}F?nNj88*k(!VMq~laUUI{Xk$$^8djs@jyv9% zBaS!n2&9le21%rmtVqb*4sU2cpI#K+H%E=t_(J5BRbr{-mO}PYgGjOEH9-z>C2pS)=6hCa?V*zFLmx&XD@j2X{VKQ@~MVwk&U1MMIelzWS9}; za32_-6l$rTfchfnopxrrX{VspnIv-~wULYm6XKQTbjD0NiY~hJ|B{O?zT^TZptAxB zYplJ%noBOV);jC1y8MbOtg;r{tENhjDgp>xZ6Uz~IjI_w4FW0S1tq)UQtYqbDhqD7 z#P&MtxVC=#t+Bu2l8YS9iXiD5AyJDaOp@NW?Jn((>u$K{;v(>`xBTlbxCSGfi@U4n zz+gxcWROt~BgAyC2$kteiNFO5?D5AShb*$k3x`~?z;1-_um}^#2;m4WMg~(xQc_}z zEw|*X^Ugf??DNk*tMcV+(~59|KsPuG@zL4NVKdIP>>RbuQ|DYY)mCGDOD$1%y|vD6 zOc>@%E#K1ygOQcpG$mZO?e^Pn$1V5VwFv#}*e~sHk1NZ z`RubPoCKlY@)9ICEtFSo`Q?~ret9jLQ?5!7sfO7TO>d;&cL*WK82B8A#M1feuxmcc zER`!qTTD0z)CJmCL0pXFth;W?E5sLX{PD;qZ~XAY&;E)jrXUennipjBMg~~P{1R8d z|3N(T;D;~%_~eWKJ@l`*^1LT3Oc;}+`SOrc_VZa)eOIiDQhq6}sBelZ(BmHf2gtwS zsqcUQgkAyxn2Id8r&?TT1NL-+H+$)XY26b=DM(R@4th|4{d0u}`}e^PhOmSv?BFSA zfTlF*?H+81z|qa8s($2)$aj-lw|9`y*wPFNqFae@;a=&}zfOk8YfFcu;|H?dQLK2Y(s6YjZ&Vd?qpanfBK_`I) zY_jYE$+*WcD1ZXIy<{XDI0--LkOxUf0uqpj1V~3JP)Hzxq#q@zNI|+%mIgGWkr0AI zC-A~8R4YZ>TZp#ukO-5G)Tbu}=}8em)SnWys7FnzQ6Dh_p77*;#>l`$X~;4R@^cP( zAnGBK%GIuR^$=V2DpwaF1E)SKUtNd*>Q)vpnt2neiAV%kw>np_YPGI)MZ{e1n%6%d zLavVx!kR_`0oCmw0uX~t2-1WBH+s_xdmySI3}M$pOjfIuwXA08I$69@wzGaM#3P!} zgc3{u1k#y69PR;!2|%#~%fVM0e%BBS|K(w_gqW;ucdOgn^7gmD{ljF@FoP@5fIceQ z=MEqPF$(NpwGh$P9&+mk;QE%ggvhQTe9K+zR@VAMFYOrQiosF(yU@Vhp+HbOLIkruR&0~@@zwsW{ccIQiB z`VyiK7oM<&F-+kLci6-8)k9N70E71IbCe;`0UY3vg9$`n0w{1RgzZ3xLh#|nIL@(- zb4-XG`R1>0*v77Qw()@NW8Oo_HK9f)jKyVZm4cD&`?ZEo)Y z4`UGQduY;yYGGvpx>2_m<}h!18~or1KXx6OkY@-0uHTEL4-Sqo4V7q%;MnFiw-L_m z2p=2c2xm38N0I?*+`|KE|5}skYI5;v9dewB8!x(-r5=FM*0uk~6 zZEezWJAho?G>7@km%eJF-`oy4x5F5QtP@4rR0JlmN#F)PXr?>8<{$q$)5p&AFU)}n zkI6_EF0g~4YrW`X2RqpZ9(ShG;R|1Yf(%6907=~-2NBi!)|38qvFE(*OsD(J>Av&n z#Gwrx(5T>>His{W9r1`CxZ)3gb1(oQ1RS^rGFCo$DG}W4m{&aJ5l;jXD3bK0*A}%e zUw6*0e(ZEu0tt@Rm(p*Y>rYQT*=>*eRa2n^!t{O9=s^48Xa44#=lsB>zyeDv|30W+ zdh>B!ch%2*4o+af|30s;FE4ms_^T)Ws>A=t>!&j6aliceS3Uo+N1^)U7YH-PVEg*V z9rgalbWp$ol6QU100oMNcejUrWCsN$AQbs`51wFl(l-ZmV17AgeqI0u8fbwQXnq{H zfnGod8K{Bg7X>8{4H0+`%s>T!5C$)Ia7SlwGx!8Du!8#M1z$jdbN~i(FoHZtf*crx zJZOPJNQ6N+f;NbQ0^tm9Fa;MFVcEBRAGdnhH-IY0gySFwtRM$+;0d1Kg#@{&;fObgKuDcc}RZA*N4~FWPs>N%N5CA)90y>lc literal 0 HcmV?d00001 diff --git a/manifest b/manifest index 0dcfda40aa..71bc736efa 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Typo\sfixes\s[forum:c19bbf245d|reported\sin\sthe\sforum].\sNo\scode\schanges. -D 2024-02-23T18:02:31.402 +C Add\stwo\sGIFs\sthat\scontain\sthe\sfeather\slogo. +D 2024-02-24T19:58:15.434 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -9,6 +9,8 @@ F Makefile.msc df56c06ef05add5ebcdcc9d4823fb2ec66ac16b06acb6971a7420859025886fa F README.md 6358805260a03ebead84e168bbf3740ddf3f683b477e478567186aa7afb490d3 F VERSION c84541c6a9e8426462176fbb1f9ecb5cfd7d1bb56228053ff7eeba8841673eb6 F aclocal.m4 a5c22d164aff7ed549d53a90fa56d56955281f50 +F art/icon-243x273.gif 9750b734f82fdb3dc43127753d5e6fbf3b62c9f4e136c2fbf573b2f57ea87af5 +F art/icon-80x90.gif 65509ce3e5f86a9cd64fe7fca2d23954199f31fe44c1e09e208c80fb83d87031 F art/sqlite370.eps aa97a671332b432a54e1d74ff5e8775be34200c2 F art/sqlite370.ico af56c1d00fee7cd4753e8631ed60703ed0fc6e90 F art/sqlite370.jpg d512473dae7e378a67e28ff96a34da7cb331def2 @@ -2162,8 +2164,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P e5db08993127dfc18cc2b621a13cbfef52974f0f504f4d8208093bfad1ffdcc5 -R fbd01c060093cc83561018ffcc839787 -U stephan -Z 3309f779a4e95b40300e717423266d54 +P 67d8bae0f695c0839e724c1aadea0a22f736fdd9664d40a29b4d82c91fb89ab3 +R dab9490920c21cf9a17070c8cfa63576 +U drh +Z 37fca3febc4fffca5469b7a46e713d26 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 75ab08df22..ec8bd6f0d0 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -67d8bae0f695c0839e724c1aadea0a22f736fdd9664d40a29b4d82c91fb89ab3 \ No newline at end of file +5f21e6a8ee709d8c5ec12c45e8dc702a7d0bb041f31b5715e28cd904dfd566b0 \ No newline at end of file From dfd991c3b947f3d746ee56ba3295acd8074eead2 Mon Sep 17 00:00:00 2001 From: drh <> Date: Sun, 25 Feb 2024 21:30:33 +0000 Subject: [PATCH 143/430] Make sure key comprisons are done correctly if the index key contains NaN values that have not been shifted into NULLs. That can only happen due to database corruption, but we need to deal with it nevertheless. FossilOrigin-Name: 7e4c743f9e6ef33500795543e6db9a77c533025bf00c2ee97abd433a3871b5a1 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/vdbeaux.c | 36 ++++++++++++++++++++++++++++++++---- 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 71bc736efa..034aae79aa 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\stwo\sGIFs\sthat\scontain\sthe\sfeather\slogo. -D 2024-02-24T19:58:15.434 +C Make\ssure\skey\scomprisons\sare\sdone\scorrectly\sif\sthe\sindex\skey\scontains\sNaN\nvalues\sthat\shave\snot\sbeen\sshifted\sinto\sNULLs.\s\sThat\scan\sonly\shappen\sdue\sto\ndatabase\scorruption,\sbut\swe\sneed\sto\sdeal\swith\sit\snevertheless. +D 2024-02-25T21:30:33.710 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -815,7 +815,7 @@ F src/vdbe.c 805af8bec9cae76a873b0ec4c91c3d1bd49b38e86c1c533ed87ec7a07a5042a5 F src/vdbe.h 88e19a982df9027ec1c177c793d1a5d34dc23d8f06e3b2d997f43688b05ee0eb F src/vdbeInt.h 949669dfd8a41550d27dcb905b494f2ccde9a2e6c1b0b04daa1227e2e74c2b2c F src/vdbeapi.c 8f57d60c89da0b60e6d4e272358c511f6bae4e24330bdb11f8b42f986d1bf21b -F src/vdbeaux.c c5a471b34e9c4cfc0295a3e10734fd197670ffaebcb742f284c8e17e8026ceea +F src/vdbeaux.c 56900c9a41f23260c8346f212bd6005eb9171f9a2f70d0cfb1441a078a0e4b84 F src/vdbeblob.c 13f9287b55b6356b4b1845410382d6bede203ceb29ef69388a4a3d007ffacbe5 F src/vdbemem.c 3e37dab421b74e9ce55c1e88fbc7bc6fead590b5ab258bc684f8b70abb1d6e71 F src/vdbesort.c 237840ca1947511fa59bd4e18b9eeae93f2af2468c34d2427b059f896230a547 @@ -2164,8 +2164,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 67d8bae0f695c0839e724c1aadea0a22f736fdd9664d40a29b4d82c91fb89ab3 -R dab9490920c21cf9a17070c8cfa63576 +P 5f21e6a8ee709d8c5ec12c45e8dc702a7d0bb041f31b5715e28cd904dfd566b0 +R 6483dab5f9a5754b844e2de29e4108e4 U drh -Z 37fca3febc4fffca5469b7a46e713d26 +Z 27901e47f4de6ad53eaa2c16e520ba30 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index ec8bd6f0d0..ccb9a0f0ae 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5f21e6a8ee709d8c5ec12c45e8dc702a7d0bb041f31b5715e28cd904dfd566b0 \ No newline at end of file +7e4c743f9e6ef33500795543e6db9a77c533025bf00c2ee97abd433a3871b5a1 \ No newline at end of file diff --git a/src/vdbeaux.c b/src/vdbeaux.c index 420365e930..fe0dbd6b0e 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -4060,6 +4060,23 @@ static void serialGet( pMem->flags = IsNaN(x) ? MEM_Null : MEM_Real; } } +static int serialGet7( + const unsigned char *buf, /* Buffer to deserialize from */ + Mem *pMem /* Memory cell to write value into */ +){ + u64 x = FOUR_BYTE_UINT(buf); + u32 y = FOUR_BYTE_UINT(buf+4); + x = (x<<32) + y; + assert( sizeof(x)==8 && sizeof(pMem->u.r)==8 ); + swapMixedEndianFloat(x); + memcpy(&pMem->u.r, &x, sizeof(x)); + if( IsNaN(x) ){ + pMem->flags = MEM_Null; + return 1; + } + pMem->flags = MEM_Real; + return 0; +} void sqlite3VdbeSerialGet( const unsigned char *buf, /* Buffer to deserialize from */ u32 serial_type, /* Serial type to deserialize */ @@ -4739,7 +4756,7 @@ int sqlite3VdbeRecordCompareWithSkip( }else if( serial_type==0 ){ rc = -1; }else if( serial_type==7 ){ - sqlite3VdbeSerialGet(&aKey1[d1], serial_type, &mem1); + serialGet7(&aKey1[d1], &mem1); rc = -sqlite3IntFloatCompare(pRhs->u.i, mem1.u.r); }else{ i64 lhs = vdbeRecordDecodeInt(serial_type, &aKey1[d1]); @@ -4764,14 +4781,18 @@ int sqlite3VdbeRecordCompareWithSkip( }else if( serial_type==0 ){ rc = -1; }else{ - sqlite3VdbeSerialGet(&aKey1[d1], serial_type, &mem1); if( serial_type==7 ){ - if( mem1.u.ru.r ){ + if( serialGet7(&aKey1[d1], &mem1) ){ + rc = -1; /* mem1 is a NaN */ + }else if( mem1.u.ru.r ){ rc = -1; }else if( mem1.u.r>pRhs->u.r ){ rc = +1; + }else{ + assert( rc==0 ); } }else{ + sqlite3VdbeSerialGet(&aKey1[d1], serial_type, &mem1); rc = sqlite3IntFloatCompare(mem1.u.i, pRhs->u.r); } } @@ -4841,7 +4862,14 @@ int sqlite3VdbeRecordCompareWithSkip( /* RHS is null */ else{ serial_type = aKey1[idx1]; - rc = (serial_type!=0 && serial_type!=10); + if( serial_type==0 + || serial_type==10 + || (serial_type==7 && serialGet7(&aKey1[d1], &mem1)!=0) + ){ + assert( rc==0 ); + }else{ + rc = 1; + } } if( rc!=0 ){ From f286ad9211dceab80dc81e9207afdeac80bc777e Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 26 Feb 2024 11:43:44 +0000 Subject: [PATCH 144/430] Remove a local variable from sqlite3IntFloatCompare() that was being optimized out anyhow, in order to get back to 100% MC/DC. FossilOrigin-Name: 52b13d6acbb738b9281f7dd44edd6c3c9585d22d98b1951b7059534fbd16fac0 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/vdbeaux.c | 10 ++++------ 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/manifest b/manifest index 034aae79aa..012a9a59e8 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Make\ssure\skey\scomprisons\sare\sdone\scorrectly\sif\sthe\sindex\skey\scontains\sNaN\nvalues\sthat\shave\snot\sbeen\sshifted\sinto\sNULLs.\s\sThat\scan\sonly\shappen\sdue\sto\ndatabase\scorruption,\sbut\swe\sneed\sto\sdeal\swith\sit\snevertheless. -D 2024-02-25T21:30:33.710 +C Remove\sa\slocal\svariable\sfrom\ssqlite3IntFloatCompare()\sthat\swas\sbeing\soptimized\nout\sanyhow,\sin\sorder\sto\sget\sback\sto\s100%\sMC/DC. +D 2024-02-26T11:43:44.331 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -815,7 +815,7 @@ F src/vdbe.c 805af8bec9cae76a873b0ec4c91c3d1bd49b38e86c1c533ed87ec7a07a5042a5 F src/vdbe.h 88e19a982df9027ec1c177c793d1a5d34dc23d8f06e3b2d997f43688b05ee0eb F src/vdbeInt.h 949669dfd8a41550d27dcb905b494f2ccde9a2e6c1b0b04daa1227e2e74c2b2c F src/vdbeapi.c 8f57d60c89da0b60e6d4e272358c511f6bae4e24330bdb11f8b42f986d1bf21b -F src/vdbeaux.c 56900c9a41f23260c8346f212bd6005eb9171f9a2f70d0cfb1441a078a0e4b84 +F src/vdbeaux.c 66161ba75c4a2d86aab124fe3cbcc2a752d8e4b1fc8c1fc6e00625db4798168c F src/vdbeblob.c 13f9287b55b6356b4b1845410382d6bede203ceb29ef69388a4a3d007ffacbe5 F src/vdbemem.c 3e37dab421b74e9ce55c1e88fbc7bc6fead590b5ab258bc684f8b70abb1d6e71 F src/vdbesort.c 237840ca1947511fa59bd4e18b9eeae93f2af2468c34d2427b059f896230a547 @@ -2164,8 +2164,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 5f21e6a8ee709d8c5ec12c45e8dc702a7d0bb041f31b5715e28cd904dfd566b0 -R 6483dab5f9a5754b844e2de29e4108e4 +P 7e4c743f9e6ef33500795543e6db9a77c533025bf00c2ee97abd433a3871b5a1 +R c6dffb6e7b319997a7eba2ad9ac6eb44 U drh -Z 27901e47f4de6ad53eaa2c16e520ba30 +Z d409ac0ab10fc8970bce183981ba2543 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index ccb9a0f0ae..31f714bf7c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7e4c743f9e6ef33500795543e6db9a77c533025bf00c2ee97abd433a3871b5a1 \ No newline at end of file +52b13d6acbb738b9281f7dd44edd6c3c9585d22d98b1951b7059534fbd16fac0 \ No newline at end of file diff --git a/src/vdbeaux.c b/src/vdbeaux.c index fe0dbd6b0e..209d02a049 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -4516,17 +4516,15 @@ int sqlite3IntFloatCompare(i64 i, double r){ return (xr); }else{ i64 y; - double s; if( r<-9223372036854775808.0 ) return +1; if( r>=9223372036854775808.0 ) return -1; y = (i64)r; if( iy ) return +1; - s = (double)i; - testcase( doubleLt(s,r) ); - testcase( doubleLt(r,s) ); - testcase( doubleEq(r,s) ); - return (sr); + testcase( doubleLt(((double)i),r) ); + testcase( doubleLt(r,((double)i)) ); + testcase( doubleEq(r,((double)i)) ); + return (((double)i)r); } } From 1103eb423e7c975ba77f8a9a10b0667636191be8 Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 26 Feb 2024 11:51:21 +0000 Subject: [PATCH 145/430] Fix header comments on test scripts. FossilOrigin-Name: 9fe9670c977ce7ad2c19657783a63998769dbb7741a587889c72ecc04d895793 --- ext/intck/intck1.test | 5 ++--- ext/intck/intck2.test | 4 ++-- manifest | 16 ++++++++-------- manifest.uuid | 2 +- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/ext/intck/intck1.test b/ext/intck/intck1.test index e05ae06166..1708406304 100644 --- a/ext/intck/intck1.test +++ b/ext/intck/intck1.test @@ -9,7 +9,8 @@ # #*********************************************************************** # -# The focus of this file is testing the r-tree extension. +# The focus of this file is testing the incremental integrity check +# (intck) extension. # source [file join [file dirname [info script]] intck_common.tcl] @@ -328,5 +329,3 @@ do_intck_test 7.5 {} finish_test - - diff --git a/ext/intck/intck2.test b/ext/intck/intck2.test index c168118535..c8503042c9 100644 --- a/ext/intck/intck2.test +++ b/ext/intck/intck2.test @@ -9,7 +9,8 @@ # #*********************************************************************** # -# The focus of this file is testing the r-tree extension. +# The focus of this file is testing the incremental integrity check +# (intck) extension. # source [file join [file dirname [info script]] intck_common.tcl] @@ -173,4 +174,3 @@ do_intck_test 3.8 { } finish_test - diff --git a/manifest b/manifest index f34154f890..912b02d07c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Merge\slatest\strunk\schanges\sinto\sthis\sbranch. -D 2024-02-26T10:56:54.404 +C Fix\sheader\scomments\son\stest\sscripts. +D 2024-02-26T11:51:21.317 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -250,8 +250,8 @@ F ext/fts5/tool/showfts5.tcl d54da0e067306663e2d5d523965ca487698e722c F ext/icu/README.txt 7ab7ced8ae78e3a645b57e78570ff589d4c672b71370f5aa9e1cd7024f400fc9 F ext/icu/icu.c c074519b46baa484bb5396c7e01e051034da8884bad1a1cb7f09bbe6be3f0282 F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a32075a8 -F ext/intck/intck1.test 866f0937911bf3a10491af6ce319b75bcd587c39dc8decf2444746b946aa4f3e -F ext/intck/intck2.test 97daaf43b8a3c870ba7c2fd421dc1887053f5b30188896fa64677ce8174c206f +F ext/intck/intck1.test 8a879640c90fdff5e91e6c2c41d509485ee634e8077fe0ca9f76be4cbd441fa3 +F ext/intck/intck2.test 47afb44681d13d11072cd8906e6aa877c967e65be788b01f6139922fd91474ef F ext/intck/intck_common.tcl 9e51458126576783f11051ac0fd25bea3f6b17f570a55884223737f3200b214b F ext/intck/intckbusy.test 0732fe3efbb9e0a53ffdcc240073f6ff2777ea82c3e08812b16494f650763fe1 F ext/intck/intckcorrupt.test 3211ef68ac53e83951b6c8f6a8d2396506d123fe5898f97f848a25837744ec56 @@ -2173,8 +2173,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P c253e276b29de28a18270d01b60d95157ce3fc4b37e246d991f9119d26e718d7 7e4c743f9e6ef33500795543e6db9a77c533025bf00c2ee97abd433a3871b5a1 -R d91900a2b738ceadf979774120590e4a -U dan -Z 9b2321809e4d89643b001730f06f9a2c +P b6371ff9f5c3d4e87a5b1127a82970202f74c790b828dda20df88dd727bcc9b4 +R 3add559ac6b3cdeca1489f677e09e848 +U drh +Z 4a33c5af1c72f813c7944d5f457e89df # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index b5e0bfba97..391e1cbab5 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b6371ff9f5c3d4e87a5b1127a82970202f74c790b828dda20df88dd727bcc9b4 \ No newline at end of file +9fe9670c977ce7ad2c19657783a63998769dbb7741a587889c72ecc04d895793 \ No newline at end of file From 7c6433cfff58499a7ee2c9b103590359e0cf5226 Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 26 Feb 2024 15:27:33 +0000 Subject: [PATCH 146/430] When inserting a 3-byte cell into a btree, ensure that the extra padding byte is 0x00. This is not necessary for security, as far as I can tell, but it seems like a reasonable precaution. FossilOrigin-Name: 5766f1279dab91e030d4dcf5133659e5cedf914a1628ccf00d67d8e50a9957fd --- manifest | 15 +++++++-------- manifest.uuid | 2 +- src/btree.c | 10 ++++++++-- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index aea982c3aa..38fe85d7c4 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\sintck\sextension.\sFor\sperforming\sincremental\sintegrity-check\son\sa\sdatabase. -D 2024-02-26T12:16:02.164 +C When\sinserting\sa\s3-byte\scell\sinto\sa\sbtree,\sensure\sthat\sthe\sextra\spadding\sbyte\nis\s0x00.\s\sThis\sis\snot\snecessary\sfor\ssecurity,\sas\sfar\sas\sI\scan\stell,\sbut\sit\nseems\slike\sa\sreasonable\sprecaution. +D 2024-02-26T15:27:33.122 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -689,7 +689,7 @@ F src/auth.c 19b7ccacae3dfba23fc6f1d0af68134fa216e9040e53b0681b4715445ea030b4 F src/backup.c 5c97e8023aab1ce14a42387eb3ae00ba5a0644569e3476f38661fa6f824c3523 F src/bitvec.c 9eac5f42c11914d5ef00a75605bb205e934f435c579687f985f1f8b0995c8645 F src/btmutex.c 79a43670447eacc651519a429f6ece9fd638563cf95b469d6891185ddae2b522 -F src/btree.c 2f9dcf7c27879edb7897354029343bcab0c5a3dd2bde3bf3fd8f814b71344d22 +F src/btree.c 5e86e2b4c4ddb094c4a5e782b79d5fde5d52a7b516182494787e4edd01e86435 F src/btree.h 03e3356f5208bcab8eed4e094240fdac4a7f9f5ddf5e91045ce589f67d47c240 F src/btreeInt.h 3e2589726c4f105e653461814f65857465da68be1fac688de340c43b873f4062 F src/build.c 04f1bcee189f045ab086d84fee95db42cb49df82ff8e84af8136309ff3c8a75f @@ -2173,9 +2173,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 52b13d6acbb738b9281f7dd44edd6c3c9585d22d98b1951b7059534fbd16fac0 9fe9670c977ce7ad2c19657783a63998769dbb7741a587889c72ecc04d895793 -R bbd9def4c46dfeeca89016db47528759 -T +closed 9fe9670c977ce7ad2c19657783a63998769dbb7741a587889c72ecc04d895793 -U dan -Z ac496782ea3735f2c2a49bf7149a7694 +P 141d8bb059f8987d05d18327b97c4d36e98258f657b41a3d4d8877fe8b4e72e3 +R 814829b1dbfec006c60cbfc4ee055b02 +U drh +Z 06102cc64bbcbae3a093de2757fdfb8e # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index b5c3adb2b1..ae9679a05c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -141d8bb059f8987d05d18327b97c4d36e98258f657b41a3d4d8877fe8b4e72e3 \ No newline at end of file +5766f1279dab91e030d4dcf5133659e5cedf914a1628ccf00d67d8e50a9957fd \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 16b683abe7..3e08dc6a1b 100644 --- a/src/btree.c +++ b/src/btree.c @@ -7007,7 +7007,10 @@ static int fillInCell( n = nHeader + nPayload; testcase( n==3 ); testcase( n==4 ); - if( n<4 ) n = 4; + if( n<4 ){ + n = 4; + pPayload[nPayload] = 0; + } *pnSize = n; assert( nSrc<=nPayload ); testcase( nSrcpBt->nPreformatSize; - if( szNew<4 ) szNew = 4; + if( szNew<4 ){ + szNew = 4; + newCell[3] = 0; + } if( ISAUTOVACUUM(p->pBt) && szNew>pPage->maxLocal ){ CellInfo info; pPage->xParseCell(pPage, newCell, &info); From f79b0bdcbfb46164cfd665d256f2862bf3f42a7c Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 26 Feb 2024 22:28:21 +0000 Subject: [PATCH 147/430] The quote() SQL function should convert +Inf into 9.0e+999 and -Inf into -9.0e+999. See [forum:/forumpost/6675b25108|forum post 6675b25108]. FossilOrigin-Name: 85dd79a6edecfc8c6307c6d215998f76dab086aa14528ddc64eb9955501becfd --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/func.c | 4 ++-- test/func.test | 5 +++++ 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 38fe85d7c4..406669c1d8 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C When\sinserting\sa\s3-byte\scell\sinto\sa\sbtree,\sensure\sthat\sthe\sextra\spadding\sbyte\nis\s0x00.\s\sThis\sis\snot\snecessary\sfor\ssecurity,\sas\sfar\sas\sI\scan\stell,\sbut\sit\nseems\slike\sa\sreasonable\sprecaution. -D 2024-02-26T15:27:33.122 +C The\squote()\sSQL\sfunction\sshould\sconvert\s+Inf\sinto\s9.0e+999\sand\s-Inf\sinto\n-9.0e+999.\s\sSee\s[forum:/forumpost/6675b25108|forum\spost\s6675b25108]. +D 2024-02-26T22:28:21.332 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -703,7 +703,7 @@ F src/delete.c cb766727c78e715f9fb7ec8a7d03658ed2a3016343ca687acfcec9083cdca500 F src/expr.c 3381ee4c9aa7ccde22a2a7f35ce343925a7a25d96bdc943649131f9decdebad2 F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c a47610f0a5c6cb0ad79f8fcef039c01833dec0c751bb695f28dc0ec6a4c3ba00 -F src/func.c c71b81223e165722cd81fa71fb869a235de5998c4c5142a5dfa2725d6331f539 +F src/func.c 4204c56196847faefef57fa14e43b8e4d65eb8d7e65318abe463472e3fd148cb F src/global.c 765a0656d6cbf043cb272ff0ae38f39cc46713539ffe6793258ed3eb4b188b52 F src/hash.c 9ee4269fb1d6632a6fecfb9479c93a1f29271bddbbaf215dd60420bcb80c7220 F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 @@ -1228,7 +1228,7 @@ F test/fts4umlaut.test fcaca4471de7e78c9d1f7e8976e3e8704d7d8ad979d57a739d00f3f75 F test/fts4unicode.test 82a9c16b68ba2f358a856226bb2ee02f81583797bc4744061c54401bf1a0f4c9 F test/fts4upfrom.test f25835162c989dffd5e2ef91ec24c4848cc9973093e2d492d1c7b32afac1b49d F test/full.test 6b3c8fb43c6beab6b95438c1675374b95fab245d -F test/func.test da1332f6ab70338b83f5e2d594e72c7aa438c9b68406915e5a54618d601c09ee +F test/func.test 504d202650c7940b5aa98364dd68f242df87f39f829e51074a55d79fc7bc7414 F test/func2.test 772d66227e4e6684b86053302e2d74a2500e1e0f F test/func3.test 600a632c305a88f3946d38f9a51efe145c989b2e13bd2b2a488db47fe76bab6a F test/func4.test e8ef9b2bd6a192a213cbd5cf31a3b35e25cd6ff2fdaeea0b58d63be31b03d220 @@ -2173,8 +2173,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 141d8bb059f8987d05d18327b97c4d36e98258f657b41a3d4d8877fe8b4e72e3 -R 814829b1dbfec006c60cbfc4ee055b02 +P 5766f1279dab91e030d4dcf5133659e5cedf914a1628ccf00d67d8e50a9957fd +R 3cd78a5a9341c0a117222898fc0a6308 U drh -Z 06102cc64bbcbae3a093de2757fdfb8e +Z 7d29334815d11708910ce9fb84e949e7 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index ae9679a05c..c1fa5c043b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5766f1279dab91e030d4dcf5133659e5cedf914a1628ccf00d67d8e50a9957fd \ No newline at end of file +85dd79a6edecfc8c6307c6d215998f76dab086aa14528ddc64eb9955501becfd \ No newline at end of file diff --git a/src/func.c b/src/func.c index 249c17857e..9fbd1e9e1c 100644 --- a/src/func.c +++ b/src/func.c @@ -1101,13 +1101,13 @@ void sqlite3QuoteValue(StrAccum *pStr, sqlite3_value *pValue){ double r1, r2; const char *zVal; r1 = sqlite3_value_double(pValue); - sqlite3_str_appendf(pStr, "%!.15g", r1); + sqlite3_str_appendf(pStr, "%!0.15g", r1); zVal = sqlite3_str_value(pStr); if( zVal ){ sqlite3AtoF(zVal, &r2, pStr->nChar, SQLITE_UTF8); if( r1!=r2 ){ sqlite3_str_reset(pStr); - sqlite3_str_appendf(pStr, "%!.20e", r1); + sqlite3_str_appendf(pStr, "%!0.20e", r1); } } break; diff --git a/test/func.test b/test/func.test index 82f51b857d..c7b8f72352 100644 --- a/test/func.test +++ b/test/func.test @@ -786,6 +786,11 @@ do_test func-16.1 { } } {X'616263' NULL} +# Test the quote function for +Inf and -Inf +do_execsql_test func-16.2 { + SELECT quote(4.2e+859), quote(-7.8e+904); +} {9.0e+999 -9.0e+999} + # Correctly handle function error messages that include %. Ticket #1354 # do_test func-17.1 { From 8732fce9856632c3cce29787263f2770a1f0c6aa Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 27 Feb 2024 14:31:31 +0000 Subject: [PATCH 148/430] Ensure memory cells are properly freed before they are overwritten by OP_IntegrityCk. FossilOrigin-Name: e50acaf934f44f8833bc588e0ae1abd59df907b9a42d4cafd5518427a8c7b627 --- manifest | 14 +++++----- manifest.uuid | 2 +- src/vdbemem.c | 6 ++-- test/pragma6.test | 71 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 83 insertions(+), 10 deletions(-) create mode 100644 test/pragma6.test diff --git a/manifest b/manifest index bf570f6644..c7341f42f2 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Have\s"PRAGMA\squick_check"\scompare\sthe\snumber\sof\sentries\sin\stables\sand\sindexes. -D 2024-02-27T11:03:10.418 +C Ensure\smemory\scells\sare\sproperly\sfreed\sbefore\sthey\sare\soverwritten\sby\sOP_IntegrityCk. +D 2024-02-27T14:31:31.983 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -826,7 +826,7 @@ F src/vdbeInt.h 949669dfd8a41550d27dcb905b494f2ccde9a2e6c1b0b04daa1227e2e74c2b2c F src/vdbeapi.c 8f57d60c89da0b60e6d4e272358c511f6bae4e24330bdb11f8b42f986d1bf21b F src/vdbeaux.c 66161ba75c4a2d86aab124fe3cbcc2a752d8e4b1fc8c1fc6e00625db4798168c F src/vdbeblob.c 13f9287b55b6356b4b1845410382d6bede203ceb29ef69388a4a3d007ffacbe5 -F src/vdbemem.c 6f1728ea70d9523cc446567d3bf1cca3f26515d15160dd9f540fc549cdfbe2a6 +F src/vdbemem.c 213bf303826c0ef702e3a2a69dab2309d84b8381b822c6787885859fd7cd4c4e F src/vdbesort.c 237840ca1947511fa59bd4e18b9eeae93f2af2468c34d2427b059f896230a547 F src/vdbetrace.c fe0bc29ebd4e02c8bc5c1945f1d2e6be5927ec12c06d89b03ef2a4def34bf823 F src/vdbevtab.c 2143db7db0ceed69b21422581f434baffc507a08d831565193a7a02882a1b6a7 @@ -1500,6 +1500,7 @@ F test/pragma2.test e5d5c176360c321344249354c0c16aec46214c9f F test/pragma3.test 92a46bbea12322dd94a404f49edcfbfc913a2c98115f0d030a7459bb4712ef31 F test/pragma4.test 9559cf5173864bf47c0431873d158fbeb72f920a59905b1f46069d8543eccdab F test/pragma5.test 7b33fc43e2e41abf17f35fb73f71b49671a380ea92a6c94b6ce530a25f8d9102 +F test/pragma6.test fc3b670ab8ed985b2e5faa870f0f81aba1bfd5c3877ef3214e2df88592ccd3e5 F test/pragmafault.test 275edaf3161771d37de60e5c2b412627ac94cef11739236bec12ed1258b240f8 F test/prefixes.test b524a1c44bffec225b9aec98bd728480352aa8532ac4c15771fb85e8beef65d9 F test/printf.test 685fec5a0c5af2490ab0632775a301554361d674211d690f5bee0a97b05333de @@ -2175,9 +2176,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 61676f1e18a405e4f3b6007488f2e68f3f55b312c107359ae5e52929f0c104c8 cc294c041b4c7a044ff344989f872415ced5263a0b654112371b2da7c852a688 -R 5ed88641845fcb2fc70cf72b4cd45874 -T +closed cc294c041b4c7a044ff344989f872415ced5263a0b654112371b2da7c852a688 +P b736519d3d2e93c76fa36253143f2664b9dd12e26acba555f0bf9c4d44705499 +R 725744da1444e5fefe1d2ce5b7ed4e0a U dan -Z 4d80cc60a3752c9ff93baadf82143f0e +Z 55bcecaeff9ae7b0e1973c81cc615ff2 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index a8b2d749cb..e98dc9d1dc 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b736519d3d2e93c76fa36253143f2664b9dd12e26acba555f0bf9c4d44705499 \ No newline at end of file +e50acaf934f44f8833bc588e0ae1abd59df907b9a42d4cafd5518427a8c7b627 \ No newline at end of file diff --git a/src/vdbemem.c b/src/vdbemem.c index 03c58f3024..d0015206d5 100644 --- a/src/vdbemem.c +++ b/src/vdbemem.c @@ -943,9 +943,11 @@ void sqlite3VdbeMemSetInt64(Mem *pMem, i64 val){ } } +/* +** Set the iIdx'th entry of array aMem[] to contain integer value val. +*/ void sqlite3MemSetArrayInt64(sqlite3_value *aMem, int iIdx, i64 val){ - aMem[iIdx].u.i = val; - aMem[iIdx].flags = MEM_Int; + sqlite3VdbeMemSetInt64(&aMem[iIdx], val); } /* A no-op destructor */ diff --git a/test/pragma6.test b/test/pragma6.test new file mode 100644 index 0000000000..8e4233a536 --- /dev/null +++ b/test/pragma6.test @@ -0,0 +1,71 @@ +# 2024 February 27 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements tests for PRAGMAs quick_check and integrity_check. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix pragma6 + +database_may_be_corrupt + +#------------------------------------------------------------------------- +# +do_test 1.0 { + sqlite3 db {} + db deserialize [decode_hexdb { + .open --hexdb + | size 12288 pagesize 4096 filename crash-540f4c1eb1e7ac.db + | page 1 offset 0 + | 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. + | 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 03 .....@ ........ + | 32: 00 bb 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + | 96: 00 00 00 00 0d 00 00 00 02 0f 7f 00 0f c3 0f 7f ................ + | 3952: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 42 ...............B + | 3968: 02 06 17 11 11 01 71 74 61 62 6c 65 74 32 74 32 ......qtablet2t2 + | 3984: 03 43 52 45 41 54 45 20 54 41 42 4c 45 20 74 32 .CREATE TABLE t2 + | 4000: 28 61 20 49 4e 54 2c 20 62 20 41 53 20 28 61 2a (a INT, b AS (a* + | 4016: 32 29 20 53 54 4f 52 45 44 20 4e 4f 54 20 4e 55 2) STORED NOT NU + | 4032: 4c 4c 29 3b 01 06 17 11 11 01 63 74 61 62 6c 65 LL);......ctable + | 4048: 74 31 74 31 02 43 52 45 41 54 45 20 54 41 42 4c t1t1.CREATE TABL + | 4064: 45 20 74 31 28 61 20 49 4e 54 2c 20 62 20 41 53 E t1(a INT, b AS + | 4080: 20 28 61 2a 32 29 20 4e 4f 54 20 4e 55 4c 4c 29 (a*2) NOT NULL) + | page 2 offset 4096 + | 0: 0d 00 00 00 05 0f e7 00 00 00 00 00 00 00 00 00 ................ + | 4064: 00 00 00 00 00 00 00 00 03 05 02 01 05 03 04 02 ................ + | 4080: 01 04 03 03 02 01 03 03 02 02 01 02 02 01 02 09 ................ + | page 3 offset 8192 + | 0: 0d 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + | 4048: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 05 05 ................ + | 4064: 03 01 01 05 0a 05 04 03 01 01 04 08 05 03 03 01 ................ + | 4080: 01 03 06 05 02 03 00 00 00 00 00 00 00 00 00 00 ................ + | end crash-540f4c1eb1e7ac.db + }] +} {} + +do_execsql_test 1.1 { + CREATE TEMP TABLE t2( + a t1 PRIMARY KEY default 27, + b default(current_timestamp), + d TEXT UNIQUE DEFAULT 'ch`arlie', + c TEXT UNIQUE DEFAULT 084, + UNIQUE(c,b,b,a,b) + ) WITHOUT ROWID; + INSERT INTO t1(a) VALUES(zeroblob(40000)); +} + +do_test 1.2 { + execsql { PRAGMA integrity_check; } + execsql { PRAGMA quick_check; } + set {} {} +} {} + +finish_test From 39670a5345e438104d2618480e124ce7581a2f88 Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 27 Feb 2024 15:33:54 +0000 Subject: [PATCH 149/430] Remove unreachable branches from the PRAGMA integrity_check enhancement of [b736519d3d2e93c7]. FossilOrigin-Name: 6d02fb233fb86f9907cc374d06a7ed71a638091d6e75abc199001c42eab51e5c --- manifest | 18 +++++++++--------- manifest.uuid | 2 +- src/btree.c | 8 ++++---- src/pragma.c | 2 +- src/vdbe.c | 2 ++ 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/manifest b/manifest index c7341f42f2..12161e7bd5 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Ensure\smemory\scells\sare\sproperly\sfreed\sbefore\sthey\sare\soverwritten\sby\sOP_IntegrityCk. -D 2024-02-27T14:31:31.983 +C Remove\sunreachable\sbranches\sfrom\sthe\sPRAGMA\sintegrity_check\senhancement\sof\n[b736519d3d2e93c7]. +D 2024-02-27T15:33:54.328 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -689,7 +689,7 @@ F src/auth.c 19b7ccacae3dfba23fc6f1d0af68134fa216e9040e53b0681b4715445ea030b4 F src/backup.c 5c97e8023aab1ce14a42387eb3ae00ba5a0644569e3476f38661fa6f824c3523 F src/bitvec.c 9eac5f42c11914d5ef00a75605bb205e934f435c579687f985f1f8b0995c8645 F src/btmutex.c 79a43670447eacc651519a429f6ece9fd638563cf95b469d6891185ddae2b522 -F src/btree.c 28a97cee62ec9d701ee4d45d034dab1a113a81f0db53773db4c298d79a1dbce1 +F src/btree.c 9f2278fa80de5cd7ef31de42a1ed636c9c5d39d0a0053b1a0bd011f0a6374ad1 F src/btree.h 55066f513eb095db935169dab1dc2f7c7a747ef223c533f5d4ad4dfed346cbd0 F src/btreeInt.h 98aadb6dcb77b012cab2574d6a728fad56b337fc946839b9898c4b4c969e30b6 F src/build.c 04f1bcee189f045ab086d84fee95db42cb49df82ff8e84af8136309ff3c8a75f @@ -743,7 +743,7 @@ F src/parse.y 6209f01e8e7495379571454744fa82a5cfc2e7eeb89e46dee3f410d73ea6252d F src/pcache.c 040b165f30622a21b7a9a77c6f2e4877a32fb7f22d4c7f0d2a6fa6833a156a75 F src/pcache.h 1497ce1b823cf00094bb0cf3bac37b345937e6f910890c626b16512316d3abf5 F src/pcache1.c 602acb23c471bb8d557a6f0083cc2be641d6cafcafa19e481eba7ef4c9ca0f00 -F src/pragma.c 3b6ffa36e3b7520e35e958814f1865d4474e53d5cac87773e2a6b11c2a26adc8 +F src/pragma.c 35d3d604e5a2770b4ac9d7fc22092a06ca8c71784dc0c388d474760af28cfcf8 F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7 F src/prepare.c 371f6115cb69286ebc12c6f2d7511279c2e47d9f54f475d46a554d687a3b312c F src/printf.c 10e8bad30042f8bd6114a013b4afc229ec8ad255ab27518d7d9f52e8cbc5cd0a @@ -820,7 +820,7 @@ F src/upsert.c fa125a8d3410ce9a97b02cb50f7ae68a2476c405c76aa692d3acf6b8586e9242 F src/utf.c f23165685a67b4caf8ec08fb274cb3f319103decfb2a980b7cfd55d18dfa855e F src/util.c 7a49c6a5442757bb6344e7839e0b1f6ba8e54df4e4d092b439c6f6b7035bb01a F src/vacuum.c 604fcdaebe76f3497c855afcbf91b8fa5046b32de3045bab89cc008d68e40104 -F src/vdbe.c f1097e0a5faf9c3939d1431beade2536487be9704ee020416c74eddea46dc4bc +F src/vdbe.c 523a88b3df328810fbcbb407738c352dd9d5163b7af4c953e6e9887a4b582859 F src/vdbe.h c2d78d15112c3fc5ab87f5e8e0b75d2db1c624409de2e858c3d1aafb1650bb4f F src/vdbeInt.h 949669dfd8a41550d27dcb905b494f2ccde9a2e6c1b0b04daa1227e2e74c2b2c F src/vdbeapi.c 8f57d60c89da0b60e6d4e272358c511f6bae4e24330bdb11f8b42f986d1bf21b @@ -2176,8 +2176,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P b736519d3d2e93c76fa36253143f2664b9dd12e26acba555f0bf9c4d44705499 -R 725744da1444e5fefe1d2ce5b7ed4e0a -U dan -Z 55bcecaeff9ae7b0e1973c81cc615ff2 +P e50acaf934f44f8833bc588e0ae1abd59df907b9a42d4cafd5518427a8c7b627 +R 65aed5a318a1485a77b2828f417462c5 +U drh +Z 14ec372b01ad9570d9528860ace49e84 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index e98dc9d1dc..a75c3adf6f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e50acaf934f44f8833bc588e0ae1abd59df907b9a42d4cafd5518427a8c7b627 \ No newline at end of file +6d02fb233fb86f9907cc374d06a7ed71a638091d6e75abc199001c42eab51e5c \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index f5bd5349cc..46c077a038 100644 --- a/src/btree.c +++ b/src/btree.c @@ -11027,7 +11027,9 @@ int sqlite3BtreeIntegrityCheck( int bPartial = 0; /* True if not checking all btrees */ int bCkFreelist = 1; /* True to scan the freelist */ VVA_ONLY( int nRef ); + assert( nRoot>0 ); + assert( aCnt!=0 ); /* aRoot[0]==0 means this is a partial check */ if( aRoot[0]==0 ){ @@ -11101,7 +11103,7 @@ int sqlite3BtreeIntegrityCheck( pBt->db->flags &= ~(u64)SQLITE_CellSizeCk; for(i=0; (int)iautoVacuum && aRoot[i]>1 && !bPartial ){ @@ -11111,9 +11113,7 @@ int sqlite3BtreeIntegrityCheck( sCheck.v0 = aRoot[i]; checkTreePage(&sCheck, aRoot[i], ¬Used, LARGEST_INT64); } - if( aCnt ){ - sqlite3MemSetArrayInt64(aCnt, i, sCheck.nRow); - } + sqlite3MemSetArrayInt64(aCnt, i, sCheck.nRow); } pBt->db->flags = savedDbFlags; diff --git a/src/pragma.c b/src/pragma.c index 529cdc83a1..a3ac1f370f 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -1786,7 +1786,7 @@ void sqlite3Pragma( iTab = cnt++; }else{ iTab = cnt; - for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ + for(pIdx=pTab->pIndex; ALWAYS(pIdx); pIdx=pIdx->pNext){ if( IsPrimaryKeyIndex(pIdx) ) break; iTab++; } diff --git a/src/vdbe.c b/src/vdbe.c index 55f5290ec4..489c4825f4 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -7142,9 +7142,11 @@ case OP_IntegrityCk: { Mem *pnErr; /* Register keeping track of errors remaining */ assert( p->bIsReader ); + assert( pOp->p4type==P4_INTARRAY ); nRoot = pOp->p2; aRoot = pOp->p4.ai; assert( nRoot>0 ); + assert( aRoot!=0 ); assert( aRoot[0]==(Pgno)nRoot ); assert( pOp->p1>0 && (pOp->p1+1)<=(p->nMem+1 - p->nCursor) ); pnErr = &aMem[pOp->p1]; From 2aea6083bdb2c57ca79578e75b33910bd8192d13 Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 27 Feb 2024 16:36:40 +0000 Subject: [PATCH 150/430] Adjust a VdbeCoverage() macro in PRAGMA integrity_check to account for the fact that arguments to the OP_Eq opcode used are never NULL. FossilOrigin-Name: 759ccea3f6e21493c0153f884b601988efd59e409b113b28f8cf23f59a74e418 --- manifest | 13 +++++++------ manifest.uuid | 2 +- src/pragma.c | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 12161e7bd5..23f6c9aa67 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\sunreachable\sbranches\sfrom\sthe\sPRAGMA\sintegrity_check\senhancement\sof\n[b736519d3d2e93c7]. -D 2024-02-27T15:33:54.328 +C Adjust\sa\sVdbeCoverage()\smacro\sin\sPRAGMA\sintegrity_check\sto\saccount\sfor\sthe\nfact\sthat\sarguments\sto\sthe\sOP_Eq\sopcode\sused\sare\snever\sNULL. +D 2024-02-27T16:36:40.485 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -743,7 +743,7 @@ F src/parse.y 6209f01e8e7495379571454744fa82a5cfc2e7eeb89e46dee3f410d73ea6252d F src/pcache.c 040b165f30622a21b7a9a77c6f2e4877a32fb7f22d4c7f0d2a6fa6833a156a75 F src/pcache.h 1497ce1b823cf00094bb0cf3bac37b345937e6f910890c626b16512316d3abf5 F src/pcache1.c 602acb23c471bb8d557a6f0083cc2be641d6cafcafa19e481eba7ef4c9ca0f00 -F src/pragma.c 35d3d604e5a2770b4ac9d7fc22092a06ca8c71784dc0c388d474760af28cfcf8 +F src/pragma.c e8221d6310c9923c80f6fa6d09b7ea7c5263a671f53db8d0894df23efcdb617b F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7 F src/prepare.c 371f6115cb69286ebc12c6f2d7511279c2e47d9f54f475d46a554d687a3b312c F src/printf.c 10e8bad30042f8bd6114a013b4afc229ec8ad255ab27518d7d9f52e8cbc5cd0a @@ -2176,8 +2176,9 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P e50acaf934f44f8833bc588e0ae1abd59df907b9a42d4cafd5518427a8c7b627 -R 65aed5a318a1485a77b2828f417462c5 +P 6d02fb233fb86f9907cc374d06a7ed71a638091d6e75abc199001c42eab51e5c +Q +8c788fc4b2ff21e4f051c9ddc6103ecddf2bbbaf2b6448f1b6dd465d6bd7630d +R aa090c9c9f482341f70a36ba64dc71b9 U drh -Z 14ec372b01ad9570d9528860ace49e84 +Z f5f75171aadd4bf4f2a1819642f85884 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index a75c3adf6f..85bf861b4b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6d02fb233fb86f9907cc374d06a7ed71a638091d6e75abc199001c42eab51e5c \ No newline at end of file +759ccea3f6e21493c0153f884b601988efd59e409b113b28f8cf23f59a74e418 \ No newline at end of file diff --git a/src/pragma.c b/src/pragma.c index a3ac1f370f..d3b0198236 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -1794,7 +1794,7 @@ void sqlite3Pragma( for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ if( pIdx->pPartIdxWhere==0 ){ addr = sqlite3VdbeAddOp3(v, OP_Eq, 8+cnt, 0, 8+iTab); - VdbeCoverage(v); + VdbeCoverageNeverNull(v); sqlite3VdbeLoadString(v, 4, pIdx->zName); sqlite3VdbeAddOp3(v, OP_Concat, 4, 2, 3); integrityCheckResultRow(v); From 6324cdfdcde2362a0e641e41b60a7200563f18fb Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 27 Feb 2024 19:57:31 +0000 Subject: [PATCH 151/430] Add an assert() to help scan-build recognize that a variable is initialized. FossilOrigin-Name: 10d26f1ee8e7624cbb957332b4397d2f1fcdaf916acec93077f2ddd33e01f1d8 --- manifest | 13 ++++++------- manifest.uuid | 2 +- src/btree.c | 1 + 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 23f6c9aa67..90edfbec04 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Adjust\sa\sVdbeCoverage()\smacro\sin\sPRAGMA\sintegrity_check\sto\saccount\sfor\sthe\nfact\sthat\sarguments\sto\sthe\sOP_Eq\sopcode\sused\sare\snever\sNULL. -D 2024-02-27T16:36:40.485 +C Add\san\sassert()\sto\shelp\sscan-build\srecognize\sthat\sa\svariable\sis\sinitialized. +D 2024-02-27T19:57:31.283 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -689,7 +689,7 @@ F src/auth.c 19b7ccacae3dfba23fc6f1d0af68134fa216e9040e53b0681b4715445ea030b4 F src/backup.c 5c97e8023aab1ce14a42387eb3ae00ba5a0644569e3476f38661fa6f824c3523 F src/bitvec.c 9eac5f42c11914d5ef00a75605bb205e934f435c579687f985f1f8b0995c8645 F src/btmutex.c 79a43670447eacc651519a429f6ece9fd638563cf95b469d6891185ddae2b522 -F src/btree.c 9f2278fa80de5cd7ef31de42a1ed636c9c5d39d0a0053b1a0bd011f0a6374ad1 +F src/btree.c 285b493d843e7ba8ef78b6ae7d31238e904901dbc0c484f7904de4cf18fd8802 F src/btree.h 55066f513eb095db935169dab1dc2f7c7a747ef223c533f5d4ad4dfed346cbd0 F src/btreeInt.h 98aadb6dcb77b012cab2574d6a728fad56b337fc946839b9898c4b4c969e30b6 F src/build.c 04f1bcee189f045ab086d84fee95db42cb49df82ff8e84af8136309ff3c8a75f @@ -2176,9 +2176,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 6d02fb233fb86f9907cc374d06a7ed71a638091d6e75abc199001c42eab51e5c -Q +8c788fc4b2ff21e4f051c9ddc6103ecddf2bbbaf2b6448f1b6dd465d6bd7630d -R aa090c9c9f482341f70a36ba64dc71b9 +P 759ccea3f6e21493c0153f884b601988efd59e409b113b28f8cf23f59a74e418 +R c66f74a56da0d53be1c2b9694225d21a U drh -Z f5f75171aadd4bf4f2a1819642f85884 +Z c9bf8cf4057f71ba3123aac76ae5d8bc # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 85bf861b4b..3d2dc9e7b5 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -759ccea3f6e21493c0153f884b601988efd59e409b113b28f8cf23f59a74e418 \ No newline at end of file +10d26f1ee8e7624cbb957332b4397d2f1fcdaf916acec93077f2ddd33e01f1d8 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 46c077a038..ddfa3c63f3 100644 --- a/src/btree.c +++ b/src/btree.c @@ -10914,6 +10914,7 @@ static int checkTreePage( btreeHeapInsert(heap, (pc<<16)|(pc+size-1)); } } + assert( heap!=0 ); /* Add the freeblocks to the min-heap ** ** EVIDENCE-OF: R-20690-50594 The second field of the b-tree page header From b542933cba507c9660dd41df6e73866cc4c7d601 Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 27 Feb 2024 20:19:32 +0000 Subject: [PATCH 152/430] Fix an eputf() macro without its argument in the CLI. FossilOrigin-Name: c2f5e257d2cfb91341f5261ed3924dc4ec2a6f854f3692fb416043f5c654a963 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/shell.c.in | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 90edfbec04..4fc938e015 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\san\sassert()\sto\shelp\sscan-build\srecognize\sthat\sa\svariable\sis\sinitialized. -D 2024-02-27T19:57:31.283 +C Fix\san\seputf()\smacro\swithout\sits\sargument\sin\sthe\sCLI. +D 2024-02-27T20:19:32.980 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -751,7 +751,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c d77c6160bc8f249c2196fdd3e75f66a1dd70e37aa25c39aedc7b1f93c42b7c6d F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c 43fabfc01bf87addd15e39f112f1e2ade15b19594835ab8a9e5bd50839d4e1b1 -F src/shell.c.in 0c13f7cc3bb8c31190efbd96f5c1d8f2fafdbcad549424b7e7850cb5617b115a +F src/shell.c.in 2ec564ed3ff0147036be313efeb47b3dbfb8753d5eb5ea0e90636427c6b3a365 F src/sqlite.h.in 19a2db3995a699bd7f6dfb423856242bfceb7ec849a93c91d241d19fc28d9f0f F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 @@ -2176,8 +2176,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 759ccea3f6e21493c0153f884b601988efd59e409b113b28f8cf23f59a74e418 -R c66f74a56da0d53be1c2b9694225d21a +P 10d26f1ee8e7624cbb957332b4397d2f1fcdaf916acec93077f2ddd33e01f1d8 +R 5abca0ff3e66ec32c7da5aae96062851 U drh -Z c9bf8cf4057f71ba3123aac76ae5d8bc +Z 174bf550e5155919f4d414b95c3db5bd # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 3d2dc9e7b5..d100fcde72 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -10d26f1ee8e7624cbb957332b4397d2f1fcdaf916acec93077f2ddd33e01f1d8 \ No newline at end of file +c2f5e257d2cfb91341f5261ed3924dc4ec2a6f854f3692fb416043f5c654a963 \ No newline at end of file diff --git a/src/shell.c.in b/src/shell.c.in index 07e4b201ce..05583b2f34 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -9185,7 +9185,7 @@ static int do_meta_command(char *zLine, ShellState *p){ if( iArg==0 ) iArg = -1; } if( (nArg!=1 && nArg!=2) || iArg<0 ){ - eputf("Usage: .intck STEPS_PER_UNLOCK\n"); + eputf("%s","Usage: .intck STEPS_PER_UNLOCK\n"); rc = 1; goto meta_command_exit; } From 8597eee1196c263be80f9d03639360b40fe17307 Mon Sep 17 00:00:00 2001 From: drh <> Date: Wed, 28 Feb 2024 01:12:21 +0000 Subject: [PATCH 153/430] Always convert 32-bit integer literals into EP_IntValue notation, even if they contain "_" separators. FossilOrigin-Name: 2dfc427f676255cbe189a26bfec2405d41d31ccc4512c55b31e6e633261d7a23 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/expr.c | 11 ++++++----- src/util.c | 10 ++++++++++ test/literal.test | 7 +++++++ 5 files changed, 32 insertions(+), 14 deletions(-) diff --git a/manifest b/manifest index 4fc938e015..a458d26d4f 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\san\seputf()\smacro\swithout\sits\sargument\sin\sthe\sCLI. -D 2024-02-27T20:19:32.980 +C Always\sconvert\s32-bit\sinteger\sliterals\sinto\sEP_IntValue\snotation,\seven\sif\nthey\scontain\s"_"\sseparators. +D 2024-02-28T01:12:21.520 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -700,7 +700,7 @@ F src/date.c 90df32c2d8b2a38dd2e83d32e47802629305c4882fb2ec75c9ecdcd75b68bcb2 F src/dbpage.c 80e46e1df623ec40486da7a5086cb723b0275a6e2a7b01d9f9b5da0f04ba2782 F src/dbstat.c 3b677254d512fcafd4d0b341bf267b38b235ccfddbef24f9154e19360fa22e43 F src/delete.c cb766727c78e715f9fb7ec8a7d03658ed2a3016343ca687acfcec9083cdca500 -F src/expr.c 3381ee4c9aa7ccde22a2a7f35ce343925a7a25d96bdc943649131f9decdebad2 +F src/expr.c 2803f5e7e3458ced24c0de48ec3640cd7a68ec61350d99c9f30b1bcd6640bd61 F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c a47610f0a5c6cb0ad79f8fcef039c01833dec0c751bb695f28dc0ec6a4c3ba00 F src/func.c 4204c56196847faefef57fa14e43b8e4d65eb8d7e65318abe463472e3fd148cb @@ -818,7 +818,7 @@ F src/trigger.c 0905b96b04bb6658509f711a8207287f1315cdbc3df1a1b13ba6483c8e341c81 F src/update.c 6904814dd62a7a93bbb86d9f1419c7f134a9119582645854ab02b36b676d9f92 F src/upsert.c fa125a8d3410ce9a97b02cb50f7ae68a2476c405c76aa692d3acf6b8586e9242 F src/utf.c f23165685a67b4caf8ec08fb274cb3f319103decfb2a980b7cfd55d18dfa855e -F src/util.c 7a49c6a5442757bb6344e7839e0b1f6ba8e54df4e4d092b439c6f6b7035bb01a +F src/util.c 0765014847e2a06c952dd64aef0bea5144cd5b335a161eb0768ebe4f63dfe216 F src/vacuum.c 604fcdaebe76f3497c855afcbf91b8fa5046b32de3045bab89cc008d68e40104 F src/vdbe.c 523a88b3df328810fbcbb407738c352dd9d5163b7af4c953e6e9887a4b582859 F src/vdbe.h c2d78d15112c3fc5ab87f5e8e0b75d2db1c624409de2e858c3d1aafb1650bb4f @@ -1368,7 +1368,7 @@ F test/like2.test d3be15fefee3e02fc88942a9b98f26c5339bbdef7783c90023c092c4955fe3 F test/like3.test a76e5938fadbe6d32807284c796bafd869974a961057bc5fc5a28e06de98745c F test/limit.test 350f5d03c29e7dff9a2cde016f84f8d368d40bcd02fa2b2a52fa10c4bf3cbfaf F test/limit2.test 9409b033284642a859fafc95f29a5a6a557bd57c1f0d7c3f554bd64ed69df77e -F test/literal.test c4f6f281964ac5ab48a32bd978e80644affac822664879d7558762b2fad7aff5 +F test/literal.test a65dca9fef86e51b8e45544268e37abbd4bb94ba35fd65f6fdcab2f288cd8f79 F test/literal2.tcl 1499037beaf661aeecdbe48801220a181d805372a64c6128d5f26bb6a4a8f0ce F test/literal2.test b149e16b5fc9ee6249069a8858ed41052f222014fe0ba7ad43c2fb989c2dada2 F test/loadext.test faa4f6eed07a5aac35d57fdd7bc07f8fc82464cfd327567c10cf0ba3c86cde04 @@ -2176,8 +2176,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 10d26f1ee8e7624cbb957332b4397d2f1fcdaf916acec93077f2ddd33e01f1d8 -R 5abca0ff3e66ec32c7da5aae96062851 +P c2f5e257d2cfb91341f5261ed3924dc4ec2a6f854f3692fb416043f5c654a963 +R a81000c304b1245e80843833b1cb44da U drh -Z 174bf550e5155919f4d414b95c3db5bd +Z 74cbb43b6190c4a6f68e781473d23cde # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index d100fcde72..25ba439edc 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c2f5e257d2cfb91341f5261ed3924dc4ec2a6f854f3692fb416043f5c654a963 \ No newline at end of file +2dfc427f676255cbe189a26bfec2405d41d31ccc4512c55b31e6e633261d7a23 \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index f9b280bbc5..e2cc15cfd6 100644 --- a/src/expr.c +++ b/src/expr.c @@ -914,11 +914,12 @@ void sqlite3ExprSetErrorOffset(Expr *pExpr, int iOfst){ ** appear to be quoted. If the quotes were of the form "..." (double-quotes) ** then the EP_DblQuoted flag is set on the expression node. ** -** Special case: If op==TK_INTEGER and pToken points to a string that -** can be translated into a 32-bit integer, then the token is not -** stored in u.zToken. Instead, the integer values is written -** into u.iValue and the EP_IntValue flag is set. No extra storage +** Special case (tag-20240227-a): If op==TK_INTEGER and pToken points to +** a string that can be translated into a 32-bit integer, then the token is +** not stored in u.zToken. Instead, the integer values is written +** into u.iValue and the EP_IntValue flag is set. No extra storage ** is allocated to hold the integer text and the dequote flag is ignored. +** See also tag-20240227-b. */ Expr *sqlite3ExprAlloc( sqlite3 *db, /* Handle for sqlite3DbMallocRawNN() */ @@ -934,7 +935,7 @@ Expr *sqlite3ExprAlloc( if( pToken ){ if( op!=TK_INTEGER || pToken->z==0 || sqlite3GetInt32(pToken->z, &iValue)==0 ){ - nExtra = pToken->n+1; + nExtra = pToken->n+1; /* tag-20240227-a */ assert( iValue>=0 ); } } diff --git a/src/util.c b/src/util.c index bdf92d9c4f..311b7385a6 100644 --- a/src/util.c +++ b/src/util.c @@ -317,10 +317,12 @@ void sqlite3DequoteExpr(Expr *p){ ** that contain '_' characters that must be removed before further processing. */ void sqlite3DequoteNumber(Parse *pParse, Expr *p){ + assert( p!=0 || pParse->db->mallocFailed ); if( p ){ const char *pIn = p->u.zToken; char *pOut = p->u.zToken; int bHex = (pIn[0]=='0' && (pIn[1]=='x' || pIn[1]=='X')); + int iValue; assert( p->op==TK_QNUMBER ); p->op = TK_INTEGER; do { @@ -336,6 +338,14 @@ void sqlite3DequoteNumber(Parse *pParse, Expr *p){ } }while( *pIn++ ); if( bHex ) p->op = TK_INTEGER; + + /* tag-20240227-a: If after dequoting, the number is an integer that + ** fits in 32 bits, then it must be converted into EP_IntValue. Other + ** parts of the code expect this. See also tag-20240227-b. */ + if( p->op==TK_INTEGER && sqlite3GetInt32(p->u.zToken, &iValue) ){ + p->u.iValue = iValue; + p->flags |= EP_IntValue; + } } } diff --git a/test/literal.test b/test/literal.test index 30205692c9..5aa331e39b 100644 --- a/test/literal.test +++ b/test/literal.test @@ -93,4 +93,11 @@ foreach {tn lit unrec} { test_literal_error 4.$tn $lit $unrec } +# dbsqlfuzz e3186a9e7826e9cd7f4085aa4452f8696485f9e1 +# See tag-20240224-a and -b +# +do_catchsql_test 5.1 { + SELECT 1 ORDER BY 2_3; +} {1 {1st ORDER BY term out of range - should be between 1 and 1}} + finish_test From 09a71d8d44697adb592ec7064559b1b2145241e6 Mon Sep 17 00:00:00 2001 From: drh <> Date: Wed, 28 Feb 2024 15:32:32 +0000 Subject: [PATCH 154/430] Add in a VdbeCoverage() macro needed by STAT4 that should have been part of check-in [63ef234e88857a65]. FossilOrigin-Name: d51c699ae413215d534f954c129691ef5d95d540dc5d4304cbba576c976d931c --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/analyze.c | 1 + 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index a458d26d4f..ff9e226028 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Always\sconvert\s32-bit\sinteger\sliterals\sinto\sEP_IntValue\snotation,\seven\sif\nthey\scontain\s"_"\sseparators. -D 2024-02-28T01:12:21.520 +C Add\sin\sa\sVdbeCoverage()\smacro\sneeded\sby\sSTAT4\sthat\sshould\shave\sbeen\spart\sof\ncheck-in\s[63ef234e88857a65]. +D 2024-02-28T15:32:32.228 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -683,7 +683,7 @@ F sqlite3.1 acdff36db796e2d00225b911d3047d580cd136547298435426ce9d40347973cc F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a F sqlite_cfg.h.in baf2e409c63d4e7a765e17769b6ff17c5a82bbd9cbf1e284fd2e4cefaff3fcf2 F src/alter.c 30c2333b8bb3af71e4eb9adeadee8aa20edb15917ed44b8422e5cd15f3dfcddc -F src/analyze.c dacc8f062bbda02c8ed3bbca0ab6122de010d094101d568df266a7b0d665d74f +F src/analyze.c a3df28274e2565ba5656577d7e3fd262169a213e6eb0bd47890e0f0729a4031c F src/attach.c cc9d00d30da916ff656038211410ccf04ed784b7564639b9b61d1839ed69fd39 F src/auth.c 19b7ccacae3dfba23fc6f1d0af68134fa216e9040e53b0681b4715445ea030b4 F src/backup.c 5c97e8023aab1ce14a42387eb3ae00ba5a0644569e3476f38661fa6f824c3523 @@ -2176,8 +2176,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P c2f5e257d2cfb91341f5261ed3924dc4ec2a6f854f3692fb416043f5c654a963 -R a81000c304b1245e80843833b1cb44da +P 2dfc427f676255cbe189a26bfec2405d41d31ccc4512c55b31e6e633261d7a23 +R fc556e11bf89363bdfe386e7578ab33b U drh -Z 74cbb43b6190c4a6f68e781473d23cde +Z 7f63c0d877ef8881aed016b2612db7ff # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 25ba439edc..709e981bf9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2dfc427f676255cbe189a26bfec2405d41d31ccc4512c55b31e6e633261d7a23 \ No newline at end of file +d51c699ae413215d534f954c129691ef5d95d540dc5d4304cbba576c976d931c \ No newline at end of file diff --git a/src/analyze.c b/src/analyze.c index e7c1068ae0..8c48a8ff2a 100644 --- a/src/analyze.c +++ b/src/analyze.c @@ -1296,6 +1296,7 @@ static void analyzeOneTable( if( addrGotoEnd==0 ){ sqlite3VdbeAddOp2(v, OP_Cast, regStat1, SQLITE_AFF_INTEGER); addrGotoEnd = sqlite3VdbeAddOp1(v, OP_IfNot, regStat1); + VdbeCoverage(v); } if( doOnce ){ From 087e6c9ada2306e34a9dddd6e1b4eb8565d14502 Mon Sep 17 00:00:00 2001 From: stephan Date: Thu, 29 Feb 2024 03:45:18 +0000 Subject: [PATCH 155/430] Fix two -Werror=lto-type-mismatch warnings reported in [forum:ef62b57bd5|forum post ef62b57bd5]. FossilOrigin-Name: 29f94610dc8319709b8d3726a60e2a7a33ffbf4998c681f772da26c9701cc0b0 --- manifest | 17 ++++++++++------- manifest.uuid | 2 +- test/fuzzcheck.c | 4 ++-- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index ff9e226028..2f85e3833f 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sin\sa\sVdbeCoverage()\smacro\sneeded\sby\sSTAT4\sthat\sshould\shave\sbeen\spart\sof\ncheck-in\s[63ef234e88857a65]. -D 2024-02-28T15:32:32.228 +C Fix\stwo\s-Werror=lto-type-mismatch\swarnings\sreported\sin\s[forum:ef62b57bd5|forum\spost\sef62b57bd5]. +D 2024-02-29T03:45:18.006 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -1244,7 +1244,7 @@ F test/fuzz3.test 9c813e6613b837cb7a277b0383cd66bfa07042b4cf0317157c35852f30043c F test/fuzz4.test c229bcdb45518a89e1d208a21343e061503460ac69fae1539320a89f572eb634 F test/fuzz_common.tcl b7197de6ed1ee8250a4f82d67876f4561b42ee8cbbfc6160dcb66331bad3f830 F test/fuzz_malloc.test f348276e732e814802e39f042b1f6da6362a610af73a528d8f76898fde6b22f2 -F test/fuzzcheck.c 7e1bcc242dc4b42e43e4708c8140fe268db83a6901fbc681d150c77aa185e328 +F test/fuzzcheck.c e6a40f53ac5624aa5b7c4f31c385f09ba088d524cecc4512fd3057caeed8f530 F test/fuzzdata1.db 3e86d9cf5aea68ddb8e27c02d7dfdaa226347426c7eb814918e4d95475bf8517 F test/fuzzdata2.db 128b3feeb78918d075c9b14b48610145a0dd4c8d6f1ca7c2870c7e425f5bf31f F test/fuzzdata3.db c6586d3e3cef0fbc18108f9bb649aa77bfc38aba @@ -2176,8 +2176,11 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 2dfc427f676255cbe189a26bfec2405d41d31ccc4512c55b31e6e633261d7a23 -R fc556e11bf89363bdfe386e7578ab33b -U drh -Z 7f63c0d877ef8881aed016b2612db7ff +P d51c699ae413215d534f954c129691ef5d95d540dc5d4304cbba576c976d931c +R 728f9a968510fa9cb95ea7ce7eec45f1 +T *branch * lto-type-mismatch +T *sym-lto-type-mismatch * +T -sym-trunk * Cancelled\sby\sbranch. +U stephan +Z 4ef24b5fab0d660b380d1bcfc2ce1289 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 709e981bf9..83e3daf352 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d51c699ae413215d534f954c129691ef5d95d540dc5d4304cbba576c976d931c \ No newline at end of file +29f94610dc8319709b8d3726a60e2a7a33ffbf4998c681f772da26c9701cc0b0 \ No newline at end of file diff --git a/test/fuzzcheck.c b/test/fuzzcheck.c index dd49120115..e4ad1c1137 100644 --- a/test/fuzzcheck.c +++ b/test/fuzzcheck.c @@ -161,8 +161,8 @@ static struct GlobalVars { /* ** Include the external vt02.c and randomjson.c modules. */ -extern int sqlite3_vt02_init(sqlite3*,char***,void*); -extern int sqlite3_randomjson_init(sqlite3*,char***,void*); +extern int sqlite3_vt02_init(sqlite3*,char**,const sqlite3_api_routines*); +extern int sqlite3_randomjson_init(sqlite3*,char**,const sqlite3_api_routines*); /* From 696400584766e3c49edf22863ce463c6655ea775 Mon Sep 17 00:00:00 2001 From: drh <> Date: Sat, 2 Mar 2024 13:38:46 +0000 Subject: [PATCH 156/430] Proof-of-concept for new time-interval operator "pg-month" and "pg-year" that use the truncate-to-month algorithm for month overflow instead of the wrap-to-next-month algorithm that is used by SQLite by default. FossilOrigin-Name: b606c0965788f56547435c9318b60e32990877e14a9640d887f33f39d1bdc7c3 --- manifest | 18 ++++++++++-------- manifest.uuid | 2 +- src/date.c | 35 ++++++++++++++++++++++++++--------- 3 files changed, 37 insertions(+), 18 deletions(-) diff --git a/manifest b/manifest index 28b15c7a43..9ca9c979c5 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\stwo\s-Werror=lto-type-mismatch\swarnings\sreported\sin\s[forum:ef62b57bd5|forum\spost\sef62b57bd5]. -D 2024-02-29T10:55:02.008 +C Proof-of-concept\sfor\snew\stime-interval\soperator\s"pg-month"\sand\s"pg-year"\sthat\nuse\sthe\struncate-to-month\salgorithm\sfor\smonth\soverflow\sinstead\sof\sthe\nwrap-to-next-month\salgorithm\sthat\sis\sused\sby\sSQLite\sby\sdefault. +D 2024-03-02T13:38:46.691 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -696,7 +696,7 @@ F src/build.c 04f1bcee189f045ab086d84fee95db42cb49df82ff8e84af8136309ff3c8a75f F src/callback.c db3a45e376deff6a16c0058163fe0ae2b73a2945f3f408ca32cf74960b28d490 F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e F src/ctime.c 23331529e654be40ca97d171cbbffe9b3d4c71cc53b78fe5501230675952da8b -F src/date.c 90df32c2d8b2a38dd2e83d32e47802629305c4882fb2ec75c9ecdcd75b68bcb2 +F src/date.c f0bde50092368a0eaff79e25ab24c3c91763859adffd91af6bf47cbc13cc7512 F src/dbpage.c 80e46e1df623ec40486da7a5086cb723b0275a6e2a7b01d9f9b5da0f04ba2782 F src/dbstat.c 3b677254d512fcafd4d0b341bf267b38b235ccfddbef24f9154e19360fa22e43 F src/delete.c cb766727c78e715f9fb7ec8a7d03658ed2a3016343ca687acfcec9083cdca500 @@ -2176,9 +2176,11 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P d51c699ae413215d534f954c129691ef5d95d540dc5d4304cbba576c976d931c 29f94610dc8319709b8d3726a60e2a7a33ffbf4998c681f772da26c9701cc0b0 -R 728f9a968510fa9cb95ea7ce7eec45f1 -T +closed 29f94610dc8319709b8d3726a60e2a7a33ffbf4998c681f772da26c9701cc0b0 Closed\sby\sintegrate-merge. -U stephan -Z 37dee8fa6539319388e07ab4c515c697 +P 803481f25020f3c25941f1e7d1a8071937820dea951e8798198b0b0fa3fb48ce +R 736136842d7746223f17212059cfe765 +T *branch * month-truncate +T *sym-month-truncate * +T -sym-trunk * +U drh +Z e1892067371eb0569faf26bcf07d7955 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 2f2c96f612..5a462d35fa 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -803481f25020f3c25941f1e7d1a8071937820dea951e8798198b0b0fa3fb48ce \ No newline at end of file +b606c0965788f56547435c9318b60e32990877e14a9640d887f33f39d1bdc7c3 \ No newline at end of file diff --git a/src/date.c b/src/date.c index 026d83391a..fd225d1e29 100644 --- a/src/date.c +++ b/src/date.c @@ -626,16 +626,18 @@ static int toLocaltime( */ static const struct { u8 nName; /* Length of the name */ - char zName[7]; /* Name of the transformation */ + char zName[9]; /* Name of the transformation */ float rLimit; /* Maximum NNN value for this transform */ float rXform; /* Constant used for this transform */ } aXformType[] = { - { 6, "second", 4.6427e+14, 1.0 }, - { 6, "minute", 7.7379e+12, 60.0 }, - { 4, "hour", 1.2897e+11, 3600.0 }, - { 3, "day", 5373485.0, 86400.0 }, - { 5, "month", 176546.0, 2592000.0 }, - { 4, "year", 14713.0, 31536000.0 }, + { 6, "second", 4.6427e+14, 1.0 }, + { 6, "minute", 7.7379e+12, 60.0 }, + { 4, "hour", 1.2897e+11, 3600.0 }, + { 3, "day", 5373485.0, 86400.0 }, + { 5, "month", 176546.0, 2592000.0 }, + { 4, "year", 14713.0, 31536000.0 }, + { 8, "pg-month", 176546.0, 2592000.0 }, + { 7, "pg-year", 14713.0, 31536000.0 }, }; /* @@ -966,22 +968,31 @@ static int parseModifier( && sqlite3_strnicmp(aXformType[i].zName, z, n)==0 && r>-aXformType[i].rLimit && rM += (int)r; x = p->M>0 ? (p->M-1)/12 : (p->M-12)/12; p->Y += x; p->M -= x*12; + assert( p->M>=1 && p->M<=12 ); + if( i==6 ) targetMonth = p->M; p->validJD = 0; r -= (int)r; break; } + case 7: case 5: { /* Special processing to add years */ int y = (int)r; - assert( strcmp(aXformType[i].zName,"year")==0 ); + assert( strcmp(aXformType[i].zName,"year")==0 + || strcmp(aXformType[i].zName,"pg-year")==0 ); computeYMD_HMS(p); + assert( p->M>=1 && p->M<=12 ); + if( i==7 ) targetMonth = p->M; p->Y += y; p->validJD = 0; r -= (int)r; @@ -989,6 +1000,12 @@ static int parseModifier( } } computeJD(p); + if( targetMonth>0 ){ + p->validYMD = 0; + computeYMD(p); + if( p->M==targetMonth+1 ) p->iJD -= p->D*86400000; + p->validYMD = 0; + } p->iJD += (sqlite3_int64)(r*1000.0*aXformType[i].rXform + rRounder); rc = 0; break; From f52afaf738f97ea024d54cfb8fb17fa11fc4fe5e Mon Sep 17 00:00:00 2001 From: drh <> Date: Sat, 2 Mar 2024 20:50:56 +0000 Subject: [PATCH 157/430] Change the magic time-interval names that do truncate-to-same-month to be "mnth" and "yr" - "month" and "year" without the vowels. FossilOrigin-Name: 296b46c529d79385d7f4db2c789254a992c01ff66fe8ba6d3a3ce4aaac0203fb --- manifest | 17 +++++++---------- manifest.uuid | 2 +- src/date.c | 38 +++++++++++++++++++------------------- test/date.test | 9 +++++++++ 4 files changed, 36 insertions(+), 30 deletions(-) diff --git a/manifest b/manifest index 9ca9c979c5..ad4067ae8c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Proof-of-concept\sfor\snew\stime-interval\soperator\s"pg-month"\sand\s"pg-year"\sthat\nuse\sthe\struncate-to-month\salgorithm\sfor\smonth\soverflow\sinstead\sof\sthe\nwrap-to-next-month\salgorithm\sthat\sis\sused\sby\sSQLite\sby\sdefault. -D 2024-03-02T13:38:46.691 +C Change\sthe\smagic\stime-interval\snames\sthat\sdo\struncate-to-same-month\sto\sbe\n"mnth"\sand\s"yr"\s-\s"month"\sand\s"year"\swithout\sthe\svowels. +D 2024-03-02T20:50:56.172 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -696,7 +696,7 @@ F src/build.c 04f1bcee189f045ab086d84fee95db42cb49df82ff8e84af8136309ff3c8a75f F src/callback.c db3a45e376deff6a16c0058163fe0ae2b73a2945f3f408ca32cf74960b28d490 F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e F src/ctime.c 23331529e654be40ca97d171cbbffe9b3d4c71cc53b78fe5501230675952da8b -F src/date.c f0bde50092368a0eaff79e25ab24c3c91763859adffd91af6bf47cbc13cc7512 +F src/date.c 89083264f1832e2bb892d6b313a6c642a5cd730cfcc89574019aa06c69192dcd F src/dbpage.c 80e46e1df623ec40486da7a5086cb723b0275a6e2a7b01d9f9b5da0f04ba2782 F src/dbstat.c 3b677254d512fcafd4d0b341bf267b38b235ccfddbef24f9154e19360fa22e43 F src/delete.c cb766727c78e715f9fb7ec8a7d03658ed2a3016343ca687acfcec9083cdca500 @@ -1042,7 +1042,7 @@ F test/ctime.test 340f362f41f92972bbd71f44e10569a5cc694062b692231bd08aa6fe6c1c47 F test/cursorhint.test 05cf0febe5c5f8a31f199401fd1c9322249e753950d55f26f9d5aca61408a270 F test/cursorhint2.test 6f3aa9cb19e7418967a10ec6905209bcbb5968054da855fc36c8beee9ae9c42f F test/dataversion1.test 6e5e86ac681f0782e766ebcb56c019ae001522d114e0e111e5ebf68ccf2a7bb8 -F test/date.test b1a5208e6a9c390cf1d1fa4e38a910386b427b0e27046901c6b0fb995d19800e +F test/date.test 9583b421058d8366a06d4a07135ced29b64e31b5e7dafd03a2040bf84ef69adb F test/date2.test 7e12ec14aaf4d5e6294b4ba140445b0eca06ea50062a9c3a69c4ee13d0b6f8b1 F test/date3.test a1b77abf05c6772fe5ca2337cac1398892f2a41e62bce7e6be0f4a08a0e64ae5 F test/date4.test 75dc8401e8c0639a228cd26a6eaa4ff5ea8ccda912b9853d1c9462c476670e17 @@ -2176,11 +2176,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 803481f25020f3c25941f1e7d1a8071937820dea951e8798198b0b0fa3fb48ce -R 736136842d7746223f17212059cfe765 -T *branch * month-truncate -T *sym-month-truncate * -T -sym-trunk * +P b606c0965788f56547435c9318b60e32990877e14a9640d887f33f39d1bdc7c3 +R e86e5c292ead4f22cefd158cafe4f8bc U drh -Z e1892067371eb0569faf26bcf07d7955 +Z 74c79cb89bee4e9b933a0e487d4797f3 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 5a462d35fa..607ef1e19e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b606c0965788f56547435c9318b60e32990877e14a9640d887f33f39d1bdc7c3 \ No newline at end of file +296b46c529d79385d7f4db2c789254a992c01ff66fe8ba6d3a3ce4aaac0203fb \ No newline at end of file diff --git a/src/date.c b/src/date.c index fd225d1e29..d4c3afdd38 100644 --- a/src/date.c +++ b/src/date.c @@ -626,18 +626,18 @@ static int toLocaltime( */ static const struct { u8 nName; /* Length of the name */ - char zName[9]; /* Name of the transformation */ + char zName[7]; /* Name of the transformation */ float rLimit; /* Maximum NNN value for this transform */ float rXform; /* Constant used for this transform */ } aXformType[] = { - { 6, "second", 4.6427e+14, 1.0 }, - { 6, "minute", 7.7379e+12, 60.0 }, - { 4, "hour", 1.2897e+11, 3600.0 }, - { 3, "day", 5373485.0, 86400.0 }, - { 5, "month", 176546.0, 2592000.0 }, - { 4, "year", 14713.0, 31536000.0 }, - { 8, "pg-month", 176546.0, 2592000.0 }, - { 7, "pg-year", 14713.0, 31536000.0 }, + /* 0 */ { 6, "second", 4.6427e+14, 1.0 }, + /* 1 */ { 6, "minute", 7.7379e+12, 60.0 }, + /* 2 */ { 4, "hour", 1.2897e+11, 3600.0 }, + /* 3 */ { 3, "day", 5373485.0, 86400.0 }, + /* 4 */ { 5, "month", 176546.0, 30.0*86400.0 }, + /* 5 */ { 4, "mnth", 176546.0, 30.0*86400.0 }, + /* 6 */ { 4, "year", 14713.0, 365.0*86400.0 }, + /* 7 */ { 2, "yr", 14713.0, 365.0*86400.0 }, }; /* @@ -958,7 +958,7 @@ static int parseModifier( z += n; while( sqlite3Isspace(*z) ) z++; n = sqlite3Strlen30(z); - if( n>10 || n<3 ) break; + if( n>10 || n<2 ) break; if( sqlite3UpperToLower[(u8)z[n-1]]=='s' ) n--; computeJD(p); assert( rc==1 ); @@ -970,26 +970,26 @@ static int parseModifier( ){ int targetMonth = 0; switch( i ){ - case 6: - case 4: { /* Special processing to add months */ - assert( strcmp(aXformType[i].zName,"month")==0 - || strcmp(aXformType[i].zName,"pg-month")==0 ); + case 4: + case 5: { /* Special processing to add months */ + assert( strcmp(aXformType[4].zName,"month")==0 ); + assert( strcmp(aXformType[5].zName,"mnth")==0 ); computeYMD_HMS(p); p->M += (int)r; x = p->M>0 ? (p->M-1)/12 : (p->M-12)/12; p->Y += x; p->M -= x*12; assert( p->M>=1 && p->M<=12 ); - if( i==6 ) targetMonth = p->M; + if( i==5 ) targetMonth = p->M; p->validJD = 0; r -= (int)r; break; } - case 7: - case 5: { /* Special processing to add years */ + case 6: + case 7: { /* Special processing to add years */ int y = (int)r; - assert( strcmp(aXformType[i].zName,"year")==0 - || strcmp(aXformType[i].zName,"pg-year")==0 ); + assert( strcmp(aXformType[6].zName,"year")==0 ); + assert( strcmp(aXformType[7].zName,"yr")==0 ); computeYMD_HMS(p); assert( p->M>=1 && p->M<=12 ); if( i==7 ) targetMonth = p->M; diff --git a/test/date.test b/test/date.test index d536c65fce..f0616f6570 100644 --- a/test/date.test +++ b/test/date.test @@ -148,6 +148,15 @@ datetest 2.51 {datetime('2003-10-22 12:24','nonsense')} NULL datetest 2.60 {datetime('2023-02-31')} {2023-03-03 00:00:00} +datetest 2.70 {date('2024-01-31','+1 month')} {2024-03-02} +datetest 2.71 {date('2024-01-31','+1 mnth')} {2024-02-29} +datetest 2.72 {date('2023-01-31','+1 month')} {2023-03-03} +datetest 2.73 {date('2023-01-31','+1 mnth')} {2023-02-28} +datetest 2.74 {date('2024-02-29','+1 year')} {2025-03-01} +datetest 2.75 {date('2024-02-29','+1 yr')} {2025-02-28} +datetest 2.76 {date('2024-02-29','-110 years')} {1914-03-01} +datetest 2.77 {date('2024-02-29','-110 yrs')} {1914-02-28} + datetest 3.1 {strftime('%d','2003-10-31 12:34:56.432')} 31 datetest 3.2.1 {strftime('pre%fpost','2003-10-31 12:34:56.432')} pre56.432post datetest 3.2.2 {strftime('%f','2003-10-31 12:34:59.9999999')} 59.999 From aefa7afddbe11afa11aa972fe096d34ec0338ce2 Mon Sep 17 00:00:00 2001 From: drh <> Date: Sun, 3 Mar 2024 20:15:36 +0000 Subject: [PATCH 158/430] Back out the previous change. Replace it with new date modifiers "ceiling" and "floor". FossilOrigin-Name: f0831cced2c919e409214d936c81473ae321a98c5bd78b5b729c1269bf71bc45 --- manifest | 15 ++++---- manifest.uuid | 2 +- src/date.c | 100 ++++++++++++++++++++++++++++++++++++------------- test/date.test | 56 ++++++++++++++++++++++----- 4 files changed, 130 insertions(+), 43 deletions(-) diff --git a/manifest b/manifest index 8e0dc8a667..69581e9a5b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C New\sdate/time\smodifiers\s"mnth"\sand\s"yr"\swork\slike\s"month"\sand\s"year"\sbut\nresolve\sday-of-month\soverflow\sby\struncating\srather\sthan\srolling\sover\sinto\nthe\snext\smonth.\s[forum:/forumpost/232d1abb5d|Forum\sthread\s232d1abb5d] -D 2024-03-02T21:02:41.160 +C Back\sout\sthe\sprevious\schange.\s\sReplace\sit\swith\snew\sdate\smodifiers\s"ceiling"\nand\s"floor". +D 2024-03-03T20:15:36.398 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -696,7 +696,7 @@ F src/build.c 04f1bcee189f045ab086d84fee95db42cb49df82ff8e84af8136309ff3c8a75f F src/callback.c db3a45e376deff6a16c0058163fe0ae2b73a2945f3f408ca32cf74960b28d490 F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e F src/ctime.c 23331529e654be40ca97d171cbbffe9b3d4c71cc53b78fe5501230675952da8b -F src/date.c 89083264f1832e2bb892d6b313a6c642a5cd730cfcc89574019aa06c69192dcd +F src/date.c b36a3cc75ac691bf72b4759130b04ac2926af6fd4ca98df3400ff20d34a15878 F src/dbpage.c 80e46e1df623ec40486da7a5086cb723b0275a6e2a7b01d9f9b5da0f04ba2782 F src/dbstat.c 3b677254d512fcafd4d0b341bf267b38b235ccfddbef24f9154e19360fa22e43 F src/delete.c cb766727c78e715f9fb7ec8a7d03658ed2a3016343ca687acfcec9083cdca500 @@ -1042,7 +1042,7 @@ F test/ctime.test 340f362f41f92972bbd71f44e10569a5cc694062b692231bd08aa6fe6c1c47 F test/cursorhint.test 05cf0febe5c5f8a31f199401fd1c9322249e753950d55f26f9d5aca61408a270 F test/cursorhint2.test 6f3aa9cb19e7418967a10ec6905209bcbb5968054da855fc36c8beee9ae9c42f F test/dataversion1.test 6e5e86ac681f0782e766ebcb56c019ae001522d114e0e111e5ebf68ccf2a7bb8 -F test/date.test 9583b421058d8366a06d4a07135ced29b64e31b5e7dafd03a2040bf84ef69adb +F test/date.test 99bfd3a77a3f9ae54eebd374a4301af960f2b2e9a581cf63e26445bae830a435 F test/date2.test 7e12ec14aaf4d5e6294b4ba140445b0eca06ea50062a9c3a69c4ee13d0b6f8b1 F test/date3.test a1b77abf05c6772fe5ca2337cac1398892f2a41e62bce7e6be0f4a08a0e64ae5 F test/date4.test 75dc8401e8c0639a228cd26a6eaa4ff5ea8ccda912b9853d1c9462c476670e17 @@ -2176,9 +2176,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 803481f25020f3c25941f1e7d1a8071937820dea951e8798198b0b0fa3fb48ce 296b46c529d79385d7f4db2c789254a992c01ff66fe8ba6d3a3ce4aaac0203fb -R e86e5c292ead4f22cefd158cafe4f8bc -T +closed 296b46c529d79385d7f4db2c789254a992c01ff66fe8ba6d3a3ce4aaac0203fb +P 5d392c16bb5658bc92f60d250ab82c45cc109e32d58a073498c9a487b8625e96 +R 9967c002ac0a5c05f7a39fb253518624 U drh -Z b02519e2fed4e4d80162d593e160efa1 +Z 10e35251deea062b6c8093330abd75ed # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index d954bb7e4a..deb11dc730 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5d392c16bb5658bc92f60d250ab82c45cc109e32d58a073498c9a487b8625e96 \ No newline at end of file +f0831cced2c919e409214d936c81473ae321a98c5bd78b5b729c1269bf71bc45 \ No newline at end of file diff --git a/src/date.c b/src/date.c index d4c3afdd38..37bf7fdb4f 100644 --- a/src/date.c +++ b/src/date.c @@ -71,13 +71,14 @@ struct DateTime { int tz; /* Timezone offset in minutes */ double s; /* Seconds */ char validJD; /* True (1) if iJD is valid */ - char rawS; /* Raw numeric value stored in s */ char validYMD; /* True (1) if Y,M,D are valid */ char validHMS; /* True (1) if h,m,s are valid */ char validTZ; /* True (1) if tz is valid */ - char tzSet; /* Timezone was set explicitly */ - char isError; /* An overflow has occurred */ - char useSubsec; /* Display subsecond precision */ + char nFloor; /* Days to implement "floor" */ + unsigned rawS : 1; /* Raw numeric value stored in s */ + unsigned tzSet : 1; /* Timezone was set explicitly */ + unsigned isError : 1; /* An overflow has occurred */ + unsigned useSubsec : 1; /* Display subsecond precision */ }; @@ -287,6 +288,29 @@ static void computeJD(DateTime *p){ } } +/* +** Given the YYYY-MM-DD information current in p, determine if there +** is day-of-month overflow and set nFloor to the number of days that +** would need to be subtracted from the date in order to bring the +** date back to the end of the month. +*/ +static void computeFloor(DateTime *p){ + assert( p->validYMD || p->isError ); + assert( (p->D>=1 && p->D<=31) || p->isError ); + assert( (p->M>=1 && p->M<=12) || p->isError ); + if( p->D<=28 ){ + p->nFloor = 0; + }else if( (1<M) & 0x15aa ){ + p->nFloor = 0; + }else if( p->M!=2 ){ + p->nFloor = (p->D==31); + }else if( p->Y%4!=0 || (p->Y%100==0 && p->Y%400!=0) ){ + p->nFloor = p->D - 28; + }else{ + p->nFloor = p->D - 29; + } +} + /* ** Parse dates of the form ** @@ -325,6 +349,7 @@ static int parseYyyyMmDd(const char *zDate, DateTime *p){ p->Y = neg ? -Y : Y; p->M = M; p->D = D; + computeFloor(p); if( p->validTZ ){ computeJD(p); } @@ -635,9 +660,7 @@ static const struct { /* 2 */ { 4, "hour", 1.2897e+11, 3600.0 }, /* 3 */ { 3, "day", 5373485.0, 86400.0 }, /* 4 */ { 5, "month", 176546.0, 30.0*86400.0 }, - /* 5 */ { 4, "mnth", 176546.0, 30.0*86400.0 }, - /* 6 */ { 4, "year", 14713.0, 365.0*86400.0 }, - /* 7 */ { 2, "yr", 14713.0, 365.0*86400.0 }, + /* 5 */ { 4, "year", 14713.0, 365.0*86400.0 }, }; /* @@ -669,14 +692,20 @@ static void autoAdjustDate(DateTime *p){ ** NNN.NNNN seconds ** NNN months ** NNN years +** +/-YYYY-MM-DD HH:MM:SS.SSS +** ceiling +** floor ** start of month ** start of year ** start of week ** start of day ** weekday N ** unixepoch +** auto ** localtime ** utc +** subsec +** subsecond ** ** Return 0 on success and 1 if there is any kind of error. If the error ** is in a system call (i.e. localtime()), then an error message is written @@ -707,6 +736,37 @@ static int parseModifier( } break; } + case 'c': { + /* + ** ceiling + ** + ** Resolve day-of-month overflow by rolling forward into the next + ** month. As this is the default action, this modifier is really + ** a no-op that is only included for symmetry. See "floor". + */ + if( sqlite3_stricmp(z, "ceiling")==0 ){ + computeJD(p); + clearYMD_HMS_TZ(p); + rc = 0; + p->nFloor = 0; + } + break; + } + case 'f': { + /* + ** floor + ** + ** Resolve day-of-month overflow by rolling back to the end of the + ** previous month. + */ + if( sqlite3_stricmp(z, "floor")==0 ){ + computeJD(p); + p->iJD -= p->nFloor*86400000; + clearYMD_HMS_TZ(p); + rc = 0; + } + break; + } case 'j': { /* ** julianday @@ -912,6 +972,7 @@ static int parseModifier( x = p->M>0 ? (p->M-1)/12 : (p->M-12)/12; p->Y += x; p->M -= x*12; + computeFloor(p); computeJD(p); p->validHMS = 0; p->validYMD = 0; @@ -958,54 +1019,43 @@ static int parseModifier( z += n; while( sqlite3Isspace(*z) ) z++; n = sqlite3Strlen30(z); - if( n>10 || n<2 ) break; + if( n<3 || n>10 ) break; if( sqlite3UpperToLower[(u8)z[n-1]]=='s' ) n--; computeJD(p); assert( rc==1 ); rRounder = r<0 ? -0.5 : +0.5; + p->nFloor = 0; for(i=0; i-aXformType[i].rLimit && rM += (int)r; x = p->M>0 ? (p->M-1)/12 : (p->M-12)/12; p->Y += x; p->M -= x*12; - assert( p->M>=1 && p->M<=12 ); - if( i==5 ) targetMonth = p->M; + computeFloor(p); p->validJD = 0; r -= (int)r; break; } - case 6: - case 7: { /* Special processing to add years */ + case 5: { /* Special processing to add years */ int y = (int)r; - assert( strcmp(aXformType[6].zName,"year")==0 ); - assert( strcmp(aXformType[7].zName,"yr")==0 ); + assert( strcmp(aXformType[5].zName,"year")==0 ); computeYMD_HMS(p); assert( p->M>=1 && p->M<=12 ); - if( i==7 ) targetMonth = p->M; p->Y += y; + computeFloor(p); p->validJD = 0; r -= (int)r; break; } } computeJD(p); - if( targetMonth>0 ){ - p->validYMD = 0; - computeYMD(p); - if( p->M==targetMonth+1 ) p->iJD -= p->D*86400000; - p->validYMD = 0; - } p->iJD += (sqlite3_int64)(r*1000.0*aXformType[i].rXform + rRounder); rc = 0; break; diff --git a/test/date.test b/test/date.test index f0616f6570..2a6e93df40 100644 --- a/test/date.test +++ b/test/date.test @@ -148,15 +148,6 @@ datetest 2.51 {datetime('2003-10-22 12:24','nonsense')} NULL datetest 2.60 {datetime('2023-02-31')} {2023-03-03 00:00:00} -datetest 2.70 {date('2024-01-31','+1 month')} {2024-03-02} -datetest 2.71 {date('2024-01-31','+1 mnth')} {2024-02-29} -datetest 2.72 {date('2023-01-31','+1 month')} {2023-03-03} -datetest 2.73 {date('2023-01-31','+1 mnth')} {2023-02-28} -datetest 2.74 {date('2024-02-29','+1 year')} {2025-03-01} -datetest 2.75 {date('2024-02-29','+1 yr')} {2025-02-28} -datetest 2.76 {date('2024-02-29','-110 years')} {1914-03-01} -datetest 2.77 {date('2024-02-29','-110 yrs')} {1914-02-28} - datetest 3.1 {strftime('%d','2003-10-31 12:34:56.432')} 31 datetest 3.2.1 {strftime('pre%fpost','2003-10-31 12:34:56.432')} pre56.432post datetest 3.2.2 {strftime('%f','2003-10-31 12:34:59.9999999')} 59.999 @@ -582,4 +573,51 @@ datetest 18.2 {unixepoch('1970-01-01T00:00:00.1', 'subsec')} {0.1} datetest 18.3 {unixepoch('1970-01-01T00:00:00.2', 'subsecond')} {0.2} datetest 18.4 {julianday('-4713-11-24 13:40:48.864', 'subsec')} {0.07001} datetest 18.5 {typeof(unixepoch('now', 'subsecond'))} {real} + +# 2024-03-03 the 'ceiling' and 'floor' operators. +# +datetest 19.1 {date('2000-01-31','floor')} {2000-01-31} +datetest 19.2a {date('2000-02-31','floor')} {2000-02-29} +datetest 19.2b {date('1999-02-31','floor')} {1999-02-28} +datetest 19.2c {date('1900-02-31','floor')} {1900-02-28} +datetest 19.3 {date('2000-03-31','floor')} {2000-03-31} +datetest 19.4 {date('2000-04-31','floor')} {2000-04-30} +datetest 19.5 {date('2000-05-31','floor')} {2000-05-31} +datetest 19.6 {date('2000-06-31','floor')} {2000-06-30} +datetest 19.7 {date('2000-07-31','floor')} {2000-07-31} +datetest 19.8 {date('2000-08-31','floor')} {2000-08-31} +datetest 19.9 {date('2000-09-31','floor')} {2000-09-30} +datetest 19.10 {date('2000-10-31','floor')} {2000-10-31} +datetest 19.11 {date('2000-11-31','floor')} {2000-11-30} +datetest 19.12 {date('2000-12-31','floor')} {2000-12-31} +datetest 19.21 {date('2000-01-31','ceiling')} {2000-01-31} +datetest 19.22a {date('2000-02-31','ceiling')} {2000-03-02} +datetest 19.22b {date('1999-02-31','ceiling')} {1999-03-03} +datetest 19.22c {date('1900-02-31','ceiling')} {1900-03-03} +datetest 19.23 {date('2000-03-31','ceiling')} {2000-03-31} +datetest 19.24 {date('2000-04-31','ceiling')} {2000-05-01} +datetest 19.25 {date('2000-05-31','ceiling')} {2000-05-31} +datetest 19.26 {date('2000-06-31','ceiling')} {2000-07-01} +datetest 19.27 {date('2000-07-31','ceiling')} {2000-07-31} +datetest 19.28 {date('2000-08-31','ceiling')} {2000-08-31} +datetest 19.29 {date('2000-09-31','ceiling')} {2000-10-01} +datetest 19.30 {date('2000-10-31','ceiling')} {2000-10-31} +datetest 19.31 {date('2000-11-31','ceiling')} {2000-12-01} +datetest 19.32 {date('2000-12-31','ceiling')} {2000-12-31} +datetest 19.40 {date('2024-01-31','+1 month','ceiling')} {2024-03-02} +datetest 19.41 {date('2024-01-31','+1 month','floor')} {2024-02-29} +datetest 19.42 {date('2023-01-31','+1 month','ceiling')} {2023-03-03} +datetest 19.43 {date('2023-01-31','+1 month','floor')} {2023-02-28} +datetest 19.44 {date('2024-02-29','+1 year','ceiling')} {2025-03-01} +datetest 19.45 {date('2024-02-29','+1 year','floor')} {2025-02-28} +datetest 19.46 {date('2024-02-29','-110 years','ceiling')} {1914-03-01} +datetest 19.47 {date('2024-02-29','-110 years','floor')} {1914-02-28} +datetest 19.48 {date('2024-02-29','-0110-00-00','floor')} {1914-02-28} +datetest 19.49 {date('2024-02-29','-0110-00-00','ceiling')} {1914-03-01} +datetest 19.50 {date('2000-08-31','+0023-06-00','floor')} {2024-02-29} +datetest 19.51 {date('2000-08-31','+0022-06-00','floor')} {2023-02-28} +datetest 19.52 {date('2000-08-31','+0023-06-00','ceiling')} {2024-03-02} +datetest 19.53 {date('2000-08-31','+0022-06-00','ceiling')} {2023-03-03} + + finish_test From e6af60c14f8b11c68fca76a0d1aba1c4696b51c2 Mon Sep 17 00:00:00 2001 From: stephan Date: Mon, 4 Mar 2024 06:54:41 +0000 Subject: [PATCH 159/430] After wasm bootstrapping has read the optional global-scope config objects, delete those objects because any further changes would not have any useful effect. Expand the docs regarding the sqlite3ApiBootstrap() config object and explain the necessary evil of a separate global-scope object for that configuration. FossilOrigin-Name: e6b14f73136aae4c1a92d6d6ab8c5d1510db5244d0b0f168eed5b4b257c99064 --- ext/wasm/api/sqlite3-api-prologue.js | 32 +++++++++++++++++++++++++++- manifest | 14 ++++++------ manifest.uuid | 2 +- 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/ext/wasm/api/sqlite3-api-prologue.js b/ext/wasm/api/sqlite3-api-prologue.js index c784b69909..d3c8e9ffba 100644 --- a/ext/wasm/api/sqlite3-api-prologue.js +++ b/ext/wasm/api/sqlite3-api-prologue.js @@ -37,7 +37,7 @@ This function expects a configuration object, intended to abstract away details specific to any given WASM environment, primarily so - that it can be used without any _direct_ dependency on + that it can be used without any direct dependency on Emscripten. (Note the default values for the config object!) The config object is only honored the first time this is called. Subsequent calls ignore the argument and return the same @@ -98,6 +98,27 @@ The returned object is the top-level sqlite3 namespace object. + + Client code may optionally assign sqlite3ApiBootstrap.defaultConfig + an object-type value before calling sqlite3ApiBootstrap() (without + arguments) in order to tell that call to use this object as its + default config value. The intention of this is to provide + downstream clients with a reasonably flexible approach for plugging + in an environment-suitable configuration without having to define a + new global-scope symbol. + + However, because clients who access this library via an + Emscripten-hosted module will not have an opportunity to call + sqlite3ApiBootstrap() themselves, nor to access it before it is + called, an alternative option for setting the configuration is to + define globalThis.sqlite3ApiConfig to an object. If it is set, it + is used instead of sqlite3ApiBootstrap.defaultConfig if + sqlite3ApiBootstrap() is called without arguments. + + Both sqlite3ApiBootstrap.defaultConfig and + globalThis.sqlite3ApiConfig get deleted by sqlite3ApiBootstrap() + because any changes to them made after that point would have no + useful effect. */ 'use strict'; globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap( @@ -149,6 +170,15 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap( config[k] = config[k](); } }); + + /** + Eliminate any confusion about whether these config objects may + be used after library initialization by eliminating the outward-facing + objects... + */ + delete globalThis.sqlite3ApiConfig; + delete sqlite3ApiBootstrap.defaultConfig; + /** The main sqlite3 binding API gets installed into this object, mimicking the C API as closely as we can. The numerous members diff --git a/manifest b/manifest index 69581e9a5b..5d8e095922 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Back\sout\sthe\sprevious\schange.\s\sReplace\sit\swith\snew\sdate\smodifiers\s"ceiling"\nand\s"floor". -D 2024-03-03T20:15:36.398 +C After\swasm\sbootstrapping\shas\sread\sthe\soptional\sglobal-scope\sconfig\sobjects,\sdelete\sthose\sobjects\sbecause\sany\sfurther\schanges\swould\snot\shave\sany\suseful\seffect.\sExpand\sthe\sdocs\sregarding\sthe\ssqlite3ApiBootstrap()\sconfig\sobject\sand\sexplain\sthe\snecessary\sevil\sof\sa\sseparate\sglobal-scope\sobject\sfor\sthat\sconfiguration. +D 2024-03-04T06:54:41.070 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -607,7 +607,7 @@ F ext/wasm/api/pre-js.c-pp.js ad906703f7429590f2fbf5e6498513bf727a1a4f0ebfa057af F ext/wasm/api/sqlite3-api-cleanup.js d235ad237df6954145404305040991c72ef8b1881715d2a650dda7b3c2576d0e F ext/wasm/api/sqlite3-api-glue.js 587dc6db2d69329a5f4cb9635c377f516cf4a8e30f443f33380e5044889ec71b F ext/wasm/api/sqlite3-api-oo1.js 7f3bcf0549ac44cde4b9da0b642d771916738d3f6781fb8a1757c50a91e506c0 -F ext/wasm/api/sqlite3-api-prologue.js fffcee629bf020a8ccf5c367fbe6a169f5d5d73dfce1707a75c9fbf4aa21c7da +F ext/wasm/api/sqlite3-api-prologue.js 5f09126bc807fc506f9922a88228abb553fcbfa676a5724aa6d08e148e32af5b F ext/wasm/api/sqlite3-api-worker1.js 8d9c0562831f62218170a3373468d8a0b7a6503b5985e309b69bf71187b525cf F ext/wasm/api/sqlite3-license-version-header.js 0c807a421f0187e778dc1078f10d2994b915123c1223fe752b60afdcd1263f89 F ext/wasm/api/sqlite3-opfs-async-proxy.js 8cf8a897726f14071fae6be6648125162b256dfb4f96555b865dbb7a6b65e379 @@ -2176,8 +2176,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 5d392c16bb5658bc92f60d250ab82c45cc109e32d58a073498c9a487b8625e96 -R 9967c002ac0a5c05f7a39fb253518624 -U drh -Z 10e35251deea062b6c8093330abd75ed +P f0831cced2c919e409214d936c81473ae321a98c5bd78b5b729c1269bf71bc45 +R 4a8c0aeaafa0cb5a978f136d9342c53b +U stephan +Z 2d4a13ca44f781b5c37a0c6aad22e4d0 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index deb11dc730..399be41ba6 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f0831cced2c919e409214d936c81473ae321a98c5bd78b5b729c1269bf71bc45 \ No newline at end of file +e6b14f73136aae4c1a92d6d6ab8c5d1510db5244d0b0f168eed5b4b257c99064 \ No newline at end of file From bae55a768505c448384985a9cf9ddcd18c8107ca Mon Sep 17 00:00:00 2001 From: stephan Date: Mon, 4 Mar 2024 09:23:52 +0000 Subject: [PATCH 160/430] When warning about multiple invocations of JS's sqlite3ApiBootstrap(), use the warning logger installed by the first invocation, rather than console.warn. FossilOrigin-Name: d162af2d9941cd8c53e3928efb42aaaf4e59454f7d39aebf980a30b1427ea75b --- ext/wasm/api/sqlite3-api-prologue.js | 6 ++++-- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/ext/wasm/api/sqlite3-api-prologue.js b/ext/wasm/api/sqlite3-api-prologue.js index d3c8e9ffba..5fe587c147 100644 --- a/ext/wasm/api/sqlite3-api-prologue.js +++ b/ext/wasm/api/sqlite3-api-prologue.js @@ -125,8 +125,10 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap( apiConfig = (globalThis.sqlite3ApiConfig || sqlite3ApiBootstrap.defaultConfig) ){ if(sqlite3ApiBootstrap.sqlite3){ /* already initalized */ - console.warn("sqlite3ApiBootstrap() called multiple times.", - "Config and external initializers are ignored on calls after the first."); + (sqlite3ApiBootstrap.sqlite3.config || console).warn( + "sqlite3ApiBootstrap() called multiple times.", + "Config and external initializers are ignored on calls after the first." + ); return sqlite3ApiBootstrap.sqlite3; } const config = Object.assign(Object.create(null),{ diff --git a/manifest b/manifest index 5d8e095922..3c3e555b90 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C After\swasm\sbootstrapping\shas\sread\sthe\soptional\sglobal-scope\sconfig\sobjects,\sdelete\sthose\sobjects\sbecause\sany\sfurther\schanges\swould\snot\shave\sany\suseful\seffect.\sExpand\sthe\sdocs\sregarding\sthe\ssqlite3ApiBootstrap()\sconfig\sobject\sand\sexplain\sthe\snecessary\sevil\sof\sa\sseparate\sglobal-scope\sobject\sfor\sthat\sconfiguration. -D 2024-03-04T06:54:41.070 +C When\swarning\sabout\smultiple\sinvocations\sof\sJS's\ssqlite3ApiBootstrap(),\suse\sthe\swarning\slogger\sinstalled\sby\sthe\sfirst\sinvocation,\srather\sthan\sconsole.warn. +D 2024-03-04T09:23:52.944 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -607,7 +607,7 @@ F ext/wasm/api/pre-js.c-pp.js ad906703f7429590f2fbf5e6498513bf727a1a4f0ebfa057af F ext/wasm/api/sqlite3-api-cleanup.js d235ad237df6954145404305040991c72ef8b1881715d2a650dda7b3c2576d0e F ext/wasm/api/sqlite3-api-glue.js 587dc6db2d69329a5f4cb9635c377f516cf4a8e30f443f33380e5044889ec71b F ext/wasm/api/sqlite3-api-oo1.js 7f3bcf0549ac44cde4b9da0b642d771916738d3f6781fb8a1757c50a91e506c0 -F ext/wasm/api/sqlite3-api-prologue.js 5f09126bc807fc506f9922a88228abb553fcbfa676a5724aa6d08e148e32af5b +F ext/wasm/api/sqlite3-api-prologue.js 5000fea107dcd2754c1d9c9080a8d534ad7e299bb6f8ad6dd97c08740fde2dca F ext/wasm/api/sqlite3-api-worker1.js 8d9c0562831f62218170a3373468d8a0b7a6503b5985e309b69bf71187b525cf F ext/wasm/api/sqlite3-license-version-header.js 0c807a421f0187e778dc1078f10d2994b915123c1223fe752b60afdcd1263f89 F ext/wasm/api/sqlite3-opfs-async-proxy.js 8cf8a897726f14071fae6be6648125162b256dfb4f96555b865dbb7a6b65e379 @@ -2176,8 +2176,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P f0831cced2c919e409214d936c81473ae321a98c5bd78b5b729c1269bf71bc45 -R 4a8c0aeaafa0cb5a978f136d9342c53b +P e6b14f73136aae4c1a92d6d6ab8c5d1510db5244d0b0f168eed5b4b257c99064 +R 386793253f6df9a64972715ed54c745e U stephan -Z 2d4a13ca44f781b5c37a0c6aad22e4d0 +Z 0abd34f742b690ed7162270a587892b4 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 399be41ba6..191350b6e0 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e6b14f73136aae4c1a92d6d6ab8c5d1510db5244d0b0f168eed5b4b257c99064 \ No newline at end of file +d162af2d9941cd8c53e3928efb42aaaf4e59454f7d39aebf980a30b1427ea75b \ No newline at end of file From 2775f10ebcebc303fa18ab12bd1697ed0794fdcd Mon Sep 17 00:00:00 2001 From: stephan Date: Mon, 4 Mar 2024 09:56:47 +0000 Subject: [PATCH 161/430] Document why the wasm build does not use Emscripten's -sSTRICT=1 flag and account for a behaviour change in emsdk 3.1.55 regarding the HEAPxyz symbols. FossilOrigin-Name: f6e887203365b30cea6e9c145366345e48256a347388577edf2bada65e0655b7 --- ext/wasm/GNUmakefile | 9 +++++++++ ext/wasm/api/sqlite3-api-prologue.js | 12 ++++++++++-- manifest | 14 +++++++------- manifest.uuid | 2 +- 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/ext/wasm/GNUmakefile b/ext/wasm/GNUmakefile index 75fc785182..098a4330b0 100644 --- a/ext/wasm/GNUmakefile +++ b/ext/wasm/GNUmakefile @@ -531,6 +531,10 @@ emcc.jsflags += -sSTRICT_JS=0 # 3.1.31. The fix for that in newer emcc's is to throw a built-time # error if STRICT_JS is used together with those options. +# emcc.jsflags += -sSTRICT=1 +# -sSTRICT=1 Causes failures about unknown symbols which the build +# tools should be installing, e.g. __syscall_geteuid32 + # -sENVIRONMENT values for the various build modes: emcc.environment.vanilla := web,worker emcc.environment.bundler-friendly := $(emcc.environment.vanilla) @@ -551,6 +555,11 @@ emcc.environment.node := node # time with 16mb+ memory and 3X time when starting with 8MB. However, # such test results are inconsistent due to browser internals which # are opaque to us. +# +# 2024-03-04: emsdk 3.1.55 replaces INITIAL_MEMORY with INITIAL_HEAP, +# but also says (in its changelog): "Note that it is currently not +# supported in all configurations (#21071)." +# https://github.com/emscripten-core/emscripten/blob/main/ChangeLog.md emcc.jsflags += -sALLOW_MEMORY_GROWTH emcc.INITIAL_MEMORY.128 := 134217728 emcc.INITIAL_MEMORY.96 := 100663296 diff --git a/ext/wasm/api/sqlite3-api-prologue.js b/ext/wasm/api/sqlite3-api-prologue.js index 5fe587c147..c3cc25f43a 100644 --- a/ext/wasm/api/sqlite3-api-prologue.js +++ b/ext/wasm/api/sqlite3-api-prologue.js @@ -137,8 +137,16 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap( bigIntEnabled: (()=>{ if('undefined'!==typeof Module){ /* Emscripten module will contain HEAPU64 when built with - -sWASM_BIGINT=1, else it will not. */ - return !!Module.HEAPU64; + -sWASM_BIGINT=1, else it will not. + + As of emsdk 3.1.55, when building in strict mode, HEAPxyz + are only available if _explicitly_ included in the exports, + else they are not. We do not (as of 2024-03-04) use -sSTRICT + for the canonical builds. + */ + if( !!Module.HEAPU64 ) return true; + /* Else fall through and hope for the best. Nobody _really_ + builds this without BigInt support, do they? */ } return !!globalThis.BigInt64Array; })(), diff --git a/manifest b/manifest index 3c3e555b90..0705277b93 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C When\swarning\sabout\smultiple\sinvocations\sof\sJS's\ssqlite3ApiBootstrap(),\suse\sthe\swarning\slogger\sinstalled\sby\sthe\sfirst\sinvocation,\srather\sthan\sconsole.warn. -D 2024-03-04T09:23:52.944 +C Document\swhy\sthe\swasm\sbuild\sdoes\snot\suse\sEmscripten's\s-sSTRICT=1\sflag\sand\saccount\sfor\sa\sbehaviour\schange\sin\semsdk\s3.1.55\sregarding\sthe\sHEAPxyz\ssymbols. +D 2024-03-04T09:56:47.061 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -587,7 +587,7 @@ F ext/userauth/sqlite3userauth.h 7f3ea8c4686db8e40b0a0e7a8e0b00fac13aa7a3 F ext/userauth/user-auth.txt ca7e9ee82ca4e1c1744295f8184dd70edfae1992865d26c64303f539eb6c084c F ext/userauth/userauth.c 7f00cded7dcaa5d47f54539b290a43d2e59f4b1eb5f447545fa865f002fc80cb F ext/wasm/EXPORTED_FUNCTIONS.fiddle.in 27450c8b8c70875a260aca55435ec927068b34cef801a96205adb81bdcefc65c -F ext/wasm/GNUmakefile 316349101671037a30311fbb40bd0b8702d9a223b5205a6a5eae8bac7b8dc1a0 +F ext/wasm/GNUmakefile 92e929315c3f1e0ea389fc9666b87a67a61fa1ecbe37e44c5ad226bda3bc6abe F ext/wasm/README-dist.txt 6382cb9548076fca472fb3330bbdba3a55c1ea0b180ff9253f084f07ff383576 F ext/wasm/README.md a8a2962c3aebdf8d2104a9102e336c5554e78fc6072746e5daf9c61514e7d193 F ext/wasm/SQLTester/GNUmakefile e0794f676d55819951bbfae45cc5e8d7818dc460492dc317ce7f0d2eca15caff @@ -607,7 +607,7 @@ F ext/wasm/api/pre-js.c-pp.js ad906703f7429590f2fbf5e6498513bf727a1a4f0ebfa057af F ext/wasm/api/sqlite3-api-cleanup.js d235ad237df6954145404305040991c72ef8b1881715d2a650dda7b3c2576d0e F ext/wasm/api/sqlite3-api-glue.js 587dc6db2d69329a5f4cb9635c377f516cf4a8e30f443f33380e5044889ec71b F ext/wasm/api/sqlite3-api-oo1.js 7f3bcf0549ac44cde4b9da0b642d771916738d3f6781fb8a1757c50a91e506c0 -F ext/wasm/api/sqlite3-api-prologue.js 5000fea107dcd2754c1d9c9080a8d534ad7e299bb6f8ad6dd97c08740fde2dca +F ext/wasm/api/sqlite3-api-prologue.js 93a72b07b2a5d964d2edc76a90b439ece49298bd7ba60a1c6ae5d4878213701e F ext/wasm/api/sqlite3-api-worker1.js 8d9c0562831f62218170a3373468d8a0b7a6503b5985e309b69bf71187b525cf F ext/wasm/api/sqlite3-license-version-header.js 0c807a421f0187e778dc1078f10d2994b915123c1223fe752b60afdcd1263f89 F ext/wasm/api/sqlite3-opfs-async-proxy.js 8cf8a897726f14071fae6be6648125162b256dfb4f96555b865dbb7a6b65e379 @@ -2176,8 +2176,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P e6b14f73136aae4c1a92d6d6ab8c5d1510db5244d0b0f168eed5b4b257c99064 -R 386793253f6df9a64972715ed54c745e +P d162af2d9941cd8c53e3928efb42aaaf4e59454f7d39aebf980a30b1427ea75b +R a1392e5e8b70ba68a9cec5956be8638d U stephan -Z 0abd34f742b690ed7162270a587892b4 +Z eecd3ea1a1eec87bef8ed5be6afc5f59 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 191350b6e0..4b98f8cca6 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d162af2d9941cd8c53e3928efb42aaaf4e59454f7d39aebf980a30b1427ea75b \ No newline at end of file +f6e887203365b30cea6e9c145366345e48256a347388577edf2bada65e0655b7 \ No newline at end of file From 8d25d07d50ecfdf82b2148606fb1bdce24509bd2 Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 4 Mar 2024 11:12:15 +0000 Subject: [PATCH 162/430] Fix assert() statements in date/time computations: The month and day numbers can be zero if an error has been seen. FossilOrigin-Name: fc773f6c76ec114be8b6e25b13885acb5adcc9d052dca0d8d0ff94e2a0743d64 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/date.c | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 0705277b93..f23cc045a5 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Document\swhy\sthe\swasm\sbuild\sdoes\snot\suse\sEmscripten's\s-sSTRICT=1\sflag\sand\saccount\sfor\sa\sbehaviour\schange\sin\semsdk\s3.1.55\sregarding\sthe\sHEAPxyz\ssymbols. -D 2024-03-04T09:56:47.061 +C Fix\sassert()\sstatements\sin\sdate/time\scomputations:\sThe\smonth\sand\sday\snumbers\ncan\sbe\szero\sif\san\serror\shas\sbeen\sseen. +D 2024-03-04T11:12:15.305 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -696,7 +696,7 @@ F src/build.c 04f1bcee189f045ab086d84fee95db42cb49df82ff8e84af8136309ff3c8a75f F src/callback.c db3a45e376deff6a16c0058163fe0ae2b73a2945f3f408ca32cf74960b28d490 F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e F src/ctime.c 23331529e654be40ca97d171cbbffe9b3d4c71cc53b78fe5501230675952da8b -F src/date.c b36a3cc75ac691bf72b4759130b04ac2926af6fd4ca98df3400ff20d34a15878 +F src/date.c 29cecfe69287242a12f753ffc883e4231afde3af501fb1b4a7b721b159fc4bb2 F src/dbpage.c 80e46e1df623ec40486da7a5086cb723b0275a6e2a7b01d9f9b5da0f04ba2782 F src/dbstat.c 3b677254d512fcafd4d0b341bf267b38b235ccfddbef24f9154e19360fa22e43 F src/delete.c cb766727c78e715f9fb7ec8a7d03658ed2a3016343ca687acfcec9083cdca500 @@ -2176,8 +2176,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P d162af2d9941cd8c53e3928efb42aaaf4e59454f7d39aebf980a30b1427ea75b -R a1392e5e8b70ba68a9cec5956be8638d -U stephan -Z eecd3ea1a1eec87bef8ed5be6afc5f59 +P f6e887203365b30cea6e9c145366345e48256a347388577edf2bada65e0655b7 +R 68522a41082e7767e1ccbf426313c9cf +U drh +Z cb9173c28803c9d207f1634b7853f7aa # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 4b98f8cca6..9788f68f52 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f6e887203365b30cea6e9c145366345e48256a347388577edf2bada65e0655b7 \ No newline at end of file +fc773f6c76ec114be8b6e25b13885acb5adcc9d052dca0d8d0ff94e2a0743d64 \ No newline at end of file diff --git a/src/date.c b/src/date.c index 37bf7fdb4f..239a772ca2 100644 --- a/src/date.c +++ b/src/date.c @@ -296,8 +296,8 @@ static void computeJD(DateTime *p){ */ static void computeFloor(DateTime *p){ assert( p->validYMD || p->isError ); - assert( (p->D>=1 && p->D<=31) || p->isError ); - assert( (p->M>=1 && p->M<=12) || p->isError ); + assert( p->D>=0 && p->D<=31 ); + assert( p->M>=0 && p->M<=12 ); if( p->D<=28 ){ p->nFloor = 0; }else if( (1<M) & 0x15aa ){ @@ -1047,7 +1047,7 @@ static int parseModifier( int y = (int)r; assert( strcmp(aXformType[5].zName,"year")==0 ); computeYMD_HMS(p); - assert( p->M>=1 && p->M<=12 ); + assert( p->M>=0 && p->M<=12 ); p->Y += y; computeFloor(p); p->validJD = 0; From 3f273db39b080803219d2100fc066f17638db348 Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 4 Mar 2024 13:58:09 +0000 Subject: [PATCH 163/430] Adjust date/time functions so that they do a better job of keeping track of whether the current time is UTC or localtime, and no-op the 'utc' and 'localtime' modifiers accordingly. See [forum:/info/e7a939e074|forum post e7a939e074]. Also add the datedebug() function, available only under -DSQLITE_DEBUG, for improved visibility of the DateTime object during debugging and testing. FossilOrigin-Name: dc569683748354a6db83438904422e802d3ea780775c48da85b474fff03ca8a1 --- manifest | 16 ++++----- manifest.uuid | 2 +- src/date.c | 78 ++++++++++++++++++++++++++++++---------- test/date.test | 34 +++++++++++++++++- test/tkt-bd484a090c.test | 2 +- 5 files changed, 103 insertions(+), 29 deletions(-) diff --git a/manifest b/manifest index f23cc045a5..e7d61781cc 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sassert()\sstatements\sin\sdate/time\scomputations:\sThe\smonth\sand\sday\snumbers\ncan\sbe\szero\sif\san\serror\shas\sbeen\sseen. -D 2024-03-04T11:12:15.305 +C Adjust\sdate/time\sfunctions\sso\sthat\sthey\sdo\sa\sbetter\sjob\sof\skeeping\strack\nof\swhether\sthe\scurrent\stime\sis\sUTC\sor\slocaltime,\sand\sno-op\sthe\s'utc'\sand\n'localtime'\smodifiers\saccordingly.\sSee\n[forum:/info/e7a939e074|forum\spost\se7a939e074].\nAlso\sadd\sthe\sdatedebug()\sfunction,\savailable\nonly\sunder\s-DSQLITE_DEBUG,\sfor\simproved\svisibility\sof\sthe\sDateTime\sobject\nduring\sdebugging\sand\stesting. +D 2024-03-04T13:58:09.237 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -696,7 +696,7 @@ F src/build.c 04f1bcee189f045ab086d84fee95db42cb49df82ff8e84af8136309ff3c8a75f F src/callback.c db3a45e376deff6a16c0058163fe0ae2b73a2945f3f408ca32cf74960b28d490 F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e F src/ctime.c 23331529e654be40ca97d171cbbffe9b3d4c71cc53b78fe5501230675952da8b -F src/date.c 29cecfe69287242a12f753ffc883e4231afde3af501fb1b4a7b721b159fc4bb2 +F src/date.c a9e4382961fb26156a308645f7363519ab7eb20e412e78b7c1fe16bbfbb1689a F src/dbpage.c 80e46e1df623ec40486da7a5086cb723b0275a6e2a7b01d9f9b5da0f04ba2782 F src/dbstat.c 3b677254d512fcafd4d0b341bf267b38b235ccfddbef24f9154e19360fa22e43 F src/delete.c cb766727c78e715f9fb7ec8a7d03658ed2a3016343ca687acfcec9083cdca500 @@ -1042,7 +1042,7 @@ F test/ctime.test 340f362f41f92972bbd71f44e10569a5cc694062b692231bd08aa6fe6c1c47 F test/cursorhint.test 05cf0febe5c5f8a31f199401fd1c9322249e753950d55f26f9d5aca61408a270 F test/cursorhint2.test 6f3aa9cb19e7418967a10ec6905209bcbb5968054da855fc36c8beee9ae9c42f F test/dataversion1.test 6e5e86ac681f0782e766ebcb56c019ae001522d114e0e111e5ebf68ccf2a7bb8 -F test/date.test 99bfd3a77a3f9ae54eebd374a4301af960f2b2e9a581cf63e26445bae830a435 +F test/date.test c8ff835023f2107b57ce7a45c92265d51c98a23fc93231e998f12d850831aad6 F test/date2.test 7e12ec14aaf4d5e6294b4ba140445b0eca06ea50062a9c3a69c4ee13d0b6f8b1 F test/date3.test a1b77abf05c6772fe5ca2337cac1398892f2a41e62bce7e6be0f4a08a0e64ae5 F test/date4.test 75dc8401e8c0639a228cd26a6eaa4ff5ea8ccda912b9853d1c9462c476670e17 @@ -1749,7 +1749,7 @@ F test/tkt-b351d95f9.test d14a503c414c5c58fdde3e80f9a3cfef986498c0 F test/tkt-b72787b1.test a95e8cdad0b98af1853ac7f0afd4ab27b77bf5f3 F test/tkt-b75a9ca6b0.test dc6a853c242f7d0326564ae32e9e5eb462b5e8d2bc5b01ea3b18fd24f8e5894b F test/tkt-ba7cbfaedc.test b4c0deccc12aeb55cfdb57935b16b5d67c5a9877 -F test/tkt-bd484a090c.test 60460bf946f79a79712b71f202eda501ca99b898 +F test/tkt-bd484a090c.test e6af3e3a4242cd8f1c91c736364f09075d8e33e3b86f6492a1ee36278ea71b61 F test/tkt-bdc6bbbb38.test fc38bb09bdd440e3513a1f5f98fc60a075182d7d F test/tkt-c48d99d690.test ba61977d62ab612fc515b3c488a6fbd6464a2447 F test/tkt-c694113d5.test 82c461924ada5c14866c47e85535b0b0923ba16a2e907e370061a5ca77f65d77 @@ -2176,8 +2176,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P f6e887203365b30cea6e9c145366345e48256a347388577edf2bada65e0655b7 -R 68522a41082e7767e1ccbf426313c9cf +P fc773f6c76ec114be8b6e25b13885acb5adcc9d052dca0d8d0ff94e2a0743d64 +R 0f693fc7ce53368753332e9082e39c9c U drh -Z cb9173c28803c9d207f1634b7853f7aa +Z b0035812b357d7d3f0f59f737bf36230 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 9788f68f52..7e9ada2541 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -fc773f6c76ec114be8b6e25b13885acb5adcc9d052dca0d8d0ff94e2a0743d64 \ No newline at end of file +dc569683748354a6db83438904422e802d3ea780775c48da85b474fff03ca8a1 \ No newline at end of file diff --git a/src/date.c b/src/date.c index 239a772ca2..3bb4a8c714 100644 --- a/src/date.c +++ b/src/date.c @@ -73,12 +73,12 @@ struct DateTime { char validJD; /* True (1) if iJD is valid */ char validYMD; /* True (1) if Y,M,D are valid */ char validHMS; /* True (1) if h,m,s are valid */ - char validTZ; /* True (1) if tz is valid */ char nFloor; /* Days to implement "floor" */ unsigned rawS : 1; /* Raw numeric value stored in s */ - unsigned tzSet : 1; /* Timezone was set explicitly */ unsigned isError : 1; /* An overflow has occurred */ unsigned useSubsec : 1; /* Display subsecond precision */ + unsigned isUtc : 1; /* Time is known to be UTC */ + unsigned isLocal : 1; /* Time is known to be localtime */ }; @@ -176,6 +176,8 @@ static int parseTimezone(const char *zDate, DateTime *p){ sgn = +1; }else if( c=='Z' || c=='z' ){ zDate++; + p->isLocal = 0; + p->isUtc = 1; goto zulu_time; }else{ return c!=0; @@ -188,7 +190,6 @@ static int parseTimezone(const char *zDate, DateTime *p){ p->tz = sgn*(nMn + nHr*60); zulu_time: while( sqlite3Isspace(*zDate) ){ zDate++; } - p->tzSet = 1; return *zDate!=0; } @@ -232,7 +233,6 @@ static int parseHhMmSs(const char *zDate, DateTime *p){ p->m = m; p->s = s + ms; if( parseTimezone(zDate, p) ) return 1; - p->validTZ = (p->tz!=0)?1:0; return 0; } @@ -279,11 +279,13 @@ static void computeJD(DateTime *p){ p->validJD = 1; if( p->validHMS ){ p->iJD += p->h*3600000 + p->m*60000 + (sqlite3_int64)(p->s*1000 + 0.5); - if( p->validTZ ){ + if( p->tz ){ p->iJD -= p->tz*60000; p->validYMD = 0; p->validHMS = 0; - p->validTZ = 0; + p->tz = 0; + p->isUtc = 1; + p->isLocal = 0; } } } @@ -350,11 +352,14 @@ static int parseYyyyMmDd(const char *zDate, DateTime *p){ p->M = M; p->D = D; computeFloor(p); - if( p->validTZ ){ + if( p->tz ){ computeJD(p); } return 0; -} +}; + + +static void clearYMD_HMS_TZ(DateTime *p); /* Forward declaration */ /* ** Set the time to the current time reported by the VFS. @@ -365,6 +370,9 @@ static int setDateTimeToCurrent(sqlite3_context *context, DateTime *p){ p->iJD = sqlite3StmtCurrentTime(context); if( p->iJD>0 ){ p->validJD = 1; + p->isUtc = 1; + p->isLocal = 0; + clearYMD_HMS_TZ(p); return 0; }else{ return 1; @@ -503,7 +511,7 @@ static void computeYMD_HMS(DateTime *p){ static void clearYMD_HMS_TZ(DateTime *p){ p->validYMD = 0; p->validHMS = 0; - p->validTZ = 0; + p->tz = 0; } #ifndef SQLITE_OMIT_LOCALTIME @@ -635,7 +643,7 @@ static int toLocaltime( p->validHMS = 1; p->validJD = 0; p->rawS = 0; - p->validTZ = 0; + p->tz = 0; p->isError = 0; return SQLITE_OK; } @@ -793,7 +801,9 @@ static int parseModifier( ** show local time. */ if( sqlite3_stricmp(z, "localtime")==0 && sqlite3NotPureFunc(pCtx) ){ - rc = toLocaltime(p, pCtx); + rc = p->isLocal ? SQLITE_OK : toLocaltime(p, pCtx); + p->isUtc = 0; + p->isLocal = 1; } break; } @@ -818,7 +828,7 @@ static int parseModifier( } #ifndef SQLITE_OMIT_LOCALTIME else if( sqlite3_stricmp(z, "utc")==0 && sqlite3NotPureFunc(pCtx) ){ - if( p->tzSet==0 ){ + if( p->isUtc==0 ){ i64 iOrigJD; /* Original localtime */ i64 iGuess; /* Guess at the corresponding utc time */ int cnt = 0; /* Safety to prevent infinite loop */ @@ -841,7 +851,8 @@ static int parseModifier( memset(p, 0, sizeof(*p)); p->iJD = iGuess; p->validJD = 1; - p->tzSet = 1; + p->isUtc = 1; + p->isLocal = 0; } rc = SQLITE_OK; } @@ -861,7 +872,7 @@ static int parseModifier( && r>=0.0 && r<7.0 && (n=(int)r)==r ){ sqlite3_int64 Z; computeYMD_HMS(p); - p->validTZ = 0; + p->tz = 0; p->validJD = 0; computeJD(p); Z = ((p->iJD + 129600000)/86400000) % 7; @@ -901,7 +912,7 @@ static int parseModifier( p->h = p->m = 0; p->s = 0.0; p->rawS = 0; - p->validTZ = 0; + p->tz = 0; p->validJD = 0; if( sqlite3_stricmp(z,"month")==0 ){ p->D = 1; @@ -1674,9 +1685,7 @@ static void timediffFunc( d1.iJD = d2.iJD - d1.iJD; d1.iJD += (u64)1486995408 * (u64)100000; } - d1.validYMD = 0; - d1.validHMS = 0; - d1.validTZ = 0; + clearYMD_HMS_TZ(&d1); computeYMD_HMS(&d1); sqlite3StrAccumInit(&sRes, 0, 0, 0, 100); sqlite3_str_appendf(&sRes, "%c%04d-%02d-%02d %02d:%02d:%06.3f", @@ -1745,6 +1754,36 @@ static void currentTimeFunc( } #endif +#if !defined(SQLITE_OMIT_DATETIME_FUNCS) && defined(SQLITE_DEBUG) +/* +** datedebug(...) +** +** This routine returns JSON that describes the internal DateTime object. +** Used for debugging and testing only. Subject to change. +*/ +static void datedebugFunc( + sqlite3_context *context, + int argc, + sqlite3_value **argv +){ + DateTime x; + if( isDate(context, argc, argv, &x)==0 ){ + char *zJson; + zJson = sqlite3_mprintf( + "{iJD:%lld,Y:%d,M:%d,D:%d,h:%d,m:%d,tz:%d," + "s:%.3f,validJD:%d,validYMS:%d,validHMS:%d," + "nFloor:%d,rawS:%d,isError:%d,useSubsec:%d," + "isUtc:%d,isLocal:%d}", + x.iJD, x.Y, x.M, x.D, x.h, x.m, x.tz, + x.s, x.validJD, x.validYMD, x.validHMS, + x.nFloor, x.rawS, x.isError, x.useSubsec, + x.isUtc, x.isLocal); + sqlite3_result_text(context, zJson, -1, sqlite3_free); + } +} +#endif /* !SQLITE_OMIT_DATETIME_FUNCS && SQLITE_DEBUG */ + + /* ** This function registered all of the above C functions as SQL ** functions. This should be the only routine in this file with @@ -1760,6 +1799,9 @@ void sqlite3RegisterDateTimeFunctions(void){ PURE_DATE(datetime, -1, 0, 0, datetimeFunc ), PURE_DATE(strftime, -1, 0, 0, strftimeFunc ), PURE_DATE(timediff, 2, 0, 0, timediffFunc ), +#ifdef SQLITE_DEBUG + PURE_DATE(datedebug, -1, 0, 0, datedebugFunc ), +#endif DFUNCTION(current_time, 0, 0, 0, ctimeFunc ), DFUNCTION(current_timestamp, 0, 0, 0, ctimestampFunc), DFUNCTION(current_date, 0, 0, 0, cdateFunc ), diff --git a/test/date.test b/test/date.test index 2a6e93df40..d22b652b47 100644 --- a/test/date.test +++ b/test/date.test @@ -262,7 +262,7 @@ datetest 5.15 {datetime('1994-04-16 14:00:00 +05:00 Z')} NULL # localtime->utc and utc->localtime conversions. # # Use SQLITE_TESTCTRL_LOCALTIME_FAULT=2 to set an alternative localtime_r() -# implementation that is not locale-dependent. This testing localtime_r() +# implementation that is not locale-dependent. The testing localtime_r() # operates as follows: # # (1) Localtime is 30 minutes earlier than (west of) UTC on @@ -321,6 +321,38 @@ utc_to_local 6.22 {1800-10-29 12:30:00} {1800-10-29 12:00:00} local_to_utc 6.23 {3000-10-30 12:00:00} {3000-10-30 11:30:00} utc_to_local 6.24 {3000-10-30 11:30:00} {3000-10-30 12:00:00} +# If the time is specified to be ZULU, or if it has an explicit +# timezone extension, then the time will already be UTC and subsequent +# 'utc' modifiers are no-ops. +# +do_execsql_test date-6.25 { + SELECT datetime('2000-10-29 12:00Z','utc','utc'); +} {{2000-10-29 12:00:00}} +do_execsql_test date-6.26 { + SELECT datetime('2000-10-29 12:00:00+05:00'); +} {{2000-10-29 07:00:00}} +do_execsql_test date-6.27 { + SELECT datetime('2000-10-29 12:00:00+05:00', 'utc'); +} {{2000-10-29 07:00:00}} + +# Multiple back-and-forth UTC to LOCAL to UTC... +do_execsql_test date-6.28 { + SELECT datetime('2000-10-29 12:00:00Z', 'localtime'); +} {{2000-10-29 12:30:00}} +do_execsql_test date-6.29 { + SELECT datetime('2000-10-29 12:00:00Z', 'utc', 'localtime'); +} {{2000-10-29 12:30:00}} +do_execsql_test date-6.30 { + SELECT datetime('2000-10-29 12:00:00Z', 'utc', 'localtime', 'utc'); +} {{2000-10-29 12:00:00}} +do_execsql_test date-6.31 { + SELECT datetime('2000-10-29 12:00:00Z', 'utc','localtime','utc','localtime'); +} {{2000-10-29 12:30:00}} +do_execsql_test date-6.32 { + SELECT datetime('2000-10-29 12:00:00Z', 'localtime','localtime'); +} {{2000-10-29 12:30:00}} + + # Restore the use of the OS localtime_r() before going on... sqlite3_test_control SQLITE_TESTCTRL_LOCALTIME_FAULT 0 diff --git a/test/tkt-bd484a090c.test b/test/tkt-bd484a090c.test index 3d2b599958..7867c8dc97 100644 --- a/test/tkt-bd484a090c.test +++ b/test/tkt-bd484a090c.test @@ -30,7 +30,7 @@ do_test 2.1 { catchsql { SELECT datetime('now', 'localtime') } } {1 {local time unavailable}} do_test 2.2 { - catchsql { SELECT datetime('now', 'utc') } + catchsql { SELECT datetime('2000-01-01', 'utc') } } {1 {local time unavailable}} sqlite3_test_control SQLITE_TESTCTRL_LOCALTIME_FAULT 0 From 90170503b4e1cfbab7ef600ef5957397b188f746 Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 4 Mar 2024 16:18:40 +0000 Subject: [PATCH 164/430] Fix harmless compiler warnings in the increment integrity_check extension. FossilOrigin-Name: 596668e6625208ff5d2ffbb4e0530530ebb3a400efa0df54bad1d91953e32694 --- ext/intck/sqlite3intck.c | 5 ++--- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/ext/intck/sqlite3intck.c b/ext/intck/sqlite3intck.c index 12d205e4d9..ed169a2664 100644 --- a/ext/intck/sqlite3intck.c +++ b/ext/intck/sqlite3intck.c @@ -422,7 +422,7 @@ static const char *intckParseCreateIndex(const char *z, int iCol, int *pnByte){ int n = intckGetToken(&z[iOff]); if( n==5 && 0==sqlite3_strnicmp(&z[iOff], "where", 5) ){ zRet = &z[iOff+5]; - nRet = strlen(zRet); + nRet = (int)strlen(zRet); } iOff += n; } @@ -785,7 +785,7 @@ int sqlite3_intck_open( sqlite3_intck *pNew = 0; int rc = SQLITE_OK; const char *zDb = zDbArg ? zDbArg : "main"; - int nDb = strlen(zDb); + int nDb = (int)strlen(zDb); pNew = (sqlite3_intck*)sqlite3_malloc(sizeof(*pNew) + nDb + 1); if( pNew==0 ){ @@ -938,4 +938,3 @@ const char *sqlite3_intck_test_sql(sqlite3_intck *p, const char *zObj){ } return p->zTestSql; } - diff --git a/manifest b/manifest index e7d61781cc..b78fb5ca46 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Adjust\sdate/time\sfunctions\sso\sthat\sthey\sdo\sa\sbetter\sjob\sof\skeeping\strack\nof\swhether\sthe\scurrent\stime\sis\sUTC\sor\slocaltime,\sand\sno-op\sthe\s'utc'\sand\n'localtime'\smodifiers\saccordingly.\sSee\n[forum:/info/e7a939e074|forum\spost\se7a939e074].\nAlso\sadd\sthe\sdatedebug()\sfunction,\savailable\nonly\sunder\s-DSQLITE_DEBUG,\sfor\simproved\svisibility\sof\sthe\sDateTime\sobject\nduring\sdebugging\sand\stesting. -D 2024-03-04T13:58:09.237 +C Fix\sharmless\scompiler\swarnings\sin\sthe\sincrement\sintegrity_check\sextension. +D 2024-03-04T16:18:40.992 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -256,7 +256,7 @@ F ext/intck/intck_common.tcl 9e51458126576783f11051ac0fd25bea3f6b17f570a55884223 F ext/intck/intckbusy.test 0732fe3efbb9e0a53ffdcc240073f6ff2777ea82c3e08812b16494f650763fe1 F ext/intck/intckcorrupt.test 3211ef68ac53e83951b6c8f6a8d2396506d123fe5898f97f848a25837744ec56 F ext/intck/intckfault.test ba0213c9c8dce08d519d5251268a3bab076a184b4d07acdea23b65e89c9ae03c -F ext/intck/sqlite3intck.c 52381a627637504a49e93400814b36e99afa0b972a9a24ef1732b8268bb27fa8 +F ext/intck/sqlite3intck.c 0d10df36e2b7b438aa80ecd3f5e584d41b747586b038258fe6b407f66b81e7c5 F ext/intck/sqlite3intck.h 2b40c38e7063ab822c974c0bd4aed97dabb579ccfe2e180a4639bb3bbef0f1c9 F ext/intck/test_intck.c d63f1707432802f5db125ee40b794923af77d4686869bd8d3a7eb43332344267 F ext/jni/GNUmakefile 59eb05f2a363bdfac8d15d66bed624bfe1ff289229184f3861b95f98a19cf4b2 @@ -2176,8 +2176,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P fc773f6c76ec114be8b6e25b13885acb5adcc9d052dca0d8d0ff94e2a0743d64 -R 0f693fc7ce53368753332e9082e39c9c +P dc569683748354a6db83438904422e802d3ea780775c48da85b474fff03ca8a1 +R 7e46f34cc8a5ab9c09b7645f58d236c7 U drh -Z b0035812b357d7d3f0f59f737bf36230 +Z 8407adbd700d1bcd9619e8d4b35bf5f1 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 7e9ada2541..ebba8e337e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -dc569683748354a6db83438904422e802d3ea780775c48da85b474fff03ca8a1 \ No newline at end of file +596668e6625208ff5d2ffbb4e0530530ebb3a400efa0df54bad1d91953e32694 \ No newline at end of file From 4cf953731f640c88db344dc2e6bab90db170049f Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 4 Mar 2024 16:44:37 +0000 Subject: [PATCH 165/430] Change test results in corruptC.test to account for the added detail in the output of "PRAGMA integrity_check" from [b736519d3d2e93c7]. FossilOrigin-Name: 0d19eeaafb296aad212ee4f55a0f6df8c7c5185b14d7f7f49c020fe4cbe370c1 --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/corruptC.test | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index b78fb5ca46..9a3eabe50d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sharmless\scompiler\swarnings\sin\sthe\sincrement\sintegrity_check\sextension. -D 2024-03-04T16:18:40.992 +C Change\stest\sresults\sin\scorruptC.test\sto\saccount\sfor\sthe\sadded\sdetail\sin\sthe\noutput\sof\s"PRAGMA\sintegrity_check"\sfrom\s[b736519d3d2e93c7]. +D 2024-03-04T16:44:37.718 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -1009,7 +1009,7 @@ F test/corrupt8.test 2399dfe40d2c0c63af86706e30f3e6302a8d0516 F test/corrupt9.test 730a3db08d4ab9aa43392ea30d9c2b4879cbff85 F test/corruptA.test 112f4b2ae0b95ebf3ea63718642fb969a93acea557ace3a307234d19c245989b F test/corruptB.test 73a8d6c0b9833697ecf16b63e3c5c05c945b5dec -F test/corruptC.test 9cf32275dae3ca33f645afe5d1d3f5ba5ac2af2b0833dfb5282f9dccb6fb81bb +F test/corruptC.test 7d6d9e907334ea3ccb7111a0656cafa30a28f8a5f2aaf1c45ad712236302856a F test/corruptD.test 614320aa519f6bf6c7dd2f581f9513ff7b6826954180cca1a606d0e25ea084a3 F test/corruptE.test 4143791f2dfb443aec5b7fabfa5821e6063eccc3b49b06f212c2f014715fd476 F test/corruptF.test be9fde98e4c93648f1ba52b74e5318edc8f59fe4 @@ -2176,8 +2176,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P dc569683748354a6db83438904422e802d3ea780775c48da85b474fff03ca8a1 -R 7e46f34cc8a5ab9c09b7645f58d236c7 +P 596668e6625208ff5d2ffbb4e0530530ebb3a400efa0df54bad1d91953e32694 +R e247d8c69a2f1de22f60330dc6b8c1d7 U drh -Z 8407adbd700d1bcd9619e8d4b35bf5f1 +Z c67139450867debeac7f30d4414de41e # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index ebba8e337e..063d7c49a5 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -596668e6625208ff5d2ffbb4e0530530ebb3a400efa0df54bad1d91953e32694 \ No newline at end of file +0d19eeaafb296aad212ee4f55a0f6df8c7c5185b14d7f7f49c020fe4cbe370c1 \ No newline at end of file diff --git a/test/corruptC.test b/test/corruptC.test index f5733a8186..bf324c120f 100644 --- a/test/corruptC.test +++ b/test/corruptC.test @@ -98,7 +98,7 @@ do_test corruptC-2.1 { sqlite3 db test.db catchsql {PRAGMA integrity_check} } {0 {{*** in database main *** -Tree 3 page 3: free space corruption}}} +Tree 3 page 3: free space corruption} {wrong # of entries in index t1i1}}} # test that a corrupt content offset size is handled (seed 5649) # From 18281494a27095687cb136783878fbbde8286f51 Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 4 Mar 2024 18:22:18 +0000 Subject: [PATCH 166/430] Fix a compiler warning in date.c. Update makefiles to include all necessary dependencies for building shell.c. FossilOrigin-Name: 178b7d46f9c8e1694ed6f506d2785a9f5c49e2b428e04c8096d557cc1b5c9680 --- Makefile.in | 60 ++++++++++++++++++++++++++------------------------- Makefile.msc | 59 +++++++++++++++++++++++++++----------------------- main.mk | 60 +++++++++++++++++++++++++++------------------------ manifest | 18 ++++++++-------- manifest.uuid | 2 +- src/date.c | 2 +- 6 files changed, 106 insertions(+), 95 deletions(-) diff --git a/Makefile.in b/Makefile.in index e858e55c34..321fb75278 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1156,35 +1156,37 @@ keywordhash.h: $(TOP)/tool/mkkeywordhash.c $(BCC) -o mkkeywordhash$(BEXE) $(OPT_FEATURE_FLAGS) $(OPTS) $(TOP)/tool/mkkeywordhash.c ./mkkeywordhash$(BEXE) >keywordhash.h -# Source files that go into making shell.c -SHELL_SRC = \ - $(TOP)/src/shell.c.in \ - $(TOP)/ext/consio/console_io.c \ - $(TOP)/ext/consio/console_io.h \ - $(TOP)/ext/misc/appendvfs.c \ - $(TOP)/ext/misc/completion.c \ - $(TOP)/ext/misc/decimal.c \ - $(TOP)/ext/misc/basexx.c \ - $(TOP)/ext/misc/base64.c \ - $(TOP)/ext/misc/base85.c \ - $(TOP)/ext/misc/fileio.c \ - $(TOP)/ext/misc/ieee754.c \ - $(TOP)/ext/misc/regexp.c \ - $(TOP)/ext/misc/series.c \ - $(TOP)/ext/misc/shathree.c \ - $(TOP)/ext/misc/sqlar.c \ - $(TOP)/ext/misc/uint.c \ - $(TOP)/ext/expert/sqlite3expert.c \ - $(TOP)/ext/expert/sqlite3expert.h \ - $(TOP)/ext/misc/zipfile.c \ - $(TOP)/ext/misc/memtrace.c \ - $(TOP)/ext/misc/pcachetrace.c \ - $(TOP)/ext/recover/dbdata.c \ - $(TOP)/ext/recover/sqlite3recover.c \ - $(TOP)/ext/recover/sqlite3recover.h \ - $(TOP)/src/test_windirent.c - -shell.c: $(SHELL_SRC) $(TOP)/tool/mkshellc.tcl has_tclsh84 +# Source and header files that shell.c depends on +SHELL_DEP = \ + $(TOP)/src/shell.c.in \ + $(TOP)/ext/consio/console_io.c \ + $(TOP)/ext/consio/console_io.h \ + $(TOP)/ext/expert/sqlite3expert.c \ + $(TOP)/ext/expert/sqlite3expert.h \ + $(TOP)/ext/intck/sqlite3intck.c \ + $(TOP)/ext/intck/sqlite3intck.h \ + $(TOP)/ext/misc/appendvfs.c \ + $(TOP)/ext/misc/base64.c \ + $(TOP)/ext/misc/base85.c \ + $(TOP)/ext/misc/completion.c \ + $(TOP)/ext/misc/decimal.c \ + $(TOP)/ext/misc/fileio.c \ + $(TOP)/ext/misc/ieee754.c \ + $(TOP)/ext/misc/memtrace.c \ + $(TOP)/ext/misc/pcachetrace.c \ + $(TOP)/ext/misc/regexp.c \ + $(TOP)/ext/misc/series.c \ + $(TOP)/ext/misc/shathree.c \ + $(TOP)/ext/misc/sqlar.c \ + $(TOP)/ext/misc/uint.c \ + $(TOP)/ext/misc/zipfile.c \ + $(TOP)/ext/recover/dbdata.c \ + $(TOP)/ext/recover/sqlite3recover.c \ + $(TOP)/ext/recover/sqlite3recover.h \ + $(TOP)/src/test_windirent.c \ + $(TOP)/src/test_windirent.h + +shell.c: $(SHELL_DEP) $(TOP)/tool/mkshellc.tcl has_tclsh84 $(TCLSH_CMD) $(TOP)/tool/mkshellc.tcl >shell.c diff --git a/Makefile.msc b/Makefile.msc index d0875c92e1..2f67600c31 100644 --- a/Makefile.msc +++ b/Makefile.msc @@ -2272,39 +2272,44 @@ mkkeywordhash.exe: $(TOP)\tool\mkkeywordhash.c keywordhash.h: $(TOP)\tool\mkkeywordhash.c mkkeywordhash.exe .\mkkeywordhash.exe > keywordhash.h -# Source files that go into making shell.c -SHELL_SRC = \ - $(TOP)\src\shell.c.in \ - $(TOP)\ext\consio\console_io.c \ - $(TOP)\ext\consio\console_io.h \ - $(TOP)\ext\misc\appendvfs.c \ - $(TOP)\ext\misc\completion.c \ - $(TOP)\ext\misc\base64.c \ - $(TOP)\ext\misc\base85.c \ - $(TOP)\ext\misc\decimal.c \ - $(TOP)\ext\misc\fileio.c \ - $(TOP)\ext\misc\ieee754.c \ - $(TOP)\ext\misc\regexp.c \ - $(TOP)\ext\misc\series.c \ - $(TOP)\ext\misc\shathree.c \ - $(TOP)\ext\misc\uint.c \ - $(TOP)\ext\expert\sqlite3expert.c \ - $(TOP)\ext\expert\sqlite3expert.h \ - $(TOP)\ext\misc\memtrace.c \ - $(TOP)\ext\misc\pcachetrace.c \ - $(TOP)\ext\recover\dbdata.c \ - $(TOP)\ext\recover\sqlite3recover.c \ - $(TOP)\ext\recover\sqlite3recover.h \ - $(TOP)\src\test_windirent.c +# Source and header files that shell.c depends on +SHELL_DEP = \ + $(TOP)\src\shell.c.in \ + $(TOP)\ext\consio\console_io.c \ + $(TOP)\ext\consio\console_io.h \ + $(TOP)\ext\expert\sqlite3expert.c \ + $(TOP)\ext\expert\sqlite3expert.h \ + $(TOP)\ext\intck\sqlite3intck.c \ + $(TOP)\ext\intck\sqlite3intck.h \ + $(TOP)\ext\misc\appendvfs.c \ + $(TOP)\ext\misc\base64.c \ + $(TOP)\ext\misc\base85.c \ + $(TOP)\ext\misc\completion.c \ + $(TOP)\ext\misc\decimal.c \ + $(TOP)\ext\misc\fileio.c \ + $(TOP)\ext\misc\ieee754.c \ + $(TOP)\ext\misc\memtrace.c \ + $(TOP)\ext\misc\pcachetrace.c \ + $(TOP)\ext\misc\regexp.c \ + $(TOP)\ext\misc\series.c \ + $(TOP)\ext\misc\shathree.c \ + $(TOP)\ext\misc\sqlar.c \ + $(TOP)\ext\misc\uint.c \ + $(TOP)\ext\misc\zipfile.c \ + $(TOP)\ext\recover\dbdata.c \ + $(TOP)\ext\recover\sqlite3recover.c \ + $(TOP)\ext\recover\sqlite3recover.h \ + $(TOP)\src\test_windirent.c \ + $(TOP)\src\test_windirent.h # If use of zlib is enabled, add the "zipfile.c" source file. # !IF $(USE_ZLIB)!=0 -SHELL_SRC = $(SHELL_SRC) $(TOP)\ext\misc\sqlar.c -SHELL_SRC = $(SHELL_SRC) $(TOP)\ext\misc\zipfile.c +SHELL_DEP = $(SHELL_DEP) $(TOP)\ext\misc\sqlar.c +SHELL_DEP = $(SHELL_DEP) $(TOP)\ext\misc\zipfile.c !ENDIF -shell.c: $(SHELL_SRC) $(TOP)\tool\mkshellc.tcl +shell.c: $(SHELL_DEP) $(TOP)\tool\mkshellc.tcl $(TCLSH_CMD) $(TOP)\tool\mkshellc.tcl > shell.c zlib: diff --git a/main.mk b/main.mk index be485b69ed..139e182eb1 100644 --- a/main.mk +++ b/main.mk @@ -718,8 +718,7 @@ opcodes.c: opcodes.h $(TOP)/tool/mkopcodec.tcl tclsh $(TOP)/tool/mkopcodec.tcl opcodes.h >opcodes.c opcodes.h: parse.h $(TOP)/src/vdbe.c $(TOP)/tool/mkopcodeh.tcl - cat parse.h $(TOP)/src/vdbe.c | \ - tclsh $(TOP)/tool/mkopcodeh.tcl >opcodes.h + cat parse.h $(TOP)/src/vdbe.c | tclsh $(TOP)/tool/mkopcodeh.tcl >opcodes.h # Rules to build parse.c and parse.h - the outputs of lemon. # @@ -742,32 +741,37 @@ keywordhash.h: $(TOP)/tool/mkkeywordhash.c $(BCC) -o mkkeywordhash $(OPTS) $(TOP)/tool/mkkeywordhash.c ./mkkeywordhash >keywordhash.h -# Source files that go into making shell.c -SHELL_SRC = \ - $(TOP)/src/shell.c.in \ - $(TOP)/ext/misc/appendvfs.c \ - $(TOP)/ext/misc/completion.c \ - $(TOP)/ext/misc/base64.c \ - $(TOP)/ext/misc/base85.c \ - $(TOP)/ext/misc/decimal.c \ - $(TOP)/ext/misc/fileio.c \ - $(TOP)/ext/misc/ieee754.c \ - $(TOP)/ext/misc/regexp.c \ - $(TOP)/ext/misc/series.c \ - $(TOP)/ext/misc/shathree.c \ - $(TOP)/ext/misc/sqlar.c \ - $(TOP)/ext/misc/uint.c \ - $(TOP)/ext/expert/sqlite3expert.c \ - $(TOP)/ext/expert/sqlite3expert.h \ - $(TOP)/ext/misc/zipfile.c \ - $(TOP)/ext/misc/memtrace.c \ - $(TOP)/ext/misc/pcachetrace.c \ - $(TOP)/ext/recover/dbdata.c \ - $(TOP)/ext/recover/sqlite3recover.c \ - $(TOP)/ext/recover/sqlite3recover.h \ - $(TOP)/src/test_windirent.c - -shell.c: $(SHELL_SRC) $(TOP)/tool/mkshellc.tcl +# Source and header files that shell.c depends on +SHELL_DEP = \ + $(TOP)/src/shell.c.in \ + $(TOP)/ext/consio/console_io.c \ + $(TOP)/ext/consio/console_io.h \ + $(TOP)/ext/expert/sqlite3expert.c \ + $(TOP)/ext/expert/sqlite3expert.h \ + $(TOP)/ext/intck/sqlite3intck.c \ + $(TOP)/ext/intck/sqlite3intck.h \ + $(TOP)/ext/misc/appendvfs.c \ + $(TOP)/ext/misc/base64.c \ + $(TOP)/ext/misc/base85.c \ + $(TOP)/ext/misc/completion.c \ + $(TOP)/ext/misc/decimal.c \ + $(TOP)/ext/misc/fileio.c \ + $(TOP)/ext/misc/ieee754.c \ + $(TOP)/ext/misc/memtrace.c \ + $(TOP)/ext/misc/pcachetrace.c \ + $(TOP)/ext/misc/regexp.c \ + $(TOP)/ext/misc/series.c \ + $(TOP)/ext/misc/shathree.c \ + $(TOP)/ext/misc/sqlar.c \ + $(TOP)/ext/misc/uint.c \ + $(TOP)/ext/misc/zipfile.c \ + $(TOP)/ext/recover/dbdata.c \ + $(TOP)/ext/recover/sqlite3recover.c \ + $(TOP)/ext/recover/sqlite3recover.h \ + $(TOP)/src/test_windirent.c \ + $(TOP)/src/test_windirent.h + +shell.c: $(SHELL_DEP) $(TOP)/tool/mkshellc.tcl tclsh $(TOP)/tool/mkshellc.tcl >shell.c diff --git a/manifest b/manifest index 9a3eabe50d..47ed7609bb 100644 --- a/manifest +++ b/manifest @@ -1,11 +1,11 @@ -C Change\stest\sresults\sin\scorruptC.test\sto\saccount\sfor\sthe\sadded\sdetail\sin\sthe\noutput\sof\s"PRAGMA\sintegrity_check"\sfrom\s[b736519d3d2e93c7]. -D 2024-03-04T16:44:37.718 +C Fix\sa\scompiler\swarning\sin\sdate.c.\s\sUpdate\smakefiles\sto\sinclude\sall\snecessary\ndependencies\sfor\sbuilding\sshell.c. +D 2024-03-04T18:22:18.359 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 -F Makefile.in 3c4f4879b2301e5486939f68cc64f84430861d246ac11430ff1a1d7347ed5b8c +F Makefile.in ca8b906b1c3285fc32cff9978a5b827f99ae3d440077babf32c257a92a2ba11c F Makefile.linux-gcc f3842a0b1efbfbb74ac0ef60e56b301836d05b4d867d014f714fa750048f1ab6 -F Makefile.msc 15a875f6016c4200e7093db92365fabb8b32eb09f9e40e1aadeedeecad4050d5 +F Makefile.msc 72c8436ee7528cb78f7318230548aab145ef05d15a8feed0f3cb251a26384403 F README.md 6358805260a03ebead84e168bbf3740ddf3f683b477e478567186aa7afb490d3 F VERSION c84541c6a9e8426462176fbb1f9ecb5cfd7d1bb56228053ff7eeba8841673eb6 F aclocal.m4 a5c22d164aff7ed549d53a90fa56d56955281f50 @@ -670,7 +670,7 @@ F ext/wasm/wasmfs.make 8a4955882aaa0783b3f60a9484a1f0f3d8b6f775c0fcd17c082f31966 F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8 F magic.txt 5ade0bc977aa135e79e3faaea894d5671b26107cc91e70783aa7dc83f22f3ba0 -F main.mk 2c8b556ba7a4a15f5440663f7b05da221355d1921d5c75298bb50e2bb8081d79 +F main.mk e5da4b6c13f2b15bba7f1efb0a47089dfdde0973e85a024785485655d59fd758 F mptest/config01.test 3c6adcbc50b991866855f1977ff172eb6d901271 F mptest/config02.test 4415dfe36c48785f751e16e32c20b077c28ae504 F mptest/crash01.test 61e61469e257df0850df4293d7d4d6c2af301421 @@ -696,7 +696,7 @@ F src/build.c 04f1bcee189f045ab086d84fee95db42cb49df82ff8e84af8136309ff3c8a75f F src/callback.c db3a45e376deff6a16c0058163fe0ae2b73a2945f3f408ca32cf74960b28d490 F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e F src/ctime.c 23331529e654be40ca97d171cbbffe9b3d4c71cc53b78fe5501230675952da8b -F src/date.c a9e4382961fb26156a308645f7363519ab7eb20e412e78b7c1fe16bbfbb1689a +F src/date.c 126ba2ab10aeb2e7ba6e089b5f07b747c0625b8287f78b60da346eda8d23c875 F src/dbpage.c 80e46e1df623ec40486da7a5086cb723b0275a6e2a7b01d9f9b5da0f04ba2782 F src/dbstat.c 3b677254d512fcafd4d0b341bf267b38b235ccfddbef24f9154e19360fa22e43 F src/delete.c cb766727c78e715f9fb7ec8a7d03658ed2a3016343ca687acfcec9083cdca500 @@ -2176,8 +2176,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 596668e6625208ff5d2ffbb4e0530530ebb3a400efa0df54bad1d91953e32694 -R e247d8c69a2f1de22f60330dc6b8c1d7 +P 0d19eeaafb296aad212ee4f55a0f6df8c7c5185b14d7f7f49c020fe4cbe370c1 +R 191956f8db663f29da20ebca61821faf U drh -Z c67139450867debeac7f30d4414de41e +Z 23a2cbc5a581c90c55252c83bc05fa14 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 063d7c49a5..4c6664f160 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0d19eeaafb296aad212ee4f55a0f6df8c7c5185b14d7f7f49c020fe4cbe370c1 \ No newline at end of file +178b7d46f9c8e1694ed6f506d2785a9f5c49e2b428e04c8096d557cc1b5c9680 \ No newline at end of file diff --git a/src/date.c b/src/date.c index 3bb4a8c714..d74cecb1d9 100644 --- a/src/date.c +++ b/src/date.c @@ -356,7 +356,7 @@ static int parseYyyyMmDd(const char *zDate, DateTime *p){ computeJD(p); } return 0; -}; +} static void clearYMD_HMS_TZ(DateTime *p); /* Forward declaration */ From 2c3973fdff6f3ffa6f8aac63a2c5d3fa02b66a24 Mon Sep 17 00:00:00 2001 From: stephan Date: Tue, 5 Mar 2024 06:31:37 +0000 Subject: [PATCH 167/430] /fiddle: before resetting a db, roll back any transactions (resolves problem reported in [forum:0b41a25d65|forum post 0b41a25d65]) and remove an obsolete/broken reference to a long-gone API which could cause initialization to fail prematurely. FossilOrigin-Name: ee164ca73cf4151b1a1bf351729afa9b0ec95bd5004a5d5bfce3ed46268bfbf3 --- ext/wasm/fiddle/fiddle-worker.js | 5 ++--- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/shell.c.in | 18 ++++++++++++++---- 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/ext/wasm/fiddle/fiddle-worker.js b/ext/wasm/fiddle/fiddle-worker.js index cf0aa1ca2c..27d915eb2c 100644 --- a/ext/wasm/fiddle/fiddle-worker.js +++ b/ext/wasm/fiddle/fiddle-worker.js @@ -166,11 +166,10 @@ stdout("SQLite version", capi.sqlite3_libversion(), capi.sqlite3_sourceid().substr(0,19)); stdout('Welcome to the "fiddle" shell.'); - if(sqlite3.opfs){ + if(capi.sqlite3_vfs_find("opfs")){ stdout("\nOPFS is available. To open a persistent db, use:\n\n", " .open file:name?vfs=opfs\n\nbut note that some", "features (e.g. upload) do not yet work with OPFS."); - sqlite3.opfs.registerVfs(); } stdout('\nEnter ".help" for usage hints.'); this.exec([ // initialization commands... @@ -317,7 +316,7 @@ }; console.warn("Unknown fiddle-worker message type:",ev); }; - + /** emscripten module for use with build mode -sMODULARIZE. */ diff --git a/manifest b/manifest index 47ed7609bb..2e23e4d0aa 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\scompiler\swarning\sin\sdate.c.\s\sUpdate\smakefiles\sto\sinclude\sall\snecessary\ndependencies\sfor\sbuilding\sshell.c. -D 2024-03-04T18:22:18.359 +C /fiddle:\sbefore\sresetting\sa\sdb,\sroll\sback\sany\stransactions\s(resolves\sproblem\sreported\sin\s[forum:0b41a25d65|forum\spost\s0b41a25d65])\sand\sremove\san\sobsolete/broken\sreference\sto\sa\slong-gone\sAPI\swhich\scould\scause\sinitialization\sto\sfail\sprematurely. +D 2024-03-05T06:31:37.489 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -640,7 +640,7 @@ F ext/wasm/dist.make 3a851858aad72e246a5d9c5aaf6b6a144305f1bf898ac1846760ea7bab9 F ext/wasm/example_extra_init.c 2347cd69d19d839ef4e5e77b7855103a7fe3ef2af86f2e8c95839afd8b05862f F ext/wasm/fiddle.make fa2ba6e90457ba2a71cb745f200d409caf773076df75ae5b177cc225d7627a11 F ext/wasm/fiddle/emscripten.css 3d253a6fdb8983a2ac983855bfbdd4b6fa1ff267c28d69513dd6ef1f289ada3f -F ext/wasm/fiddle/fiddle-worker.js 9be57887756c6854dbdcb5e7d8b7a26935d565491333a2f91dc4113598c659b5 +F ext/wasm/fiddle/fiddle-worker.js 850e66fce39b89d59e161d1abac43a181a4caa89ddeea162765d660277cd84ce F ext/wasm/fiddle/fiddle.js 974b995119ac443685d7d94d3b3c58c6a36540e9eb3fed7069d5653284071715 F ext/wasm/fiddle/index.html 5daf54e8f3d7777cbb1ca4f93affe28858dbfff25841cb4ab81d694efed28ec2 F ext/wasm/index-dist.html e91d76e4581185238fd3d42ed86ec600f7023ed3e3a944c5c356f25304bf1263 @@ -751,7 +751,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c d77c6160bc8f249c2196fdd3e75f66a1dd70e37aa25c39aedc7b1f93c42b7c6d F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c 43fabfc01bf87addd15e39f112f1e2ade15b19594835ab8a9e5bd50839d4e1b1 -F src/shell.c.in 2ec564ed3ff0147036be313efeb47b3dbfb8753d5eb5ea0e90636427c6b3a365 +F src/shell.c.in 6e7cd81874e3cea68b4f2dc72a8731a5f545aca0b3e48f132e3c6ee6862e3c0a F src/sqlite.h.in 19a2db3995a699bd7f6dfb423856242bfceb7ec849a93c91d241d19fc28d9f0f F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 @@ -2176,8 +2176,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 0d19eeaafb296aad212ee4f55a0f6df8c7c5185b14d7f7f49c020fe4cbe370c1 -R 191956f8db663f29da20ebca61821faf -U drh -Z 23a2cbc5a581c90c55252c83bc05fa14 +P 178b7d46f9c8e1694ed6f506d2785a9f5c49e2b428e04c8096d557cc1b5c9680 +R 64eca58e8ac762a5eb6b341ff69c8405 +U stephan +Z ff3bca729d13aff9e0b3d1adfb9ed46d # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 4c6664f160..c3a86e0b30 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -178b7d46f9c8e1694ed6f506d2785a9f5c49e2b428e04c8096d557cc1b5c9680 \ No newline at end of file +ee164ca73cf4151b1a1bf351729afa9b0ec95bd5004a5d5bfce3ed46268bfbf3 \ No newline at end of file diff --git a/src/shell.c.in b/src/shell.c.in index 05583b2f34..36bbb93ec1 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -12838,7 +12838,7 @@ sqlite3_vfs * fiddle_db_vfs(const char *zDbName){ /* Only for emcc experimentation purposes. */ sqlite3 * fiddle_db_arg(sqlite3 *arg){ - printf("fiddle_db_arg(%p)\n", (const void*)arg); + oputf("fiddle_db_arg(%p)\n", (const void*)arg); return arg; } @@ -12864,12 +12864,22 @@ const char * fiddle_db_filename(const char * zDbName){ /* ** Completely wipes out the contents of the currently-opened database -** but leaves its storage intact for reuse. +** but leaves its storage intact for reuse. If any transactions are +** active, they are forcibly rolled back. */ void fiddle_reset_db(void){ if( globalDb ){ - int rc = sqlite3_db_config(globalDb, SQLITE_DBCONFIG_RESET_DATABASE, 1, 0); - if( 0==rc ) rc = sqlite3_exec(globalDb, "VACUUM", 0, 0, 0); + int rc; + while( sqlite3_txn_state(globalDb,0)>0 ){ + /* + ** Resolve problem reported in + ** https://sqlite.org/forum/forumpost/0b41a25d65 + */ + oputz("Rolling back in-progress transaction.\n"); + sqlite3_exec(globalDb,"ROLLBACK", 0, 0, 0); + } + rc = sqlite3_db_config(globalDb, SQLITE_DBCONFIG_RESET_DATABASE, 1, 0); + if( 0==rc ) sqlite3_exec(globalDb, "VACUUM", 0, 0, 0); sqlite3_db_config(globalDb, SQLITE_DBCONFIG_RESET_DATABASE, 0, 0); } } From d5045a92462977e7655e8ec2f842b16e3d6f7cac Mon Sep 17 00:00:00 2001 From: stephan Date: Tue, 5 Mar 2024 07:55:20 +0000 Subject: [PATCH 168/430] Update fiddle.make to account for Makefile changes in [178b7d46f9]. FossilOrigin-Name: 7a5d810549f2686ae923fd0ca03ad8f536c9080b6879128ee8f00e653bb7f3f1 --- ext/wasm/fiddle.make | 10 ++++++---- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/ext/wasm/fiddle.make b/ext/wasm/fiddle.make index 57141d7e2b..496e518de6 100644 --- a/ext/wasm/fiddle.make +++ b/ext/wasm/fiddle.make @@ -9,16 +9,18 @@ MAKEFILE.fiddle := $(lastword $(MAKEFILE_LIST)) # shell.c and its build flags... make-np-0 := make -C $(dir.top) -n -p make-np-1 := sed -e 's/(TOP)/(dir.top)/g' +# Extract SHELL_OPT and SHELL_DEP from the top-most makefile and import +# them as vars here... $(eval $(shell $(make-np-0) | grep -e '^SHELL_OPT ' | $(make-np-1))) -$(eval $(shell $(make-np-0) | grep -e '^SHELL_SRC ' | $(make-np-1))) +$(eval $(shell $(make-np-0) | grep -e '^SHELL_DEP ' | $(make-np-1))) # ^^^ can't do that in 1 invocation b/c newlines get stripped ifeq (,$(SHELL_OPT)) $(error Could not parse SHELL_OPT from $(dir.top)/Makefile.) endif -ifeq (,$(SHELL_SRC)) -$(error Could not parse SHELL_SRC from $(dir.top)/Makefile.) +ifeq (,$(SHELL_DEP)) +$(error Could not parse SHELL_DEP from $(dir.top)/Makefile.) endif -$(dir.top)/shell.c: $(SHELL_SRC) $(dir.top)/tool/mkshellc.tcl $(sqlite3.c) +$(dir.top)/shell.c: $(SHELL_DEP) $(dir.top)/tool/mkshellc.tcl $(sqlite3.c) $(MAKE) -C $(dir.top) shell.c # /shell.c ######################################################################## diff --git a/manifest b/manifest index 2e23e4d0aa..5d51d24787 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C /fiddle:\sbefore\sresetting\sa\sdb,\sroll\sback\sany\stransactions\s(resolves\sproblem\sreported\sin\s[forum:0b41a25d65|forum\spost\s0b41a25d65])\sand\sremove\san\sobsolete/broken\sreference\sto\sa\slong-gone\sAPI\swhich\scould\scause\sinitialization\sto\sfail\sprematurely. -D 2024-03-05T06:31:37.489 +C Update\sfiddle.make\sto\saccount\sfor\sMakefile\schanges\sin\s[178b7d46f9]. +D 2024-03-05T07:55:20.122 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -638,7 +638,7 @@ F ext/wasm/demo-worker1.html 2c178c1890a2beb5a5fecb1453e796d067a4b8d3d2a04d65ca2 F ext/wasm/demo-worker1.js 836bece8615b17b1b572584f7b15912236a5947fe8c68b98d2737d7e287447ef F ext/wasm/dist.make 3a851858aad72e246a5d9c5aaf6b6a144305f1bf898ac1846760ea7bab95c9a3 F ext/wasm/example_extra_init.c 2347cd69d19d839ef4e5e77b7855103a7fe3ef2af86f2e8c95839afd8b05862f -F ext/wasm/fiddle.make fa2ba6e90457ba2a71cb745f200d409caf773076df75ae5b177cc225d7627a11 +F ext/wasm/fiddle.make 3c2eace29255d6ddd219f5d8cc2728cb28b9fe717ea80b6062c2a6178947a16b F ext/wasm/fiddle/emscripten.css 3d253a6fdb8983a2ac983855bfbdd4b6fa1ff267c28d69513dd6ef1f289ada3f F ext/wasm/fiddle/fiddle-worker.js 850e66fce39b89d59e161d1abac43a181a4caa89ddeea162765d660277cd84ce F ext/wasm/fiddle/fiddle.js 974b995119ac443685d7d94d3b3c58c6a36540e9eb3fed7069d5653284071715 @@ -2176,8 +2176,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 178b7d46f9c8e1694ed6f506d2785a9f5c49e2b428e04c8096d557cc1b5c9680 -R 64eca58e8ac762a5eb6b341ff69c8405 +P ee164ca73cf4151b1a1bf351729afa9b0ec95bd5004a5d5bfce3ed46268bfbf3 +R 83071ca8acab359a5924e5d4cf357b67 U stephan -Z ff3bca729d13aff9e0b3d1adfb9ed46d +Z 2b4d9c85414ada098b40af0814689ab8 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index c3a86e0b30..b6932ff82e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ee164ca73cf4151b1a1bf351729afa9b0ec95bd5004a5d5bfce3ed46268bfbf3 \ No newline at end of file +7a5d810549f2686ae923fd0ca03ad8f536c9080b6879128ee8f00e653bb7f3f1 \ No newline at end of file From 7eb0ddf68b11a333c3056818cac31d6b8ad44455 Mon Sep 17 00:00:00 2001 From: stephan Date: Tue, 5 Mar 2024 08:48:40 +0000 Subject: [PATCH 169/430] /fiddle 'Mandlebrot' typo fix reported in the forum. FossilOrigin-Name: ceefe6ba380c18279c2ae88443649e00e5e8110b529d447131ea9726de61f5d0 --- ext/wasm/fiddle/fiddle.js | 2 +- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ext/wasm/fiddle/fiddle.js b/ext/wasm/fiddle/fiddle.js index 2a3d1746f3..73c55af9c5 100644 --- a/ext/wasm/fiddle/fiddle.js +++ b/ext/wasm/fiddle/fiddle.js @@ -742,7 +742,7 @@ {name: "Table list", sql: ".tables"}, {name: "Box Mode", sql: ".mode box"}, {name: "JSON Mode", sql: ".mode json"}, - {name: "Mandlebrot", sql:[ + {name: "Mandelbrot", sql:[ "WITH RECURSIVE", " xaxis(x) AS (VALUES(-2.0) UNION ALL SELECT x+0.05 FROM xaxis WHERE x<1.2),\n", " yaxis(y) AS (VALUES(-1.0) UNION ALL SELECT y+0.1 FROM yaxis WHERE y<1.0),\n", diff --git a/manifest b/manifest index 5d51d24787..14997b656f 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Update\sfiddle.make\sto\saccount\sfor\sMakefile\schanges\sin\s[178b7d46f9]. -D 2024-03-05T07:55:20.122 +C /fiddle\s'Mandlebrot'\stypo\sfix\sreported\sin\sthe\sforum. +D 2024-03-05T08:48:40.508 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -641,7 +641,7 @@ F ext/wasm/example_extra_init.c 2347cd69d19d839ef4e5e77b7855103a7fe3ef2af86f2e8c F ext/wasm/fiddle.make 3c2eace29255d6ddd219f5d8cc2728cb28b9fe717ea80b6062c2a6178947a16b F ext/wasm/fiddle/emscripten.css 3d253a6fdb8983a2ac983855bfbdd4b6fa1ff267c28d69513dd6ef1f289ada3f F ext/wasm/fiddle/fiddle-worker.js 850e66fce39b89d59e161d1abac43a181a4caa89ddeea162765d660277cd84ce -F ext/wasm/fiddle/fiddle.js 974b995119ac443685d7d94d3b3c58c6a36540e9eb3fed7069d5653284071715 +F ext/wasm/fiddle/fiddle.js 3d5cbee561bfd317f1fc83c429a0f29e7d36b9494bb983b58bed25b5b49295d7 F ext/wasm/fiddle/index.html 5daf54e8f3d7777cbb1ca4f93affe28858dbfff25841cb4ab81d694efed28ec2 F ext/wasm/index-dist.html e91d76e4581185238fd3d42ed86ec600f7023ed3e3a944c5c356f25304bf1263 F ext/wasm/index.html b31ce41c0da476d5ffcef23069b9d3415b419d65af5779096ebcfbcbade453a9 @@ -2176,8 +2176,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P ee164ca73cf4151b1a1bf351729afa9b0ec95bd5004a5d5bfce3ed46268bfbf3 -R 83071ca8acab359a5924e5d4cf357b67 +P 7a5d810549f2686ae923fd0ca03ad8f536c9080b6879128ee8f00e653bb7f3f1 +R dedcee47046ad2c820affc54bbfebf0e U stephan -Z 2b4d9c85414ada098b40af0814689ab8 +Z b6cbff2ce0125252a8326bff1a4d2a0d # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index b6932ff82e..134a211ac4 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7a5d810549f2686ae923fd0ca03ad8f536c9080b6879128ee8f00e653bb7f3f1 \ No newline at end of file +ceefe6ba380c18279c2ae88443649e00e5e8110b529d447131ea9726de61f5d0 \ No newline at end of file From 891aa0545071329a1898815e8304d67299dee758 Mon Sep 17 00:00:00 2001 From: stephan Date: Tue, 5 Mar 2024 12:48:26 +0000 Subject: [PATCH 170/430] /fiddle: reorder/replace example entries to make them more coherent when tried in order and clear the example selection list when the input area is cleared, both based on forum feedback. FossilOrigin-Name: b4ce270b3f19499385d0923f0f28f702c8f664476def3994fdba5d418e3c5edb --- ext/wasm/fiddle/fiddle.js | 7 ++++--- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/ext/wasm/fiddle/fiddle.js b/ext/wasm/fiddle/fiddle.js index 73c55af9c5..f409d92112 100644 --- a/ext/wasm/fiddle/fiddle.js +++ b/ext/wasm/fiddle/fiddle.js @@ -403,8 +403,10 @@ E('#btn-reset').addEventListener('click',()=>SF.resetDb()); const taInput = E('#input'); const btnClearIn = E('#btn-clear'); + const selectExamples = E('#select-examples'); btnClearIn.addEventListener('click',function(){ taInput.value = ''; + selectExamples.selectedIndex = 0; },false); // Ctrl-enter and shift-enter both run the current SQL. taInput.addEventListener('keydown',function(ev){ @@ -733,15 +735,14 @@ ]}, //{name: "Timer on", sql: ".timer on"}, // ^^^ re-enable if emscripten re-enables getrusage() + {name: "Box Mode", sql: ".mode box"}, {name: "Setup table T", sql:[ ".nullvalue NULL\n", "CREATE TABLE t(a,b);\n", "INSERT INTO t(a,b) VALUES('abc',123),('def',456),(NULL,789),('ghi',012);\n", "SELECT * FROM t;\n" ]}, - {name: "Table list", sql: ".tables"}, - {name: "Box Mode", sql: ".mode box"}, - {name: "JSON Mode", sql: ".mode json"}, + {name: "sqlite_schema", sql: "select * from sqlite_schema"}, {name: "Mandelbrot", sql:[ "WITH RECURSIVE", " xaxis(x) AS (VALUES(-2.0) UNION ALL SELECT x+0.05 FROM xaxis WHERE x<1.2),\n", diff --git a/manifest b/manifest index 14997b656f..888463b04b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C /fiddle\s'Mandlebrot'\stypo\sfix\sreported\sin\sthe\sforum. -D 2024-03-05T08:48:40.508 +C /fiddle:\sreorder/replace\sexample\sentries\sto\smake\sthem\smore\scoherent\swhen\stried\sin\sorder\sand\sclear\sthe\sexample\sselection\slist\swhen\sthe\sinput\sarea\sis\scleared,\sboth\sbased\son\sforum\sfeedback. +D 2024-03-05T12:48:26.029 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -641,7 +641,7 @@ F ext/wasm/example_extra_init.c 2347cd69d19d839ef4e5e77b7855103a7fe3ef2af86f2e8c F ext/wasm/fiddle.make 3c2eace29255d6ddd219f5d8cc2728cb28b9fe717ea80b6062c2a6178947a16b F ext/wasm/fiddle/emscripten.css 3d253a6fdb8983a2ac983855bfbdd4b6fa1ff267c28d69513dd6ef1f289ada3f F ext/wasm/fiddle/fiddle-worker.js 850e66fce39b89d59e161d1abac43a181a4caa89ddeea162765d660277cd84ce -F ext/wasm/fiddle/fiddle.js 3d5cbee561bfd317f1fc83c429a0f29e7d36b9494bb983b58bed25b5b49295d7 +F ext/wasm/fiddle/fiddle.js 04a638e3ed8fc9ca7c05cbe73ac4196e4529ec564639a76fbcecaffdf62bd983 F ext/wasm/fiddle/index.html 5daf54e8f3d7777cbb1ca4f93affe28858dbfff25841cb4ab81d694efed28ec2 F ext/wasm/index-dist.html e91d76e4581185238fd3d42ed86ec600f7023ed3e3a944c5c356f25304bf1263 F ext/wasm/index.html b31ce41c0da476d5ffcef23069b9d3415b419d65af5779096ebcfbcbade453a9 @@ -2176,8 +2176,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 7a5d810549f2686ae923fd0ca03ad8f536c9080b6879128ee8f00e653bb7f3f1 -R dedcee47046ad2c820affc54bbfebf0e +P ceefe6ba380c18279c2ae88443649e00e5e8110b529d447131ea9726de61f5d0 +R 3f0174e7da224959eee01bc457acd8b1 U stephan -Z b6cbff2ce0125252a8326bff1a4d2a0d +Z 597983e79d7a5c5d218f87484b9eb1bc # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 134a211ac4..8dabc0f49f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ceefe6ba380c18279c2ae88443649e00e5e8110b529d447131ea9726de61f5d0 \ No newline at end of file +b4ce270b3f19499385d0923f0f28f702c8f664476def3994fdba5d418e3c5edb \ No newline at end of file From 28001204f4afcd2bba65ba7a5704d2e60b405ba6 Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 5 Mar 2024 16:47:48 +0000 Subject: [PATCH 171/430] The value returned by the json_each.json field needs to survive longer than the json_each virtual table itself, in the event that the value is used in an aggregate expression. dbsqlfuzz 5120bd0b3bb0b73eebbcb79ac37c6b0663fccad6 FossilOrigin-Name: 952ed71b9b61e79fe807ac3134bdfa7c94a415e02f13f94440a34d6d548d171e --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/json.c | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 888463b04b..7fb6fd304c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C /fiddle:\sreorder/replace\sexample\sentries\sto\smake\sthem\smore\scoherent\swhen\stried\sin\sorder\sand\sclear\sthe\sexample\sselection\slist\swhen\sthe\sinput\sarea\sis\scleared,\sboth\sbased\son\sforum\sfeedback. -D 2024-03-05T12:48:26.029 +C The\svalue\sreturned\sby\sthe\sjson_each.json\sfield\sneeds\sto\ssurvive\slonger\sthan\nthe\sjson_each\svirtual\stable\sitself,\sin\sthe\sevent\sthat\sthe\svalue\sis\sused\sin\nan\saggregate\sexpression.\s\sdbsqlfuzz\s5120bd0b3bb0b73eebbcb79ac37c6b0663fccad6 +D 2024-03-05T16:47:48.118 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -710,7 +710,7 @@ F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 F src/insert.c 3f0a94082d978bbdd33c38fefea15346c6c6bffb70bc645a71dc0f1f87dd3276 -F src/json.c 3b4e2778d95d923d6d77e8a5efd51a6265017b466782d597303f5f094fcd68af +F src/json.c 9337dac9d9d4c77461db55fd3e06e4d006f4283cb1da2b3a9b1f8d750701583e F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 F src/main.c 438b95162acfa17b7d218f586f5bde11d6ae82bcf030c9611fc537556870ad6b @@ -2176,8 +2176,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P ceefe6ba380c18279c2ae88443649e00e5e8110b529d447131ea9726de61f5d0 -R 3f0174e7da224959eee01bc457acd8b1 -U stephan -Z 597983e79d7a5c5d218f87484b9eb1bc +P b4ce270b3f19499385d0923f0f28f702c8f664476def3994fdba5d418e3c5edb +R c608a41202eeb1dd993e7f11e029f933 +U drh +Z 7dedc29c56fa74e9a5dfd76b2357e847 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 8dabc0f49f..14670d7436 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b4ce270b3f19499385d0923f0f28f702c8f664476def3994fdba5d418e3c5edb \ No newline at end of file +952ed71b9b61e79fe807ac3134bdfa7c94a415e02f13f94440a34d6d548d171e \ No newline at end of file diff --git a/src/json.c b/src/json.c index 1227ada78e..fe7f938883 100644 --- a/src/json.c +++ b/src/json.c @@ -4993,9 +4993,9 @@ static int jsonEachColumn( case JEACH_JSON: { if( p->sParse.zJson==0 ){ sqlite3_result_blob(ctx, p->sParse.aBlob, p->sParse.nBlob, - SQLITE_STATIC); + SQLITE_TRANSIENT); }else{ - sqlite3_result_text(ctx, p->sParse.zJson, -1, SQLITE_STATIC); + sqlite3_result_text(ctx, p->sParse.zJson, -1, SQLITE_TRANSIENT); } break; } From 75aed691585281de2d75032e24d20d77d674ddac Mon Sep 17 00:00:00 2001 From: stephan Date: Tue, 5 Mar 2024 17:33:04 +0000 Subject: [PATCH 172/430] Reformulate [34439fe3aeea7cbb] slightly to resolve a false-positive OOM reported in [forum:2eadfe94e3|forum post 2eadfe94e3]. FossilOrigin-Name: 8290646792bc5411112b0c01dc5ac0837743056a7679725ee2edefef2e10d146 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/shell.c.in | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 7fb6fd304c..b875311c58 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C The\svalue\sreturned\sby\sthe\sjson_each.json\sfield\sneeds\sto\ssurvive\slonger\sthan\nthe\sjson_each\svirtual\stable\sitself,\sin\sthe\sevent\sthat\sthe\svalue\sis\sused\sin\nan\saggregate\sexpression.\s\sdbsqlfuzz\s5120bd0b3bb0b73eebbcb79ac37c6b0663fccad6 -D 2024-03-05T16:47:48.118 +C Reformulate\s[34439fe3aeea7cbb]\sslightly\sto\sresolve\sa\sfalse-positive\sOOM\sreported\sin\s[forum:2eadfe94e3|forum\spost\s2eadfe94e3]. +D 2024-03-05T17:33:04.627 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -751,7 +751,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c d77c6160bc8f249c2196fdd3e75f66a1dd70e37aa25c39aedc7b1f93c42b7c6d F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c 43fabfc01bf87addd15e39f112f1e2ade15b19594835ab8a9e5bd50839d4e1b1 -F src/shell.c.in 6e7cd81874e3cea68b4f2dc72a8731a5f545aca0b3e48f132e3c6ee6862e3c0a +F src/shell.c.in 78bbd861cd0128aed67c0136561572ebcf11649be6cea86bee8491576d5958d0 F src/sqlite.h.in 19a2db3995a699bd7f6dfb423856242bfceb7ec849a93c91d241d19fc28d9f0f F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 @@ -2176,8 +2176,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P b4ce270b3f19499385d0923f0f28f702c8f664476def3994fdba5d418e3c5edb -R c608a41202eeb1dd993e7f11e029f933 -U drh -Z 7dedc29c56fa74e9a5dfd76b2357e847 +P 952ed71b9b61e79fe807ac3134bdfa7c94a415e02f13f94440a34d6d548d171e +R 7a7e70231da662a6d891be7e73e90380 +U stephan +Z b9dbf98318196caf6d04789a6da016ae # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 14670d7436..59d20d5266 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -952ed71b9b61e79fe807ac3134bdfa7c94a415e02f13f94440a34d6d548d171e \ No newline at end of file +8290646792bc5411112b0c01dc5ac0837743056a7679725ee2edefef2e10d146 \ No newline at end of file diff --git a/src/shell.c.in b/src/shell.c.in index 36bbb93ec1..1d7f8df450 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -3776,6 +3776,7 @@ static void exec_prepared_stmt_columnar( rc = sqlite3_step(pStmt); if( rc!=SQLITE_ROW ) return; nColumn = sqlite3_column_count(pStmt); + if( nColumn==0 ) goto columnar_end; nAlloc = nColumn*4; if( nAlloc<=0 ) nAlloc = 1; azData = sqlite3_malloc64( nAlloc*sizeof(char*) ); @@ -3861,7 +3862,6 @@ static void exec_prepared_stmt_columnar( if( n>p->actualWidth[j] ) p->actualWidth[j] = n; } if( seenInterrupt ) goto columnar_end; - if( nColumn==0 ) goto columnar_end; switch( p->cMode ){ case MODE_Column: { colSep = " "; From 7ab40cda7be4ba05f45ecf30053f2cdf41248eff Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 5 Mar 2024 18:41:03 +0000 Subject: [PATCH 173/430] Remove code that added a P4 parameter to the OP_Variable opcode. This is no longer required. FossilOrigin-Name: dd5977c9a8a418be3fbd646d74933996381099a9263a02eb4a990f0084463dc1 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/expr.c | 6 ------ src/vdbe.c | 8 ++------ 4 files changed, 11 insertions(+), 21 deletions(-) diff --git a/manifest b/manifest index b875311c58..1364d73542 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Reformulate\s[34439fe3aeea7cbb]\sslightly\sto\sresolve\sa\sfalse-positive\sOOM\sreported\sin\s[forum:2eadfe94e3|forum\spost\s2eadfe94e3]. -D 2024-03-05T17:33:04.627 +C Remove\scode\sthat\sadded\sa\sP4\sparameter\sto\sthe\sOP_Variable\sopcode.\sThis\sis\sno\slonger\srequired. +D 2024-03-05T18:41:03.600 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -700,7 +700,7 @@ F src/date.c 126ba2ab10aeb2e7ba6e089b5f07b747c0625b8287f78b60da346eda8d23c875 F src/dbpage.c 80e46e1df623ec40486da7a5086cb723b0275a6e2a7b01d9f9b5da0f04ba2782 F src/dbstat.c 3b677254d512fcafd4d0b341bf267b38b235ccfddbef24f9154e19360fa22e43 F src/delete.c cb766727c78e715f9fb7ec8a7d03658ed2a3016343ca687acfcec9083cdca500 -F src/expr.c 2803f5e7e3458ced24c0de48ec3640cd7a68ec61350d99c9f30b1bcd6640bd61 +F src/expr.c 05516e8b7d7d22f98160a0360fde69edce3304a430600567ed33e66d588ca59b F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c a47610f0a5c6cb0ad79f8fcef039c01833dec0c751bb695f28dc0ec6a4c3ba00 F src/func.c 4204c56196847faefef57fa14e43b8e4d65eb8d7e65318abe463472e3fd148cb @@ -820,7 +820,7 @@ F src/upsert.c fa125a8d3410ce9a97b02cb50f7ae68a2476c405c76aa692d3acf6b8586e9242 F src/utf.c f23165685a67b4caf8ec08fb274cb3f319103decfb2a980b7cfd55d18dfa855e F src/util.c 0765014847e2a06c952dd64aef0bea5144cd5b335a161eb0768ebe4f63dfe216 F src/vacuum.c 604fcdaebe76f3497c855afcbf91b8fa5046b32de3045bab89cc008d68e40104 -F src/vdbe.c 523a88b3df328810fbcbb407738c352dd9d5163b7af4c953e6e9887a4b582859 +F src/vdbe.c 7a33c5bb37e12ce35ac2d1d56a6429288b0b56c940ba660265c1428c67883729 F src/vdbe.h c2d78d15112c3fc5ab87f5e8e0b75d2db1c624409de2e858c3d1aafb1650bb4f F src/vdbeInt.h 949669dfd8a41550d27dcb905b494f2ccde9a2e6c1b0b04daa1227e2e74c2b2c F src/vdbeapi.c 8f57d60c89da0b60e6d4e272358c511f6bae4e24330bdb11f8b42f986d1bf21b @@ -2176,8 +2176,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 952ed71b9b61e79fe807ac3134bdfa7c94a415e02f13f94440a34d6d548d171e -R 7a7e70231da662a6d891be7e73e90380 -U stephan -Z b9dbf98318196caf6d04789a6da016ae +P 8290646792bc5411112b0c01dc5ac0837743056a7679725ee2edefef2e10d146 +R 1ae68caeb21ed926e0c7d42963259d28 +U dan +Z 4bf196184c1c27ebc7d6a427ff362e10 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 59d20d5266..663d96d614 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8290646792bc5411112b0c01dc5ac0837743056a7679725ee2edefef2e10d146 \ No newline at end of file +dd5977c9a8a418be3fbd646d74933996381099a9263a02eb4a990f0084463dc1 \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index e2cc15cfd6..6640d1907d 100644 --- a/src/expr.c +++ b/src/expr.c @@ -4617,12 +4617,6 @@ int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target){ assert( pExpr->u.zToken!=0 ); assert( pExpr->u.zToken[0]!=0 ); sqlite3VdbeAddOp2(v, OP_Variable, pExpr->iColumn, target); - if( pExpr->u.zToken[1]!=0 ){ - const char *z = sqlite3VListNumToName(pParse->pVList, pExpr->iColumn); - assert( pExpr->u.zToken[0]=='?' || (z && !strcmp(pExpr->u.zToken, z)) ); - pParse->pVList[0] = 0; /* Indicate VList may no longer be enlarged */ - sqlite3VdbeAppendP4(v, (char*)z, P4_STATIC); - } return target; } case TK_REGISTER: { diff --git a/src/vdbe.c b/src/vdbe.c index 489c4825f4..709ebd9fb8 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -1512,19 +1512,15 @@ case OP_Blob: { /* out2 */ break; } -/* Opcode: Variable P1 P2 * P4 * -** Synopsis: r[P2]=parameter(P1,P4) +/* Opcode: Variable P1 P2 * * * +** Synopsis: r[P2]=parameter(P1) ** ** Transfer the values of bound parameter P1 into register P2 -** -** If the parameter is named, then its name appears in P4. -** The P4 value is used by sqlite3_bind_parameter_name(). */ case OP_Variable: { /* out2 */ Mem *pVar; /* Value being transferred */ assert( pOp->p1>0 && pOp->p1<=p->nVar ); - assert( pOp->p4.z==0 || pOp->p4.z==sqlite3VListNumToName(p->pVList,pOp->p1) ); pVar = &p->aVar[pOp->p1 - 1]; if( sqlite3VdbeMemTooBig(pVar) ){ goto too_big; From 53ca213e7345167e23e79740476ec5b65fc0adb2 Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 6 Mar 2024 11:35:36 +0000 Subject: [PATCH 174/430] =?UTF-8?q?Fix=20handling=20of=20"id=3D=3F"=20corn?= =?UTF-8?q?er=20cases=20in=20rtree=20when=20the=20value=20on=20the=20RHS?= =?UTF-8?q?=20is=20a=20real=20value.?= FossilOrigin-Name: 027e5336acc26f57f21df4980928731026c30cf88688fa0b66f13ffa0b5da3a0 --- ext/rtree/rtree.c | 2 +- ext/rtree/rtree1.test | 12 ++++++++++++ manifest | 14 +++++++------- manifest.uuid | 2 +- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/ext/rtree/rtree.c b/ext/rtree/rtree.c index 11996d110c..f2585bc25f 100644 --- a/ext/rtree/rtree.c +++ b/ext/rtree/rtree.c @@ -1870,7 +1870,7 @@ static int rtreeFilter( i64 iNode = 0; int eType = sqlite3_value_numeric_type(argv[0]); if( eType==SQLITE_INTEGER - || (eType==SQLITE_FLOAT && sqlite3_value_double(argv[0])==iRowid) + || (eType==SQLITE_FLOAT && (i64)(sqlite3_value_double(argv[0]))==iRowid) ){ rc = findLeafNode(pRtree, iRowid, &pLeaf, &iNode); }else{ diff --git a/ext/rtree/rtree1.test b/ext/rtree/rtree1.test index 61664e1529..467a523fe5 100644 --- a/ext/rtree/rtree1.test +++ b/ext/rtree/rtree1.test @@ -797,4 +797,16 @@ do_test 23.0 { db eval {PRAGMA integrity_check;} } {ok} +reset_db +do_execsql_test 24.0 { + CREATE VIRTUAL TABLE rt1 USING rtree_i32(rid, c1, c2); + INSERT INTO rt1(rid, c1, c2) VALUES (9223372036854775807, 10, 18); +} + +do_execsql_test 1.1 { + SELECT (rid = (CAST (9223372036854775807 AS REAL))) + FROM rt1 WHERE + (rid = (CAST (9223372036854775807 AS REAL))); +} + finish_test diff --git a/manifest b/manifest index 1364d73542..8808c702a3 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\scode\sthat\sadded\sa\sP4\sparameter\sto\sthe\sOP_Variable\sopcode.\sThis\sis\sno\slonger\srequired. -D 2024-03-05T18:41:03.600 +C Fix\shandling\sof\s"id=?"\scorner\scases\sin\srtree\swhen\sthe\svalue\son\sthe\sRHS\sis\sa\sreal\svalue. +D 2024-03-06T11:35:36.090 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -506,9 +506,9 @@ F ext/repair/test/checkindex01.test b530f141413b587c9eb78ff734de6bb79bc3515c3350 F ext/repair/test/test.tcl 686d76d888dffd021f64260abf29a55c57b2cedfa7fc69150b42b1d6119aac3c F ext/rtree/README 6315c0d73ebf0ec40dedb5aa0e942bc8b54e3761 F ext/rtree/geopoly.c 0dd4775e896cee6067979d67aff7c998e75c2c9d9cd8d62a1a790c09cde7adca -F ext/rtree/rtree.c 1baf9f6aa7251ddecdb019d914df4db46eb227720c00f89c485c66dbfdc7863d +F ext/rtree/rtree.c 57e5269d7d3c502626dfb3dcb3866cb49f0e965b5b3457c8e8e4c092d9d54d34 F ext/rtree/rtree.h 4a690463901cb5e6127cf05eb8e642f127012fd5003830dbc974eca5802d9412 -F ext/rtree/rtree1.test 2b5b8c719c6a4abe377f57766f428a49af36a93061cb146cccfdc3b30000c0a4 +F ext/rtree/rtree1.test aa738f9956be79de80688ebe515d5b96de75ddd5a8cf3b18819b29f5853ddbdb F ext/rtree/rtree2.test 9d9deddbb16fd0c30c36e6b4fdc3ee3132d765567f0f9432ee71e1303d32603d F ext/rtree/rtree3.test 272594f88c344e973864008bbe4c71fd3a41a264c097d568593ee7886d83d409 F ext/rtree/rtree4.test 304de65d484540111b896827e4261815e5dca4ce28eeecd58be648cd73452c4b @@ -2176,8 +2176,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 8290646792bc5411112b0c01dc5ac0837743056a7679725ee2edefef2e10d146 -R 1ae68caeb21ed926e0c7d42963259d28 +P dd5977c9a8a418be3fbd646d74933996381099a9263a02eb4a990f0084463dc1 +R 0d34808880ac8ee78310466df4068ad3 U dan -Z 4bf196184c1c27ebc7d6a427ff362e10 +Z f219ac544948fab5884c3a1cf576bfbe # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 663d96d614..ac34f60cfe 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -dd5977c9a8a418be3fbd646d74933996381099a9263a02eb4a990f0084463dc1 \ No newline at end of file +027e5336acc26f57f21df4980928731026c30cf88688fa0b66f13ffa0b5da3a0 \ No newline at end of file From a64342ee9cca331cddda4c2c241d593c7516c999 Mon Sep 17 00:00:00 2001 From: drh <> Date: Wed, 6 Mar 2024 12:28:55 +0000 Subject: [PATCH 175/430] Correction to the previous check-in. FossilOrigin-Name: 483fa2969e1e10cd8e8d2f9e3027871c65b1360b6c23897efe3ce63a3a55ae13 --- ext/rtree/rtree.c | 4 +++- ext/rtree/rtree1.test | 8 +++++++- manifest | 16 ++++++++-------- manifest.uuid | 2 +- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/ext/rtree/rtree.c b/ext/rtree/rtree.c index f2585bc25f..a24304a8ac 100644 --- a/ext/rtree/rtree.c +++ b/ext/rtree/rtree.c @@ -1870,7 +1870,9 @@ static int rtreeFilter( i64 iNode = 0; int eType = sqlite3_value_numeric_type(argv[0]); if( eType==SQLITE_INTEGER - || (eType==SQLITE_FLOAT && (i64)(sqlite3_value_double(argv[0]))==iRowid) + || (eType==SQLITE_FLOAT + && (i64)(sqlite3_value_double(argv[0]))==iRowid + && (double)iRowid==sqlite3_value_double(argv[0])) ){ rc = findLeafNode(pRtree, iRowid, &pLeaf, &iNode); }else{ diff --git a/ext/rtree/rtree1.test b/ext/rtree/rtree1.test index 467a523fe5..e596df71d5 100644 --- a/ext/rtree/rtree1.test +++ b/ext/rtree/rtree1.test @@ -803,10 +803,16 @@ do_execsql_test 24.0 { INSERT INTO rt1(rid, c1, c2) VALUES (9223372036854775807, 10, 18); } -do_execsql_test 1.1 { +do_execsql_test 24.1 { SELECT (rid = (CAST (9223372036854775807 AS REAL))) FROM rt1 WHERE (rid = (CAST (9223372036854775807 AS REAL))); } +do_execsql_test 24.2 { + DELETE FROM rt1; + INSERT INTO rt1(rid, c1, c2) VALUES(1,2,3); + SELECT * FROM rt1 WHERE rid=1.005; +} {} + finish_test diff --git a/manifest b/manifest index 8808c702a3..da94066647 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\shandling\sof\s"id=?"\scorner\scases\sin\srtree\swhen\sthe\svalue\son\sthe\sRHS\sis\sa\sreal\svalue. -D 2024-03-06T11:35:36.090 +C Correction\sto\sthe\sprevious\scheck-in. +D 2024-03-06T12:28:55.128 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -506,9 +506,9 @@ F ext/repair/test/checkindex01.test b530f141413b587c9eb78ff734de6bb79bc3515c3350 F ext/repair/test/test.tcl 686d76d888dffd021f64260abf29a55c57b2cedfa7fc69150b42b1d6119aac3c F ext/rtree/README 6315c0d73ebf0ec40dedb5aa0e942bc8b54e3761 F ext/rtree/geopoly.c 0dd4775e896cee6067979d67aff7c998e75c2c9d9cd8d62a1a790c09cde7adca -F ext/rtree/rtree.c 57e5269d7d3c502626dfb3dcb3866cb49f0e965b5b3457c8e8e4c092d9d54d34 +F ext/rtree/rtree.c d87dfef2dd8ee2360898857187b9f763e90dcee9cf98f3f487ec473b6ae30db3 F ext/rtree/rtree.h 4a690463901cb5e6127cf05eb8e642f127012fd5003830dbc974eca5802d9412 -F ext/rtree/rtree1.test aa738f9956be79de80688ebe515d5b96de75ddd5a8cf3b18819b29f5853ddbdb +F ext/rtree/rtree1.test e0608db762b2aadca0ecb6f97396cf66244490adc3ba88f2a292b27be3e1da3e F ext/rtree/rtree2.test 9d9deddbb16fd0c30c36e6b4fdc3ee3132d765567f0f9432ee71e1303d32603d F ext/rtree/rtree3.test 272594f88c344e973864008bbe4c71fd3a41a264c097d568593ee7886d83d409 F ext/rtree/rtree4.test 304de65d484540111b896827e4261815e5dca4ce28eeecd58be648cd73452c4b @@ -2176,8 +2176,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P dd5977c9a8a418be3fbd646d74933996381099a9263a02eb4a990f0084463dc1 -R 0d34808880ac8ee78310466df4068ad3 -U dan -Z f219ac544948fab5884c3a1cf576bfbe +P 027e5336acc26f57f21df4980928731026c30cf88688fa0b66f13ffa0b5da3a0 +R ee785ecad1867a820bb9e665fd92d3e8 +U drh +Z 74daf43f110405d8b8bf503998b8174f # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index ac34f60cfe..dba854ccd3 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -027e5336acc26f57f21df4980928731026c30cf88688fa0b66f13ffa0b5da3a0 \ No newline at end of file +483fa2969e1e10cd8e8d2f9e3027871c65b1360b6c23897efe3ce63a3a55ae13 \ No newline at end of file From b4e7d59f4fa9653fad5bd1c833c3472dfe1aaf71 Mon Sep 17 00:00:00 2001 From: drh <> Date: Wed, 6 Mar 2024 14:30:42 +0000 Subject: [PATCH 176/430] Add the json_pretty(J) function for pretty-printing of JSON. An optional 2nd argument is text used for indentation, with a default value being four spaces. FossilOrigin-Name: 39552bd36c06fe9ee346cb71e0659baceccde031b67c0974f2dd14eb11ebc055 --- manifest | 15 +++--- manifest.uuid | 2 +- src/json.c | 143 +++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 152 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index da94066647..682a374dee 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Correction\sto\sthe\sprevious\scheck-in. -D 2024-03-06T12:28:55.128 +C Add\sthe\sjson_pretty(J)\sfunction\sfor\spretty-printing\sof\sJSON.\s\sAn\soptional\n2nd\sargument\sis\stext\sused\sfor\sindentation,\swith\sa\sdefault\svalue\sbeing\sfour\nspaces. +D 2024-03-06T14:30:42.046 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -710,7 +710,7 @@ F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 F src/insert.c 3f0a94082d978bbdd33c38fefea15346c6c6bffb70bc645a71dc0f1f87dd3276 -F src/json.c 9337dac9d9d4c77461db55fd3e06e4d006f4283cb1da2b3a9b1f8d750701583e +F src/json.c e2e40760d6689134c3e2ece38c6a496b34ff5e2661a8f238444a119af666fdce F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 F src/main.c 438b95162acfa17b7d218f586f5bde11d6ae82bcf030c9611fc537556870ad6b @@ -2176,8 +2176,11 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 027e5336acc26f57f21df4980928731026c30cf88688fa0b66f13ffa0b5da3a0 -R ee785ecad1867a820bb9e665fd92d3e8 +P 483fa2969e1e10cd8e8d2f9e3027871c65b1360b6c23897efe3ce63a3a55ae13 +R cdcb4f4f681bccfe01ba6f525ed68e3e +T *branch * json-pretty +T *sym-json-pretty * +T -sym-trunk * U drh -Z 74daf43f110405d8b8bf503998b8174f +Z 040cd116c25b3e34e2b8acda05bc14c7 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index dba854ccd3..0340f39ad2 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -483fa2969e1e10cd8e8d2f9e3027871c65b1360b6c23897efe3ce63a3a55ae13 \ No newline at end of file +39552bd36c06fe9ee346cb71e0659baceccde031b67c0974f2dd14eb11ebc055 \ No newline at end of file diff --git a/src/json.c b/src/json.c index fe7f938883..44ae846461 100644 --- a/src/json.c +++ b/src/json.c @@ -563,7 +563,6 @@ static void jsonAppendRawNZ(JsonString *p, const char *zIn, u32 N){ } } - /* Append formatted text (not to exceed N bytes) to the JsonString. */ static void jsonPrintf(int N, JsonString *p, const char *zFormat, ...){ @@ -2336,6 +2335,112 @@ static u32 jsonTranslateBlobToText( return i+n+sz; } +/* Context for recursion of json_pretty() +*/ +typedef struct JsonPretty JsonPretty; +struct JsonPretty { + JsonParse *pParse; /* The BLOB being rendered */ + JsonString *pOut; /* Generate pretty output into this string */ + const char *zIndent; /* Use this text for indentation */ + u32 szIndent; /* Bytes in zIndent[] */ + u32 nIndent; /* Current level of indentation */ +}; + +/* Append indentation to the pretty JSON under construction */ +static void jsonPrettyIndent(JsonPretty *pPretty){ + u32 jj; + for(jj=0; jjnIndent; jj++){ + jsonAppendRaw(pPretty->pOut, pPretty->zIndent, pPretty->szIndent); + } +} + +/* +** Translate the binary JSONB representation of JSON beginning at +** pParse->aBlob[i] into a JSON text string. Append the JSON +** text onto the end of pOut. Return the index in pParse->aBlob[] +** of the first byte past the end of the element that is translated. +** +** This is a variant of jsonTranslateBlobToText() that "pretty-prints" +** the output. Extra whitespace is inserted to make the JSON easier +** for humans to read. +** +** If an error is detected in the BLOB input, the pOut->eErr flag +** might get set to JSTRING_MALFORMED. But not all BLOB input errors +** are detected. So a malformed JSONB input might either result +** in an error, or in incorrect JSON. +** +** The pOut->eErr JSTRING_OOM flag is set on a OOM. +*/ +static u32 jsonTranslateBlobToPrettyText( + JsonPretty *pPretty, /* Pretty-printing context */ + u32 i /* Start rendering at this index */ +){ + u32 sz, n, j, iEnd; + const JsonParse *pParse = pPretty->pParse; + JsonString *pOut = pPretty->pOut; + n = jsonbPayloadSize(pParse, i, &sz); + if( n==0 ){ + pOut->eErr |= JSTRING_MALFORMED; + return pParse->nBlob+1; + } + switch( pParse->aBlob[i] & 0x0f ){ + case JSONB_ARRAY: { + j = i+n; + iEnd = j+sz; + jsonAppendChar(pOut, '['); + if( jnIndent++; + while( pOut->eErr==0 ){ + jsonPrettyIndent(pPretty); + j = jsonTranslateBlobToPrettyText(pPretty, j); + if( j>=iEnd ) break; + jsonAppendRawNZ(pOut, ",\n", 2); + } + jsonAppendChar(pOut, '\n'); + pPretty->nIndent--; + jsonPrettyIndent(pPretty); + } + jsonAppendChar(pOut, ']'); + i = iEnd; + break; + } + case JSONB_OBJECT: { + j = i+n; + iEnd = j+sz; + jsonAppendChar(pOut, '{'); + if( jnIndent++; + while( pOut->eErr==0 ){ + jsonPrettyIndent(pPretty); + j = jsonTranslateBlobToText(pParse, j, pOut); + if( j>iEnd ){ + pOut->eErr |= JSTRING_MALFORMED; + break; + } + jsonAppendRawNZ(pOut, ": ", 2); + j = jsonTranslateBlobToPrettyText(pPretty, j); + if( j>=iEnd ) break; + jsonAppendRawNZ(pOut, ",\n", 2); + } + jsonAppendChar(pOut, '\n'); + pPretty->nIndent--; + jsonPrettyIndent(pPretty); + } + jsonAppendChar(pOut, '}'); + i = iEnd; + break; + } + default: { + i = jsonTranslateBlobToText(pParse, i, pOut); + break; + } + } + return i; +} + + /* Return true if the input pJson ** ** For performance reasons, this routine does not do a detailed check of the @@ -4255,6 +4360,40 @@ static void jsonTypeFunc( jsonParseFree(p); } +/* +** json_pretty(JSON) +** json_pretty(JSON, INDENT) +** +** Return text that is a pretty-printed rendering of the input JSON. +** If the argument is not valid JSON, return NULL. +** +** The INDENT argument is text that is used for indentation. If omitted, +** it defaults to four spaces (the same as PostgreSQL). +*/ +static void jsonPrettyFunc( + sqlite3_context *ctx, + int argc, + sqlite3_value **argv +){ + JsonString s; /* The output string */ + JsonPretty x; /* Pretty printing context */ + + memset(&x, 0, sizeof(x)); + x.pParse = jsonParseFuncArg(ctx, argv[0], 0); + if( x.pParse==0 ) return; + x.pOut = &s; + jsonStringInit(&s, ctx); + if( argc==1 || (x.zIndent = (const char*)sqlite3_value_text(argv[1]))==0 ){ + x.zIndent = " "; + x.szIndent = 4; + }else{ + x.szIndent = (u32)strlen(x.zIndent); + } + jsonTranslateBlobToPrettyText(&x, 0); + jsonReturnString(&s, 0, 0); + jsonParseFree(x.pParse); +} + /* ** json_valid(JSON) ** json_valid(JSON, FLAGS) @@ -5269,6 +5408,8 @@ void sqlite3RegisterJsonFunctions(void){ JFUNCTION(jsonb_object, -1,0,1, 1,1,0, jsonObjectFunc), JFUNCTION(json_patch, 2,1,1, 0,0,0, jsonPatchFunc), JFUNCTION(jsonb_patch, 2,1,0, 0,1,0, jsonPatchFunc), + JFUNCTION(json_pretty, 1,1,0, 0,0,0, jsonPrettyFunc), + JFUNCTION(json_pretty, 2,1,0, 0,0,0, jsonPrettyFunc), JFUNCTION(json_quote, 1,0,1, 1,0,0, jsonQuoteFunc), JFUNCTION(json_remove, -1,1,1, 0,0,0, jsonRemoveFunc), JFUNCTION(jsonb_remove, -1,1,0, 0,1,0, jsonRemoveFunc), From 31c3ac9049a3e6c418ad3a1d7ce97c980968b9b9 Mon Sep 17 00:00:00 2001 From: stephan Date: Wed, 6 Mar 2024 14:42:06 +0000 Subject: [PATCH 177/430] Add a couple of json_pretty() examples to /fiddle. FossilOrigin-Name: d5e1687b1d49cec5daa8793ea138fdf3bd29436c1e67071707ec0594bd1c66c6 --- ext/wasm/fiddle/fiddle.js | 8 +++++++- manifest | 17 +++++++---------- manifest.uuid | 2 +- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/ext/wasm/fiddle/fiddle.js b/ext/wasm/fiddle/fiddle.js index f409d92112..d28589835c 100644 --- a/ext/wasm/fiddle/fiddle.js +++ b/ext/wasm/fiddle/fiddle.js @@ -761,7 +761,13 @@ " FROM m2 GROUP BY cy\n", " )\n", "SELECT group_concat(rtrim(t),x'0a') as Mandelbrot FROM a;\n", - ]} + ]}, + {name: "JSON pretty-print", + sql: "select json_pretty(json_object('ex',json('[52,3.14159]')))" + }, + {name: "JSON pretty-print (with tabs)", + sql: "select json_pretty(json_object('ex',json('[52,3.14159]')),char(0x09))" + } ]; const newOpt = function(lbl,val){ const o = document.createElement('option'); diff --git a/manifest b/manifest index 682a374dee..3636941e49 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\sjson_pretty(J)\sfunction\sfor\spretty-printing\sof\sJSON.\s\sAn\soptional\n2nd\sargument\sis\stext\sused\sfor\sindentation,\swith\sa\sdefault\svalue\sbeing\sfour\nspaces. -D 2024-03-06T14:30:42.046 +C Add\sa\scouple\sof\sjson_pretty()\sexamples\sto\s/fiddle. +D 2024-03-06T14:42:06.357 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -641,7 +641,7 @@ F ext/wasm/example_extra_init.c 2347cd69d19d839ef4e5e77b7855103a7fe3ef2af86f2e8c F ext/wasm/fiddle.make 3c2eace29255d6ddd219f5d8cc2728cb28b9fe717ea80b6062c2a6178947a16b F ext/wasm/fiddle/emscripten.css 3d253a6fdb8983a2ac983855bfbdd4b6fa1ff267c28d69513dd6ef1f289ada3f F ext/wasm/fiddle/fiddle-worker.js 850e66fce39b89d59e161d1abac43a181a4caa89ddeea162765d660277cd84ce -F ext/wasm/fiddle/fiddle.js 04a638e3ed8fc9ca7c05cbe73ac4196e4529ec564639a76fbcecaffdf62bd983 +F ext/wasm/fiddle/fiddle.js b444a5646a9aac9f3fc06c53d78af5e1912eb235d69a8e6010723e4eb0e9d4a1 F ext/wasm/fiddle/index.html 5daf54e8f3d7777cbb1ca4f93affe28858dbfff25841cb4ab81d694efed28ec2 F ext/wasm/index-dist.html e91d76e4581185238fd3d42ed86ec600f7023ed3e3a944c5c356f25304bf1263 F ext/wasm/index.html b31ce41c0da476d5ffcef23069b9d3415b419d65af5779096ebcfbcbade453a9 @@ -2176,11 +2176,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 483fa2969e1e10cd8e8d2f9e3027871c65b1360b6c23897efe3ce63a3a55ae13 -R cdcb4f4f681bccfe01ba6f525ed68e3e -T *branch * json-pretty -T *sym-json-pretty * -T -sym-trunk * -U drh -Z 040cd116c25b3e34e2b8acda05bc14c7 +P 39552bd36c06fe9ee346cb71e0659baceccde031b67c0974f2dd14eb11ebc055 +R f12e2eeb9bae468bef7713e1648b6a8a +U stephan +Z 3bec70ffdc2a1f410c64a91b9d3ada78 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 0340f39ad2..ea3e1e8458 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -39552bd36c06fe9ee346cb71e0659baceccde031b67c0974f2dd14eb11ebc055 \ No newline at end of file +d5e1687b1d49cec5daa8793ea138fdf3bd29436c1e67071707ec0594bd1c66c6 \ No newline at end of file From 1bd583e201fbc1f81fc5cf0ba938c048742215f7 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Wed, 6 Mar 2024 20:24:02 +0000 Subject: [PATCH 178/430] Work around obscure floating point issue seen with older versions of MSVC. FossilOrigin-Name: 42d39f9140cc315df04b048f3811311fa50b51e1831d6cdf982fbce029778e43 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/util.c | 3 +++ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index da94066647..cccb344c9c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Correction\sto\sthe\sprevious\scheck-in. -D 2024-03-06T12:28:55.128 +C Work\saround\sobscure\sfloating\spoint\sissue\sseen\swith\solder\sversions\sof\sMSVC. +D 2024-03-06T20:24:02.178 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -818,7 +818,7 @@ F src/trigger.c 0905b96b04bb6658509f711a8207287f1315cdbc3df1a1b13ba6483c8e341c81 F src/update.c 6904814dd62a7a93bbb86d9f1419c7f134a9119582645854ab02b36b676d9f92 F src/upsert.c fa125a8d3410ce9a97b02cb50f7ae68a2476c405c76aa692d3acf6b8586e9242 F src/utf.c f23165685a67b4caf8ec08fb274cb3f319103decfb2a980b7cfd55d18dfa855e -F src/util.c 0765014847e2a06c952dd64aef0bea5144cd5b335a161eb0768ebe4f63dfe216 +F src/util.c f27a17e6e43fa362abea4db507a1c409f0adc8048ecf4c6479e8d162158ed529 F src/vacuum.c 604fcdaebe76f3497c855afcbf91b8fa5046b32de3045bab89cc008d68e40104 F src/vdbe.c 7a33c5bb37e12ce35ac2d1d56a6429288b0b56c940ba660265c1428c67883729 F src/vdbe.h c2d78d15112c3fc5ab87f5e8e0b75d2db1c624409de2e858c3d1aafb1650bb4f @@ -2176,8 +2176,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 027e5336acc26f57f21df4980928731026c30cf88688fa0b66f13ffa0b5da3a0 -R ee785ecad1867a820bb9e665fd92d3e8 -U drh -Z 74daf43f110405d8b8bf503998b8174f +P 483fa2969e1e10cd8e8d2f9e3027871c65b1360b6c23897efe3ce63a3a55ae13 +R e5a2f85d4c7fe1bb0d133ab32d8d2d60 +U mistachkin +Z 8ca80acfec7b6e2b98a8f7ce94a903f4 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index dba854ccd3..9cbb89be52 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -483fa2969e1e10cd8e8d2f9e3027871c65b1360b6c23897efe3ce63a3a55ae13 \ No newline at end of file +42d39f9140cc315df04b048f3811311fa50b51e1831d6cdf982fbce029778e43 \ No newline at end of file diff --git a/src/util.c b/src/util.c index 311b7385a6..8c9e980cd1 100644 --- a/src/util.c +++ b/src/util.c @@ -665,6 +665,9 @@ int sqlite3AtoF(const char *z, double *pResult, int length, u8 enc){ u64 s2; rr[0] = (double)s; s2 = (u64)rr[0]; +#if defined(_MSC_VER) && _MSC_VER<1700 + if( s2==0x8000000000000000LL ){ s2 = 2*(u64)(0.5*rr[0]); } +#endif rr[1] = s>=s2 ? (double)(s - s2) : -(double)(s2 - s); if( e>0 ){ while( e>=100 ){ From 1b977e3ae83db9fdfe70e650ca3bc3d22703ead9 Mon Sep 17 00:00:00 2001 From: drh <> Date: Wed, 6 Mar 2024 20:38:52 +0000 Subject: [PATCH 179/430] Add test cases for json_pretty(). FossilOrigin-Name: 6448b90708eeedef03e82dcb10d2879e1bc859d422b450c5fc403ffbe0343bed --- manifest | 15 ++++++++------- manifest.uuid | 2 +- test/json106.test | 6 ++++++ test/json108.test | 45 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 60 insertions(+), 8 deletions(-) create mode 100644 test/json108.test diff --git a/manifest b/manifest index 3636941e49..91c87d0a12 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sa\scouple\sof\sjson_pretty()\sexamples\sto\s/fiddle. -D 2024-03-06T14:42:06.357 +C Add\stest\scases\sfor\sjson_pretty(). +D 2024-03-06T20:38:52.875 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -1353,8 +1353,9 @@ F test/json102.test 557a46e16df1aa9bdbc4076a71a45814ea0e7503d6621d87d42a8c04cbc2 F test/json103.test 53df87f83a4e5fa0c0a56eb29ff6c94055c6eb919f33316d62161a8880112dbe F test/json104.test 1b844a70cddcfa2e4cd81a5db0657b2e61e7f00868310f24f56a9ba0114348c1 F test/json105.test 043838b56e68f3252a0dcf5be1689016f6f3f05056f8dcfcdc9d074f4d932988 -F test/json106.test 1d46a9294e2ced35c7f87cebbcb9626d01abab04f1969d7ded7b6f6a1d9be0f2 +F test/json106.test 4aed3afd16549045d198a8d9cea00deea96e1f2ecf55864dce96cac558b8abef F test/json107.test 59054e815c8f6b67d634d44ace421cf975828fb5651c4460aa66015c8e19d562 +F test/json108.test 0a5f1e2d4b35a1bc33052563d2a5ede03052e2099e58cb424547656c898e0f49 F test/json501.test b95e2d14988b682a5cadf079dd6162f0f85fb74cd59c6b1f1624110104a974eb F test/json502.test 84634d3dbb521d2814e43624025b760c6198456c8197bbec6c977c0236648f5b F test/jsonb01.test f4cdfb4cf5a0c940091b17675ed9583f45add0c938f07d65b0de0e19d3a9a101 @@ -2176,8 +2177,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 39552bd36c06fe9ee346cb71e0659baceccde031b67c0974f2dd14eb11ebc055 -R f12e2eeb9bae468bef7713e1648b6a8a -U stephan -Z 3bec70ffdc2a1f410c64a91b9d3ada78 +P d5e1687b1d49cec5daa8793ea138fdf3bd29436c1e67071707ec0594bd1c66c6 +R b5d425c8e8367f72e383ae1d2d9e4ea0 +U drh +Z ce296be00f3b33d5cde8abdb22061e01 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index ea3e1e8458..342c0db21d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d5e1687b1d49cec5daa8793ea138fdf3bd29436c1e67071707ec0594bd1c66c6 \ No newline at end of file +6448b90708eeedef03e82dcb10d2879e1bc859d422b450c5fc403ffbe0343bed \ No newline at end of file diff --git a/test/json106.test b/test/json106.test index 23fa028431..06859a10b4 100644 --- a/test/json106.test +++ b/test/json106.test @@ -67,6 +67,12 @@ for {set ii 1} {$ii<=5000} {incr ii} { FROM t1, kv WHERE p->>key IS NOT val } 0 + do_execsql_test $ii.8 { + SELECT j0 FROM t1 WHERE json(j0)!=json(json_pretty(j0)); + } {} + do_execsql_test $ii.9 { + SELECT j5 FROM t1 WHERE json(j5)!=json(json_pretty(j5)); + } {} } diff --git a/test/json108.test b/test/json108.test new file mode 100644 index 0000000000..71f3814dce --- /dev/null +++ b/test/json108.test @@ -0,0 +1,45 @@ +# 2024-03-06 +# +# 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. +# +#*********************************************************************** +# Invariant tests for JSON built around the randomjson extension +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix json108 + +# These tests require virtual table "json_tree" to run. +ifcapable !vtab { finish_test ; return } + +load_static_extension db randomjson +db eval { + CREATE TEMP TABLE t1(j0,j5); + WITH RECURSIVE c(n) AS (VALUES(0) UNION ALL SELECT n+1 FROM c WHERE n<9) + INSERT INTO t1 SELECT random_json(n), random_json5(n) FROM c; +} + +do_execsql_test 1.1 { + SELECT count(*) FROM t1 WHERE json(j0)==json(json_pretty(j0,NULL)); +} 10 +do_execsql_test 1.2 { + SELECT count(*) FROM t1 WHERE json(j0)==json(json_pretty(j0,NULL)); +} 10 +do_execsql_test 1.3 { + SELECT count(*) FROM t1 WHERE json(j0)==json(json_pretty(j0,'')); +} 10 +do_execsql_test 1.4 { + SELECT count(*) FROM t1 WHERE json(j0)==json(json_pretty(j0,char(9))); +} 10 +do_execsql_test 1.5 { + SELECT count(*) FROM t1 WHERE json(j0)==json(json_pretty(j0,'/*hello*/')); +} 10 + + +finish_test From 5fb718aaab631e6a7f750e5049aa6f1eb33fb4a8 Mon Sep 17 00:00:00 2001 From: drh <> Date: Thu, 7 Mar 2024 12:34:26 +0000 Subject: [PATCH 180/430] Do not allow the query planner to be tricked into thinking that an index on a constant expression might be useful for something. Problem reported on [forum:/forumpost/ecdfc02339|forum post ecdfc02339]. This is a follow-up to the fixes at [44200596aa943963] and [2d2b91cc0f6fed8c]. FossilOrigin-Name: 720ce06d93a9e4cc25c34c873c82165d8801f208c22701e51538f3210de84f65 --- manifest | 15 +++++++-------- manifest.uuid | 2 +- src/whereexpr.c | 2 +- test/whereL.test | 18 ++++++++++++++++++ 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index b220f92a5e..9809f4437d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\sjson_pretty()\sSQL\sfunction. -D 2024-03-06T20:49:05.359 +C Do\snot\sallow\sthe\squery\splanner\sto\sbe\stricked\sinto\sthinking\sthat\san\sindex\son\sa\nconstant\sexpression\smight\sbe\suseful\sfor\ssomething.\s\sProblem\sreported\son\n[forum:/forumpost/ecdfc02339|forum\spost\secdfc02339].\s\sThis\sis\sa\sfollow-up\nto\sthe\sfixes\sat\s[44200596aa943963]\sand\s[2d2b91cc0f6fed8c]. +D 2024-03-07T12:34:26.192 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -838,7 +838,7 @@ F src/walker.c 7c7ea0115345851c3da4e04e2e239a29983b61fb5b038b94eede6aba462640e2 F src/where.c 33eaaeef3aef10c2b9e82096e70a174d6636e35cb0b180321b8ddf804590e5cd F src/whereInt.h 82a13766f13d1a53b05387c2e60726289ef26404bc7b9b1f7770204d97357fb8 F src/wherecode.c 5d77db30a2a3dd532492ae882de114edba2fae672622056b1c7fd61f5917a8f1 -F src/whereexpr.c dc5096eca5ed503999be3bdee8a90c51361289a678d396a220912e9cb73b3c00 +F src/whereexpr.c 6ebd90b553f4bb5c7df5a4b2f39b6a7c81a67484353827cdd2048f2514ec6f30 F src/window.c 5b1387d59df30d481ed14cceef5f4d1dab1f8752aa106ba72c8b62777bd139d2 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/affinity2.test ce1aafc86e110685b324e9a763eab4f2a73f737842ec3b687bd965867de90627 @@ -2009,7 +2009,7 @@ F test/whereH.test e4b07f7a3c2f5d31195cd33710054c78667573b2 F test/whereI.test c4bb7e2ca56d49bd8ab5c7bd085b8b83e353922b46904d68aefb3c7468643581 F test/whereJ.test fc05e374cc9f2dc204148d6c06822c380ad388895fe97a6d335b94a26a08aecf F test/whereK.test 0270ab7f04ba5436fb9156d31d642a1c82727f4c4bfe5ba90d435c78cf44684a -F test/whereL.test 9d7c8a9f4e5e82d6859e61cf8758c3856c7e0a7fd8be11c92cac8c3ec39228fd +F test/whereL.test f0e9585623af522ee9f382f8f945ad4b7eb7d806d18746f33f00c374acf6ab65 F test/whereM.test 0dbc9998783458ddcf3cc078ca7c2951d8b2677d472ecf0028f449ed327c0250 F test/wherefault.test 6cf2a9c5712952d463d3f45ebee7f6caf400984df51a195d884cfb7eb0e837a7 F test/wherelfault.test 9012e4ef5259058b771606616bd007af5d154e64cc25fa9fd4170f6411db44e3 @@ -2177,9 +2177,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 42d39f9140cc315df04b048f3811311fa50b51e1831d6cdf982fbce029778e43 6448b90708eeedef03e82dcb10d2879e1bc859d422b450c5fc403ffbe0343bed -R 88bdf8f2cb7f2d0936a740d66ef2bdb9 -T +closed 6448b90708eeedef03e82dcb10d2879e1bc859d422b450c5fc403ffbe0343bed +P ceb51c1cc36dfb78db8f2be042a0d74ab9a877d14a53dadf876d09e1a0616d6a +R 897d3888369143acaff743303856f10f U drh -Z 6f02a8d0c883d9be78c99bd4533f623f +Z ee9fb6bc0a9a21d42249dd521593d5a5 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index e46cc0fc12..a75e256014 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ceb51c1cc36dfb78db8f2be042a0d74ab9a877d14a53dadf876d09e1a0616d6a \ No newline at end of file +720ce06d93a9e4cc25c34c873c82165d8801f208c22701e51538f3210de84f65 \ No newline at end of file diff --git a/src/whereexpr.c b/src/whereexpr.c index daf3d5d950..25db8f396f 100644 --- a/src/whereexpr.c +++ b/src/whereexpr.c @@ -989,7 +989,7 @@ static SQLITE_NOINLINE int exprMightBeIndexed2( if( pIdx->aiColumn[i]!=XN_EXPR ) continue; assert( pIdx->bHasExpr ); if( sqlite3ExprCompareSkip(pExpr,pIdx->aColExpr->a[i].pExpr,iCur)==0 - && pExpr->op!=TK_STRING + && !sqlite3ExprIsConstant(pIdx->aColExpr->a[i].pExpr) ){ aiCurCol[0] = iCur; aiCurCol[1] = XN_EXPR; diff --git a/test/whereL.test b/test/whereL.test index c3bdcb8f34..068ee05cd4 100644 --- a/test/whereL.test +++ b/test/whereL.test @@ -209,4 +209,22 @@ do_eqp_test 710 { `--SEARCH t1 USING INDEX idx (=?) } +# 2024-03-07 https://sqlite.org/forum/forumpost/ecdfc02339 +# A refinement is needed to the enhancements tested by the prior test case +# to avoid another problem with indexes on constant expressions. +# +reset_db +db null NULL +do_execsql_test 800 { + CREATE TABLE t0(c0, c1); + CREATE TABLE t1(c2); + CREATE INDEX i0 ON t1(NULL); + INSERT INTO t1(c2) VALUES (0.2); + CREATE VIEW v0(c3) AS SELECT DISTINCT c2 FROM t1; + SELECT * FROM v0 LEFT JOIN t0 ON c3 Date: Thu, 7 Mar 2024 15:58:06 +0000 Subject: [PATCH 181/430] Fix harmless compiler warnings in test code for the intck extension. FossilOrigin-Name: 7fbdc1a849af3440579459bbb8797ebc7f9cce7b34d95675b8baa82db194ea9c --- ext/intck/test_intck.c | 6 +++--- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ext/intck/test_intck.c b/ext/intck/test_intck.c index 72f72d8c13..84008fb07f 100644 --- a/ext/intck/test_intck.c +++ b/ext/intck/test_intck.c @@ -79,7 +79,7 @@ static int testIntckCmd( } case 1: assert( 0==strcmp("step", aCmd[iIdx].zName) ); { - int rc = sqlite3_intck_step(p->intck); + rc = sqlite3_intck_step(p->intck); Tcl_SetObjResult(interp, Tcl_NewStringObj(sqlite3ErrName(rc), -1)); break; } @@ -92,7 +92,7 @@ static int testIntckCmd( case 3: assert( 0==strcmp("error", aCmd[iIdx].zName) ); { const char *zErr = 0; - int rc = sqlite3_intck_error(p->intck, 0); + rc = sqlite3_intck_error(p->intck, 0); Tcl_Obj *pRes = Tcl_NewObj(); Tcl_ListObjAppendElement( interp, pRes, Tcl_NewStringObj(sqlite3ErrName(rc), -1) @@ -106,7 +106,7 @@ static int testIntckCmd( } case 4: assert( 0==strcmp("unlock", aCmd[iIdx].zName) ); { - int rc = sqlite3_intck_unlock(p->intck); + rc = sqlite3_intck_unlock(p->intck); Tcl_SetObjResult(interp, Tcl_NewStringObj(sqlite3ErrName(rc), -1)); break; } diff --git a/manifest b/manifest index 9809f4437d..cf220e9f26 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Do\snot\sallow\sthe\squery\splanner\sto\sbe\stricked\sinto\sthinking\sthat\san\sindex\son\sa\nconstant\sexpression\smight\sbe\suseful\sfor\ssomething.\s\sProblem\sreported\son\n[forum:/forumpost/ecdfc02339|forum\spost\secdfc02339].\s\sThis\sis\sa\sfollow-up\nto\sthe\sfixes\sat\s[44200596aa943963]\sand\s[2d2b91cc0f6fed8c]. -D 2024-03-07T12:34:26.192 +C Fix\sharmless\scompiler\swarnings\sin\stest\scode\sfor\sthe\sintck\sextension. +D 2024-03-07T15:58:06.345 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -258,7 +258,7 @@ F ext/intck/intckcorrupt.test 3211ef68ac53e83951b6c8f6a8d2396506d123fe5898f97f84 F ext/intck/intckfault.test ba0213c9c8dce08d519d5251268a3bab076a184b4d07acdea23b65e89c9ae03c F ext/intck/sqlite3intck.c 0d10df36e2b7b438aa80ecd3f5e584d41b747586b038258fe6b407f66b81e7c5 F ext/intck/sqlite3intck.h 2b40c38e7063ab822c974c0bd4aed97dabb579ccfe2e180a4639bb3bbef0f1c9 -F ext/intck/test_intck.c d63f1707432802f5db125ee40b794923af77d4686869bd8d3a7eb43332344267 +F ext/intck/test_intck.c 34243458378a12d1356c79219a03f244800533b3ab65b4a02861f0403364df12 F ext/jni/GNUmakefile 59eb05f2a363bdfac8d15d66bed624bfe1ff289229184f3861b95f98a19cf4b2 F ext/jni/README.md d899789a9082a07b99bf30b1bbb6204ae57c060efcaa634536fa669323918f42 F ext/jni/jar-dist.make 030aaa4ae71dd86e4ec5e7c1e6cd86f9dfa47c4592c070d2e35157e42498e1fa @@ -2177,8 +2177,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P ceb51c1cc36dfb78db8f2be042a0d74ab9a877d14a53dadf876d09e1a0616d6a -R 897d3888369143acaff743303856f10f +P 720ce06d93a9e4cc25c34c873c82165d8801f208c22701e51538f3210de84f65 +R 78475c96717bed229515f020acd7cf0b U drh -Z ee9fb6bc0a9a21d42249dd521593d5a5 +Z b05395e7bb390bd5a3c76ba7c1373e1f # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index a75e256014..510215797c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -720ce06d93a9e4cc25c34c873c82165d8801f208c22701e51538f3210de84f65 \ No newline at end of file +7fbdc1a849af3440579459bbb8797ebc7f9cce7b34d95675b8baa82db194ea9c \ No newline at end of file From 61405c463d16d6fa40257c012df5c5a5d3af3af4 Mon Sep 17 00:00:00 2001 From: stephan Date: Thu, 7 Mar 2024 16:04:43 +0000 Subject: [PATCH 182/430] Initial work at getting sqlite3Worker1Promiser.v2() to return a Promise instead of using an onready() callback, and also creating an ESM build for promiser1 per user request. It seems to work but requires more testing. FossilOrigin-Name: 0e272123ace55ed63fe86632671cca48e8965a28fc3625324984028729fc203f --- ext/wasm/GNUmakefile | 18 ++++--- ext/wasm/api/sqlite3-worker1-promiser.c-pp.js | 48 +++++++++++++++++-- ext/wasm/demo-worker1-promiser.js | 24 +++++----- manifest | 21 ++++---- manifest.uuid | 2 +- 5 files changed, 82 insertions(+), 31 deletions(-) diff --git a/ext/wasm/GNUmakefile b/ext/wasm/GNUmakefile index 098a4330b0..ff11ab6552 100644 --- a/ext/wasm/GNUmakefile +++ b/ext/wasm/GNUmakefile @@ -307,8 +307,9 @@ DISTCLEAN_FILES += $(bin.stripccomments) ######################################################################## -# C-PP.FILTER: a $(call)able to transform $(1) to $(2) via ./c-pp -f -# $(1) ... +# C-PP.FILTER: a $(call)able to transform $(1) to $(2) via: +# +# ./c-pp -f $(1) -o $(2) $(3) # # Historical notes: # @@ -825,13 +826,13 @@ pre-post-jses.deps.common := $(extern-pre-js.js) $(sqlite3-license-version.js) # $4 = resulting sqlite-api JS/MJS file # $5 = resulting JS/MJS file # $6 = -D... flags for $(bin.c-pp) -# $7 = emcc -sXYZ flags (CURRENTLY UNUSED - was factored out) +# $7 = optional extra flags for emcc # # Maintenance reminder: be careful not to introduce spaces around args # ($1, $2), otherwise string concatenation will malfunction. # -# emcc.environment.$(2) must be set to a value for emcc's -# -sENVIRONMENT flag. +# Before calling this, emcc.environment.$(2) must be set to a value +# for emcc's -sENVIRONMENT flag. # # $(cflags.$(1)) and $(cflags.$(1).$(2)) may be defined to append # CFLAGS to a given build mode. @@ -938,6 +939,7 @@ sqlite3-worker1.js.in := $(dir.api)/sqlite3-worker1.c-pp.js sqlite3-worker1-promiser.js.in := $(dir.api)/sqlite3-worker1-promiser.c-pp.js sqlite3-worker1.js := $(dir.dout)/sqlite3-worker1.js sqlite3-worker1-promiser.js := $(dir.dout)/sqlite3-worker1-promiser.js +sqlite3-worker1-promiser.mjs := $(dir.dout)/sqlite3-worker1-promiser.mjs sqlite3-worker1-bundler-friendly.js := $(dir.dout)/sqlite3-worker1-bundler-friendly.mjs sqlite3-worker1-promiser-bundler-friendly.js := $(dir.dout)/sqlite3-worker1-promiser-bundler-friendly.js $(eval $(call C-PP.FILTER,$(sqlite3-worker1.js.in),$(sqlite3-worker1.js))) @@ -947,10 +949,12 @@ $(eval $(call C-PP.FILTER,$(sqlite3-worker1-promiser.js.in),$(sqlite3-worker1-pr $(eval $(call C-PP.FILTER,$(sqlite3-worker1-promiser.js.in),\ $(sqlite3-worker1-promiser-bundler-friendly.js),\ $(c-pp.D.sqlite3-bundler-friendly))) +$(eval $(call C-PP.FILTER,$(sqlite3-worker1-promiser.js.in),$(sqlite3-worker1-promiser.mjs),\ + -Dtarget=es6-module -Dtarget=es6-bundler-friendly)) $(sqlite3-bundler-friendly.mjs): $(sqlite3-worker1-bundler-friendly.js) \ $(sqlite3-worker1-promiser-bundler-friendly.js) -$(sqlite3.js) $(sqlite3.mjs): $(sqlite3-worker1.js) $(sqlite3-worker1-promiser.js) - +$(sqlite3.js) $(sqlite3.mjs): $(sqlite3-worker1.js) \ + $(sqlite3-worker1-promiser.js) $(sqlite3-worker1-promiser.mjs) ######################################################################## # batch-runner.js is part of one of the test apps which reads in SQL # dumps generated by $(speedtest1) and executes them. diff --git a/ext/wasm/api/sqlite3-worker1-promiser.c-pp.js b/ext/wasm/api/sqlite3-worker1-promiser.c-pp.js index 68846209e5..5e399cd344 100644 --- a/ext/wasm/api/sqlite3-worker1-promiser.c-pp.js +++ b/ext/wasm/api/sqlite3-worker1-promiser.c-pp.js @@ -42,9 +42,13 @@ - `onready` (optional, but...): this callback is called with no arguments when the worker fires its initial 'sqlite3-api'/'worker1-ready' message, which it does when - sqlite3.initWorker1API() completes its initialization. This is - the simplest way to tell the worker to kick off work at the - earliest opportunity. + sqlite3.initWorker1API() completes its initialization. This is the + simplest way to tell the worker to kick off work at the earliest + opportunity, and the only way to know when the worker module has + completed loading. The irony of using a callback for this, instead + of returning a promise from sqlite3Worker1Promiser() is not lost on + the developers, but initial attempts to return a promise resulted + in a much clumsier interface. - `onunhandled` (optional): a callback which gets passed the message event object for any worker.onmessage() events which @@ -277,7 +281,45 @@ globalThis.sqlite3Worker1Promiser.defaultConfig = { //#endif , onerror: (...args)=>console.error('worker1 promiser error',...args) +}/*defaultConfig*/; + +/** + sqlite3Worker1Promiser.v2() works identically to + sqlite3Worker1Promiser() except that it returns a promise instead + of relying an an onready callback in the config object. +*/ +sqlite3Worker1Promiser.v2 = function(config){ + const x = Object.create(null); + let oldFunc; + if( 'function' == typeof config ){ + oldFunc = config; + config = {}; + }else if('function'===typeof config?.onready){ + oldFunc = config.onready; + delete config.onready; + } + config = Object.assign((config || Object.create(null)),{ + onready: function(func){ + try { + if( oldFunc ){ + oldFunc(func); + } + x.resolve(func); + } + catch(e){x.reject(e)} + } + }); + const p = new Promise(function(resolve,reject){ + x.resolve = resolve; + x.reject = reject; + }); + sqlite3Worker1Promiser(config); + return p; }; + +//#if target=es6-module +export default sqlite3Worker1Promiser.v2; +//#endif /* target=es6-module */ //#else /* Built with the omit-oo1 flag. */ //#endif ifnot omit-oo1 diff --git a/ext/wasm/demo-worker1-promiser.js b/ext/wasm/demo-worker1-promiser.js index 4327f7487d..19a7af1143 100644 --- a/ext/wasm/demo-worker1-promiser.js +++ b/ext/wasm/demo-worker1-promiser.js @@ -14,8 +14,8 @@ proxy for for the sqlite3 Worker #1 API. */ 'use strict'; -(function(){ - const T = self.SqliteTestUtil; +(async function(){ + const T = globalThis.SqliteTestUtil; const eOutput = document.querySelector('#test-output'); const warn = console.warn.bind(console); const error = console.error.bind(console); @@ -48,18 +48,20 @@ onunhandled: function(ev){ error("Unhandled worker message:",ev.data); }, - onready: function(){ - T.affirm(arguments[0] === workerPromise - /* as of version 3.46. Prior to that this callback had no arguments */); - self.sqlite3TestModule.setStatus(null)/*hide the HTML-side is-loading spinner*/; - runTests(); - }, onerror: function(ev){ error("worker1 error:",ev); + }, + onready: function(f){ + warn("This is the v2 interface - don't pass an onready() function."); } }; - const workerPromise = self.sqlite3Worker1Promiser(promiserConfig); - delete self.sqlite3Worker1Promiser; + const workerPromise = await globalThis.sqlite3Worker1Promiser.v2(promiserConfig) + .then((func)=>{ + log("Init complete. Starting tests momentarily."); + globalThis.sqlite3TestModule.setStatus(null)/*hide the HTML-side is-loading spinner*/; + return func; + }); + delete globalThis.sqlite3Worker1Promiser; const wtest = async function(msgType, msgArgs, callback){ if(2===arguments.length && 'function'===typeof msgArgs){ @@ -273,5 +275,5 @@ }).finally(()=>logHtml('',"That's all, folks!")); }/*runTests2()*/; - log("Init complete, but async init bits may still be running."); + runTests(); })(); diff --git a/manifest b/manifest index da94066647..9d045f3c98 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Correction\sto\sthe\sprevious\scheck-in. -D 2024-03-06T12:28:55.128 +C Initial\swork\sat\sgetting\ssqlite3Worker1Promiser.v2()\sto\sreturn\sa\sPromise\sinstead\sof\susing\san\sonready()\scallback,\sand\salso\screating\san\sESM\sbuild\sfor\spromiser1\sper\suser\srequest.\sIt\sseems\sto\swork\sbut\srequires\smore\stesting. +D 2024-03-07T16:04:43.823 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -587,7 +587,7 @@ F ext/userauth/sqlite3userauth.h 7f3ea8c4686db8e40b0a0e7a8e0b00fac13aa7a3 F ext/userauth/user-auth.txt ca7e9ee82ca4e1c1744295f8184dd70edfae1992865d26c64303f539eb6c084c F ext/userauth/userauth.c 7f00cded7dcaa5d47f54539b290a43d2e59f4b1eb5f447545fa865f002fc80cb F ext/wasm/EXPORTED_FUNCTIONS.fiddle.in 27450c8b8c70875a260aca55435ec927068b34cef801a96205adb81bdcefc65c -F ext/wasm/GNUmakefile 92e929315c3f1e0ea389fc9666b87a67a61fa1ecbe37e44c5ad226bda3bc6abe +F ext/wasm/GNUmakefile e04f36fec0ab949424622a906020902651bd8d17f9696c56ed572eebc63e2355 F ext/wasm/README-dist.txt 6382cb9548076fca472fb3330bbdba3a55c1ea0b180ff9253f084f07ff383576 F ext/wasm/README.md a8a2962c3aebdf8d2104a9102e336c5554e78fc6072746e5daf9c61514e7d193 F ext/wasm/SQLTester/GNUmakefile e0794f676d55819951bbfae45cc5e8d7818dc460492dc317ce7f0d2eca15caff @@ -616,7 +616,7 @@ F ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js 5a430874906ff3f4a6ca69aadf0c2aae F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js fe427645e1499618f5fa7bc670af850577d8bcc132df982078690c9bf8400baa F ext/wasm/api/sqlite3-vtab-helper.c-pp.js a2fcbc3fecdd0eea229283584ebc122f29d98194083675dbe5cb2cf3a17fe309 F ext/wasm/api/sqlite3-wasm.c d33a16495ca871781e78812d3a18fed78b797468fffee657b8d7199b277ff359 -F ext/wasm/api/sqlite3-worker1-promiser.c-pp.js e8135b44a568badfe197e2379f6b42899f2240b5c3a77fa044331110f7ce8e50 +F ext/wasm/api/sqlite3-worker1-promiser.c-pp.js c11220b21f748c955ca798ad43ba7fea75ca0bf8dba78f46508f09517de26c05 F ext/wasm/api/sqlite3-worker1.c-pp.js 5e8706c2c4af2a57fbcdc02f4e7ef79869971bc21bb8ede777687786ce1c92d5 F ext/wasm/batch-runner-sahpool.html e9a38fdeb36a13eac7b50241dfe7ae066fe3f51f5c0b0151e7baee5fce0d07a7 F ext/wasm/batch-runner-sahpool.js 54a3ac228e6c4703fe72fb65c897e19156263a51fe9b7e21d2834a45e876aabd @@ -633,7 +633,7 @@ F ext/wasm/demo-123.js c7b3cca50c55841c381a9ca4f9396e5bbdc6114273d0b10a43e378e32 F ext/wasm/demo-jsstorage.html 409c4be4af5f207fb2877160724b91b33ea36a3cd8c204e8da1acb828ffe588e F ext/wasm/demo-jsstorage.js 44e3ae7ec2483b6c511384c3c290beb6f305c721186bcf5398ca4e00004a06b8 F ext/wasm/demo-worker1-promiser.html 1de7c248c7c2cfd4a5783d2aa154bce62d74c6de98ab22f5786620b3354ed15f -F ext/wasm/demo-worker1-promiser.js 786ae8a3214c2a29f6fb2c80eb4f90cc401fcc5b524d95c35fdc66a454e32bad +F ext/wasm/demo-worker1-promiser.js e4cd1089269d106dd3bd20684eaddcd176c73baa31867ba0e445c8e7e29160b5 F ext/wasm/demo-worker1.html 2c178c1890a2beb5a5fecb1453e796d067a4b8d3d2a04d65ca2eb1ab2c68ef5d F ext/wasm/demo-worker1.js 836bece8615b17b1b572584f7b15912236a5947fe8c68b98d2737d7e287447ef F ext/wasm/dist.make 3a851858aad72e246a5d9c5aaf6b6a144305f1bf898ac1846760ea7bab95c9a3 @@ -2176,8 +2176,11 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 027e5336acc26f57f21df4980928731026c30cf88688fa0b66f13ffa0b5da3a0 -R ee785ecad1867a820bb9e665fd92d3e8 -U drh -Z 74daf43f110405d8b8bf503998b8174f +P 483fa2969e1e10cd8e8d2f9e3027871c65b1360b6c23897efe3ce63a3a55ae13 +R fb2d3021442c55c82ff56e48b32fdd31 +T *branch * wasm-promiser1-v2 +T *sym-wasm-promiser1-v2 * +T -sym-trunk * Cancelled\sby\sbranch. +U stephan +Z d10f630418c41733e8d0108d272da900 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index dba854ccd3..145a2be6b8 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -483fa2969e1e10cd8e8d2f9e3027871c65b1360b6c23897efe3ce63a3a55ae13 \ No newline at end of file +0e272123ace55ed63fe86632671cca48e8965a28fc3625324984028729fc203f \ No newline at end of file From ffa0fa69b6fce393641562d7b794a91adbab1618 Mon Sep 17 00:00:00 2001 From: stephan Date: Thu, 7 Mar 2024 17:56:08 +0000 Subject: [PATCH 183/430] wasm promiser.v2 is essentially working but the demo code is double-loading the module for as-yet-undetermined reasons. FossilOrigin-Name: aa877ce0c3b3aa1accd6e5fcd722d1bfaa79bea28c04c6badd8a547cea4bbc63 --- ext/wasm/GNUmakefile | 24 +- ext/wasm/api/sqlite3-worker1-promiser.c-pp.js | 49 ++- ext/wasm/demo-worker1-promiser-esm.html | 311 ++++++++++++++++++ ext/wasm/dist.make | 11 +- ext/wasm/index-dist.html | 2 + ext/wasm/index.html | 2 + manifest | 24 +- manifest.uuid | 2 +- 8 files changed, 385 insertions(+), 40 deletions(-) create mode 100644 ext/wasm/demo-worker1-promiser-esm.html diff --git a/ext/wasm/GNUmakefile b/ext/wasm/GNUmakefile index ff11ab6552..922f341857 100644 --- a/ext/wasm/GNUmakefile +++ b/ext/wasm/GNUmakefile @@ -453,13 +453,14 @@ sqlite3-api.jses += $(dir.api)/sqlite3-api-cleanup.js # the first OPFS VFS and necessarily an external file. SOAP.js := $(dir.api)/sqlite3-opfs-async-proxy.js SOAP.js.bld := $(dir.dout)/$(notdir $(SOAP.js)) -sqlite3-api.ext.jses += $(SOAP.js.bld) +# +# $(sqlite3-api.ext.jses) = API-related files which are standalone files, +# not part of the amalgamation. +# +sqlite3-api.ext.jses := $(SOAP.js.bld) $(SOAP.js.bld): $(SOAP.js) cp $< $@ -all quick: $(sqlite3-api.ext.jses) -q: quick - ######################################################################## # $(sqlite3-api*.*js) contain the core library code but not the # Emscripten-related glue which deals with loading sqlite3.wasm. In @@ -940,10 +941,10 @@ sqlite3-worker1-promiser.js.in := $(dir.api)/sqlite3-worker1-promiser.c-pp.js sqlite3-worker1.js := $(dir.dout)/sqlite3-worker1.js sqlite3-worker1-promiser.js := $(dir.dout)/sqlite3-worker1-promiser.js sqlite3-worker1-promiser.mjs := $(dir.dout)/sqlite3-worker1-promiser.mjs -sqlite3-worker1-bundler-friendly.js := $(dir.dout)/sqlite3-worker1-bundler-friendly.mjs +sqlite3-worker1-bundler-friendly.mjs := $(dir.dout)/sqlite3-worker1-bundler-friendly.mjs sqlite3-worker1-promiser-bundler-friendly.js := $(dir.dout)/sqlite3-worker1-promiser-bundler-friendly.js $(eval $(call C-PP.FILTER,$(sqlite3-worker1.js.in),$(sqlite3-worker1.js))) -$(eval $(call C-PP.FILTER,$(sqlite3-worker1.js.in),$(sqlite3-worker1-bundler-friendly.js),\ +$(eval $(call C-PP.FILTER,$(sqlite3-worker1.js.in),$(sqlite3-worker1-bundler-friendly.mjs),\ $(c-pp.D.sqlite3-bundler-friendly))) $(eval $(call C-PP.FILTER,$(sqlite3-worker1-promiser.js.in),$(sqlite3-worker1-promiser.js))) $(eval $(call C-PP.FILTER,$(sqlite3-worker1-promiser.js.in),\ @@ -951,10 +952,17 @@ $(eval $(call C-PP.FILTER,$(sqlite3-worker1-promiser.js.in),\ $(c-pp.D.sqlite3-bundler-friendly))) $(eval $(call C-PP.FILTER,$(sqlite3-worker1-promiser.js.in),$(sqlite3-worker1-promiser.mjs),\ -Dtarget=es6-module -Dtarget=es6-bundler-friendly)) -$(sqlite3-bundler-friendly.mjs): $(sqlite3-worker1-bundler-friendly.js) \ +$(sqlite3-bundler-friendly.mjs): $(sqlite3-worker1-bundler-friendly.mjs) \ $(sqlite3-worker1-promiser-bundler-friendly.js) -$(sqlite3.js) $(sqlite3.mjs): $(sqlite3-worker1.js) \ +all: $(sqlite3-worker1.js) \ $(sqlite3-worker1-promiser.js) $(sqlite3-worker1-promiser.mjs) + +sqlite3-api.ext.jses += \ + $(sqlite3-worker1-promiser.mjs) \ + $(sqlite3-worker1.js) +all quick: $(sqlite3-api.ext.jses) +q: quick + ######################################################################## # batch-runner.js is part of one of the test apps which reads in SQL # dumps generated by $(speedtest1) and executes them. diff --git a/ext/wasm/api/sqlite3-worker1-promiser.c-pp.js b/ext/wasm/api/sqlite3-worker1-promiser.c-pp.js index 5e399cd344..06eb0781c8 100644 --- a/ext/wasm/api/sqlite3-worker1-promiser.c-pp.js +++ b/ext/wasm/api/sqlite3-worker1-promiser.c-pp.js @@ -47,8 +47,8 @@ opportunity, and the only way to know when the worker module has completed loading. The irony of using a callback for this, instead of returning a promise from sqlite3Worker1Promiser() is not lost on - the developers, but initial attempts to return a promise resulted - in a much clumsier interface. + the developers: see sqlite3Worker1Promiser.v2() which uses a + Promise instead. - `onunhandled` (optional): a callback which gets passed the message event object for any worker.onmessage() events which @@ -251,9 +251,10 @@ globalThis.sqlite3Worker1Promiser = function callee(config = callee.defaultConfi return p; }; }/*sqlite3Worker1Promiser()*/; + globalThis.sqlite3Worker1Promiser.defaultConfig = { worker: function(){ -//#if target=es6-bundler-friendly +//#if target=es6-module return new Worker(new URL("sqlite3-worker1-bundler-friendly.mjs", import.meta.url),{ type: 'module' }); @@ -274,7 +275,7 @@ globalThis.sqlite3Worker1Promiser.defaultConfig = { return new Worker(theJs + globalThis.location.search); //#endif } -//#ifnot target=es6-bundler-friendly +//#ifnot target=es6-module .bind({ currentScript: globalThis?.document?.currentScript }) @@ -285,11 +286,17 @@ globalThis.sqlite3Worker1Promiser.defaultConfig = { /** sqlite3Worker1Promiser.v2() works identically to - sqlite3Worker1Promiser() except that it returns a promise instead - of relying an an onready callback in the config object. + sqlite3Worker1Promiser() except that it returns a Promise instead + of relying an an onready callback in the config object. The Promise + resolves to the same factory function which + sqlite3Worker1Promiser() returns. + + If config is-a function or is an object which contains an onready + function, that function is replaced by a proxy which will resolve + after calling the original function and will reject if that + function throws. */ sqlite3Worker1Promiser.v2 = function(config){ - const x = Object.create(null); let oldFunc; if( 'function' == typeof config ){ oldFunc = config; @@ -298,26 +305,36 @@ sqlite3Worker1Promiser.v2 = function(config){ oldFunc = config.onready; delete config.onready; } + const promiseProxy = Object.create(null); config = Object.assign((config || Object.create(null)),{ - onready: function(func){ + onready: async function(func){ try { - if( oldFunc ){ - oldFunc(func); - } - x.resolve(func); + if( oldFunc ) await oldFunc(func); + promiseProxy.resolve(func); } - catch(e){x.reject(e)} + catch(e){promiseProxy.reject(e)} } }); const p = new Promise(function(resolve,reject){ - x.resolve = resolve; - x.reject = reject; + promiseProxy.resolve = resolve; + promiseProxy.reject = reject; }); - sqlite3Worker1Promiser(config); + try{ + sqlite3Worker1Promiser(config); + }catch(e){ + promiseProxy.reject(e); + } return p; }; //#if target=es6-module +/** + When built as a module, we export sqlite3Worker1Promiser.v2() + instead of sqlite3Worker1Promise() because (A) its interface is more + conventional for ESM usage and (B) the ESM option export option for + this API did not exist until v2 was created, so there's no backwards + incompatibility. +*/ export default sqlite3Worker1Promiser.v2; //#endif /* target=es6-module */ //#else diff --git a/ext/wasm/demo-worker1-promiser-esm.html b/ext/wasm/demo-worker1-promiser-esm.html new file mode 100644 index 0000000000..3995950938 --- /dev/null +++ b/ext/wasm/demo-worker1-promiser-esm.html @@ -0,0 +1,311 @@ + + + + + + + + + worker-promise (via ESM) tests + + +

    worker-promise (via ESM) tests
    + +
    +
    +
    Initializing app...
    +
    + On a slow internet connection this may take a moment. If this + message displays for "a long time", intialization may have + failed and the JavaScript console may contain clues as to why. +
    +
    +
    Downloading...
    +
    + +
    +
    Most stuff on this page happens in the dev console.
    +
    +
    + + + + + diff --git a/ext/wasm/dist.make b/ext/wasm/dist.make index 5d610e37b1..5165a7ec4b 100644 --- a/ext/wasm/dist.make +++ b/ext/wasm/dist.make @@ -49,12 +49,17 @@ dist.top.extras := \ tester1.js tester1.mjs \ demo-jsstorage.html demo-jsstorage.js \ demo-worker1.html demo-worker1.js \ - demo-worker1-promiser.html demo-worker1-promiser.js + demo-worker1-promiser.html demo-worker1-promiser.js \ + demo-worker1-promiser-esm.html dist.jswasm.extras := $(sqlite3-api.ext.jses) $(sqlite3.wasm) dist.common.extras := \ $(wildcard $(dir.common)/*.css) \ $(dir.common)/SqliteTestUtil.js +#$(info sqlite3-worker1-promiser.mjs = $(sqlite3-worker1-promiser.mjs)) +#$(info sqlite3-worker1.js = $(sqlite3-worker1.js)) +#$(info sqlite3-api.ext.jses = $(sqlite3-api.ext.jses)) +#$(info dist.jswasm.extras = $(dist.jswasm.extras)) .PHONY: dist snapshot # DIST_STRIP_COMMENTS $(call)able to be used in stripping C-style # from the dist copies of certain files. @@ -67,7 +72,8 @@ endef # STRIP_K1.js = list of JS files which need to be passed through # $(bin.stripcomments) with a single -k flag. STRIP_K1.js := $(sqlite3-worker1.js) $(sqlite3-worker1-promiser.js) \ - $(sqlite3-worker1-bundler-friendly.js) $(sqlite3-worker1-promiser-bundler-friendly.js) + $(sqlite3-worker1-bundler-friendly.js) \ + $(sqlite3-api.ext.jses) # STRIP_K2.js = list of JS files which need to be passed through # $(bin.stripcomments) with two -k flags. STRIP_K2.js := $(sqlite3.js) $(sqlite3.mjs) \ @@ -88,6 +94,7 @@ STRIP_K2.js := $(sqlite3.js) $(sqlite3.mjs) \ dist: \ $(bin.stripccomments) $(bin.version-info) \ $(dist.build) $(STRIP_K1.js) $(STRIP_K2.js) \ + $(dist.jswasm.extras) $(dist.common.extras) \ $(MAKEFILE) $(MAKEFILE.dist) @echo "Making end-user deliverables..." @rm -fr $(dist-dir.top) diff --git a/ext/wasm/index-dist.html b/ext/wasm/index-dist.html index f5bcdc1cb2..7b778b0205 100644 --- a/ext/wasm/index-dist.html +++ b/ext/wasm/index-dist.html @@ -97,6 +97,8 @@ wrapper is significantly easier to use, however.
  • demo-worker1-promiser: a demo of the Promise-based wrapper of the Worker1 API.
  • +
  • demo-worker1-promiser-esm: + same as the previous demo except loads the promiser from an ESM module.
  • diff --git a/ext/wasm/index.html b/ext/wasm/index.html index ebbfd6763d..d12a3aa03f 100644 --- a/ext/wasm/index.html +++ b/ext/wasm/index.html @@ -84,6 +84,8 @@ wrapper is significantly easier to use, however.
  • demo-worker1-promiser: a demo of the Promise-based wrapper of the Worker1 API.
  • +
  • demo-worker1-promiser-esm: + same as the previous demo except loads the promiser from an ESM module.
  • speedtest1 ports (sqlite3's primary benchmarking tool)... diff --git a/manifest b/manifest index 9d045f3c98..199d0f3b07 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Initial\swork\sat\sgetting\ssqlite3Worker1Promiser.v2()\sto\sreturn\sa\sPromise\sinstead\sof\susing\san\sonready()\scallback,\sand\salso\screating\san\sESM\sbuild\sfor\spromiser1\sper\suser\srequest.\sIt\sseems\sto\swork\sbut\srequires\smore\stesting. -D 2024-03-07T16:04:43.823 +C wasm\spromiser.v2\sis\sessentially\sworking\sbut\sthe\sdemo\scode\sis\sdouble-loading\sthe\smodule\sfor\sas-yet-undetermined\sreasons. +D 2024-03-07T17:56:08.872 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -587,7 +587,7 @@ F ext/userauth/sqlite3userauth.h 7f3ea8c4686db8e40b0a0e7a8e0b00fac13aa7a3 F ext/userauth/user-auth.txt ca7e9ee82ca4e1c1744295f8184dd70edfae1992865d26c64303f539eb6c084c F ext/userauth/userauth.c 7f00cded7dcaa5d47f54539b290a43d2e59f4b1eb5f447545fa865f002fc80cb F ext/wasm/EXPORTED_FUNCTIONS.fiddle.in 27450c8b8c70875a260aca55435ec927068b34cef801a96205adb81bdcefc65c -F ext/wasm/GNUmakefile e04f36fec0ab949424622a906020902651bd8d17f9696c56ed572eebc63e2355 +F ext/wasm/GNUmakefile fc361b472fdbf1256931769339d6d6e866048f6fcdbbe4bc1a60bfe70034895f F ext/wasm/README-dist.txt 6382cb9548076fca472fb3330bbdba3a55c1ea0b180ff9253f084f07ff383576 F ext/wasm/README.md a8a2962c3aebdf8d2104a9102e336c5554e78fc6072746e5daf9c61514e7d193 F ext/wasm/SQLTester/GNUmakefile e0794f676d55819951bbfae45cc5e8d7818dc460492dc317ce7f0d2eca15caff @@ -616,7 +616,7 @@ F ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js 5a430874906ff3f4a6ca69aadf0c2aae F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js fe427645e1499618f5fa7bc670af850577d8bcc132df982078690c9bf8400baa F ext/wasm/api/sqlite3-vtab-helper.c-pp.js a2fcbc3fecdd0eea229283584ebc122f29d98194083675dbe5cb2cf3a17fe309 F ext/wasm/api/sqlite3-wasm.c d33a16495ca871781e78812d3a18fed78b797468fffee657b8d7199b277ff359 -F ext/wasm/api/sqlite3-worker1-promiser.c-pp.js c11220b21f748c955ca798ad43ba7fea75ca0bf8dba78f46508f09517de26c05 +F ext/wasm/api/sqlite3-worker1-promiser.c-pp.js aff58bf96c253451af02194bf883e1c4851ef4ddbbff0cdd6cfca8f04231ec5d F ext/wasm/api/sqlite3-worker1.c-pp.js 5e8706c2c4af2a57fbcdc02f4e7ef79869971bc21bb8ede777687786ce1c92d5 F ext/wasm/batch-runner-sahpool.html e9a38fdeb36a13eac7b50241dfe7ae066fe3f51f5c0b0151e7baee5fce0d07a7 F ext/wasm/batch-runner-sahpool.js 54a3ac228e6c4703fe72fb65c897e19156263a51fe9b7e21d2834a45e876aabd @@ -632,19 +632,20 @@ F ext/wasm/demo-123.html 8c70a412ce386bd3796534257935eb1e3ea5c581e5d5aea0490b823 F ext/wasm/demo-123.js c7b3cca50c55841c381a9ca4f9396e5bbdc6114273d0b10a43e378e32e7be5bf F ext/wasm/demo-jsstorage.html 409c4be4af5f207fb2877160724b91b33ea36a3cd8c204e8da1acb828ffe588e F ext/wasm/demo-jsstorage.js 44e3ae7ec2483b6c511384c3c290beb6f305c721186bcf5398ca4e00004a06b8 +F ext/wasm/demo-worker1-promiser-esm.html 181039b54e1d88181626d7e157f0f8832a532cf5c0ff6a62607cdbcc746649f3 F ext/wasm/demo-worker1-promiser.html 1de7c248c7c2cfd4a5783d2aa154bce62d74c6de98ab22f5786620b3354ed15f F ext/wasm/demo-worker1-promiser.js e4cd1089269d106dd3bd20684eaddcd176c73baa31867ba0e445c8e7e29160b5 F ext/wasm/demo-worker1.html 2c178c1890a2beb5a5fecb1453e796d067a4b8d3d2a04d65ca2eb1ab2c68ef5d F ext/wasm/demo-worker1.js 836bece8615b17b1b572584f7b15912236a5947fe8c68b98d2737d7e287447ef -F ext/wasm/dist.make 3a851858aad72e246a5d9c5aaf6b6a144305f1bf898ac1846760ea7bab95c9a3 +F ext/wasm/dist.make 8a6e829868e88a67a82670c6bb5d7ffda5dc46aa3f227ba3563c346d246f96d5 F ext/wasm/example_extra_init.c 2347cd69d19d839ef4e5e77b7855103a7fe3ef2af86f2e8c95839afd8b05862f F ext/wasm/fiddle.make 3c2eace29255d6ddd219f5d8cc2728cb28b9fe717ea80b6062c2a6178947a16b F ext/wasm/fiddle/emscripten.css 3d253a6fdb8983a2ac983855bfbdd4b6fa1ff267c28d69513dd6ef1f289ada3f F ext/wasm/fiddle/fiddle-worker.js 850e66fce39b89d59e161d1abac43a181a4caa89ddeea162765d660277cd84ce F ext/wasm/fiddle/fiddle.js 04a638e3ed8fc9ca7c05cbe73ac4196e4529ec564639a76fbcecaffdf62bd983 F ext/wasm/fiddle/index.html 5daf54e8f3d7777cbb1ca4f93affe28858dbfff25841cb4ab81d694efed28ec2 -F ext/wasm/index-dist.html e91d76e4581185238fd3d42ed86ec600f7023ed3e3a944c5c356f25304bf1263 -F ext/wasm/index.html b31ce41c0da476d5ffcef23069b9d3415b419d65af5779096ebcfbcbade453a9 +F ext/wasm/index-dist.html 564b5ec5669676482c5a25dea9e721d8eafed426ecb155f93d29aeff8507511f +F ext/wasm/index.html 4337f495416756802669f69f9f9f3df9f87ee4c1918e6718719b4b5718e4713a F ext/wasm/jaccwabyt/jaccwabyt.js 1264710db3cfbcb6887d95665b7aeba60c1126eaef789ca4cf1a4a17d5bc7f54 F ext/wasm/jaccwabyt/jaccwabyt.md 59a20df389abcc3606eb4eaea7fb7ba14504beb3e345dbea9b99a0618ba3bec8 F ext/wasm/module-symbols.html dc476b403369b26a1a23773e13b80f41b9a49f0825e81435fe3600a7cfbbe337 @@ -2176,11 +2177,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 483fa2969e1e10cd8e8d2f9e3027871c65b1360b6c23897efe3ce63a3a55ae13 -R fb2d3021442c55c82ff56e48b32fdd31 -T *branch * wasm-promiser1-v2 -T *sym-wasm-promiser1-v2 * -T -sym-trunk * Cancelled\sby\sbranch. +P 0e272123ace55ed63fe86632671cca48e8965a28fc3625324984028729fc203f +R c8505d5644abe3c20f07eb87db82c9ac U stephan -Z d10f630418c41733e8d0108d272da900 +Z 20c543fa694914574de31b908812d405 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 145a2be6b8..1bcbadbb82 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0e272123ace55ed63fe86632671cca48e8965a28fc3625324984028729fc203f \ No newline at end of file +aa877ce0c3b3aa1accd6e5fcd722d1bfaa79bea28c04c6badd8a547cea4bbc63 \ No newline at end of file From 84016759dd86626aa8c92270cb4939b0733c7dba Mon Sep 17 00:00:00 2001 From: stephan Date: Thu, 7 Mar 2024 18:53:27 +0000 Subject: [PATCH 184/430] Resolve duplicate loading of promiser v2 demo code (a side effect of having done precisely what it was told to do). Consolidate demo-worker1-promiser(-esm).html/(m)js variants into central copies processed with c-pp. FossilOrigin-Name: 9347d9b9a69277e40ea2f3ec6e1ff37ea19d24b4af80c6230b10624173f2f17c --- ext/wasm/GNUmakefile | 11 + ext/wasm/api/sqlite3-worker1-promiser.c-pp.js | 8 +- ext/wasm/demo-worker1-promiser-esm.html | 311 ------------------ ...r.html => demo-worker1-promiser.c-pp.html} | 10 +- ...miser.js => demo-worker1-promiser.c-pp.js} | 38 ++- ext/wasm/dist.make | 5 +- manifest | 21 +- manifest.uuid | 2 +- 8 files changed, 62 insertions(+), 344 deletions(-) delete mode 100644 ext/wasm/demo-worker1-promiser-esm.html rename ext/wasm/{demo-worker1-promiser.html => demo-worker1-promiser.c-pp.html} (86%) rename ext/wasm/{demo-worker1-promiser.js => demo-worker1-promiser.c-pp.js} (89%) diff --git a/ext/wasm/GNUmakefile b/ext/wasm/GNUmakefile index 922f341857..6e7b49875f 100644 --- a/ext/wasm/GNUmakefile +++ b/ext/wasm/GNUmakefile @@ -954,11 +954,22 @@ $(eval $(call C-PP.FILTER,$(sqlite3-worker1-promiser.js.in),$(sqlite3-worker1-pr -Dtarget=es6-module -Dtarget=es6-bundler-friendly)) $(sqlite3-bundler-friendly.mjs): $(sqlite3-worker1-bundler-friendly.mjs) \ $(sqlite3-worker1-promiser-bundler-friendly.js) +$(eval $(call C-PP.FILTER,demo-worker1-promiser.c-pp.js,demo-worker1-promiser.js)) +$(eval $(call C-PP.FILTER,demo-worker1-promiser.c-pp.js,demo-worker1-promiser.mjs,\ + -Dtarget=es6-module)) +$(eval $(call C-PP.FILTER,demo-worker1-promiser.c-pp.html,demo-worker1-promiser.html)) +$(eval $(call C-PP.FILTER,demo-worker1-promiser.c-pp.html,demo-worker1-promiser-esm.html,\ + -Dtarget=es6-module)) all: $(sqlite3-worker1.js) \ $(sqlite3-worker1-promiser.js) $(sqlite3-worker1-promiser.mjs) +demo-worker1-promiser.html: $(sqlite3-worker1-promiser.js) demo-worker1-promiser.js +demo-worker1-promiser-esm.html: $(sqlite3-worker1-promiser.mjs) demo-worker1-promiser.mjs +all: demo-worker1-promiser.html demo-worker1-promiser-esm.html + sqlite3-api.ext.jses += \ $(sqlite3-worker1-promiser.mjs) \ + $(sqlite3-worker1-bundler-friendly.mjs) \ $(sqlite3-worker1.js) all quick: $(sqlite3-api.ext.jses) q: quick diff --git a/ext/wasm/api/sqlite3-worker1-promiser.c-pp.js b/ext/wasm/api/sqlite3-worker1-promiser.c-pp.js index 06eb0781c8..878147acd6 100644 --- a/ext/wasm/api/sqlite3-worker1-promiser.c-pp.js +++ b/ext/wasm/api/sqlite3-worker1-promiser.c-pp.js @@ -320,12 +320,16 @@ sqlite3Worker1Promiser.v2 = function(config){ promiseProxy.reject = reject; }); try{ - sqlite3Worker1Promiser(config); + this.original(config); }catch(e){ promiseProxy.reject(e); } return p; -}; +}.bind({ + /* We do this because clients are + recommended to delete globalThis.sqlite3Worker1Promiser. */ + original: sqlite3Worker1Promiser +}); //#if target=es6-module /** diff --git a/ext/wasm/demo-worker1-promiser-esm.html b/ext/wasm/demo-worker1-promiser-esm.html deleted file mode 100644 index 3995950938..0000000000 --- a/ext/wasm/demo-worker1-promiser-esm.html +++ /dev/null @@ -1,311 +0,0 @@ - - - - - - - - - worker-promise (via ESM) tests - - -
    worker-promise (via ESM) tests
    - -
    -
    -
    Initializing app...
    -
    - On a slow internet connection this may take a moment. If this - message displays for "a long time", intialization may have - failed and the JavaScript console may contain clues as to why. -
    -
    -
    Downloading...
    -
    - -
    -
    Most stuff on this page happens in the dev console.
    -
    -
    - - - - - diff --git a/ext/wasm/demo-worker1-promiser.html b/ext/wasm/demo-worker1-promiser.c-pp.html similarity index 86% rename from ext/wasm/demo-worker1-promiser.html rename to ext/wasm/demo-worker1-promiser.c-pp.html index e99131e6c9..e0b487bdf3 100644 --- a/ext/wasm/demo-worker1-promiser.html +++ b/ext/wasm/demo-worker1-promiser.c-pp.html @@ -6,7 +6,11 @@ +//#if target=es6-module + worker-promise (via ESM) tests +//#else worker-promise tests +//#endif
    worker-promise tests
    @@ -22,13 +26,17 @@
    Downloading...
    - +
    Most stuff on this page happens in the dev console.

    +//#if target=es6-module + +//#else +//#endif diff --git a/ext/wasm/demo-worker1-promiser.js b/ext/wasm/demo-worker1-promiser.c-pp.js similarity index 89% rename from ext/wasm/demo-worker1-promiser.js rename to ext/wasm/demo-worker1-promiser.c-pp.js index 19a7af1143..f6fc9568ae 100644 --- a/ext/wasm/demo-worker1-promiser.js +++ b/ext/wasm/demo-worker1-promiser.c-pp.js @@ -13,7 +13,13 @@ Demonstration of the sqlite3 Worker API #1 Promiser: a Promise-based proxy for for the sqlite3 Worker #1 API. */ -'use strict'; +//#if target=es6-module +import {default as promiserFactory} from "./jswasm/sqlite3-worker1-promiser.mjs"; +//#else +"use strict"; +const promiserFactory = globalThis.sqlite3Worker1Promiser.v2; +delete globalThis.sqlite3Worker1Promiser; +//#endif (async function(){ const T = globalThis.SqliteTestUtil; const eOutput = document.querySelector('#test-output'); @@ -33,35 +39,35 @@ logHtml("","Total test count:",T.counter+". Total time =",(performance.now() - startTime),"ms"); }; - //why is this triggered even when we catch() a Promise? - //window.addEventListener('unhandledrejection', function(event) { - // warn('unhandledrejection',event); - //}); - const promiserConfig = { - worker: ()=>{ - const w = new Worker("jswasm/sqlite3-worker1.js"); - w.onerror = (event)=>error("worker.onerror",event); - return w; +//#ifnot target=es6-module + /** + The v1 interfaces uses an onready function. The v2 interface optionally + accepts one but does not require it. If provided, it is called _before_ + the promise is resolved, and the promise is rejected if onready() throws. + */ + onready: function(f){ + /* f === the function returned by promiserFactory(). + Ostensibly (f === workerPromise) but this function is + called before the promiserFactory() Promise resolves, so + before workerPromise is set. */ + console.warn("This is the v2 interface - you don't need an onready() function."); }, +//#endif debug: 1 ? undefined : (...args)=>console.debug('worker debug',...args), onunhandled: function(ev){ error("Unhandled worker message:",ev.data); }, onerror: function(ev){ error("worker1 error:",ev); - }, - onready: function(f){ - warn("This is the v2 interface - don't pass an onready() function."); } }; - const workerPromise = await globalThis.sqlite3Worker1Promiser.v2(promiserConfig) + const workerPromise = await promiserFactory(promiserConfig) .then((func)=>{ - log("Init complete. Starting tests momentarily."); + console.log("Init complete. Starting tests momentarily."); globalThis.sqlite3TestModule.setStatus(null)/*hide the HTML-side is-loading spinner*/; return func; }); - delete globalThis.sqlite3Worker1Promiser; const wtest = async function(msgType, msgArgs, callback){ if(2===arguments.length && 'function'===typeof msgArgs){ diff --git a/ext/wasm/dist.make b/ext/wasm/dist.make index 5165a7ec4b..0ea53063b4 100644 --- a/ext/wasm/dist.make +++ b/ext/wasm/dist.make @@ -50,8 +50,9 @@ dist.top.extras := \ demo-jsstorage.html demo-jsstorage.js \ demo-worker1.html demo-worker1.js \ demo-worker1-promiser.html demo-worker1-promiser.js \ - demo-worker1-promiser-esm.html -dist.jswasm.extras := $(sqlite3-api.ext.jses) $(sqlite3.wasm) + demo-worker1-promiser-esm.html demo-worker1-promiser.mjs +dist.jswasm.extras := $(sqlite3.wasm) \ + $(sqlite3-api.ext.jses) dist.common.extras := \ $(wildcard $(dir.common)/*.css) \ $(dir.common)/SqliteTestUtil.js diff --git a/manifest b/manifest index 199d0f3b07..7d1e1e777f 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C wasm\spromiser.v2\sis\sessentially\sworking\sbut\sthe\sdemo\scode\sis\sdouble-loading\sthe\smodule\sfor\sas-yet-undetermined\sreasons. -D 2024-03-07T17:56:08.872 +C Resolve\sduplicate\sloading\sof\spromiser\sv2\sdemo\scode\s(a\sside\seffect\sof\shaving\sdone\sprecisely\swhat\sit\swas\stold\sto\sdo).\sConsolidate\sdemo-worker1-promiser(-esm).html/(m)js\svariants\sinto\scentral\scopies\sprocessed\swith\sc-pp. +D 2024-03-07T18:53:27.916 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -587,7 +587,7 @@ F ext/userauth/sqlite3userauth.h 7f3ea8c4686db8e40b0a0e7a8e0b00fac13aa7a3 F ext/userauth/user-auth.txt ca7e9ee82ca4e1c1744295f8184dd70edfae1992865d26c64303f539eb6c084c F ext/userauth/userauth.c 7f00cded7dcaa5d47f54539b290a43d2e59f4b1eb5f447545fa865f002fc80cb F ext/wasm/EXPORTED_FUNCTIONS.fiddle.in 27450c8b8c70875a260aca55435ec927068b34cef801a96205adb81bdcefc65c -F ext/wasm/GNUmakefile fc361b472fdbf1256931769339d6d6e866048f6fcdbbe4bc1a60bfe70034895f +F ext/wasm/GNUmakefile 4bb4cf70a8153dd5b5fee17d724075c54174da630b424bbcf48c744633396f62 F ext/wasm/README-dist.txt 6382cb9548076fca472fb3330bbdba3a55c1ea0b180ff9253f084f07ff383576 F ext/wasm/README.md a8a2962c3aebdf8d2104a9102e336c5554e78fc6072746e5daf9c61514e7d193 F ext/wasm/SQLTester/GNUmakefile e0794f676d55819951bbfae45cc5e8d7818dc460492dc317ce7f0d2eca15caff @@ -616,7 +616,7 @@ F ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js 5a430874906ff3f4a6ca69aadf0c2aae F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js fe427645e1499618f5fa7bc670af850577d8bcc132df982078690c9bf8400baa F ext/wasm/api/sqlite3-vtab-helper.c-pp.js a2fcbc3fecdd0eea229283584ebc122f29d98194083675dbe5cb2cf3a17fe309 F ext/wasm/api/sqlite3-wasm.c d33a16495ca871781e78812d3a18fed78b797468fffee657b8d7199b277ff359 -F ext/wasm/api/sqlite3-worker1-promiser.c-pp.js aff58bf96c253451af02194bf883e1c4851ef4ddbbff0cdd6cfca8f04231ec5d +F ext/wasm/api/sqlite3-worker1-promiser.c-pp.js bd89edfe42a4d7122a6d6d405c5423cf00aabba1f76f6ea8e2dba9c628ddd91a F ext/wasm/api/sqlite3-worker1.c-pp.js 5e8706c2c4af2a57fbcdc02f4e7ef79869971bc21bb8ede777687786ce1c92d5 F ext/wasm/batch-runner-sahpool.html e9a38fdeb36a13eac7b50241dfe7ae066fe3f51f5c0b0151e7baee5fce0d07a7 F ext/wasm/batch-runner-sahpool.js 54a3ac228e6c4703fe72fb65c897e19156263a51fe9b7e21d2834a45e876aabd @@ -632,12 +632,11 @@ F ext/wasm/demo-123.html 8c70a412ce386bd3796534257935eb1e3ea5c581e5d5aea0490b823 F ext/wasm/demo-123.js c7b3cca50c55841c381a9ca4f9396e5bbdc6114273d0b10a43e378e32e7be5bf F ext/wasm/demo-jsstorage.html 409c4be4af5f207fb2877160724b91b33ea36a3cd8c204e8da1acb828ffe588e F ext/wasm/demo-jsstorage.js 44e3ae7ec2483b6c511384c3c290beb6f305c721186bcf5398ca4e00004a06b8 -F ext/wasm/demo-worker1-promiser-esm.html 181039b54e1d88181626d7e157f0f8832a532cf5c0ff6a62607cdbcc746649f3 -F ext/wasm/demo-worker1-promiser.html 1de7c248c7c2cfd4a5783d2aa154bce62d74c6de98ab22f5786620b3354ed15f -F ext/wasm/demo-worker1-promiser.js e4cd1089269d106dd3bd20684eaddcd176c73baa31867ba0e445c8e7e29160b5 +F ext/wasm/demo-worker1-promiser.c-pp.html 635cf90685805e21772a5f7a35d1ace80f98a9ef7c42ff04d7a125ddca7e5db8 w ext/wasm/demo-worker1-promiser.html +F ext/wasm/demo-worker1-promiser.c-pp.js fcc628cb42fcfaf07d250477801de1e6deb1e319d003976612a0db8d76b9fccc w ext/wasm/demo-worker1-promiser.js F ext/wasm/demo-worker1.html 2c178c1890a2beb5a5fecb1453e796d067a4b8d3d2a04d65ca2eb1ab2c68ef5d F ext/wasm/demo-worker1.js 836bece8615b17b1b572584f7b15912236a5947fe8c68b98d2737d7e287447ef -F ext/wasm/dist.make 8a6e829868e88a67a82670c6bb5d7ffda5dc46aa3f227ba3563c346d246f96d5 +F ext/wasm/dist.make f2ce42305268fe33d4b50f6e4bb3daf4a60302a90736eee382f1b8af9ff32ec1 F ext/wasm/example_extra_init.c 2347cd69d19d839ef4e5e77b7855103a7fe3ef2af86f2e8c95839afd8b05862f F ext/wasm/fiddle.make 3c2eace29255d6ddd219f5d8cc2728cb28b9fe717ea80b6062c2a6178947a16b F ext/wasm/fiddle/emscripten.css 3d253a6fdb8983a2ac983855bfbdd4b6fa1ff267c28d69513dd6ef1f289ada3f @@ -2177,8 +2176,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 0e272123ace55ed63fe86632671cca48e8965a28fc3625324984028729fc203f -R c8505d5644abe3c20f07eb87db82c9ac +P aa877ce0c3b3aa1accd6e5fcd722d1bfaa79bea28c04c6badd8a547cea4bbc63 +R defcc9933f81850986aa7430cee8afd6 U stephan -Z 20c543fa694914574de31b908812d405 +Z bec63fded5235320bd7ff6ae8e1104cd # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 1bcbadbb82..828254e7bc 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -aa877ce0c3b3aa1accd6e5fcd722d1bfaa79bea28c04c6badd8a547cea4bbc63 \ No newline at end of file +9347d9b9a69277e40ea2f3ec6e1ff37ea19d24b4af80c6230b10624173f2f17c \ No newline at end of file From f10de5360ad8941a1bd35c84e7dc461da1a21454 Mon Sep 17 00:00:00 2001 From: drh <> Date: Fri, 8 Mar 2024 03:24:09 +0000 Subject: [PATCH 185/430] Must use sqlite3IntFloatCompare() for accurate comparisons between very large integer and floating point values in RTREE. Otherwise the comparison does not work on all platforms. Further fix to [027e5336acc26f57]. FossilOrigin-Name: 820f106acff5f2cd01da0e95a0e6f2bcc087705bf8c08b730b1fdb08db5679c8 --- ext/rtree/rtree.c | 5 +++-- manifest | 18 +++++++++--------- manifest.uuid | 2 +- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/ext/rtree/rtree.c b/ext/rtree/rtree.c index a24304a8ac..299b5b54b9 100644 --- a/ext/rtree/rtree.c +++ b/ext/rtree/rtree.c @@ -1841,6 +1841,8 @@ static int deserializeGeometry(sqlite3_value *pValue, RtreeConstraint *pCons){ return SQLITE_OK; } +int sqlite3IntFloatCompare(i64,double); + /* ** Rtree virtual table module xFilter method. */ @@ -1871,8 +1873,7 @@ static int rtreeFilter( int eType = sqlite3_value_numeric_type(argv[0]); if( eType==SQLITE_INTEGER || (eType==SQLITE_FLOAT - && (i64)(sqlite3_value_double(argv[0]))==iRowid - && (double)iRowid==sqlite3_value_double(argv[0])) + && 0==sqlite3IntFloatCompare(iRowid,sqlite3_value_double(argv[0]))) ){ rc = findLeafNode(pRtree, iRowid, &pLeaf, &iNode); }else{ diff --git a/manifest b/manifest index a1d3e6d18a..1c8020e2d0 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Introducing\sJS\sworker1\spromiser\sv2,\swhich\sinitializes\svia\sPromise\s(instead\sof\sa\scallback\sfunction)\sand\scan\sbe\sloaded\sas\san\sESM\smodule. -D 2024-03-07T19:29:53.171 +C Must\suse\ssqlite3IntFloatCompare()\sfor\saccurate\scomparisons\sbetween\svery\slarge\ninteger\sand\sfloating\spoint\svalues\sin\sRTREE.\s\sOtherwise\sthe\scomparison\sdoes\nnot\swork\son\sall\splatforms.\s\sFurther\sfix\sto\s[027e5336acc26f57]. +D 2024-03-08T03:24:09.798 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -506,7 +506,7 @@ F ext/repair/test/checkindex01.test b530f141413b587c9eb78ff734de6bb79bc3515c3350 F ext/repair/test/test.tcl 686d76d888dffd021f64260abf29a55c57b2cedfa7fc69150b42b1d6119aac3c F ext/rtree/README 6315c0d73ebf0ec40dedb5aa0e942bc8b54e3761 F ext/rtree/geopoly.c 0dd4775e896cee6067979d67aff7c998e75c2c9d9cd8d62a1a790c09cde7adca -F ext/rtree/rtree.c d87dfef2dd8ee2360898857187b9f763e90dcee9cf98f3f487ec473b6ae30db3 +F ext/rtree/rtree.c b6133dba5ae331fa6c1fc34df6aa623eba951b05ac35116f954a0bf7ab550436 F ext/rtree/rtree.h 4a690463901cb5e6127cf05eb8e642f127012fd5003830dbc974eca5802d9412 F ext/rtree/rtree1.test e0608db762b2aadca0ecb6f97396cf66244490adc3ba88f2a292b27be3e1da3e F ext/rtree/rtree2.test 9d9deddbb16fd0c30c36e6b4fdc3ee3132d765567f0f9432ee71e1303d32603d @@ -632,8 +632,8 @@ F ext/wasm/demo-123.html 8c70a412ce386bd3796534257935eb1e3ea5c581e5d5aea0490b823 F ext/wasm/demo-123.js c7b3cca50c55841c381a9ca4f9396e5bbdc6114273d0b10a43e378e32e7be5bf F ext/wasm/demo-jsstorage.html 409c4be4af5f207fb2877160724b91b33ea36a3cd8c204e8da1acb828ffe588e F ext/wasm/demo-jsstorage.js 44e3ae7ec2483b6c511384c3c290beb6f305c721186bcf5398ca4e00004a06b8 -F ext/wasm/demo-worker1-promiser.c-pp.html 635cf90685805e21772a5f7a35d1ace80f98a9ef7c42ff04d7a125ddca7e5db8 w ext/wasm/demo-worker1-promiser.html -F ext/wasm/demo-worker1-promiser.c-pp.js fcc628cb42fcfaf07d250477801de1e6deb1e319d003976612a0db8d76b9fccc w ext/wasm/demo-worker1-promiser.js +F ext/wasm/demo-worker1-promiser.c-pp.html 635cf90685805e21772a5f7a35d1ace80f98a9ef7c42ff04d7a125ddca7e5db8 +F ext/wasm/demo-worker1-promiser.c-pp.js fcc628cb42fcfaf07d250477801de1e6deb1e319d003976612a0db8d76b9fccc F ext/wasm/demo-worker1.html 2c178c1890a2beb5a5fecb1453e796d067a4b8d3d2a04d65ca2eb1ab2c68ef5d F ext/wasm/demo-worker1.js 836bece8615b17b1b572584f7b15912236a5947fe8c68b98d2737d7e287447ef F ext/wasm/dist.make f2ce42305268fe33d4b50f6e4bb3daf4a60302a90736eee382f1b8af9ff32ec1 @@ -2177,8 +2177,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 7fbdc1a849af3440579459bbb8797ebc7f9cce7b34d95675b8baa82db194ea9c 9347d9b9a69277e40ea2f3ec6e1ff37ea19d24b4af80c6230b10624173f2f17c -R 45d7a69c537ca325c17486c899557483 -U stephan -Z 1167a057df3ec3b4a36537840625ce5c +P 2fbaf2f51d37f70ee26d45f0c62f32c15a9e03f68b6d2e2892115e7dc028b929 +R 9853c9517d878f0be47f300b894b10da +U drh +Z 35bc8555140472f74b11b6aaf0808349 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 73fafb821c..922f1dae60 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2fbaf2f51d37f70ee26d45f0c62f32c15a9e03f68b6d2e2892115e7dc028b929 \ No newline at end of file +820f106acff5f2cd01da0e95a0e6f2bcc087705bf8c08b730b1fdb08db5679c8 \ No newline at end of file From a219fb5bb92371aa66fa7e21cb659b97163c2ab5 Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 8 Mar 2024 11:08:53 +0000 Subject: [PATCH 186/430] Do not run tests for the intck extension in OMIT_VIRTUAL_TABLE or OMIT_PRAGMA builds. FossilOrigin-Name: de8130c020821a1615cceeb730423a2d6e01578caaaddeb11950363c4f8ea412 --- ext/intck/intck1.test | 1 + ext/intck/intck2.test | 1 + ext/intck/intck_common.tcl | 10 ++++++++++ ext/intck/intckfault.test | 5 +---- manifest | 20 ++++++++++---------- manifest.uuid | 2 +- 6 files changed, 24 insertions(+), 15 deletions(-) diff --git a/ext/intck/intck1.test b/ext/intck/intck1.test index 1708406304..187132f766 100644 --- a/ext/intck/intck1.test +++ b/ext/intck/intck1.test @@ -15,6 +15,7 @@ source [file join [file dirname [info script]] intck_common.tcl] set testprefix intck1 +return_if_no_intck foreach {tn sql} { 1 "CREATE TABLE t1(a PRIMARY KEY, b)" diff --git a/ext/intck/intck2.test b/ext/intck/intck2.test index c8503042c9..23b241b5a9 100644 --- a/ext/intck/intck2.test +++ b/ext/intck/intck2.test @@ -15,6 +15,7 @@ source [file join [file dirname [info script]] intck_common.tcl] set testprefix intck2 +return_if_no_intck do_execsql_test 1.0 { diff --git a/ext/intck/intck_common.tcl b/ext/intck/intck_common.tcl index 7d6579ae03..1e216b59f3 100644 --- a/ext/intck/intck_common.tcl +++ b/ext/intck/intck_common.tcl @@ -15,6 +15,16 @@ if {![info exists testdir]} { } source $testdir/tester.tcl +ifcapable !vtab||!pragma { + proc return_if_no_intck {} { + finish_test + return -code return + } + return +} else { + proc return_if_no_intck {} {} +} + proc do_intck {db {bSuspend 0}} { set ic [sqlite3_intck $db main] diff --git a/ext/intck/intckfault.test b/ext/intck/intckfault.test index 5c383681ac..0bc06e584a 100644 --- a/ext/intck/intckfault.test +++ b/ext/intck/intckfault.test @@ -12,8 +12,7 @@ source [file join [file dirname [info script]] intck_common.tcl] set testprefix intckfault - - +return_if_no_intck do_execsql_test 1.0 { CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c); @@ -36,8 +35,6 @@ do_faultsim_test 1 -faults oom-t* -prep { set res } -test { catch { $::ic close } -puts $testresult -puts $testnfail faultsim_test_result {0 {SQLITE_OK {}}} {0 {SQLITE_NOMEM {}}} {0 {SQLITE_NOMEM {out of memory}}} } diff --git a/manifest b/manifest index 1c8020e2d0..4a3f018db0 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Must\suse\ssqlite3IntFloatCompare()\sfor\saccurate\scomparisons\sbetween\svery\slarge\ninteger\sand\sfloating\spoint\svalues\sin\sRTREE.\s\sOtherwise\sthe\scomparison\sdoes\nnot\swork\son\sall\splatforms.\s\sFurther\sfix\sto\s[027e5336acc26f57]. -D 2024-03-08T03:24:09.798 +C Do\snot\srun\stests\sfor\sthe\sintck\sextension\sin\sOMIT_VIRTUAL_TABLE\sor\sOMIT_PRAGMA\sbuilds. +D 2024-03-08T11:08:53.935 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -250,12 +250,12 @@ F ext/fts5/tool/showfts5.tcl d54da0e067306663e2d5d523965ca487698e722c F ext/icu/README.txt 7ab7ced8ae78e3a645b57e78570ff589d4c672b71370f5aa9e1cd7024f400fc9 F ext/icu/icu.c c074519b46baa484bb5396c7e01e051034da8884bad1a1cb7f09bbe6be3f0282 F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a32075a8 -F ext/intck/intck1.test 8a879640c90fdff5e91e6c2c41d509485ee634e8077fe0ca9f76be4cbd441fa3 -F ext/intck/intck2.test 47afb44681d13d11072cd8906e6aa877c967e65be788b01f6139922fd91474ef -F ext/intck/intck_common.tcl 9e51458126576783f11051ac0fd25bea3f6b17f570a55884223737f3200b214b +F ext/intck/intck1.test f3a3cba14b6aeff145ffa5515546dd22f7510dad91512e519f43b92b56514012 +F ext/intck/intck2.test d2457c7e5e5b688046d15ebe08a1e1427cc5e7a6dc8d6af215f42e8bcaf67304 +F ext/intck/intck_common.tcl a61fd2697ae55b0a3d89847ca0b590c6e0d8ff64bebb70920d93724799894159 F ext/intck/intckbusy.test 0732fe3efbb9e0a53ffdcc240073f6ff2777ea82c3e08812b16494f650763fe1 F ext/intck/intckcorrupt.test 3211ef68ac53e83951b6c8f6a8d2396506d123fe5898f97f848a25837744ec56 -F ext/intck/intckfault.test ba0213c9c8dce08d519d5251268a3bab076a184b4d07acdea23b65e89c9ae03c +F ext/intck/intckfault.test cff3f75dff74abb3edfcb13f6aa53f6436746ab64b09fe5e2028f051e985efab F ext/intck/sqlite3intck.c 0d10df36e2b7b438aa80ecd3f5e584d41b747586b038258fe6b407f66b81e7c5 F ext/intck/sqlite3intck.h 2b40c38e7063ab822c974c0bd4aed97dabb579ccfe2e180a4639bb3bbef0f1c9 F ext/intck/test_intck.c 34243458378a12d1356c79219a03f244800533b3ab65b4a02861f0403364df12 @@ -2177,8 +2177,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 2fbaf2f51d37f70ee26d45f0c62f32c15a9e03f68b6d2e2892115e7dc028b929 -R 9853c9517d878f0be47f300b894b10da -U drh -Z 35bc8555140472f74b11b6aaf0808349 +P 820f106acff5f2cd01da0e95a0e6f2bcc087705bf8c08b730b1fdb08db5679c8 +R e79b9941107e8b2e4d5643573f5112b9 +U dan +Z 20f09b597a6402ea271e837d23b82103 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 922f1dae60..8a852f1cf2 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -820f106acff5f2cd01da0e95a0e6f2bcc087705bf8c08b730b1fdb08db5679c8 \ No newline at end of file +de8130c020821a1615cceeb730423a2d6e01578caaaddeb11950363c4f8ea412 \ No newline at end of file From 3041642b1a7bfe853302e58d1986eb6792cfe55a Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 8 Mar 2024 11:13:20 +0000 Subject: [PATCH 187/430] Fix pragma6.test so that it works with ENABLE_OVERSIZE_CELL_CHECK builds. FossilOrigin-Name: a02551de4c2d7085569ee76f88bfef5da429e40137cc1d1349b4637f88259ad1 --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/pragma6.test | 23 +++++++++++++---------- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/manifest b/manifest index 4a3f018db0..e42792ac4a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Do\snot\srun\stests\sfor\sthe\sintck\sextension\sin\sOMIT_VIRTUAL_TABLE\sor\sOMIT_PRAGMA\sbuilds. -D 2024-03-08T11:08:53.935 +C Fix\spragma6.test\sso\sthat\sit\sworks\swith\sENABLE_OVERSIZE_CELL_CHECK\sbuilds. +D 2024-03-08T11:13:20.081 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -1501,7 +1501,7 @@ F test/pragma2.test e5d5c176360c321344249354c0c16aec46214c9f F test/pragma3.test 92a46bbea12322dd94a404f49edcfbfc913a2c98115f0d030a7459bb4712ef31 F test/pragma4.test 9559cf5173864bf47c0431873d158fbeb72f920a59905b1f46069d8543eccdab F test/pragma5.test 7b33fc43e2e41abf17f35fb73f71b49671a380ea92a6c94b6ce530a25f8d9102 -F test/pragma6.test fc3b670ab8ed985b2e5faa870f0f81aba1bfd5c3877ef3214e2df88592ccd3e5 +F test/pragma6.test c5ec577ba087954b4dfa619a3cbe97b155b60a0af487527abe89b10fc17e6512 F test/pragmafault.test 275edaf3161771d37de60e5c2b412627ac94cef11739236bec12ed1258b240f8 F test/prefixes.test b524a1c44bffec225b9aec98bd728480352aa8532ac4c15771fb85e8beef65d9 F test/printf.test 685fec5a0c5af2490ab0632775a301554361d674211d690f5bee0a97b05333de @@ -2177,8 +2177,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 820f106acff5f2cd01da0e95a0e6f2bcc087705bf8c08b730b1fdb08db5679c8 -R e79b9941107e8b2e4d5643573f5112b9 +P de8130c020821a1615cceeb730423a2d6e01578caaaddeb11950363c4f8ea412 +R 7c7022496908a493f9a8f2b8a0b5ac5e U dan -Z 20f09b597a6402ea271e837d23b82103 +Z 4eebf82ab948ebc787bc88c49fe0f5a5 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 8a852f1cf2..3d95c47ad5 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -de8130c020821a1615cceeb730423a2d6e01578caaaddeb11950363c4f8ea412 \ No newline at end of file +a02551de4c2d7085569ee76f88bfef5da429e40137cc1d1349b4637f88259ad1 \ No newline at end of file diff --git a/test/pragma6.test b/test/pragma6.test index 8e4233a536..fc5566af10 100644 --- a/test/pragma6.test +++ b/test/pragma6.test @@ -51,16 +51,19 @@ do_test 1.0 { }] } {} -do_execsql_test 1.1 { - CREATE TEMP TABLE t2( - a t1 PRIMARY KEY default 27, - b default(current_timestamp), - d TEXT UNIQUE DEFAULT 'ch`arlie', - c TEXT UNIQUE DEFAULT 084, - UNIQUE(c,b,b,a,b) - ) WITHOUT ROWID; - INSERT INTO t1(a) VALUES(zeroblob(40000)); -} +do_test 1.1 { + execsql { + CREATE TEMP TABLE t2( + a t1 PRIMARY KEY default 27, + b default(current_timestamp), + d TEXT UNIQUE DEFAULT 'ch`arlie', + c TEXT UNIQUE DEFAULT 084, + UNIQUE(c,b,b,a,b) + ) WITHOUT ROWID; + } + catchsql { INSERT INTO t1(a) VALUES(zeroblob(40000)) } + set {} {} +} {} do_test 1.2 { execsql { PRAGMA integrity_check; } From b89aa10cd0d980563df54b5ad0fb2214f06c7c80 Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 8 Mar 2024 13:49:43 +0000 Subject: [PATCH 188/430] Omit some extra tests for the intck extension in OMIT_VIRTUAL_TABLE or OMIT_PRAGMA builds. FossilOrigin-Name: 29d9eb7d55755604781e507f6ca36c50d62fa8d8589ab932d7cefca94ba24f3e --- ext/intck/intckbusy.test | 1 + ext/intck/intckcorrupt.test | 1 + manifest | 14 +++++++------- manifest.uuid | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/ext/intck/intckbusy.test b/ext/intck/intckbusy.test index edfedf5ae8..7c65b686bb 100644 --- a/ext/intck/intckbusy.test +++ b/ext/intck/intckbusy.test @@ -12,6 +12,7 @@ source [file join [file dirname [info script]] intck_common.tcl] set testprefix intckbusy +return_if_no_intck diff --git a/ext/intck/intckcorrupt.test b/ext/intck/intckcorrupt.test index 40f009f9c2..eee63b32f0 100644 --- a/ext/intck/intckcorrupt.test +++ b/ext/intck/intckcorrupt.test @@ -15,6 +15,7 @@ source [file join [file dirname [info script]] intck_common.tcl] set testprefix intckcorrupt +return_if_no_intck #------------------------------------------------------------------------- reset_db diff --git a/manifest b/manifest index e42792ac4a..91661718cc 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\spragma6.test\sso\sthat\sit\sworks\swith\sENABLE_OVERSIZE_CELL_CHECK\sbuilds. -D 2024-03-08T11:13:20.081 +C Omit\ssome\sextra\stests\sfor\sthe\sintck\sextension\sin\sOMIT_VIRTUAL_TABLE\sor\sOMIT_PRAGMA\sbuilds. +D 2024-03-08T13:49:43.243 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -253,8 +253,8 @@ F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a3 F ext/intck/intck1.test f3a3cba14b6aeff145ffa5515546dd22f7510dad91512e519f43b92b56514012 F ext/intck/intck2.test d2457c7e5e5b688046d15ebe08a1e1427cc5e7a6dc8d6af215f42e8bcaf67304 F ext/intck/intck_common.tcl a61fd2697ae55b0a3d89847ca0b590c6e0d8ff64bebb70920d93724799894159 -F ext/intck/intckbusy.test 0732fe3efbb9e0a53ffdcc240073f6ff2777ea82c3e08812b16494f650763fe1 -F ext/intck/intckcorrupt.test 3211ef68ac53e83951b6c8f6a8d2396506d123fe5898f97f848a25837744ec56 +F ext/intck/intckbusy.test d5ed4ef85a4b1dc1dee2484bd14a4bb68529659cca743327df0c775f005fa387 +F ext/intck/intckcorrupt.test f6c302792326fb3db9dcfc70b554c55369bc4b52882eaaf039cfe0b74c821029 F ext/intck/intckfault.test cff3f75dff74abb3edfcb13f6aa53f6436746ab64b09fe5e2028f051e985efab F ext/intck/sqlite3intck.c 0d10df36e2b7b438aa80ecd3f5e584d41b747586b038258fe6b407f66b81e7c5 F ext/intck/sqlite3intck.h 2b40c38e7063ab822c974c0bd4aed97dabb579ccfe2e180a4639bb3bbef0f1c9 @@ -2177,8 +2177,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P de8130c020821a1615cceeb730423a2d6e01578caaaddeb11950363c4f8ea412 -R 7c7022496908a493f9a8f2b8a0b5ac5e +P a02551de4c2d7085569ee76f88bfef5da429e40137cc1d1349b4637f88259ad1 +R af066a0422542da1cc5e88fc5055710e U dan -Z 4eebf82ab948ebc787bc88c49fe0f5a5 +Z b2bec38f4a2e9b652e878f166176c721 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 3d95c47ad5..d5fb64437e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a02551de4c2d7085569ee76f88bfef5da429e40137cc1d1349b4637f88259ad1 \ No newline at end of file +29d9eb7d55755604781e507f6ca36c50d62fa8d8589ab932d7cefca94ba24f3e \ No newline at end of file From 926fb60b05be799ff6e9f0013d2a0f393cfd380c Mon Sep 17 00:00:00 2001 From: drh <> Date: Fri, 8 Mar 2024 14:01:48 +0000 Subject: [PATCH 189/430] Silently ignore redundant ON CONFLICT clauses in an UPSERT. Only the first ON CONFLICT for each index is active. Do not issue an error, since that might break legacy queries. But ignore the redundant ON CONFLICT clauses to prevent problems such as described in [forum:/forumpost/919c6579c8|forum post 919c6579c8]. FossilOrigin-Name: d0ea6b6ba64dba9d68c2b391ccf1171ea96fcdd7409dafdb2b697accb00246b8 --- manifest | 20 ++++++++++---------- manifest.uuid | 2 +- src/insert.c | 2 +- src/sqliteInt.h | 3 ++- src/upsert.c | 21 +++++++++++++++++---- test/upsert5.test | 42 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 73 insertions(+), 17 deletions(-) diff --git a/manifest b/manifest index 91661718cc..e75a8d5b89 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Omit\ssome\sextra\stests\sfor\sthe\sintck\sextension\sin\sOMIT_VIRTUAL_TABLE\sor\sOMIT_PRAGMA\sbuilds. -D 2024-03-08T13:49:43.243 +C Silently\signore\sredundant\sON\sCONFLICT\sclauses\sin\san\sUPSERT.\s\sOnly\sthe\sfirst\nON\sCONFLICT\sfor\seach\sindex\sis\sactive.\s\sDo\snot\sissue\san\serror,\ssince\sthat\smight\nbreak\slegacy\squeries.\s\sBut\signore\sthe\sredundant\sON\sCONFLICT\sclauses\sto\sprevent\nproblems\ssuch\sas\sdescribed\sin\s[forum:/forumpost/919c6579c8|forum\spost\s919c6579c8]. +D 2024-03-08T14:01:48.797 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -709,7 +709,7 @@ F src/hash.c 9ee4269fb1d6632a6fecfb9479c93a1f29271bddbbaf215dd60420bcb80c7220 F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 -F src/insert.c 3f0a94082d978bbdd33c38fefea15346c6c6bffb70bc645a71dc0f1f87dd3276 +F src/insert.c eb33ea46dcab93e90f112fced343aaf41f59cbd2e951d5066f1f9302be1c2f34 F src/json.c e2e40760d6689134c3e2ece38c6a496b34ff5e2661a8f238444a119af666fdce F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 @@ -755,7 +755,7 @@ F src/shell.c.in 78bbd861cd0128aed67c0136561572ebcf11649be6cea86bee8491576d5958d F src/sqlite.h.in 19a2db3995a699bd7f6dfb423856242bfceb7ec849a93c91d241d19fc28d9f0f F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 -F src/sqliteInt.h 58b7295a748ca5ed9e211510205b4a66a24c68f864225b81e19d4cf6038b40a1 +F src/sqliteInt.h 06d757ee6cd22f59593e51a7066327a0690a6cb66dad4f0077ee3297228f5401 F src/sqliteLimit.h 6878ab64bdeb8c24a1d762d45635e34b96da21132179023338c93f820eee6728 F src/status.c cb11f8589a6912af2da3bb1ec509a94dd8ef27df4d4c1a97e0bcf2309ece972b F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1 @@ -816,7 +816,7 @@ F src/tokenize.c 3f703cacdab728d7741e5a6ac242006d74fe1c2754d4f03ed889d7253259bd6 F src/treeview.c c6fc972683fd00f975d8b32a81c1f25d2fb7d4035366bf45c9f5622d3ccd70ee F src/trigger.c 0905b96b04bb6658509f711a8207287f1315cdbc3df1a1b13ba6483c8e341c81 F src/update.c 6904814dd62a7a93bbb86d9f1419c7f134a9119582645854ab02b36b676d9f92 -F src/upsert.c fa125a8d3410ce9a97b02cb50f7ae68a2476c405c76aa692d3acf6b8586e9242 +F src/upsert.c 2e60567a0e9e8520c18671b30712a88dc73534474304af94f32bb5f3ef65ac65 F src/utf.c f23165685a67b4caf8ec08fb274cb3f319103decfb2a980b7cfd55d18dfa855e F src/util.c f27a17e6e43fa362abea4db507a1c409f0adc8048ecf4c6479e8d162158ed529 F src/vacuum.c 604fcdaebe76f3497c855afcbf91b8fa5046b32de3045bab89cc008d68e40104 @@ -1907,7 +1907,7 @@ F test/upsert1.test a512e2f884d3a36159fce2e45108c236f78ae38e35bda55f4050db580ceb F test/upsert2.test 720e94d09f7362a282bc69b3c6b83d51daeaaf0440eb4920a08b86518b8c7496 F test/upsert3.test 88d7d590a1948a9cb6eac1b54b0642f67a9f35a1fc0f19b200e97d5d39e3179c F test/upsert4.test 25d2a1da92f149331ae0c51ca6e3eee78189577585eab92de149900d62994fa5 -F test/upsert5.test fff0dcfce73c649204543088d8e5bde01172676063ec9b8f8fc7f195abc386fe +F test/upsert5.test 9953b180d02d1369cdbb6c73c900834e5fef8cb78e98e07511c8762ec21cc176 F test/upsertfault.test f21ca47740841fdb4d61acfa7b17646d773e67724fe8c185b71c018db8a94b35 F test/uri.test c1abaaaa28e9422d61e5f3f9cbc8ef993ec49fe802f581520731708561d49384 F test/uri2.test 9d3ba7a53ee167572d53a298ee4a5d38ec4a8fb7 @@ -2177,8 +2177,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P a02551de4c2d7085569ee76f88bfef5da429e40137cc1d1349b4637f88259ad1 -R af066a0422542da1cc5e88fc5055710e -U dan -Z b2bec38f4a2e9b652e878f166176c721 +P 29d9eb7d55755604781e507f6ca36c50d62fa8d8589ab932d7cefca94ba24f3e +R 854945d64d6a5cfe38a3cc1c6a5b5bd3 +U drh +Z 3c2e932dfbe4dcd203c5f3b4ed97d851 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index d5fb64437e..492aebc3bd 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -29d9eb7d55755604781e507f6ca36c50d62fa8d8589ab932d7cefca94ba24f3e \ No newline at end of file +d0ea6b6ba64dba9d68c2b391ccf1171ea96fcdd7409dafdb2b697accb00246b8 \ No newline at end of file diff --git a/src/insert.c b/src/insert.c index 1c31ca2338..095298b90c 100644 --- a/src/insert.c +++ b/src/insert.c @@ -1086,7 +1086,7 @@ void sqlite3Insert( pNx->iDataCur = iDataCur; pNx->iIdxCur = iIdxCur; if( pNx->pUpsertTarget ){ - if( sqlite3UpsertAnalyzeTarget(pParse, pTabList, pNx) ){ + if( sqlite3UpsertAnalyzeTarget(pParse, pTabList, pNx, pUpsert) ){ goto insert_cleanup; } } diff --git a/src/sqliteInt.h b/src/sqliteInt.h index f5920748ba..91cf173040 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -3476,6 +3476,7 @@ struct Upsert { Expr *pUpsertWhere; /* WHERE clause for the ON CONFLICT UPDATE */ Upsert *pNextUpsert; /* Next ON CONFLICT clause in the list */ u8 isDoUpdate; /* True for DO UPDATE. False for DO NOTHING */ + u8 isDup; /* True if 2nd or later with same pUpsertIdx */ /* Above this point is the parse tree for the ON CONFLICT clauses. ** The next group of fields stores intermediate data. */ void *pToFree; /* Free memory when deleting the Upsert object */ @@ -5552,7 +5553,7 @@ const char *sqlite3JournalModename(int); Upsert *sqlite3UpsertNew(sqlite3*,ExprList*,Expr*,ExprList*,Expr*,Upsert*); void sqlite3UpsertDelete(sqlite3*,Upsert*); Upsert *sqlite3UpsertDup(sqlite3*,Upsert*); - int sqlite3UpsertAnalyzeTarget(Parse*,SrcList*,Upsert*); + int sqlite3UpsertAnalyzeTarget(Parse*,SrcList*,Upsert*,Upsert*); void sqlite3UpsertDoUpdate(Parse*,Upsert*,Table*,Index*,int); Upsert *sqlite3UpsertOfIndex(Upsert*,Index*); int sqlite3UpsertNextIsIPK(Upsert*); diff --git a/src/upsert.c b/src/upsert.c index be0d0550df..f74d4fabf5 100644 --- a/src/upsert.c +++ b/src/upsert.c @@ -90,7 +90,8 @@ Upsert *sqlite3UpsertNew( int sqlite3UpsertAnalyzeTarget( Parse *pParse, /* The parsing context */ SrcList *pTabList, /* Table into which we are inserting */ - Upsert *pUpsert /* The ON CONFLICT clauses */ + Upsert *pUpsert, /* The ON CONFLICT clauses */ + Upsert *pAll /* Complete list of all ON CONFLICT clauses */ ){ Table *pTab; /* That table into which we are inserting */ int rc; /* Result code */ @@ -193,6 +194,14 @@ int sqlite3UpsertAnalyzeTarget( continue; } pUpsert->pUpsertIdx = pIdx; + if( sqlite3UpsertOfIndex(pAll,pIdx)!=pUpsert ){ + /* Really this should be an error. The isDup ON CONFLICT clause will + ** never fire. But this problem was not discovered until three years + ** after multi-CONFLICT upsert was added, and so we silently ignore + ** the problem to prevent breaking applications that might actually + ** have redundant ON CONFLICT clauses. */ + pUpsert->isDup = 1; + } break; } if( pUpsert->pUpsertIdx==0 ){ @@ -219,9 +228,13 @@ int sqlite3UpsertNextIsIPK(Upsert *pUpsert){ Upsert *pNext; if( NEVER(pUpsert==0) ) return 0; pNext = pUpsert->pNextUpsert; - if( pNext==0 ) return 1; - if( pNext->pUpsertTarget==0 ) return 1; - if( pNext->pUpsertIdx==0 ) return 1; + while( 1 /*exit-by-return*/ ){ + if( pNext==0 ) return 1; + if( pNext->pUpsertTarget==0 ) return 1; + if( pNext->pUpsertIdx==0 ) return 1; + if( !pNext->isDup ) return 0; + pNext = pNext->pNextUpsert; + } return 0; } diff --git a/test/upsert5.test b/test/upsert5.test index 3161abf15e..e56e71d4b9 100644 --- a/test/upsert5.test +++ b/test/upsert5.test @@ -408,4 +408,46 @@ do_catchsql_test 2.1 { } {1 {no such table: nosuchtable}} +# 2024-03-08 https://sqlite.org/forum/forumpost/919c6579c8 +# A redundant ON CONFLICT clause in an upsert can lead to +# index corruption. +# +reset_db +do_execsql_test 3.0 { + CREATE TABLE t1(aa INTEGER PRIMARY KEY, bb INT); + INSERT INTO t1 VALUES(11,22); + CREATE UNIQUE INDEX t1bb ON t1(bb); + REPLACE INTO t1 VALUES(11,33) + ON CONFLICT(bb) DO UPDATE SET aa = 44 + ON CONFLICT(bb) DO UPDATE SET aa = 44; + PRAGMA integrity_check; +} {ok} +do_execsql_test 3.1 { + SELECT * FROM t1 NOT INDEXED; +} {11 33} +do_execsql_test 3.2 { + SELECT * FROM t1 INDEXED BY t1bb; +} {11 33} +do_execsql_test 3.3 { + DROP TABLE t1; + CREATE TABLE t1(aa INTEGER PRIMARY KEY, bb INT, cc INT); + INSERT INTO t1 VALUES(10,21,32),(11,22,33),(12,23,34); + CREATE UNIQUE INDEX t1bb ON t1(bb); + CREATE UNIQUE INDEX t1cc ON t1(cc); + REPLACE INTO t1 VALUES(11,44,55) + ON CONFLICT(bb) DO UPDATE SET aa = 99 + ON CONFLICT(cc) DO UPDATE SET aa = 99 + ON CONFLICT(bb) DO UPDATE SET aa = 99; + PRAGMA integrity_check; +} {ok} +do_execsql_test 3.4 { + SELECT * FROM t1 NOT INDEXED ORDER BY +aa; +} {10 21 32 11 44 55 12 23 34} +do_execsql_test 3.5 { + SELECT * FROM t1 INDEXED BY t1bb ORDER BY +aa; +} {10 21 32 11 44 55 12 23 34} +do_execsql_test 3.6 { + SELECT * FROM t1 INDEXED BY t1cc ORDER BY +aa; +} {10 21 32 11 44 55 12 23 34} + finish_test From 744e5672bff25eb4c83a568566c7168ff60d731e Mon Sep 17 00:00:00 2001 From: drh <> Date: Fri, 8 Mar 2024 15:39:59 +0000 Subject: [PATCH 190/430] Add new assert() statements, which if they had existed three years ago, would have detected the code generator problem fixed by the previous check-in. FossilOrigin-Name: 166d1e5d26ef88e995f44182144891f60bd51c1aa585b4a148f01a920b2a8eea --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/vdbe.c | 28 +++++++++++++++------------- src/vdbeaux.c | 8 ++++++++ tool/mkopcodeh.tcl | 9 ++++++++- 5 files changed, 40 insertions(+), 23 deletions(-) diff --git a/manifest b/manifest index e75a8d5b89..240d8fc2aa 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Silently\signore\sredundant\sON\sCONFLICT\sclauses\sin\san\sUPSERT.\s\sOnly\sthe\sfirst\nON\sCONFLICT\sfor\seach\sindex\sis\sactive.\s\sDo\snot\sissue\san\serror,\ssince\sthat\smight\nbreak\slegacy\squeries.\s\sBut\signore\sthe\sredundant\sON\sCONFLICT\sclauses\sto\sprevent\nproblems\ssuch\sas\sdescribed\sin\s[forum:/forumpost/919c6579c8|forum\spost\s919c6579c8]. -D 2024-03-08T14:01:48.797 +C Add\snew\sassert()\sstatements,\swhich\sif\sthey\shad\sexisted\sthree\syears\sago,\nwould\shave\sdetected\sthe\scode\sgenerator\sproblem\sfixed\sby\sthe\sprevious\scheck-in. +D 2024-03-08T15:39:59.999 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -820,11 +820,11 @@ F src/upsert.c 2e60567a0e9e8520c18671b30712a88dc73534474304af94f32bb5f3ef65ac65 F src/utf.c f23165685a67b4caf8ec08fb274cb3f319103decfb2a980b7cfd55d18dfa855e F src/util.c f27a17e6e43fa362abea4db507a1c409f0adc8048ecf4c6479e8d162158ed529 F src/vacuum.c 604fcdaebe76f3497c855afcbf91b8fa5046b32de3045bab89cc008d68e40104 -F src/vdbe.c 7a33c5bb37e12ce35ac2d1d56a6429288b0b56c940ba660265c1428c67883729 +F src/vdbe.c da8407be6055f5751bf85681542d130a320b4fd1f4d8719bf83a464743d9aae4 F src/vdbe.h c2d78d15112c3fc5ab87f5e8e0b75d2db1c624409de2e858c3d1aafb1650bb4f F src/vdbeInt.h 949669dfd8a41550d27dcb905b494f2ccde9a2e6c1b0b04daa1227e2e74c2b2c F src/vdbeapi.c 8f57d60c89da0b60e6d4e272358c511f6bae4e24330bdb11f8b42f986d1bf21b -F src/vdbeaux.c 66161ba75c4a2d86aab124fe3cbcc2a752d8e4b1fc8c1fc6e00625db4798168c +F src/vdbeaux.c e52815bc11fccedcc7acb14ae98c607a1c5b6c773ff4d584cd192432540502c9 F src/vdbeblob.c 13f9287b55b6356b4b1845410382d6bede203ceb29ef69388a4a3d007ffacbe5 F src/vdbemem.c 213bf303826c0ef702e3a2a69dab2309d84b8381b822c6787885859fd7cd4c4e F src/vdbesort.c 237840ca1947511fa59bd4e18b9eeae93f2af2468c34d2427b059f896230a547 @@ -2101,7 +2101,7 @@ F tool/mkctimec.tcl a16682eae5f01f85e5861b2aa215ca0d46b4230658ee25977e02b4508566 F tool/mkkeywordhash.c b9faa0ae7e14e4dbbcd951cddd786bf46b8a65bb07b129ba8c0cfade723aaffd F tool/mkmsvcmin.tcl 8897d515ef7f94772322db95a3b6fce6c614d84fe0bdd06ba5a1c786351d5a1d F tool/mkopcodec.tcl 33d20791e191df43209b77d37f0ff0904620b28465cca6990cf8d60da61a07ef -F tool/mkopcodeh.tcl 769d9e6a8b462323150dc13a8539d6064664b72974f7894befe2491cc73e05cd +F tool/mkopcodeh.tcl 2b4e6967a670ef21bf53a164964c35c6163277d002a4c6f56fa231d68c88d023 F tool/mkopts.tcl 680f785fdb09729fd9ac50632413da4eadbdf9071535e3f26d03795828ab07fa F tool/mkpragmatab.tcl 32e359ccb21011958a821955254bd7a5fa7915d01a8c16fed91ffc8b40cb4adf F tool/mkshellc.tcl b7adf08b82de60811d2cb6af05ff59fc17e5cd6f3e98743c14eaaa3f8971fed0 @@ -2177,8 +2177,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 29d9eb7d55755604781e507f6ca36c50d62fa8d8589ab932d7cefca94ba24f3e -R 854945d64d6a5cfe38a3cc1c6a5b5bd3 +P d0ea6b6ba64dba9d68c2b391ccf1171ea96fcdd7409dafdb2b697accb00246b8 +R e2ddfd9aa39901e567d105504257c018 U drh -Z 3c2e932dfbe4dcd203c5f3b4ed97d851 +Z 9df6c164111bd68c49bf51ae68acbbe9 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 492aebc3bd..249f75b766 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d0ea6b6ba64dba9d68c2b391ccf1171ea96fcdd7409dafdb2b697accb00246b8 \ No newline at end of file +166d1e5d26ef88e995f44182144891f60bd51c1aa585b4a148f01a920b2a8eea \ No newline at end of file diff --git a/src/vdbe.c b/src/vdbe.c index 709ebd9fb8..faa12aaf8d 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -1129,7 +1129,7 @@ case OP_Return: { /* in1 */ ** ** See also: EndCoroutine */ -case OP_InitCoroutine: { /* jump */ +case OP_InitCoroutine: { /* jump0 */ assert( pOp->p1>0 && pOp->p1<=(p->nMem+1 - p->nCursor) ); assert( pOp->p2>=0 && pOp->p2nOp ); assert( pOp->p3>=0 && pOp->p3nOp ); @@ -1182,7 +1182,7 @@ case OP_EndCoroutine: { /* in1 */ ** ** See also: InitCoroutine */ -case OP_Yield: { /* in1, jump */ +case OP_Yield: { /* in1, jump0 */ int pcDest; pIn1 = &aMem[pOp->p1]; assert( VdbeMemDynamic(pIn1)==0 ); @@ -2041,7 +2041,7 @@ case OP_AddImm: { /* in1 */ ** without data loss, then jump immediately to P2, or if P2==0 ** raise an SQLITE_MISMATCH exception. */ -case OP_MustBeInt: { /* jump, in1 */ +case OP_MustBeInt: { /* jump0, in1 */ pIn1 = &aMem[pOp->p1]; if( (pIn1->flags & MEM_Int)==0 ){ applyAffinity(pIn1, SQLITE_AFF_NUMERIC, encoding); @@ -4725,10 +4725,10 @@ case OP_ColumnsUsed: { ** ** See also: Found, NotFound, SeekGt, SeekGe, SeekLt */ -case OP_SeekLT: /* jump, in3, group, ncycle */ -case OP_SeekLE: /* jump, in3, group, ncycle */ -case OP_SeekGE: /* jump, in3, group, ncycle */ -case OP_SeekGT: { /* jump, in3, group, ncycle */ +case OP_SeekLT: /* jump0, in3, group, ncycle */ +case OP_SeekLE: /* jump0, in3, group, ncycle */ +case OP_SeekGE: /* jump0, in3, group, ncycle */ +case OP_SeekGT: { /* jump0, in3, group, ncycle */ int res; /* Comparison result */ int oc; /* Opcode */ VdbeCursor *pC; /* The cursor to seek */ @@ -5395,7 +5395,7 @@ case OP_Found: { /* jump, in3, ncycle */ ** ** See also: Found, NotFound, NoConflict, SeekRowid */ -case OP_SeekRowid: { /* jump, in3, ncycle */ +case OP_SeekRowid: { /* jump0, in3, ncycle */ VdbeCursor *pC; BtCursor *pCrsr; int res; @@ -6154,7 +6154,7 @@ case OP_NullRow: { ** configured to use Prev, not Next. */ case OP_SeekEnd: /* ncycle */ -case OP_Last: { /* jump, ncycle */ +case OP_Last: { /* jump0, ncycle */ VdbeCursor *pC; BtCursor *pCrsr; int res; @@ -6271,7 +6271,7 @@ case OP_Sort: { /* jump ncycle */ ** from the beginning toward the end. In other words, the cursor is ** configured to use Next, not Prev. */ -case OP_Rewind: { /* jump, ncycle */ +case OP_Rewind: { /* jump0, ncycle */ VdbeCursor *pC; BtCursor *pCrsr; int res; @@ -7279,7 +7279,9 @@ case OP_RowSetTest: { /* jump, in1, in3 */ ** P1 contains the address of the memory cell that contains the first memory ** cell in an array of values used as arguments to the sub-program. P2 ** contains the address to jump to if the sub-program throws an IGNORE -** exception using the RAISE() function. Register P3 contains the address +** exception using the RAISE() function. P2 might be zero, if there is +** no possibility that an IGNORE exception will be raised. +** Register P3 contains the address ** of a memory cell in this (the parent) VM that is used to allocate the ** memory required by the sub-vdbe at runtime. ** @@ -7287,7 +7289,7 @@ case OP_RowSetTest: { /* jump, in1, in3 */ ** ** If P5 is non-zero, then recursive program invocation is enabled. */ -case OP_Program: { /* jump */ +case OP_Program: { /* jump0 */ int nMem; /* Number of memory registers for sub-program */ int nByte; /* Bytes of runtime space required for sub-program */ Mem *pRt; /* Register to allocate runtime space */ @@ -8836,7 +8838,7 @@ case OP_Filter: { /* jump */ ** error is encountered. */ case OP_Trace: -case OP_Init: { /* jump */ +case OP_Init: { /* jump0 */ int i; #ifndef SQLITE_OMIT_TRACE char *zTrace; diff --git a/src/vdbeaux.c b/src/vdbeaux.c index 209d02a049..6519bc9651 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -939,6 +939,14 @@ static void resolveP2Values(Vdbe *p, int *pMaxFuncArgs){ assert( aLabel!=0 ); /* True because of tag-20230419-1 */ pOp->p2 = aLabel[ADDR(pOp->p2)]; } + + /* OPFLG_JUMP opcodes never have P2==0, though OPFLG_JUMP0 opcodes + ** might */ + assert( pOp->p2>0 + || (sqlite3OpcodeProperty[pOp->opcode] & OPFLG_JUMP0)!=0 ); + + /* Jumps never go off the end of the bytecode array */ + assert( pOp->p2nOp ); break; } } diff --git a/tool/mkopcodeh.tcl b/tool/mkopcodeh.tcl index 6fb3b75940..18fe1a2658 100644 --- a/tool/mkopcodeh.tcl +++ b/tool/mkopcodeh.tcl @@ -81,6 +81,7 @@ while {![eof $in]} { set op($name) -1 set group($name) 0 set jump($name) 0 + set jump0($name) 0 set in1($name) 0 set in2($name) 0 set in3($name) 0 @@ -109,6 +110,7 @@ while {![eof $in]} { out2 {set out2($name) 1} out3 {set out3($name) 1} ncycle {set ncycle($name) 1} + jump0 {set jump($name) 1; set jump0($name) 1;} } } if {$group($name)} { @@ -137,6 +139,7 @@ puts "/* Automatically generated. Do not edit */" puts "/* See the tool/mkopcodeh.tcl script for details */" foreach name {OP_Noop OP_Explain OP_Abortable} { set jump($name) 0 + set jump0($name) 0 set in1($name) 0 set in2($name) 0 set in3($name) 0 @@ -256,7 +259,9 @@ for {set i 0} {$i<=$max} {incr i} { set name $def($i) puts -nonewline [format {#define %-16s %3d} $name $i] set com {} - if {[info exists jump($name)] && $jump($name)} { + if {[info exists jump0($name)] && $jump0($name)} { + lappend com "jump0" + } elseif {[info exists jump($name)] && $jump($name)} { lappend com "jump" } if {[info exists sameas($i)]} { @@ -289,6 +294,7 @@ for {set i 0} {$i<=$max} {incr i} { if {$out2($name)} {incr x 16} if {$out3($name)} {incr x 32} if {$ncycle($name)} {incr x 64} + if {$jump0($name)} {incr x 128} } set bv($i) $x } @@ -304,6 +310,7 @@ puts "#define OPFLG_IN3 0x08 /* in3: P3 is an input */" puts "#define OPFLG_OUT2 0x10 /* out2: P2 is an output */" puts "#define OPFLG_OUT3 0x20 /* out3: P3 is an output */" puts "#define OPFLG_NCYCLE 0x40 /* ncycle:Cycles count against P1 */" +puts "#define OPFLG_JUMP0 0x80 /* jump0: P2 might be zero */" puts "#define OPFLG_INITIALIZER \173\\" for {set i 0} {$i<=$max} {incr i} { if {$i%8==0} { From 96f5ae6bd74a43f0ada92bdc40d3b23257116291 Mon Sep 17 00:00:00 2001 From: drh <> Date: Fri, 8 Mar 2024 19:03:30 +0000 Subject: [PATCH 191/430] One of the assert()s added by the previous check-in was not quite correct. This commit fixes it. FossilOrigin-Name: d401358329f5a70f9a0b9b033609a4db2af89b83c6b40242be0c76f3d6474def --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/vdbeaux.c | 3 ++- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 240d8fc2aa..fcee6b38c4 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\snew\sassert()\sstatements,\swhich\sif\sthey\shad\sexisted\sthree\syears\sago,\nwould\shave\sdetected\sthe\scode\sgenerator\sproblem\sfixed\sby\sthe\sprevious\scheck-in. -D 2024-03-08T15:39:59.999 +C One\sof\sthe\sassert()s\sadded\sby\sthe\sprevious\scheck-in\swas\snot\squite\scorrect.\nThis\scommit\sfixes\sit. +D 2024-03-08T19:03:30.426 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -824,7 +824,7 @@ F src/vdbe.c da8407be6055f5751bf85681542d130a320b4fd1f4d8719bf83a464743d9aae4 F src/vdbe.h c2d78d15112c3fc5ab87f5e8e0b75d2db1c624409de2e858c3d1aafb1650bb4f F src/vdbeInt.h 949669dfd8a41550d27dcb905b494f2ccde9a2e6c1b0b04daa1227e2e74c2b2c F src/vdbeapi.c 8f57d60c89da0b60e6d4e272358c511f6bae4e24330bdb11f8b42f986d1bf21b -F src/vdbeaux.c e52815bc11fccedcc7acb14ae98c607a1c5b6c773ff4d584cd192432540502c9 +F src/vdbeaux.c 6385727adf51a649e4993098870a62c3945fe21dbc0e0fd9013772aff930b8fb F src/vdbeblob.c 13f9287b55b6356b4b1845410382d6bede203ceb29ef69388a4a3d007ffacbe5 F src/vdbemem.c 213bf303826c0ef702e3a2a69dab2309d84b8381b822c6787885859fd7cd4c4e F src/vdbesort.c 237840ca1947511fa59bd4e18b9eeae93f2af2468c34d2427b059f896230a547 @@ -2177,8 +2177,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P d0ea6b6ba64dba9d68c2b391ccf1171ea96fcdd7409dafdb2b697accb00246b8 -R e2ddfd9aa39901e567d105504257c018 +P 166d1e5d26ef88e995f44182144891f60bd51c1aa585b4a148f01a920b2a8eea +R a10b9cfdedf65df80cd98f59556bbeca U drh -Z 9df6c164111bd68c49bf51ae68acbbe9 +Z 203e497a1090dbea6a05556e060a1144 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 249f75b766..a61603c541 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -166d1e5d26ef88e995f44182144891f60bd51c1aa585b4a148f01a920b2a8eea \ No newline at end of file +d401358329f5a70f9a0b9b033609a4db2af89b83c6b40242be0c76f3d6474def \ No newline at end of file diff --git a/src/vdbeaux.c b/src/vdbeaux.c index 6519bc9651..e5c8303435 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -946,7 +946,8 @@ static void resolveP2Values(Vdbe *p, int *pMaxFuncArgs){ || (sqlite3OpcodeProperty[pOp->opcode] & OPFLG_JUMP0)!=0 ); /* Jumps never go off the end of the bytecode array */ - assert( pOp->p2nOp ); + assert( pOp->p2nOp + || (sqlite3OpcodeProperty[pOp->opcode] & OPFLG_JUMP)==0 ); break; } } From 61b77a6fe14d271c89b0c392898b83dc05c658e5 Mon Sep 17 00:00:00 2001 From: drh <> Date: Fri, 8 Mar 2024 21:37:18 +0000 Subject: [PATCH 192/430] The NOT NULL strength reduction optimization from [de9c86c9e4cdb34f] should be applied to the WHERE clause only. Otherwise, the operand of the IS NULL or IS NOT NULL operator might be a reference to a bare column of an aggregate table, and we can't tell if it is NULL or not based only on its NOT NULL attribute. [forum:/forumpost/440f2a2f17|Forum post 440f2a2f17]. FossilOrigin-Name: 51704feae224eff601db5607f8651da11b3c2ed8a58ffe5b6ee8260cab50695b --- manifest | 16 +++++++------- manifest.uuid | 2 +- src/resolve.c | 52 +++++++++++++++++++++++++++++++++++++--------- src/sqliteInt.h | 2 ++ test/notnull2.test | 16 ++++++++++---- 5 files changed, 65 insertions(+), 23 deletions(-) diff --git a/manifest b/manifest index fcee6b38c4..c35db0c838 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C One\sof\sthe\sassert()s\sadded\sby\sthe\sprevious\scheck-in\swas\snot\squite\scorrect.\nThis\scommit\sfixes\sit. -D 2024-03-08T19:03:30.426 +C The\sNOT\sNULL\sstrength\sreduction\soptimization\sfrom\s[de9c86c9e4cdb34f]\sshould\nbe\sapplied\sto\sthe\sWHERE\sclause\sonly.\s\sOtherwise,\sthe\soperand\sof\sthe\sIS\sNULL\nor\sIS\sNOT\sNULL\soperator\smight\sbe\sa\sreference\sto\sa\sbare\scolumn\sof\san\naggregate\stable,\sand\swe\scan't\stell\sif\sit\sis\sNULL\sor\snot\sbased\sonly\son\sits\nNOT\sNULL\sattribute.\s\s[forum:/forumpost/440f2a2f17|Forum\spost\s440f2a2f17]. +D 2024-03-08T21:37:18.921 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -748,14 +748,14 @@ F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7 F src/prepare.c 371f6115cb69286ebc12c6f2d7511279c2e47d9f54f475d46a554d687a3b312c F src/printf.c 10e8bad30042f8bd6114a013b4afc229ec8ad255ab27518d7d9f52e8cbc5cd0a F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c -F src/resolve.c d77c6160bc8f249c2196fdd3e75f66a1dd70e37aa25c39aedc7b1f93c42b7c6d +F src/resolve.c ef87e3bc7700bfe761a7bbee2ce6084f1766dc816dd82a3ae77c133eec898432 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c 43fabfc01bf87addd15e39f112f1e2ade15b19594835ab8a9e5bd50839d4e1b1 F src/shell.c.in 78bbd861cd0128aed67c0136561572ebcf11649be6cea86bee8491576d5958d0 F src/sqlite.h.in 19a2db3995a699bd7f6dfb423856242bfceb7ec849a93c91d241d19fc28d9f0f F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 -F src/sqliteInt.h 06d757ee6cd22f59593e51a7066327a0690a6cb66dad4f0077ee3297228f5401 +F src/sqliteInt.h 6123ce6ca6a1ef351c3b87189e92c92042728f16c088de56b9b5bc2552d0ae33 F src/sqliteLimit.h 6878ab64bdeb8c24a1d762d45635e34b96da21132179023338c93f820eee6728 F src/status.c cb11f8589a6912af2da3bb1ec509a94dd8ef27df4d4c1a97e0bcf2309ece972b F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1 @@ -1455,7 +1455,7 @@ F test/notify1.test 669b2b743618efdc18ca4b02f45423d5d2304abf F test/notify2.test 2ecabaa1305083856b7c39cf32816b612740c161 F test/notify3.test 796c7b7157f55c93b4e672b724e9c923a6fc6aa72ac419379a623e2350472e22 F test/notnull.test a37b663d5bb728d66fc182016613fb8e4a0a4bbf3d75b8876a7527f7d4ed3f18 -F test/notnull2.test 1ee4acbd614d3cf5f1c4a52f5af7fc771b82352f1a51a86afeaa02c9df1d82ef +F test/notnull2.test 2ac7b4e04917148c7a1a9ed36df20150175ce942f07f5714375b29acbaca7106 F test/notnullfault.test fc4bb7845582a2b3db376001ef49118393b1b11abe0d24adb03db057ee2b73d5 F test/null.test b7ff206a1c60fe01aa2abd33ef9ea83c93727d993ca8a613de86e925c9f2bc6f F test/nulls1.test 7a5e4346ee4285034100b4cd20e6784f16a9d6c927e44ecdf10034086bbee9c9 @@ -2177,8 +2177,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 166d1e5d26ef88e995f44182144891f60bd51c1aa585b4a148f01a920b2a8eea -R a10b9cfdedf65df80cd98f59556bbeca +P d401358329f5a70f9a0b9b033609a4db2af89b83c6b40242be0c76f3d6474def +R 05ce52a0a931825416b225aa397af1ac U drh -Z 203e497a1090dbea6a05556e060a1144 +Z ce9603354c09773b286e10e1291765af # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index a61603c541..8202619d3e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d401358329f5a70f9a0b9b033609a4db2af89b83c6b40242be0c76f3d6474def \ No newline at end of file +51704feae224eff601db5607f8651da11b3c2ed8a58ffe5b6ee8260cab50695b \ No newline at end of file diff --git a/src/resolve.c b/src/resolve.c index 5d0801e82e..c2957a870a 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -971,6 +971,19 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){ ** resolved. This prevents "column" from being counted as having been ** referenced, which might prevent a SELECT from being erroneously ** marked as correlated. + ** + ** 2024-03-28: Beware of aggregates. A bare column of aggregated table + ** can still evaluate to NULL even though it is marked as NOT NULL. + ** Example: + ** + ** CREATE TABLE t1(a INT NOT NULL); + ** SELECT a, a IS NULL, a IS NOT NULL, count(*) FROM t1; + ** + ** The "a IS NULL" and "a IS NOT NULL" expressions cannot be optimized + ** here because at the time this case is hit, we do not yet know whether + ** or not t1 is being aggregated. We have to assume the worst and omit + ** the optimization. The only time it is safe to apply this optimization + ** is within the WHERE clause. */ case TK_NOTNULL: case TK_ISNULL: { @@ -981,19 +994,36 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){ anRef[i] = p->nRef; } sqlite3WalkExpr(pWalker, pExpr->pLeft); - if( 0==sqlite3ExprCanBeNull(pExpr->pLeft) && !IN_RENAME_OBJECT ){ - testcase( ExprHasProperty(pExpr, EP_OuterON) ); - assert( !ExprHasProperty(pExpr, EP_IntValue) ); - pExpr->u.iValue = (pExpr->op==TK_NOTNULL); - pExpr->flags |= EP_IntValue; - pExpr->op = TK_INTEGER; + if( IN_RENAME_OBJECT ) return WRC_Prune; + if( sqlite3ExprCanBeNull(pExpr->pLeft) ){ + /* The expression can be NULL. So the optimization does not apply */ + return WRC_Prune; + } - for(i=0, p=pNC; p && ipNext, i++){ - p->nRef = anRef[i]; + for(i=0, p=pNC; p; p=p->pNext, i++){ + if( (p->ncFlags & NC_Where)==0 ){ + return WRC_Prune; /* Not in a WHERE clause. Unsafe to optimize. */ } - sqlite3ExprDelete(pParse->db, pExpr->pLeft); - pExpr->pLeft = 0; } + testcase( ExprHasProperty(pExpr, EP_OuterON) ); + assert( !ExprHasProperty(pExpr, EP_IntValue) ); +#if TREETRACE_ENABLED + if( sqlite3TreeTrace & 0x80000 ){ + sqlite3DebugPrintf( + "NOT NULL strength reduction converts the following to %d:\n", + pExpr->op==TK_NOTNULL + ); + sqlite3ShowExpr(pExpr); + } +#endif /* TREETRACE_ENABLED */ + pExpr->u.iValue = (pExpr->op==TK_NOTNULL); + pExpr->flags |= EP_IntValue; + pExpr->op = TK_INTEGER; + for(i=0, p=pNC; p && ipNext, i++){ + p->nRef = anRef[i]; + } + sqlite3ExprDelete(pParse->db, pExpr->pLeft); + pExpr->pLeft = 0; return WRC_Prune; } @@ -1891,7 +1921,9 @@ static int resolveSelectStep(Walker *pWalker, Select *p){ } if( sqlite3ResolveExprNames(&sNC, p->pHaving) ) return WRC_Abort; } + sNC.ncFlags |= NC_Where; if( sqlite3ResolveExprNames(&sNC, p->pWhere) ) return WRC_Abort; + sNC.ncFlags &= ~NC_Where; /* Resolve names in table-valued-function arguments */ for(i=0; ipSrc->nSrc; i++){ diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 91cf173040..e11b5b3a4e 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -1125,6 +1125,7 @@ extern u32 sqlite3TreeTrace; ** 0x00010000 Beginning of DELETE/INSERT/UPDATE processing ** 0x00020000 Transform DISTINCT into GROUP BY ** 0x00040000 SELECT tree dump after all code has been generated +** 0x00080000 NOT NULL strength reduction */ /* @@ -3453,6 +3454,7 @@ struct NameContext { #define NC_InAggFunc 0x020000 /* True if analyzing arguments to an agg func */ #define NC_FromDDL 0x040000 /* SQL text comes from sqlite_schema */ #define NC_NoSelect 0x080000 /* Do not descend into sub-selects */ +#define NC_Where 0x100000 /* Processing WHERE clause of a SELECT */ #define NC_OrderAgg 0x8000000 /* Has an aggregate other than count/min/max */ /* diff --git a/test/notnull2.test b/test/notnull2.test index 7f68086810..09161efbdb 100644 --- a/test/notnull2.test +++ b/test/notnull2.test @@ -59,14 +59,14 @@ do_vmstep_test 1.4.2 { do_vmstep_test 1.5.1 { SELECT count(*) FROM t2 WHERE EXISTS( - SELECT t2.d IS NULL FROM t1 WHERE t1.a=450 + SELECT 1 FROM t1 WHERE t1.a=450 AND t2.d IS NULL ) -} 10000 {1000} +} 7000 {0} do_vmstep_test 1.5.2 { SELECT count(*) FROM t2 WHERE EXISTS( - SELECT t2.c IS NULL FROM t1 WHERE t1.a=450 + SELECT 1 FROM t1 WHERE t1.a=450 AND t2.c IS NULL ) -} +100000 {1000} +} +8000 {0} #------------------------------------------------------------------------- reset_db @@ -111,4 +111,12 @@ do_execsql_test 4.1 { SELECT * FROM (SELECT 3 AS c FROM t1) AS t3 LEFT JOIN t2 ON c IS NULL; } {3 {}} +# 2024-03-08 https://sqlite.org/forum/forumpost/440f2a2f17 +# +reset_db +do_execsql_test 5.0 { + CREATE TABLE t1(a INT NOT NULL); + SELECT a IS NULL, a IS NOT NULL, count(*) FROM t1; +} {1 0 0} + finish_test From aa13f4c132ced1fda8d0d436b72c9c0b58ab16e2 Mon Sep 17 00:00:00 2001 From: drh <> Date: Sat, 9 Mar 2024 13:31:10 +0000 Subject: [PATCH 193/430] Fuzzcheck is run automatically by testrunner.tcl, so there is no need to include fuzzcheck as a separate dependency for the releasetest target in the MSVC makefile. FossilOrigin-Name: 76629b2bff01df3d42eef2e93d626c291a2f129bd923498941465e5bca74e9f1 --- Makefile.msc | 2 +- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Makefile.msc b/Makefile.msc index 2f67600c31..31a9c57ebc 100644 --- a/Makefile.msc +++ b/Makefile.msc @@ -2553,7 +2553,7 @@ mdevtest: # Testing for a release # -releasetest: testfixture.exe fuzztest +releasetest: testfixture.exe testfixture.exe $(TOP)\test\testrunner.tcl release diff --git a/manifest b/manifest index c35db0c838..17eafff732 100644 --- a/manifest +++ b/manifest @@ -1,11 +1,11 @@ -C The\sNOT\sNULL\sstrength\sreduction\soptimization\sfrom\s[de9c86c9e4cdb34f]\sshould\nbe\sapplied\sto\sthe\sWHERE\sclause\sonly.\s\sOtherwise,\sthe\soperand\sof\sthe\sIS\sNULL\nor\sIS\sNOT\sNULL\soperator\smight\sbe\sa\sreference\sto\sa\sbare\scolumn\sof\san\naggregate\stable,\sand\swe\scan't\stell\sif\sit\sis\sNULL\sor\snot\sbased\sonly\son\sits\nNOT\sNULL\sattribute.\s\s[forum:/forumpost/440f2a2f17|Forum\spost\s440f2a2f17]. -D 2024-03-08T21:37:18.921 +C Fuzzcheck\sis\srun\sautomatically\sby\stestrunner.tcl,\sso\sthere\sis\sno\sneed\sto\ninclude\sfuzzcheck\sas\sa\sseparate\sdependency\sfor\sthe\sreleasetest\starget\sin\nthe\sMSVC\smakefile. +D 2024-03-09T13:31:10.052 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 F Makefile.in ca8b906b1c3285fc32cff9978a5b827f99ae3d440077babf32c257a92a2ba11c F Makefile.linux-gcc f3842a0b1efbfbb74ac0ef60e56b301836d05b4d867d014f714fa750048f1ab6 -F Makefile.msc 72c8436ee7528cb78f7318230548aab145ef05d15a8feed0f3cb251a26384403 +F Makefile.msc 7d88d6a654d86e6a1bede090f67d633d0a57c73e591d772fce8e15bfb07147f8 F README.md 6358805260a03ebead84e168bbf3740ddf3f683b477e478567186aa7afb490d3 F VERSION c84541c6a9e8426462176fbb1f9ecb5cfd7d1bb56228053ff7eeba8841673eb6 F aclocal.m4 a5c22d164aff7ed549d53a90fa56d56955281f50 @@ -2177,8 +2177,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P d401358329f5a70f9a0b9b033609a4db2af89b83c6b40242be0c76f3d6474def -R 05ce52a0a931825416b225aa397af1ac +P 51704feae224eff601db5607f8651da11b3c2ed8a58ffe5b6ee8260cab50695b +R 66041f681c588cd6eeb93d190f070a45 U drh -Z ce9603354c09773b286e10e1291765af +Z a7ed925f686a031dca2d1e814c8b92d8 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 8202619d3e..0f2473c5c0 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -51704feae224eff601db5607f8651da11b3c2ed8a58ffe5b6ee8260cab50695b \ No newline at end of file +76629b2bff01df3d42eef2e93d626c291a2f129bd923498941465e5bca74e9f1 \ No newline at end of file From 5007833f5f82d33c95f44c65fc46221de1c5950f Mon Sep 17 00:00:00 2001 From: drh <> Date: Sat, 9 Mar 2024 18:41:40 +0000 Subject: [PATCH 194/430] Fix the .expert command in the shell so that it does not leak memory if not followed by SQL and so that it works with reverse_unordered_selects. FossilOrigin-Name: 7ead022edaf7a0cd6a8976a1261246084975c9a5be5c893f6c751bb5f963ac0f --- ext/expert/sqlite3expert.c | 2 +- manifest | 14 +++++++------- manifest.uuid | 2 +- src/shell.c.in | 5 +++++ 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/ext/expert/sqlite3expert.c b/ext/expert/sqlite3expert.c index 33d62226f0..276c2cc9fe 100644 --- a/ext/expert/sqlite3expert.c +++ b/ext/expert/sqlite3expert.c @@ -1948,7 +1948,7 @@ sqlite3expert *sqlite3_expert_new(sqlite3 *db, char **pzErrmsg){ sqlite3_stmt *pSql = 0; rc = idxPrintfPrepareStmt(pNew->db, &pSql, pzErrmsg, "SELECT sql FROM sqlite_schema WHERE name NOT LIKE 'sqlite_%%'" - " AND sql NOT LIKE 'CREATE VIRTUAL %%'" + " AND sql NOT LIKE 'CREATE VIRTUAL %%' ORDER BY rowid" ); while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSql) ){ const char *zSql = (const char*)sqlite3_column_text(pSql, 0); diff --git a/manifest b/manifest index 17eafff732..8e74d529af 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fuzzcheck\sis\srun\sautomatically\sby\stestrunner.tcl,\sso\sthere\sis\sno\sneed\sto\ninclude\sfuzzcheck\sas\sa\sseparate\sdependency\sfor\sthe\sreleasetest\starget\sin\nthe\sMSVC\smakefile. -D 2024-03-09T13:31:10.052 +C Fix\sthe\s.expert\scommand\sin\sthe\sshell\sso\sthat\sit\sdoes\snot\sleak\smemory\sif\snot\nfollowed\sby\sSQL\sand\sso\sthat\sit\sworks\swith\sreverse_unordered_selects. +D 2024-03-09T18:41:40.779 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -58,7 +58,7 @@ F ext/consio/console_io.h 0548b83d7c4b7270ad544a67f2bb90cebc519637fa39b1838df474 F ext/expert/README.md b321c2762bb93c18ea102d5a5f7753a4b8bac646cb392b3b437f633caf2020c3 F ext/expert/expert.c d548d603a4cc9e61f446cc179c120c6713511c413f82a4a32b1e1e69d3f086a4 F ext/expert/expert1.test 0dd5cb096d66bed593e33053a3b364f6ef52ed72064bf5cf298364636dbf3cd6 -F ext/expert/sqlite3expert.c 90446bb1183429308c68ceb23e00cb8252f43b8886cf5efa3fc7e833b5fa24c8 +F ext/expert/sqlite3expert.c c8cea5ff15fbe792cccc4992a9b40b706411c41d32611f617897fecac6ff06a4 F ext/expert/sqlite3expert.h ca81efc2679a92373a13a3e76a6138d0310e32be53d6c3bfaedabd158ea8969b F ext/expert/test_expert.c d56c194b769bdc90cf829a14c9ecbc1edca9c850b837a4d0b13be14095c32a72 F ext/fts3/README.content b9078d0843a094d86af0d48dffbff13c906702b4c3558012e67b9c7cc3bf59ee @@ -751,7 +751,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c ef87e3bc7700bfe761a7bbee2ce6084f1766dc816dd82a3ae77c133eec898432 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c 43fabfc01bf87addd15e39f112f1e2ade15b19594835ab8a9e5bd50839d4e1b1 -F src/shell.c.in 78bbd861cd0128aed67c0136561572ebcf11649be6cea86bee8491576d5958d0 +F src/shell.c.in 74a51fcae1bd945bcc818b6273a901f204410f4e8d2648221352a486ba2fe5ea F src/sqlite.h.in 19a2db3995a699bd7f6dfb423856242bfceb7ec849a93c91d241d19fc28d9f0f F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 @@ -2177,8 +2177,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 51704feae224eff601db5607f8651da11b3c2ed8a58ffe5b6ee8260cab50695b -R 66041f681c588cd6eeb93d190f070a45 +P 76629b2bff01df3d42eef2e93d626c291a2f129bd923498941465e5bca74e9f1 +R d4c5b88cb6e2dcca46b9c5560f050fe6 U drh -Z a7ed925f686a031dca2d1e814c8b92d8 +Z b901e762e961c86b4b7445204eab052b # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 0f2473c5c0..bb9cddfbd6 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -76629b2bff01df3d42eef2e93d626c291a2f129bd923498941465e5bca74e9f1 \ No newline at end of file +7ead022edaf7a0cd6a8976a1261246084975c9a5be5c893f6c751bb5f963ac0f \ No newline at end of file diff --git a/src/shell.c.in b/src/shell.c.in index 1d7f8df450..73161cf646 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -12772,6 +12772,11 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){ #ifndef SQLITE_SHELL_FIDDLE /* In WASM mode we have to leave the db state in place so that ** client code can "push" SQL into it after this call returns. */ +#ifndef SQLITE_OMIT_VIRTUALTABLE + if( data.expert.pExpert ){ + expertFinish(&data, 1, 0); + } +#endif free(azCmd); set_table_name(&data, 0); if( data.db ){ From bf030d53b14bc38fbdc745636ef8dffdd57a1fa0 Mon Sep 17 00:00:00 2001 From: stephan Date: Mon, 11 Mar 2024 09:32:38 +0000 Subject: [PATCH 195/430] Add delete-before-open=1 URI flag to the 'opfs' VFS to tell it to xDelete the db file before opening it, primarily to enable users to work around a corrupt db without having to reach into OPFS-specific APIs to remove the db file. FossilOrigin-Name: e83f9788636f7f9bcca7d2a09620c13ab4eb83436d5b2946a827e48addf0267d --- ext/wasm/api/sqlite3-opfs-async-proxy.js | 11 ++++++++ ext/wasm/api/sqlite3-vfs-opfs.c-pp.js | 18 ++++++++++-- ext/wasm/tester1.c-pp.js | 36 ++++++++++++++---------- manifest | 21 ++++++++------ manifest.uuid | 2 +- 5 files changed, 60 insertions(+), 28 deletions(-) diff --git a/ext/wasm/api/sqlite3-opfs-async-proxy.js b/ext/wasm/api/sqlite3-opfs-async-proxy.js index cafd296c61..58b8bcb233 100644 --- a/ext/wasm/api/sqlite3-opfs-async-proxy.js +++ b/ext/wasm/api/sqlite3-opfs-async-proxy.js @@ -562,6 +562,17 @@ const installAsyncProxy = function(self){ wTimeEnd(); return; } + if( state.opfsFlags.OPFS_UNLINK_BEFORE_OPEN & opfsFlags ){ + //log("async proxy opfsFlags =",opfsFlags); + try{ + await hDir.removeEntry(filenamePart); + //log("Unlinked",filename,hDir,filenamePart); + } + catch(e){ + /* ignoring */ + //warn("Ignoring failed Unlink of",filename,":",e); + } + } const hFile = await hDir.getFileHandle(filenamePart, {create}); wTimeEnd(); const fh = Object.assign(Object.create(null),{ diff --git a/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js b/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js index f7fd951a40..65e39e5b5e 100644 --- a/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js +++ b/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js @@ -423,10 +423,18 @@ const installOpfsVfs = function callee(options){ }); state.opfsFlags = Object.assign(Object.create(null),{ /** - Flag for use with xOpen(). "opfs-unlock-asap=1" enables - this. See defaultUnlockAsap, below. + Flag for use with xOpen(). URI flag "opfs-unlock-asap=1" + enables this. See defaultUnlockAsap, below. */ OPFS_UNLOCK_ASAP: 0x01, + /** + Flag for use with xOpen(). URI flag "delete-before-open=1" + tells the VFS to delete the db file before attempting to open + it. This can be used, e.g., to replace a db which has been + corrupted (without forcing us to expose a delete/unlink() + function in the public API). + */ + OPFS_UNLINK_BEFORE_OPEN: 0x02, /** If true, any async routine which implicitly acquires a sync access handle (i.e. an OPFS lock) will release that locks at @@ -875,13 +883,17 @@ const installOpfsVfs = function callee(options){ let opfsFlags = 0; if(0===zName){ zName = randomFilename(); - }else if('number'===typeof zName){ + }else if(wasm.isPtr(zName)){ if(capi.sqlite3_uri_boolean(zName, "opfs-unlock-asap", 0)){ /* -----------------------^^^^^ MUST pass the untranslated C-string here. */ opfsFlags |= state.opfsFlags.OPFS_UNLOCK_ASAP; } + if(capi.sqlite3_uri_boolean(zName, "delete-before-open", 0)){ + opfsFlags |= state.opfsFlags.OPFS_UNLINK_BEFORE_OPEN; + } zName = wasm.cstrToJs(zName); + //warn("xOpen zName =",zName, "opfsFlags =",opfsFlags); } const fh = Object.create(null); fh.fid = pFile; diff --git a/ext/wasm/tester1.c-pp.js b/ext/wasm/tester1.c-pp.js index f8a0225234..fdde986355 100644 --- a/ext/wasm/tester1.c-pp.js +++ b/ext/wasm/tester1.c-pp.js @@ -2888,18 +2888,17 @@ globalThis.sqlite3InitModule = sqlite3InitModule; .t({ name: 'OPFS db sanity checks', test: async function(sqlite3){ + T.assert(capi.sqlite3_vfs_find('opfs')); + const opfs = sqlite3.opfs; const filename = this.opfsDbFile = '/dir/sqlite3-tester1.db'; - const pVfs = this.opfsVfs = capi.sqlite3_vfs_find('opfs'); - T.assert(pVfs); - const unlink = this.opfsUnlink = - (fn=filename)=>{sqlite3.util.sqlite3__wasm_vfs_unlink(pVfs,fn)}; - unlink(); - let db = new sqlite3.oo1.OpfsDb(filename); + const fileUri = 'file://'+filename+'?delete-before-open=1'; + const initSql = [ + 'create table p(a);', + 'insert into p(a) values(1),(2),(3)' + ]; + let db = new sqlite3.oo1.OpfsDb(fileUri); try { - db.exec([ - 'create table p(a);', - 'insert into p(a) values(1),(2),(3)' - ]); + db.exec(initSql); T.assert(3 === db.selectValue('select count(*) from p')); db.close(); db = new sqlite3.oo1.OpfsDb(filename); @@ -2911,7 +2910,14 @@ globalThis.sqlite3InitModule = sqlite3InitModule; && 0===this.opfsDbExport.byteLength % 512); }finally{ db.close(); - unlink(); + } + T.assert(await opfs.entryExists(filename)); + try { + db = new sqlite3.oo1.OpfsDb(fileUri); + db.exec(initSql) /* will throw if delete-before-open did not work */; + T.assert(3 === db.selectValue('select count(*) from p')); + }finally{ + if(db) db.close(); } } }/*OPFS db sanity checks*/) @@ -2919,15 +2925,17 @@ globalThis.sqlite3InitModule = sqlite3InitModule; name: 'OPFS import', test: async function(sqlite3){ let db; + const filename = this.opfsDbFile; try { const exp = this.opfsDbExport; - const filename = this.opfsDbFile; delete this.opfsDbExport; this.opfsImportSize = await sqlite3.oo1.OpfsDb.importDb(filename, exp); db = new sqlite3.oo1.OpfsDb(this.opfsDbFile); T.assert(6 === db.selectValue('select count(*) from p')). assert( this.opfsImportSize == exp.byteLength ); db.close(); + const unlink = this.opfsUnlink = + (fn=filename)=>sqlite3.util.sqlite3__wasm_vfs_unlink("opfs",fn); this.opfsUnlink(filename); T.assert(!(await sqlite3.opfs.entryExists(filename))); // Try again with a function as an input source: @@ -2954,11 +2962,9 @@ globalThis.sqlite3InitModule = sqlite3InitModule; name: '(Internal-use) OPFS utility APIs', test: async function(sqlite3){ const filename = this.opfsDbFile; - const pVfs = this.opfsVfs; const unlink = this.opfsUnlink; - T.assert(filename && pVfs && !!unlink); + T.assert(filename && !!unlink); delete this.opfsDbFile; - delete this.opfsVfs; delete this.opfsUnlink; /************************************************************** ATTENTION CLIENT-SIDE USERS: sqlite3.opfs is NOT intended diff --git a/manifest b/manifest index 8e74d529af..a08f5bc55d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\s.expert\scommand\sin\sthe\sshell\sso\sthat\sit\sdoes\snot\sleak\smemory\sif\snot\nfollowed\sby\sSQL\sand\sso\sthat\sit\sworks\swith\sreverse_unordered_selects. -D 2024-03-09T18:41:40.779 +C Add\sdelete-before-open=1\sURI\sflag\sto\sthe\s'opfs'\sVFS\sto\stell\sit\sto\sxDelete\sthe\sdb\sfile\sbefore\sopening\sit,\sprimarily\sto\senable\susers\sto\swork\saround\sa\scorrupt\sdb\swithout\shaving\sto\sreach\sinto\sOPFS-specific\sAPIs\sto\sremove\sthe\sdb\sfile. +D 2024-03-11T09:32:38.668 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -610,10 +610,10 @@ F ext/wasm/api/sqlite3-api-oo1.js 7f3bcf0549ac44cde4b9da0b642d771916738d3f6781fb F ext/wasm/api/sqlite3-api-prologue.js 93a72b07b2a5d964d2edc76a90b439ece49298bd7ba60a1c6ae5d4878213701e F ext/wasm/api/sqlite3-api-worker1.js 8d9c0562831f62218170a3373468d8a0b7a6503b5985e309b69bf71187b525cf F ext/wasm/api/sqlite3-license-version-header.js 0c807a421f0187e778dc1078f10d2994b915123c1223fe752b60afdcd1263f89 -F ext/wasm/api/sqlite3-opfs-async-proxy.js 8cf8a897726f14071fae6be6648125162b256dfb4f96555b865dbb7a6b65e379 +F ext/wasm/api/sqlite3-opfs-async-proxy.js b4c7ce9d7f7957f243d0fbd5b6e28bac80cd3c1b738374cd0c96d89df8f2f316 F ext/wasm/api/sqlite3-vfs-helper.c-pp.js 3f828cc66758acb40e9c5b4dcfd87fd478a14c8fb7f0630264e6c7fa0e57515d F ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js 5a430874906ff3f4a6ca69aadf0c2aaedc1bb45489b8365bff7e955a83a8d42a -F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js fe427645e1499618f5fa7bc670af850577d8bcc132df982078690c9bf8400baa +F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js fb12aa55667109cfd76b5f645c4a4aec1a8ed9af59d62e05604b39e6390f54aa F ext/wasm/api/sqlite3-vtab-helper.c-pp.js a2fcbc3fecdd0eea229283584ebc122f29d98194083675dbe5cb2cf3a17fe309 F ext/wasm/api/sqlite3-wasm.c d33a16495ca871781e78812d3a18fed78b797468fffee657b8d7199b277ff359 F ext/wasm/api/sqlite3-worker1-promiser.c-pp.js bd89edfe42a4d7122a6d6d405c5423cf00aabba1f76f6ea8e2dba9c628ddd91a @@ -662,7 +662,7 @@ F ext/wasm/test-opfs-vfs.html 1f2d672f3f3fce810dfd48a8d56914aba22e45c6834e262555 F ext/wasm/test-opfs-vfs.js 1618670e466f424aa289859fe0ec8ded223e42e9e69b5c851f809baaaca1a00c F ext/wasm/tester1-worker.html ebc4b820a128963afce328ecf63ab200bd923309eb939f4110510ab449e9814c F ext/wasm/tester1.c-pp.html 1c1bc78b858af2019e663b1a31e76657b73dc24bede28ca92fbe917c3a972af2 -F ext/wasm/tester1.c-pp.js 7c51d19f3644904156a154ddedd7024539ffba1a4e2df5e1efe10333e5b91b8f +F ext/wasm/tester1.c-pp.js 18331ec28d7e63c8e262a9872a8da3964d37b7ac22eabe0016af93f3c6f74cc4 F ext/wasm/tests/opfs/concurrency/index.html 0802373d57034d51835ff6041cda438c7a982deea6079efd98098d3e42fbcbc1 F ext/wasm/tests/opfs/concurrency/test.js a98016113eaf71e81ddbf71655aa29b0fed9a8b79a3cdd3620d1658eb1cc9a5d F ext/wasm/tests/opfs/concurrency/worker.js 0a8c1a3e6ebb38aabbee24f122693f1fb29d599948915c76906681bb7da1d3d2 @@ -2177,8 +2177,11 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 76629b2bff01df3d42eef2e93d626c291a2f129bd923498941465e5bca74e9f1 -R d4c5b88cb6e2dcca46b9c5560f050fe6 -U drh -Z b901e762e961c86b4b7445204eab052b +P 7ead022edaf7a0cd6a8976a1261246084975c9a5be5c893f6c751bb5f963ac0f +R 9e249fa0727bf1c60716395bdc490ae1 +T *branch * opfs-delete-before-open +T *sym-opfs-delete-before-open * +T -sym-trunk * Cancelled\sby\sbranch. +U stephan +Z f66cad865afa3b804834b14eccf1a085 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index bb9cddfbd6..82d8c76fd0 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7ead022edaf7a0cd6a8976a1261246084975c9a5be5c893f6c751bb5f963ac0f \ No newline at end of file +e83f9788636f7f9bcca7d2a09620c13ab4eb83436d5b2946a827e48addf0267d \ No newline at end of file From 289507d78bd98f08ce2fae592ff9fb1d234753f3 Mon Sep 17 00:00:00 2001 From: stephan Date: Mon, 11 Mar 2024 09:39:52 +0000 Subject: [PATCH 196/430] Add more docs for the OPFS delete-before-open feature. FossilOrigin-Name: cb8d9c269c01f78f09069a2361e15087d9aeac63e9f1fd63fbd96b951384e9aa --- ext/wasm/api/sqlite3-vfs-opfs.c-pp.js | 7 +++++++ manifest | 13 ++++++------- manifest.uuid | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js b/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js index 65e39e5b5e..4c654c3351 100644 --- a/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js +++ b/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js @@ -433,6 +433,13 @@ const installOpfsVfs = function callee(options){ it. This can be used, e.g., to replace a db which has been corrupted (without forcing us to expose a delete/unlink() function in the public API). + + Failure to unlink the file is ignored but may lead to + downstream errors. An unlink can fail if, e.g., another tab + has the handle open. + + It goes without saying that deleting a file out from under another + instance results in Undefined Behavior. */ OPFS_UNLINK_BEFORE_OPEN: 0x02, /** diff --git a/manifest b/manifest index b49a60d948..b43b4c140b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sdelete-before-open=1\sURI\sflag\sto\sthe\s'opfs'\sVFS\sto\stell\sit\sto\sxDelete\sthe\sdb\sfile\sbefore\sopening\sit,\sprimarily\sto\senable\susers\sto\swork\saround\sa\scorrupt\sdb\swithout\shaving\sto\sreach\sinto\sOPFS-specific\sAPIs\sto\sremove\sthe\sdb\sfile. -D 2024-03-11T09:34:38.171 +C Add\smore\sdocs\sfor\sthe\sOPFS\sdelete-before-open\sfeature. +D 2024-03-11T09:39:52.643 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -613,7 +613,7 @@ F ext/wasm/api/sqlite3-license-version-header.js 0c807a421f0187e778dc1078f10d299 F ext/wasm/api/sqlite3-opfs-async-proxy.js b4c7ce9d7f7957f243d0fbd5b6e28bac80cd3c1b738374cd0c96d89df8f2f316 F ext/wasm/api/sqlite3-vfs-helper.c-pp.js 3f828cc66758acb40e9c5b4dcfd87fd478a14c8fb7f0630264e6c7fa0e57515d F ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js 5a430874906ff3f4a6ca69aadf0c2aaedc1bb45489b8365bff7e955a83a8d42a -F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js fb12aa55667109cfd76b5f645c4a4aec1a8ed9af59d62e05604b39e6390f54aa +F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js 3c72f1a0e6a7343c8c882d29d01bb440f10be12c844651605b486e76f3d6cc8c F ext/wasm/api/sqlite3-vtab-helper.c-pp.js a2fcbc3fecdd0eea229283584ebc122f29d98194083675dbe5cb2cf3a17fe309 F ext/wasm/api/sqlite3-wasm.c d33a16495ca871781e78812d3a18fed78b797468fffee657b8d7199b277ff359 F ext/wasm/api/sqlite3-worker1-promiser.c-pp.js bd89edfe42a4d7122a6d6d405c5423cf00aabba1f76f6ea8e2dba9c628ddd91a @@ -2177,9 +2177,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 7ead022edaf7a0cd6a8976a1261246084975c9a5be5c893f6c751bb5f963ac0f e83f9788636f7f9bcca7d2a09620c13ab4eb83436d5b2946a827e48addf0267d -R 9e249fa0727bf1c60716395bdc490ae1 -T +closed e83f9788636f7f9bcca7d2a09620c13ab4eb83436d5b2946a827e48addf0267d Closed\sby\sintegrate-merge. +P e87cf0d7700d33a439c91725460fbfe3a1765b48f71b4d73c38cadf6c166e0bd +R 86fc5680f4ee4960f4c1dcde68c7d5ad U stephan -Z e48b52f183c07790d9437c2d350f2700 +Z ee95146c516bc7ecdb021be98ac7e603 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 091241ce53..5f9e9ae6f3 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e87cf0d7700d33a439c91725460fbfe3a1765b48f71b4d73c38cadf6c166e0bd \ No newline at end of file +cb8d9c269c01f78f09069a2361e15087d9aeac63e9f1fd63fbd96b951384e9aa \ No newline at end of file From 5dfff386e53a0ec1acd9854f676f9c2dda0cf25e Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 11 Mar 2024 11:24:59 +0000 Subject: [PATCH 197/430] Fix the ".import" command in the CLI so that it works correctly with tables that contain computed columns. [forum:/forumpost/ca014d7358|forum post ca014d7358]. FossilOrigin-Name: 95a9c88b258f18ac671a4c712603931167cc8bd0b86e41481b200c08043338b5 --- manifest | 16 +++++----- manifest.uuid | 2 +- src/shell.c.in | 78 ++++++++++++++++++++++++++++-------------------- test/shell5.test | 14 +++++++++ 4 files changed, 68 insertions(+), 42 deletions(-) diff --git a/manifest b/manifest index b43b4c140b..49e6d916e1 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\smore\sdocs\sfor\sthe\sOPFS\sdelete-before-open\sfeature. -D 2024-03-11T09:39:52.643 +C Fix\sthe\s".import"\scommand\sin\sthe\sCLI\sso\sthat\sit\sworks\scorrectly\swith\stables\nthat\scontain\scomputed\scolumns.\n[forum:/forumpost/ca014d7358|forum\spost\sca014d7358]. +D 2024-03-11T11:24:59.268 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -751,7 +751,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c ef87e3bc7700bfe761a7bbee2ce6084f1766dc816dd82a3ae77c133eec898432 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c 43fabfc01bf87addd15e39f112f1e2ade15b19594835ab8a9e5bd50839d4e1b1 -F src/shell.c.in 74a51fcae1bd945bcc818b6273a901f204410f4e8d2648221352a486ba2fe5ea +F src/shell.c.in cf80c636bccb0ff9db46995e39d69ca21fde2a8a331d1691e4d62a69d7841c8a F src/sqlite.h.in 19a2db3995a699bd7f6dfb423856242bfceb7ec849a93c91d241d19fc28d9f0f F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 @@ -1604,7 +1604,7 @@ F test/shell1.test c7127a5e780ffc9e14c476773127fdf292c6db226529c44c1676f37b37931 F test/shell2.test 35226c070a8c7f64fd016dfac2a0db2a40f709b3131f61daacd9dad61536c9cb F test/shell3.test 91febeac0412812bf6370abb8ed72700e32bf8f9878849414518f662dfd55e8a F test/shell4.test 947029e5a9efae9054d424b309fc0311439c0c3a0866ebfa3b8a771120708220 -F test/shell5.test c8b6c54f26ec537f8558273d7ed293ca3725ef42e6b12b8f151718628bd1473b +F test/shell5.test 263bfd6a49049295277e3f5bdc221390dc5e72f39954b23d43204ed81993304f F test/shell6.test 1ceb51b2678c472ba6cf1e5da96679ce8347889fe2c3bf93a0e0fa73f00b00d3 F test/shell7.test 115132f66d0463417f408562cc2cf534f6bbc6d83a6d50f0072a9eb171bae97f F test/shell8.test 3fd093d481aaa94dc77fb73f1044c1f19c7efe3477a395cc4f7450133bc54915 @@ -2177,8 +2177,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P e87cf0d7700d33a439c91725460fbfe3a1765b48f71b4d73c38cadf6c166e0bd -R 86fc5680f4ee4960f4c1dcde68c7d5ad -U stephan -Z ee95146c516bc7ecdb021be98ac7e603 +P cb8d9c269c01f78f09069a2361e15087d9aeac63e9f1fd63fbd96b951384e9aa +R 9bba8f8b4bc3bf41627766fe1aa44b9c +U drh +Z 1d2e3bf230fd6cd6fbc6ff6c84cfd8fb # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 5f9e9ae6f3..c57a5b98bf 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -cb8d9c269c01f78f09069a2361e15087d9aeac63e9f1fd63fbd96b951384e9aa \ No newline at end of file +95a9c88b258f18ac671a4c712603931167cc8bd0b86e41481b200c08043338b5 \ No newline at end of file diff --git a/src/shell.c.in b/src/shell.c.in index 73161cf646..9fdf909523 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -8778,16 +8778,15 @@ static int do_meta_command(char *zLine, ShellState *p){ #ifndef SQLITE_SHELL_FIDDLE if( c=='i' && cli_strncmp(azArg[0], "import", n)==0 ){ char *zTable = 0; /* Insert data into this table */ - char *zSchema = 0; /* within this schema (may default to "main") */ + char *zSchema = 0; /* Schema of zTable */ char *zFile = 0; /* Name of file to extra content from */ sqlite3_stmt *pStmt = NULL; /* A statement */ int nCol; /* Number of columns in the table */ - int nByte; /* Number of bytes in an SQL string */ + i64 nByte; /* Number of bytes in an SQL string */ int i, j; /* Loop counters */ int needCommit; /* True to COMMIT or ROLLBACK at end */ int nSep; /* Number of bytes in p->colSeparator[] */ - char *zSql; /* An SQL statement */ - char *zFullTabName; /* Table name with schema if applicable */ + char *zSql = 0; /* An SQL statement */ ImportCtx sCtx; /* Reader context */ char *(SQLITE_CDECL *xRead)(ImportCtx*); /* Func to read one value */ int eVerbose = 0; /* Larger for more console output */ @@ -8921,24 +8920,14 @@ static int do_meta_command(char *zLine, ShellState *p){ while( (nSkip--)>0 ){ while( xRead(&sCtx) && sCtx.cTerm==sCtx.cColSep ){} } - if( zSchema!=0 ){ - zFullTabName = sqlite3_mprintf("\"%w\".\"%w\"", zSchema, zTable); - }else{ - zFullTabName = sqlite3_mprintf("\"%w\"", zTable); - } - zSql = sqlite3_mprintf("SELECT * FROM %s", zFullTabName); - if( zSql==0 || zFullTabName==0 ){ - import_cleanup(&sCtx); - shell_out_of_memory(); - } - nByte = strlen30(zSql); - rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0); import_append_char(&sCtx, 0); /* To ensure sCtx.z is allocated */ - if( rc && sqlite3_strglob("no such table: *", sqlite3_errmsg(p->db))==0 ){ + if( sqlite3_table_column_metadata(p->db, zSchema, zTable,0,0,0,0,0,0) ){ + /* Table does not exist. Create it. */ sqlite3 *dbCols = 0; char *zRenames = 0; char *zColDefs; - zCreate = sqlite3_mprintf("CREATE TABLE %s", zFullTabName); + zCreate = sqlite3_mprintf("CREATE TABLE \"%w\".\"%w\"", + zSchema ? zSchema : "main", zTable); while( xRead(&sCtx) ){ zAutoColumn(sCtx.z, &dbCols, 0); if( sCtx.cTerm!=sCtx.cColSep ) break; @@ -8953,34 +8942,50 @@ static int do_meta_command(char *zLine, ShellState *p){ assert(dbCols==0); if( zColDefs==0 ){ eputf("%s: empty file\n", sCtx.zFile); - import_fail: - sqlite3_free(zCreate); - sqlite3_free(zSql); - sqlite3_free(zFullTabName); import_cleanup(&sCtx); rc = 1; goto meta_command_exit; } zCreate = sqlite3_mprintf("%z%z\n", zCreate, zColDefs); + if( zCreate==0 ){ + import_cleanup(&sCtx); + shell_out_of_memory(); + } if( eVerbose>=1 ){ oputf("%s\n", zCreate); } rc = sqlite3_exec(p->db, zCreate, 0, 0, 0); + sqlite3_free(zCreate); + zCreate = 0; if( rc ){ eputf("%s failed:\n%s\n", zCreate, sqlite3_errmsg(p->db)); - goto import_fail; + import_cleanup(&sCtx); + rc = 1; + goto meta_command_exit; } - sqlite3_free(zCreate); - zCreate = 0; - rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0); } + zSql = sqlite3_mprintf("SELECT count(*) FROM pragma_table_info(%Q,%Q);", + zTable, zSchema); + if( zSql==0 ){ + import_cleanup(&sCtx); + shell_out_of_memory(); + } + nByte = strlen(zSql); + rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0); + sqlite3_free(zSql); + zSql = 0; if( rc ){ if (pStmt) sqlite3_finalize(pStmt); eputf("Error: %s\n", sqlite3_errmsg(p->db)); - goto import_fail; + import_cleanup(&sCtx); + rc = 1; + goto meta_command_exit; + } + if( sqlite3_step(pStmt)==SQLITE_ROW ){ + nCol = sqlite3_column_int(pStmt, 0); + }else{ + nCol = 0; } - sqlite3_free(zSql); - nCol = sqlite3_column_count(pStmt); sqlite3_finalize(pStmt); pStmt = 0; if( nCol==0 ) return 0; /* no columns, no error */ @@ -8989,7 +8994,12 @@ static int do_meta_command(char *zLine, ShellState *p){ import_cleanup(&sCtx); shell_out_of_memory(); } - sqlite3_snprintf(nByte+20, zSql, "INSERT INTO %s VALUES(?", zFullTabName); + if( zSchema ){ + sqlite3_snprintf(nByte+20, zSql, "INSERT INTO \"%w\".\"%w\" VALUES(?", + zSchema, zTable); + }else{ + sqlite3_snprintf(nByte+20, zSql, "INSERT INTO \"%w\" VALUES(?", zTable); + } j = strlen30(zSql); for(i=1; idb, zSql, -1, &pStmt, 0); + sqlite3_free(zSql); + zSql = 0; if( rc ){ eputf("Error: %s\n", sqlite3_errmsg(p->db)); if (pStmt) sqlite3_finalize(pStmt); - goto import_fail; + import_cleanup(&sCtx); + rc = 1; + goto meta_command_exit; } - sqlite3_free(zSql); - sqlite3_free(zFullTabName); needCommit = sqlite3_get_autocommit(p->db); if( needCommit ) sqlite3_exec(p->db, "BEGIN", 0, 0, 0); do{ diff --git a/test/shell5.test b/test/shell5.test index 39018a0ce9..20f2ba219d 100644 --- a/test/shell5.test +++ b/test/shell5.test @@ -570,4 +570,18 @@ SELECT * FROM t1;} } {0 { 1 = あい 2 = うえお}} +# 2024-03-11 https://sqlite.org/forum/forumpost/ca014d7358 +# Import into a table that contains computed columns. +# +do_test shell5-7.1 { + set out [open shell5.csv w] + fconfigure $out -translation lf + puts $out {aaa|bbb} + close $out + forcedelete test.db + catchcmd :memory: {CREATE TABLE t1(a TEXT, b TEXT, c AS (a||b)); +.import shell5.csv t1 +SELECT * FROM t1;} +} {0 aaa|bbb|aaabbb} + finish_test From 815e055bff42d57f49cf46cc70771cdcf5930d83 Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 11 Mar 2024 17:27:19 +0000 Subject: [PATCH 198/430] Attempt to reduce the memory used by VALUES clauses in as many statements as possible, not just INSERT. This branch still has problems. FossilOrigin-Name: 17d1f7cfabc7593d0725051b0c7c9619a23a482265f30f15ab9493fef5caeeb0 --- manifest | 29 +++-- manifest.uuid | 2 +- src/expr.c | 1 + src/insert.c | 137 +++++++++++++++++++--- src/parse.y | 27 ++--- src/select.c | 2 +- src/sqliteInt.h | 4 + src/where.c | 1 + test/values.test | 256 ++++++++++++++++++++++++++++++++++++++++++ test/valuesfault.test | 37 ++++++ 10 files changed, 451 insertions(+), 45 deletions(-) create mode 100644 test/values.test create mode 100644 test/valuesfault.test diff --git a/manifest b/manifest index 49e6d916e1..afde134bd1 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\s".import"\scommand\sin\sthe\sCLI\sso\sthat\sit\sworks\scorrectly\swith\stables\nthat\scontain\scomputed\scolumns.\n[forum:/forumpost/ca014d7358|forum\spost\sca014d7358]. -D 2024-03-11T11:24:59.268 +C Attempt\sto\sreduce\sthe\smemory\sused\sby\sVALUES\sclauses\sin\sas\smany\sstatements\sas\spossible,\snot\sjust\sINSERT.\sThis\sbranch\sstill\shas\sproblems. +D 2024-03-11T17:27:19.668 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -700,7 +700,7 @@ F src/date.c 126ba2ab10aeb2e7ba6e089b5f07b747c0625b8287f78b60da346eda8d23c875 F src/dbpage.c 80e46e1df623ec40486da7a5086cb723b0275a6e2a7b01d9f9b5da0f04ba2782 F src/dbstat.c 3b677254d512fcafd4d0b341bf267b38b235ccfddbef24f9154e19360fa22e43 F src/delete.c cb766727c78e715f9fb7ec8a7d03658ed2a3016343ca687acfcec9083cdca500 -F src/expr.c 05516e8b7d7d22f98160a0360fde69edce3304a430600567ed33e66d588ca59b +F src/expr.c 7d0280860f8683fa1e81202304a5107f493fe9bd52be6590d0d0d6c3564c7a07 F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c a47610f0a5c6cb0ad79f8fcef039c01833dec0c751bb695f28dc0ec6a4c3ba00 F src/func.c 4204c56196847faefef57fa14e43b8e4d65eb8d7e65318abe463472e3fd148cb @@ -709,7 +709,7 @@ F src/hash.c 9ee4269fb1d6632a6fecfb9479c93a1f29271bddbbaf215dd60420bcb80c7220 F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 -F src/insert.c eb33ea46dcab93e90f112fced343aaf41f59cbd2e951d5066f1f9302be1c2f34 +F src/insert.c 2c34cf51e9d8c00498ba68b7f130e448038bb31f624c9c1ca80fa8e3237b51fb F src/json.c e2e40760d6689134c3e2ece38c6a496b34ff5e2661a8f238444a119af666fdce F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 @@ -739,7 +739,7 @@ F src/os_win.c 6ff43bac175bd9ed79e7c0f96840b139f2f51d01689a638fd05128becf94908a F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a F src/pager.c ff60e98138d2499082ac6230f01ac508aba545315debccfca2fd6042f5f10fcd F src/pager.h 4b1140d691860de0be1347474c51fee07d5420bd7f802d38cbab8ea4ab9f538a -F src/parse.y 6209f01e8e7495379571454744fa82a5cfc2e7eeb89e46dee3f410d73ea6252d +F src/parse.y 3d022ba4c68bf8c7c4c40b3e364d7a8226c4089fc9ff7a3a95f969f8f1bec959 F src/pcache.c 040b165f30622a21b7a9a77c6f2e4877a32fb7f22d4c7f0d2a6fa6833a156a75 F src/pcache.h 1497ce1b823cf00094bb0cf3bac37b345937e6f910890c626b16512316d3abf5 F src/pcache1.c 602acb23c471bb8d557a6f0083cc2be641d6cafcafa19e481eba7ef4c9ca0f00 @@ -750,12 +750,12 @@ F src/printf.c 10e8bad30042f8bd6114a013b4afc229ec8ad255ab27518d7d9f52e8cbc5cd0a F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c ef87e3bc7700bfe761a7bbee2ce6084f1766dc816dd82a3ae77c133eec898432 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 -F src/select.c 43fabfc01bf87addd15e39f112f1e2ade15b19594835ab8a9e5bd50839d4e1b1 +F src/select.c 2a12c6ed8131db7c49b6f8141c3420cab825cfc6bd222d347fa1382f36b174b7 F src/shell.c.in cf80c636bccb0ff9db46995e39d69ca21fde2a8a331d1691e4d62a69d7841c8a F src/sqlite.h.in 19a2db3995a699bd7f6dfb423856242bfceb7ec849a93c91d241d19fc28d9f0f F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 -F src/sqliteInt.h 6123ce6ca6a1ef351c3b87189e92c92042728f16c088de56b9b5bc2552d0ae33 +F src/sqliteInt.h b3ac44ca090011813d5a07f63be59785a4558e74052eb94b686f52eef1af684b F src/sqliteLimit.h 6878ab64bdeb8c24a1d762d45635e34b96da21132179023338c93f820eee6728 F src/status.c cb11f8589a6912af2da3bb1ec509a94dd8ef27df4d4c1a97e0bcf2309ece972b F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1 @@ -835,7 +835,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c 887fc4ca3f020ebb2e376f222069570834ac63bf50111ef0cbf3ae417048ed89 F src/wal.h ba252daaa94f889f4b2c17c027e823d9be47ce39da1d3799886bbd51f0490452 F src/walker.c 7c7ea0115345851c3da4e04e2e239a29983b61fb5b038b94eede6aba462640e2 -F src/where.c 33eaaeef3aef10c2b9e82096e70a174d6636e35cb0b180321b8ddf804590e5cd +F src/where.c 8bb70b3caadcf35073f8857ecd83d33d97bf6aa03de3342287037bae43c6f364 F src/whereInt.h 82a13766f13d1a53b05387c2e60726289ef26404bc7b9b1f7770204d97357fb8 F src/wherecode.c 5d77db30a2a3dd532492ae882de114edba2fae672622056b1c7fd61f5917a8f1 F src/whereexpr.c 6ebd90b553f4bb5c7df5a4b2f39b6a7c81a67484353827cdd2048f2514ec6f30 @@ -1921,6 +1921,8 @@ F test/vacuum4.test 7ea76b769fffeb41f925303b04cbcf5a5bbeabe55e4c60ae754ff24eeeb7 F test/vacuum5.test 263b144d537e92ad8e9ca8a73cc6e1583f41cfd0dda9432b87f7806174a2f48c F test/vacuum6.test b137b04bf3392d3f5c3b8fda0ce85a6775a70ca112f6559f74ff52dc9ce042fd F test/vacuummem.test 4b30f5b95a9ff86e9d5c20741e50a898b2dc10b0962a3211571eb165357003fb +F test/values.test 8438dea6826738291ff2019993d62e1eae7a3efb66ea8312fa9ac9bfaf0f95cb +F test/valuesfault.test 2ef23ed965e3bd08e268cdc38a0d11653390ddbbe1e8e2e98d16f55edd30f6e8 F test/varint.test bbce22cda8fc4d135bcc2b589574be8410614e62 F test/veryquick.test 57ab846bacf7b90cf4e9a672721ea5c5b669b661 F test/view.test d4c4281e1679245829db35597817282f60dc513fc39cc5439078f009bd118487 @@ -2177,8 +2179,11 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P cb8d9c269c01f78f09069a2361e15087d9aeac63e9f1fd63fbd96b951384e9aa -R 9bba8f8b4bc3bf41627766fe1aa44b9c -U drh -Z 1d2e3bf230fd6cd6fbc6ff6c84cfd8fb +P 95a9c88b258f18ac671a4c712603931167cc8bd0b86e41481b200c08043338b5 +R 62b6db11e5c879766b23978dd0871f55 +T *branch * exp-values-clause2 +T *sym-exp-values-clause2 * +T -sym-trunk * +U dan +Z 521a450017e9a427470d7f09cc068c5e # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index c57a5b98bf..633c59c43c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -95a9c88b258f18ac671a4c712603931167cc8bd0b86e41481b200c08043338b5 \ No newline at end of file +17d1f7cfabc7593d0725051b0c7c9619a23a482265f30f15ab9493fef5caeeb0 \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index 6640d1907d..e4bfa995d7 100644 --- a/src/expr.c +++ b/src/expr.c @@ -1869,6 +1869,7 @@ SrcList *sqlite3SrcListDup(sqlite3 *db, const SrcList *p, int flags){ pNewItem->iCursor = pOldItem->iCursor; pNewItem->addrFillSub = pOldItem->addrFillSub; pNewItem->regReturn = pOldItem->regReturn; + pNewItem->regResult = pOldItem->regResult; if( pNewItem->fg.isIndexedBy ){ pNewItem->u1.zIndexedBy = sqlite3DbStrDup(db, pOldItem->u1.zIndexedBy); } diff --git a/src/insert.c b/src/insert.c index 095298b90c..7b253e9262 100644 --- a/src/insert.c +++ b/src/insert.c @@ -577,6 +577,104 @@ void sqlite3AutoincrementEnd(Parse *pParse){ # define autoIncStep(A,B,C) #endif /* SQLITE_OMIT_AUTOINCREMENT */ +void sqlite3MultiValuesEnd(Parse *pParse, Select *pVal){ + if( pVal->pSrc->nSrc>0 ){ + SrcItem *pItem = &pVal->pSrc->a[0]; + sqlite3VdbeEndCoroutine(pParse->pVdbe, pItem->regReturn); + sqlite3VdbeJumpHere(pParse->pVdbe, pItem->addrFillSub - 1); + } +} + +static int multiValueIsConstant(ExprList *pRow){ + int ii; + for(ii=0; iinExpr; ii++){ + if( 0==sqlite3ExprIsConstant(pRow->a[ii].pExpr) ) return 0; + } + return 1; +} + +Select *sqlite3MultiValues(Parse *pParse, Select *pLeft, ExprList *pRow){ + SrcItem *p; + SelectDest dest; + Select *pSelect = 0; + + if( pParse->db->init.busy + || pParse->pNewTrigger + || pParse->bHasWith + || multiValueIsConstant(pRow)==0 + || pLeft->pPrior + ){ + int f = SF_Values | SF_MultiValue; + if( pLeft->pPrior || pLeft->pSrc->nSrc ){ + sqlite3MultiValuesEnd(pParse, pLeft); + f = SF_Values; + } + /* This VALUES clause is part of a VIEW or some other schema item. In + ** this case the co-routine cannot be coded immediately. */ + pSelect = sqlite3SelectNew(pParse,pRow,0,0,0,0,0,f,0); + pLeft->selFlags &= ~SF_MultiValue; + if( pSelect ){ + pSelect->op = TK_ALL; + pSelect->pPrior = pLeft; + pLeft = pSelect; + } + }else{ + + if( pLeft->pSrc->nSrc==0 ){ + /* Co-routine has not yet been started. */ + Vdbe *v = sqlite3GetVdbe(pParse); + Select *pRet; + + if( v==0 ) return pLeft; + pRet = sqlite3SelectNew(pParse, 0, 0, 0, 0, 0, 0, 0, 0); + if( pRet==0 ) return pLeft; + p = &pRet->pSrc->a[0]; + pRet->pSrc->nSrc = 1; + + p->pSelect = pLeft; + p->fg.viaCoroutine = 1; + p->addrFillSub = sqlite3VdbeCurrentAddr(v) + 1; + p->regReturn = ++pParse->nMem; + + sqlite3VdbeAddOp3(v,OP_InitCoroutine,p->regReturn,0,p->addrFillSub); + sqlite3SelectDestInit(&dest, SRT_Coroutine, p->regReturn); + sqlite3Select(pParse, pLeft, &dest); + p->regResult = dest.iSdst; + assert( pParse->nErr || dest.iSdst>0 ); + + pLeft = pRet; + }else{ + p = &pLeft->pSrc->a[0]; + } + + if( pParse->nErr==0 ){ + pSelect = sqlite3SelectNew(pParse, pRow, 0, 0, 0, 0, 0, SF_Values, 0); + if( pSelect ){ + if( p->pSelect->pEList->nExpr!=pSelect->pEList->nExpr ){ + sqlite3SelectWrongNumTermsError(pParse, pSelect); + }else{ + sqlite3SelectPrep(pParse, pSelect, 0); +#ifndef SQLITE_OMIT_WINDOWFUNC + if( pSelect->pWin ){ + sqlite3SelectDestInit(&dest, SRT_Coroutine, p->regReturn); + dest.iSdst = p->regResult; + dest.nSdst = pRow->nExpr; + dest.iSDParm = p->regReturn; + sqlite3Select(pParse, pSelect, &dest); + }else +#endif + { + sqlite3ExprCodeExprList(pParse, pSelect->pEList,p->regResult,0,0); + sqlite3VdbeAddOp1(pParse->pVdbe, OP_Yield, p->regReturn); + } + } + sqlite3SelectDelete(pParse->db, pSelect); + } + } + } + + return pLeft; +} /* Forward declaration */ static int xferOptimization( @@ -914,24 +1012,31 @@ void sqlite3Insert( /* Data is coming from a SELECT or from a multi-row VALUES clause. ** Generate a co-routine to run the SELECT. */ int regYield; /* Register holding co-routine entry-point */ - int addrTop; /* Top of the co-routine */ int rc; /* Result code */ - regYield = ++pParse->nMem; - addrTop = sqlite3VdbeCurrentAddr(v) + 1; - sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, addrTop); - sqlite3SelectDestInit(&dest, SRT_Coroutine, regYield); - dest.iSdst = bIdListInOrder ? regData : 0; - dest.nSdst = pTab->nCol; - rc = sqlite3Select(pParse, pSelect, &dest); - regFromSelect = dest.iSdst; - assert( db->pParse==pParse ); - if( rc || pParse->nErr ) goto insert_cleanup; - assert( db->mallocFailed==0 ); - sqlite3VdbeEndCoroutine(v, regYield); - sqlite3VdbeJumpHere(v, addrTop - 1); /* label B: */ - assert( pSelect->pEList ); - nColumn = pSelect->pEList->nExpr; + if( pSelect->pSrc->nSrc==1 && pSelect->pSrc->a[0].fg.viaCoroutine ){ + SrcItem *pItem = &pSelect->pSrc->a[0]; + dest.iSDParm = regYield = pItem->regReturn; + regFromSelect = pItem->regResult; + nColumn = pItem->pSelect->pEList->nExpr; + }else{ + int addrTop; /* Top of the co-routine */ + regYield = ++pParse->nMem; + addrTop = sqlite3VdbeCurrentAddr(v) + 1; + sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, addrTop); + sqlite3SelectDestInit(&dest, SRT_Coroutine, regYield); + dest.iSdst = bIdListInOrder ? regData : 0; + dest.nSdst = pTab->nCol; + rc = sqlite3Select(pParse, pSelect, &dest); + regFromSelect = dest.iSdst; + assert( db->pParse==pParse ); + if( rc || pParse->nErr ) goto insert_cleanup; + assert( db->mallocFailed==0 ); + sqlite3VdbeEndCoroutine(v, regYield); + sqlite3VdbeJumpHere(v, addrTop - 1); /* label B: */ + assert( pSelect->pEList ); + nColumn = pSelect->pEList->nExpr; + } /* Set useTempTable to TRUE if the result of the SELECT statement ** should be written into a temporary table (template 4). Set to diff --git a/src/parse.y b/src/parse.y index 37c9fa8bc9..515d512f2c 100644 --- a/src/parse.y +++ b/src/parse.y @@ -562,9 +562,13 @@ cmd ::= select(X). { } %ifndef SQLITE_OMIT_CTE -select(A) ::= WITH wqlist(W) selectnowith(X). {A = attachWithToSelect(pParse,X,W);} -select(A) ::= WITH RECURSIVE wqlist(W) selectnowith(X). +select(A) ::= withkw wqlist(W) selectnowith(X). {A = attachWithToSelect(pParse,X,W);} +select(A) ::= withkw RECURSIVE wqlist(W) selectnowith(X). {A = attachWithToSelect(pParse,X,W);} + +withkw ::= WITH. { + pParse->bHasWith = 1; +} %endif /* SQLITE_OMIT_CTE */ select(A) ::= selectnowith(A). { Select *p = A; @@ -622,7 +626,9 @@ oneselect(A) ::= SELECT distinct(D) selcollist(W) from(X) where_opt(Y) %endif -oneselect(A) ::= values(A). +oneselect(A) ::= values(A). { + sqlite3MultiValuesEnd(pParse, A); +} %type values {Select*} %destructor values {sqlite3SelectDelete(pParse->db, $$);} @@ -630,16 +636,7 @@ values(A) ::= VALUES LP nexprlist(X) RP. { A = sqlite3SelectNew(pParse,X,0,0,0,0,0,SF_Values,0); } values(A) ::= values(A) COMMA LP nexprlist(Y) RP. { - Select *pRight, *pLeft = A; - pRight = sqlite3SelectNew(pParse,Y,0,0,0,0,0,SF_Values|SF_MultiValue,0); - if( ALWAYS(pLeft) ) pLeft->selFlags &= ~SF_MultiValue; - if( pRight ){ - pRight->op = TK_ALL; - pRight->pPrior = pLeft; - A = pRight; - }else{ - A = pLeft; - } + A = sqlite3MultiValues(pParse, A, Y); } // The "distinct" nonterminal is true (1) if the DISTINCT keyword is @@ -1754,8 +1751,8 @@ anylist ::= anylist ANY. with ::= . %ifndef SQLITE_OMIT_CTE -with ::= WITH wqlist(W). { sqlite3WithPush(pParse, W, 1); } -with ::= WITH RECURSIVE wqlist(W). { sqlite3WithPush(pParse, W, 1); } +with ::= withkw wqlist(W). { sqlite3WithPush(pParse, W, 1); } +with ::= withkw RECURSIVE wqlist(W). { sqlite3WithPush(pParse, W, 1); } %type wqas {u8} wqas(A) ::= AS. {A = M10d_Any;} diff --git a/src/select.c b/src/select.c index 81e802d6e4..4158dd2fdc 100644 --- a/src/select.c +++ b/src/select.c @@ -7636,7 +7636,7 @@ int sqlite3Select( /* Generate code for all sub-queries in the FROM clause */ pSub = pItem->pSelect; - if( pSub==0 ) continue; + if( pSub==0 || pItem->addrFillSub!=0 ) continue; /* The code for a subquery should only be generated once. */ assert( pItem->addrFillSub==0 ); diff --git a/src/sqliteInt.h b/src/sqliteInt.h index e11b5b3a4e..3913392712 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -3812,6 +3812,7 @@ struct Parse { u8 disableLookaside; /* Number of times lookaside has been disabled */ u8 prepFlags; /* SQLITE_PREPARE_* flags */ u8 withinRJSubrtn; /* Nesting level for RIGHT JOIN body subroutines */ + u8 bHasWith; /* True if statement contains WITH */ #if defined(SQLITE_DEBUG) || defined(SQLITE_COVERAGE_TEST) u8 earlyCleanup; /* OOM inside sqlite3ParserAddCleanup() */ #endif @@ -4486,6 +4487,9 @@ struct Window { ** due to the SQLITE_SUBTYPE flag */ }; +Select *sqlite3MultiValues(Parse *pParse, Select *pLeft, ExprList *pRow); +void sqlite3MultiValuesEnd(Parse *pParse, Select *pVal); + #ifndef SQLITE_OMIT_WINDOWFUNC void sqlite3WindowDelete(sqlite3*, Window*); void sqlite3WindowUnlinkFromSelect(Window*); diff --git a/src/where.c b/src/where.c index 9850d22cc3..9abc8e30f6 100644 --- a/src/where.c +++ b/src/where.c @@ -6896,6 +6896,7 @@ void sqlite3WhereEnd(WhereInfo *pWInfo){ */ if( pTabItem->fg.viaCoroutine ){ testcase( pParse->db->mallocFailed ); + assert( pTabItem->regResult>=0 ); translateColumnToCopy(pParse, pLevel->addrBody, pLevel->iTabCur, pTabItem->regResult, 0); continue; diff --git a/test/values.test b/test/values.test new file mode 100644 index 0000000000..66e29ef6f0 --- /dev/null +++ b/test/values.test @@ -0,0 +1,256 @@ +# 2024 March 3 +# +# 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. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix values + + +do_execsql_test 1.0 { + CREATE TABLE x1(a, b, c); +} + + +explain_i { + INSERT INTO x1(a, b, c) VALUES(1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4); +} +do_execsql_test 1.1.1 { + INSERT INTO x1 VALUES(1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4); +} +do_execsql_test 1.1.2 { + SELECT * FROM x1; +} { + 1 1 1 + 2 2 2 + 3 3 3 + 4 4 4 +} + +do_execsql_test 1.2.0 { + DELETE FROM x1 +} +do_execsql_test 1.2.1 { + INSERT INTO x1 VALUES(1, 1, 1), (2, 2, 2), (3, 3, 3) UNION ALL SELECT 4, 4, 4; + SELECT * FROM x1; +} {1 1 1 2 2 2 3 3 3 4 4 4} + +sqlite3_limit db SQLITE_LIMIT_COMPOUND_SELECT 4 + +do_execsql_test 1.2.2 { + DELETE FROM x1; + INSERT INTO x1 + VALUES(1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4), (5, 5, 5) + UNION ALL SELECT 6, 6, 6; + SELECT * FROM x1; +} {1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6} + +do_execsql_test 1.2.3 { + DELETE FROM x1; + INSERT INTO x1 + VALUES(1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4) + UNION ALL SELECT 6, 6, 6; + SELECT * FROM x1; +} {1 1 1 2 2 2 3 3 3 4 4 4 6 6 6} + +do_execsql_test 1.2.4 { + DELETE FROM x1; + INSERT INTO x1 VALUES(1, 1, 1), (2, 2, 2), (3, 3, 3) UNION ALL SELECT 6, 6, 6; + SELECT * FROM x1; +} { + 1 1 1 + 2 2 2 + 3 3 3 + 6 6 6 +} + +set a 4 +set b 5 +set c 6 +do_execsql_test 1.2.5 { + DELETE FROM x1; + INSERT INTO x1 + VALUES(1, 1, 1), (2, 2, 2), (3, 3, 3), + (4, 4, $a), (5, 5, $b), (6, 6, $c) +} + +do_execsql_test 1.2.6 { + SELECT * FROM x1; +} { + 1 1 1 + 2 2 2 + 3 3 3 + 4 4 4 + 5 5 5 + 6 6 6 +} + +#------------------------------------------------------------------------- +# SQLITE_LIMIT_COMPOUND_SELECT set to 0. +# +reset_db + +do_execsql_test 2.0 { + CREATE TABLE x1(a, b, c); +} + +sqlite3_limit db SQLITE_LIMIT_COMPOUND_SELECT 3 + +do_catchsql_test 2.1.1 { + INSERT INTO x1 VALUES + (1, 1, 1), + (2, 2, 2), + (3, 3, 3), + (4, 4, 4), + (5, 5, 5), + (6, 6, 6), + (7, 7, 7), + (8, 8, 8), + (9, 9, 9), + (10, 10, 10, 10) +} {1 {all VALUES must have the same number of terms}} + +do_catchsql_test 2.1.2 { + INSERT INTO x1 VALUES + (1, 1, 1), + (2, 2, 2, 2), + (3, 3, 3), + (4, 4, 4), + (5, 5, 5), + (6, 6, 6), + (7, 7, 7), + (8, 8, 8), + (9, 9, 9), + (10, 10, 10) +} {1 {all VALUES must have the same number of terms}} + +sqlite3_limit db SQLITE_LIMIT_COMPOUND_SELECT 0 + +do_execsql_test 2.2 { + INSERT INTO x1 VALUES + (1, 1, 1), + (2, 2, 2), + (3, 3, 3), + (4, 4, 4), + (5, 5, 5), + (6, 6, 6), + (7, 7, 7), + (8, 8, 8), + (9, 9, 9), + (10, 10, 10) +} {} +do_execsql_test 2.3 { + INSERT INTO x1 VALUES + (1, 1, 1), + (2, 2, 2), + (3, 3, 3), + (4, 4, 4), + (5, 5, 5), + (6, 6, 6), + (7, 7, 7), + (8, 8, 8), + (9, 9, 9), + (10, 10, 10) + UNION ALL + SELECT 5, 12, 12 + ORDER BY 1 +} {} + +#------------------------------------------------------------------------- +reset_db + +do_execsql_test 3.0 { + CREATE TABLE y1(x, y); +} + +do_execsql_test 3.1.1 { + DELETE FROM y1; + INSERT INTO y1 VALUES(1, 2), (3, 4), (row_number() OVER (), 5); +} +do_execsql_test 3.1.2 { + SELECT * FROM y1; +} {1 2 3 4 1 5} +do_execsql_test 3.2.1 { + DELETE FROM y1; + INSERT INTO y1 VALUES(1, 2), (3, 4), (row_number() OVER (), 6) + , (row_number() OVER (), 7) +} +do_execsql_test 3.1.2 { + SELECT * FROM y1; +} {1 2 3 4 1 6 1 7} + +#------------------------------------------------------------------------- +reset_db + +do_execsql_test 4.0 { + CREATE TABLE x1(a PRIMARY KEY, b) WITHOUT ROWID; +} + +foreach {tn iLimit} {1 0 2 3} { + sqlite3_limit db SQLITE_LIMIT_COMPOUND_SELECT $iLimit + + do_execsql_test 4.1.1 { + DELETE FROM x1; + INSERT INTO x1 VALUES + (1, 1), + (2, (SELECT * FROM (VALUES('a'), ('b'), ('c'), ('d')) )) + } + do_execsql_test 4.1.2 { + SELECT * FROM x1 + } {1 1 2 a} + + do_execsql_test 4.2.1 { + DELETE FROM x1; + INSERT INTO x1 VALUES + (1, 1), + (2, 2), + (3, 3), + (4, 4), + (5, (SELECT * FROM (VALUES('a'), ('b'), ('c'), ('d')) )) + } + do_execsql_test 4.2.2 { + SELECT * FROM x1 + } {1 1 2 2 3 3 4 4 5 a} + + do_execsql_test 4.3.1 { + DELETE FROM x1; + INSERT INTO x1 VALUES + (1, (SELECT * FROM (VALUES('a'), ('b'), ('c'), ('d'), ('e')) )) + } + do_execsql_test 4.3.2 { + SELECT * FROM x1 + } {1 a} +} + +#------------------------------------------------------------------------ +reset_db + +do_execsql_test 5.0 { + CREATE VIEW v1 AS VALUES(1, 2, 3), (4, 5, 6), (7, 8, 9); +} +do_execsql_test 5.1 { + SELECT * FROM v1 +} {1 2 3 4 5 6 7 8 9} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 6.0 { + CREATE TABLE t1(x); + INSERT INTO t1 VALUES(1), (2); +} + +do_execsql_test 6.1 { + SELECT ( VALUES( x ), ( x ) ) FROM t1; +} {1 2} + + +finish_test diff --git a/test/valuesfault.test b/test/valuesfault.test new file mode 100644 index 0000000000..bc5dddfb0e --- /dev/null +++ b/test/valuesfault.test @@ -0,0 +1,37 @@ +# 2024 March 3 +# +# 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. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix valuesfault +source $testdir/malloc_common.tcl + + +do_execsql_test 1.0 { + CREATE TABLE x1(a, b, c); +} +faultsim_save_and_close + +do_faultsim_test 1 -prep { + faultsim_restore_and_reopen + sqlite3_limit db SQLITE_LIMIT_COMPOUND_SELECT 2 +} -body { + execsql { + INSERT INTO x1 VALUES(1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4); + } +} -test { + faultsim_test_result {0 {}} +} + + +finish_test From c6481e0289f18598985bba974e901a24e528fc2c Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 11 Mar 2024 18:21:02 +0000 Subject: [PATCH 199/430] Run shell*.test modules with "make mdevtest". FossilOrigin-Name: 76c471061809307c1922a9460f1ea37291ff5f4dc11a71af594351e875fdc8e3 --- Makefile.in | 4 ++-- Makefile.msc | 4 ++-- manifest | 16 ++++++++-------- manifest.uuid | 2 +- test/testrunner.tcl | 11 ++++++++++- 5 files changed, 23 insertions(+), 14 deletions(-) diff --git a/Makefile.in b/Makefile.in index 321fb75278..e16fa94345 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1314,9 +1314,9 @@ testfixture$(TEXE): has_tclsh85 $(TESTFIXTURE_SRC) $(LTLINK) -DSQLITE_NO_SYNC=1 $(TEMP_STORE) $(TESTFIXTURE_FLAGS) \ -o $@ $(TESTFIXTURE_SRC) $(LIBTCL) $(TLIBS) -coretestprogs: $(TESTPROGS) +coretestprogs: testfixture$(BEXE) sqlite3$(BEXE) -testprogs: coretestprogs srcck1$(BEXE) fuzzcheck$(TEXE) sessionfuzz$(TEXE) +testprogs: $(TESTPROGS) srcck1$(BEXE) fuzzcheck$(TEXE) sessionfuzz$(TEXE) # A very detailed test running most or all test cases fulltest: alltest fuzztest diff --git a/Makefile.msc b/Makefile.msc index 31a9c57ebc..5257cee981 100644 --- a/Makefile.msc +++ b/Makefile.msc @@ -2496,9 +2496,9 @@ extensiontest: testfixture.exe testloadext.dll tool-zip: testfixture.exe sqlite3.exe sqldiff.exe sqlite3_analyzer.exe $(TOP)\tool\mktoolzip.tcl .\testfixture.exe $(TOP)\tool\mktoolzip.tcl -coretestprogs: $(TESTPROGS) +coretestprogs: testfixture.exe sqlite3.exe -testprogs: coretestprogs srcck1.exe fuzzcheck.exe sessionfuzz.exe +testprogs: $(TESTPROGS) srcck1.exe fuzzcheck.exe sessionfuzz.exe fulltest: alltest fuzztest diff --git a/manifest b/manifest index 49e6d916e1..d8e6bebb99 100644 --- a/manifest +++ b/manifest @@ -1,11 +1,11 @@ -C Fix\sthe\s".import"\scommand\sin\sthe\sCLI\sso\sthat\sit\sworks\scorrectly\swith\stables\nthat\scontain\scomputed\scolumns.\n[forum:/forumpost/ca014d7358|forum\spost\sca014d7358]. -D 2024-03-11T11:24:59.268 +C Run\sshell*.test\smodules\swith\s"make\smdevtest". +D 2024-03-11T18:21:02.927 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 -F Makefile.in ca8b906b1c3285fc32cff9978a5b827f99ae3d440077babf32c257a92a2ba11c +F Makefile.in 5f2389d2a3c44b56621bb5156a9cb6e2bef01f7ec14a19335b1559cf0474bdde F Makefile.linux-gcc f3842a0b1efbfbb74ac0ef60e56b301836d05b4d867d014f714fa750048f1ab6 -F Makefile.msc 7d88d6a654d86e6a1bede090f67d633d0a57c73e591d772fce8e15bfb07147f8 +F Makefile.msc e64a52619310d3067f6c38f56eedd15918a82dade70954197d6da486ad99d7f4 F README.md 6358805260a03ebead84e168bbf3740ddf3f683b477e478567186aa7afb490d3 F VERSION c84541c6a9e8426462176fbb1f9ecb5cfd7d1bb56228053ff7eeba8841673eb6 F aclocal.m4 a5c22d164aff7ed549d53a90fa56d56955281f50 @@ -1687,7 +1687,7 @@ F test/temptable2.test 76821347810ecc88203e6ef0dd6897b6036ac788e9dd3e6b04fd4d163 F test/temptable3.test d11a0974e52b347e45ee54ef1923c91ed91e4637 F test/temptrigger.test 38f0ca479b1822d3117069e014daabcaacefffcc F test/tester.tcl fe617b88c7eb08bdf983d2aaa31c20fbf439eee7b8e0d61ca636fcd0c305bbbf -F test/testrunner.tcl 8e2a5c7550b78d3283eee6103104ae2bcf56aa1df892dbd1608f27b93ebf4de8 +F test/testrunner.tcl 277bf6ed811b1f07796eedf8b5740ef521fc7fa99bd50faad9760a1fa53653b3 F test/testrunner_data.tcl 7ffd951527bbc614e723fd8d123b6834321878530696adecfdf6035100bac64e F test/thread001.test a0985c117eab62c0c65526e9fa5d1360dd1cac5b03bde223902763274ce21899 F test/thread002.test c24c83408e35ba5a952a3638b7ac03ccdf1ce4409289c54a050ac4c5f1de7502 @@ -2177,8 +2177,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P cb8d9c269c01f78f09069a2361e15087d9aeac63e9f1fd63fbd96b951384e9aa -R 9bba8f8b4bc3bf41627766fe1aa44b9c +P 95a9c88b258f18ac671a4c712603931167cc8bd0b86e41481b200c08043338b5 +R 29b12e6b8f2a6bc2a8ea9a08c15b926a U drh -Z 1d2e3bf230fd6cd6fbc6ff6c84cfd8fb +Z a3f33edbc2a09bf20230f9f2220bf336 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index c57a5b98bf..d3cdb542bf 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -95a9c88b258f18ac671a4c712603931167cc8bd0b86e41481b200c08043338b5 \ No newline at end of file +76c471061809307c1922a9460f1ea37291ff5f4dc11a71af594351e875fdc8e3 \ No newline at end of file diff --git a/test/testrunner.tcl b/test/testrunner.tcl index 0c704daf21..b5bd54e2b1 100644 --- a/test/testrunner.tcl +++ b/test/testrunner.tcl @@ -681,13 +681,22 @@ proc add_build_job {buildname target} { set dirname "[string tolower [string map {- _} $buildname]]_$target" set dirname "testrunner_bld_$dirname" + switch $target { + testfixture - + testfixture.exe { + set mktarget coretestprogs + } + default { + set mktarget $target + } + } set id [add_job \ -displaytype bld \ -displayname "Build $buildname ($target)" \ -dirname $dirname \ -build $buildname \ - -cmd "$TRG(makecmd) $target" \ + -cmd "$TRG(makecmd) $mktarget" \ -priority 3 ] From 2dbf276e93ecbeb3c067806c8c823cc4da87c2fc Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 11 Mar 2024 19:33:55 +0000 Subject: [PATCH 200/430] Update mdevtest and sdevtest to do shell builds in parallel. And only if one or more of the tcl scripts run requires it. FossilOrigin-Name: 6eae4547d4d50c798d1f05eaa1da02f4682d261dbd64e94748179923839024e6 --- ext/expert/expert1.test | 1 + manifest | 38 ++++++++++++------------ manifest.uuid | 2 +- test/avfs.test | 1 + test/recover.test | 1 + test/shell1.test | 1 + test/shell2.test | 1 + test/shell3.test | 1 + test/shell4.test | 1 + test/shell5.test | 1 + test/shell6.test | 1 + test/shell7.test | 1 + test/shell8.test | 1 + test/shell9.test | 1 + test/testrunner.tcl | 65 ++++++++++++++++++++++++++++++++--------- 15 files changed, 83 insertions(+), 34 deletions(-) diff --git a/ext/expert/expert1.test b/ext/expert/expert1.test index 453334234d..c456c30c52 100644 --- a/ext/expert/expert1.test +++ b/ext/expert/expert1.test @@ -8,6 +8,7 @@ # May you share freely, never taking more than you give. # #*********************************************************************** +# TESTRUNNER: shell # # The focus of this file is testing the CLI shell tool. Specifically, # the ".recommend" command. diff --git a/manifest b/manifest index d8e6bebb99..ccb451459a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Run\sshell*.test\smodules\swith\s"make\smdevtest". -D 2024-03-11T18:21:02.927 +C Update\smdevtest\sand\ssdevtest\sto\sdo\sshell\sbuilds\sin\sparallel.\sAnd\sonly\sif\sone\sor\smore\sof\sthe\stcl\sscripts\srun\srequires\sit. +D 2024-03-11T19:33:55.704 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -57,7 +57,7 @@ F ext/consio/console_io.c f32b757c9ee7fdf68e7586bee306f8368759e7cd12febb2a683919 F ext/consio/console_io.h 0548b83d7c4b7270ad544a67f2bb90cebc519637fa39b1838df4744cf0d87646 F ext/expert/README.md b321c2762bb93c18ea102d5a5f7753a4b8bac646cb392b3b437f633caf2020c3 F ext/expert/expert.c d548d603a4cc9e61f446cc179c120c6713511c413f82a4a32b1e1e69d3f086a4 -F ext/expert/expert1.test 0dd5cb096d66bed593e33053a3b364f6ef52ed72064bf5cf298364636dbf3cd6 +F ext/expert/expert1.test 53a749de08939e3bc14f804e97410927d46fa772cbce0247d7e8fa6fc2523b0c F ext/expert/sqlite3expert.c c8cea5ff15fbe792cccc4992a9b40b706411c41d32611f617897fecac6ff06a4 F ext/expert/sqlite3expert.h ca81efc2679a92373a13a3e76a6138d0310e32be53d6c3bfaedabd158ea8969b F ext/expert/test_expert.c d56c194b769bdc90cf829a14c9ecbc1edca9c850b837a4d0b13be14095c32a72 @@ -911,7 +911,7 @@ F test/autoindex5.test 2ee94f033b87ca0160e08d81034c507aff8e230df2627f0304fa309b2 F test/autovacuum.test 00671369bbf96c6a49989a9425f5b78b94075d6a4b031e5e00000c2c32f365df F test/autovacuum2.test 76f7eb4fe6a6bf6d33a196a7141dba98886d2fb53a268d7feca285d5da4759d7 F test/autovacuum_ioerr2.test 8a367b224183ad801e0e24dcb7d1501f45f244b4 -F test/avfs.test 0c3a38e03cccb0fc3127838462dc05dc3f4c1480d770c084b388304c25de3652 +F test/avfs.test 76f59743dc1f5fa533840d1818b420fe1ee45e21c0fd6bbac7942ba677903128 F test/avtrans.test b7dc25459ecbd86c6fa9c606ee3068f59d81e225118617dcf2bbb6ded2ade89e F test/backcompat.test 3e64cedda754c778ef6bbe417b6e7a295e662a4d F test/backup.test 3b08fd4af69f0fa786931103a31f4542b184aba16e239e5f22b18c3c2476697f @@ -1520,7 +1520,7 @@ F test/randexpr1.tcl 40dec52119ed3a2b8b2a773bce24b63a3a746459 F test/randexpr1.test eda062a97e60f9c38ae8d806b03b0ddf23d796df F test/rbu.test 168573d353cd0fd10196b87b0caa322c144ef736 F test/rdonly.test 64e2696c322e3538df0b1ed624e21f9a23ed9ff8 -F test/recover.test fd5199f928757cb308661b5fdca1abc19398a798ff7f24b57c3071e9f8e0471e +F test/recover.test 6463509a7404e0c35431dd9b4a1c3b4a29d7a6af8a08462b31670c8a5a616d3a F test/regexp1.test 8f2a8bc1569666e29a4cee6c1a666cd224eb6d50e2470d1dc1df995170f3e0f1 F test/regexp2.test 55ed41da802b0e284ac7e2fe944be3948f93ff25abbca0361a609acfed1368b5 F test/reindex.test cd9d6021729910ece82267b4f5e1b5ac2911a7566c43b43c176a6a4732e2118d @@ -1600,15 +1600,15 @@ F test/sharedA.test 64bdd21216dda2c6a3bd3475348ccdc108160f34682c97f2f51c19fc0e21 F test/sharedB.test 1a84863d7a2204e0d42f2e1606577c5e92e4473fa37ea0f5bdf829e4bf8ee707 F test/shared_err.test 32634e404a3317eeb94abc7a099c556a346fdb8fb3858dbe222a4cbb8926a939 F test/sharedlock.test 5ede3c37439067c43b0198f580fd374ebf15d304 -F test/shell1.test c7127a5e780ffc9e14c476773127fdf292c6db226529c44c1676f37b3793123f -F test/shell2.test 35226c070a8c7f64fd016dfac2a0db2a40f709b3131f61daacd9dad61536c9cb -F test/shell3.test 91febeac0412812bf6370abb8ed72700e32bf8f9878849414518f662dfd55e8a -F test/shell4.test 947029e5a9efae9054d424b309fc0311439c0c3a0866ebfa3b8a771120708220 -F test/shell5.test 263bfd6a49049295277e3f5bdc221390dc5e72f39954b23d43204ed81993304f -F test/shell6.test 1ceb51b2678c472ba6cf1e5da96679ce8347889fe2c3bf93a0e0fa73f00b00d3 -F test/shell7.test 115132f66d0463417f408562cc2cf534f6bbc6d83a6d50f0072a9eb171bae97f -F test/shell8.test 3fd093d481aaa94dc77fb73f1044c1f19c7efe3477a395cc4f7450133bc54915 -F test/shell9.test f457a96c088344908e0518dbabffd02eda8ac2a8733f278679e5f47c103efbab +F test/shell1.test 17a5ca9c6f24f807b2f505b4b38fcbce143d96cd8664c06c34bbbe0672bf7c30 +F test/shell2.test 56da24128304c9ab67da2964cc80beff7b35761c446ec6e6e98bff2775b15026 +F test/shell3.test 5ad4b2813717956414f2c0c8a2027895cd98ccf7dd54dbacbde4d4f5591ce5a1 +F test/shell4.test 522fdc628c55eff697b061504fb0a9e4e6dfc5d9087a633ab0f3dd11bcc4f807 +F test/shell5.test 5b2ab1c0540217773f939927c24163a56257446da3f564d4724042620bfea762 +F test/shell6.test e3b883b61d4916b6906678a35f9d19054861123ad91b856461e0a456273bdbb8 +F test/shell7.test 753c6ece5361df50025a50cadf378ea36db9cc05fb23d7a96cff7fa130626ef9 +F test/shell8.test 9b71d56a6f6fc62edd9163534ac21eaa328ad95f1b9026e7bd08d5b4621eacf6 +F test/shell9.test 8742a5b390cdcef6369f5aa223e415aa4255a4129ef249b177887dc635a87209 F test/shmlock.test 3dbf017d34ab0c60abe6a44e447d3552154bd0c87b41eaf5ceacd408dd13fda5 F test/shortread1.test bb591ef20f0fd9ed26d0d12e80eee6d7ac8897a3 F test/show_speedtest1_rtree.tcl 32e6c5f073d7426148a6936a0408f4b5b169aba5 @@ -1687,7 +1687,7 @@ F test/temptable2.test 76821347810ecc88203e6ef0dd6897b6036ac788e9dd3e6b04fd4d163 F test/temptable3.test d11a0974e52b347e45ee54ef1923c91ed91e4637 F test/temptrigger.test 38f0ca479b1822d3117069e014daabcaacefffcc F test/tester.tcl fe617b88c7eb08bdf983d2aaa31c20fbf439eee7b8e0d61ca636fcd0c305bbbf -F test/testrunner.tcl 277bf6ed811b1f07796eedf8b5740ef521fc7fa99bd50faad9760a1fa53653b3 +F test/testrunner.tcl 742a86037556cc6a9e51b5598955fcfc7a610a187ca257791c320b13ce2d5232 F test/testrunner_data.tcl 7ffd951527bbc614e723fd8d123b6834321878530696adecfdf6035100bac64e F test/thread001.test a0985c117eab62c0c65526e9fa5d1360dd1cac5b03bde223902763274ce21899 F test/thread002.test c24c83408e35ba5a952a3638b7ac03ccdf1ce4409289c54a050ac4c5f1de7502 @@ -2177,8 +2177,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 95a9c88b258f18ac671a4c712603931167cc8bd0b86e41481b200c08043338b5 -R 29b12e6b8f2a6bc2a8ea9a08c15b926a -U drh -Z a3f33edbc2a09bf20230f9f2220bf336 +P 76c471061809307c1922a9460f1ea37291ff5f4dc11a71af594351e875fdc8e3 +R 3a2de83b3312aef9322c95d69c88f610 +U dan +Z ad568019dcaf7d3ff511c52e874411fe # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index d3cdb542bf..b517c05b4d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -76c471061809307c1922a9460f1ea37291ff5f4dc11a71af594351e875fdc8e3 \ No newline at end of file +6eae4547d4d50c798d1f05eaa1da02f4682d261dbd64e94748179923839024e6 \ No newline at end of file diff --git a/test/avfs.test b/test/avfs.test index 2ebd608baa..ffd6b309fc 100644 --- a/test/avfs.test +++ b/test/avfs.test @@ -8,6 +8,7 @@ # May you share freely, never taking more than you give. # #*********************************************************************** +# TESTRUNNER: shell # # This file implements tests for the appendvfs extension. # diff --git a/test/recover.test b/test/recover.test index 8d9ad013c0..5495b7a006 100644 --- a/test/recover.test +++ b/test/recover.test @@ -8,6 +8,7 @@ # May you share freely, never taking more than you give. # #*********************************************************************** +# TESTRUNNER: shell # # Test the shell tool ".ar" command. # diff --git a/test/shell1.test b/test/shell1.test index 5d4243f47a..206fb0a4fd 100644 --- a/test/shell1.test +++ b/test/shell1.test @@ -11,6 +11,7 @@ # # The focus of this file is testing the CLI shell tool. # +# TESTRUNNER: shell # # Test plan: diff --git a/test/shell2.test b/test/shell2.test index 16ed33c442..c6c27d2165 100644 --- a/test/shell2.test +++ b/test/shell2.test @@ -8,6 +8,7 @@ # May you share freely, never taking more than you give. # #*********************************************************************** +# TESTRUNNER: shell # # The focus of this file is testing the CLI shell tool. # diff --git a/test/shell3.test b/test/shell3.test index f8d69946e7..c1ea9f6a75 100644 --- a/test/shell3.test +++ b/test/shell3.test @@ -8,6 +8,7 @@ # May you share freely, never taking more than you give. # #*********************************************************************** +# TESTRUNNER: shell # # The focus of this file is testing the CLI shell tool. # diff --git a/test/shell4.test b/test/shell4.test index eee59b02b8..4b7e9b8eec 100644 --- a/test/shell4.test +++ b/test/shell4.test @@ -8,6 +8,7 @@ # May you share freely, never taking more than you give. # #*********************************************************************** +# TESTRUNNER: shell # # The focus of this file is testing the CLI shell tool. # These tests are specific to the .stats command. diff --git a/test/shell5.test b/test/shell5.test index 20f2ba219d..877676d726 100644 --- a/test/shell5.test +++ b/test/shell5.test @@ -8,6 +8,7 @@ # May you share freely, never taking more than you give. # #*********************************************************************** +# TESTRUNNER: shell # # The focus of this file is testing the CLI shell tool. # These tests are specific to the .import command. diff --git a/test/shell6.test b/test/shell6.test index 49b4cc3344..4841d6c01a 100644 --- a/test/shell6.test +++ b/test/shell6.test @@ -8,6 +8,7 @@ # May you share freely, never taking more than you give. # #*********************************************************************** +# TESTRUNNER: shell # # Test the shell tool ".lint fkey-indexes" command. # diff --git a/test/shell7.test b/test/shell7.test index 898018d775..dfd9e47c2d 100644 --- a/test/shell7.test +++ b/test/shell7.test @@ -8,6 +8,7 @@ # May you share freely, never taking more than you give. # #*********************************************************************** +# TESTRUNNER: shell # # Test the readfile() function built into the shell tool. Specifically, # that it does not truncate the blob read at the first embedded 0x00 diff --git a/test/shell8.test b/test/shell8.test index bee6039232..944173a2a1 100644 --- a/test/shell8.test +++ b/test/shell8.test @@ -8,6 +8,7 @@ # May you share freely, never taking more than you give. # #*********************************************************************** +# TESTRUNNER: shell # # Test the shell tool ".ar" command. # diff --git a/test/shell9.test b/test/shell9.test index 34c9d8c5d6..869cb075da 100644 --- a/test/shell9.test +++ b/test/shell9.test @@ -8,6 +8,7 @@ # May you share freely, never taking more than you give. # #*********************************************************************** +# TESTRUNNER: shell # # The focus of this file is testing the CLI shell tool. Specifically, # testing that it is possible to run a ".dump" script that creates diff --git a/test/testrunner.tcl b/test/testrunner.tcl index b5bd54e2b1..dd909ea186 100644 --- a/test/testrunner.tcl +++ b/test/testrunner.tcl @@ -159,6 +159,7 @@ switch -nocase -glob -- $tcl_platform(os) { set TRG(make) make.sh set TRG(makecmd) "bash make.sh" set TRG(testfixture) testfixture + set TRG(shell) sqlite3 set TRG(run) run.sh set TRG(runcmd) "bash run.sh" } @@ -167,6 +168,7 @@ switch -nocase -glob -- $tcl_platform(os) { set TRG(make) make.sh set TRG(makecmd) "bash make.sh" set TRG(testfixture) testfixture + set TRG(shell) sqlite3 set TRG(run) run.sh set TRG(runcmd) "bash run.sh" } @@ -175,6 +177,7 @@ switch -nocase -glob -- $tcl_platform(os) { set TRG(make) make.bat set TRG(makecmd) make.bat set TRG(testfixture) testfixture.exe + set TRG(shell) sqlite3.exe set TRG(run) run.bat set TRG(runcmd) "run.bat" } @@ -617,7 +620,16 @@ proc add_job {args} { trdb last_insert_rowid } -proc add_tcl_jobs {build config patternlist} { +# Argument $build is either an empty string, or else a list of length 3 +# describing the job to build testfixture. In the usual form: +# +# {ID DIRNAME DISPLAYNAME} +# +# e.g +# +# {1 /home/user/sqlite/test/testrunner_bld_xyz All-Debug} +# +proc add_tcl_jobs {build config patternlist {shelldepid ""}} { global TRG set topdir [file dirname $::testdir] @@ -666,29 +678,28 @@ proc add_tcl_jobs {build config patternlist} { if {[lsearch $lProp slow]>=0} { set priority 2 } if {[lsearch $lProp superslow]>=0} { set priority 4 } + set depid [lindex $build 0] + if {$shelldepid!="" && [lsearch $lProp shell]>=0} { set depid $shelldepid } + add_job \ -displaytype tcl \ -displayname $displayname \ -cmd $cmd \ - -depid [lindex $build 0] \ + -depid $depid \ -priority $priority - } } -proc add_build_job {buildname target} { +proc add_build_job {buildname target {postcmd ""} {depid ""}} { global TRG set dirname "[string tolower [string map {- _} $buildname]]_$target" set dirname "testrunner_bld_$dirname" - switch $target { - testfixture - - testfixture.exe { - set mktarget coretestprogs - } - default { - set mktarget $target - } + + set cmd "$TRG(makecmd) $target" + if {$postcmd!=""} { + append cmd "\n" + append cmd $postcmd } set id [add_job \ @@ -696,13 +707,30 @@ proc add_build_job {buildname target} { -displayname "Build $buildname ($target)" \ -dirname $dirname \ -build $buildname \ - -cmd "$TRG(makecmd) $mktarget" \ + -cmd $cmd \ + -depid $depid \ -priority 3 ] list $id [file normalize $dirname] $buildname } +proc add_shell_build_job {buildname dirname depid} { + global TRG + + if {$TRG(platform)=="win"} { + set path [string map {/ \\} "$dirname/" + set copycmd "xcopy /S $TRG(shell) $path" + } else { + set copycmd "cp $TRG(shell) $dirname/" + } + + return [ + add_build_job $buildname $TRG(shell) $copycmd $depid + ] +} + + proc add_make_job {bld target} { global TRG @@ -776,10 +804,19 @@ proc add_devtest_jobs {lBld patternlist} { foreach b $lBld { set bld [add_build_job $b $TRG(testfixture)] - add_tcl_jobs $bld veryquick $patternlist + add_tcl_jobs $bld veryquick $patternlist SHELL if {$patternlist==""} { add_fuzztest_jobs $b } + + if {[trdb one "SELECT EXISTS (SELECT 1 FROM jobs WHERE depid='SHELL')"]} { + set sbld [add_shell_build_job $b [lindex $bld 1] [lindex $bld 0]] + set sbldid [lindex $sbld 0] + trdb eval { + UPDATE jobs SET depid=$sbldid WHERE depid='SHELL' + } + } + } } From f4783d4d7fab71d05b76a0e88448f7042a50086c Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 11 Mar 2024 19:43:43 +0000 Subject: [PATCH 201/430] Fix a missing brace problem in testrunner.tcl introduced by the previous commit. FossilOrigin-Name: 1f5e334d98d98cd90a2fb53502015a883d96fed05c04c1c3e1e78c302bede50f --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/testrunner.tcl | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index ccb451459a..ac3fa0c2bd 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Update\smdevtest\sand\ssdevtest\sto\sdo\sshell\sbuilds\sin\sparallel.\sAnd\sonly\sif\sone\sor\smore\sof\sthe\stcl\sscripts\srun\srequires\sit. -D 2024-03-11T19:33:55.704 +C Fix\sa\smissing\sbrace\sproblem\sin\stestrunner.tcl\sintroduced\sby\sthe\sprevious\scommit. +D 2024-03-11T19:43:43.289 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -1687,7 +1687,7 @@ F test/temptable2.test 76821347810ecc88203e6ef0dd6897b6036ac788e9dd3e6b04fd4d163 F test/temptable3.test d11a0974e52b347e45ee54ef1923c91ed91e4637 F test/temptrigger.test 38f0ca479b1822d3117069e014daabcaacefffcc F test/tester.tcl fe617b88c7eb08bdf983d2aaa31c20fbf439eee7b8e0d61ca636fcd0c305bbbf -F test/testrunner.tcl 742a86037556cc6a9e51b5598955fcfc7a610a187ca257791c320b13ce2d5232 +F test/testrunner.tcl dc2e0d1256292f098f247a0ac33f1ad1be70e3d474bdd064c99b06637b116d3f F test/testrunner_data.tcl 7ffd951527bbc614e723fd8d123b6834321878530696adecfdf6035100bac64e F test/thread001.test a0985c117eab62c0c65526e9fa5d1360dd1cac5b03bde223902763274ce21899 F test/thread002.test c24c83408e35ba5a952a3638b7ac03ccdf1ce4409289c54a050ac4c5f1de7502 @@ -2177,8 +2177,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 76c471061809307c1922a9460f1ea37291ff5f4dc11a71af594351e875fdc8e3 -R 3a2de83b3312aef9322c95d69c88f610 +P 6eae4547d4d50c798d1f05eaa1da02f4682d261dbd64e94748179923839024e6 +R ffb80cc7c28af1ee50c0fc7e45c14ced U dan -Z ad568019dcaf7d3ff511c52e874411fe +Z da9cdae477120048435de0332185ec30 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index b517c05b4d..01d0a91a04 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6eae4547d4d50c798d1f05eaa1da02f4682d261dbd64e94748179923839024e6 \ No newline at end of file +1f5e334d98d98cd90a2fb53502015a883d96fed05c04c1c3e1e78c302bede50f \ No newline at end of file diff --git a/test/testrunner.tcl b/test/testrunner.tcl index dd909ea186..170e0457cc 100644 --- a/test/testrunner.tcl +++ b/test/testrunner.tcl @@ -719,7 +719,7 @@ proc add_shell_build_job {buildname dirname depid} { global TRG if {$TRG(platform)=="win"} { - set path [string map {/ \\} "$dirname/" + set path [string map {/ \\} "$dirname/"] set copycmd "xcopy /S $TRG(shell) $path" } else { set copycmd "cp $TRG(shell) $dirname/" From 38152d9d04c4db92e871ef24bed43be2232c134b Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 11 Mar 2024 20:34:02 +0000 Subject: [PATCH 202/430] Fix another testrunner.tcl problem on windows. FossilOrigin-Name: 7805844bc4433ae088dae6d54eb972e082c5a3df06e844cfc8b69e7d97aeb432 --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/testrunner.tcl | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index ac3fa0c2bd..5731f2374e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\smissing\sbrace\sproblem\sin\stestrunner.tcl\sintroduced\sby\sthe\sprevious\scommit. -D 2024-03-11T19:43:43.289 +C Fix\sanother\stestrunner.tcl\sproblem\son\swindows. +D 2024-03-11T20:34:02.340 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -1687,7 +1687,7 @@ F test/temptable2.test 76821347810ecc88203e6ef0dd6897b6036ac788e9dd3e6b04fd4d163 F test/temptable3.test d11a0974e52b347e45ee54ef1923c91ed91e4637 F test/temptrigger.test 38f0ca479b1822d3117069e014daabcaacefffcc F test/tester.tcl fe617b88c7eb08bdf983d2aaa31c20fbf439eee7b8e0d61ca636fcd0c305bbbf -F test/testrunner.tcl dc2e0d1256292f098f247a0ac33f1ad1be70e3d474bdd064c99b06637b116d3f +F test/testrunner.tcl 283be0c85bd132136ed564a99227b946194c31a0658df43c22a5e86956b70b43 F test/testrunner_data.tcl 7ffd951527bbc614e723fd8d123b6834321878530696adecfdf6035100bac64e F test/thread001.test a0985c117eab62c0c65526e9fa5d1360dd1cac5b03bde223902763274ce21899 F test/thread002.test c24c83408e35ba5a952a3638b7ac03ccdf1ce4409289c54a050ac4c5f1de7502 @@ -2177,8 +2177,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 6eae4547d4d50c798d1f05eaa1da02f4682d261dbd64e94748179923839024e6 -R ffb80cc7c28af1ee50c0fc7e45c14ced +P 1f5e334d98d98cd90a2fb53502015a883d96fed05c04c1c3e1e78c302bede50f +R 3329f7728eccdd894e074db61e3ec3e5 U dan -Z da9cdae477120048435de0332185ec30 +Z 4fb36ca27e18f07178be9aab3a444f9c # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 01d0a91a04..cf0788db21 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1f5e334d98d98cd90a2fb53502015a883d96fed05c04c1c3e1e78c302bede50f \ No newline at end of file +7805844bc4433ae088dae6d54eb972e082c5a3df06e844cfc8b69e7d97aeb432 \ No newline at end of file diff --git a/test/testrunner.tcl b/test/testrunner.tcl index 170e0457cc..daf7457170 100644 --- a/test/testrunner.tcl +++ b/test/testrunner.tcl @@ -175,7 +175,7 @@ switch -nocase -glob -- $tcl_platform(os) { *win* { set TRG(platform) win set TRG(make) make.bat - set TRG(makecmd) make.bat + set TRG(makecmd) "call make.bat" set TRG(testfixture) testfixture.exe set TRG(shell) sqlite3.exe set TRG(run) run.bat @@ -720,7 +720,7 @@ proc add_shell_build_job {buildname dirname depid} { if {$TRG(platform)=="win"} { set path [string map {/ \\} "$dirname/"] - set copycmd "xcopy /S $TRG(shell) $path" + set copycmd "xcopy $TRG(shell) $path" } else { set copycmd "cp $TRG(shell) $dirname/" } From 3ac5c0818073382eaaec5acca38925dcd8e4d52f Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 12 Mar 2024 18:04:40 +0000 Subject: [PATCH 203/430] Have testrunner.tcl have each test store its temp files in its working directory. To avoid unlikely, but possible, collisions. FossilOrigin-Name: 775a10d10b9bf2227071e778718ba4054d4b2b4238751eb147338d687b4e0d58 --- manifest | 15 +++++++++------ manifest.uuid | 2 +- test/testrunner.tcl | 7 ++++++- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 5731f2374e..e4db435c3e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sanother\stestrunner.tcl\sproblem\son\swindows. -D 2024-03-11T20:34:02.340 +C Have\stestrunner.tcl\shave\seach\stest\sstore\sits\stemp\sfiles\sin\sits\sworking\sdirectory.\sTo\savoid\sunlikely,\sbut\spossible,\scollisions. +D 2024-03-12T18:04:40.495 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -1687,7 +1687,7 @@ F test/temptable2.test 76821347810ecc88203e6ef0dd6897b6036ac788e9dd3e6b04fd4d163 F test/temptable3.test d11a0974e52b347e45ee54ef1923c91ed91e4637 F test/temptrigger.test 38f0ca479b1822d3117069e014daabcaacefffcc F test/tester.tcl fe617b88c7eb08bdf983d2aaa31c20fbf439eee7b8e0d61ca636fcd0c305bbbf -F test/testrunner.tcl 283be0c85bd132136ed564a99227b946194c31a0658df43c22a5e86956b70b43 +F test/testrunner.tcl 9fb1341f4a3fcc169b0cffa2f319abde197a738d98131d178a81509a0638f2df F test/testrunner_data.tcl 7ffd951527bbc614e723fd8d123b6834321878530696adecfdf6035100bac64e F test/thread001.test a0985c117eab62c0c65526e9fa5d1360dd1cac5b03bde223902763274ce21899 F test/thread002.test c24c83408e35ba5a952a3638b7ac03ccdf1ce4409289c54a050ac4c5f1de7502 @@ -2177,8 +2177,11 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 1f5e334d98d98cd90a2fb53502015a883d96fed05c04c1c3e1e78c302bede50f -R 3329f7728eccdd894e074db61e3ec3e5 +P 7805844bc4433ae088dae6d54eb972e082c5a3df06e844cfc8b69e7d97aeb432 +R 9fe0d14be342ac1becb45016c9700f68 +T *branch * testrunner-tmpdir-fix +T *sym-testrunner-tmpdir-fix * +T -sym-trunk * U dan -Z 4fb36ca27e18f07178be9aab3a444f9c +Z 7a40c29cf47919cba49700f99392c55a # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index cf0788db21..1af80e0611 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7805844bc4433ae088dae6d54eb972e082c5a3df06e844cfc8b69e7d97aeb432 \ No newline at end of file +775a10d10b9bf2227071e778718ba4054d4b2b4238751eb147338d687b4e0d58 \ No newline at end of file diff --git a/test/testrunner.tcl b/test/testrunner.tcl index daf7457170..7dbfc251de 100644 --- a/test/testrunner.tcl +++ b/test/testrunner.tcl @@ -994,6 +994,11 @@ proc launch_another_job {iJob} { close $fd } + set job_cmd $job(cmd) + if {$TRG(platform)!="win"} { + set job_cmd "export SQLITE_TMPDIR=\"[file normalize $dir]\"\n$job_cmd" + } + if { $TRG(dryrun) } { mark_job_as_finished $job(jobid) "" done 0 @@ -1008,7 +1013,7 @@ proc launch_another_job {iJob} { set pwd [pwd] cd $dir set fd [open $TRG(run) w] - puts $fd $job(cmd) + puts $fd $job_cmd close $fd set fd [open "|$TRG(runcmd) 2>@1" r] cd $pwd From 5badd048d2e63b900683eefd01a3427a3d82b277 Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 12 Mar 2024 20:10:46 +0000 Subject: [PATCH 204/430] Correctly initialize the SrcItem.iCursor field to -1 when creating a co-routine from a multi-values VALUES clause. FossilOrigin-Name: c32953ff6d72910815eaff29ab1b790c412e1a741d02c03c5911dda0c08e5130 --- manifest | 17 +++++++---------- manifest.uuid | 2 +- src/insert.c | 1 + test/values.test | 11 +++++++++++ 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index afde134bd1..ae283f24ef 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Attempt\sto\sreduce\sthe\smemory\sused\sby\sVALUES\sclauses\sin\sas\smany\sstatements\sas\spossible,\snot\sjust\sINSERT.\sThis\sbranch\sstill\shas\sproblems. -D 2024-03-11T17:27:19.668 +C Correctly\sinitialize\sthe\sSrcItem.iCursor\sfield\sto\s-1\swhen\screating\sa\sco-routine\sfrom\sa\smulti-values\sVALUES\sclause. +D 2024-03-12T20:10:46.651 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -709,7 +709,7 @@ F src/hash.c 9ee4269fb1d6632a6fecfb9479c93a1f29271bddbbaf215dd60420bcb80c7220 F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 -F src/insert.c 2c34cf51e9d8c00498ba68b7f130e448038bb31f624c9c1ca80fa8e3237b51fb +F src/insert.c 9d48439a0fff35d3c4850bc9ab3657f9d45b2800af52ef3b083e7068e32d8aa2 F src/json.c e2e40760d6689134c3e2ece38c6a496b34ff5e2661a8f238444a119af666fdce F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 @@ -1921,7 +1921,7 @@ F test/vacuum4.test 7ea76b769fffeb41f925303b04cbcf5a5bbeabe55e4c60ae754ff24eeeb7 F test/vacuum5.test 263b144d537e92ad8e9ca8a73cc6e1583f41cfd0dda9432b87f7806174a2f48c F test/vacuum6.test b137b04bf3392d3f5c3b8fda0ce85a6775a70ca112f6559f74ff52dc9ce042fd F test/vacuummem.test 4b30f5b95a9ff86e9d5c20741e50a898b2dc10b0962a3211571eb165357003fb -F test/values.test 8438dea6826738291ff2019993d62e1eae7a3efb66ea8312fa9ac9bfaf0f95cb +F test/values.test 042f30d897d3b2bfa54dc89a48ef6c8f6ba3ffdfd4fc35c2cc877d28a1095ce3 F test/valuesfault.test 2ef23ed965e3bd08e268cdc38a0d11653390ddbbe1e8e2e98d16f55edd30f6e8 F test/varint.test bbce22cda8fc4d135bcc2b589574be8410614e62 F test/veryquick.test 57ab846bacf7b90cf4e9a672721ea5c5b669b661 @@ -2179,11 +2179,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 95a9c88b258f18ac671a4c712603931167cc8bd0b86e41481b200c08043338b5 -R 62b6db11e5c879766b23978dd0871f55 -T *branch * exp-values-clause2 -T *sym-exp-values-clause2 * -T -sym-trunk * +P 17d1f7cfabc7593d0725051b0c7c9619a23a482265f30f15ab9493fef5caeeb0 +R bc124d03e15c7cb41c52570d66be2e47 U dan -Z 521a450017e9a427470d7f09cc068c5e +Z 476dd3f62c65ec97a150406261356d2a # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 633c59c43c..bc849bef9a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -17d1f7cfabc7593d0725051b0c7c9619a23a482265f30f15ab9493fef5caeeb0 \ No newline at end of file +c32953ff6d72910815eaff29ab1b790c412e1a741d02c03c5911dda0c08e5130 \ No newline at end of file diff --git a/src/insert.c b/src/insert.c index 7b253e9262..071d9aeff9 100644 --- a/src/insert.c +++ b/src/insert.c @@ -635,6 +635,7 @@ Select *sqlite3MultiValues(Parse *pParse, Select *pLeft, ExprList *pRow){ p->fg.viaCoroutine = 1; p->addrFillSub = sqlite3VdbeCurrentAddr(v) + 1; p->regReturn = ++pParse->nMem; + p->iCursor = -1; sqlite3VdbeAddOp3(v,OP_InitCoroutine,p->regReturn,0,p->addrFillSub); sqlite3SelectDestInit(&dest, SRT_Coroutine, p->regReturn); diff --git a/test/values.test b/test/values.test index 66e29ef6f0..8df0e6138f 100644 --- a/test/values.test +++ b/test/values.test @@ -252,5 +252,16 @@ do_execsql_test 6.1 { SELECT ( VALUES( x ), ( x ) ) FROM t1; } {1 2} +#------------------------------------------------------------------------- +reset_db +do_execsql_test 6.0 { + CREATE TABLE t1(x); + INSERT INTO t1 VALUES('x'), ('y'); +} + +do_execsql_test 6.1 { + SELECT * FROM t1, (VALUES(1), (2)) +} {x 1 x 2 y 1 y 2} finish_test + From eea6bdce8453c07567f24b96e6ea3e1ea994940d Mon Sep 17 00:00:00 2001 From: drh <> Date: Wed, 13 Mar 2024 00:37:37 +0000 Subject: [PATCH 205/430] On testrunner.tcl: (1) Add the "help" command. (2) Add the "script" command to the help message. (3) Improve the error message generated by "script" when an incorrect CONFIG option is provided. FossilOrigin-Name: 1b7f0be44036fb90d763eabae84b95734e766f8010b39122f8787189308a7fc1 --- manifest | 17 ++++++++--------- manifest.uuid | 2 +- test/testrunner.tcl | 14 ++++++++++++++ test/testrunner_data.tcl | 8 ++++++-- 4 files changed, 29 insertions(+), 12 deletions(-) diff --git a/manifest b/manifest index 5da9367f47..ed93666844 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Have\stestrunner.tcl\shave\seach\stest\sstore\sits\stemp\sfiles\sin\sits\sworking\sdirectory.\sTo\savoid\sunlikely,\sbut\spossible,\scollisions. -D 2024-03-12T18:33:57.893 +C On\stestrunner.tcl:\s(1)\sAdd\sthe\s"help"\scommand.\s\s(2)\sAdd\sthe\s"script"\scommand\nto\sthe\shelp\smessage.\s\s(3)\sImprove\sthe\serror\smessage\sgenerated\sby\s"script"\swhen\nan\sincorrect\sCONFIG\soption\sis\sprovided. +D 2024-03-13T00:37:37.096 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -1687,8 +1687,8 @@ F test/temptable2.test 76821347810ecc88203e6ef0dd6897b6036ac788e9dd3e6b04fd4d163 F test/temptable3.test d11a0974e52b347e45ee54ef1923c91ed91e4637 F test/temptrigger.test 38f0ca479b1822d3117069e014daabcaacefffcc F test/tester.tcl fe617b88c7eb08bdf983d2aaa31c20fbf439eee7b8e0d61ca636fcd0c305bbbf -F test/testrunner.tcl 9fb1341f4a3fcc169b0cffa2f319abde197a738d98131d178a81509a0638f2df -F test/testrunner_data.tcl 7ffd951527bbc614e723fd8d123b6834321878530696adecfdf6035100bac64e +F test/testrunner.tcl 7cd31694a52affd636284b3e74ec10213c60e247ec71f56e9061cf669f897105 +F test/testrunner_data.tcl 2f94974e5e3a56af880be72f7a7fd239aa9d4ecf978625435fcc698319c927fa F test/thread001.test a0985c117eab62c0c65526e9fa5d1360dd1cac5b03bde223902763274ce21899 F test/thread002.test c24c83408e35ba5a952a3638b7ac03ccdf1ce4409289c54a050ac4c5f1de7502 F test/thread003.test ee4c9efc3b86a6a2767516a37bd64251272560a7 @@ -2177,9 +2177,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 7805844bc4433ae088dae6d54eb972e082c5a3df06e844cfc8b69e7d97aeb432 775a10d10b9bf2227071e778718ba4054d4b2b4238751eb147338d687b4e0d58 -R 9fe0d14be342ac1becb45016c9700f68 -T +closed 775a10d10b9bf2227071e778718ba4054d4b2b4238751eb147338d687b4e0d58 -U dan -Z d2698b4f4cd69108bc3174c8dffaf5d3 +P 18842d0d72048561312c2c83035c01253150e1fe1ff37160f266d24d41a01df3 +R a8f09c1fdaad1d594fe806932cdf9a66 +U drh +Z 2fb114f4336505cce7dafa69e9c32517 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 2770d1d0c4..dffe028c56 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -18842d0d72048561312c2c83035c01253150e1fe1ff37160f266d24d41a01df3 \ No newline at end of file +1b7f0be44036fb90d763eabae84b95734e766f8010b39122f8787189308a7fc1 \ No newline at end of file diff --git a/test/testrunner.tcl b/test/testrunner.tcl index 7dbfc251de..163ddc01e0 100644 --- a/test/testrunner.tcl +++ b/test/testrunner.tcl @@ -54,7 +54,9 @@ proc usage {} { Usage: $a0 ?SWITCHES? ?PERMUTATION? ?PATTERNS? $a0 PERMUTATION FILE + $a0 help $a0 njob ?NJOB? + $a0 script ?-msvc? CONFIG $a0 status where SWITCHES are: @@ -89,6 +91,10 @@ directory as a running testrunner.tcl script that is running tests. The "status" command prints a report describing the current state and progress of the tests. The "njob" command may be used to query or modify the number of sub-processes the test script uses to run tests. + +The "script" command outputs the script used to build a configuration. +Add the "-msvc" option for a Windows-compatible script. For a list of +available configurations enter "$a0 script help". }]] exit 1 @@ -329,6 +335,14 @@ if {([llength $argv]==2 || [llength $argv]==1) } #-------------------------------------------------------------------------- +#-------------------------------------------------------------------------- +# Check if this is the "help" command: +# +if {[string compare -nocase help [lindex $argv 0]]==0} { + usage +} +#-------------------------------------------------------------------------- + #-------------------------------------------------------------------------- # Check if this is the "script" command: # diff --git a/test/testrunner_data.tcl b/test/testrunner_data.tcl index 984c6d8272..f38abad589 100644 --- a/test/testrunner_data.tcl +++ b/test/testrunner_data.tcl @@ -598,7 +598,12 @@ proc trd_buildscript {config srcdir bMsvc} { # Ensure that the named configuration exists. if {![info exists build($config)]} { - error "No such build config: $config" + if {$config!="help"} { + puts "No such build config: $config" + } + puts "Available configurations: [lsort [array names build]]" + flush stdout + exit 1 } # Generate and return the script. @@ -637,4 +642,3 @@ proc trd_test_script_properties {path} { set trd_test_script_properties_cache($path) } - From 3de08a6ee0eb5eeb3d5b0008946ea606dcd8eee3 Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 13 Mar 2024 10:47:54 +0000 Subject: [PATCH 206/430] Have testrunner.tcl set SQLITE_TMPDIR on windows as well. FossilOrigin-Name: 64f4dad1f928716b8688c650d043f18afcc72ec78d990145c580e2b98905b919 --- manifest | 14 +++++++------- manifest.uuid | 2 +- test/testrunner.tcl | 14 ++++++++++---- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/manifest b/manifest index ed93666844..2735ee46af 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C On\stestrunner.tcl:\s(1)\sAdd\sthe\s"help"\scommand.\s\s(2)\sAdd\sthe\s"script"\scommand\nto\sthe\shelp\smessage.\s\s(3)\sImprove\sthe\serror\smessage\sgenerated\sby\s"script"\swhen\nan\sincorrect\sCONFIG\soption\sis\sprovided. -D 2024-03-13T00:37:37.096 +C Have\stestrunner.tcl\sset\sSQLITE_TMPDIR\son\swindows\sas\swell. +D 2024-03-13T10:47:54.860 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -1687,7 +1687,7 @@ F test/temptable2.test 76821347810ecc88203e6ef0dd6897b6036ac788e9dd3e6b04fd4d163 F test/temptable3.test d11a0974e52b347e45ee54ef1923c91ed91e4637 F test/temptrigger.test 38f0ca479b1822d3117069e014daabcaacefffcc F test/tester.tcl fe617b88c7eb08bdf983d2aaa31c20fbf439eee7b8e0d61ca636fcd0c305bbbf -F test/testrunner.tcl 7cd31694a52affd636284b3e74ec10213c60e247ec71f56e9061cf669f897105 +F test/testrunner.tcl 29b60469f0bd1aa717507e2ec7660128894914def0f058bb6752c9bdfe61bbaa F test/testrunner_data.tcl 2f94974e5e3a56af880be72f7a7fd239aa9d4ecf978625435fcc698319c927fa F test/thread001.test a0985c117eab62c0c65526e9fa5d1360dd1cac5b03bde223902763274ce21899 F test/thread002.test c24c83408e35ba5a952a3638b7ac03ccdf1ce4409289c54a050ac4c5f1de7502 @@ -2177,8 +2177,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 18842d0d72048561312c2c83035c01253150e1fe1ff37160f266d24d41a01df3 -R a8f09c1fdaad1d594fe806932cdf9a66 -U drh -Z 2fb114f4336505cce7dafa69e9c32517 +P 1b7f0be44036fb90d763eabae84b95734e766f8010b39122f8787189308a7fc1 +R 3f6a714f6a93dd220bd97ec3c31ac4b4 +U dan +Z 4ab7e95a7dcf535e4920c95d1b703486 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index dffe028c56..ee62c57213 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1b7f0be44036fb90d763eabae84b95734e766f8010b39122f8787189308a7fc1 \ No newline at end of file +64f4dad1f928716b8688c650d043f18afcc72ec78d990145c580e2b98905b919 \ No newline at end of file diff --git a/test/testrunner.tcl b/test/testrunner.tcl index 163ddc01e0..f05b399e3a 100644 --- a/test/testrunner.tcl +++ b/test/testrunner.tcl @@ -1008,9 +1008,14 @@ proc launch_another_job {iJob} { close $fd } - set job_cmd $job(cmd) - if {$TRG(platform)!="win"} { - set job_cmd "export SQLITE_TMPDIR=\"[file normalize $dir]\"\n$job_cmd" + # Add a batch/shell file command to set the directory used for temp + # files to the test's working directory. Otherwise, tests that use + # large numbers of temp files (e.g. zipvfs), might generate temp + # filename collisions. + if {$TRG(platform)=="win"} { + set set_tmp_dir "SET SQLITE_TMPDIR=[file normalize $dir]" + } else { + set set_tmp_dir "export SQLITE_TMPDIR=\"[file normalize $dir]\"" } if { $TRG(dryrun) } { @@ -1027,7 +1032,8 @@ proc launch_another_job {iJob} { set pwd [pwd] cd $dir set fd [open $TRG(run) w] - puts $fd $job_cmd + puts $fd $set_tmp_dir + puts $fd $job(cmd) close $fd set fd [open "|$TRG(runcmd) 2>@1" r] cd $pwd From 1769640c8be768f42b9a25d175f7d2760a6534bc Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 13 Mar 2024 10:54:04 +0000 Subject: [PATCH 207/430] Add pointer to documentation to testrunner.tcl help message. FossilOrigin-Name: eff855102f9c0b4e9d876d1cff9d06c07de427b4880c2fa326d4d6e3e1dd13c8 --- doc/testrunner.md | 1 - manifest | 14 +++++++------- manifest.uuid | 2 +- test/testrunner.tcl | 2 ++ 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/doc/testrunner.md b/doc/testrunner.md index d420076c4f..f7fd296718 100644 --- a/doc/testrunner.md +++ b/doc/testrunner.md @@ -17,7 +17,6 @@
  • 3.3. Investigating Source Code Test Failures
  • 4. Extra testrunner.tcl Options -# 4. Extra testrunner.tcl Options
  • 5. Controlling CPU Core Utilization diff --git a/manifest b/manifest index 2735ee46af..38fcd0cd0c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Have\stestrunner.tcl\sset\sSQLITE_TMPDIR\son\swindows\sas\swell. -D 2024-03-13T10:47:54.860 +C Add\spointer\sto\sdocumentation\sto\stestrunner.tcl\shelp\smessage. +D 2024-03-13T10:54:04.498 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -44,7 +44,7 @@ F doc/json-enhancements.md e356fc834781f1f1aa22ee300027a270b2c960122468499bf347b F doc/jsonb.md 5fab4b8613aa9153fbeb6259297bd4697988af8b3d23900deba588fa7841456b F doc/lemon.html 8b266ff711d2ec7f867c3dca37634963f48a630329908cc282beebfa8c708706 F doc/pager-invariants.txt 27fed9a70ddad2088750c4a2b493b63853da2710 -F doc/testrunner.md 8d36ec692cf4994bb66d84a4645b9afa1ce9d47dc12cbf8d437c5a5fb6ddeedb +F doc/testrunner.md 7d16aa94aec424d5316be7f336f84f2961ab4e5e0acbc54bc610a80c4cbd87de F doc/trusted-schema.md 33625008620e879c7bcfbbfa079587612c434fa094d338b08242288d358c3e8a F doc/vdbesort-memory.md 4da2639c14cd24a31e0af694b1a8dd37eaf277aff3867e9a8cc14046bc49df56 F doc/vfs-shm.txt e101f27ea02a8387ce46a05be2b1a902a021d37a @@ -1687,7 +1687,7 @@ F test/temptable2.test 76821347810ecc88203e6ef0dd6897b6036ac788e9dd3e6b04fd4d163 F test/temptable3.test d11a0974e52b347e45ee54ef1923c91ed91e4637 F test/temptrigger.test 38f0ca479b1822d3117069e014daabcaacefffcc F test/tester.tcl fe617b88c7eb08bdf983d2aaa31c20fbf439eee7b8e0d61ca636fcd0c305bbbf -F test/testrunner.tcl 29b60469f0bd1aa717507e2ec7660128894914def0f058bb6752c9bdfe61bbaa +F test/testrunner.tcl cc3e416435f9bef832fb5e9f2b09e9d365faec77544573a9d9dc7b0f95b1120d F test/testrunner_data.tcl 2f94974e5e3a56af880be72f7a7fd239aa9d4ecf978625435fcc698319c927fa F test/thread001.test a0985c117eab62c0c65526e9fa5d1360dd1cac5b03bde223902763274ce21899 F test/thread002.test c24c83408e35ba5a952a3638b7ac03ccdf1ce4409289c54a050ac4c5f1de7502 @@ -2177,8 +2177,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 1b7f0be44036fb90d763eabae84b95734e766f8010b39122f8787189308a7fc1 -R 3f6a714f6a93dd220bd97ec3c31ac4b4 +P 64f4dad1f928716b8688c650d043f18afcc72ec78d990145c580e2b98905b919 +R 1134b8266271a887377fc4f455ed517a U dan -Z 4ab7e95a7dcf535e4920c95d1b703486 +Z 833508436e05f778ed8b702f9da8c8a7 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index ee62c57213..b4442bcf4f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -64f4dad1f928716b8688c650d043f18afcc72ec78d990145c580e2b98905b919 \ No newline at end of file +eff855102f9c0b4e9d876d1cff9d06c07de427b4880c2fa326d4d6e3e1dd13c8 \ No newline at end of file diff --git a/test/testrunner.tcl b/test/testrunner.tcl index f05b399e3a..439ccb0886 100644 --- a/test/testrunner.tcl +++ b/test/testrunner.tcl @@ -95,6 +95,8 @@ of sub-processes the test script uses to run tests. The "script" command outputs the script used to build a configuration. Add the "-msvc" option for a Windows-compatible script. For a list of available configurations enter "$a0 script help". + +Full documentation here: https://sqlite.org/src/doc/trunk/doc/testrunner.md }]] exit 1 From 484193fe7f7dccc1371757e339569f7c5c3e8bea Mon Sep 17 00:00:00 2001 From: drh <> Date: Wed, 13 Mar 2024 10:55:47 +0000 Subject: [PATCH 208/430] Improvements to the "help" message generated by testrunner.tcl. Add the special "list" permutation that does nothing but list all allowed values for the PERMUTATION argument to testrunner.tcl. FossilOrigin-Name: 1f5bfc6a9030f9905d258c5b665b9ff27efc7da71556c912ab3dce0f8f5aa8da --- manifest | 14 +++++++------- manifest.uuid | 2 +- test/testrunner.tcl | 34 ++++++++++++++++++++++++++++++---- 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/manifest b/manifest index 38fcd0cd0c..6f92138cec 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\spointer\sto\sdocumentation\sto\stestrunner.tcl\shelp\smessage. -D 2024-03-13T10:54:04.498 +C Improvements\sto\sthe\s"help"\smessage\sgenerated\sby\stestrunner.tcl.\s\sAdd\sthe\nspecial\s"list"\spermutation\sthat\sdoes\snothing\sbut\slist\sall\sallowed\nvalues\sfor\sthe\sPERMUTATION\sargument\sto\stestrunner.tcl. +D 2024-03-13T10:55:47.181 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -1687,7 +1687,7 @@ F test/temptable2.test 76821347810ecc88203e6ef0dd6897b6036ac788e9dd3e6b04fd4d163 F test/temptable3.test d11a0974e52b347e45ee54ef1923c91ed91e4637 F test/temptrigger.test 38f0ca479b1822d3117069e014daabcaacefffcc F test/tester.tcl fe617b88c7eb08bdf983d2aaa31c20fbf439eee7b8e0d61ca636fcd0c305bbbf -F test/testrunner.tcl cc3e416435f9bef832fb5e9f2b09e9d365faec77544573a9d9dc7b0f95b1120d +F test/testrunner.tcl acc25035b127471961ff8f77b829dc51a9615b1016bb874a339733b4c0881f30 F test/testrunner_data.tcl 2f94974e5e3a56af880be72f7a7fd239aa9d4ecf978625435fcc698319c927fa F test/thread001.test a0985c117eab62c0c65526e9fa5d1360dd1cac5b03bde223902763274ce21899 F test/thread002.test c24c83408e35ba5a952a3638b7ac03ccdf1ce4409289c54a050ac4c5f1de7502 @@ -2177,8 +2177,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 64f4dad1f928716b8688c650d043f18afcc72ec78d990145c580e2b98905b919 -R 1134b8266271a887377fc4f455ed517a -U dan -Z 833508436e05f778ed8b702f9da8c8a7 +P eff855102f9c0b4e9d876d1cff9d06c07de427b4880c2fa326d4d6e3e1dd13c8 +R 932e56d0dea34c025007477ebbf78453 +U drh +Z 0cfae733ff130354c2d77ebd401ddd94 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index b4442bcf4f..2f15429b49 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -eff855102f9c0b4e9d876d1cff9d06c07de427b4880c2fa326d4d6e3e1dd13c8 \ No newline at end of file +1f5bfc6a9030f9905d258c5b665b9ff27efc7da71556c912ab3dce0f8f5aa8da \ No newline at end of file diff --git a/test/testrunner.tcl b/test/testrunner.tcl index 439ccb0886..ba3d9b5533 100644 --- a/test/testrunner.tcl +++ b/test/testrunner.tcl @@ -65,13 +65,19 @@ Usage: --jobs NUMBER-OF-JOBS --zipvfs ZIPVFS-SOURCE-DIR -Interesting values for PERMUTATION are: +Special values for PERMUTATION that work with plain tclsh: + + list - show all allowed PERMUTATION arguments. + mdevtest - tests recommended prior to normal development check-ins. + release - full release test with various builds. + sdevtest - like mdevtest but using ASAN and UBSAN. + +Other PERMUTATION arguments must be run using testfixture, not tclsh: - veryquick - a fast subset of the tcl test scripts. This is the default. - full - all tcl test scripts. all - all tcl test scripts, plus a subset of test scripts rerun with various permutations. - release - full release test with various builds. + full - all tcl test scripts. + veryquick - a fast subset of the tcl test scripts. This is the default. If no PATTERN arguments are present, all tests specified by the PERMUTATION are run. Otherwise, each pattern is interpreted as a glob pattern. Only @@ -836,6 +842,17 @@ proc add_devtest_jobs {lBld patternlist} { } } +# Check to ensure that the interpreter is a full-blown "testfixture" +# build and not just a "tclsh". If this is not the case, issue an +# error message and exit. +# +proc must_be_testfixture {} { + if {[lsearch [info commands] sqlite3_soft_heap_limit]<0} { + puts "Use ./testfixture, not tclsh, for these arguments" + exit 1 + } +} + proc add_jobs_from_cmdline {patternlist} { global TRG @@ -851,6 +868,7 @@ proc add_jobs_from_cmdline {patternlist} { set first [lindex $patternlist 0] switch -- $first { all { + must_be_testfixture set patternlist [lrange $patternlist 1 end] set clist [trd_all_configs] foreach c $clist { @@ -886,7 +904,15 @@ proc add_jobs_from_cmdline {patternlist} { } } + list { + set allperm [array names ::testspec] + lappend allperm all mdevtest sdevtest release list + puts "Allowed values for the PERMUTATION argument: [lsort $allperm]" + exit 0 + } + default { + must_be_testfixture if {[info exists ::testspec($first)]} { add_tcl_jobs "" $first [lrange $patternlist 1 end] } else { From c2764dbb3310922cf3127c057c508804353230c7 Mon Sep 17 00:00:00 2001 From: drh <> Date: Wed, 13 Mar 2024 11:29:04 +0000 Subject: [PATCH 209/430] Minor tweaks to the testrunner documentation. FossilOrigin-Name: 3128b98d2656c7f23f6071c173f96329c7bdc49cd641050fbb7b105b810ba7c7 --- doc/testrunner.md | 27 +++++++++++++++------------ manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/doc/testrunner.md b/doc/testrunner.md index f7fd296718..470c770f1d 100644 --- a/doc/testrunner.md +++ b/doc/testrunner.md @@ -28,12 +28,18 @@ multiple jobs. It supports the following types of tests: * Tcl test scripts. - * Tests run with [make] commands. Specifically, at time of writing, - [make fuzztest], [make mptest], [make sourcetest] and [make threadtest]. + * Tests run with `make` commands. Examples: + - `make mdevtest` + - `make releasetest` + - `make sdevtest` + - `make testrunner` testrunner.tcl pipes the output of all tests and builds run into log file -**testrunner.log**, created in the cwd directory. Searching this file for -"failed" is a good way to find the output of a failed test. +**testrunner.log**, created in the current working directory. Search this +file to find details of errors. Suggested search commands: + + * `grep "^!" testrunner.log` + * `grep failed testrunner.log` testrunner.tcl also populates SQLite database **testrunner.db**. This database contains details of all tests run, running and to be run. A useful query @@ -59,7 +65,7 @@ Running: in another terminal is a good way to keep an eye on a long running test. -Sometimes testrunner.tcl uses the [testfixture] binary that it is run with +Sometimes testrunner.tcl uses the `testfixture` binary that it is run with to run tests (see "Binary Tests" below). Sometimes it builds testfixture and other binaries in specific configurations to test (see "Source Tests"). @@ -67,9 +73,9 @@ other binaries in specific configurations to test (see "Source Tests"). # 2. Binary Tests The commands described in this section all run various combinations of the Tcl -test scripts using the [testfixture] binary used to run the testrunner.tcl +test scripts using the `testfixture` binary used to run the testrunner.tcl script (i.e. they do not invoke the compiler to build new binaries, or the -[make] command to run tests that are not Tcl scripts). The procedure to run +`make` command to run tests that are not Tcl scripts). The procedure to run these tests is therefore: 1. Build the "testfixture" (or "testfixture.exe" for windows) binary using @@ -192,7 +198,7 @@ TODO: ./configure + Makefile.msc build systems. ## 3.1. Commands to Run SQLite Tests The **mdevtest** command is equivalent to running the veryquick tests and -the [make fuzztest] target once for each of two --enable-all builds - one +the `make fuzztest` target once for each of two --enable-all builds - one with debugging enabled and one without: ``` @@ -282,7 +288,7 @@ a dos \*.bat file on windows. For example: ``` The generated bash or \*.bat file script accepts a single argument - a makefile -target to build. This may be used either to run a [make] command test directly, +target to build. This may be used either to run a `make` command test directly, or else to build a testfixture (or testfixture.exe) binary with which to run a Tcl test script, as described above. @@ -338,6 +344,3 @@ testrunner.log and testrunner.db files: ``` $ ./testfixture $TESTDIR/testrunner.tcl njob $NEW_NUMBER_OF_JOBS ``` - - - diff --git a/manifest b/manifest index 6f92138cec..ea1d4a7d34 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improvements\sto\sthe\s"help"\smessage\sgenerated\sby\stestrunner.tcl.\s\sAdd\sthe\nspecial\s"list"\spermutation\sthat\sdoes\snothing\sbut\slist\sall\sallowed\nvalues\sfor\sthe\sPERMUTATION\sargument\sto\stestrunner.tcl. -D 2024-03-13T10:55:47.181 +C Minor\stweaks\sto\sthe\stestrunner\sdocumentation. +D 2024-03-13T11:29:04.049 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -44,7 +44,7 @@ F doc/json-enhancements.md e356fc834781f1f1aa22ee300027a270b2c960122468499bf347b F doc/jsonb.md 5fab4b8613aa9153fbeb6259297bd4697988af8b3d23900deba588fa7841456b F doc/lemon.html 8b266ff711d2ec7f867c3dca37634963f48a630329908cc282beebfa8c708706 F doc/pager-invariants.txt 27fed9a70ddad2088750c4a2b493b63853da2710 -F doc/testrunner.md 7d16aa94aec424d5316be7f336f84f2961ab4e5e0acbc54bc610a80c4cbd87de +F doc/testrunner.md 50570a63efb68fd1472cbe7eeccf78c7b7d66ac1f966ab18d29f824f7cdba2b3 F doc/trusted-schema.md 33625008620e879c7bcfbbfa079587612c434fa094d338b08242288d358c3e8a F doc/vdbesort-memory.md 4da2639c14cd24a31e0af694b1a8dd37eaf277aff3867e9a8cc14046bc49df56 F doc/vfs-shm.txt e101f27ea02a8387ce46a05be2b1a902a021d37a @@ -2177,8 +2177,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P eff855102f9c0b4e9d876d1cff9d06c07de427b4880c2fa326d4d6e3e1dd13c8 -R 932e56d0dea34c025007477ebbf78453 +P 1f5bfc6a9030f9905d258c5b665b9ff27efc7da71556c912ab3dce0f8f5aa8da +R f1d87f081beab0bb7e2677dcc20d7af9 U drh -Z 0cfae733ff130354c2d77ebd401ddd94 +Z 7d008234f4102bc09ae556028dcb2b0f # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 2f15429b49..f66ed3c2e4 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1f5bfc6a9030f9905d258c5b665b9ff27efc7da71556c912ab3dce0f8f5aa8da \ No newline at end of file +3128b98d2656c7f23f6071c173f96329c7bdc49cd641050fbb7b105b810ba7c7 \ No newline at end of file From 9b6e535609a114846a4570d263533845b6cf0f77 Mon Sep 17 00:00:00 2001 From: drh <> Date: Wed, 13 Mar 2024 11:46:23 +0000 Subject: [PATCH 210/430] Improve one of the error messages from testrunner.tcl. FossilOrigin-Name: 233155c174575fa99b34030c1936bc2b04489417f4d5223f18cdb3c8fc274a56 --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/testrunner.tcl | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index ea1d4a7d34..a67db52106 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Minor\stweaks\sto\sthe\stestrunner\sdocumentation. -D 2024-03-13T11:29:04.049 +C Improve\sone\sof\sthe\serror\smessages\sfrom\stestrunner.tcl. +D 2024-03-13T11:46:23.016 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -1687,7 +1687,7 @@ F test/temptable2.test 76821347810ecc88203e6ef0dd6897b6036ac788e9dd3e6b04fd4d163 F test/temptable3.test d11a0974e52b347e45ee54ef1923c91ed91e4637 F test/temptrigger.test 38f0ca479b1822d3117069e014daabcaacefffcc F test/tester.tcl fe617b88c7eb08bdf983d2aaa31c20fbf439eee7b8e0d61ca636fcd0c305bbbf -F test/testrunner.tcl acc25035b127471961ff8f77b829dc51a9615b1016bb874a339733b4c0881f30 +F test/testrunner.tcl cdbfe4b24952a411fcc2cb48331d10ece650b6a3108bd05ae890304cfed93fed F test/testrunner_data.tcl 2f94974e5e3a56af880be72f7a7fd239aa9d4ecf978625435fcc698319c927fa F test/thread001.test a0985c117eab62c0c65526e9fa5d1360dd1cac5b03bde223902763274ce21899 F test/thread002.test c24c83408e35ba5a952a3638b7ac03ccdf1ce4409289c54a050ac4c5f1de7502 @@ -2177,8 +2177,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 1f5bfc6a9030f9905d258c5b665b9ff27efc7da71556c912ab3dce0f8f5aa8da -R f1d87f081beab0bb7e2677dcc20d7af9 +P 3128b98d2656c7f23f6071c173f96329c7bdc49cd641050fbb7b105b810ba7c7 +R b30ace34515f0911b2a0db585efbc51d U drh -Z 7d008234f4102bc09ae556028dcb2b0f +Z 4fb6ed0f5ce1c12c4ccfa1c6192fc974 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index f66ed3c2e4..7d5581e36c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -3128b98d2656c7f23f6071c173f96329c7bdc49cd641050fbb7b105b810ba7c7 \ No newline at end of file +233155c174575fa99b34030c1936bc2b04489417f4d5223f18cdb3c8fc274a56 \ No newline at end of file diff --git a/test/testrunner.tcl b/test/testrunner.tcl index ba3d9b5533..76a73a6ba7 100644 --- a/test/testrunner.tcl +++ b/test/testrunner.tcl @@ -848,7 +848,7 @@ proc add_devtest_jobs {lBld patternlist} { # proc must_be_testfixture {} { if {[lsearch [info commands] sqlite3_soft_heap_limit]<0} { - puts "Use ./testfixture, not tclsh, for these arguments" + puts "Use testfixture, not tclsh, for these arguments." exit 1 } } From 4659ec34c1c5ffceb64ce486502acb92f14688eb Mon Sep 17 00:00:00 2001 From: drh <> Date: Wed, 13 Mar 2024 13:09:58 +0000 Subject: [PATCH 211/430] Add the --explain option to testrunner.tcl. FossilOrigin-Name: f0c9eb0326f189fe5ebbee83532ac2c413e91c6a8e9d5b93aa6170cba66fdd22 --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/testrunner.tcl | 45 ++++++++++++++++++++++++++++++++++++++------- 3 files changed, 45 insertions(+), 14 deletions(-) diff --git a/manifest b/manifest index a67db52106..683882b1c4 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improve\sone\sof\sthe\serror\smessages\sfrom\stestrunner.tcl. -D 2024-03-13T11:46:23.016 +C Add\sthe\s--explain\soption\sto\stestrunner.tcl. +D 2024-03-13T13:09:58.491 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -1687,7 +1687,7 @@ F test/temptable2.test 76821347810ecc88203e6ef0dd6897b6036ac788e9dd3e6b04fd4d163 F test/temptable3.test d11a0974e52b347e45ee54ef1923c91ed91e4637 F test/temptrigger.test 38f0ca479b1822d3117069e014daabcaacefffcc F test/tester.tcl fe617b88c7eb08bdf983d2aaa31c20fbf439eee7b8e0d61ca636fcd0c305bbbf -F test/testrunner.tcl cdbfe4b24952a411fcc2cb48331d10ece650b6a3108bd05ae890304cfed93fed +F test/testrunner.tcl f172c5141b890acfc223884071f90176031e3a059218280952f536eb2c851ee8 F test/testrunner_data.tcl 2f94974e5e3a56af880be72f7a7fd239aa9d4ecf978625435fcc698319c927fa F test/thread001.test a0985c117eab62c0c65526e9fa5d1360dd1cac5b03bde223902763274ce21899 F test/thread002.test c24c83408e35ba5a952a3638b7ac03ccdf1ce4409289c54a050ac4c5f1de7502 @@ -2177,8 +2177,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 3128b98d2656c7f23f6071c173f96329c7bdc49cd641050fbb7b105b810ba7c7 -R b30ace34515f0911b2a0db585efbc51d +P 233155c174575fa99b34030c1936bc2b04489417f4d5223f18cdb3c8fc274a56 +R 73b7b3b0e43269248a0a7f9b5744d286 U drh -Z 4fb6ed0f5ce1c12c4ccfa1c6192fc974 +Z bad41bec7a1c5ea3149d7911ab3a6c38 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 7d5581e36c..6ccc32a8fd 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -233155c174575fa99b34030c1936bc2b04489417f4d5223f18cdb3c8fc274a56 \ No newline at end of file +f0c9eb0326f189fe5ebbee83532ac2c413e91c6a8e9d5b93aa6170cba66fdd22 \ No newline at end of file diff --git a/test/testrunner.tcl b/test/testrunner.tcl index 76a73a6ba7..96494dc3a5 100644 --- a/test/testrunner.tcl +++ b/test/testrunner.tcl @@ -62,6 +62,7 @@ Usage: where SWITCHES are: --buildonly --dryrun + --explain --jobs NUMBER-OF-JOBS --zipvfs ZIPVFS-SOURCE-DIR @@ -166,6 +167,7 @@ set TRG(fuzztest) 0 ;# is the fuzztest option present. set TRG(zipvfs) "" ;# -zipvfs option, if any set TRG(buildonly) 0 ;# True if --buildonly option set TRG(dryrun) 0 ;# True if --dryrun option +set TRG(explain) 0 ;# True for the --explain option switch -nocase -glob -- $tcl_platform(os) { *darwin* { @@ -460,6 +462,8 @@ for {set ii 0} {$ii < [llength $argv]} {incr ii} { set TRG(buildonly) 1 } elseif {($n>2 && [string match "$a*" --dryrun]) || $a=="-d"} { set TRG(dryrun) 1 + } elseif {($n>2 && [string match "$a*" --explain]) || $a=="-e"} { + set TRG(explain) 1 } else { usage } @@ -1177,15 +1181,42 @@ proc handle_buildonly {} { } } +# Handle the --explain option. Provide a human-readable +# explanation of all the tests that are in the trdb database jobs +# table. +# +proc explain_layer {indent depid} { + global TRG + if {$TRG(buildonly)} { + set showtests 0 + } else { + set showtests 1 + } + trdb eval {SELECT jobid, displayname, displaytype, dirname + FROM jobs WHERE depid=$depid ORDER BY displayname} { + if {$displaytype=="bld"} { + puts "${indent}$displayname in $dirname" + explain_layer "${indent} " $jobid + } elseif {$showtests} { + puts "${indent}[lindex $displayname end]" + } + } +} +proc explain_tests {} { + explain_layer "" "" +} + sqlite3 trdb $TRG(dbname) trdb timeout $TRG(timeout) set tm [lindex [time { make_new_testset }] 0] -if {$TRG(nJob)>1} { - puts "splitting work across $TRG(nJob) jobs" +if {$TRG(explain)} { + explain_tests +} else { + if {$TRG(nJob)>1} { + puts "splitting work across $TRG(nJob) jobs" + } + puts "built testset in [expr $tm/1000]ms.." + handle_buildonly + run_testset } -puts "built testset in [expr $tm/1000]ms.." - -handle_buildonly -run_testset trdb close -#puts [pwd] From 4565c8417b1ff0f188fe7272f7049f2c33ced134 Mon Sep 17 00:00:00 2001 From: drh <> Date: Wed, 13 Mar 2024 13:27:16 +0000 Subject: [PATCH 212/430] Document the testrunner.tcl --explain option in doc/testrunner.md. FossilOrigin-Name: 5a7b5fc99a9d5c7693a5707c2050a8c59a8f97732e4763a56982579f8d5959ec --- doc/testrunner.md | 10 ++++++++++ manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/doc/testrunner.md b/doc/testrunner.md index 470c770f1d..d0248573ee 100644 --- a/doc/testrunner.md +++ b/doc/testrunner.md @@ -315,6 +315,16 @@ would normally execute into the testrunner.log file. Example: tclsh $TESTDIR/testrunner.tcl --dryrun mdevtest" ``` +The **--explain** option is similar to --dryrun in that it prevents testrunner.tcl +from building any binaries or running any tests. The difference is that --explain +prints on standard output a human-readable summary of all the builds and tests that +would have been run. + +``` + # Show what builds and tests would have been run + tclsh $TESTDIR/testrunner.tcl --explain mdevtest +``` + # 5. Controlling CPU Core Utilization diff --git a/manifest b/manifest index 683882b1c4..a5d47b0edb 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\s--explain\soption\sto\stestrunner.tcl. -D 2024-03-13T13:09:58.491 +C Document\sthe\stestrunner.tcl\s--explain\soption\sin\sdoc/testrunner.md. +D 2024-03-13T13:27:16.812 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -44,7 +44,7 @@ F doc/json-enhancements.md e356fc834781f1f1aa22ee300027a270b2c960122468499bf347b F doc/jsonb.md 5fab4b8613aa9153fbeb6259297bd4697988af8b3d23900deba588fa7841456b F doc/lemon.html 8b266ff711d2ec7f867c3dca37634963f48a630329908cc282beebfa8c708706 F doc/pager-invariants.txt 27fed9a70ddad2088750c4a2b493b63853da2710 -F doc/testrunner.md 50570a63efb68fd1472cbe7eeccf78c7b7d66ac1f966ab18d29f824f7cdba2b3 +F doc/testrunner.md 15583cf8c7d8a1c3378fd5d4319ca769a14c4d950a5df9b015d01d5be290dc69 F doc/trusted-schema.md 33625008620e879c7bcfbbfa079587612c434fa094d338b08242288d358c3e8a F doc/vdbesort-memory.md 4da2639c14cd24a31e0af694b1a8dd37eaf277aff3867e9a8cc14046bc49df56 F doc/vfs-shm.txt e101f27ea02a8387ce46a05be2b1a902a021d37a @@ -2177,8 +2177,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 233155c174575fa99b34030c1936bc2b04489417f4d5223f18cdb3c8fc274a56 -R 73b7b3b0e43269248a0a7f9b5744d286 +P f0c9eb0326f189fe5ebbee83532ac2c413e91c6a8e9d5b93aa6170cba66fdd22 +R 4e0be3056348c8f1e7d2864a45b77c77 U drh -Z bad41bec7a1c5ea3149d7911ab3a6c38 +Z 5cfab6cb98d5a454aa1c2e14d97de81e # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 6ccc32a8fd..b5e8f2c31e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f0c9eb0326f189fe5ebbee83532ac2c413e91c6a8e9d5b93aa6170cba66fdd22 \ No newline at end of file +5a7b5fc99a9d5c7693a5707c2050a8c59a8f97732e4763a56982579f8d5959ec \ No newline at end of file From 6bb6a9c94162ec7faf5489bca4fbebbe90901604 Mon Sep 17 00:00:00 2001 From: drh <> Date: Wed, 13 Mar 2024 13:43:21 +0000 Subject: [PATCH 213/430] If the NJOB environment variable is a positive integer, it causes testrunner.tcl to run that many jobs. FossilOrigin-Name: 924281b94d8e6ba674d6fe2f7f01da890351355a854e9e6fe623fad1180f7392 --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/testrunner.tcl | 4 ++++ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index a5d47b0edb..f47cb0a280 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Document\sthe\stestrunner.tcl\s--explain\soption\sin\sdoc/testrunner.md. -D 2024-03-13T13:27:16.812 +C If\sthe\sNJOB\senvironment\svariable\sis\sa\spositive\sinteger,\sit\scauses\ntestrunner.tcl\sto\srun\sthat\smany\sjobs. +D 2024-03-13T13:43:21.042 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -1687,7 +1687,7 @@ F test/temptable2.test 76821347810ecc88203e6ef0dd6897b6036ac788e9dd3e6b04fd4d163 F test/temptable3.test d11a0974e52b347e45ee54ef1923c91ed91e4637 F test/temptrigger.test 38f0ca479b1822d3117069e014daabcaacefffcc F test/tester.tcl fe617b88c7eb08bdf983d2aaa31c20fbf439eee7b8e0d61ca636fcd0c305bbbf -F test/testrunner.tcl f172c5141b890acfc223884071f90176031e3a059218280952f536eb2c851ee8 +F test/testrunner.tcl 48e33d99f0bad37a03b8a4064a44184de4c4ed8cd2e3174fef8d7c5f4e28ecc3 F test/testrunner_data.tcl 2f94974e5e3a56af880be72f7a7fd239aa9d4ecf978625435fcc698319c927fa F test/thread001.test a0985c117eab62c0c65526e9fa5d1360dd1cac5b03bde223902763274ce21899 F test/thread002.test c24c83408e35ba5a952a3638b7ac03ccdf1ce4409289c54a050ac4c5f1de7502 @@ -2177,8 +2177,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P f0c9eb0326f189fe5ebbee83532ac2c413e91c6a8e9d5b93aa6170cba66fdd22 -R 4e0be3056348c8f1e7d2864a45b77c77 +P 5a7b5fc99a9d5c7693a5707c2050a8c59a8f97732e4763a56982579f8d5959ec +R 407830b5c90e1eed2d3fe5c7fa3b86c4 U drh -Z 5cfab6cb98d5a454aa1c2e14d97de81e +Z 7cb4f1a4becd0bff0730a94c93a2e20f # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index b5e8f2c31e..a1fceec15d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5a7b5fc99a9d5c7693a5707c2050a8c59a8f97732e4763a56982579f8d5959ec \ No newline at end of file +924281b94d8e6ba674d6fe2f7f01da890351355a854e9e6fe623fad1180f7392 \ No newline at end of file diff --git a/test/testrunner.tcl b/test/testrunner.tcl index 96494dc3a5..b201a263d1 100644 --- a/test/testrunner.tcl +++ b/test/testrunner.tcl @@ -141,6 +141,10 @@ proc guess_number_of_cores {} { } proc default_njob {} { + global env + if {[info exists env(NJOB)] && $env(NJOB)>=1} { + return $env(NJOB) + } set nCore [guess_number_of_cores] if {$nCore<=2} { set nHelper 1 From 609aba00d930c4909a1dfa313645847de5804b68 Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 13 Mar 2024 15:34:44 +0000 Subject: [PATCH 214/430] Avoid creating a co-routine incrementally for a VALUES clause that has affinities other than NONE. FossilOrigin-Name: 4229b12b327b05561dcf49b8585a66467d17d4e998b14eff65eb886f2434b53c --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/insert.c | 12 ++++++++++++ test/values.test | 4 ++++ 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index ae283f24ef..1eef7fdddb 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Correctly\sinitialize\sthe\sSrcItem.iCursor\sfield\sto\s-1\swhen\screating\sa\sco-routine\sfrom\sa\smulti-values\sVALUES\sclause. -D 2024-03-12T20:10:46.651 +C Avoid\screating\sa\sco-routine\sincrementally\sfor\sa\sVALUES\sclause\sthat\shas\saffinities\sother\sthan\sNONE. +D 2024-03-13T15:34:44.818 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -709,7 +709,7 @@ F src/hash.c 9ee4269fb1d6632a6fecfb9479c93a1f29271bddbbaf215dd60420bcb80c7220 F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 -F src/insert.c 9d48439a0fff35d3c4850bc9ab3657f9d45b2800af52ef3b083e7068e32d8aa2 +F src/insert.c aef8d3dfc86116e0226a90549b5fbe8c63cda51eaca01d22f4d16e7b4e554a1b F src/json.c e2e40760d6689134c3e2ece38c6a496b34ff5e2661a8f238444a119af666fdce F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 @@ -1921,7 +1921,7 @@ F test/vacuum4.test 7ea76b769fffeb41f925303b04cbcf5a5bbeabe55e4c60ae754ff24eeeb7 F test/vacuum5.test 263b144d537e92ad8e9ca8a73cc6e1583f41cfd0dda9432b87f7806174a2f48c F test/vacuum6.test b137b04bf3392d3f5c3b8fda0ce85a6775a70ca112f6559f74ff52dc9ce042fd F test/vacuummem.test 4b30f5b95a9ff86e9d5c20741e50a898b2dc10b0962a3211571eb165357003fb -F test/values.test 042f30d897d3b2bfa54dc89a48ef6c8f6ba3ffdfd4fc35c2cc877d28a1095ce3 +F test/values.test 3f0fe0e8859306e9a5cfc800e327278762510c8d5b075d8ddce40f2d13d1405a F test/valuesfault.test 2ef23ed965e3bd08e268cdc38a0d11653390ddbbe1e8e2e98d16f55edd30f6e8 F test/varint.test bbce22cda8fc4d135bcc2b589574be8410614e62 F test/veryquick.test 57ab846bacf7b90cf4e9a672721ea5c5b669b661 @@ -2179,8 +2179,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 17d1f7cfabc7593d0725051b0c7c9619a23a482265f30f15ab9493fef5caeeb0 -R bc124d03e15c7cb41c52570d66be2e47 +P c32953ff6d72910815eaff29ab1b790c412e1a741d02c03c5911dda0c08e5130 +R 919d468c68cfa043ffb3132b71e307d6 U dan -Z 476dd3f62c65ec97a150406261356d2a +Z 074e750da48e105e4f7bff52672dad88 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index bc849bef9a..e4e6f66f77 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c32953ff6d72910815eaff29ab1b790c412e1a741d02c03c5911dda0c08e5130 \ No newline at end of file +4229b12b327b05561dcf49b8585a66467d17d4e998b14eff65eb886f2434b53c \ No newline at end of file diff --git a/src/insert.c b/src/insert.c index 071d9aeff9..10eafaa413 100644 --- a/src/insert.c +++ b/src/insert.c @@ -593,6 +593,17 @@ static int multiValueIsConstant(ExprList *pRow){ return 1; } +static int multiValueIsConstantNoAff(ExprList *pRow){ + int ii; + if( multiValueIsConstant(pRow)==0 ) return 0; + for(ii=0; iinExpr; ii++){ + assert( pRow->a[ii].pExpr->affExpr==0 ); + if( 0!=sqlite3ExprAffinity(pRow->a[ii].pExpr) ) return 0; + } + return 1; + +} + Select *sqlite3MultiValues(Parse *pParse, Select *pLeft, ExprList *pRow){ SrcItem *p; SelectDest dest; @@ -603,6 +614,7 @@ Select *sqlite3MultiValues(Parse *pParse, Select *pLeft, ExprList *pRow){ || pParse->bHasWith || multiValueIsConstant(pRow)==0 || pLeft->pPrior + || (pLeft->pSrc->nSrc==0 && multiValueIsConstantNoAff(pLeft->pEList)==0) ){ int f = SF_Values | SF_MultiValue; if( pLeft->pPrior || pLeft->pSrc->nSrc ){ diff --git a/test/values.test b/test/values.test index 8df0e6138f..627987b43b 100644 --- a/test/values.test +++ b/test/values.test @@ -263,5 +263,9 @@ do_execsql_test 6.1 { SELECT * FROM t1, (VALUES(1), (2)) } {x 1 x 2 y 1 y 2} +do_execsql_test 6.2 { + VALUES(CAST(44 AS REAL)),(55); +} {44.0 55} + finish_test From e116fa153f752192ce96e285f7a3685549e0e2a4 Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 13 Mar 2024 15:44:31 +0000 Subject: [PATCH 215/430] Ensure that if a multi-row VALUES cannot be coded while being parsed, the SF_MultiValue flag is correctly set. FossilOrigin-Name: 94791824a6f04782aac6bc16c182685e2d6ebf5c688dc9f8d59e479c6fd5a40e --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/insert.c | 9 ++++++--- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 1eef7fdddb..fc5a54bd05 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Avoid\screating\sa\sco-routine\sincrementally\sfor\sa\sVALUES\sclause\sthat\shas\saffinities\sother\sthan\sNONE. -D 2024-03-13T15:34:44.818 +C Ensure\sthat\sif\sa\smulti-row\sVALUES\scannot\sbe\scoded\swhile\sbeing\sparsed,\sthe\sSF_MultiValue\sflag\sis\scorrectly\sset. +D 2024-03-13T15:44:31.439 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -709,7 +709,7 @@ F src/hash.c 9ee4269fb1d6632a6fecfb9479c93a1f29271bddbbaf215dd60420bcb80c7220 F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 -F src/insert.c aef8d3dfc86116e0226a90549b5fbe8c63cda51eaca01d22f4d16e7b4e554a1b +F src/insert.c 88f3c98b0ebbee295bb5085753bdb64ef1546ee5f0f0100b8be4f756b8a1acc6 F src/json.c e2e40760d6689134c3e2ece38c6a496b34ff5e2661a8f238444a119af666fdce F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 @@ -2179,8 +2179,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P c32953ff6d72910815eaff29ab1b790c412e1a741d02c03c5911dda0c08e5130 -R 919d468c68cfa043ffb3132b71e307d6 +P 4229b12b327b05561dcf49b8585a66467d17d4e998b14eff65eb886f2434b53c +R 759c4fdaf4045c9f2dff7c53c191816c U dan -Z 074e750da48e105e4f7bff52672dad88 +Z 9143cafae67b08f919f57c93acfe5550 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index e4e6f66f77..bd6f8334d3 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4229b12b327b05561dcf49b8585a66467d17d4e998b14eff65eb886f2434b53c \ No newline at end of file +94791824a6f04782aac6bc16c182685e2d6ebf5c688dc9f8d59e479c6fd5a40e \ No newline at end of file diff --git a/src/insert.c b/src/insert.c index 10eafaa413..7303e1950a 100644 --- a/src/insert.c +++ b/src/insert.c @@ -616,13 +616,16 @@ Select *sqlite3MultiValues(Parse *pParse, Select *pLeft, ExprList *pRow){ || pLeft->pPrior || (pLeft->pSrc->nSrc==0 && multiValueIsConstantNoAff(pLeft->pEList)==0) ){ + /* This row of the VALUES clause cannot be coded immediately. */ int f = SF_Values | SF_MultiValue; - if( pLeft->pPrior || pLeft->pSrc->nSrc ){ + if( pLeft->pSrc->nSrc ){ sqlite3MultiValuesEnd(pParse, pLeft); f = SF_Values; + }else if( pLeft->pPrior ){ + /* In this case set the SF_MultiValue flag only if it was set on + ** the previous Select structure. */ + f = (f & pLeft->selFlags); } - /* This VALUES clause is part of a VIEW or some other schema item. In - ** this case the co-routine cannot be coded immediately. */ pSelect = sqlite3SelectNew(pParse,pRow,0,0,0,0,0,f,0); pLeft->selFlags &= ~SF_MultiValue; if( pSelect ){ From 81a244c514a5273b8b293bcc68cf2467c9b8c771 Mon Sep 17 00:00:00 2001 From: drh <> Date: Wed, 13 Mar 2024 16:32:05 +0000 Subject: [PATCH 216/430] Minor change to the "mdevtest" and "sdevtest" in testrunner.tcl, to make it easier to add configurations in branches. FossilOrigin-Name: 9349d94e05dcf266b02afcd89f1e433cdc45f23e8536b2f3f9aa242d5d89c307 --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/testrunner.tcl | 12 ++++++++++-- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index f47cb0a280..d831726a46 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C If\sthe\sNJOB\senvironment\svariable\sis\sa\spositive\sinteger,\sit\scauses\ntestrunner.tcl\sto\srun\sthat\smany\sjobs. -D 2024-03-13T13:43:21.042 +C Minor\schange\sto\sthe\s"mdevtest"\sand\s"sdevtest"\sin\stestrunner.tcl,\sto\smake\sit\neasier\sto\sadd\sconfigurations\sin\sbranches. +D 2024-03-13T16:32:05.539 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -1687,7 +1687,7 @@ F test/temptable2.test 76821347810ecc88203e6ef0dd6897b6036ac788e9dd3e6b04fd4d163 F test/temptable3.test d11a0974e52b347e45ee54ef1923c91ed91e4637 F test/temptrigger.test 38f0ca479b1822d3117069e014daabcaacefffcc F test/tester.tcl fe617b88c7eb08bdf983d2aaa31c20fbf439eee7b8e0d61ca636fcd0c305bbbf -F test/testrunner.tcl 48e33d99f0bad37a03b8a4064a44184de4c4ed8cd2e3174fef8d7c5f4e28ecc3 +F test/testrunner.tcl 9f198e41c0d8899d547a5beb4af0c0d512021d18da136918dd96be6a242dbab5 F test/testrunner_data.tcl 2f94974e5e3a56af880be72f7a7fd239aa9d4ecf978625435fcc698319c927fa F test/thread001.test a0985c117eab62c0c65526e9fa5d1360dd1cac5b03bde223902763274ce21899 F test/thread002.test c24c83408e35ba5a952a3638b7ac03ccdf1ce4409289c54a050ac4c5f1de7502 @@ -2177,8 +2177,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 5a7b5fc99a9d5c7693a5707c2050a8c59a8f97732e4763a56982579f8d5959ec -R 407830b5c90e1eed2d3fe5c7fa3b86c4 +P 924281b94d8e6ba674d6fe2f7f01da890351355a854e9e6fe623fad1180f7392 +R 92509b8a5762b034ecb1ec5b7039a632 U drh -Z 7cb4f1a4becd0bff0730a94c93a2e20f +Z 644a950afdac6e39b6751ae1898b20f1 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index a1fceec15d..cd3ae2f7ad 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -924281b94d8e6ba674d6fe2f7f01da890351355a854e9e6fe623fad1180f7392 \ No newline at end of file +9349d94e05dcf266b02afcd89f1e433cdc45f23e8536b2f3f9aa242d5d89c307 \ No newline at end of file diff --git a/test/testrunner.tcl b/test/testrunner.tcl index b201a263d1..e8d0f76864 100644 --- a/test/testrunner.tcl +++ b/test/testrunner.tcl @@ -885,11 +885,19 @@ proc add_jobs_from_cmdline {patternlist} { } mdevtest { - add_devtest_jobs {All-O0 All-Debug} [lrange $patternlist 1 end] + set config_set { + All-O0 + All-Debug + } + add_devtest_jobs $config_set [lrange $patternlist 1 end] } sdevtest { - add_devtest_jobs {All-Sanitize All-Debug} [lrange $patternlist 1 end] + set config_set { + All-Sanitize + All-Debug + } + add_devtest_jobs $config_set [lrange $patternlist 1 end] } release { From 35057fb4bc78c5080fc41e81ab3f6c4f4d2a797c Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 13 Mar 2024 17:33:45 +0000 Subject: [PATCH 217/430] Fix some OOM handling problems on this branch. FossilOrigin-Name: 2085c7f12a3916ec883c31795e29f2e2b6641c30ecf748cce9bff7b13b061d1f --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/insert.c | 39 ++++++++++++++++++++------------------- 3 files changed, 27 insertions(+), 26 deletions(-) diff --git a/manifest b/manifest index 80413c4c4e..a91c89a359 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Merge\strunk\sinto\sthis\sbranch. -D 2024-03-13T15:47:52.750 +C Fix\ssome\sOOM\shandling\sproblems\son\sthis\sbranch. +D 2024-03-13T17:33:45.566 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -709,7 +709,7 @@ F src/hash.c 9ee4269fb1d6632a6fecfb9479c93a1f29271bddbbaf215dd60420bcb80c7220 F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 -F src/insert.c 88f3c98b0ebbee295bb5085753bdb64ef1546ee5f0f0100b8be4f756b8a1acc6 +F src/insert.c 7d4e27871c23ad98d062dcf21509573229b41307e125d4569a89e4a489383134 F src/json.c e2e40760d6689134c3e2ece38c6a496b34ff5e2661a8f238444a119af666fdce F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 @@ -2179,8 +2179,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 94791824a6f04782aac6bc16c182685e2d6ebf5c688dc9f8d59e479c6fd5a40e 924281b94d8e6ba674d6fe2f7f01da890351355a854e9e6fe623fad1180f7392 -R af81f2952048774d882db6d201804b0c +P 38635651f08d42110c01d6b24f6e362e340511846294f8696af4afc795dae80d +R 3557bbe553b856781f68b1001ce502f1 U dan -Z a427b7a910e44c4f56ce4ce6ef8524f2 +Z cbe8c4c577b21b3ca1560ccfb96c64e5 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 4f0c6af8d4..f60296676d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -38635651f08d42110c01d6b24f6e362e340511846294f8696af4afc795dae80d \ No newline at end of file +2085c7f12a3916ec883c31795e29f2e2b6641c30ecf748cce9bff7b13b061d1f \ No newline at end of file diff --git a/src/insert.c b/src/insert.c index 7303e1950a..627a4892ec 100644 --- a/src/insert.c +++ b/src/insert.c @@ -578,7 +578,7 @@ void sqlite3AutoincrementEnd(Parse *pParse){ #endif /* SQLITE_OMIT_AUTOINCREMENT */ void sqlite3MultiValuesEnd(Parse *pParse, Select *pVal){ - if( pVal->pSrc->nSrc>0 ){ + if( pVal && pVal->pSrc->nSrc>0 ){ SrcItem *pItem = &pVal->pSrc->a[0]; sqlite3VdbeEndCoroutine(pParse->pVdbe, pItem->regReturn); sqlite3VdbeJumpHere(pParse->pVdbe, pItem->addrFillSub - 1); @@ -640,25 +640,24 @@ Select *sqlite3MultiValues(Parse *pParse, Select *pLeft, ExprList *pRow){ Vdbe *v = sqlite3GetVdbe(pParse); Select *pRet; - if( v==0 ) return pLeft; pRet = sqlite3SelectNew(pParse, 0, 0, 0, 0, 0, 0, 0, 0); - if( pRet==0 ) return pLeft; - p = &pRet->pSrc->a[0]; - pRet->pSrc->nSrc = 1; - - p->pSelect = pLeft; - p->fg.viaCoroutine = 1; - p->addrFillSub = sqlite3VdbeCurrentAddr(v) + 1; - p->regReturn = ++pParse->nMem; - p->iCursor = -1; - - sqlite3VdbeAddOp3(v,OP_InitCoroutine,p->regReturn,0,p->addrFillSub); - sqlite3SelectDestInit(&dest, SRT_Coroutine, p->regReturn); - sqlite3Select(pParse, pLeft, &dest); - p->regResult = dest.iSdst; - assert( pParse->nErr || dest.iSdst>0 ); - - pLeft = pRet; + if( pRet ){ + p = &pRet->pSrc->a[0]; + pRet->pSrc->nSrc = 1; + + p->pSelect = pLeft; + p->fg.viaCoroutine = 1; + p->addrFillSub = sqlite3VdbeCurrentAddr(v) + 1; + p->regReturn = ++pParse->nMem; + p->iCursor = -1; + + sqlite3VdbeAddOp3(v,OP_InitCoroutine,p->regReturn,0,p->addrFillSub); + sqlite3SelectDestInit(&dest, SRT_Coroutine, p->regReturn); + sqlite3Select(pParse, pLeft, &dest); + p->regResult = dest.iSdst; + assert( pParse->nErr || dest.iSdst>0 ); + pLeft = pRet; + } }else{ p = &pLeft->pSrc->a[0]; } @@ -686,6 +685,8 @@ Select *sqlite3MultiValues(Parse *pParse, Select *pLeft, ExprList *pRow){ } sqlite3SelectDelete(pParse->db, pSelect); } + }else{ + sqlite3ExprListDelete(pParse->db, pRow); } } From aa2e244e146de01c51be139cc95cec92aa7fe104 Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 13 Mar 2024 18:41:05 +0000 Subject: [PATCH 218/430] Remove unreachable code from this branch. FossilOrigin-Name: 657c7b4f9df53e041a33cfad00ee2f507ac09c97a2ae61164bd189d660d167da --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/insert.c | 53 +++++++++++++++++---------------------------------- 3 files changed, 25 insertions(+), 42 deletions(-) diff --git a/manifest b/manifest index a91c89a359..1f5591b8ed 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\ssome\sOOM\shandling\sproblems\son\sthis\sbranch. -D 2024-03-13T17:33:45.566 +C Remove\sunreachable\scode\sfrom\sthis\sbranch. +D 2024-03-13T18:41:05.450 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -709,7 +709,7 @@ F src/hash.c 9ee4269fb1d6632a6fecfb9479c93a1f29271bddbbaf215dd60420bcb80c7220 F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 -F src/insert.c 7d4e27871c23ad98d062dcf21509573229b41307e125d4569a89e4a489383134 +F src/insert.c 05dd5ea1b8da8a81e1132140fd4dd6d4d9e777ee282799c53cce4f3e9d7dd0ca F src/json.c e2e40760d6689134c3e2ece38c6a496b34ff5e2661a8f238444a119af666fdce F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 @@ -2179,8 +2179,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 38635651f08d42110c01d6b24f6e362e340511846294f8696af4afc795dae80d -R 3557bbe553b856781f68b1001ce502f1 +P 2085c7f12a3916ec883c31795e29f2e2b6641c30ecf748cce9bff7b13b061d1f +R 77c42a89dcd308559626c377320e4df2 U dan -Z cbe8c4c577b21b3ca1560ccfb96c64e5 +Z 54b19091c4c166a485c83de0a7190e37 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index f60296676d..0dc187c408 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2085c7f12a3916ec883c31795e29f2e2b6641c30ecf748cce9bff7b13b061d1f \ No newline at end of file +657c7b4f9df53e041a33cfad00ee2f507ac09c97a2ae61164bd189d660d167da \ No newline at end of file diff --git a/src/insert.c b/src/insert.c index 627a4892ec..49ec5e0dc9 100644 --- a/src/insert.c +++ b/src/insert.c @@ -604,29 +604,29 @@ static int multiValueIsConstantNoAff(ExprList *pRow){ } +/* +** This function is called by the parser for the second and subsequent +** rows of a multi-row VALUES clause. +*/ Select *sqlite3MultiValues(Parse *pParse, Select *pLeft, ExprList *pRow){ - SrcItem *p; - SelectDest dest; - Select *pSelect = 0; - if( pParse->db->init.busy - || pParse->pNewTrigger + if( pLeft->pPrior || pParse->bHasWith + || pParse->db->init.busy || multiValueIsConstant(pRow)==0 - || pLeft->pPrior || (pLeft->pSrc->nSrc==0 && multiValueIsConstantNoAff(pLeft->pEList)==0) ){ /* This row of the VALUES clause cannot be coded immediately. */ + Select *pSelect = 0; int f = SF_Values | SF_MultiValue; if( pLeft->pSrc->nSrc ){ sqlite3MultiValuesEnd(pParse, pLeft); f = SF_Values; }else if( pLeft->pPrior ){ - /* In this case set the SF_MultiValue flag only if it was set on - ** the previous Select structure. */ + /* In this case set the SF_MultiValue flag only if it was set on pLeft */ f = (f & pLeft->selFlags); } - pSelect = sqlite3SelectNew(pParse,pRow,0,0,0,0,0,f,0); + pSelect = sqlite3SelectNew(pParse, pRow, 0, 0, 0, 0, 0, f, 0); pLeft->selFlags &= ~SF_MultiValue; if( pSelect ){ pSelect->op = TK_ALL; @@ -634,6 +634,7 @@ Select *sqlite3MultiValues(Parse *pParse, Select *pLeft, ExprList *pRow){ pLeft = pSelect; } }else{ + SrcItem *p = 0; if( pLeft->pSrc->nSrc==0 ){ /* Co-routine has not yet been started. */ @@ -642,15 +643,14 @@ Select *sqlite3MultiValues(Parse *pParse, Select *pLeft, ExprList *pRow){ pRet = sqlite3SelectNew(pParse, 0, 0, 0, 0, 0, 0, 0, 0); if( pRet ){ - p = &pRet->pSrc->a[0]; + SelectDest dest; pRet->pSrc->nSrc = 1; - + p = &pRet->pSrc->a[0]; p->pSelect = pLeft; p->fg.viaCoroutine = 1; p->addrFillSub = sqlite3VdbeCurrentAddr(v) + 1; p->regReturn = ++pParse->nMem; p->iCursor = -1; - sqlite3VdbeAddOp3(v,OP_InitCoroutine,p->regReturn,0,p->addrFillSub); sqlite3SelectDestInit(&dest, SRT_Coroutine, p->regReturn); sqlite3Select(pParse, pLeft, &dest); @@ -663,31 +663,14 @@ Select *sqlite3MultiValues(Parse *pParse, Select *pLeft, ExprList *pRow){ } if( pParse->nErr==0 ){ - pSelect = sqlite3SelectNew(pParse, pRow, 0, 0, 0, 0, 0, SF_Values, 0); - if( pSelect ){ - if( p->pSelect->pEList->nExpr!=pSelect->pEList->nExpr ){ - sqlite3SelectWrongNumTermsError(pParse, pSelect); - }else{ - sqlite3SelectPrep(pParse, pSelect, 0); -#ifndef SQLITE_OMIT_WINDOWFUNC - if( pSelect->pWin ){ - sqlite3SelectDestInit(&dest, SRT_Coroutine, p->regReturn); - dest.iSdst = p->regResult; - dest.nSdst = pRow->nExpr; - dest.iSDParm = p->regReturn; - sqlite3Select(pParse, pSelect, &dest); - }else -#endif - { - sqlite3ExprCodeExprList(pParse, pSelect->pEList,p->regResult,0,0); - sqlite3VdbeAddOp1(pParse->pVdbe, OP_Yield, p->regReturn); - } - } - sqlite3SelectDelete(pParse->db, pSelect); + if( p->pSelect->pEList->nExpr!=pRow->nExpr ){ + sqlite3SelectWrongNumTermsError(pParse, p->pSelect); + }else{ + sqlite3ExprCodeExprList(pParse, pRow, p->regResult, 0, 0); + sqlite3VdbeAddOp1(pParse->pVdbe, OP_Yield, p->regReturn); } - }else{ - sqlite3ExprListDelete(pParse->db, pRow); } + sqlite3ExprListDelete(pParse->db, pRow); } return pLeft; From 56be6f6c084070026fe720668f644f82fd628f8a Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 13 Mar 2024 20:04:11 +0000 Subject: [PATCH 219/430] Change the way parse.y handles multi-row VALUES clauses to save a few cycles. FossilOrigin-Name: 88d5bc91a52675d2a83748b79ad50de0e9732b2afd23107627bdc604f744d275 --- manifest | 16 ++++----- manifest.uuid | 2 +- src/insert.c | 90 ++++++++++++++++++++++++++++++++++++++++-------- src/parse.y | 34 +++++++++++------- test/values.test | 13 +++++++ 5 files changed, 118 insertions(+), 37 deletions(-) diff --git a/manifest b/manifest index 1f5591b8ed..86fcabaf5e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\sunreachable\scode\sfrom\sthis\sbranch. -D 2024-03-13T18:41:05.450 +C Change\sthe\sway\sparse.y\shandles\smulti-row\sVALUES\sclauses\sto\ssave\sa\sfew\scycles. +D 2024-03-13T20:04:11.997 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -709,7 +709,7 @@ F src/hash.c 9ee4269fb1d6632a6fecfb9479c93a1f29271bddbbaf215dd60420bcb80c7220 F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 -F src/insert.c 05dd5ea1b8da8a81e1132140fd4dd6d4d9e777ee282799c53cce4f3e9d7dd0ca +F src/insert.c 6323a2da33b5af954f914f33e06af30cce354bbd2553261a4b64e578339e498f F src/json.c e2e40760d6689134c3e2ece38c6a496b34ff5e2661a8f238444a119af666fdce F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 @@ -739,7 +739,7 @@ F src/os_win.c 6ff43bac175bd9ed79e7c0f96840b139f2f51d01689a638fd05128becf94908a F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a F src/pager.c ff60e98138d2499082ac6230f01ac508aba545315debccfca2fd6042f5f10fcd F src/pager.h 4b1140d691860de0be1347474c51fee07d5420bd7f802d38cbab8ea4ab9f538a -F src/parse.y 3d022ba4c68bf8c7c4c40b3e364d7a8226c4089fc9ff7a3a95f969f8f1bec959 +F src/parse.y 2ff84e5e346974100b7ed37f01abfd148012e1ce65a6b5a72d5025258077121e F src/pcache.c 040b165f30622a21b7a9a77c6f2e4877a32fb7f22d4c7f0d2a6fa6833a156a75 F src/pcache.h 1497ce1b823cf00094bb0cf3bac37b345937e6f910890c626b16512316d3abf5 F src/pcache1.c 602acb23c471bb8d557a6f0083cc2be641d6cafcafa19e481eba7ef4c9ca0f00 @@ -1921,7 +1921,7 @@ F test/vacuum4.test 7ea76b769fffeb41f925303b04cbcf5a5bbeabe55e4c60ae754ff24eeeb7 F test/vacuum5.test 263b144d537e92ad8e9ca8a73cc6e1583f41cfd0dda9432b87f7806174a2f48c F test/vacuum6.test b137b04bf3392d3f5c3b8fda0ce85a6775a70ca112f6559f74ff52dc9ce042fd F test/vacuummem.test 4b30f5b95a9ff86e9d5c20741e50a898b2dc10b0962a3211571eb165357003fb -F test/values.test 3f0fe0e8859306e9a5cfc800e327278762510c8d5b075d8ddce40f2d13d1405a +F test/values.test 1f0a7f8468d7f087bc4add7a95545afb15e22d5e629a18fbea73b9d76f3ef8bd F test/valuesfault.test 2ef23ed965e3bd08e268cdc38a0d11653390ddbbe1e8e2e98d16f55edd30f6e8 F test/varint.test bbce22cda8fc4d135bcc2b589574be8410614e62 F test/veryquick.test 57ab846bacf7b90cf4e9a672721ea5c5b669b661 @@ -2179,8 +2179,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 2085c7f12a3916ec883c31795e29f2e2b6641c30ecf748cce9bff7b13b061d1f -R 77c42a89dcd308559626c377320e4df2 +P 657c7b4f9df53e041a33cfad00ee2f507ac09c97a2ae61164bd189d660d167da +R c74bcaf2a43ef6c41ceff5cdf5beeb0e U dan -Z 54b19091c4c166a485c83de0a7190e37 +Z dc10b4e059ebbb23528a1aebd608a6c4 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 0dc187c408..e561c09c27 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -657c7b4f9df53e041a33cfad00ee2f507ac09c97a2ae61164bd189d660d167da \ No newline at end of file +88d5bc91a52675d2a83748b79ad50de0e9732b2afd23107627bdc604f744d275 \ No newline at end of file diff --git a/src/insert.c b/src/insert.c index 49ec5e0dc9..9302c10417 100644 --- a/src/insert.c +++ b/src/insert.c @@ -577,6 +577,11 @@ void sqlite3AutoincrementEnd(Parse *pParse){ # define autoIncStep(A,B,C) #endif /* SQLITE_OMIT_AUTOINCREMENT */ +/* +** If argument pVal is a Select object returned by an sqlite3MultiValues() +** that was able to use the co-routine optimization, finish coding the +** co-routine. +*/ void sqlite3MultiValuesEnd(Parse *pParse, Select *pVal){ if( pVal && pVal->pSrc->nSrc>0 ){ SrcItem *pItem = &pVal->pSrc->a[0]; @@ -585,7 +590,11 @@ void sqlite3MultiValuesEnd(Parse *pParse, Select *pVal){ } } -static int multiValueIsConstant(ExprList *pRow){ +/* +** Return true if all expressions in the expression-list passed as the +** only argument are constant. +*/ +static int exprListIsConstant(ExprList *pRow){ int ii; for(ii=0; iinExpr; ii++){ if( 0==sqlite3ExprIsConstant(pRow->a[ii].pExpr) ) return 0; @@ -593,9 +602,13 @@ static int multiValueIsConstant(ExprList *pRow){ return 1; } -static int multiValueIsConstantNoAff(ExprList *pRow){ +/* +** Return true if all expressions in the expression-list passed as the +** only argument are both constant and have no affinity. +*/ +static int exprListIsNoAffinity(ExprList *pRow){ int ii; - if( multiValueIsConstant(pRow)==0 ) return 0; + if( exprListIsConstant(pRow)==0 ) return 0; for(ii=0; iinExpr; ii++){ assert( pRow->a[ii].pExpr->affExpr==0 ); if( 0!=sqlite3ExprAffinity(pRow->a[ii].pExpr) ) return 0; @@ -606,17 +619,64 @@ static int multiValueIsConstantNoAff(ExprList *pRow){ /* ** This function is called by the parser for the second and subsequent -** rows of a multi-row VALUES clause. +** rows of a multi-row VALUES clause. Argument pLeft is the part of +** the VALUES clause already parsed, argument pRow is the vector of values +** for the new row. The Select object returned represents the complete +** VALUES clause, including the new row. +** +** There are two ways in which this may be achieved - by incremental +** coding of a co-routine (the "co-routine" method) or by returning a +** Select object equivalent to the following (the "UNION ALL" method): +** +** "pLeft UNION ALL SELECT pRow" +** +** If the VALUES clause contains a lot of rows, this compound Select +** object may consume a lot of memory. +** +** When the co-routine method is used, each row that will be returned +** by the VALUES clause is coded into part of a co-routine as it is +** passed to this function. The returned Select object is equivalent to: +** +** SELECT * FROM ( +** Select object to read co-routine +** ) +** +** The co-routine method is used in most cases. Exceptions are: +** +** a) If the current statement has a WITH clause. This is to avoid +** statements like: +** +** WITH cte AS ( VALUES('x'), ('y') ... ) +** SELECT * FROM cte AS a, cte AS b; +** +** This will not work, as the co-routine uses a hard-coded register +** for its OP_Yield instructions, and so it is not possible for two +** cursors to iterate through it concurrently. +** +** b) The schema is currently being parsed (i.e. the VALUES clause is part +** of a schema item like a VIEW or TRIGGER). In this case there is no VM +** being generated when parsing is taking place, and so generating +** a co-routine is not possible. +** +** c) There are non-constant expressions in the VALUES clause (e.g. +** the VALUES clause is part of a correlated sub-query). +** +** d) One or more of the values in the first row of the VALUES clause +** has an affinity (i.e. is a CAST expression). This causes problems +** because the complex rules SQLite uses (see function +** sqlite3SubqueryColumnTypes() in select.c) to determine the effective +** affinity of such a column for all rows require access to all values in +** the column simultaneously. */ Select *sqlite3MultiValues(Parse *pParse, Select *pLeft, ExprList *pRow){ - if( pLeft->pPrior - || pParse->bHasWith - || pParse->db->init.busy - || multiValueIsConstant(pRow)==0 - || (pLeft->pSrc->nSrc==0 && multiValueIsConstantNoAff(pLeft->pEList)==0) + if( pLeft->pPrior /* co-routine precluded by prior row */ + || pParse->bHasWith /* condition (a) above */ + || pParse->db->init.busy /* condition (b) above */ + || exprListIsConstant(pRow)==0 /* condition (c) above */ + || (pLeft->pSrc->nSrc==0 && exprListIsNoAffinity(pLeft->pEList)==0) /* (d) */ ){ - /* This row of the VALUES clause cannot be coded immediately. */ + /* The co-routine method cannot be used. Fall back to UNION ALL. */ Select *pSelect = 0; int f = SF_Values | SF_MultiValue; if( pLeft->pSrc->nSrc ){ @@ -634,14 +694,14 @@ Select *sqlite3MultiValues(Parse *pParse, Select *pLeft, ExprList *pRow){ pLeft = pSelect; } }else{ - SrcItem *p = 0; + SrcItem *p = 0; /* SrcItem that reads from co-routine */ if( pLeft->pSrc->nSrc==0 ){ - /* Co-routine has not yet been started. */ + /* Co-routine has not yet been started and the special Select object + ** that accesses the co-routine has not yet been created. This block + ** does both those things. */ Vdbe *v = sqlite3GetVdbe(pParse); - Select *pRet; - - pRet = sqlite3SelectNew(pParse, 0, 0, 0, 0, 0, 0, 0, 0); + Select *pRet = sqlite3SelectNew(pParse, 0, 0, 0, 0, 0, 0, 0, 0); if( pRet ){ SelectDest dest; pRet->pSrc->nSrc = 1; diff --git a/src/parse.y b/src/parse.y index 515d512f2c..36566d28aa 100644 --- a/src/parse.y +++ b/src/parse.y @@ -562,13 +562,10 @@ cmd ::= select(X). { } %ifndef SQLITE_OMIT_CTE -select(A) ::= withkw wqlist(W) selectnowith(X). {A = attachWithToSelect(pParse,X,W);} -select(A) ::= withkw RECURSIVE wqlist(W) selectnowith(X). +select(A) ::= WITH wqlist(W) selectnowith(X). {A = attachWithToSelect(pParse,X,W);} +select(A) ::= WITH RECURSIVE wqlist(W) selectnowith(X). {A = attachWithToSelect(pParse,X,W);} -withkw ::= WITH. { - pParse->bHasWith = 1; -} %endif /* SQLITE_OMIT_CTE */ select(A) ::= selectnowith(A). { Select *p = A; @@ -626,16 +623,26 @@ oneselect(A) ::= SELECT distinct(D) selcollist(W) from(X) where_opt(Y) %endif -oneselect(A) ::= values(A). { - sqlite3MultiValuesEnd(pParse, A); -} - +// Single row VALUES clause. +// %type values {Select*} +oneselect(A) ::= values(A). %destructor values {sqlite3SelectDelete(pParse->db, $$);} values(A) ::= VALUES LP nexprlist(X) RP. { A = sqlite3SelectNew(pParse,X,0,0,0,0,0,SF_Values,0); } -values(A) ::= values(A) COMMA LP nexprlist(Y) RP. { + +// Multiple row VALUES clause. +// +%type mvalues {Select*} +oneselect(A) ::= mvalues(A). { + sqlite3MultiValuesEnd(pParse, A); +} +%destructor mvalues {sqlite3SelectDelete(pParse->db, $$);} +mvalues(A) ::= values(A) COMMA LP nexprlist(Y) RP. { + A = sqlite3MultiValues(pParse, A, Y); +} +mvalues(A) ::= mvalues(A) COMMA LP nexprlist(Y) RP. { A = sqlite3MultiValues(pParse, A, Y); } @@ -1751,16 +1758,17 @@ anylist ::= anylist ANY. with ::= . %ifndef SQLITE_OMIT_CTE -with ::= withkw wqlist(W). { sqlite3WithPush(pParse, W, 1); } -with ::= withkw RECURSIVE wqlist(W). { sqlite3WithPush(pParse, W, 1); } +with ::= WITH wqlist(W). { sqlite3WithPush(pParse, W, 1); } +with ::= WITH RECURSIVE wqlist(W). { sqlite3WithPush(pParse, W, 1); } %type wqas {u8} wqas(A) ::= AS. {A = M10d_Any;} wqas(A) ::= AS MATERIALIZED. {A = M10d_Yes;} wqas(A) ::= AS NOT MATERIALIZED. {A = M10d_No;} -wqitem(A) ::= nm(X) eidlist_opt(Y) wqas(M) LP select(Z) RP. { +wqitem(A) ::= withnm(X) eidlist_opt(Y) wqas(M) LP select(Z) RP. { A = sqlite3CteNew(pParse, &X, Y, Z, M); /*A-overwrites-X*/ } +withnm(A) ::= nm(A). {pParse->bHasWith = 1;} wqlist(A) ::= wqitem(X). { A = sqlite3WithAdd(pParse, 0, X); /*A-overwrites-X*/ } diff --git a/test/values.test b/test/values.test index 627987b43b..7c260260d0 100644 --- a/test/values.test +++ b/test/values.test @@ -267,5 +267,18 @@ do_execsql_test 6.2 { VALUES(CAST(44 AS REAL)),(55); } {44.0 55} +#------------------------------------------------------------------------ +do_execsql_test 7.1 { + WITH x1(a, b) AS ( + VALUES(1, 2), ('a', 'b') + ) + SELECT * FROM x1 one, x1 two +} { + 1 2 1 2 + 1 2 a b + a b 1 2 + a b a b +} + finish_test From a06c046e29d5024efafb1cc5a90fead8731bc96b Mon Sep 17 00:00:00 2001 From: dan Date: Thu, 14 Mar 2024 11:45:39 +0000 Subject: [PATCH 220/430] Add further tests for VALUES clauses in various contexts. FossilOrigin-Name: 973d197d9676c066a95cea77a27e36d2d7f5778283919d8cac4424d2ec952f47 --- manifest | 12 +++---- manifest.uuid | 2 +- test/values.test | 91 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index 86fcabaf5e..92b88f4681 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Change\sthe\sway\sparse.y\shandles\smulti-row\sVALUES\sclauses\sto\ssave\sa\sfew\scycles. -D 2024-03-13T20:04:11.997 +C Add\sfurther\stests\sfor\sVALUES\sclauses\sin\svarious\scontexts. +D 2024-03-14T11:45:39.711 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -1921,7 +1921,7 @@ F test/vacuum4.test 7ea76b769fffeb41f925303b04cbcf5a5bbeabe55e4c60ae754ff24eeeb7 F test/vacuum5.test 263b144d537e92ad8e9ca8a73cc6e1583f41cfd0dda9432b87f7806174a2f48c F test/vacuum6.test b137b04bf3392d3f5c3b8fda0ce85a6775a70ca112f6559f74ff52dc9ce042fd F test/vacuummem.test 4b30f5b95a9ff86e9d5c20741e50a898b2dc10b0962a3211571eb165357003fb -F test/values.test 1f0a7f8468d7f087bc4add7a95545afb15e22d5e629a18fbea73b9d76f3ef8bd +F test/values.test 97a12553a3bb5bae5bdd924e1bdc53540e59d255f5072fe1f744412497ffb8e9 F test/valuesfault.test 2ef23ed965e3bd08e268cdc38a0d11653390ddbbe1e8e2e98d16f55edd30f6e8 F test/varint.test bbce22cda8fc4d135bcc2b589574be8410614e62 F test/veryquick.test 57ab846bacf7b90cf4e9a672721ea5c5b669b661 @@ -2179,8 +2179,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 657c7b4f9df53e041a33cfad00ee2f507ac09c97a2ae61164bd189d660d167da -R c74bcaf2a43ef6c41ceff5cdf5beeb0e +P 88d5bc91a52675d2a83748b79ad50de0e9732b2afd23107627bdc604f744d275 +R ff7025814ffdce6724f42ac930401faa U dan -Z dc10b4e059ebbb23528a1aebd608a6c4 +Z a6579ddbeb44182b511c7d09df6cac16 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index e561c09c27..21731dcc23 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -88d5bc91a52675d2a83748b79ad50de0e9732b2afd23107627bdc604f744d275 \ No newline at end of file +973d197d9676c066a95cea77a27e36d2d7f5778283919d8cac4424d2ec952f47 \ No newline at end of file diff --git a/test/values.test b/test/values.test index 7c260260d0..08f8193f95 100644 --- a/test/values.test +++ b/test/values.test @@ -280,5 +280,96 @@ do_execsql_test 7.1 { a b a b } +#------------------------------------------------------------------------- +reset_db + +set VVV { + ( VALUES('a', 'b'), ('c', 'd'), (123, NULL) ) +} +set VVV2 { + ( + SELECT 'a' AS column1, 'b' AS column2 + UNION ALL SELECT 'c', 'd' UNION ALL SELECT 123, NULL + ) +} + +do_execsql_test 8.0 { + CREATE TABLE t1(x); + INSERT INTO t1 VALUES('d'), (NULL), (123) +} +foreach {tn q res} { + 1 "SELECT * FROM t1 LEFT JOIN VVV" { + d a b d c d d 123 {} + {} a b {} c d {} 123 {} + 123 a b 123 c d 123 123 {} + } + + 2 "SELECT * FROM t1 LEFT JOIN VVV ON (column1=x)" { + d {} {} + {} {} {} + 123 123 {} + } + + 3 "SELECT * FROM t1 RIGHT JOIN VVV" { + d a b d c d d 123 {} + {} a b {} c d {} 123 {} + 123 a b 123 c d 123 123 {} + } + + 4 "SELECT * FROM t1 RIGHT JOIN VVV ON (column1=x)" { + 123 123 {} + {} a b + {} c d + } + + 5 "SELECT * FROM t1 FULL OUTER JOIN VVV ON (column1=x)" { + d {} {} + {} {} {} + 123 123 {} + {} a b + {} c d + } + + 6 "SELECT count(*) FROM VVV" { 3 } + + 7 "SELECT (SELECT column1 FROM VVV)" { a } + + 8 "SELECT * FROM VVV UNION ALL SELECT * FROM VVV" { + a b c d 123 {} + a b c d 123 {} + } + + 9 "SELECT * FROM VVV INTERSECT SELECT * FROM VVV" { + 123 {} a b c d + } + + 10 "SELECT * FROM VVV eXCEPT SELECT * FROM VVV" { } + + 11 "SELECT * FROM VVV eXCEPT SELECT 'a', 'b'" { 123 {} c d } + +} { + set q1 [string map [list VVV $VVV] $q] + set q2 [string map [list VVV $VVV2] $q] + set q3 "WITH VVV AS $VVV $q" + + do_execsql_test 8.1.$tn.1 $q1 $res + do_execsql_test 8.1.$tn.2 $q2 $res + do_execsql_test 8.1.$tn.3 $q3 $res +} + +#------------------------------------------------------------------------- +reset_db + +do_execsql_test 9.1 { + VALUES(456), (123), (NULL) UNION ALL SELECT 122 ORDER BY 1 +} { {} 122 123 456 } + +do_execsql_test 9.2 { + VALUES (1, 2), (3, 4), ( + ( SELECT column1 FROM ( VALUES (5, 6), (7, 8) ) ), + ( SELECT max(column2) FROM ( VALUES (5, 1), (7, 6) ) ) + ) +} { 1 2 3 4 5 6 } + finish_test From 5a0fd81fcec15afd0ecdcbb565b6014ad21b2c96 Mon Sep 17 00:00:00 2001 From: stephan Date: Thu, 14 Mar 2024 13:18:19 +0000 Subject: [PATCH 221/430] JS: remove an unused function argument and some debug-related comments. No functional changes. FossilOrigin-Name: f15709430d4ba2fcf5729bc30a45dacb77102927b82cda12de0b67935b526cc0 --- ext/wasm/api/sqlite3-opfs-async-proxy.js | 9 +++------ manifest | 14 +++++++------- manifest.uuid | 2 +- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/ext/wasm/api/sqlite3-opfs-async-proxy.js b/ext/wasm/api/sqlite3-opfs-async-proxy.js index 58b8bcb233..e671094f04 100644 --- a/ext/wasm/api/sqlite3-opfs-async-proxy.js +++ b/ext/wasm/api/sqlite3-opfs-async-proxy.js @@ -51,7 +51,7 @@ */ "use strict"; const wPost = (type,...args)=>postMessage({type, payload:args}); -const installAsyncProxy = function(self){ +const installAsyncProxy = function(){ const toss = function(...args){throw new Error(args.join(' '))}; if(globalThis.window === globalThis){ toss("This code cannot run from the main thread.", @@ -563,12 +563,9 @@ const installAsyncProxy = function(self){ return; } if( state.opfsFlags.OPFS_UNLINK_BEFORE_OPEN & opfsFlags ){ - //log("async proxy opfsFlags =",opfsFlags); try{ await hDir.removeEntry(filenamePart); - //log("Unlinked",filename,hDir,filenamePart); - } - catch(e){ + }catch(e){ /* ignoring */ //warn("Ignoring failed Unlink of",filename,":",e); } @@ -922,5 +919,5 @@ if(!globalThis.SharedArrayBuffer){ !navigator?.storage?.getDirectory){ wPost('opfs-unavailable',"Missing required OPFS APIs."); }else{ - installAsyncProxy(self); + installAsyncProxy(); } diff --git a/manifest b/manifest index d831726a46..d9e3176a98 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Minor\schange\sto\sthe\s"mdevtest"\sand\s"sdevtest"\sin\stestrunner.tcl,\sto\smake\sit\neasier\sto\sadd\sconfigurations\sin\sbranches. -D 2024-03-13T16:32:05.539 +C JS:\sremove\san\sunused\sfunction\sargument\sand\ssome\sdebug-related\scomments.\sNo\sfunctional\schanges. +D 2024-03-14T13:18:19.313 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -610,7 +610,7 @@ F ext/wasm/api/sqlite3-api-oo1.js 7f3bcf0549ac44cde4b9da0b642d771916738d3f6781fb F ext/wasm/api/sqlite3-api-prologue.js 93a72b07b2a5d964d2edc76a90b439ece49298bd7ba60a1c6ae5d4878213701e F ext/wasm/api/sqlite3-api-worker1.js 8d9c0562831f62218170a3373468d8a0b7a6503b5985e309b69bf71187b525cf F ext/wasm/api/sqlite3-license-version-header.js 0c807a421f0187e778dc1078f10d2994b915123c1223fe752b60afdcd1263f89 -F ext/wasm/api/sqlite3-opfs-async-proxy.js b4c7ce9d7f7957f243d0fbd5b6e28bac80cd3c1b738374cd0c96d89df8f2f316 +F ext/wasm/api/sqlite3-opfs-async-proxy.js 196ad83d36ca794e564044788c9d21b964679d63cad865f604da37c4afc9a285 F ext/wasm/api/sqlite3-vfs-helper.c-pp.js 3f828cc66758acb40e9c5b4dcfd87fd478a14c8fb7f0630264e6c7fa0e57515d F ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js 5a430874906ff3f4a6ca69aadf0c2aaedc1bb45489b8365bff7e955a83a8d42a F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js 3c72f1a0e6a7343c8c882d29d01bb440f10be12c844651605b486e76f3d6cc8c @@ -2177,8 +2177,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 924281b94d8e6ba674d6fe2f7f01da890351355a854e9e6fe623fad1180f7392 -R 92509b8a5762b034ecb1ec5b7039a632 -U drh -Z 644a950afdac6e39b6751ae1898b20f1 +P 9349d94e05dcf266b02afcd89f1e433cdc45f23e8536b2f3f9aa242d5d89c307 +R e2c267441183e97923991728d71c55b9 +U stephan +Z f0980170118e0dee3925f721da1aaab7 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index cd3ae2f7ad..19a52c5ee0 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9349d94e05dcf266b02afcd89f1e433cdc45f23e8536b2f3f9aa242d5d89c307 \ No newline at end of file +f15709430d4ba2fcf5729bc30a45dacb77102927b82cda12de0b67935b526cc0 \ No newline at end of file From f0f43238248e3e6491686acf1104217face58b00 Mon Sep 17 00:00:00 2001 From: dan Date: Thu, 14 Mar 2024 17:04:18 +0000 Subject: [PATCH 222/430] Avoid some OP_SCopy instructions in "INSERT INTO .. VALUES" statements that insert more than one row in cases where the VALUES clause contains a value for all columns of the table. FossilOrigin-Name: 988f0ea70cd21b3194011e0cd1ddd4990a07669e0fd9c37afa48f69698ab7212 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/insert.c | 15 +++++++++++++++ test/values.test | 17 +++++++++++++++++ 4 files changed, 40 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 92b88f4681..4b2722dbe6 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sfurther\stests\sfor\sVALUES\sclauses\sin\svarious\scontexts. -D 2024-03-14T11:45:39.711 +C Avoid\ssome\sOP_SCopy\sinstructions\sin\s"INSERT\sINTO\s..\sVALUES"\sstatements\sthat\sinsert\smore\sthan\sone\srow\sin\scases\swhere\sthe\sVALUES\sclause\scontains\sa\svalue\sfor\sall\scolumns\sof\sthe\stable. +D 2024-03-14T17:04:18.708 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -709,7 +709,7 @@ F src/hash.c 9ee4269fb1d6632a6fecfb9479c93a1f29271bddbbaf215dd60420bcb80c7220 F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 -F src/insert.c 6323a2da33b5af954f914f33e06af30cce354bbd2553261a4b64e578339e498f +F src/insert.c 49b1f253248a7492595ee5b602f8b9f8f5bd25037148ca4429b24bd11d9033ed F src/json.c e2e40760d6689134c3e2ece38c6a496b34ff5e2661a8f238444a119af666fdce F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 @@ -1921,7 +1921,7 @@ F test/vacuum4.test 7ea76b769fffeb41f925303b04cbcf5a5bbeabe55e4c60ae754ff24eeeb7 F test/vacuum5.test 263b144d537e92ad8e9ca8a73cc6e1583f41cfd0dda9432b87f7806174a2f48c F test/vacuum6.test b137b04bf3392d3f5c3b8fda0ce85a6775a70ca112f6559f74ff52dc9ce042fd F test/vacuummem.test 4b30f5b95a9ff86e9d5c20741e50a898b2dc10b0962a3211571eb165357003fb -F test/values.test 97a12553a3bb5bae5bdd924e1bdc53540e59d255f5072fe1f744412497ffb8e9 +F test/values.test 9ec708b15ef0c6a63ece21b2cffcf1bc11cdc96b7fc778e62995de51609afcad F test/valuesfault.test 2ef23ed965e3bd08e268cdc38a0d11653390ddbbe1e8e2e98d16f55edd30f6e8 F test/varint.test bbce22cda8fc4d135bcc2b589574be8410614e62 F test/veryquick.test 57ab846bacf7b90cf4e9a672721ea5c5b669b661 @@ -2179,8 +2179,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 88d5bc91a52675d2a83748b79ad50de0e9732b2afd23107627bdc604f744d275 -R ff7025814ffdce6724f42ac930401faa +P 973d197d9676c066a95cea77a27e36d2d7f5778283919d8cac4424d2ec952f47 +R 35577c4549391d6fa401c7e1873df695 U dan -Z a6579ddbeb44182b511c7d09df6cac16 +Z 98186a481119713b14ebbdd018027220 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 21731dcc23..591f868806 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -973d197d9676c066a95cea77a27e36d2d7f5778283919d8cac4424d2ec952f47 \ No newline at end of file +988f0ea70cd21b3194011e0cd1ddd4990a07669e0fd9c37afa48f69698ab7212 \ No newline at end of file diff --git a/src/insert.c b/src/insert.c index 9302c10417..3fc5f6ccdb 100644 --- a/src/insert.c +++ b/src/insert.c @@ -713,6 +713,16 @@ Select *sqlite3MultiValues(Parse *pParse, Select *pLeft, ExprList *pRow){ p->iCursor = -1; sqlite3VdbeAddOp3(v,OP_InitCoroutine,p->regReturn,0,p->addrFillSub); sqlite3SelectDestInit(&dest, SRT_Coroutine, p->regReturn); + + /* Allocate registers for the output of the co-routine. Do so so + ** that there are two unused registers immediately before those + ** used by the co-routine. This allows the code in sqlite3Insert() + ** to use these registers directly, instead of copying the output + ** of the co-routine to a separate array for processing. */ + dest.iSdst = pParse->nMem + 3; + dest.nSdst = pLeft->pEList->nExpr; + pParse->nMem += 2 + dest.nSdst; + sqlite3Select(pParse, pLeft, &dest); p->regResult = dest.iSdst; assert( pParse->nErr || dest.iSdst>0 ); @@ -1079,6 +1089,11 @@ void sqlite3Insert( dest.iSDParm = regYield = pItem->regReturn; regFromSelect = pItem->regResult; nColumn = pItem->pSelect->pEList->nExpr; + if( bIdListInOrder && nColumn==pTab->nCol ){ + regData = regFromSelect; + regRowid = regData - 1; + regIns = regRowid - (IsVirtual(pTab) ? 1 : 0); + } }else{ int addrTop; /* Top of the co-routine */ regYield = ++pParse->nMem; diff --git a/test/values.test b/test/values.test index 08f8193f95..51fb818a3a 100644 --- a/test/values.test +++ b/test/values.test @@ -371,5 +371,22 @@ do_execsql_test 9.2 { ) } { 1 2 3 4 5 6 } +do_execsql_test 10.1 { + CREATE TABLE a2(a, b, c DEFAULT 'xyz'); +} +do_execsql_test 10.2 { + INSERT INTO a2(a) VALUES(3),(4); +} + +#------------------------------------------------------------------------- +reset_db +ifcapable fts5 { + do_execsql_test 11.0 { + CREATE VIRTUAL TABLE ft USING fts3(x); + } + do_execsql_test 11.1 { + INSERT INTO ft VALUES('one'), ('two'); + } +} finish_test From 400992b1c4e48b10bbfb29301f5582f74e3188a3 Mon Sep 17 00:00:00 2001 From: dan Date: Thu, 14 Mar 2024 19:01:17 +0000 Subject: [PATCH 223/430] Fix a problem handling "INSERT INTO ... SELECT ... UNION VALUES(...), (...)" and similar statements. FossilOrigin-Name: e8a2a8198a97046ff376bc5d38e4bc0a24fcac79f5a0dadb9d29d953a862a012 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/insert.c | 5 ++++- test/values.test | 14 ++++++++++++++ 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 4b2722dbe6..70d506eb4c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Avoid\ssome\sOP_SCopy\sinstructions\sin\s"INSERT\sINTO\s..\sVALUES"\sstatements\sthat\sinsert\smore\sthan\sone\srow\sin\scases\swhere\sthe\sVALUES\sclause\scontains\sa\svalue\sfor\sall\scolumns\sof\sthe\stable. -D 2024-03-14T17:04:18.708 +C Fix\sa\sproblem\shandling\s"INSERT\sINTO\s...\sSELECT\s...\sUNION\sVALUES(...),\s(...)"\sand\ssimilar\sstatements. +D 2024-03-14T19:01:17.847 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -709,7 +709,7 @@ F src/hash.c 9ee4269fb1d6632a6fecfb9479c93a1f29271bddbbaf215dd60420bcb80c7220 F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 -F src/insert.c 49b1f253248a7492595ee5b602f8b9f8f5bd25037148ca4429b24bd11d9033ed +F src/insert.c 609b1862f7047c13f5bf531210b6918367e3f594fddd6deb0f9a3bc90aebc1a5 F src/json.c e2e40760d6689134c3e2ece38c6a496b34ff5e2661a8f238444a119af666fdce F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 @@ -1921,7 +1921,7 @@ F test/vacuum4.test 7ea76b769fffeb41f925303b04cbcf5a5bbeabe55e4c60ae754ff24eeeb7 F test/vacuum5.test 263b144d537e92ad8e9ca8a73cc6e1583f41cfd0dda9432b87f7806174a2f48c F test/vacuum6.test b137b04bf3392d3f5c3b8fda0ce85a6775a70ca112f6559f74ff52dc9ce042fd F test/vacuummem.test 4b30f5b95a9ff86e9d5c20741e50a898b2dc10b0962a3211571eb165357003fb -F test/values.test 9ec708b15ef0c6a63ece21b2cffcf1bc11cdc96b7fc778e62995de51609afcad +F test/values.test f888bc7e833cc84258497f2c1b016f04515db00f9ee2e37ea12164eb9c8f47cf F test/valuesfault.test 2ef23ed965e3bd08e268cdc38a0d11653390ddbbe1e8e2e98d16f55edd30f6e8 F test/varint.test bbce22cda8fc4d135bcc2b589574be8410614e62 F test/veryquick.test 57ab846bacf7b90cf4e9a672721ea5c5b669b661 @@ -2179,8 +2179,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 973d197d9676c066a95cea77a27e36d2d7f5778283919d8cac4424d2ec952f47 -R 35577c4549391d6fa401c7e1873df695 +P 988f0ea70cd21b3194011e0cd1ddd4990a07669e0fd9c37afa48f69698ab7212 +R 15823514808bcf5b8985bdd8c17c3034 U dan -Z 98186a481119713b14ebbdd018027220 +Z 3a0769f650aec425942250a7ea141fa5 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 591f868806..9344f0ae07 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -988f0ea70cd21b3194011e0cd1ddd4990a07669e0fd9c37afa48f69698ab7212 \ No newline at end of file +e8a2a8198a97046ff376bc5d38e4bc0a24fcac79f5a0dadb9d29d953a862a012 \ No newline at end of file diff --git a/src/insert.c b/src/insert.c index 3fc5f6ccdb..428d5c1940 100644 --- a/src/insert.c +++ b/src/insert.c @@ -1084,7 +1084,10 @@ void sqlite3Insert( int regYield; /* Register holding co-routine entry-point */ int rc; /* Result code */ - if( pSelect->pSrc->nSrc==1 && pSelect->pSrc->a[0].fg.viaCoroutine ){ + if( pSelect->pSrc->nSrc==1 + && pSelect->pSrc->a[0].fg.viaCoroutine + && pSelect->pPrior==0 + ){ SrcItem *pItem = &pSelect->pSrc->a[0]; dest.iSDParm = regYield = pItem->regReturn; regFromSelect = pItem->regResult; diff --git a/test/values.test b/test/values.test index 51fb818a3a..3dba3dda94 100644 --- a/test/values.test +++ b/test/values.test @@ -388,5 +388,19 @@ ifcapable fts5 { INSERT INTO ft VALUES('one'), ('two'); } } + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 12.0 { + CREATE TABLE t1(a, b); +} +do_execsql_test 12.1 { + INSERT INTO t1 SELECT 1, 2 UNION ALL VALUES(3, 4), (5, 6); +} +do_execsql_test 12.2 { + SELECT * FROM t1 +} {1 2 3 4 5 6} + + finish_test From 26a3ef7557c6118a717f6555aefc7e424ffe1ca9 Mon Sep 17 00:00:00 2001 From: dan Date: Thu, 14 Mar 2024 19:31:06 +0000 Subject: [PATCH 224/430] Fix a problem with ALTER TABLE and correlated multi-row VALUES clauses. FossilOrigin-Name: d543c829ef74dbd64105bd757ca660e4f02e9ce562be4f1688a701fa535351c4 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/insert.c | 1 + test/altertab3.test | 27 +++++++++++++++++++++++++++ 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 70d506eb4c..fb7853d8f0 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sproblem\shandling\s"INSERT\sINTO\s...\sSELECT\s...\sUNION\sVALUES(...),\s(...)"\sand\ssimilar\sstatements. -D 2024-03-14T19:01:17.847 +C Fix\sa\sproblem\swith\sALTER\sTABLE\sand\scorrelated\smulti-row\sVALUES\sclauses. +D 2024-03-14T19:31:06.929 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -709,7 +709,7 @@ F src/hash.c 9ee4269fb1d6632a6fecfb9479c93a1f29271bddbbaf215dd60420bcb80c7220 F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 -F src/insert.c 609b1862f7047c13f5bf531210b6918367e3f594fddd6deb0f9a3bc90aebc1a5 +F src/insert.c b03721dfe0679445c635c33f137fde594e73abdd5bc042ca3c15990b339151d0 F src/json.c e2e40760d6689134c3e2ece38c6a496b34ff5e2661a8f238444a119af666fdce F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 @@ -867,7 +867,7 @@ F test/altermalloc3.test 8040e486368403f2fdd6fc3998258b499bd4cc2f3ddbb5f8f874cd4 F test/alterqf.test 8ec03d776de9c391daa0078ea8f838903bdcfb11dfae4ba3576b48436834ccba F test/altertab.test 8a2712f9076da5012a002d0b5cc0a421398a5bf61c25bab41b77c427586a7a27 F test/altertab2.test 62597b6fd08feaba1b6bfe7d31dac6117c67e06dc9ce9c478a3abe75b5926de0 -F test/altertab3.test 6c432fbb9963e0bd6549bf1422f6861d744ee5a80cb3298564e81e556481df16 +F test/altertab3.test e167ce3b8e243b52306c1e40b13eb868f402a969513c063998593862cc643b44 F test/altertrig.test aacc980b657354fe2d3d4d3a004f07d04ccc1a93e5ef82d68a79088c274ddc6b F test/amatch1.test b5ae7065f042b7f4c1c922933f4700add50cdb9f F test/analyze.test 2fb21d7d64748636384e6cb8998dbf83968caf644c07fcb4f76c18f2e7ede94b @@ -2179,8 +2179,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 988f0ea70cd21b3194011e0cd1ddd4990a07669e0fd9c37afa48f69698ab7212 -R 15823514808bcf5b8985bdd8c17c3034 +P e8a2a8198a97046ff376bc5d38e4bc0a24fcac79f5a0dadb9d29d953a862a012 +R 52836dd49dafb492a11e027744e0ffa5 U dan -Z 3a0769f650aec425942250a7ea141fa5 +Z 97470bd397212d168f5c1df2d58f75c8 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 9344f0ae07..8c9e08af96 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e8a2a8198a97046ff376bc5d38e4bc0a24fcac79f5a0dadb9d29d953a862a012 \ No newline at end of file +d543c829ef74dbd64105bd757ca660e4f02e9ce562be4f1688a701fa535351c4 \ No newline at end of file diff --git a/src/insert.c b/src/insert.c index 428d5c1940..2bd846e834 100644 --- a/src/insert.c +++ b/src/insert.c @@ -675,6 +675,7 @@ Select *sqlite3MultiValues(Parse *pParse, Select *pLeft, ExprList *pRow){ || pParse->db->init.busy /* condition (b) above */ || exprListIsConstant(pRow)==0 /* condition (c) above */ || (pLeft->pSrc->nSrc==0 && exprListIsNoAffinity(pLeft->pEList)==0) /* (d) */ + || IN_SPECIAL_PARSE ){ /* The co-routine method cannot be used. Fall back to UNION ALL. */ Select *pSelect = 0; diff --git a/test/altertab3.test b/test/altertab3.test index 5fd17f3a2f..cb6f00de48 100644 --- a/test/altertab3.test +++ b/test/altertab3.test @@ -736,4 +736,31 @@ do_execsql_test 29.7 { END} } +#------------------------------------------------------------------------- +reset_db +do_execsql_test 30.0 { + CREATE TABLE t1(a, b); + CREATE VIEW v1 AS + SELECT ( VALUES(a), (b) ) FROM ( + SELECT a, b FROM t1 + ) + ; +} + +do_execsql_test 30.1 { + SELECT * FROM v1 +} + +do_execsql_test 30.1 { + ALTER TABLE t1 RENAME TO t2; +} +do_execsql_test 30.2 { + SELECT sql FROM sqlite_schema WHERE type='view' +} { + {CREATE VIEW v1 AS + SELECT ( VALUES(a), (b) ) FROM ( + SELECT a, b FROM "t2" + )} +} + finish_test From 932b5f457509f5141f75f5cce7a6050124d1cc8c Mon Sep 17 00:00:00 2001 From: drh <> Date: Thu, 14 Mar 2024 20:39:03 +0000 Subject: [PATCH 225/430] Fix testcase to account for new behaviors with this branch. FossilOrigin-Name: 823e579362c05bb8accf6c3b158c5162a16eb23cf81d6021c9e3246e32583d1c --- manifest | 14 +++++++------- manifest.uuid | 2 +- test/sqllimits1.test | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index fb7853d8f0..e6296bc3ee 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sproblem\swith\sALTER\sTABLE\sand\scorrelated\smulti-row\sVALUES\sclauses. -D 2024-03-14T19:31:06.929 +C Fix\stestcase\sto\saccount\sfor\snew\sbehaviors\swith\sthis\sbranch. +D 2024-03-14T20:39:03.615 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -1648,7 +1648,7 @@ F test/spellfix2.test dfc8f519a3fc204cb2dfa8b4f29821ae90f6f8c3 F test/spellfix3.test 0f9efaaa502a0e0a09848028518a6fb096c8ad33 F test/spellfix4.test 51c7c26514ade169855c66bcf130bd5acfb4d7fd090cc624645ab275ae6a41fb F test/sqldiff1.test 1b7ab4f312442c5cc6b3a5f299fa8ca051416d1dd173cb1126fd51bf64f2c3fb -F test/sqllimits1.test 5880a2f107185744ba4d93637f44c78d17706a9899a38b694d50f209735c81cc +F test/sqllimits1.test dee96a51b83ef866d06ec3c687d4c951d97b02549facc5be88c9dfcb215b98bf F test/sqllog.test 6af6cb0b09f4e44e1917e06ce85be7670302517a F test/startup.c 1beb5ca66fcc0fce95c3444db9d1674f90fc605499a574ae2434dcfc10d22805 F test/stat.test 123212a20ceb496893d5254a5f6c76442ce549fdc08d1702d8288a2bbaac8408 @@ -2179,8 +2179,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P e8a2a8198a97046ff376bc5d38e4bc0a24fcac79f5a0dadb9d29d953a862a012 -R 52836dd49dafb492a11e027744e0ffa5 -U dan -Z 97470bd397212d168f5c1df2d58f75c8 +P d543c829ef74dbd64105bd757ca660e4f02e9ce562be4f1688a701fa535351c4 +R 9a3605a04234115bfc68cd6fc0f2125f +U drh +Z eb4b6e81254ae60e2fa77bddac123f09 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 8c9e08af96..ad17c6052c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d543c829ef74dbd64105bd757ca660e4f02e9ce562be4f1688a701fa535351c4 \ No newline at end of file +823e579362c05bb8accf6c3b158c5162a16eb23cf81d6021c9e3246e32583d1c \ No newline at end of file diff --git a/test/sqllimits1.test b/test/sqllimits1.test index e9e20f40cc..14d39e6911 100644 --- a/test/sqllimits1.test +++ b/test/sqllimits1.test @@ -922,7 +922,7 @@ do_catchsql_test sqllimits1-18.1 { do_catchsql_test sqllimits1-18.2 { INSERT INTO b1 VALUES(1), (2), (3), (4), (5), (6), (7), (8), (9), (10) UNION VALUES(11); -} {1 {too many terms in compound SELECT}} +} {0 {}} #------------------------------------------------------------------------- # From 0ebd1c382cfbe4cd5fd09a9929add6b203d93d0a Mon Sep 17 00:00:00 2001 From: drh <> Date: Fri, 15 Mar 2024 13:16:13 +0000 Subject: [PATCH 226/430] Tweaks to the func4.test test module (which tests the rarely used totype.c extension) so that it works on i586 compiled using gcc-13 with -O0. Details at [forum:/forumpost/0a7553b0f734c033|forum post 0a7553b0f734c033]. FossilOrigin-Name: d0fbe779bc2460e120da4f39063a9f4121c700f0b86d85f4311715b1366c3515 --- manifest | 14 +++++++------- manifest.uuid | 2 +- test/func4.test | 35 +++++++++++++++++++++++++++++------ 3 files changed, 37 insertions(+), 14 deletions(-) diff --git a/manifest b/manifest index d9e3176a98..dcb0f53470 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C JS:\sremove\san\sunused\sfunction\sargument\sand\ssome\sdebug-related\scomments.\sNo\sfunctional\schanges. -D 2024-03-14T13:18:19.313 +C Tweaks\sto\sthe\sfunc4.test\stest\smodule\s(which\stests\sthe\srarely\sused\stotype.c\nextension)\sso\sthat\sit\sworks\son\si586\scompiled\susing\sgcc-13\swith\s-O0.\s\sDetails\nat\s[forum:/forumpost/0a7553b0f734c033|forum\spost\s0a7553b0f734c033]. +D 2024-03-15T13:16:13.460 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -1231,7 +1231,7 @@ F test/full.test 6b3c8fb43c6beab6b95438c1675374b95fab245d F test/func.test 504d202650c7940b5aa98364dd68f242df87f39f829e51074a55d79fc7bc7414 F test/func2.test 772d66227e4e6684b86053302e2d74a2500e1e0f F test/func3.test 600a632c305a88f3946d38f9a51efe145c989b2e13bd2b2a488db47fe76bab6a -F test/func4.test e8ef9b2bd6a192a213cbd5cf31a3b35e25cd6ff2fdaeea0b58d63be31b03d220 +F test/func4.test a3f9062487dbd826776f54f4e0e9517fe8c3cf689af92735308965774d51fac5 F test/func5.test 863e6d1bd0013d09c17236f8a13ea34008dd857d87d85a13a673960e4c25d82a F test/func6.test 9cc9b1f43b435af34fe1416eb1e318c8920448ea7a6962f2121972f5215cb9b0 F test/func7.test adbfc910385a6ffd15dc47be3c619ef070c542fcb7488964badb17b2d9a4d080 @@ -2177,8 +2177,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 9349d94e05dcf266b02afcd89f1e433cdc45f23e8536b2f3f9aa242d5d89c307 -R e2c267441183e97923991728d71c55b9 -U stephan -Z f0980170118e0dee3925f721da1aaab7 +P f15709430d4ba2fcf5729bc30a45dacb77102927b82cda12de0b67935b526cc0 +R 5b57f46c94d279354a994dbd1c18ea0b +U drh +Z ac2ce8f2de4e984fc417325734d61778 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 19a52c5ee0..e7275106fa 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f15709430d4ba2fcf5729bc30a45dacb77102927b82cda12de0b67935b526cc0 \ No newline at end of file +d0fbe779bc2460e120da4f39063a9f4121c700f0b86d85f4311715b1366c3515 \ No newline at end of file diff --git a/test/func4.test b/test/func4.test index 64c7a11edc..56cc9063a1 100644 --- a/test/func4.test +++ b/test/func4.test @@ -1,4 +1,4 @@ -# 2013 March 10 +# 2023-03-10 # # The author disclaims copyright to this source code. In place of # a legal notice, here is a blessing: @@ -9,7 +9,10 @@ # #*********************************************************************** # This file implements regression tests for SQLite library. The focus of -# this file is testing the tointeger() and toreal() functions. +# this file is testing the tointeger() and toreal() functions that are +# part of the "totype.c" extension. This file does not test the core +# SQLite library. Failures of tests in this file are related to the +# ext/misc/totype.c extension. # # Several of the toreal() tests are disabled on platforms where floating # point precision is not high enough to represent their constant integer @@ -23,6 +26,20 @@ load_static_extension db totype set highPrecision(1) [expr \ {[db eval {SELECT tointeger(9223372036854775807 + 1);}] eq {{}}}] +set highPrecision(2) [expr \ + {[db eval {SELECT toreal(-9223372036854775808 + 1);}] eq {{}}}] + +# highPrecision(3) is only known to be false on i586 with gcc-13 and -O2. +# It is true on the exact same platform with -O0. Both results seem +# reasonable, so we'll just very the expectation accordingly. +# +set highPrecision(3) [expr \ + {[db eval {SELECT toreal(9007199254740992 + 1);}] eq {{}}}] + +if {!$highPrecision(1) || !$highPrecision(2) || !$highPrecision(3)} { + puts "NOTICE: use_long_double: [use_long_double] \ + highPrecision: $highPrecision(1) $highPrecision(2) $highPrecision(3)" +} do_execsql_test func4-1.1 { SELECT tointeger(NULL); @@ -195,8 +212,6 @@ do_execsql_test func4-1.55 { } {{}} ifcapable floatingpoint { - set highPrecision(2) [expr \ - {[db eval {SELECT toreal(-9223372036854775808 + 1);}] eq {{}}}] do_execsql_test func4-2.1 { SELECT toreal(NULL); @@ -341,10 +356,14 @@ ifcapable floatingpoint { do_execsql_test func4-2.45 { SELECT toreal(9007199254740992); } {9007199254740992.0} - if {$highPrecision(2)} { + if {$highPrecision(3)} { do_execsql_test func4-2.46 { SELECT toreal(9007199254740992 + 1); } {{}} + } else { + do_execsql_test func4-2.46 { + SELECT toreal(9007199254740992 + 1); + } {9007199254740992.0} } do_execsql_test func4-2.47 { SELECT toreal(9007199254740992 + 2); @@ -626,10 +645,14 @@ ifcapable floatingpoint { do_execsql_test func4-5.22 { SELECT tointeger(toreal(9007199254740992)); } {9007199254740992} - if {$highPrecision(2)} { + if {$highPrecision(3)} { do_execsql_test func4-5.23 { SELECT tointeger(toreal(9007199254740992 + 1)); } {{}} + } else { + do_execsql_test func4-5.23 { + SELECT tointeger(toreal(9007199254740992 + 1)); + } {9007199254740992} } do_execsql_test func4-5.24 { SELECT tointeger(toreal(9007199254740992 + 2)); From 825596481fad09348607da0b161216fa7d2ef4ae Mon Sep 17 00:00:00 2001 From: drh <> Date: Fri, 15 Mar 2024 17:04:55 +0000 Subject: [PATCH 227/430] Fix (totally harmless) memory leaks in Lemon to avoid warnings during ASAN builds. FossilOrigin-Name: ce009205a8edc02b7d45ac01bd0e692c3d2c3ffeadb68e4f1bad20c39075e692 --- manifest | 12 +-- manifest.uuid | 2 +- tool/lemon.c | 219 +++++++++++++++++++++++++++++++++----------------- 3 files changed, 153 insertions(+), 80 deletions(-) diff --git a/manifest b/manifest index dcb0f53470..f747e5569e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Tweaks\sto\sthe\sfunc4.test\stest\smodule\s(which\stests\sthe\srarely\sused\stotype.c\nextension)\sso\sthat\sit\sworks\son\si586\scompiled\susing\sgcc-13\swith\s-O0.\s\sDetails\nat\s[forum:/forumpost/0a7553b0f734c033|forum\spost\s0a7553b0f734c033]. -D 2024-03-15T13:16:13.460 +C Fix\s(totally\sharmless)\smemory\sleaks\sin\sLemon\sto\savoid\swarnings\sduring\sASAN\nbuilds. +D 2024-03-15T17:04:55.912 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -2088,7 +2088,7 @@ F tool/genfkey.test b6afd7b825d797a1e1274f519ab5695373552ecad5cd373530c63533638a F tool/getlock.c f4c39b651370156cae979501a7b156bdba50e7ce F tool/index_usage.c f62a0c701b2c7ff2f3e21d206f093c123f222dbf07136a10ffd1ca15a5c706c5 F tool/kvtest-speed.sh 4761a9c4b3530907562314d7757995787f7aef8f -F tool/lemon.c 7f264d5d06450f929a20fa63a1b7e8f2df47dfaa6d7f80e4afef3639157497a4 +F tool/lemon.c 2eaee61479f9b97056950741c8f671a13281c819b94246698264a322360319a9 F tool/lempar.c e6b649778e5c027c8365ff01d7ef39297cd7285fa1f881cce31792689541e79f F tool/libvers.c caafc3b689638a1d88d44bc5f526c2278760d9b9 F tool/loadfts.c c3c64e4d5e90e8ba41159232c2189dba4be7b862 @@ -2177,8 +2177,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P f15709430d4ba2fcf5729bc30a45dacb77102927b82cda12de0b67935b526cc0 -R 5b57f46c94d279354a994dbd1c18ea0b +P d0fbe779bc2460e120da4f39063a9f4121c700f0b86d85f4311715b1366c3515 +R 23ce63f7e666b66fe29613cc12e69c85 U drh -Z ac2ce8f2de4e984fc417325734d61778 +Z 6317df74aefa1b57098e3d6e2401e93c # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index e7275106fa..d62b446349 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d0fbe779bc2460e120da4f39063a9f4121c700f0b86d85f4311715b1366c3515 \ No newline at end of file +ce009205a8edc02b7d45ac01bd0e692c3d2c3ffeadb68e4f1bad20c39075e692 \ No newline at end of file diff --git a/tool/lemon.c b/tool/lemon.c index 0239b2d86f..06b9109a1d 100644 --- a/tool/lemon.c +++ b/tool/lemon.c @@ -59,6 +59,82 @@ static char *msort(char*,char**,int(*)(const char*,const char*)); */ #define lemonStrlen(X) ((int)strlen(X)) +/* +** Header on the linked list of memory allocations. +*/ +typedef struct MemChunk MemChunk; +struct MemChunk { + MemChunk *pNext; + size_t sz; + /* Actually memory follows */ +}; + +/* +** Global linked list of all memory allocations. +*/ +static MemChunk *memChunkList = 0; + +/* +** Wrappers around malloc(), calloc(), realloc() and free(). +** +** All memory allocations are kept on a doubly-linked list. The +** lemon_free_all() function can be called prior to exit to clean +** up any memory leaks. +** +** This is not necessary. But compilers and getting increasingly +** fussy about memory leaks, even in command-line programs like Lemon +** where they do not matter. So this code is provided to hush the +** warnings. +*/ +static void *lemon_malloc(size_t nByte){ + MemChunk *p; + if( nByte<0 ) return 0; + p = malloc( nByte + sizeof(MemChunk) ); + if( p==0 ){ + fprintf(stderr, "Out of memory. Failed to allocate %lld bytes.\n", + (long long int)nByte); + exit(1); + } + p->pNext = memChunkList; + p->sz = nByte; + memChunkList = p; + return (void*)&p[1]; +} +static void *lemon_calloc(size_t nElem, size_t sz){ + void *p = lemon_malloc(nElem*sz); + memset(p, 0, nElem*sz); + return p; +} +static void lemon_free(void *pOld){ + if( pOld ){ + MemChunk *p = (MemChunk*)pOld; + p--; + memset(pOld, 0, p->sz); + } +} +static void *lemon_realloc(void *pOld, size_t nNew){ + void *pNew; + MemChunk *p; + if( pOld==0 ) return lemon_malloc(nNew); + p = (MemChunk*)pOld; + p--; + if( p->sz>=nNew ) return pOld; + pNew = lemon_malloc( nNew ); + memcpy(pNew, pOld, p->sz); + return pNew; +} + +/* Free all outstanding memory allocations. +** Do this right before exiting. +*/ +static void lemon_free_all(void){ + while( memChunkList ){ + MemChunk *pNext = memChunkList->pNext; + free( memChunkList ); + memChunkList = pNext; + } +} + /* ** Compilers are starting to complain about the use of sprintf() and strcpy(), ** saying they are unsafe. So we define our own versions of those routines too. @@ -497,7 +573,7 @@ static struct action *Action_new(void){ if( actionfreelist==0 ){ int i; int amt = 100; - actionfreelist = (struct action *)calloc(amt, sizeof(struct action)); + actionfreelist = (struct action *)lemon_calloc(amt, sizeof(struct action)); if( actionfreelist==0 ){ fprintf(stderr,"Unable to allocate memory for a new parser action."); exit(1); @@ -616,14 +692,14 @@ struct acttab { /* Free all memory associated with the given acttab */ void acttab_free(acttab *p){ - free( p->aAction ); - free( p->aLookahead ); - free( p ); + lemon_free( p->aAction ); + lemon_free( p->aLookahead ); + lemon_free( p ); } /* Allocate a new acttab structure */ acttab *acttab_alloc(int nsymbol, int nterminal){ - acttab *p = (acttab *) calloc( 1, sizeof(*p) ); + acttab *p = (acttab *) lemon_calloc( 1, sizeof(*p) ); if( p==0 ){ fprintf(stderr,"Unable to allocate memory for a new acttab."); exit(1); @@ -642,7 +718,7 @@ acttab *acttab_alloc(int nsymbol, int nterminal){ void acttab_action(acttab *p, int lookahead, int action){ if( p->nLookahead>=p->nLookaheadAlloc ){ p->nLookaheadAlloc += 25; - p->aLookahead = (struct lookahead_action *) realloc( p->aLookahead, + p->aLookahead = (struct lookahead_action *) lemon_realloc( p->aLookahead, sizeof(p->aLookahead[0])*p->nLookaheadAlloc ); if( p->aLookahead==0 ){ fprintf(stderr,"malloc failed\n"); @@ -692,7 +768,7 @@ int acttab_insert(acttab *p, int makeItSafe){ if( p->nAction + n >= p->nActionAlloc ){ int oldAlloc = p->nActionAlloc; p->nActionAlloc = p->nAction + n + p->nActionAlloc + 20; - p->aAction = (struct lookahead_action *) realloc( p->aAction, + p->aAction = (struct lookahead_action *) lemon_realloc( p->aAction, sizeof(p->aAction[0])*p->nActionAlloc); if( p->aAction==0 ){ fprintf(stderr,"malloc failed\n"); @@ -1314,7 +1390,7 @@ static struct config **basisend = 0; /* End of list of basis configs */ /* Return a pointer to a new configuration */ PRIVATE struct config *newconfig(void){ - return (struct config*)calloc(1, sizeof(struct config)); + return (struct config*)lemon_calloc(1, sizeof(struct config)); } /* The configuration "old" is no longer used */ @@ -1530,19 +1606,19 @@ static char *bDefineUsed = 0; /* True for every -D macro actually used */ static void handle_D_option(char *z){ char **paz; nDefine++; - azDefine = (char **) realloc(azDefine, sizeof(azDefine[0])*nDefine); + azDefine = (char **) lemon_realloc(azDefine, sizeof(azDefine[0])*nDefine); if( azDefine==0 ){ fprintf(stderr,"out of memory\n"); exit(1); } - bDefineUsed = (char*)realloc(bDefineUsed, nDefine); + bDefineUsed = (char*)lemon_realloc(bDefineUsed, nDefine); if( bDefineUsed==0 ){ fprintf(stderr,"out of memory\n"); exit(1); } bDefineUsed[nDefine-1] = 0; paz = &azDefine[nDefine-1]; - *paz = (char *) malloc( lemonStrlen(z)+1 ); + *paz = (char *) lemon_malloc( lemonStrlen(z)+1 ); if( *paz==0 ){ fprintf(stderr,"out of memory\n"); exit(1); @@ -1556,7 +1632,7 @@ static void handle_D_option(char *z){ */ static char *outputDir = NULL; static void handle_d_option(char *z){ - outputDir = (char *) malloc( lemonStrlen(z)+1 ); + outputDir = (char *) lemon_malloc( lemonStrlen(z)+1 ); if( outputDir==0 ){ fprintf(stderr,"out of memory\n"); exit(1); @@ -1566,7 +1642,7 @@ static void handle_d_option(char *z){ static char *user_templatename = NULL; static void handle_T_option(char *z){ - user_templatename = (char *) malloc( lemonStrlen(z)+1 ); + user_templatename = (char *) lemon_malloc( lemonStrlen(z)+1 ); if( user_templatename==0 ){ memory_error(); } @@ -1803,6 +1879,7 @@ int main(int argc, char **argv){ /* return 0 on success, 1 on failure. */ exitcode = ((lem.errorcnt > 0) || (lem.nconflict > 0)) ? 1 : 0; + lemon_free_all(); exit(exitcode); return (exitcode); } @@ -2391,7 +2468,7 @@ static void parseonetoken(struct pstate *psp) case IN_RHS: if( x[0]=='.' ){ struct rule *rp; - rp = (struct rule *)calloc( sizeof(struct rule) + + rp = (struct rule *)lemon_calloc( sizeof(struct rule) + sizeof(struct symbol*)*psp->nrhs + sizeof(char*)*psp->nrhs, 1); if( rp==0 ){ ErrorMsg(psp->filename,psp->tokenlineno, @@ -2443,17 +2520,17 @@ static void parseonetoken(struct pstate *psp) struct symbol *msp = psp->rhs[psp->nrhs-1]; if( msp->type!=MULTITERMINAL ){ struct symbol *origsp = msp; - msp = (struct symbol *) calloc(1,sizeof(*msp)); + msp = (struct symbol *) lemon_calloc(1,sizeof(*msp)); memset(msp, 0, sizeof(*msp)); msp->type = MULTITERMINAL; msp->nsubsym = 1; - msp->subsym = (struct symbol **) calloc(1,sizeof(struct symbol*)); + msp->subsym = (struct symbol**)lemon_calloc(1,sizeof(struct symbol*)); msp->subsym[0] = origsp; msp->name = origsp->name; psp->rhs[psp->nrhs-1] = msp; } msp->nsubsym++; - msp->subsym = (struct symbol **) realloc(msp->subsym, + msp->subsym = (struct symbol **) lemon_realloc(msp->subsym, sizeof(struct symbol*)*msp->nsubsym); msp->subsym[msp->nsubsym-1] = Symbol_new(&x[1]); if( ISLOWER(x[1]) || ISLOWER(msp->subsym[0]->name[0]) ){ @@ -2669,7 +2746,7 @@ static void parseonetoken(struct pstate *psp) nLine = lemonStrlen(zLine); n += nLine + lemonStrlen(psp->filename) + nBack; } - *psp->declargslot = (char *) realloc(*psp->declargslot, n); + *psp->declargslot = (char *) lemon_realloc(*psp->declargslot, n); zBuf = *psp->declargslot + nOld; if( addLineMacro ){ if( nOld && zBuf[-1]!='\n' ){ @@ -2783,7 +2860,7 @@ static void parseonetoken(struct pstate *psp) }else if( ISUPPER(x[0]) || ((x[0]=='|' || x[0]=='/') && ISUPPER(x[1])) ){ struct symbol *msp = psp->tkclass; msp->nsubsym++; - msp->subsym = (struct symbol **) realloc(msp->subsym, + msp->subsym = (struct symbol **) lemon_realloc(msp->subsym, sizeof(struct symbol*)*msp->nsubsym); if( !ISUPPER(x[0]) ) x++; msp->subsym[msp->nsubsym-1] = Symbol_new(x); @@ -2998,10 +3075,10 @@ void Parse(struct lemon *gp) fseek(fp,0,2); filesize = ftell(fp); rewind(fp); - filebuf = (char *)malloc( filesize+1 ); + filebuf = (char *)lemon_malloc( filesize+1 ); if( filesize>100000000 || filebuf==0 ){ ErrorMsg(ps.filename,0,"Input file too large."); - free(filebuf); + lemon_free(filebuf); gp->errorcnt++; fclose(fp); return; @@ -3009,7 +3086,7 @@ void Parse(struct lemon *gp) if( fread(filebuf,1,filesize,fp)!=filesize ){ ErrorMsg(ps.filename,0,"Can't read in all %d bytes of this file.", filesize); - free(filebuf); + lemon_free(filebuf); gp->errorcnt++; fclose(fp); return; @@ -3121,7 +3198,7 @@ void Parse(struct lemon *gp) *cp = (char)c; /* Restore the buffer */ cp = nextcp; } - free(filebuf); /* Release the buffer after parsing */ + lemon_free(filebuf); /* Release the buffer after parsing */ gp->rule = ps.firstrule; gp->errorcnt = ps.errorcnt; } @@ -3139,7 +3216,7 @@ struct plink *Plink_new(void){ if( plink_freelist==0 ){ int i; int amt = 100; - plink_freelist = (struct plink *)calloc( amt, sizeof(struct plink) ); + plink_freelist = (struct plink *)lemon_calloc( amt, sizeof(struct plink) ); if( plink_freelist==0 ){ fprintf(stderr, "Unable to allocate memory for a new follow-set propagation link.\n"); @@ -3192,9 +3269,7 @@ void Plink_delete(struct plink *plp) ** Procedures for generating reports and tables in the LEMON parser generator. */ -/* Generate a filename with the given suffix. Space to hold the -** name comes from malloc() and must be freed by the calling -** function. +/* Generate a filename with the given suffix. */ PRIVATE char *file_makename(struct lemon *lemp, const char *suffix) { @@ -3211,7 +3286,7 @@ PRIVATE char *file_makename(struct lemon *lemp, const char *suffix) sz += lemonStrlen(suffix); if( outputDir ) sz += lemonStrlen(outputDir) + 1; sz += 5; - name = (char*)malloc( sz ); + name = (char*)lemon_malloc( sz ); if( name==0 ){ fprintf(stderr,"Can't allocate space for a filename.\n"); exit(1); @@ -3238,7 +3313,7 @@ PRIVATE FILE *file_open( ){ FILE *fp; - if( lemp->outname ) free(lemp->outname); + if( lemp->outname ) lemon_free(lemp->outname); lemp->outname = file_makename(lemp, suffix); fp = fopen(lemp->outname,mode); if( fp==0 && *mode=='w' ){ @@ -3554,14 +3629,14 @@ PRIVATE char *pathsearch(char *argv0, char *name, int modemask) if( cp ){ c = *cp; *cp = 0; - path = (char *)malloc( lemonStrlen(argv0) + lemonStrlen(name) + 2 ); + path = (char *)lemon_malloc( lemonStrlen(argv0) + lemonStrlen(name) + 2 ); if( path ) lemon_sprintf(path,"%s/%s",argv0,name); *cp = c; }else{ pathlist = getenv("PATH"); if( pathlist==0 ) pathlist = ".:/bin:/usr/bin"; - pathbuf = (char *) malloc( lemonStrlen(pathlist) + 1 ); - path = (char *)malloc( lemonStrlen(pathlist)+lemonStrlen(name)+2 ); + pathbuf = (char *) lemon_malloc( lemonStrlen(pathlist) + 1 ); + path = (char *)lemon_malloc( lemonStrlen(pathlist)+lemonStrlen(name)+2 ); if( (pathbuf != 0) && (path!=0) ){ pathbufptr = pathbuf; lemon_strcpy(pathbuf, pathlist); @@ -3577,7 +3652,7 @@ PRIVATE char *pathsearch(char *argv0, char *name, int modemask) if( access(path,modemask)==0 ) break; } } - free(pathbufptr); + lemon_free(pathbufptr); } return path; } @@ -3708,7 +3783,7 @@ PRIVATE FILE *tplt_open(struct lemon *lemp) fprintf(stderr,"Can't open the template file \"%s\".\n",tpltname); lemp->errorcnt++; } - free(toFree); + lemon_free(toFree); return in; } @@ -3837,7 +3912,7 @@ PRIVATE char *append_str(const char *zText, int n, int p1, int p2){ } if( (int) (n+sizeof(zInt)*2+used) >= alloced ){ alloced = n + sizeof(zInt)*2 + used + 200; - z = (char *) realloc(z, alloced); + z = (char *) lemon_realloc(z, alloced); } if( z==0 ) return empty; while( n-- > 0 ){ @@ -4127,7 +4202,7 @@ void print_stack_union( /* Allocate and initialize types[] and allocate stddt[] */ arraysize = lemp->nsymbol * 2; - types = (char**)calloc( arraysize, sizeof(char*) ); + types = (char**)lemon_calloc( arraysize, sizeof(char*) ); if( types==0 ){ fprintf(stderr,"Out of memory.\n"); exit(1); @@ -4144,7 +4219,7 @@ void print_stack_union( len = lemonStrlen(sp->datatype); if( len>maxdtlength ) maxdtlength = len; } - stddt = (char*)malloc( maxdtlength*2 + 1 ); + stddt = (char*)lemon_malloc( maxdtlength*2 + 1 ); if( stddt==0 ){ fprintf(stderr,"Out of memory.\n"); exit(1); @@ -4193,7 +4268,7 @@ void print_stack_union( } if( types[hash]==0 ){ sp->dtnum = hash + 1; - types[hash] = (char*)malloc( lemonStrlen(stddt)+1 ); + types[hash] = (char*)lemon_malloc( lemonStrlen(stddt)+1 ); if( types[hash]==0 ){ fprintf(stderr,"Out of memory.\n"); exit(1); @@ -4215,13 +4290,13 @@ void print_stack_union( for(i=0; ierrsym && lemp->errsym->useCnt ){ fprintf(out," int yy%d;\n",lemp->errsym->dtnum); lineno++; } - free(stddt); - free(types); + lemon_free(stddt); + lemon_free(types); fprintf(out,"} YYMINORTYPE;\n"); lineno++; *plineno = lineno; } @@ -4450,7 +4525,7 @@ void ReportTable( if( mhflag ){ char *incName = file_makename(lemp, ".h"); fprintf(out,"#include \"%s\"\n", incName); lineno++; - free(incName); + lemon_free(incName); } tplt_xfer(lemp->name,in,out,&lineno); @@ -4557,7 +4632,7 @@ void ReportTable( ** table must be computed before generating the YYNSTATE macro because ** we need to know how many states can be eliminated. */ - ax = (struct axset *) calloc(lemp->nxstate*2, sizeof(ax[0])); + ax = (struct axset *) lemon_calloc(lemp->nxstate*2, sizeof(ax[0])); if( ax==0 ){ fprintf(stderr,"malloc failed\n"); exit(1); @@ -4615,7 +4690,7 @@ void ReportTable( } #endif } - free(ax); + lemon_free(ax); /* Mark rules that are actually used for reduce actions after all ** optimizations have been applied @@ -5241,7 +5316,7 @@ void SetSize(int n) /* Allocate a new set */ char *SetNew(void){ char *s; - s = (char*)calloc( size, 1); + s = (char*)lemon_calloc( size, 1); if( s==0 ){ memory_error(); } @@ -5251,7 +5326,7 @@ char *SetNew(void){ /* Deallocate a set */ void SetFree(char *s) { - free(s); + lemon_free(s); } /* Add a new element to the set. Return TRUE if the element was added @@ -5310,7 +5385,7 @@ const char *Strsafe(const char *y) if( y==0 ) return 0; z = Strsafe_find(y); - if( z==0 && (cpy=(char *)malloc( lemonStrlen(y)+1 ))!=0 ){ + if( z==0 && (cpy=(char *)lemon_malloc( lemonStrlen(y)+1 ))!=0 ){ lemon_strcpy(cpy,y); z = cpy; Strsafe_insert(z); @@ -5346,13 +5421,13 @@ static struct s_x1 *x1a; /* Allocate a new associative array */ void Strsafe_init(void){ if( x1a ) return; - x1a = (struct s_x1*)malloc( sizeof(struct s_x1) ); + x1a = (struct s_x1*)lemon_malloc( sizeof(struct s_x1) ); if( x1a ){ x1a->size = 1024; x1a->count = 0; - x1a->tbl = (x1node*)calloc(1024, sizeof(x1node) + sizeof(x1node*)); + x1a->tbl = (x1node*)lemon_calloc(1024, sizeof(x1node) + sizeof(x1node*)); if( x1a->tbl==0 ){ - free(x1a); + lemon_free(x1a); x1a = 0; }else{ int i; @@ -5387,7 +5462,7 @@ int Strsafe_insert(const char *data) struct s_x1 array; array.size = arrSize = x1a->size*2; array.count = x1a->count; - array.tbl = (x1node*)calloc(arrSize, sizeof(x1node) + sizeof(x1node*)); + array.tbl = (x1node*)lemon_calloc(arrSize, sizeof(x1node)+sizeof(x1node*)); if( array.tbl==0 ) return 0; /* Fail due to malloc failure */ array.ht = (x1node**)&(array.tbl[arrSize]); for(i=0; ifrom = &(array.ht[h]); array.ht[h] = newnp; } - /* free(x1a->tbl); // This program was originally for 16-bit machines. + /* lemon_free(x1a->tbl); // This program was originally for 16-bit machines. ** Don't worry about freeing memory on modern platforms. */ *x1a = array; } @@ -5443,7 +5518,7 @@ struct symbol *Symbol_new(const char *x) sp = Symbol_find(x); if( sp==0 ){ - sp = (struct symbol *)calloc(1, sizeof(struct symbol) ); + sp = (struct symbol *)lemon_calloc(1, sizeof(struct symbol) ); MemoryCheck(sp); sp->name = Strsafe(x); sp->type = ISUPPER(*x) ? TERMINAL : NONTERMINAL; @@ -5514,13 +5589,13 @@ static struct s_x2 *x2a; /* Allocate a new associative array */ void Symbol_init(void){ if( x2a ) return; - x2a = (struct s_x2*)malloc( sizeof(struct s_x2) ); + x2a = (struct s_x2*)lemon_malloc( sizeof(struct s_x2) ); if( x2a ){ x2a->size = 128; x2a->count = 0; - x2a->tbl = (x2node*)calloc(128, sizeof(x2node) + sizeof(x2node*)); + x2a->tbl = (x2node*)lemon_calloc(128, sizeof(x2node) + sizeof(x2node*)); if( x2a->tbl==0 ){ - free(x2a); + lemon_free(x2a); x2a = 0; }else{ int i; @@ -5555,7 +5630,7 @@ int Symbol_insert(struct symbol *data, const char *key) struct s_x2 array; array.size = arrSize = x2a->size*2; array.count = x2a->count; - array.tbl = (x2node*)calloc(arrSize, sizeof(x2node) + sizeof(x2node*)); + array.tbl = (x2node*)lemon_calloc(arrSize, sizeof(x2node)+sizeof(x2node*)); if( array.tbl==0 ) return 0; /* Fail due to malloc failure */ array.ht = (x2node**)&(array.tbl[arrSize]); for(i=0; ifrom = &(array.ht[h]); array.ht[h] = newnp; } - /* free(x2a->tbl); // This program was originally written for 16-bit + /* lemon_free(x2a->tbl); // This program was originally written for 16-bit ** machines. Don't worry about freeing this trivial amount of memory ** on modern platforms. Just leak it. */ *x2a = array; @@ -5632,7 +5707,7 @@ struct symbol **Symbol_arrayof() int i,arrSize; if( x2a==0 ) return 0; arrSize = x2a->count; - array = (struct symbol **)calloc(arrSize, sizeof(struct symbol *)); + array = (struct symbol **)lemon_calloc(arrSize, sizeof(struct symbol *)); if( array ){ for(i=0; itbl[i].data; } @@ -5680,7 +5755,7 @@ PRIVATE unsigned statehash(struct config *a) struct state *State_new() { struct state *newstate; - newstate = (struct state *)calloc(1, sizeof(struct state) ); + newstate = (struct state *)lemon_calloc(1, sizeof(struct state) ); MemoryCheck(newstate); return newstate; } @@ -5713,13 +5788,13 @@ static struct s_x3 *x3a; /* Allocate a new associative array */ void State_init(void){ if( x3a ) return; - x3a = (struct s_x3*)malloc( sizeof(struct s_x3) ); + x3a = (struct s_x3*)lemon_malloc( sizeof(struct s_x3) ); if( x3a ){ x3a->size = 128; x3a->count = 0; - x3a->tbl = (x3node*)calloc(128, sizeof(x3node) + sizeof(x3node*)); + x3a->tbl = (x3node*)lemon_calloc(128, sizeof(x3node) + sizeof(x3node*)); if( x3a->tbl==0 ){ - free(x3a); + lemon_free(x3a); x3a = 0; }else{ int i; @@ -5754,7 +5829,7 @@ int State_insert(struct state *data, struct config *key) struct s_x3 array; array.size = arrSize = x3a->size*2; array.count = x3a->count; - array.tbl = (x3node*)calloc(arrSize, sizeof(x3node) + sizeof(x3node*)); + array.tbl = (x3node*)lemon_calloc(arrSize, sizeof(x3node)+sizeof(x3node*)); if( array.tbl==0 ) return 0; /* Fail due to malloc failure */ array.ht = (x3node**)&(array.tbl[arrSize]); for(i=0; ifrom = &(array.ht[h]); array.ht[h] = newnp; } - free(x3a->tbl); + lemon_free(x3a->tbl); *x3a = array; } /* Insert the new data */ @@ -5811,7 +5886,7 @@ struct state **State_arrayof(void) int i,arrSize; if( x3a==0 ) return 0; arrSize = x3a->count; - array = (struct state **)calloc(arrSize, sizeof(struct state *)); + array = (struct state **)lemon_calloc(arrSize, sizeof(struct state *)); if( array ){ for(i=0; itbl[i].data; } @@ -5853,13 +5928,13 @@ static struct s_x4 *x4a; /* Allocate a new associative array */ void Configtable_init(void){ if( x4a ) return; - x4a = (struct s_x4*)malloc( sizeof(struct s_x4) ); + x4a = (struct s_x4*)lemon_malloc( sizeof(struct s_x4) ); if( x4a ){ x4a->size = 64; x4a->count = 0; - x4a->tbl = (x4node*)calloc(64, sizeof(x4node) + sizeof(x4node*)); + x4a->tbl = (x4node*)lemon_calloc(64, sizeof(x4node) + sizeof(x4node*)); if( x4a->tbl==0 ){ - free(x4a); + lemon_free(x4a); x4a = 0; }else{ int i; @@ -5894,7 +5969,8 @@ int Configtable_insert(struct config *data) struct s_x4 array; array.size = arrSize = x4a->size*2; array.count = x4a->count; - array.tbl = (x4node*)calloc(arrSize, sizeof(x4node) + sizeof(x4node*)); + array.tbl = (x4node*)lemon_calloc(arrSize, + sizeof(x4node) + sizeof(x4node*)); if( array.tbl==0 ) return 0; /* Fail due to malloc failure */ array.ht = (x4node**)&(array.tbl[arrSize]); for(i=0; ifrom = &(array.ht[h]); array.ht[h] = newnp; } - /* free(x4a->tbl); // This code was originall written for 16-bit machines. - ** on modern machines, don't worry about freeing this trival amount of - ** memory. */ *x4a = array; } /* Insert the new data */ From d31fc6e9cfd4d25d2fdea2f5aa41fee0a1d5e80c Mon Sep 17 00:00:00 2001 From: drh <> Date: Fri, 15 Mar 2024 17:57:58 +0000 Subject: [PATCH 228/430] New options for testrunner.tcl: --stop-on-error and --stop-on-coredump. FossilOrigin-Name: 82035b9cfd28ef6b0ecc6f469f03d2b001189aa4925147cdb784b6b1964eb3b2 --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/testrunner.tcl | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index f747e5569e..345be73124 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\s(totally\sharmless)\smemory\sleaks\sin\sLemon\sto\savoid\swarnings\sduring\sASAN\nbuilds. -D 2024-03-15T17:04:55.912 +C New\soptions\sfor\stestrunner.tcl:\s\s--stop-on-error\sand\s--stop-on-coredump. +D 2024-03-15T17:57:58.502 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -1687,7 +1687,7 @@ F test/temptable2.test 76821347810ecc88203e6ef0dd6897b6036ac788e9dd3e6b04fd4d163 F test/temptable3.test d11a0974e52b347e45ee54ef1923c91ed91e4637 F test/temptrigger.test 38f0ca479b1822d3117069e014daabcaacefffcc F test/tester.tcl fe617b88c7eb08bdf983d2aaa31c20fbf439eee7b8e0d61ca636fcd0c305bbbf -F test/testrunner.tcl 9f198e41c0d8899d547a5beb4af0c0d512021d18da136918dd96be6a242dbab5 +F test/testrunner.tcl 01bc3b5bc900dc73b076180727eb2869dc61426b1ab95ac2f42def5d1f3d407e F test/testrunner_data.tcl 2f94974e5e3a56af880be72f7a7fd239aa9d4ecf978625435fcc698319c927fa F test/thread001.test a0985c117eab62c0c65526e9fa5d1360dd1cac5b03bde223902763274ce21899 F test/thread002.test c24c83408e35ba5a952a3638b7ac03ccdf1ce4409289c54a050ac4c5f1de7502 @@ -2177,8 +2177,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P d0fbe779bc2460e120da4f39063a9f4121c700f0b86d85f4311715b1366c3515 -R 23ce63f7e666b66fe29613cc12e69c85 +P ce009205a8edc02b7d45ac01bd0e692c3d2c3ffeadb68e4f1bad20c39075e692 +R 6f65d3d8f9136f71ba32b06be27a8871 U drh -Z 6317df74aefa1b57098e3d6e2401e93c +Z 3ec0c84d38eb2a8a3a9b0c26445e8068 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index d62b446349..39c5e3d4e3 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ce009205a8edc02b7d45ac01bd0e692c3d2c3ffeadb68e4f1bad20c39075e692 \ No newline at end of file +82035b9cfd28ef6b0ecc6f469f03d2b001189aa4925147cdb784b6b1964eb3b2 \ No newline at end of file diff --git a/test/testrunner.tcl b/test/testrunner.tcl index e8d0f76864..e8570ddf19 100644 --- a/test/testrunner.tcl +++ b/test/testrunner.tcl @@ -64,6 +64,8 @@ Usage: --dryrun --explain --jobs NUMBER-OF-JOBS + --stop-on-coredump + --stop-on-error --zipvfs ZIPVFS-SOURCE-DIR Special values for PERMUTATION that work with plain tclsh: @@ -172,6 +174,8 @@ set TRG(zipvfs) "" ;# -zipvfs option, if any set TRG(buildonly) 0 ;# True if --buildonly option set TRG(dryrun) 0 ;# True if --dryrun option set TRG(explain) 0 ;# True for the --explain option +set TRG(stopOnError) 0 ;# Stop running at first failure +set TRG(stopOnCore) 0 ;# Stop on a core-dump switch -nocase -glob -- $tcl_platform(os) { *darwin* { @@ -468,6 +472,10 @@ for {set ii 0} {$ii < [llength $argv]} {incr ii} { set TRG(dryrun) 1 } elseif {($n>2 && [string match "$a*" --explain]) || $a=="-e"} { set TRG(explain) 1 + } elseif {[string match "$a*" --stop-on-error]} { + set TRG(stopOnError) 1 + } elseif {[string match "$a*" --stop-on-coredump]} { + set TRG(stopOnCore) 1 } else { usage } @@ -992,6 +1000,14 @@ proc script_input_ready {fd iJob jobid} { } puts "FAILED: $job(displayname) ($iJob)" set state "failed" + if {$TRG(stopOnError)} { + puts "OUTPUT: $O($iJob)" + exit 1 + } + if {$TRG(stopOnCore) && [string first {core dumped} $O($iJob)]>0} { + puts "OUTPUT: $O($iJob)" + exit 1 + } } set tm [clock_milliseconds] From f696591dd45bea11c24d9f219e6f17161a329934 Mon Sep 17 00:00:00 2001 From: drh <> Date: Sat, 16 Mar 2024 13:18:48 +0000 Subject: [PATCH 229/430] Enhance the sqlite3ExprIsConstant() function so that it recognizes constant functions. So far the enhancement only applies to the multi-row VALUES clause, but it could possibly be applied in many other places. FossilOrigin-Name: c9e0488c6c0135932b6e76b0f3f3acd69ef65327e0a54daa59777f35da1aef26 --- manifest | 29 ++++++++++--------- manifest.uuid | 2 +- src/expr.c | 74 +++++++++++++++++++++++++++++++++++++++++++++---- src/insert.c | 19 +++++++------ src/parse.y | 2 +- src/select.c | 6 ++-- src/sqliteInt.h | 2 +- src/where.c | 10 +++---- src/whereexpr.c | 2 +- src/window.c | 2 +- 10 files changed, 108 insertions(+), 40 deletions(-) diff --git a/manifest b/manifest index e6296bc3ee..5926610ec1 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\stestcase\sto\saccount\sfor\snew\sbehaviors\swith\sthis\sbranch. -D 2024-03-14T20:39:03.615 +C Enhance\sthe\ssqlite3ExprIsConstant()\sfunction\sso\sthat\sit\srecognizes\nconstant\sfunctions.\s\sSo\sfar\sthe\senhancement\sonly\sapplies\sto\sthe\smulti-row\nVALUES\sclause,\sbut\sit\scould\spossibly\sbe\sapplied\sin\smany\sother\splaces. +D 2024-03-16T13:18:48.351 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -700,7 +700,7 @@ F src/date.c 126ba2ab10aeb2e7ba6e089b5f07b747c0625b8287f78b60da346eda8d23c875 F src/dbpage.c 80e46e1df623ec40486da7a5086cb723b0275a6e2a7b01d9f9b5da0f04ba2782 F src/dbstat.c 3b677254d512fcafd4d0b341bf267b38b235ccfddbef24f9154e19360fa22e43 F src/delete.c cb766727c78e715f9fb7ec8a7d03658ed2a3016343ca687acfcec9083cdca500 -F src/expr.c 7d0280860f8683fa1e81202304a5107f493fe9bd52be6590d0d0d6c3564c7a07 +F src/expr.c 023e84202023d58bc10cb1f7a4dcc7fe1342e11daa054ea1024e8b78144bd589 F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c a47610f0a5c6cb0ad79f8fcef039c01833dec0c751bb695f28dc0ec6a4c3ba00 F src/func.c 4204c56196847faefef57fa14e43b8e4d65eb8d7e65318abe463472e3fd148cb @@ -709,7 +709,7 @@ F src/hash.c 9ee4269fb1d6632a6fecfb9479c93a1f29271bddbbaf215dd60420bcb80c7220 F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 -F src/insert.c b03721dfe0679445c635c33f137fde594e73abdd5bc042ca3c15990b339151d0 +F src/insert.c e28426630ebbac5763d5802099164ad24fbf46fea79d48a8313117a64b950871 F src/json.c e2e40760d6689134c3e2ece38c6a496b34ff5e2661a8f238444a119af666fdce F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 @@ -739,7 +739,7 @@ F src/os_win.c 6ff43bac175bd9ed79e7c0f96840b139f2f51d01689a638fd05128becf94908a F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a F src/pager.c ff60e98138d2499082ac6230f01ac508aba545315debccfca2fd6042f5f10fcd F src/pager.h 4b1140d691860de0be1347474c51fee07d5420bd7f802d38cbab8ea4ab9f538a -F src/parse.y 2ff84e5e346974100b7ed37f01abfd148012e1ce65a6b5a72d5025258077121e +F src/parse.y 004faaa6b6d6a88d9ec5e535281d7a203e1a03e83617ef8249f40e18bda23dc4 F src/pcache.c 040b165f30622a21b7a9a77c6f2e4877a32fb7f22d4c7f0d2a6fa6833a156a75 F src/pcache.h 1497ce1b823cf00094bb0cf3bac37b345937e6f910890c626b16512316d3abf5 F src/pcache1.c 602acb23c471bb8d557a6f0083cc2be641d6cafcafa19e481eba7ef4c9ca0f00 @@ -750,12 +750,12 @@ F src/printf.c 10e8bad30042f8bd6114a013b4afc229ec8ad255ab27518d7d9f52e8cbc5cd0a F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c ef87e3bc7700bfe761a7bbee2ce6084f1766dc816dd82a3ae77c133eec898432 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 -F src/select.c 2a12c6ed8131db7c49b6f8141c3420cab825cfc6bd222d347fa1382f36b174b7 +F src/select.c 4a3abb346d184a5b1f4f10f10da22465ff18db170099c2d2e0b0cb6ea5f2720e F src/shell.c.in cf80c636bccb0ff9db46995e39d69ca21fde2a8a331d1691e4d62a69d7841c8a F src/sqlite.h.in 19a2db3995a699bd7f6dfb423856242bfceb7ec849a93c91d241d19fc28d9f0f F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 -F src/sqliteInt.h b3ac44ca090011813d5a07f63be59785a4558e74052eb94b686f52eef1af684b +F src/sqliteInt.h 92d3323ba58a1a745f0f6a300d619ea12a6b142f0e8d8d49ce24d84ed85092f1 F src/sqliteLimit.h 6878ab64bdeb8c24a1d762d45635e34b96da21132179023338c93f820eee6728 F src/status.c cb11f8589a6912af2da3bb1ec509a94dd8ef27df4d4c1a97e0bcf2309ece972b F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1 @@ -835,11 +835,11 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c 887fc4ca3f020ebb2e376f222069570834ac63bf50111ef0cbf3ae417048ed89 F src/wal.h ba252daaa94f889f4b2c17c027e823d9be47ce39da1d3799886bbd51f0490452 F src/walker.c 7c7ea0115345851c3da4e04e2e239a29983b61fb5b038b94eede6aba462640e2 -F src/where.c 8bb70b3caadcf35073f8857ecd83d33d97bf6aa03de3342287037bae43c6f364 +F src/where.c 3efa165f9205602eef711af071db3862531fcda2b1ad875cda5e2c5effa56fee F src/whereInt.h 82a13766f13d1a53b05387c2e60726289ef26404bc7b9b1f7770204d97357fb8 F src/wherecode.c 5d77db30a2a3dd532492ae882de114edba2fae672622056b1c7fd61f5917a8f1 -F src/whereexpr.c 6ebd90b553f4bb5c7df5a4b2f39b6a7c81a67484353827cdd2048f2514ec6f30 -F src/window.c 5b1387d59df30d481ed14cceef5f4d1dab1f8752aa106ba72c8b62777bd139d2 +F src/whereexpr.c 7b64295f1d82ad0928df435925dd7bbd5997b44a026153113eace0d9e71ff435 +F src/window.c 5d95122dd330bfaebd732358c8ef067c5a9394a53ac249470d611d0ce2c52be2 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/affinity2.test ce1aafc86e110685b324e9a763eab4f2a73f737842ec3b687bd965867de90627 F test/affinity3.test f094773025eddf31135c7ad4cde722b7696f8eb07b97511f98585addf2a510a9 @@ -2179,8 +2179,11 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P d543c829ef74dbd64105bd757ca660e4f02e9ce562be4f1688a701fa535351c4 -R 9a3605a04234115bfc68cd6fc0f2125f +P 823e579362c05bb8accf6c3b158c5162a16eb23cf81d6021c9e3246e32583d1c +R 2ac63c110cf6a72c96a474d2b73e892b +T *branch * enhanced-expr-is-const +T *sym-enhanced-expr-is-const * +T -sym-exp-values-clause2 * U drh -Z eb4b6e81254ae60e2fa77bddac123f09 +Z 0a7dc94654580f17d6264250f37030ea # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index ad17c6052c..38b8366e49 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -823e579362c05bb8accf6c3b158c5162a16eb23cf81d6021c9e3246e32583d1c \ No newline at end of file +c9e0488c6c0135932b6e76b0f3f3acd69ef65327e0a54daa59777f35da1aef26 \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index e4bfa995d7..6050058e43 100644 --- a/src/expr.c +++ b/src/expr.c @@ -2346,6 +2346,52 @@ Expr *sqlite3ExprSimplifiedAndOr(Expr *pExpr){ return pExpr; } +/* +** pExpr is a TK_FUNCTION node. Try to determine whether or not the +** function is a constant function. A function is constant if all of +** the following are true: +** +** (1) It is a scalar function (not an aggregate or window function) +** (2) It has either the SQLITE_FUNC_CONSTANT or SQLITE_FUNC_SLOCHNG +** property. +** (3) All of its arguments are constants +** +** This routine sets pWalker->eCode to 0 if pExpr is not a constant. +** It makes no changes to pWalker->eCode if pExpr is constant. In +** every case, it returns WRC_Abort. +** +** Called as a service subroutine from exprNodeIsConstant(). +*/ +static SQLITE_NOINLINE int exprNodeIsConstantFunction( + Walker *pWalker, + Expr *pExpr +){ + int n; /* Number of arguments */ + ExprList *pList; /* List of arguments */ + FuncDef *pDef; /* The function */ + sqlite3 *db; /* The database */ + + assert( pExpr->op==TK_FUNCTION ); + if( pWalker->eCode==0 ) return WRC_Abort; + pList = pExpr->x.pList; + if( pList==0 ){ + n = 0; + }else{ + n = pList->nExpr; + sqlite3WalkExprList(pWalker, pList); + if( pWalker->eCode==0 ) return WRC_Abort; + } + db = pWalker->pParse->db; + pDef = sqlite3FindFunction(db, pExpr->u.zToken, n, ENC(db), 0); + if( pDef==0 + || pDef->xFinalize!=0 + || (pDef->funcFlags & (SQLITE_FUNC_CONSTANT|SQLITE_FUNC_SLOCHNG))==0 + ){ + pWalker->eCode = 0; + } + return WRC_Abort; +} + /* ** These routines are Walker callbacks used to check expressions to @@ -2393,6 +2439,8 @@ static int exprNodeIsConstant(Walker *pWalker, Expr *pExpr){ ){ if( pWalker->eCode==5 ) ExprSetProperty(pExpr, EP_FromDDL); return WRC_Continue; + }else if( pWalker->pParse ){ + return exprNodeIsConstantFunction(pWalker, pExpr); }else{ pWalker->eCode = 0; return WRC_Abort; @@ -2448,6 +2496,7 @@ static int exprNodeIsConstant(Walker *pWalker, Expr *pExpr){ static int exprIsConst(Expr *p, int initFlag, int iCur){ Walker w; w.eCode = initFlag; + w.pParse = 0; w.xExprCallback = exprNodeIsConstant; w.xSelectCallback = sqlite3SelectWalkFail; #ifdef SQLITE_DEBUG @@ -2465,9 +2514,24 @@ static int exprIsConst(Expr *p, int initFlag, int iCur){ ** For the purposes of this function, a double-quoted string (ex: "abc") ** is considered a variable but a single-quoted string (ex: 'abc') is ** a constant. +** +** The pParse parameter may be NULL. But if it is NULL, there is no way +** to determine if function calls are constant or not, and hence all +** function calls will be considered to be non-constant. If pParse is +** not NULL, then a function call might be constant, depending on the +** function and on its parameters. */ -int sqlite3ExprIsConstant(Expr *p){ - return exprIsConst(p, 1, 0); +int sqlite3ExprIsConstant(Parse *pParse, Expr *p){ + Walker w; + w.eCode = 1; + w.pParse = pParse; + w.xExprCallback = exprNodeIsConstant; + w.xSelectCallback = sqlite3SelectWalkFail; +#ifdef SQLITE_DEBUG + w.xSelectCallback2 = sqlite3SelectWalkAssert2; +#endif + sqlite3WalkExpr(&w, p); + return w.eCode; } /* @@ -2902,7 +2966,7 @@ static int sqlite3InRhsIsConstant(Expr *pIn){ assert( !ExprHasProperty(pIn, EP_xIsSelect) ); pLHS = pIn->pLeft; pIn->pLeft = 0; - res = sqlite3ExprIsConstant(pIn); + res = sqlite3ExprIsConstant(0, pIn); pIn->pLeft = pLHS; return res; } @@ -3454,7 +3518,7 @@ void sqlite3CodeRhsOfIN( ** this code only executes once. Because for a non-constant ** expression we need to rerun this code each time. */ - if( addrOnce && !sqlite3ExprIsConstant(pE2) ){ + if( addrOnce && !sqlite3ExprIsConstant(0, pE2) ){ sqlite3VdbeChangeToNoop(v, addrOnce-1); sqlite3VdbeChangeToNoop(v, addrOnce); ExprClearProperty(pExpr, EP_Subrtn); @@ -4822,7 +4886,7 @@ int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target){ } for(i=0; ia[i].pExpr) ){ + if( i<32 && sqlite3ExprIsConstant(0, pFarg->a[i].pExpr) ){ testcase( i==31 ); constMask |= MASKBIT32(i); } diff --git a/src/insert.c b/src/insert.c index 2bd846e834..915f368fbd 100644 --- a/src/insert.c +++ b/src/insert.c @@ -594,10 +594,10 @@ void sqlite3MultiValuesEnd(Parse *pParse, Select *pVal){ ** Return true if all expressions in the expression-list passed as the ** only argument are constant. */ -static int exprListIsConstant(ExprList *pRow){ +static int exprListIsConstant(Parse *pParse, ExprList *pRow){ int ii; for(ii=0; iinExpr; ii++){ - if( 0==sqlite3ExprIsConstant(pRow->a[ii].pExpr) ) return 0; + if( 0==sqlite3ExprIsConstant(pParse, pRow->a[ii].pExpr) ) return 0; } return 1; } @@ -606,9 +606,9 @@ static int exprListIsConstant(ExprList *pRow){ ** Return true if all expressions in the expression-list passed as the ** only argument are both constant and have no affinity. */ -static int exprListIsNoAffinity(ExprList *pRow){ +static int exprListIsNoAffinity(Parse *pParse, ExprList *pRow){ int ii; - if( exprListIsConstant(pRow)==0 ) return 0; + if( exprListIsConstant(pParse,pRow)==0 ) return 0; for(ii=0; iinExpr; ii++){ assert( pRow->a[ii].pExpr->affExpr==0 ); if( 0!=sqlite3ExprAffinity(pRow->a[ii].pExpr) ) return 0; @@ -670,11 +670,12 @@ static int exprListIsNoAffinity(ExprList *pRow){ */ Select *sqlite3MultiValues(Parse *pParse, Select *pLeft, ExprList *pRow){ - if( pLeft->pPrior /* co-routine precluded by prior row */ - || pParse->bHasWith /* condition (a) above */ - || pParse->db->init.busy /* condition (b) above */ - || exprListIsConstant(pRow)==0 /* condition (c) above */ - || (pLeft->pSrc->nSrc==0 && exprListIsNoAffinity(pLeft->pEList)==0) /* (d) */ + if( pLeft->pPrior /* co-routine precluded by prior row */ + || pParse->bHasWith /* condition (a) above */ + || pParse->db->init.busy /* condition (b) above */ + || exprListIsConstant(pParse,pRow)==0 /* condition (c) above */ + || (pLeft->pSrc->nSrc==0 && + exprListIsNoAffinity(pParse,pLeft->pEList)==0) /* condition (d) above */ || IN_SPECIAL_PARSE ){ /* The co-routine method cannot be used. Fall back to UNION ALL. */ diff --git a/src/parse.y b/src/parse.y index 36566d28aa..78404ce673 100644 --- a/src/parse.y +++ b/src/parse.y @@ -1325,7 +1325,7 @@ expr(A) ::= expr(A) between_op(N) expr(X) AND expr(Y). [BETWEEN] { if( A ) sqlite3ExprIdToTrueFalse(A); }else{ Expr *pRHS = Y->a[0].pExpr; - if( Y->nExpr==1 && sqlite3ExprIsConstant(pRHS) && A->op!=TK_VECTOR ){ + if( Y->nExpr==1 && sqlite3ExprIsConstant(0,pRHS) && A->op!=TK_VECTOR ){ Y->a[0].pExpr = 0; sqlite3ExprListDelete(pParse->db, Y); pRHS = sqlite3PExpr(pParse, TK_UPLUS, pRHS, 0); diff --git a/src/select.c b/src/select.c index 4158dd2fdc..bffbaa9800 100644 --- a/src/select.c +++ b/src/select.c @@ -4776,7 +4776,7 @@ static void constInsert( ){ int i; assert( pColumn->op==TK_COLUMN ); - assert( sqlite3ExprIsConstant(pValue) ); + assert( sqlite3ExprIsConstant(0, pValue) ); if( ExprHasProperty(pColumn, EP_FixedCol) ) return; if( sqlite3ExprAffinity(pValue)!=0 ) return; @@ -4834,10 +4834,10 @@ static void findConstInWhere(WhereConst *pConst, Expr *pExpr){ pLeft = pExpr->pLeft; assert( pRight!=0 ); assert( pLeft!=0 ); - if( pRight->op==TK_COLUMN && sqlite3ExprIsConstant(pLeft) ){ + if( pRight->op==TK_COLUMN && sqlite3ExprIsConstant(0, pLeft) ){ constInsert(pConst,pRight,pLeft,pExpr); } - if( pLeft->op==TK_COLUMN && sqlite3ExprIsConstant(pRight) ){ + if( pLeft->op==TK_COLUMN && sqlite3ExprIsConstant(0, pRight) ){ constInsert(pConst,pLeft,pRight,pExpr); } } diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 3913392712..205cb6afe0 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -5058,7 +5058,7 @@ void sqlite3LeaveMutexAndCloseZombie(sqlite3*); u32 sqlite3IsTrueOrFalse(const char*); int sqlite3ExprIdToTrueFalse(Expr*); int sqlite3ExprTruthValue(const Expr*); -int sqlite3ExprIsConstant(Expr*); +int sqlite3ExprIsConstant(Parse*,Expr*); int sqlite3ExprIsConstantNotJoin(Expr*); int sqlite3ExprIsConstantOrFunction(Expr*, u8); int sqlite3ExprIsConstantOrGroupBy(Parse*, Expr*, ExprList*); diff --git a/src/where.c b/src/where.c index 9abc8e30f6..2a99c73980 100644 --- a/src/where.c +++ b/src/where.c @@ -1329,7 +1329,7 @@ static sqlite3_index_info *allocateIndexInfo( Expr *pE2; /* Skip over constant terms in the ORDER BY clause */ - if( sqlite3ExprIsConstant(pExpr) ){ + if( sqlite3ExprIsConstant(0, pExpr) ){ continue; } @@ -1441,7 +1441,7 @@ static sqlite3_index_info *allocateIndexInfo( pIdxInfo->nConstraint = j; for(i=j=0; ia[i].pExpr; - if( sqlite3ExprIsConstant(pExpr) ) continue; + if( sqlite3ExprIsConstant(0, pExpr) ) continue; assert( pExpr->op==TK_COLUMN || (pExpr->op==TK_COLLATE && pExpr->pLeft->op==TK_COLUMN && pExpr->iColumn==pExpr->pLeft->iColumn) ); @@ -3623,7 +3623,7 @@ static void wherePartIdxExpr( u8 aff; if( pLeft->op!=TK_COLUMN ) return; - if( !sqlite3ExprIsConstant(pRight) ) return; + if( !sqlite3ExprIsConstant(0, pRight) ) return; if( !sqlite3IsBinary(sqlite3ExprCompareCollSeq(pParse, pPart)) ) return; if( pLeft->iColumn<0 ) return; aff = pIdx->pTable->aCol[pLeft->iColumn].affinity; @@ -4997,7 +4997,7 @@ static i8 wherePathSatisfiesOrderBy( if( MASKBIT(i) & obSat ) continue; p = pOrderBy->a[i].pExpr; mTerm = sqlite3WhereExprUsage(&pWInfo->sMaskSet,p); - if( mTerm==0 && !sqlite3ExprIsConstant(p) ) continue; + if( mTerm==0 && !sqlite3ExprIsConstant(0,p) ) continue; if( (mTerm&~orderDistinctMask)==0 ){ obSat |= MASKBIT(i); } @@ -5866,7 +5866,7 @@ static SQLITE_NOINLINE void whereAddIndexedExpr( }else{ continue; } - if( sqlite3ExprIsConstant(pExpr) ) continue; + if( sqlite3ExprIsConstant(0,pExpr) ) continue; if( pExpr->op==TK_FUNCTION ){ /* Functions that might set a subtype should not be replaced by the ** value taken from an expression index since the index omits the diff --git a/src/whereexpr.c b/src/whereexpr.c index 25db8f396f..9d1f947a09 100644 --- a/src/whereexpr.c +++ b/src/whereexpr.c @@ -989,7 +989,7 @@ static SQLITE_NOINLINE int exprMightBeIndexed2( if( pIdx->aiColumn[i]!=XN_EXPR ) continue; assert( pIdx->bHasExpr ); if( sqlite3ExprCompareSkip(pExpr,pIdx->aColExpr->a[i].pExpr,iCur)==0 - && !sqlite3ExprIsConstant(pIdx->aColExpr->a[i].pExpr) + && !sqlite3ExprIsConstant(0,pIdx->aColExpr->a[i].pExpr) ){ aiCurCol[0] = iCur; aiCurCol[1] = XN_EXPR; diff --git a/src/window.c b/src/window.c index 62df349fb3..bcee65d924 100644 --- a/src/window.c +++ b/src/window.c @@ -1164,7 +1164,7 @@ void sqlite3WindowListDelete(sqlite3 *db, Window *p){ ** variable values in the expression tree. */ static Expr *sqlite3WindowOffsetExpr(Parse *pParse, Expr *pExpr){ - if( 0==sqlite3ExprIsConstant(pExpr) ){ + if( 0==sqlite3ExprIsConstant(0,pExpr) ){ if( IN_RENAME_OBJECT ) sqlite3RenameExprUnmap(pParse, pExpr); sqlite3ExprDelete(pParse->db, pExpr); pExpr = sqlite3ExprAlloc(pParse->db, TK_NULL, 0, 0); From 40514dd1f661ad05b679cda3df90ed4efd0133fc Mon Sep 17 00:00:00 2001 From: dan Date: Sat, 16 Mar 2024 14:27:10 +0000 Subject: [PATCH 230/430] Fix exprNodeIsConstantFunction() so that it returns WRC_Continue, not WRC_Abort, if the function really is constant. FossilOrigin-Name: d85dd4de2d0989127e0ae6a2eec9d83a577777f8d5ba40700084a0b498016634 --- manifest | 19 ++++++++----------- manifest.uuid | 2 +- src/expr.c | 3 ++- test/values.test | 13 +++++++++++++ 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/manifest b/manifest index 5926610ec1..521628dfe1 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Enhance\sthe\ssqlite3ExprIsConstant()\sfunction\sso\sthat\sit\srecognizes\nconstant\sfunctions.\s\sSo\sfar\sthe\senhancement\sonly\sapplies\sto\sthe\smulti-row\nVALUES\sclause,\sbut\sit\scould\spossibly\sbe\sapplied\sin\smany\sother\splaces. -D 2024-03-16T13:18:48.351 +C Fix\sexprNodeIsConstantFunction()\sso\sthat\sit\sreturns\sWRC_Continue,\snot\sWRC_Abort,\sif\sthe\sfunction\sreally\sis\sconstant. +D 2024-03-16T14:27:10.517 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -700,7 +700,7 @@ F src/date.c 126ba2ab10aeb2e7ba6e089b5f07b747c0625b8287f78b60da346eda8d23c875 F src/dbpage.c 80e46e1df623ec40486da7a5086cb723b0275a6e2a7b01d9f9b5da0f04ba2782 F src/dbstat.c 3b677254d512fcafd4d0b341bf267b38b235ccfddbef24f9154e19360fa22e43 F src/delete.c cb766727c78e715f9fb7ec8a7d03658ed2a3016343ca687acfcec9083cdca500 -F src/expr.c 023e84202023d58bc10cb1f7a4dcc7fe1342e11daa054ea1024e8b78144bd589 +F src/expr.c b3914ec5ac4f1c43d0743123fabab27c089f16dcfdcfd47973e2eebe0834f94b F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c a47610f0a5c6cb0ad79f8fcef039c01833dec0c751bb695f28dc0ec6a4c3ba00 F src/func.c 4204c56196847faefef57fa14e43b8e4d65eb8d7e65318abe463472e3fd148cb @@ -1921,7 +1921,7 @@ F test/vacuum4.test 7ea76b769fffeb41f925303b04cbcf5a5bbeabe55e4c60ae754ff24eeeb7 F test/vacuum5.test 263b144d537e92ad8e9ca8a73cc6e1583f41cfd0dda9432b87f7806174a2f48c F test/vacuum6.test b137b04bf3392d3f5c3b8fda0ce85a6775a70ca112f6559f74ff52dc9ce042fd F test/vacuummem.test 4b30f5b95a9ff86e9d5c20741e50a898b2dc10b0962a3211571eb165357003fb -F test/values.test f888bc7e833cc84258497f2c1b016f04515db00f9ee2e37ea12164eb9c8f47cf +F test/values.test 60723a55f68e8e42027d49a159a1be8b92cb0f538a65cb363ff65637e8a41703 F test/valuesfault.test 2ef23ed965e3bd08e268cdc38a0d11653390ddbbe1e8e2e98d16f55edd30f6e8 F test/varint.test bbce22cda8fc4d135bcc2b589574be8410614e62 F test/veryquick.test 57ab846bacf7b90cf4e9a672721ea5c5b669b661 @@ -2179,11 +2179,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 823e579362c05bb8accf6c3b158c5162a16eb23cf81d6021c9e3246e32583d1c -R 2ac63c110cf6a72c96a474d2b73e892b -T *branch * enhanced-expr-is-const -T *sym-enhanced-expr-is-const * -T -sym-exp-values-clause2 * -U drh -Z 0a7dc94654580f17d6264250f37030ea +P c9e0488c6c0135932b6e76b0f3f3acd69ef65327e0a54daa59777f35da1aef26 +R 073539ebd1c8b85d1f5a19f0731cb417 +U dan +Z afcb8a3f36080c6ea414186a5d7c11c8 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 38b8366e49..35e0b4aa0d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c9e0488c6c0135932b6e76b0f3f3acd69ef65327e0a54daa59777f35da1aef26 \ No newline at end of file +d85dd4de2d0989127e0ae6a2eec9d83a577777f8d5ba40700084a0b498016634 \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index 6050058e43..95567de799 100644 --- a/src/expr.c +++ b/src/expr.c @@ -2388,8 +2388,9 @@ static SQLITE_NOINLINE int exprNodeIsConstantFunction( || (pDef->funcFlags & (SQLITE_FUNC_CONSTANT|SQLITE_FUNC_SLOCHNG))==0 ){ pWalker->eCode = 0; + return WRC_Abort; } - return WRC_Abort; + return WRC_Continue; } diff --git a/test/values.test b/test/values.test index 3dba3dda94..b96c9e5d23 100644 --- a/test/values.test +++ b/test/values.test @@ -401,6 +401,19 @@ do_execsql_test 12.2 { SELECT * FROM t1 } {1 2 3 4 5 6} +#------------------------------------------------------------------------- +reset_db +do_execsql_test 13.0 { + CREATE TABLE t1(x); + INSERT INTO t1 VALUES('xyz'); + + SELECT ( + VALUES( (max(substr('abc', 1, 1), x)) ), + (123), + (456) + ) + FROM t1; +} {xyz} finish_test From bf4105d76851ba3fb4ad56190284f9ebc6decfd8 Mon Sep 17 00:00:00 2001 From: drh <> Date: Sat, 16 Mar 2024 17:04:08 +0000 Subject: [PATCH 231/430] Extend the scope expr-is-constant for function to cover the IN-to-EQ optimization. FossilOrigin-Name: dae669245c86021bcd28716aff6e316257cc8075d02081745d4b7de17f8ad553 --- manifest | 18 +++++++++--------- manifest.uuid | 2 +- src/parse.y | 2 +- src/test1.c | 21 +++++++++++++++++++++ test/in4.test | 5 +++-- 5 files changed, 35 insertions(+), 13 deletions(-) diff --git a/manifest b/manifest index 521628dfe1..bbfca938b7 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sexprNodeIsConstantFunction()\sso\sthat\sit\sreturns\sWRC_Continue,\snot\sWRC_Abort,\sif\sthe\sfunction\sreally\sis\sconstant. -D 2024-03-16T14:27:10.517 +C Extend\sthe\sscope\sexpr-is-constant\sfor\sfunction\sto\scover\sthe\sIN-to-EQ\noptimization. +D 2024-03-16T17:04:08.435 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -739,7 +739,7 @@ F src/os_win.c 6ff43bac175bd9ed79e7c0f96840b139f2f51d01689a638fd05128becf94908a F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a F src/pager.c ff60e98138d2499082ac6230f01ac508aba545315debccfca2fd6042f5f10fcd F src/pager.h 4b1140d691860de0be1347474c51fee07d5420bd7f802d38cbab8ea4ab9f538a -F src/parse.y 004faaa6b6d6a88d9ec5e535281d7a203e1a03e83617ef8249f40e18bda23dc4 +F src/parse.y 5bcef16094213efcc365a9d4dc4e3131f09251dc8838dce4a9e5f9764bff5b82 F src/pcache.c 040b165f30622a21b7a9a77c6f2e4877a32fb7f22d4c7f0d2a6fa6833a156a75 F src/pcache.h 1497ce1b823cf00094bb0cf3bac37b345937e6f910890c626b16512316d3abf5 F src/pcache1.c 602acb23c471bb8d557a6f0083cc2be641d6cafcafa19e481eba7ef4c9ca0f00 @@ -760,7 +760,7 @@ F src/sqliteLimit.h 6878ab64bdeb8c24a1d762d45635e34b96da21132179023338c93f820eee F src/status.c cb11f8589a6912af2da3bb1ec509a94dd8ef27df4d4c1a97e0bcf2309ece972b F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1 F src/tclsqlite.c ecbc3c99c0d0c3ed122a913f143026c26d38d57f33e06bb71185dd5c1efe37cd -F src/test1.c 310f43eb17a9252a7790726ca652e4ea3197da17c19eec93b8578863a49dc7b4 +F src/test1.c 5a67577fa7d93a19a72aa165b7013606a35e53f62d0de11587940aed5797d92d F src/test2.c 54520d0565ef2b9bf0f8f1dcac43dc4d06baf4ffe13d10905f8d8c3ad3e4b9ab F src/test3.c e5178558c41ff53236ae0271e9acb3d6885a94981d2eb939536ee6474598840e F src/test4.c 4533b76419e7feb41b40582554663ed3cd77aaa54e135cf76b3205098cd6e664 @@ -1271,7 +1271,7 @@ F test/imposter1.test c3f1db2d3db2c24611a6596a3fc0ffc14f1466c8 F test/in.test d1cad4ededd425568b2e39fb0c31fa9a3772311dd595801ff13ba3912b69bba6 F test/in2.test 5d4c61d17493c832f7d2d32bef785119e87bde75 F test/in3.test 3cbf58c87f4052cee3a58b37b6389777505aa0c0 -F test/in4.test fdd1d8134da8376985c2edba6035a2de1f6c731524d2ffa651419e8fe2cd1c5a +F test/in4.test 176719161ba96c9386027891602700738aadac3419964f72b628f59d2071d53d F test/in5.test b32ce7f4a93f44c5dee94af16886d922cc16ebe33c8e1765c73d4049d0f4b40f F test/in6.test f5f40d6816a8bb7c784424b58a10ac38efb76ab29127a2c17399e0cbeeda0e4b F test/incrblob.test c9b96afc292aeff43d6687bcb09b0280aa599822 @@ -2179,8 +2179,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P c9e0488c6c0135932b6e76b0f3f3acd69ef65327e0a54daa59777f35da1aef26 -R 073539ebd1c8b85d1f5a19f0731cb417 -U dan -Z afcb8a3f36080c6ea414186a5d7c11c8 +P d85dd4de2d0989127e0ae6a2eec9d83a577777f8d5ba40700084a0b498016634 +R ca429b76372fd82d8194dbd47566db28 +U drh +Z 9b82b5806afe1db311bd1eb3f3eb021c # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 35e0b4aa0d..23dbdeae40 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d85dd4de2d0989127e0ae6a2eec9d83a577777f8d5ba40700084a0b498016634 \ No newline at end of file +dae669245c86021bcd28716aff6e316257cc8075d02081745d4b7de17f8ad553 \ No newline at end of file diff --git a/src/parse.y b/src/parse.y index 78404ce673..d22c8e6fc2 100644 --- a/src/parse.y +++ b/src/parse.y @@ -1325,7 +1325,7 @@ expr(A) ::= expr(A) between_op(N) expr(X) AND expr(Y). [BETWEEN] { if( A ) sqlite3ExprIdToTrueFalse(A); }else{ Expr *pRHS = Y->a[0].pExpr; - if( Y->nExpr==1 && sqlite3ExprIsConstant(0,pRHS) && A->op!=TK_VECTOR ){ + if( Y->nExpr==1 && sqlite3ExprIsConstant(pParse,pRHS) && A->op!=TK_VECTOR ){ Y->a[0].pExpr = 0; sqlite3ExprListDelete(pParse->db, Y); pRHS = sqlite3PExpr(pParse, TK_UPLUS, pRHS, 0); diff --git a/src/test1.c b/src/test1.c index 8faf5a397b..a552c3f509 100644 --- a/src/test1.c +++ b/src/test1.c @@ -1024,6 +1024,23 @@ static void addRealTypeFunction( sqlite3_result_value(context, argv[0]); } +/* +** Implementation of the noop(X) SQL function. +** +** The result is just a copy of its argument. However, this function +** does not have the SQLITE_FUNC_CONSTANT flag, so it is consider +** non-constant by sqlite3ExprIsConstant(). +*/ +static void noopFunction( + sqlite3_context *context, + int argc, + sqlite3_value **argv +){ + (void)argc; + sqlite3_result_value(context, argv[0]); +} + + /* ** SQL function: strtod(X) ** @@ -1151,6 +1168,10 @@ static int SQLITE_TCLAPI test_create_function( rc = sqlite3_create_function(db, "add_real_type", 1, SQLITE_UTF8, 0, addRealTypeFunction, 0, 0); } + if( rc==SQLITE_OK ){ + rc = sqlite3_create_function(db, "noop", 1, SQLITE_UTF8, + 0, noopFunction, 0, 0); + } /* Functions strtod() and dtostr() work as in the shell. These routines ** use the standard C library to convert between floating point and diff --git a/test/in4.test b/test/in4.test index a3fe22e787..81f2b2840d 100644 --- a/test/in4.test +++ b/test/in4.test @@ -455,17 +455,18 @@ do_execsql_test 11.0 { INSERT INTO sqlite_stat1 VALUES('t1','t1abc','10000 5 00 2003 10'); ANALYZE sqlite_schema; } {} +sqlite3_create_function db do_execsql_test 11.1 { SELECT * FROM t1 WHERE b IN (345, (SELECT 1 FROM t1 - WHERE b IN (345 NOT GLOB 510) + WHERE b IN (noop(1)) AND c GLOB 'abc*xyz')) AND c BETWEEN 'abc' AND 'xyz'; } {xyz 1 abcdefxyz 99} do_execsql_test 11.2 { EXPLAIN SELECT * FROM t1 WHERE b IN (345, (SELECT 1 FROM t1 - WHERE b IN (345 NOT GLOB 510) + WHERE b IN (noop(1)) AND c GLOB 'abc*xyz')) AND c BETWEEN 'abc' AND 'xyz'; } {/ SeekScan /} From b918a0f8215b43d62e2824dbe439261cafaf48c2 Mon Sep 17 00:00:00 2001 From: drh <> Date: Sat, 16 Mar 2024 19:36:18 +0000 Subject: [PATCH 232/430] Activate the enhanced constant-expression for the [constant propagation optimization](/info/f4229707ac08d66c). FossilOrigin-Name: 92afea38881a1a4f266c79ddc6e1027cf17c288dcc8f7e7d50466899ac0054c4 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/select.c | 6 +++--- test/whereL.test | 26 ++++++++++++++++++++++++++ 4 files changed, 37 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index bbfca938b7..8f71171d11 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Extend\sthe\sscope\sexpr-is-constant\sfor\sfunction\sto\scover\sthe\sIN-to-EQ\noptimization. -D 2024-03-16T17:04:08.435 +C Activate\sthe\senhanced\sconstant-expression\sfor\sthe\n[constant\spropagation\soptimization](/info/f4229707ac08d66c). +D 2024-03-16T19:36:18.764 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -750,7 +750,7 @@ F src/printf.c 10e8bad30042f8bd6114a013b4afc229ec8ad255ab27518d7d9f52e8cbc5cd0a F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c ef87e3bc7700bfe761a7bbee2ce6084f1766dc816dd82a3ae77c133eec898432 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 -F src/select.c 4a3abb346d184a5b1f4f10f10da22465ff18db170099c2d2e0b0cb6ea5f2720e +F src/select.c df2bf515fc36e02e97959a70e82da8a4967d6c85590646a7fda2926a734c81ce F src/shell.c.in cf80c636bccb0ff9db46995e39d69ca21fde2a8a331d1691e4d62a69d7841c8a F src/sqlite.h.in 19a2db3995a699bd7f6dfb423856242bfceb7ec849a93c91d241d19fc28d9f0f F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 @@ -2011,7 +2011,7 @@ F test/whereH.test e4b07f7a3c2f5d31195cd33710054c78667573b2 F test/whereI.test c4bb7e2ca56d49bd8ab5c7bd085b8b83e353922b46904d68aefb3c7468643581 F test/whereJ.test fc05e374cc9f2dc204148d6c06822c380ad388895fe97a6d335b94a26a08aecf F test/whereK.test 0270ab7f04ba5436fb9156d31d642a1c82727f4c4bfe5ba90d435c78cf44684a -F test/whereL.test f0e9585623af522ee9f382f8f945ad4b7eb7d806d18746f33f00c374acf6ab65 +F test/whereL.test bf41203fda5e19e4c554a296b4ad2ff3eb27207549b94a819a2bc37275b4529d F test/whereM.test 0dbc9998783458ddcf3cc078ca7c2951d8b2677d472ecf0028f449ed327c0250 F test/wherefault.test 6cf2a9c5712952d463d3f45ebee7f6caf400984df51a195d884cfb7eb0e837a7 F test/wherelfault.test 9012e4ef5259058b771606616bd007af5d154e64cc25fa9fd4170f6411db44e3 @@ -2179,8 +2179,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P d85dd4de2d0989127e0ae6a2eec9d83a577777f8d5ba40700084a0b498016634 -R ca429b76372fd82d8194dbd47566db28 +P dae669245c86021bcd28716aff6e316257cc8075d02081745d4b7de17f8ad553 +R 02d7863e0170a404854cbdb7daab35da U drh -Z 9b82b5806afe1db311bd1eb3f3eb021c +Z 4782493dacf06603b1147674a9e69d60 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 23dbdeae40..7aaeff4fab 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -dae669245c86021bcd28716aff6e316257cc8075d02081745d4b7de17f8ad553 \ No newline at end of file +92afea38881a1a4f266c79ddc6e1027cf17c288dcc8f7e7d50466899ac0054c4 \ No newline at end of file diff --git a/src/select.c b/src/select.c index bffbaa9800..1085b99436 100644 --- a/src/select.c +++ b/src/select.c @@ -4776,7 +4776,7 @@ static void constInsert( ){ int i; assert( pColumn->op==TK_COLUMN ); - assert( sqlite3ExprIsConstant(0, pValue) ); + assert( sqlite3ExprIsConstant(pConst->pParse, pValue) ); if( ExprHasProperty(pColumn, EP_FixedCol) ) return; if( sqlite3ExprAffinity(pValue)!=0 ) return; @@ -4834,10 +4834,10 @@ static void findConstInWhere(WhereConst *pConst, Expr *pExpr){ pLeft = pExpr->pLeft; assert( pRight!=0 ); assert( pLeft!=0 ); - if( pRight->op==TK_COLUMN && sqlite3ExprIsConstant(0, pLeft) ){ + if( pRight->op==TK_COLUMN && sqlite3ExprIsConstant(pConst->pParse, pLeft) ){ constInsert(pConst,pRight,pLeft,pExpr); } - if( pLeft->op==TK_COLUMN && sqlite3ExprIsConstant(0, pRight) ){ + if( pLeft->op==TK_COLUMN && sqlite3ExprIsConstant(pConst->pParse, pRight) ){ constInsert(pConst,pLeft,pRight,pExpr); } } diff --git a/test/whereL.test b/test/whereL.test index 068ee05cd4..9d1054964c 100644 --- a/test/whereL.test +++ b/test/whereL.test @@ -49,6 +49,32 @@ do_eqp_test 120 { |--SEARCH t2 USING INDEX sqlite_autoindex_t2_1 (a=?) `--SCAN t3 } +do_eqp_test 121 { + SELECT * FROM t1, t2, t3 + WHERE t1.a=t2.a AND t2.a=t3.j AND t3.j=abs(5) + ORDER BY t1.a; +} { + QUERY PLAN + |--SEARCH t1 USING INDEX sqlite_autoindex_t1_1 (a=?) + |--SEARCH t2 USING INDEX sqlite_autoindex_t2_1 (a=?) + `--SCAN t3 +} + +# The sqlite3ExprIsConstant() routine does not believe that noop(3) +# is constant. So the optimization does not apply in this case. +# +sqlite3_create_function db +do_eqp_test 122 { + SELECT * FROM t1, t2, t3 + WHERE t1.a=t2.a AND t2.a=t3.j AND t3.j=noop(5) + ORDER BY t1.a; +} { + QUERY PLAN + |--SCAN t3 + |--SEARCH t1 USING INDEX sqlite_autoindex_t1_1 (a=?) + |--SEARCH t2 USING INDEX sqlite_autoindex_t2_1 (a=?) + `--USE TEMP B-TREE FOR ORDER BY +} # Constant propagation in the face of collating sequences: # From 4713b2d73ca0053671c7b6e8502647e1a2c0a411 Mon Sep 17 00:00:00 2001 From: drh <> Date: Sat, 16 Mar 2024 19:48:51 +0000 Subject: [PATCH 233/430] Assert that the eCode is always non-zero upon entry into exprNodeIsConstant(). FossilOrigin-Name: f71b28f6713126745bca53e098dfe3444d4235d6a2b87ced5b333a7f0ee79be8 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/expr.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 8f71171d11..fb57f31af9 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Activate\sthe\senhanced\sconstant-expression\sfor\sthe\n[constant\spropagation\soptimization](/info/f4229707ac08d66c). -D 2024-03-16T19:36:18.764 +C Assert\sthat\sthe\seCode\sis\salways\snon-zero\supon\sentry\sinto\sexprNodeIsConstant(). +D 2024-03-16T19:48:51.062 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -700,7 +700,7 @@ F src/date.c 126ba2ab10aeb2e7ba6e089b5f07b747c0625b8287f78b60da346eda8d23c875 F src/dbpage.c 80e46e1df623ec40486da7a5086cb723b0275a6e2a7b01d9f9b5da0f04ba2782 F src/dbstat.c 3b677254d512fcafd4d0b341bf267b38b235ccfddbef24f9154e19360fa22e43 F src/delete.c cb766727c78e715f9fb7ec8a7d03658ed2a3016343ca687acfcec9083cdca500 -F src/expr.c b3914ec5ac4f1c43d0743123fabab27c089f16dcfdcfd47973e2eebe0834f94b +F src/expr.c a6cc77ccca00905f5ba0739dd8112fcb0411231d9228239553829a85bf35b0dd F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c a47610f0a5c6cb0ad79f8fcef039c01833dec0c751bb695f28dc0ec6a4c3ba00 F src/func.c 4204c56196847faefef57fa14e43b8e4d65eb8d7e65318abe463472e3fd148cb @@ -2179,8 +2179,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P dae669245c86021bcd28716aff6e316257cc8075d02081745d4b7de17f8ad553 -R 02d7863e0170a404854cbdb7daab35da +P 92afea38881a1a4f266c79ddc6e1027cf17c288dcc8f7e7d50466899ac0054c4 +R 03a747756d1c2eaa7bed49327f66bff5 U drh -Z 4782493dacf06603b1147674a9e69d60 +Z 34a5fcb15810c923d4200d4da137f642 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 7aaeff4fab..5218da70b2 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -92afea38881a1a4f266c79ddc6e1027cf17c288dcc8f7e7d50466899ac0054c4 \ No newline at end of file +f71b28f6713126745bca53e098dfe3444d4235d6a2b87ced5b333a7f0ee79be8 \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index 95567de799..66070db5b9 100644 --- a/src/expr.c +++ b/src/expr.c @@ -2372,7 +2372,6 @@ static SQLITE_NOINLINE int exprNodeIsConstantFunction( sqlite3 *db; /* The database */ assert( pExpr->op==TK_FUNCTION ); - if( pWalker->eCode==0 ) return WRC_Abort; pList = pExpr->x.pList; if( pList==0 ){ n = 0; @@ -2421,6 +2420,7 @@ static SQLITE_NOINLINE int exprNodeIsConstantFunction( ** malformed schema error. */ static int exprNodeIsConstant(Walker *pWalker, Expr *pExpr){ + assert( pWalker->eCode>0 ); /* If pWalker->eCode is 2 then any term of the expression that comes from ** the ON or USING clauses of an outer join disqualifies the expression From 7dc3e923c4066eeb3c8a16f9de736c755b621b00 Mon Sep 17 00:00:00 2001 From: drh <> Date: Sat, 16 Mar 2024 20:15:34 +0000 Subject: [PATCH 234/430] Further expand the scope of usage for the enhacement to expr-is-constant. FossilOrigin-Name: d7eadcf7dd089f0f4aa963c58f0df32edd951368c9906375fd62b0a61cd393b8 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/expr.c | 48 +++++++++++++++++++++--------------------------- src/sqliteInt.h | 1 - 4 files changed, 29 insertions(+), 36 deletions(-) diff --git a/manifest b/manifest index fb57f31af9..bbd7c592eb 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Assert\sthat\sthe\seCode\sis\salways\snon-zero\supon\sentry\sinto\sexprNodeIsConstant(). -D 2024-03-16T19:48:51.062 +C Further\sexpand\sthe\sscope\sof\susage\sfor\sthe\senhacement\sto\sexpr-is-constant. +D 2024-03-16T20:15:34.449 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -700,7 +700,7 @@ F src/date.c 126ba2ab10aeb2e7ba6e089b5f07b747c0625b8287f78b60da346eda8d23c875 F src/dbpage.c 80e46e1df623ec40486da7a5086cb723b0275a6e2a7b01d9f9b5da0f04ba2782 F src/dbstat.c 3b677254d512fcafd4d0b341bf267b38b235ccfddbef24f9154e19360fa22e43 F src/delete.c cb766727c78e715f9fb7ec8a7d03658ed2a3016343ca687acfcec9083cdca500 -F src/expr.c a6cc77ccca00905f5ba0739dd8112fcb0411231d9228239553829a85bf35b0dd +F src/expr.c 8968e7bef87f595a3e7a5a31b1ee849dd26b600cae9caae17d0bd151f7771eb3 F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c a47610f0a5c6cb0ad79f8fcef039c01833dec0c751bb695f28dc0ec6a4c3ba00 F src/func.c 4204c56196847faefef57fa14e43b8e4d65eb8d7e65318abe463472e3fd148cb @@ -755,7 +755,7 @@ F src/shell.c.in cf80c636bccb0ff9db46995e39d69ca21fde2a8a331d1691e4d62a69d7841c8 F src/sqlite.h.in 19a2db3995a699bd7f6dfb423856242bfceb7ec849a93c91d241d19fc28d9f0f F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 -F src/sqliteInt.h 92d3323ba58a1a745f0f6a300d619ea12a6b142f0e8d8d49ce24d84ed85092f1 +F src/sqliteInt.h 4bf7dcc1d2015a6cdd0a2cba5ef33f8f4f7bc14ebc7205321e2488c14eead77d F src/sqliteLimit.h 6878ab64bdeb8c24a1d762d45635e34b96da21132179023338c93f820eee6728 F src/status.c cb11f8589a6912af2da3bb1ec509a94dd8ef27df4d4c1a97e0bcf2309ece972b F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1 @@ -2179,8 +2179,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 92afea38881a1a4f266c79ddc6e1027cf17c288dcc8f7e7d50466899ac0054c4 -R 03a747756d1c2eaa7bed49327f66bff5 +P f71b28f6713126745bca53e098dfe3444d4235d6a2b87ced5b333a7f0ee79be8 +R d3bfccf80dd34f5216cfa96d96bbce32 U drh -Z 34a5fcb15810c923d4200d4da137f642 +Z d29542cf1f94495f6b9d8836a34942e6 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 5218da70b2..ce44e01dd6 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f71b28f6713126745bca53e098dfe3444d4235d6a2b87ced5b333a7f0ee79be8 \ No newline at end of file +d7eadcf7dd089f0f4aa963c58f0df32edd951368c9906375fd62b0a61cd393b8 \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index 66070db5b9..4b312873f7 100644 --- a/src/expr.c +++ b/src/expr.c @@ -2372,8 +2372,9 @@ static SQLITE_NOINLINE int exprNodeIsConstantFunction( sqlite3 *db; /* The database */ assert( pExpr->op==TK_FUNCTION ); - pList = pExpr->x.pList; - if( pList==0 ){ + if( ExprHasProperty(pExpr, EP_TokenOnly) + || (pList = pExpr->x.pList)==0 + ){; n = 0; }else{ n = pList->nExpr; @@ -2494,10 +2495,10 @@ static int exprNodeIsConstant(Walker *pWalker, Expr *pExpr){ return WRC_Continue; } } -static int exprIsConst(Expr *p, int initFlag, int iCur){ +static int exprIsConst(Parse *pParse, Expr *p, int initFlag, int iCur){ Walker w; w.eCode = initFlag; - w.pParse = 0; + w.pParse = pParse; w.xExprCallback = exprNodeIsConstant; w.xSelectCallback = sqlite3SelectWalkFail; #ifdef SQLITE_DEBUG @@ -2523,16 +2524,7 @@ static int exprIsConst(Expr *p, int initFlag, int iCur){ ** function and on its parameters. */ int sqlite3ExprIsConstant(Parse *pParse, Expr *p){ - Walker w; - w.eCode = 1; - w.pParse = pParse; - w.xExprCallback = exprNodeIsConstant; - w.xSelectCallback = sqlite3SelectWalkFail; -#ifdef SQLITE_DEBUG - w.xSelectCallback2 = sqlite3SelectWalkAssert2; -#endif - sqlite3WalkExpr(&w, p); - return w.eCode; + return exprIsConst(pParse, p, 1, 0); } /* @@ -2548,8 +2540,8 @@ int sqlite3ExprIsConstant(Parse *pParse, Expr *p){ ** can be added to the pParse->pConstExpr list and evaluated once when ** the prepared statement starts up. See sqlite3ExprCodeRunJustOnce(). */ -int sqlite3ExprIsConstantNotJoin(Expr *p){ - return exprIsConst(p, 2, 0); +static int sqlite3ExprIsConstantNotJoin(Parse *pParse, Expr *p){ + return exprIsConst(pParse, p, 2, 0); } /* @@ -2559,7 +2551,7 @@ int sqlite3ExprIsConstantNotJoin(Expr *p){ ** table other than iCur. */ int sqlite3ExprIsTableConstant(Expr *p, int iCur){ - return exprIsConst(p, 3, iCur); + return exprIsConst(0, p, 3, iCur); } /* @@ -2716,7 +2708,7 @@ int sqlite3ExprIsConstantOrGroupBy(Parse *pParse, Expr *p, ExprList *pGroupBy){ */ int sqlite3ExprIsConstantOrFunction(Expr *p, u8 isInit){ assert( isInit==0 || isInit==1 ); - return exprIsConst(p, 4+isInit, 0); + return exprIsConst(0, p, 4+isInit, 0); } #ifdef SQLITE_ENABLE_CURSOR_HINTS @@ -2961,13 +2953,13 @@ static void sqlite3SetHasNullFlag(Vdbe *v, int iCur, int regHasNull){ ** The argument is an IN operator with a list (not a subquery) on the ** right-hand side. Return TRUE if that list is constant. */ -static int sqlite3InRhsIsConstant(Expr *pIn){ +static int sqlite3InRhsIsConstant(Parse *pParse, Expr *pIn){ Expr *pLHS; int res; assert( !ExprHasProperty(pIn, EP_xIsSelect) ); pLHS = pIn->pLeft; pIn->pLeft = 0; - res = sqlite3ExprIsConstant(0, pIn); + res = sqlite3ExprIsConstant(pParse, pIn); pIn->pLeft = pLHS; return res; } @@ -3236,7 +3228,7 @@ int sqlite3FindInIndex( if( eType==0 && (inFlags & IN_INDEX_NOOP_OK) && ExprUseXList(pX) - && (!sqlite3InRhsIsConstant(pX) || pX->x.pList->nExpr<=2) + && (!sqlite3InRhsIsConstant(pParse,pX) || pX->x.pList->nExpr<=2) ){ pParse->nTab--; /* Back out the allocation of the unused cursor */ iTab = -1; /* Cursor is not allocated */ @@ -3519,7 +3511,7 @@ void sqlite3CodeRhsOfIN( ** this code only executes once. Because for a non-constant ** expression we need to rerun this code each time. */ - if( addrOnce && !sqlite3ExprIsConstant(0, pE2) ){ + if( addrOnce && !sqlite3ExprIsConstant(pParse, pE2) ){ sqlite3VdbeChangeToNoop(v, addrOnce-1); sqlite3VdbeChangeToNoop(v, addrOnce); ExprClearProperty(pExpr, EP_Subrtn); @@ -4856,7 +4848,9 @@ int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target){ } #endif - if( ConstFactorOk(pParse) && sqlite3ExprIsConstantNotJoin(pExpr) ){ + if( ConstFactorOk(pParse) + && sqlite3ExprIsConstantNotJoin(pParse,pExpr) + ){ /* SQL functions can be expensive. So try to avoid running them ** multiple times if we know they always give the same result */ return sqlite3ExprCodeRunJustOnce(pParse, pExpr, -1); @@ -4887,7 +4881,7 @@ int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target){ } for(i=0; ia[i].pExpr) ){ + if( i<32 && sqlite3ExprIsConstant(pParse, pFarg->a[i].pExpr) ){ testcase( i==31 ); constMask |= MASKBIT32(i); } @@ -5354,7 +5348,7 @@ int sqlite3ExprCodeTemp(Parse *pParse, Expr *pExpr, int *pReg){ if( ConstFactorOk(pParse) && ALWAYS(pExpr!=0) && pExpr->op!=TK_REGISTER - && sqlite3ExprIsConstantNotJoin(pExpr) + && sqlite3ExprIsConstantNotJoin(pParse, pExpr) ){ *pReg = 0; r2 = sqlite3ExprCodeRunJustOnce(pParse, pExpr, -1); @@ -5418,7 +5412,7 @@ void sqlite3ExprCodeCopy(Parse *pParse, Expr *pExpr, int target){ ** might choose to code the expression at initialization time. */ void sqlite3ExprCodeFactorable(Parse *pParse, Expr *pExpr, int target){ - if( pParse->okConstFactor && sqlite3ExprIsConstantNotJoin(pExpr) ){ + if( pParse->okConstFactor && sqlite3ExprIsConstantNotJoin(pParse,pExpr) ){ sqlite3ExprCodeRunJustOnce(pParse, pExpr, target); }else{ sqlite3ExprCodeCopy(pParse, pExpr, target); @@ -5477,7 +5471,7 @@ int sqlite3ExprCodeExprList( sqlite3VdbeAddOp2(v, copyOp, j+srcReg-1, target+i); } }else if( (flags & SQLITE_ECEL_FACTOR)!=0 - && sqlite3ExprIsConstantNotJoin(pExpr) + && sqlite3ExprIsConstantNotJoin(pParse,pExpr) ){ sqlite3ExprCodeRunJustOnce(pParse, pExpr, target+i); }else{ diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 205cb6afe0..54fe9458fc 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -5059,7 +5059,6 @@ u32 sqlite3IsTrueOrFalse(const char*); int sqlite3ExprIdToTrueFalse(Expr*); int sqlite3ExprTruthValue(const Expr*); int sqlite3ExprIsConstant(Parse*,Expr*); -int sqlite3ExprIsConstantNotJoin(Expr*); int sqlite3ExprIsConstantOrFunction(Expr*, u8); int sqlite3ExprIsConstantOrGroupBy(Parse*, Expr*, ExprList*); int sqlite3ExprIsTableConstant(Expr*,int); From ec00a4d11148e4127a30bb1b1d26bf09409204e6 Mon Sep 17 00:00:00 2001 From: drh <> Date: Sat, 16 Mar 2024 21:04:32 +0000 Subject: [PATCH 235/430] A formerly impossible case has now become possible because of the new ExprIsConstant enhancements. So deal with that. FossilOrigin-Name: 9ba3cff9d48fe8fc8a0a51291169599209d464465e44bdfd60058fd1e314a2b1 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/expr.c | 5 +++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index bbd7c592eb..5a88394c42 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Further\sexpand\sthe\sscope\sof\susage\sfor\sthe\senhacement\sto\sexpr-is-constant. -D 2024-03-16T20:15:34.449 +C A\sformerly\simpossible\scase\shas\snow\sbecome\spossible\sbecause\sof\sthe\snew\nExprIsConstant\senhancements.\s\sSo\sdeal\swith\sthat. +D 2024-03-16T21:04:32.468 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -700,7 +700,7 @@ F src/date.c 126ba2ab10aeb2e7ba6e089b5f07b747c0625b8287f78b60da346eda8d23c875 F src/dbpage.c 80e46e1df623ec40486da7a5086cb723b0275a6e2a7b01d9f9b5da0f04ba2782 F src/dbstat.c 3b677254d512fcafd4d0b341bf267b38b235ccfddbef24f9154e19360fa22e43 F src/delete.c cb766727c78e715f9fb7ec8a7d03658ed2a3016343ca687acfcec9083cdca500 -F src/expr.c 8968e7bef87f595a3e7a5a31b1ee849dd26b600cae9caae17d0bd151f7771eb3 +F src/expr.c eef4b58b1c5f488c7bd099af3a571ff32509d00a1c990f17c0bc5e752ed33462 F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c a47610f0a5c6cb0ad79f8fcef039c01833dec0c751bb695f28dc0ec6a4c3ba00 F src/func.c 4204c56196847faefef57fa14e43b8e4d65eb8d7e65318abe463472e3fd148cb @@ -2179,8 +2179,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P f71b28f6713126745bca53e098dfe3444d4235d6a2b87ced5b333a7f0ee79be8 -R d3bfccf80dd34f5216cfa96d96bbce32 +P d7eadcf7dd089f0f4aa963c58f0df32edd951368c9906375fd62b0a61cd393b8 +R 8cf165d7d4e6171fbfcc63e324d78f15 U drh -Z d29542cf1f94495f6b9d8836a34942e6 +Z 950e1346eed1b73efa50ee1189a08fc5 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index ce44e01dd6..3675f57590 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d7eadcf7dd089f0f4aa963c58f0df32edd951368c9906375fd62b0a61cd393b8 \ No newline at end of file +9ba3cff9d48fe8fc8a0a51291169599209d464465e44bdfd60058fd1e314a2b1 \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index 4b312873f7..3ba07fb2dc 100644 --- a/src/expr.c +++ b/src/expr.c @@ -218,9 +218,10 @@ Expr *sqlite3ExprSkipCollateAndLikely(Expr *pExpr){ assert( pExpr->x.pList->nExpr>0 ); assert( pExpr->op==TK_FUNCTION ); pExpr = pExpr->x.pList->a[0].pExpr; - }else{ - assert( pExpr->op==TK_COLLATE ); + }else if( pExpr->op==TK_COLLATE ){ pExpr = pExpr->pLeft; + }else{ + break; } } return pExpr; From e4a1b4da4f8e76293209071b7bc3588d6c05f736 Mon Sep 17 00:00:00 2001 From: drh <> Date: Sun, 17 Mar 2024 00:13:12 +0000 Subject: [PATCH 236/430] Add an ALWAYS on an unreachable branch. FossilOrigin-Name: 0dce6211690210e802545cbca9b3375e07075e117fad3f8c921879da7671d981 --- manifest | 13 ++++++------- manifest.uuid | 2 +- src/insert.c | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index ee5a613c1a..d667045fa5 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Recognize\swhen\san\sSQL\sfunction\sis\sconstant\sand\scan\soccur\sinside\san\noptimized\sVALUES\sclause. -D 2024-03-16T21:12:51.251 +C Add\san\sALWAYS\son\san\sunreachable\sbranch. +D 2024-03-17T00:13:12.278 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -709,7 +709,7 @@ F src/hash.c 9ee4269fb1d6632a6fecfb9479c93a1f29271bddbbaf215dd60420bcb80c7220 F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 -F src/insert.c e28426630ebbac5763d5802099164ad24fbf46fea79d48a8313117a64b950871 +F src/insert.c f0755de645ee8e632445b731951c75b7484ccadb890ade4cbc8db269327ff4b8 F src/json.c e2e40760d6689134c3e2ece38c6a496b34ff5e2661a8f238444a119af666fdce F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 @@ -2179,9 +2179,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 823e579362c05bb8accf6c3b158c5162a16eb23cf81d6021c9e3246e32583d1c 9ba3cff9d48fe8fc8a0a51291169599209d464465e44bdfd60058fd1e314a2b1 -R 8cf165d7d4e6171fbfcc63e324d78f15 -T +closed 9ba3cff9d48fe8fc8a0a51291169599209d464465e44bdfd60058fd1e314a2b1 +P c0e5ceb87d3cf28f22d381f863b8f91043804fd7901f23f3afb02fe698e6a12a +R c0fd5d4c2ab2c847266cf4b9416ae243 U drh -Z 1c2f2833c22bf92aec87aab6cf84bca7 +Z 061bbac91348ec107ed9e1ccfd2e024e # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index ca62261369..9a374d564f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c0e5ceb87d3cf28f22d381f863b8f91043804fd7901f23f3afb02fe698e6a12a \ No newline at end of file +0dce6211690210e802545cbca9b3375e07075e117fad3f8c921879da7671d981 \ No newline at end of file diff --git a/src/insert.c b/src/insert.c index 915f368fbd..2c6a76b78d 100644 --- a/src/insert.c +++ b/src/insert.c @@ -583,7 +583,7 @@ void sqlite3AutoincrementEnd(Parse *pParse){ ** co-routine. */ void sqlite3MultiValuesEnd(Parse *pParse, Select *pVal){ - if( pVal && pVal->pSrc->nSrc>0 ){ + if( ALWAYS(pVal) && pVal->pSrc->nSrc>0 ){ SrcItem *pItem = &pVal->pSrc->a[0]; sqlite3VdbeEndCoroutine(pParse->pVdbe, pItem->regReturn); sqlite3VdbeJumpHere(pParse->pVdbe, pItem->addrFillSub - 1); From 54bf109e807cc2c12cd81883affd008d718d0748 Mon Sep 17 00:00:00 2001 From: drh <> Date: Sun, 17 Mar 2024 16:01:23 +0000 Subject: [PATCH 237/430] Omit the "noop(X)" test SQL function. Accomplish the same thing using the idiom: "coalesce(X,random())". FossilOrigin-Name: 0eb2fbb8910e7a372c50db3ae44238d7b161f0e45858b74061b5228aec5fcc7e --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/test1.c | 21 --------------------- test/in4.test | 5 ++--- test/whereL.test | 7 ++++--- 5 files changed, 15 insertions(+), 36 deletions(-) diff --git a/manifest b/manifest index d667045fa5..7f30177097 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\san\sALWAYS\son\san\sunreachable\sbranch. -D 2024-03-17T00:13:12.278 +C Omit\sthe\s"noop(X)"\stest\sSQL\sfunction.\s\sAccomplish\sthe\ssame\sthing\susing\nthe\sidiom:\s\s"coalesce(X,random())". +D 2024-03-17T16:01:23.923 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -760,7 +760,7 @@ F src/sqliteLimit.h 6878ab64bdeb8c24a1d762d45635e34b96da21132179023338c93f820eee F src/status.c cb11f8589a6912af2da3bb1ec509a94dd8ef27df4d4c1a97e0bcf2309ece972b F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1 F src/tclsqlite.c ecbc3c99c0d0c3ed122a913f143026c26d38d57f33e06bb71185dd5c1efe37cd -F src/test1.c 5a67577fa7d93a19a72aa165b7013606a35e53f62d0de11587940aed5797d92d +F src/test1.c 310f43eb17a9252a7790726ca652e4ea3197da17c19eec93b8578863a49dc7b4 F src/test2.c 54520d0565ef2b9bf0f8f1dcac43dc4d06baf4ffe13d10905f8d8c3ad3e4b9ab F src/test3.c e5178558c41ff53236ae0271e9acb3d6885a94981d2eb939536ee6474598840e F src/test4.c 4533b76419e7feb41b40582554663ed3cd77aaa54e135cf76b3205098cd6e664 @@ -1271,7 +1271,7 @@ F test/imposter1.test c3f1db2d3db2c24611a6596a3fc0ffc14f1466c8 F test/in.test d1cad4ededd425568b2e39fb0c31fa9a3772311dd595801ff13ba3912b69bba6 F test/in2.test 5d4c61d17493c832f7d2d32bef785119e87bde75 F test/in3.test 3cbf58c87f4052cee3a58b37b6389777505aa0c0 -F test/in4.test 176719161ba96c9386027891602700738aadac3419964f72b628f59d2071d53d +F test/in4.test bb767ec1cfd1730256f0a83219f0acda36bc251b63f8b8bb7d8c7cff17875a4f F test/in5.test b32ce7f4a93f44c5dee94af16886d922cc16ebe33c8e1765c73d4049d0f4b40f F test/in6.test f5f40d6816a8bb7c784424b58a10ac38efb76ab29127a2c17399e0cbeeda0e4b F test/incrblob.test c9b96afc292aeff43d6687bcb09b0280aa599822 @@ -2011,7 +2011,7 @@ F test/whereH.test e4b07f7a3c2f5d31195cd33710054c78667573b2 F test/whereI.test c4bb7e2ca56d49bd8ab5c7bd085b8b83e353922b46904d68aefb3c7468643581 F test/whereJ.test fc05e374cc9f2dc204148d6c06822c380ad388895fe97a6d335b94a26a08aecf F test/whereK.test 0270ab7f04ba5436fb9156d31d642a1c82727f4c4bfe5ba90d435c78cf44684a -F test/whereL.test bf41203fda5e19e4c554a296b4ad2ff3eb27207549b94a819a2bc37275b4529d +F test/whereL.test 438a397fa883b77bb6361c08a8befa41b52e9cfbe15a2a43715d122f8cfa8649 F test/whereM.test 0dbc9998783458ddcf3cc078ca7c2951d8b2677d472ecf0028f449ed327c0250 F test/wherefault.test 6cf2a9c5712952d463d3f45ebee7f6caf400984df51a195d884cfb7eb0e837a7 F test/wherelfault.test 9012e4ef5259058b771606616bd007af5d154e64cc25fa9fd4170f6411db44e3 @@ -2179,8 +2179,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P c0e5ceb87d3cf28f22d381f863b8f91043804fd7901f23f3afb02fe698e6a12a -R c0fd5d4c2ab2c847266cf4b9416ae243 +P 0dce6211690210e802545cbca9b3375e07075e117fad3f8c921879da7671d981 +R 04c934383a09ffd06af013a1dd47675b U drh -Z 061bbac91348ec107ed9e1ccfd2e024e +Z ca3e70db7b33adfad0eeda8b7a11174b # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 9a374d564f..186e057cef 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0dce6211690210e802545cbca9b3375e07075e117fad3f8c921879da7671d981 \ No newline at end of file +0eb2fbb8910e7a372c50db3ae44238d7b161f0e45858b74061b5228aec5fcc7e \ No newline at end of file diff --git a/src/test1.c b/src/test1.c index a552c3f509..8faf5a397b 100644 --- a/src/test1.c +++ b/src/test1.c @@ -1024,23 +1024,6 @@ static void addRealTypeFunction( sqlite3_result_value(context, argv[0]); } -/* -** Implementation of the noop(X) SQL function. -** -** The result is just a copy of its argument. However, this function -** does not have the SQLITE_FUNC_CONSTANT flag, so it is consider -** non-constant by sqlite3ExprIsConstant(). -*/ -static void noopFunction( - sqlite3_context *context, - int argc, - sqlite3_value **argv -){ - (void)argc; - sqlite3_result_value(context, argv[0]); -} - - /* ** SQL function: strtod(X) ** @@ -1168,10 +1151,6 @@ static int SQLITE_TCLAPI test_create_function( rc = sqlite3_create_function(db, "add_real_type", 1, SQLITE_UTF8, 0, addRealTypeFunction, 0, 0); } - if( rc==SQLITE_OK ){ - rc = sqlite3_create_function(db, "noop", 1, SQLITE_UTF8, - 0, noopFunction, 0, 0); - } /* Functions strtod() and dtostr() work as in the shell. These routines ** use the standard C library to convert between floating point and diff --git a/test/in4.test b/test/in4.test index 81f2b2840d..71993e7003 100644 --- a/test/in4.test +++ b/test/in4.test @@ -455,18 +455,17 @@ do_execsql_test 11.0 { INSERT INTO sqlite_stat1 VALUES('t1','t1abc','10000 5 00 2003 10'); ANALYZE sqlite_schema; } {} -sqlite3_create_function db do_execsql_test 11.1 { SELECT * FROM t1 WHERE b IN (345, (SELECT 1 FROM t1 - WHERE b IN (noop(1)) + WHERE b IN (coalesce(1,random())) AND c GLOB 'abc*xyz')) AND c BETWEEN 'abc' AND 'xyz'; } {xyz 1 abcdefxyz 99} do_execsql_test 11.2 { EXPLAIN SELECT * FROM t1 WHERE b IN (345, (SELECT 1 FROM t1 - WHERE b IN (noop(1)) + WHERE b IN (coalesce(1,random())) AND c GLOB 'abc*xyz')) AND c BETWEEN 'abc' AND 'xyz'; } {/ SeekScan /} diff --git a/test/whereL.test b/test/whereL.test index 9d1054964c..2e9ae219e1 100644 --- a/test/whereL.test +++ b/test/whereL.test @@ -60,13 +60,14 @@ do_eqp_test 121 { `--SCAN t3 } -# The sqlite3ExprIsConstant() routine does not believe that noop(3) -# is constant. So the optimization does not apply in this case. +# The sqlite3ExprIsConstant() routine does not believe that +# the expression "coalesce(5,random())" is constant. So the +# optimization does not apply in this case. # sqlite3_create_function db do_eqp_test 122 { SELECT * FROM t1, t2, t3 - WHERE t1.a=t2.a AND t2.a=t3.j AND t3.j=noop(5) + WHERE t1.a=t2.a AND t2.a=t3.j AND t3.j=coalesce(5,random()) ORDER BY t1.a; } { QUERY PLAN From 2f4a8cc2d8f1ce29814a97887d9e8e96e9ed7725 Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 18 Mar 2024 10:54:48 +0000 Subject: [PATCH 238/430] Fix a problem caused by a non-aggregate function with an OVER clause in a multi-row VALUES clause. FossilOrigin-Name: 10ee6fcba08ab1281235197602148fe062560e1d5034a477b8e7b574dd3e2907 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/expr.c | 1 + test/values.test | 5 +++++ 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 7f30177097..f72f4d1d80 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Omit\sthe\s"noop(X)"\stest\sSQL\sfunction.\s\sAccomplish\sthe\ssame\sthing\susing\nthe\sidiom:\s\s"coalesce(X,random())". -D 2024-03-17T16:01:23.923 +C Fix\sa\sproblem\scaused\sby\sa\snon-aggregate\sfunction\swith\san\sOVER\sclause\sin\sa\smulti-row\sVALUES\sclause. +D 2024-03-18T10:54:48.739 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -700,7 +700,7 @@ F src/date.c 126ba2ab10aeb2e7ba6e089b5f07b747c0625b8287f78b60da346eda8d23c875 F src/dbpage.c 80e46e1df623ec40486da7a5086cb723b0275a6e2a7b01d9f9b5da0f04ba2782 F src/dbstat.c 3b677254d512fcafd4d0b341bf267b38b235ccfddbef24f9154e19360fa22e43 F src/delete.c cb766727c78e715f9fb7ec8a7d03658ed2a3016343ca687acfcec9083cdca500 -F src/expr.c eef4b58b1c5f488c7bd099af3a571ff32509d00a1c990f17c0bc5e752ed33462 +F src/expr.c 27fdcdc65bca88934dfc4af0efe7a3eae095267bf7592b562abb6a11292c2b82 F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c a47610f0a5c6cb0ad79f8fcef039c01833dec0c751bb695f28dc0ec6a4c3ba00 F src/func.c 4204c56196847faefef57fa14e43b8e4d65eb8d7e65318abe463472e3fd148cb @@ -1921,7 +1921,7 @@ F test/vacuum4.test 7ea76b769fffeb41f925303b04cbcf5a5bbeabe55e4c60ae754ff24eeeb7 F test/vacuum5.test 263b144d537e92ad8e9ca8a73cc6e1583f41cfd0dda9432b87f7806174a2f48c F test/vacuum6.test b137b04bf3392d3f5c3b8fda0ce85a6775a70ca112f6559f74ff52dc9ce042fd F test/vacuummem.test 4b30f5b95a9ff86e9d5c20741e50a898b2dc10b0962a3211571eb165357003fb -F test/values.test 60723a55f68e8e42027d49a159a1be8b92cb0f538a65cb363ff65637e8a41703 +F test/values.test 336ce9404c15cc9ff70f74a374e6da474724c94e69ea658aeab279d94623142f F test/valuesfault.test 2ef23ed965e3bd08e268cdc38a0d11653390ddbbe1e8e2e98d16f55edd30f6e8 F test/varint.test bbce22cda8fc4d135bcc2b589574be8410614e62 F test/veryquick.test 57ab846bacf7b90cf4e9a672721ea5c5b669b661 @@ -2179,8 +2179,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 0dce6211690210e802545cbca9b3375e07075e117fad3f8c921879da7671d981 -R 04c934383a09ffd06af013a1dd47675b -U drh -Z ca3e70db7b33adfad0eeda8b7a11174b +P 0eb2fbb8910e7a372c50db3ae44238d7b161f0e45858b74061b5228aec5fcc7e +R 0c271dec25d4e7ba3707539d1d6d785b +U dan +Z 92342f3e47401a6da453743f142fe632 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 186e057cef..18c1998557 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0eb2fbb8910e7a372c50db3ae44238d7b161f0e45858b74061b5228aec5fcc7e \ No newline at end of file +10ee6fcba08ab1281235197602148fe062560e1d5034a477b8e7b574dd3e2907 \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index 3ba07fb2dc..be8339c305 100644 --- a/src/expr.c +++ b/src/expr.c @@ -2387,6 +2387,7 @@ static SQLITE_NOINLINE int exprNodeIsConstantFunction( if( pDef==0 || pDef->xFinalize!=0 || (pDef->funcFlags & (SQLITE_FUNC_CONSTANT|SQLITE_FUNC_SLOCHNG))==0 + || pExpr->y.pWin ){ pWalker->eCode = 0; return WRC_Abort; diff --git a/test/values.test b/test/values.test index b96c9e5d23..caa33058bf 100644 --- a/test/values.test +++ b/test/values.test @@ -415,5 +415,10 @@ do_execsql_test 13.0 { FROM t1; } {xyz} +do_catchsql_test 13.1 { + VALUES(300), (zeroblob(300) OVER win); +} {1 {zeroblob() may not be used as a window function}} + + finish_test From 75924d3ae22587cac6c68caad9212a7621e47135 Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 18 Mar 2024 11:12:22 +0000 Subject: [PATCH 239/430] Ensure the database schema has been loaded and the database encoding gleaned before beginning to code a multi-row VALUES clause. FossilOrigin-Name: 2ff476eb3d1f4a2146f4a48b57895a00a3ff5beb29afa679ae53ea58cac07c76 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/insert.c | 8 ++++++++ test/values.test | 16 ++++++++++++++++ 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index f72f4d1d80..b3ff72f880 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sproblem\scaused\sby\sa\snon-aggregate\sfunction\swith\san\sOVER\sclause\sin\sa\smulti-row\sVALUES\sclause. -D 2024-03-18T10:54:48.739 +C Ensure\sthe\sdatabase\sschema\shas\sbeen\sloaded\sand\sthe\sdatabase\sencoding\sgleaned\sbefore\sbeginning\sto\scode\sa\smulti-row\sVALUES\sclause. +D 2024-03-18T11:12:22.121 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -709,7 +709,7 @@ F src/hash.c 9ee4269fb1d6632a6fecfb9479c93a1f29271bddbbaf215dd60420bcb80c7220 F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 -F src/insert.c f0755de645ee8e632445b731951c75b7484ccadb890ade4cbc8db269327ff4b8 +F src/insert.c 507113439413cdda2705b98089068be2b84273984bd2fbefe5e6a63efd2654a4 F src/json.c e2e40760d6689134c3e2ece38c6a496b34ff5e2661a8f238444a119af666fdce F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 @@ -1921,7 +1921,7 @@ F test/vacuum4.test 7ea76b769fffeb41f925303b04cbcf5a5bbeabe55e4c60ae754ff24eeeb7 F test/vacuum5.test 263b144d537e92ad8e9ca8a73cc6e1583f41cfd0dda9432b87f7806174a2f48c F test/vacuum6.test b137b04bf3392d3f5c3b8fda0ce85a6775a70ca112f6559f74ff52dc9ce042fd F test/vacuummem.test 4b30f5b95a9ff86e9d5c20741e50a898b2dc10b0962a3211571eb165357003fb -F test/values.test 336ce9404c15cc9ff70f74a374e6da474724c94e69ea658aeab279d94623142f +F test/values.test 301f9dcf37e654e9fb7f210ebeded878b620f17965f3b6b0d273323183538e82 F test/valuesfault.test 2ef23ed965e3bd08e268cdc38a0d11653390ddbbe1e8e2e98d16f55edd30f6e8 F test/varint.test bbce22cda8fc4d135bcc2b589574be8410614e62 F test/veryquick.test 57ab846bacf7b90cf4e9a672721ea5c5b669b661 @@ -2179,8 +2179,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 0eb2fbb8910e7a372c50db3ae44238d7b161f0e45858b74061b5228aec5fcc7e -R 0c271dec25d4e7ba3707539d1d6d785b +P 10ee6fcba08ab1281235197602148fe062560e1d5034a477b8e7b574dd3e2907 +R 22155fb84ed7e9f97f13e6f0600beffd U dan -Z 92342f3e47401a6da453743f142fe632 +Z 0dcb69e533979c58b8fa8014884ff3fb # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 18c1998557..f196850839 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -10ee6fcba08ab1281235197602148fe062560e1d5034a477b8e7b574dd3e2907 \ No newline at end of file +2ff476eb3d1f4a2146f4a48b57895a00a3ff5beb29afa679ae53ea58cac07c76 \ No newline at end of file diff --git a/src/insert.c b/src/insert.c index 2c6a76b78d..7d386f5d2b 100644 --- a/src/insert.c +++ b/src/insert.c @@ -698,12 +698,20 @@ Select *sqlite3MultiValues(Parse *pParse, Select *pLeft, ExprList *pRow){ }else{ SrcItem *p = 0; /* SrcItem that reads from co-routine */ + if( pLeft->pSrc->nSrc==0 ){ /* Co-routine has not yet been started and the special Select object ** that accesses the co-routine has not yet been created. This block ** does both those things. */ Vdbe *v = sqlite3GetVdbe(pParse); Select *pRet = sqlite3SelectNew(pParse, 0, 0, 0, 0, 0, 0, 0, 0); + + /* Ensure the database schema has been read. This is to ensure we have + ** the correct text encoding. */ + if( (pParse->db->mDbFlags & DBFLAG_SchemaKnownOk)==0 ){ + sqlite3ReadSchema(pParse); + } + if( pRet ){ SelectDest dest; pRet->pSrc->nSrc = 1; diff --git a/test/values.test b/test/values.test index caa33058bf..d6eb0684e1 100644 --- a/test/values.test +++ b/test/values.test @@ -419,6 +419,22 @@ do_catchsql_test 13.1 { VALUES(300), (zeroblob(300) OVER win); } {1 {zeroblob() may not be used as a window function}} +#-------------------------------------------------------------------------- +reset_db +do_execsql_test 14.1 { + PRAGMA encoding = utf16; + CREATE TABLE t1(a, b); +} {} + +db close +sqlite3 db test.db + +do_execsql_test 14.2 { + INSERT INTO t1 VALUES + (17, 'craft'), + (16, 'urtlek' IN(1,2,3)); +} + finish_test From 27a5ee855d6428246ea7fc9511a2a10a85c3199c Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 18 Mar 2024 12:49:30 +0000 Subject: [PATCH 240/430] Improvements to EXPLAIN QUERY PLAN output for multi-row VALUES claues. FossilOrigin-Name: ac6f095e13e43d66c06552c8b01f6bec3407c9d41a34c4cdb0be57b0b828ad0d --- manifest | 22 ++++++++++---------- manifest.uuid | 2 +- src/insert.c | 4 ++++ src/printf.c | 3 +++ src/sqliteInt.h | 1 + src/where.c | 6 +++++- test/values.test | 52 +++++++++++++++++++++++++++++++++++++++++++++++- 7 files changed, 76 insertions(+), 14 deletions(-) diff --git a/manifest b/manifest index b3ff72f880..93cb0216d1 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Ensure\sthe\sdatabase\sschema\shas\sbeen\sloaded\sand\sthe\sdatabase\sencoding\sgleaned\sbefore\sbeginning\sto\scode\sa\smulti-row\sVALUES\sclause. -D 2024-03-18T11:12:22.121 +C Improvements\sto\sEXPLAIN\sQUERY\sPLAN\soutput\sfor\smulti-row\sVALUES\sclaues. +D 2024-03-18T12:49:30.989 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -709,7 +709,7 @@ F src/hash.c 9ee4269fb1d6632a6fecfb9479c93a1f29271bddbbaf215dd60420bcb80c7220 F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 -F src/insert.c 507113439413cdda2705b98089068be2b84273984bd2fbefe5e6a63efd2654a4 +F src/insert.c 3b3661886b198d9c5e26c189a802782d35e6b415d0edf57af8c273225c2ae8f2 F src/json.c e2e40760d6689134c3e2ece38c6a496b34ff5e2661a8f238444a119af666fdce F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 @@ -746,7 +746,7 @@ F src/pcache1.c 602acb23c471bb8d557a6f0083cc2be641d6cafcafa19e481eba7ef4c9ca0f00 F src/pragma.c e8221d6310c9923c80f6fa6d09b7ea7c5263a671f53db8d0894df23efcdb617b F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7 F src/prepare.c 371f6115cb69286ebc12c6f2d7511279c2e47d9f54f475d46a554d687a3b312c -F src/printf.c 10e8bad30042f8bd6114a013b4afc229ec8ad255ab27518d7d9f52e8cbc5cd0a +F src/printf.c aec4a5d743796be82d61c5d127d0f4615efbe61620a7a16968c5e2c9378ab37b F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c ef87e3bc7700bfe761a7bbee2ce6084f1766dc816dd82a3ae77c133eec898432 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 @@ -755,7 +755,7 @@ F src/shell.c.in cf80c636bccb0ff9db46995e39d69ca21fde2a8a331d1691e4d62a69d7841c8 F src/sqlite.h.in 19a2db3995a699bd7f6dfb423856242bfceb7ec849a93c91d241d19fc28d9f0f F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 -F src/sqliteInt.h 4bf7dcc1d2015a6cdd0a2cba5ef33f8f4f7bc14ebc7205321e2488c14eead77d +F src/sqliteInt.h f0014674d40b401795b4ff026fc4804aed3887f50d206fb221ddf4f2004bc3ef F src/sqliteLimit.h 6878ab64bdeb8c24a1d762d45635e34b96da21132179023338c93f820eee6728 F src/status.c cb11f8589a6912af2da3bb1ec509a94dd8ef27df4d4c1a97e0bcf2309ece972b F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1 @@ -835,7 +835,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c 887fc4ca3f020ebb2e376f222069570834ac63bf50111ef0cbf3ae417048ed89 F src/wal.h ba252daaa94f889f4b2c17c027e823d9be47ce39da1d3799886bbd51f0490452 F src/walker.c 7c7ea0115345851c3da4e04e2e239a29983b61fb5b038b94eede6aba462640e2 -F src/where.c 3efa165f9205602eef711af071db3862531fcda2b1ad875cda5e2c5effa56fee +F src/where.c 5e9a5d642cceb666152c59091a3dbb645a9dda209b4e65a2f9215ee9298d26cf F src/whereInt.h 82a13766f13d1a53b05387c2e60726289ef26404bc7b9b1f7770204d97357fb8 F src/wherecode.c 5d77db30a2a3dd532492ae882de114edba2fae672622056b1c7fd61f5917a8f1 F src/whereexpr.c 7b64295f1d82ad0928df435925dd7bbd5997b44a026153113eace0d9e71ff435 @@ -1921,7 +1921,7 @@ F test/vacuum4.test 7ea76b769fffeb41f925303b04cbcf5a5bbeabe55e4c60ae754ff24eeeb7 F test/vacuum5.test 263b144d537e92ad8e9ca8a73cc6e1583f41cfd0dda9432b87f7806174a2f48c F test/vacuum6.test b137b04bf3392d3f5c3b8fda0ce85a6775a70ca112f6559f74ff52dc9ce042fd F test/vacuummem.test 4b30f5b95a9ff86e9d5c20741e50a898b2dc10b0962a3211571eb165357003fb -F test/values.test 301f9dcf37e654e9fb7f210ebeded878b620f17965f3b6b0d273323183538e82 +F test/values.test 77f72e80ad7b9e362e309bccb391307f41d0a41d1cd159cbdadb2de043505184 F test/valuesfault.test 2ef23ed965e3bd08e268cdc38a0d11653390ddbbe1e8e2e98d16f55edd30f6e8 F test/varint.test bbce22cda8fc4d135bcc2b589574be8410614e62 F test/veryquick.test 57ab846bacf7b90cf4e9a672721ea5c5b669b661 @@ -2179,8 +2179,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 10ee6fcba08ab1281235197602148fe062560e1d5034a477b8e7b574dd3e2907 -R 22155fb84ed7e9f97f13e6f0600beffd -U dan -Z 0dcb69e533979c58b8fa8014884ff3fb +P 2ff476eb3d1f4a2146f4a48b57895a00a3ff5beb29afa679ae53ea58cac07c76 +R dd6d36e36b292e54015829bdd4a764a6 +U drh +Z 67655d85fa3f7ad082be72ee3ee927a1 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index f196850839..21dcd3d6f2 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2ff476eb3d1f4a2146f4a48b57895a00a3ff5beb29afa679ae53ea58cac07c76 \ No newline at end of file +ac6f095e13e43d66c06552c8b01f6bec3407c9d41a34c4cdb0be57b0b828ad0d \ No newline at end of file diff --git a/src/insert.c b/src/insert.c index 7d386f5d2b..7256281fd2 100644 --- a/src/insert.c +++ b/src/insert.c @@ -721,6 +721,7 @@ Select *sqlite3MultiValues(Parse *pParse, Select *pLeft, ExprList *pRow){ p->addrFillSub = sqlite3VdbeCurrentAddr(v) + 1; p->regReturn = ++pParse->nMem; p->iCursor = -1; + p->u1.nRow = 2; sqlite3VdbeAddOp3(v,OP_InitCoroutine,p->regReturn,0,p->addrFillSub); sqlite3SelectDestInit(&dest, SRT_Coroutine, p->regReturn); @@ -733,6 +734,7 @@ Select *sqlite3MultiValues(Parse *pParse, Select *pLeft, ExprList *pRow){ dest.nSdst = pLeft->pEList->nExpr; pParse->nMem += 2 + dest.nSdst; + pLeft->selFlags |= SF_MultiValue; sqlite3Select(pParse, pLeft, &dest); p->regResult = dest.iSdst; assert( pParse->nErr || dest.iSdst>0 ); @@ -740,6 +742,7 @@ Select *sqlite3MultiValues(Parse *pParse, Select *pLeft, ExprList *pRow){ } }else{ p = &pLeft->pSrc->a[0]; + p->u1.nRow++; } if( pParse->nErr==0 ){ @@ -1102,6 +1105,7 @@ void sqlite3Insert( dest.iSDParm = regYield = pItem->regReturn; regFromSelect = pItem->regResult; nColumn = pItem->pSelect->pEList->nExpr; + ExplainQueryPlan((pParse, 0, "SCAN %S", pItem)); if( bIdListInOrder && nColumn==pTab->nCol ){ regData = regFromSelect; regRowid = regData - 1; diff --git a/src/printf.c b/src/printf.c index 186e95bb85..0aea74e890 100644 --- a/src/printf.c +++ b/src/printf.c @@ -860,6 +860,9 @@ void sqlite3_str_vappendf( assert( pSel!=0 ); if( pSel->selFlags & SF_NestedFrom ){ sqlite3_str_appendf(pAccum, "(join-%u)", pSel->selId); + }else if( pSel->selFlags & SF_MultiValue ){ + sqlite3_str_appendf(pAccum, "%u-ROW VALUES CLAUSE", + pItem->u1.nRow); }else{ sqlite3_str_appendf(pAccum, "(subquery-%u)", pSel->selId); } diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 54fe9458fc..01a5126499 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -3311,6 +3311,7 @@ struct SrcItem { union { char *zIndexedBy; /* Identifier from "INDEXED BY " clause */ ExprList *pFuncArg; /* Arguments to table-valued-function */ + u32 nRow; /* Number of rows in a VALUES clause */ } u1; union { Index *pIBIndex; /* Index structure corresponding to u1.zIndexedBy */ diff --git a/src/where.c b/src/where.c index 2a99c73980..2463e823c8 100644 --- a/src/where.c +++ b/src/where.c @@ -6144,7 +6144,11 @@ WhereInfo *sqlite3WhereBegin( ){ pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE; } - ExplainQueryPlan((pParse, 0, "SCAN CONSTANT ROW")); + if( ALWAYS(pWInfo->pSelect) + && (pWInfo->pSelect->selFlags & SF_MultiValue)==0 + ){ + ExplainQueryPlan((pParse, 0, "SCAN CONSTANT ROW")); + } }else{ /* Assign a bit from the bitmask to every term in the FROM clause. ** diff --git a/test/values.test b/test/values.test index d6eb0684e1..8365584b4a 100644 --- a/test/values.test +++ b/test/values.test @@ -435,6 +435,56 @@ do_execsql_test 14.2 { (16, 'urtlek' IN(1,2,3)); } +#-------------------------------------------------------------------------- +# +reset_db +do_eqp_test 15.1 { + VALUES(1),(2),(3),(4),(5); +} { + QUERY PLAN + `--SCAN 5-ROW VALUES CLAUSE +} +do_execsql_test 15.2 { + CREATE TABLE t1(a,b); +} +do_eqp_test 15.3 { + INSERT INTO t1 VALUES + (1,2),(3,4),(7,8); +} { + QUERY PLAN + `--SCAN 3-ROW VALUES CLAUSE +} +do_eqp_test 15.4 { + INSERT INTO t1 VALUES + (1,2),(3,4),(7,8), + (5,coalesce(6,random())); +} { + QUERY PLAN + `--COMPOUND QUERY + |--LEFT-MOST SUBQUERY + | `--SCAN 3-ROW VALUES CLAUSE + `--UNION ALL + `--SCAN CONSTANT ROW +} +do_eqp_test 15.5 { + SELECT * FROM (VALUES(1),(2),(3),(4),(5),(6)), (VALUES('a'),('b'),('c')); +} { + QUERY PLAN + |--SCAN 6-ROW VALUES CLAUSE + `--SCAN 3-ROW VALUES CLAUSE +} +do_execsql_test 15.6 { + CREATE TABLE t2(x,y); +} +do_eqp_test 15.7 { + SELECT * FROM t2 UNION ALL VALUES(1,2),(3,4),(5,6),(7,8); +} { + QUERY PLAN + `--COMPOUND QUERY + |--LEFT-MOST SUBQUERY + | `--SCAN t2 + `--UNION ALL + `--SCAN 4-ROW VALUES CLAUSE +} finish_test - From 871786b7927bc101e25e38d1c446cecd55939ed4 Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 18 Mar 2024 13:10:54 +0000 Subject: [PATCH 241/430] Fix the patch at [10ee6fcba08ab128] so that it works on reduced-size Expr nodes. FossilOrigin-Name: 260bd764c3f2d6d067adb9cd0045b7c24d5e00b02ab2735b1cba455a6143ff4c --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/expr.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 93cb0216d1..5876e426d7 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improvements\sto\sEXPLAIN\sQUERY\sPLAN\soutput\sfor\smulti-row\sVALUES\sclaues. -D 2024-03-18T12:49:30.989 +C Fix\sthe\spatch\sat\s[10ee6fcba08ab128]\sso\sthat\sit\sworks\son\sreduced-size\sExpr\nnodes. +D 2024-03-18T13:10:54.954 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -700,7 +700,7 @@ F src/date.c 126ba2ab10aeb2e7ba6e089b5f07b747c0625b8287f78b60da346eda8d23c875 F src/dbpage.c 80e46e1df623ec40486da7a5086cb723b0275a6e2a7b01d9f9b5da0f04ba2782 F src/dbstat.c 3b677254d512fcafd4d0b341bf267b38b235ccfddbef24f9154e19360fa22e43 F src/delete.c cb766727c78e715f9fb7ec8a7d03658ed2a3016343ca687acfcec9083cdca500 -F src/expr.c 27fdcdc65bca88934dfc4af0efe7a3eae095267bf7592b562abb6a11292c2b82 +F src/expr.c d7cfe9b9fe7ab47b254706589467d2e65fec3536b936d6f4eb28b84da6726ecc F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c a47610f0a5c6cb0ad79f8fcef039c01833dec0c751bb695f28dc0ec6a4c3ba00 F src/func.c 4204c56196847faefef57fa14e43b8e4d65eb8d7e65318abe463472e3fd148cb @@ -2179,8 +2179,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 2ff476eb3d1f4a2146f4a48b57895a00a3ff5beb29afa679ae53ea58cac07c76 -R dd6d36e36b292e54015829bdd4a764a6 +P ac6f095e13e43d66c06552c8b01f6bec3407c9d41a34c4cdb0be57b0b828ad0d +R 5e57ddae8e8fa784e790916f6a9e17d3 U drh -Z 67655d85fa3f7ad082be72ee3ee927a1 +Z 9ad56bfa46f009d741e8a52554c68de1 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 21dcd3d6f2..2ca2f7c4e3 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ac6f095e13e43d66c06552c8b01f6bec3407c9d41a34c4cdb0be57b0b828ad0d \ No newline at end of file +260bd764c3f2d6d067adb9cd0045b7c24d5e00b02ab2735b1cba455a6143ff4c \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index be8339c305..3a7065b21f 100644 --- a/src/expr.c +++ b/src/expr.c @@ -2387,7 +2387,7 @@ static SQLITE_NOINLINE int exprNodeIsConstantFunction( if( pDef==0 || pDef->xFinalize!=0 || (pDef->funcFlags & (SQLITE_FUNC_CONSTANT|SQLITE_FUNC_SLOCHNG))==0 - || pExpr->y.pWin + || ExprHasProperty(pExpr, EP_WinFunc) ){ pWalker->eCode = 0; return WRC_Abort; From ac7c6f58540e07a1db2cda5ed58b5fe06fc23dd2 Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 18 Mar 2024 13:31:24 +0000 Subject: [PATCH 242/430] Add assert() statements to validate access to the SrcItem.u1.nRow union member. FossilOrigin-Name: 21f616d9b948efca441f8d45d0a95f4c052ce8b6daec7fa582ad9a00b82ca570 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/insert.c | 2 +- src/printf.c | 1 + src/sqliteInt.h | 10 ++++++---- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/manifest b/manifest index 5876e426d7..96cee0f9f8 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\spatch\sat\s[10ee6fcba08ab128]\sso\sthat\sit\sworks\son\sreduced-size\sExpr\nnodes. -D 2024-03-18T13:10:54.954 +C Add\sassert()\sstatements\sto\svalidate\saccess\sto\sthe\sSrcItem.u1.nRow\sunion\smember. +D 2024-03-18T13:31:24.110 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -709,7 +709,7 @@ F src/hash.c 9ee4269fb1d6632a6fecfb9479c93a1f29271bddbbaf215dd60420bcb80c7220 F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 -F src/insert.c 3b3661886b198d9c5e26c189a802782d35e6b415d0edf57af8c273225c2ae8f2 +F src/insert.c 59ae6959ccd23ea084159b4268d3fb5e6daffcc26b7cf1ad37201d823eecad82 F src/json.c e2e40760d6689134c3e2ece38c6a496b34ff5e2661a8f238444a119af666fdce F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 @@ -746,7 +746,7 @@ F src/pcache1.c 602acb23c471bb8d557a6f0083cc2be641d6cafcafa19e481eba7ef4c9ca0f00 F src/pragma.c e8221d6310c9923c80f6fa6d09b7ea7c5263a671f53db8d0894df23efcdb617b F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7 F src/prepare.c 371f6115cb69286ebc12c6f2d7511279c2e47d9f54f475d46a554d687a3b312c -F src/printf.c aec4a5d743796be82d61c5d127d0f4615efbe61620a7a16968c5e2c9378ab37b +F src/printf.c 87b67bba3662a0523f39ae6b084a3907109702f717c654d6cecb838af5cd57f1 F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c ef87e3bc7700bfe761a7bbee2ce6084f1766dc816dd82a3ae77c133eec898432 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 @@ -755,7 +755,7 @@ F src/shell.c.in cf80c636bccb0ff9db46995e39d69ca21fde2a8a331d1691e4d62a69d7841c8 F src/sqlite.h.in 19a2db3995a699bd7f6dfb423856242bfceb7ec849a93c91d241d19fc28d9f0f F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 -F src/sqliteInt.h f0014674d40b401795b4ff026fc4804aed3887f50d206fb221ddf4f2004bc3ef +F src/sqliteInt.h a58b4a33a9807667503a053721a4cd736cda8b60daae896a1b04f120a64c9fd2 F src/sqliteLimit.h 6878ab64bdeb8c24a1d762d45635e34b96da21132179023338c93f820eee6728 F src/status.c cb11f8589a6912af2da3bb1ec509a94dd8ef27df4d4c1a97e0bcf2309ece972b F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1 @@ -2179,8 +2179,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P ac6f095e13e43d66c06552c8b01f6bec3407c9d41a34c4cdb0be57b0b828ad0d -R 5e57ddae8e8fa784e790916f6a9e17d3 +P 260bd764c3f2d6d067adb9cd0045b7c24d5e00b02ab2735b1cba455a6143ff4c +R 75dcb9b9acd93ebd15b87898d6bfec55 U drh -Z 9ad56bfa46f009d741e8a52554c68de1 +Z 5ddd66d0b5fd1a33a6a204e07bcebf08 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 2ca2f7c4e3..242c703a39 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -260bd764c3f2d6d067adb9cd0045b7c24d5e00b02ab2735b1cba455a6143ff4c \ No newline at end of file +21f616d9b948efca441f8d45d0a95f4c052ce8b6daec7fa582ad9a00b82ca570 \ No newline at end of file diff --git a/src/insert.c b/src/insert.c index 7256281fd2..be558be78d 100644 --- a/src/insert.c +++ b/src/insert.c @@ -698,7 +698,6 @@ Select *sqlite3MultiValues(Parse *pParse, Select *pLeft, ExprList *pRow){ }else{ SrcItem *p = 0; /* SrcItem that reads from co-routine */ - if( pLeft->pSrc->nSrc==0 ){ /* Co-routine has not yet been started and the special Select object ** that accesses the co-routine has not yet been created. This block @@ -742,6 +741,7 @@ Select *sqlite3MultiValues(Parse *pParse, Select *pLeft, ExprList *pRow){ } }else{ p = &pLeft->pSrc->a[0]; + assert( !p->fg.isTabFunc && !p->fg.isIndexedBy ); p->u1.nRow++; } diff --git a/src/printf.c b/src/printf.c index 0aea74e890..eb22ee320d 100644 --- a/src/printf.c +++ b/src/printf.c @@ -861,6 +861,7 @@ void sqlite3_str_vappendf( if( pSel->selFlags & SF_NestedFrom ){ sqlite3_str_appendf(pAccum, "(join-%u)", pSel->selId); }else if( pSel->selFlags & SF_MultiValue ){ + assert( !pItem->fg.isTabFunc && !pItem->fg.isIndexedBy ); sqlite3_str_appendf(pAccum, "%u-ROW VALUES CLAUSE", pItem->u1.nRow); }else{ diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 01a5126499..8d18bfdfbb 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -3270,10 +3270,12 @@ struct IdList { ** ** Union member validity: ** -** u1.zIndexedBy fg.isIndexedBy && !fg.isTabFunc -** u1.pFuncArg fg.isTabFunc && !fg.isIndexedBy -** u2.pIBIndex fg.isIndexedBy && !fg.isCte -** u2.pCteUse fg.isCte && !fg.isIndexedBy +** u1.zIndexedBy fg.isIndexedBy && !fg.isTabFunc +** u1.pFuncArg fg.isTabFunc && !fg.isIndexedBy +** u1.nRow !fg.isTabFunc && !fg.isIndexedBy +** +** u2.pIBIndex fg.isIndexedBy && !fg.isCte +** u2.pCteUse fg.isCte && !fg.isIndexedBy */ struct SrcItem { Schema *pSchema; /* Schema to which this item is fixed */ From b03805b70b1312dc92b6a394ac0d09be132e6a68 Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 18 Mar 2024 15:10:00 +0000 Subject: [PATCH 243/430] Change a test case to use a window function rather than random() to disable the VALUES clause optimization. FossilOrigin-Name: c589149a138fa0a6be3153986fc0f315e052e13ebc0e7006b6529ca02bae413b --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/values.test | 6 ++++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 96cee0f9f8..1e6486f30b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sassert()\sstatements\sto\svalidate\saccess\sto\sthe\sSrcItem.u1.nRow\sunion\smember. -D 2024-03-18T13:31:24.110 +C Change\sa\stest\scase\sto\suse\sa\swindow\sfunction\srather\sthan\srandom()\sto\sdisable\nthe\sVALUES\sclause\soptimization. +D 2024-03-18T15:10:00.843 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -1921,7 +1921,7 @@ F test/vacuum4.test 7ea76b769fffeb41f925303b04cbcf5a5bbeabe55e4c60ae754ff24eeeb7 F test/vacuum5.test 263b144d537e92ad8e9ca8a73cc6e1583f41cfd0dda9432b87f7806174a2f48c F test/vacuum6.test b137b04bf3392d3f5c3b8fda0ce85a6775a70ca112f6559f74ff52dc9ce042fd F test/vacuummem.test 4b30f5b95a9ff86e9d5c20741e50a898b2dc10b0962a3211571eb165357003fb -F test/values.test 77f72e80ad7b9e362e309bccb391307f41d0a41d1cd159cbdadb2de043505184 +F test/values.test 28aae97e976968c8540df0294c3f1cee80780c0df87101ca8969f184789f3029 F test/valuesfault.test 2ef23ed965e3bd08e268cdc38a0d11653390ddbbe1e8e2e98d16f55edd30f6e8 F test/varint.test bbce22cda8fc4d135bcc2b589574be8410614e62 F test/veryquick.test 57ab846bacf7b90cf4e9a672721ea5c5b669b661 @@ -2179,8 +2179,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 260bd764c3f2d6d067adb9cd0045b7c24d5e00b02ab2735b1cba455a6143ff4c -R 75dcb9b9acd93ebd15b87898d6bfec55 +P 21f616d9b948efca441f8d45d0a95f4c052ce8b6daec7fa582ad9a00b82ca570 +R 8397e730ec47ff60644573ff69916492 U drh -Z 5ddd66d0b5fd1a33a6a204e07bcebf08 +Z 4aa38dc309434c1f95f0da72b0b4ecc4 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 242c703a39..168fa1695d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -21f616d9b948efca441f8d45d0a95f4c052ce8b6daec7fa582ad9a00b82ca570 \ No newline at end of file +c589149a138fa0a6be3153986fc0f315e052e13ebc0e7006b6529ca02bae413b \ No newline at end of file diff --git a/test/values.test b/test/values.test index 8365584b4a..14b242c9ec 100644 --- a/test/values.test +++ b/test/values.test @@ -457,14 +457,16 @@ do_eqp_test 15.3 { do_eqp_test 15.4 { INSERT INTO t1 VALUES (1,2),(3,4),(7,8), - (5,coalesce(6,random())); + (5,row_number()OVER()); } { QUERY PLAN `--COMPOUND QUERY |--LEFT-MOST SUBQUERY | `--SCAN 3-ROW VALUES CLAUSE `--UNION ALL - `--SCAN CONSTANT ROW + |--CO-ROUTINE (subquery-xxxxxx) + | `--SCAN CONSTANT ROW + `--SCAN (subquery-xxxxxx) } do_eqp_test 15.5 { SELECT * FROM (VALUES(1),(2),(3),(4),(5),(6)), (VALUES('a'),('b'),('c')); From c195e2374b63d29190e00a74482238eaf426d73f Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 18 Mar 2024 16:30:00 +0000 Subject: [PATCH 244/430] Allow the VALUES-as-coroutine optimization to be applied to later rows of a VALUES clause even if earlier rows do not qualify. FossilOrigin-Name: 9a47ea7f0f675f7bf4710901487ce34c7689e618cd1d8b9f94f0ff7ebc3f2841 --- manifest | 14 ++++---- manifest.uuid | 2 +- src/insert.c | 9 +++-- test/values.test | 91 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 106 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 1e6486f30b..e3e832688e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Change\sa\stest\scase\sto\suse\sa\swindow\sfunction\srather\sthan\srandom()\sto\sdisable\nthe\sVALUES\sclause\soptimization. -D 2024-03-18T15:10:00.843 +C Allow\sthe\sVALUES-as-coroutine\soptimization\sto\sbe\sapplied\sto\slater\srows\sof\na\sVALUES\sclause\seven\sif\searlier\srows\sdo\snot\squalify. +D 2024-03-18T16:30:00.996 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -709,7 +709,7 @@ F src/hash.c 9ee4269fb1d6632a6fecfb9479c93a1f29271bddbbaf215dd60420bcb80c7220 F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 -F src/insert.c 59ae6959ccd23ea084159b4268d3fb5e6daffcc26b7cf1ad37201d823eecad82 +F src/insert.c a71901268468aff9bc5d4034209026b45a0163c7a21422337de21940c8ab5310 F src/json.c e2e40760d6689134c3e2ece38c6a496b34ff5e2661a8f238444a119af666fdce F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 @@ -1921,7 +1921,7 @@ F test/vacuum4.test 7ea76b769fffeb41f925303b04cbcf5a5bbeabe55e4c60ae754ff24eeeb7 F test/vacuum5.test 263b144d537e92ad8e9ca8a73cc6e1583f41cfd0dda9432b87f7806174a2f48c F test/vacuum6.test b137b04bf3392d3f5c3b8fda0ce85a6775a70ca112f6559f74ff52dc9ce042fd F test/vacuummem.test 4b30f5b95a9ff86e9d5c20741e50a898b2dc10b0962a3211571eb165357003fb -F test/values.test 28aae97e976968c8540df0294c3f1cee80780c0df87101ca8969f184789f3029 +F test/values.test e7c156f92d32ed645908fbad0a1144f0f31650376cdcb212fde701978c89d3b1 F test/valuesfault.test 2ef23ed965e3bd08e268cdc38a0d11653390ddbbe1e8e2e98d16f55edd30f6e8 F test/varint.test bbce22cda8fc4d135bcc2b589574be8410614e62 F test/veryquick.test 57ab846bacf7b90cf4e9a672721ea5c5b669b661 @@ -2179,8 +2179,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 21f616d9b948efca441f8d45d0a95f4c052ce8b6daec7fa582ad9a00b82ca570 -R 8397e730ec47ff60644573ff69916492 +P c589149a138fa0a6be3153986fc0f315e052e13ebc0e7006b6529ca02bae413b +R 940f14de84991bdaec1e3874c3d6141e U drh -Z 4aa38dc309434c1f95f0da72b0b4ecc4 +Z d0598787dc817aed0c423e65e0b46555 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 168fa1695d..c08cd51c0e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c589149a138fa0a6be3153986fc0f315e052e13ebc0e7006b6529ca02bae413b \ No newline at end of file +9a47ea7f0f675f7bf4710901487ce34c7689e618cd1d8b9f94f0ff7ebc3f2841 \ No newline at end of file diff --git a/src/insert.c b/src/insert.c index be558be78d..a87d714a0c 100644 --- a/src/insert.c +++ b/src/insert.c @@ -670,8 +670,7 @@ static int exprListIsNoAffinity(Parse *pParse, ExprList *pRow){ */ Select *sqlite3MultiValues(Parse *pParse, Select *pLeft, ExprList *pRow){ - if( pLeft->pPrior /* co-routine precluded by prior row */ - || pParse->bHasWith /* condition (a) above */ + if( pParse->bHasWith /* condition (a) above */ || pParse->db->init.busy /* condition (b) above */ || exprListIsConstant(pParse,pRow)==0 /* condition (c) above */ || (pLeft->pSrc->nSrc==0 && @@ -714,6 +713,12 @@ Select *sqlite3MultiValues(Parse *pParse, Select *pLeft, ExprList *pRow){ if( pRet ){ SelectDest dest; pRet->pSrc->nSrc = 1; + pRet->pPrior = pLeft->pPrior; + pRet->op = pLeft->op; + pLeft->pPrior = 0; + pLeft->op = TK_SELECT; + assert( pLeft->pNext==0 ); + assert( pRet->pNext==0 ); p = &pRet->pSrc->a[0]; p->pSelect = pLeft; p->fg.viaCoroutine = 1; diff --git a/test/values.test b/test/values.test index 14b242c9ec..43f8e0e6fe 100644 --- a/test/values.test +++ b/test/values.test @@ -489,4 +489,95 @@ do_eqp_test 15.7 { `--SCAN 4-ROW VALUES CLAUSE } +#-------------------------------------------------------------------------- +# The VALUES-as-coroutine optimization can be applied to later rows of +# a VALUES clause even if earlier rows do not qualify. +# +reset_db +do_execsql_test 16.1 { + CREATE TABLE t1(a,b); +} +do_execsql_test 16.2 { + BEGIN; + INSERT INTO t1 VALUES(1,2),(3,4),(5,6), + (7,row_number()OVER()), + (9,10), (11,12), (13,14), (15,16); + SELECT * FROM t1 ORDER BY a, b; + ROLLBACK; +} {1 2 3 4 5 6 7 1 9 10 11 12 13 14 15 16} +do_eqp_test 16.3 { + INSERT INTO t1 VALUES(1,2),(3,4),(5,6), + (7,row_number()OVER()), + (9,10), (11,12), (13,14), (15,16); +} { + QUERY PLAN + `--COMPOUND QUERY + |--LEFT-MOST SUBQUERY + | `--SCAN 3-ROW VALUES CLAUSE + |--UNION ALL + | |--CO-ROUTINE (subquery-xxxxxx) + | | `--SCAN CONSTANT ROW + | `--SCAN (subquery-xxxxxx) + `--UNION ALL + `--SCAN 4-ROW VALUES CLAUSE +} +do_execsql_test 16.4 { + BEGIN; + INSERT INTO t1 VALUES + (1,row_number()OVER()), + (2,3), (4,5), (6,7); + SELECT * FROM t1 ORDER BY a, b; + ROLLBACK; +} {1 1 2 3 4 5 6 7} +do_eqp_test 16.5 { + INSERT INTO t1 VALUES + (1,row_number()OVER()), + (2,3), (4,5), (6,7); +} { + QUERY PLAN + `--COMPOUND QUERY + |--LEFT-MOST SUBQUERY + | |--CO-ROUTINE (subquery-xxxxxx) + | | `--SCAN CONSTANT ROW + | `--SCAN (subquery-xxxxxx) + `--UNION ALL + `--SCAN 3-ROW VALUES CLAUSE +} +do_execsql_test 16.6 { + BEGIN; + INSERT INTO t1 VALUES + (1,2),(3,4), + (5,row_number()OVER()), + (7,8),(9,10),(11,12), + (13,row_number()OVER()), + (15,16),(17,18),(19,20),(21,22); + SELECT * FROM t1 ORDER BY a, b; + ROLLBACK; +} { 1 2 3 4 5 1 7 8 9 10 11 12 13 1 15 16 17 18 19 20 21 22} +do_eqp_test 16.7 { + INSERT INTO t1 VALUES + (1,2),(3,4), + (5,row_number()OVER()), + (7,8),(9,10),(11,12), + (13,row_number()OVER()), + (15,16),(17,18),(19,20),(21,22); +} { + QUERY PLAN + `--COMPOUND QUERY + |--LEFT-MOST SUBQUERY + | `--SCAN 2-ROW VALUES CLAUSE + |--UNION ALL + | |--CO-ROUTINE (subquery-xxxxxx) + | | `--SCAN CONSTANT ROW + | `--SCAN (subquery-xxxxxx) + |--UNION ALL + | `--SCAN 3-ROW VALUES CLAUSE + |--UNION ALL + | |--CO-ROUTINE (subquery-xxxxxx) + | | `--SCAN CONSTANT ROW + | `--SCAN (subquery-xxxxxx) + `--UNION ALL + `--SCAN 4-ROW VALUES CLAUSE +} + finish_test From 2ad2584581992f59543bc00c3be313d29448aeb0 Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 18 Mar 2024 17:13:52 +0000 Subject: [PATCH 245/430] Fix harmless compiler (scan-build) warnings. FossilOrigin-Name: c86f9f2a15ffc726b7f0d9bba5a8c4dfdaeea6a297e0b591c554fff3d1fe6e1c --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/insert.c | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index e3e832688e..1e94c6c964 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Allow\sthe\sVALUES-as-coroutine\soptimization\sto\sbe\sapplied\sto\slater\srows\sof\na\sVALUES\sclause\seven\sif\searlier\srows\sdo\snot\squalify. -D 2024-03-18T16:30:00.996 +C Fix\sharmless\scompiler\s(scan-build)\swarnings. +D 2024-03-18T17:13:52.924 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -709,7 +709,7 @@ F src/hash.c 9ee4269fb1d6632a6fecfb9479c93a1f29271bddbbaf215dd60420bcb80c7220 F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 -F src/insert.c a71901268468aff9bc5d4034209026b45a0163c7a21422337de21940c8ab5310 +F src/insert.c 06ce505713e86172612f9e01febefd2d3331d1f70461b4ada0eae5a76bb6349f F src/json.c e2e40760d6689134c3e2ece38c6a496b34ff5e2661a8f238444a119af666fdce F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 @@ -2179,8 +2179,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P c589149a138fa0a6be3153986fc0f315e052e13ebc0e7006b6529ca02bae413b -R 940f14de84991bdaec1e3874c3d6141e +P 9a47ea7f0f675f7bf4710901487ce34c7689e618cd1d8b9f94f0ff7ebc3f2841 +R 99b0c172599c8a90caf2454e462eb6ef U drh -Z d0598787dc817aed0c423e65e0b46555 +Z e6f67e954fdd4f797f1644f6604d7595 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index c08cd51c0e..7f56713a39 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9a47ea7f0f675f7bf4710901487ce34c7689e618cd1d8b9f94f0ff7ebc3f2841 \ No newline at end of file +c86f9f2a15ffc726b7f0d9bba5a8c4dfdaeea6a297e0b591c554fff3d1fe6e1c \ No newline at end of file diff --git a/src/insert.c b/src/insert.c index a87d714a0c..fe7ba05dc1 100644 --- a/src/insert.c +++ b/src/insert.c @@ -751,6 +751,7 @@ Select *sqlite3MultiValues(Parse *pParse, Select *pLeft, ExprList *pRow){ } if( pParse->nErr==0 ){ + assert( p!=0 ); if( p->pSelect->pEList->nExpr!=pRow->nExpr ){ sqlite3SelectWrongNumTermsError(pParse, p->pSelect); }else{ @@ -1099,7 +1100,6 @@ void sqlite3Insert( if( pSelect ){ /* Data is coming from a SELECT or from a multi-row VALUES clause. ** Generate a co-routine to run the SELECT. */ - int regYield; /* Register holding co-routine entry-point */ int rc; /* Result code */ if( pSelect->pSrc->nSrc==1 @@ -1107,7 +1107,7 @@ void sqlite3Insert( && pSelect->pPrior==0 ){ SrcItem *pItem = &pSelect->pSrc->a[0]; - dest.iSDParm = regYield = pItem->regReturn; + dest.iSDParm = pItem->regReturn; regFromSelect = pItem->regResult; nColumn = pItem->pSelect->pEList->nExpr; ExplainQueryPlan((pParse, 0, "SCAN %S", pItem)); @@ -1118,7 +1118,7 @@ void sqlite3Insert( } }else{ int addrTop; /* Top of the co-routine */ - regYield = ++pParse->nMem; + int regYield = ++pParse->nMem; addrTop = sqlite3VdbeCurrentAddr(v) + 1; sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, addrTop); sqlite3SelectDestInit(&dest, SRT_Coroutine, regYield); From fc2d862318876ff36910b57f8ecafdda8d36fa59 Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 18 Mar 2024 18:03:17 +0000 Subject: [PATCH 246/430] Remove unnecessary blank lines from build commands in the default Makefile.in. FossilOrigin-Name: 76fb3a908f45230b956cb659c754e47603e80aa72a2aad50d479437a9c013f61 --- Makefile.in | 6 ++---- manifest | 13 ++++++------- manifest.uuid | 2 +- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/Makefile.in b/Makefile.in index e16fa94345..c16e1c127d 100644 --- a/Makefile.in +++ b/Makefile.in @@ -817,8 +817,7 @@ has_tclsh85: touch .target_source sqlite3.c: .target_source $(TOP)/tool/mksqlite3c.tcl src-verify has_tclsh84 - $(TCLSH_CMD) $(TOP)/tool/mksqlite3c.tcl $(AMALGAMATION_LINE_MACROS) \ - $(EXTRA_SRC) + $(TCLSH_CMD) $(TOP)/tool/mksqlite3c.tcl $(AMALGAMATION_LINE_MACROS) $(EXTRA_SRC) cp tsrc/sqlite3ext.h . cp $(TOP)/ext/session/sqlite3session.h . @@ -829,8 +828,7 @@ sqlite3r.c: sqlite3.c sqlite3r.h has_tclsh84 cp $(TOP)/ext/recover/sqlite3recover.c tsrc/ cp $(TOP)/ext/recover/sqlite3recover.h tsrc/ cp $(TOP)/ext/recover/dbdata.c tsrc/ - $(TCLSH_CMD) $(TOP)/tool/mksqlite3c.tcl --enable-recover \ - $(AMALGAMATION_LINE_MACROS) $(EXTRA_SRC) + $(TCLSH_CMD) $(TOP)/tool/mksqlite3c.tcl --enable-recover $(AMALGAMATION_LINE_MACROS) $(EXTRA_SRC) sqlite3ext.h: .target_source cp tsrc/sqlite3ext.h . diff --git a/manifest b/manifest index 55bb6354bf..68196a51d6 100644 --- a/manifest +++ b/manifest @@ -1,9 +1,9 @@ -C Add\sthe\s"VALUES-as-coroutine"\soptimization.\s\sLarge\sVALUES\sclauses\son\san\nINSERT,\sfor\sexample,\sprepare\sand\srun\sin\sabout\shalf\sthe\stime\sand\swith\shalf\nthe\smemory.\s\sThis\scheck-in\salso\sincludes\senhancements\sto\sthe\sinternal\nsqlite3ExprIsConstant()\sroutine\sto\srecognize\spure\sSQL\sfunctions\sas\sconstant\nif\sthey\shave\sconstant\sarguments. -D 2024-03-18T18:00:17.106 +C Remove\sunnecessary\sblank\slines\sfrom\sbuild\scommands\sin\sthe\sdefault\sMakefile.in. +D 2024-03-18T18:03:17.115 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 -F Makefile.in 5f2389d2a3c44b56621bb5156a9cb6e2bef01f7ec14a19335b1559cf0474bdde +F Makefile.in 993a7874e3d3721df61846f03dda4a9ef7490da11953ae36ba1bb0c0346eaf4a F Makefile.linux-gcc f3842a0b1efbfbb74ac0ef60e56b301836d05b4d867d014f714fa750048f1ab6 F Makefile.msc e64a52619310d3067f6c38f56eedd15918a82dade70954197d6da486ad99d7f4 F README.md 6358805260a03ebead84e168bbf3740ddf3f683b477e478567186aa7afb490d3 @@ -2179,9 +2179,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 82035b9cfd28ef6b0ecc6f469f03d2b001189aa4925147cdb784b6b1964eb3b2 c86f9f2a15ffc726b7f0d9bba5a8c4dfdaeea6a297e0b591c554fff3d1fe6e1c -R d086636689a6bb7c4b198edffb3a7c63 -T +closed c86f9f2a15ffc726b7f0d9bba5a8c4dfdaeea6a297e0b591c554fff3d1fe6e1c +P a120c9235f125e05be494038c16a9dd326fd79837698bef17e7879cd0cd75831 +R 8ff4324227d383f5da29d0bfe203141e U drh -Z 48e8dd6fe42c5583ed5ba3f909ede536 +Z 25814839eb089de12c64c949b849b19e # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 82d6efaeee..73c10f1cd5 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a120c9235f125e05be494038c16a9dd326fd79837698bef17e7879cd0cd75831 \ No newline at end of file +76fb3a908f45230b956cb659c754e47603e80aa72a2aad50d479437a9c013f61 \ No newline at end of file From 365b6e9769681b2bab3300c53ec7131d3df08064 Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 18 Mar 2024 20:52:45 +0000 Subject: [PATCH 247/430] Avoid spurious SQLITE_IOERR_DATA errors when reading partial pages from a cksumvfs database using a SQLITE_DIRECT_OVERFLOW_READ build. FossilOrigin-Name: 0f485dbece9146eabe5a5c0998a9e35c685a170c3fe6d4509e92aa8dae18a2c0 --- ext/misc/cksumvfs.c | 6 +++--- manifest | 15 ++++++++------- manifest.uuid | 2 +- test/cksumvfs.test | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 45 insertions(+), 11 deletions(-) create mode 100644 test/cksumvfs.test diff --git a/ext/misc/cksumvfs.c b/ext/misc/cksumvfs.c index e7c2c9d5c0..2d7f6584ea 100644 --- a/ext/misc/cksumvfs.c +++ b/ext/misc/cksumvfs.c @@ -446,9 +446,9 @@ static int cksmRead( ** (2) checksum verification is enabled ** (3) we are not in the middle of checkpoint */ - if( iAmt>=512 /* (1) */ - && p->verifyCksm /* (2) */ - && !p->inCkpt /* (3) */ + if( iAmt>=512 && (iAmt & (iAmt-1))==0 /* (1) */ + && p->verifyCksm /* (2) */ + && !p->inCkpt /* (3) */ ){ u8 cksum[8]; cksmCompute((u8*)zBuf, iAmt-8, cksum); diff --git a/manifest b/manifest index 68196a51d6..e0127ab6bd 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\sunnecessary\sblank\slines\sfrom\sbuild\scommands\sin\sthe\sdefault\sMakefile.in. -D 2024-03-18T18:03:17.115 +C Avoid\sspurious\sSQLITE_IOERR_DATA\serrors\swhen\sreading\spartial\spages\sfrom\sa\scksumvfs\sdatabase\susing\sa\sSQLITE_DIRECT_OVERFLOW_READ\sbuild. +D 2024-03-18T20:52:45.827 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -382,7 +382,7 @@ F ext/misc/blobio.c a867c4c4617f6ec223a307ebfe0eabb45e0992f74dd47722b96f3e631c0e F ext/misc/btreeinfo.c cb952620eedf5c0b7625b678f0f08e54d2ec0011d4e50efda5ebdc97f3df7d04 F ext/misc/carray.c 34fac63770971611c5285de0a9f0ac67d504eaf66be891f637add9290f1c76a5 F ext/misc/carray.h 503209952ccf2431c7fd899ebb92bf46bf7635b38aace42ec8aa1b8d7b6e98a5 -F ext/misc/cksumvfs.c 9224e33cc0cb6aa61ff1d7d7b8fd6fe56beca9f9c47954fa4ae0a69bef608f69 +F ext/misc/cksumvfs.c 3a7931dd30667be6348af919f3f9e6188dfd7646b42af8e399a499b327f5bd63 F ext/misc/closure.c 0e04f52d93e678dd6f950f195f365992edf3c380df246f3d80425cba4c13891e F ext/misc/completion.c ef78835483b43ac18c96be312b90b615d8368189909be03513ab7a9338131298 F ext/misc/compress.c 3354c77a7c8e86e07d849916000cdac451ed96500bfb5bd83b20eb61eee012c9 @@ -977,6 +977,7 @@ F test/changes2.test 07949edcc732af28cb54276bfb7d99723bccc1e905a423648bf57ac5cb0 F test/check.test 56e4ed457e9f8683b9fc56f5b964f461f6e8a8dd5a13f3d495408215d66419ed F test/checkfault.test da6cb3d50247169efcb20bdf57863a3ccfa1d27d9e55cd324f0680096970f014 F test/chunksize.test 427d87791743486cbf0c3b8c625002f3255cb3a89c6eba655a98923b1387b760 +F test/cksumvfs.test 6f05dc95847c06a3dc10eee6b5ab1351d78314a52d0db15717c9388f4cb96646 F test/close.test eccbad8ecd611d974cbf47278c3d4e5874faf02d811338d5d348af42d56d647c F test/closure01.test 9905883f1b171a4638f98fc764879f154e214a306d3d8daf412a15e7f3a9b1e0 F test/coalesce.test cee0dccb9fbd2d494b77234bccf9dc6c6786eb91 @@ -2179,8 +2180,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P a120c9235f125e05be494038c16a9dd326fd79837698bef17e7879cd0cd75831 -R 8ff4324227d383f5da29d0bfe203141e -U drh -Z 25814839eb089de12c64c949b849b19e +P 76fb3a908f45230b956cb659c754e47603e80aa72a2aad50d479437a9c013f61 +R 3ba9b9e82b0006578500d53bc7e1cee3 +U dan +Z 687b3a53beb157acf8ccda89bb48f5f1 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 73c10f1cd5..e141632691 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -76fb3a908f45230b956cb659c754e47603e80aa72a2aad50d479437a9c013f61 \ No newline at end of file +0f485dbece9146eabe5a5c0998a9e35c685a170c3fe6d4509e92aa8dae18a2c0 \ No newline at end of file diff --git a/test/cksumvfs.test b/test/cksumvfs.test new file mode 100644 index 0000000000..8c7bcf5511 --- /dev/null +++ b/test/cksumvfs.test @@ -0,0 +1,33 @@ +# 2024 March 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. +# +#*********************************************************************** +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix cksumvfs + +sqlite3_register_cksumvfs +db close +sqlite3 db test.db +file_control_reservebytes db 8 + +set text [db one "SELECT hex(randomblob(5000))"] + +do_execsql_test 1.0 { + CREATE TABLE t1(a INTEGER PRIMARY KEY, b); + INSERT INTO t1 VALUES(1, $text); +} + +do_execsql_test 1.1 { + SELECT * FROM t1; +} [list 1 $text] + +finish_test From 28cd72ac520883a94cbb8444c38ff42aab485c52 Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 18 Mar 2024 21:08:33 +0000 Subject: [PATCH 248/430] Fix asan problems in sqlite3rbu.c. Enable RBU for sanitizer release tests. FossilOrigin-Name: ad2ae7717e7a10cf42aeabd3c544e7884fa082295c2babf0fdb19a684d2aba1e --- ext/rbu/sqlite3rbu.c | 4 +++- manifest | 14 +++++++------- manifest.uuid | 2 +- test/testrunner_data.tcl | 1 + 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/ext/rbu/sqlite3rbu.c b/ext/rbu/sqlite3rbu.c index 15b05cede1..feb7695d66 100644 --- a/ext/rbu/sqlite3rbu.c +++ b/ext/rbu/sqlite3rbu.c @@ -199,6 +199,7 @@ typedef unsigned int u32; typedef unsigned short u16; typedef unsigned char u8; typedef sqlite3_int64 i64; +typedef sqlite3_uint64 u64; #endif /* @@ -885,6 +886,7 @@ static int rbuObjIterNext(sqlite3rbu *p, RbuObjIter *pIter){ if( rc!=SQLITE_ROW ){ rc = resetAndCollectError(pIter->pTblIter, &p->zErrmsg); pIter->zTbl = 0; + pIter->zDataTbl = 0; }else{ pIter->zTbl = (const char*)sqlite3_column_text(pIter->pTblIter, 0); pIter->zDataTbl = (const char*)sqlite3_column_text(pIter->pTblIter,1); @@ -2979,7 +2981,7 @@ static i64 rbuShmChecksum(sqlite3rbu *p){ u32 volatile *ptr; p->rc = pDb->pMethods->xShmMap(pDb, 0, 32*1024, 0, (void volatile**)&ptr); if( p->rc==SQLITE_OK ){ - iRet = ((i64)ptr[10] << 32) + ptr[11]; + iRet = (i64)(((u64)ptr[10] << 32) + ptr[11]); } } return iRet; diff --git a/manifest b/manifest index e0127ab6bd..a13b01a2c2 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Avoid\sspurious\sSQLITE_IOERR_DATA\serrors\swhen\sreading\spartial\spages\sfrom\sa\scksumvfs\sdatabase\susing\sa\sSQLITE_DIRECT_OVERFLOW_READ\sbuild. -D 2024-03-18T20:52:45.827 +C Fix\sasan\sproblems\sin\ssqlite3rbu.c.\sEnable\sRBU\sfor\ssanitizer\srelease\stests. +D 2024-03-18T21:08:33.041 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -475,7 +475,7 @@ F ext/rbu/rbuvacuum.test 542561741ff2b262e3694bc6012b44694ee62c545845319a06f3237 F ext/rbu/rbuvacuum2.test ae097d04feb041446a74fac94b24bffeb3fdd60e32b848c5611e507ab702b81b F ext/rbu/rbuvacuum3.test 3ce42695fdf21aaa3499e857d7d4253bc499ad759bcd6c9362042c13cd37d8de F ext/rbu/rbuvacuum4.test ffccd22f67e2d0b380d2889685742159dfe0d19a3880ca3d2d1d69eefaebb205 -F ext/rbu/sqlite3rbu.c d4ddf8f0e93772556e452a6c2814063cf47efb760a0834391a9d0cd9859fa4b9 +F ext/rbu/sqlite3rbu.c 4a3376c0fb9a844a799ac529fb81260523f6b13c9f629bc270c632dbae5fc1f8 F ext/rbu/sqlite3rbu.h 9d923eb135c5d04aa6afd7c39ca47b0d1d0707c100e02f19fdde6a494e414304 F ext/rbu/test_rbu.c ee6ede75147bc081fe9bc3931e6b206277418d14d3fbceea6fdc6216d9b47055 F ext/recover/dbdata.c b7746c2ec801b453840831311be4b31f8c8f9dd97791060a69bbf12392c78949 @@ -1689,7 +1689,7 @@ F test/temptable3.test d11a0974e52b347e45ee54ef1923c91ed91e4637 F test/temptrigger.test 38f0ca479b1822d3117069e014daabcaacefffcc F test/tester.tcl fe617b88c7eb08bdf983d2aaa31c20fbf439eee7b8e0d61ca636fcd0c305bbbf F test/testrunner.tcl 01bc3b5bc900dc73b076180727eb2869dc61426b1ab95ac2f42def5d1f3d407e -F test/testrunner_data.tcl 2f94974e5e3a56af880be72f7a7fd239aa9d4ecf978625435fcc698319c927fa +F test/testrunner_data.tcl 7032a64e4757db0bf83c6874cab2ccbb14a8708b4d68c1ddc8b359e204139cb7 F test/thread001.test a0985c117eab62c0c65526e9fa5d1360dd1cac5b03bde223902763274ce21899 F test/thread002.test c24c83408e35ba5a952a3638b7ac03ccdf1ce4409289c54a050ac4c5f1de7502 F test/thread003.test ee4c9efc3b86a6a2767516a37bd64251272560a7 @@ -2180,8 +2180,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 76fb3a908f45230b956cb659c754e47603e80aa72a2aad50d479437a9c013f61 -R 3ba9b9e82b0006578500d53bc7e1cee3 +P 0f485dbece9146eabe5a5c0998a9e35c685a170c3fe6d4509e92aa8dae18a2c0 +R 59c6c1819c5f6280d4b2fc1e8ab12326 U dan -Z 687b3a53beb157acf8ccda89bb48f5f1 +Z 8b503392df6e7d7e46ebd7af33bbcc16 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index e141632691..7dfd6e9373 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0f485dbece9146eabe5a5c0998a9e35c685a170c3fe6d4509e92aa8dae18a2c0 \ No newline at end of file +ad2ae7717e7a10cf42aeabd3c544e7884fa082295c2babf0fdb19a684d2aba1e \ No newline at end of file diff --git a/test/testrunner_data.tcl b/test/testrunner_data.tcl index f38abad589..73b5472a99 100644 --- a/test/testrunner_data.tcl +++ b/test/testrunner_data.tcl @@ -108,6 +108,7 @@ namespace eval trd { -DSQLITE_ENABLE_STAT4 -DSQLITE_OMIT_LOOKASIDE=1 -DCONFIG_SLOWDOWN_FACTOR=5.0 + -DSQLITE_ENABLE_RBU --enable-debug --enable-all } From 108dd6a52d3679cc3a772600ac22de792f92c897 Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 19 Mar 2024 02:30:24 +0000 Subject: [PATCH 249/430] First steps toward getting -DSQLITE_ALLOW_ROWID_IN_VIEW to work again. That compile-time option is untested, undocumented, and unsupported. But it was mentioned in the release notes for version 3.36.0, so I think that means we need to support it forever. FossilOrigin-Name: 7c46ff640247584f1ea260c062de29a0e49f649d1894a526574c1a479006a1fc --- manifest | 17 ++++++++++------- manifest.uuid | 2 +- src/select.c | 7 ++++++- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index a13b01a2c2..a8b9d2e2ff 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sasan\sproblems\sin\ssqlite3rbu.c.\sEnable\sRBU\sfor\ssanitizer\srelease\stests. -D 2024-03-18T21:08:33.041 +C First\ssteps\stoward\sgetting\s-DSQLITE_ALLOW_ROWID_IN_VIEW\sto\swork\sagain.\s\sThat\ncompile-time\soption\sis\suntested,\sundocumented,\sand\sunsupported.\s\sBut\sit\swas\nmentioned\sin\sthe\srelease\snotes\sfor\sversion\s3.36.0,\sso\sI\sthink\sthat\smeans\swe\nneed\sto\ssupport\sit\sforever. +D 2024-03-19T02:30:24.246 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -750,7 +750,7 @@ F src/printf.c 87b67bba3662a0523f39ae6b084a3907109702f717c654d6cecb838af5cd57f1 F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c ef87e3bc7700bfe761a7bbee2ce6084f1766dc816dd82a3ae77c133eec898432 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 -F src/select.c df2bf515fc36e02e97959a70e82da8a4967d6c85590646a7fda2926a734c81ce +F src/select.c 934eb6e543133cb373ab76f791ded2b2b5c13ac50684453494c4b6c4ea4fba24 F src/shell.c.in cf80c636bccb0ff9db46995e39d69ca21fde2a8a331d1691e4d62a69d7841c8a F src/sqlite.h.in 19a2db3995a699bd7f6dfb423856242bfceb7ec849a93c91d241d19fc28d9f0f F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 @@ -2180,8 +2180,11 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 0f485dbece9146eabe5a5c0998a9e35c685a170c3fe6d4509e92aa8dae18a2c0 -R 59c6c1819c5f6280d4b2fc1e8ab12326 -U dan -Z 8b503392df6e7d7e46ebd7af33bbcc16 +P ad2ae7717e7a10cf42aeabd3c544e7884fa082295c2babf0fdb19a684d2aba1e +R cc156187f695f7801f18b2af21acf477 +T *branch * rowid-in-view +T *sym-rowid-in-view * +T -sym-trunk * +U drh +Z d1168aa5ebee2530ad432f8f9a6ecbd1 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 7dfd6e9373..3c83ab3dfc 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ad2ae7717e7a10cf42aeabd3c544e7884fa082295c2babf0fdb19a684d2aba1e \ No newline at end of file +7c46ff640247584f1ea260c062de29a0e49f649d1894a526574c1a479006a1fc \ No newline at end of file diff --git a/src/select.c b/src/select.c index 1085b99436..5dfabb140d 100644 --- a/src/select.c +++ b/src/select.c @@ -6142,7 +6142,9 @@ static int selectExpander(Walker *pWalker, Select *p){ pNestedFrom = pFrom->pSelect->pEList; assert( pNestedFrom!=0 ); assert( pNestedFrom->nExpr==pTab->nCol ); +#ifndef SQLITE_ALLOW_ROWID_IN_VIEW assert( VisibleRowid(pTab)==0 ); +#endif }else{ if( zTName && sqlite3StrICmp(zTName, zTabName)!=0 ){ continue; @@ -6174,7 +6176,10 @@ static int selectExpander(Walker *pWalker, Select *p){ pUsing = 0; } - nAdd = pTab->nCol + (VisibleRowid(pTab) && (selFlags&SF_NestedFrom)); + nAdd = pTab->nCol; +#ifndef SQLITE_ALLOW_ROWID_IN_VIEW + if( VisibleRowid(pTab) && (selFlags & SF_NestedFrom)!=0 ) nAdd++; +#endif for(j=0; j Date: Tue, 19 Mar 2024 10:16:17 +0000 Subject: [PATCH 250/430] Fix another problem from [c63e26e705f5e967] involving infinities and the Kahan-Babushka-Neumaier summation algorithm. Problem reported by [forum:/forumpost/23b8688ef4|forum post 23b8688ef4]. FossilOrigin-Name: 45d272ef38d5ee6189f81369aefb8e3ac35868a67687012d93c84f2bbc42520a --- manifest | 20 ++++++++++---------- manifest.uuid | 2 +- src/func.c | 6 +++--- src/sqliteInt.h | 7 +++++-- src/util.c | 13 +++++++++++++ test/func.test | 21 +++++++++++++++++++++ 6 files changed, 53 insertions(+), 16 deletions(-) diff --git a/manifest b/manifest index a13b01a2c2..d421c59182 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sasan\sproblems\sin\ssqlite3rbu.c.\sEnable\sRBU\sfor\ssanitizer\srelease\stests. -D 2024-03-18T21:08:33.041 +C Fix\sanother\sproblem\sfrom\s[c63e26e705f5e967]\sinvolving\sinfinities\sand\sthe\nKahan-Babushka-Neumaier\ssummation\salgorithm.\s\sProblem\sreported\sby\n[forum:/forumpost/23b8688ef4|forum\spost\s23b8688ef4]. +D 2024-03-19T10:16:17.413 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -703,7 +703,7 @@ F src/delete.c cb766727c78e715f9fb7ec8a7d03658ed2a3016343ca687acfcec9083cdca500 F src/expr.c d7cfe9b9fe7ab47b254706589467d2e65fec3536b936d6f4eb28b84da6726ecc F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c a47610f0a5c6cb0ad79f8fcef039c01833dec0c751bb695f28dc0ec6a4c3ba00 -F src/func.c 4204c56196847faefef57fa14e43b8e4d65eb8d7e65318abe463472e3fd148cb +F src/func.c 283d4f3b2751a1d9339fd93a8a013d1948fd5f4474a3cab0955eb4fafd445d0f F src/global.c 765a0656d6cbf043cb272ff0ae38f39cc46713539ffe6793258ed3eb4b188b52 F src/hash.c 9ee4269fb1d6632a6fecfb9479c93a1f29271bddbbaf215dd60420bcb80c7220 F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 @@ -755,7 +755,7 @@ F src/shell.c.in cf80c636bccb0ff9db46995e39d69ca21fde2a8a331d1691e4d62a69d7841c8 F src/sqlite.h.in 19a2db3995a699bd7f6dfb423856242bfceb7ec849a93c91d241d19fc28d9f0f F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 -F src/sqliteInt.h a58b4a33a9807667503a053721a4cd736cda8b60daae896a1b04f120a64c9fd2 +F src/sqliteInt.h 9ffcf672d8a55d5bd5b5c8988c14ea575350c4920b7e43393608ac65aee332fe F src/sqliteLimit.h 6878ab64bdeb8c24a1d762d45635e34b96da21132179023338c93f820eee6728 F src/status.c cb11f8589a6912af2da3bb1ec509a94dd8ef27df4d4c1a97e0bcf2309ece972b F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1 @@ -818,7 +818,7 @@ F src/trigger.c 0905b96b04bb6658509f711a8207287f1315cdbc3df1a1b13ba6483c8e341c81 F src/update.c 6904814dd62a7a93bbb86d9f1419c7f134a9119582645854ab02b36b676d9f92 F src/upsert.c 2e60567a0e9e8520c18671b30712a88dc73534474304af94f32bb5f3ef65ac65 F src/utf.c f23165685a67b4caf8ec08fb274cb3f319103decfb2a980b7cfd55d18dfa855e -F src/util.c f27a17e6e43fa362abea4db507a1c409f0adc8048ecf4c6479e8d162158ed529 +F src/util.c 4d6d7ebfe6772a1b950c97bbb1d1a72ad4874617ec498ab8aa73b7f5a43e44bb F src/vacuum.c 604fcdaebe76f3497c855afcbf91b8fa5046b32de3045bab89cc008d68e40104 F src/vdbe.c da8407be6055f5751bf85681542d130a320b4fd1f4d8719bf83a464743d9aae4 F src/vdbe.h c2d78d15112c3fc5ab87f5e8e0b75d2db1c624409de2e858c3d1aafb1650bb4f @@ -1229,7 +1229,7 @@ F test/fts4umlaut.test fcaca4471de7e78c9d1f7e8976e3e8704d7d8ad979d57a739d00f3f75 F test/fts4unicode.test 82a9c16b68ba2f358a856226bb2ee02f81583797bc4744061c54401bf1a0f4c9 F test/fts4upfrom.test f25835162c989dffd5e2ef91ec24c4848cc9973093e2d492d1c7b32afac1b49d F test/full.test 6b3c8fb43c6beab6b95438c1675374b95fab245d -F test/func.test 504d202650c7940b5aa98364dd68f242df87f39f829e51074a55d79fc7bc7414 +F test/func.test 648ca90b9c36e9eefd8005d64cd8ad2d2dba73891df0fbe157b866d1cc95bdc8 F test/func2.test 772d66227e4e6684b86053302e2d74a2500e1e0f F test/func3.test 600a632c305a88f3946d38f9a51efe145c989b2e13bd2b2a488db47fe76bab6a F test/func4.test a3f9062487dbd826776f54f4e0e9517fe8c3cf689af92735308965774d51fac5 @@ -2180,8 +2180,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 0f485dbece9146eabe5a5c0998a9e35c685a170c3fe6d4509e92aa8dae18a2c0 -R 59c6c1819c5f6280d4b2fc1e8ab12326 -U dan -Z 8b503392df6e7d7e46ebd7af33bbcc16 +P ad2ae7717e7a10cf42aeabd3c544e7884fa082295c2babf0fdb19a684d2aba1e +R 6728c90829563f9564b3fe7ee7e264f2 +U drh +Z 8f46ba2909e90f1ebfbdf6c7d1fcfdc3 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 7dfd6e9373..aafcf89491 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ad2ae7717e7a10cf42aeabd3c544e7884fa082295c2babf0fdb19a684d2aba1e \ No newline at end of file +45d272ef38d5ee6189f81369aefb8e3ac35868a67687012d93c84f2bbc42520a \ No newline at end of file diff --git a/src/func.c b/src/func.c index 9fbd1e9e1c..18004984d9 100644 --- a/src/func.c +++ b/src/func.c @@ -1892,7 +1892,7 @@ static void sumFinalize(sqlite3_context *context){ if( p->approx ){ if( p->ovrfl ){ sqlite3_result_error(context,"integer overflow",-1); - }else if( !sqlite3IsNaN(p->rErr) ){ + }else if( !sqlite3IsOverflow(p->rErr) ){ sqlite3_result_double(context, p->rSum+p->rErr); }else{ sqlite3_result_double(context, p->rSum); @@ -1909,7 +1909,7 @@ static void avgFinalize(sqlite3_context *context){ double r; if( p->approx ){ r = p->rSum; - if( !sqlite3IsNaN(p->rErr) ) r += p->rErr; + if( !sqlite3IsOverflow(p->rErr) ) r += p->rErr; }else{ r = (double)(p->iSum); } @@ -1923,7 +1923,7 @@ static void totalFinalize(sqlite3_context *context){ if( p ){ if( p->approx ){ r = p->rSum; - if( !sqlite3IsNaN(p->rErr) ) r += p->rErr; + if( !sqlite3IsOverflow(p->rErr) ) r += p->rErr; }else{ r = (double)(p->iSum); } diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 8d18bfdfbb..db1ede8e6d 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -4712,10 +4712,13 @@ void sqlite3MutexWarnOnContention(sqlite3_mutex*); # define EXP754 (((u64)0x7ff)<<52) # define MAN754 ((((u64)1)<<52)-1) # define IsNaN(X) (((X)&EXP754)==EXP754 && ((X)&MAN754)!=0) +# define IsOvfl(X) (((X)&EXP754)==EXP754) int sqlite3IsNaN(double); + int sqlite3IsOverflow(double); #else -# define IsNaN(X) 0 -# define sqlite3IsNaN(X) 0 +# define IsNaN(X) 0 +# define sqlite3IsNaN(X) 0 +# define sqlite3IsOVerflow(X) 0 #endif /* diff --git a/src/util.c b/src/util.c index 8c9e980cd1..3b10ba60ad 100644 --- a/src/util.c +++ b/src/util.c @@ -68,6 +68,19 @@ int sqlite3IsNaN(double x){ } #endif /* SQLITE_OMIT_FLOATING_POINT */ +#ifndef SQLITE_OMIT_FLOATING_POINT +/* +** Return true if the floating point value is NaN or +Inf or -Inf. +*/ +int sqlite3IsOverflow(double x){ + int rc; /* The value return */ + u64 y; + memcpy(&y,&x,sizeof(y)); + rc = IsOvfl(y); + return rc; +} +#endif /* SQLITE_OMIT_FLOATING_POINT */ + /* ** Compute a string length that is limited to what can be stored in ** lower 30 bits of a 32-bit signed integer. diff --git a/test/func.test b/test/func.test index c7b8f72352..fa7be84242 100644 --- a/test/func.test +++ b/test/func.test @@ -1561,4 +1561,25 @@ do_execsql_test func-38.100 { WITH t1(x) AS (VALUES(-9e+999)) SELECT sum(x), avg(x), total(x) FROM t1; } {Inf Inf Inf -Inf -Inf -Inf} +# 2024-03-21 https://sqlite.org/forum/forumpost/23b8688ef4 +# Another problem with Kahan-Babushka-Neumaier summation and +# infinities. +# +do_execsql_test func-39.101 { + WITH RECURSIVE c(n) AS (VALUES(1) UNION ALL SELECT n+1 FROM c WHERE n<1) + SELECT quote(sum(1.7976931348623157e308)), + quote(avg(1.7976931348623157e308)), + quote(total(1.7976931348623157e308)) + FROM c; +} {1.797693134862315708e+308 1.797693134862315708e+308 1.797693134862315708e+308} +for {set i 2} {$i<10} {incr i} { + do_execsql_test func-39.[expr {10*$i+100}] { + WITH RECURSIVE c(n) AS (VALUES(1) UNION ALL SELECT n+1 FROM c WHERE n<$i) + SELECT quote(sum(1.7976931348623157e308)), + quote(avg(1.7976931348623157e308)), + quote(total(1.7976931348623157e308)) + FROM c; + } {9.0e+999 9.0e+999 9.0e+999} +} + finish_test From 1fe31dcfabf886517e41cbab3b8435e0e828b44f Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 19 Mar 2024 10:41:18 +0000 Subject: [PATCH 251/430] Adjustments to the test cases for the previous check-in to make them cross-platform Linux/Mac/Windows. Test chance only. No change to core code. FossilOrigin-Name: 0dddadbd5b217a48bb5c1b0568a03fbafb89dba98c577727bf4f79ff7e0ca849 --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/func.test | 16 ++++++++-------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/manifest b/manifest index d421c59182..26d692be1b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sanother\sproblem\sfrom\s[c63e26e705f5e967]\sinvolving\sinfinities\sand\sthe\nKahan-Babushka-Neumaier\ssummation\salgorithm.\s\sProblem\sreported\sby\n[forum:/forumpost/23b8688ef4|forum\spost\s23b8688ef4]. -D 2024-03-19T10:16:17.413 +C Adjustments\sto\sthe\stest\scases\sfor\sthe\sprevious\scheck-in\sto\smake\sthem\ncross-platform\sLinux/Mac/Windows.\s\sTest\schance\sonly.\s\sNo\schange\sto\score\scode. +D 2024-03-19T10:41:18.138 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -1229,7 +1229,7 @@ F test/fts4umlaut.test fcaca4471de7e78c9d1f7e8976e3e8704d7d8ad979d57a739d00f3f75 F test/fts4unicode.test 82a9c16b68ba2f358a856226bb2ee02f81583797bc4744061c54401bf1a0f4c9 F test/fts4upfrom.test f25835162c989dffd5e2ef91ec24c4848cc9973093e2d492d1c7b32afac1b49d F test/full.test 6b3c8fb43c6beab6b95438c1675374b95fab245d -F test/func.test 648ca90b9c36e9eefd8005d64cd8ad2d2dba73891df0fbe157b866d1cc95bdc8 +F test/func.test b56905748ce0567c01d60005f3e6ad1af19453d224ba4730ee687d048fd09ef9 F test/func2.test 772d66227e4e6684b86053302e2d74a2500e1e0f F test/func3.test 600a632c305a88f3946d38f9a51efe145c989b2e13bd2b2a488db47fe76bab6a F test/func4.test a3f9062487dbd826776f54f4e0e9517fe8c3cf689af92735308965774d51fac5 @@ -2180,8 +2180,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P ad2ae7717e7a10cf42aeabd3c544e7884fa082295c2babf0fdb19a684d2aba1e -R 6728c90829563f9564b3fe7ee7e264f2 +P 45d272ef38d5ee6189f81369aefb8e3ac35868a67687012d93c84f2bbc42520a +R 06f52063180a10fd2f7e8878024a8e93 U drh -Z 8f46ba2909e90f1ebfbdf6c7d1fcfdc3 +Z be89e098a4549a3844da98de72222ae6 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index aafcf89491..46aef1d450 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -45d272ef38d5ee6189f81369aefb8e3ac35868a67687012d93c84f2bbc42520a \ No newline at end of file +0dddadbd5b217a48bb5c1b0568a03fbafb89dba98c577727bf4f79ff7e0ca849 \ No newline at end of file diff --git a/test/func.test b/test/func.test index fa7be84242..a3ecd4e30b 100644 --- a/test/func.test +++ b/test/func.test @@ -1567,19 +1567,19 @@ do_execsql_test func-38.100 { # do_execsql_test func-39.101 { WITH RECURSIVE c(n) AS (VALUES(1) UNION ALL SELECT n+1 FROM c WHERE n<1) - SELECT quote(sum(1.7976931348623157e308)), - quote(avg(1.7976931348623157e308)), - quote(total(1.7976931348623157e308)) + SELECT sum(1.7976931348623157e308), + avg(1.7976931348623157e308), + total(1.7976931348623157e308) FROM c; -} {1.797693134862315708e+308 1.797693134862315708e+308 1.797693134862315708e+308} +} {1.79769313486232e+308 1.79769313486232e+308 1.79769313486232e+308} for {set i 2} {$i<10} {incr i} { do_execsql_test func-39.[expr {10*$i+100}] { WITH RECURSIVE c(n) AS (VALUES(1) UNION ALL SELECT n+1 FROM c WHERE n<$i) - SELECT quote(sum(1.7976931348623157e308)), - quote(avg(1.7976931348623157e308)), - quote(total(1.7976931348623157e308)) + SELECT sum(1.7976931348623157e308), + avg(1.7976931348623157e308), + total(1.7976931348623157e308) FROM c; - } {9.0e+999 9.0e+999 9.0e+999} + } {Inf Inf Inf} } finish_test From 4b42b5259f151aad0ece49b7132a6bc2e40b262f Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 19 Mar 2024 13:31:54 +0000 Subject: [PATCH 252/430] When compiled with SQLITE_ALLOW_ROWID_IN_VIEW, rowid-in-view is on by default but can now be turned off using SQLITE_TESTCTRL_ROWID_IN_VIEW. Without the compile-time option, rowid-in-view is always off. FossilOrigin-Name: 8a6196ab29052071be753c5c77ac945c2d62ecc8019c6160f954eafe34ab05a8 --- manifest | 27 ++++++++++++--------------- manifest.uuid | 2 +- src/build.c | 9 ++++++--- src/global.c | 3 +++ src/main.c | 33 +++++++++++++++++++++++++++++++++ src/select.c | 22 ++++++++++------------ src/shell.c.in | 15 +++++++++++++++ src/sqlite.h.in | 1 + src/sqliteInt.h | 14 ++++++++++++++ 9 files changed, 95 insertions(+), 31 deletions(-) diff --git a/manifest b/manifest index a8b9d2e2ff..051742cb39 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C First\ssteps\stoward\sgetting\s-DSQLITE_ALLOW_ROWID_IN_VIEW\sto\swork\sagain.\s\sThat\ncompile-time\soption\sis\suntested,\sundocumented,\sand\sunsupported.\s\sBut\sit\swas\nmentioned\sin\sthe\srelease\snotes\sfor\sversion\s3.36.0,\sso\sI\sthink\sthat\smeans\swe\nneed\sto\ssupport\sit\sforever. -D 2024-03-19T02:30:24.246 +C When\scompiled\swith\sSQLITE_ALLOW_ROWID_IN_VIEW,\srowid-in-view\sis\son\sby\sdefault\nbut\scan\snow\sbe\sturned\soff\susing\sSQLITE_TESTCTRL_ROWID_IN_VIEW.\s\sWithout\sthe\ncompile-time\soption,\srowid-in-view\sis\salways\soff. +D 2024-03-19T13:31:54.376 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -692,7 +692,7 @@ F src/btmutex.c 79a43670447eacc651519a429f6ece9fd638563cf95b469d6891185ddae2b522 F src/btree.c 285b493d843e7ba8ef78b6ae7d31238e904901dbc0c484f7904de4cf18fd8802 F src/btree.h 55066f513eb095db935169dab1dc2f7c7a747ef223c533f5d4ad4dfed346cbd0 F src/btreeInt.h 98aadb6dcb77b012cab2574d6a728fad56b337fc946839b9898c4b4c969e30b6 -F src/build.c 04f1bcee189f045ab086d84fee95db42cb49df82ff8e84af8136309ff3c8a75f +F src/build.c 18b4caf7f4eabf4c46727f476b669505aa67cfd3c3587b0fb82f5b8b69acc0e0 F src/callback.c db3a45e376deff6a16c0058163fe0ae2b73a2945f3f408ca32cf74960b28d490 F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e F src/ctime.c 23331529e654be40ca97d171cbbffe9b3d4c71cc53b78fe5501230675952da8b @@ -704,7 +704,7 @@ F src/expr.c d7cfe9b9fe7ab47b254706589467d2e65fec3536b936d6f4eb28b84da6726ecc F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c a47610f0a5c6cb0ad79f8fcef039c01833dec0c751bb695f28dc0ec6a4c3ba00 F src/func.c 4204c56196847faefef57fa14e43b8e4d65eb8d7e65318abe463472e3fd148cb -F src/global.c 765a0656d6cbf043cb272ff0ae38f39cc46713539ffe6793258ed3eb4b188b52 +F src/global.c 61a419dd9e993b9be0f91de4c4ccf322b053eb829868e089f0321dd669be3b90 F src/hash.c 9ee4269fb1d6632a6fecfb9479c93a1f29271bddbbaf215dd60420bcb80c7220 F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6 @@ -713,7 +713,7 @@ F src/insert.c 06ce505713e86172612f9e01febefd2d3331d1f70461b4ada0eae5a76bb6349f F src/json.c e2e40760d6689134c3e2ece38c6a496b34ff5e2661a8f238444a119af666fdce F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 -F src/main.c 438b95162acfa17b7d218f586f5bde11d6ae82bcf030c9611fc537556870ad6b +F src/main.c e7e6e9356ba86713051199968e22ac2c64b1078f266518ca5791dab5fc1af237 F src/malloc.c 410e570b30c26cc36e3372577df50f7a96ee3eed5b2b161c6b6b48773c650c5e F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c 3bb59158c38e05f6270e761a9f435bf19827a264c13d1631c58b84bdc96d73b2 @@ -750,12 +750,12 @@ F src/printf.c 87b67bba3662a0523f39ae6b084a3907109702f717c654d6cecb838af5cd57f1 F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c ef87e3bc7700bfe761a7bbee2ce6084f1766dc816dd82a3ae77c133eec898432 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 -F src/select.c 934eb6e543133cb373ab76f791ded2b2b5c13ac50684453494c4b6c4ea4fba24 -F src/shell.c.in cf80c636bccb0ff9db46995e39d69ca21fde2a8a331d1691e4d62a69d7841c8a -F src/sqlite.h.in 19a2db3995a699bd7f6dfb423856242bfceb7ec849a93c91d241d19fc28d9f0f +F src/select.c 6d6301429c1de03d14ccdad371c36464747e4b0245e4a3a48c8e264ccc5f69df +F src/shell.c.in 21d998d82e169acd7905263674afdf4eff690125fcc8bf7766bcc9f463cd1b13 +F src/sqlite.h.in 09d55c3707ee5e3e041301fc558de6fc124bd4af6135ea1288d9c30dc43a7fd9 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 -F src/sqliteInt.h a58b4a33a9807667503a053721a4cd736cda8b60daae896a1b04f120a64c9fd2 +F src/sqliteInt.h b97455359ea9410d2568d54d752e8e67d1d47fc8968b3d0c8c34ef7cc70d88b7 F src/sqliteLimit.h 6878ab64bdeb8c24a1d762d45635e34b96da21132179023338c93f820eee6728 F src/status.c cb11f8589a6912af2da3bb1ec509a94dd8ef27df4d4c1a97e0bcf2309ece972b F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1 @@ -2180,11 +2180,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P ad2ae7717e7a10cf42aeabd3c544e7884fa082295c2babf0fdb19a684d2aba1e -R cc156187f695f7801f18b2af21acf477 -T *branch * rowid-in-view -T *sym-rowid-in-view * -T -sym-trunk * +P 7c46ff640247584f1ea260c062de29a0e49f649d1894a526574c1a479006a1fc +R e5e0882c9142c10ac12b6ecaf695934e U drh -Z d1168aa5ebee2530ad432f8f9a6ecbd1 +Z 8e31fdf538ff0513b533fb4971fc8443 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 3c83ab3dfc..24809892dc 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7c46ff640247584f1ea260c062de29a0e49f649d1894a526574c1a479006a1fc \ No newline at end of file +8a6196ab29052071be753c5c77ac945c2d62ecc8019c6160f954eafe34ab05a8 \ No newline at end of file diff --git a/src/build.c b/src/build.c index 15f8fe1d24..1bc6008ecd 100644 --- a/src/build.c +++ b/src/build.c @@ -3006,9 +3006,12 @@ void sqlite3CreateView( ** on a view, even though views do not have rowids. The following flag ** setting fixes this problem. But the fix can be disabled by compiling ** with -DSQLITE_ALLOW_ROWID_IN_VIEW in case there are legacy apps that - ** depend upon the old buggy behavior. */ -#ifndef SQLITE_ALLOW_ROWID_IN_VIEW - p->tabFlags |= TF_NoVisibleRowid; + ** depend upon the old buggy behavior. The ability can also be toggled + ** using SQLITE_TESTCTRL_ROWID_IN_VIEW */ +#ifdef SQLITE_ALLOW_ROWID_IN_VIEW + p->tabFlags |= sqlite3Config.mNoVisibleRowid; /* Optional. Allow by default */ +#else + p->tabFlags |= TF_NoVisibleRowid; /* Never allow rowid in view */ #endif sqlite3TwoPartName(pParse, pName1, pName2, &pName); diff --git a/src/global.c b/src/global.c index 7f27d91d15..121b3f6d6b 100644 --- a/src/global.c +++ b/src/global.c @@ -288,6 +288,9 @@ SQLITE_WSD struct Sqlite3Config sqlite3Config = { #endif #ifndef SQLITE_UNTESTABLE 0, /* xTestCallback */ +#endif +#ifdef SQLITE_ALLOW_ROWID_IN_VIEW + 0, /* mNoVisibleRowid. 0 == allow rowid-in-view */ #endif 0, /* bLocaltimeFault */ 0, /* xAltLocaltime */ diff --git a/src/main.c b/src/main.c index 03429983d6..67191fb0fe 100644 --- a/src/main.c +++ b/src/main.c @@ -4405,6 +4405,39 @@ int sqlite3_test_control(int op, ...){ break; } + /* sqlite3_test_control(SQLITE_TESTCTRL_ROWID_IN_VIEW, int *pVal); + ** + ** Query or set the sqlite3Config.mNoVisibleRowid flag. Cases: + ** + ** *pVal==1 Allow ROWID in VIEWs + ** *pVal==0 Disallow ROWID in VIEWs + ** *pVal<0 No change + ** + ** In every case *pVal is written with 1 if ROWID is allowd in VIEWs and + ** 0 if not. Changes to the setting only occur if SQLite is compiled + ** with -DSQLITE_ALLOW_ROWID_IN_VIEW (hereafter: "SARIV"). With the + ** "SARIV" compile-time option the default value for this setting is 1. + ** Otherwise this setting defaults to 0. This setting may only be changed + ** if SQLite is compiled with "SARIV". Hence, in the normal case when + ** SQLite is compiled without "SARIV", this test-control is a no-op + ** that always leaves *pVal set to 0. + ** + ** IMPORTANT: If you change this setting while a database connection + ** is option, it is very important to run "PRAGMA writable_schema=RESET" + ** afterwards in order to reparse all VIEW definitions in the schema. + */ + case SQLITE_TESTCTRL_ROWID_IN_VIEW: { + int *pVal = va_arg(ap, int*); +#ifdef SQLITE_ALLOW_ROWID_IN_VIEW + if( *pVal==0 ) sqlite3Config.mNoVisibleRowid = TF_NoVisibleRowid; + if( *pVal==1 ) sqlite3Config.mNoVisibleRowid = 0; + *pVal = (sqlite3Config.mNoVisibleRowid==0); +#else + *pVal = 0; +#endif + break; + } + /* sqlite3_test_control(SQLITE_TESTCTRL_INTERNAL_FUNCTIONS, sqlite3*); ** ** Toggle the ability to use internal functions on or off for diff --git a/src/select.c b/src/select.c index 5dfabb140d..7f8a0f892e 100644 --- a/src/select.c +++ b/src/select.c @@ -1953,11 +1953,7 @@ static const char *columnTypeImpl( ** data for the result-set column of the sub-select. */ if( iColpEList->nExpr -#ifdef SQLITE_ALLOW_ROWID_IN_VIEW - && iCol>=0 -#else - && ALWAYS(iCol>=0) -#endif + && (!ViewCanHaveRowid || iCol>=0) ){ /* If iCol is less than zero, then the expression requests the ** rowid of the sub-select or view. This expression is legal (see @@ -5874,7 +5870,8 @@ int sqlite3ExpandSubquery(Parse *pParse, SrcItem *pFrom){ /* The usual case - do not allow ROWID on a subquery */ pTab->tabFlags |= TF_Ephemeral | TF_NoVisibleRowid; #else - pTab->tabFlags |= TF_Ephemeral; /* Legacy compatibility mode */ + /* Legacy compatibility mode */ + pTab->tabFlags |= TF_Ephemeral | sqlite3Config.mNoVisibleRowid; #endif return pParse->nErr ? SQLITE_ERROR : SQLITE_OK; } @@ -6142,9 +6139,7 @@ static int selectExpander(Walker *pWalker, Select *p){ pNestedFrom = pFrom->pSelect->pEList; assert( pNestedFrom!=0 ); assert( pNestedFrom->nExpr==pTab->nCol ); -#ifndef SQLITE_ALLOW_ROWID_IN_VIEW - assert( VisibleRowid(pTab)==0 ); -#endif + assert( VisibleRowid(pTab)==0 || ViewCanHaveRowid ); }else{ if( zTName && sqlite3StrICmp(zTName, zTabName)!=0 ){ continue; @@ -6177,9 +6172,12 @@ static int selectExpander(Walker *pWalker, Select *p){ } nAdd = pTab->nCol; -#ifndef SQLITE_ALLOW_ROWID_IN_VIEW - if( VisibleRowid(pTab) && (selFlags & SF_NestedFrom)!=0 ) nAdd++; -#endif + if( VisibleRowid(pTab) + && !ViewCanHaveRowid + && (selFlags & SF_NestedFrom)!=0 + ){ + nAdd++; + } for(j=0; j=3 ){ + if( !ShellHasFlag(p,SHFLG_TestingMode) ){ + eputz("The --unsafe-testing option is required to change " + "this setting\n"); + }else{ + rc2 = booleanValue(azArg[2]); + } + } + sqlite3_test_control(testctrl, &rc2); + isOk = 1; + break; + } #ifdef SQLITE_DEBUG case SQLITE_TESTCTRL_TUNE: { if( nArg==4 ){ diff --git a/src/sqlite.h.in b/src/sqlite.h.in index e05d7b231a..17a231860a 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -8307,6 +8307,7 @@ int sqlite3_test_control(int op, ...); #define SQLITE_TESTCTRL_JSON_SELFCHECK 14 #define SQLITE_TESTCTRL_OPTIMIZATIONS 15 #define SQLITE_TESTCTRL_ISKEYWORD 16 /* NOT USED */ +#define SQLITE_TESTCTRL_ROWID_IN_VIEW 16 #define SQLITE_TESTCTRL_SCRATCHMALLOC 17 /* NOT USED */ #define SQLITE_TESTCTRL_INTERNAL_FUNCTIONS 17 #define SQLITE_TESTCTRL_LOCALTIME_FAULT 18 diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 8d18bfdfbb..9fdc721e40 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -2535,6 +2535,15 @@ struct Table { #define HasRowid(X) (((X)->tabFlags & TF_WithoutRowid)==0) #define VisibleRowid(X) (((X)->tabFlags & TF_NoVisibleRowid)==0) +/* Macro is true if the SQLITE_ALLOW_ROWID_IN_VIEW (mis-)feature is +** available. By default, this macro is false +*/ +#ifndef SQLITE_ALLOW_ROWID_IN_VIEW +# define ViewCanHaveRowid 0 +#else +# define ViewCanHaveRowid (sqlite3Config.mNoVisibleRowid==0) +#endif + /* ** Each foreign key constraint is an instance of the following structure. ** @@ -4253,6 +4262,11 @@ struct Sqlite3Config { #endif #ifndef SQLITE_UNTESTABLE int (*xTestCallback)(int); /* Invoked by sqlite3FaultSim() */ +#endif +#ifdef SQLITE_ALLOW_ROWID_IN_VIEW + u32 mNoVisibleRowid; /* TF_NoVisibleRowid if the ROWID_IN_VIEW + ** feature is disabled. 0 if rowids can + ** occur in views. */ #endif int bLocaltimeFault; /* True to fail localtime() calls */ int (*xAltLocaltime)(const void*,void*); /* Alternative localtime() routine */ From 261c6dfe7b32b8a66b91026ac134afb91aada452 Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 19 Mar 2024 13:55:10 +0000 Subject: [PATCH 253/430] On second thought, change SQLITE_TESTCTRL_ROWID_IN_VIEW into a start-time option SQLITE_CONFIG_NO_ROWID_IN_VIEW. FossilOrigin-Name: b8e045c9e1d098d116f8745704b10ed76569d4b063c0b81cce16bc136930755d --- manifest | 18 +++++++++--------- manifest.uuid | 2 +- src/build.c | 2 +- src/main.c | 40 +++++++--------------------------------- src/shell.c.in | 19 ++++--------------- src/sqlite.h.in | 12 +++++++++++- 6 files changed, 33 insertions(+), 60 deletions(-) diff --git a/manifest b/manifest index 051742cb39..eec7c4d0c1 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C When\scompiled\swith\sSQLITE_ALLOW_ROWID_IN_VIEW,\srowid-in-view\sis\son\sby\sdefault\nbut\scan\snow\sbe\sturned\soff\susing\sSQLITE_TESTCTRL_ROWID_IN_VIEW.\s\sWithout\sthe\ncompile-time\soption,\srowid-in-view\sis\salways\soff. -D 2024-03-19T13:31:54.376 +C On\ssecond\sthought,\schange\sSQLITE_TESTCTRL_ROWID_IN_VIEW\sinto\sa\sstart-time\noption\sSQLITE_CONFIG_NO_ROWID_IN_VIEW. +D 2024-03-19T13:55:10.156 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -692,7 +692,7 @@ F src/btmutex.c 79a43670447eacc651519a429f6ece9fd638563cf95b469d6891185ddae2b522 F src/btree.c 285b493d843e7ba8ef78b6ae7d31238e904901dbc0c484f7904de4cf18fd8802 F src/btree.h 55066f513eb095db935169dab1dc2f7c7a747ef223c533f5d4ad4dfed346cbd0 F src/btreeInt.h 98aadb6dcb77b012cab2574d6a728fad56b337fc946839b9898c4b4c969e30b6 -F src/build.c 18b4caf7f4eabf4c46727f476b669505aa67cfd3c3587b0fb82f5b8b69acc0e0 +F src/build.c 71445e2d1e2c78b120a20a46d80a29a9ea42370df430efda5bb6ef377e8016c8 F src/callback.c db3a45e376deff6a16c0058163fe0ae2b73a2945f3f408ca32cf74960b28d490 F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e F src/ctime.c 23331529e654be40ca97d171cbbffe9b3d4c71cc53b78fe5501230675952da8b @@ -713,7 +713,7 @@ F src/insert.c 06ce505713e86172612f9e01febefd2d3331d1f70461b4ada0eae5a76bb6349f F src/json.c e2e40760d6689134c3e2ece38c6a496b34ff5e2661a8f238444a119af666fdce F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 -F src/main.c e7e6e9356ba86713051199968e22ac2c64b1078f266518ca5791dab5fc1af237 +F src/main.c 3db8bc4c8e0515b9e23bed3167de8b626a55e9eb1f65fe42b878d820cfa90628 F src/malloc.c 410e570b30c26cc36e3372577df50f7a96ee3eed5b2b161c6b6b48773c650c5e F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c 3bb59158c38e05f6270e761a9f435bf19827a264c13d1631c58b84bdc96d73b2 @@ -751,8 +751,8 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c ef87e3bc7700bfe761a7bbee2ce6084f1766dc816dd82a3ae77c133eec898432 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c 6d6301429c1de03d14ccdad371c36464747e4b0245e4a3a48c8e264ccc5f69df -F src/shell.c.in 21d998d82e169acd7905263674afdf4eff690125fcc8bf7766bcc9f463cd1b13 -F src/sqlite.h.in 09d55c3707ee5e3e041301fc558de6fc124bd4af6135ea1288d9c30dc43a7fd9 +F src/shell.c.in a2ccceb9a250613f8156b098736bd94424c422972a1c1ddda35604531ae1762e +F src/sqlite.h.in e9d785f9d17f2caa366641d6616748310c8092cc0746f064c8cf5bcc767bcab0 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 F src/sqliteInt.h b97455359ea9410d2568d54d752e8e67d1d47fc8968b3d0c8c34ef7cc70d88b7 @@ -2180,8 +2180,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 7c46ff640247584f1ea260c062de29a0e49f649d1894a526574c1a479006a1fc -R e5e0882c9142c10ac12b6ecaf695934e +P 8a6196ab29052071be753c5c77ac945c2d62ecc8019c6160f954eafe34ab05a8 +R d89345c69403f3ed5d805ef59957407f U drh -Z 8e31fdf538ff0513b533fb4971fc8443 +Z a176e962a21e6476d0fc3787bbf8685d # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 24809892dc..578f79ca78 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8a6196ab29052071be753c5c77ac945c2d62ecc8019c6160f954eafe34ab05a8 \ No newline at end of file +b8e045c9e1d098d116f8745704b10ed76569d4b063c0b81cce16bc136930755d \ No newline at end of file diff --git a/src/build.c b/src/build.c index 1bc6008ecd..e7c23c173a 100644 --- a/src/build.c +++ b/src/build.c @@ -3007,7 +3007,7 @@ void sqlite3CreateView( ** setting fixes this problem. But the fix can be disabled by compiling ** with -DSQLITE_ALLOW_ROWID_IN_VIEW in case there are legacy apps that ** depend upon the old buggy behavior. The ability can also be toggled - ** using SQLITE_TESTCTRL_ROWID_IN_VIEW */ + ** using SQLITE_CONFIG_NO_ROWID_IN_VIEW */ #ifdef SQLITE_ALLOW_ROWID_IN_VIEW p->tabFlags |= sqlite3Config.mNoVisibleRowid; /* Optional. Allow by default */ #else diff --git a/src/main.c b/src/main.c index 67191fb0fe..6c8ae5b281 100644 --- a/src/main.c +++ b/src/main.c @@ -765,6 +765,13 @@ int sqlite3_config(int op, ...){ } #endif /* SQLITE_OMIT_DESERIALIZE */ + case SQLITE_CONFIG_NO_ROWID_IN_VIEW: { +#ifdef SQLITE_ALLOW_ROWID_IN_VIEW + sqlite3GlobalConfig.mNoVisibleRowid = TF_NoVisibleRowid; +#endif + break; + } + default: { rc = SQLITE_ERROR; break; @@ -4405,39 +4412,6 @@ int sqlite3_test_control(int op, ...){ break; } - /* sqlite3_test_control(SQLITE_TESTCTRL_ROWID_IN_VIEW, int *pVal); - ** - ** Query or set the sqlite3Config.mNoVisibleRowid flag. Cases: - ** - ** *pVal==1 Allow ROWID in VIEWs - ** *pVal==0 Disallow ROWID in VIEWs - ** *pVal<0 No change - ** - ** In every case *pVal is written with 1 if ROWID is allowd in VIEWs and - ** 0 if not. Changes to the setting only occur if SQLite is compiled - ** with -DSQLITE_ALLOW_ROWID_IN_VIEW (hereafter: "SARIV"). With the - ** "SARIV" compile-time option the default value for this setting is 1. - ** Otherwise this setting defaults to 0. This setting may only be changed - ** if SQLite is compiled with "SARIV". Hence, in the normal case when - ** SQLite is compiled without "SARIV", this test-control is a no-op - ** that always leaves *pVal set to 0. - ** - ** IMPORTANT: If you change this setting while a database connection - ** is option, it is very important to run "PRAGMA writable_schema=RESET" - ** afterwards in order to reparse all VIEW definitions in the schema. - */ - case SQLITE_TESTCTRL_ROWID_IN_VIEW: { - int *pVal = va_arg(ap, int*); -#ifdef SQLITE_ALLOW_ROWID_IN_VIEW - if( *pVal==0 ) sqlite3Config.mNoVisibleRowid = TF_NoVisibleRowid; - if( *pVal==1 ) sqlite3Config.mNoVisibleRowid = 0; - *pVal = (sqlite3Config.mNoVisibleRowid==0); -#else - *pVal = 0; -#endif - break; - } - /* sqlite3_test_control(SQLITE_TESTCTRL_INTERNAL_FUNCTIONS, sqlite3*); ** ** Toggle the ability to use internal functions on or off for diff --git a/src/shell.c.in b/src/shell.c.in index fbec5a8c9a..51769a67d7 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -10893,7 +10893,6 @@ static int do_meta_command(char *zLine, ShellState *p){ {"prng_restore", SQLITE_TESTCTRL_PRNG_RESTORE,0, "" }, {"prng_save", SQLITE_TESTCTRL_PRNG_SAVE, 0, "" }, {"prng_seed", SQLITE_TESTCTRL_PRNG_SEED, 0, "SEED ?db?" }, - {"rowid_in_view", SQLITE_TESTCTRL_ROWID_IN_VIEW,0,"?BOOLEAN?" }, {"seek_count", SQLITE_TESTCTRL_SEEK_COUNT, 0, "" }, {"sorter_mmap", SQLITE_TESTCTRL_SORTER_MMAP, 0, "NMAX" }, {"tune", SQLITE_TESTCTRL_TUNE, 1, "ID VALUE" }, @@ -11068,20 +11067,6 @@ static int do_meta_command(char *zLine, ShellState *p){ break; } #endif - case SQLITE_TESTCTRL_ROWID_IN_VIEW: { - rc2 = -1; - if( nArg>=3 ){ - if( !ShellHasFlag(p,SHFLG_TestingMode) ){ - eputz("The --unsafe-testing option is required to change " - "this setting\n"); - }else{ - rc2 = booleanValue(azArg[2]); - } - } - sqlite3_test_control(testctrl, &rc2); - isOk = 1; - break; - } #ifdef SQLITE_DEBUG case SQLITE_TESTCTRL_TUNE: { if( nArg==4 ){ @@ -12363,6 +12348,8 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){ stdin_is_interactive = 0; }else if( cli_strcmp(z,"-utf8")==0 ){ }else if( cli_strcmp(z,"-no-utf8")==0 ){ + }else if( cli_strcmp(z,"-no-rowid-in-view")==0 ){ + sqlite3_config(SQLITE_CONFIG_NO_ROWID_IN_VIEW); }else if( cli_strcmp(z,"-heap")==0 ){ #if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5) const char *zSize; @@ -12638,6 +12625,8 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){ /* already handled */ }else if( cli_strcmp(z,"-no-utf8")==0 ){ /* already handled */ + }else if( cli_strcmp(z,"-no-rowid-in-view")==0 ){ + /* already handled */ }else if( cli_strcmp(z,"-heap")==0 ){ i++; }else if( cli_strcmp(z,"-pagecache")==0 ){ diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 17a231860a..9c9a78c453 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -2143,6 +2143,16 @@ struct sqlite3_mem_methods { ** configuration setting is never used, then the default maximum is determined ** by the [SQLITE_MEMDB_DEFAULT_MAXSIZE] compile-time option. If that ** compile-time option is not set, then the default maximum is 1073741824. +** +** [[SQLITE_CONFIG_NO_ROWID_IN_VIEW]] +**
    SQLITE_CONFIG_NO_ROWID_IN_VIEW +**
    The SQLITE_CONFIG_NO_ROWID_IN_VIEW option prohibits VIEWs from having +** a ROWID. This is the default behavior and so test sqlite_config() option +** is normally a no-op. However, if SQLite is compiled with the +** -DSQLITE_ALLOW_ROWID_IN_VIEW option (not recommended!) then this configuration +** option will disable that capability and make SQLite operate as it normally +** would given default the default compile-time options. Once ROWIDs in VIEWs +** have been disabled using this option, they cannot be reenabled. ** */ #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ @@ -2174,6 +2184,7 @@ struct sqlite3_mem_methods { #define SQLITE_CONFIG_SMALL_MALLOC 27 /* boolean */ #define SQLITE_CONFIG_SORTERREF_SIZE 28 /* int nByte */ #define SQLITE_CONFIG_MEMDB_MAXSIZE 29 /* sqlite3_int64 */ +#define SQLITE_CONFIG_NO_ROWID_IN_VIEW 30 /* nil */ /* ** CAPI3REF: Database Connection Configuration Options @@ -8307,7 +8318,6 @@ int sqlite3_test_control(int op, ...); #define SQLITE_TESTCTRL_JSON_SELFCHECK 14 #define SQLITE_TESTCTRL_OPTIMIZATIONS 15 #define SQLITE_TESTCTRL_ISKEYWORD 16 /* NOT USED */ -#define SQLITE_TESTCTRL_ROWID_IN_VIEW 16 #define SQLITE_TESTCTRL_SCRATCHMALLOC 17 /* NOT USED */ #define SQLITE_TESTCTRL_INTERNAL_FUNCTIONS 17 #define SQLITE_TESTCTRL_LOCALTIME_FAULT 18 From d75bdf51c7623d70bba6e3e330e59d59a4f7b6dd Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 19 Mar 2024 14:21:26 +0000 Subject: [PATCH 254/430] Improvements to the first check-in on this branch, causing less collateral damage. FossilOrigin-Name: 7bc882897b6910f93695ad372445df7791b096412089ccbcd4fde365c62fa074 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/select.c | 9 ++------- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/manifest b/manifest index eec7c4d0c1..e338d56c6e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C On\ssecond\sthought,\schange\sSQLITE_TESTCTRL_ROWID_IN_VIEW\sinto\sa\sstart-time\noption\sSQLITE_CONFIG_NO_ROWID_IN_VIEW. -D 2024-03-19T13:55:10.156 +C Improvements\sto\sthe\sfirst\scheck-in\son\sthis\sbranch,\scausing\sless\scollateral\ndamage. +D 2024-03-19T14:21:26.201 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -750,7 +750,7 @@ F src/printf.c 87b67bba3662a0523f39ae6b084a3907109702f717c654d6cecb838af5cd57f1 F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c ef87e3bc7700bfe761a7bbee2ce6084f1766dc816dd82a3ae77c133eec898432 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 -F src/select.c 6d6301429c1de03d14ccdad371c36464747e4b0245e4a3a48c8e264ccc5f69df +F src/select.c ac3689a3f54f81e8b710ce772c5c49c13a152e4ac484c2429ad5264243e7de66 F src/shell.c.in a2ccceb9a250613f8156b098736bd94424c422972a1c1ddda35604531ae1762e F src/sqlite.h.in e9d785f9d17f2caa366641d6616748310c8092cc0746f064c8cf5bcc767bcab0 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 @@ -2180,8 +2180,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 8a6196ab29052071be753c5c77ac945c2d62ecc8019c6160f954eafe34ab05a8 -R d89345c69403f3ed5d805ef59957407f +P b8e045c9e1d098d116f8745704b10ed76569d4b063c0b81cce16bc136930755d +R 9d63476358fa70a434b2b00bc72db1e7 U drh -Z a176e962a21e6476d0fc3787bbf8685d +Z f699d32733c11fd3a8c679549f29c036 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 578f79ca78..add372b711 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b8e045c9e1d098d116f8745704b10ed76569d4b063c0b81cce16bc136930755d \ No newline at end of file +7bc882897b6910f93695ad372445df7791b096412089ccbcd4fde365c62fa074 \ No newline at end of file diff --git a/src/select.c b/src/select.c index 7f8a0f892e..f71b715517 100644 --- a/src/select.c +++ b/src/select.c @@ -6172,12 +6172,7 @@ static int selectExpander(Walker *pWalker, Select *p){ } nAdd = pTab->nCol; - if( VisibleRowid(pTab) - && !ViewCanHaveRowid - && (selFlags & SF_NestedFrom)!=0 - ){ - nAdd++; - } + if( VisibleRowid(pTab) && (selFlags & SF_NestedFrom)!=0 ) nAdd++; for(j=0; ja[pNew->nExpr-1]; assert( pX->zEName==0 ); if( (selFlags & SF_NestedFrom)!=0 && !IN_RENAME_OBJECT ){ - if( pNestedFrom ){ + if( pNestedFrom && jnExpr ){ pX->zEName = sqlite3DbStrDup(db, pNestedFrom->a[j].zEName); testcase( pX->zEName==0 ); }else{ From 967c3032124b1365c65946371809660404376169 Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 19 Mar 2024 14:38:39 +0000 Subject: [PATCH 255/430] Fix the fuzzinvariants.c test module so that it does not generate invariants that depend on rowid when SQLITE_ALLOW_ROWID_IN_VIEW is used, since rowid values can be unreliable in that context. FossilOrigin-Name: 0d711aaaa14472a82f8893e1b07d845073f3d018bd5b8093ec0b00ffbbc8cd5a --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/fuzzinvariants.c | 8 ++++++++ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index e338d56c6e..1bd5d0bc66 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improvements\sto\sthe\sfirst\scheck-in\son\sthis\sbranch,\scausing\sless\scollateral\ndamage. -D 2024-03-19T14:21:26.201 +C Fix\sthe\sfuzzinvariants.c\stest\smodule\sso\sthat\sit\sdoes\snot\sgenerate\ninvariants\sthat\sdepend\son\srowid\swhen\sSQLITE_ALLOW_ROWID_IN_VIEW\sis\sused,\nsince\srowid\svalues\scan\sbe\sunreliable\sin\sthat\scontext. +D 2024-03-19T14:38:39.687 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -1257,7 +1257,7 @@ F test/fuzzdata8.db 4a53b6d077c6a5c23b609d8d3ac66996fa55ba3f8d02f9b6efdd0214a767 F test/fuzzer1.test 3d4c4b7e547aba5e5511a2991e3e3d07166cfbb8 F test/fuzzer2.test a85ef814ce071293bce1ad8dffa217cbbaad4c14 F test/fuzzerfault.test f64c4aef4c9e9edf1d6dc0d3f1e65dcc81e67c996403c88d14f09b74807a42bc -F test/fuzzinvariants.c b34530e8431f2cf3591eff588fc7684d6fdef466916fb46141c8c5374a3d8099 +F test/fuzzinvariants.c 4355043e98cd8555c62462fcbba91c17c6492b0b017bbbe68656d5f2208f6444 F test/gcfault.test 4ea410ac161e685f17b19e1f606f58514a2850e806c65b846d05f60d436c5b0d F test/gencol1.test e169bdfa11c7ed5e9f322a98a7db3afe9e66235750b68c923efee8e1876b46ec F test/genesis.tcl 1e2e2e8e5cc4058549a154ff1892fe5c9de19f98 @@ -2180,8 +2180,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P b8e045c9e1d098d116f8745704b10ed76569d4b063c0b81cce16bc136930755d -R 9d63476358fa70a434b2b00bc72db1e7 +P 7bc882897b6910f93695ad372445df7791b096412089ccbcd4fde365c62fa074 +R 1d0ab0a71fdecadee0025e4c9e79a52a U drh -Z f699d32733c11fd3a8c679549f29c036 +Z ef38e4f5190d6a950df6cf2eac0e14a7 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index add372b711..6d341e4ed1 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7bc882897b6910f93695ad372445df7791b096412089ccbcd4fde365c62fa074 \ No newline at end of file +0d711aaaa14472a82f8893e1b07d845073f3d018bd5b8093ec0b00ffbbc8cd5a \ No newline at end of file diff --git a/test/fuzzinvariants.c b/test/fuzzinvariants.c index 5d473f19f3..00b2c11742 100644 --- a/test/fuzzinvariants.c +++ b/test/fuzzinvariants.c @@ -296,6 +296,14 @@ static char *fuzz_invariant_sql(sqlite3_stmt *pStmt, int iCnt){ ** WHERE clause. */ continue; } +#ifdef SQLITE_ALLOW_ROWID_IN_VIEW + if( sqlite3_strlike("%rowid%",zColName,0)==0 + || sqlite3_strlike("%oid%",zColName,0)==0 + ){ + /* ROWID values are unreliable if SQLITE_ALLOW_ROWID_IN_VIEW is used */ + continue; + } +#endif for(j=0; j Date: Tue, 19 Mar 2024 14:55:49 +0000 Subject: [PATCH 256/430] Return the error "ambiguous column name: rowid", instead of "no such column: rowid", when a "rowid" reference is ambiguous. FossilOrigin-Name: 021f34fcfed41b607be8169bbda59aef93f130108d944f4741b46e8e345b2bbb --- manifest | 23 +++++++++++++---------- manifest.uuid | 2 +- src/resolve.c | 4 ++-- test/joinH.test | 6 +++--- test/rowid.test | 5 +++-- test/unionall.test | 2 +- 6 files changed, 23 insertions(+), 19 deletions(-) diff --git a/manifest b/manifest index 26d692be1b..bf79ca82f1 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Adjustments\sto\sthe\stest\scases\sfor\sthe\sprevious\scheck-in\sto\smake\sthem\ncross-platform\sLinux/Mac/Windows.\s\sTest\schance\sonly.\s\sNo\schange\sto\score\scode. -D 2024-03-19T10:41:18.138 +C Return\sthe\serror\s"ambiguous\scolumn\sname:\srowid",\sinstead\sof\s"no\ssuch\scolumn:\srowid",\swhen\sa\s"rowid"\sreference\sis\sambiguous. +D 2024-03-19T14:55:49.846 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -748,7 +748,7 @@ F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7 F src/prepare.c 371f6115cb69286ebc12c6f2d7511279c2e47d9f54f475d46a554d687a3b312c F src/printf.c 87b67bba3662a0523f39ae6b084a3907109702f717c654d6cecb838af5cd57f1 F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c -F src/resolve.c ef87e3bc7700bfe761a7bbee2ce6084f1766dc816dd82a3ae77c133eec898432 +F src/resolve.c c3d6f422645c1fab9b6c493a39624d0b20af5b62f085484293c47d38114edd4f F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c df2bf515fc36e02e97959a70e82da8a4967d6c85590646a7fda2926a734c81ce F src/shell.c.in cf80c636bccb0ff9db46995e39d69ca21fde2a8a331d1691e4d62a69d7841c8a @@ -1337,7 +1337,7 @@ F test/joinC.test 1f1a602c2127f55f136e2cbd3bf2d26546614bf8cffe5902ec1ac9c07f87f2 F test/joinD.test 2ce62e7353a0702ca5e70008faf319c1d4686aa19fba34275c6d1da0e960be28 F test/joinE.test d5d182f3812771e2c0d97c9dcf5dbe4c41c8e21c82560e59358731c4a3981d6b F test/joinF.test 53dd66158806823ea680dd7543b5406af151b5aafa5cd06a7f3231cd94938127 -F test/joinH.test f69e5b53b7d887914e854b6a131efbed4ea9f5ca52bdab81788bfc3e79299f43 +F test/joinH.test d5054173442fdf98260eeb6bb9751daa733b0ae6842fe50dcbd5469945b86985 F test/journal1.test c7b768041b7f494471531e17abc2f4f5ebf9e5096984f43ed17c4eb80ba34497 F test/journal2.test 9dac6b4ba0ca79c3b21446bbae993a462c2397c4 F test/journal3.test 7c3cf23ffc77db06601c1fcfc9743de8441cb77db9d1aa931863d94f5ffa140e @@ -1535,7 +1535,7 @@ F test/rollbackfault.test 0e646aeab8840c399cfbfa43daab46fd609cf04a F test/round1.test 29c3c9039936ed024d672f003c4d35ee11c14c0acb75c5f7d6188ff16190cfd4 F test/rowallock.test 3f88ec6819489d0b2341c7a7528ae17c053ab7cc F test/rowhash.test 0bc1d31415e4575d10cacf31e1a66b5cc0f8be81 -F test/rowid.test e29025be95baf6b32f0d5edef59a7633028325896a98f1caa8019559ca910350 +F test/rowid.test 9910c999e58d211d182599bc0023bdfa849d02c712163476afd384780936b404 F test/rowvalue.test baf4fa3ec1a8c1c920c3faa5fd25959cb454bbd99ac8960397c34549d9fc4abe F test/rowvalue2.test 060d238b7e5639a7c5630cb5e63e311b44efef2b F test/rowvalue3.test 1347e25ca11c547c5a6ff0cc5626f95aa9740e9275bfaec096029f57cb2130ce @@ -1887,7 +1887,7 @@ F test/types.test bf816ce73c7dfcfe26b700c19f97ef4050d194ff F test/types2.test 1aeb81976841a91eef292723649b5c4fe3bc3cac F test/types3.test c9db8f9e80309edfa4252585cf16bcab7ed31f39eeb904d21e831199a3613fb0 F test/unhex.test b7f1b806207cb77fa31c3e434fe92fba524464e3e9356809bfcc28f15af1a8b7 -F test/unionall.test 5b1c4186a661e4bf762875caf4c61d8fda3dd04a6fa9005187f6ba8900c2913f +F test/unionall.test 04d30726c5056f84f92b3a12bf8d8a1dbbe807d1ddc8af95def09e6ef2dd91e3 F test/unionall2.test 71e8fa08d5699d50dc9f9dc0c9799c2e7a6bb7931a330d369307a4df7f157fa1 F test/unionallfault.test 652bfbb630e6c43135965dc1e8f0a9a791da83aec885d626a632fe1909c56f73 F test/unionvtab.test e1704ab1b4c1bb3ffc9da4681f8e85a0b909fd80b937984fc94b27415ac8e5a4 @@ -2180,8 +2180,11 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 45d272ef38d5ee6189f81369aefb8e3ac35868a67687012d93c84f2bbc42520a -R 06f52063180a10fd2f7e8878024a8e93 -U drh -Z be89e098a4549a3844da98de72222ae6 +P 0dddadbd5b217a48bb5c1b0568a03fbafb89dba98c577727bf4f79ff7e0ca849 +R 9d3e521ec7779aa5763735bc3fc68d12 +T *branch * ambiguous-rowid-error +T *sym-ambiguous-rowid-error * +T -sym-trunk * +U dan +Z 8273ce08b357f09baf92785ce3364245 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 46aef1d450..5279cb0694 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0dddadbd5b217a48bb5c1b0568a03fbafb89dba98c577727bf4f79ff7e0ca849 \ No newline at end of file +021f34fcfed41b607be8169bbda59aef93f130108d944f4741b46e8e345b2bbb \ No newline at end of file diff --git a/src/resolve.c b/src/resolve.c index c2957a870a..2a128199db 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -596,13 +596,13 @@ static int lookupName( ** Perhaps the name is a reference to the ROWID */ if( cnt==0 - && cntTab==1 + && cntTab>=1 && pMatch && (pNC->ncFlags & (NC_IdxExpr|NC_GenCol))==0 && sqlite3IsRowid(zCol) && ALWAYS(VisibleRowid(pMatch->pTab) || pMatch->fg.isNestedFrom) ){ - cnt = 1; + cnt = cntTab; if( pMatch->fg.isNestedFrom==0 ) pExpr->iColumn = -1; pExpr->affExpr = SQLITE_AFF_INTEGER; } diff --git a/test/joinH.test b/test/joinH.test index 3702266804..e3f979409a 100644 --- a/test/joinH.test +++ b/test/joinH.test @@ -201,13 +201,13 @@ do_execsql_test 9.0 { do_catchsql_test 9.1 { SELECT rowid FROM wo1, x1, x2; -} {1 {no such column: rowid}} +} {1 {ambiguous column name: rowid}} do_catchsql_test 9.2 { SELECT rowid FROM wo1, (x1, x2); -} {1 {no such column: rowid}} +} {1 {ambiguous column name: rowid}} do_catchsql_test 9.3 { SELECT rowid FROM wo1 JOIN (x1 JOIN x2); -} {1 {no such column: rowid}} +} {1 {ambiguous column name: rowid}} do_catchsql_test 9.4 { SELECT a FROM wo1, x1, x2; } {1 {ambiguous column name: a}} diff --git a/test/rowid.test b/test/rowid.test index 4327004d31..8b76762b7b 100644 --- a/test/rowid.test +++ b/test/rowid.test @@ -813,8 +813,9 @@ do_execsql_test 16.6 { SELECT rowid FROM v1, t1; } {1} do_execsql_test 16.7 { SELECT rowid FROM v1, t3; } {3} do_execsql_test 16.8 { SELECT rowid FROM (SELECT 123), t3; } {3} -do_catchsql_test 16.5 { SELECT rowid FROM t1, t3; } {1 {no such column: rowid}} - +do_catchsql_test 16.9 { + SELECT rowid FROM t1, t3; +} {1 {ambiguous column name: rowid}} finish_test diff --git a/test/unionall.test b/test/unionall.test index 99cb48a259..9057199070 100644 --- a/test/unionall.test +++ b/test/unionall.test @@ -351,7 +351,7 @@ do_catchsql_test 5.30 { SELECT * FROM (t1 NATURAL JOIN pragma_table_xinfo('t1_a') NATURAL JOIN t3) t1 NATURAL JOIN t2 NATURAL JOIN t3 WHERE rowid ISNULL>0 AND 0%y; -} {1 {no such column: rowid}} +} {1 {ambiguous column name: rowid}} } reset_db From f891ef8d6111c8c8aa7de74bcd36aaf2f4569c47 Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 19 Mar 2024 15:27:15 +0000 Subject: [PATCH 257/430] Update tests to work with SQLITE_ALLOW_ROWID_IN_VIEW. FossilOrigin-Name: 495b8c7b08b998ddfe2ad055703f058c768e7e94014952e5cd8a81c7c1515cb1 --- manifest | 28 ++++++++++++++-------------- manifest.uuid | 2 +- src/ctime.c | 3 +++ src/test_config.c | 8 ++++++++ test/join5.test | 13 +++++++++++-- test/join8.test | 7 ++++++- test/misc2.test | 29 ++++++++++++++++++++++------- test/returning1.test | 43 ++++++++++++++++++++++++++++++++----------- test/rowid.test | 33 +++++++++++++++++++++++---------- test/trigger9.test | 27 +++++++++++++++++++++------ 10 files changed, 141 insertions(+), 52 deletions(-) diff --git a/manifest b/manifest index 1bd5d0bc66..c5b4e813c0 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\sfuzzinvariants.c\stest\smodule\sso\sthat\sit\sdoes\snot\sgenerate\ninvariants\sthat\sdepend\son\srowid\swhen\sSQLITE_ALLOW_ROWID_IN_VIEW\sis\sused,\nsince\srowid\svalues\scan\sbe\sunreliable\sin\sthat\scontext. -D 2024-03-19T14:38:39.687 +C Update\stests\sto\swork\swith\sSQLITE_ALLOW_ROWID_IN_VIEW. +D 2024-03-19T15:27:15.880 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -695,7 +695,7 @@ F src/btreeInt.h 98aadb6dcb77b012cab2574d6a728fad56b337fc946839b9898c4b4c969e30b F src/build.c 71445e2d1e2c78b120a20a46d80a29a9ea42370df430efda5bb6ef377e8016c8 F src/callback.c db3a45e376deff6a16c0058163fe0ae2b73a2945f3f408ca32cf74960b28d490 F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e -F src/ctime.c 23331529e654be40ca97d171cbbffe9b3d4c71cc53b78fe5501230675952da8b +F src/ctime.c 64e4b1227b4ed123146f0aa2989131d1fbd9b927b11e80c9d58c6a68f9cd5ce3 F src/date.c 126ba2ab10aeb2e7ba6e089b5f07b747c0625b8287f78b60da346eda8d23c875 F src/dbpage.c 80e46e1df623ec40486da7a5086cb723b0275a6e2a7b01d9f9b5da0f04ba2782 F src/dbstat.c 3b677254d512fcafd4d0b341bf267b38b235ccfddbef24f9154e19360fa22e43 @@ -774,7 +774,7 @@ F src/test_backup.c bf5da90c9926df0a4b941f2d92825a01bbe090a0 F src/test_bestindex.c f6af1e41cb7901edafb065a8198e4a0192dd42432b642d038965be5e628dec12 F src/test_blob.c ae4a0620b478548afb67963095a7417cd06a4ec0a56adb453542203bfdcb31ce F src/test_btree.c 8b2dc8b8848cf3a4db93f11578f075e82252a274 -F src/test_config.c f0cc1f517deaa96dd384822ae2bb91534fa56aa458528b439830d709941d3932 +F src/test_config.c 5fa77ee6064ba546e144c4fea870c5ede2c54314616f81485c6a9c4192100c75 F src/test_delete.c e2fe07646dff6300b48d49b2fee2fe192ed389e834dd635e3b3bac0ce0bf9f8f F src/test_demovfs.c 38a459d1c78fd9afa770445b224c485e079018d6ac07332ff9bd07b54d2b8ce9 F src/test_devsym.c 649434ed34d0b03fbd5a6b42df80f0f9a7e53f94dd1710aad5dd8831e91c4e86 @@ -1326,10 +1326,10 @@ F test/join.test f7abfef3faeaf2800308872e33a57e5b6e4a2b44fb8c6b90c6068412e71a6cf F test/join2.test 8561fe82ce434ac96de91544072e578dc2cadddf2d9bc9cd802f866a9b92502e F test/join3.test 6f0c774ff1ba0489e6c88a3e77b9d3528fb4fda0 F test/join4.test 1a352e4e267114444c29266ce79e941af5885916 -F test/join5.test 7cc3f3595bb41e60f3f96d5cb6dd8cfcbc31212f0136bba6fc081c082994a94a +F test/join5.test f939b2c7f45a8d36f6b690b797cfa2d7bb828a5ff6e43d9cca88bd91e08fb464 F test/join6.test f809c025fa253f9e150c0e9afd4cef8813257bceeb6f46e04041228c9403cc2c F test/join7.test 2268dcbb54b724391dda3748ea95c60d960607ffeed67885675998e7117697f6 -F test/join8.test d384d63985e3991c404afccadaf3efd1cdf9cd72680167f80e3cb80b95c18c68 +F test/join8.test 02da1534b2b47599a078e513f597c205934d115a5a6bc31af8a5615a7488a81f F test/join9.test 9056ddd3b0c0f4f9d658f4521038d9a37dc23ead8ca9a505d0b0db2b6a471e05 F test/joinA.test 6ac4efdbb1eb9ca398162c5bc5623a757803b04bb4d76453c8563a0bdc2f73bd F test/joinB.test 1b2ba3fc8568b49411787fccbf540570c148e9b6a53a30f80691cb6268098ded @@ -1426,7 +1426,7 @@ F test/minmax2.test cf9311babb6f0518d04e42fd6a42c619531c4309a9dd790a2c4e9b3bc595 F test/minmax3.test cc1e8b010136db0d01a6f2a29ba5a9f321034354 F test/minmax4.test 272ca395257f05937dc96441c9dde4bc9fbf116a8d4fa02baeb0d13d50e36c87 F test/misc1.test e3e36262aff1bd9b8b9bf1eeb3af04adb3fc1e23f0a92dbff708bba9e939ace1 -F test/misc2.test 71e746af479119386ac2ed7ab7d81d99970e75b49ffd3e8efffee100b4b5f350 +F test/misc2.test a1a3573cc02662becd967766021d6f16c54684d56df5f227481c7ef0d9df0bd0 F test/misc3.test cf3dda47d5dda3e53fc5804a100d3c82be736c9d F test/misc4.test 10cd6addb2fa9093df4751a1b92b50440175dd5468a6ec84d0386e78f087db0e F test/misc5.test 027cf0ac10314ea534173f335a33bb4059907ddabbac2c16786766d6f26c8923 @@ -1527,7 +1527,7 @@ F test/regexp2.test 55ed41da802b0e284ac7e2fe944be3948f93ff25abbca0361a609acfed13 F test/reindex.test cd9d6021729910ece82267b4f5e1b5ac2911a7566c43b43c176a6a4732e2118d F test/resetdb.test 54c06f18bc832ac6d6319e5ab23d5c8dd49fdbeec7c696d791682a8006bd5fc3 F test/resolver01.test f4022acafda7f4d40eca94dbf16bc5fc4ac30ceb -F test/returning1.test db532cde29d6aebbc48c6ddc3149b30476f8e69ca7a2c4b53986c7635e6fd8ec +F test/returning1.test 3ead782eddf51f573cdd43bcbb10d1b485ac095a19a76d16c43fd159ea9b7466 F test/returningfault.test ae4c4b5e8745813287a359d9ccdb9d5c883c2e68afb18fb0767937d5de5692a4 F test/rollback.test 06680159bc6746d0f26276e339e3ae2f951c64812468308838e0a3362d911eaa F test/rollback2.test 3f3a4e20401825017df7e7671e9f31b6de5fae5620c2b9b49917f52f8c160a8f @@ -1535,7 +1535,7 @@ F test/rollbackfault.test 0e646aeab8840c399cfbfa43daab46fd609cf04a F test/round1.test 29c3c9039936ed024d672f003c4d35ee11c14c0acb75c5f7d6188ff16190cfd4 F test/rowallock.test 3f88ec6819489d0b2341c7a7528ae17c053ab7cc F test/rowhash.test 0bc1d31415e4575d10cacf31e1a66b5cc0f8be81 -F test/rowid.test e29025be95baf6b32f0d5edef59a7633028325896a98f1caa8019559ca910350 +F test/rowid.test 17e2a82e0567eec4b265fd063c44b96d5fd7b25ad6bd976d9c5fd892f0c2e258 F test/rowvalue.test baf4fa3ec1a8c1c920c3faa5fd25959cb454bbd99ac8960397c34549d9fc4abe F test/rowvalue2.test 060d238b7e5639a7c5630cb5e63e311b44efef2b F test/rowvalue3.test 1347e25ca11c547c5a6ff0cc5626f95aa9740e9275bfaec096029f57cb2130ce @@ -1867,7 +1867,7 @@ F test/trigger5.test 619391a3e9fc194081d22cefd830d811e7badf83 F test/trigger6.test 0e411654f122552da6590f0b4e6f781048a4a9b9 F test/trigger7.test e7ce54bfda67a88d778aea42544e151c465547a7e617127b6914c2221a6d53c1 F test/trigger8.test 30cb0530bd7c4728055420e3f739aa00412eafa4 -F test/trigger9.test fd49aff8b724ae1a6238989ecf84320d88c0e8f8d9142a891b93f826dfe37b59 +F test/trigger9.test 1724b595661da3dd3c8d79f0ebae818132a39e65c241bad2049f66952b1dc29d F test/triggerA.test 837be862d8721f903dba3f3ceff05b32e0bee5214cf6ea3da5fadf12d3650e9d F test/triggerB.test 56780c031b454abac2340dbb3b71ac5c56c3d7fe F test/triggerC.test 29f5a28d0fe39e6e2c01f6e1f53f08c0955170ae10a63ad023e33cb0a1682a51 @@ -2180,8 +2180,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 7bc882897b6910f93695ad372445df7791b096412089ccbcd4fde365c62fa074 -R 1d0ab0a71fdecadee0025e4c9e79a52a -U drh -Z ef38e4f5190d6a950df6cf2eac0e14a7 +P 0d711aaaa14472a82f8893e1b07d845073f3d018bd5b8093ec0b00ffbbc8cd5a +R 9a00ab01baff88b608a562a16a741256 +U dan +Z 3b22054791de9eb30bbf5d96e1597df1 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 6d341e4ed1..2d1f2cba94 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0d711aaaa14472a82f8893e1b07d845073f3d018bd5b8093ec0b00ffbbc8cd5a \ No newline at end of file +495b8c7b08b998ddfe2ad055703f058c768e7e94014952e5cd8a81c7c1515cb1 \ No newline at end of file diff --git a/src/ctime.c b/src/ctime.c index cf761299fe..0ffe2a5bdf 100644 --- a/src/ctime.c +++ b/src/ctime.c @@ -65,6 +65,9 @@ static const char * const sqlite3azCompileOpt[] = { "ALLOW_COVERING_INDEX_SCAN=" CTIMEOPT_VAL(SQLITE_ALLOW_COVERING_INDEX_SCAN), # endif #endif +#ifdef SQLITE_ALLOW_ROWID_IN_VIEW + "ALLOW_ROWID_IN_VIEW", +#endif #ifdef SQLITE_ALLOW_URI_AUTHORITY "ALLOW_URI_AUTHORITY", #endif diff --git a/src/test_config.c b/src/test_config.c index ee766a26d8..76904e5bf2 100644 --- a/src/test_config.c +++ b/src/test_config.c @@ -59,6 +59,14 @@ static void set_options(Tcl_Interp *interp){ Tcl_SetVar2(interp, "sqlite_options", "rowid32", "0", TCL_GLOBAL_ONLY); #endif +#ifdef SQLITE_ALLOW_ROWID_IN_VIEW + Tcl_SetVar2( + interp, "sqlite_options", "allow_rowid_in_view", "1", TCL_GLOBAL_ONLY); +#else + Tcl_SetVar2( + interp, "sqlite_options", "allow_rowid_in_view", "0", TCL_GLOBAL_ONLY); +#endif + #ifdef SQLITE_CASE_SENSITIVE_LIKE Tcl_SetVar2(interp, "sqlite_options","casesensitivelike","1",TCL_GLOBAL_ONLY); #else diff --git a/test/join5.test b/test/join5.test index 44c8b71a8d..7f8c2f6e65 100644 --- a/test/join5.test +++ b/test/join5.test @@ -370,8 +370,17 @@ do_execsql_test 9.1 { ANALYZE sqlite_schema; INSERT INTO sqlite_stat1 VALUES('t1','t1x1','648 324 81 81 81 81 81 81 81081 81 81 81'); ANALYZE sqlite_schema; - SELECT a FROM (SELECT a FROM t1 NATURAL LEFT JOIN t1) NATURAL LEFT JOIN t1 WHERE (rowid,1)<=(5,0); -} {1} +} +ifcapable allow_rowid_in_view { + set res {1 {no such column: rowid}} +} else { + set res {0 1} +} +do_catchsql_test 9.2 { + SELECT a FROM + (SELECT a FROM t1 NATURAL LEFT JOIN t1) NATURAL LEFT JOIN t1 + WHERE (rowid,1)<=(5,0); +} $res # 2022-03-02 https://sqlite.org/forum/info/50a1bbe08ce4c29c # Bloom-filter pulldown is incompatible with skip-scan. diff --git a/test/join8.test b/test/join8.test index fc50df32ff..269d251fcc 100644 --- a/test/join8.test +++ b/test/join8.test @@ -41,6 +41,11 @@ do_execsql_test join8-1000 { CREATE INDEX t1x2 ON t1(b); INSERT INTO t1 DEFAULT VALUES; } {} +ifcapable allow_rowid_in_view { + set res {1 {no such column: rowid}} +} else { + set res {0 1} +} do_catchsql_test join8-1010 { SELECT a FROM ( @@ -61,7 +66,7 @@ do_catchsql_test join8-1010 { NATURAL LEFT FULL JOIN t1 WHERE ( rowid , 1 )<=(CASE 5 WHEN 619 THEN 841 ELSE 3374391096 END,0) ORDER BY a ASC; -} {0 1} +} $res # Pending issue #2: (now resolved) # Jump to addrHalt inside the RIGHT JOIN body subroutine bypasses the diff --git a/test/misc2.test b/test/misc2.test index 4796d5d374..607799ea21 100644 --- a/test/misc2.test +++ b/test/misc2.test @@ -54,19 +54,34 @@ do_test misc2-2.1 { } } {} ifcapable subquery { - do_catchsql_test misc2-2.2 { - SELECT rowid, * FROM (SELECT * FROM t1, t2); - } {1 {no such column: rowid}} + ifcapable allow_rowid_in_view { + do_catchsql_test misc2-2.2 { + SELECT rowid, * FROM (SELECT * FROM t1, t2); + } {0 {{} 1 2 3 7 8 9}} + } else { + do_catchsql_test misc2-2.2 { + SELECT rowid, * FROM (SELECT * FROM t1, t2); + } {1 {no such column: rowid}} + } do_catchsql_test misc2-2.2b { SELECT 'rowid', * FROM (SELECT * FROM t1, t2); } {0 {rowid 1 2 3 7 8 9}} } ifcapable view { - do_catchsql_test misc2-2.3 { - CREATE VIEW v1 AS SELECT * FROM t1, t2; - SELECT rowid, * FROM v1; - } {1 {no such column: rowid}} + ifcapable allow_rowid_in_view { + do_catchsql_test misc2-2.3 { + CREATE VIEW v1 AS SELECT * FROM t1, t2; + SELECT rowid, * FROM v1; + } {0 {{} 1 2 3 7 8 9}} + } else { + do_catchsql_test misc2-2.3 { + CREATE VIEW v1 AS SELECT * FROM t1, t2; + SELECT rowid, * FROM v1; + } {1 {no such column: rowid}} + } + + do_catchsql_test misc2-2.3b { SELECT 'rowid', * FROM v1; } {0 {rowid 1 2 3 7 8 9}} diff --git a/test/returning1.test b/test/returning1.test index 6c098dc256..24032496ce 100644 --- a/test/returning1.test +++ b/test/returning1.test @@ -212,17 +212,38 @@ do_execsql_test 10.2 { END; } -do_catchsql_test 10.3a { - INSERT INTO t1(a, b) VALUES(1234, 5678) RETURNING rowid; -} {1 {no such column: new.rowid}} - -do_catchsql_test 10.3b { - UPDATE t1 SET a='z' WHERE b='y' RETURNING rowid; -} {1 {no such column: new.rowid}} - -do_execsql_test 10.4 { - SELECT * FROM log; -} {} +ifcapable !allow_rowid_in_view { + do_catchsql_test 10.3a { + INSERT INTO t1(a, b) VALUES(1234, 5678) RETURNING rowid; + } {1 {no such column: new.rowid}} + + do_catchsql_test 10.3b { + UPDATE t1 SET a='z' WHERE b='y' RETURNING rowid; + } {1 {no such column: new.rowid}} + + do_execsql_test 10.4 { + SELECT * FROM log; + } {} +} else { + # Note: The values returned by the RETURNING clauses of the following + # two statements are the rowid columns of views. These values are not + # well defined, so the INSERT returns -1, and the UPDATE returns 1, 2 + # and 3. These match the values used for new.rowid expressions, but + # not much else. + do_catchsql_test 10.3a { + INSERT INTO t1(a, b) VALUES(1234, 5678) RETURNING rowid; + } {0 -1} + + do_catchsql_test 10.3b { + UPDATE t1 SET a='z' WHERE b='y' RETURNING rowid; + } {0 {1 2 3}} + + do_execsql_test 10.4 { + SELECT * FROM log; + } { + insert -1 1234 5678 update 1 z y update 2 z y update 3 z y + } +} # 2021-04-27 dbsqlfuzz 78b9400770ef8cc7d9427dfba26f4fcf46ea7dc2 # Returning clauses on TEMP tables with triggers. diff --git a/test/rowid.test b/test/rowid.test index 4327004d31..450ae35cce 100644 --- a/test/rowid.test +++ b/test/rowid.test @@ -803,17 +803,30 @@ do_execsql_test 16.0 { INSERT INTO t3(rowid, z) VALUES(3, 3); } -do_execsql_test 16.1 { SELECT rowid FROM t1, t2; } {1} -do_execsql_test 16.2 { SELECT rowid FROM t1, v1; } {1} -do_execsql_test 16.3 { SELECT rowid FROM t3, v1; } {3} -do_execsql_test 16.4 { SELECT rowid FROM t3, (SELECT 123); } {3} - -do_execsql_test 16.5 { SELECT rowid FROM t2, t1; } {1} -do_execsql_test 16.6 { SELECT rowid FROM v1, t1; } {1} -do_execsql_test 16.7 { SELECT rowid FROM v1, t3; } {3} -do_execsql_test 16.8 { SELECT rowid FROM (SELECT 123), t3; } {3} +ifcapable allow_rowid_in_view { + set nosuch "1 {no such column: rowid}" + do_execsql_test 16.1 { SELECT rowid FROM t1, t2; } {1} + do_catchsql_test 16.2 { SELECT rowid FROM t1, v1; } $nosuch + do_catchsql_test 16.3 { SELECT rowid FROM t3, v1; } $nosuch + do_catchsql_test 16.4 { SELECT rowid FROM t3, (SELECT 123); } $nosuch + + do_execsql_test 16.5 { SELECT rowid FROM t2, t1; } {1} + do_catchsql_test 16.6 { SELECT rowid FROM v1, t1; } $nosuch + do_catchsql_test 16.7 { SELECT rowid FROM v1, t3; } $nosuch + do_catchsql_test 16.8 { SELECT rowid FROM (SELECT 123), t3; } $nosuch +} else { + do_execsql_test 16.1 { SELECT rowid FROM t1, t2; } {1} + do_execsql_test 16.2 { SELECT rowid FROM t1, v1; } {1} + do_execsql_test 16.3 { SELECT rowid FROM t3, v1; } {3} + do_execsql_test 16.4 { SELECT rowid FROM t3, (SELECT 123); } {3} + + do_execsql_test 16.5 { SELECT rowid FROM t2, t1; } {1} + do_execsql_test 16.6 { SELECT rowid FROM v1, t1; } {1} + do_execsql_test 16.7 { SELECT rowid FROM v1, t3; } {3} + do_execsql_test 16.8 { SELECT rowid FROM (SELECT 123), t3; } {3} +} -do_catchsql_test 16.5 { SELECT rowid FROM t1, t3; } {1 {no such column: rowid}} +do_catchsql_test 16.9 { SELECT rowid FROM t1, t3; } {1 {no such column: rowid}} diff --git a/test/trigger9.test b/test/trigger9.test index 6e31d1af97..47940de577 100644 --- a/test/trigger9.test +++ b/test/trigger9.test @@ -242,12 +242,27 @@ do_execsql_test 4.1 { END; } -do_catchsql_test 4.2 { - DELETE FROM v1 WHERE rowid=1; -} {1 {no such column: rowid}} +ifcapable !allow_rowid_in_view { + do_catchsql_test 4.2 { + DELETE FROM v1 WHERE rowid=1; + } {1 {no such column: rowid}} -do_catchsql_test 4.3 { - UPDATE v1 SET a=b WHERE rowid=2; -} {1 {no such column: rowid}} + do_catchsql_test 4.3 { + UPDATE v1 SET a=b WHERE rowid=2; + } {1 {no such column: rowid}} +} else { + do_execsql_test 4.2a { + DELETE FROM log; + } + do_catchsql_test 4.2 { + DELETE FROM v1 WHERE rowid=1; + } {0 {}} + do_catchsql_test 4.3 { + UPDATE v1 SET a=b WHERE rowid=2; + } {0 {}} + do_execsql_test 4.3b { + SELECT * FROM log; + } +} finish_test From e9feb0acfc4bd4fc86fbc7eaa160361bef3e4198 Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 19 Mar 2024 16:34:32 +0000 Subject: [PATCH 258/430] In the name resolver when SQLITE_ALLOW_ROWID_IN_INDEX is enabled, if there are multiple views that might resolve to the "rowid" but only one real table, then use that one real table and ignore the views. FossilOrigin-Name: 8fcea4cdfc89dd78eca5e7f62aa31aff0e296f41e79349d3af1cc3a2bc4d77c6 --- manifest | 18 +++++++++--------- manifest.uuid | 2 +- src/ctime.c | 3 --- src/resolve.c | 29 +++++++++++++++++++++++++++++ test/unionall.test | 2 +- 5 files changed, 40 insertions(+), 14 deletions(-) diff --git a/manifest b/manifest index c5b4e813c0..98c9af5c57 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Update\stests\sto\swork\swith\sSQLITE_ALLOW_ROWID_IN_VIEW. -D 2024-03-19T15:27:15.880 +C In\sthe\sname\sresolver\swhen\sSQLITE_ALLOW_ROWID_IN_INDEX\sis\senabled,\sif\sthere\nare\smultiple\sviews\sthat\smight\sresolve\sto\sthe\s"rowid"\sbut\sonly\sone\sreal\stable,\nthen\suse\sthat\sone\sreal\stable\sand\signore\sthe\sviews. +D 2024-03-19T16:34:32.133 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -695,7 +695,7 @@ F src/btreeInt.h 98aadb6dcb77b012cab2574d6a728fad56b337fc946839b9898c4b4c969e30b F src/build.c 71445e2d1e2c78b120a20a46d80a29a9ea42370df430efda5bb6ef377e8016c8 F src/callback.c db3a45e376deff6a16c0058163fe0ae2b73a2945f3f408ca32cf74960b28d490 F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e -F src/ctime.c 64e4b1227b4ed123146f0aa2989131d1fbd9b927b11e80c9d58c6a68f9cd5ce3 +F src/ctime.c 23331529e654be40ca97d171cbbffe9b3d4c71cc53b78fe5501230675952da8b F src/date.c 126ba2ab10aeb2e7ba6e089b5f07b747c0625b8287f78b60da346eda8d23c875 F src/dbpage.c 80e46e1df623ec40486da7a5086cb723b0275a6e2a7b01d9f9b5da0f04ba2782 F src/dbstat.c 3b677254d512fcafd4d0b341bf267b38b235ccfddbef24f9154e19360fa22e43 @@ -748,7 +748,7 @@ F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7 F src/prepare.c 371f6115cb69286ebc12c6f2d7511279c2e47d9f54f475d46a554d687a3b312c F src/printf.c 87b67bba3662a0523f39ae6b084a3907109702f717c654d6cecb838af5cd57f1 F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c -F src/resolve.c ef87e3bc7700bfe761a7bbee2ce6084f1766dc816dd82a3ae77c133eec898432 +F src/resolve.c f851f7cce8cca274f82242b09e2fab67a42fa52de21c8a25cbdb490b057004ac F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c ac3689a3f54f81e8b710ce772c5c49c13a152e4ac484c2429ad5264243e7de66 F src/shell.c.in a2ccceb9a250613f8156b098736bd94424c422972a1c1ddda35604531ae1762e @@ -1887,7 +1887,7 @@ F test/types.test bf816ce73c7dfcfe26b700c19f97ef4050d194ff F test/types2.test 1aeb81976841a91eef292723649b5c4fe3bc3cac F test/types3.test c9db8f9e80309edfa4252585cf16bcab7ed31f39eeb904d21e831199a3613fb0 F test/unhex.test b7f1b806207cb77fa31c3e434fe92fba524464e3e9356809bfcc28f15af1a8b7 -F test/unionall.test 5b1c4186a661e4bf762875caf4c61d8fda3dd04a6fa9005187f6ba8900c2913f +F test/unionall.test cdae0b1b47128991d0c26075e552cbb1c1fa0b62c4fa7ffa5575e65a5e9fe834 F test/unionall2.test 71e8fa08d5699d50dc9f9dc0c9799c2e7a6bb7931a330d369307a4df7f157fa1 F test/unionallfault.test 652bfbb630e6c43135965dc1e8f0a9a791da83aec885d626a632fe1909c56f73 F test/unionvtab.test e1704ab1b4c1bb3ffc9da4681f8e85a0b909fd80b937984fc94b27415ac8e5a4 @@ -2180,8 +2180,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 0d711aaaa14472a82f8893e1b07d845073f3d018bd5b8093ec0b00ffbbc8cd5a -R 9a00ab01baff88b608a562a16a741256 -U dan -Z 3b22054791de9eb30bbf5d96e1597df1 +P 495b8c7b08b998ddfe2ad055703f058c768e7e94014952e5cd8a81c7c1515cb1 +R 8eb7d29f7ff85a3768eaeec1cf36e8a2 +U drh +Z 689a4a1a83e57ca389a38b62f6fe8edf # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 2d1f2cba94..0ad3f9c566 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -495b8c7b08b998ddfe2ad055703f058c768e7e94014952e5cd8a81c7c1515cb1 \ No newline at end of file +8fcea4cdfc89dd78eca5e7f62aa31aff0e296f41e79349d3af1cc3a2bc4d77c6 \ No newline at end of file diff --git a/src/ctime.c b/src/ctime.c index 0ffe2a5bdf..cf761299fe 100644 --- a/src/ctime.c +++ b/src/ctime.c @@ -65,9 +65,6 @@ static const char * const sqlite3azCompileOpt[] = { "ALLOW_COVERING_INDEX_SCAN=" CTIMEOPT_VAL(SQLITE_ALLOW_COVERING_INDEX_SCAN), # endif #endif -#ifdef SQLITE_ALLOW_ROWID_IN_VIEW - "ALLOW_ROWID_IN_VIEW", -#endif #ifdef SQLITE_ALLOW_URI_AUTHORITY "ALLOW_URI_AUTHORITY", #endif diff --git a/src/resolve.c b/src/resolve.c index c2957a870a..2971936105 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -469,8 +469,37 @@ static int lookupName( } } if( 0==cnt && VisibleRowid(pTab) ){ + /* pTab is a potential ROWID match. Keep track of it and match + ** the ROWID later if that seems appropriate. (Search for "cntTab" + ** to find related code.) Only allow a ROWID match if there is + ** a single ROWID match candidate. + */ +#ifdef SQLITE_ALLOW_ROWID_IN_VIEW + /* In SQLITE_ALLOW_ROWID_IN_VIEW mode, allow a ROWID match + ** if there is a single VIEW candidate or if there is a single + ** non-VIEW candidate plus multiple VIEW candidates. In other + ** words non-VIEW candidate terms take precedence over VIEWs. + */ + if( cntTab==0 + || (cntTab==1 + && ALWAYS(pMatch!=0) + && ALWAYS(pMatch->pTab!=0) + && (pMatch->pTab->tabFlags & TF_Ephemeral)!=0 + && (pTab->tabFlags & TF_Ephemeral)==0) + ){ + cntTab = 1; + pMatch = pItem; + }else{ + cntTab++; + } +#else + /* The (much more common) non-SQLITE_ALLOW_ROWID_IN_VIEW case is + ** simpler since we require exactly one candidate, which will + ** always be a non-VIEW + */ cntTab++; pMatch = pItem; +#endif } } if( pMatch ){ diff --git a/test/unionall.test b/test/unionall.test index 99cb48a259..ae1a271bfc 100644 --- a/test/unionall.test +++ b/test/unionall.test @@ -351,7 +351,7 @@ do_catchsql_test 5.30 { SELECT * FROM (t1 NATURAL JOIN pragma_table_xinfo('t1_a') NATURAL JOIN t3) t1 NATURAL JOIN t2 NATURAL JOIN t3 WHERE rowid ISNULL>0 AND 0%y; -} {1 {no such column: rowid}} +} {/1 {no such column: [a-z]+}/} } reset_db From ffbe4925532ed82f61dd93af40c288a593a5b5d3 Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 19 Mar 2024 16:51:18 +0000 Subject: [PATCH 259/430] Update test scripts to account for [8fcea4cd]. FossilOrigin-Name: 0c543c51a8c5c8916f649a5e7fd3fedc9c05f2df36064b1699ea6f5e08eaa9e0 --- manifest | 18 +++++++++--------- manifest.uuid | 2 +- test/join5.test | 7 +------ test/join8.test | 7 +------ test/rowid.test | 2 +- 5 files changed, 13 insertions(+), 23 deletions(-) diff --git a/manifest b/manifest index 98c9af5c57..c2d38c6cc9 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C In\sthe\sname\sresolver\swhen\sSQLITE_ALLOW_ROWID_IN_INDEX\sis\senabled,\sif\sthere\nare\smultiple\sviews\sthat\smight\sresolve\sto\sthe\s"rowid"\sbut\sonly\sone\sreal\stable,\nthen\suse\sthat\sone\sreal\stable\sand\signore\sthe\sviews. -D 2024-03-19T16:34:32.133 +C Update\stest\sscripts\sto\saccount\sfor\s[8fcea4cd]. +D 2024-03-19T16:51:18.484 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -1326,10 +1326,10 @@ F test/join.test f7abfef3faeaf2800308872e33a57e5b6e4a2b44fb8c6b90c6068412e71a6cf F test/join2.test 8561fe82ce434ac96de91544072e578dc2cadddf2d9bc9cd802f866a9b92502e F test/join3.test 6f0c774ff1ba0489e6c88a3e77b9d3528fb4fda0 F test/join4.test 1a352e4e267114444c29266ce79e941af5885916 -F test/join5.test f939b2c7f45a8d36f6b690b797cfa2d7bb828a5ff6e43d9cca88bd91e08fb464 +F test/join5.test 380d12a9350f99f0cc681a4f1fea999886f18b3fe0d71a9b3065bcaead1e007f F test/join6.test f809c025fa253f9e150c0e9afd4cef8813257bceeb6f46e04041228c9403cc2c F test/join7.test 2268dcbb54b724391dda3748ea95c60d960607ffeed67885675998e7117697f6 -F test/join8.test 02da1534b2b47599a078e513f597c205934d115a5a6bc31af8a5615a7488a81f +F test/join8.test d384d63985e3991c404afccadaf3efd1cdf9cd72680167f80e3cb80b95c18c68 F test/join9.test 9056ddd3b0c0f4f9d658f4521038d9a37dc23ead8ca9a505d0b0db2b6a471e05 F test/joinA.test 6ac4efdbb1eb9ca398162c5bc5623a757803b04bb4d76453c8563a0bdc2f73bd F test/joinB.test 1b2ba3fc8568b49411787fccbf540570c148e9b6a53a30f80691cb6268098ded @@ -1535,7 +1535,7 @@ F test/rollbackfault.test 0e646aeab8840c399cfbfa43daab46fd609cf04a F test/round1.test 29c3c9039936ed024d672f003c4d35ee11c14c0acb75c5f7d6188ff16190cfd4 F test/rowallock.test 3f88ec6819489d0b2341c7a7528ae17c053ab7cc F test/rowhash.test 0bc1d31415e4575d10cacf31e1a66b5cc0f8be81 -F test/rowid.test 17e2a82e0567eec4b265fd063c44b96d5fd7b25ad6bd976d9c5fd892f0c2e258 +F test/rowid.test f1e15169727f50a77854280b6cb9100f0bb1cff286f2a8157eecc2e1b5e01bbd F test/rowvalue.test baf4fa3ec1a8c1c920c3faa5fd25959cb454bbd99ac8960397c34549d9fc4abe F test/rowvalue2.test 060d238b7e5639a7c5630cb5e63e311b44efef2b F test/rowvalue3.test 1347e25ca11c547c5a6ff0cc5626f95aa9740e9275bfaec096029f57cb2130ce @@ -2180,8 +2180,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 495b8c7b08b998ddfe2ad055703f058c768e7e94014952e5cd8a81c7c1515cb1 -R 8eb7d29f7ff85a3768eaeec1cf36e8a2 -U drh -Z 689a4a1a83e57ca389a38b62f6fe8edf +P 8fcea4cdfc89dd78eca5e7f62aa31aff0e296f41e79349d3af1cc3a2bc4d77c6 +R 83391bbbe1b5a044197ab1ad94f98ae7 +U dan +Z 5ca20466e8061812ee63f9a3dfe46ebc # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 0ad3f9c566..f4ba89c174 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8fcea4cdfc89dd78eca5e7f62aa31aff0e296f41e79349d3af1cc3a2bc4d77c6 \ No newline at end of file +0c543c51a8c5c8916f649a5e7fd3fedc9c05f2df36064b1699ea6f5e08eaa9e0 \ No newline at end of file diff --git a/test/join5.test b/test/join5.test index 7f8c2f6e65..703c256f86 100644 --- a/test/join5.test +++ b/test/join5.test @@ -371,16 +371,11 @@ do_execsql_test 9.1 { INSERT INTO sqlite_stat1 VALUES('t1','t1x1','648 324 81 81 81 81 81 81 81081 81 81 81'); ANALYZE sqlite_schema; } -ifcapable allow_rowid_in_view { - set res {1 {no such column: rowid}} -} else { - set res {0 1} -} do_catchsql_test 9.2 { SELECT a FROM (SELECT a FROM t1 NATURAL LEFT JOIN t1) NATURAL LEFT JOIN t1 WHERE (rowid,1)<=(5,0); -} $res +} {0 1} # 2022-03-02 https://sqlite.org/forum/info/50a1bbe08ce4c29c # Bloom-filter pulldown is incompatible with skip-scan. diff --git a/test/join8.test b/test/join8.test index 269d251fcc..fc50df32ff 100644 --- a/test/join8.test +++ b/test/join8.test @@ -41,11 +41,6 @@ do_execsql_test join8-1000 { CREATE INDEX t1x2 ON t1(b); INSERT INTO t1 DEFAULT VALUES; } {} -ifcapable allow_rowid_in_view { - set res {1 {no such column: rowid}} -} else { - set res {0 1} -} do_catchsql_test join8-1010 { SELECT a FROM ( @@ -66,7 +61,7 @@ do_catchsql_test join8-1010 { NATURAL LEFT FULL JOIN t1 WHERE ( rowid , 1 )<=(CASE 5 WHEN 619 THEN 841 ELSE 3374391096 END,0) ORDER BY a ASC; -} $res +} {0 1} # Pending issue #2: (now resolved) # Jump to addrHalt inside the RIGHT JOIN body subroutine bypasses the diff --git a/test/rowid.test b/test/rowid.test index 450ae35cce..75215d5dfc 100644 --- a/test/rowid.test +++ b/test/rowid.test @@ -813,7 +813,7 @@ ifcapable allow_rowid_in_view { do_execsql_test 16.5 { SELECT rowid FROM t2, t1; } {1} do_catchsql_test 16.6 { SELECT rowid FROM v1, t1; } $nosuch do_catchsql_test 16.7 { SELECT rowid FROM v1, t3; } $nosuch - do_catchsql_test 16.8 { SELECT rowid FROM (SELECT 123), t3; } $nosuch + do_execsql_test 16.8 { SELECT rowid FROM (SELECT 123), t3; } {3} } else { do_execsql_test 16.1 { SELECT rowid FROM t1, t2; } {1} do_execsql_test 16.2 { SELECT rowid FROM t1, v1; } {1} From 27ea83f66ec0a95ab07e93945e7be1ed76d6499c Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 19 Mar 2024 19:42:56 +0000 Subject: [PATCH 260/430] Make sure the new u1.nRow value is copied when making a copy of a SrcItem object. This fixes a problem in [ac6f095e13e43d66] from yesterady. FossilOrigin-Name: 262f8f9d80d37160e4126634b99aa48fce2073e61f6365e8bdbe1cc4fa560a96 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/expr.c | 9 +++++---- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 26d692be1b..3e08c7de52 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Adjustments\sto\sthe\stest\scases\sfor\sthe\sprevious\scheck-in\sto\smake\sthem\ncross-platform\sLinux/Mac/Windows.\s\sTest\schance\sonly.\s\sNo\schange\sto\score\scode. -D 2024-03-19T10:41:18.138 +C Make\ssure\sthe\snew\su1.nRow\svalue\sis\scopied\swhen\smaking\sa\scopy\sof\sa\sSrcItem\nobject.\s\sThis\sfixes\sa\sproblem\sin\s[ac6f095e13e43d66]\sfrom\syesterady. +D 2024-03-19T19:42:56.248 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -700,7 +700,7 @@ F src/date.c 126ba2ab10aeb2e7ba6e089b5f07b747c0625b8287f78b60da346eda8d23c875 F src/dbpage.c 80e46e1df623ec40486da7a5086cb723b0275a6e2a7b01d9f9b5da0f04ba2782 F src/dbstat.c 3b677254d512fcafd4d0b341bf267b38b235ccfddbef24f9154e19360fa22e43 F src/delete.c cb766727c78e715f9fb7ec8a7d03658ed2a3016343ca687acfcec9083cdca500 -F src/expr.c d7cfe9b9fe7ab47b254706589467d2e65fec3536b936d6f4eb28b84da6726ecc +F src/expr.c 94f48513fbec07725501298dee3f16d95b1762bb4a12296455f544b2d7f2d74a F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c a47610f0a5c6cb0ad79f8fcef039c01833dec0c751bb695f28dc0ec6a4c3ba00 F src/func.c 283d4f3b2751a1d9339fd93a8a013d1948fd5f4474a3cab0955eb4fafd445d0f @@ -2180,8 +2180,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 45d272ef38d5ee6189f81369aefb8e3ac35868a67687012d93c84f2bbc42520a -R 06f52063180a10fd2f7e8878024a8e93 +P 0dddadbd5b217a48bb5c1b0568a03fbafb89dba98c577727bf4f79ff7e0ca849 +R e14b4caec27431611935484cb358ede2 U drh -Z be89e098a4549a3844da98de72222ae6 +Z bd83640688abf542746530f70fd640a9 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 46aef1d450..a3e0e0577d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0dddadbd5b217a48bb5c1b0568a03fbafb89dba98c577727bf4f79ff7e0ca849 \ No newline at end of file +262f8f9d80d37160e4126634b99aa48fce2073e61f6365e8bdbe1cc4fa560a96 \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index 3a7065b21f..7e3f38279d 100644 --- a/src/expr.c +++ b/src/expr.c @@ -1873,15 +1873,16 @@ SrcList *sqlite3SrcListDup(sqlite3 *db, const SrcList *p, int flags){ pNewItem->regResult = pOldItem->regResult; if( pNewItem->fg.isIndexedBy ){ pNewItem->u1.zIndexedBy = sqlite3DbStrDup(db, pOldItem->u1.zIndexedBy); + }else if( pNewItem->fg.isTabFunc ){ + pNewItem->u1.pFuncArg = + sqlite3ExprListDup(db, pOldItem->u1.pFuncArg, flags); + }else{ + pNewItem->u1.nRow = pOldItem->u1.nRow; } pNewItem->u2 = pOldItem->u2; if( pNewItem->fg.isCte ){ pNewItem->u2.pCteUse->nUse++; } - if( pNewItem->fg.isTabFunc ){ - pNewItem->u1.pFuncArg = - sqlite3ExprListDup(db, pOldItem->u1.pFuncArg, flags); - } pTab = pNewItem->pTab = pOldItem->pTab; if( pTab ){ pTab->nTabRef++; From 4aa21492d134e4713e7d0b9a2fa0df69af0595f3 Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 19 Mar 2024 19:48:50 +0000 Subject: [PATCH 261/430] Add the --no-rowid-in-view option to the --help output of the CLI. FossilOrigin-Name: 134da9c348a5e3b5cef97b79f37d48257afd4fa958a84f6930ac9874284a14cd --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/shell.c.in | 1 + 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index c2d38c6cc9..54c1de2dbc 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Update\stest\sscripts\sto\saccount\sfor\s[8fcea4cd]. -D 2024-03-19T16:51:18.484 +C Add\sthe\s--no-rowid-in-view\soption\sto\sthe\s--help\soutput\sof\sthe\sCLI. +D 2024-03-19T19:48:50.520 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -751,7 +751,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c f851f7cce8cca274f82242b09e2fab67a42fa52de21c8a25cbdb490b057004ac F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c ac3689a3f54f81e8b710ce772c5c49c13a152e4ac484c2429ad5264243e7de66 -F src/shell.c.in a2ccceb9a250613f8156b098736bd94424c422972a1c1ddda35604531ae1762e +F src/shell.c.in 31c3845fae8382e5c9c46a8985b51a444387edf77404ac4db6716493efe2c72f F src/sqlite.h.in e9d785f9d17f2caa366641d6616748310c8092cc0746f064c8cf5bcc767bcab0 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 @@ -2180,8 +2180,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 8fcea4cdfc89dd78eca5e7f62aa31aff0e296f41e79349d3af1cc3a2bc4d77c6 -R 83391bbbe1b5a044197ab1ad94f98ae7 -U dan -Z 5ca20466e8061812ee63f9a3dfe46ebc +P 0c543c51a8c5c8916f649a5e7fd3fedc9c05f2df36064b1699ea6f5e08eaa9e0 +R d8ca3828d85dd4e8623c1490de65b057 +U drh +Z c0e8acb3c82219f215133f9caa378b5b # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index f4ba89c174..408e38f5d9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0c543c51a8c5c8916f649a5e7fd3fedc9c05f2df36064b1699ea6f5e08eaa9e0 \ No newline at end of file +134da9c348a5e3b5cef97b79f37d48257afd4fa958a84f6930ac9874284a14cd \ No newline at end of file diff --git a/src/shell.c.in b/src/shell.c.in index 51769a67d7..9a86a06659 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -12058,6 +12058,7 @@ static const char zOptions[] = " -newline SEP set output row separator. Default: '\\n'\n" " -nofollow refuse to open symbolic links to database files\n" " -nonce STRING set the safe-mode escape nonce\n" + " -no-rowid-in-view Disable rowid-in-view using sqlite3_config()\n" " -nullvalue TEXT set text string for NULL values. Default ''\n" " -pagecache SIZE N use N slots of SZ bytes each for page cache memory\n" " -pcachetrace trace all page cache operations\n" From 254729edb7b7e704b95af059e91bc4b3e11e9e4e Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 19 Mar 2024 23:01:56 +0000 Subject: [PATCH 262/430] Change the SQLITE_CONFIG_NO_ROWID_IN_VIEW configuration option to be just SQLITE_CONFIG_ROWID_IN_VIEW (without the "_NO_" in the middle) and give it the ability to turn the option on and off. Otherwise, it is difficult to test. FossilOrigin-Name: 5d412edc2e378999ad798d1d7d73c7f7a17ee4e3c751a0dd00b9d5ce32759550 --- manifest | 19 +++++++++---------- manifest.uuid | 2 +- src/main.c | 9 +++++++-- src/select.c | 3 ++- src/shell.c.in | 4 +++- src/sqlite.h.in | 25 +++++++++++++++---------- 6 files changed, 37 insertions(+), 25 deletions(-) diff --git a/manifest b/manifest index 3a9d289865..a4d4966bbc 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Return\sthe\serror\s"ambiguous\scolumn\sname:\srowid",\sinstead\sof\s"no\ssuch\scolumn:\srowid",\swhen\sa\s"rowid"\sreference\sis\sambiguous. -D 2024-03-19T19:56:39.777 +C Change\sthe\sSQLITE_CONFIG_NO_ROWID_IN_VIEW\sconfiguration\soption\sto\sbe\njust\sSQLITE_CONFIG_ROWID_IN_VIEW\s(without\sthe\s"_NO_"\sin\sthe\smiddle)\sand\sgive\nit\sthe\sability\sto\sturn\sthe\soption\son\sand\soff.\s\sOtherwise,\sit\sis\sdifficult\nto\stest. +D 2024-03-19T23:01:56.437 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -713,7 +713,7 @@ F src/insert.c 06ce505713e86172612f9e01febefd2d3331d1f70461b4ada0eae5a76bb6349f F src/json.c e2e40760d6689134c3e2ece38c6a496b34ff5e2661a8f238444a119af666fdce F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 -F src/main.c 3db8bc4c8e0515b9e23bed3167de8b626a55e9eb1f65fe42b878d820cfa90628 +F src/main.c 8a59d297ec77e6b78550433bfccb95a1b26f2fb69aaaf233206e21579a1cfcc1 F src/malloc.c 410e570b30c26cc36e3372577df50f7a96ee3eed5b2b161c6b6b48773c650c5e F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c 3bb59158c38e05f6270e761a9f435bf19827a264c13d1631c58b84bdc96d73b2 @@ -750,9 +750,9 @@ F src/printf.c 87b67bba3662a0523f39ae6b084a3907109702f717c654d6cecb838af5cd57f1 F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c eb1860b134fb044fd819c4347105c148d5aac7c6498032be2829e5cc95619b28 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 -F src/select.c ac3689a3f54f81e8b710ce772c5c49c13a152e4ac484c2429ad5264243e7de66 -F src/shell.c.in 31c3845fae8382e5c9c46a8985b51a444387edf77404ac4db6716493efe2c72f -F src/sqlite.h.in e9d785f9d17f2caa366641d6616748310c8092cc0746f064c8cf5bcc767bcab0 +F src/select.c a83532bae45185f271b59babf715a31a831ac17e2b4bc061f52ee53825c688f1 +F src/shell.c.in 0354ca51eee5fbf6af394a7ef9f5ef6823ef45b743db65431f6777e4d5be2199 +F src/sqlite.h.in f099b625b073ba250ff9f0feb4d7d0fb570ac1b9584584009ff4951f729e147c F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 F src/sqliteInt.h f8928f0397d797046396dd9d360a6af8ce6dcb48bd72ea290165b07c8c518744 @@ -2180,9 +2180,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 134da9c348a5e3b5cef97b79f37d48257afd4fa958a84f6930ac9874284a14cd 021f34fcfed41b607be8169bbda59aef93f130108d944f4741b46e8e345b2bbb -R be08dcf8f811c87330d104f5ec4dbed8 -T +closed 021f34fcfed41b607be8169bbda59aef93f130108d944f4741b46e8e345b2bbb +P 0615bdae2dfc70c7e0416a28e89ffde31fa44ed4b3dac46e5ef20eed0d89e58c +R 0da4f5b6bfe3d8c8b355040cbb4a265d U drh -Z e6cd68fc074ecbc59d0059bf2fbd13d3 +Z c8d34cb65d7a95190f13ea53bc6d7b05 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 15c3871d50..59f541b818 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0615bdae2dfc70c7e0416a28e89ffde31fa44ed4b3dac46e5ef20eed0d89e58c \ No newline at end of file +5d412edc2e378999ad798d1d7d73c7f7a17ee4e3c751a0dd00b9d5ce32759550 \ No newline at end of file diff --git a/src/main.c b/src/main.c index 6c8ae5b281..bff801a87d 100644 --- a/src/main.c +++ b/src/main.c @@ -765,9 +765,14 @@ int sqlite3_config(int op, ...){ } #endif /* SQLITE_OMIT_DESERIALIZE */ - case SQLITE_CONFIG_NO_ROWID_IN_VIEW: { + case SQLITE_CONFIG_ROWID_IN_VIEW: { + int *pVal = va_arg(ap,int*); #ifdef SQLITE_ALLOW_ROWID_IN_VIEW - sqlite3GlobalConfig.mNoVisibleRowid = TF_NoVisibleRowid; + if( 0==*pVal ) sqlite3GlobalConfig.mNoVisibleRowid = TF_NoVisibleRowid; + if( 1==*pVal ) sqlite3GlobalConfig.mNoVisibleRowid = 0; + *pVal = (sqlite3GlobalConfig.mNoVisibleRowid==0); +#else + *pVal = 0; #endif break; } diff --git a/src/select.c b/src/select.c index f71b715517..8d3c69ebb9 100644 --- a/src/select.c +++ b/src/select.c @@ -6254,7 +6254,8 @@ static int selectExpander(Walker *pWalker, Select *p){ pX = &pNew->a[pNew->nExpr-1]; assert( pX->zEName==0 ); if( (selFlags & SF_NestedFrom)!=0 && !IN_RENAME_OBJECT ){ - if( pNestedFrom && jnExpr ){ + if( pNestedFrom && (!ViewCanHaveRowid || jnExpr) ){ + assert( jnExpr ); pX->zEName = sqlite3DbStrDup(db, pNestedFrom->a[j].zEName); testcase( pX->zEName==0 ); }else{ diff --git a/src/shell.c.in b/src/shell.c.in index 9a86a06659..2f91ac8ba1 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -12350,7 +12350,9 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){ }else if( cli_strcmp(z,"-utf8")==0 ){ }else if( cli_strcmp(z,"-no-utf8")==0 ){ }else if( cli_strcmp(z,"-no-rowid-in-view")==0 ){ - sqlite3_config(SQLITE_CONFIG_NO_ROWID_IN_VIEW); + int val = 0; + sqlite3_config(SQLITE_CONFIG_ROWID_IN_VIEW, &val); + assert( val==0 ); }else if( cli_strcmp(z,"-heap")==0 ){ #if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5) const char *zSize; diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 9c9a78c453..811ea3c5ef 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -2144,15 +2144,20 @@ struct sqlite3_mem_methods { ** by the [SQLITE_MEMDB_DEFAULT_MAXSIZE] compile-time option. If that ** compile-time option is not set, then the default maximum is 1073741824. ** -** [[SQLITE_CONFIG_NO_ROWID_IN_VIEW]] -**
    SQLITE_CONFIG_NO_ROWID_IN_VIEW -**
    The SQLITE_CONFIG_NO_ROWID_IN_VIEW option prohibits VIEWs from having -** a ROWID. This is the default behavior and so test sqlite_config() option -** is normally a no-op. However, if SQLite is compiled with the -** -DSQLITE_ALLOW_ROWID_IN_VIEW option (not recommended!) then this configuration -** option will disable that capability and make SQLite operate as it normally -** would given default the default compile-time options. Once ROWIDs in VIEWs -** have been disabled using this option, they cannot be reenabled. +** [[SQLITE_CONFIG_ROWID_IN_VIEW]] +**
    SQLITE_CONFIG_ROWID_IN_VIEW +**
    The SQLITE_CONFIG_ROWID_IN_VIEW option enables are disables the ability +** for VIEWs to have a ROWID. The capability can only be abled if SQLite is +** compiled with -DSQLITE_ALLOW_ROWID_IN_VIEW, in which case it the capability +** defaults to on. This configuration option queries the current setting or +** changes the setting to off or on. The argument is a pointer to an integer. +** If that integer initially holds a value of 1, then the ability for VIEWs to +** have ROWIDs is activated. If the integer initially holds zero, then the +** ability is deactivated. After any changes, the integer is written with +** a 1 or 0, if the ability for VIEWs to have ROWIDs is on or off. If SQLite +** is compiled without -DSQLITE_ALLOW_ROWID_IN_VIEW (which is the usual and +** recommended case) then the integer is always filled with zero, regardless +** if its initial value. ** */ #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ @@ -2184,7 +2189,7 @@ struct sqlite3_mem_methods { #define SQLITE_CONFIG_SMALL_MALLOC 27 /* boolean */ #define SQLITE_CONFIG_SORTERREF_SIZE 28 /* int nByte */ #define SQLITE_CONFIG_MEMDB_MAXSIZE 29 /* sqlite3_int64 */ -#define SQLITE_CONFIG_NO_ROWID_IN_VIEW 30 /* nil */ +#define SQLITE_CONFIG_ROWID_IN_VIEW 30 /* int* */ /* ** CAPI3REF: Database Connection Configuration Options From 697e122a11bdf15e9f503b1eb222c70b90874e03 Mon Sep 17 00:00:00 2001 From: drh <> Date: Wed, 20 Mar 2024 09:45:44 +0000 Subject: [PATCH 263/430] Fix typos in the SQLITE_CONFIG_ROWID_IN_VIEW documentation. FossilOrigin-Name: 1ad1ca498296493c8e89cda911cc153baa51c90ae6c19961841e6b4e37302a23 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/sqlite.h.in | 9 +++++---- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index a4d4966bbc..2d322553b1 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Change\sthe\sSQLITE_CONFIG_NO_ROWID_IN_VIEW\sconfiguration\soption\sto\sbe\njust\sSQLITE_CONFIG_ROWID_IN_VIEW\s(without\sthe\s"_NO_"\sin\sthe\smiddle)\sand\sgive\nit\sthe\sability\sto\sturn\sthe\soption\son\sand\soff.\s\sOtherwise,\sit\sis\sdifficult\nto\stest. -D 2024-03-19T23:01:56.437 +C Fix\stypos\sin\sthe\sSQLITE_CONFIG_ROWID_IN_VIEW\sdocumentation. +D 2024-03-20T09:45:44.382 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -752,7 +752,7 @@ F src/resolve.c eb1860b134fb044fd819c4347105c148d5aac7c6498032be2829e5cc95619b28 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c a83532bae45185f271b59babf715a31a831ac17e2b4bc061f52ee53825c688f1 F src/shell.c.in 0354ca51eee5fbf6af394a7ef9f5ef6823ef45b743db65431f6777e4d5be2199 -F src/sqlite.h.in f099b625b073ba250ff9f0feb4d7d0fb570ac1b9584584009ff4951f729e147c +F src/sqlite.h.in 41c5febd217b1e475aae022895c60f57fbe39ff6136450110662cfad67002d43 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 F src/sqliteInt.h f8928f0397d797046396dd9d360a6af8ce6dcb48bd72ea290165b07c8c518744 @@ -2180,8 +2180,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 0615bdae2dfc70c7e0416a28e89ffde31fa44ed4b3dac46e5ef20eed0d89e58c -R 0da4f5b6bfe3d8c8b355040cbb4a265d +P 5d412edc2e378999ad798d1d7d73c7f7a17ee4e3c751a0dd00b9d5ce32759550 +R d82f649ee8e5d633f69feebd0d7bf101 U drh -Z c8d34cb65d7a95190f13ea53bc6d7b05 +Z ae521986bd186966a5bde1a9ef372fcb # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 59f541b818..83e1223c29 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5d412edc2e378999ad798d1d7d73c7f7a17ee4e3c751a0dd00b9d5ce32759550 \ No newline at end of file +1ad1ca498296493c8e89cda911cc153baa51c90ae6c19961841e6b4e37302a23 \ No newline at end of file diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 811ea3c5ef..06fcd3f89e 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -2146,14 +2146,15 @@ struct sqlite3_mem_methods { ** ** [[SQLITE_CONFIG_ROWID_IN_VIEW]] **
    SQLITE_CONFIG_ROWID_IN_VIEW -**
    The SQLITE_CONFIG_ROWID_IN_VIEW option enables are disables the ability -** for VIEWs to have a ROWID. The capability can only be abled if SQLite is -** compiled with -DSQLITE_ALLOW_ROWID_IN_VIEW, in which case it the capability +**
    The SQLITE_CONFIG_ROWID_IN_VIEW option enables or disables the ability +** for VIEWs to have a ROWID. The capability can only be enabled if SQLite is +** compiled with -DSQLITE_ALLOW_ROWID_IN_VIEW, in which case the capability ** defaults to on. This configuration option queries the current setting or ** changes the setting to off or on. The argument is a pointer to an integer. ** If that integer initially holds a value of 1, then the ability for VIEWs to ** have ROWIDs is activated. If the integer initially holds zero, then the -** ability is deactivated. After any changes, the integer is written with +** ability is deactivated. Any other initial value for the integer leaves the +** setting unchanged. After changes, if any, the integer is written with ** a 1 or 0, if the ability for VIEWs to have ROWIDs is on or off. If SQLite ** is compiled without -DSQLITE_ALLOW_ROWID_IN_VIEW (which is the usual and ** recommended case) then the integer is always filled with zero, regardless From 7128c789bd98dd06bd261107fb78803236af45b2 Mon Sep 17 00:00:00 2001 From: drh <> Date: Wed, 20 Mar 2024 10:40:25 +0000 Subject: [PATCH 264/430] Fix a typo in a comment. FossilOrigin-Name: 54680d0fbec1f0575ac4be6dca866971795dab2c42b02a492d5cd485f46d153f --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/build.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 2d322553b1..970e874f41 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\stypos\sin\sthe\sSQLITE_CONFIG_ROWID_IN_VIEW\sdocumentation. -D 2024-03-20T09:45:44.382 +C Fix\sa\stypo\sin\sa\scomment. +D 2024-03-20T10:40:25.308 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -692,7 +692,7 @@ F src/btmutex.c 79a43670447eacc651519a429f6ece9fd638563cf95b469d6891185ddae2b522 F src/btree.c 285b493d843e7ba8ef78b6ae7d31238e904901dbc0c484f7904de4cf18fd8802 F src/btree.h 55066f513eb095db935169dab1dc2f7c7a747ef223c533f5d4ad4dfed346cbd0 F src/btreeInt.h 98aadb6dcb77b012cab2574d6a728fad56b337fc946839b9898c4b4c969e30b6 -F src/build.c 71445e2d1e2c78b120a20a46d80a29a9ea42370df430efda5bb6ef377e8016c8 +F src/build.c fff536730a6d83120ae38d960f812b548394e8af6907249effb1764d69178106 F src/callback.c db3a45e376deff6a16c0058163fe0ae2b73a2945f3f408ca32cf74960b28d490 F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e F src/ctime.c 23331529e654be40ca97d171cbbffe9b3d4c71cc53b78fe5501230675952da8b @@ -2180,8 +2180,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 5d412edc2e378999ad798d1d7d73c7f7a17ee4e3c751a0dd00b9d5ce32759550 -R d82f649ee8e5d633f69feebd0d7bf101 +P 1ad1ca498296493c8e89cda911cc153baa51c90ae6c19961841e6b4e37302a23 +R 881bc9317ed9df88acd3db1968866969 U drh -Z ae521986bd186966a5bde1a9ef372fcb +Z 3ac48e6dcd121003681750f4a6450153 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 83e1223c29..753c2ed9a5 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1ad1ca498296493c8e89cda911cc153baa51c90ae6c19961841e6b4e37302a23 \ No newline at end of file +54680d0fbec1f0575ac4be6dca866971795dab2c42b02a492d5cd485f46d153f \ No newline at end of file diff --git a/src/build.c b/src/build.c index e7c23c173a..3ea35b331c 100644 --- a/src/build.c +++ b/src/build.c @@ -3007,7 +3007,7 @@ void sqlite3CreateView( ** setting fixes this problem. But the fix can be disabled by compiling ** with -DSQLITE_ALLOW_ROWID_IN_VIEW in case there are legacy apps that ** depend upon the old buggy behavior. The ability can also be toggled - ** using SQLITE_CONFIG_NO_ROWID_IN_VIEW */ + ** using sqlite3_config(SQLITE_CONFIG_ROWID_IN_VIEW,...) */ #ifdef SQLITE_ALLOW_ROWID_IN_VIEW p->tabFlags |= sqlite3Config.mNoVisibleRowid; /* Optional. Allow by default */ #else From e555bd4f0263b31e180e2bcc65703beed24011f9 Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 20 Mar 2024 16:27:08 +0000 Subject: [PATCH 265/430] Change EXPLAIN QUERY PLAN output to say "USE TEMP B-TREE FOR LAST TERM OF ORDER BY", or "LAST N TERMS OF ORDER BY", instead of "RIGHT PART OF ORDER BY". FossilOrigin-Name: cd547c500442f3f58c05d6da8a67c3238560c5204ea62ec14afa844cc8fb94f0 --- manifest | 27 +++++++++++++------------ manifest.uuid | 2 +- src/select.c | 14 +++++++++---- test/cost.test | 2 +- test/eqp.test | 6 +++--- test/eqp2.test | 49 ++++++++++++++++++++++++++++++++++++++++++++++ test/orderby1.test | 2 +- test/selectA.test | 4 ++-- 8 files changed, 82 insertions(+), 24 deletions(-) create mode 100644 test/eqp2.test diff --git a/manifest b/manifest index 5cf6262c5f..8c06159035 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\sSQLITE_ALLOW_ROWID_IN_VIEW\sbug-compatibility\soption\sso\sthat\sit\sworks\nagain.\s\sAdd\sthe\sSQLITE_CONFIG_ROWID_IN_VIEW\ssqlite3_config()\svalue\nto\soptionally\sdisable\sthe\sbug-compatibility\smode\sat\sstart-time.\s\sEnable\ntesting\sof\sSQLITE_ALLOW_ROWID_IN_VIEW. -D 2024-03-20T10:45:13.735 +C Change\sEXPLAIN\sQUERY\sPLAN\soutput\sto\ssay\s"USE\sTEMP\sB-TREE\sFOR\sLAST\sTERM\sOF\sORDER\sBY",\sor\s"LAST\sN\sTERMS\sOF\sORDER\sBY",\sinstead\sof\s"RIGHT\sPART\sOF\sORDER\sBY". +D 2024-03-20T16:27:08.690 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -750,7 +750,7 @@ F src/printf.c 87b67bba3662a0523f39ae6b084a3907109702f717c654d6cecb838af5cd57f1 F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c eb1860b134fb044fd819c4347105c148d5aac7c6498032be2829e5cc95619b28 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 -F src/select.c a83532bae45185f271b59babf715a31a831ac17e2b4bc061f52ee53825c688f1 +F src/select.c ced6678ead94c08d58cdb65cdda00a4871a3048e7834146f2a58ce71171808f8 F src/shell.c.in 0354ca51eee5fbf6af394a7ef9f5ef6823ef45b743db65431f6777e4d5be2199 F src/sqlite.h.in 41c5febd217b1e475aae022895c60f57fbe39ff6136450110662cfad67002d43 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 @@ -1022,7 +1022,7 @@ F test/corruptK.test 5b4212fe346699831c5ad559a62c54e11c0611bdde1ea8423a091f9c01a F test/corruptL.test 504d90502d9993440226edc355d2275524b89064ea3df5ee5c27f7028ec59d07 F test/corruptM.test 7d574320e08c1b36caa3e47262061f186367d593a7e305d35f15289cc2c3e067 F test/corruptN.test 7c099d153a554001b4fb829c799b01f2ea6276cbc32479131e0db0da4efd9cc4 -F test/cost.test b11cdbf9f11ffe8ef99c9881bf390e61fe92baf2182bad1dbe6de59a7295c576 +F test/cost.test cc434a026b1e9d0d98137a147e24e5daf1b1ad09e9ff7da63b34c83ddd136d92 F test/count.test cd4bd531066e8d77ef8fe1e3fc8253d042072e117ccab214b290cf83f1602249 F test/countofview.test 4088e461a10ee33e69803c177a69aa1d7bba81a9ffc2df66d76465a22ca7fdfc F test/coveridxscan.test f35c7208dedc4f98e471c569df64c0f95a49f6e072d8dc7c8f99bdee2697de1b @@ -1100,7 +1100,8 @@ F test/enc.test 9a7be5479da985381d740b15f432800f65e2c87029ee57a318f42cb2eb43763a F test/enc2.test 848bf05f15b011719f478dddb7b5e9aea35e39e457493cba4c4eef75d849a5ec F test/enc3.test 55ef64416d72975c66167310a51dc9fc544ba3ae4858b8d5ab22f4cb6500b087 F test/enc4.test c8f1ce3618508fd0909945beb8b8831feef2c020 -F test/eqp.test f3f7548d2f3df03e2f23ecaf35c7c2cc7b89848bd7c3606d94a010521b7ea4f6 +F test/eqp.test 3302598f611220a6c61e29d9b7bb62fd4a43504509b978dbabdb0b3e56ae3bc0 +F test/eqp2.test 6e8996148de88f0e7670491e92e712a2920a369b4406f21a27c3c9b6a46b68dd F test/errmsg.test eae9f091eb39ce7e20305de45d8e5d115b68fa856fba4ea6757b6ca3705ff7f9 F test/eval.test 73969a2d43a511bf44080c44485a8c4d796b6a4f038d19e491867081155692c0 F test/exclusive.test 7ff63be7503990921838d5c9f77f6e33e68e48ed1a9d48cd28745bf650bf0747 @@ -1467,7 +1468,7 @@ F test/openv2.test 0d3040974bf402e19b7df4b783e447289d7ab394 F test/optfuzz-db01.c 9f2fa80b8f84ebbf1f2e8b13421a4e0477fe300f6686fbd76cac1d2db66e0fdc F test/optfuzz-db01.txt 21f6bdeadc701cf11528276e2a55c70bfcb846ba42df327f979bd9e7b6ce7041 F test/optfuzz.c 690430a0bf0ad047d5a168bf52b05b2ee97aedaad8c14337e9eb5050faa64994 -F test/orderby1.test 02cfd870127a7342170b829175c5c53e9e7405744451ac1aeb2f7e2b0c18ca76 +F test/orderby1.test 7d0e4ee692a3e808c1026b3c483594ad1e468b68b50dcefa0d678a8c05274ceb F test/orderby2.test bc11009f7cd99d96b1b11e57b199b00633eb5b04 F test/orderby3.test 8619d06a3debdcd80a27c0fdea5c40b468854b99 F test/orderby4.test 4d39bfbaaa3ae64d026ca2ff166353d2edca4ba4 @@ -1578,7 +1579,7 @@ F test/select6.test 9b2fb4ffedf52e1b5703cfcae1212e7a4a063f014c0458d78d29aca3db76 F test/select7.test f659f231489349e8c5734e610803d7654207318f F test/select8.test 8c8f5ae43894c891efc5755ed905467d1d67ad5d F test/select9.test f7586b207ce2304ab80dc93d3146469a28fd4403621dd3a82d06644563d3c812 -F test/selectA.test 6aef8b2136a4ac7a3e2e4161d2b8ca7bc6ebe2779de084f9bb66ca9e2323a937 +F test/selectA.test 1da8ce3884c326e11d2855baffb76436b0d7e044404af8a2a70d1399a4ff7e29 F test/selectB.test 954e4e49cf1f896d61794e440669e03a27ceea25 F test/selectC.test 38c530b0cc5728b793c3c11f52b52c70290d39822224acd39011c89c1853bd31 F test/selectD.test 6d1909b49970bf92f45ce657505befcef5fc7cbc13544e18103a316d32189bfb @@ -2180,9 +2181,11 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 262f8f9d80d37160e4126634b99aa48fce2073e61f6365e8bdbe1cc4fa560a96 54680d0fbec1f0575ac4be6dca866971795dab2c42b02a492d5cd485f46d153f -R 1676f1a7037df308a062e51e2c63ab1f -T +closed 54680d0fbec1f0575ac4be6dca866971795dab2c42b02a492d5cd485f46d153f -U drh -Z 8bdaec16fb58072604ac6ea406b7bf1a +P b6802565df0f63286a7ef26c92d3ed817895f244920a24909cd855090fdfa08c +R 8123b01b9bcdf105a2e2ddc317d657f0 +T *branch * eqp-orderby +T *sym-eqp-orderby * +T -sym-trunk * +U dan +Z b979ee1c2ca7e0d90b1c38ab5826e1ad # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index b48a5a89de..310df97d77 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b6802565df0f63286a7ef26c92d3ed817895f244920a24909cd855090fdfa08c \ No newline at end of file +cd547c500442f3f58c05d6da8a67c3238560c5204ea62ec14afa844cc8fb94f0 \ No newline at end of file diff --git a/src/select.c b/src/select.c index 8d3c69ebb9..b539288e9d 100644 --- a/src/select.c +++ b/src/select.c @@ -1673,9 +1673,16 @@ static void generateSortTail( int addrExplain; /* Address of OP_Explain instruction */ #endif - ExplainQueryPlan2(addrExplain, (pParse, 0, - "USE TEMP B-TREE FOR %sORDER BY", pSort->nOBSat>0?"RIGHT PART OF ":"") - ); + nKey = pOrderBy->nExpr - pSort->nOBSat; + if( pSort->nOBSat==0 || nKey==1 ){ + ExplainQueryPlan2(addrExplain, (pParse, 0, + "USE TEMP B-TREE FOR %sORDER BY", pSort->nOBSat?"LAST TERM OF ":"" + )); + }else{ + ExplainQueryPlan2(addrExplain, (pParse, 0, + "USE TEMP B-TREE FOR LAST %d TERMS OF ORDER BY", nKey + )); + } sqlite3VdbeScanStatusRange(v, addrExplain,pSort->addrPush,pSort->addrPushEnd); sqlite3VdbeScanStatusCounters(v, addrExplain, addrExplain, pSort->addrPush); @@ -1713,7 +1720,6 @@ static void generateSortTail( regRow = sqlite3GetTempRange(pParse, nColumn); } } - nKey = pOrderBy->nExpr - pSort->nOBSat; if( pSort->sortFlags & SORTFLAG_UseSorter ){ int regSortOut = ++pParse->nMem; iSortTab = pParse->nTab++; diff --git a/test/cost.test b/test/cost.test index 5684177a13..6106caba8c 100644 --- a/test/cost.test +++ b/test/cost.test @@ -103,7 +103,7 @@ do_eqp_test 5.2 { } { QUERY PLAN |--SCAN t2 USING INDEX t2i1 - `--USE TEMP B-TREE FOR RIGHT PART OF ORDER BY + `--USE TEMP B-TREE FOR LAST TERM OF ORDER BY } do_eqp_test 5.3 { diff --git a/test/eqp.test b/test/eqp.test index 61fd617d89..cd441c271d 100644 --- a/test/eqp.test +++ b/test/eqp.test @@ -413,7 +413,7 @@ do_eqp_test 4.2.3 { | `--USE TEMP B-TREE FOR ORDER BY `--RIGHT |--SCAN t2 USING INDEX t2i1 - `--USE TEMP B-TREE FOR RIGHT PART OF ORDER BY + `--USE TEMP B-TREE FOR LAST 2 TERMS OF ORDER BY } do_eqp_test 4.2.4 { SELECT * FROM t1 INTERSECT SELECT * FROM t2 ORDER BY 1 @@ -425,7 +425,7 @@ do_eqp_test 4.2.4 { | `--USE TEMP B-TREE FOR ORDER BY `--RIGHT |--SCAN t2 USING INDEX t2i1 - `--USE TEMP B-TREE FOR RIGHT PART OF ORDER BY + `--USE TEMP B-TREE FOR LAST 2 TERMS OF ORDER BY } do_eqp_test 4.2.5 { SELECT * FROM t1 EXCEPT SELECT * FROM t2 ORDER BY 1 @@ -437,7 +437,7 @@ do_eqp_test 4.2.5 { | `--USE TEMP B-TREE FOR ORDER BY `--RIGHT |--SCAN t2 USING INDEX t2i1 - `--USE TEMP B-TREE FOR RIGHT PART OF ORDER BY + `--USE TEMP B-TREE FOR LAST 2 TERMS OF ORDER BY } do_eqp_test 4.3.1 { diff --git a/test/eqp2.test b/test/eqp2.test new file mode 100644 index 0000000000..3c634fc28a --- /dev/null +++ b/test/eqp2.test @@ -0,0 +1,49 @@ +# 2024 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. +# +#*********************************************************************** +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +set testprefix eqp2 + +do_execsql_test 1.0 { + CREATE TABLE t1(a, b, c, d); + CREATE INDEX i1 ON t1(a, b, c); +} + +do_eqp_test 1.1 { + SELECT * FROM t1 ORDER BY a, b, c +} { + QUERY PLAN + `--SCAN t1 USING INDEX i1 +} + + +do_eqp_test 1.2 { + SELECT * FROM t1 ORDER BY a, b, +c +} { + QUERY PLAN + |--SCAN t1 USING INDEX i1 + `--USE TEMP B-TREE FOR LAST TERM OF ORDER BY +} + +do_eqp_test 1.3 { + SELECT * FROM t1 ORDER BY a, +b, +c +} { + QUERY PLAN + |--SCAN t1 USING INDEX i1 + `--USE TEMP B-TREE FOR LAST 2 TERMS OF ORDER BY +} + +finish_test + + diff --git a/test/orderby1.test b/test/orderby1.test index 7432b5473d..41444a44c3 100644 --- a/test/orderby1.test +++ b/test/orderby1.test @@ -520,7 +520,7 @@ do_eqp_test 8.1 { } { QUERY PLAN |--SCAN t1 USING INDEX i1 - `--USE TEMP B-TREE FOR RIGHT PART OF ORDER BY + `--USE TEMP B-TREE FOR LAST TERM OF ORDER BY } do_execsql_test 8.2 { diff --git a/test/selectA.test b/test/selectA.test index 7d72bb3fa5..91b1548488 100644 --- a/test/selectA.test +++ b/test/selectA.test @@ -1340,10 +1340,10 @@ do_eqp_test 4.1.2 { `--MERGE (UNION ALL) |--LEFT | |--SCAN t5 USING INDEX i2 - | `--USE TEMP B-TREE FOR RIGHT PART OF ORDER BY + | `--USE TEMP B-TREE FOR LAST TERM OF ORDER BY `--RIGHT |--SCAN t4 USING INDEX i1 - `--USE TEMP B-TREE FOR RIGHT PART OF ORDER BY + `--USE TEMP B-TREE FOR LAST TERM OF ORDER BY } do_execsql_test 4.1.3 { From 296ae1e4673151e59593105b653e87eceae25163 Mon Sep 17 00:00:00 2001 From: drh <> Date: Thu, 21 Mar 2024 10:35:33 +0000 Subject: [PATCH 266/430] Fix all test cases so that they work with SQLITE_ALLOW_ROWID_IN_VIEW. FossilOrigin-Name: 66c69e2f20f7692e0f34743ae97b09c4d8d11b874cdc5381795f2d1e0410f724 --- manifest | 21 ++++++++++----------- manifest.uuid | 2 +- src/ctime.c | 3 +++ test/misc8.test | 7 ++++++- test/rowid.test | 2 +- tool/mkctimec.tcl | 1 + 6 files changed, 22 insertions(+), 14 deletions(-) diff --git a/manifest b/manifest index 64843591f9..0e4698a26a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Change\sEXPLAIN\sQUERY\sPLAN\soutput\sto\ssay\s"USE\sTEMP\sB-TREE\sFOR\sLAST\sTERM\sOF\sORDER\sBY",\sor\s"LAST\sN\sTERMS\sOF\sORDER\sBY",\sinstead\sof\s"RIGHT\sPART\sOF\sORDER\sBY". -D 2024-03-20T16:56:12.477 +C Fix\sall\stest\scases\sso\sthat\sthey\swork\swith\sSQLITE_ALLOW_ROWID_IN_VIEW. +D 2024-03-21T10:35:33.254 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -695,7 +695,7 @@ F src/btreeInt.h 98aadb6dcb77b012cab2574d6a728fad56b337fc946839b9898c4b4c969e30b F src/build.c fff536730a6d83120ae38d960f812b548394e8af6907249effb1764d69178106 F src/callback.c db3a45e376deff6a16c0058163fe0ae2b73a2945f3f408ca32cf74960b28d490 F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e -F src/ctime.c 23331529e654be40ca97d171cbbffe9b3d4c71cc53b78fe5501230675952da8b +F src/ctime.c 64e4b1227b4ed123146f0aa2989131d1fbd9b927b11e80c9d58c6a68f9cd5ce3 F src/date.c 126ba2ab10aeb2e7ba6e089b5f07b747c0625b8287f78b60da346eda8d23c875 F src/dbpage.c 80e46e1df623ec40486da7a5086cb723b0275a6e2a7b01d9f9b5da0f04ba2782 F src/dbstat.c 3b677254d512fcafd4d0b341bf267b38b235ccfddbef24f9154e19360fa22e43 @@ -1433,7 +1433,7 @@ F test/misc4.test 10cd6addb2fa9093df4751a1b92b50440175dd5468a6ec84d0386e78f087db F test/misc5.test 027cf0ac10314ea534173f335a33bb4059907ddabbac2c16786766d6f26c8923 F test/misc6.test 953cc693924d88e6117aeba16f46f0bf5abede91 F test/misc7.test d912f3d45c2989191b797504a220ca225d6be80b21acad22ba0d35f4a9ee4579 -F test/misc8.test 4db9f8be59834cea08c87e9658014080efa02678ef54a088f84fa5647e81fee0 +F test/misc8.test 08d2380bc435486b12161521f225043ac2be26f02471c2c1ea4cac0b1548edbd F test/misuse.test 9e7f78402005e833af71dcab32d048003869eca5abcaccc985d4f8dc1d86bcc7 F test/mjournal.test 28a08d5cb5fb5b5702a46e19176e45e964e0800d1f894677169e79f34030e152 F test/mmap1.test 18de3fd7b70a777af6004ca2feecfcdd3d0be17fa04058e808baf530c94b1a1d @@ -1536,7 +1536,7 @@ F test/rollbackfault.test 0e646aeab8840c399cfbfa43daab46fd609cf04a F test/round1.test 29c3c9039936ed024d672f003c4d35ee11c14c0acb75c5f7d6188ff16190cfd4 F test/rowallock.test 3f88ec6819489d0b2341c7a7528ae17c053ab7cc F test/rowhash.test 0bc1d31415e4575d10cacf31e1a66b5cc0f8be81 -F test/rowid.test aaa2572271edf58f8f88ac4d39f69e57ee5ae7a858332cdce9106e7cff8b7963 +F test/rowid.test d27191b5ce794c05bf61081e8b2c546a1844c1641321dcaf7fb785234256cc8e F test/rowvalue.test baf4fa3ec1a8c1c920c3faa5fd25959cb454bbd99ac8960397c34549d9fc4abe F test/rowvalue2.test 060d238b7e5639a7c5630cb5e63e311b44efef2b F test/rowvalue3.test 1347e25ca11c547c5a6ff0cc5626f95aa9740e9275bfaec096029f57cb2130ce @@ -2101,7 +2101,7 @@ F tool/max-limits.c cbb635fbb37ae4d05f240bfb5b5270bb63c54439 F tool/merge-test.tcl de76b62f2de2a92d4c1ca4f976bce0aea6899e0229e250479b229b2a1914b176 F tool/mkautoconfamal.sh cbdcf993fa83dccbef7fb77b39cdeb31ef9f77d9d88c9e343b58d35ca3898a6a F tool/mkccode.tcl 86463e68ce9c15d3041610fedd285ce32a5cf7a58fc88b3202b8b76837650dbe x -F tool/mkctimec.tcl a16682eae5f01f85e5861b2aa215ca0d46b4230658ee25977e02b4508566fb75 x +F tool/mkctimec.tcl 060e9785e9503bf51f8b1b11b542bdeef90fd0ceb0738154f6762acec0c61e5f x F tool/mkkeywordhash.c b9faa0ae7e14e4dbbcd951cddd786bf46b8a65bb07b129ba8c0cfade723aaffd F tool/mkmsvcmin.tcl 8897d515ef7f94772322db95a3b6fce6c614d84fe0bdd06ba5a1c786351d5a1d F tool/mkopcodec.tcl 33d20791e191df43209b77d37f0ff0904620b28465cca6990cf8d60da61a07ef @@ -2181,9 +2181,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P b6802565df0f63286a7ef26c92d3ed817895f244920a24909cd855090fdfa08c cd547c500442f3f58c05d6da8a67c3238560c5204ea62ec14afa844cc8fb94f0 -R 8123b01b9bcdf105a2e2ddc317d657f0 -T +closed cd547c500442f3f58c05d6da8a67c3238560c5204ea62ec14afa844cc8fb94f0 -U dan -Z cfb92556c121157a43b1e3903f143f16 +P 7e13a2c7583dbcb660adde6b0465da037365971c56726b8f18a541d8803ffeed +R 2027b60f20ab6be3fc26d73a48e5361c +U drh +Z 4767141a590293471cedda2bdaf01e5d # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 800ecf82c9..423f236b45 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7e13a2c7583dbcb660adde6b0465da037365971c56726b8f18a541d8803ffeed \ No newline at end of file +66c69e2f20f7692e0f34743ae97b09c4d8d11b874cdc5381795f2d1e0410f724 \ No newline at end of file diff --git a/src/ctime.c b/src/ctime.c index cf761299fe..0ffe2a5bdf 100644 --- a/src/ctime.c +++ b/src/ctime.c @@ -65,6 +65,9 @@ static const char * const sqlite3azCompileOpt[] = { "ALLOW_COVERING_INDEX_SCAN=" CTIMEOPT_VAL(SQLITE_ALLOW_COVERING_INDEX_SCAN), # endif #endif +#ifdef SQLITE_ALLOW_ROWID_IN_VIEW + "ALLOW_ROWID_IN_VIEW", +#endif #ifdef SQLITE_ALLOW_URI_AUTHORITY "ALLOW_URI_AUTHORITY", #endif diff --git a/test/misc8.test b/test/misc8.test index 32b3a597dc..60b44fe1c7 100644 --- a/test/misc8.test +++ b/test/misc8.test @@ -100,6 +100,11 @@ do_execsql_test misc8-2.1 { # 2016-02-26: An assertion fault found by the libFuzzer project # +ifcapable allow_rowid_in_view { + set nosuch "1 {ambiguous column name: rowid}" +} else { + set nosuch "1 {no such column: rowid}" +} do_catchsql_test misc8-3.0 { SELECT * FROM @@ -110,7 +115,7 @@ do_catchsql_test misc8-3.0 { (SELECT 6 AS j UNION ALL SELECT 7) AS x4 WHERE i Date: Thu, 21 Mar 2024 11:37:36 +0000 Subject: [PATCH 267/430] Have os_unix.c reuse cached file-descriptors in the case when a read-write fd is requested on a read-only file and a read-only fd returned. FossilOrigin-Name: a678e85402af08c1e387bf30ff2205f84dd7da749755da565d70f831c007a3d9 --- manifest | 15 +++++++------ manifest.uuid | 2 +- src/os_unix.c | 9 +++++++- test/readonly.test | 54 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+), 9 deletions(-) create mode 100644 test/readonly.test diff --git a/manifest b/manifest index 0e4698a26a..d352d9cc2b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sall\stest\scases\sso\sthat\sthey\swork\swith\sSQLITE_ALLOW_ROWID_IN_VIEW. -D 2024-03-21T10:35:33.254 +C Have\sos_unix.c\sreuse\scached\sfile-descriptors\sin\sthe\scase\swhen\sa\sread-write\sfd\sis\srequested\son\sa\sread-only\sfile\sand\sa\sread-only\sfd\sreturned. +D 2024-03-21T11:37:36.346 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -734,7 +734,7 @@ F src/os.h 1ff5ae51d339d0e30d8a9d814f4b8f8e448169304d83a7ed9db66a65732f3e63 F src/os_common.h 6c0eb8dd40ef3e12fe585a13e709710267a258e2c8dd1c40b1948a1d14582e06 F src/os_kv.c 4d39e1f1c180b11162c6dc4aa8ad34053873a639bac6baae23272fc03349986a F src/os_setup.h 6011ad7af5db4e05155f385eb3a9b4470688de6f65d6166b8956e58a3d872107 -F src/os_unix.c 8d7533b3b4d0d2d6ddd34d1ebc92f50a91f04e722a3a9295a000bc3c25128e2f +F src/os_unix.c 6227cbc4ac93046f121436886cf3712da6f4e2082af6314f976eeae1d86b794a F src/os_win.c 6ff43bac175bd9ed79e7c0f96840b139f2f51d01689a638fd05128becf94908a F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a F src/pager.c ff60e98138d2499082ac6230f01ac508aba545315debccfca2fd6042f5f10fcd @@ -1522,6 +1522,7 @@ F test/randexpr1.tcl 40dec52119ed3a2b8b2a773bce24b63a3a746459 F test/randexpr1.test eda062a97e60f9c38ae8d806b03b0ddf23d796df F test/rbu.test 168573d353cd0fd10196b87b0caa322c144ef736 F test/rdonly.test 64e2696c322e3538df0b1ed624e21f9a23ed9ff8 +F test/readonly.test bdf5a451f415bc3153764122d034f553797c27194ffbd1e9763ecd9500af41d2 F test/recover.test 6463509a7404e0c35431dd9b4a1c3b4a29d7a6af8a08462b31670c8a5a616d3a F test/regexp1.test 8f2a8bc1569666e29a4cee6c1a666cd224eb6d50e2470d1dc1df995170f3e0f1 F test/regexp2.test 55ed41da802b0e284ac7e2fe944be3948f93ff25abbca0361a609acfed1368b5 @@ -2181,8 +2182,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 7e13a2c7583dbcb660adde6b0465da037365971c56726b8f18a541d8803ffeed -R 2027b60f20ab6be3fc26d73a48e5361c -U drh -Z 4767141a590293471cedda2bdaf01e5d +P 66c69e2f20f7692e0f34743ae97b09c4d8d11b874cdc5381795f2d1e0410f724 +R 41345a246cf3c264839b8ebe82b82196 +U dan +Z d2317639297bfb820720d835feec7e58 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 423f236b45..ac95fcbf05 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -66c69e2f20f7692e0f34743ae97b09c4d8d11b874cdc5381795f2d1e0410f724 \ No newline at end of file +a678e85402af08c1e387bf30ff2205f84dd7da749755da565d70f831c007a3d9 \ No newline at end of file diff --git a/src/os_unix.c b/src/os_unix.c index 4663c22d94..9e7ba05d68 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -6398,12 +6398,19 @@ static int unixOpen( rc = SQLITE_READONLY_DIRECTORY; }else if( errno!=EISDIR && isReadWrite ){ /* Failed to open the file for read/write access. Try read-only. */ + UnixUnusedFd *pReadonly = 0; flags &= ~(SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE); openFlags &= ~(O_RDWR|O_CREAT); flags |= SQLITE_OPEN_READONLY; openFlags |= O_RDONLY; isReadonly = 1; - fd = robust_open(zName, openFlags, openMode); + pReadonly = findReusableFd(zName, flags); + if( pReadonly ){ + fd = pReadonly->fd; + sqlite3_free(pReadonly); + }else{ + fd = robust_open(zName, openFlags, openMode); + } } } if( fd<0 ){ diff --git a/test/readonly.test b/test/readonly.test new file mode 100644 index 0000000000..811d54f3b5 --- /dev/null +++ b/test/readonly.test @@ -0,0 +1,54 @@ +# 2024 March 21 +# +# 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 contains tests for using databases in read-only mode on +# unix. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/lock_common.tcl +source $testdir/wal_common.tcl +set ::testprefix readonly + +do_execsql_test 1.0 { + CREATE TABLE t1(a, b); + INSERT INTO t1 VALUES(1, 2), (3, 4), (5, 6); +} + +db close +file attributes test.db -permissions r--r--r-- + +sqlite3 db test.db + +do_catchsql_test 1.1 { + INSERT INTO t1 VALUES(7, 8); +} {1 {attempt to write a readonly database}} + +do_execsql_test 1.2 { + BEGIN; + SELECT * FROM t1; +} {1 2 3 4 5 6} + +# The following attempts to open a read/write fd on the database 20,000 +# times. And each time instead opens a read-only fd. At one point this +# was failing to reuse cached fds, causing a "too many open file-descriptors" +# error. +do_test 1.3 { + for {set ii 0} {$ii < 20000} {incr ii} { + sqlite3 db2 test.db + db2 close + } + set {} {} +} {} + + +finish_test From 529ed1a3a3b1a32fa1343e0466f627870cffbfb6 Mon Sep 17 00:00:00 2001 From: drh <> Date: Thu, 21 Mar 2024 11:46:52 +0000 Subject: [PATCH 268/430] Enhancements to testrunner.tcl: (1) Add the "--config CONFIGS" option, to that only configuration named on the comma-separated list CONFIGS are run. (2) Add the "--omit CONFIGS" to omit configuration on the CONFIGS list (3) Add the Android configuration to "release" FossilOrigin-Name: 4ccb372967fab779b29be8f01c879a99ef247981466f81f55e18e3961fbd7d5a --- manifest | 18 +++++++++--------- manifest.uuid | 2 +- test/sessionfuzz.c | 1 + test/testrunner.tcl | 28 +++++++++++++++++++--------- test/testrunner_data.tcl | 36 ++++++++++++++++++++++++++++++++++++ 5 files changed, 66 insertions(+), 19 deletions(-) diff --git a/manifest b/manifest index d352d9cc2b..3f732c3abd 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Have\sos_unix.c\sreuse\scached\sfile-descriptors\sin\sthe\scase\swhen\sa\sread-write\sfd\sis\srequested\son\sa\sread-only\sfile\sand\sa\sread-only\sfd\sreturned. -D 2024-03-21T11:37:36.346 +C Enhancements\sto\stestrunner.tcl:\n(1)\sAdd\sthe\s"--config\sCONFIGS"\soption,\sto\sthat\sonly\sconfiguration\snamed\non\sthe\scomma-separated\slist\sCONFIGS\sare\srun.\n(2)\sAdd\sthe\s"--omit\sCONFIGS"\sto\somit\sconfiguration\son\sthe\sCONFIGS\slist\n(3)\sAdd\sthe\sAndroid\sconfiguration\sto\s"release" +D 2024-03-21T11:46:52.796 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -1590,7 +1590,7 @@ F test/selectG.test 089f7d3d7e6db91566f00b036cb353107a2cca6220eb1cb264085a836dae F test/selectH.test 0b54599f1917d99568c9b929df22ec6261ed7b6d2f02a46b5945ef81b7871aac F test/session.test 78fa2365e93d3663a6e933f86e7afc395adf18be F test/sessionfuzz-data1.db 1f8d5def831f19b1c74571037f0d53a588ea49a6c4ca2a028fc0c27ef896dbcb -F test/sessionfuzz.c 666b47e177c7b25f01ba645d41fb9131d2d54ae673f0d81c08f5af2b3e6ecbda +F test/sessionfuzz.c f693b8827034a3bed7616d89c65fb4fe8b7ff3c0f000c6ea6beda69b7f1aced3 F test/shared.test f022874d9d299fe913529dc10f52ad5a386e4e7ff709270b9b1111b3a0f3420a F test/shared2.test 03eb4a8d372e290107d34b6ce1809919a698e879 F test/shared3.test f8cd07c1a2b7cdb315c01671a0b2f8e3830b11ef31da6baa9a9cd8da88965403 @@ -1690,8 +1690,8 @@ F test/temptable2.test 76821347810ecc88203e6ef0dd6897b6036ac788e9dd3e6b04fd4d163 F test/temptable3.test d11a0974e52b347e45ee54ef1923c91ed91e4637 F test/temptrigger.test 38f0ca479b1822d3117069e014daabcaacefffcc F test/tester.tcl fe617b88c7eb08bdf983d2aaa31c20fbf439eee7b8e0d61ca636fcd0c305bbbf -F test/testrunner.tcl 01bc3b5bc900dc73b076180727eb2869dc61426b1ab95ac2f42def5d1f3d407e -F test/testrunner_data.tcl 7032a64e4757db0bf83c6874cab2ccbb14a8708b4d68c1ddc8b359e204139cb7 +F test/testrunner.tcl b48a8fc17e3b200244f53d60348afa7fe9482400d164e95709890743af9536d0 +F test/testrunner_data.tcl 3d36660cfd55ea5e20e661e8f94c0520feebcb437848f9b98b33c483cc479c0c F test/thread001.test a0985c117eab62c0c65526e9fa5d1360dd1cac5b03bde223902763274ce21899 F test/thread002.test c24c83408e35ba5a952a3638b7ac03ccdf1ce4409289c54a050ac4c5f1de7502 F test/thread003.test ee4c9efc3b86a6a2767516a37bd64251272560a7 @@ -2182,8 +2182,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 66c69e2f20f7692e0f34743ae97b09c4d8d11b874cdc5381795f2d1e0410f724 -R 41345a246cf3c264839b8ebe82b82196 -U dan -Z d2317639297bfb820720d835feec7e58 +P a678e85402af08c1e387bf30ff2205f84dd7da749755da565d70f831c007a3d9 +R 2c6a53e503eb513e49b4f3899bff37cd +U drh +Z 89d0196ee33d74016c89e304cba255b3 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index ac95fcbf05..09d6bad378 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a678e85402af08c1e387bf30ff2205f84dd7da749755da565d70f831c007a3d9 \ No newline at end of file +4ccb372967fab779b29be8f01c879a99ef247981466f81f55e18e3961fbd7d5a \ No newline at end of file diff --git a/test/sessionfuzz.c b/test/sessionfuzz.c index 093c2b043d..c389a5e996 100644 --- a/test/sessionfuzz.c +++ b/test/sessionfuzz.c @@ -60,6 +60,7 @@ #define SQLITE_DEBUG 1 #define SQLITE_THREADSAFE 0 +#undef SQLITE_OMIT_LOAD_EXTENSION #define SQLITE_OMIT_LOAD_EXTENSION 0 #define SQLITE_ENABLE_SESSION 1 #define SQLITE_ENABLE_PREUPDATE_HOOK 1 diff --git a/test/testrunner.tcl b/test/testrunner.tcl index e8570ddf19..05f7d4cc98 100644 --- a/test/testrunner.tcl +++ b/test/testrunner.tcl @@ -60,13 +60,15 @@ Usage: $a0 status where SWITCHES are: - --buildonly - --dryrun - --explain - --jobs NUMBER-OF-JOBS - --stop-on-coredump - --stop-on-error - --zipvfs ZIPVFS-SOURCE-DIR + --buildonly Build test exes but do not run tests + --config CONFIGS Only use configs on comma-separate list CONFIGS + --dryrun Write what would have happened to testrunner.log + --explain Write summary to stdout + --jobs NUM Run tests using NUM separate processes + --omit CONFIGS Omit configs on comma-separated list CONFIGS + --stop-on-coredump Stop running if any test segfaults + --stop-on-error Stop running after any reported error + --zipvfs ZIPVFSDIR ZIPVFS source directory Special values for PERMUTATION that work with plain tclsh: @@ -172,6 +174,8 @@ set TRG(reporttime) 2000 set TRG(fuzztest) 0 ;# is the fuzztest option present. set TRG(zipvfs) "" ;# -zipvfs option, if any set TRG(buildonly) 0 ;# True if --buildonly option +set TRG(config) {} ;# Only build the named configurations +set TRG(omitconfig) {} ;# Do not build these configurations set TRG(dryrun) 0 ;# True if --dryrun option set TRG(explain) 0 ;# True for the --explain option set TRG(stopOnError) 0 ;# Stop running at first failure @@ -468,10 +472,16 @@ for {set ii 0} {$ii < [llength $argv]} {incr ii} { if {$isLast} { usage } } elseif {($n>2 && [string match "$a*" --buildonly]) || $a=="-b"} { set TRG(buildonly) 1 + } elseif {($n>2 && [string match "$a*" --config]) || $a=="-c"} { + incr ii + set TRG(config) [lindex $argv $ii] } elseif {($n>2 && [string match "$a*" --dryrun]) || $a=="-d"} { set TRG(dryrun) 1 } elseif {($n>2 && [string match "$a*" --explain]) || $a=="-e"} { set TRG(explain) 1 + } elseif {($n>2 && [string match "$a*" --omit]) || $a=="-c"} { + incr ii + set TRG(omitconfig) [lindex $argv $ii] } elseif {[string match "$a*" --stop-on-error]} { set TRG(stopOnError) 1 } elseif {[string match "$a*" --stop-on-coredump]} { @@ -485,8 +495,6 @@ for {set ii 0} {$ii < [llength $argv]} {incr ii} { } set argv [list] - - # This script runs individual tests - tcl scripts or [make xyz] commands - # in directories named "testdir$N", where $N is an integer. This variable # contains a list of integers indicating the directories in use. @@ -911,6 +919,8 @@ proc add_jobs_from_cmdline {patternlist} { release { set patternlist [lrange $patternlist 1 end] foreach b [trd_builds $TRG(platform)] { + if {$TRG(config)!="" && ![regexp "\\y$b\\y" $TRG(config)]} continue + if {[regexp "\\y$b\\y" $TRG(omitconfig)]} continue set bld [add_build_job $b $TRG(testfixture)] foreach c [trd_configs $TRG(platform) $b] { add_tcl_jobs $bld $c $patternlist diff --git a/test/testrunner_data.tcl b/test/testrunner_data.tcl index 73b5472a99..f8f12d91a7 100644 --- a/test/testrunner_data.tcl +++ b/test/testrunner_data.tcl @@ -23,6 +23,7 @@ namespace eval trd { set tcltest(linux.No-lookaside) veryquick set tcltest(linux.Devkit) veryquick set tcltest(linux.Apple) veryquick + set tcltest(linux.Android) veryquick set tcltest(linux.Sanitize) veryquick set tcltest(linux.Device-One) all set tcltest(linux.Default) all_plus_autovacuum_crash @@ -53,6 +54,7 @@ namespace eval trd { set extra(linux.Device-Two) {fuzztest sourcetest threadtest} set extra(linux.No-lookaside) {fuzztest sourcetest} set extra(linux.Devkit) {fuzztest sourcetest} + set extra(linux.Android) {fuzztest sourcetest} set extra(linux.Apple) {fuzztest sourcetest} set extra(linux.Sanitize) {fuzztest sourcetest} set extra(linux.Default) {fuzztest sourcetest threadtest} @@ -246,6 +248,40 @@ namespace eval trd { -O2 -DSQLITE_ENABLE_LOCKING_STYLE=1 } + set build(Android) { + -Os + -DHAVE_USLEEP=1 + -DSQLITE_HAVE_ISNAN + -DSQLITE_POWERSAFE_OVERWRITE=1 + -DSQLITE_DEFAULT_FILE_FORMAT=4 + -DSQLITE_DEFAULT_AUTOVACUUM=1 + -DSQLITE_ENABLE_MEMORY_MANAGEMENT=1 + -DSQLITE_ENABLE_FTS3 + -DSQLITE_ENABLE_FTS3_BACKWARDS + -DSQLITE_ENABLE_FTS4 + -DSQLITE_SECURE_DELETE + -DSQLITE_ENABLE_BATCH_ATOMIC_WRITE + -DBIONIC_IOCTL_NO_SIGNEDNESS_OVERLOAD + -DSQLITE_ALLOW_ROWID_IN_VIEW + -DSQLITE_ENABLE_BYTECODE_VTAB + -Wno-unused-parameter + -Werror + -DUSE_PREAD64 + -Dfdatasync=fdatasync + -DHAVE_MALLOC_H=1 + -DHAVE_MALLOC_USABLE_SIZE + -DSQLITE_ENABLE_DBSTAT_VTAB + } + # Compile-options used by Android but omitted from these + # tests: + # -DNDEBUG=1 + # -DSQLITE_DEFAULT_LEGACY_ALTER_TABLE + # -DSQLITE_DEFAULT_JOURNAL_SIZE_LIMIT=1048576 + # -DSQLITE_DEFAULT_FILE_PERMISSIONS=0600 + # -DSQLITE_OMIT_BUILTIN_TEST + # -DSQLITE_OMIT_LOAD_EXTENSION + # -DSQLITE_OMIT_COMPILEOPTION_DIAGS + # set build(Apple) { -Os -DHAVE_GMTIME_R=1 From 006a9b51aa5fcb636325587d28b17474148bb41e Mon Sep 17 00:00:00 2001 From: stephan Date: Thu, 21 Mar 2024 15:52:52 +0000 Subject: [PATCH 269/430] Add comments (only, no code) to the JS sqlite3_config() bindings reminding us why SQLITE_CONFIG_ROWID_IN_VIEW is specifically not included. JNI does not need this treatment because it explicitly supports only a very small subset of config options. FossilOrigin-Name: 4fea396221e84f9532f9327226691621a23bd966a860329fc579141c69cf7f64 --- ext/wasm/api/sqlite3-api-glue.js | 4 ++++ ext/wasm/api/sqlite3-wasm.c | 4 ++++ manifest | 16 ++++++++-------- manifest.uuid | 2 +- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/ext/wasm/api/sqlite3-api-glue.js b/ext/wasm/api/sqlite3-api-glue.js index 2cb4c800d2..b05d7a765a 100644 --- a/ext/wasm/api/sqlite3-api-glue.js +++ b/ext/wasm/api/sqlite3-api-glue.js @@ -1547,6 +1547,10 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ case capi.SQLITE_CONFIG_SQLLOG: // 21 /* xSqllog, void* */ case capi.SQLITE_CONFIG_WIN32_HEAPSIZE: // 23 /* int nByte */ default: + /* maintenance note: we specifically do not include + SQLITE_CONFIG_ROWID_IN_VIEW here, on the grounds that + it's only for legacy support and no apps written with + this API require that. */ return capi.SQLITE_NOTFOUND; } }; diff --git a/ext/wasm/api/sqlite3-wasm.c b/ext/wasm/api/sqlite3-wasm.c index bd0eb884c9..cc1db6723a 100644 --- a/ext/wasm/api/sqlite3-wasm.c +++ b/ext/wasm/api/sqlite3-wasm.c @@ -545,6 +545,10 @@ const char * sqlite3__wasm_enum_json(void){ DefInt(SQLITE_CONFIG_SMALL_MALLOC); DefInt(SQLITE_CONFIG_SORTERREF_SIZE); DefInt(SQLITE_CONFIG_MEMDB_MAXSIZE); + /* maintenance note: we specifically do not include + SQLITE_CONFIG_ROWID_IN_VIEW here, on the grounds that + it's only for legacy support and no apps written with + this API require that. */ } _DefGroup; DefGroup(dataTypes) { diff --git a/manifest b/manifest index 3f732c3abd..de98d45464 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Enhancements\sto\stestrunner.tcl:\n(1)\sAdd\sthe\s"--config\sCONFIGS"\soption,\sto\sthat\sonly\sconfiguration\snamed\non\sthe\scomma-separated\slist\sCONFIGS\sare\srun.\n(2)\sAdd\sthe\s"--omit\sCONFIGS"\sto\somit\sconfiguration\son\sthe\sCONFIGS\slist\n(3)\sAdd\sthe\sAndroid\sconfiguration\sto\s"release" -D 2024-03-21T11:46:52.796 +C Add\scomments\s(only,\sno\scode)\sto\sthe\sJS\ssqlite3_config()\sbindings\sreminding\sus\swhy\sSQLITE_CONFIG_ROWID_IN_VIEW\sis\sspecifically\snot\sincluded.\sJNI\sdoes\snot\sneed\sthis\streatment\sbecause\sit\sexplicitly\ssupports\sonly\sa\svery\ssmall\ssubset\sof\sconfig\soptions. +D 2024-03-21T15:52:52.021 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -605,7 +605,7 @@ F ext/wasm/api/post-js-footer.js cd0a8ec768501d9bd45d325ab0442037fb0e33d1f3b4f08 F ext/wasm/api/post-js-header.js 04dc12c3edd666b64a1b4ef3b6690c88dcc653f26451fd4734472d8e29c1c122 F ext/wasm/api/pre-js.c-pp.js ad906703f7429590f2fbf5e6498513bf727a1a4f0ebfa057afb08161d7511219 F ext/wasm/api/sqlite3-api-cleanup.js d235ad237df6954145404305040991c72ef8b1881715d2a650dda7b3c2576d0e -F ext/wasm/api/sqlite3-api-glue.js 587dc6db2d69329a5f4cb9635c377f516cf4a8e30f443f33380e5044889ec71b +F ext/wasm/api/sqlite3-api-glue.js 2d35660c52dcb4bb16d00c56553d34e7caa6ad30083938b515e6f9aa0b312fbb F ext/wasm/api/sqlite3-api-oo1.js 7f3bcf0549ac44cde4b9da0b642d771916738d3f6781fb8a1757c50a91e506c0 F ext/wasm/api/sqlite3-api-prologue.js 93a72b07b2a5d964d2edc76a90b439ece49298bd7ba60a1c6ae5d4878213701e F ext/wasm/api/sqlite3-api-worker1.js 8d9c0562831f62218170a3373468d8a0b7a6503b5985e309b69bf71187b525cf @@ -615,7 +615,7 @@ F ext/wasm/api/sqlite3-vfs-helper.c-pp.js 3f828cc66758acb40e9c5b4dcfd87fd478a14c F ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js 5a430874906ff3f4a6ca69aadf0c2aaedc1bb45489b8365bff7e955a83a8d42a F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js 3c72f1a0e6a7343c8c882d29d01bb440f10be12c844651605b486e76f3d6cc8c F ext/wasm/api/sqlite3-vtab-helper.c-pp.js a2fcbc3fecdd0eea229283584ebc122f29d98194083675dbe5cb2cf3a17fe309 -F ext/wasm/api/sqlite3-wasm.c d33a16495ca871781e78812d3a18fed78b797468fffee657b8d7199b277ff359 +F ext/wasm/api/sqlite3-wasm.c afba6827a49151b564af5cf588a6bbd0401b16ef5cbe3269c66f676fee9ca92c F ext/wasm/api/sqlite3-worker1-promiser.c-pp.js bd89edfe42a4d7122a6d6d405c5423cf00aabba1f76f6ea8e2dba9c628ddd91a F ext/wasm/api/sqlite3-worker1.c-pp.js 5e8706c2c4af2a57fbcdc02f4e7ef79869971bc21bb8ede777687786ce1c92d5 F ext/wasm/batch-runner-sahpool.html e9a38fdeb36a13eac7b50241dfe7ae066fe3f51f5c0b0151e7baee5fce0d07a7 @@ -2182,8 +2182,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P a678e85402af08c1e387bf30ff2205f84dd7da749755da565d70f831c007a3d9 -R 2c6a53e503eb513e49b4f3899bff37cd -U drh -Z 89d0196ee33d74016c89e304cba255b3 +P 4ccb372967fab779b29be8f01c879a99ef247981466f81f55e18e3961fbd7d5a +R ea9e20b51710635b69a86f29c94e13a1 +U stephan +Z 968d86b7461df92ba4077d882e3cd299 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 09d6bad378..15f1e0f519 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4ccb372967fab779b29be8f01c879a99ef247981466f81f55e18e3961fbd7d5a \ No newline at end of file +4fea396221e84f9532f9327226691621a23bd966a860329fc579141c69cf7f64 \ No newline at end of file From 2faaf3830efc93db406d6a58c837ad87f49e95db Mon Sep 17 00:00:00 2001 From: drh <> Date: Thu, 21 Mar 2024 22:18:24 +0000 Subject: [PATCH 270/430] Test case for the assert() problem fixed by [9ba3cff9d48fe8fc]. FossilOrigin-Name: 865f0de7a17ce6059b8f0708002cff5f13b9dba3ebc41896ee0fdc21ae4f3740 --- manifest | 14 +++++++------- manifest.uuid | 2 +- test/default.test | 4 ++++ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index de98d45464..3a62236ed9 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\scomments\s(only,\sno\scode)\sto\sthe\sJS\ssqlite3_config()\sbindings\sreminding\sus\swhy\sSQLITE_CONFIG_ROWID_IN_VIEW\sis\sspecifically\snot\sincluded.\sJNI\sdoes\snot\sneed\sthis\streatment\sbecause\sit\sexplicitly\ssupports\sonly\sa\svery\ssmall\ssubset\sof\sconfig\soptions. -D 2024-03-21T15:52:52.021 +C Test\scase\sfor\sthe\sassert()\sproblem\sfixed\sby\s[9ba3cff9d48fe8fc]. +D 2024-03-21T22:18:24.397 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -1057,7 +1057,7 @@ F test/dbpagefault.test 35f06cfb2ef100a9b19d25754e8141b9cba9b7daabd4c60fa5af93fc F test/dbstatus.test 4a4221a883025ffd39696b3d1b3910b928fb097d77e671351acb35f3aed42759 F test/dbstatus2.test f5fe0afed3fa45e57cfa70d1147606c20d2ba23feac78e9a172f2fe8ab5b78ef F test/decimal.test ef731887b43ee32ef86e1c8fddb61a40789f988332c029c601dcf2c319277e9e -F test/default.test 9687cfb16717e4b8238c191697c98be88c0b16e568dd5368cd9284154097ef50 +F test/default.test 830fad7180cdf0e6a06e93acc0403bf73762314a639363314db5674c631b6127 F test/delete.test 2686e1c98d552ef37d79ad55b17b93fe96fad9737786917ce3839767f734c48f F test/delete2.test 3a03f2cca1f9a67ec469915cb8babd6485db43fa F test/delete3.test 555e84a00a99230b7d049d477a324a631126a6ab @@ -2182,8 +2182,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 4ccb372967fab779b29be8f01c879a99ef247981466f81f55e18e3961fbd7d5a -R ea9e20b51710635b69a86f29c94e13a1 -U stephan -Z 968d86b7461df92ba4077d882e3cd299 +P 4fea396221e84f9532f9327226691621a23bd966a860329fc579141c69cf7f64 +R 1d5390331fd847f868d4cf4de5871522 +U drh +Z 2f8691d3650feb9b039ca6336d443329 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 15f1e0f519..120c9883b8 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4fea396221e84f9532f9327226691621a23bd966a860329fc579141c69cf7f64 \ No newline at end of file +865f0de7a17ce6059b8f0708002cff5f13b9dba3ebc41896ee0fdc21ae4f3740 \ No newline at end of file diff --git a/test/default.test b/test/default.test index 06a180c1de..de67f643b4 100644 --- a/test/default.test +++ b/test/default.test @@ -136,5 +136,9 @@ do_catchsql_test default-5.1 { CREATE TABLE t1 (a,b DEFAULT(random() NOTNULL IN (RAISE(IGNORE),2,3))); INSERT INTO t1(a) VALUES(1); } {1 {RAISE() may only be used within a trigger-program}} +do_catchsql_test default-5.2 { + CREATE TABLE Table0 (Col0 DEFAULT (RAISE(IGNORE) ) ) ; + INSERT INTO Table0 DEFAULT VALUES ; +} {1 {RAISE() may only be used within a trigger-program}} finish_test From 378bf82e2bc09734b8c5869f9b148efe37d29527 Mon Sep 17 00:00:00 2001 From: drh <> Date: Fri, 22 Mar 2024 10:32:14 +0000 Subject: [PATCH 271/430] Fix incorrect boundary assert()s on the new OP_IfSizeBetween opcode. FossilOrigin-Name: 8eda4797c573382cbb989a4ab4b1f19d8fd538dbc9818d86a9aa6189cfa90f37 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/vdbe.c | 7 ++++--- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 3a62236ed9..2210416533 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Test\scase\sfor\sthe\sassert()\sproblem\sfixed\sby\s[9ba3cff9d48fe8fc]. -D 2024-03-21T22:18:24.397 +C Fix\sincorrect\sboundary\sassert()s\son\sthe\snew\sOP_IfSizeBetween\sopcode. +D 2024-03-22T10:32:14.835 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -820,7 +820,7 @@ F src/upsert.c 2e60567a0e9e8520c18671b30712a88dc73534474304af94f32bb5f3ef65ac65 F src/utf.c f23165685a67b4caf8ec08fb274cb3f319103decfb2a980b7cfd55d18dfa855e F src/util.c 4d6d7ebfe6772a1b950c97bbb1d1a72ad4874617ec498ab8aa73b7f5a43e44bb F src/vacuum.c 604fcdaebe76f3497c855afcbf91b8fa5046b32de3045bab89cc008d68e40104 -F src/vdbe.c da8407be6055f5751bf85681542d130a320b4fd1f4d8719bf83a464743d9aae4 +F src/vdbe.c 651aa0f31027d5d0a133eb7b41d11c41dc3b88ecb760b770430da0e477ae3b6c F src/vdbe.h c2d78d15112c3fc5ab87f5e8e0b75d2db1c624409de2e858c3d1aafb1650bb4f F src/vdbeInt.h 949669dfd8a41550d27dcb905b494f2ccde9a2e6c1b0b04daa1227e2e74c2b2c F src/vdbeapi.c 8f57d60c89da0b60e6d4e272358c511f6bae4e24330bdb11f8b42f986d1bf21b @@ -2182,8 +2182,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 4fea396221e84f9532f9327226691621a23bd966a860329fc579141c69cf7f64 -R 1d5390331fd847f868d4cf4de5871522 +P 865f0de7a17ce6059b8f0708002cff5f13b9dba3ebc41896ee0fdc21ae4f3740 +R 7ab31df9ffdd4f8066f809be43b05ba6 U drh -Z 2f8691d3650feb9b039ca6336d443329 +Z 00e0c5317c8b57851c68c1832373c781 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 120c9883b8..21b3877a0f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -865f0de7a17ce6059b8f0708002cff5f13b9dba3ebc41896ee0fdc21ae4f3740 \ No newline at end of file +8eda4797c573382cbb989a4ab4b1f19d8fd538dbc9818d86a9aa6189cfa90f37 \ No newline at end of file diff --git a/src/vdbe.c b/src/vdbe.c index faa12aaf8d..ed1d277b23 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -6192,7 +6192,8 @@ case OP_Last: { /* jump0, ncycle */ ** ** Let N be the approximate number of rows in the table or index ** with cursor P1 and let X be 10*log2(N) if N is positive or -1 -** if N is zero. Thus X will be within the range of -1 to 640, inclusive +** if N is zero. +** ** Jump to P2 if X is in between P3 and P4, inclusive. */ case OP_IfSizeBetween: { /* jump */ @@ -6203,8 +6204,8 @@ case OP_IfSizeBetween: { /* jump */ assert( pOp->p1>=0 && pOp->p1nCursor ); assert( pOp->p4type==P4_INT32 ); - assert( pOp->p3>=-1 && pOp->p3<=640 ); - assert( pOp->p4.i>=-1 && pOp->p4.i<=640 ); + assert( pOp->p3>=-1 && pOp->p3<=640*2 ); + assert( pOp->p4.i>=-1 && pOp->p4.i<=640*2 ); pC = p->apCsr[pOp->p1]; assert( pC!=0 ); pCrsr = pC->uc.pCursor; From d9eee787bd1ab041fef140dd29a5a8316647d3bc Mon Sep 17 00:00:00 2001 From: drh <> Date: Sat, 23 Mar 2024 15:17:38 +0000 Subject: [PATCH 272/430] Fix an adverse interaction between CREATE TABLE AS and the new [/info/a120c9235f125e05|VALUES-as-coroutine] optimization. dbsqlfuzz c2c5e7e08b7e489d270a26d895077a03f678c33b FossilOrigin-Name: 84b6fdea0bf07c73df0ca8ef110db066164a5f34606e6c069a060476e04ef44e --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/build.c | 12 ++++++------ test/values.test | 12 ++++++++++++ 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/manifest b/manifest index 2210416533..2662568857 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sincorrect\sboundary\sassert()s\son\sthe\snew\sOP_IfSizeBetween\sopcode. -D 2024-03-22T10:32:14.835 +C Fix\san\sadverse\sinteraction\sbetween\sCREATE\sTABLE\sAS\sand\sthe\snew\n[/info/a120c9235f125e05|VALUES-as-coroutine]\soptimization.\ndbsqlfuzz\sc2c5e7e08b7e489d270a26d895077a03f678c33b +D 2024-03-23T15:17:38.317 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -692,7 +692,7 @@ F src/btmutex.c 79a43670447eacc651519a429f6ece9fd638563cf95b469d6891185ddae2b522 F src/btree.c 285b493d843e7ba8ef78b6ae7d31238e904901dbc0c484f7904de4cf18fd8802 F src/btree.h 55066f513eb095db935169dab1dc2f7c7a747ef223c533f5d4ad4dfed346cbd0 F src/btreeInt.h 98aadb6dcb77b012cab2574d6a728fad56b337fc946839b9898c4b4c969e30b6 -F src/build.c fff536730a6d83120ae38d960f812b548394e8af6907249effb1764d69178106 +F src/build.c 02f5b25ca854c83b5015cb02b8c9ab236c60b1795528675aee8a5070e58da52a F src/callback.c db3a45e376deff6a16c0058163fe0ae2b73a2945f3f408ca32cf74960b28d490 F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e F src/ctime.c 64e4b1227b4ed123146f0aa2989131d1fbd9b927b11e80c9d58c6a68f9cd5ce3 @@ -1924,7 +1924,7 @@ F test/vacuum4.test 7ea76b769fffeb41f925303b04cbcf5a5bbeabe55e4c60ae754ff24eeeb7 F test/vacuum5.test 263b144d537e92ad8e9ca8a73cc6e1583f41cfd0dda9432b87f7806174a2f48c F test/vacuum6.test b137b04bf3392d3f5c3b8fda0ce85a6775a70ca112f6559f74ff52dc9ce042fd F test/vacuummem.test 4b30f5b95a9ff86e9d5c20741e50a898b2dc10b0962a3211571eb165357003fb -F test/values.test e7c156f92d32ed645908fbad0a1144f0f31650376cdcb212fde701978c89d3b1 +F test/values.test ee77c1cb540c47868848f85c39f92bb11d787657ade32f91eedf2988727769cd F test/valuesfault.test 2ef23ed965e3bd08e268cdc38a0d11653390ddbbe1e8e2e98d16f55edd30f6e8 F test/varint.test bbce22cda8fc4d135bcc2b589574be8410614e62 F test/veryquick.test 57ab846bacf7b90cf4e9a672721ea5c5b669b661 @@ -2182,8 +2182,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 865f0de7a17ce6059b8f0708002cff5f13b9dba3ebc41896ee0fdc21ae4f3740 -R 7ab31df9ffdd4f8066f809be43b05ba6 +P 8eda4797c573382cbb989a4ab4b1f19d8fd538dbc9818d86a9aa6189cfa90f37 +R da9288a1e61bb5eb45cf509b5ee97ccd U drh -Z 00e0c5317c8b57851c68c1832373c781 +Z 02c1f27357ab211e7de37d670fb693ee # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 21b3877a0f..cb38d5c115 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8eda4797c573382cbb989a4ab4b1f19d8fd538dbc9818d86a9aa6189cfa90f37 \ No newline at end of file +84b6fdea0bf07c73df0ca8ef110db066164a5f34606e6c069a060476e04ef44e \ No newline at end of file diff --git a/src/build.c b/src/build.c index 3ea35b331c..8279c0a89c 100644 --- a/src/build.c +++ b/src/build.c @@ -2828,20 +2828,20 @@ void sqlite3EndTable( int regRowid; /* Rowid of the next row to insert */ int addrInsLoop; /* Top of the loop for inserting rows */ Table *pSelTab; /* A table that describes the SELECT results */ + int iCsr; /* Write cursor on the new table */ if( IN_SPECIAL_PARSE ){ pParse->rc = SQLITE_ERROR; pParse->nErr++; return; } + iCsr = pParse->nTab++; regYield = ++pParse->nMem; regRec = ++pParse->nMem; regRowid = ++pParse->nMem; - assert(pParse->nTab==1); sqlite3MayAbort(pParse); - sqlite3VdbeAddOp3(v, OP_OpenWrite, 1, pParse->regRoot, iDb); + sqlite3VdbeAddOp3(v, OP_OpenWrite, iCsr, pParse->regRoot, iDb); sqlite3VdbeChangeP5(v, OPFLAG_P2ISREG); - pParse->nTab = 2; addrTop = sqlite3VdbeCurrentAddr(v) + 1; sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, addrTop); if( pParse->nErr ) return; @@ -2862,11 +2862,11 @@ void sqlite3EndTable( VdbeCoverage(v); sqlite3VdbeAddOp3(v, OP_MakeRecord, dest.iSdst, dest.nSdst, regRec); sqlite3TableAffinity(v, p, 0); - sqlite3VdbeAddOp2(v, OP_NewRowid, 1, regRowid); - sqlite3VdbeAddOp3(v, OP_Insert, 1, regRec, regRowid); + sqlite3VdbeAddOp2(v, OP_NewRowid, iCsr, regRowid); + sqlite3VdbeAddOp3(v, OP_Insert, iCsr, regRec, regRowid); sqlite3VdbeGoto(v, addrInsLoop); sqlite3VdbeJumpHere(v, addrInsLoop); - sqlite3VdbeAddOp1(v, OP_Close, 1); + sqlite3VdbeAddOp1(v, OP_Close, iCsr); } /* Compute the complete text of the CREATE statement */ diff --git a/test/values.test b/test/values.test index 43f8e0e6fe..26f2812237 100644 --- a/test/values.test +++ b/test/values.test @@ -580,4 +580,16 @@ do_eqp_test 16.7 { `--SCAN 4-ROW VALUES CLAUSE } +#-------------------------------------------------------------------------- +# 2024-03-23 dbsqlfuzz crash-c2c5e7e08b7e489d270a26d895077a03f678c33b +# +do_execsql_test 17.1 { + DROP TABLE IF EXISTS t1; + CREATE TABLE t1 AS SELECT * FROM (VALUES(1,2), (3,4 IN (1,2,3))); +} + +do_execsql_test 17.2 { + SELECT * FROM t1 +} {1 2 3 0} + finish_test From a631eb378d94eb10ade6a0c2d18b2e411c1da806 Mon Sep 17 00:00:00 2001 From: drh <> Date: Sun, 24 Mar 2024 16:33:31 +0000 Subject: [PATCH 273/430] Do not automatically assume that ROWID is NOT NULL when compiled with SQLITE_ALLOW_ROWID_IN_VIEW. dbsqlfuzz 31b38eeb63a4e1562de665078f52b7b47a7543cf FossilOrigin-Name: 80c4223098c1827ff3a564f1f9a4203164a943e9a83eef99df68378fa3c4764b --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/expr.c | 9 ++++++--- src/select.c | 17 +++++++++++++++++ 4 files changed, 31 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 2662568857..d217a1389c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\san\sadverse\sinteraction\sbetween\sCREATE\sTABLE\sAS\sand\sthe\snew\n[/info/a120c9235f125e05|VALUES-as-coroutine]\soptimization.\ndbsqlfuzz\sc2c5e7e08b7e489d270a26d895077a03f678c33b -D 2024-03-23T15:17:38.317 +C Do\snot\sautomatically\sassume\sthat\sROWID\sis\sNOT\sNULL\swhen\scompiled\swith\nSQLITE_ALLOW_ROWID_IN_VIEW.\ndbsqlfuzz\s31b38eeb63a4e1562de665078f52b7b47a7543cf +D 2024-03-24T16:33:31.285 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -700,7 +700,7 @@ F src/date.c 126ba2ab10aeb2e7ba6e089b5f07b747c0625b8287f78b60da346eda8d23c875 F src/dbpage.c 80e46e1df623ec40486da7a5086cb723b0275a6e2a7b01d9f9b5da0f04ba2782 F src/dbstat.c 3b677254d512fcafd4d0b341bf267b38b235ccfddbef24f9154e19360fa22e43 F src/delete.c cb766727c78e715f9fb7ec8a7d03658ed2a3016343ca687acfcec9083cdca500 -F src/expr.c 94f48513fbec07725501298dee3f16d95b1762bb4a12296455f544b2d7f2d74a +F src/expr.c ff1bb1bdbcdc20505cfa900f332e18239ab3cf20d2b0d220a960b5b3513b7cb4 F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c a47610f0a5c6cb0ad79f8fcef039c01833dec0c751bb695f28dc0ec6a4c3ba00 F src/func.c 283d4f3b2751a1d9339fd93a8a013d1948fd5f4474a3cab0955eb4fafd445d0f @@ -750,7 +750,7 @@ F src/printf.c 87b67bba3662a0523f39ae6b084a3907109702f717c654d6cecb838af5cd57f1 F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c eb1860b134fb044fd819c4347105c148d5aac7c6498032be2829e5cc95619b28 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 -F src/select.c ced6678ead94c08d58cdb65cdda00a4871a3048e7834146f2a58ce71171808f8 +F src/select.c 15a221347789e393b39e7d2d2bd102167979c95a1ce0675bb870b86a24ca6cf4 F src/shell.c.in 0354ca51eee5fbf6af394a7ef9f5ef6823ef45b743db65431f6777e4d5be2199 F src/sqlite.h.in 41c5febd217b1e475aae022895c60f57fbe39ff6136450110662cfad67002d43 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 @@ -2182,8 +2182,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 8eda4797c573382cbb989a4ab4b1f19d8fd538dbc9818d86a9aa6189cfa90f37 -R da9288a1e61bb5eb45cf509b5ee97ccd +P 84b6fdea0bf07c73df0ca8ef110db066164a5f34606e6c069a060476e04ef44e +R 1acc2c5116f8a8c5695dfb6ee536b3ee U drh -Z 02c1f27357ab211e7de37d670fb693ee +Z 664dfa62372b996e1fbf277d588e4a7b # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index cb38d5c115..001db1b9c8 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -84b6fdea0bf07c73df0ca8ef110db066164a5f34606e6c069a060476e04ef44e \ No newline at end of file +80c4223098c1827ff3a564f1f9a4203164a943e9a83eef99df68378fa3c4764b \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index 7e3f38279d..d71353f174 100644 --- a/src/expr.c +++ b/src/expr.c @@ -2801,9 +2801,12 @@ int sqlite3ExprCanBeNull(const Expr *p){ return 0; case TK_COLUMN: assert( ExprUseYTab(p) ); - return ExprHasProperty(p, EP_CanBeNull) || - NEVER(p->y.pTab==0) || /* Reference to column of index on expr */ - (p->iColumn>=0 + return ExprHasProperty(p, EP_CanBeNull) + || NEVER(p->y.pTab==0) /* Reference to column of index on expr */ +#ifdef SQLITE_ALLOW_ROWID_IN_VIEW + || (p->iColumn==XN_ROWID && IsView(p->y.pTab)) +#endif + || (p->iColumn>=0 && p->y.pTab->aCol!=0 /* Possible due to prior error */ && ALWAYS(p->iColumny.pTab->nCol) && p->y.pTab->aCol[p->iColumn].notNull==0); diff --git a/src/select.c b/src/select.c index b539288e9d..b200518518 100644 --- a/src/select.c +++ b/src/select.c @@ -5134,6 +5134,10 @@ static int pushDownWindowCheck(Parse *pParse, Select *pSubq, Expr *pExpr){ ** ** (11) The subquery is not a VALUES clause ** +** (12) The WHERE clause is not "rowid ISNULL" or the equivalent. This +** case only comes up if SQLite is compiled using +** SQLITE_ALLOW_ROWID_IN_VIEW. +** ** Return 0 if no changes are made and non-zero if one or more WHERE clause ** terms are duplicated into the subquery. */ @@ -5244,6 +5248,18 @@ static int pushDownWhereTerms( } #endif +#ifdef SQLITE_ALLOW_ROWID_IN_VIEW + if( ViewCanHaveRowid && (pWhere->op==TK_ISNULL || pWhere->op==TK_NOTNULL) ){ + Expr *pLeft = pWhere->pLeft; + if( ALWAYS(pLeft) + && pLeft->op==TK_COLUMN + && pLeft->iColumn < 0 + ){ + return 0; /* Restriction (12) */ + } + } +#endif + if( sqlite3ExprIsSingleTableConstraint(pWhere, pSrcList, iSrc) ){ nChng++; pSubq->selFlags |= SF_PushDown; @@ -5871,6 +5887,7 @@ int sqlite3ExpandSubquery(Parse *pParse, SrcItem *pFrom){ while( pSel->pPrior ){ pSel = pSel->pPrior; } sqlite3ColumnsFromExprList(pParse, pSel->pEList,&pTab->nCol,&pTab->aCol); pTab->iPKey = -1; + pTab->eTabType = TABTYP_VIEW; pTab->nRowLogEst = 200; assert( 200==sqlite3LogEst(1048576) ); #ifndef SQLITE_ALLOW_ROWID_IN_VIEW /* The usual case - do not allow ROWID on a subquery */ From 4a402b80c59d4d3f929544e8eea54e8e5965700a Mon Sep 17 00:00:00 2001 From: drh <> Date: Sun, 24 Mar 2024 20:26:59 +0000 Subject: [PATCH 274/430] Improved "wheretrace" debugging output for calls to xBestIndex. No changes to release code. FossilOrigin-Name: 33966bb06ce9a8e90734de59a8d43c523f60870d20be64789638da4c84a8b81b --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/where.c | 20 ++++++++++++++------ 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/manifest b/manifest index d217a1389c..eea486cab1 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Do\snot\sautomatically\sassume\sthat\sROWID\sis\sNOT\sNULL\swhen\scompiled\swith\nSQLITE_ALLOW_ROWID_IN_VIEW.\ndbsqlfuzz\s31b38eeb63a4e1562de665078f52b7b47a7543cf -D 2024-03-24T16:33:31.285 +C Improved\s"wheretrace"\sdebugging\soutput\sfor\scalls\sto\sxBestIndex.\s\sNo\schanges\nto\srelease\scode. +D 2024-03-24T20:26:59.325 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -835,7 +835,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c 887fc4ca3f020ebb2e376f222069570834ac63bf50111ef0cbf3ae417048ed89 F src/wal.h ba252daaa94f889f4b2c17c027e823d9be47ce39da1d3799886bbd51f0490452 F src/walker.c 7c7ea0115345851c3da4e04e2e239a29983b61fb5b038b94eede6aba462640e2 -F src/where.c 5e9a5d642cceb666152c59091a3dbb645a9dda209b4e65a2f9215ee9298d26cf +F src/where.c 2e01199202dd117a27f7597e1f554a5cd55e7465e2f39ff9a78adc9cba98b971 F src/whereInt.h 82a13766f13d1a53b05387c2e60726289ef26404bc7b9b1f7770204d97357fb8 F src/wherecode.c 5d77db30a2a3dd532492ae882de114edba2fae672622056b1c7fd61f5917a8f1 F src/whereexpr.c 7b64295f1d82ad0928df435925dd7bbd5997b44a026153113eace0d9e71ff435 @@ -2182,8 +2182,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 84b6fdea0bf07c73df0ca8ef110db066164a5f34606e6c069a060476e04ef44e -R 1acc2c5116f8a8c5695dfb6ee536b3ee +P 80c4223098c1827ff3a564f1f9a4203164a943e9a83eef99df68378fa3c4764b +R 85708579a006a76a9ac19f57eff9986d U drh -Z 664dfa62372b996e1fbf277d588e4a7b +Z 2f119c894f4b4cc81a59e37d61239a6c # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 001db1b9c8..c6fd4f1e53 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -80c4223098c1827ff3a564f1f9a4203164a943e9a83eef99df68378fa3c4764b \ No newline at end of file +33966bb06ce9a8e90734de59a8d43c523f60870d20be64789638da4c84a8b81b \ No newline at end of file diff --git a/src/where.c b/src/where.c index 2463e823c8..3fbb768af5 100644 --- a/src/where.c +++ b/src/where.c @@ -713,9 +713,13 @@ static void translateColumnToCopy( ** are no-ops. */ #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(WHERETRACE_ENABLED) -static void whereTraceIndexInfoInputs(sqlite3_index_info *p){ +static void whereTraceIndexInfoInputs( + sqlite3_index_info *p, /* The IndexInfo object */ + Table *pTab /* The TABLE that is the virtual table */ +){ int i; if( (sqlite3WhereTrace & 0x10)==0 ) return; + sqlite3DebugPrintf("sqlite3_index_info inputs for %s:\n", pTab->zName); for(i=0; inConstraint; i++){ sqlite3DebugPrintf( " constraint[%d]: col=%d termid=%d op=%d usabled=%d collseq=%s\n", @@ -733,9 +737,13 @@ static void whereTraceIndexInfoInputs(sqlite3_index_info *p){ p->aOrderBy[i].desc); } } -static void whereTraceIndexInfoOutputs(sqlite3_index_info *p){ +static void whereTraceIndexInfoOutputs( + sqlite3_index_info *p, /* The IndexInfo object */ + Table *pTab /* The TABLE that is the virtual table */ +){ int i; if( (sqlite3WhereTrace & 0x10)==0 ) return; + sqlite3DebugPrintf("sqlite3_index_info outputs for %s:\n", pTab->zName); for(i=0; inConstraint; i++){ sqlite3DebugPrintf(" usage[%d]: argvIdx=%d omit=%d\n", i, @@ -749,8 +757,8 @@ static void whereTraceIndexInfoOutputs(sqlite3_index_info *p){ sqlite3DebugPrintf(" estimatedRows=%lld\n", p->estimatedRows); } #else -#define whereTraceIndexInfoInputs(A) -#define whereTraceIndexInfoOutputs(A) +#define whereTraceIndexInfoInputs(A,B) +#define whereTraceIndexInfoOutputs(A,B) #endif /* @@ -1493,11 +1501,11 @@ static int vtabBestIndex(Parse *pParse, Table *pTab, sqlite3_index_info *p){ sqlite3_vtab *pVtab = sqlite3GetVTable(pParse->db, pTab)->pVtab; int rc; - whereTraceIndexInfoInputs(p); + whereTraceIndexInfoInputs(p, pTab); pParse->db->nSchemaLock++; rc = pVtab->pModule->xBestIndex(pVtab, p); pParse->db->nSchemaLock--; - whereTraceIndexInfoOutputs(p); + whereTraceIndexInfoOutputs(p, pTab); if( rc!=SQLITE_OK && rc!=SQLITE_CONSTRAINT ){ if( rc==SQLITE_NOMEM ){ From cf84ae0189ced4937662feebfcc855d64a5232a1 Mon Sep 17 00:00:00 2001 From: drh <> Date: Sun, 24 Mar 2024 21:10:45 +0000 Subject: [PATCH 275/430] Fix the xBestIndex method of the pragma virtual table so that it correctly gives a higher cost to plans where the schema hidden parameter is unconstrained. Fix for the problem reported by [forum:/forumpost/85b6a8b6705fb77a|forum post 85b6a8b6705fb77a]. FossilOrigin-Name: bc516ff5202ee6e9834266bf755fe26e30ac557dcc7975ca7a06dfe33874fcd2 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/pragma.c | 6 +++++- test/pragma4.test | 12 ++++++++++++ 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index eea486cab1..d0fa3fb808 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improved\s"wheretrace"\sdebugging\soutput\sfor\scalls\sto\sxBestIndex.\s\sNo\schanges\nto\srelease\scode. -D 2024-03-24T20:26:59.325 +C Fix\sthe\sxBestIndex\smethod\sof\sthe\spragma\svirtual\stable\sso\sthat\sit\scorrectly\ngives\sa\shigher\scost\sto\splans\swhere\sthe\sschema\shidden\sparameter\sis\nunconstrained.\s\sFix\sfor\sthe\sproblem\sreported\sby\n[forum:/forumpost/85b6a8b6705fb77a|forum\spost\s85b6a8b6705fb77a]. +D 2024-03-24T21:10:45.270 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -743,7 +743,7 @@ F src/parse.y 5bcef16094213efcc365a9d4dc4e3131f09251dc8838dce4a9e5f9764bff5b82 F src/pcache.c 040b165f30622a21b7a9a77c6f2e4877a32fb7f22d4c7f0d2a6fa6833a156a75 F src/pcache.h 1497ce1b823cf00094bb0cf3bac37b345937e6f910890c626b16512316d3abf5 F src/pcache1.c 602acb23c471bb8d557a6f0083cc2be641d6cafcafa19e481eba7ef4c9ca0f00 -F src/pragma.c e8221d6310c9923c80f6fa6d09b7ea7c5263a671f53db8d0894df23efcdb617b +F src/pragma.c 4629926f936cdc586873d5ff24acb1af12a1db0172988a0dc2b32e46b798a640 F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7 F src/prepare.c 371f6115cb69286ebc12c6f2d7511279c2e47d9f54f475d46a554d687a3b312c F src/printf.c 87b67bba3662a0523f39ae6b084a3907109702f717c654d6cecb838af5cd57f1 @@ -1501,7 +1501,7 @@ F test/pg_common.tcl 3b27542224db1e713ae387459b5d117c836a5f6e328846922993b6d2b76 F test/pragma.test 8bb6d3992c1c31ff6d5553d1e0693d642f7e19015648c6ae7034cb497d26bbd4 F test/pragma2.test e5d5c176360c321344249354c0c16aec46214c9f F test/pragma3.test 92a46bbea12322dd94a404f49edcfbfc913a2c98115f0d030a7459bb4712ef31 -F test/pragma4.test 9559cf5173864bf47c0431873d158fbeb72f920a59905b1f46069d8543eccdab +F test/pragma4.test 1951dc5a6d87c4ccd8eab35c65f18380c80fac4a0897e828cf518e3cc8a4c292 F test/pragma5.test 7b33fc43e2e41abf17f35fb73f71b49671a380ea92a6c94b6ce530a25f8d9102 F test/pragma6.test c5ec577ba087954b4dfa619a3cbe97b155b60a0af487527abe89b10fc17e6512 F test/pragmafault.test 275edaf3161771d37de60e5c2b412627ac94cef11739236bec12ed1258b240f8 @@ -2182,8 +2182,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 80c4223098c1827ff3a564f1f9a4203164a943e9a83eef99df68378fa3c4764b -R 85708579a006a76a9ac19f57eff9986d +P 33966bb06ce9a8e90734de59a8d43c523f60870d20be64789638da4c84a8b81b +R 97fc378a830906e74d1623fece2781ad U drh -Z 2f119c894f4b4cc81a59e37d61239a6c +Z 0dbd1f88ff00b9d3018bd54394a97ce0 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index c6fd4f1e53..cc6bf08fca 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -33966bb06ce9a8e90734de59a8d43c523f60870d20be64789638da4c84a8b81b \ No newline at end of file +bc516ff5202ee6e9834266bf755fe26e30ac557dcc7975ca7a06dfe33874fcd2 \ No newline at end of file diff --git a/src/pragma.c b/src/pragma.c index d3b0198236..d14428f75e 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -2885,7 +2885,11 @@ static int pragmaVtabBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){ j = seen[0]-1; pIdxInfo->aConstraintUsage[j].argvIndex = 1; pIdxInfo->aConstraintUsage[j].omit = 1; - if( seen[1]==0 ) return SQLITE_OK; + if( seen[1]==0 ){ + pIdxInfo->estimatedCost = (double)1000; + pIdxInfo->estimatedRows = 1000; + return SQLITE_OK; + } pIdxInfo->estimatedCost = (double)20; pIdxInfo->estimatedRows = 20; j = seen[1]-1; diff --git a/test/pragma4.test b/test/pragma4.test index 9d5a363d65..9b2fa9ba2a 100644 --- a/test/pragma4.test +++ b/test/pragma4.test @@ -264,5 +264,17 @@ do_execsql_test 5.0 { 0 a {} 0 'abc' 0 1 b {} 0 -1 0 2 c {} 0 +4.0 0 } +# 2024-03-24 https://sqlite.org/forum/forumpost/85b6a8b6705fb77a +# +reset_db +do_execsql_test 6.0 { + CREATE TABLE t1(a INT PRIMARY KEY, b INT); + CREATE TABLE t2(c INT PRIMARY KEY, d INT REFERENCES t1); + SELECT t.name, f."table", f."from", i.name, i.pk + FROM pragma_table_list() AS t + JOIN pragma_foreign_key_list(t.name, t.schema) AS f + JOIN pragma_table_info(f."table", t.schema) AS i + WHERE i.pk; +} {t2 t1 d a 1} finish_test From d2b3b72a2b2524cb8a9b017c08fd255d8fe842d7 Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 25 Mar 2024 00:38:55 +0000 Subject: [PATCH 276/430] Improvements to the vtablog.c extension, for better logging of virtual table interactions. FossilOrigin-Name: e253bb36a5f4f601c9b08858b55a9ce198239ace8efa8dab7c0ec019028967c1 --- ext/misc/vtablog.c | 147 ++++++++++++++++++++++++++++++++++----------- manifest | 12 ++-- manifest.uuid | 2 +- 3 files changed, 119 insertions(+), 42 deletions(-) diff --git a/ext/misc/vtablog.c b/ext/misc/vtablog.c index e414e7afa7..301e82fcc1 100644 --- a/ext/misc/vtablog.c +++ b/ext/misc/vtablog.c @@ -38,8 +38,9 @@ SQLITE_EXTENSION_INIT1 typedef struct vtablog_vtab vtablog_vtab; struct vtablog_vtab { sqlite3_vtab base; /* Base class - must be first */ + char *zDb; /* Schema name. argv[1] of xConnect/xCreate */ + char *zName; /* Table name. argv[2] of xConnect/xCreate */ int nRow; /* Number of rows in the table */ - int iInst; /* Instance number for this vtablog table */ int nCursor; /* Number of cursors created */ }; @@ -167,15 +168,14 @@ static int vtablogConnectCreate( char **pzErr, int isCreate ){ - static int nInst = 0; vtablog_vtab *pNew; int i; int rc; - int iInst = ++nInst; char *zSchema = 0; char *zNRow = 0; - printf("vtablog%s(tab=%d):\n", isCreate ? "Create" : "Connect", iInst); + printf("%s.%s.%s():\n", argv[1], argv[2], + isCreate ? "xCreate" : "xConnect"); printf(" argc=%d\n", argc); for(i=0; inRow = 10; if( zNRow ) pNew->nRow = atoi(zNRow); - pNew->iInst = iInst; + pNew->zDb = sqlite3_mprintf("%s", argv[1]); + pNew->zName = sqlite3_mprintf("%s", argv[2]); } return rc; } @@ -237,7 +236,9 @@ static int vtablogConnect( */ static int vtablogDisconnect(sqlite3_vtab *pVtab){ vtablog_vtab *pTab = (vtablog_vtab*)pVtab; - printf("vtablogDisconnect(%d)\n", pTab->iInst); + printf("%s.%s.xDisconnect()\n", pTab->zDb, pTab->zName); + sqlite3_free(pTab->zDb); + sqlite3_free(pTab->zName); sqlite3_free(pVtab); return SQLITE_OK; } @@ -247,7 +248,8 @@ static int vtablogDisconnect(sqlite3_vtab *pVtab){ */ static int vtablogDestroy(sqlite3_vtab *pVtab){ vtablog_vtab *pTab = (vtablog_vtab*)pVtab; - printf("vtablogDestroy(%d)\n", pTab->iInst); + printf("%s.%s.xDestroy()\n", pTab->zDb, pTab->zName); + sqlite3_free(pTab->zName); sqlite3_free(pVtab); return SQLITE_OK; } @@ -258,7 +260,8 @@ static int vtablogDestroy(sqlite3_vtab *pVtab){ static int vtablogOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor){ vtablog_vtab *pTab = (vtablog_vtab*)p; vtablog_cursor *pCur; - printf("vtablogOpen(tab=%d, cursor=%d)\n", pTab->iInst, ++pTab->nCursor); + printf("%s.%s.xOpen(cursor=%d)\n", pTab->zDb, pTab->zName, + ++pTab->nCursor); pCur = sqlite3_malloc( sizeof(*pCur) ); if( pCur==0 ) return SQLITE_NOMEM; memset(pCur, 0, sizeof(*pCur)); @@ -273,7 +276,7 @@ static int vtablogOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor){ static int vtablogClose(sqlite3_vtab_cursor *cur){ vtablog_cursor *pCur = (vtablog_cursor*)cur; vtablog_vtab *pTab = (vtablog_vtab*)cur->pVtab; - printf("vtablogClose(tab=%d, cursor=%d)\n", pTab->iInst, pCur->iCursor); + printf("%s.%s.xClose(cursor=%d)\n", pTab->zDb, pTab->zName, pCur->iCursor); sqlite3_free(cur); return SQLITE_OK; } @@ -285,8 +288,9 @@ static int vtablogClose(sqlite3_vtab_cursor *cur){ static int vtablogNext(sqlite3_vtab_cursor *cur){ vtablog_cursor *pCur = (vtablog_cursor*)cur; vtablog_vtab *pTab = (vtablog_vtab*)cur->pVtab; - printf("vtablogNext(tab=%d, cursor=%d) rowid %d -> %d\n", - pTab->iInst, pCur->iCursor, (int)pCur->iRowid, (int)pCur->iRowid+1); + printf("%s.%s.xNext(cursor=%d) rowid %d -> %d\n", + pTab->zDb, pTab->zName, pCur->iCursor, + (int)pCur->iRowid, (int)pCur->iRowid+1); pCur->iRowid++; return SQLITE_OK; } @@ -310,8 +314,8 @@ static int vtablogColumn( }else{ sqlite3_snprintf(sizeof(zVal),zVal,"{%d}%d", i, pCur->iRowid); } - printf("vtablogColumn(tab=%d, cursor=%d, i=%d): [%s]\n", - pTab->iInst, pCur->iCursor, i, zVal); + printf("%s.%s.xColumn(cursor=%d, i=%d): [%s]\n", + pTab->zDb, pTab->zName, pCur->iCursor, i, zVal); sqlite3_result_text(ctx, zVal, -1, SQLITE_TRANSIENT); return SQLITE_OK; } @@ -323,8 +327,8 @@ static int vtablogColumn( static int vtablogRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){ vtablog_cursor *pCur = (vtablog_cursor*)cur; vtablog_vtab *pTab = (vtablog_vtab*)cur->pVtab; - printf("vtablogRowid(tab=%d, cursor=%d): %d\n", - pTab->iInst, pCur->iCursor, (int)pCur->iRowid); + printf("%s.%s.xRowid(cursor=%d): %d\n", + pTab->zDb, pTab->zName, pCur->iCursor, (int)pCur->iRowid); *pRowid = pCur->iRowid; return SQLITE_OK; } @@ -337,8 +341,8 @@ static int vtablogEof(sqlite3_vtab_cursor *cur){ vtablog_cursor *pCur = (vtablog_cursor*)cur; vtablog_vtab *pTab = (vtablog_vtab*)cur->pVtab; int rc = pCur->iRowid >= pTab->nRow; - printf("vtablogEof(tab=%d, cursor=%d): %d\n", - pTab->iInst, pCur->iCursor, rc); + printf("%s.%s.xEof(cursor=%d): %d\n", + pTab->zDb, pTab->zName, pCur->iCursor, rc); return rc; } @@ -417,7 +421,7 @@ static int vtablogFilter( ){ vtablog_cursor *pCur = (vtablog_cursor *)cur; vtablog_vtab *pTab = (vtablog_vtab*)cur->pVtab; - printf("vtablogFilter(tab=%d, cursor=%d):\n", pTab->iInst, pCur->iCursor); + printf("%s.%s.xFilter(cursor=%d):\n", pTab->zDb, pTab->zName, pCur->iCursor); pCur->iRowid = 0; return SQLITE_OK; } @@ -433,7 +437,7 @@ static int vtablogBestIndex( sqlite3_index_info *pIdxInfo ){ vtablog_vtab *pTab = (vtablog_vtab*)tab; - printf("vtablogBestIndex(tab=%d):\n", pTab->iInst); + printf("%s.%s.xBestIndex():\n", pTab->zDb, pTab->zName); pIdxInfo->estimatedCost = (double)500; pIdxInfo->estimatedRows = 500; return SQLITE_OK; @@ -454,7 +458,7 @@ static int vtablogUpdate( ){ vtablog_vtab *pTab = (vtablog_vtab*)tab; int i; - printf("vtablogUpdate(tab=%d):\n", pTab->iInst); + printf("%s.%s.xUpdate():\n", pTab->zDb, pTab->zName); printf(" argc=%d\n", argc); for(i=0; izDb, pTab->zName); + return SQLITE_OK; +} +static int vtablogSync(sqlite3_vtab *tab){ + vtablog_vtab *pTab = (vtablog_vtab*)tab; + printf("%s.%s.xSync()\n", pTab->zDb, pTab->zName); + return SQLITE_OK; +} +static int vtablogCommit(sqlite3_vtab *tab){ + vtablog_vtab *pTab = (vtablog_vtab*)tab; + printf("%s.%s.xCommit()\n", pTab->zDb, pTab->zName); + return SQLITE_OK; +} +static int vtablogRollback(sqlite3_vtab *tab){ + vtablog_vtab *pTab = (vtablog_vtab*)tab; + printf("%s.%s.xRollback()\n", pTab->zDb, pTab->zName); + return SQLITE_OK; +} +static int vtablogSavepoint(sqlite3_vtab *tab, int N){ + vtablog_vtab *pTab = (vtablog_vtab*)tab; + printf("%s.%s.xSavepoint(%d)\n", pTab->zDb, pTab->zName, N); + return SQLITE_OK; +} +static int vtablogRelease(sqlite3_vtab *tab, int N){ + vtablog_vtab *pTab = (vtablog_vtab*)tab; + printf("%s.%s.xRelease(%d)\n", pTab->zDb, pTab->zName, N); + return SQLITE_OK; +} +static int vtablogRollbackTo(sqlite3_vtab *tab, int N){ + vtablog_vtab *pTab = (vtablog_vtab*)tab; + printf("%s.%s.xRollbackTo(%d)\n", pTab->zDb, pTab->zName, N); + return SQLITE_OK; +} + +static int vtablogFindMethod( + sqlite3_vtab *tab, + int nArg, + const char *zName, + void (**pxFunc)(sqlite3_context*,int,sqlite3_value**), + void **ppArg +){ + vtablog_vtab *pTab = (vtablog_vtab*)tab; + printf("%s.%s.xFindMethod(nArg=%d, zName=%s)\n", + pTab->zDb, pTab->zName, nArg, zName); + return SQLITE_OK; +} +static int vtablogRename(sqlite3_vtab *tab, const char *zNew){ + vtablog_vtab *pTab = (vtablog_vtab*)tab; + printf("%s.%s.xRename('%s')\n", pTab->zDb, pTab->zName, zNew); + sqlite3_free(pTab->zName); + pTab->zName = sqlite3_mprintf("%s", zNew); + return SQLITE_OK; +} + +static int vtablogShadowName(const char *zName){ + printf("vtablog.xShadowName('%s')\n", zName); + return 0; +} + +static int vtablogIntegrity( + sqlite3_vtab *tab, + const char *zSchema, + const char *zTabName, + int mFlags, + char **pzErr +){ + vtablog_vtab *pTab = (vtablog_vtab*)tab; + printf("%s.%s.xIntegrity(mFlags=0x%x)\n", pTab->zDb, pTab->zName, mFlags); + return 0; +} + /* ** This following structure defines all the methods for the ** vtablog virtual table. */ static sqlite3_module vtablogModule = { - 0, /* iVersion */ + 4, /* iVersion */ vtablogCreate, /* xCreate */ vtablogConnect, /* xConnect */ vtablogBestIndex, /* xBestIndex */ @@ -483,17 +560,17 @@ static sqlite3_module vtablogModule = { vtablogColumn, /* xColumn - read data */ vtablogRowid, /* xRowid - read data */ vtablogUpdate, /* xUpdate */ - 0, /* xBegin */ - 0, /* xSync */ - 0, /* xCommit */ - 0, /* xRollback */ - 0, /* xFindMethod */ - 0, /* xRename */ - 0, /* xSavepoint */ - 0, /* xRelease */ - 0, /* xRollbackTo */ - 0, /* xShadowName */ - 0 /* xIntegrity */ + vtablogBegin, /* xBegin */ + vtablogSync, /* xSync */ + vtablogCommit, /* xCommit */ + vtablogRollback, /* xRollback */ + vtablogFindMethod, /* xFindMethod */ + vtablogRename, /* xRename */ + vtablogSavepoint, /* xSavepoint */ + vtablogRelease, /* xRelease */ + vtablogRollbackTo, /* xRollbackTo */ + vtablogShadowName, /* xShadowName */ + vtablogIntegrity /* xIntegrity */ }; #ifdef _WIN32 diff --git a/manifest b/manifest index d0fa3fb808..cfb54dfdeb 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\sxBestIndex\smethod\sof\sthe\spragma\svirtual\stable\sso\sthat\sit\scorrectly\ngives\sa\shigher\scost\sto\splans\swhere\sthe\sschema\shidden\sparameter\sis\nunconstrained.\s\sFix\sfor\sthe\sproblem\sreported\sby\n[forum:/forumpost/85b6a8b6705fb77a|forum\spost\s85b6a8b6705fb77a]. -D 2024-03-24T21:10:45.270 +C Improvements\sto\sthe\svtablog.c\sextension,\sfor\sbetter\slogging\sof\svirtual\ntable\sinteractions. +D 2024-03-25T00:38:55.563 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -426,7 +426,7 @@ F ext/misc/urifuncs.c f71360d14fa9e7626b563f1f781c6148109462741c5235ac63ae0f8917 F ext/misc/uuid.c 5bb2264c1b64d163efa46509544fd7500cb8769cb7c16dd52052da8d961505cf F ext/misc/vfslog.c 3932ab932eeb2601dbc4447cb14d445aaa9fbe43b863ef5f014401c3420afd20 F ext/misc/vfsstat.c a85df08654743922a19410d7b1e3111de41bb7cd07d20dd16eda4e2b808d269d -F ext/misc/vtablog.c f2c9d41afe00b51b2c8307b79f508eb0c2dcd57bae074807944e73376fcf15b7 +F ext/misc/vtablog.c 10b3b8abb57c9e6ad5b9fd7789a15359931f4ae7eea1ce4c42692b5ab458b58d F ext/misc/vtshim.c 1976e6dd68dd0d64508c91a6dfab8e75f8aaf6cd F ext/misc/wholenumber.c 0fa0c082676b7868bf2fa918e911133f2b349bcdceabd1198bba5f65b4fc0668 F ext/misc/zipfile.c 64cb3d98b6316586e6056d182051aa9d28fdedfbf4b908e6b7a7d70209b1db11 @@ -2182,8 +2182,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 33966bb06ce9a8e90734de59a8d43c523f60870d20be64789638da4c84a8b81b -R 97fc378a830906e74d1623fece2781ad +P bc516ff5202ee6e9834266bf755fe26e30ac557dcc7975ca7a06dfe33874fcd2 +R 73586b393bce9c1bed9e065f652632d2 U drh -Z 0dbd1f88ff00b9d3018bd54394a97ce0 +Z 2f68833aa47d50c9278d5d5a2c9b24b3 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index cc6bf08fca..fe309677df 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -bc516ff5202ee6e9834266bf755fe26e30ac557dcc7975ca7a06dfe33874fcd2 \ No newline at end of file +e253bb36a5f4f601c9b08858b55a9ce198239ace8efa8dab7c0ec019028967c1 \ No newline at end of file From 55051d661c05ed2e5879fd082184687ecf71c8d8 Mon Sep 17 00:00:00 2001 From: stephan Date: Mon, 25 Mar 2024 10:28:10 +0000 Subject: [PATCH 277/430] Flag sqlite3_trace() and sqlite3_profile() as deprecated so that the doc generator for funclist.html sees them as such, and add 'Deprecated' to their page's title for consistency with other deprecated APIs. Comment changes only. Addresses [forum:0901025836|forum post 0901025836]. FossilOrigin-Name: 87c54f93f5711739741ed0ff3c1a6fe24ffc8a025b43523bf78c1f6be8c1b4cd --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/sqlite.h.in | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index cfb54dfdeb..d0cd7ceb0b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improvements\sto\sthe\svtablog.c\sextension,\sfor\sbetter\slogging\sof\svirtual\ntable\sinteractions. -D 2024-03-25T00:38:55.563 +C Flag\ssqlite3_trace()\sand\ssqlite3_profile()\sas\sdeprecated\sso\sthat\sthe\sdoc\sgenerator\sfor\sfunclist.html\ssees\sthem\sas\ssuch,\sand\sadd\s'Deprecated'\sto\stheir\spage's\stitle\sfor\sconsistency\swith\sother\sdeprecated\sAPIs.\sComment\schanges\sonly.\sAddresses\s[forum:0901025836|forum\spost\s0901025836]. +D 2024-03-25T10:28:10.796 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -752,7 +752,7 @@ F src/resolve.c eb1860b134fb044fd819c4347105c148d5aac7c6498032be2829e5cc95619b28 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c 15a221347789e393b39e7d2d2bd102167979c95a1ce0675bb870b86a24ca6cf4 F src/shell.c.in 0354ca51eee5fbf6af394a7ef9f5ef6823ef45b743db65431f6777e4d5be2199 -F src/sqlite.h.in 41c5febd217b1e475aae022895c60f57fbe39ff6136450110662cfad67002d43 +F src/sqlite.h.in e9af5761aab316d52e5a5ac11b42d6a25eaaa49352e982c14f1080aab684b5c4 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 F src/sqliteInt.h f8928f0397d797046396dd9d360a6af8ce6dcb48bd72ea290165b07c8c518744 @@ -2182,8 +2182,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P bc516ff5202ee6e9834266bf755fe26e30ac557dcc7975ca7a06dfe33874fcd2 -R 73586b393bce9c1bed9e065f652632d2 -U drh -Z 2f68833aa47d50c9278d5d5a2c9b24b3 +P e253bb36a5f4f601c9b08858b55a9ce198239ace8efa8dab7c0ec019028967c1 +R 9b310c2f5986c86858424e569b4e6f77 +U stephan +Z 6c78d97a358d85a52548c24a097975e6 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index fe309677df..906e916a84 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e253bb36a5f4f601c9b08858b55a9ce198239ace8efa8dab7c0ec019028967c1 \ No newline at end of file +87c54f93f5711739741ed0ff3c1a6fe24ffc8a025b43523bf78c1f6be8c1b4cd \ No newline at end of file diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 06fcd3f89e..6841cf38f7 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -3305,8 +3305,8 @@ int sqlite3_set_authorizer( #define SQLITE_RECURSIVE 33 /* NULL NULL */ /* -** CAPI3REF: Tracing And Profiling Functions -** METHOD: sqlite3 +** CAPI3REF: Deprecated Tracing And Profiling Functions +** DEPRECATED ** ** These routines are deprecated. Use the [sqlite3_trace_v2()] interface ** instead of the routines described here. From 4397d2837889a5b9c8d6ac26b19281acba45ff61 Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 25 Mar 2024 10:55:08 +0000 Subject: [PATCH 278/430] Improvements to the vtablog.c extension: Eliminate memory leaks. More diagnostic output for xBestIndex. FossilOrigin-Name: 92e9a71bc4daa261d7c9a81fb66f7d7c0f0a74eb9e0c9dec8b4651acc5217bff --- ext/misc/vtablog.c | 51 +++++++++++++++++++++++++++++++++++++++------- manifest | 14 ++++++------- manifest.uuid | 2 +- 3 files changed, 52 insertions(+), 15 deletions(-) diff --git a/ext/misc/vtablog.c b/ext/misc/vtablog.c index 301e82fcc1..2cc29c285f 100644 --- a/ext/misc/vtablog.c +++ b/ext/misc/vtablog.c @@ -189,15 +189,18 @@ static int vtablogConnectCreate( for(i=3; inRow = 10; if( zNRow ) pNew->nRow = atoi(zNRow); + printf(" nrow = %d\n", pNew->nRow); pNew->zDb = sqlite3_mprintf("%s", argv[1]); pNew->zName = sqlite3_mprintf("%s", argv[2]); } + +vtablog_end_connect: + sqlite3_free(zSchema); + sqlite3_free(zNRow); return rc; } static int vtablogCreate( @@ -249,6 +257,7 @@ static int vtablogDisconnect(sqlite3_vtab *pVtab){ static int vtablogDestroy(sqlite3_vtab *pVtab){ vtablog_vtab *pTab = (vtablog_vtab*)pVtab; printf("%s.%s.xDestroy()\n", pTab->zDb, pTab->zName); + sqlite3_free(pTab->zDb); sqlite3_free(pTab->zName); sqlite3_free(pVtab); return SQLITE_OK; @@ -434,12 +443,37 @@ static int vtablogFilter( */ static int vtablogBestIndex( sqlite3_vtab *tab, - sqlite3_index_info *pIdxInfo + sqlite3_index_info *p ){ vtablog_vtab *pTab = (vtablog_vtab*)tab; + int i; printf("%s.%s.xBestIndex():\n", pTab->zDb, pTab->zName); - pIdxInfo->estimatedCost = (double)500; - pIdxInfo->estimatedRows = 500; + printf(" colUsed: 0x%016llx\n", p->colUsed); + printf(" nConstraint: %d\n", p->nConstraint); + for(i=0; inConstraint; i++){ + printf( + " constraint[%d]: col=%d termid=%d op=%d usabled=%d collseq=%s\n", + i, + p->aConstraint[i].iColumn, + p->aConstraint[i].iTermOffset, + p->aConstraint[i].op, + p->aConstraint[i].usable, + sqlite3_vtab_collation(p,i)); + } + printf(" nOrderBy: %d\n", p->nOrderBy); + for(i=0; inOrderBy; i++){ + printf(" orderby[%d]: col=%d desc=%d\n", + i, + p->aOrderBy[i].iColumn, + p->aOrderBy[i].desc); + } + p->estimatedCost = (double)500; + p->estimatedRows = 500; + printf(" idxNum=%d\n", p->idxNum); + printf(" idxStr=NULL\n"); + printf(" orderByConsumed=%d\n", p->orderByConsumed); + printf(" estimatedCost=%g\n", p->estimatedCost); + printf(" estimatedRows=%lld\n", p->estimatedRows); return SQLITE_OK; } @@ -524,9 +558,12 @@ static int vtablogRename(sqlite3_vtab *tab, const char *zNew){ return SQLITE_OK; } +/* Any table name that contains the text "shadow" is seen as a +** shadow table. Nothing else is. +*/ static int vtablogShadowName(const char *zName){ printf("vtablog.xShadowName('%s')\n", zName); - return 0; + return sqlite3_strglob("*shadow*", zName)==0; } static int vtablogIntegrity( diff --git a/manifest b/manifest index d0cd7ceb0b..16315ac093 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Flag\ssqlite3_trace()\sand\ssqlite3_profile()\sas\sdeprecated\sso\sthat\sthe\sdoc\sgenerator\sfor\sfunclist.html\ssees\sthem\sas\ssuch,\sand\sadd\s'Deprecated'\sto\stheir\spage's\stitle\sfor\sconsistency\swith\sother\sdeprecated\sAPIs.\sComment\schanges\sonly.\sAddresses\s[forum:0901025836|forum\spost\s0901025836]. -D 2024-03-25T10:28:10.796 +C Improvements\sto\sthe\svtablog.c\sextension:\s\sEliminate\smemory\sleaks.\nMore\sdiagnostic\soutput\sfor\sxBestIndex. +D 2024-03-25T10:55:08.289 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -426,7 +426,7 @@ F ext/misc/urifuncs.c f71360d14fa9e7626b563f1f781c6148109462741c5235ac63ae0f8917 F ext/misc/uuid.c 5bb2264c1b64d163efa46509544fd7500cb8769cb7c16dd52052da8d961505cf F ext/misc/vfslog.c 3932ab932eeb2601dbc4447cb14d445aaa9fbe43b863ef5f014401c3420afd20 F ext/misc/vfsstat.c a85df08654743922a19410d7b1e3111de41bb7cd07d20dd16eda4e2b808d269d -F ext/misc/vtablog.c 10b3b8abb57c9e6ad5b9fd7789a15359931f4ae7eea1ce4c42692b5ab458b58d +F ext/misc/vtablog.c 1100250ce8782db37c833e3a9a5c9a3ecf1af5e15b8325572b82e6e0a138ffb5 F ext/misc/vtshim.c 1976e6dd68dd0d64508c91a6dfab8e75f8aaf6cd F ext/misc/wholenumber.c 0fa0c082676b7868bf2fa918e911133f2b349bcdceabd1198bba5f65b4fc0668 F ext/misc/zipfile.c 64cb3d98b6316586e6056d182051aa9d28fdedfbf4b908e6b7a7d70209b1db11 @@ -2182,8 +2182,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P e253bb36a5f4f601c9b08858b55a9ce198239ace8efa8dab7c0ec019028967c1 -R 9b310c2f5986c86858424e569b4e6f77 -U stephan -Z 6c78d97a358d85a52548c24a097975e6 +P 87c54f93f5711739741ed0ff3c1a6fe24ffc8a025b43523bf78c1f6be8c1b4cd +R 5d99a8b46e486ca8140c2e5b9bcd6d3d +U drh +Z 2928903171aaf3fcef9f3546955ace45 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 906e916a84..f2c8986bfb 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -87c54f93f5711739741ed0ff3c1a6fe24ffc8a025b43523bf78c1f6be8c1b4cd \ No newline at end of file +92e9a71bc4daa261d7c9a81fb66f7d7c0f0a74eb9e0c9dec8b4651acc5217bff \ No newline at end of file From 41c9945c746018b3bcec1e6ecc3e900f7b209ce4 Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 25 Mar 2024 11:34:42 +0000 Subject: [PATCH 279/430] Use the SQLITE_CONSTRAINT return value from xBestIndex to prohibit bad query plans in the pragma virtual table. FossilOrigin-Name: b1259d4448f744861e416f42328c1450854370e5c77102d2a5abe5cf6c7f12bd --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/pragma.c | 17 +++++++---------- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/manifest b/manifest index 16315ac093..462d7295e3 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improvements\sto\sthe\svtablog.c\sextension:\s\sEliminate\smemory\sleaks.\nMore\sdiagnostic\soutput\sfor\sxBestIndex. -D 2024-03-25T10:55:08.289 +C Use\sthe\sSQLITE_CONSTRAINT\sreturn\svalue\sfrom\sxBestIndex\sto\sprohibit\sbad\nquery\splans\sin\sthe\spragma\svirtual\stable. +D 2024-03-25T11:34:42.948 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -743,7 +743,7 @@ F src/parse.y 5bcef16094213efcc365a9d4dc4e3131f09251dc8838dce4a9e5f9764bff5b82 F src/pcache.c 040b165f30622a21b7a9a77c6f2e4877a32fb7f22d4c7f0d2a6fa6833a156a75 F src/pcache.h 1497ce1b823cf00094bb0cf3bac37b345937e6f910890c626b16512316d3abf5 F src/pcache1.c 602acb23c471bb8d557a6f0083cc2be641d6cafcafa19e481eba7ef4c9ca0f00 -F src/pragma.c 4629926f936cdc586873d5ff24acb1af12a1db0172988a0dc2b32e46b798a640 +F src/pragma.c f8f1845b42df684e9d31c5a1628c989a34939686049d7878bc5394ac1ae9cac4 F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7 F src/prepare.c 371f6115cb69286ebc12c6f2d7511279c2e47d9f54f475d46a554d687a3b312c F src/printf.c 87b67bba3662a0523f39ae6b084a3907109702f717c654d6cecb838af5cd57f1 @@ -2182,8 +2182,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 87c54f93f5711739741ed0ff3c1a6fe24ffc8a025b43523bf78c1f6be8c1b4cd -R 5d99a8b46e486ca8140c2e5b9bcd6d3d +P 92e9a71bc4daa261d7c9a81fb66f7d7c0f0a74eb9e0c9dec8b4651acc5217bff +R 7a45ef8d7654e3d4a6dd224e77e73806 U drh -Z 2928903171aaf3fcef9f3546955ace45 +Z d7913bb9141ded55d9621342d895b371 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index f2c8986bfb..81c9591139 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -92e9a71bc4daa261d7c9a81fb66f7d7c0f0a74eb9e0c9dec8b4651acc5217bff \ No newline at end of file +b1259d4448f744861e416f42328c1450854370e5c77102d2a5abe5cf6c7f12bd \ No newline at end of file diff --git a/src/pragma.c b/src/pragma.c index d14428f75e..8af18cbf20 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -2870,9 +2870,9 @@ static int pragmaVtabBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){ seen[0] = 0; seen[1] = 0; for(i=0; inConstraint; i++, pConstraint++){ - if( pConstraint->usable==0 ) continue; - if( pConstraint->op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue; if( pConstraint->iColumn < pTab->iHidden ) continue; + if( pConstraint->op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue; + if( pConstraint->usable==0 ) return SQLITE_CONSTRAINT; j = pConstraint->iColumn - pTab->iHidden; assert( j < 2 ); seen[j] = i+1; @@ -2885,16 +2885,13 @@ static int pragmaVtabBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){ j = seen[0]-1; pIdxInfo->aConstraintUsage[j].argvIndex = 1; pIdxInfo->aConstraintUsage[j].omit = 1; - if( seen[1]==0 ){ - pIdxInfo->estimatedCost = (double)1000; - pIdxInfo->estimatedRows = 1000; - return SQLITE_OK; - } pIdxInfo->estimatedCost = (double)20; pIdxInfo->estimatedRows = 20; - j = seen[1]-1; - pIdxInfo->aConstraintUsage[j].argvIndex = 2; - pIdxInfo->aConstraintUsage[j].omit = 1; + if( seen[1] ){ + j = seen[1]-1; + pIdxInfo->aConstraintUsage[j].argvIndex = 2; + pIdxInfo->aConstraintUsage[j].omit = 1; + } return SQLITE_OK; } From 99b4e6e25467f33db7e4140ce70bb052b01e2c02 Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 25 Mar 2024 12:28:06 +0000 Subject: [PATCH 280/430] Fix recent test case changes so that they also work on Windows. FossilOrigin-Name: 38578b5af2e97c420f3106bc486318604aecbaa327365bbc2e9518be84491495 --- manifest | 14 +++++++------- manifest.uuid | 2 +- test/pragma4.test | 6 +++++- test/readonly.test | 1 + 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 462d7295e3..9250890ce0 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Use\sthe\sSQLITE_CONSTRAINT\sreturn\svalue\sfrom\sxBestIndex\sto\sprohibit\sbad\nquery\splans\sin\sthe\spragma\svirtual\stable. -D 2024-03-25T11:34:42.948 +C Fix\srecent\stest\scase\schanges\sso\sthat\sthey\salso\swork\son\sWindows. +D 2024-03-25T12:28:06.030 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -1501,7 +1501,7 @@ F test/pg_common.tcl 3b27542224db1e713ae387459b5d117c836a5f6e328846922993b6d2b76 F test/pragma.test 8bb6d3992c1c31ff6d5553d1e0693d642f7e19015648c6ae7034cb497d26bbd4 F test/pragma2.test e5d5c176360c321344249354c0c16aec46214c9f F test/pragma3.test 92a46bbea12322dd94a404f49edcfbfc913a2c98115f0d030a7459bb4712ef31 -F test/pragma4.test 1951dc5a6d87c4ccd8eab35c65f18380c80fac4a0897e828cf518e3cc8a4c292 +F test/pragma4.test d864430507fc5628c150f1e50c1d128a444ccf8dab39b5465644f53fa4232311 F test/pragma5.test 7b33fc43e2e41abf17f35fb73f71b49671a380ea92a6c94b6ce530a25f8d9102 F test/pragma6.test c5ec577ba087954b4dfa619a3cbe97b155b60a0af487527abe89b10fc17e6512 F test/pragmafault.test 275edaf3161771d37de60e5c2b412627ac94cef11739236bec12ed1258b240f8 @@ -1522,7 +1522,7 @@ F test/randexpr1.tcl 40dec52119ed3a2b8b2a773bce24b63a3a746459 F test/randexpr1.test eda062a97e60f9c38ae8d806b03b0ddf23d796df F test/rbu.test 168573d353cd0fd10196b87b0caa322c144ef736 F test/rdonly.test 64e2696c322e3538df0b1ed624e21f9a23ed9ff8 -F test/readonly.test bdf5a451f415bc3153764122d034f553797c27194ffbd1e9763ecd9500af41d2 +F test/readonly.test c1985f0b4ab55041f2ba629dadc6578a3ff0f0e5b0ec7912e85c51f49c3e82fe F test/recover.test 6463509a7404e0c35431dd9b4a1c3b4a29d7a6af8a08462b31670c8a5a616d3a F test/regexp1.test 8f2a8bc1569666e29a4cee6c1a666cd224eb6d50e2470d1dc1df995170f3e0f1 F test/regexp2.test 55ed41da802b0e284ac7e2fe944be3948f93ff25abbca0361a609acfed1368b5 @@ -2182,8 +2182,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 92e9a71bc4daa261d7c9a81fb66f7d7c0f0a74eb9e0c9dec8b4651acc5217bff -R 7a45ef8d7654e3d4a6dd224e77e73806 +P b1259d4448f744861e416f42328c1450854370e5c77102d2a5abe5cf6c7f12bd +R 8e93d8f33bb14264477f8796f06f56d6 U drh -Z d7913bb9141ded55d9621342d895b371 +Z 14ed6a8037fd4481b1dadac4489cca1e # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 81c9591139..ca79f423a7 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b1259d4448f744861e416f42328c1450854370e5c77102d2a5abe5cf6c7f12bd \ No newline at end of file +38578b5af2e97c420f3106bc486318604aecbaa327365bbc2e9518be84491495 \ No newline at end of file diff --git a/test/pragma4.test b/test/pragma4.test index 9b2fa9ba2a..7c244c78b6 100644 --- a/test/pragma4.test +++ b/test/pragma4.test @@ -83,7 +83,7 @@ foreach {tn sql} { # Verify that that P4_INTARRAY argument to OP_IntegrityCk is rendered # correctly. # -db close +catch {db close} forcedelete test.db sqlite3 db test.db do_test pragma4-2.100 { @@ -266,8 +266,12 @@ do_execsql_test 5.0 { # 2024-03-24 https://sqlite.org/forum/forumpost/85b6a8b6705fb77a # +catch {db2 close} +catch {db3 close} reset_db do_execsql_test 6.0 { + DROP TABLE IF EXISTS t1; + DROP TABLE IF EXISTS t2; CREATE TABLE t1(a INT PRIMARY KEY, b INT); CREATE TABLE t2(c INT PRIMARY KEY, d INT REFERENCES t1); SELECT t.name, f."table", f."from", i.name, i.pk diff --git a/test/readonly.test b/test/readonly.test index 811d54f3b5..1ccbcee284 100644 --- a/test/readonly.test +++ b/test/readonly.test @@ -15,6 +15,7 @@ set testdir [file dirname $argv0] source $testdir/tester.tcl +if {$tcl_platform(platform)=="windows"} finish_test source $testdir/lock_common.tcl source $testdir/wal_common.tcl set ::testprefix readonly From bcf97e70f5ee50dac50f8604c9b62b3429912bff Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 25 Mar 2024 13:18:46 +0000 Subject: [PATCH 281/430] Fix the pragma4.test script so that it works with SQLITE_OMIT_VIRTUALTABLE. FossilOrigin-Name: f8fe6fb69c4164d087783a0d6990112afabea78daa4d8985eb6df7df6f45ac27 --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/pragma4.test | 26 ++++++++++++++------------ 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/manifest b/manifest index 9250890ce0..4797b53cd8 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\srecent\stest\scase\schanges\sso\sthat\sthey\salso\swork\son\sWindows. -D 2024-03-25T12:28:06.030 +C Fix\sthe\spragma4.test\sscript\sso\sthat\sit\sworks\swith\sSQLITE_OMIT_VIRTUALTABLE. +D 2024-03-25T13:18:46.591 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -1501,7 +1501,7 @@ F test/pg_common.tcl 3b27542224db1e713ae387459b5d117c836a5f6e328846922993b6d2b76 F test/pragma.test 8bb6d3992c1c31ff6d5553d1e0693d642f7e19015648c6ae7034cb497d26bbd4 F test/pragma2.test e5d5c176360c321344249354c0c16aec46214c9f F test/pragma3.test 92a46bbea12322dd94a404f49edcfbfc913a2c98115f0d030a7459bb4712ef31 -F test/pragma4.test d864430507fc5628c150f1e50c1d128a444ccf8dab39b5465644f53fa4232311 +F test/pragma4.test 22834a228e59b80f5c15b519b710474859d91535002670ddb7cd13ac44b54e9a F test/pragma5.test 7b33fc43e2e41abf17f35fb73f71b49671a380ea92a6c94b6ce530a25f8d9102 F test/pragma6.test c5ec577ba087954b4dfa619a3cbe97b155b60a0af487527abe89b10fc17e6512 F test/pragmafault.test 275edaf3161771d37de60e5c2b412627ac94cef11739236bec12ed1258b240f8 @@ -2182,8 +2182,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P b1259d4448f744861e416f42328c1450854370e5c77102d2a5abe5cf6c7f12bd -R 8e93d8f33bb14264477f8796f06f56d6 +P 38578b5af2e97c420f3106bc486318604aecbaa327365bbc2e9518be84491495 +R 4aabcb0c5c9b41b63fc5196fb947c9b6 U drh -Z 14ed6a8037fd4481b1dadac4489cca1e +Z d83b8554c188328afa7b3f0d71ba5b85 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index ca79f423a7..e76f63aa38 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -38578b5af2e97c420f3106bc486318604aecbaa327365bbc2e9518be84491495 \ No newline at end of file +f8fe6fb69c4164d087783a0d6990112afabea78daa4d8985eb6df7df6f45ac27 \ No newline at end of file diff --git a/test/pragma4.test b/test/pragma4.test index 7c244c78b6..6d59b4fff3 100644 --- a/test/pragma4.test +++ b/test/pragma4.test @@ -268,17 +268,19 @@ do_execsql_test 5.0 { # catch {db2 close} catch {db3 close} -reset_db -do_execsql_test 6.0 { - DROP TABLE IF EXISTS t1; - DROP TABLE IF EXISTS t2; - CREATE TABLE t1(a INT PRIMARY KEY, b INT); - CREATE TABLE t2(c INT PRIMARY KEY, d INT REFERENCES t1); - SELECT t.name, f."table", f."from", i.name, i.pk - FROM pragma_table_list() AS t - JOIN pragma_foreign_key_list(t.name, t.schema) AS f - JOIN pragma_table_info(f."table", t.schema) AS i - WHERE i.pk; -} {t2 t1 d a 1} +ifcapable vtab { + reset_db + do_execsql_test 6.0 { + DROP TABLE IF EXISTS t1; + DROP TABLE IF EXISTS t2; + CREATE TABLE t1(a INT PRIMARY KEY, b INT); + CREATE TABLE t2(c INT PRIMARY KEY, d INT REFERENCES t1); + SELECT t.name, f."table", f."from", i.name, i.pk + FROM pragma_table_list() AS t + JOIN pragma_foreign_key_list(t.name, t.schema) AS f + JOIN pragma_table_info(f."table", t.schema) AS i + WHERE i.pk; + } {t2 t1 d a 1} +} finish_test From ed6c9aa6abf27b198313a1e274a7a9a22b6a8542 Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 25 Mar 2024 14:44:10 +0000 Subject: [PATCH 282/430] Fix an inaccuracy in automatic indexes that was exposed by the fix at [80c4223098c1827f]. FossilOrigin-Name: fdc9406f1c8ba4a7341c1e408f6042ddc788cf65f98e1de2ee101390bfb0abae --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/where.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 4797b53cd8..a5e165b27b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\spragma4.test\sscript\sso\sthat\sit\sworks\swith\sSQLITE_OMIT_VIRTUALTABLE. -D 2024-03-25T13:18:46.591 +C Fix\san\sinaccuracy\sin\sautomatic\sindexes\sthat\swas\sexposed\sby\sthe\sfix\nat\s[80c4223098c1827f]. +D 2024-03-25T14:44:10.198 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -835,7 +835,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c 887fc4ca3f020ebb2e376f222069570834ac63bf50111ef0cbf3ae417048ed89 F src/wal.h ba252daaa94f889f4b2c17c027e823d9be47ce39da1d3799886bbd51f0490452 F src/walker.c 7c7ea0115345851c3da4e04e2e239a29983b61fb5b038b94eede6aba462640e2 -F src/where.c 2e01199202dd117a27f7597e1f554a5cd55e7465e2f39ff9a78adc9cba98b971 +F src/where.c 11a67988c3a5be2e7ee07c958998f3ad4b30dc491c0add894c2933c752415b16 F src/whereInt.h 82a13766f13d1a53b05387c2e60726289ef26404bc7b9b1f7770204d97357fb8 F src/wherecode.c 5d77db30a2a3dd532492ae882de114edba2fae672622056b1c7fd61f5917a8f1 F src/whereexpr.c 7b64295f1d82ad0928df435925dd7bbd5997b44a026153113eace0d9e71ff435 @@ -2182,8 +2182,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 38578b5af2e97c420f3106bc486318604aecbaa327365bbc2e9518be84491495 -R 4aabcb0c5c9b41b63fc5196fb947c9b6 +P f8fe6fb69c4164d087783a0d6990112afabea78daa4d8985eb6df7df6f45ac27 +R a7eca515ed0d2c704ec351621eaadae9 U drh -Z d83b8554c188328afa7b3f0d71ba5b85 +Z 126d8b46e6dcce24a23c7b6d521c4841 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index e76f63aa38..e02a458158 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f8fe6fb69c4164d087783a0d6990112afabea78daa4d8985eb6df7df6f45ac27 \ No newline at end of file +fdc9406f1c8ba4a7341c1e408f6042ddc788cf65f98e1de2ee101390bfb0abae \ No newline at end of file diff --git a/src/where.c b/src/where.c index 3fbb768af5..5767b44128 100644 --- a/src/where.c +++ b/src/where.c @@ -984,7 +984,7 @@ static SQLITE_NOINLINE void constructAutomaticIndex( ** if they go out of sync. */ if( IsView(pTable) ){ - extraCols = ALLBITS; + extraCols = ALLBITS & ~idxCols; }else{ extraCols = pSrc->colUsed & (~idxCols | MASKBIT(BMS-1)); } From f7aab656ff0c38260c2daf01591518cadcd04359 Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 25 Mar 2024 17:43:11 +0000 Subject: [PATCH 283/430] Remove an ALWAYS() from a condition that can be true. FossilOrigin-Name: 715fcf033a6c0c64fa3076d58be8c39246aebef922c1a44a31831b40e165015e --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/vtab.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index a5e165b27b..991d1c97d7 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\san\sinaccuracy\sin\sautomatic\sindexes\sthat\swas\sexposed\sby\sthe\sfix\nat\s[80c4223098c1827f]. -D 2024-03-25T14:44:10.198 +C Remove\san\sALWAYS()\sfrom\sa\scondition\sthat\scan\sbe\strue. +D 2024-03-25T17:43:11.374 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -830,7 +830,7 @@ F src/vdbemem.c 213bf303826c0ef702e3a2a69dab2309d84b8381b822c6787885859fd7cd4c4e F src/vdbesort.c 237840ca1947511fa59bd4e18b9eeae93f2af2468c34d2427b059f896230a547 F src/vdbetrace.c fe0bc29ebd4e02c8bc5c1945f1d2e6be5927ec12c06d89b03ef2a4def34bf823 F src/vdbevtab.c 2143db7db0ceed69b21422581f434baffc507a08d831565193a7a02882a1b6a7 -F src/vtab.c 38fcf63832f7e606755fa47b028c2eb6d6cd5facb40e280d66fbda4ed9a52188 +F src/vtab.c cd53fee1d4ca6c9dd6eb673aeb87ecaa1c5a067da30e3b231678bd9e3f771b60 F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c 887fc4ca3f020ebb2e376f222069570834ac63bf50111ef0cbf3ae417048ed89 F src/wal.h ba252daaa94f889f4b2c17c027e823d9be47ce39da1d3799886bbd51f0490452 @@ -2182,8 +2182,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P f8fe6fb69c4164d087783a0d6990112afabea78daa4d8985eb6df7df6f45ac27 -R a7eca515ed0d2c704ec351621eaadae9 +P fdc9406f1c8ba4a7341c1e408f6042ddc788cf65f98e1de2ee101390bfb0abae +R f76b08b792dbded66ddcd94e7cec15b2 U drh -Z 126d8b46e6dcce24a23c7b6d521c4841 +Z b7fa3cba61650ea05eb1778d7cc33597 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index e02a458158..ae66038eef 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -fdc9406f1c8ba4a7341c1e408f6042ddc788cf65f98e1de2ee101390bfb0abae \ No newline at end of file +715fcf033a6c0c64fa3076d58be8c39246aebef922c1a44a31831b40e165015e \ No newline at end of file diff --git a/src/vtab.c b/src/vtab.c index 67226c63c8..199ae32171 100644 --- a/src/vtab.c +++ b/src/vtab.c @@ -840,7 +840,7 @@ int sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){ db->init.busy = 0; sParse.nQueryLoop = 1; if( SQLITE_OK==sqlite3RunParser(&sParse, zCreateTable) - && ALWAYS(sParse.pNewTable!=0) + && sParse.pNewTable!=0 && ALWAYS(!db->mallocFailed) && IsOrdinaryTable(sParse.pNewTable) ){ From 791b6f36cc8ed25766e709dfe2dc6d23782652b8 Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 25 Mar 2024 18:24:28 +0000 Subject: [PATCH 284/430] Revert the previous change. Instead, do a pre-check of the CREATE TABLE statement that is the second argument to sqlite3_declare_vtab() and if the first two keywords are not "CREATE" and "TABLE", then raise an SQLITE_MISUSE error. FossilOrigin-Name: 6a2ff8351244da2336055454dfad2dd40534b7cfb51e840f7f8cf2ddacf8649e --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/vtab.c | 18 +++++++++++++++++- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 991d1c97d7..3e57f6173d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\san\sALWAYS()\sfrom\sa\scondition\sthat\scan\sbe\strue. -D 2024-03-25T17:43:11.374 +C Revert\sthe\sprevious\schange.\s\sInstead,\sdo\sa\spre-check\sof\sthe\sCREATE\sTABLE\nstatement\sthat\sis\sthe\ssecond\sargument\sto\ssqlite3_declare_vtab()\sand\sif\nthe\sfirst\stwo\skeywords\sare\snot\s"CREATE"\sand\s"TABLE",\sthen\sraise\san\nSQLITE_MISUSE\serror. +D 2024-03-25T18:24:28.496 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -830,7 +830,7 @@ F src/vdbemem.c 213bf303826c0ef702e3a2a69dab2309d84b8381b822c6787885859fd7cd4c4e F src/vdbesort.c 237840ca1947511fa59bd4e18b9eeae93f2af2468c34d2427b059f896230a547 F src/vdbetrace.c fe0bc29ebd4e02c8bc5c1945f1d2e6be5927ec12c06d89b03ef2a4def34bf823 F src/vdbevtab.c 2143db7db0ceed69b21422581f434baffc507a08d831565193a7a02882a1b6a7 -F src/vtab.c cd53fee1d4ca6c9dd6eb673aeb87ecaa1c5a067da30e3b231678bd9e3f771b60 +F src/vtab.c 13481f3532a3a89624d1853ebc8c980215e716e275a729444c12e3f1005b4b74 F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c 887fc4ca3f020ebb2e376f222069570834ac63bf50111ef0cbf3ae417048ed89 F src/wal.h ba252daaa94f889f4b2c17c027e823d9be47ce39da1d3799886bbd51f0490452 @@ -2182,8 +2182,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P fdc9406f1c8ba4a7341c1e408f6042ddc788cf65f98e1de2ee101390bfb0abae -R f76b08b792dbded66ddcd94e7cec15b2 +P 715fcf033a6c0c64fa3076d58be8c39246aebef922c1a44a31831b40e165015e +R 56888bcd4145065d254cef5a88e451fc U drh -Z b7fa3cba61650ea05eb1778d7cc33597 +Z d2c55463ac4c41ce779d550b765c534c # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index ae66038eef..8fc054c745 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -715fcf033a6c0c64fa3076d58be8c39246aebef922c1a44a31831b40e165015e \ No newline at end of file +6a2ff8351244da2336055454dfad2dd40534b7cfb51e840f7f8cf2ddacf8649e \ No newline at end of file diff --git a/src/vtab.c b/src/vtab.c index 199ae32171..aad93fef8b 100644 --- a/src/vtab.c +++ b/src/vtab.c @@ -813,12 +813,27 @@ int sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){ Table *pTab; Parse sParse; int initBusy; + int i; + const unsigned char *z; + static const u8 aKeyword[] = { TK_CREATE, TK_TABLE, 0 }; #ifdef SQLITE_ENABLE_API_ARMOR if( !sqlite3SafetyCheckOk(db) || zCreateTable==0 ){ return SQLITE_MISUSE_BKPT; } #endif + + /* Verify that the first two keywords in the CREATE TABLE statement + ** really are "CREATE" and "TABLE". If this is not the case, then + ** sqlite3_declare_vtab() is being misused. + */ + z = (const unsigned char*)zCreateTable; + for(i=0; aKeyword[i]; i++){ + int tokenType = 0; + do{ z += sqlite3GetToken(z, &tokenType); }while( tokenType==TK_SPACE ); + if( tokenType!=aKeyword[i] ) return SQLITE_MISUSE_BKPT; + } + sqlite3_mutex_enter(db->mutex); pCtx = db->pVtabCtx; if( !pCtx || pCtx->bDeclared ){ @@ -826,6 +841,7 @@ int sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){ sqlite3_mutex_leave(db->mutex); return SQLITE_MISUSE_BKPT; } + pTab = pCtx->pTab; assert( IsVirtual(pTab) ); @@ -840,7 +856,7 @@ int sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){ db->init.busy = 0; sParse.nQueryLoop = 1; if( SQLITE_OK==sqlite3RunParser(&sParse, zCreateTable) - && sParse.pNewTable!=0 + && ALWAYS(sParse.pNewTable!=0) && ALWAYS(!db->mallocFailed) && IsOrdinaryTable(sParse.pNewTable) ){ From eb5bd4db91430a44f96bf636e4aba1c5eaa69c7d Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 25 Mar 2024 18:30:15 +0000 Subject: [PATCH 285/430] Fix a theoretical OOB memory access in sqlite3_stmt_scanstatus_v2(). FossilOrigin-Name: 87be9580747b405c2c534beadb0f95cee0d4f34e0245f90e157a6b7ada38e092 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/vdbeapi.c | 3 ++- test/scanstatus2.test | 11 +++++++++++ 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 3e57f6173d..2ec51c300c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Revert\sthe\sprevious\schange.\s\sInstead,\sdo\sa\spre-check\sof\sthe\sCREATE\sTABLE\nstatement\sthat\sis\sthe\ssecond\sargument\sto\ssqlite3_declare_vtab()\sand\sif\nthe\sfirst\stwo\skeywords\sare\snot\s"CREATE"\sand\s"TABLE",\sthen\sraise\san\nSQLITE_MISUSE\serror. -D 2024-03-25T18:24:28.496 +C Fix\sa\stheoretical\sOOB\smemory\saccess\sin\ssqlite3_stmt_scanstatus_v2(). +D 2024-03-25T18:30:15.250 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -823,7 +823,7 @@ F src/vacuum.c 604fcdaebe76f3497c855afcbf91b8fa5046b32de3045bab89cc008d68e40104 F src/vdbe.c 651aa0f31027d5d0a133eb7b41d11c41dc3b88ecb760b770430da0e477ae3b6c F src/vdbe.h c2d78d15112c3fc5ab87f5e8e0b75d2db1c624409de2e858c3d1aafb1650bb4f F src/vdbeInt.h 949669dfd8a41550d27dcb905b494f2ccde9a2e6c1b0b04daa1227e2e74c2b2c -F src/vdbeapi.c 8f57d60c89da0b60e6d4e272358c511f6bae4e24330bdb11f8b42f986d1bf21b +F src/vdbeapi.c 80235ac380e9467fec1cb0883354d841f2a771976e766995f7e0c77f845406df F src/vdbeaux.c 6385727adf51a649e4993098870a62c3945fe21dbc0e0fd9013772aff930b8fb F src/vdbeblob.c 13f9287b55b6356b4b1845410382d6bede203ceb29ef69388a4a3d007ffacbe5 F src/vdbemem.c 213bf303826c0ef702e3a2a69dab2309d84b8381b822c6787885859fd7cd4c4e @@ -1560,7 +1560,7 @@ F test/savepoint6.test f41279c5e137139fa5c21485773332c7adb98cd7 F test/savepoint7.test cde525ea3075283eb950cdcdefe23ead4f700daa F test/savepointfault.test f044eac64b59f09746c7020ee261734de82bf9b2 F test/scanstatus.test b249328caf4d317e71058006872b8012598a5fa045b30bf24a81eeff650ab49e -F test/scanstatus2.test 317670daf7f3eef48a9598cb7800ba8eccab51949cf52bca3f7da3b83a0c1c8c +F test/scanstatus2.test 688adc0c3ab1ffadead218cbce6446b10aa892004a8ea5e3640d59257fb836f2 F test/schema.test 5dd11c96ba64744de955315d2e4f8992e447533690153b93377dffb2a5ef5431 F test/schema2.test 906408621ea881fdb496d878b1822572a34e32c5 F test/schema3.test 8ed4ae66e082cdd8b1b1f22d8549e1e7a0db4527a8e6ee8b6193053ee1e5c9ce @@ -2182,8 +2182,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 715fcf033a6c0c64fa3076d58be8c39246aebef922c1a44a31831b40e165015e -R 56888bcd4145065d254cef5a88e451fc -U drh -Z d2c55463ac4c41ce779d550b765c534c +P 6a2ff8351244da2336055454dfad2dd40534b7cfb51e840f7f8cf2ddacf8649e +R 1054addf5a80b70d64920561ede27990 +U dan +Z b1b40567e29d2af418e3b643400eabb8 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 8fc054c745..e0d4ad9044 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6a2ff8351244da2336055454dfad2dd40534b7cfb51e840f7f8cf2ddacf8649e \ No newline at end of file +87be9580747b405c2c534beadb0f95cee0d4f34e0245f90e157a6b7ada38e092 \ No newline at end of file diff --git a/src/vdbeapi.c b/src/vdbeapi.c index 14c6091e0c..3182e4070f 100644 --- a/src/vdbeapi.c +++ b/src/vdbeapi.c @@ -2404,7 +2404,6 @@ int sqlite3_stmt_scanstatus_v2( } if( flags & SQLITE_SCANSTAT_COMPLEX ){ idx = iScan; - pScan = &p->aScan[idx]; }else{ /* If the COMPLEX flag is clear, then this function must ignore any ** ScanStatus structures with ScanStatus.addrLoop set to 0. */ @@ -2417,6 +2416,8 @@ int sqlite3_stmt_scanstatus_v2( } } if( idx>=p->nScan ) return 1; + assert( pScan==0 || pScan==&p->aScan[idx] ); + pScan = &p->aScan[idx]; switch( iScanStatusOp ){ case SQLITE_SCANSTAT_NLOOP: { diff --git a/test/scanstatus2.test b/test/scanstatus2.test index e4b510d20f..7f107cd2eb 100644 --- a/test/scanstatus2.test +++ b/test/scanstatus2.test @@ -328,6 +328,17 @@ QUERY (nCycle=nnn) --SCAN xy2 (nCycle=nnn) } +#------------------------------------------------------------------------- +reset_db + +# Check that an OOB parameter (45) does not cause asan or valgrind errors. +# +do_test 7.0 { + db eval {SELECT * FROM sqlite_schema} + set stmt [db version -last-stmt-ptr] + sqlite3_stmt_scanstatus -flags complex $stmt 1000000 +} {} + #explain_i { SELECT (a % 2), group_concat(b) FROM t1 GROUP BY 1 } #puts_debug_info { SELECT (a % 2), group_concat(b) FROM t1 GROUP BY 1 } From 1872f8d8442f0c21a7ae573dc557a1784e30bbf1 Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 25 Mar 2024 19:31:03 +0000 Subject: [PATCH 286/430] Simplifications to the sqlite3_declare_vtab() implementation. Changes some conditionals into assert() statements, for coverage. FossilOrigin-Name: ff7b898a6f9cb9aecb51bd6b63e253b4b7486ac9367f59c3c0491d78cfb39993 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/vtab.c | 9 ++++----- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/manifest b/manifest index 2ec51c300c..ba1ed56e3d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\stheoretical\sOOB\smemory\saccess\sin\ssqlite3_stmt_scanstatus_v2(). -D 2024-03-25T18:30:15.250 +C Simplifications\sto\sthe\ssqlite3_declare_vtab()\simplementation.\s\sChanges\nsome\sconditionals\sinto\sassert()\sstatements,\sfor\scoverage. +D 2024-03-25T19:31:03.875 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -830,7 +830,7 @@ F src/vdbemem.c 213bf303826c0ef702e3a2a69dab2309d84b8381b822c6787885859fd7cd4c4e F src/vdbesort.c 237840ca1947511fa59bd4e18b9eeae93f2af2468c34d2427b059f896230a547 F src/vdbetrace.c fe0bc29ebd4e02c8bc5c1945f1d2e6be5927ec12c06d89b03ef2a4def34bf823 F src/vdbevtab.c 2143db7db0ceed69b21422581f434baffc507a08d831565193a7a02882a1b6a7 -F src/vtab.c 13481f3532a3a89624d1853ebc8c980215e716e275a729444c12e3f1005b4b74 +F src/vtab.c 4c475fb672a6fe57830561e614dbee21a9a24a6f616d1cfcbe85f356a09f14ad F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c 887fc4ca3f020ebb2e376f222069570834ac63bf50111ef0cbf3ae417048ed89 F src/wal.h ba252daaa94f889f4b2c17c027e823d9be47ce39da1d3799886bbd51f0490452 @@ -2182,8 +2182,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 6a2ff8351244da2336055454dfad2dd40534b7cfb51e840f7f8cf2ddacf8649e -R 1054addf5a80b70d64920561ede27990 -U dan -Z b1b40567e29d2af418e3b643400eabb8 +P 87be9580747b405c2c534beadb0f95cee0d4f34e0245f90e157a6b7ada38e092 +R ad8aac9f3b06a2e42b637acda669767c +U drh +Z b1a7a78f1aa22406dcb910ac85bd2eff # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index e0d4ad9044..f0cba94336 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -87be9580747b405c2c534beadb0f95cee0d4f34e0245f90e157a6b7ada38e092 \ No newline at end of file +ff7b898a6f9cb9aecb51bd6b63e253b4b7486ac9367f59c3c0491d78cfb39993 \ No newline at end of file diff --git a/src/vtab.c b/src/vtab.c index aad93fef8b..61dafab711 100644 --- a/src/vtab.c +++ b/src/vtab.c @@ -855,11 +855,10 @@ int sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){ initBusy = db->init.busy; db->init.busy = 0; sParse.nQueryLoop = 1; - if( SQLITE_OK==sqlite3RunParser(&sParse, zCreateTable) - && ALWAYS(sParse.pNewTable!=0) - && ALWAYS(!db->mallocFailed) - && IsOrdinaryTable(sParse.pNewTable) - ){ + if( SQLITE_OK==sqlite3RunParser(&sParse, zCreateTable) ){ + assert( sParse.pNewTable!=0 ); + assert( !db->mallocFailed ); + assert( IsOrdinaryTable(sParse.pNewTable) ); assert( sParse.zErrMsg==0 ); if( !pTab->aCol ){ Table *pNew = sParse.pNewTable; From ca3b9096c45f308b89608155baabfff587d96616 Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 25 Mar 2024 20:00:40 +0000 Subject: [PATCH 287/430] Add further tests for sqlite3_declare_vtab(). FossilOrigin-Name: f3c4433f6b33087494c8d38ff9dbb008a1bd30b424ca9aaa51c1956d75a86249 --- manifest | 13 ++++++------ manifest.uuid | 2 +- test/vtabL.test | 55 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 7 deletions(-) create mode 100644 test/vtabL.test diff --git a/manifest b/manifest index ba1ed56e3d..2f44648bcd 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Simplifications\sto\sthe\ssqlite3_declare_vtab()\simplementation.\s\sChanges\nsome\sconditionals\sinto\sassert()\sstatements,\sfor\scoverage. -D 2024-03-25T19:31:03.875 +C Add\sfurther\stests\sfor\ssqlite3_declare_vtab(). +D 2024-03-25T20:00:40.445 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -1951,6 +1951,7 @@ F test/vtabH.test 2efb5a24b0bb50796b21eca23032cfb77abfa4b0c03938e38ce5897abac404 F test/vtabI.test 751b07636700dbdea328e4265b6077ccd6811a3f F test/vtabJ.test a6aef49d558af90fae10565b29501f82a95781cb4f797f2d13e2d19f9b6bc77b F test/vtabK.test 13293177528fada1235c0112db0d187d754af1355c5a39371abd365104e3afbf +F test/vtabL.test 040b9f782a3b41844f2a5c660e6a0bfd298492980c6b4e126d82113c9785cec3 F test/vtab_alter.test 736e66fb5ec7b4fee58229aa3ada2f27ec58bc58c00edae4836890c3784c6783 F test/vtab_err.test dcc8b7b9cb67522b3fe7a272c73856829dae4ab7fdb30399aea1b6981bda2b65 F test/vtab_shared.test 5253bff2355a9a3f014c15337da7e177ab0ef8ad @@ -2182,8 +2183,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 87be9580747b405c2c534beadb0f95cee0d4f34e0245f90e157a6b7ada38e092 -R ad8aac9f3b06a2e42b637acda669767c -U drh -Z b1a7a78f1aa22406dcb910ac85bd2eff +P ff7b898a6f9cb9aecb51bd6b63e253b4b7486ac9367f59c3c0491d78cfb39993 +R aae449702ba5a25d8e948527e6058f06 +U dan +Z 4c63f0c0b8b71810a39e1da8a896d2df # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index f0cba94336..bb07a9bef8 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ff7b898a6f9cb9aecb51bd6b63e253b4b7486ac9367f59c3c0491d78cfb39993 \ No newline at end of file +f3c4433f6b33087494c8d38ff9dbb008a1bd30b424ca9aaa51c1956d75a86249 \ No newline at end of file diff --git a/test/vtabL.test b/test/vtabL.test new file mode 100644 index 0000000000..a801481c84 --- /dev/null +++ b/test/vtabL.test @@ -0,0 +1,55 @@ +# 2024-03-26 +# +# 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. +# +#*********************************************************************** +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix vtabL + +ifcapable !vtab { + finish_test + return +} + +register_tcl_module db + +proc vtab_command {method args} { + switch -- $method { + xConnect { + return $::create_table_sql + } + } + + return {} +} + +do_execsql_test 1.0 { + CREATE TABLE t1(a, b); +} + +foreach {tn cts} { + 1 {SELECT 123} + 2 {SELECT 123, 456} + 3 {INSERT INTO t1 VALUES(5, 6)} + 4 {CREATE INDEX i1 ON t1(a)} + 5 {CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN SELECT 1; END;} + 6 {DROP TABLE nosuchtable} + 7 {DROP TABLE x1} + 8 {DROP TABLE t1} +} { + set ::create_table_sql $cts + do_catchsql_test 1.$tn { + CREATE VIRTUAL TABLE x1 USING tcl(vtab_command); + } {1 {vtable constructor failed: x1}} +} + +finish_test + From a509a90958ddb234d1785ed7801880ccb18b497e Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 25 Mar 2024 20:35:14 +0000 Subject: [PATCH 288/430] The RAISE() operator is not a constant expression and cannot participate in the VALUE-as-coroutine optimization. dbsqlfuzz 74cf7c9904360322a6c917e4934b127543d1cd51 FossilOrigin-Name: 6a06dc73847716c88d65651d1bf0e002002303881df1389beac884d0032eae08 --- manifest | 18 +++++++-------- manifest.uuid | 2 +- src/expr.c | 2 ++ src/insert.c | 6 +++-- test/values.test | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 74 insertions(+), 12 deletions(-) diff --git a/manifest b/manifest index 2f44648bcd..24f7bb9fb9 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sfurther\stests\sfor\ssqlite3_declare_vtab(). -D 2024-03-25T20:00:40.445 +C The\sRAISE()\soperator\sis\snot\sa\sconstant\sexpression\sand\scannot\sparticipate\sin\nthe\sVALUE-as-coroutine\soptimization.\ndbsqlfuzz\s74cf7c9904360322a6c917e4934b127543d1cd51 +D 2024-03-25T20:35:14.251 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -700,7 +700,7 @@ F src/date.c 126ba2ab10aeb2e7ba6e089b5f07b747c0625b8287f78b60da346eda8d23c875 F src/dbpage.c 80e46e1df623ec40486da7a5086cb723b0275a6e2a7b01d9f9b5da0f04ba2782 F src/dbstat.c 3b677254d512fcafd4d0b341bf267b38b235ccfddbef24f9154e19360fa22e43 F src/delete.c cb766727c78e715f9fb7ec8a7d03658ed2a3016343ca687acfcec9083cdca500 -F src/expr.c ff1bb1bdbcdc20505cfa900f332e18239ab3cf20d2b0d220a960b5b3513b7cb4 +F src/expr.c cd46ce2ebe46a30e63087dbe8aff7d6e34ba8acc8c658e8e18fcaa35f2711391 F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c a47610f0a5c6cb0ad79f8fcef039c01833dec0c751bb695f28dc0ec6a4c3ba00 F src/func.c 283d4f3b2751a1d9339fd93a8a013d1948fd5f4474a3cab0955eb4fafd445d0f @@ -709,7 +709,7 @@ F src/hash.c 9ee4269fb1d6632a6fecfb9479c93a1f29271bddbbaf215dd60420bcb80c7220 F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 -F src/insert.c 06ce505713e86172612f9e01febefd2d3331d1f70461b4ada0eae5a76bb6349f +F src/insert.c bc4d172b52a6167cd28797397a464c2cca9607dc047dfa0b5cf61687962e6964 F src/json.c e2e40760d6689134c3e2ece38c6a496b34ff5e2661a8f238444a119af666fdce F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 @@ -1924,7 +1924,7 @@ F test/vacuum4.test 7ea76b769fffeb41f925303b04cbcf5a5bbeabe55e4c60ae754ff24eeeb7 F test/vacuum5.test 263b144d537e92ad8e9ca8a73cc6e1583f41cfd0dda9432b87f7806174a2f48c F test/vacuum6.test b137b04bf3392d3f5c3b8fda0ce85a6775a70ca112f6559f74ff52dc9ce042fd F test/vacuummem.test 4b30f5b95a9ff86e9d5c20741e50a898b2dc10b0962a3211571eb165357003fb -F test/values.test ee77c1cb540c47868848f85c39f92bb11d787657ade32f91eedf2988727769cd +F test/values.test 6c2426de40cd397a8ab68d375b6964ab3bce1244bbb69f5d1ed3ccd0e039c1f3 F test/valuesfault.test 2ef23ed965e3bd08e268cdc38a0d11653390ddbbe1e8e2e98d16f55edd30f6e8 F test/varint.test bbce22cda8fc4d135bcc2b589574be8410614e62 F test/veryquick.test 57ab846bacf7b90cf4e9a672721ea5c5b669b661 @@ -2183,8 +2183,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P ff7b898a6f9cb9aecb51bd6b63e253b4b7486ac9367f59c3c0491d78cfb39993 -R aae449702ba5a25d8e948527e6058f06 -U dan -Z 4c63f0c0b8b71810a39e1da8a896d2df +P f3c4433f6b33087494c8d38ff9dbb008a1bd30b424ca9aaa51c1956d75a86249 +R 11afa0c0cb35ff6b57f28ca49a3f27d4 +U drh +Z 38f01fde0dacda37a79ba00b3f8d1e29 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index bb07a9bef8..04e087afeb 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f3c4433f6b33087494c8d38ff9dbb008a1bd30b424ca9aaa51c1956d75a86249 \ No newline at end of file +6a06dc73847716c88d65651d1bf0e002002303881df1389beac884d0032eae08 \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index d71353f174..edfea3fc92 100644 --- a/src/expr.c +++ b/src/expr.c @@ -2474,9 +2474,11 @@ static int exprNodeIsConstant(Walker *pWalker, Expr *pExpr){ case TK_IF_NULL_ROW: case TK_REGISTER: case TK_DOT: + case TK_RAISE: testcase( pExpr->op==TK_REGISTER ); testcase( pExpr->op==TK_IF_NULL_ROW ); testcase( pExpr->op==TK_DOT ); + testcase( pExpr->op==TK_RAISE ); pWalker->eCode = 0; return WRC_Abort; case TK_VARIABLE: diff --git a/src/insert.c b/src/insert.c index fe7ba05dc1..c126a83952 100644 --- a/src/insert.c +++ b/src/insert.c @@ -610,8 +610,10 @@ static int exprListIsNoAffinity(Parse *pParse, ExprList *pRow){ int ii; if( exprListIsConstant(pParse,pRow)==0 ) return 0; for(ii=0; iinExpr; ii++){ - assert( pRow->a[ii].pExpr->affExpr==0 ); - if( 0!=sqlite3ExprAffinity(pRow->a[ii].pExpr) ) return 0; + Expr *pExpr = pRow->a[ii].pExpr; + assert( pExpr->op!=TK_RAISE ); + assert( pExpr->affExpr==0 ); + if( 0!=sqlite3ExprAffinity(pExpr) ) return 0; } return 1; diff --git a/test/values.test b/test/values.test index 26f2812237..4252f2e13b 100644 --- a/test/values.test +++ b/test/values.test @@ -592,4 +592,62 @@ do_execsql_test 17.2 { SELECT * FROM t1 } {1 2 3 0} +# 2024-03-25 dbsqlfuzz crash-74cf7c9904360322a6c917e4934b127543d1cd51 +# +do_catchsql_test 18.1 { + DROP TABLE t1; + CREATE TABLE t1(x INTEGER PRIMARY KEY); + INSERT INTO t1 VALUES(RAISE(IGNORE)),(0); +} {1 {RAISE() may only be used within a trigger-program}} +do_catchsql_test 18.2 { + DROP TABLE t1; + CREATE TABLE t1(x INTEGER PRIMARY KEY, y, z); + CREATE TRIGGER r2 AFTER INSERT ON t1 BEGIN + INSERT INTO t1(y) VALUES(RAISE(IGNORE)),(0); + END; + INSERT INTO t1 VALUES(1,2,3); + SELECT * FROM t1; +} {0 {1 2 3}} +do_catchsql_test 18.3.1 { + DROP TABLE t1; + CREATE TABLE t1(x INTEGER PRIMARY KEY, y, z); + CREATE TRIGGER r2 AFTER INSERT ON t1 BEGIN + INSERT INTO t1(y) VALUES(RAISE(ABORT,'error 18.3')),(0); + END; + INSERT INTO t1 VALUES(1,2,3); +} {1 {error 18.3}} +do_execsql_test 18.3.2 { + SELECT * FROM t1; +} {} +do_catchsql_test 18.4.1 { + DROP TABLE t1; + CREATE TABLE t1(x INTEGER PRIMARY KEY, y, z); + CREATE TRIGGER r2 AFTER INSERT ON t1 BEGIN + INSERT INTO t1(y) VALUES(1),(RAISE(ABORT,'error 18.4')),(0); + END; + INSERT INTO t1 VALUES(1,2,3); +} {1 {error 18.4}} +do_execsql_test 18.4.2 { + SELECT * FROM t1; +} {} +do_catchsql_test 18.5.1 { + DROP TABLE t1; + CREATE TABLE t1(x INTEGER PRIMARY KEY, y, z); + CREATE TRIGGER r2 AFTER INSERT ON t1 BEGIN + INSERT INTO t1(y) VALUES(1), + (CASE WHEN new.z>7 THEN RAISE(ABORT,'error 18.5') ELSE 2 END); + END; + INSERT INTO t1 VALUES(1,2,3); + SELECT * FROM t1; +} {0 {1 2 3 2 1 {} 3 2 {}}} +do_catchsql_test 18.5.2 { + DELETE FROM t1; + INSERT INTO t1 VALUES(1,2,13); +} {1 {error 18.5}} +do_catchsql_test 18.5.3 { + SELECT * FROM t1; +} {0 {}} + + + finish_test From dcc121999cb458e36b5aef9808f856a734041622 Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 26 Mar 2024 11:14:52 +0000 Subject: [PATCH 289/430] Avoid expanding integer values in columns with real affinity to the full 8-byte representation when editing records as part of a DROP COLUMN command. FossilOrigin-Name: a49296de0061931badaf3db6b965131a78b1c6c21b1eeb62815ea7adf767d0b3 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/alter.c | 5 +++++ test/altertab3.test | 23 +++++++++++++++++++++++ 4 files changed, 37 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 24f7bb9fb9..ea43bdf8f8 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C The\sRAISE()\soperator\sis\snot\sa\sconstant\sexpression\sand\scannot\sparticipate\sin\nthe\sVALUE-as-coroutine\soptimization.\ndbsqlfuzz\s74cf7c9904360322a6c917e4934b127543d1cd51 -D 2024-03-25T20:35:14.251 +C Avoid\sexpanding\sinteger\svalues\sin\scolumns\swith\sreal\saffinity\sto\sthe\sfull\s8-byte\srepresentation\swhen\sediting\srecords\sas\spart\sof\sa\sDROP\sCOLUMN\scommand. +D 2024-03-26T11:14:52.242 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -682,7 +682,7 @@ F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b F sqlite3.1 acdff36db796e2d00225b911d3047d580cd136547298435426ce9d40347973cc F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a F sqlite_cfg.h.in baf2e409c63d4e7a765e17769b6ff17c5a82bbd9cbf1e284fd2e4cefaff3fcf2 -F src/alter.c 30c2333b8bb3af71e4eb9adeadee8aa20edb15917ed44b8422e5cd15f3dfcddc +F src/alter.c e1b6782b85dd758f89e5c588e4e3eb82638c2dafc0c857b79a43bb8ec1746fca F src/analyze.c a3df28274e2565ba5656577d7e3fd262169a213e6eb0bd47890e0f0729a4031c F src/attach.c cc9d00d30da916ff656038211410ccf04ed784b7564639b9b61d1839ed69fd39 F src/auth.c 19b7ccacae3dfba23fc6f1d0af68134fa216e9040e53b0681b4715445ea030b4 @@ -867,7 +867,7 @@ F test/altermalloc3.test 8040e486368403f2fdd6fc3998258b499bd4cc2f3ddbb5f8f874cd4 F test/alterqf.test 8ec03d776de9c391daa0078ea8f838903bdcfb11dfae4ba3576b48436834ccba F test/altertab.test 8a2712f9076da5012a002d0b5cc0a421398a5bf61c25bab41b77c427586a7a27 F test/altertab2.test 62597b6fd08feaba1b6bfe7d31dac6117c67e06dc9ce9c478a3abe75b5926de0 -F test/altertab3.test e167ce3b8e243b52306c1e40b13eb868f402a969513c063998593862cc643b44 +F test/altertab3.test b331ae34e69594e19605e3297805202d6156fcc8f75379dfd972a2e51cae8721 F test/altertrig.test aacc980b657354fe2d3d4d3a004f07d04ccc1a93e5ef82d68a79088c274ddc6b F test/amatch1.test b5ae7065f042b7f4c1c922933f4700add50cdb9f F test/analyze.test 2fb21d7d64748636384e6cb8998dbf83968caf644c07fcb4f76c18f2e7ede94b @@ -2183,8 +2183,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P f3c4433f6b33087494c8d38ff9dbb008a1bd30b424ca9aaa51c1956d75a86249 -R 11afa0c0cb35ff6b57f28ca49a3f27d4 -U drh -Z 38f01fde0dacda37a79ba00b3f8d1e29 +P 6a06dc73847716c88d65651d1bf0e002002303881df1389beac884d0032eae08 +R 9f7cc1bf5356d77f08ae122347a7b675 +U dan +Z 96694e9dd3b3c0e4acdff2534541b848 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 04e087afeb..8c514c694f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6a06dc73847716c88d65651d1bf0e002002303881df1389beac884d0032eae08 \ No newline at end of file +a49296de0061931badaf3db6b965131a78b1c6c21b1eeb62815ea7adf767d0b3 \ No newline at end of file diff --git a/src/alter.c b/src/alter.c index ec45e14331..c1e0a295a4 100644 --- a/src/alter.c +++ b/src/alter.c @@ -2262,7 +2262,12 @@ void sqlite3AlterDropColumn(Parse *pParse, SrcList *pSrc, const Token *pName){ if( i==pTab->iPKey ){ sqlite3VdbeAddOp2(v, OP_Null, 0, regOut); }else{ + char aff = pTab->aCol[i].affinity; + if( aff==SQLITE_AFF_REAL ){ + pTab->aCol[i].affinity = SQLITE_AFF_NUMERIC; + } sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, i, regOut); + pTab->aCol[i].affinity = aff; } nField++; } diff --git a/test/altertab3.test b/test/altertab3.test index cb6f00de48..5f5c11b0bb 100644 --- a/test/altertab3.test +++ b/test/altertab3.test @@ -763,4 +763,27 @@ do_execsql_test 30.2 { )} } +#------------------------------------------------------------------------- +reset_db +do_execsql_test 31.0 { + CREATE TABLE t1(ii INTEGER PRIMARY KEY, tt INTEGER, rr REAL); + WITH s(i) AS ( + SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<50000 + ) + INSERT INTO t1 SELECT NULL, i, 5.0 FROM s; +} + +do_test 31.1 { + set pg [db one {PRAGMA page_count}] + execsql { + ALTER TABLE t1 DROP COLUMN tt; + } + set pg2 [db one {PRAGMA page_count}] + expr $pg==$pg2 +} {1} + +do_execsql_test 31.2 { + SELECT rr FROM t1 LIMIT 1 +} {5.0} + finish_test From ed517a708284b6e00b6ae5f1e3f702bbfcbd32ed Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 26 Mar 2024 18:07:39 +0000 Subject: [PATCH 290/430] Add extra tests to vtabL.test. FossilOrigin-Name: fe209099f5c348f1280b9b827ffbf6a6742ebdd1a23ef189445147894b1832ba --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/vtabL.test | 21 +++++++++++++++++---- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index ea43bdf8f8..8b6dfb5fc7 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Avoid\sexpanding\sinteger\svalues\sin\scolumns\swith\sreal\saffinity\sto\sthe\sfull\s8-byte\srepresentation\swhen\sediting\srecords\sas\spart\sof\sa\sDROP\sCOLUMN\scommand. -D 2024-03-26T11:14:52.242 +C Add\sextra\stests\sto\svtabL.test. +D 2024-03-26T18:07:39.608 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -1951,7 +1951,7 @@ F test/vtabH.test 2efb5a24b0bb50796b21eca23032cfb77abfa4b0c03938e38ce5897abac404 F test/vtabI.test 751b07636700dbdea328e4265b6077ccd6811a3f F test/vtabJ.test a6aef49d558af90fae10565b29501f82a95781cb4f797f2d13e2d19f9b6bc77b F test/vtabK.test 13293177528fada1235c0112db0d187d754af1355c5a39371abd365104e3afbf -F test/vtabL.test 040b9f782a3b41844f2a5c660e6a0bfd298492980c6b4e126d82113c9785cec3 +F test/vtabL.test 49ec7342e8bfcb0d6c3d2443c619f430c609c042d5d7e6ddf52def65d6d1812f F test/vtab_alter.test 736e66fb5ec7b4fee58229aa3ada2f27ec58bc58c00edae4836890c3784c6783 F test/vtab_err.test dcc8b7b9cb67522b3fe7a272c73856829dae4ab7fdb30399aea1b6981bda2b65 F test/vtab_shared.test 5253bff2355a9a3f014c15337da7e177ab0ef8ad @@ -2183,8 +2183,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 6a06dc73847716c88d65651d1bf0e002002303881df1389beac884d0032eae08 -R 9f7cc1bf5356d77f08ae122347a7b675 +P a49296de0061931badaf3db6b965131a78b1c6c21b1eeb62815ea7adf767d0b3 +R 7ff7efd995047005d6aa8ecbdebb1507 U dan -Z 96694e9dd3b3c0e4acdff2534541b848 +Z ff7145a12bdc41a2553dea79acaa6e0c # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 8c514c694f..46f1a1149d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a49296de0061931badaf3db6b965131a78b1c6c21b1eeb62815ea7adf767d0b3 \ No newline at end of file +fe209099f5c348f1280b9b827ffbf6a6742ebdd1a23ef189445147894b1832ba \ No newline at end of file diff --git a/test/vtabL.test b/test/vtabL.test index a801481c84..0834655ffd 100644 --- a/test/vtabL.test +++ b/test/vtabL.test @@ -31,10 +31,7 @@ proc vtab_command {method args} { return {} } -do_execsql_test 1.0 { - CREATE TABLE t1(a, b); -} - +breakpoint foreach {tn cts} { 1 {SELECT 123} 2 {SELECT 123, 456} @@ -44,6 +41,8 @@ foreach {tn cts} { 6 {DROP TABLE nosuchtable} 7 {DROP TABLE x1} 8 {DROP TABLE t1} + 9 {CREATE TABLE xyz AS SELECT * FROM sqlite_schema} + 10 {CREATE TABLE xyz AS SELECT 1 AS 'col'} } { set ::create_table_sql $cts do_catchsql_test 1.$tn { @@ -51,5 +50,19 @@ foreach {tn cts} { } {1 {vtable constructor failed: x1}} } +foreach {tn cts} { + 1 {CREATE TABLE IF NOT EXISTS t1(a, b)} + 2 {CREATE TABLE ""(a, b PRIMARY KEY) WITHOUT ROWID} +} { + set ::create_table_sql $cts + execsql { DROP TABLE IF EXISTS x1 } + do_execsql_test 2.$tn.1 { + CREATE VIRTUAL TABLE x1 USING tcl(vtab_command); + } + do_execsql_test 2.$tn.2 { + SELECT a, b FROM x1 + } +} + finish_test From 6921a2d2054dcbf26c5f455dded278fac795ea5e Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 27 Mar 2024 20:34:14 +0000 Subject: [PATCH 291/430] Update comments in fts5.h. FossilOrigin-Name: 862945d5c432c27377e90d93d64c4655eefcc369d086eb51edef925fb3d80b57 --- ext/fts5/fts5.h | 4 ++-- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/ext/fts5/fts5.h b/ext/fts5/fts5.h index 250d2ee7e3..551618e718 100644 --- a/ext/fts5/fts5.h +++ b/ext/fts5/fts5.h @@ -55,8 +55,8 @@ struct Fts5PhraseIter { ** EXTENSION API FUNCTIONS ** ** xUserData(pFts): -** Return a copy of the context pointer the extension function was -** registered with. +** Return a copy of the pUserData pointer passed to the xCreateFunction() +** API when the extension function was registered. ** ** xColumnTotalSize(pFts, iCol, pnToken): ** If parameter iCol is less than zero, set output variable *pnToken diff --git a/manifest b/manifest index 8b6dfb5fc7..0580f02c1d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sextra\stests\sto\svtabL.test. -D 2024-03-26T18:07:39.608 +C Update\scomments\sin\sfts5.h. +D 2024-03-27T20:34:14.698 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -92,7 +92,7 @@ F ext/fts3/unicode/UnicodeData.txt cd07314edb62d49fde34debdaf92fa2aa69011e7 F ext/fts3/unicode/mkunicode.tcl d5aebf022fa4577ee8cdf27468f0d847879993959101f6dbd6348ef0cfc324a7 F ext/fts3/unicode/parseunicode.tcl a981bd6466d12dd17967515801c3ff23f74a281be1a03cf1e6f52a6959fc77eb F ext/fts5/extract_api_docs.tcl bc3a0ca78be7d3df08e7602c00ca48021ebae40682d75eb001bfdf6e54ffb44e -F ext/fts5/fts5.h ecba24fed7b359b3a53016bb07e411b3b4c9cdf163aa141006536423a63b611e +F ext/fts5/fts5.h 8856e11a5f0269cd346754cea0765efe8089635b80cad3222e8bfdb08cd5348a F ext/fts5/fts5Int.h defa43c0932265138ee910ca416e6baccf8b774e0f3d610e74be1ab2880e9834 F ext/fts5/fts5_aux.c 4584e88878e54828bf7d4d0d83deedd232ec60628b7731be02bad6adb62304b1 F ext/fts5/fts5_buffer.c 0eec58bff585f1a44ea9147eae5da2447292080ea435957f7488c70673cb6f09 @@ -2183,8 +2183,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P a49296de0061931badaf3db6b965131a78b1c6c21b1eeb62815ea7adf767d0b3 -R 7ff7efd995047005d6aa8ecbdebb1507 +P fe209099f5c348f1280b9b827ffbf6a6742ebdd1a23ef189445147894b1832ba +R c56763aed4d4e5080faa164bf6334faf U dan -Z ff7145a12bdc41a2553dea79acaa6e0c +Z d4f93415501168b234b57e2165e695ab # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 46f1a1149d..1b105c4bee 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -fe209099f5c348f1280b9b827ffbf6a6742ebdd1a23ef189445147894b1832ba \ No newline at end of file +862945d5c432c27377e90d93d64c4655eefcc369d086eb51edef925fb3d80b57 \ No newline at end of file From cfd4507c830a73dad165ec5db2ae28549f62ae9f Mon Sep 17 00:00:00 2001 From: stephan Date: Thu, 28 Mar 2024 10:58:18 +0000 Subject: [PATCH 292/430] Document that the order of an update hook call is unspecied vis-a-vis the final result of the operation which triggers that hook. Doc changes only. FossilOrigin-Name: 3d4b1f0791384d3e531d6757daecf67e5b873954de61f37032474e3ae23cd22b --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/sqlite.h.in | 6 ++++++ 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 0580f02c1d..335dcd41b5 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Update\scomments\sin\sfts5.h. -D 2024-03-27T20:34:14.698 +C Document\sthat\sthe\sorder\sof\san\supdate\shook\scall\sis\sunspecied\svis-a-vis\sthe\sfinal\sresult\sof\sthe\soperation\swhich\striggers\sthat\shook.\sDoc\schanges\sonly. +D 2024-03-28T10:58:18.871 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -752,7 +752,7 @@ F src/resolve.c eb1860b134fb044fd819c4347105c148d5aac7c6498032be2829e5cc95619b28 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c 15a221347789e393b39e7d2d2bd102167979c95a1ce0675bb870b86a24ca6cf4 F src/shell.c.in 0354ca51eee5fbf6af394a7ef9f5ef6823ef45b743db65431f6777e4d5be2199 -F src/sqlite.h.in e9af5761aab316d52e5a5ac11b42d6a25eaaa49352e982c14f1080aab684b5c4 +F src/sqlite.h.in b5fb41b730da29d7cec58c6020afba627baf58a3dca4e30814bd674bc2a6fc86 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 F src/sqliteInt.h f8928f0397d797046396dd9d360a6af8ce6dcb48bd72ea290165b07c8c518744 @@ -2183,8 +2183,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P fe209099f5c348f1280b9b827ffbf6a6742ebdd1a23ef189445147894b1832ba -R c56763aed4d4e5080faa164bf6334faf -U dan -Z d4f93415501168b234b57e2165e695ab +P 862945d5c432c27377e90d93d64c4655eefcc369d086eb51edef925fb3d80b57 +R c8b4c3bc800aa223f9c43a96ed885105 +U stephan +Z 8903ace573828f0152a9ba1563932171 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 1b105c4bee..8763970a63 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -862945d5c432c27377e90d93d64c4655eefcc369d086eb51edef925fb3d80b57 \ No newline at end of file +3d4b1f0791384d3e531d6757daecf67e5b873954de61f37032474e3ae23cd22b \ No newline at end of file diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 6841cf38f7..0a020d691c 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -6887,6 +6887,12 @@ int sqlite3_autovacuum_pages( ** The exceptions defined in this paragraph might change in a future ** release of SQLite. ** +** Whether the update hook is invoked before or after the +** corresponding change is currently unspecified and may differ +** depending on the type of change. Do not rely on the order of the +** hook call with regards to the final result of the operation which +** triggers the hook. +** ** The update hook implementation must not do anything that will modify ** the database connection that invoked the update hook. Any actions ** to modify the database connection must be deferred until after the From 69dbd7a4e772e5f5a59409c45f29dbb038a06adc Mon Sep 17 00:00:00 2001 From: stephan Date: Sat, 30 Mar 2024 14:11:30 +0000 Subject: [PATCH 293/430] Make explicit that sqlite3_keyword_name()'s index is 0-based, per forum request. Doc changes only. FossilOrigin-Name: 090943dc31e7a3af5c11c1c0953cb82ae3ca07ba000189bb85deaecc76921504 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/sqlite.h.in | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 335dcd41b5..1e6bf524c1 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Document\sthat\sthe\sorder\sof\san\supdate\shook\scall\sis\sunspecied\svis-a-vis\sthe\sfinal\sresult\sof\sthe\soperation\swhich\striggers\sthat\shook.\sDoc\schanges\sonly. -D 2024-03-28T10:58:18.871 +C Make\sexplicit\sthat\ssqlite3_keyword_name()'s\sindex\sis\s0-based,\sper\sforum\srequest.\sDoc\schanges\sonly. +D 2024-03-30T14:11:30.350 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -752,7 +752,7 @@ F src/resolve.c eb1860b134fb044fd819c4347105c148d5aac7c6498032be2829e5cc95619b28 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c 15a221347789e393b39e7d2d2bd102167979c95a1ce0675bb870b86a24ca6cf4 F src/shell.c.in 0354ca51eee5fbf6af394a7ef9f5ef6823ef45b743db65431f6777e4d5be2199 -F src/sqlite.h.in b5fb41b730da29d7cec58c6020afba627baf58a3dca4e30814bd674bc2a6fc86 +F src/sqlite.h.in 32389e0d584551b300d0157881336162c14315a424cbf385c0d65eb7c2e31f7b F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 F src/sqliteInt.h f8928f0397d797046396dd9d360a6af8ce6dcb48bd72ea290165b07c8c518744 @@ -2183,8 +2183,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 862945d5c432c27377e90d93d64c4655eefcc369d086eb51edef925fb3d80b57 -R c8b4c3bc800aa223f9c43a96ed885105 +P 3d4b1f0791384d3e531d6757daecf67e5b873954de61f37032474e3ae23cd22b +R 1ec9bcb0364e01dba28a12b65d50cd52 U stephan -Z 8903ace573828f0152a9ba1563932171 +Z 8fd3b1df728a4b7485ff966dda79d536 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 8763970a63..a86194fdb9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -3d4b1f0791384d3e531d6757daecf67e5b873954de61f37032474e3ae23cd22b \ No newline at end of file +090943dc31e7a3af5c11c1c0953cb82ae3ca07ba000189bb85deaecc76921504 \ No newline at end of file diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 0a020d691c..d553abb7bf 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -8363,7 +8363,7 @@ int sqlite3_test_control(int op, ...); ** The sqlite3_keyword_count() interface returns the number of distinct ** keywords understood by SQLite. ** -** The sqlite3_keyword_name(N,Z,L) interface finds the N-th keyword and +** The sqlite3_keyword_name(N,Z,L) interface finds the 0-based N-th keyword and ** makes *Z point to that keyword expressed as UTF8 and writes the number ** of bytes in the keyword into *L. The string that *Z points to is not ** zero-terminated. The sqlite3_keyword_name(N,Z,L) routine returns From 9352cfa30b33bc88a422a05564616b5397d54a97 Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 1 Apr 2024 15:38:15 +0000 Subject: [PATCH 294/430] Improved comments in the query planner logic that computes the cost for a particular step in a query plan. No code changes. FossilOrigin-Name: 0b2ac2cdc767db764e3ea8bbc33898cac4e1ec27fe8c9b60ce08a1785f921e6d --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/where.c | 21 ++++++++++++++++----- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/manifest b/manifest index 1e6bf524c1..4939830a71 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Make\sexplicit\sthat\ssqlite3_keyword_name()'s\sindex\sis\s0-based,\sper\sforum\srequest.\sDoc\schanges\sonly. -D 2024-03-30T14:11:30.350 +C Improved\scomments\sin\sthe\squery\splanner\slogic\sthat\scomputes\sthe\scost\sfor\sa\nparticular\sstep\sin\sa\squery\splan.\s\sNo\scode\schanges. +D 2024-04-01T15:38:15.301 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -835,7 +835,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c 887fc4ca3f020ebb2e376f222069570834ac63bf50111ef0cbf3ae417048ed89 F src/wal.h ba252daaa94f889f4b2c17c027e823d9be47ce39da1d3799886bbd51f0490452 F src/walker.c 7c7ea0115345851c3da4e04e2e239a29983b61fb5b038b94eede6aba462640e2 -F src/where.c 11a67988c3a5be2e7ee07c958998f3ad4b30dc491c0add894c2933c752415b16 +F src/where.c a15429ae9d42c7b824b9faad7e8234b006abf0a4526166dc4dfc0cc9cd2c9e6a F src/whereInt.h 82a13766f13d1a53b05387c2e60726289ef26404bc7b9b1f7770204d97357fb8 F src/wherecode.c 5d77db30a2a3dd532492ae882de114edba2fae672622056b1c7fd61f5917a8f1 F src/whereexpr.c 7b64295f1d82ad0928df435925dd7bbd5997b44a026153113eace0d9e71ff435 @@ -2183,8 +2183,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 3d4b1f0791384d3e531d6757daecf67e5b873954de61f37032474e3ae23cd22b -R 1ec9bcb0364e01dba28a12b65d50cd52 -U stephan -Z 8fd3b1df728a4b7485ff966dda79d536 +P 090943dc31e7a3af5c11c1c0953cb82ae3ca07ba000189bb85deaecc76921504 +R 27a9be3de32bd888ad6632e320231186 +U drh +Z 13460dee49d687f64f99bd37193c204d # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index a86194fdb9..3fb4e018f6 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -090943dc31e7a3af5c11c1c0953cb82ae3ca07ba000189bb85deaecc76921504 \ No newline at end of file +0b2ac2cdc767db764e3ea8bbc33898cac4e1ec27fe8c9b60ce08a1785f921e6d \ No newline at end of file diff --git a/src/where.c b/src/where.c index 5767b44128..cea134d0e2 100644 --- a/src/where.c +++ b/src/where.c @@ -3252,10 +3252,13 @@ static int whereLoopAddBtreeIndex( } } - /* Set rCostIdx to the cost of visiting selected rows in index. Add - ** it to pNew->rRun, which is currently set to the cost of the index - ** seek only. Then, if this is a non-covering index, add the cost of - ** visiting the rows in the main table. */ + /* Set rCostIdx to the estimated cost of visiting selected rows in the + ** index. The estimate is the sum of two values: + ** 1. The cost of doing one search-by-key to find the first matching + ** entry + ** 2. Stepping forward in the index pNew->nOut times to find all + ** additional matching entries. + */ assert( pSrc->pTab->szTabRow>0 ); if( pProbe->idxType==SQLITE_IDXTYPE_IPK ){ /* The pProbe->szIdxRow is low for an IPK table since the interior @@ -3266,7 +3269,15 @@ static int whereLoopAddBtreeIndex( }else{ rCostIdx = pNew->nOut + 1 + (15*pProbe->szIdxRow)/pSrc->pTab->szTabRow; } - pNew->rRun = sqlite3LogEstAdd(rLogSize, rCostIdx); + rCostIdx = sqlite3LogEstAdd(rLogSize, rCostIdx); + + /* Estimate the cost of running the loop. If all data is coming + ** from the index, then this is just the cost of doing the index + ** lookup and scan. But if some data is coming out of the main table, + ** we also have to add in the cost of doing pNew->nOut searches to + ** locate the row in the main table that corresponds to the index entry. + */ + pNew->rRun = rCostIdx; if( (pNew->wsFlags & (WHERE_IDX_ONLY|WHERE_IPK|WHERE_EXPRIDX))==0 ){ pNew->rRun = sqlite3LogEstAdd(pNew->rRun, pNew->nOut + 16); } From 7f7d0b19f8d2628466d8e25bbb0f7d10bfb98baf Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 2 Apr 2024 11:44:44 +0000 Subject: [PATCH 295/430] Add a heuristic in between the two solver() passes of the query planner that tries to prevent a very slow query plan in cases where the output row count estimate is imprecise. FossilOrigin-Name: 8018417b0143ea11535f2457bf3e4b3755717c554a17df1076425b4251b5f2c6 --- manifest | 16 +++++--- manifest.uuid | 2 +- src/where.c | 64 ++++++++++++++++++++++++++++- test/whereN.test | 103 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 177 insertions(+), 8 deletions(-) create mode 100644 test/whereN.test diff --git a/manifest b/manifest index 4939830a71..24a90e1c43 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improved\scomments\sin\sthe\squery\splanner\slogic\sthat\scomputes\sthe\scost\sfor\sa\nparticular\sstep\sin\sa\squery\splan.\s\sNo\scode\schanges. -D 2024-04-01T15:38:15.301 +C Add\sa\sheuristic\sin\sbetween\sthe\stwo\ssolver()\spasses\sof\sthe\squery\splanner\sthat\ntries\sto\sprevent\sa\svery\sslow\squery\splan\sin\scases\swhere\sthe\soutput\srow\scount\nestimate\sis\simprecise. +D 2024-04-02T11:44:44.648 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -835,7 +835,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c 887fc4ca3f020ebb2e376f222069570834ac63bf50111ef0cbf3ae417048ed89 F src/wal.h ba252daaa94f889f4b2c17c027e823d9be47ce39da1d3799886bbd51f0490452 F src/walker.c 7c7ea0115345851c3da4e04e2e239a29983b61fb5b038b94eede6aba462640e2 -F src/where.c a15429ae9d42c7b824b9faad7e8234b006abf0a4526166dc4dfc0cc9cd2c9e6a +F src/where.c ba9d22fda3850b508e075f8bdc4f4d4f1ff314551597a6f14842bb03aeec0d3a F src/whereInt.h 82a13766f13d1a53b05387c2e60726289ef26404bc7b9b1f7770204d97357fb8 F src/wherecode.c 5d77db30a2a3dd532492ae882de114edba2fae672622056b1c7fd61f5917a8f1 F src/whereexpr.c 7b64295f1d82ad0928df435925dd7bbd5997b44a026153113eace0d9e71ff435 @@ -2017,6 +2017,7 @@ F test/whereJ.test fc05e374cc9f2dc204148d6c06822c380ad388895fe97a6d335b94a26a08a F test/whereK.test 0270ab7f04ba5436fb9156d31d642a1c82727f4c4bfe5ba90d435c78cf44684a F test/whereL.test 438a397fa883b77bb6361c08a8befa41b52e9cfbe15a2a43715d122f8cfa8649 F test/whereM.test 0dbc9998783458ddcf3cc078ca7c2951d8b2677d472ecf0028f449ed327c0250 +F test/whereN.test 63a3584b71acfb6963416de82f26c6b1644abc5ca6080c76546b9246734c8803 F test/wherefault.test 6cf2a9c5712952d463d3f45ebee7f6caf400984df51a195d884cfb7eb0e837a7 F test/wherelfault.test 9012e4ef5259058b771606616bd007af5d154e64cc25fa9fd4170f6411db44e3 F test/wherelimit.test afb46397c6d7e964e6e294ba3569864a0c570fe3807afc634236c2b752372f31 @@ -2183,8 +2184,11 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 090943dc31e7a3af5c11c1c0953cb82ae3ca07ba000189bb85deaecc76921504 -R 27a9be3de32bd888ad6632e320231186 +P 0b2ac2cdc767db764e3ea8bbc33898cac4e1ec27fe8c9b60ce08a1785f921e6d +R bbe24560206aebee12aa3740963fd4bf +T *branch * interstage-heuristic +T *sym-interstage-heuristic * +T -sym-trunk * U drh -Z 13460dee49d687f64f99bd37193c204d +Z f6898799f068ada043c459f74f460b9b # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 3fb4e018f6..4593d196ec 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0b2ac2cdc767db764e3ea8bbc33898cac4e1ec27fe8c9b60ce08a1785f921e6d \ No newline at end of file +8018417b0143ea11535f2457bf3e4b3755717c554a17df1076425b4251b5f2c6 \ No newline at end of file diff --git a/src/where.c b/src/where.c index cea134d0e2..fe76f2c960 100644 --- a/src/where.c +++ b/src/where.c @@ -5530,7 +5530,6 @@ static int wherePathSolver(WhereInfo *pWInfo, LogEst nRowEst){ } } - pWInfo->nRowOut = pFrom->nRow; /* Free temporary memory and return success */ @@ -5538,6 +5537,68 @@ static int wherePathSolver(WhereInfo *pWInfo, LogEst nRowEst){ return SQLITE_OK; } +/* +** This routine implements a heuristic designed to improve query planning. +** This routine is called in between the first and second call to +** wherePathSolver(). Hence the name "Interstage" "Heuristic". +** +** The first call to wherePathSolver() (hereafter just "solver()") computes +** the best path without regard to the order of the outputs. The second call +** to the solver() builds upon the first call to try to find an alternative +** path that satisfies the ORDER BY clause. +** +** This routine looks at the results of the first solver() run, and for +** every FROM clause term in the resulting query plan that uses an equality +** constraint against an index, disable other WhereLoops for that same +** FROM clause term that would try to do a full-table scan. This prevents +** an index search from being converted into a full-table scan in order to +** satisfy an ORDER BY clause, since even though we might get slightly better +** performance using the full-scan without sorting if the output size +** estimates are very precise, we might also get severe performance +** degradation using the full-scan if the output size estimate is too large. +** It is better to err on the side of caution. +** +** Except, if the first solver() call generated a full-table scan in an outer +** loop then stop this analysis at the first full-scan, since the second +** solver() run might try to swap that full-scan for another in order to +** get the output into the correct order. In other words, we do *not* want +** to inhibit a rewrites like this: +** +** First Solver() Second Solver() +** |-- SCAN t1 |-- SCAN t2 +** |-- SEARCH t2 `-- SEARCH t1 +** `-- SORT USING B-TREE +** +** Rather, the purpose of this routine is to inhibit rewrites such as: +** +** First Solver() Second Solver() +** |-- SEARCH t1 |-- SCAN t2 <--- bad! +** |-- SEARCH t2 `-- SEARCH t1 +** `-- SORT USING B-TREE +** +** See test cases in test/whereN.test for the real-world query that +** originally provoked this heuristic. +*/ +static SQLITE_NOINLINE void whereInterstageHeuristic(WhereInfo *pWInfo){ + int i; + for(i=0; inLevel; i++){ + WhereLoop *p = pWInfo->a[i].pWLoop; + if( p==0 ) break; + if( (p->wsFlags & WHERE_VIRTUALTABLE)!=0 ) continue; + if( (p->wsFlags & (WHERE_COLUMN_EQ|WHERE_COLUMN_NULL|WHERE_COLUMN_IN))!=0 ){ + u8 iTab = p->iTab; + WhereLoop *pLoop; + for(pLoop=pWInfo->pLoops; pLoop; pLoop=pLoop->pNextLoop){ + if( pLoop->iTab!=iTab ) continue; + if( (pLoop->wsFlags & WHERE_CONSTRAINT)!=0 ) continue; + pLoop->prereq = ALLBITS; /* Prevent 2nd solver() from using this one */ + } + }else{ + break; + } + } +} + /* ** Most queries use only a single table (they are not joins) and have ** simple == constraints against indexed fields. This routine attempts @@ -6320,6 +6381,7 @@ WhereInfo *sqlite3WhereBegin( wherePathSolver(pWInfo, 0); if( db->mallocFailed ) goto whereBeginError; if( pWInfo->pOrderBy ){ + whereInterstageHeuristic(pWInfo); wherePathSolver(pWInfo, pWInfo->nRowOut+1); if( db->mallocFailed ) goto whereBeginError; } diff --git a/test/whereN.test b/test/whereN.test new file mode 100644 index 0000000000..b9b889fa28 --- /dev/null +++ b/test/whereN.test @@ -0,0 +1,103 @@ +# 2024-04-02 +# +# 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. +# +#*********************************************************************** +# Tests for the whereInterstageHeuristic() routine in the query planner. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix whereN + +# The following is a simplified and "sanitized" version of the original +# real-world query that brought the problem to light. +# +# The issue is a slow query. The answer is correct, but it was taking too +# much time, because it was doing a full table scan rather than an indexed +# lookup. +# +# The problem was that the query planner was overestimating the number of +# output rows. The estimated number of output rows is accurate if the +# DSNAME parameter is "ds-one". In that case, a large fraction of the rows +# in "violation" end up being output. The query planner correctly deduces +# that it is faster to do a full table scan of the large "violation" table +# to avoid the after-query sort that implements the ORDER BY clause. However, +# if the DSNAME is "ds-two", then only a few rows (about 6) are generated, +# and it is much much faster to do an indexed lookup of "violation" followed +# by a sort operation to implement ORDER BY +# +# The problem, of course, is that the query planner has no way of knowing +# in advance how many rows will be generated. The query planner tries to +# estimate a worst case, which is a large number of output rows, and it picks +# the best plan for that case. However, the plan choosen is very inefficient +# when the number of output rows is small. +# +# The whereInterstageHeuristic() routine in the query planner attempts to +# correct this by adjusting the query plan such that it avoids the very bad +# query plan for a small number of rows, at the expense of a slightly less +# efficient plan for a large number of rows. The large number of rows case +# is perhaps 5% slower with the revised plan, but the small number of +# rows case is around 100 times faster. That seems like a good tradeoff. +# +do_execsql_test 1.0 { + CREATE TABLE datasource(dsid INT, name TEXT); + INSERT INTO datasource VALUES(1,'ds-one'),(2,'ds-two'),(3,'ds-three'); + CREATE INDEX ds1 ON datasource(name, dsid); + + CREATE TABLE rule(rid INT, team_id INT, dsid INT); + WITH RECURSIVE c(n) AS (VALUES(1) UNION ALL SELECT n+1 FROM c WHERE n<9) + INSERT INTO rule(rid,team_id,dsid) SELECT n, 1, 1 FROM c; + WITH RECURSIVE c(n) AS (VALUES(10) UNION ALL SELECT n+1 FROM c WHERE n<24) + INSERT INTO rule(rid,team_id,dsid) SELECT n, 2, 2 FROM c; + CREATE INDEX rule2 ON rule(dsid, rid); + + CREATE TABLE violation(vid INT, rid INT, vx BLOB); + /*** Uncomment to insert actual data + WITH src(rid, cnt) AS (VALUES(1,3586),(2,1343),(3,6505),(5,76230), + (6,740),(7,287794),(8,457),(12,1), + (14,1),(16,1),(17,1),(18,1),(19,1)) + INSERT INTO violation(vid, rid, vx) + SELECT rid*1000000+value, rid, randomblob(15) + FROM src, generate_series(1,cnt); + ***/ + CREATE INDEX v1 ON violation(rid, vid); + CREATE INDEX v2 ON violation(vid); + ANALYZE; + DELETE FROM sqlite_stat1; + DROP TABLE IF EXISTS sqlite_stat4; + INSERT INTO sqlite_stat1 VALUES + ('violation','v2','376661 1'), + ('violation','v1','376661 28974 1'), + ('rule','rule2','24 12 1'), + ('datasource','ds1','3 1 1'); + ANALYZE sqlite_schema; +} +set DSNAME ds-two ;# Only a few rows. Change to "ds-one" for many rows. +do_eqp_test 1.1 { + SELECT count(*), length(group_concat(vx)) FROM ( + SELECT V.* + FROM datasource DS, rule R, violation V + WHERE V.rid=R.rid + AND R.dsid=DS.dsid + AND DS.name=$DSNAME + ORDER BY V.vid desc + ); +} { + QUERY PLAN + |--CO-ROUTINE (subquery-xxxxxx) + | |--SEARCH DS USING COVERING INDEX ds1 (name=?) + | |--SEARCH R USING COVERING INDEX rule2 (dsid=?) + | |--SEARCH V USING INDEX v1 (rid=?) + | `--USE TEMP B-TREE FOR ORDER BY + `--SCAN (subquery-xxxxxx) +} +# ^^^^---- We want to see three SEARCH terms. No SCAN terms. +# The ORDER BY is implemented by a separate sorter pass. + +finish_test From 8ce73ce15b8f02b8e86c8a4d567dce42f40c70ba Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 2 Apr 2024 14:12:29 +0000 Subject: [PATCH 296/430] Fix typos in comments. Provided ".wheretrace" debugging output for the interstage heuristic module. Do omit automatic index loops in the interstage heuristic. FossilOrigin-Name: 186dcae19e249db36de15f295999cff25063b54ee3d5d481cd2ba99b6d13148e --- manifest | 17 +++++++---------- manifest.uuid | 2 +- src/sqliteInt.h | 2 +- src/where.c | 23 +++++++++++++++++++---- 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/manifest b/manifest index 24a90e1c43..790c61ed9b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sa\sheuristic\sin\sbetween\sthe\stwo\ssolver()\spasses\sof\sthe\squery\splanner\sthat\ntries\sto\sprevent\sa\svery\sslow\squery\splan\sin\scases\swhere\sthe\soutput\srow\scount\nestimate\sis\simprecise. -D 2024-04-02T11:44:44.648 +C Fix\stypos\sin\scomments.\s\sProvided\s".wheretrace"\sdebugging\soutput\sfor\sthe\ninterstage\sheuristic\smodule.\s\sDo\somit\sautomatic\sindex\sloops\sin\sthe\ninterstage\sheuristic. +D 2024-04-02T14:12:29.323 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -755,7 +755,7 @@ F src/shell.c.in 0354ca51eee5fbf6af394a7ef9f5ef6823ef45b743db65431f6777e4d5be219 F src/sqlite.h.in 32389e0d584551b300d0157881336162c14315a424cbf385c0d65eb7c2e31f7b F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 -F src/sqliteInt.h f8928f0397d797046396dd9d360a6af8ce6dcb48bd72ea290165b07c8c518744 +F src/sqliteInt.h 170f85c5a9d6189cf9b5dd304f4d40b73a8c9762fb927f1327e8ed2cb99c06b6 F src/sqliteLimit.h 6878ab64bdeb8c24a1d762d45635e34b96da21132179023338c93f820eee6728 F src/status.c cb11f8589a6912af2da3bb1ec509a94dd8ef27df4d4c1a97e0bcf2309ece972b F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1 @@ -835,7 +835,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c 887fc4ca3f020ebb2e376f222069570834ac63bf50111ef0cbf3ae417048ed89 F src/wal.h ba252daaa94f889f4b2c17c027e823d9be47ce39da1d3799886bbd51f0490452 F src/walker.c 7c7ea0115345851c3da4e04e2e239a29983b61fb5b038b94eede6aba462640e2 -F src/where.c ba9d22fda3850b508e075f8bdc4f4d4f1ff314551597a6f14842bb03aeec0d3a +F src/where.c 08ffccb5b8df523a484af2ae8593c8f571113475fe76b13360f2dfd74e117b4e F src/whereInt.h 82a13766f13d1a53b05387c2e60726289ef26404bc7b9b1f7770204d97357fb8 F src/wherecode.c 5d77db30a2a3dd532492ae882de114edba2fae672622056b1c7fd61f5917a8f1 F src/whereexpr.c 7b64295f1d82ad0928df435925dd7bbd5997b44a026153113eace0d9e71ff435 @@ -2184,11 +2184,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 0b2ac2cdc767db764e3ea8bbc33898cac4e1ec27fe8c9b60ce08a1785f921e6d -R bbe24560206aebee12aa3740963fd4bf -T *branch * interstage-heuristic -T *sym-interstage-heuristic * -T -sym-trunk * +P 8018417b0143ea11535f2457bf3e4b3755717c554a17df1076425b4251b5f2c6 +R 9b55b3987ec7e07bd641f4ba8c80fe98 U drh -Z f6898799f068ada043c459f74f460b9b +Z 1d7be0abb1ed0f4f893f7da5731cd389 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 4593d196ec..5063c5ac66 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8018417b0143ea11535f2457bf3e4b3755717c554a17df1076425b4251b5f2c6 \ No newline at end of file +186dcae19e249db36de15f295999cff25063b54ee3d5d481cd2ba99b6d13148e \ No newline at end of file diff --git a/src/sqliteInt.h b/src/sqliteInt.h index dba64c71bd..365ff2c7f5 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -1156,7 +1156,7 @@ extern u32 sqlite3WhereTrace; ** 0x00000010 Display sqlite3_index_info xBestIndex calls ** 0x00000020 Range an equality scan metrics ** 0x00000040 IN operator decisions -** 0x00000080 WhereLoop cost adjustements +** 0x00000080 WhereLoop cost adjustments ** 0x00000100 ** 0x00000200 Covering index decisions ** 0x00000400 OR optimization diff --git a/src/where.c b/src/where.c index fe76f2c960..a4506602a2 100644 --- a/src/where.c +++ b/src/where.c @@ -5561,15 +5561,15 @@ static int wherePathSolver(WhereInfo *pWInfo, LogEst nRowEst){ ** Except, if the first solver() call generated a full-table scan in an outer ** loop then stop this analysis at the first full-scan, since the second ** solver() run might try to swap that full-scan for another in order to -** get the output into the correct order. In other words, we do *not* want -** to inhibit a rewrites like this: +** get the output into the correct order. In other words, we allow a +** rewrite like this: ** ** First Solver() Second Solver() ** |-- SCAN t1 |-- SCAN t2 ** |-- SEARCH t2 `-- SEARCH t1 ** `-- SORT USING B-TREE ** -** Rather, the purpose of this routine is to inhibit rewrites such as: +** The purpose of this routine is to disallow rewrites such as: ** ** First Solver() Second Solver() ** |-- SEARCH t1 |-- SCAN t2 <--- bad! @@ -5581,6 +5581,9 @@ static int wherePathSolver(WhereInfo *pWInfo, LogEst nRowEst){ */ static SQLITE_NOINLINE void whereInterstageHeuristic(WhereInfo *pWInfo){ int i; +#ifdef WHERETRACE_ENABLED + int once = 0; +#endif for(i=0; inLevel; i++){ WhereLoop *p = pWInfo->a[i].pWLoop; if( p==0 ) break; @@ -5590,7 +5593,19 @@ static SQLITE_NOINLINE void whereInterstageHeuristic(WhereInfo *pWInfo){ WhereLoop *pLoop; for(pLoop=pWInfo->pLoops; pLoop; pLoop=pLoop->pNextLoop){ if( pLoop->iTab!=iTab ) continue; - if( (pLoop->wsFlags & WHERE_CONSTRAINT)!=0 ) continue; + if( (pLoop->wsFlags & (WHERE_CONSTRAINT|WHERE_AUTO_INDEX))!=0 ){ + /* Auto-index and index-constrained loops allowed to remain */ + continue; + } +#ifdef WHERETRACE_ENABLED + if( sqlite3WhereTrace & 0x80 ){ + if( once==0 ){ + sqlite3DebugPrintf("Loops disabled by interstage heuristic:\n"); + once = 1; + } + sqlite3WhereLoopPrint(pLoop, &pWInfo->sWC); + } +#endif /* WHERETRACE_ENABLED */ pLoop->prereq = ALLBITS; /* Prevent 2nd solver() from using this one */ } }else{ From 307f290b329603e70d1053282a96e5536184b252 Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 2 Apr 2024 21:55:45 +0000 Subject: [PATCH 297/430] Add an optional 3rd argument to the icu_load_collation() function that specifies the "strength" of the comparison. FossilOrigin-Name: acddbc489d5231dacf29890d1aa562da499026690f55c256a07d04a3190faacc --- ext/icu/icu.c | 37 +++++++++++++++++++++++++++++++++++-- manifest | 14 +++++++------- manifest.uuid | 2 +- test/icu.test | 18 +++++++++++++++++- 4 files changed, 60 insertions(+), 11 deletions(-) diff --git a/ext/icu/icu.c b/ext/icu/icu.c index e745ab0253..f9d9eef905 100644 --- a/ext/icu/icu.c +++ b/ext/icu/icu.c @@ -471,7 +471,7 @@ static void icuLoadCollation( UCollator *pUCollator; /* ICU library collation object */ int rc; /* Return code from sqlite3_create_collation_x() */ - assert(nArg==2); + assert(nArg==2 || nArg==3); (void)nArg; /* Unused parameter */ zLocale = (const char *)sqlite3_value_text(apArg[0]); zName = (const char *)sqlite3_value_text(apArg[1]); @@ -486,7 +486,39 @@ static void icuLoadCollation( return; } assert(p); - + if(nArg==3){ + const char *zOption = (const char*)sqlite3_value_text(apArg[2]); + static const struct { + const char *zName; + UColAttributeValue val; + } aStrength[] = { + { "PRIMARY", UCOL_PRIMARY }, + { "SECONDARY", UCOL_SECONDARY }, + { "TERTIARY", UCOL_TERTIARY }, + { "DEFAULT", UCOL_DEFAULT_STRENGTH }, + { "QUARTERNARY", UCOL_QUATERNARY }, + { "IDENTICAL", UCOL_IDENTICAL }, + }; + int i; + for(i=0; i=sizeof(aStrength)/sizeof(aStrength[0]) ){ + sqlite3_str *pStr = sqlite3_str_new(sqlite3_context_db_handle(p)); + sqlite3_str_appendf(pStr, + "unknown collation strength \"%s\" - should be one of:", + zOption); + for(i=0; i Date: Thu, 4 Apr 2024 12:36:33 +0000 Subject: [PATCH 298/430] Fix exception propagation when the opfs-sahpool VFS fails to initialize to address report in [forum:be0141c639|forum post be0141c639]. FossilOrigin-Name: cdb3a90055afe371962ec6c0931f1b08797aaeaab0358ef64b1cabda0a855b33 --- ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js | 2 +- manifest | 14 +++++++------- manifest.uuid | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js b/ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js index f3664fd4b8..3f4182dacc 100644 --- a/ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js +++ b/ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js @@ -1272,7 +1272,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ return poolUtil; }).catch(async (e)=>{ await thePool.removeVfs().catch(()=>{}); - return e; + throw e; }); }).catch((err)=>{ //error("rejecting promise:",err); diff --git a/manifest b/manifest index d49c515d29..b640e1905b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\san\soptional\s3rd\sargument\sto\sthe\sicu_load_collation()\sfunction\sthat\nspecifies\sthe\s"strength"\sof\sthe\scomparison. -D 2024-04-02T21:55:45.687 +C Fix\sexception\spropagation\swhen\sthe\sopfs-sahpool\sVFS\sfails\sto\sinitialize\sto\saddress\sreport\sin\s[forum:be0141c639|forum\spost\sbe0141c639]. +D 2024-04-04T12:36:33.682 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -612,7 +612,7 @@ F ext/wasm/api/sqlite3-api-worker1.js 8d9c0562831f62218170a3373468d8a0b7a6503b59 F ext/wasm/api/sqlite3-license-version-header.js 0c807a421f0187e778dc1078f10d2994b915123c1223fe752b60afdcd1263f89 F ext/wasm/api/sqlite3-opfs-async-proxy.js 196ad83d36ca794e564044788c9d21b964679d63cad865f604da37c4afc9a285 F ext/wasm/api/sqlite3-vfs-helper.c-pp.js 3f828cc66758acb40e9c5b4dcfd87fd478a14c8fb7f0630264e6c7fa0e57515d -F ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js 5a430874906ff3f4a6ca69aadf0c2aaedc1bb45489b8365bff7e955a83a8d42a +F ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js 8433ee332d5f5e39fb19427fccb7bad7f44aa99b5504daad3343fc128c311e78 F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js 3c72f1a0e6a7343c8c882d29d01bb440f10be12c844651605b486e76f3d6cc8c F ext/wasm/api/sqlite3-vtab-helper.c-pp.js a2fcbc3fecdd0eea229283584ebc122f29d98194083675dbe5cb2cf3a17fe309 F ext/wasm/api/sqlite3-wasm.c afba6827a49151b564af5cf588a6bbd0401b16ef5cbe3269c66f676fee9ca92c @@ -2183,8 +2183,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 0b2ac2cdc767db764e3ea8bbc33898cac4e1ec27fe8c9b60ce08a1785f921e6d -R c7e032bcb5236f4db4e7b2c73488ed57 -U drh -Z bc9a8cdde88480024e55380b78b92154 +P acddbc489d5231dacf29890d1aa562da499026690f55c256a07d04a3190faacc +R f4284681fd828de592cb5ab0ae30f403 +U stephan +Z 66fed09968d914b9f5c12c3e86ad8491 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index a90644ab0e..f32fa06d10 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -acddbc489d5231dacf29890d1aa562da499026690f55c256a07d04a3190faacc \ No newline at end of file +cdb3a90055afe371962ec6c0931f1b08797aaeaab0358ef64b1cabda0a855b33 \ No newline at end of file From efe9500af7051c259e9564db96c900be778ff65c Mon Sep 17 00:00:00 2001 From: drh <> Date: Thu, 4 Apr 2024 13:07:43 +0000 Subject: [PATCH 299/430] Fix test cases due to an error message change. FossilOrigin-Name: c49ec239eddde6f07f8d528cccd6224c4c80b240dc8f5c974186e3bb08afb83b --- manifest | 14 +++++++------- manifest.uuid | 2 +- test/default.test | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index b640e1905b..4b231f8550 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sexception\spropagation\swhen\sthe\sopfs-sahpool\sVFS\sfails\sto\sinitialize\sto\saddress\sreport\sin\s[forum:be0141c639|forum\spost\sbe0141c639]. -D 2024-04-04T12:36:33.682 +C Fix\stest\scases\sdue\sto\san\serror\smessage\schange. +D 2024-04-04T13:07:43.910 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -1057,7 +1057,7 @@ F test/dbpagefault.test 35f06cfb2ef100a9b19d25754e8141b9cba9b7daabd4c60fa5af93fc F test/dbstatus.test 4a4221a883025ffd39696b3d1b3910b928fb097d77e671351acb35f3aed42759 F test/dbstatus2.test f5fe0afed3fa45e57cfa70d1147606c20d2ba23feac78e9a172f2fe8ab5b78ef F test/decimal.test ef731887b43ee32ef86e1c8fddb61a40789f988332c029c601dcf2c319277e9e -F test/default.test 830fad7180cdf0e6a06e93acc0403bf73762314a639363314db5674c631b6127 +F test/default.test c7124864cded213a3f118bc7e2e26f34b7c36dfa26cf6945cc8b7f5db1191277 F test/delete.test 2686e1c98d552ef37d79ad55b17b93fe96fad9737786917ce3839767f734c48f F test/delete2.test 3a03f2cca1f9a67ec469915cb8babd6485db43fa F test/delete3.test 555e84a00a99230b7d049d477a324a631126a6ab @@ -2183,8 +2183,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P acddbc489d5231dacf29890d1aa562da499026690f55c256a07d04a3190faacc -R f4284681fd828de592cb5ab0ae30f403 -U stephan -Z 66fed09968d914b9f5c12c3e86ad8491 +P cdb3a90055afe371962ec6c0931f1b08797aaeaab0358ef64b1cabda0a855b33 +R ccb06537668742bb198e005c80e2d348 +U drh +Z 5666fcda290346432865b5fd5e238e7f # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index f32fa06d10..68f73f7bce 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -cdb3a90055afe371962ec6c0931f1b08797aaeaab0358ef64b1cabda0a855b33 \ No newline at end of file +c49ec239eddde6f07f8d528cccd6224c4c80b240dc8f5c974186e3bb08afb83b \ No newline at end of file diff --git a/test/default.test b/test/default.test index de67f643b4..192b3d2ff3 100644 --- a/test/default.test +++ b/test/default.test @@ -135,10 +135,10 @@ reset_db do_catchsql_test default-5.1 { CREATE TABLE t1 (a,b DEFAULT(random() NOTNULL IN (RAISE(IGNORE),2,3))); INSERT INTO t1(a) VALUES(1); -} {1 {RAISE() may only be used within a trigger-program}} +} {1 {default value of column [b] is not constant}} do_catchsql_test default-5.2 { CREATE TABLE Table0 (Col0 DEFAULT (RAISE(IGNORE) ) ) ; INSERT INTO Table0 DEFAULT VALUES ; -} {1 {RAISE() may only be used within a trigger-program}} +} {1 {default value of column [Col0] is not constant}} finish_test From 634f43468605b8f53404b7838472dff52639d249 Mon Sep 17 00:00:00 2001 From: drh <> Date: Thu, 4 Apr 2024 13:36:48 +0000 Subject: [PATCH 300/430] Fix an ASAN problem in part of the test harness. No changes to SQLite itself. FossilOrigin-Name: 797cda7ddcceb140330d58892c3e73d28df72b638df00fd48f07dfcba7706c5f --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/test_bestindex.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 4b231f8550..9947cad665 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\stest\scases\sdue\sto\san\serror\smessage\schange. -D 2024-04-04T13:07:43.910 +C Fix\san\sASAN\sproblem\sin\spart\sof\sthe\stest\sharness.\s\sNo\schanges\sto\sSQLite\sitself. +D 2024-04-04T13:36:48.714 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -771,7 +771,7 @@ F src/test9.c 12e5ba554d2d1cbe0158f6ab3f7ffcd7a86ee4e5 F src/test_async.c 195ab49da082053fdb0f949c114b806a49ca770a F src/test_autoext.c 915d245e736652a219a907909bb6710f0d587871 F src/test_backup.c bf5da90c9926df0a4b941f2d92825a01bbe090a0 -F src/test_bestindex.c f6af1e41cb7901edafb065a8198e4a0192dd42432b642d038965be5e628dec12 +F src/test_bestindex.c 1ee3d64b49ca06a9cb8195fab04f1a0585cafc90d25a2a817caa14e7caab22e7 F src/test_blob.c ae4a0620b478548afb67963095a7417cd06a4ec0a56adb453542203bfdcb31ce F src/test_btree.c 8b2dc8b8848cf3a4db93f11578f075e82252a274 F src/test_config.c 5fa77ee6064ba546e144c4fea870c5ede2c54314616f81485c6a9c4192100c75 @@ -2183,8 +2183,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P cdb3a90055afe371962ec6c0931f1b08797aaeaab0358ef64b1cabda0a855b33 -R ccb06537668742bb198e005c80e2d348 +P c49ec239eddde6f07f8d528cccd6224c4c80b240dc8f5c974186e3bb08afb83b +R 7af8cb79e580778082df3d4aa754bb75 U drh -Z 5666fcda290346432865b5fd5e238e7f +Z e0623a1804a9fd12482c3193ee60e8ba # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 68f73f7bce..12ab17b4c2 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c49ec239eddde6f07f8d528cccd6224c4c80b240dc8f5c974186e3bb08afb83b \ No newline at end of file +797cda7ddcceb140330d58892c3e73d28df72b638df00fd48f07dfcba7706c5f \ No newline at end of file diff --git a/src/test_bestindex.c b/src/test_bestindex.c index 8128530b40..6b6b413950 100644 --- a/src/test_bestindex.c +++ b/src/test_bestindex.c @@ -226,7 +226,7 @@ static int tclConnect( } sqlite3_free(zCmd); - *ppVtab = &pTab->base; + *ppVtab = pTab ? &pTab->base : 0; return rc; } From 7fd9b53308d8bea8a8851fb71e6dbe0db4a73775 Mon Sep 17 00:00:00 2001 From: stephan Date: Thu, 4 Apr 2024 22:53:09 +0000 Subject: [PATCH 301/430] Optimize sqlite3.oo1.DB.exec() for the rowMode='object' case to avoid converting the object property keys (column names) from native code to JS for each row. This speeds up large data sets considerably and addresses the report in [forum:3632183d2470617d|forum post 3632183d2470617d]. FossilOrigin-Name: 8b41ef8690001eb299f5b7182c28f5318333bff5b505e1d59d6e6f4556b1c759 --- ext/wasm/api/sqlite3-api-oo1.js | 91 ++++++++++++++++++++------------- manifest | 15 +++--- manifest.uuid | 2 +- 3 files changed, 64 insertions(+), 44 deletions(-) diff --git a/ext/wasm/api/sqlite3-api-oo1.js b/ext/wasm/api/sqlite3-api-oo1.js index 160d59db5a..425b52eeca 100644 --- a/ext/wasm/api/sqlite3-api-oo1.js +++ b/ext/wasm/api/sqlite3-api-oo1.js @@ -433,40 +433,56 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ out.returnVal = ()=>opt.resultRows; } if(opt.callback || opt.resultRows){ - switch((undefined===opt.rowMode) - ? 'array' : opt.rowMode) { - case 'object': out.cbArg = (stmt)=>stmt.get(Object.create(null)); break; - case 'array': out.cbArg = (stmt)=>stmt.get([]); break; - case 'stmt': - if(Array.isArray(opt.resultRows)){ - toss3("exec(): invalid rowMode for a resultRows array: must", - "be one of 'array', 'object',", - "a result column number, or column name reference."); - } - out.cbArg = (stmt)=>stmt; + switch((undefined===opt.rowMode) ? 'array' : opt.rowMode) { + case 'object': + out.cbArg = (stmt,cache)=>{ + if( !cache.columnNames ) cache.columnNames = stmt.getColumnNames([]); + /* https://sqlite.org/forum/forumpost/3632183d2470617d: + conversion of rows to objects (key/val pairs) is + somewhat expensive for large data sets because of the + native-to-JS conversion of the column names. If we + instead cache the names and build objects from that + list of strings, it can run twice as fast. The + difference is not noticeable for small data sets but + becomes human-perceivable when enough rows are + involved. */ + const row = stmt.get([]); + const rv = Object.create(null); + for( const i in cache.columnNames ) rv[cache.columnNames[i]] = row[i]; + return rv; + }; + break; + case 'array': out.cbArg = (stmt)=>stmt.get([]); break; + case 'stmt': + if(Array.isArray(opt.resultRows)){ + toss3("exec(): invalid rowMode for a resultRows array: must", + "be one of 'array', 'object',", + "a result column number, or column name reference."); + } + out.cbArg = (stmt)=>stmt; + break; + default: + if(util.isInt32(opt.rowMode)){ + out.cbArg = (stmt)=>stmt.get(opt.rowMode); break; - default: - if(util.isInt32(opt.rowMode)){ - out.cbArg = (stmt)=>stmt.get(opt.rowMode); - break; - }else if('string'===typeof opt.rowMode - && opt.rowMode.length>1 - && '$'===opt.rowMode[0]){ - /* "$X": fetch column named "X" (case-sensitive!). Prior - to 2022-12-14 ":X" and "@X" were also permitted, but - having so many options is unnecessary and likely to - cause confusion. */ - const $colName = opt.rowMode.substr(1); - out.cbArg = (stmt)=>{ - const rc = stmt.get(Object.create(null))[$colName]; - return (undefined===rc) - ? toss3(capi.SQLITE_NOTFOUND, - "exec(): unknown result column:",$colName) - : rc; - }; - break; - } - toss3("Invalid rowMode:",opt.rowMode); + }else if('string'===typeof opt.rowMode + && opt.rowMode.length>1 + && '$'===opt.rowMode[0]){ + /* "$X": fetch column named "X" (case-sensitive!). Prior + to 2022-12-14 ":X" and "@X" were also permitted, but + having so many options is unnecessary and likely to + cause confusion. */ + const $colName = opt.rowMode.substr(1); + out.cbArg = (stmt)=>{ + const rc = stmt.get(Object.create(null))[$colName]; + return (undefined===rc) + ? toss3(capi.SQLITE_NOTFOUND, + "exec(): unknown result column:",$colName) + : rc; + }; + break; + } + toss3("Invalid rowMode:",opt.rowMode); } } return out; @@ -884,10 +900,15 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ and names. */) ? 0 : 1; evalFirstResult = false; if(arg.cbArg || resultRows){ + const cbArgCache = Object.create(null) + /* 2nd arg for arg.cbArg, used by (at least) row-to-object + converter */; for(; stmt.step(); stmt._lockedByExec = false){ - if(0===gotColNames++) stmt.getColumnNames(opt.columnNames); + if(0===gotColNames++){ + stmt.getColumnNames(cbArgCache.columnNames = (opt.columnNames || [])); + } stmt._lockedByExec = true; - const row = arg.cbArg(stmt); + const row = arg.cbArg(stmt,cbArgCache); if(resultRows) resultRows.push(row); if(callback && false === callback.call(opt, row, stmt)){ break; diff --git a/manifest b/manifest index e296c36245..457e113cfd 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\s"interstage-heuristic"\sthat\sattempts\sto\savoid\swildly\sinefficient\nqueries\sthat\suse\stable\sscans\sinstead\sof\sindex\slookups\sbecause\sthe\soutput\nrow\sestimates\sare\sinaccurate. -D 2024-04-04T14:26:42.961 +C Optimize\ssqlite3.oo1.DB.exec()\sfor\sthe\srowMode='object'\scase\sto\savoid\sconverting\sthe\sobject\sproperty\skeys\s(column\snames)\sfrom\snative\scode\sto\sJS\sfor\seach\srow.\sThis\sspeeds\sup\slarge\sdata\ssets\sconsiderably\sand\saddresses\sthe\sreport\sin\s[forum:3632183d2470617d|forum\spost\s3632183d2470617d]. +D 2024-04-04T22:53:09.385 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -606,7 +606,7 @@ F ext/wasm/api/post-js-header.js 04dc12c3edd666b64a1b4ef3b6690c88dcc653f26451fd4 F ext/wasm/api/pre-js.c-pp.js ad906703f7429590f2fbf5e6498513bf727a1a4f0ebfa057afb08161d7511219 F ext/wasm/api/sqlite3-api-cleanup.js d235ad237df6954145404305040991c72ef8b1881715d2a650dda7b3c2576d0e F ext/wasm/api/sqlite3-api-glue.js 2d35660c52dcb4bb16d00c56553d34e7caa6ad30083938b515e6f9aa0b312fbb -F ext/wasm/api/sqlite3-api-oo1.js 7f3bcf0549ac44cde4b9da0b642d771916738d3f6781fb8a1757c50a91e506c0 +F ext/wasm/api/sqlite3-api-oo1.js 365b3ae01a461dc974796823652ef1ecb1a9fac5df295ee1a78002cc77afb0d8 F ext/wasm/api/sqlite3-api-prologue.js 93a72b07b2a5d964d2edc76a90b439ece49298bd7ba60a1c6ae5d4878213701e F ext/wasm/api/sqlite3-api-worker1.js 8d9c0562831f62218170a3373468d8a0b7a6503b5985e309b69bf71187b525cf F ext/wasm/api/sqlite3-license-version-header.js 0c807a421f0187e778dc1078f10d2994b915123c1223fe752b60afdcd1263f89 @@ -2184,9 +2184,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 797cda7ddcceb140330d58892c3e73d28df72b638df00fd48f07dfcba7706c5f 186dcae19e249db36de15f295999cff25063b54ee3d5d481cd2ba99b6d13148e -R 869b12f296c2e2b0f215f1adb6cf5942 -T +closed 186dcae19e249db36de15f295999cff25063b54ee3d5d481cd2ba99b6d13148e -U drh -Z 93e4543ac83acbe7df90dc3896cd40af +P 7bf49e2c54c9f6f336416f01c0e76aaf70f1e2f3fd612232e5a33ae5dabe0900 +R 32cab23d7481e1a388944c536dd694cd +U stephan +Z 96ae2cb4464d7637da1ca6fd97c9b197 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index e59021c9b1..4ea31d83a3 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7bf49e2c54c9f6f336416f01c0e76aaf70f1e2f3fd612232e5a33ae5dabe0900 \ No newline at end of file +8b41ef8690001eb299f5b7182c28f5318333bff5b505e1d59d6e6f4556b1c759 \ No newline at end of file From 65a1d7a28464a62488d4771dcbdb35cafa5a4e39 Mon Sep 17 00:00:00 2001 From: drh <> Date: Fri, 5 Apr 2024 11:23:51 +0000 Subject: [PATCH 302/430] When compiling with SQLITE_ALLOW_ROWID_IN_VIEW, if the RETURNING clause of an UPDATE of a view specifies a rowid, then return NULL for the value of that rowid. dbsqlfuzz 7863696e9e5ec10b29bcf5ab2681cd6c82a78a4a. FossilOrigin-Name: c7896e88850669e18e89d44c4169d4f4a5d4b904bea6ccb2ac64f93b6d348a42 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/update.c | 3 +++ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 457e113cfd..51f9fbab8a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Optimize\ssqlite3.oo1.DB.exec()\sfor\sthe\srowMode='object'\scase\sto\savoid\sconverting\sthe\sobject\sproperty\skeys\s(column\snames)\sfrom\snative\scode\sto\sJS\sfor\seach\srow.\sThis\sspeeds\sup\slarge\sdata\ssets\sconsiderably\sand\saddresses\sthe\sreport\sin\s[forum:3632183d2470617d|forum\spost\s3632183d2470617d]. -D 2024-04-04T22:53:09.385 +C When\scompiling\swith\sSQLITE_ALLOW_ROWID_IN_VIEW,\sif\sthe\sRETURNING\sclause\sof\nan\sUPDATE\sof\sa\sview\sspecifies\sa\srowid,\sthen\sreturn\sNULL\sfor\sthe\svalue\sof\nthat\srowid.\s\sdbsqlfuzz\s7863696e9e5ec10b29bcf5ab2681cd6c82a78a4a. +D 2024-04-05T11:23:51.958 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -815,7 +815,7 @@ F src/threads.c 4ae07fa022a3dc7c5beb373cf744a85d3c5c6c3c F src/tokenize.c 3f703cacdab728d7741e5a6ac242006d74fe1c2754d4f03ed889d7253259bd68 F src/treeview.c c6fc972683fd00f975d8b32a81c1f25d2fb7d4035366bf45c9f5622d3ccd70ee F src/trigger.c 0905b96b04bb6658509f711a8207287f1315cdbc3df1a1b13ba6483c8e341c81 -F src/update.c 6904814dd62a7a93bbb86d9f1419c7f134a9119582645854ab02b36b676d9f92 +F src/update.c 732404a04d1737ef14bb6ec6b84f74edf28b3c102a92ae46b4855438a710efe7 F src/upsert.c 2e60567a0e9e8520c18671b30712a88dc73534474304af94f32bb5f3ef65ac65 F src/utf.c f23165685a67b4caf8ec08fb274cb3f319103decfb2a980b7cfd55d18dfa855e F src/util.c 4d6d7ebfe6772a1b950c97bbb1d1a72ad4874617ec498ab8aa73b7f5a43e44bb @@ -2184,8 +2184,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 7bf49e2c54c9f6f336416f01c0e76aaf70f1e2f3fd612232e5a33ae5dabe0900 -R 32cab23d7481e1a388944c536dd694cd -U stephan -Z 96ae2cb4464d7637da1ca6fd97c9b197 +P 8b41ef8690001eb299f5b7182c28f5318333bff5b505e1d59d6e6f4556b1c759 +R f56441a29ebaf6b9cc2fa5b75235bdce +U drh +Z ca20487feeb5219923a08470db600847 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 4ea31d83a3..58ff11c4a9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8b41ef8690001eb299f5b7182c28f5318333bff5b505e1d59d6e6f4556b1c759 \ No newline at end of file +c7896e88850669e18e89d44c4169d4f4a5d4b904bea6ccb2ac64f93b6d348a42 \ No newline at end of file diff --git a/src/update.c b/src/update.c index cd7d73f3f7..b6068caa79 100644 --- a/src/update.c +++ b/src/update.c @@ -921,6 +921,9 @@ void sqlite3Update( } } if( chngRowid==0 && pPk==0 ){ +#ifdef SQLITE_ALLOW_ROWID_IN_VIEW + if( isView ) sqlite3VdbeAddOp2(v, OP_Null, 0, regOldRowid); +#endif sqlite3VdbeAddOp2(v, OP_Copy, regOldRowid, regNewRowid); } } From b411c4d69e1d7df018e9c313e104e973fc79d583 Mon Sep 17 00:00:00 2001 From: drh <> Date: Fri, 5 Apr 2024 13:56:05 +0000 Subject: [PATCH 303/430] Check-in [a9657c87c53c1922] is wrong: the IndexedExpr.bMaybeNullRow flag is required for virtual columns if they are part of an outer join. Add a test case (derived from dbsqlfuzz b9e65e2f110df998f1306571fae7af6c01e4d92b) to prove it. FossilOrigin-Name: 4484ec6d26b31305e31de89bdbae26344d8083a7e7de20861430d31737d9979c --- manifest | 15 ++++++++------- manifest.uuid | 2 +- src/where.c | 8 +------- test/joinH.test | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 15 deletions(-) diff --git a/manifest b/manifest index 51f9fbab8a..8b598b2633 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C When\scompiling\swith\sSQLITE_ALLOW_ROWID_IN_VIEW,\sif\sthe\sRETURNING\sclause\sof\nan\sUPDATE\sof\sa\sview\sspecifies\sa\srowid,\sthen\sreturn\sNULL\sfor\sthe\svalue\sof\nthat\srowid.\s\sdbsqlfuzz\s7863696e9e5ec10b29bcf5ab2681cd6c82a78a4a. -D 2024-04-05T11:23:51.958 +C Check-in\s[a9657c87c53c1922]\sis\swrong:\sthe\sIndexedExpr.bMaybeNullRow\sflag\sis\nrequired\sfor\svirtual\scolumns\sif\sthey\sare\spart\sof\san\souter\sjoin.\s\sAdd\sa\ntest\scase\s(derived\sfrom\sdbsqlfuzz\sb9e65e2f110df998f1306571fae7af6c01e4d92b)\nto\sprove\sit. +D 2024-04-05T13:56:05.021 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -835,7 +835,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c 887fc4ca3f020ebb2e376f222069570834ac63bf50111ef0cbf3ae417048ed89 F src/wal.h ba252daaa94f889f4b2c17c027e823d9be47ce39da1d3799886bbd51f0490452 F src/walker.c 7c7ea0115345851c3da4e04e2e239a29983b61fb5b038b94eede6aba462640e2 -F src/where.c 08ffccb5b8df523a484af2ae8593c8f571113475fe76b13360f2dfd74e117b4e +F src/where.c 9982128f010a699560fb5be37633801c7641ac3540f49db43cec878025929a0e F src/whereInt.h 82a13766f13d1a53b05387c2e60726289ef26404bc7b9b1f7770204d97357fb8 F src/wherecode.c 5d77db30a2a3dd532492ae882de114edba2fae672622056b1c7fd61f5917a8f1 F src/whereexpr.c 7b64295f1d82ad0928df435925dd7bbd5997b44a026153113eace0d9e71ff435 @@ -1338,7 +1338,7 @@ F test/joinC.test 1f1a602c2127f55f136e2cbd3bf2d26546614bf8cffe5902ec1ac9c07f87f2 F test/joinD.test 2ce62e7353a0702ca5e70008faf319c1d4686aa19fba34275c6d1da0e960be28 F test/joinE.test d5d182f3812771e2c0d97c9dcf5dbe4c41c8e21c82560e59358731c4a3981d6b F test/joinF.test 53dd66158806823ea680dd7543b5406af151b5aafa5cd06a7f3231cd94938127 -F test/joinH.test d5054173442fdf98260eeb6bb9751daa733b0ae6842fe50dcbd5469945b86985 +F test/joinH.test 55f69e64da74d4eca2235237f3acb657aef181e22e45daa228e35bba865e0255 F test/journal1.test c7b768041b7f494471531e17abc2f4f5ebf9e5096984f43ed17c4eb80ba34497 F test/journal2.test 9dac6b4ba0ca79c3b21446bbae993a462c2397c4 F test/journal3.test 7c3cf23ffc77db06601c1fcfc9743de8441cb77db9d1aa931863d94f5ffa140e @@ -2184,8 +2184,9 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 8b41ef8690001eb299f5b7182c28f5318333bff5b505e1d59d6e6f4556b1c759 -R f56441a29ebaf6b9cc2fa5b75235bdce +P c7896e88850669e18e89d44c4169d4f4a5d4b904bea6ccb2ac64f93b6d348a42 +Q -a9657c87c53c19228a42559c82c54b504a5ad729e407e9e2c7dabcc0c949b261 +R 00fdd25fa9a3c1e58bfe6d44fd3eb812 U drh -Z ca20487feeb5219923a08470db600847 +Z d45c3b35e63ad3a95f4d8ac3c99323f3 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 58ff11c4a9..0dad7c2062 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c7896e88850669e18e89d44c4169d4f4a5d4b904bea6ccb2ac64f93b6d348a42 \ No newline at end of file +4484ec6d26b31305e31de89bdbae26344d8083a7e7de20861430d31737d9979c \ No newline at end of file diff --git a/src/where.c b/src/where.c index a4506602a2..a1837b5879 100644 --- a/src/where.c +++ b/src/where.c @@ -5948,16 +5948,10 @@ static SQLITE_NOINLINE void whereAddIndexedExpr( for(i=0; inColumn; i++){ Expr *pExpr; int j = pIdx->aiColumn[i]; - int bMaybeNullRow; if( j==XN_EXPR ){ pExpr = pIdx->aColExpr->a[i].pExpr; - testcase( pTabItem->fg.jointype & JT_LEFT ); - testcase( pTabItem->fg.jointype & JT_RIGHT ); - testcase( pTabItem->fg.jointype & JT_LTORJ ); - bMaybeNullRow = (pTabItem->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))!=0; }else if( j>=0 && (pTab->aCol[j].colFlags & COLFLAG_VIRTUAL)!=0 ){ pExpr = sqlite3ColumnExpr(pTab, &pTab->aCol[j]); - bMaybeNullRow = 0; }else{ continue; } @@ -5989,7 +5983,7 @@ static SQLITE_NOINLINE void whereAddIndexedExpr( p->iDataCur = pTabItem->iCursor; p->iIdxCur = iIdxCur; p->iIdxCol = i; - p->bMaybeNullRow = bMaybeNullRow; + p->bMaybeNullRow = (pTabItem->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))!=0; if( sqlite3IndexAffinityStr(pParse->db, pIdx) ){ p->aff = pIdx->zColAff[i]; } diff --git a/test/joinH.test b/test/joinH.test index e3f979409a..908b93dee5 100644 --- a/test/joinH.test +++ b/test/joinH.test @@ -309,4 +309,36 @@ do_execsql_test 12.3 { SELECT * FROM t1 LEFT JOIN t2 ON true RIGHT JOIN t3 ON d2=e3 WHERE c2 BETWEEN NULL AND a1; } +#------------------------------------------------------------------------- +# 2024-04-05 dbsqlfuzz b9e65e2f110df998f1306571fae7af6c01e4d92b +reset_db +do_execsql_test 13.1 { + CREATE TABLE t1(a INT AS (b), b INT); + INSERT INTO t1(b) VALUES(123); + CREATE TABLE t2(a INT, c INT); + SELECT a FROM t2 NATURAL RIGHT JOIN t1; +} {123} +do_execsql_test 13.2 { + CREATE INDEX t1a ON t1(a); + SELECT a FROM t2 NATURAL RIGHT JOIN t1; +} {123} +# Further tests of the same logic (indexes on expressions +# used by RIGHT JOIN) from check-in ffe23af73fcb324d and +# forum post https://sqlite.org/forum/forumpost/9b491e1debf0b67a. +db null NULL +do_execsql_test 13.3 { + CREATE TABLE t3(a INT, b INT); + CREATE UNIQUE INDEX t3x ON t3(a, a+b); + INSERT INTO t3(a,b) VALUES(1,2),(4,8),(16,32),(4,80),(1,-300); + CREATE TABLE t4(x INT, y INT); + INSERT INTO t4(x,y) SELECT a, b FROM t3; + INSERT INTO t4(x,y) VALUES(99,99); + SELECT a1.a, sum( a1.a+a1.b ) FROM t3 AS a1 RIGHT JOIN t4 ON a=x + GROUP BY a1.a ORDER BY 1; +} {NULL NULL 1 -592 4 192 16 48} +do_execsql_test 13.4 { + SELECT sum( a1.a+a1.b ) FROM t3 AS a1 RIGHT JOIN t3 ON true + GROUP BY a1.a ORDER BY 1; +} {-1480 240 480} + finish_test From 743ae4c68b51fe56e6a269a79532224d2e45ce12 Mon Sep 17 00:00:00 2001 From: drh <> Date: Fri, 5 Apr 2024 20:01:28 +0000 Subject: [PATCH 304/430] Experimental enhancement in which expressions of the form "expr IN table" can be pushed down into subexpressions. FossilOrigin-Name: 2cbd7838fd6ffdf210f34671cd2e3e749a076a3a6f155bbe5f910a67db31c5b1 --- manifest | 22 ++++++------ manifest.uuid | 2 +- src/expr.c | 60 ++++++++++++++++++++++++++++---- src/parse.y | 4 +++ src/sqliteInt.h | 3 +- test/pushdown.test | 85 ++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 157 insertions(+), 19 deletions(-) diff --git a/manifest b/manifest index 8b598b2633..8fd5496617 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Check-in\s[a9657c87c53c1922]\sis\swrong:\sthe\sIndexedExpr.bMaybeNullRow\sflag\sis\nrequired\sfor\svirtual\scolumns\sif\sthey\sare\spart\sof\san\souter\sjoin.\s\sAdd\sa\ntest\scase\s(derived\sfrom\sdbsqlfuzz\sb9e65e2f110df998f1306571fae7af6c01e4d92b)\nto\sprove\sit. -D 2024-04-05T13:56:05.021 +C Experimental\senhancement\sin\swhich\sexpressions\sof\sthe\sform\s"expr\sIN\stable"\ncan\sbe\spushed\sdown\sinto\ssubexpressions. +D 2024-04-05T20:01:28.787 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -700,7 +700,7 @@ F src/date.c 126ba2ab10aeb2e7ba6e089b5f07b747c0625b8287f78b60da346eda8d23c875 F src/dbpage.c 80e46e1df623ec40486da7a5086cb723b0275a6e2a7b01d9f9b5da0f04ba2782 F src/dbstat.c 3b677254d512fcafd4d0b341bf267b38b235ccfddbef24f9154e19360fa22e43 F src/delete.c cb766727c78e715f9fb7ec8a7d03658ed2a3016343ca687acfcec9083cdca500 -F src/expr.c cd46ce2ebe46a30e63087dbe8aff7d6e34ba8acc8c658e8e18fcaa35f2711391 +F src/expr.c 48e6732170b5f3c07f9ebbdbe12c478e2867ea4be4361946ed26e2c8d607f7e8 F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c a47610f0a5c6cb0ad79f8fcef039c01833dec0c751bb695f28dc0ec6a4c3ba00 F src/func.c 283d4f3b2751a1d9339fd93a8a013d1948fd5f4474a3cab0955eb4fafd445d0f @@ -739,7 +739,7 @@ F src/os_win.c 6ff43bac175bd9ed79e7c0f96840b139f2f51d01689a638fd05128becf94908a F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a F src/pager.c ff60e98138d2499082ac6230f01ac508aba545315debccfca2fd6042f5f10fcd F src/pager.h 4b1140d691860de0be1347474c51fee07d5420bd7f802d38cbab8ea4ab9f538a -F src/parse.y 5bcef16094213efcc365a9d4dc4e3131f09251dc8838dce4a9e5f9764bff5b82 +F src/parse.y 67b9965a501599d5a1a4333125fab0dd230e03e28045700c9b331f7c3269bda5 F src/pcache.c 040b165f30622a21b7a9a77c6f2e4877a32fb7f22d4c7f0d2a6fa6833a156a75 F src/pcache.h 1497ce1b823cf00094bb0cf3bac37b345937e6f910890c626b16512316d3abf5 F src/pcache1.c 602acb23c471bb8d557a6f0083cc2be641d6cafcafa19e481eba7ef4c9ca0f00 @@ -755,7 +755,7 @@ F src/shell.c.in 0354ca51eee5fbf6af394a7ef9f5ef6823ef45b743db65431f6777e4d5be219 F src/sqlite.h.in 32389e0d584551b300d0157881336162c14315a424cbf385c0d65eb7c2e31f7b F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 -F src/sqliteInt.h 170f85c5a9d6189cf9b5dd304f4d40b73a8c9762fb927f1327e8ed2cb99c06b6 +F src/sqliteInt.h a0d0f014baafcb61f5d0a6d206d4b190644d57bb762dff2073903595653d6319 F src/sqliteLimit.h 6878ab64bdeb8c24a1d762d45635e34b96da21132179023338c93f820eee6728 F src/status.c cb11f8589a6912af2da3bb1ec509a94dd8ef27df4d4c1a97e0bcf2309ece972b F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1 @@ -1510,7 +1510,7 @@ F test/printf.test 685fec5a0c5af2490ab0632775a301554361d674211d690f5bee0a97b0533 F test/printf2.test 3f55c1871a5a65507416076f6eb97e738d5210aeda7595a74ee895f2224cce60 F test/progress.test ebab27f670bd0d4eb9d20d49cef96e68141d92fb F test/ptrchng.test ef1aa72d6cf35a2bbd0869a649b744e9d84977fc -F test/pushdown.test 1495a09837a1cedfc0adf07ba42dc6b83be05a2c15de331b67c39a0e22078238 +F test/pushdown.test a8472a771ff80f9652477a688a5beed40b1f6de6546ed3a38150d3b272891173 F test/queryonly.test 5f653159e0f552f0552d43259890c1089391dcca F test/quick.test 1681febc928d686362d50057c642f77a02c62e57 F test/quickcheck.test a4b7e878cd97e46108291c409b0bf8214f29e18fddd68a42bc5c1375ad1fb80a @@ -2184,9 +2184,11 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P c7896e88850669e18e89d44c4169d4f4a5d4b904bea6ccb2ac64f93b6d348a42 -Q -a9657c87c53c19228a42559c82c54b504a5ad729e407e9e2c7dabcc0c949b261 -R 00fdd25fa9a3c1e58bfe6d44fd3eb812 +P 4484ec6d26b31305e31de89bdbae26344d8083a7e7de20861430d31737d9979c +R 445c665a7eec3209ded422866778f161 +T *branch * pushdown-IN-table +T *sym-pushdown-IN-table * +T -sym-trunk * U drh -Z d45c3b35e63ad3a95f4d8ac3c99323f3 +Z 5ecd3bbce21aa8f702309c384d09dab0 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 0dad7c2062..7d0dacd7c0 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4484ec6d26b31305e31de89bdbae26344d8083a7e7de20861430d31737d9979c \ No newline at end of file +2cbd7838fd6ffdf210f34671cd2e3e749a076a3a6f155bbe5f910a67db31c5b1 \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index edfea3fc92..f2b252792b 100644 --- a/src/expr.c +++ b/src/expr.c @@ -2500,7 +2500,7 @@ static int exprNodeIsConstant(Walker *pWalker, Expr *pExpr){ return WRC_Continue; } } -static int exprIsConst(Parse *pParse, Expr *p, int initFlag, int iCur){ +static int exprIsConst(Parse *pParse, Expr *p, int initFlag){ Walker w; w.eCode = initFlag; w.pParse = pParse; @@ -2509,7 +2509,6 @@ static int exprIsConst(Parse *pParse, Expr *p, int initFlag, int iCur){ #ifdef SQLITE_DEBUG w.xSelectCallback2 = sqlite3SelectWalkAssert2; #endif - w.u.iCur = iCur; sqlite3WalkExpr(&w, p); return w.eCode; } @@ -2529,7 +2528,7 @@ static int exprIsConst(Parse *pParse, Expr *p, int initFlag, int iCur){ ** function and on its parameters. */ int sqlite3ExprIsConstant(Parse *pParse, Expr *p){ - return exprIsConst(pParse, p, 1, 0); + return exprIsConst(pParse, p, 1); } /* @@ -2546,7 +2545,44 @@ int sqlite3ExprIsConstant(Parse *pParse, Expr *p){ ** the prepared statement starts up. See sqlite3ExprCodeRunJustOnce(). */ static int sqlite3ExprIsConstantNotJoin(Parse *pParse, Expr *p){ - return exprIsConst(pParse, p, 2, 0); + return exprIsConst(pParse, p, 2); +} + +/* +** This routine examines sub-SELECT statements as an expression is being +** walked as part of sqlite3ExprIsTableConstant() (hereafter IsTabConst()). +** Most SELECT statements will cause IsTabConst() to return false. However, +** if: +** +** (1) The SELECT is the right-hand side of an IN operator, and +** (2) Nothing in the SELECT refers to anything other than itself +** +** Then this routine causes the sub-SELECT to be bypassed, so that if +** nothing else is amiss the IsTabConst() routine can return true. +*/ +static int exprSelectWalkTableConstant(Walker *pWalker, Select *pSelect){ + int savedCursor; + assert( pSelect!=0 ); + assert( pWalker->eCode==3 || pWalker->eCode==0 ); + if( (pSelect->selFlags & SF_RhsOfIN)==0 ){ + pWalker->eCode = 0; + return WRC_Abort; + } + assert( pSelect->pSrc!=0 ); + assert( pSelect->pSrc->nSrc==1 ); + assert( pSelect->pWhere==0 ); + assert( pSelect->pGroupBy==0 ); + assert( pSelect->pHaving==0 ); + assert( pSelect->pOrderBy==0 ); + assert( pSelect->pPrior==0 ); + assert( pSelect->pNext==0 ); + assert( pSelect->pLimit==0 ); + assert( pSelect->pWith==0 ); + savedCursor = pWalker->u.iCur; + pWalker->u.iCur = pSelect->pSrc->a[0].iCursor; + sqlite3WalkExprList(pWalker, pSelect->pEList); + pWalker->u.iCur = savedCursor; + return WRC_Prune; } /* @@ -2554,9 +2590,19 @@ static int sqlite3ExprIsConstantNotJoin(Parse *pParse, Expr *p){ ** for any single row of the table with cursor iCur. In other words, the ** expression must not refer to any non-deterministic function nor any ** table other than iCur. +** +** 2024-04-05: Operators of the form "expr IN table" are now allowed, where +** "table" is the name of a table. */ -int sqlite3ExprIsTableConstant(Expr *p, int iCur){ - return exprIsConst(0, p, 3, iCur); +static int sqlite3ExprIsTableConstant(Expr *p, int iCur){ + Walker w; + w.eCode = 3; + w.pParse = 0; + w.xExprCallback = exprNodeIsConstant; + w.xSelectCallback = exprSelectWalkTableConstant; + w.u.iCur = iCur; + sqlite3WalkExpr(&w, p); + return w.eCode; } /* @@ -2713,7 +2759,7 @@ int sqlite3ExprIsConstantOrGroupBy(Parse *pParse, Expr *p, ExprList *pGroupBy){ */ int sqlite3ExprIsConstantOrFunction(Expr *p, u8 isInit){ assert( isInit==0 || isInit==1 ); - return exprIsConst(0, p, 4+isInit, 0); + return exprIsConst(0, p, 4+isInit); } #ifdef SQLITE_ENABLE_CURSOR_HINTS diff --git a/src/parse.y b/src/parse.y index d22c8e6fc2..7a3d637663 100644 --- a/src/parse.y +++ b/src/parse.y @@ -1369,6 +1369,10 @@ expr(A) ::= expr(A) between_op(N) expr(X) AND expr(Y). [BETWEEN] { if( E ) sqlite3SrcListFuncArgs(pParse, pSelect ? pSrc : 0, E); A = sqlite3PExpr(pParse, TK_IN, A, 0); sqlite3PExprAddSelect(pParse, A, pSelect); + if( pParse->nErr==0 ){ + assert( pSelect!=0 ); + pSelect->selFlags |= SF_RhsOfIN; + } if( N ) A = sqlite3PExpr(pParse, TK_NOT, A, 0); } expr(A) ::= EXISTS LP select(Y) RP. { diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 365ff2c7f5..29acb570de 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -3585,6 +3585,7 @@ struct Select { #define SF_CopyCte 0x4000000 /* SELECT statement is a copy of a CTE */ #define SF_OrderByReqd 0x8000000 /* The ORDER BY clause may not be omitted */ #define SF_UpdateFrom 0x10000000 /* Query originates with UPDATE FROM */ +#define SF_RhsOfIN 0x20000000 /* Right-hand-side of an IN operator */ /* True if S exists and has SF_NestedFrom */ #define IsNestedFrom(S) ((S)!=0 && ((S)->selFlags&SF_NestedFrom)!=0) @@ -5081,7 +5082,7 @@ int sqlite3ExprTruthValue(const Expr*); int sqlite3ExprIsConstant(Parse*,Expr*); int sqlite3ExprIsConstantOrFunction(Expr*, u8); int sqlite3ExprIsConstantOrGroupBy(Parse*, Expr*, ExprList*); -int sqlite3ExprIsTableConstant(Expr*,int); +// int sqlite3ExprIsTableConstant(Expr*,int); int sqlite3ExprIsSingleTableConstraint(Expr*,const SrcList*,int); #ifdef SQLITE_ENABLE_CURSOR_HINTS int sqlite3ExprContainsSubquery(Expr*); diff --git a/test/pushdown.test b/test/pushdown.test index 1fbe6f34cd..036fe2e2d8 100644 --- a/test/pushdown.test +++ b/test/pushdown.test @@ -227,4 +227,89 @@ do_execsql_test 5.0 { WHERE e>0; } {- - 3 4 5} + +# 2024-04-05 +# Allow push-down of operators of the form "expr IN table". +# +reset_db +do_execsql_test 6.0 { + CREATE TABLE t01(w,x,y,z); + CREATE TABLE t02(w,x,y,z); + CREATE VIEW t0(w,x,y,z) AS + SELECT w,x,y,z FROM t01 UNION ALL SELECT w,x,y,z FROM t02; + CREATE INDEX t01x ON t01(w,x,y); + CREATE INDEX t02x ON t02(w,x,y); + CREATE VIEW v1(k) AS VALUES(77),(88),(99); + CREATE TABLE k1(k); + INSERT INTO k1 SELECT * FROM v1; +} +do_eqp_test 6.1 { + WITH k(n) AS (VALUES(77),(88),(99)) + SELECT max(z) FROM t0 WHERE w=123 AND x IN k AND y BETWEEN 44 AND 55; +} { + QUERY PLAN + |--CO-ROUTINE t0 + | `--COMPOUND QUERY + | |--LEFT-MOST SUBQUERY + | | |--SEARCH t01 USING INDEX t01x (w=? AND x=? AND y>? AND y? AND y? AND y? AND y? AND y? AND y Date: Sat, 6 Apr 2024 12:19:50 +0000 Subject: [PATCH 305/430] Generalize pushdown to allow any uncorrelated subquery to be pushed down. FossilOrigin-Name: 87c45fb0d5f5ca5d6d1ad27bef83f294231d17d94299e1997364a7975b423e38 --- manifest | 24 ++++++++++++------------ manifest.uuid | 2 +- src/expr.c | 32 +++++--------------------------- src/parse.y | 4 ---- src/resolve.c | 2 ++ src/sqliteInt.h | 3 +-- 6 files changed, 21 insertions(+), 46 deletions(-) diff --git a/manifest b/manifest index 8fd5496617..581e5d22d1 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Experimental\senhancement\sin\swhich\sexpressions\sof\sthe\sform\s"expr\sIN\stable"\ncan\sbe\spushed\sdown\sinto\ssubexpressions. -D 2024-04-05T20:01:28.787 +C Generalize\spushdown\sto\sallow\sany\suncorrelated\ssubquery\sto\sbe\spushed\sdown. +D 2024-04-06T12:19:50.927 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -700,7 +700,7 @@ F src/date.c 126ba2ab10aeb2e7ba6e089b5f07b747c0625b8287f78b60da346eda8d23c875 F src/dbpage.c 80e46e1df623ec40486da7a5086cb723b0275a6e2a7b01d9f9b5da0f04ba2782 F src/dbstat.c 3b677254d512fcafd4d0b341bf267b38b235ccfddbef24f9154e19360fa22e43 F src/delete.c cb766727c78e715f9fb7ec8a7d03658ed2a3016343ca687acfcec9083cdca500 -F src/expr.c 48e6732170b5f3c07f9ebbdbe12c478e2867ea4be4361946ed26e2c8d607f7e8 +F src/expr.c f2f4768a25d62f645d11233930c0514f5f05fdadd8150e17d64187dd5aa41e4a F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c a47610f0a5c6cb0ad79f8fcef039c01833dec0c751bb695f28dc0ec6a4c3ba00 F src/func.c 283d4f3b2751a1d9339fd93a8a013d1948fd5f4474a3cab0955eb4fafd445d0f @@ -739,7 +739,7 @@ F src/os_win.c 6ff43bac175bd9ed79e7c0f96840b139f2f51d01689a638fd05128becf94908a F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a F src/pager.c ff60e98138d2499082ac6230f01ac508aba545315debccfca2fd6042f5f10fcd F src/pager.h 4b1140d691860de0be1347474c51fee07d5420bd7f802d38cbab8ea4ab9f538a -F src/parse.y 67b9965a501599d5a1a4333125fab0dd230e03e28045700c9b331f7c3269bda5 +F src/parse.y 5bcef16094213efcc365a9d4dc4e3131f09251dc8838dce4a9e5f9764bff5b82 F src/pcache.c 040b165f30622a21b7a9a77c6f2e4877a32fb7f22d4c7f0d2a6fa6833a156a75 F src/pcache.h 1497ce1b823cf00094bb0cf3bac37b345937e6f910890c626b16512316d3abf5 F src/pcache1.c 602acb23c471bb8d557a6f0083cc2be641d6cafcafa19e481eba7ef4c9ca0f00 @@ -748,14 +748,14 @@ F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7 F src/prepare.c 371f6115cb69286ebc12c6f2d7511279c2e47d9f54f475d46a554d687a3b312c F src/printf.c 87b67bba3662a0523f39ae6b084a3907109702f717c654d6cecb838af5cd57f1 F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c -F src/resolve.c eb1860b134fb044fd819c4347105c148d5aac7c6498032be2829e5cc95619b28 +F src/resolve.c f242e509b2ff9e31799d26ddd87f20db1124426203aa16833a694d401b50d650 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c 15a221347789e393b39e7d2d2bd102167979c95a1ce0675bb870b86a24ca6cf4 F src/shell.c.in 0354ca51eee5fbf6af394a7ef9f5ef6823ef45b743db65431f6777e4d5be2199 F src/sqlite.h.in 32389e0d584551b300d0157881336162c14315a424cbf385c0d65eb7c2e31f7b F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 -F src/sqliteInt.h a0d0f014baafcb61f5d0a6d206d4b190644d57bb762dff2073903595653d6319 +F src/sqliteInt.h e9ef8bb759f6ed7c41971bd8189dca3d38cc8bc69c463a6f49aaa9401857091a F src/sqliteLimit.h 6878ab64bdeb8c24a1d762d45635e34b96da21132179023338c93f820eee6728 F src/status.c cb11f8589a6912af2da3bb1ec509a94dd8ef27df4d4c1a97e0bcf2309ece972b F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1 @@ -2184,11 +2184,11 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 4484ec6d26b31305e31de89bdbae26344d8083a7e7de20861430d31737d9979c -R 445c665a7eec3209ded422866778f161 -T *branch * pushdown-IN-table -T *sym-pushdown-IN-table * -T -sym-trunk * +P 2cbd7838fd6ffdf210f34671cd2e3e749a076a3a6f155bbe5f910a67db31c5b1 +R 3f1ebbef3f30ee834eac030ff4cc2f9a +T *branch * pushdown-subquery +T *sym-pushdown-subquery * +T -sym-pushdown-IN-table * U drh -Z 5ecd3bbce21aa8f702309c384d09dab0 +Z 00cc18dd5b8247ec2ec6349e18d457dd # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 7d0dacd7c0..b3cce22c82 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2cbd7838fd6ffdf210f34671cd2e3e749a076a3a6f155bbe5f910a67db31c5b1 \ No newline at end of file +87c45fb0d5f5ca5d6d1ad27bef83f294231d17d94299e1997364a7975b423e38 \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index f2b252792b..9513e5ffd5 100644 --- a/src/expr.c +++ b/src/expr.c @@ -2550,38 +2550,17 @@ static int sqlite3ExprIsConstantNotJoin(Parse *pParse, Expr *p){ /* ** This routine examines sub-SELECT statements as an expression is being -** walked as part of sqlite3ExprIsTableConstant() (hereafter IsTabConst()). -** Most SELECT statements will cause IsTabConst() to return false. However, -** if: -** -** (1) The SELECT is the right-hand side of an IN operator, and -** (2) Nothing in the SELECT refers to anything other than itself -** -** Then this routine causes the sub-SELECT to be bypassed, so that if -** nothing else is amiss the IsTabConst() routine can return true. +** walked as part of sqlite3ExprIsTableConstant(). Sub-SELECTs are considered +** constant as long as they are uncorrelated - meaning that they do not +** contain any terms from outer contexts. */ static int exprSelectWalkTableConstant(Walker *pWalker, Select *pSelect){ - int savedCursor; assert( pSelect!=0 ); assert( pWalker->eCode==3 || pWalker->eCode==0 ); - if( (pSelect->selFlags & SF_RhsOfIN)==0 ){ + if( (pSelect->selFlags & SF_Correlated)!=0 ){ pWalker->eCode = 0; return WRC_Abort; } - assert( pSelect->pSrc!=0 ); - assert( pSelect->pSrc->nSrc==1 ); - assert( pSelect->pWhere==0 ); - assert( pSelect->pGroupBy==0 ); - assert( pSelect->pHaving==0 ); - assert( pSelect->pOrderBy==0 ); - assert( pSelect->pPrior==0 ); - assert( pSelect->pNext==0 ); - assert( pSelect->pLimit==0 ); - assert( pSelect->pWith==0 ); - savedCursor = pWalker->u.iCur; - pWalker->u.iCur = pSelect->pSrc->a[0].iCursor; - sqlite3WalkExprList(pWalker, pSelect->pEList); - pWalker->u.iCur = savedCursor; return WRC_Prune; } @@ -2591,8 +2570,7 @@ static int exprSelectWalkTableConstant(Walker *pWalker, Select *pSelect){ ** expression must not refer to any non-deterministic function nor any ** table other than iCur. ** -** 2024-04-05: Operators of the form "expr IN table" are now allowed, where -** "table" is the name of a table. +** Enhanced on 2024-04-06: Allow pExpr to contain uncorrelated subqueries. */ static int sqlite3ExprIsTableConstant(Expr *p, int iCur){ Walker w; diff --git a/src/parse.y b/src/parse.y index 7a3d637663..d22c8e6fc2 100644 --- a/src/parse.y +++ b/src/parse.y @@ -1369,10 +1369,6 @@ expr(A) ::= expr(A) between_op(N) expr(X) AND expr(Y). [BETWEEN] { if( E ) sqlite3SrcListFuncArgs(pParse, pSelect ? pSrc : 0, E); A = sqlite3PExpr(pParse, TK_IN, A, 0); sqlite3PExprAddSelect(pParse, A, pSelect); - if( pParse->nErr==0 ){ - assert( pSelect!=0 ); - pSelect->selFlags |= SF_RhsOfIN; - } if( N ) A = sqlite3PExpr(pParse, TK_NOT, A, 0); } expr(A) ::= EXISTS LP select(Y) RP. { diff --git a/src/resolve.c b/src/resolve.c index 6e0c9906a6..7378addf5d 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -1349,6 +1349,7 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){ testcase( pNC->ncFlags & NC_PartIdx ); testcase( pNC->ncFlags & NC_IdxExpr ); testcase( pNC->ncFlags & NC_GenCol ); + assert( pExpr->x.pSelect ); if( pNC->ncFlags & NC_SelfRef ){ notValidImpl(pParse, pNC, "subqueries", pExpr, pExpr); }else{ @@ -1357,6 +1358,7 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){ assert( pNC->nRef>=nRef ); if( nRef!=pNC->nRef ){ ExprSetProperty(pExpr, EP_VarSelect); + pExpr->x.pSelect->selFlags |= SF_Correlated; } pNC->ncFlags |= NC_Subquery; } diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 29acb570de..a735c445e7 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -3585,7 +3585,7 @@ struct Select { #define SF_CopyCte 0x4000000 /* SELECT statement is a copy of a CTE */ #define SF_OrderByReqd 0x8000000 /* The ORDER BY clause may not be omitted */ #define SF_UpdateFrom 0x10000000 /* Query originates with UPDATE FROM */ -#define SF_RhsOfIN 0x20000000 /* Right-hand-side of an IN operator */ +#define SF_Correlated 0x20000000 /* True if references the outer context */ /* True if S exists and has SF_NestedFrom */ #define IsNestedFrom(S) ((S)!=0 && ((S)->selFlags&SF_NestedFrom)!=0) @@ -5082,7 +5082,6 @@ int sqlite3ExprTruthValue(const Expr*); int sqlite3ExprIsConstant(Parse*,Expr*); int sqlite3ExprIsConstantOrFunction(Expr*, u8); int sqlite3ExprIsConstantOrGroupBy(Parse*, Expr*, ExprList*); -// int sqlite3ExprIsTableConstant(Expr*,int); int sqlite3ExprIsSingleTableConstraint(Expr*,const SrcList*,int); #ifdef SQLITE_ENABLE_CURSOR_HINTS int sqlite3ExprContainsSubquery(Expr*); From 8181cc6c105f3a0253999563d73aa541a6f9916e Mon Sep 17 00:00:00 2001 From: drh <> Date: Sat, 6 Apr 2024 17:37:30 +0000 Subject: [PATCH 306/430] Improvements to the accurancy of the fuzzinvariants.c testing module when SQLITE_ALLOW_ROWID_IN_VIEW is defined and the test query involves rowids. FossilOrigin-Name: c6e873d4db3ef36a0d561e64ead6feada5d1654c0757b4b6e55f671c9db66469 --- manifest | 13 ++++++------- manifest.uuid | 2 +- test/fuzzinvariants.c | 35 ++++++++++++++++++++++++++++++++--- 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 8b598b2633..3fc2321c7a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Check-in\s[a9657c87c53c1922]\sis\swrong:\sthe\sIndexedExpr.bMaybeNullRow\sflag\sis\nrequired\sfor\svirtual\scolumns\sif\sthey\sare\spart\sof\san\souter\sjoin.\s\sAdd\sa\ntest\scase\s(derived\sfrom\sdbsqlfuzz\sb9e65e2f110df998f1306571fae7af6c01e4d92b)\nto\sprove\sit. -D 2024-04-05T13:56:05.021 +C Improvements\sto\sthe\saccurancy\sof\sthe\sfuzzinvariants.c\stesting\smodule\swhen\nSQLITE_ALLOW_ROWID_IN_VIEW\sis\sdefined\sand\sthe\stest\squery\sinvolves\srowids. +D 2024-04-06T17:37:30.138 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -1258,7 +1258,7 @@ F test/fuzzdata8.db 4a53b6d077c6a5c23b609d8d3ac66996fa55ba3f8d02f9b6efdd0214a767 F test/fuzzer1.test 3d4c4b7e547aba5e5511a2991e3e3d07166cfbb8 F test/fuzzer2.test a85ef814ce071293bce1ad8dffa217cbbaad4c14 F test/fuzzerfault.test f64c4aef4c9e9edf1d6dc0d3f1e65dcc81e67c996403c88d14f09b74807a42bc -F test/fuzzinvariants.c 4355043e98cd8555c62462fcbba91c17c6492b0b017bbbe68656d5f2208f6444 +F test/fuzzinvariants.c 9fc6810dde21e1aee20ed7a6c8ed944ffee127cf082fc48caba398fa31c762ca F test/gcfault.test 4ea410ac161e685f17b19e1f606f58514a2850e806c65b846d05f60d436c5b0d F test/gencol1.test e169bdfa11c7ed5e9f322a98a7db3afe9e66235750b68c923efee8e1876b46ec F test/genesis.tcl 1e2e2e8e5cc4058549a154ff1892fe5c9de19f98 @@ -2184,9 +2184,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P c7896e88850669e18e89d44c4169d4f4a5d4b904bea6ccb2ac64f93b6d348a42 -Q -a9657c87c53c19228a42559c82c54b504a5ad729e407e9e2c7dabcc0c949b261 -R 00fdd25fa9a3c1e58bfe6d44fd3eb812 +P 4484ec6d26b31305e31de89bdbae26344d8083a7e7de20861430d31737d9979c +R e668dfe755aeff2fdd8b334389296750 U drh -Z d45c3b35e63ad3a95f4d8ac3c99323f3 +Z 4d6c822e968c71422e1200a444d830a0 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 0dad7c2062..57aabf40aa 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4484ec6d26b31305e31de89bdbae26344d8083a7e7de20861430d31737d9979c \ No newline at end of file +c6e873d4db3ef36a0d561e64ead6feada5d1654c0757b4b6e55f671c9db66469 \ No newline at end of file diff --git a/test/fuzzinvariants.c b/test/fuzzinvariants.c index 00b2c11742..25b35d4f6b 100644 --- a/test/fuzzinvariants.c +++ b/test/fuzzinvariants.c @@ -223,6 +223,18 @@ int fuzz_invariant( return SQLITE_OK; } +#ifdef SQLITE_ALLOW_ROWID_IN_VIEW +/* +** Return TRUE if the i-th column of pStmt might be a ROWID value. +*/ +static int column_might_be_rowid(sqlite3_stmt *pStmt, int i){ + const char *zColName = sqlite3_column_name(pStmt, i); + if( sqlite3_strlike("%rowid%",zColName,0)==0 ) return 1; + if( sqlite3_strlike("%oid%",zColName,0)==0 ) return 1; + return 0; +} +#endif /* SQLITE_ALLOW_ROWID_IN_VIEW */ + /* ** Generate SQL used to test a statement invariant. @@ -297,9 +309,7 @@ static char *fuzz_invariant_sql(sqlite3_stmt *pStmt, int iCnt){ continue; } #ifdef SQLITE_ALLOW_ROWID_IN_VIEW - if( sqlite3_strlike("%rowid%",zColName,0)==0 - || sqlite3_strlike("%oid%",zColName,0)==0 - ){ + if( column_might_be_rowid(pBase,i) ){ /* ROWID values are unreliable if SQLITE_ALLOW_ROWID_IN_VIEW is used */ continue; } @@ -332,6 +342,11 @@ static char *fuzz_invariant_sql(sqlite3_stmt *pStmt, int iCnt){ /* ** Return true if and only if v1 and is the same as v2. +** +** When compiled with SQLITE_ALLOW_ROWID_IN_VIEW, and if either +** v1 or v2 has a column name that indicates that it is a rowid +** then a NULL value in the rowid column will compare equal to +** an integer value in the other. */ static int sameValue( sqlite3_stmt *pS1, int i1, /* Value to text on the left */ @@ -346,6 +361,20 @@ static int sameValue( || (t1==SQLITE_FLOAT && t2==SQLITE_INTEGER) ){ /* Comparison of numerics is ok */ +#ifdef SQLITE_ALLOW_ROWID_IN_VIEW + }else + if( t1==SQLITE_INTEGER + && t2==SQLITE_NULL + && column_might_be_rowid(pS2,i2) + ){ + return 1; + }else + if( t2==SQLITE_INTEGER + && t1==SQLITE_NULL + && column_might_be_rowid(pS1,i1) + ){ + return 1; +#endif /* SQLITE_ALLOW_ROWID_IN_VIEW */ }else{ return 0; } From 6951c4977976ddca0b9e4ce75e79fc69c44dfd77 Mon Sep 17 00:00:00 2001 From: drh <> Date: Sat, 6 Apr 2024 18:30:09 +0000 Subject: [PATCH 307/430] Do not allow changes to sqlite3ExprIsTableConstant() that support pushdown of subqueries interfere with the hash-join logic. FossilOrigin-Name: 8682931f9c6b40e1b09139c10bbe932c38330b5eb0c5c84f2432ad19a6793e37 --- manifest | 18 +++++++++--------- manifest.uuid | 2 +- src/expr.c | 25 +++++++++++++++++++------ src/select.c | 2 +- src/sqliteInt.h | 2 +- src/where.c | 4 ++-- 6 files changed, 33 insertions(+), 20 deletions(-) diff --git a/manifest b/manifest index b13e8b0b82..781df2e045 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Merge\stesting\slogic\sfixes\son\strunk\sinto\sthe\spushdown-subquery\sbranch. -D 2024-04-06T17:42:14.598 +C Do\snot\sallow\schanges\sto\ssqlite3ExprIsTableConstant()\sthat\ssupport\spushdown\sof\nsubqueries\sinterfere\swith\sthe\shash-join\slogic. +D 2024-04-06T18:30:09.352 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -700,7 +700,7 @@ F src/date.c 126ba2ab10aeb2e7ba6e089b5f07b747c0625b8287f78b60da346eda8d23c875 F src/dbpage.c 80e46e1df623ec40486da7a5086cb723b0275a6e2a7b01d9f9b5da0f04ba2782 F src/dbstat.c 3b677254d512fcafd4d0b341bf267b38b235ccfddbef24f9154e19360fa22e43 F src/delete.c cb766727c78e715f9fb7ec8a7d03658ed2a3016343ca687acfcec9083cdca500 -F src/expr.c f2f4768a25d62f645d11233930c0514f5f05fdadd8150e17d64187dd5aa41e4a +F src/expr.c a475049e45329a4586ce8967963784a72023cef0f5821a2265ccacb7f68e0bc6 F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c a47610f0a5c6cb0ad79f8fcef039c01833dec0c751bb695f28dc0ec6a4c3ba00 F src/func.c 283d4f3b2751a1d9339fd93a8a013d1948fd5f4474a3cab0955eb4fafd445d0f @@ -750,12 +750,12 @@ F src/printf.c 87b67bba3662a0523f39ae6b084a3907109702f717c654d6cecb838af5cd57f1 F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c f242e509b2ff9e31799d26ddd87f20db1124426203aa16833a694d401b50d650 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 -F src/select.c 15a221347789e393b39e7d2d2bd102167979c95a1ce0675bb870b86a24ca6cf4 +F src/select.c 6208d6d4acafc944b9916df28e63fc4e47b922b0335d0db057f68e334b87fc8e F src/shell.c.in 0354ca51eee5fbf6af394a7ef9f5ef6823ef45b743db65431f6777e4d5be2199 F src/sqlite.h.in 32389e0d584551b300d0157881336162c14315a424cbf385c0d65eb7c2e31f7b F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 -F src/sqliteInt.h e9ef8bb759f6ed7c41971bd8189dca3d38cc8bc69c463a6f49aaa9401857091a +F src/sqliteInt.h 257a7addbdb67b1f9f514a28904ed3f574de16bd87c21570faf30600c9c39f40 F src/sqliteLimit.h 6878ab64bdeb8c24a1d762d45635e34b96da21132179023338c93f820eee6728 F src/status.c cb11f8589a6912af2da3bb1ec509a94dd8ef27df4d4c1a97e0bcf2309ece972b F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1 @@ -835,7 +835,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c 887fc4ca3f020ebb2e376f222069570834ac63bf50111ef0cbf3ae417048ed89 F src/wal.h ba252daaa94f889f4b2c17c027e823d9be47ce39da1d3799886bbd51f0490452 F src/walker.c 7c7ea0115345851c3da4e04e2e239a29983b61fb5b038b94eede6aba462640e2 -F src/where.c 9982128f010a699560fb5be37633801c7641ac3540f49db43cec878025929a0e +F src/where.c 09253e913dc1a93aa6e0e1a5d25a392b8fa39096cc30d230dd302264b3be0661 F src/whereInt.h 82a13766f13d1a53b05387c2e60726289ef26404bc7b9b1f7770204d97357fb8 F src/wherecode.c 5d77db30a2a3dd532492ae882de114edba2fae672622056b1c7fd61f5917a8f1 F src/whereexpr.c 7b64295f1d82ad0928df435925dd7bbd5997b44a026153113eace0d9e71ff435 @@ -2184,8 +2184,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 87c45fb0d5f5ca5d6d1ad27bef83f294231d17d94299e1997364a7975b423e38 c6e873d4db3ef36a0d561e64ead6feada5d1654c0757b4b6e55f671c9db66469 -R 5c918916ac2b7aa6a88b463bfdfa1fb1 +P a4e1f03dcad70e828a4b56e7a332946daf84d6eae078e3ec9a248b8157a53963 +R d7462427e22b33861c511b137742aefb U drh -Z 8a9056dc314aaed8a12c375787e3cb55 +Z cfcd3c15df77757710cc4630347f7777 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 6465b19d72..545d7417cd 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a4e1f03dcad70e828a4b56e7a332946daf84d6eae078e3ec9a248b8157a53963 \ No newline at end of file +8682931f9c6b40e1b09139c10bbe932c38330b5eb0c5c84f2432ad19a6793e37 \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index 9513e5ffd5..0ccb39cc6e 100644 --- a/src/expr.c +++ b/src/expr.c @@ -2570,14 +2570,22 @@ static int exprSelectWalkTableConstant(Walker *pWalker, Select *pSelect){ ** expression must not refer to any non-deterministic function nor any ** table other than iCur. ** -** Enhanced on 2024-04-06: Allow pExpr to contain uncorrelated subqueries. +** Consider uncorrelated subqueries to be constants if the bAllowSubq +** parameter is true. */ -static int sqlite3ExprIsTableConstant(Expr *p, int iCur){ +static int sqlite3ExprIsTableConstant(Expr *p, int iCur, int bAllowSubq){ Walker w; w.eCode = 3; w.pParse = 0; w.xExprCallback = exprNodeIsConstant; - w.xSelectCallback = exprSelectWalkTableConstant; + if( bAllowSubq ){ + w.xSelectCallback = exprSelectWalkTableConstant; + }else{ + w.xSelectCallback = sqlite3SelectWalkFail; +#ifdef SQLITE_DEBUG + w.xSelectCallback2 = sqlite3SelectWalkAssert2; +#endif + } w.u.iCur = iCur; sqlite3WalkExpr(&w, p); return w.eCode; @@ -2598,7 +2606,10 @@ static int sqlite3ExprIsTableConstant(Expr *p, int iCur){ ** ** (1) pExpr cannot refer to any table other than pSrc->iCursor. ** -** (2) pExpr cannot use subqueries or non-deterministic functions. +** (2a) pExpr cannot use subqueries unless the bAllowSubq parameter is +** true and the subquery is non-correlated +** +** (2b) pExpr cannot use non-deterministic functions. ** ** (3) pSrc cannot be part of the left operand for a RIGHT JOIN. ** (Is there some way to relax this constraint?) @@ -2627,7 +2638,8 @@ static int sqlite3ExprIsTableConstant(Expr *p, int iCur){ int sqlite3ExprIsSingleTableConstraint( Expr *pExpr, /* The constraint */ const SrcList *pSrcList, /* Complete FROM clause */ - int iSrc /* Which element of pSrcList to use */ + int iSrc, /* Which element of pSrcList to use */ + int bAllowSubq /* Allow non-correlated subqueries */ ){ const SrcItem *pSrc = &pSrcList->a[iSrc]; if( pSrc->fg.jointype & JT_LTORJ ){ @@ -2652,7 +2664,8 @@ int sqlite3ExprIsSingleTableConstraint( } } } - return sqlite3ExprIsTableConstant(pExpr, pSrc->iCursor); /* rules (1), (2) */ + /* Rules (1), (2a), and (2b) handled by the following: */ + return sqlite3ExprIsTableConstant(pExpr, pSrc->iCursor, bAllowSubq); } diff --git a/src/select.c b/src/select.c index b200518518..b13aae1f9a 100644 --- a/src/select.c +++ b/src/select.c @@ -5260,7 +5260,7 @@ static int pushDownWhereTerms( } #endif - if( sqlite3ExprIsSingleTableConstraint(pWhere, pSrcList, iSrc) ){ + if( sqlite3ExprIsSingleTableConstraint(pWhere, pSrcList, iSrc, 1) ){ nChng++; pSubq->selFlags |= SF_PushDown; while( pSubq ){ diff --git a/src/sqliteInt.h b/src/sqliteInt.h index a735c445e7..d80a646093 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -5082,7 +5082,7 @@ int sqlite3ExprTruthValue(const Expr*); int sqlite3ExprIsConstant(Parse*,Expr*); int sqlite3ExprIsConstantOrFunction(Expr*, u8); int sqlite3ExprIsConstantOrGroupBy(Parse*, Expr*, ExprList*); -int sqlite3ExprIsSingleTableConstraint(Expr*,const SrcList*,int); +int sqlite3ExprIsSingleTableConstraint(Expr*,const SrcList*,int,int); #ifdef SQLITE_ENABLE_CURSOR_HINTS int sqlite3ExprContainsSubquery(Expr*); #endif diff --git a/src/where.c b/src/where.c index a1837b5879..65b6ae2c92 100644 --- a/src/where.c +++ b/src/where.c @@ -942,7 +942,7 @@ static SQLITE_NOINLINE void constructAutomaticIndex( ** WHERE clause (or the ON clause of a LEFT join) that constrain which ** rows of the target table (pSrc) that can be used. */ if( (pTerm->wtFlags & TERM_VIRTUAL)==0 - && sqlite3ExprIsSingleTableConstraint(pExpr, pTabList, pLevel->iFrom) + && sqlite3ExprIsSingleTableConstraint(pExpr, pTabList, pLevel->iFrom, 0) ){ pPartial = sqlite3ExprAnd(pParse, pPartial, sqlite3ExprDup(pParse->db, pExpr, 0)); @@ -1211,7 +1211,7 @@ static SQLITE_NOINLINE void sqlite3ConstructBloomFilter( for(pTerm=pWInfo->sWC.a; pTermpExpr; if( (pTerm->wtFlags & TERM_VIRTUAL)==0 - && sqlite3ExprIsSingleTableConstraint(pExpr, pTabList, iSrc) + && sqlite3ExprIsSingleTableConstraint(pExpr, pTabList, iSrc, 0) ){ sqlite3ExprIfFalse(pParse, pTerm->pExpr, addrCont, SQLITE_JUMPIFNULL); } From 05c6d13027db5e2f8dd6311fd6520e1ca0e7bdb9 Mon Sep 17 00:00:00 2001 From: drh <> Date: Sun, 7 Apr 2024 10:27:18 +0000 Subject: [PATCH 308/430] Add comments to note the name abiguity between the MySQL push-down optimization and the WHERE-clause push-down optimization. FossilOrigin-Name: 3d5fb1ec7a0440072d6e3b957903c85d0f32b8b07207a1ef22d1a69cf5e664d1 --- manifest | 21 +++++++++++---------- manifest.uuid | 2 +- src/expr.c | 5 +++-- src/select.c | 22 +++++++++++++++++----- src/sqliteInt.h | 4 ++-- src/wherecode.c | 6 ++++++ test/pushdown.test | 28 ++++++++++++++++++++++++---- 7 files changed, 64 insertions(+), 24 deletions(-) diff --git a/manifest b/manifest index 3fc2321c7a..64b52c9b24 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improvements\sto\sthe\saccurancy\sof\sthe\sfuzzinvariants.c\stesting\smodule\swhen\nSQLITE_ALLOW_ROWID_IN_VIEW\sis\sdefined\sand\sthe\stest\squery\sinvolves\srowids. -D 2024-04-06T17:37:30.138 +C Add\scomments\sto\snote\sthe\sname\sabiguity\sbetween\sthe\sMySQL\spush-down\noptimization\sand\sthe\sWHERE-clause\spush-down\soptimization. +D 2024-04-07T10:27:18.165 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -700,7 +700,7 @@ F src/date.c 126ba2ab10aeb2e7ba6e089b5f07b747c0625b8287f78b60da346eda8d23c875 F src/dbpage.c 80e46e1df623ec40486da7a5086cb723b0275a6e2a7b01d9f9b5da0f04ba2782 F src/dbstat.c 3b677254d512fcafd4d0b341bf267b38b235ccfddbef24f9154e19360fa22e43 F src/delete.c cb766727c78e715f9fb7ec8a7d03658ed2a3016343ca687acfcec9083cdca500 -F src/expr.c cd46ce2ebe46a30e63087dbe8aff7d6e34ba8acc8c658e8e18fcaa35f2711391 +F src/expr.c 98a1cabc44fbf64e4c87a639f4399d1afde640875c16dbc2e62a37c102cca9e8 F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c a47610f0a5c6cb0ad79f8fcef039c01833dec0c751bb695f28dc0ec6a4c3ba00 F src/func.c 283d4f3b2751a1d9339fd93a8a013d1948fd5f4474a3cab0955eb4fafd445d0f @@ -750,12 +750,12 @@ F src/printf.c 87b67bba3662a0523f39ae6b084a3907109702f717c654d6cecb838af5cd57f1 F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c eb1860b134fb044fd819c4347105c148d5aac7c6498032be2829e5cc95619b28 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 -F src/select.c 15a221347789e393b39e7d2d2bd102167979c95a1ce0675bb870b86a24ca6cf4 +F src/select.c 3c8e1b921edfb71904b01c1ef9fb378224cdba71543342b164c7718cc8e82a44 F src/shell.c.in 0354ca51eee5fbf6af394a7ef9f5ef6823ef45b743db65431f6777e4d5be2199 F src/sqlite.h.in 32389e0d584551b300d0157881336162c14315a424cbf385c0d65eb7c2e31f7b F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 -F src/sqliteInt.h 170f85c5a9d6189cf9b5dd304f4d40b73a8c9762fb927f1327e8ed2cb99c06b6 +F src/sqliteInt.h a275d95f5612f2640380532e484d1f6c46a48d84ae227e6c12e36712c22b7b8a F src/sqliteLimit.h 6878ab64bdeb8c24a1d762d45635e34b96da21132179023338c93f820eee6728 F src/status.c cb11f8589a6912af2da3bb1ec509a94dd8ef27df4d4c1a97e0bcf2309ece972b F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1 @@ -837,7 +837,7 @@ F src/wal.h ba252daaa94f889f4b2c17c027e823d9be47ce39da1d3799886bbd51f0490452 F src/walker.c 7c7ea0115345851c3da4e04e2e239a29983b61fb5b038b94eede6aba462640e2 F src/where.c 9982128f010a699560fb5be37633801c7641ac3540f49db43cec878025929a0e F src/whereInt.h 82a13766f13d1a53b05387c2e60726289ef26404bc7b9b1f7770204d97357fb8 -F src/wherecode.c 5d77db30a2a3dd532492ae882de114edba2fae672622056b1c7fd61f5917a8f1 +F src/wherecode.c e033875570f5d65b99fdb5189e597d91c8bc34f4196089fd50e6086d174035e7 F src/whereexpr.c 7b64295f1d82ad0928df435925dd7bbd5997b44a026153113eace0d9e71ff435 F src/window.c 5d95122dd330bfaebd732358c8ef067c5a9394a53ac249470d611d0ce2c52be2 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 @@ -1510,7 +1510,7 @@ F test/printf.test 685fec5a0c5af2490ab0632775a301554361d674211d690f5bee0a97b0533 F test/printf2.test 3f55c1871a5a65507416076f6eb97e738d5210aeda7595a74ee895f2224cce60 F test/progress.test ebab27f670bd0d4eb9d20d49cef96e68141d92fb F test/ptrchng.test ef1aa72d6cf35a2bbd0869a649b744e9d84977fc -F test/pushdown.test 1495a09837a1cedfc0adf07ba42dc6b83be05a2c15de331b67c39a0e22078238 +F test/pushdown.test 45c6fa615f225041bbebac398d42aaaffdb6e0cdef8e542be9a8337a43d0ad95 F test/queryonly.test 5f653159e0f552f0552d43259890c1089391dcca F test/quick.test 1681febc928d686362d50057c642f77a02c62e57 F test/quickcheck.test a4b7e878cd97e46108291c409b0bf8214f29e18fddd68a42bc5c1375ad1fb80a @@ -2184,8 +2184,9 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 4484ec6d26b31305e31de89bdbae26344d8083a7e7de20861430d31737d9979c -R e668dfe755aeff2fdd8b334389296750 +P c6e873d4db3ef36a0d561e64ead6feada5d1654c0757b4b6e55f671c9db66469 +Q +681dfe2dd60714daf4987d45231d877f389825ab93e9bd0749391230186d6091 +R 023f47c11f43b462b0bef8a0994a0c0a U drh -Z 4d6c822e968c71422e1200a444d830a0 +Z 5c41a9ea676fc6eeb1fc7c2dc29fd70c # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 57aabf40aa..1888e324a6 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c6e873d4db3ef36a0d561e64ead6feada5d1654c0757b4b6e55f671c9db66469 \ No newline at end of file +3d5fb1ec7a0440072d6e3b957903c85d0f32b8b07207a1ef22d1a69cf5e664d1 \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index edfea3fc92..9ec77e823b 100644 --- a/src/expr.c +++ b/src/expr.c @@ -5031,8 +5031,9 @@ int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target){ if( !ExprHasProperty(pExpr, EP_Collate) ){ /* A TK_COLLATE Expr node without the EP_Collate tag is a so-called ** "SOFT-COLLATE" that is added to constraints that are pushed down - ** from outer queries into sub-queries by the push-down optimization. - ** Clear subtypes as subtypes may not cross a subquery boundary. + ** from outer queries into sub-queries by the WHERE-clause push-down + ** optimization. Clear subtypes as subtypes may not cross a subquery + ** boundary. */ assert( pExpr->pLeft ); sqlite3ExprCode(pParse, pExpr->pLeft, target); diff --git a/src/select.c b/src/select.c index b200518518..821f9a0c4e 100644 --- a/src/select.c +++ b/src/select.c @@ -5060,6 +5060,18 @@ static int pushDownWindowCheck(Parse *pParse, Select *pSubq, Expr *pExpr){ ** The hope is that the terms added to the inner query will make it more ** efficient. ** +** NAME AMBIGUITY +** +** This optimization is called the "WHERE-clause push-down optimization". +** +** Do not confuse this optimization with another unrelated optimization +** with a similar name: The "MySQL push-down optimization" causes WHERE +** clause terms that can be evaluated using only the index and without +** reference to the table are run first, so that if they are false, +** unnecessary table seeks are avoided. +** +** RULES +** ** Do not attempt this optimization if: ** ** (1) (** This restriction was removed on 2017-09-29. We used to @@ -5125,10 +5137,10 @@ static int pushDownWindowCheck(Parse *pParse, Select *pSubq, Expr *pExpr){ ** (9c) There is a RIGHT JOIN (or FULL JOIN) in between the ON/USING ** clause and the subquery. ** -** Without this restriction, the push-down optimization might move -** the ON/USING filter expression from the left side of a RIGHT JOIN -** over to the right side, which leads to incorrect answers. See -** also restriction (6) in sqlite3ExprIsSingleTableConstraint(). +** Without this restriction, the WHERE-clause push-down optimization +** might move the ON/USING filter expression from the left side of a +** RIGHT JOIN over to the right side, which leads to incorrect answers. +** See also restriction (6) in sqlite3ExprIsSingleTableConstraint(). ** ** (10) The inner query is not the right-hand table of a RIGHT JOIN. ** @@ -7689,7 +7701,7 @@ int sqlite3Select( #endif assert( pItem->pSelect && (pItem->pSelect->selFlags & SF_PushDown)!=0 ); }else{ - TREETRACE(0x4000,pParse,p,("Push-down not possible\n")); + TREETRACE(0x4000,pParse,p,("WHERE-lcause push-down not possible\n")); } /* Convert unused result columns of the subquery into simple NULL diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 365ff2c7f5..d7e339d181 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -1906,7 +1906,7 @@ struct sqlite3 { #define SQLITE_CursorHints 0x00000400 /* Add OP_CursorHint opcodes */ #define SQLITE_Stat4 0x00000800 /* Use STAT4 data */ /* TH3 expects this value ^^^^^^^^^^ to be 0x0000800. Don't change it */ -#define SQLITE_PushDown 0x00001000 /* The push-down optimization */ +#define SQLITE_PushDown 0x00001000 /* WHERE-clause push-down opt */ #define SQLITE_SimplifyJoin 0x00002000 /* Convert LEFT JOIN to JOIN */ #define SQLITE_SkipScan 0x00004000 /* Skip-scans */ #define SQLITE_PropagateConst 0x00008000 /* The constant propagation opt */ @@ -3580,7 +3580,7 @@ struct Select { #define SF_View 0x0200000 /* SELECT statement is a view */ #define SF_NoopOrderBy 0x0400000 /* ORDER BY is ignored for this query */ #define SF_UFSrcCheck 0x0800000 /* Check pSrc as required by UPDATE...FROM */ -#define SF_PushDown 0x1000000 /* SELECT has be modified by push-down opt */ +#define SF_PushDown 0x1000000 /* Modified by WHERE-clause push-down opt */ #define SF_MultiPart 0x2000000 /* Has multiple incompatible PARTITIONs */ #define SF_CopyCte 0x4000000 /* SELECT statement is a copy of a CTE */ #define SF_OrderByReqd 0x8000000 /* The ORDER BY clause may not be omitted */ diff --git a/src/wherecode.c b/src/wherecode.c index 47ce36ce38..1f9c84f008 100644 --- a/src/wherecode.c +++ b/src/wherecode.c @@ -2474,6 +2474,12 @@ Bitmask sqlite3WhereCodeOneLoopStart( ** iLoop==3: Code all remaining expressions. ** ** An effort is made to skip unnecessary iterations of the loop. + ** + ** This optimization of causing simple query restrictions to occur before + ** more complex one is call the "push-down" optimization in MySQL. Here + ** in SQLite, the name is "MySQL push-down", since there is also another + ** totally unrelated optimization called "WHERE-clause push-down". + ** Sometimes the qualifier is omitted, resulting in an ambiguity, so beware. */ iLoop = (pIdx ? 1 : 2); do{ diff --git a/test/pushdown.test b/test/pushdown.test index 1fbe6f34cd..ac46eee8a8 100644 --- a/test/pushdown.test +++ b/test/pushdown.test @@ -1,4 +1,4 @@ -# 2017 April 29 +# 2017-04-29 # # The author disclaims copyright to this source code. In place of # a legal notice, here is a blessing: @@ -8,6 +8,26 @@ # May you share freely, never taking more than you give. # #*********************************************************************** +# +# Test cases for the push-down optimizations. +# +# +# There are two different meanings for "push-down optimization". +# +# (1) "MySQL push-down" means that WHERE clause terms that can be +# evaluated using only the index and without reference to the +# table are run first, so that if they are false, unnecessary table +# seeks are avoided. See https://sqlite.org/src/info/d7bb79ed3a40419d +# from 2017-04-29. +# +# (2) "WHERE-clause pushdown" means to push WHERE clause terms in +# outer queries down into subqueries. See +# https://sqlite.org/src/info/6df18e949d367629 from 2015-06-02. +# +# This module started out as tests for MySQL push-down only. But because +# of naming ambiguity, it has picked up test cases for WHERE-clause push-down +# over the years. +# set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -87,8 +107,8 @@ do_test 2.2 { } {three} # 2022-11-25 dbsqlfuzz crash-3a548de406a50e896c1bf7142692d35d339d697f -# Disable the push-down optimization for compound subqueries if any -# arm of the compound has an incompatible affinity. +# Disable the WHERE-clause push-down optimization for compound subqueries +# if any arm of the compound has an incompatible affinity. # reset_db do_execsql_test 3.1 { @@ -185,7 +205,7 @@ do_eqp_test 3.8 { # SELECT (SELECT count(*) FROM t1)+(SELECT count(*) FROM t2) # 2023-05-09 https://sqlite.org/forum/forumpost/a7d4be7fb6 -# Restriction (9) on the push-down optimization. +# Restriction (9) on the WHERE-clause push-down optimization. # reset_db db null - From 1152def76ecc8bfb95a51562b6bad949471f6863 Mon Sep 17 00:00:00 2001 From: drh <> Date: Sun, 7 Apr 2024 18:23:30 +0000 Subject: [PATCH 309/430] If SQLITE_ALLOW_ROWID_IN_VIEW is set to 2, then all rowids for views return a value of NULL. FossilOrigin-Name: 0a53dde21403aa6de11c5085c16def3f95046c5629daf2675b075e4d6683ef94 --- manifest | 13 ++++++------- manifest.uuid | 2 +- src/resolve.c | 5 +++++ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 64b52c9b24..b806287450 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\scomments\sto\snote\sthe\sname\sabiguity\sbetween\sthe\sMySQL\spush-down\noptimization\sand\sthe\sWHERE-clause\spush-down\soptimization. -D 2024-04-07T10:27:18.165 +C If\sSQLITE_ALLOW_ROWID_IN_VIEW\sis\sset\sto\s2,\sthen\sall\srowids\sfor\sviews\sreturn\na\svalue\sof\sNULL. +D 2024-04-07T18:23:30.116 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -748,7 +748,7 @@ F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7 F src/prepare.c 371f6115cb69286ebc12c6f2d7511279c2e47d9f54f475d46a554d687a3b312c F src/printf.c 87b67bba3662a0523f39ae6b084a3907109702f717c654d6cecb838af5cd57f1 F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c -F src/resolve.c eb1860b134fb044fd819c4347105c148d5aac7c6498032be2829e5cc95619b28 +F src/resolve.c 42d5d75a6ccfaf5b17d81fca64203ebce87f59702089142feed90df28dec1203 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c 3c8e1b921edfb71904b01c1ef9fb378224cdba71543342b164c7718cc8e82a44 F src/shell.c.in 0354ca51eee5fbf6af394a7ef9f5ef6823ef45b743db65431f6777e4d5be2199 @@ -2184,9 +2184,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P c6e873d4db3ef36a0d561e64ead6feada5d1654c0757b4b6e55f671c9db66469 -Q +681dfe2dd60714daf4987d45231d877f389825ab93e9bd0749391230186d6091 -R 023f47c11f43b462b0bef8a0994a0c0a +P 3d5fb1ec7a0440072d6e3b957903c85d0f32b8b07207a1ef22d1a69cf5e664d1 +R 0db0e0612520e2d37c806507a6db9dae U drh -Z 5c41a9ea676fc6eeb1fc7c2dc29fd70c +Z 2bafcb904067739b9429bfd86a29a830 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 1888e324a6..2f2bda0775 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -3d5fb1ec7a0440072d6e3b957903c85d0f32b8b07207a1ef22d1a69cf5e664d1 \ No newline at end of file +0a53dde21403aa6de11c5085c16def3f95046c5629daf2675b075e4d6683ef94 \ No newline at end of file diff --git a/src/resolve.c b/src/resolve.c index 6e0c9906a6..86532db154 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -632,6 +632,11 @@ static int lookupName( && ALWAYS(VisibleRowid(pMatch->pTab) || pMatch->fg.isNestedFrom) ){ cnt = cntTab; +#if SQLITE_ALLOW_ROWID_IN_VIEW+0==2 + if( pMatch->pTab!=0 && IsView(pMatch->pTab) ){ + eNewExprOp = TK_NULL; + } +#endif if( pMatch->fg.isNestedFrom==0 ) pExpr->iColumn = -1; pExpr->affExpr = SQLITE_AFF_INTEGER; } From fa4c4247a573b0f8f5875fba23b1c5a19562c44e Mon Sep 17 00:00:00 2001 From: drh <> Date: Sun, 7 Apr 2024 18:36:32 +0000 Subject: [PATCH 310/430] Omit all rowid-in-view restrictions from the fuzzinvariant.c test module as they are no longer necessary, as of the previous check-in. FossilOrigin-Name: 6431538f0bb3bb8606786f3c3e5c055c4bc387098dd3bdc8a94f6fda61c47f52 --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/fuzzinvariants.c | 38 -------------------------------------- 3 files changed, 7 insertions(+), 45 deletions(-) diff --git a/manifest b/manifest index b806287450..c4e5160b20 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C If\sSQLITE_ALLOW_ROWID_IN_VIEW\sis\sset\sto\s2,\sthen\sall\srowids\sfor\sviews\sreturn\na\svalue\sof\sNULL. -D 2024-04-07T18:23:30.116 +C Omit\sall\srowid-in-view\srestrictions\sfrom\sthe\sfuzzinvariant.c\stest\smodule\nas\sthey\sare\sno\slonger\snecessary,\sas\sof\sthe\sprevious\scheck-in. +D 2024-04-07T18:36:32.081 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -1258,7 +1258,7 @@ F test/fuzzdata8.db 4a53b6d077c6a5c23b609d8d3ac66996fa55ba3f8d02f9b6efdd0214a767 F test/fuzzer1.test 3d4c4b7e547aba5e5511a2991e3e3d07166cfbb8 F test/fuzzer2.test a85ef814ce071293bce1ad8dffa217cbbaad4c14 F test/fuzzerfault.test f64c4aef4c9e9edf1d6dc0d3f1e65dcc81e67c996403c88d14f09b74807a42bc -F test/fuzzinvariants.c 9fc6810dde21e1aee20ed7a6c8ed944ffee127cf082fc48caba398fa31c762ca +F test/fuzzinvariants.c d89b81c3bdad7b2837f8cce645d5b563ffa965f6d819ce33f0f6d82a71c6ca9a F test/gcfault.test 4ea410ac161e685f17b19e1f606f58514a2850e806c65b846d05f60d436c5b0d F test/gencol1.test e169bdfa11c7ed5e9f322a98a7db3afe9e66235750b68c923efee8e1876b46ec F test/genesis.tcl 1e2e2e8e5cc4058549a154ff1892fe5c9de19f98 @@ -2184,8 +2184,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 3d5fb1ec7a0440072d6e3b957903c85d0f32b8b07207a1ef22d1a69cf5e664d1 -R 0db0e0612520e2d37c806507a6db9dae +P 0a53dde21403aa6de11c5085c16def3f95046c5629daf2675b075e4d6683ef94 +R 950039d72c57e0f5f8da3387d03515aa U drh -Z 2bafcb904067739b9429bfd86a29a830 +Z decff099e336dbab63d6324042d80ad4 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 2f2bda0775..e1d7770bd6 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0a53dde21403aa6de11c5085c16def3f95046c5629daf2675b075e4d6683ef94 \ No newline at end of file +6431538f0bb3bb8606786f3c3e5c055c4bc387098dd3bdc8a94f6fda61c47f52 \ No newline at end of file diff --git a/test/fuzzinvariants.c b/test/fuzzinvariants.c index 25b35d4f6b..66475270b0 100644 --- a/test/fuzzinvariants.c +++ b/test/fuzzinvariants.c @@ -223,19 +223,6 @@ int fuzz_invariant( return SQLITE_OK; } -#ifdef SQLITE_ALLOW_ROWID_IN_VIEW -/* -** Return TRUE if the i-th column of pStmt might be a ROWID value. -*/ -static int column_might_be_rowid(sqlite3_stmt *pStmt, int i){ - const char *zColName = sqlite3_column_name(pStmt, i); - if( sqlite3_strlike("%rowid%",zColName,0)==0 ) return 1; - if( sqlite3_strlike("%oid%",zColName,0)==0 ) return 1; - return 0; -} -#endif /* SQLITE_ALLOW_ROWID_IN_VIEW */ - - /* ** Generate SQL used to test a statement invariant. ** @@ -308,12 +295,6 @@ static char *fuzz_invariant_sql(sqlite3_stmt *pStmt, int iCnt){ ** WHERE clause. */ continue; } -#ifdef SQLITE_ALLOW_ROWID_IN_VIEW - if( column_might_be_rowid(pBase,i) ){ - /* ROWID values are unreliable if SQLITE_ALLOW_ROWID_IN_VIEW is used */ - continue; - } -#endif for(j=0; j Date: Mon, 8 Apr 2024 06:37:19 +0000 Subject: [PATCH 311/430] Enhancements to the fuzzer invariant checker to turn optimizations on and off. FossilOrigin-Name: 67594481379824823105939fea2ce1fe280667f6db91735ac78b4b6164a78dab --- manifest | 14 +++++++------- manifest.uuid | 2 +- test/fuzzcheck.c | 16 +++++++++++----- test/fuzzinvariants.c | 30 ++++++++++++++++++++++++------ 4 files changed, 43 insertions(+), 19 deletions(-) diff --git a/manifest b/manifest index 9489e7d05e..f59889aa63 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Merge\strunk\stesting\senhancements\sinto\sthe\spushdown-subquery\sbranch. -D 2024-04-07T18:55:57.788 +C Enhancements\sto\sthe\sfuzzer\sinvariant\schecker\sto\sturn\soptimizations\son\sand\noff. +D 2024-04-08T06:37:19.669 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -1246,7 +1246,7 @@ F test/fuzz3.test 9c813e6613b837cb7a277b0383cd66bfa07042b4cf0317157c35852f30043c F test/fuzz4.test c229bcdb45518a89e1d208a21343e061503460ac69fae1539320a89f572eb634 F test/fuzz_common.tcl b7197de6ed1ee8250a4f82d67876f4561b42ee8cbbfc6160dcb66331bad3f830 F test/fuzz_malloc.test f348276e732e814802e39f042b1f6da6362a610af73a528d8f76898fde6b22f2 -F test/fuzzcheck.c e6a40f53ac5624aa5b7c4f31c385f09ba088d524cecc4512fd3057caeed8f530 +F test/fuzzcheck.c dc159967609d00b0cfe619e735cbbf8482570aca85711397034b0662b6c18fc7 F test/fuzzdata1.db 3e86d9cf5aea68ddb8e27c02d7dfdaa226347426c7eb814918e4d95475bf8517 F test/fuzzdata2.db 128b3feeb78918d075c9b14b48610145a0dd4c8d6f1ca7c2870c7e425f5bf31f F test/fuzzdata3.db c6586d3e3cef0fbc18108f9bb649aa77bfc38aba @@ -1258,7 +1258,7 @@ F test/fuzzdata8.db 4a53b6d077c6a5c23b609d8d3ac66996fa55ba3f8d02f9b6efdd0214a767 F test/fuzzer1.test 3d4c4b7e547aba5e5511a2991e3e3d07166cfbb8 F test/fuzzer2.test a85ef814ce071293bce1ad8dffa217cbbaad4c14 F test/fuzzerfault.test f64c4aef4c9e9edf1d6dc0d3f1e65dcc81e67c996403c88d14f09b74807a42bc -F test/fuzzinvariants.c d89b81c3bdad7b2837f8cce645d5b563ffa965f6d819ce33f0f6d82a71c6ca9a +F test/fuzzinvariants.c 0729b9d8ed77ad0f8c5c7601168a707d5803087d2da030ede9057c51c809cc6c F test/gcfault.test 4ea410ac161e685f17b19e1f606f58514a2850e806c65b846d05f60d436c5b0d F test/gencol1.test e169bdfa11c7ed5e9f322a98a7db3afe9e66235750b68c923efee8e1876b46ec F test/genesis.tcl 1e2e2e8e5cc4058549a154ff1892fe5c9de19f98 @@ -2184,8 +2184,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 27865e316f8dfbf4c20290cf1be3024d7518fec46655e34f3fc435e15346c63e 6431538f0bb3bb8606786f3c3e5c055c4bc387098dd3bdc8a94f6fda61c47f52 -R a6f74894c0cda8635456b45fc1556948 +P 287ff24b26a512ff7648679767e68244f6eef95df6a49c46ed1f2594030ed523 +R f668a18b739f9caf1d0ed3baa3bf6c8f U drh -Z d0677700c03f1b93b120f5cc4adf200f +Z 70cb6868aa0f914c12631462fc26d140 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index c911a505d2..30cfd87b8f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -287ff24b26a512ff7648679767e68244f6eef95df6a49c46ed1f2594030ed523 \ No newline at end of file +67594481379824823105939fea2ce1fe280667f6db91735ac78b4b6164a78dab \ No newline at end of file diff --git a/test/fuzzcheck.c b/test/fuzzcheck.c index e4ad1c1137..6cae348bd6 100644 --- a/test/fuzzcheck.c +++ b/test/fuzzcheck.c @@ -979,7 +979,8 @@ extern int fuzz_invariant( int iRow, /* The row number for pStmt */ int nRow, /* Total number of output rows */ int *pbCorrupt, /* IN/OUT: Flag indicating a corrupt database file */ - int eVerbosity /* How much debugging output */ + int eVerbosity, /* How much debugging output */ + unsigned int dbOpt /* Default optimization flags */ ); /* Implementation of sqlite_dbdata and sqlite_dbptr */ @@ -1031,7 +1032,12 @@ static int recoverDatabase(sqlite3 *db){ /* ** Run the SQL text */ -static int runDbSql(sqlite3 *db, const char *zSql, unsigned int *pBtsFlags){ +static int runDbSql( + sqlite3 *db, /* Run SQL on this database connection */ + const char *zSql, /* The SQL to be run */ + unsigned int *pBtsFlags, + unsigned int dbOpt /* Default optimization flags */ +){ int rc; sqlite3_stmt *pStmt; int bCorrupt = 0; @@ -1107,7 +1113,7 @@ static int runDbSql(sqlite3 *db, const char *zSql, unsigned int *pBtsFlags){ iRow++; for(iCnt=0; iCnt<99999; iCnt++){ rc = fuzz_invariant(db, pStmt, iCnt, iRow, nRow, - &bCorrupt, eVerbosity); + &bCorrupt, eVerbosity, dbOpt); if( rc==SQLITE_DONE ) break; if( rc!=SQLITE_ERROR ) g.nInvariant++; if( eVerbosity>0 ){ @@ -1330,7 +1336,7 @@ int runCombinedDbSqlInput( char cSaved = zSql[i+1]; zSql[i+1] = 0; if( sqlite3_complete(zSql+j) ){ - rc = runDbSql(cx.db, zSql+j, &btsFlags); + rc = runDbSql(cx.db, zSql+j, &btsFlags, dbOpt); j = i+1; } zSql[i+1] = cSaved; @@ -1340,7 +1346,7 @@ int runCombinedDbSqlInput( } } if( j100 ) return SQLITE_DONE; zTest = fuzz_invariant_sql(pStmt, iCnt); if( zTest==0 ) return SQLITE_DONE; + if( noOpt ){ + sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS, db, ~dbOpt); + } rc = sqlite3_prepare_v2(db, zTest, -1, &pTestStmt, 0); + if( noOpt ){ + sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS, db, dbOpt); + } if( rc ){ if( eVerbosity ){ printf("invariant compile failed: %s\n%s\n", @@ -212,7 +226,7 @@ int fuzz_invariant( } sqlite3_finalize(pCk); if( rc==SQLITE_DONE ){ - reportInvariantFailed(pStmt, pTestStmt, iRow); + reportInvariantFailed(pStmt, pTestStmt, iRow, dbOpt, noOpt); return SQLITE_INTERNAL; }else if( eVerbosity>0 ){ printf("invariant-error ignored due to the use of virtual tables\n"); @@ -488,13 +502,17 @@ static void printRow(sqlite3_stmt *pStmt, int iRow){ static void reportInvariantFailed( sqlite3_stmt *pOrig, /* The original query */ sqlite3_stmt *pTest, /* The alternative test query with a missing row */ - int iRow /* Row number in pOrig */ + int iRow, /* Row number in pOrig */ + unsigned int dbOpt, /* Optimization flags on pOrig */ + int noOpt /* True if opt flags inverted for pTest */ ){ int iTestRow = 0; printf("Invariant check failed on row %d.\n", iRow); - printf("Original query --------------------------------------------------\n"); + printf("Original query (opt-flags: 0x%08x) --------------------------\n", + dbOpt); printf("%s\n", sqlite3_expanded_sql(pOrig)); - printf("Alternative query -----------------------------------------------\n"); + printf("Alternative query (opt-flags: 0x%08x) -----------------------\n", + noOpt ? ~dbOpt : dbOpt); printf("%s\n", sqlite3_expanded_sql(pTest)); printf("Result row that is missing from the alternative -----------------\n"); printRow(pOrig, iRow); From 0389d5f8d0838c4b7eb415d6ce515a07aeb958d1 Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 8 Apr 2024 11:45:15 +0000 Subject: [PATCH 312/430] Fix a harmless compiler warning in the ICU extension due to [acddbc489d5231da]. FossilOrigin-Name: 3d8750e88558f8ea6a1523a5add4ccca3262e31f348b603e56ab193d81908995 --- ext/icu/icu.c | 2 +- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ext/icu/icu.c b/ext/icu/icu.c index f9d9eef905..69867bfa83 100644 --- a/ext/icu/icu.c +++ b/ext/icu/icu.c @@ -499,7 +499,7 @@ static void icuLoadCollation( { "QUARTERNARY", UCOL_QUATERNARY }, { "IDENTICAL", UCOL_IDENTICAL }, }; - int i; + unsigned int i; for(i=0; i Date: Mon, 8 Apr 2024 17:55:15 +0000 Subject: [PATCH 313/430] Update tests in returning1.test to account for [c7896e88]. FossilOrigin-Name: c02956cd5cbf87027ba201b5d273e0efd429836ee6cabdc2f6d5b8096c876b7b --- manifest | 15 +++++++-------- manifest.uuid | 2 +- test/returning1.test | 10 +++++----- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/manifest b/manifest index 739651c910..9dfb5b4e7d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Enhance\sthe\sWHERE-clause\spush-down\soptimization\sso\sthat\sit\sis\sable\sto\npush\sdown\sWHERE\sclause\sterms\sthat\scontain\suncorrelated\ssubqueries. -D 2024-04-08T11:50:07.908 +C Update\stests\sin\sreturning1.test\sto\saccount\sfor\s[c7896e88]. +D 2024-04-08T17:55:15.936 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -1529,7 +1529,7 @@ F test/regexp2.test 55ed41da802b0e284ac7e2fe944be3948f93ff25abbca0361a609acfed13 F test/reindex.test cd9d6021729910ece82267b4f5e1b5ac2911a7566c43b43c176a6a4732e2118d F test/resetdb.test 54c06f18bc832ac6d6319e5ab23d5c8dd49fdbeec7c696d791682a8006bd5fc3 F test/resolver01.test f4022acafda7f4d40eca94dbf16bc5fc4ac30ceb -F test/returning1.test 3ead782eddf51f573cdd43bcbb10d1b485ac095a19a76d16c43fd159ea9b7466 +F test/returning1.test b27646c5e25431dd47cf72f525d1b2d5ad4ae14e21d9cf3d65769f05e48f64f3 F test/returningfault.test ae4c4b5e8745813287a359d9ccdb9d5c883c2e68afb18fb0767937d5de5692a4 F test/rollback.test 06680159bc6746d0f26276e339e3ae2f951c64812468308838e0a3362d911eaa F test/rollback2.test 3f3a4e20401825017df7e7671e9f31b6de5fae5620c2b9b49917f52f8c160a8f @@ -2184,9 +2184,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 3d8750e88558f8ea6a1523a5add4ccca3262e31f348b603e56ab193d81908995 67594481379824823105939fea2ce1fe280667f6db91735ac78b4b6164a78dab -R 1ffe1af0415e1a4fed09276e65c27d2f -T +closed 67594481379824823105939fea2ce1fe280667f6db91735ac78b4b6164a78dab -U drh -Z a907cc2f6ecf59760a4baca00ef3db65 +P 69ec714b2d698acf9e37635256c01b233ce32f22e8323e226441d5ddd948a940 +R 02f4dab5c53b9393812ce64cd20da4c4 +U dan +Z d5b97b3de9d6c5aa7782c9d7a19a211c # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 35e356a937..df4e321c0c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -69ec714b2d698acf9e37635256c01b233ce32f22e8323e226441d5ddd948a940 \ No newline at end of file +c02956cd5cbf87027ba201b5d273e0efd429836ee6cabdc2f6d5b8096c876b7b \ No newline at end of file diff --git a/test/returning1.test b/test/returning1.test index 24032496ce..02743b2bdc 100644 --- a/test/returning1.test +++ b/test/returning1.test @@ -227,21 +227,21 @@ ifcapable !allow_rowid_in_view { } else { # Note: The values returned by the RETURNING clauses of the following # two statements are the rowid columns of views. These values are not - # well defined, so the INSERT returns -1, and the UPDATE returns 1, 2 - # and 3. These match the values used for new.rowid expressions, but - # not much else. + # well defined, so the INSERT returns -1, and the UPDATE returns NULL. + # These match the values used for new.rowid expressions, but not much + # else. do_catchsql_test 10.3a { INSERT INTO t1(a, b) VALUES(1234, 5678) RETURNING rowid; } {0 -1} do_catchsql_test 10.3b { UPDATE t1 SET a='z' WHERE b='y' RETURNING rowid; - } {0 {1 2 3}} + } {0 {{} {} {}}} do_execsql_test 10.4 { SELECT * FROM log; } { - insert -1 1234 5678 update 1 z y update 2 z y update 3 z y + insert -1 1234 5678 update {} z y update {} z y update {} z y } } From d21d5b21db209597aeaf41d0394cf70ddd62235d Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 9 Apr 2024 13:57:27 +0000 Subject: [PATCH 314/430] The read-only CHECK-constraint optimization of [34ddf02d3d21151b] inhibits the xfer optimization for tables with CHECK constraints. However, the xfer optimization is required for correct operation of VACUUM INTO on tables that contain generated columns. Fix this by ignoring CHECK constraints when qualifying the xfer optimization while running VACUUM. Problem reported by [forum:/forumpost/3ec177d68fe7fa2c|forum post 3ec177d68fe7fa2c]. FossilOrigin-Name: a6e26e778812c8409fca77183e24d3b70189c4d02fce10c7e74cd4ccc8c8ea97 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/insert.c | 5 ++++- test/vacuum-into.test | 35 ++++++++++++++++++++++++++++++++++- 4 files changed, 47 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 9dfb5b4e7d..8197099293 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Update\stests\sin\sreturning1.test\sto\saccount\sfor\s[c7896e88]. -D 2024-04-08T17:55:15.936 +C The\sread-only\sCHECK-constraint\soptimization\sof\s[34ddf02d3d21151b]\sinhibits\sthe\nxfer\soptimization\sfor\stables\swith\sCHECK\sconstraints.\s\sHowever,\sthe\sxfer\noptimization\sis\srequired\sfor\scorrect\soperation\sof\sVACUUM\sINTO\son\stables\sthat\ncontain\sgenerated\scolumns.\sFix\sthis\sby\signoring\sCHECK\sconstraints\swhen\nqualifying\sthe\sxfer\soptimization\swhile\srunning\sVACUUM.\s\sProblem\sreported\sby\n[forum:/forumpost/3ec177d68fe7fa2c|forum\spost\s3ec177d68fe7fa2c]. +D 2024-04-09T13:57:27.143 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -709,7 +709,7 @@ F src/hash.c 9ee4269fb1d6632a6fecfb9479c93a1f29271bddbbaf215dd60420bcb80c7220 F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 -F src/insert.c bc4d172b52a6167cd28797397a464c2cca9607dc047dfa0b5cf61687962e6964 +F src/insert.c 4bd7c7e54a1062dcd0214b7a6296f7194eb10fb14d3ddca1ed20b01c2a86a18c F src/json.c e2e40760d6689134c3e2ece38c6a496b34ff5e2661a8f238444a119af666fdce F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 @@ -1916,7 +1916,7 @@ F test/uri.test c1abaaaa28e9422d61e5f3f9cbc8ef993ec49fe802f581520731708561d49384 F test/uri2.test 9d3ba7a53ee167572d53a298ee4a5d38ec4a8fb7 F test/userauth01.test e740a2697a7b40d7c5003a7d7edaee16acd349a9 F test/utf16align.test 9fde0bb5d3a821594aa68c6829ab9c5453a084384137ebb9f6153e2d678039da -F test/vacuum-into.test 35dc6f79b563f91c61822f61797363e97fed1bf28f1f722688b98d43f1980d76 +F test/vacuum-into.test 77845cee98770c416dae9b0da6bb3229753861f2da65c11b4f9715d081712d8a F test/vacuum.test ce91c39f7f91a4273bf620efad21086b5aa6ef1d F test/vacuum2.test 9fd45ce6ce29f5614c249e03938d3567c06a9e772d4f155949f8eafe2d8af520 F test/vacuum3.test d9d9a04ee58c485b94694fd4f68cffaba49c32234fdefe1ac1a622c5e17d4ce3 @@ -2184,8 +2184,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 69ec714b2d698acf9e37635256c01b233ce32f22e8323e226441d5ddd948a940 -R 02f4dab5c53b9393812ce64cd20da4c4 -U dan -Z d5b97b3de9d6c5aa7782c9d7a19a211c +P c02956cd5cbf87027ba201b5d273e0efd429836ee6cabdc2f6d5b8096c876b7b +R 14ee2c4095f13f5f59e64d6dfae705ab +U drh +Z 40f988c61dc13a84e5a7ab5ecd628e6c # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index df4e321c0c..3f94593291 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c02956cd5cbf87027ba201b5d273e0efd429836ee6cabdc2f6d5b8096c876b7b \ No newline at end of file +a6e26e778812c8409fca77183e24d3b70189c4d02fce10c7e74cd4ccc8c8ea97 \ No newline at end of file diff --git a/src/insert.c b/src/insert.c index c126a83952..072386e656 100644 --- a/src/insert.c +++ b/src/insert.c @@ -3182,7 +3182,10 @@ static int xferOptimization( } } #ifndef SQLITE_OMIT_CHECK - if( pDest->pCheck && sqlite3ExprListCompare(pSrc->pCheck,pDest->pCheck,-1) ){ + if( pDest->pCheck + && (db->mDbFlags & DBFLAG_Vacuum)==0 + && sqlite3ExprListCompare(pSrc->pCheck,pDest->pCheck,-1) + ){ return 0; /* Tables have different CHECK constraints. Ticket #2252 */ } #endif diff --git a/test/vacuum-into.test b/test/vacuum-into.test index 698d65f540..d559b7fb39 100644 --- a/test/vacuum-into.test +++ b/test/vacuum-into.test @@ -26,13 +26,36 @@ ifcapable {!vacuum} { forcedelete out.db do_execsql_test vacuum-into-100 { - CREATE TABLE t1(a INTEGER PRIMARY KEY, b); + CREATE TABLE t1( + a INTEGER PRIMARY KEY, + b ANY, + c INT AS (b+1), --- See "2024-04-09" block + CHECK( typeof(b)!='integer' OR b>a-5 ) --- comment below + ); WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<100) INSERT INTO t1(a,b) SELECT x, randomblob(600) FROM c; CREATE INDEX t1b ON t1(b); DELETE FROM t1 WHERE a%2; SELECT count(*), sum(a), sum(length(b)) FROM t1; } {50 2550 30000} + +# Update 2024-04-09 for forum post eec177d68fe7fa2c. +# +# VACUUM INTO is sensitive to tables holding both generated columns +# and CHECK constraints. +# +# CHECK constraints are ignored for read-only databases in order to save +# memory (see check-in 34ddf02d3d21151b on 2014-05-21). But the xfer +# optimization normally only works if CHECK constraints match between the +# source and destination tables. So the xfer optimization was not +# working for VACUUM INTO when the source was a read-only database and the +# table held CHECK constraints. But if the table has generated columns, +# then the xfer optimization is required or else VACUUM will raise an +# error. +# +# Fix this by ignoring CHECK constraints when determining whether or not +# the xfer optimization can run while doing VACUUM. + do_execsql_test vacuum-into-110 { VACUUM main INTO 'out.db'; } {} @@ -88,11 +111,21 @@ do_catchsql_test vacuum-into-420 { # The ability to VACUUM INTO a read-only database db close +if {$tcl_platform(platform)=="windows"} { + file attributes test.db -readonly 1 +} else { + file attributes test.db -permissions 292 ;# 292 == 0444 +} sqlite3 db test.db -readonly 1 forcedelete test.db2 do_execsql_test vacuum-into-500 { VACUUM INTO 'test.db2'; } +if {$tcl_platform(platform)=="windows"} { + file attributes test.db -readonly 0 +} else { + file attributes test.db -permissions 420 ;# 420 = 0644 +} sqlite3 db2 test.db2 do_test vacuum-into-510 { db2 eval {SELECT name FROM sqlite_master ORDER BY 1} From 73a50fa42cbc2ddd1bf9e795a1407c3c746896e9 Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 9 Apr 2024 15:09:54 +0000 Subject: [PATCH 315/430] Avoid some performance problems in the recover extension when recovering strategically corrupted databases. FossilOrigin-Name: e66a834bbab9d71e02b70588ad4c71eae2e13b50e299b0269d488402bc4a7fc5 --- ext/recover/dbdata.c | 24 +++++++++++++++++++----- ext/recover/recovercorrupt2.test | 28 ++++++++++++++++++++++++++++ ext/recover/sqlite3recover.c | 2 +- manifest | 18 +++++++++--------- manifest.uuid | 2 +- 5 files changed, 58 insertions(+), 16 deletions(-) diff --git a/ext/recover/dbdata.c b/ext/recover/dbdata.c index b6cb26ecd3..ca6371026e 100644 --- a/ext/recover/dbdata.c +++ b/ext/recover/dbdata.c @@ -494,6 +494,15 @@ static void dbdataValue( } } +/* This macro is a copy of the MX_CELL() macro in the SQLite core. Given +** a page-size, it returns the maximum number of cells that may be present +** on the page. */ +#define DBDATA_MX_CELL(pgsz) ((pgsz-8)/6) + +/* Maximum number of fields that may appear in a single record. This is +** the "hard-limit", according to comments in sqliteLimit.h. */ +#define DBDATA_MX_FIELD 32676 + /* ** Move an sqlite_dbdata or sqlite_dbptr cursor to the next entry. */ @@ -522,6 +531,9 @@ static int dbdataNext(sqlite3_vtab_cursor *pCursor){ assert( iOff+3+2<=pCsr->nPage ); pCsr->iCell = pTab->bPtr ? -2 : 0; pCsr->nCell = get_uint16(&pCsr->aPage[iOff+3]); + if( pCsr->nCell>DBDATA_MX_CELL(pCsr->nPage) ){ + pCsr->nCell = DBDATA_MX_CELL(pCsr->nPage); + } } if( pTab->bPtr ){ @@ -566,19 +578,19 @@ static int dbdataNext(sqlite3_vtab_cursor *pCursor){ if( pCsr->iCell>=pCsr->nCell ){ bNextPage = 1; }else{ + int iCellPtr = iOff + 8 + nPointer + pCsr->iCell*2; - iOff += 8 + nPointer + pCsr->iCell*2; - if( iOff>pCsr->nPage ){ + if( iCellPtr>pCsr->nPage ){ bNextPage = 1; }else{ - iOff = get_uint16(&pCsr->aPage[iOff]); + iOff = get_uint16(&pCsr->aPage[iCellPtr]); } /* For an interior node cell, skip past the child-page number */ iOff += nPointer; /* Load the "byte of payload including overflow" field */ - if( bNextPage || iOff>pCsr->nPage ){ + if( bNextPage || iOff>pCsr->nPage || iOff<=iCellPtr ){ bNextPage = 1; }else{ iOff += dbdataGetVarintU32(&pCsr->aPage[iOff], &nPayload); @@ -661,7 +673,9 @@ static int dbdataNext(sqlite3_vtab_cursor *pCursor){ pCsr->iField++; if( pCsr->iField>0 ){ sqlite3_int64 iType; - if( pCsr->pHdrPtr>&pCsr->pRec[pCsr->nRec] ){ + if( pCsr->pHdrPtr>=&pCsr->pRec[pCsr->nRec] + || pCsr->iField>=DBDATA_MX_FIELD + ){ bNextPage = 1; }else{ int szField = 0; diff --git a/ext/recover/recovercorrupt2.test b/ext/recover/recovercorrupt2.test index 29acc27a35..6c216308f0 100644 --- a/ext/recover/recovercorrupt2.test +++ b/ext/recover/recovercorrupt2.test @@ -524,5 +524,33 @@ do_test 7.1 { list [catch { $R finish } msg] $msg } {1 {file is not a database}} +reset_db +breakpoint +do_test 8.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +| size 8192 pagesize 4096 filename db.sqlite +| page 1 offset 0 +| 0: ac ae b3 76 74 65 20 66 6f 72 6d 61 74 20 33 00 ...vte format 3. +| 16: 10 00 01 01 00 40 20 20 00 00 00 01 00 00 00 02 .....@ ........ +| 32: 00 00 00 00 00 00 00 00 00 00 00 01 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 01 ................ +| 96: 00 2e 76 8a 0d ff ff ff 1e 0f cb 00 0f cb 00 00 ..v............. +| 4032: 00 00 00 00 00 00 00 00 00 00 00 33 01 06 17 19 ...........3.... +| 4048: 19 01 43 74 61 62 6c 65 54 61 62 6c 65 30 54 61 ..CtableTable0Ta +| 4064: 62 6c 65 30 02 43 52 45 41 54 45 20 54 41 42 4c ble0.CREATE TABL +| 4080: 45 20 54 61 62 6c 65 30 20 28 43 6f 6c 30 20 29 E Table0 (Col0 ) +| page 2 offset 4096 +| 0: 0d 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00 ................ +| end db.sqlite +}]} {} + +do_test 8.1 { + set R [sqlite3_recover_init db main test.db2] + catch { $R run } + list [catch { $R finish } msg] $msg +} {0 {}} + finish_test diff --git a/ext/recover/sqlite3recover.c b/ext/recover/sqlite3recover.c index c445c51793..1d858c0ab9 100644 --- a/ext/recover/sqlite3recover.c +++ b/ext/recover/sqlite3recover.c @@ -1189,7 +1189,7 @@ static int recoverWriteSchema1(sqlite3_recover *p){ if( bTable && !bVirtual ){ if( SQLITE_ROW==sqlite3_step(pTblname) ){ const char *zTbl = (const char*)sqlite3_column_text(pTblname, 0); - recoverAddTable(p, zTbl, iRoot); + if( zTbl ) recoverAddTable(p, zTbl, iRoot); } recoverReset(p, pTblname); } diff --git a/manifest b/manifest index 8197099293..0fa7d973a9 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C The\sread-only\sCHECK-constraint\soptimization\sof\s[34ddf02d3d21151b]\sinhibits\sthe\nxfer\soptimization\sfor\stables\swith\sCHECK\sconstraints.\s\sHowever,\sthe\sxfer\noptimization\sis\srequired\sfor\scorrect\soperation\sof\sVACUUM\sINTO\son\stables\sthat\ncontain\sgenerated\scolumns.\sFix\sthis\sby\signoring\sCHECK\sconstraints\swhen\nqualifying\sthe\sxfer\soptimization\swhile\srunning\sVACUUM.\s\sProblem\sreported\sby\n[forum:/forumpost/3ec177d68fe7fa2c|forum\spost\s3ec177d68fe7fa2c]. -D 2024-04-09T13:57:27.143 +C Avoid\ssome\sperformance\sproblems\sin\sthe\srecover\sextension\swhen\srecovering\sstrategically\scorrupted\sdatabases. +D 2024-04-09T15:09:54.458 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -478,13 +478,13 @@ F ext/rbu/rbuvacuum4.test ffccd22f67e2d0b380d2889685742159dfe0d19a3880ca3d2d1d69 F ext/rbu/sqlite3rbu.c 4a3376c0fb9a844a799ac529fb81260523f6b13c9f629bc270c632dbae5fc1f8 F ext/rbu/sqlite3rbu.h 9d923eb135c5d04aa6afd7c39ca47b0d1d0707c100e02f19fdde6a494e414304 F ext/rbu/test_rbu.c ee6ede75147bc081fe9bc3931e6b206277418d14d3fbceea6fdc6216d9b47055 -F ext/recover/dbdata.c b7746c2ec801b453840831311be4b31f8c8f9dd97791060a69bbf12392c78949 +F ext/recover/dbdata.c d2e00d3cac74319c9c6def2e56ab2146b4f4ba5d820ab275e8da24e9766c247e F ext/recover/recover1.test c484d01502239f11b61f23c1cee9f5dd19fa17617f8974e42e74d64639c524cf F ext/recover/recover_common.tcl a61306c1eb45c0c3fc45652c35b2d4ec19729e340bdf65a272ce4c229cefd85a F ext/recover/recoverbuild.test c74170e0f7b02456af41838afeb5353fdb985a48cc2331d661bbabbca7c6b8e3 F ext/recover/recoverclobber.test 3ba6c0c373c5c63d17e82eced64c05c57ccaf26c1abe1ca7141334022a79f32e F ext/recover/recovercorrupt.test 64c081ad1200ae77b447da99eb724785d6bf71715f394543dc7689642e92bf49 -F ext/recover/recovercorrupt2.test b9b974f006340a1300b5a7e687bd6097c5238498181c6f92d87406a77ece430b +F ext/recover/recovercorrupt2.test 1418f1710debc24ff38276cedfcea234beb37a34205708e7e3e6d76cc4a979db F ext/recover/recoverfault.test 9d9f88eeb222615a25e7514f234c950d46bee20d24cd8db49d8fff8d650dcfe1 F ext/recover/recoverfault2.test 730e7371bcda769554d15460cb23126abba1be8eca9539ccabf63623e7bb7e09 F ext/recover/recoverold.test 68db3d6f85dd2b98e785b6c4da4f5eea4bbe52ccf6674d9a94c7506dc92596aa @@ -492,7 +492,7 @@ F ext/recover/recoverpgsz.test 3658ab8e68475b1bb87d6af88baa04551c84b73280a566a1b F ext/recover/recoverrowid.test f948bf4024a5f41b0e21b8af80c60564c5b5d78c05a8d64fc00787715ff9f45f F ext/recover/recoverslowidx.test 5205a9742dd9490ee99950dabb622307355ef1662dea6a3a21030057bfd81411 F ext/recover/recoversql.test e66d01f95302a223bcd3fd42b5ee58dc2b53d70afa90b0d00e41e4b8eab20486 -F ext/recover/sqlite3recover.c e6eb20c469bcdb96f297f2241860bccabf9f036bfa7f3d47bcc6ca1191b108dc +F ext/recover/sqlite3recover.c 65ef0f56301a16c0536c9839fb7e23540c9c4f75da0afe3b7b4d163c8f624404 F ext/recover/sqlite3recover.h 011c799f02deb70ab685916f6f538e6bb32c4e0025e79bfd0e24ff9c74820959 F ext/recover/test_recover.c fd871a40f2238022bedcbdf3cb493b91225edaa94d6ae8892af97a10e7ccc4ba F ext/repair/README.md 92f5e8aae749a4dae14f02eea8e1bb42d4db2b6ce5e83dbcdd6b1446997e0c15 @@ -2184,8 +2184,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P c02956cd5cbf87027ba201b5d273e0efd429836ee6cabdc2f6d5b8096c876b7b -R 14ee2c4095f13f5f59e64d6dfae705ab -U drh -Z 40f988c61dc13a84e5a7ab5ecd628e6c +P a6e26e778812c8409fca77183e24d3b70189c4d02fce10c7e74cd4ccc8c8ea97 +R b9c21ffc9d4065568ea5ca672bfa94a1 +U dan +Z a2100870dc1c15edbdbfdff1cdb0d2d0 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 3f94593291..e73f4c80e2 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a6e26e778812c8409fca77183e24d3b70189c4d02fce10c7e74cd4ccc8c8ea97 \ No newline at end of file +e66a834bbab9d71e02b70588ad4c71eae2e13b50e299b0269d488402bc4a7fc5 \ No newline at end of file From 495ce22d49a8be9df2753b1ab33b354be2066a20 Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 9 Apr 2024 19:23:18 +0000 Subject: [PATCH 316/430] Fix a "shift exponent is too large" usan error that could occur in the fts3 snippet() function when a query phrase contains more than 64 tokens. FossilOrigin-Name: 6d2c7ac4ecfc1ec408cb1820985a70650d7cc5613b4b8fd1829f68ea48fce6a3 --- ext/fts3/fts3_snippet.c | 2 +- manifest | 14 +++++++------- manifest.uuid | 2 +- test/fts3snippet2.test | 11 +++++++++++ 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/ext/fts3/fts3_snippet.c b/ext/fts3/fts3_snippet.c index 227c5f00f6..f6caabf4c9 100644 --- a/ext/fts3/fts3_snippet.c +++ b/ext/fts3/fts3_snippet.c @@ -446,7 +446,7 @@ static void fts3SnippetDetails( } mCover |= mPhrase; - for(j=0; jnToken; j++){ + for(j=0; jnToken && jnSnippet; j++){ mHighlight |= (mPos>>j); } diff --git a/manifest b/manifest index 0fa7d973a9..764ffbd97a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Avoid\ssome\sperformance\sproblems\sin\sthe\srecover\sextension\swhen\srecovering\sstrategically\scorrupted\sdatabases. -D 2024-04-09T15:09:54.458 +C Fix\sa\s"shift\sexponent\sis\stoo\slarge"\susan\serror\sthat\scould\soccur\sin\sthe\sfts3\ssnippet()\sfunction\swhen\sa\squery\sphrase\scontains\smore\sthan\s64\stokens. +D 2024-04-09T19:23:18.637 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -74,7 +74,7 @@ F ext/fts3/fts3_hash.c 8b6e31bfb0844c27dc6092c2620bdb1fca17ed613072db057d96952c6 F ext/fts3/fts3_hash.h 39cf6874dc239d6b4e30479b1975fe5b22a3caaf F ext/fts3/fts3_icu.c 305ce7fb6036484085b5556a9c8e62acdc7763f0f4cdf5fd538212a9f3720116 F ext/fts3/fts3_porter.c e19807ce0ae31c1c6e9898e89ecc93183d7ec224ea101af039722a4f49e5f2b8 -F ext/fts3/fts3_snippet.c 4d6523e3eddeb7b46e7a82b3476a0a86a0c04821e0e2b8dd40f45ee28057cb13 +F ext/fts3/fts3_snippet.c 610328fe128c047c6b0eba77768982ccf3933daae095d497949a75c9dfd47409 F ext/fts3/fts3_term.c 845f0e2456b1be42f7f1bec1da1dfc05bc347531eff90775ffc6698902c281de F ext/fts3/fts3_test.c d8d7b2734f894e8a489987447658e374cdd3a3bc8575c401decf1911cb7c6454 F ext/fts3/fts3_tokenize_vtab.c 7fd9ef364f257b97218b9c331f2378e307375c592f70fd541f714e747d944962 @@ -1200,7 +1200,7 @@ F test/fts3rank.test cd99bc83a3c923c8d52afd90d86979cf05fc41849f892faeac3988055ef F test/fts3rnd.test 1320d8826a845e38a96e769562bf83d7a92a15d0 F test/fts3shared.test 57e26a801f21027b7530da77db54286a6fe4997e F test/fts3snippet.test 0887196d67cffbe365edde535b95ecc642a532ce8551ccd9a73aab5999c3ffae -F test/fts3snippet2.test e79afeb1f673713f96d7fc5655726081975399d11e659d15553207be43301dc4 +F test/fts3snippet2.test 03f6738ab3897bea2ba6be424a0613872e167acbf37a66200d655d737b470f65 F test/fts3sort.test ed34c716a11cc2009a35210e84ad5f9c102362ca F test/fts3tok1.test a663f4cac22a9505400bc22aacb818d7055240409c28729669ea7d4cc2120d15 F test/fts3tok_err.test 52273cd193b9036282f7bacb43da78c6be87418d @@ -2184,8 +2184,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P a6e26e778812c8409fca77183e24d3b70189c4d02fce10c7e74cd4ccc8c8ea97 -R b9c21ffc9d4065568ea5ca672bfa94a1 +P e66a834bbab9d71e02b70588ad4c71eae2e13b50e299b0269d488402bc4a7fc5 +R 75450b3380949a2b13147c3a28eab747 U dan -Z a2100870dc1c15edbdbfdff1cdb0d2d0 +Z 0a239b81f481c07e165698bd6a5a4da2 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index e73f4c80e2..71eaeff0e3 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e66a834bbab9d71e02b70588ad4c71eae2e13b50e299b0269d488402bc4a7fc5 \ No newline at end of file +6d2c7ac4ecfc1ec408cb1820985a70650d7cc5613b4b8fd1829f68ea48fce6a3 \ No newline at end of file diff --git a/test/fts3snippet2.test b/test/fts3snippet2.test index 607b01e0f8..f55a5f203a 100644 --- a/test/fts3snippet2.test +++ b/test/fts3snippet2.test @@ -55,5 +55,16 @@ do_execsql_test 2.2 { '(def AND (one NEAR abc)) OR one' } {one} +#------------------------------------------------------------------------- + +do_execsql_test 3.0 { +CREATE VIRTUAL TABLE f USING fts3(a,b); +INSERT INTO f VALUES (101,x'056522650565056505650d051e056505650565286505650565056505056505650565056505650565056505650565056505650565056505656505650565056505650d05650505656505650565ef65056505844c746e65650565056505650565056505650565056505650565058405800565056505650565056505651e650565056505650565056505650d056505056565056505650565056505840580056505650565056f05650565056505650565056505650565050565056505640565056505650565056505651e05650565056505650565056505650505656565056505650565056505651e0565056505650565056505650565052265056505650569056505650565056505650565056505650565056505650500406505650565056505650565056505000101e5c501014b010101c501c5c501010101f5010201010101014101017373737373737373737373737373737373737373737373737373737330737373737373737373737373737365056505650d051e05650565056528056505650d05650505656505650565650565056505650565056505e505650565056505656505650565056505650d05650505656505650565ef65056505844c746e65650565056505650565056505650565056505650565058405800565056505650565056505651e650565056505650565056505650d056505056565056505650565056505840580056505650565286505c705650565050565059494949494949494949494949494949494949494949494949494949494949494949494650565056505650565056505650565056505650565056505656505650565056505650d05650505656505650565ef650565058405056505650565056505650565056505650565056505650565058405800565056505650565056505651e650565056505650565056505650d056505056565056505650565056505840580056505650565056505650565056505650505650565056505650565056505650565056500000000000000000000000000000000000000000000000000000000000000000565056505656505650565056505650d056500000000000000000000000000000000000000000000000000000000000000000100000000000000ed0000000000ffffffffffffffffffffff0007ffffff0001c5c50001c5c50001c5c50001c5c50001c5c50001c5c50001e5c50001c5c50001c5c50001c5c50001c5c50001c5c5000100000014720000000000000016dac5c50001c5c50001c5c50001c5c50001c5c50001c5c50d0505656505650565ef650565058405056505650565056505650565056505650565056505650565058405800465056505650565056505651e650565056505650565056505650d05650505656505650565050565650584058005650565056505650565056505650565056522650565056505650d051e056505650561286505c70565056505056505650565056505650565056505650565056505650565056505656505650565056505650d05650505656505650565ef650565058405056505650565056505650565056505650565056505650565058405800565056505650565056505651e650565056505650565056505650d056505056565056505650565056505840580056505650565056505650565056505650565226505737373737373737373737373737373737373737373737373737373737373737373737373737373737373737373737373733a73737373737373737373737373737373737373737373737373737373737373737373737373737373737c7373737365056505650d051e05650565056528650565056505650505650565056505650565056505650565056505e505650565056505656505650565056505650d05650505656505650565ef65056505'); +} + +do_execsql_test 3.1 { + SELECT length(snippet(f)) FROM f WHERE b MATCH x'0565056505650565056505650565056505650565058405800565056505650565056505651e650565056505650565056505650d056505056565056505650565056505840580056505650565056505650565056505650565056505650565050565056505640565056505650565056505651e05650565056522650565056505650d051e056505650565286505650565056505056505650565056505650565056505650565056505650565056505656505650565056505650d05650505656505650565ef65056505844c746e65650565056505650565056505650565056505650565058405800565056505650565056505651e650565056505650565056505650d056505056565056505650565056505840580056505650565056f05650565056505650565056505650565050565056505640565056505650565056505651e05650565056505650565056505650505656565056505650565056505651e0565056505650565056505650565052265056505650569056505650565056505650565056505650565056505650500406505650565056505650565056505000101e5c501014b010101c501c5c501010101f50102010101010141010141010001017bf15905000000000017'; +} {192} + set sqlite_fts3_enable_parentheses 0 finish_test From b6d108f0b37a0fcda58647cfb75d18909a496d77 Mon Sep 17 00:00:00 2001 From: stephan Date: Thu, 11 Apr 2024 19:08:12 +0000 Subject: [PATCH 317/430] Fix handling of the SQLITE_OMIT_WAL check in one place. Resolves [forum:87cc13302de160eb|forum post 87cc13302de160eb]. FossilOrigin-Name: 5dae6e6df4921f42e45c6c8de40853ab63f53a4bd1d9088a8cdac957ce62f196 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/pager.c | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 764ffbd97a..eab5ebd169 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\s"shift\sexponent\sis\stoo\slarge"\susan\serror\sthat\scould\soccur\sin\sthe\sfts3\ssnippet()\sfunction\swhen\sa\squery\sphrase\scontains\smore\sthan\s64\stokens. -D 2024-04-09T19:23:18.637 +C Fix\shandling\sof\sthe\sSQLITE_OMIT_WAL\scheck\sin\sone\splace.\sResolves\s[forum:87cc13302de160eb|forum\spost\s87cc13302de160eb]. +D 2024-04-11T19:08:12.217 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -737,7 +737,7 @@ F src/os_setup.h 6011ad7af5db4e05155f385eb3a9b4470688de6f65d6166b8956e58a3d87210 F src/os_unix.c 6227cbc4ac93046f121436886cf3712da6f4e2082af6314f976eeae1d86b794a F src/os_win.c 6ff43bac175bd9ed79e7c0f96840b139f2f51d01689a638fd05128becf94908a F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a -F src/pager.c ff60e98138d2499082ac6230f01ac508aba545315debccfca2fd6042f5f10fcd +F src/pager.c 9beb80f6e330dd63c5d8ba0f7a7f3a55fff22067a68d424949c389bfc6fa0c56 F src/pager.h 4b1140d691860de0be1347474c51fee07d5420bd7f802d38cbab8ea4ab9f538a F src/parse.y 5bcef16094213efcc365a9d4dc4e3131f09251dc8838dce4a9e5f9764bff5b82 F src/pcache.c 040b165f30622a21b7a9a77c6f2e4877a32fb7f22d4c7f0d2a6fa6833a156a75 @@ -2184,8 +2184,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P e66a834bbab9d71e02b70588ad4c71eae2e13b50e299b0269d488402bc4a7fc5 -R 75450b3380949a2b13147c3a28eab747 -U dan -Z 0a239b81f481c07e165698bd6a5a4da2 +P 6d2c7ac4ecfc1ec408cb1820985a70650d7cc5613b4b8fd1829f68ea48fce6a3 +R 0071938b1b4e5105037f1334ca733633 +U stephan +Z d6eaf14882bbc596d43b8bd29ecbee42 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 71eaeff0e3..4d8c2440ec 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6d2c7ac4ecfc1ec408cb1820985a70650d7cc5613b4b8fd1829f68ea48fce6a3 \ No newline at end of file +5dae6e6df4921f42e45c6c8de40853ab63f53a4bd1d9088a8cdac957ce62f196 \ No newline at end of file diff --git a/src/pager.c b/src/pager.c index 37588f0b25..268dc7db31 100644 --- a/src/pager.c +++ b/src/pager.c @@ -7087,7 +7087,7 @@ sqlite3_file *sqlite3PagerFile(Pager *pPager){ ** This will be either the rollback journal or the WAL file. */ sqlite3_file *sqlite3PagerJrnlFile(Pager *pPager){ -#if SQLITE_OMIT_WAL +#ifdef SQLITE_OMIT_WAL return pPager->jfd; #else return pPager->pWal ? sqlite3WalFile(pPager->pWal) : pPager->jfd; From c494fdb580bc7c738a3a53be1ad2fd2ca3aa08e5 Mon Sep 17 00:00:00 2001 From: drh <> Date: Fri, 12 Apr 2024 02:57:52 +0000 Subject: [PATCH 318/430] Mark the BTree cell overflow cache as invalid whenever the rowid goes invalid. FossilOrigin-Name: 74c9e19c92c887012aebbe96450f6ed7a60ba22d6e3edbaa39a0f989fb7f2901 --- manifest | 17 ++++++++++------- manifest.uuid | 2 +- src/btree.c | 4 ++-- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index eab5ebd169..2daa24ebaa 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\shandling\sof\sthe\sSQLITE_OMIT_WAL\scheck\sin\sone\splace.\sResolves\s[forum:87cc13302de160eb|forum\spost\s87cc13302de160eb]. -D 2024-04-11T19:08:12.217 +C Mark\sthe\sBTree\scell\soverflow\scache\sas\sinvalid\swhenever\sthe\srowid\sgoes\sinvalid. +D 2024-04-12T02:57:52.425 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -689,7 +689,7 @@ F src/auth.c 19b7ccacae3dfba23fc6f1d0af68134fa216e9040e53b0681b4715445ea030b4 F src/backup.c 5c97e8023aab1ce14a42387eb3ae00ba5a0644569e3476f38661fa6f824c3523 F src/bitvec.c 9eac5f42c11914d5ef00a75605bb205e934f435c579687f985f1f8b0995c8645 F src/btmutex.c 79a43670447eacc651519a429f6ece9fd638563cf95b469d6891185ddae2b522 -F src/btree.c 285b493d843e7ba8ef78b6ae7d31238e904901dbc0c484f7904de4cf18fd8802 +F src/btree.c a654c4b4d84821f4fdeb322df185317493be30c1b114cb75d56adb50dd3f661c F src/btree.h 55066f513eb095db935169dab1dc2f7c7a747ef223c533f5d4ad4dfed346cbd0 F src/btreeInt.h 98aadb6dcb77b012cab2574d6a728fad56b337fc946839b9898c4b4c969e30b6 F src/build.c 02f5b25ca854c83b5015cb02b8c9ab236c60b1795528675aee8a5070e58da52a @@ -2184,8 +2184,11 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 6d2c7ac4ecfc1ec408cb1820985a70650d7cc5613b4b8fd1829f68ea48fce6a3 -R 0071938b1b4e5105037f1334ca733633 -U stephan -Z d6eaf14882bbc596d43b8bd29ecbee42 +P 5dae6e6df4921f42e45c6c8de40853ab63f53a4bd1d9088a8cdac957ce62f196 +R 991bf551528ac37b754c129e51db564b +T *branch * btree-ovfl-cache +T *sym-btree-ovfl-cache * +T -sym-trunk * +U drh +Z d43adcfd8cc8586ed5a00034a7473bf9 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 4d8c2440ec..5ce114455e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5dae6e6df4921f42e45c6c8de40853ab63f53a4bd1d9088a8cdac957ce62f196 \ No newline at end of file +74c9e19c92c887012aebbe96450f6ed7a60ba22d6e3edbaa39a0f989fb7f2901 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index ddfa3c63f3..e957ccb199 100644 --- a/src/btree.c +++ b/src/btree.c @@ -9521,7 +9521,7 @@ int sqlite3BtreeInsert( }else if( loc<0 && pPage->nCell>0 ){ assert( pPage->leaf ); idx = ++pCur->ix; - pCur->curFlags &= ~BTCF_ValidNKey; + pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl); }else{ assert( pPage->leaf ); } @@ -9551,7 +9551,7 @@ int sqlite3BtreeInsert( */ if( pPage->nOverflow ){ assert( rc==SQLITE_OK ); - pCur->curFlags &= ~(BTCF_ValidNKey); + pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl); rc = balance(pCur); /* Must make sure nOverflow is reset to zero even if the balance() From 366b419d0084fad8b60ec47e89b882f8218b25e6 Mon Sep 17 00:00:00 2001 From: drh <> Date: Fri, 12 Apr 2024 11:28:35 +0000 Subject: [PATCH 319/430] Test case for the fix in the previous check-in. FossilOrigin-Name: 0cf4d835dae260b01178e94e77be6b8a130f2031e898ef79ceba8df6c2bba58f --- manifest | 15 ++++++--------- manifest.uuid | 2 +- test/upsert1.test | 24 ++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 2daa24ebaa..3d880dd346 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Mark\sthe\sBTree\scell\soverflow\scache\sas\sinvalid\swhenever\sthe\srowid\sgoes\sinvalid. -D 2024-04-12T02:57:52.425 +C Test\scase\sfor\sthe\sfix\sin\sthe\sprevious\scheck-in. +D 2024-04-12T11:28:35.112 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -1906,7 +1906,7 @@ F test/upfrom2.test 66f3ebf721b3cebd922faee5c386bf244f816d416b57c000753ff51af623 F test/upfrom3.test 6130f24ebf97f5ea865e5d2a14a2d543fe5428a62e87cc60f62d875e45c1f5f0 F test/upfrom4.test 78f742a6577c91a7a55c64edb8811004e7c6aa99b8d57b2320f70a918c357807 F test/upfromfault.test 3a10075a0043f0c4fad6614b2c371f88a8ba5a4acab68b907438413865d6a8d6 -F test/upsert1.test a512e2f884d3a36159fce2e45108c236f78ae38e35bda55f4050db580ceb25d3 +F test/upsert1.test beba4316fbd4b7b9d76784313f6129a548cfe7abea04d46db33e2efce1ab0ac2 F test/upsert2.test 720e94d09f7362a282bc69b3c6b83d51daeaaf0440eb4920a08b86518b8c7496 F test/upsert3.test 88d7d590a1948a9cb6eac1b54b0642f67a9f35a1fc0f19b200e97d5d39e3179c F test/upsert4.test 25d2a1da92f149331ae0c51ca6e3eee78189577585eab92de149900d62994fa5 @@ -2184,11 +2184,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 5dae6e6df4921f42e45c6c8de40853ab63f53a4bd1d9088a8cdac957ce62f196 -R 991bf551528ac37b754c129e51db564b -T *branch * btree-ovfl-cache -T *sym-btree-ovfl-cache * -T -sym-trunk * +P 74c9e19c92c887012aebbe96450f6ed7a60ba22d6e3edbaa39a0f989fb7f2901 +R e5ebeec2e7c87917a5e915be853b1124 U drh -Z d43adcfd8cc8586ed5a00034a7473bf9 +Z 367db0044284a550a3cf0e6c6563bd86 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 5ce114455e..3a012e5380 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -74c9e19c92c887012aebbe96450f6ed7a60ba22d6e3edbaa39a0f989fb7f2901 \ No newline at end of file +0cf4d835dae260b01178e94e77be6b8a130f2031e898ef79ceba8df6c2bba58f \ No newline at end of file diff --git a/test/upsert1.test b/test/upsert1.test index 7818311330..8af273a89a 100644 --- a/test/upsert1.test +++ b/test/upsert1.test @@ -268,4 +268,28 @@ do_catchsql_test upsert1-1210 { INSERT INTO t1(a,b) VALUES(1,2) ON CONFLICT(b+?1) DO NOTHING; } {1 {ON CONFLICT clause does not match any PRIMARY KEY or UNIQUE constraint}} +# 2024-04-11 https://sqlite.org/forum/forumpost/284955a3cd454a15 +# Incorrect value passed into a trigger that fires as the result of +# an upsert. +# +reset_db +do_execsql_test upsert1-1300 { + CREATE TABLE t1(x INT, y TEXT); + INSERT INTO t1 VALUES + (11, printf('%.9000c','a')), + (11, printf('%.9000c','a')), + (33, printf('%.9000c','b')), + (33, printf('%.9000c','b')); + CREATE TABLE t2(x INT UNIQUE, y TEXT); + CREATE TRIGGER r1 BEFORE UPDATE ON t2 BEGIN + SELECT raise(ABORT,'Incorrect old.y value passed to trigger!') + WHERE old.y != new.y; + /* ^^^ This trigger will fire and cause the ABORT if the problem has + ** not been fixed, or if there is a regression. */ + END; + INSERT INTO t2(x, y) SELECT x, y FROM t1 + WHERE true + ON CONFLICT (x) DO UPDATE SET y = excluded.y; +} {} + finish_test From ae7ede4a4f70648170b05d176b877f97734d1383 Mon Sep 17 00:00:00 2001 From: drh <> Date: Fri, 12 Apr 2024 12:32:09 +0000 Subject: [PATCH 320/430] New assert() statements to verify the correctness of the BTCF_AtLast flag on btree cursors. FossilOrigin-Name: 4efecd6167de71500c90b63155eba1b8567c90e9d1e282fbea54130f9ee21813 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/btree.c | 31 +++++++++++++++++++------------ 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/manifest b/manifest index 3d880dd346..070fa270cd 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Test\scase\sfor\sthe\sfix\sin\sthe\sprevious\scheck-in. -D 2024-04-12T11:28:35.112 +C New\sassert()\sstatements\sto\sverify\sthe\scorrectness\sof\sthe\sBTCF_AtLast\sflag\non\sbtree\scursors. +D 2024-04-12T12:32:09.806 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -689,7 +689,7 @@ F src/auth.c 19b7ccacae3dfba23fc6f1d0af68134fa216e9040e53b0681b4715445ea030b4 F src/backup.c 5c97e8023aab1ce14a42387eb3ae00ba5a0644569e3476f38661fa6f824c3523 F src/bitvec.c 9eac5f42c11914d5ef00a75605bb205e934f435c579687f985f1f8b0995c8645 F src/btmutex.c 79a43670447eacc651519a429f6ece9fd638563cf95b469d6891185ddae2b522 -F src/btree.c a654c4b4d84821f4fdeb322df185317493be30c1b114cb75d56adb50dd3f661c +F src/btree.c b489280734e3c085774ecc86a07f5ad5b805d86e2cb28650c3b3e141673993d6 F src/btree.h 55066f513eb095db935169dab1dc2f7c7a747ef223c533f5d4ad4dfed346cbd0 F src/btreeInt.h 98aadb6dcb77b012cab2574d6a728fad56b337fc946839b9898c4b4c969e30b6 F src/build.c 02f5b25ca854c83b5015cb02b8c9ab236c60b1795528675aee8a5070e58da52a @@ -2184,8 +2184,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 74c9e19c92c887012aebbe96450f6ed7a60ba22d6e3edbaa39a0f989fb7f2901 -R e5ebeec2e7c87917a5e915be853b1124 +P 0cf4d835dae260b01178e94e77be6b8a130f2031e898ef79ceba8df6c2bba58f +R 3352218b957f71135e62b28b93e477b6 U drh -Z 367db0044284a550a3cf0e6c6563bd86 +Z 55f6b761ddb19ac9081b9562cfbe54ea # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 3a012e5380..01cbdd4cd6 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0cf4d835dae260b01178e94e77be6b8a130f2031e898ef79ceba8df6c2bba58f \ No newline at end of file +4efecd6167de71500c90b63155eba1b8567c90e9d1e282fbea54130f9ee21813 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index e957ccb199..91c9e4fb57 100644 --- a/src/btree.c +++ b/src/btree.c @@ -5624,6 +5624,23 @@ int sqlite3BtreeFirst(BtCursor *pCur, int *pRes){ return rc; } +#ifdef SQLITE_DEBUG +/* The cursors is CURSOR_VALID and has BTCF_AtLast set. Verify that +** this flags are true for a consistent database. +** +** This routine is is called from within assert() statements only. +** It is an internal verification routine and does not appear in production +** builds. +*/ +static int cursorIsAtLastEntry(BtCursor *pCur){ + int ii; + for(ii=0; iiiPage; ii++){ + if( pCur->aiIdx[ii]!=pCur->apPage[ii]->nCell ) return 0; + } + return pCur->ix==pCur->pPage->nCell-1 && pCur->pPage->leaf!=0; +} +#endif + /* Move the cursor to the last entry in the table. Return SQLITE_OK ** on success. Set *pRes to 0 if the cursor actually points to something ** or set *pRes to 1 if the table is empty. @@ -5652,18 +5669,7 @@ int sqlite3BtreeLast(BtCursor *pCur, int *pRes){ /* If the cursor already points to the last entry, this is a no-op. */ if( CURSOR_VALID==pCur->eState && (pCur->curFlags & BTCF_AtLast)!=0 ){ -#ifdef SQLITE_DEBUG - /* This block serves to assert() that the cursor really does point - ** to the last entry in the b-tree. */ - int ii; - for(ii=0; iiiPage; ii++){ - assert( pCur->aiIdx[ii]==pCur->apPage[ii]->nCell ); - } - assert( pCur->ix==pCur->pPage->nCell-1 || CORRUPT_DB ); - testcase( pCur->ix!=pCur->pPage->nCell-1 ); - /* ^-- dbsqlfuzz b92b72e4de80b5140c30ab71372ca719b8feb618 */ - assert( pCur->pPage->leaf ); -#endif + assert( cursorIsAtLastEntry(pCur) || CORRUPT_DB ); *pRes = 0; return SQLITE_OK; } @@ -5716,6 +5722,7 @@ int sqlite3BtreeTableMoveto( } if( pCur->info.nKeycurFlags & BTCF_AtLast)!=0 ){ + assert( cursorIsAtLastEntry(pCur) || CORRUPT_DB ); *pRes = -1; return SQLITE_OK; } From 1d40237bc8b1c6ec71dfe763329e1aceacf022fa Mon Sep 17 00:00:00 2001 From: drh <> Date: Fri, 12 Apr 2024 13:05:36 +0000 Subject: [PATCH 321/430] Add assert() statements to help verify the overflow page cache. FossilOrigin-Name: 0ebc65481f4a3e7974558adea51c620a025bc0e76c0a139e549b56c5abe0cabb --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/btree.c | 4 ++++ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index 070fa270cd..17af620303 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C New\sassert()\sstatements\sto\sverify\sthe\scorrectness\sof\sthe\sBTCF_AtLast\sflag\non\sbtree\scursors. -D 2024-04-12T12:32:09.806 +C Add\sassert()\sstatements\sto\shelp\sverify\sthe\soverflow\spage\scache. +D 2024-04-12T13:05:36.039 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -689,7 +689,7 @@ F src/auth.c 19b7ccacae3dfba23fc6f1d0af68134fa216e9040e53b0681b4715445ea030b4 F src/backup.c 5c97e8023aab1ce14a42387eb3ae00ba5a0644569e3476f38661fa6f824c3523 F src/bitvec.c 9eac5f42c11914d5ef00a75605bb205e934f435c579687f985f1f8b0995c8645 F src/btmutex.c 79a43670447eacc651519a429f6ece9fd638563cf95b469d6891185ddae2b522 -F src/btree.c b489280734e3c085774ecc86a07f5ad5b805d86e2cb28650c3b3e141673993d6 +F src/btree.c 8c2d32661d9b3333b5e2192a9baf0f34aaf50224c7e0130bdb96a1e5dee9009c F src/btree.h 55066f513eb095db935169dab1dc2f7c7a747ef223c533f5d4ad4dfed346cbd0 F src/btreeInt.h 98aadb6dcb77b012cab2574d6a728fad56b337fc946839b9898c4b4c969e30b6 F src/build.c 02f5b25ca854c83b5015cb02b8c9ab236c60b1795528675aee8a5070e58da52a @@ -2184,8 +2184,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 0cf4d835dae260b01178e94e77be6b8a130f2031e898ef79ceba8df6c2bba58f -R 3352218b957f71135e62b28b93e477b6 +P 4efecd6167de71500c90b63155eba1b8567c90e9d1e282fbea54130f9ee21813 +R 733b2640d8dc44517728193a890baeff U drh -Z 55f6b761ddb19ac9081b9562cfbe54ea +Z 6194d89088ab528754e159fb92573073 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 01cbdd4cd6..621be8e4f9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4efecd6167de71500c90b63155eba1b8567c90e9d1e282fbea54130f9ee21813 \ No newline at end of file +0ebc65481f4a3e7974558adea51c620a025bc0e76c0a139e549b56c5abe0cabb \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 91c9e4fb57..756ec942c3 100644 --- a/src/btree.c +++ b/src/btree.c @@ -5143,6 +5143,10 @@ static int accessPayload( memset(pCur->aOverflow, 0, nOvfl*sizeof(Pgno)); pCur->curFlags |= BTCF_ValidOvfl; }else{ + /* Sanity check the validity of the overflow page cache */ + assert( pCur->aOverflow[0]==nextPage || pCur->aOverflow[0]==0 ); + assert( pCur->aOverflow[0]!=0 || pCur->aOverflow[offset/ovflSize]==0 ); + /* If the overflow page-list cache has been allocated and the ** entry for the first required overflow page is valid, skip ** directly to it. From 0221cacea70d50f8cf5033aecfa104e4582a1532 Mon Sep 17 00:00:00 2001 From: drh <> Date: Fri, 12 Apr 2024 18:46:34 +0000 Subject: [PATCH 322/430] If a build fails in testrunner.tcl, do not attempt to run the jobs that depend on that build. Instead, report those jobs as having been skipped. FossilOrigin-Name: b40580be719a129ecd1aa3c69d1086c967d063920fdd48617c864e73c059abc1 --- manifest | 13 ++++++------- manifest.uuid | 2 +- test/testrunner.tcl | 17 +++++++++++++++-- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index ceff35c009..c7c6ea43af 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fixes\sand\snew\stests\slogic\sto\sensure\sthat\sthe\sbtree\soverflow\spage\scache\sis\nonly\sused\swhen\sit\sis\sconsistent.\s\sThis\sresolves\sthe\smalfunction\sobserved\nin\s[forum:/forumpost/284955a3cd454a15|forum\spost\s284955a3cd454a15]. -D 2024-04-12T15:02:16.718 +C If\sa\sbuild\sfails\sin\stestrunner.tcl,\sdo\snot\sattempt\sto\srun\sthe\sjobs\sthat\ndepend\son\sthat\sbuild.\s\sInstead,\sreport\sthose\sjobs\sas\shaving\sbeen\sskipped. +D 2024-04-12T18:46:34.309 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -1690,7 +1690,7 @@ F test/temptable2.test 76821347810ecc88203e6ef0dd6897b6036ac788e9dd3e6b04fd4d163 F test/temptable3.test d11a0974e52b347e45ee54ef1923c91ed91e4637 F test/temptrigger.test 38f0ca479b1822d3117069e014daabcaacefffcc F test/tester.tcl fe617b88c7eb08bdf983d2aaa31c20fbf439eee7b8e0d61ca636fcd0c305bbbf -F test/testrunner.tcl b48a8fc17e3b200244f53d60348afa7fe9482400d164e95709890743af9536d0 +F test/testrunner.tcl 1386667c04207d0a540ce1a9bc5ee0b734f7a3ba856c14a03943fb4f32de55bb F test/testrunner_data.tcl 3d36660cfd55ea5e20e661e8f94c0520feebcb437848f9b98b33c483cc479c0c F test/thread001.test a0985c117eab62c0c65526e9fa5d1360dd1cac5b03bde223902763274ce21899 F test/thread002.test c24c83408e35ba5a952a3638b7ac03ccdf1ce4409289c54a050ac4c5f1de7502 @@ -2184,9 +2184,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 5dae6e6df4921f42e45c6c8de40853ab63f53a4bd1d9088a8cdac957ce62f196 0ebc65481f4a3e7974558adea51c620a025bc0e76c0a139e549b56c5abe0cabb -R 733b2640d8dc44517728193a890baeff -T +closed 0ebc65481f4a3e7974558adea51c620a025bc0e76c0a139e549b56c5abe0cabb +P 5dede50d9e7b6942df9f7b00fbfeaa2103c36c5da01d63d88136fb0ef4b7d26d +R 4f3eb54a5cce9aa23292ec96983abdb3 U drh -Z 49129cd4194bac4dbb6265651119b7c1 +Z 1648e8675f24aa01764212367c0fba7b # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 8b1f8f1238..b40ee8722e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5dede50d9e7b6942df9f7b00fbfeaa2103c36c5da01d63d88136fb0ef4b7d26d \ No newline at end of file +b40580be719a129ecd1aa3c69d1086c967d063920fdd48617c864e73c059abc1 \ No newline at end of file diff --git a/test/testrunner.tcl b/test/testrunner.tcl index 05f7d4cc98..fd82716769 100644 --- a/test/testrunner.tcl +++ b/test/testrunner.tcl @@ -270,7 +270,7 @@ set TRG(schema) { /* Fields updated as jobs run */ starttime INTEGER, endtime INTEGER, - state TEXT CHECK( state IN ('', 'ready', 'running', 'done', 'failed') ), + state TEXT CHECK( state IN ('','ready','running','done','failed','omit') ), output TEXT ); @@ -447,6 +447,10 @@ if {[llength $argv]==1 } job { display_job [array get job] } + set nOmit [db one {SELECT count(*) FROM jobs WHERE state='omit'}] + if {$nOmit} { + puts "$nOmit jobs omitted due to failures" + } } mydb close @@ -975,11 +979,16 @@ proc make_new_testset {} { proc mark_job_as_finished {jobid output state endtm} { r_write_db { + if {$state=="failed"} { + set childstate omit + } else { + set childstate ready + } trdb eval { UPDATE jobs SET output=$output, state=$state, endtime=$endtm WHERE jobid=$jobid; - UPDATE jobs SET state='ready' WHERE depid=$jobid; + UPDATE jobs SET state=$childstate WHERE depid=$jobid; } } } @@ -1202,6 +1211,10 @@ proc run_testset {} { puts "FAILED: $displayname" } } + set nOmit [trdb one {SELECT count(*) FROM jobs WHERE state='omit'}] + if {$nOmit>0} { + puts "$nOmit jobs skipped due to prior failures" + } } puts "\nTest database is $TRG(dbname)" From 06915d014545ebf1b00163351e76fbaa6a3ba7b8 Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 15 Apr 2024 20:43:21 +0000 Subject: [PATCH 323/430] The first assert() added in [0ebc65481f4a3e79] is not necessarily true in a corrupt database file. So add a term to make it true. FossilOrigin-Name: 6b21cccdeec92db9f6ce3dd7ea5e61b8b46650cc1e550271aa51bdc619f55b11 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/btree.c | 4 +++- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index c7c6ea43af..51a37eef64 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C If\sa\sbuild\sfails\sin\stestrunner.tcl,\sdo\snot\sattempt\sto\srun\sthe\sjobs\sthat\ndepend\son\sthat\sbuild.\s\sInstead,\sreport\sthose\sjobs\sas\shaving\sbeen\sskipped. -D 2024-04-12T18:46:34.309 +C The\sfirst\sassert()\sadded\sin\s[0ebc65481f4a3e79]\sis\snot\snecessarily\strue\sin\sa\ncorrupt\sdatabase\sfile.\s\sSo\sadd\sa\sterm\sto\smake\sit\strue. +D 2024-04-15T20:43:21.644 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -689,7 +689,7 @@ F src/auth.c 19b7ccacae3dfba23fc6f1d0af68134fa216e9040e53b0681b4715445ea030b4 F src/backup.c 5c97e8023aab1ce14a42387eb3ae00ba5a0644569e3476f38661fa6f824c3523 F src/bitvec.c 9eac5f42c11914d5ef00a75605bb205e934f435c579687f985f1f8b0995c8645 F src/btmutex.c 79a43670447eacc651519a429f6ece9fd638563cf95b469d6891185ddae2b522 -F src/btree.c 8c2d32661d9b3333b5e2192a9baf0f34aaf50224c7e0130bdb96a1e5dee9009c +F src/btree.c 71b80e77b255144db47180fda8138740608e382a44231942464029b1a45fc036 F src/btree.h 55066f513eb095db935169dab1dc2f7c7a747ef223c533f5d4ad4dfed346cbd0 F src/btreeInt.h 98aadb6dcb77b012cab2574d6a728fad56b337fc946839b9898c4b4c969e30b6 F src/build.c 02f5b25ca854c83b5015cb02b8c9ab236c60b1795528675aee8a5070e58da52a @@ -2184,8 +2184,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 5dede50d9e7b6942df9f7b00fbfeaa2103c36c5da01d63d88136fb0ef4b7d26d -R 4f3eb54a5cce9aa23292ec96983abdb3 +P b40580be719a129ecd1aa3c69d1086c967d063920fdd48617c864e73c059abc1 +R 8fc5f990e4d938881ab9bd286e3b11d3 U drh -Z 1648e8675f24aa01764212367c0fba7b +Z fa0c07b8b0de569fa969f3e2656bc2dc # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index b40ee8722e..b31a38051e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b40580be719a129ecd1aa3c69d1086c967d063920fdd48617c864e73c059abc1 \ No newline at end of file +6b21cccdeec92db9f6ce3dd7ea5e61b8b46650cc1e550271aa51bdc619f55b11 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 756ec942c3..62b8989796 100644 --- a/src/btree.c +++ b/src/btree.c @@ -5144,7 +5144,9 @@ static int accessPayload( pCur->curFlags |= BTCF_ValidOvfl; }else{ /* Sanity check the validity of the overflow page cache */ - assert( pCur->aOverflow[0]==nextPage || pCur->aOverflow[0]==0 ); + assert( pCur->aOverflow[0]==nextPage + || pCur->aOverflow[0]==0 + || CORRUPT_DB ); assert( pCur->aOverflow[0]!=0 || pCur->aOverflow[offset/ovflSize]==0 ); /* If the overflow page-list cache has been allocated and the From 0526db32e2657b2b16fa3333e5b8c6e24754eaf2 Mon Sep 17 00:00:00 2001 From: drh <> Date: Thu, 18 Apr 2024 16:11:01 +0000 Subject: [PATCH 324/430] Correct handling of OUTER JOIN when on or the other operand is a subquery implemented using the VALUES-as-coroutine optimization. dbsqlfuzz bde3bf80aedf25afa56e2997a0545a314765d3f8. FossilOrigin-Name: 8c0f69e0e4ae0a446838cc193bfd4395fd251f3c7659b35ac388e5a0a7650a66 --- manifest | 18 +++++++++--------- manifest.uuid | 2 +- src/vdbe.c | 6 ++++-- src/where.c | 13 +++++++++++-- src/wherecode.c | 18 ++++++++++++++---- test/values.test | 23 ++++++++++++++++++++++- 6 files changed, 61 insertions(+), 19 deletions(-) diff --git a/manifest b/manifest index 51a37eef64..98a7d3bada 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C The\sfirst\sassert()\sadded\sin\s[0ebc65481f4a3e79]\sis\snot\snecessarily\strue\sin\sa\ncorrupt\sdatabase\sfile.\s\sSo\sadd\sa\sterm\sto\smake\sit\strue. -D 2024-04-15T20:43:21.644 +C Correct\shandling\sof\sOUTER\sJOIN\swhen\son\sor\sthe\sother\soperand\sis\sa\ssubquery\nimplemented\susing\sthe\sVALUES-as-coroutine\soptimization.\ndbsqlfuzz\sbde3bf80aedf25afa56e2997a0545a314765d3f8. +D 2024-04-18T16:11:01.833 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -820,7 +820,7 @@ F src/upsert.c 2e60567a0e9e8520c18671b30712a88dc73534474304af94f32bb5f3ef65ac65 F src/utf.c f23165685a67b4caf8ec08fb274cb3f319103decfb2a980b7cfd55d18dfa855e F src/util.c 4d6d7ebfe6772a1b950c97bbb1d1a72ad4874617ec498ab8aa73b7f5a43e44bb F src/vacuum.c 604fcdaebe76f3497c855afcbf91b8fa5046b32de3045bab89cc008d68e40104 -F src/vdbe.c 651aa0f31027d5d0a133eb7b41d11c41dc3b88ecb760b770430da0e477ae3b6c +F src/vdbe.c 298e8bf31adbcad0d8dfa37e106372e0d59ce531f2cca5b8ce559f9e173085f2 F src/vdbe.h c2d78d15112c3fc5ab87f5e8e0b75d2db1c624409de2e858c3d1aafb1650bb4f F src/vdbeInt.h 949669dfd8a41550d27dcb905b494f2ccde9a2e6c1b0b04daa1227e2e74c2b2c F src/vdbeapi.c 80235ac380e9467fec1cb0883354d841f2a771976e766995f7e0c77f845406df @@ -835,9 +835,9 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c 887fc4ca3f020ebb2e376f222069570834ac63bf50111ef0cbf3ae417048ed89 F src/wal.h ba252daaa94f889f4b2c17c027e823d9be47ce39da1d3799886bbd51f0490452 F src/walker.c 7c7ea0115345851c3da4e04e2e239a29983b61fb5b038b94eede6aba462640e2 -F src/where.c 09253e913dc1a93aa6e0e1a5d25a392b8fa39096cc30d230dd302264b3be0661 +F src/where.c 40ee94edd4cf31e6dc3e4c9ac814777b8cf4dc8ee985d87eb5f77bd4c42e69da F src/whereInt.h 82a13766f13d1a53b05387c2e60726289ef26404bc7b9b1f7770204d97357fb8 -F src/wherecode.c e033875570f5d65b99fdb5189e597d91c8bc34f4196089fd50e6086d174035e7 +F src/wherecode.c 4b5909be0c36030eec18ea0e7a64c60254180a21e626c9d2e0e9be3007ad47c1 F src/whereexpr.c 7b64295f1d82ad0928df435925dd7bbd5997b44a026153113eace0d9e71ff435 F src/window.c 5d95122dd330bfaebd732358c8ef067c5a9394a53ac249470d611d0ce2c52be2 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 @@ -1924,7 +1924,7 @@ F test/vacuum4.test 7ea76b769fffeb41f925303b04cbcf5a5bbeabe55e4c60ae754ff24eeeb7 F test/vacuum5.test 263b144d537e92ad8e9ca8a73cc6e1583f41cfd0dda9432b87f7806174a2f48c F test/vacuum6.test b137b04bf3392d3f5c3b8fda0ce85a6775a70ca112f6559f74ff52dc9ce042fd F test/vacuummem.test 4b30f5b95a9ff86e9d5c20741e50a898b2dc10b0962a3211571eb165357003fb -F test/values.test 6c2426de40cd397a8ab68d375b6964ab3bce1244bbb69f5d1ed3ccd0e039c1f3 +F test/values.test 8c1e0157ba64aeaebdecd4b0b6b1b1422740664e29c17153499973e77ca5200b F test/valuesfault.test 2ef23ed965e3bd08e268cdc38a0d11653390ddbbe1e8e2e98d16f55edd30f6e8 F test/varint.test bbce22cda8fc4d135bcc2b589574be8410614e62 F test/veryquick.test 57ab846bacf7b90cf4e9a672721ea5c5b669b661 @@ -2184,8 +2184,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P b40580be719a129ecd1aa3c69d1086c967d063920fdd48617c864e73c059abc1 -R 8fc5f990e4d938881ab9bd286e3b11d3 +P 6b21cccdeec92db9f6ce3dd7ea5e61b8b46650cc1e550271aa51bdc619f55b11 +R 742e51db40c512171314564bf9760205 U drh -Z fa0c07b8b0de569fa969f3e2656bc2dc +Z 2a179895cc5d13f95288c795c253907b # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index b31a38051e..2e5a76fc98 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6b21cccdeec92db9f6ce3dd7ea5e61b8b46650cc1e550271aa51bdc619f55b11 \ No newline at end of file +8c0f69e0e4ae0a446838cc193bfd4395fd251f3c7659b35ac388e5a0a7650a66 \ No newline at end of file diff --git a/src/vdbe.c b/src/vdbe.c index ed1d277b23..143fd49c1e 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -1152,7 +1152,9 @@ case OP_InitCoroutine: { /* jump0 */ ** ** The instruction at the address in register P1 is a Yield. ** Jump to the P2 parameter of that Yield. -** After the jump, register P1 becomes undefined. +** After the jump, the value register P1 is left with a value +** such that subsequent OP_Yields go back to the this same +** OP_EndCoroutine instruction. ** ** See also: InitCoroutine */ @@ -1164,8 +1166,8 @@ case OP_EndCoroutine: { /* in1 */ pCaller = &aOp[pIn1->u.i]; assert( pCaller->opcode==OP_Yield ); assert( pCaller->p2>=0 && pCaller->p2nOp ); + pIn1->u.i = (int)(pOp - p->aOp) - 1; pOp = &aOp[pCaller->p2 - 1]; - pIn1->flags = MEM_Undefined; break; } diff --git a/src/where.c b/src/where.c index 65b6ae2c92..93984347b7 100644 --- a/src/where.c +++ b/src/where.c @@ -6940,8 +6940,17 @@ void sqlite3WhereEnd(WhereInfo *pWInfo){ addr = sqlite3VdbeAddOp1(v, OP_IfPos, pLevel->iLeftJoin); VdbeCoverage(v); assert( (ws & WHERE_IDX_ONLY)==0 || (ws & WHERE_INDEXED)!=0 ); if( (ws & WHERE_IDX_ONLY)==0 ){ - assert( pLevel->iTabCur==pTabList->a[pLevel->iFrom].iCursor ); - sqlite3VdbeAddOp1(v, OP_NullRow, pLevel->iTabCur); + SrcItem *pSrc = &pTabList->a[pLevel->iFrom]; + assert( pLevel->iTabCur==pSrc->iCursor ); + if( pSrc->fg.viaCoroutine ){ + int m, n; + n = pSrc->regResult; + assert( pSrc->pTab!=0 ); + m = pSrc->pTab->nCol; + sqlite3VdbeAddOp3(v, OP_Null, 0, n, n+m-1); + }else{ + sqlite3VdbeAddOp1(v, OP_NullRow, pLevel->iTabCur); + } } if( (ws & WHERE_INDEXED) || ((ws & WHERE_MULTI_OR) && pLevel->u.pCoveringIdx) diff --git a/src/wherecode.c b/src/wherecode.c index 1f9c84f008..e91bc283b7 100644 --- a/src/wherecode.c +++ b/src/wherecode.c @@ -2730,11 +2730,21 @@ SQLITE_NOINLINE void sqlite3WhereRightJoinLoop( pRJ->regReturn); for(k=0; ka[k].pWLoop->iTab == pWInfo->a[k].iFrom ); + pRight = &pWInfo->pTabList->a[pWInfo->a[k].iFrom]; mAll |= pWInfo->a[k].pWLoop->maskSelf; - sqlite3VdbeAddOp1(v, OP_NullRow, pWInfo->a[k].iTabCur); - iIdxCur = pWInfo->a[k].iIdxCur; - if( iIdxCur ){ - sqlite3VdbeAddOp1(v, OP_NullRow, iIdxCur); + if( pRight->fg.viaCoroutine ){ + sqlite3VdbeAddOp3( + v, OP_Null, 0, pRight->regResult, + pRight->regResult + pRight->pSelect->pEList->nExpr-1 + ); + }else{ + sqlite3VdbeAddOp1(v, OP_NullRow, pWInfo->a[k].iTabCur); + iIdxCur = pWInfo->a[k].iIdxCur; + if( iIdxCur ){ + sqlite3VdbeAddOp1(v, OP_NullRow, iIdxCur); + } } } if( (pTabItem->fg.jointype & JT_LTORJ)==0 ){ diff --git a/test/values.test b/test/values.test index 4252f2e13b..7e81cdeebb 100644 --- a/test/values.test +++ b/test/values.test @@ -648,6 +648,27 @@ do_catchsql_test 18.5.3 { SELECT * FROM t1; } {0 {}} - +# 2024-04-18 dbsqlfuzz crash-bde3bf80aedf25afa56e2997a0545a314765d3f8 +# Verify that the VALUES expressions used as an argument to an outer +# join work correctly. +# +reset_db +db null NULL +do_execsql_test 19.1 { + CREATE TABLE t1(a INT, b INT); + INSERT INTO t1 VALUES(11,22); + SELECT * FROM t1 LEFT JOIN (VALUES(33,44),(55,66)) AS t2 ON a=b; +} {11 22 NULL NULL} +do_execsql_test 19.2 { + SELECT * FROM (VALUES(33,44),(55,66)) AS t2 RIGHT JOIN t1 ON a=b; +} {NULL NULL 11 22} +do_execsql_test 19.3 { + SELECT *, '|' FROM t1 FULL JOIN (VALUES(33,44),(55,66)) AS t2 ON a=b + ORDER BY +column1 +} {11 22 NULL NULL | NULL NULL 33 44 | NULL NULL 55 66 |} +do_execsql_test 19.4 { + SELECT *, '|' FROM (VALUES(33,44),(55,66)) AS t2 FULL JOIN t1 ON a=b + ORDER BY +column1 +} {NULL NULL 11 22 | 33 44 NULL NULL | 55 66 NULL NULL |} finish_test From d737feeacfdbf6ea5d44e383647ea6ced390c3ab Mon Sep 17 00:00:00 2001 From: dan Date: Sat, 20 Apr 2024 15:14:06 +0000 Subject: [PATCH 325/430] Fix a problem where an expression like (a, b) IN (SELECT ...) might not use an index on (a, b) if the affinities and collation sequences of "a" and "b" are not identical. FossilOrigin-Name: 4d870fd8b5450047a7486fc023d1ac9439642e8ed91eadfd5026c4cda7cc9179 --- manifest | 17 ++++++++++------- manifest.uuid | 2 +- src/where.c | 38 ++++++++++++++++++++++++++++++++++---- 3 files changed, 45 insertions(+), 12 deletions(-) diff --git a/manifest b/manifest index 98a7d3bada..5c55caac4b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Correct\shandling\sof\sOUTER\sJOIN\swhen\son\sor\sthe\sother\soperand\sis\sa\ssubquery\nimplemented\susing\sthe\sVALUES-as-coroutine\soptimization.\ndbsqlfuzz\sbde3bf80aedf25afa56e2997a0545a314765d3f8. -D 2024-04-18T16:11:01.833 +C Fix\sa\sproblem\swhere\san\sexpression\slike\s(a,\sb)\sIN\s(SELECT\s...)\smight\snot\suse\san\sindex\son\s(a,\sb)\sif\sthe\saffinities\sand\scollation\ssequences\sof\s"a"\sand\s"b"\sare\snot\sidentical. +D 2024-04-20T15:14:06.554 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -835,7 +835,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c 887fc4ca3f020ebb2e376f222069570834ac63bf50111ef0cbf3ae417048ed89 F src/wal.h ba252daaa94f889f4b2c17c027e823d9be47ce39da1d3799886bbd51f0490452 F src/walker.c 7c7ea0115345851c3da4e04e2e239a29983b61fb5b038b94eede6aba462640e2 -F src/where.c 40ee94edd4cf31e6dc3e4c9ac814777b8cf4dc8ee985d87eb5f77bd4c42e69da +F src/where.c b4eb20a2e5f74e299cb19095454dd257292ad2a23a90265a9eecd2390fd0552a F src/whereInt.h 82a13766f13d1a53b05387c2e60726289ef26404bc7b9b1f7770204d97357fb8 F src/wherecode.c 4b5909be0c36030eec18ea0e7a64c60254180a21e626c9d2e0e9be3007ad47c1 F src/whereexpr.c 7b64295f1d82ad0928df435925dd7bbd5997b44a026153113eace0d9e71ff435 @@ -2184,8 +2184,11 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 6b21cccdeec92db9f6ce3dd7ea5e61b8b46650cc1e550271aa51bdc619f55b11 -R 742e51db40c512171314564bf9760205 -U drh -Z 2a179895cc5d13f95288c795c253907b +P 8c0f69e0e4ae0a446838cc193bfd4395fd251f3c7659b35ac388e5a0a7650a66 +R 76aaae3efae57f02d5fc2e79c67a8826 +T *branch * vector-in-fix +T *sym-vector-in-fix * +T -sym-trunk * +U dan +Z 8e2ed7e86b55b55a9e6d2d789c1dac73 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 2e5a76fc98..c480de9800 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8c0f69e0e4ae0a446838cc193bfd4395fd251f3c7659b35ac388e5a0a7650a66 \ No newline at end of file +4d870fd8b5450047a7486fc023d1ac9439642e8ed91eadfd5026c4cda7cc9179 \ No newline at end of file diff --git a/src/where.c b/src/where.c index 93984347b7..f6b0990e67 100644 --- a/src/where.c +++ b/src/where.c @@ -302,6 +302,28 @@ static Expr *whereRightSubexprIsColumn(Expr *p){ return 0; } +static int SQLITE_NOINLINE indexInAffinityOk( + Parse *pParse, + WhereTerm *pTerm, + u8 idxaff, + CollSeq **ppColl +){ + Expr *pX = pTerm->pExpr; + Expr inexpr; + + if( sqlite3ExprIsVector(pX->pLeft) ){ + int iField = pTerm->u.x.iField - 1; + inexpr.op = TK_EQ; + inexpr.pLeft = pX->pLeft->x.pList->a[iField].pExpr; + assert( ExprUseXSelect(pX) ); + inexpr.pRight = pX->x.pSelect->pEList->a[iField].pExpr; + pX = &inexpr; + } + + *ppColl = sqlite3ExprCompareCollSeq(pParse, pX); + return sqlite3IndexAffinityOk(pX, idxaff); +} + /* ** Advance to the next WhereTerm that matches according to the criteria ** established when the pScan object was initialized by whereScanInit(). @@ -355,11 +377,19 @@ static WhereTerm *whereScanNext(WhereScan *pScan){ CollSeq *pColl; Parse *pParse = pWC->pWInfo->pParse; pX = pTerm->pExpr; - if( !sqlite3IndexAffinityOk(pX, pScan->idxaff) ){ - continue; + + if( (pTerm->eOperator & WO_IN) ){ + if( !indexInAffinityOk(pParse, pTerm, pScan->idxaff, &pColl) ){ + continue; + } + }else{ + if( !sqlite3IndexAffinityOk(pX, pScan->idxaff) ){ + continue; + } + assert(pX->pLeft); + pColl = sqlite3ExprCompareCollSeq(pParse, pX); } - assert(pX->pLeft); - pColl = sqlite3ExprCompareCollSeq(pParse, pX); + if( pColl==0 ) pColl = pParse->db->pDfltColl; if( sqlite3StrICmp(pColl->zName, pScan->zCollName) ){ continue; From 5749e1ee4386a2a6c436dfeb45770f8352abdb65 Mon Sep 17 00:00:00 2001 From: dan Date: Sat, 20 Apr 2024 19:19:30 +0000 Subject: [PATCH 326/430] Slight performance improvement for the new code on this branch. FossilOrigin-Name: 500c67f1341fe2a7e7333d525c90df201cc73a683b943ad5c1e41d4a4f639043 --- manifest | 17 +++++++---------- manifest.uuid | 2 +- src/where.c | 35 ++++++++++++++++++++++++----------- test/in5.test | 22 ++++++++++++++++++++++ 4 files changed, 54 insertions(+), 22 deletions(-) diff --git a/manifest b/manifest index 5c55caac4b..d652ae551d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sproblem\swhere\san\sexpression\slike\s(a,\sb)\sIN\s(SELECT\s...)\smight\snot\suse\san\sindex\son\s(a,\sb)\sif\sthe\saffinities\sand\scollation\ssequences\sof\s"a"\sand\s"b"\sare\snot\sidentical. -D 2024-04-20T15:14:06.554 +C Slight\sperformance\simprovement\sfor\sthe\snew\scode\son\sthis\sbranch. +D 2024-04-20T19:19:30.713 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -835,7 +835,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c 887fc4ca3f020ebb2e376f222069570834ac63bf50111ef0cbf3ae417048ed89 F src/wal.h ba252daaa94f889f4b2c17c027e823d9be47ce39da1d3799886bbd51f0490452 F src/walker.c 7c7ea0115345851c3da4e04e2e239a29983b61fb5b038b94eede6aba462640e2 -F src/where.c b4eb20a2e5f74e299cb19095454dd257292ad2a23a90265a9eecd2390fd0552a +F src/where.c 79c673bf23b3b7fcc5e9cfa0adcd88a97645cd47920d2365dd6aec8cab7b222a F src/whereInt.h 82a13766f13d1a53b05387c2e60726289ef26404bc7b9b1f7770204d97357fb8 F src/wherecode.c 4b5909be0c36030eec18ea0e7a64c60254180a21e626c9d2e0e9be3007ad47c1 F src/whereexpr.c 7b64295f1d82ad0928df435925dd7bbd5997b44a026153113eace0d9e71ff435 @@ -1274,7 +1274,7 @@ F test/in.test d1cad4ededd425568b2e39fb0c31fa9a3772311dd595801ff13ba3912b69bba6 F test/in2.test 5d4c61d17493c832f7d2d32bef785119e87bde75 F test/in3.test 3cbf58c87f4052cee3a58b37b6389777505aa0c0 F test/in4.test bb767ec1cfd1730256f0a83219f0acda36bc251b63f8b8bb7d8c7cff17875a4f -F test/in5.test b32ce7f4a93f44c5dee94af16886d922cc16ebe33c8e1765c73d4049d0f4b40f +F test/in5.test 4fd79c70dfa0681313e8cdca07f5ff0400bdc0e20f808a5c59eaef1e4b48082a F test/in6.test f5f40d6816a8bb7c784424b58a10ac38efb76ab29127a2c17399e0cbeeda0e4b F test/incrblob.test c9b96afc292aeff43d6687bcb09b0280aa599822 F test/incrblob2.test a494c9e848560039a23974b9119cfc2cf3ad3bd15cc2694ee6367ae537ef8f1f @@ -2184,11 +2184,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 8c0f69e0e4ae0a446838cc193bfd4395fd251f3c7659b35ac388e5a0a7650a66 -R 76aaae3efae57f02d5fc2e79c67a8826 -T *branch * vector-in-fix -T *sym-vector-in-fix * -T -sym-trunk * +P 4d870fd8b5450047a7486fc023d1ac9439642e8ed91eadfd5026c4cda7cc9179 +R 6023edc800b34da7492bfeaa8c433f44 U dan -Z 8e2ed7e86b55b55a9e6d2d789c1dac73 +Z caab3df5b31f1752021c68136ff6d06a # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index c480de9800..6bb6214d88 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4d870fd8b5450047a7486fc023d1ac9439642e8ed91eadfd5026c4cda7cc9179 \ No newline at end of file +500c67f1341fe2a7e7333d525c90df201cc73a683b943ad5c1e41d4a4f639043 \ No newline at end of file diff --git a/src/where.c b/src/where.c index f6b0990e67..96a6df9deb 100644 --- a/src/where.c +++ b/src/where.c @@ -302,15 +302,25 @@ static Expr *whereRightSubexprIsColumn(Expr *p){ return 0; } -static int SQLITE_NOINLINE indexInAffinityOk( +/* +** Term pTerm is guaranteed to be a WO_IN term. It may be a component term +** of a vector IN expression of the form "(x, y, ...) IN (SELECT ...)". +** This function checks to see if the term is compatible with an index +** column with affinity idxaff (one of the SQLITE_AFF_XYZ values). If so, +** it returns a pointer to the name of the collation sequence (e.g. "BINARY" +** or "NOCASE") used by the comparison in pTerm. If it is not compatible +** with affinity idxaff, NULL is returned. +*/ +static SQLITE_NOINLINE const char *indexInAffinityOk( Parse *pParse, WhereTerm *pTerm, - u8 idxaff, - CollSeq **ppColl + u8 idxaff ){ Expr *pX = pTerm->pExpr; Expr inexpr; + assert( pTerm->eOperator & WO_IN ); + if( sqlite3ExprIsVector(pX->pLeft) ){ int iField = pTerm->u.x.iField - 1; inexpr.op = TK_EQ; @@ -320,8 +330,11 @@ static int SQLITE_NOINLINE indexInAffinityOk( pX = &inexpr; } - *ppColl = sqlite3ExprCompareCollSeq(pParse, pX); - return sqlite3IndexAffinityOk(pX, idxaff); + if( sqlite3IndexAffinityOk(pX, idxaff) ){ + CollSeq *pRet = sqlite3ExprCompareCollSeq(pParse, pX); + return pRet ? pRet->zName : sqlite3StrBINARY; + } + return 0; } /* @@ -374,24 +387,24 @@ static WhereTerm *whereScanNext(WhereScan *pScan){ if( (pTerm->eOperator & pScan->opMask)!=0 ){ /* Verify the affinity and collating sequence match */ if( pScan->zCollName && (pTerm->eOperator & WO_ISNULL)==0 ){ - CollSeq *pColl; + const char *zCollName; Parse *pParse = pWC->pWInfo->pParse; pX = pTerm->pExpr; if( (pTerm->eOperator & WO_IN) ){ - if( !indexInAffinityOk(pParse, pTerm, pScan->idxaff, &pColl) ){ - continue; - } + zCollName = indexInAffinityOk(pParse, pTerm, pScan->idxaff); + if( !zCollName ) continue; }else{ + CollSeq *pColl; if( !sqlite3IndexAffinityOk(pX, pScan->idxaff) ){ continue; } assert(pX->pLeft); pColl = sqlite3ExprCompareCollSeq(pParse, pX); + zCollName = pColl ? pColl->zName : sqlite3StrBINARY; } - if( pColl==0 ) pColl = pParse->db->pDfltColl; - if( sqlite3StrICmp(pColl->zName, pScan->zCollName) ){ + if( sqlite3StrICmp(zCollName, pScan->zCollName) ){ continue; } } diff --git a/test/in5.test b/test/in5.test index 6680641ff3..933eb90026 100644 --- a/test/in5.test +++ b/test/in5.test @@ -266,4 +266,26 @@ do_execsql_test 9.2 { SELECT lower('1e500') FROM t0 WHERE rowid != lower('1e500'); } {1e500} +#------------------------------------------------------------------------- +# +reset_db + +do_execsql_test 10.0 { + CREATE TABLE t1(a, b TEXT COLLATE NOCASE); + INSERT INTO t1 VALUES('abc', 'def'); + INSERT INTO t1 VALUES('ghi', 'jkl'); +} + +do_execsql_test 10.1 { + SELECT rowid FROM t1 WHERE (a, b) IN ( VALUES('abc', 'def'), ('ghi', 'JKL') ); +} {1 2} + +do_execsql_test 10.2 { + CREATE INDEX i1 ON t1(a, b COLLATE BINARY); +} + +do_execsql_test 10.3 { + SELECT rowid FROM t1 WHERE (a, b) IN ( VALUES('abc', 'def'), ('ghi', 'JKL') ); +} {1 2} + finish_test From db2a33a3dd9ea37180f22dce60c2b6bbbfd781bf Mon Sep 17 00:00:00 2001 From: drh <> Date: Sun, 21 Apr 2024 23:35:58 +0000 Subject: [PATCH 327/430] Fix an indentation problem in debugging routine sqlite3ShowSrcList(). No changes to production code. FossilOrigin-Name: 5560df2726fed215c98d602c5f6ebbf3c5ae23f8ba1074291c509bf446fdfe66 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/treeview.c | 2 ++ 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index 98a7d3bada..eed8f90418 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Correct\shandling\sof\sOUTER\sJOIN\swhen\son\sor\sthe\sother\soperand\sis\sa\ssubquery\nimplemented\susing\sthe\sVALUES-as-coroutine\soptimization.\ndbsqlfuzz\sbde3bf80aedf25afa56e2997a0545a314765d3f8. -D 2024-04-18T16:11:01.833 +C Fix\san\sindentation\sproblem\sin\sdebugging\sroutine\ssqlite3ShowSrcList().\s\sNo\nchanges\sto\sproduction\scode. +D 2024-04-21T23:35:58.340 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -813,7 +813,7 @@ F src/test_window.c cdae419fdcea5bad6dcd9368c685abdad6deb59e9fc8b84b153de513d394 F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9 F src/threads.c 4ae07fa022a3dc7c5beb373cf744a85d3c5c6c3c F src/tokenize.c 3f703cacdab728d7741e5a6ac242006d74fe1c2754d4f03ed889d7253259bd68 -F src/treeview.c c6fc972683fd00f975d8b32a81c1f25d2fb7d4035366bf45c9f5622d3ccd70ee +F src/treeview.c a8aa3086c886c6eb2ff2b6354b0f23d251f7219bf08fad52d4f2791e55324f1b F src/trigger.c 0905b96b04bb6658509f711a8207287f1315cdbc3df1a1b13ba6483c8e341c81 F src/update.c 732404a04d1737ef14bb6ec6b84f74edf28b3c102a92ae46b4855438a710efe7 F src/upsert.c 2e60567a0e9e8520c18671b30712a88dc73534474304af94f32bb5f3ef65ac65 @@ -2184,8 +2184,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 6b21cccdeec92db9f6ce3dd7ea5e61b8b46650cc1e550271aa51bdc619f55b11 -R 742e51db40c512171314564bf9760205 +P 8c0f69e0e4ae0a446838cc193bfd4395fd251f3c7659b35ac388e5a0a7650a66 +R d1e0ee7f01676cc6df31262dd81ddd1f U drh -Z 2a179895cc5d13f95288c795c253907b +Z 8e24853569e668dc3bc8026735d6b031 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 2e5a76fc98..c390f98bb8 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8c0f69e0e4ae0a446838cc193bfd4395fd251f3c7659b35ac388e5a0a7650a66 \ No newline at end of file +5560df2726fed215c98d602c5f6ebbf3c5ae23f8ba1074291c509bf446fdfe66 \ No newline at end of file diff --git a/src/treeview.c b/src/treeview.c index 2576532b65..c223db29e0 100644 --- a/src/treeview.c +++ b/src/treeview.c @@ -235,12 +235,14 @@ void sqlite3TreeViewSrcList(TreeView *pView, const SrcList *pSrc){ sqlite3TreeViewIdList(pView, pItem->u3.pUsing, (--n)>0, "USING"); } if( pItem->pSelect ){ + sqlite3TreeViewPush(&pView, i+1nSrc); if( pItem->pTab ){ Table *pTab = pItem->pTab; sqlite3TreeViewColumnList(pView, pTab->aCol, pTab->nCol, 1); } assert( (int)pItem->fg.isNestedFrom == IsNestedFrom(pItem->pSelect) ); sqlite3TreeViewSelect(pView, pItem->pSelect, (--n)>0); + sqlite3TreeViewPop(&pView); } if( pItem->fg.isTabFunc ){ sqlite3TreeViewExprList(pView, pItem->u1.pFuncArg, 0, "func-args:"); From 2c26adb87397842f90122a1029cb84d3f45a4090 Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 22 Apr 2024 00:42:47 +0000 Subject: [PATCH 328/430] Continuation of the fix at [8c0f69e0e4ae0a44]: If a viaCoroutine FROM clause term is participating in a RIGHT or FULL JOIN, we have to create an always-NULL pseudo-cursor for that term when processing the RIGHT join. dbsqlfuzz 6fd1ff3a64bef4a6c092e8d757548e95698b0df5. FossilOrigin-Name: e1040e51ebd04f2a076f477b6f240f849afb10f543ebe518e09d6842cc3cb38e --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/vdbe.c | 3 ++- src/wherecode.c | 1 + test/values.test | 41 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 53 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index eed8f90418..bf4199ab06 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\san\sindentation\sproblem\sin\sdebugging\sroutine\ssqlite3ShowSrcList().\s\sNo\nchanges\sto\sproduction\scode. -D 2024-04-21T23:35:58.340 +C Continuation\sof\sthe\sfix\sat\s[8c0f69e0e4ae0a44]:\sIf\sa\sviaCoroutine\sFROM\sclause\nterm\sis\sparticipating\sin\sa\sRIGHT\sor\sFULL\sJOIN,\swe\shave\sto\screate\san\nalways-NULL\spseudo-cursor\sfor\sthat\sterm\swhen\sprocessing\sthe\sRIGHT\sjoin.\ndbsqlfuzz\s6fd1ff3a64bef4a6c092e8d757548e95698b0df5. +D 2024-04-22T00:42:47.056 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -820,7 +820,7 @@ F src/upsert.c 2e60567a0e9e8520c18671b30712a88dc73534474304af94f32bb5f3ef65ac65 F src/utf.c f23165685a67b4caf8ec08fb274cb3f319103decfb2a980b7cfd55d18dfa855e F src/util.c 4d6d7ebfe6772a1b950c97bbb1d1a72ad4874617ec498ab8aa73b7f5a43e44bb F src/vacuum.c 604fcdaebe76f3497c855afcbf91b8fa5046b32de3045bab89cc008d68e40104 -F src/vdbe.c 298e8bf31adbcad0d8dfa37e106372e0d59ce531f2cca5b8ce559f9e173085f2 +F src/vdbe.c 3b1793c5d2235ae89b01ef051a33d7d2ad3704c71799653b112686735ad401ff F src/vdbe.h c2d78d15112c3fc5ab87f5e8e0b75d2db1c624409de2e858c3d1aafb1650bb4f F src/vdbeInt.h 949669dfd8a41550d27dcb905b494f2ccde9a2e6c1b0b04daa1227e2e74c2b2c F src/vdbeapi.c 80235ac380e9467fec1cb0883354d841f2a771976e766995f7e0c77f845406df @@ -837,7 +837,7 @@ F src/wal.h ba252daaa94f889f4b2c17c027e823d9be47ce39da1d3799886bbd51f0490452 F src/walker.c 7c7ea0115345851c3da4e04e2e239a29983b61fb5b038b94eede6aba462640e2 F src/where.c 40ee94edd4cf31e6dc3e4c9ac814777b8cf4dc8ee985d87eb5f77bd4c42e69da F src/whereInt.h 82a13766f13d1a53b05387c2e60726289ef26404bc7b9b1f7770204d97357fb8 -F src/wherecode.c 4b5909be0c36030eec18ea0e7a64c60254180a21e626c9d2e0e9be3007ad47c1 +F src/wherecode.c b0224e0ec3c3c4e94cbdd221df109974a1bb26255637383f0fd81795358326fc F src/whereexpr.c 7b64295f1d82ad0928df435925dd7bbd5997b44a026153113eace0d9e71ff435 F src/window.c 5d95122dd330bfaebd732358c8ef067c5a9394a53ac249470d611d0ce2c52be2 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 @@ -1924,7 +1924,7 @@ F test/vacuum4.test 7ea76b769fffeb41f925303b04cbcf5a5bbeabe55e4c60ae754ff24eeeb7 F test/vacuum5.test 263b144d537e92ad8e9ca8a73cc6e1583f41cfd0dda9432b87f7806174a2f48c F test/vacuum6.test b137b04bf3392d3f5c3b8fda0ce85a6775a70ca112f6559f74ff52dc9ce042fd F test/vacuummem.test 4b30f5b95a9ff86e9d5c20741e50a898b2dc10b0962a3211571eb165357003fb -F test/values.test 8c1e0157ba64aeaebdecd4b0b6b1b1422740664e29c17153499973e77ca5200b +F test/values.test 52102ad9e5068b449429e40a976486a52246041f7cd79d086a2b170e77dec925 F test/valuesfault.test 2ef23ed965e3bd08e268cdc38a0d11653390ddbbe1e8e2e98d16f55edd30f6e8 F test/varint.test bbce22cda8fc4d135bcc2b589574be8410614e62 F test/veryquick.test 57ab846bacf7b90cf4e9a672721ea5c5b669b661 @@ -2184,8 +2184,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 8c0f69e0e4ae0a446838cc193bfd4395fd251f3c7659b35ac388e5a0a7650a66 -R d1e0ee7f01676cc6df31262dd81ddd1f +P 5560df2726fed215c98d602c5f6ebbf3c5ae23f8ba1074291c509bf446fdfe66 +R ae9a50293e0c35742076bd20e79d2b4c U drh -Z 8e24853569e668dc3bc8026735d6b031 +Z 44b0654aae70868bd62dea2cbd768897 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index c390f98bb8..192803b3e3 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5560df2726fed215c98d602c5f6ebbf3c5ae23f8ba1074291c509bf446fdfe66 \ No newline at end of file +e1040e51ebd04f2a076f477b6f240f849afb10f543ebe518e09d6842cc3cb38e \ No newline at end of file diff --git a/src/vdbe.c b/src/vdbe.c index 143fd49c1e..d8b471de2e 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -4584,7 +4584,8 @@ case OP_SequenceTest: { ** is the only cursor opcode that works with a pseudo-table. ** ** P3 is the number of fields in the records that will be stored by -** the pseudo-table. +** the pseudo-table. If P2 is 0 or negative then the pseudo-cursor +** will return NULL for every column. */ case OP_OpenPseudo: { VdbeCursor *pCx; diff --git a/src/wherecode.c b/src/wherecode.c index e91bc283b7..cad2293ddd 100644 --- a/src/wherecode.c +++ b/src/wherecode.c @@ -2739,6 +2739,7 @@ SQLITE_NOINLINE void sqlite3WhereRightJoinLoop( v, OP_Null, 0, pRight->regResult, pRight->regResult + pRight->pSelect->pEList->nExpr-1 ); + sqlite3VdbeAddOp1(v, OP_OpenPseudo, pWInfo->a[k].iTabCur); }else{ sqlite3VdbeAddOp1(v, OP_NullRow, pWInfo->a[k].iTabCur); iIdxCur = pWInfo->a[k].iIdxCur; diff --git a/test/values.test b/test/values.test index 7e81cdeebb..fed2c5c6cb 100644 --- a/test/values.test +++ b/test/values.test @@ -671,4 +671,45 @@ do_execsql_test 19.4 { ORDER BY +column1 } {NULL NULL 11 22 | 33 44 NULL NULL | 55 66 NULL NULL |} +# 2024-04-21 dbsqlfuzz 6fd1ff3a64bef4a6c092e8d757548e95698b0df5 +# A continuation of the 2024-04-18 problem above. We have to create +# Pseudo-cursor that is always NULL on the viaCoroutine loop in case +# there are OP_Columns generated against it by the sub-WHERE clause. +# +db null N +do_execsql_test 19.5 { + DROP TABLE IF EXISTS t1; + DROP TABLE IF EXISTS t2; + DROP TABLE IF EXISTS t3; + CREATE TABLE t1(a,b); INSERT INTO t1 VALUES(1,2); + CREATE TABLE t2(column1,column2); INSERT INTO t2 VALUES(11,22),(33,44); + CREATE TABLE t3(d,e); INSERT INTO t3 VALUES(3,4); +} +do_execsql_test 19.6 { + -- output verify using PG 14.2 + SELECT * + FROM t1 CROSS JOIN t2 FULL JOIN t3 ON a=d + ORDER BY +d, +column1; +} {1 2 11 22 N N + 1 2 33 44 N N + N N N N 3 4} +do_execsql_test 19.7 { + SELECT * + FROM t1 CROSS JOIN (VALUES(11,22),(33,44)) FULL JOIN t3 ON a=d + ORDER BY +d, +column1; +} {1 2 11 22 N N + 1 2 33 44 N N + N N N N 3 4} +do_execsql_test 19.8 { + -- output verified using PG 14.2 + SELECT * + FROM t1 CROSS JOIN t2 FULL JOIN t3 ON a=d + WHERE column1 IS NULL; +} {N N N N 3 4} +do_execsql_test 19.9 { + SELECT * + FROM t1 CROSS JOIN (VALUES(11,22),(33,44)) FULL JOIN t3 ON a=d + WHERE column1 IS NULL; +} {N N N N 3 4} + finish_test From 2469350ad9f84d902793d9c8c6b8caeffd4c0a7c Mon Sep 17 00:00:00 2001 From: stephan Date: Mon, 22 Apr 2024 11:48:03 +0000 Subject: [PATCH 329/430] For sqlite3.oo1.DB JavaScript classes, bypass execution of any on-open() SQL in SEE-capable builds because it would necessarily run before the client has an opportunity to provide their decryption key, which would leave the db handle in an unusable state and cause the ctor to throw. This currently affects only the OPFS VFSes. We may want to consider extending the ctor options object to optionally accept an SEE key and apply it when opening the db. FossilOrigin-Name: 5c505ee8a73f4b4a7053d98a12024d98340676f6ae9982311f9f88a9b46c8ae2 --- ext/wasm/api/sqlite3-api-oo1.js | 33 ++++++++++++++++++++++++++------- manifest | 14 +++++++------- manifest.uuid | 2 +- 3 files changed, 34 insertions(+), 15 deletions(-) diff --git a/ext/wasm/api/sqlite3-api-oo1.js b/ext/wasm/api/sqlite3-api-oo1.js index 425b52eeca..06d1df43f9 100644 --- a/ext/wasm/api/sqlite3-api-oo1.js +++ b/ext/wasm/api/sqlite3-api-oo1.js @@ -179,12 +179,30 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ const pVfs = capi.sqlite3_js_db_vfs(pDb); if(!pVfs) toss3("Internal error: cannot get VFS for new db handle."); const postInitSql = __vfsPostOpenSql[pVfs]; - if(postInitSql instanceof Function){ - postInitSql(this, sqlite3); - }else if(postInitSql){ - checkSqlite3Rc( - pDb, capi.sqlite3_exec(pDb, postInitSql, 0, 0, 0) - ); + if(postInitSql){ + if(capi.sqlite3_activate_see){ + /** + In SEE-capable builds we have to avoid running any db + code before the client has an opportunity to apply their + decryption key. If we first run any db code, e.g. pragma + journal_mode=..., then it will fail with SQLITE_NOTADB + and the db handle will be left in an unusuable + state. Note that at this point we do not actually know + whether the db is encrypted, but if a client has gone out + of their way to create an SEE build, it seems safe to + assume that they are using the encryption. + */ + sqlite3.config.warn( + "Disabling execution of on-open() db code "+ + "because this is an SEE build. DB: "+fnJs + ); + }else if(postInitSql instanceof Function){ + postInitSql(this, sqlite3); + }else{ + checkSqlite3Rc( + pDb, capi.sqlite3_exec(pDb, postInitSql, 0, 0, 0) + ); + } } }catch(e){ this.close(); @@ -288,7 +306,8 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ For purposes of passing a DB instance to C-style sqlite3 functions, the DB object's read-only `pointer` property holds its `sqlite3*` pointer value. That property can also be used to check - whether this DB instance is still open. + whether this DB instance is still open: it will evaluate to + `undefined` after the DB object's close() method is called. In the main window thread, the filenames `":localStorage:"` and `":sessionStorage:"` are special: they cause the db to use either diff --git a/manifest b/manifest index bf4199ab06..53cd1299e0 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Continuation\sof\sthe\sfix\sat\s[8c0f69e0e4ae0a44]:\sIf\sa\sviaCoroutine\sFROM\sclause\nterm\sis\sparticipating\sin\sa\sRIGHT\sor\sFULL\sJOIN,\swe\shave\sto\screate\san\nalways-NULL\spseudo-cursor\sfor\sthat\sterm\swhen\sprocessing\sthe\sRIGHT\sjoin.\ndbsqlfuzz\s6fd1ff3a64bef4a6c092e8d757548e95698b0df5. -D 2024-04-22T00:42:47.056 +C For\ssqlite3.oo1.DB\sJavaScript\sclasses,\sbypass\sexecution\sof\sany\son-open()\sSQL\sin\sSEE-capable\sbuilds\sbecause\sit\swould\snecessarily\srun\sbefore\sthe\sclient\shas\san\sopportunity\sto\sprovide\stheir\sdecryption\skey,\swhich\swould\sleave\sthe\sdb\shandle\sin\san\sunusable\sstate\sand\scause\sthe\sctor\sto\sthrow.\sThis\scurrently\saffects\sonly\sthe\sOPFS\sVFSes.\sWe\smay\swant\sto\sconsider\sextending\sthe\sctor\soptions\sobject\sto\soptionally\saccept\san\sSEE\skey\sand\sapply\sit\swhen\sopening\sthe\sdb. +D 2024-04-22T11:48:03.633 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -606,7 +606,7 @@ F ext/wasm/api/post-js-header.js 04dc12c3edd666b64a1b4ef3b6690c88dcc653f26451fd4 F ext/wasm/api/pre-js.c-pp.js ad906703f7429590f2fbf5e6498513bf727a1a4f0ebfa057afb08161d7511219 F ext/wasm/api/sqlite3-api-cleanup.js d235ad237df6954145404305040991c72ef8b1881715d2a650dda7b3c2576d0e F ext/wasm/api/sqlite3-api-glue.js 2d35660c52dcb4bb16d00c56553d34e7caa6ad30083938b515e6f9aa0b312fbb -F ext/wasm/api/sqlite3-api-oo1.js 365b3ae01a461dc974796823652ef1ecb1a9fac5df295ee1a78002cc77afb0d8 +F ext/wasm/api/sqlite3-api-oo1.js 5b61a9ea9465d75a6086f89273778cad0c3c1794a59c23cce3363e06a1f78bfb F ext/wasm/api/sqlite3-api-prologue.js 93a72b07b2a5d964d2edc76a90b439ece49298bd7ba60a1c6ae5d4878213701e F ext/wasm/api/sqlite3-api-worker1.js 8d9c0562831f62218170a3373468d8a0b7a6503b5985e309b69bf71187b525cf F ext/wasm/api/sqlite3-license-version-header.js 0c807a421f0187e778dc1078f10d2994b915123c1223fe752b60afdcd1263f89 @@ -2184,8 +2184,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 5560df2726fed215c98d602c5f6ebbf3c5ae23f8ba1074291c509bf446fdfe66 -R ae9a50293e0c35742076bd20e79d2b4c -U drh -Z 44b0654aae70868bd62dea2cbd768897 +P e1040e51ebd04f2a076f477b6f240f849afb10f543ebe518e09d6842cc3cb38e +R c8b46c18574828a10017e60145eb2add +U stephan +Z 3fe04d60fbd968edc5f33b93665df17f # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 192803b3e3..fa166b8784 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e1040e51ebd04f2a076f477b6f240f849afb10f543ebe518e09d6842cc3cb38e \ No newline at end of file +5c505ee8a73f4b4a7053d98a12024d98340676f6ae9982311f9f88a9b46c8ae2 \ No newline at end of file From 4f2f6c74cab89f6075bc77e1ea0ba128ee8f91bf Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 22 Apr 2024 13:31:24 +0000 Subject: [PATCH 330/430] Extra robustness in the code that causes cursors to return NULL when they are participating in an OUTER JOIN. FossilOrigin-Name: 672c2869ef48e08447d37b0d76a1850cdafbe30ca1906ec98c55e3ab496fd9a6 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/where.c | 3 +-- src/wherecode.c | 12 +++++------- 4 files changed, 15 insertions(+), 18 deletions(-) diff --git a/manifest b/manifest index 53cd1299e0..c203544e0b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C For\ssqlite3.oo1.DB\sJavaScript\sclasses,\sbypass\sexecution\sof\sany\son-open()\sSQL\sin\sSEE-capable\sbuilds\sbecause\sit\swould\snecessarily\srun\sbefore\sthe\sclient\shas\san\sopportunity\sto\sprovide\stheir\sdecryption\skey,\swhich\swould\sleave\sthe\sdb\shandle\sin\san\sunusable\sstate\sand\scause\sthe\sctor\sto\sthrow.\sThis\scurrently\saffects\sonly\sthe\sOPFS\sVFSes.\sWe\smay\swant\sto\sconsider\sextending\sthe\sctor\soptions\sobject\sto\soptionally\saccept\san\sSEE\skey\sand\sapply\sit\swhen\sopening\sthe\sdb. -D 2024-04-22T11:48:03.633 +C Extra\srobustness\sin\sthe\scode\sthat\scauses\scursors\sto\sreturn\sNULL\swhen\sthey\nare\sparticipating\sin\san\sOUTER\sJOIN. +D 2024-04-22T13:31:24.188 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -835,9 +835,9 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c 887fc4ca3f020ebb2e376f222069570834ac63bf50111ef0cbf3ae417048ed89 F src/wal.h ba252daaa94f889f4b2c17c027e823d9be47ce39da1d3799886bbd51f0490452 F src/walker.c 7c7ea0115345851c3da4e04e2e239a29983b61fb5b038b94eede6aba462640e2 -F src/where.c 40ee94edd4cf31e6dc3e4c9ac814777b8cf4dc8ee985d87eb5f77bd4c42e69da +F src/where.c c6c14735091b8716763c05fb8db8b32907f4edca96ba0095bff892fbaba7f0e9 F src/whereInt.h 82a13766f13d1a53b05387c2e60726289ef26404bc7b9b1f7770204d97357fb8 -F src/wherecode.c b0224e0ec3c3c4e94cbdd221df109974a1bb26255637383f0fd81795358326fc +F src/wherecode.c 1f6940349e92a6e056aecd70163b00f331554c815c362b4cc80906c48151d73d F src/whereexpr.c 7b64295f1d82ad0928df435925dd7bbd5997b44a026153113eace0d9e71ff435 F src/window.c 5d95122dd330bfaebd732358c8ef067c5a9394a53ac249470d611d0ce2c52be2 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 @@ -2184,8 +2184,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P e1040e51ebd04f2a076f477b6f240f849afb10f543ebe518e09d6842cc3cb38e -R c8b46c18574828a10017e60145eb2add -U stephan -Z 3fe04d60fbd968edc5f33b93665df17f +P 5c505ee8a73f4b4a7053d98a12024d98340676f6ae9982311f9f88a9b46c8ae2 +R cf33b03e4c9b76c0999c9981aab311dd +U drh +Z 8e2859a20a59f6d407b535859ed9b4c0 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index fa166b8784..41b06bb769 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5c505ee8a73f4b4a7053d98a12024d98340676f6ae9982311f9f88a9b46c8ae2 \ No newline at end of file +672c2869ef48e08447d37b0d76a1850cdafbe30ca1906ec98c55e3ab496fd9a6 \ No newline at end of file diff --git a/src/where.c b/src/where.c index 93984347b7..95bea115d1 100644 --- a/src/where.c +++ b/src/where.c @@ -6948,9 +6948,8 @@ void sqlite3WhereEnd(WhereInfo *pWInfo){ assert( pSrc->pTab!=0 ); m = pSrc->pTab->nCol; sqlite3VdbeAddOp3(v, OP_Null, 0, n, n+m-1); - }else{ - sqlite3VdbeAddOp1(v, OP_NullRow, pLevel->iTabCur); } + sqlite3VdbeAddOp1(v, OP_NullRow, pLevel->iTabCur); } if( (ws & WHERE_INDEXED) || ((ws & WHERE_MULTI_OR) && pLevel->u.pCoveringIdx) diff --git a/src/wherecode.c b/src/wherecode.c index cad2293ddd..d95eae2797 100644 --- a/src/wherecode.c +++ b/src/wherecode.c @@ -2739,13 +2739,11 @@ SQLITE_NOINLINE void sqlite3WhereRightJoinLoop( v, OP_Null, 0, pRight->regResult, pRight->regResult + pRight->pSelect->pEList->nExpr-1 ); - sqlite3VdbeAddOp1(v, OP_OpenPseudo, pWInfo->a[k].iTabCur); - }else{ - sqlite3VdbeAddOp1(v, OP_NullRow, pWInfo->a[k].iTabCur); - iIdxCur = pWInfo->a[k].iIdxCur; - if( iIdxCur ){ - sqlite3VdbeAddOp1(v, OP_NullRow, iIdxCur); - } + } + sqlite3VdbeAddOp1(v, OP_NullRow, pWInfo->a[k].iTabCur); + iIdxCur = pWInfo->a[k].iIdxCur; + if( iIdxCur ){ + sqlite3VdbeAddOp1(v, OP_NullRow, iIdxCur); } } if( (pTabItem->fg.jointype & JT_LTORJ)==0 ){ From 0a42e9913b233d433bd526c4c76825d0e1785bb6 Mon Sep 17 00:00:00 2001 From: stephan Date: Mon, 22 Apr 2024 16:46:37 +0000 Subject: [PATCH 331/430] Extend the JS/WASM SEE build support by (A) filtering SEE-related bits out of the JS when not building with SEE and (B) accepting an optional key/textkey/hexkey option to the sqlite3.oo1.DB and subclass constructors to create/open SEE-encrypted databases with. Demonstrate SEE in the test app using the kvvfs. This obviates the changes made in [5c505ee8a7]. FossilOrigin-Name: 8fbda563d2f56f8dd3f695a5711e4356de79035f332270db45d4b33ed52fdfd2 --- ext/wasm/GNUmakefile | 9 +- ext/wasm/api/sqlite3-api-glue.js | 8 +- ext/wasm/api/sqlite3-api-oo1.js | 156 ++++++++++++++++++++++++++----- ext/wasm/api/sqlite3-wasm.c | 19 ++++ ext/wasm/tester1.c-pp.js | 52 ++++++++++- manifest | 22 ++--- manifest.uuid | 2 +- 7 files changed, 226 insertions(+), 42 deletions(-) diff --git a/ext/wasm/GNUmakefile b/ext/wasm/GNUmakefile index 6e7b49875f..1a119f9505 100644 --- a/ext/wasm/GNUmakefile +++ b/ext/wasm/GNUmakefile @@ -335,19 +335,26 @@ DISTCLEAN_FILES += $(bin.stripccomments) # # Note that the SQLITE_... build flags used here have NO EFFECT on the # JS/WASM build. They are solely for use with $(bin.c-pp) itself. +# +# -D... flags which should be included in all invocations should be +# appended to $(C-PP.FILTER.global). bin.c-pp := ./c-pp $(bin.c-pp): c-pp.c $(sqlite3.c) $(MAKEFILE) $(CC) -O0 -o $@ c-pp.c $(sqlite3.c) '-DCMPP_DEFAULT_DELIM="//#"' -I$(dir.top) \ -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_OMIT_DEPRECATED -DSQLITE_OMIT_UTF16 \ -DSQLITE_OMIT_SHARED_CACHE -DSQLITE_OMIT_WAL -DSQLITE_THREADSAFE=0 \ -DSQLITE_TEMP_STORE=3 +C-PP.FILTER.global ?= +ifeq (1,$(SQLITE_C_IS_SEE)) + C-PP.FILTER.global += -Denable-see +endif define C-PP.FILTER # Create $2 from $1 using $(bin.c-pp) # $1 = Input file: c-pp -f $(1).js # $2 = Output file: c-pp -o $(2).js # $3 = optional c-pp -D... flags $(2): $(1) $$(MAKEFILE) $$(bin.c-pp) - $$(bin.c-pp) -f $(1) -o $$@ $(3) + $$(bin.c-pp) -f $(1) -o $$@ $(3) $(C-PP.FILTER.global) CLEAN_FILES += $(2) endef # /end C-PP.FILTER diff --git a/ext/wasm/api/sqlite3-api-glue.js b/ext/wasm/api/sqlite3-api-glue.js index b05d7a765a..cec0a8c0af 100644 --- a/ext/wasm/api/sqlite3-api-glue.js +++ b/ext/wasm/api/sqlite3-api-glue.js @@ -329,7 +329,8 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ wasm.bindingSignatures.push(["sqlite3_normalized_sql", "string", "sqlite3_stmt*"]); } - if(wasm.exports.sqlite3_activate_see instanceof Function){ +//#if enable-see + if(wasm.exports.sqlite3_key_v2 instanceof Function){ /** This code is capable of using an SEE build but note that an SEE WASM build is generally incompatible with SEE's license @@ -346,6 +347,8 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ ["sqlite3_activate_see", undefined, "string"] ); } +//#endif enable-see + /** Functions which require BigInt (int64) support are separated from the others because we need to conditionally bind them or apply @@ -627,7 +630,8 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ ["sqlite3__wasm_vfs_create_file", "int", "sqlite3_vfs*","string","*", "int"], ["sqlite3__wasm_posix_create_file", "int", "string","*", "int"], - ["sqlite3__wasm_vfs_unlink", "int", "sqlite3_vfs*","string"] + ["sqlite3__wasm_vfs_unlink", "int", "sqlite3_vfs*","string"], + ["sqlite3__wasm_qfmt_token","string:dealloc", "string","int"] ]; /** diff --git a/ext/wasm/api/sqlite3-api-oo1.js b/ext/wasm/api/sqlite3-api-oo1.js index 06d1df43f9..a5dfcec958 100644 --- a/ext/wasm/api/sqlite3-api-oo1.js +++ b/ext/wasm/api/sqlite3-api-oo1.js @@ -87,6 +87,94 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ */ const __vfsPostOpenSql = Object.create(null); + /** + Converts ArrayBuffer or Uint8Array ba into a string of hex + digits. + */ + const byteArrayToHex = function(ba){ + if( ba instanceof ArrayBuffer ){ + ba = new Uint8Array(ba); + } + const li = []; + const digits = "0123456789abcdef"; + for( const d of ba ){ + li.push( digits[(d & 0xf0) >> 4], digits[d & 0x0f] ); + } + return li.join(''); + }; + +//#if enable-see + /** + Internal helper to apply an SEE key to a just-opened + database. Requires that db be-a DB object which has just been + opened, opt be the options object processed by its ctor, and opt + must have either the key, hexkey, or textkey properties, either + as a string, an ArrayBuffer, or a Uint8Array. + + This is a no-op in non-SEE builds. It throws on error and returns + without side effects if its key/textkey options are not of valid + types. + + Returns true if it applies the key, else a falsy value. + */ + const dbCtorApplySEEKey = function(db,opt){ + if( !capi.sqlite3_key_v2 ) return; + let keytype; + let key; + const check = (opt.key ? 1 : 0) + (opt.hexkey ? 1 : 0) + (opt.textkey ? 1 : 0); + if( !check ) return; + else if( check>1 ) toss3("Only ONE of (key, hexkey, textkey) may be provided."); + if( opt.key ){ + /* It is not legal to bind an argument to PRAGMA key=?, so we + convert it to a hexkey... */ + keytype = 'key'; + key = opt.key; + if('string'===typeof key){ + key = new TextEncoder('utf-8').encode(key); + } + if((key instanceof ArrayBuffer) || (key instanceof Uint8Array)){ + key = byteArrayToHex(key); + keytype = 'hexkey'; + }else{ + toss3("Invalid value for the 'key' option. Expecting a string, ArrayBuffer, or Uint8Array."); + return; + } + }else if( opt.textkey ){ + /* For textkey we need it to be in string form, so convert it to + a string if it's a byte array... */ + keytype = 'textkey'; + key = opt.textkey; + if(key instanceof ArrayBuffer){ + key = new Uint8Array(key); + } + if(key instanceof Uint8Array){ + key = new TextDecoder('utf-8').decode(key); + }else if('string'!==typeof key){ + toss3("Invalid value for the 'textkey' option. Expecting a string, ArrayBuffer, or Uint8Array."); + } + }else if( opt.hexkey ){ + keytype = 'hexkey'; + key = opt.hexkey; + if((key instanceof ArrayBuffer) || (key instanceof Uint8Array)){ + key = byteArrayToHex(key); + }else if('string'!==typeof key){ + toss3("Invalid value for the 'hexkey' option. Expecting a string, ArrayBuffer, or Uint8Array."); + } + /* else assume it's valid hex codes */; + }else{ + return; + } + let stmt; + try{ + stmt = db.prepare("PRAGMA "+keytype+"="+util.sqlite3__wasm_qfmt_token(key, 1)); + stmt.step(); + }finally{ + if(stmt) stmt.finalize(); + } + return true; + }; +//#endif enable-see + /** A proxy for DB class constructors. It must be called with the being-construct DB object as its "this". See the DB constructor @@ -175,28 +263,22 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ __ptrMap.set(this, pDb); __stmtMap.set(this, Object.create(null)); try{ +//#if enable-see + dbCtorApplySEEKey(this,opt); +//#endif // Check for per-VFS post-open SQL/callback... - const pVfs = capi.sqlite3_js_db_vfs(pDb); - if(!pVfs) toss3("Internal error: cannot get VFS for new db handle."); + const pVfs = capi.sqlite3_js_db_vfs(pDb) + || toss3("Internal error: cannot get VFS for new db handle."); const postInitSql = __vfsPostOpenSql[pVfs]; if(postInitSql){ - if(capi.sqlite3_activate_see){ - /** - In SEE-capable builds we have to avoid running any db - code before the client has an opportunity to apply their - decryption key. If we first run any db code, e.g. pragma - journal_mode=..., then it will fail with SQLITE_NOTADB - and the db handle will be left in an unusuable - state. Note that at this point we do not actually know - whether the db is encrypted, but if a client has gone out - of their way to create an SEE build, it seems safe to - assume that they are using the encryption. - */ - sqlite3.config.warn( - "Disabling execution of on-open() db code "+ - "because this is an SEE build. DB: "+fnJs - ); - }else if(postInitSql instanceof Function){ + /** + Reminder: if this db is encrypted and the client did _not_ pass + in the key, any init code will fail, causing the ctor to throw. + We don't actually know whether the db is encrypted, so we cannot + sensibly apply any heuristics which skip the init code only for + encrypted databases for which no key has yet been supplied. + */ + if(postInitSql instanceof Function){ postInitSql(this, sqlite3); }else{ checkSqlite3Rc( @@ -298,6 +380,20 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ - `flags`: open-mode flags - `vfs`: the VFS fname +//#if enable-see + And, for SEE-capable builds, optionally ONE of the following: + + - `key`, `hexkey`, or `textkey`: encryption key as a string, + ArrayBuffer, or Uint8Array. These flags function as documented + for the SEE pragmas of the same names. + + In non-SEE builds, these options are ignored. In SEE builds, + `PRAGMA key/textkey/hexkey=X` is executed immediately after + opening the db. If more than one of the options is provided, + or any option has an invalid argument type, an exception is + thrown. +//#endif enable-see + The `filename` and `vfs` arguments may be either JS strings or C-strings allocated via WASM. `flags` is required to be a JS string (because it's specific to this API, which is specific @@ -1562,7 +1658,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ they are larger than 32 bits, else double or int32, depending on whether they have a fractional part. Booleans are bound as integer 0 or 1. It is not expected the distinction of binding - doubles which have no fractional parts is integers is + doubles which have no fractional parts and integers is significant for the majority of clients due to sqlite3's data typing model. If [BigInt] support is enabled then this routine will bind BigInt values as 64-bit integers if they'll @@ -1946,16 +2042,26 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ Functionally equivalent to DB(storageName,'c','kvvfs') except that it throws if the given storage name is not one of 'local' or 'session'. + + As of version 3.46, the argument may optionally be an options + object in the form: + + { + filename: 'session'|'local', + ... etc. (all options supported by the DB ctor) + } + + noting that the 'vfs' option supported by main DB + constructor is ignored here: the vfs is always 'kvvfs'. */ sqlite3.oo1.JsStorageDb = function(storageName='session'){ + const opt = dbCtorHelper.normalizeArgs(...arguments); + storageName = opt.filename; if('session'!==storageName && 'local'!==storageName){ toss3("JsStorageDb db name must be one of 'session' or 'local'."); } - dbCtorHelper.call(this, { - filename: storageName, - flags: 'c', - vfs: "kvvfs" - }); + opt.vfs = 'kvvfs'; + dbCtorHelper.call(this, opt); }; const jdb = sqlite3.oo1.JsStorageDb; jdb.prototype = Object.create(DB.prototype); diff --git a/ext/wasm/api/sqlite3-wasm.c b/ext/wasm/api/sqlite3-wasm.c index cc1db6723a..d315b43d6b 100644 --- a/ext/wasm/api/sqlite3-wasm.c +++ b/ext/wasm/api/sqlite3-wasm.c @@ -1678,6 +1678,25 @@ int sqlite3__wasm_config_j(int op, sqlite3_int64 arg){ return sqlite3_config(op, arg); } +/* +** This function is NOT part of the sqlite3 public API. It is strictly +** for use by the sqlite project's own JS/WASM bindings. +** +** If z is not NULL, returns the result of passing z to +** sqlite3_mprintf()'s %Q modifier (if addQuotes is true) or %q (if +** addQuotes is 0). Returns NULL if z is NULL or on OOM. +*/ +SQLITE_WASM_EXPORT +char * sqlite3__wasm_qfmt_token(char *z, int addQuotes){ + char * rc = 0; + if( z ){ + rc = addQuotes + ? sqlite3_mprintf("%Q", z) + : sqlite3_mprintf("%q", z); + } + return rc; +} + #if 0 // Pending removal after verification of a workaround discussed in the // forum post linked to below. diff --git a/ext/wasm/tester1.c-pp.js b/ext/wasm/tester1.c-pp.js index fdde986355..e78897bedf 100644 --- a/ext/wasm/tester1.c-pp.js +++ b/ext/wasm/tester1.c-pp.js @@ -1482,7 +1482,7 @@ globalThis.sqlite3InitModule = sqlite3InitModule; /*step() skipped intentionally*/.reset(true); } finally { T.assert(0===st.finalize()) - .assert(undefined===st.finalize()); + .assert(undefined===st.finalize()); } try { @@ -2587,7 +2587,7 @@ globalThis.sqlite3InitModule = sqlite3InitModule; const pVfs = capi.sqlite3_vfs_find('kvvfs'); T.assert(pVfs); const JDb = this.JDb = sqlite3.oo1.JsStorageDb; - const unlink = this.kvvfsUnlink = ()=>{JDb.clearStorage(filename)}; + const unlink = this.kvvfsUnlink = ()=>JDb.clearStorage(this.kvvfsDbFile); unlink(); let db = new JDb(filename); try { @@ -2605,6 +2605,54 @@ globalThis.sqlite3InitModule = sqlite3InitModule; } } }/*kvvfs sanity checks*/) +//#if enable-see + .t({ + name: 'kvvfs with SEE encryption', + predicate: ()=>(isUIThread() + || "Only available in main thread."), + test: function(sqlite3){ + this.kvvfsUnlink(); + let db; + try{ + db = new this.JDb({ + filename: this.kvvfsDbFile, + key: 'foo' + }); + db.exec([ + "create table t(a,b);", + "insert into t(a,b) values(1,2),(3,4)" + ]); + db.close(); + let err; + try{ + db = new this.JDb({ + filename: this.kvvfsDbFile, + flags: 'ct' + }); + T.assert(db) /* opening is fine, but... */; + db.exec("select 1 from sqlite_schema"); + console.warn("sessionStorage =",sessionStorage); + }catch(e){ + err = e; + }finally{ + db.close(); + } + T.assert(err,"Expecting an exception") + .assert(sqlite3.capi.SQLITE_NOTADB==err.resultCode, + "Expecting NOTADB"); + db = new sqlite3.oo1.DB({ + filename: this.kvvfsDbFile, + vfs: 'kvvfs', + hexkey: new Uint8Array([0x66,0x6f,0x6f]) // equivalent: '666f6f' + }); + T.assert( 4===db.selectValue('select sum(a) from t') ); + }finally{ + if( db ) db.close(); + this.kvvfsUnlink(); + } + } + })/*kvvfs with SEE*/ +//#endif enable-see ;/* end kvvfs tests */ //////////////////////////////////////////////////////////////////////// diff --git a/manifest b/manifest index c203544e0b..a0cb0217b3 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Extra\srobustness\sin\sthe\scode\sthat\scauses\scursors\sto\sreturn\sNULL\swhen\sthey\nare\sparticipating\sin\san\sOUTER\sJOIN. -D 2024-04-22T13:31:24.188 +C Extend\sthe\sJS/WASM\sSEE\sbuild\ssupport\sby\s(A)\sfiltering\sSEE-related\sbits\sout\sof\sthe\sJS\swhen\snot\sbuilding\swith\sSEE\sand\s(B)\saccepting\san\soptional\skey/textkey/hexkey\soption\sto\sthe\ssqlite3.oo1.DB\sand\ssubclass\sconstructors\sto\screate/open\sSEE-encrypted\sdatabases\swith.\sDemonstrate\sSEE\sin\sthe\stest\sapp\susing\sthe\skvvfs.\sThis\sobviates\sthe\schanges\smade\sin\s[5c505ee8a7]. +D 2024-04-22T16:46:37.381 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -587,7 +587,7 @@ F ext/userauth/sqlite3userauth.h 7f3ea8c4686db8e40b0a0e7a8e0b00fac13aa7a3 F ext/userauth/user-auth.txt ca7e9ee82ca4e1c1744295f8184dd70edfae1992865d26c64303f539eb6c084c F ext/userauth/userauth.c 7f00cded7dcaa5d47f54539b290a43d2e59f4b1eb5f447545fa865f002fc80cb F ext/wasm/EXPORTED_FUNCTIONS.fiddle.in 27450c8b8c70875a260aca55435ec927068b34cef801a96205adb81bdcefc65c -F ext/wasm/GNUmakefile 4bb4cf70a8153dd5b5fee17d724075c54174da630b424bbcf48c744633396f62 +F ext/wasm/GNUmakefile 0d5ccc8a4814716c1c789bb3069dd4d71d5ef0a97bbea074ac182fbfb85a3ca8 F ext/wasm/README-dist.txt 6382cb9548076fca472fb3330bbdba3a55c1ea0b180ff9253f084f07ff383576 F ext/wasm/README.md a8a2962c3aebdf8d2104a9102e336c5554e78fc6072746e5daf9c61514e7d193 F ext/wasm/SQLTester/GNUmakefile e0794f676d55819951bbfae45cc5e8d7818dc460492dc317ce7f0d2eca15caff @@ -605,8 +605,8 @@ F ext/wasm/api/post-js-footer.js cd0a8ec768501d9bd45d325ab0442037fb0e33d1f3b4f08 F ext/wasm/api/post-js-header.js 04dc12c3edd666b64a1b4ef3b6690c88dcc653f26451fd4734472d8e29c1c122 F ext/wasm/api/pre-js.c-pp.js ad906703f7429590f2fbf5e6498513bf727a1a4f0ebfa057afb08161d7511219 F ext/wasm/api/sqlite3-api-cleanup.js d235ad237df6954145404305040991c72ef8b1881715d2a650dda7b3c2576d0e -F ext/wasm/api/sqlite3-api-glue.js 2d35660c52dcb4bb16d00c56553d34e7caa6ad30083938b515e6f9aa0b312fbb -F ext/wasm/api/sqlite3-api-oo1.js 5b61a9ea9465d75a6086f89273778cad0c3c1794a59c23cce3363e06a1f78bfb +F ext/wasm/api/sqlite3-api-glue.js c744f4b919e1254c898b467573858671a1c8797c2490d0eca2fdbadf2d0ac74b +F ext/wasm/api/sqlite3-api-oo1.js 708934dd9919863bb67e2a54ba6604b05835ba3779d4dc4486218c8512eb0771 F ext/wasm/api/sqlite3-api-prologue.js 93a72b07b2a5d964d2edc76a90b439ece49298bd7ba60a1c6ae5d4878213701e F ext/wasm/api/sqlite3-api-worker1.js 8d9c0562831f62218170a3373468d8a0b7a6503b5985e309b69bf71187b525cf F ext/wasm/api/sqlite3-license-version-header.js 0c807a421f0187e778dc1078f10d2994b915123c1223fe752b60afdcd1263f89 @@ -615,7 +615,7 @@ F ext/wasm/api/sqlite3-vfs-helper.c-pp.js 3f828cc66758acb40e9c5b4dcfd87fd478a14c F ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js 8433ee332d5f5e39fb19427fccb7bad7f44aa99b5504daad3343fc128c311e78 F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js 3c72f1a0e6a7343c8c882d29d01bb440f10be12c844651605b486e76f3d6cc8c F ext/wasm/api/sqlite3-vtab-helper.c-pp.js a2fcbc3fecdd0eea229283584ebc122f29d98194083675dbe5cb2cf3a17fe309 -F ext/wasm/api/sqlite3-wasm.c afba6827a49151b564af5cf588a6bbd0401b16ef5cbe3269c66f676fee9ca92c +F ext/wasm/api/sqlite3-wasm.c 3f744dc45ac4be8125d58364448bdc9c082f332a88cec211bfd0143ad0acb373 F ext/wasm/api/sqlite3-worker1-promiser.c-pp.js bd89edfe42a4d7122a6d6d405c5423cf00aabba1f76f6ea8e2dba9c628ddd91a F ext/wasm/api/sqlite3-worker1.c-pp.js 5e8706c2c4af2a57fbcdc02f4e7ef79869971bc21bb8ede777687786ce1c92d5 F ext/wasm/batch-runner-sahpool.html e9a38fdeb36a13eac7b50241dfe7ae066fe3f51f5c0b0151e7baee5fce0d07a7 @@ -662,7 +662,7 @@ F ext/wasm/test-opfs-vfs.html 1f2d672f3f3fce810dfd48a8d56914aba22e45c6834e262555 F ext/wasm/test-opfs-vfs.js 1618670e466f424aa289859fe0ec8ded223e42e9e69b5c851f809baaaca1a00c F ext/wasm/tester1-worker.html ebc4b820a128963afce328ecf63ab200bd923309eb939f4110510ab449e9814c F ext/wasm/tester1.c-pp.html 1c1bc78b858af2019e663b1a31e76657b73dc24bede28ca92fbe917c3a972af2 -F ext/wasm/tester1.c-pp.js 18331ec28d7e63c8e262a9872a8da3964d37b7ac22eabe0016af93f3c6f74cc4 +F ext/wasm/tester1.c-pp.js 9f8ae7c716ad66523cd6238fe947826c82b6a3b5c1e9d528f9f39ad9c9280ac7 F ext/wasm/tests/opfs/concurrency/index.html 0802373d57034d51835ff6041cda438c7a982deea6079efd98098d3e42fbcbc1 F ext/wasm/tests/opfs/concurrency/test.js a98016113eaf71e81ddbf71655aa29b0fed9a8b79a3cdd3620d1658eb1cc9a5d F ext/wasm/tests/opfs/concurrency/worker.js 0a8c1a3e6ebb38aabbee24f122693f1fb29d599948915c76906681bb7da1d3d2 @@ -2184,8 +2184,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 5c505ee8a73f4b4a7053d98a12024d98340676f6ae9982311f9f88a9b46c8ae2 -R cf33b03e4c9b76c0999c9981aab311dd -U drh -Z 8e2859a20a59f6d407b535859ed9b4c0 +P 672c2869ef48e08447d37b0d76a1850cdafbe30ca1906ec98c55e3ab496fd9a6 +R 69f9c602594d1ff3e9a25e02a2d41151 +U stephan +Z 6ab53eec83d52fe93f0c77e2c64383e8 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 41b06bb769..61afb9adfe 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -672c2869ef48e08447d37b0d76a1850cdafbe30ca1906ec98c55e3ab496fd9a6 \ No newline at end of file +8fbda563d2f56f8dd3f695a5711e4356de79035f332270db45d4b33ed52fdfd2 \ No newline at end of file From 5d8daf184d94e86695f45ea8b8b37e9517f7b000 Mon Sep 17 00:00:00 2001 From: stephan Date: Mon, 22 Apr 2024 17:03:52 +0000 Subject: [PATCH 332/430] Minor cleanups to [8fbda563d2f5]. FossilOrigin-Name: 5ee2594b657b96aea9e482a175820dcbacfa9298da45b38cf17f39ad076d3f7f --- ext/wasm/api/sqlite3-api-oo1.js | 12 +++++++++--- ext/wasm/tester1.c-pp.js | 10 ++++++++-- manifest | 14 +++++++------- manifest.uuid | 2 +- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/ext/wasm/api/sqlite3-api-oo1.js b/ext/wasm/api/sqlite3-api-oo1.js index a5dfcec958..b225d80b96 100644 --- a/ext/wasm/api/sqlite3-api-oo1.js +++ b/ext/wasm/api/sqlite3-api-oo1.js @@ -87,6 +87,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ */ const __vfsPostOpenSql = Object.create(null); +//#if enable-see /** Converts ArrayBuffer or Uint8Array ba into a string of hex digits. @@ -103,7 +104,6 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ return li.join(''); }; -//#if enable-see /** Internal helper to apply an SEE key to a just-opened database. Requires that db be-a DB object which has just been @@ -160,7 +160,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ }else if('string'!==typeof key){ toss3("Invalid value for the 'hexkey' option. Expecting a string, ArrayBuffer, or Uint8Array."); } - /* else assume it's valid hex codes */; + /* else assume it's valid hex codes */ }else{ return; } @@ -385,7 +385,13 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ - `key`, `hexkey`, or `textkey`: encryption key as a string, ArrayBuffer, or Uint8Array. These flags function as documented - for the SEE pragmas of the same names. + for the SEE pragmas of the same names. Using a byte array for + `hexkey` is equivalent to the same series of hex codes in + string form, so '666f6f' is equivalent to + Uint8Array([0x66,0x6f,0x6f]). A `textkey` byte array is assumed + to be UTF-8. A `key` string is transformed into a UTF-8 byte + array, and a `key` byte array is transformed into a `hexkey` + with the same bytes. In non-SEE builds, these options are ignored. In SEE builds, `PRAGMA key/textkey/hexkey=X` is executed immediately after diff --git a/ext/wasm/tester1.c-pp.js b/ext/wasm/tester1.c-pp.js index e78897bedf..fe5bdc8372 100644 --- a/ext/wasm/tester1.c-pp.js +++ b/ext/wasm/tester1.c-pp.js @@ -2613,10 +2613,16 @@ globalThis.sqlite3InitModule = sqlite3InitModule; test: function(sqlite3){ this.kvvfsUnlink(); let db; + const encOpt1 = 1 + ? {textkey: 'foo'} + : {key: 'foo'}; + const encOpt2 = encOpt1.textkey + ? encOpt1 + : {hexkey: new Uint8Array([0x66,0x6f,0x6f]/*==>"foo"*/)} try{ db = new this.JDb({ filename: this.kvvfsDbFile, - key: 'foo' + ...encOpt1 }); db.exec([ "create table t(a,b);", @@ -2643,7 +2649,7 @@ globalThis.sqlite3InitModule = sqlite3InitModule; db = new sqlite3.oo1.DB({ filename: this.kvvfsDbFile, vfs: 'kvvfs', - hexkey: new Uint8Array([0x66,0x6f,0x6f]) // equivalent: '666f6f' + ...encOpt2 }); T.assert( 4===db.selectValue('select sum(a) from t') ); }finally{ diff --git a/manifest b/manifest index a0cb0217b3..4c968dedd4 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Extend\sthe\sJS/WASM\sSEE\sbuild\ssupport\sby\s(A)\sfiltering\sSEE-related\sbits\sout\sof\sthe\sJS\swhen\snot\sbuilding\swith\sSEE\sand\s(B)\saccepting\san\soptional\skey/textkey/hexkey\soption\sto\sthe\ssqlite3.oo1.DB\sand\ssubclass\sconstructors\sto\screate/open\sSEE-encrypted\sdatabases\swith.\sDemonstrate\sSEE\sin\sthe\stest\sapp\susing\sthe\skvvfs.\sThis\sobviates\sthe\schanges\smade\sin\s[5c505ee8a7]. -D 2024-04-22T16:46:37.381 +C Minor\scleanups\sto\s[8fbda563d2f5]. +D 2024-04-22T17:03:52.050 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -606,7 +606,7 @@ F ext/wasm/api/post-js-header.js 04dc12c3edd666b64a1b4ef3b6690c88dcc653f26451fd4 F ext/wasm/api/pre-js.c-pp.js ad906703f7429590f2fbf5e6498513bf727a1a4f0ebfa057afb08161d7511219 F ext/wasm/api/sqlite3-api-cleanup.js d235ad237df6954145404305040991c72ef8b1881715d2a650dda7b3c2576d0e F ext/wasm/api/sqlite3-api-glue.js c744f4b919e1254c898b467573858671a1c8797c2490d0eca2fdbadf2d0ac74b -F ext/wasm/api/sqlite3-api-oo1.js 708934dd9919863bb67e2a54ba6604b05835ba3779d4dc4486218c8512eb0771 +F ext/wasm/api/sqlite3-api-oo1.js 7a7828c2748d60664f155821fab2d091db23399e64f3470ea14f52080d3573f7 F ext/wasm/api/sqlite3-api-prologue.js 93a72b07b2a5d964d2edc76a90b439ece49298bd7ba60a1c6ae5d4878213701e F ext/wasm/api/sqlite3-api-worker1.js 8d9c0562831f62218170a3373468d8a0b7a6503b5985e309b69bf71187b525cf F ext/wasm/api/sqlite3-license-version-header.js 0c807a421f0187e778dc1078f10d2994b915123c1223fe752b60afdcd1263f89 @@ -662,7 +662,7 @@ F ext/wasm/test-opfs-vfs.html 1f2d672f3f3fce810dfd48a8d56914aba22e45c6834e262555 F ext/wasm/test-opfs-vfs.js 1618670e466f424aa289859fe0ec8ded223e42e9e69b5c851f809baaaca1a00c F ext/wasm/tester1-worker.html ebc4b820a128963afce328ecf63ab200bd923309eb939f4110510ab449e9814c F ext/wasm/tester1.c-pp.html 1c1bc78b858af2019e663b1a31e76657b73dc24bede28ca92fbe917c3a972af2 -F ext/wasm/tester1.c-pp.js 9f8ae7c716ad66523cd6238fe947826c82b6a3b5c1e9d528f9f39ad9c9280ac7 +F ext/wasm/tester1.c-pp.js 6d0a9aa44a97b4aadd582e0999ce45a2671b854a12ea3205d1c908da6bd4bdef F ext/wasm/tests/opfs/concurrency/index.html 0802373d57034d51835ff6041cda438c7a982deea6079efd98098d3e42fbcbc1 F ext/wasm/tests/opfs/concurrency/test.js a98016113eaf71e81ddbf71655aa29b0fed9a8b79a3cdd3620d1658eb1cc9a5d F ext/wasm/tests/opfs/concurrency/worker.js 0a8c1a3e6ebb38aabbee24f122693f1fb29d599948915c76906681bb7da1d3d2 @@ -2184,8 +2184,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 672c2869ef48e08447d37b0d76a1850cdafbe30ca1906ec98c55e3ab496fd9a6 -R 69f9c602594d1ff3e9a25e02a2d41151 +P 8fbda563d2f56f8dd3f695a5711e4356de79035f332270db45d4b33ed52fdfd2 +R 0674b1f5ea56f016fc52480ad40ed87d U stephan -Z 6ab53eec83d52fe93f0c77e2c64383e8 +Z 40a1a10b8d303ee230e900a2b2af4afd # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 61afb9adfe..049eae30ae 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8fbda563d2f56f8dd3f695a5711e4356de79035f332270db45d4b33ed52fdfd2 \ No newline at end of file +5ee2594b657b96aea9e482a175820dcbacfa9298da45b38cf17f39ad076d3f7f \ No newline at end of file From 46435a04fd295e325f7d25839abd85be49d1d6d2 Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 22 Apr 2024 20:09:17 +0000 Subject: [PATCH 333/430] Add extra tests for aborting conflicts in the sessions module. FossilOrigin-Name: b4a6d32662acacb7767cfb9b8e040e6eb1f99322cb7d0cd44e6265e9ac2fb2e8 --- ext/session/sessionconflict.test | 75 ++++++++++++++++++++++++++++++++ manifest | 13 +++--- manifest.uuid | 2 +- 3 files changed, 83 insertions(+), 7 deletions(-) create mode 100644 ext/session/sessionconflict.test diff --git a/ext/session/sessionconflict.test b/ext/session/sessionconflict.test new file mode 100644 index 0000000000..c842a8aacb --- /dev/null +++ b/ext/session/sessionconflict.test @@ -0,0 +1,75 @@ +# 2011 March 07 +# +# 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 sessionconflict + +sqlite3_shutdown +test_sqlite3_log log +proc log {code msg} { puts "LOG $code $msg" } +sqlite3 db test.db + +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_execsql_test -db db2 1.1 { + INSERT INTO t1 VALUES(6, 6, 6); +} + +proc xConflict {args} { + return "ABORT" +} + + +do_test 1.2 { + set chng [changeset_from_sql { + UPDATE t1 SET b=10, c=10 WHERE a=1; + UPDATE t1 SET b=444 WHERE a=2; + INSERT INTO t1 VALUES(4, 4, 4); + INSERT INTO t1 VALUES(5, 5, 5); + INSERT INTO t1 VALUES(6, 6, 6); + }] + + execsql BEGIN db2 + set res [list [catch { sqlite3changeset_apply db2 $chng xConflict } msg] $msg] + execsql ROLLBACK db2 + set res +} {1 SQLITE_ABORT} + +do_execsql_test -db db2 1.3 { + SELECT * FROM t1; +} { + 1 1 1 + 2 2 2 + 3 3 3 + 6 6 6 +} + + + +finish_test diff --git a/manifest b/manifest index 4c968dedd4..f00e2d54f5 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Minor\scleanups\sto\s[8fbda563d2f5]. -D 2024-04-22T17:03:52.050 +C Add\sextra\stests\sfor\saborting\sconflicts\sin\sthe\ssessions\smodule. +D 2024-04-22T20:09:17.153 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -566,6 +566,7 @@ F ext/session/session_speed_test.c dcf0ef58d76b70c8fbd9eab3be77cf9deb8bc1638fed8 F ext/session/sessionalter.test 460bdac2832a550519f6bc32e5db2c0cee94f335870aaf25a3a403a81ab20e17 F ext/session/sessionat.test 00c8badb35e43a2f12a716d2734a44d614ff62361979b6b85419035bc04b45ee F ext/session/sessionbig.test 47c381e7acfabeef17d98519a3080d69151723354d220afa2053852182ca7adf +F ext/session/sessionconflict.test 28890457bb90457be772d3067cdb5f78db9b51d997e4f3d09f22cddc9be80a38 F ext/session/sessiondiff.test ad13dd65664bae26744e1f18eb3cbd5588349b7e9118851d8f9364248d67bcec F ext/session/sessionfault.test 573bf027fb870d57bd4e7cf50822a3e4b17b2b923407438747aaa918dec57a09 F ext/session/sessionfault2.test b0d6a7c1d7398a7e800d84657404909c7d385965ea8576dc79ed344c46fbf41c @@ -2184,8 +2185,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 8fbda563d2f56f8dd3f695a5711e4356de79035f332270db45d4b33ed52fdfd2 -R 0674b1f5ea56f016fc52480ad40ed87d -U stephan -Z 40a1a10b8d303ee230e900a2b2af4afd +P 5ee2594b657b96aea9e482a175820dcbacfa9298da45b38cf17f39ad076d3f7f +R 95bcc3fd0d6dba3139788e0776ab3daa +U dan +Z c4a19dd969db970154ebbee1de10bace # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 049eae30ae..89e87de37d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5ee2594b657b96aea9e482a175820dcbacfa9298da45b38cf17f39ad076d3f7f \ No newline at end of file +b4a6d32662acacb7767cfb9b8e040e6eb1f99322cb7d0cd44e6265e9ac2fb2e8 \ No newline at end of file From 6e6dfd6a236396b58b06d7636233f7687eea37b2 Mon Sep 17 00:00:00 2001 From: stephan Date: Tue, 23 Apr 2024 05:38:49 +0000 Subject: [PATCH 334/430] When running the 'dist' target in ext/wasm for an SEE-capable build, ensure that the resulting zip file and directory name include '-see'. FossilOrigin-Name: 04c552b12e3b77b9dfd83838d35ce19a37ed024a8c18a2000ada10cf3d1eb6ad --- ext/wasm/dist.make | 9 +++++++-- manifest | 14 +++++++------- manifest.uuid | 2 +- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/ext/wasm/dist.make b/ext/wasm/dist.make index 0ea53063b4..e820e066d4 100644 --- a/ext/wasm/dist.make +++ b/ext/wasm/dist.make @@ -19,10 +19,15 @@ MAKEFILE.dist := $(lastword $(MAKEFILE_LIST)) # built, and won't be built until we expand the dependencies. Thus we # have to use a temporary name for the archive until we can get # that binary built. +ifeq (1,$(SQLITE_C_IS_SEE)) +dist-name-extra := -see +else +dist-name-extra := +endif ifeq (,$(filter snapshot,$(MAKECMDGOALS))) -dist-name-prefix := sqlite-wasm +dist-name-prefix := sqlite-wasm$(dist-name-extra) else -dist-name-prefix := sqlite-wasm-snapshot-$(shell /usr/bin/date +%Y%m%d) +dist-name-prefix := sqlite-wasm$(dist-name-extra)-snapshot-$(shell /usr/bin/date +%Y%m%d) endif dist-name := $(dist-name-prefix)-TEMP diff --git a/manifest b/manifest index f00e2d54f5..7b3f6096ff 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sextra\stests\sfor\saborting\sconflicts\sin\sthe\ssessions\smodule. -D 2024-04-22T20:09:17.153 +C When\srunning\sthe\s'dist'\starget\sin\sext/wasm\sfor\san\sSEE-capable\sbuild,\sensure\sthat\sthe\sresulting\szip\sfile\sand\sdirectory\sname\sinclude\s'-see'. +D 2024-04-23T05:38:49.383 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -637,7 +637,7 @@ F ext/wasm/demo-worker1-promiser.c-pp.html 635cf90685805e21772a5f7a35d1ace80f98a F ext/wasm/demo-worker1-promiser.c-pp.js fcc628cb42fcfaf07d250477801de1e6deb1e319d003976612a0db8d76b9fccc F ext/wasm/demo-worker1.html 2c178c1890a2beb5a5fecb1453e796d067a4b8d3d2a04d65ca2eb1ab2c68ef5d F ext/wasm/demo-worker1.js 836bece8615b17b1b572584f7b15912236a5947fe8c68b98d2737d7e287447ef -F ext/wasm/dist.make f2ce42305268fe33d4b50f6e4bb3daf4a60302a90736eee382f1b8af9ff32ec1 +F ext/wasm/dist.make 653e212c1e84aa3be168d62a10616ccea45ee9585b0192745d2706707a5248ce F ext/wasm/example_extra_init.c 2347cd69d19d839ef4e5e77b7855103a7fe3ef2af86f2e8c95839afd8b05862f F ext/wasm/fiddle.make 3c2eace29255d6ddd219f5d8cc2728cb28b9fe717ea80b6062c2a6178947a16b F ext/wasm/fiddle/emscripten.css 3d253a6fdb8983a2ac983855bfbdd4b6fa1ff267c28d69513dd6ef1f289ada3f @@ -2185,8 +2185,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 5ee2594b657b96aea9e482a175820dcbacfa9298da45b38cf17f39ad076d3f7f -R 95bcc3fd0d6dba3139788e0776ab3daa -U dan -Z c4a19dd969db970154ebbee1de10bace +P b4a6d32662acacb7767cfb9b8e040e6eb1f99322cb7d0cd44e6265e9ac2fb2e8 +R 7804df285b1889ac6d0dbfb4c36fb69b +U stephan +Z 47a1361c4075358585b8d5f5c90006b4 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 89e87de37d..a235332cd6 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b4a6d32662acacb7767cfb9b8e040e6eb1f99322cb7d0cd44e6265e9ac2fb2e8 \ No newline at end of file +04c552b12e3b77b9dfd83838d35ce19a37ed024a8c18a2000ada10cf3d1eb6ad \ No newline at end of file From 642e950e637beaa6699db78f3c12f1bceae924b4 Mon Sep 17 00:00:00 2001 From: stephan Date: Tue, 23 Apr 2024 06:36:28 +0000 Subject: [PATCH 335/430] Minor touchups in JS docs and exception messages. FossilOrigin-Name: 9e7fc9370dfca121244f7a2941e8de629b277f1799f8de08a43ff1d86f94b6f5 --- ext/wasm/api/sqlite3-api-oo1.js | 46 ++++++++++++++++++++-------- ext/wasm/api/sqlite3-api-prologue.js | 2 +- manifest | 14 ++++----- manifest.uuid | 2 +- 4 files changed, 42 insertions(+), 22 deletions(-) diff --git a/ext/wasm/api/sqlite3-api-oo1.js b/ext/wasm/api/sqlite3-api-oo1.js index b225d80b96..8cd50a14bb 100644 --- a/ext/wasm/api/sqlite3-api-oo1.js +++ b/ext/wasm/api/sqlite3-api-oo1.js @@ -112,10 +112,11 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ as a string, an ArrayBuffer, or a Uint8Array. This is a no-op in non-SEE builds. It throws on error and returns - without side effects if its key/textkey options are not of valid - types. + without side effects if none of the key/textkey/hexkey options + are set. It throws if more than one is set or if any are set to + values of an invalid type. - Returns true if it applies the key, else a falsy value. + Returns true if it applies the key, else an unspecified falsy value. */ const dbCtorApplySEEKey = function(db,opt){ if( !capi.sqlite3_key_v2 ) return; @@ -123,7 +124,10 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ let key; const check = (opt.key ? 1 : 0) + (opt.hexkey ? 1 : 0) + (opt.textkey ? 1 : 0); if( !check ) return; - else if( check>1 ) toss3("Only ONE of (key, hexkey, textkey) may be provided."); + else if( check>1 ){ + toss3(capi.SQLITE_MISUSE, + "Only ONE of (key, hexkey, textkey) may be provided."); + } if( opt.key ){ /* It is not legal to bind an argument to PRAGMA key=?, so we convert it to a hexkey... */ @@ -136,7 +140,9 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ key = byteArrayToHex(key); keytype = 'hexkey'; }else{ - toss3("Invalid value for the 'key' option. Expecting a string, ArrayBuffer, or Uint8Array."); + toss3(capi.SQLITE_MISUSE, + "Invalid value for the 'key' option. Expecting a string,", + "ArrayBuffer, or Uint8Array."); return; } }else if( opt.textkey ){ @@ -150,7 +156,9 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ if(key instanceof Uint8Array){ key = new TextDecoder('utf-8').decode(key); }else if('string'!==typeof key){ - toss3("Invalid value for the 'textkey' option. Expecting a string, ArrayBuffer, or Uint8Array."); + toss3(capi.SQLITE_MISUSE, + "Invalid value for the 'textkey' option. Expecting a string,", + "ArrayBuffer, or Uint8Array."); } }else if( opt.hexkey ){ keytype = 'hexkey'; @@ -158,7 +166,9 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ if((key instanceof ArrayBuffer) || (key instanceof Uint8Array)){ key = byteArrayToHex(key); }else if('string'!==typeof key){ - toss3("Invalid value for the 'hexkey' option. Expecting a string, ArrayBuffer, or Uint8Array."); + toss3(capi.SQLITE_MISUSE, + "Invalid value for the 'hexkey' option. Expecting a string,", + "ArrayBuffer, or Uint8Array."); } /* else assume it's valid hex codes */ }else{ @@ -381,23 +391,33 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ - `vfs`: the VFS fname //#if enable-see - And, for SEE-capable builds, optionally ONE of the following: + + SEE-capable builds optionally support ONE of the following + additional options: - `key`, `hexkey`, or `textkey`: encryption key as a string, ArrayBuffer, or Uint8Array. These flags function as documented for the SEE pragmas of the same names. Using a byte array for `hexkey` is equivalent to the same series of hex codes in - string form, so '666f6f' is equivalent to - Uint8Array([0x66,0x6f,0x6f]). A `textkey` byte array is assumed - to be UTF-8. A `key` string is transformed into a UTF-8 byte - array, and a `key` byte array is transformed into a `hexkey` - with the same bytes. + string form, so `'666f6f'` is equivalent to + `Uint8Array([0x66,0x6f,0x6f])`. A `textkey` byte array is + assumed to be UTF-8. A `key` string is transformed into a UTF-8 + byte array, and a `key` byte array is transformed into a + `hexkey` with the same bytes. In non-SEE builds, these options are ignored. In SEE builds, `PRAGMA key/textkey/hexkey=X` is executed immediately after opening the db. If more than one of the options is provided, or any option has an invalid argument type, an exception is thrown. + + Note that some DB subclasses may run post-initialization SQL + code, e.g. to set a busy-handler timeout or tweak the page cache + size. Such code is run _after_ the SEE key is applied. If no key + is supplied and the database is encrypted, execution of the + post-initialization SQL will fail, causing the constructor to + throw. + //#endif enable-see The `filename` and `vfs` arguments may be either JS strings or diff --git a/ext/wasm/api/sqlite3-api-prologue.js b/ext/wasm/api/sqlite3-api-prologue.js index c3cc25f43a..849dfe10f2 100644 --- a/ext/wasm/api/sqlite3-api-prologue.js +++ b/ext/wasm/api/sqlite3-api-prologue.js @@ -245,7 +245,7 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap( The exception's message is created by concatenating its arguments with a space between each, except for the - two-args-with-an-objec form and that the first argument will + two-args-with-an-object form and that the first argument will get coerced to a string, as described above, if it's an integer. diff --git a/manifest b/manifest index 7b3f6096ff..59bddf164c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C When\srunning\sthe\s'dist'\starget\sin\sext/wasm\sfor\san\sSEE-capable\sbuild,\sensure\sthat\sthe\sresulting\szip\sfile\sand\sdirectory\sname\sinclude\s'-see'. -D 2024-04-23T05:38:49.383 +C Minor\stouchups\sin\sJS\sdocs\sand\sexception\smessages. +D 2024-04-23T06:36:28.862 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -607,8 +607,8 @@ F ext/wasm/api/post-js-header.js 04dc12c3edd666b64a1b4ef3b6690c88dcc653f26451fd4 F ext/wasm/api/pre-js.c-pp.js ad906703f7429590f2fbf5e6498513bf727a1a4f0ebfa057afb08161d7511219 F ext/wasm/api/sqlite3-api-cleanup.js d235ad237df6954145404305040991c72ef8b1881715d2a650dda7b3c2576d0e F ext/wasm/api/sqlite3-api-glue.js c744f4b919e1254c898b467573858671a1c8797c2490d0eca2fdbadf2d0ac74b -F ext/wasm/api/sqlite3-api-oo1.js 7a7828c2748d60664f155821fab2d091db23399e64f3470ea14f52080d3573f7 -F ext/wasm/api/sqlite3-api-prologue.js 93a72b07b2a5d964d2edc76a90b439ece49298bd7ba60a1c6ae5d4878213701e +F ext/wasm/api/sqlite3-api-oo1.js 40f6834314b60e636f0046a9c49b8566a992dcf04be9ea593e680c23f6984b2b +F ext/wasm/api/sqlite3-api-prologue.js 34457b25dcf0005c81d76f011f207026ec164f6ff0f69f024b608025ca808ea9 F ext/wasm/api/sqlite3-api-worker1.js 8d9c0562831f62218170a3373468d8a0b7a6503b5985e309b69bf71187b525cf F ext/wasm/api/sqlite3-license-version-header.js 0c807a421f0187e778dc1078f10d2994b915123c1223fe752b60afdcd1263f89 F ext/wasm/api/sqlite3-opfs-async-proxy.js 196ad83d36ca794e564044788c9d21b964679d63cad865f604da37c4afc9a285 @@ -2185,8 +2185,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P b4a6d32662acacb7767cfb9b8e040e6eb1f99322cb7d0cd44e6265e9ac2fb2e8 -R 7804df285b1889ac6d0dbfb4c36fb69b +P 04c552b12e3b77b9dfd83838d35ce19a37ed024a8c18a2000ada10cf3d1eb6ad +R ed22115253110bc0abaf81953307bf22 U stephan -Z 47a1361c4075358585b8d5f5c90006b4 +Z 8b53fb3b4d609195342a0ce669cacf2a # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index a235332cd6..0b66f11a13 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -04c552b12e3b77b9dfd83838d35ce19a37ed024a8c18a2000ada10cf3d1eb6ad \ No newline at end of file +9e7fc9370dfca121244f7a2941e8de629b277f1799f8de08a43ff1d86f94b6f5 \ No newline at end of file From 3ac612dd7d242c5ed0d23000b7cb212e75a10874 Mon Sep 17 00:00:00 2001 From: stephan Date: Tue, 23 Apr 2024 06:49:47 +0000 Subject: [PATCH 336/430] Remove some dead WASM-side code. FossilOrigin-Name: 0a07ee27bd6021a6fc1d81133012592351530ffcf6ae09322ea74624cff910df --- ext/wasm/api/sqlite3-wasm.c | 30 ------------------------------ manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 7 insertions(+), 37 deletions(-) diff --git a/ext/wasm/api/sqlite3-wasm.c b/ext/wasm/api/sqlite3-wasm.c index d315b43d6b..48ae2297ad 100644 --- a/ext/wasm/api/sqlite3-wasm.c +++ b/ext/wasm/api/sqlite3-wasm.c @@ -1697,36 +1697,6 @@ char * sqlite3__wasm_qfmt_token(char *z, int addQuotes){ return rc; } -#if 0 -// Pending removal after verification of a workaround discussed in the -// forum post linked to below. -/* -** This function is NOT part of the sqlite3 public API. It is strictly -** for use by the sqlite project's own JS/WASM bindings. -** -** Returns a pointer to sqlite3_free(). In compliant browsers the -** return value, when passed to sqlite3.wasm.exports.functionEntry(), -** must resolve to the same function as -** sqlite3.wasm.exports.sqlite3_free. i.e. from a dev console where -** sqlite3 is exported globally, the following must be true: -** -** ``` -** sqlite3.wasm.functionEntry( -** sqlite3.wasm.exports.sqlite3__wasm_ptr_to_sqlite3_free() -** ) === sqlite3.wasm.exports.sqlite3_free -** ``` -** -** Using a function to return this pointer, as opposed to exporting it -** via sqlite3__wasm_enum_json(), is an attempt to work around a -** Safari-specific quirk covered at -** https://sqlite.org/forum/info/e5b20e1feb37a19a. -**/ -SQLITE_WASM_EXPORT -void * sqlite3__wasm_ptr_to_sqlite3_free(void){ - return (void*)sqlite3_free; -} -#endif - #if defined(__EMSCRIPTEN__) && defined(SQLITE_ENABLE_WASMFS) #include diff --git a/manifest b/manifest index 59bddf164c..eb4d3a80ec 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Minor\stouchups\sin\sJS\sdocs\sand\sexception\smessages. -D 2024-04-23T06:36:28.862 +C Remove\ssome\sdead\sWASM-side\scode. +D 2024-04-23T06:49:47.154 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -616,7 +616,7 @@ F ext/wasm/api/sqlite3-vfs-helper.c-pp.js 3f828cc66758acb40e9c5b4dcfd87fd478a14c F ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js 8433ee332d5f5e39fb19427fccb7bad7f44aa99b5504daad3343fc128c311e78 F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js 3c72f1a0e6a7343c8c882d29d01bb440f10be12c844651605b486e76f3d6cc8c F ext/wasm/api/sqlite3-vtab-helper.c-pp.js a2fcbc3fecdd0eea229283584ebc122f29d98194083675dbe5cb2cf3a17fe309 -F ext/wasm/api/sqlite3-wasm.c 3f744dc45ac4be8125d58364448bdc9c082f332a88cec211bfd0143ad0acb373 +F ext/wasm/api/sqlite3-wasm.c 9267174b9b0591b4f71193542ab57adf95bb9415f7d3453acf4a8ca8052f5e6c F ext/wasm/api/sqlite3-worker1-promiser.c-pp.js bd89edfe42a4d7122a6d6d405c5423cf00aabba1f76f6ea8e2dba9c628ddd91a F ext/wasm/api/sqlite3-worker1.c-pp.js 5e8706c2c4af2a57fbcdc02f4e7ef79869971bc21bb8ede777687786ce1c92d5 F ext/wasm/batch-runner-sahpool.html e9a38fdeb36a13eac7b50241dfe7ae066fe3f51f5c0b0151e7baee5fce0d07a7 @@ -2185,8 +2185,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 04c552b12e3b77b9dfd83838d35ce19a37ed024a8c18a2000ada10cf3d1eb6ad -R ed22115253110bc0abaf81953307bf22 +P 9e7fc9370dfca121244f7a2941e8de629b277f1799f8de08a43ff1d86f94b6f5 +R b231e37736ffdee257e51342c04cf6fd U stephan -Z 8b53fb3b4d609195342a0ce669cacf2a +Z cab669345b54790908300b069b7a8aa6 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 0b66f11a13..77e13a296a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9e7fc9370dfca121244f7a2941e8de629b277f1799f8de08a43ff1d86f94b6f5 \ No newline at end of file +0a07ee27bd6021a6fc1d81133012592351530ffcf6ae09322ea74624cff910df \ No newline at end of file From 0309fb919aef74ee2df3b87871c43da025cefeb4 Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 23 Apr 2024 11:56:20 +0000 Subject: [PATCH 337/430] Fix an uninitialized variable problem in the new code on this branch. FossilOrigin-Name: 85625b38718c6e4cf7aa97fa3c52153bd25c810b68f19e7924e1f4b709c6a05d --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/where.c | 1 + 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index d652ae551d..1581ca907f 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Slight\sperformance\simprovement\sfor\sthe\snew\scode\son\sthis\sbranch. -D 2024-04-20T19:19:30.713 +C Fix\san\suninitialized\svariable\sproblem\sin\sthe\snew\scode\son\sthis\sbranch. +D 2024-04-23T11:56:20.612 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -835,7 +835,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c 887fc4ca3f020ebb2e376f222069570834ac63bf50111ef0cbf3ae417048ed89 F src/wal.h ba252daaa94f889f4b2c17c027e823d9be47ce39da1d3799886bbd51f0490452 F src/walker.c 7c7ea0115345851c3da4e04e2e239a29983b61fb5b038b94eede6aba462640e2 -F src/where.c 79c673bf23b3b7fcc5e9cfa0adcd88a97645cd47920d2365dd6aec8cab7b222a +F src/where.c 09dc0b63e1c18c380179f5ca15dd25ec4b796fc142bfe202b6a1a4e6c4fa8100 F src/whereInt.h 82a13766f13d1a53b05387c2e60726289ef26404bc7b9b1f7770204d97357fb8 F src/wherecode.c 4b5909be0c36030eec18ea0e7a64c60254180a21e626c9d2e0e9be3007ad47c1 F src/whereexpr.c 7b64295f1d82ad0928df435925dd7bbd5997b44a026153113eace0d9e71ff435 @@ -2184,8 +2184,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 4d870fd8b5450047a7486fc023d1ac9439642e8ed91eadfd5026c4cda7cc9179 -R 6023edc800b34da7492bfeaa8c433f44 +P 500c67f1341fe2a7e7333d525c90df201cc73a683b943ad5c1e41d4a4f639043 +R 842a99b3ce378b1a997aef4384eecd35 U dan -Z caab3df5b31f1752021c68136ff6d06a +Z 6e531b1f6828a7a325bb114af8c59a31 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 6bb6214d88..03f943f25c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -500c67f1341fe2a7e7333d525c90df201cc73a683b943ad5c1e41d4a4f639043 \ No newline at end of file +85625b38718c6e4cf7aa97fa3c52153bd25c810b68f19e7924e1f4b709c6a05d \ No newline at end of file diff --git a/src/where.c b/src/where.c index 96a6df9deb..38cf6b7287 100644 --- a/src/where.c +++ b/src/where.c @@ -323,6 +323,7 @@ static SQLITE_NOINLINE const char *indexInAffinityOk( if( sqlite3ExprIsVector(pX->pLeft) ){ int iField = pTerm->u.x.iField - 1; + inexpr.flags = 0; inexpr.op = TK_EQ; inexpr.pLeft = pX->pLeft->x.pList->a[iField].pExpr; assert( ExprUseXSelect(pX) ); From 99200b2f07034d516e863e32cc35ff0cc4c0a653 Mon Sep 17 00:00:00 2001 From: stephan Date: Wed, 24 Apr 2024 06:43:17 +0000 Subject: [PATCH 338/430] Remove an undocumented feature from the JS Worker1.open API because it relies on broken behavior which has no VFS-agnostic workaround. FossilOrigin-Name: 3a640038c70c8511e7051af83aa35d163c4f96f05c5064cffd3e4e2e63cd44a9 --- ext/wasm/api/sqlite3-api-glue.js | 7 ++-- ext/wasm/api/sqlite3-api-worker1.js | 35 +------------------ ext/wasm/api/sqlite3-worker1-promiser.c-pp.js | 2 +- manifest | 19 +++++----- manifest.uuid | 2 +- 5 files changed, 17 insertions(+), 48 deletions(-) diff --git a/ext/wasm/api/sqlite3-api-glue.js b/ext/wasm/api/sqlite3-api-glue.js index cec0a8c0af..83b2ee1721 100644 --- a/ext/wasm/api/sqlite3-api-glue.js +++ b/ext/wasm/api/sqlite3-api-glue.js @@ -627,8 +627,11 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ wasm.bindingSignatures.wasmInternal = [ ["sqlite3__wasm_db_reset", "int", "sqlite3*"], ["sqlite3__wasm_db_vfs", "sqlite3_vfs*", "sqlite3*","string"], - ["sqlite3__wasm_vfs_create_file", "int", - "sqlite3_vfs*","string","*", "int"], + [/* DO NOT USE. This is deprecated since 2023-08-11 because it can + trigger assert() in debug builds when used with file sizes + which are not sizes to a multiple of a valid db page size. */ + "sqlite3__wasm_vfs_create_file", "int", "sqlite3_vfs*","string","*", "int" + ], ["sqlite3__wasm_posix_create_file", "int", "string","*", "int"], ["sqlite3__wasm_vfs_unlink", "int", "sqlite3_vfs*","string"], ["sqlite3__wasm_qfmt_token","string:dealloc", "string","int"] diff --git a/ext/wasm/api/sqlite3-api-worker1.js b/ext/wasm/api/sqlite3-api-worker1.js index bd99f3ec8e..2e597613e1 100644 --- a/ext/wasm/api/sqlite3-api-worker1.js +++ b/ext/wasm/api/sqlite3-api-worker1.js @@ -459,11 +459,6 @@ sqlite3.initWorker1API = function(){ return wState.dbList[0] && getDbId(wState.dbList[0]); }; - const guessVfs = function(filename){ - const m = /^file:.+(vfs=(\w+))/.exec(filename); - return sqlite3.capi.sqlite3_vfs_find(m ? m[2] : 0); - }; - const isSpecialDbFilename = (n)=>{ return ""===n || ':'===n[0]; }; @@ -485,36 +480,8 @@ sqlite3.initWorker1API = function(){ toss("Throwing because of simulateError flag."); } const rc = Object.create(null); - let byteArray, pVfs; oargs.vfs = args.vfs; - if(isSpecialDbFilename(args.filename)){ - oargs.filename = args.filename || ""; - }else{ - oargs.filename = args.filename; - byteArray = args.byteArray; - if(byteArray) pVfs = guessVfs(args.filename); - } - if(pVfs){ - /* 2022-11-02: this feature is as-yet untested except that - sqlite3__wasm_vfs_create_file() has been tested from the - browser dev console. */ - let pMem; - try{ - pMem = sqlite3.wasm.allocFromTypedArray(byteArray); - const rc = util.sqlite3__wasm_vfs_create_file( - pVfs, oargs.filename, pMem, byteArray.byteLength - ); - if(rc) sqlite3.SQLite3Error.toss(rc); - }catch(e){ - throw new sqlite3.SQLite3Error( - e.name+' creating '+args.filename+": "+e.message, { - cause: e - } - ); - }finally{ - if(pMem) sqlite3.wasm.dealloc(pMem); - } - } + oargs.filename = args.filename || ""; const db = wState.open(oargs); rc.filename = db.filename; rc.persistent = !!sqlite3.capi.sqlite3_js_db_uses_vfs(db.pointer, "opfs"); diff --git a/ext/wasm/api/sqlite3-worker1-promiser.c-pp.js b/ext/wasm/api/sqlite3-worker1-promiser.c-pp.js index 878147acd6..8cfc709372 100644 --- a/ext/wasm/api/sqlite3-worker1-promiser.c-pp.js +++ b/ext/wasm/api/sqlite3-worker1-promiser.c-pp.js @@ -285,7 +285,7 @@ globalThis.sqlite3Worker1Promiser.defaultConfig = { }/*defaultConfig*/; /** - sqlite3Worker1Promiser.v2() works identically to + sqlite3Worker1Promiser.v2(), added in 3.46, works identically to sqlite3Worker1Promiser() except that it returns a Promise instead of relying an an onready callback in the config object. The Promise resolves to the same factory function which diff --git a/manifest b/manifest index 8e721c34a6..d09a6714d8 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sproblem\swith\svector\sIN\soperators\sused\swith\san\sindex\swhere\sthe\saffinities\nand\scollations\sfor\sthe\svarious\svector\sterms\sare\sdifferent. -D 2024-04-23T12:02:03.384 +C Remove\san\sundocumented\sfeature\sfrom\sthe\sJS\sWorker1.open\sAPI\sbecause\sit\srelies\son\sbroken\sbehavior\swhich\shas\sno\sVFS-agnostic\sworkaround. +D 2024-04-24T06:43:17.626 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -606,10 +606,10 @@ F ext/wasm/api/post-js-footer.js cd0a8ec768501d9bd45d325ab0442037fb0e33d1f3b4f08 F ext/wasm/api/post-js-header.js 04dc12c3edd666b64a1b4ef3b6690c88dcc653f26451fd4734472d8e29c1c122 F ext/wasm/api/pre-js.c-pp.js ad906703f7429590f2fbf5e6498513bf727a1a4f0ebfa057afb08161d7511219 F ext/wasm/api/sqlite3-api-cleanup.js d235ad237df6954145404305040991c72ef8b1881715d2a650dda7b3c2576d0e -F ext/wasm/api/sqlite3-api-glue.js c744f4b919e1254c898b467573858671a1c8797c2490d0eca2fdbadf2d0ac74b +F ext/wasm/api/sqlite3-api-glue.js 114085f4dceb28e06d20d3fb597b2501a4aa69f4b6cd29234f7cc1cf81d5b92d F ext/wasm/api/sqlite3-api-oo1.js 40f6834314b60e636f0046a9c49b8566a992dcf04be9ea593e680c23f6984b2b F ext/wasm/api/sqlite3-api-prologue.js 34457b25dcf0005c81d76f011f207026ec164f6ff0f69f024b608025ca808ea9 -F ext/wasm/api/sqlite3-api-worker1.js 8d9c0562831f62218170a3373468d8a0b7a6503b5985e309b69bf71187b525cf +F ext/wasm/api/sqlite3-api-worker1.js 9704b77b5eb9d0d498ceeaf3e7a837021b14c52ac15d6556c7f97e278ec725c3 F ext/wasm/api/sqlite3-license-version-header.js 0c807a421f0187e778dc1078f10d2994b915123c1223fe752b60afdcd1263f89 F ext/wasm/api/sqlite3-opfs-async-proxy.js 196ad83d36ca794e564044788c9d21b964679d63cad865f604da37c4afc9a285 F ext/wasm/api/sqlite3-vfs-helper.c-pp.js 3f828cc66758acb40e9c5b4dcfd87fd478a14c8fb7f0630264e6c7fa0e57515d @@ -617,7 +617,7 @@ F ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js 8433ee332d5f5e39fb19427fccb7bad7 F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js 3c72f1a0e6a7343c8c882d29d01bb440f10be12c844651605b486e76f3d6cc8c F ext/wasm/api/sqlite3-vtab-helper.c-pp.js a2fcbc3fecdd0eea229283584ebc122f29d98194083675dbe5cb2cf3a17fe309 F ext/wasm/api/sqlite3-wasm.c 9267174b9b0591b4f71193542ab57adf95bb9415f7d3453acf4a8ca8052f5e6c -F ext/wasm/api/sqlite3-worker1-promiser.c-pp.js bd89edfe42a4d7122a6d6d405c5423cf00aabba1f76f6ea8e2dba9c628ddd91a +F ext/wasm/api/sqlite3-worker1-promiser.c-pp.js 5bffc94b0ba45c658f7a70c683c536642cd95f4d6fc71d20785864111c396740 F ext/wasm/api/sqlite3-worker1.c-pp.js 5e8706c2c4af2a57fbcdc02f4e7ef79869971bc21bb8ede777687786ce1c92d5 F ext/wasm/batch-runner-sahpool.html e9a38fdeb36a13eac7b50241dfe7ae066fe3f51f5c0b0151e7baee5fce0d07a7 F ext/wasm/batch-runner-sahpool.js 54a3ac228e6c4703fe72fb65c897e19156263a51fe9b7e21d2834a45e876aabd @@ -2185,9 +2185,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 0a07ee27bd6021a6fc1d81133012592351530ffcf6ae09322ea74624cff910df 85625b38718c6e4cf7aa97fa3c52153bd25c810b68f19e7924e1f4b709c6a05d -R c4a23a5323086d7b4821fb61d859ea24 -T +closed 85625b38718c6e4cf7aa97fa3c52153bd25c810b68f19e7924e1f4b709c6a05d -U drh -Z ae5e767d94a1a535bc8f32beb80ed40d +P 86e8c782e7494377de3c27b750cd83a7eb2302c1182ee2004d3864db50fca557 +R 13de094fa4800b17b613a51d0d124b97 +U stephan +Z ed94745ed0281633dd50a259c15a286e # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index d3da69e9df..3252cc5298 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -86e8c782e7494377de3c27b750cd83a7eb2302c1182ee2004d3864db50fca557 \ No newline at end of file +3a640038c70c8511e7051af83aa35d163c4f96f05c5064cffd3e4e2e63cd44a9 \ No newline at end of file From b065eceb560a32595ccfe0ecd99bc2a0488f8062 Mon Sep 17 00:00:00 2001 From: drh <> Date: Wed, 24 Apr 2024 11:21:27 +0000 Subject: [PATCH 339/430] Ensure that temporary SrcItem objects created by trigger processing have either SrcItem.zName or SrcItem.pSelect defined. Every SrcItem should have one or the other. FossilOrigin-Name: cef4d9e3ba586735598f03eb5e8f29072c9e6f62b0d34ddd2fb3ed1795f6e21c --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/resolve.c | 1 + src/trigger.c | 1 + 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index d09a6714d8..69f0bf480d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\san\sundocumented\sfeature\sfrom\sthe\sJS\sWorker1.open\sAPI\sbecause\sit\srelies\son\sbroken\sbehavior\swhich\shas\sno\sVFS-agnostic\sworkaround. -D 2024-04-24T06:43:17.626 +C Ensure\sthat\stemporary\sSrcItem\sobjects\screated\sby\strigger\sprocessing\shave\neither\sSrcItem.zName\sor\sSrcItem.pSelect\sdefined.\s\sEvery\sSrcItem\sshould\shave\none\sor\sthe\sother. +D 2024-04-24T11:21:27.855 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -749,7 +749,7 @@ F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7 F src/prepare.c 371f6115cb69286ebc12c6f2d7511279c2e47d9f54f475d46a554d687a3b312c F src/printf.c 87b67bba3662a0523f39ae6b084a3907109702f717c654d6cecb838af5cd57f1 F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c -F src/resolve.c 6310bdfed32184cd3a5d6ba203dfee1ea323051cb38a6c2e80a5b79c069f4e87 +F src/resolve.c f430c3744a22486323a09b57185dbf38347c3dd1848af453e96ac42b3676c668 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c 51893b3e34d38ad8d46b5010a6e380ca878b578be5001a640daa907336187424 F src/shell.c.in 0354ca51eee5fbf6af394a7ef9f5ef6823ef45b743db65431f6777e4d5be2199 @@ -815,7 +815,7 @@ F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9 F src/threads.c 4ae07fa022a3dc7c5beb373cf744a85d3c5c6c3c F src/tokenize.c 3f703cacdab728d7741e5a6ac242006d74fe1c2754d4f03ed889d7253259bd68 F src/treeview.c a8aa3086c886c6eb2ff2b6354b0f23d251f7219bf08fad52d4f2791e55324f1b -F src/trigger.c 0905b96b04bb6658509f711a8207287f1315cdbc3df1a1b13ba6483c8e341c81 +F src/trigger.c fd559df58f17e127701847c74e3a0d78419d356f6c662463bc959e39ac6fed9c F src/update.c 732404a04d1737ef14bb6ec6b84f74edf28b3c102a92ae46b4855438a710efe7 F src/upsert.c 2e60567a0e9e8520c18671b30712a88dc73534474304af94f32bb5f3ef65ac65 F src/utf.c f23165685a67b4caf8ec08fb274cb3f319103decfb2a980b7cfd55d18dfa855e @@ -2185,8 +2185,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 86e8c782e7494377de3c27b750cd83a7eb2302c1182ee2004d3864db50fca557 -R 13de094fa4800b17b613a51d0d124b97 -U stephan -Z ed94745ed0281633dd50a259c15a286e +P 3a640038c70c8511e7051af83aa35d163c4f96f05c5064cffd3e4e2e63cd44a9 +R 63f308f782c1ae167ab94842d682dae8 +U drh +Z 8a5b2c860abce773c65eadddadd69986 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 3252cc5298..d3d5c10c8f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -3a640038c70c8511e7051af83aa35d163c4f96f05c5064cffd3e4e2e63cd44a9 \ No newline at end of file +cef4d9e3ba586735598f03eb5e8f29072c9e6f62b0d34ddd2fb3ed1795f6e21c \ No newline at end of file diff --git a/src/resolve.c b/src/resolve.c index 68a1d94a26..81f3d99474 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -1889,6 +1889,7 @@ static int resolveSelectStep(Walker *pWalker, Select *p){ if( pOuterNC ) pOuterNC->nNestedSelect++; for(i=0; ipSrc->nSrc; i++){ SrcItem *pItem = &p->pSrc->a[i]; + assert( pItem->zName!=0 || pItem->pSelect!=0 ); if( pItem->pSelect && (pItem->pSelect->selFlags & SF_Resolved)==0 ){ int nRef = pOuterNC ? pOuterNC->nRef : 0; const char *zSavedContext = pParse->zAuthContext; diff --git a/src/trigger.c b/src/trigger.c index 97ca249be5..813b2fac72 100644 --- a/src/trigger.c +++ b/src/trigger.c @@ -987,6 +987,7 @@ static void codeReturningTrigger( sSelect.pSrc = &sFrom; sFrom.nSrc = 1; sFrom.a[0].pTab = pTab; + sFrom.a[0].zName = pTab->zName; sFrom.a[0].iCursor = -1; sqlite3SelectPrep(pParse, &sSelect, 0); if( pParse->nErr==0 ){ From 5b27ecafbcf2dbdb7b407f8cf89703a463fb1da7 Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 24 Apr 2024 11:40:47 +0000 Subject: [PATCH 340/430] Avoid slowdown when exprNodeIsConstant() is called on deeply nested SQL functions. FossilOrigin-Name: 1c0b0345451853846076467831884f951c92ec79476be40ce7f7b766fd2d8fc1 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/expr.c | 2 +- test/func2.test | 23 +++++++++++++++++++++++ 4 files changed, 33 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 69f0bf480d..2b45341662 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Ensure\sthat\stemporary\sSrcItem\sobjects\screated\sby\strigger\sprocessing\shave\neither\sSrcItem.zName\sor\sSrcItem.pSelect\sdefined.\s\sEvery\sSrcItem\sshould\shave\none\sor\sthe\sother. -D 2024-04-24T11:21:27.855 +C Avoid\sslowdown\swhen\sexprNodeIsConstant()\sis\scalled\son\sdeeply\snested\sSQL\sfunctions. +D 2024-04-24T11:40:47.022 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -701,7 +701,7 @@ F src/date.c 126ba2ab10aeb2e7ba6e089b5f07b747c0625b8287f78b60da346eda8d23c875 F src/dbpage.c 80e46e1df623ec40486da7a5086cb723b0275a6e2a7b01d9f9b5da0f04ba2782 F src/dbstat.c 3b677254d512fcafd4d0b341bf267b38b235ccfddbef24f9154e19360fa22e43 F src/delete.c cb766727c78e715f9fb7ec8a7d03658ed2a3016343ca687acfcec9083cdca500 -F src/expr.c 36071487e377356f1dd62e1e35870ed36a7212cb34ab1578b75d4a27ecdbfcb8 +F src/expr.c 005bf7a088a2fb12a50752a2a1d40d423b8942e1920e93c3a1ba76da0bfbe52b F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c a47610f0a5c6cb0ad79f8fcef039c01833dec0c751bb695f28dc0ec6a4c3ba00 F src/func.c 283d4f3b2751a1d9339fd93a8a013d1948fd5f4474a3cab0955eb4fafd445d0f @@ -1232,7 +1232,7 @@ F test/fts4unicode.test 82a9c16b68ba2f358a856226bb2ee02f81583797bc4744061c54401b F test/fts4upfrom.test f25835162c989dffd5e2ef91ec24c4848cc9973093e2d492d1c7b32afac1b49d F test/full.test 6b3c8fb43c6beab6b95438c1675374b95fab245d F test/func.test b56905748ce0567c01d60005f3e6ad1af19453d224ba4730ee687d048fd09ef9 -F test/func2.test 772d66227e4e6684b86053302e2d74a2500e1e0f +F test/func2.test 69f6ae3751b4ec765bdc3b803c0a255aa0f693f28f44805bef03e6b4a3fd242f F test/func3.test 600a632c305a88f3946d38f9a51efe145c989b2e13bd2b2a488db47fe76bab6a F test/func4.test a3f9062487dbd826776f54f4e0e9517fe8c3cf689af92735308965774d51fac5 F test/func5.test 863e6d1bd0013d09c17236f8a13ea34008dd857d87d85a13a673960e4c25d82a @@ -2185,8 +2185,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 3a640038c70c8511e7051af83aa35d163c4f96f05c5064cffd3e4e2e63cd44a9 -R 63f308f782c1ae167ab94842d682dae8 -U drh -Z 8a5b2c860abce773c65eadddadd69986 +P cef4d9e3ba586735598f03eb5e8f29072c9e6f62b0d34ddd2fb3ed1795f6e21c +R fa1286c2555f60d15c35c2d35b75c5e3 +U dan +Z bda7fafbfb8a767264d15514a343fe9e # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index d3d5c10c8f..1e1865f9ef 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -cef4d9e3ba586735598f03eb5e8f29072c9e6f62b0d34ddd2fb3ed1795f6e21c \ No newline at end of file +1c0b0345451853846076467831884f951c92ec79476be40ce7f7b766fd2d8fc1 \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index 2257422b83..aeb04a37f2 100644 --- a/src/expr.c +++ b/src/expr.c @@ -2393,7 +2393,7 @@ static SQLITE_NOINLINE int exprNodeIsConstantFunction( pWalker->eCode = 0; return WRC_Abort; } - return WRC_Continue; + return WRC_Prune; } diff --git a/test/func2.test b/test/func2.test index 08ad857509..a7c7ec3fd8 100644 --- a/test/func2.test +++ b/test/func2.test @@ -508,4 +508,27 @@ do_test func2-3.9.2 { bin_to_hex [lindex $blob 0] } "12" +#------------------------------------------------------------------------- +# At one point this was extremely slow to compile. +# +do_test func2-3.10 { + set tm [time { + execsql { + SELECT '' IN (zerobloB(zerobloB(zerobloB(zerobloB(zerobloB( + zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(zerobloB( + zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(zerobloB( + zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(zerobloB( + zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(zerobloB( + zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(zerobloB( + zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(zerobloB( + zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(zerobloB( + zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(1) + ))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) + } + }] + + set tm [lindex $tm 0] + expr $tm<2000000 +} {1} + finish_test From 35b771e221a5e70d7dc758d6a797c63e80a98fb0 Mon Sep 17 00:00:00 2001 From: drh <> Date: Wed, 24 Apr 2024 11:51:51 +0000 Subject: [PATCH 341/430] Add comments linking the assert() added in [cef4d9e3ba586735] to the places where the precondition that the assert() tests are actually required. FossilOrigin-Name: 6f0e7e195275aeb4aefd9da20348af35e3ef7f0a6b2768a34824daeace16eff1 --- manifest | 18 +++++++++--------- manifest.uuid | 2 +- src/printf.c | 2 +- src/resolve.c | 2 +- src/trigger.c | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/manifest b/manifest index 2b45341662..fb4e297615 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Avoid\sslowdown\swhen\sexprNodeIsConstant()\sis\scalled\son\sdeeply\snested\sSQL\sfunctions. -D 2024-04-24T11:40:47.022 +C Add\scomments\slinking\sthe\sassert()\sadded\sin\s[cef4d9e3ba586735]\sto\sthe\splaces\nwhere\sthe\sprecondition\sthat\sthe\sassert()\stests\sare\sactually\srequired. +D 2024-04-24T11:51:51.477 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -747,9 +747,9 @@ F src/pcache1.c 602acb23c471bb8d557a6f0083cc2be641d6cafcafa19e481eba7ef4c9ca0f00 F src/pragma.c f8f1845b42df684e9d31c5a1628c989a34939686049d7878bc5394ac1ae9cac4 F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7 F src/prepare.c 371f6115cb69286ebc12c6f2d7511279c2e47d9f54f475d46a554d687a3b312c -F src/printf.c 87b67bba3662a0523f39ae6b084a3907109702f717c654d6cecb838af5cd57f1 +F src/printf.c 8b250972305e14b365561be5117ed0fd364e4fd58968776df1ce64c6280b90f9 F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c -F src/resolve.c f430c3744a22486323a09b57185dbf38347c3dd1848af453e96ac42b3676c668 +F src/resolve.c 647edf93729ba124c0a6048982af56c2fa4f841e69d626e4f3caa620f082bb15 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c 51893b3e34d38ad8d46b5010a6e380ca878b578be5001a640daa907336187424 F src/shell.c.in 0354ca51eee5fbf6af394a7ef9f5ef6823ef45b743db65431f6777e4d5be2199 @@ -815,7 +815,7 @@ F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9 F src/threads.c 4ae07fa022a3dc7c5beb373cf744a85d3c5c6c3c F src/tokenize.c 3f703cacdab728d7741e5a6ac242006d74fe1c2754d4f03ed889d7253259bd68 F src/treeview.c a8aa3086c886c6eb2ff2b6354b0f23d251f7219bf08fad52d4f2791e55324f1b -F src/trigger.c fd559df58f17e127701847c74e3a0d78419d356f6c662463bc959e39ac6fed9c +F src/trigger.c d087b9f50463871fc22c812835cff48d23496279758bc077bbffc17ebfe0470d F src/update.c 732404a04d1737ef14bb6ec6b84f74edf28b3c102a92ae46b4855438a710efe7 F src/upsert.c 2e60567a0e9e8520c18671b30712a88dc73534474304af94f32bb5f3ef65ac65 F src/utf.c f23165685a67b4caf8ec08fb274cb3f319103decfb2a980b7cfd55d18dfa855e @@ -2185,8 +2185,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P cef4d9e3ba586735598f03eb5e8f29072c9e6f62b0d34ddd2fb3ed1795f6e21c -R fa1286c2555f60d15c35c2d35b75c5e3 -U dan -Z bda7fafbfb8a767264d15514a343fe9e +P 1c0b0345451853846076467831884f951c92ec79476be40ce7f7b766fd2d8fc1 +R 09140f401f2e5de2029c7707ae39c044 +U drh +Z 19c09d10e1b97b5d9274dbb80f3447f0 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 1e1865f9ef..fd80c6f252 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1c0b0345451853846076467831884f951c92ec79476be40ce7f7b766fd2d8fc1 \ No newline at end of file +6f0e7e195275aeb4aefd9da20348af35e3ef7f0a6b2768a34824daeace16eff1 \ No newline at end of file diff --git a/src/printf.c b/src/printf.c index eb22ee320d..c0dcc5d0fa 100644 --- a/src/printf.c +++ b/src/printf.c @@ -857,7 +857,7 @@ void sqlite3_str_vappendf( sqlite3_str_appendall(pAccum, pItem->zAlias); }else{ Select *pSel = pItem->pSelect; - assert( pSel!=0 ); + assert( pSel!=0 ); /* Because of tag-20240424-1 */ if( pSel->selFlags & SF_NestedFrom ){ sqlite3_str_appendf(pAccum, "(join-%u)", pSel->selId); }else if( pSel->selFlags & SF_MultiValue ){ diff --git a/src/resolve.c b/src/resolve.c index 81f3d99474..6a1d82606a 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -1889,7 +1889,7 @@ static int resolveSelectStep(Walker *pWalker, Select *p){ if( pOuterNC ) pOuterNC->nNestedSelect++; for(i=0; ipSrc->nSrc; i++){ SrcItem *pItem = &p->pSrc->a[i]; - assert( pItem->zName!=0 || pItem->pSelect!=0 ); + assert( pItem->zName!=0 || pItem->pSelect!=0 );/* Test of tag-20240424-1*/ if( pItem->pSelect && (pItem->pSelect->selFlags & SF_Resolved)==0 ){ int nRef = pOuterNC ? pOuterNC->nRef : 0; const char *zSavedContext = pParse->zAuthContext; diff --git a/src/trigger.c b/src/trigger.c index 813b2fac72..34537918c9 100644 --- a/src/trigger.c +++ b/src/trigger.c @@ -987,7 +987,7 @@ static void codeReturningTrigger( sSelect.pSrc = &sFrom; sFrom.nSrc = 1; sFrom.a[0].pTab = pTab; - sFrom.a[0].zName = pTab->zName; + sFrom.a[0].zName = pTab->zName; /* tag-20240424-1 */ sFrom.a[0].iCursor = -1; sqlite3SelectPrep(pParse, &sSelect, 0); if( pParse->nErr==0 ){ From dfa628915328180a3cbb96d4407c11212258db94 Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 24 Apr 2024 14:18:20 +0000 Subject: [PATCH 342/430] Fix a case where a corrupt stat4 record could go unrecognized due to integer overflow. FossilOrigin-Name: 240a4a48b27a2b1070bba6d7da76a8df8e3f1808e262045d7ad2cf910df08f3d --- manifest | 16 ++++----- manifest.uuid | 2 +- src/vdbemem.c | 8 ++--- test/corruptL.test | 85 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 98 insertions(+), 13 deletions(-) diff --git a/manifest b/manifest index fb4e297615..b4352e70e4 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\scomments\slinking\sthe\sassert()\sadded\sin\s[cef4d9e3ba586735]\sto\sthe\splaces\nwhere\sthe\sprecondition\sthat\sthe\sassert()\stests\sare\sactually\srequired. -D 2024-04-24T11:51:51.477 +C Fix\sa\scase\swhere\sa\scorrupt\sstat4\srecord\scould\sgo\sunrecognized\sdue\sto\sinteger\soverflow. +D 2024-04-24T14:18:20.595 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -827,7 +827,7 @@ F src/vdbeInt.h 949669dfd8a41550d27dcb905b494f2ccde9a2e6c1b0b04daa1227e2e74c2b2c F src/vdbeapi.c 80235ac380e9467fec1cb0883354d841f2a771976e766995f7e0c77f845406df F src/vdbeaux.c 6385727adf51a649e4993098870a62c3945fe21dbc0e0fd9013772aff930b8fb F src/vdbeblob.c 13f9287b55b6356b4b1845410382d6bede203ceb29ef69388a4a3d007ffacbe5 -F src/vdbemem.c 213bf303826c0ef702e3a2a69dab2309d84b8381b822c6787885859fd7cd4c4e +F src/vdbemem.c 385c8b89da3b5ef9a468d77a466958aa72ee1212d5cb005f23ec63df1d413054 F src/vdbesort.c 237840ca1947511fa59bd4e18b9eeae93f2af2468c34d2427b059f896230a547 F src/vdbetrace.c fe0bc29ebd4e02c8bc5c1945f1d2e6be5927ec12c06d89b03ef2a4def34bf823 F src/vdbevtab.c 2143db7db0ceed69b21422581f434baffc507a08d831565193a7a02882a1b6a7 @@ -1020,7 +1020,7 @@ F test/corruptH.test 79801d97ec5c2f9f3c87739aa1ec2eb786f96454 F test/corruptI.test 9d8cbf6214e492abe9e822e759b9751ae336cec0a6fe3ff3b37bfbd8ff9c22ca F test/corruptJ.test 4d5ccc4bf959464229a836d60142831ef76a5aa4 F test/corruptK.test 5b4212fe346699831c5ad559a62c54e11c0611bdde1ea8423a091f9c01aa32af -F test/corruptL.test 504d90502d9993440226edc355d2275524b89064ea3df5ee5c27f7028ec59d07 +F test/corruptL.test 652fc8ac0763a6fd3eb28b951d481924167b2d9936083bcc68253b2274a0c8fe F test/corruptM.test 7d574320e08c1b36caa3e47262061f186367d593a7e305d35f15289cc2c3e067 F test/corruptN.test 7c099d153a554001b4fb829c799b01f2ea6276cbc32479131e0db0da4efd9cc4 F test/cost.test cc434a026b1e9d0d98137a147e24e5daf1b1ad09e9ff7da63b34c83ddd136d92 @@ -2185,8 +2185,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 1c0b0345451853846076467831884f951c92ec79476be40ce7f7b766fd2d8fc1 -R 09140f401f2e5de2029c7707ae39c044 -U drh -Z 19c09d10e1b97b5d9274dbb80f3447f0 +P 6f0e7e195275aeb4aefd9da20348af35e3ef7f0a6b2768a34824daeace16eff1 +R 8aa170676bd507dd4717ebad9ca82758 +U dan +Z 3e9a5a5005e3601585922bc0e00c59cc # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index fd80c6f252..1442db0c13 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6f0e7e195275aeb4aefd9da20348af35e3ef7f0a6b2768a34824daeace16eff1 \ No newline at end of file +240a4a48b27a2b1070bba6d7da76a8df8e3f1808e262045d7ad2cf910df08f3d \ No newline at end of file diff --git a/src/vdbemem.c b/src/vdbemem.c index d0015206d5..8a4011e10f 100644 --- a/src/vdbemem.c +++ b/src/vdbemem.c @@ -1949,10 +1949,10 @@ int sqlite3Stat4Column( sqlite3_value **ppVal /* OUT: Extracted value */ ){ u32 t = 0; /* a column type code */ - int nHdr; /* Size of the header in the record */ - int iHdr; /* Next unread header byte */ - int iField; /* Next unread data byte */ - int szField = 0; /* Size of the current data field */ + u32 nHdr; /* Size of the header in the record */ + u32 iHdr; /* Next unread header byte */ + i64 iField; /* Next unread data byte */ + u32 szField = 0; /* Size of the current data field */ int i; /* Column index */ u8 *a = (u8*)pRec; /* Typecast byte array */ Mem *pMem = *ppVal; /* Write result into this Mem object */ diff --git a/test/corruptL.test b/test/corruptL.test index cf38764415..52adf6fd72 100644 --- a/test/corruptL.test +++ b/test/corruptL.test @@ -1505,4 +1505,89 @@ do_catchsql_test 19.4 { PRAGMA integrity_check; } {1 {database disk image is malformed}} +#------------------------------------------------------------------------- +reset_db +do_test 18.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +.open --hexdb +| size 20480 pagesize 4096 filename crash-a4150b729051e4.db +| page 1 offset 0 +| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. +| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 05 .....@ ........ +| 32: 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 04 ................ +| 48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 ................ +| 64: 00 00 00 00 00 00 00 00 00 00 ff f0 00 00 00 00 ................ +| 96: 00 00 00 00 0d 00 00 00 04 0e e5 00 0f c2 0f 75 ...............u +| 112: 0f 19 0e e5 00 00 00 00 00 00 00 01 00 00 00 00 ................ +| 3808: 00 00 00 00 00 32 04 06 17 17 11 01 4b 69 6e 64 .....2......Kind +| 3824: 65 78 74 31 61 62 63 74 31 05 43 52 45 41 54 45 ext1abct1.CREATE +| 3840: 20 49 4e 44 45 58 20 74 31 61 62 63 20 4f 4e 20 INDEX t1abc ON +| 3856: 74 31 28 61 2c 62 2c 63 29 5a 03 06 17 25 25 01 t1(a,b,c)Z...%%. +| 3872: 79 74 61 62 6c 65 73 71 6c 69 74 65 5f 73 74 61 ytablesqlite_sta +| 3888: 74 34 73 71 6c 69 74 65 5f 73 74 61 74 34 04 43 t4sqlite_stat4.C +| 3904: 52 45 41 54 45 20 54 41 42 4c 45 20 73 71 6c 69 REATE TABLE sqli +| 3920: 74 65 5f 73 74 61 74 34 28 74 62 6c 2c 69 64 78 te_stat4(tbl,idx +| 3936: 2c 6e 65 71 2c 6e 6c 74 2c 6e 64 6c 74 2c 73 61 ,neq,nlt,ndlt,sa +| 3952: 6d 70 6c 65 29 4b 02 06 17 25 25 01 5b 74 61 62 mple)K...%%.[tab +| 3968: 6c 65 73 71 6c 69 74 65 5f 73 74 61 74 31 73 71 lesqlite_stat1sq +| 3984: 6c 69 74 65 5f 73 74 61 74 31 03 43 52 45 41 54 lite_stat1.CREAT +| 4000: 45 20 54 41 42 4c 45 20 73 71 6c 69 74 65 5f 73 E TABLE sqlite_s +| 4016: 74 61 74 31 28 74 62 6c 2c 69 64 78 2c 73 74 61 tat1(tbl,idx,sta +| 4032: 74 29 3c 01 06 17 11 11 01 65 74 61 62 6c 65 74 t)<......etablet +| 4048: 31 74 31 02 43 52 45 41 54 45 20 54 41 42 4c 45 1t1.CREATE TABLE +| 4064: 20 74 31 28 61 20 54 45 58 54 2c 20 62 20 49 4e t1(a TEXT, b IN +| 4080: 54 2c 20 63 20 49 4e 54 2c 20 64 20 49 4e 54 29 T, c INT, d INT) +| page 2 offset 4096 +| 0: 0d 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 4000: 0b 07 05 13 01 01 01 62 63 64 64 06 0b 0c 06 05 .......bcdd..... +| 4016: 13 02 01 01 64 65 66 01 59 09 0a 0c 05 05 13 03 ....def.Y....... +| 4032: 01 01 64 65 66 02 6f 08 09 0c 04 05 13 02 01 01 ..def.o......... +| 4048: 61 62 63 01 59 07 08 0c 03 05 13 02 01 01 87 62 abc.Y..........b +| 4064: 63 00 ea 06 07 0c 02 05 13 02 01 01 61 62 63 00 c...........abc. +| 4080: ea 06 06 0b 01 05 13 01 01 01 61 62 63 7b 04 04 ..........abc... +| page 3 offset 8192 +| 0: 0d 00 00 00 01 0f e0 00 0f e1 00 00 00 00 00 00 ................ +| 4064: 00 1d 01 04 11 17 31 74 31 74 31 61 62 63 31 30 ......1t1t1abc10 +| 4080: 30 30 30 20 35 30 30 30 20 32 30 30 30 20 31 30 000 5000 2000 10 +| page 4 offset 12288 +| 0: 0d 00 00 00 07 0e ac 00 0f d1 0f a0 0f 6f 0f 3e .............o.> +| 16: 0f 0e 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 3744: 00 00 00 00 00 00 00 00 00 00 00 00 2f 07 07 11 ............/... +| 3760: 17 1b 1b 1b 24 74 31 74 31 61 62 63 32 20 31 20 ....$t1t1abc2 1 +| 3776: 31 20 31 35 20 36 20 36 20 36 32 20 35 20 36 20 1 15 6 6 62 5 6 +| 3792: 36 05 13 02 01 01 64 65 66 02 37 08 05 2f 06 07 6.....def.7../.. +| 3808: 11 17 1b 1b 1b 24 74 41 74 31 61 62 63 32 20 31 .....$tAt1abc2 1 +| 3824: 20 31 20 31 35 20 35 20 55 20 35 32 20 34 20 35 1 15 5 U 52 4 5 +| 3840: 20 35 05 13 02 01 01 64 65 66 01 59 09 06 2e 05 5.....def.Y.... +| 3856: 07 11 17 1b 1b 1b 22 74 31 74 31 61 62 63 31 20 .......t1t1abc1 +| 3872: 31 20 31 20 31 34 20 34 20 34 20 34 31 20 33 20 1 1 14 4 4 41 3 +| 3888: 34 20 34 08 b3 cd f0 f1 62 63 64 64 06 07 2f 05 4 4.....bcdd../. +| 3904: 07 11 17 1b 1b 1b 24 74 37 74 31 61 62 63 34 20 ......$t7t1abc4 +| 3920: 31 20 31 20 31 30 20 33 20 33 20 33 30 20 32 20 1 1 10 3 3 30 2 +| 3936: 33 20 33 05 13 02 01 01 61 62 63 01 59 07 04 2f 3 3.....abc.Y../ +| 3952: 03 07 11 17 1b 1b 1b 24 74 31 74 31 61 62 63 34 .......$t1t1abc4 +| 3968: 20 32 20 31 20 31 30 20 31 20 32 20 32 30 20 31 2 1 10 1 2 20 1 +| 3984: 20 32 20 32 05 13 02 01 01 61 62 63 00 ea 06 03 2 2.....abc.... +| 4000: 2f 02 07 11 17 1b 1b 1b 24 74 31 74 31 61 62 63 /.......$t1t1abc +| 4016: 34 20 32 20 31 20 31 30 20 31 20 31 20 31 30 20 4 2 1 10 1 1 10 +| 4032: 31 20 31 20 31 05 13 02 01 01 61 62 63 00 ea 05 1 1 1.....abc... +| 4048: 02 2d 01 07 11 17 1b 1b 1b 20 74 31 74 31 61 62 .-....... t1t1ab +| 4064: 63 34 20 31 20 31 20 31 30 20 30 20 30 1f 30 30 c4 1 1 10 0 0.00 +| 4080: 20 30 20 30 20 30 05 13 01 01 09 61 62 63 7b 04 0 0 0.....abc.. +| page 5 offset 16384 +| 0: 0a 00 00 00 07 0f a8 00 0f f5 00 00 00 00 00 00 ................ +| 4000: 00 00 00 00 00 00 00 00 0c 05 13 02 01 01 64 65 ..............de +| 4016: 66 02 37 08 05 0c 05 13 02 01 01 64 65 66 01 59 f.7........def.Y +| 4032: 09 06 0b 05 12 01 01 01 62 63 64 64 06 07 0c 05 ........bcdd.... +| 4048: 13 02 01 01 61 62 63 01 59 07 01 2c 05 13 02 01 ....abc.Y..,.... +| 4064: 01 61 62 63 00 ea 06 03 0c 05 13 02 01 01 61 62 .abc..........ab +| 4080: 63 00 ea 05 00 00 00 00 00 00 00 00 00 00 00 00 c............... +| end crash-a4150b729051e4.db +}]} {} + +do_catchsql_test 18.1 { + SELECT a FROM t1 WHERE b GLOB b AND b GLOB '0^x]␅6␚xz]'; +} {1 {database disk image is malformed}} + finish_test From 0868d58e2caa16f19e843602bf2ca58653653162 Mon Sep 17 00:00:00 2001 From: drh <> Date: Wed, 24 Apr 2024 16:36:37 +0000 Subject: [PATCH 343/430] If a RETURNING clause contains a subquery that references the table that is being updated in the statement that includes the RETURNING clause, then mark the subquery as correlated sot hat it is recomputed for each result and not just computed once and reused. See [forum:/forumpost/2c83569ce8945d39|forum post 2c83569ce8945d39]. FossilOrigin-Name: 9ea6bcc8fdf6aadb756ec5bcaaa7af314167f8973bdd32fd23f83bd964f0c21e --- manifest | 16 +++++------ manifest.uuid | 2 +- src/trigger.c | 67 ++++++++++++++++++++++++++++++++++++++++++++ test/returning1.test | 60 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 136 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index b4352e70e4..e18f26c318 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\scase\swhere\sa\scorrupt\sstat4\srecord\scould\sgo\sunrecognized\sdue\sto\sinteger\soverflow. -D 2024-04-24T14:18:20.595 +C If\sa\sRETURNING\sclause\scontains\sa\ssubquery\sthat\sreferences\sthe\stable\sthat\sis\nbeing\supdated\sin\sthe\sstatement\sthat\sincludes\sthe\sRETURNING\sclause,\sthen\smark\nthe\ssubquery\sas\scorrelated\ssot\shat\sit\sis\srecomputed\sfor\seach\sresult\sand\snot\njust\scomputed\sonce\sand\sreused.\s\sSee\n[forum:/forumpost/2c83569ce8945d39|forum\spost\s2c83569ce8945d39]. +D 2024-04-24T16:36:37.548 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -815,7 +815,7 @@ F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9 F src/threads.c 4ae07fa022a3dc7c5beb373cf744a85d3c5c6c3c F src/tokenize.c 3f703cacdab728d7741e5a6ac242006d74fe1c2754d4f03ed889d7253259bd68 F src/treeview.c a8aa3086c886c6eb2ff2b6354b0f23d251f7219bf08fad52d4f2791e55324f1b -F src/trigger.c d087b9f50463871fc22c812835cff48d23496279758bc077bbffc17ebfe0470d +F src/trigger.c 0858f75818ed1580332db274f1032bcc5effe567cb132df5c5be8b1d800ca97f F src/update.c 732404a04d1737ef14bb6ec6b84f74edf28b3c102a92ae46b4855438a710efe7 F src/upsert.c 2e60567a0e9e8520c18671b30712a88dc73534474304af94f32bb5f3ef65ac65 F src/utf.c f23165685a67b4caf8ec08fb274cb3f319103decfb2a980b7cfd55d18dfa855e @@ -1530,7 +1530,7 @@ F test/regexp2.test 55ed41da802b0e284ac7e2fe944be3948f93ff25abbca0361a609acfed13 F test/reindex.test cd9d6021729910ece82267b4f5e1b5ac2911a7566c43b43c176a6a4732e2118d F test/resetdb.test 54c06f18bc832ac6d6319e5ab23d5c8dd49fdbeec7c696d791682a8006bd5fc3 F test/resolver01.test f4022acafda7f4d40eca94dbf16bc5fc4ac30ceb -F test/returning1.test b27646c5e25431dd47cf72f525d1b2d5ad4ae14e21d9cf3d65769f05e48f64f3 +F test/returning1.test 2ebfe6e56f3de9b194295620f46a747c26cebdab937defb9afd84b96dd202ccb F test/returningfault.test ae4c4b5e8745813287a359d9ccdb9d5c883c2e68afb18fb0767937d5de5692a4 F test/rollback.test 06680159bc6746d0f26276e339e3ae2f951c64812468308838e0a3362d911eaa F test/rollback2.test 3f3a4e20401825017df7e7671e9f31b6de5fae5620c2b9b49917f52f8c160a8f @@ -2185,8 +2185,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 6f0e7e195275aeb4aefd9da20348af35e3ef7f0a6b2768a34824daeace16eff1 -R 8aa170676bd507dd4717ebad9ca82758 -U dan -Z 3e9a5a5005e3601585922bc0e00c59cc +P 240a4a48b27a2b1070bba6d7da76a8df8e3f1808e262045d7ad2cf910df08f3d +R 0443bbe68d7ebf5917ca0dd9f2f0960d +U drh +Z a1811f8f003e2400c1c50cad60d7b2cc # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 1442db0c13..62d8aa4756 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -240a4a48b27a2b1070bba6d7da76a8df8e3f1808e262045d7ad2cf910df08f3d \ No newline at end of file +9ea6bcc8fdf6aadb756ec5bcaaa7af314167f8973bdd32fd23f83bd964f0c21e \ No newline at end of file diff --git a/src/trigger.c b/src/trigger.c index 34537918c9..98e8da58c1 100644 --- a/src/trigger.c +++ b/src/trigger.c @@ -951,6 +951,72 @@ static ExprList *sqlite3ExpandReturning( return pNew; } +/* If the Expr node is a subquery or an EXISTS operator or an IN operator that +** uses a subquery, and if the subquery is SF_Correlated, then mark the +** expression as EP_VarSelect. +*/ +static int sqlite3ReturningSubqueryVarSelect(Walker *NotUsed, Expr *pExpr){ + UNUSED_PARAMETER(NotUsed); + if( ExprUseXSelect(pExpr) + && (pExpr->x.pSelect->selFlags & SF_Correlated)!=0 + ){ + testcase( ExprHasProperty(pExpr, EP_VarSelect) ); + ExprSetProperty(pExpr, EP_VarSelect); + } + return WRC_Continue; +} + + +/* +** If the SELECT references the table pWalker->u.pTab, then do two things: +** +** (1) Mark the SELECT as as SF_Correlated. +** (2) Set pWalker->eCode to non-zero so that the caller will know +** that (1) has happened. +*/ +static int sqlite3ReturningSubqueryCorrelated(Walker *pWalker, Select *pSelect){ + int i; + SrcList *pSrc; + assert( pSelect!=0 ); + pSrc = pSelect->pSrc; + assert( pSrc!=0 ); + for(i=0; inSrc; i++){ + if( pSrc->a[i].pTab==pWalker->u.pTab ){ + testcase( pSelect->selFlags & SF_Correlated ); + pSelect->selFlags |= SF_Correlated; + pWalker->eCode = 1; + break; + } + } + return WRC_Continue; +} + +/* +** Scan the expression list that is the argument to RETURNING looking +** for subqueries that depend on the table which is being modified in the +** statement that is hosting the RETURNING clause (pTab). Mark all such +** subqueries as SF_Correlated. If the subqueries are part of an +** expression, mark the expression as EP_VarSelect. +** +** https://sqlite.org/forum/forumpost/2c83569ce8945d39 +*/ +static void sqlite3ProcessReturningSubqueries( + ExprList *pEList, + Table *pTab +){ + Walker w; + memset(&w, 0, sizeof(w)); + w.xExprCallback = sqlite3ExprWalkNoop; + w.xSelectCallback = sqlite3ReturningSubqueryCorrelated; + w.u.pTab = pTab; + sqlite3WalkExprList(&w, pEList); + if( w.eCode ){ + w.xExprCallback = sqlite3ReturningSubqueryVarSelect; + w.xSelectCallback = sqlite3SelectWalkNoop; + sqlite3WalkExprList(&w, pEList); + } +} + /* ** Generate code for the RETURNING trigger. Unlike other triggers ** that invoke a subprogram in the bytecode, the code for RETURNING @@ -1014,6 +1080,7 @@ static void codeReturningTrigger( int i; int nCol = pNew->nExpr; int reg = pParse->nMem+1; + sqlite3ProcessReturningSubqueries(pNew, pTab); pParse->nMem += nCol+2; pReturning->iRetReg = reg; for(i=0; i3 + RETURNING a, + (SELECT min(a) FROM t1), + (SELECT max(a) FROM t1), + (SELECT round(avg(a),2) FROM t1); + ROLLBACK; +} { + 1 2 8 4.6 + 2 3 8 5.25 + 4 3 8 5.67 + 6 3 8 5.5 + 8 3 3 3.0 +} +do_execsql_test 20.2 { + BEGIN; + DELETE FROM t1 + RETURNING a, + (SELECT min(a) FROM t1), + (SELECT max(a) FROM t1), + (SELECT round(avg(a),2) FROM t1); + ROLLBACK; +} { + 1 2 8 4.6 + 2 3 8 5.25 + 3 4 8 6.0 + 4 6 8 7.0 + 6 8 8 8.0 + 8 N N N +} +do_execsql_test 20.3 { + BEGIN; + DELETE FROM t1 + RETURNING a, + (SELECT min(t2.a)+t1.a*100 FROM t1 AS t2), + (SELECT max(t2.a)+t1.a*100 FROM t1 AS t2), + (SELECT round(avg(t2.a),2)+t1.a*100 FROM t1 AS t2); + ROLLBACK; +} { + 1 102 108 104.6 + 2 203 208 205.25 + 3 304 308 306.0 + 4 406 408 407.0 + 6 608 608 608.0 + 8 N N N +} + finish_test From f8e195159f933d310587bd991f66965ba184c252 Mon Sep 17 00:00:00 2001 From: drh <> Date: Wed, 24 Apr 2024 19:49:52 +0000 Subject: [PATCH 344/430] An experimental minor tweak to the way affinities are computed for compound subqueries, when the actual affinity is ambiguous. FossilOrigin-Name: 779723ad792ca24dd07b7a1425303c76b44bb173e718a33c26c9f7644e9912cb --- manifest | 17 ++++++++++------- manifest.uuid | 2 +- src/select.c | 2 +- test/view.test | 6 +++--- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/manifest b/manifest index e18f26c318..14d0ac506e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C If\sa\sRETURNING\sclause\scontains\sa\ssubquery\sthat\sreferences\sthe\stable\sthat\sis\nbeing\supdated\sin\sthe\sstatement\sthat\sincludes\sthe\sRETURNING\sclause,\sthen\smark\nthe\ssubquery\sas\scorrelated\ssot\shat\sit\sis\srecomputed\sfor\seach\sresult\sand\snot\njust\scomputed\sonce\sand\sreused.\s\sSee\n[forum:/forumpost/2c83569ce8945d39|forum\spost\s2c83569ce8945d39]. -D 2024-04-24T16:36:37.548 +C An\sexperimental\sminor\stweak\sto\sthe\sway\saffinities\sare\scomputed\sfor\scompound\nsubqueries,\swhen\sthe\sactual\saffinity\sis\sambiguous. +D 2024-04-24T19:49:52.341 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -751,7 +751,7 @@ F src/printf.c 8b250972305e14b365561be5117ed0fd364e4fd58968776df1ce64c6280b90f9 F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c 647edf93729ba124c0a6048982af56c2fa4f841e69d626e4f3caa620f082bb15 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 -F src/select.c 51893b3e34d38ad8d46b5010a6e380ca878b578be5001a640daa907336187424 +F src/select.c 39c5dc8b2fca3b1e52db1a9b469507bfc312d3e3a4bf10c58a7a716626c4bdff F src/shell.c.in 0354ca51eee5fbf6af394a7ef9f5ef6823ef45b743db65431f6777e4d5be2199 F src/sqlite.h.in 32389e0d584551b300d0157881336162c14315a424cbf385c0d65eb7c2e31f7b F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 @@ -1929,7 +1929,7 @@ F test/values.test 52102ad9e5068b449429e40a976486a52246041f7cd79d086a2b170e77dec F test/valuesfault.test 2ef23ed965e3bd08e268cdc38a0d11653390ddbbe1e8e2e98d16f55edd30f6e8 F test/varint.test bbce22cda8fc4d135bcc2b589574be8410614e62 F test/veryquick.test 57ab846bacf7b90cf4e9a672721ea5c5b669b661 -F test/view.test d4c4281e1679245829db35597817282f60dc513fc39cc5439078f009bd118487 +F test/view.test 9df7e00eb1f96a9d738a317137989a594541ce7b9ebea0506e39f89de0c1319a F test/view2.test db32c8138b5b556f610b35dfddd38c5a58a292f07fda5281eedb0851b2672679 F test/view3.test ad8a8290ee2b55ff6ce66c9ef1ce3f1e47926273a3814e1c425293e128a95456 F test/vt02.c 5b44ac67b1a283fedecf2d6e2ceda61e7a157f01d44dcb4490dcb1e87d057060 @@ -2185,8 +2185,11 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 240a4a48b27a2b1070bba6d7da76a8df8e3f1808e262045d7ad2cf910df08f3d -R 0443bbe68d7ebf5917ca0dd9f2f0960d +P 9ea6bcc8fdf6aadb756ec5bcaaa7af314167f8973bdd32fd23f83bd964f0c21e +R 069cab252330979e2eef5b88f83953a3 +T *branch * compound-subquery-affinity +T *sym-compound-subquery-affinity * +T -sym-trunk * U drh -Z a1811f8f003e2400c1c50cad60d7b2cc +Z 7c2ae6bcf3d76ce120ccc503dbc0842f # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 62d8aa4756..b78d32b4c4 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9ea6bcc8fdf6aadb756ec5bcaaa7af314167f8973bdd32fd23f83bd964f0c21e \ No newline at end of file +779723ad792ca24dd07b7a1425303c76b44bb173e718a33c26c9f7644e9912cb \ No newline at end of file diff --git a/src/select.c b/src/select.c index 9c2bf3b93c..d391762039 100644 --- a/src/select.c +++ b/src/select.c @@ -6417,7 +6417,7 @@ static void selectAddSubqueryTypeInfo(Walker *pWalker, Select *p){ /* A sub-query in the FROM clause of a SELECT */ Select *pSel = pFrom->pSelect; if( pSel ){ - sqlite3SubqueryColumnTypes(pParse, pTab, pSel, SQLITE_AFF_NONE); + sqlite3SubqueryColumnTypes(pParse, pTab, pSel, SQLITE_AFF_BLOB); } } } diff --git a/test/view.test b/test/view.test index 90c9c99092..612e0cc2e4 100644 --- a/test/view.test +++ b/test/view.test @@ -737,16 +737,16 @@ do_execsql_test view-27.5 { do_execsql_test view-27.6 { SELECT c0 Date: Thu, 25 Apr 2024 06:52:19 +0000 Subject: [PATCH 345/430] wasm: add a makefile comment about the static sqlite3.h/c version info injected into the JS files possibly differing from the runtime-emited version info when a user provides their own sqlite3.c. FossilOrigin-Name: d99a01a0f6e1f70f70c9a0625aeaa8a8015eba352bcfb3978eafca6df10ba5a8 --- ext/wasm/GNUmakefile | 6 ++++++ manifest | 14 +++++++------- manifest.uuid | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/ext/wasm/GNUmakefile b/ext/wasm/GNUmakefile index 1a119f9505..115374e623 100644 --- a/ext/wasm/GNUmakefile +++ b/ext/wasm/GNUmakefile @@ -289,6 +289,12 @@ endif # embedding in the JS files and in building the distribution zip file. # It must NOT be in $(dir.tmp) because we need it to survive the # cleanup process for the dist build to work properly. +# +# Slight caveat: this uses the version info from the in-tree +# sqlite3.c/h, which may diff from a user-provided $(sqlite3.c). The +# end result is that the generated JS files may have static version +# info from $(bin.version-info) which differ from their runtime-emited +# version info (e.g. from sqlite3_libversion()). bin.version-info := $(dir.top)/version-info .NOTPARALLEL: $(bin.version-info) $(bin.version-info): $(dir.tool)/version-info.c $(sqlite3.h) $(dir.top)/Makefile diff --git a/manifest b/manifest index e18f26c318..a6c6f526b7 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C If\sa\sRETURNING\sclause\scontains\sa\ssubquery\sthat\sreferences\sthe\stable\sthat\sis\nbeing\supdated\sin\sthe\sstatement\sthat\sincludes\sthe\sRETURNING\sclause,\sthen\smark\nthe\ssubquery\sas\scorrelated\ssot\shat\sit\sis\srecomputed\sfor\seach\sresult\sand\snot\njust\scomputed\sonce\sand\sreused.\s\sSee\n[forum:/forumpost/2c83569ce8945d39|forum\spost\s2c83569ce8945d39]. -D 2024-04-24T16:36:37.548 +C wasm:\sadd\sa\smakefile\scomment\sabout\sthe\sstatic\ssqlite3.h/c\sversion\sinfo\sinjected\sinto\sthe\sJS\sfiles\spossibly\sdiffering\sfrom\sthe\sruntime-emited\sversion\sinfo\swhen\sa\suser\sprovides\stheir\sown\ssqlite3.c. +D 2024-04-25T06:52:19.923 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -588,7 +588,7 @@ F ext/userauth/sqlite3userauth.h 7f3ea8c4686db8e40b0a0e7a8e0b00fac13aa7a3 F ext/userauth/user-auth.txt ca7e9ee82ca4e1c1744295f8184dd70edfae1992865d26c64303f539eb6c084c F ext/userauth/userauth.c 7f00cded7dcaa5d47f54539b290a43d2e59f4b1eb5f447545fa865f002fc80cb F ext/wasm/EXPORTED_FUNCTIONS.fiddle.in 27450c8b8c70875a260aca55435ec927068b34cef801a96205adb81bdcefc65c -F ext/wasm/GNUmakefile 0d5ccc8a4814716c1c789bb3069dd4d71d5ef0a97bbea074ac182fbfb85a3ca8 +F ext/wasm/GNUmakefile 21f015f342e4ed9b7ff632c10750512259d26c836a34f4f535673fae9a7c9fcc F ext/wasm/README-dist.txt 6382cb9548076fca472fb3330bbdba3a55c1ea0b180ff9253f084f07ff383576 F ext/wasm/README.md a8a2962c3aebdf8d2104a9102e336c5554e78fc6072746e5daf9c61514e7d193 F ext/wasm/SQLTester/GNUmakefile e0794f676d55819951bbfae45cc5e8d7818dc460492dc317ce7f0d2eca15caff @@ -2185,8 +2185,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 240a4a48b27a2b1070bba6d7da76a8df8e3f1808e262045d7ad2cf910df08f3d -R 0443bbe68d7ebf5917ca0dd9f2f0960d -U drh -Z a1811f8f003e2400c1c50cad60d7b2cc +P 9ea6bcc8fdf6aadb756ec5bcaaa7af314167f8973bdd32fd23f83bd964f0c21e +R 64fc844d8bd132b5a1025854e240b927 +U stephan +Z 2ab8bdbf685d01a81ecb7a8256df40c5 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 62d8aa4756..2cd915398f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9ea6bcc8fdf6aadb756ec5bcaaa7af314167f8973bdd32fd23f83bd964f0c21e \ No newline at end of file +d99a01a0f6e1f70f70c9a0625aeaa8a8015eba352bcfb3978eafca6df10ba5a8 \ No newline at end of file From 23afc2c4ec1abc95f61e75411926527e93ebb500 Mon Sep 17 00:00:00 2001 From: drh <> Date: Thu, 25 Apr 2024 16:55:53 +0000 Subject: [PATCH 346/430] Back out the previous change on this branch. In its place: Determine the affinity of a subquery by the left-most arm of the subquery that has an affinity other than NONE. In other words, scan from left to right looking for an arm of the compound subquery with an affinity of BLOB, TEXT, INTEGER, or REAL and pick the first one found. Or stay with NONE if no arm has a defined affinity. Test cases added. FossilOrigin-Name: b8ec8511b1968bbc1472b3e2e21f0fef1d5becebeb31f9d13ee3ca9e13abb1e5 --- manifest | 17 +++++++---------- manifest.uuid | 2 +- src/select.c | 12 ++++++++---- test/view.test | 29 ++++++++++++++++++++++++++--- 4 files changed, 42 insertions(+), 18 deletions(-) diff --git a/manifest b/manifest index 14d0ac506e..91f3bc3d8e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C An\sexperimental\sminor\stweak\sto\sthe\sway\saffinities\sare\scomputed\sfor\scompound\nsubqueries,\swhen\sthe\sactual\saffinity\sis\sambiguous. -D 2024-04-24T19:49:52.341 +C Back\sout\sthe\sprevious\schange\son\sthis\sbranch.\s\sIn\sits\splace:\s\sDetermine\sthe\naffinity\sof\sa\ssubquery\sby\sthe\sleft-most\sarm\sof\sthe\ssubquery\sthat\shas\san\naffinity\sother\sthan\sNONE.\s\sIn\sother\swords,\sscan\sfrom\sleft\sto\sright\slooking\nfor\san\sarm\sof\sthe\scompound\ssubquery\swith\san\saffinity\sof\sBLOB,\sTEXT,\sINTEGER,\nor\sREAL\sand\spick\sthe\sfirst\sone\sfound.\s\sOr\sstay\swith\sNONE\sif\sno\sarm\shas\sa\ndefined\saffinity.\s\sTest\scases\sadded. +D 2024-04-25T16:55:53.038 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -751,7 +751,7 @@ F src/printf.c 8b250972305e14b365561be5117ed0fd364e4fd58968776df1ce64c6280b90f9 F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c 647edf93729ba124c0a6048982af56c2fa4f841e69d626e4f3caa620f082bb15 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 -F src/select.c 39c5dc8b2fca3b1e52db1a9b469507bfc312d3e3a4bf10c58a7a716626c4bdff +F src/select.c f0f8f7fd601aff50c303205c6ac6da789d02a6e420ccb25d9aaaeccc7fa314d7 F src/shell.c.in 0354ca51eee5fbf6af394a7ef9f5ef6823ef45b743db65431f6777e4d5be2199 F src/sqlite.h.in 32389e0d584551b300d0157881336162c14315a424cbf385c0d65eb7c2e31f7b F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 @@ -1929,7 +1929,7 @@ F test/values.test 52102ad9e5068b449429e40a976486a52246041f7cd79d086a2b170e77dec F test/valuesfault.test 2ef23ed965e3bd08e268cdc38a0d11653390ddbbe1e8e2e98d16f55edd30f6e8 F test/varint.test bbce22cda8fc4d135bcc2b589574be8410614e62 F test/veryquick.test 57ab846bacf7b90cf4e9a672721ea5c5b669b661 -F test/view.test 9df7e00eb1f96a9d738a317137989a594541ce7b9ebea0506e39f89de0c1319a +F test/view.test 3c23d7a068e9e4a0c4e6907498042772adea725f0630c3d9638ffd4e5a08b92b F test/view2.test db32c8138b5b556f610b35dfddd38c5a58a292f07fda5281eedb0851b2672679 F test/view3.test ad8a8290ee2b55ff6ce66c9ef1ce3f1e47926273a3814e1c425293e128a95456 F test/vt02.c 5b44ac67b1a283fedecf2d6e2ceda61e7a157f01d44dcb4490dcb1e87d057060 @@ -2185,11 +2185,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 9ea6bcc8fdf6aadb756ec5bcaaa7af314167f8973bdd32fd23f83bd964f0c21e -R 069cab252330979e2eef5b88f83953a3 -T *branch * compound-subquery-affinity -T *sym-compound-subquery-affinity * -T -sym-trunk * +P 779723ad792ca24dd07b7a1425303c76b44bb173e718a33c26c9f7644e9912cb +R 365eec55f15f0f323e41980c307a2a9e U drh -Z 7c2ae6bcf3d76ce120ccc503dbc0842f +Z 924642415660e94bafdaa96d702ef424 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index b78d32b4c4..208bda000a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -779723ad792ca24dd07b7a1425303c76b44bb173e718a33c26c9f7644e9912cb \ No newline at end of file +b8ec8511b1968bbc1472b3e2e21f0fef1d5becebeb31f9d13ee3ca9e13abb1e5 \ No newline at end of file diff --git a/src/select.c b/src/select.c index d391762039..785f9bc255 100644 --- a/src/select.c +++ b/src/select.c @@ -2336,17 +2336,21 @@ void sqlite3SubqueryColumnTypes( for(i=0, pCol=pTab->aCol; inCol; i++, pCol++){ const char *zType; i64 n; + Select *pS2 = pSelect; pTab->tabFlags |= (pCol->colFlags & COLFLAG_NOINSERT); p = a[i].pExpr; /* pCol->szEst = ... // Column size est for SELECT tables never used */ pCol->affinity = sqlite3ExprAffinity(p); + while( pCol->affinity<=SQLITE_AFF_NONE && pS2->pNext!=0 ){ + pS2 = pS2->pNext; + pCol->affinity = sqlite3ExprAffinity(pS2->pEList->a[i].pExpr); + } if( pCol->affinity<=SQLITE_AFF_NONE ){ pCol->affinity = aff; } - if( pCol->affinity>=SQLITE_AFF_TEXT && pSelect->pNext ){ + if( pCol->affinity>=SQLITE_AFF_TEXT && pS2->pNext ){ int m = 0; - Select *pS2; - for(m=0, pS2=pSelect->pNext; pS2; pS2=pS2->pNext){ + for(m=0, pS2=pS2->pNext; pS2; pS2=pS2->pNext){ m |= sqlite3ExprDataType(pS2->pEList->a[i].pExpr); } if( pCol->affinity==SQLITE_AFF_TEXT && (m&0x01)!=0 ){ @@ -6417,7 +6421,7 @@ static void selectAddSubqueryTypeInfo(Walker *pWalker, Select *p){ /* A sub-query in the FROM clause of a SELECT */ Select *pSel = pFrom->pSelect; if( pSel ){ - sqlite3SubqueryColumnTypes(pParse, pTab, pSel, SQLITE_AFF_BLOB); + sqlite3SubqueryColumnTypes(pParse, pTab, pSel, SQLITE_AFF_NONE); } } } diff --git a/test/view.test b/test/view.test index 612e0cc2e4..241742025c 100644 --- a/test/view.test +++ b/test/view.test @@ -737,16 +737,16 @@ do_execsql_test view-27.5 { do_execsql_test view-27.6 { SELECT c0 Date: Thu, 25 Apr 2024 17:52:10 +0000 Subject: [PATCH 347/430] Further improvements to the computation of affinity for compound subqueries: make sure that the selected affinity is compatible with a literal values in arms to the left of the arm that is used to determine affinity. FossilOrigin-Name: bbdf22e3d989f42b963f1f2f219dfeac11db786f17ac27097ab72f72e7638a2a --- manifest | 14 +++++------ manifest.uuid | 2 +- src/select.c | 7 +++--- test/subquery.test | 59 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 91f3bc3d8e..59e89aa32f 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Back\sout\sthe\sprevious\schange\son\sthis\sbranch.\s\sIn\sits\splace:\s\sDetermine\sthe\naffinity\sof\sa\ssubquery\sby\sthe\sleft-most\sarm\sof\sthe\ssubquery\sthat\shas\san\naffinity\sother\sthan\sNONE.\s\sIn\sother\swords,\sscan\sfrom\sleft\sto\sright\slooking\nfor\san\sarm\sof\sthe\scompound\ssubquery\swith\san\saffinity\sof\sBLOB,\sTEXT,\sINTEGER,\nor\sREAL\sand\spick\sthe\sfirst\sone\sfound.\s\sOr\sstay\swith\sNONE\sif\sno\sarm\shas\sa\ndefined\saffinity.\s\sTest\scases\sadded. -D 2024-04-25T16:55:53.038 +C Further\simprovements\sto\sthe\scomputation\sof\saffinity\sfor\scompound\ssubqueries:\nmake\ssure\sthat\sthe\sselected\saffinity\sis\scompatible\swith\sa\sliteral\svalues\sin\narms\sto\sthe\sleft\sof\sthe\sarm\sthat\sis\sused\sto\sdetermine\saffinity. +D 2024-04-25T17:52:10.004 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -751,7 +751,7 @@ F src/printf.c 8b250972305e14b365561be5117ed0fd364e4fd58968776df1ce64c6280b90f9 F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c 647edf93729ba124c0a6048982af56c2fa4f841e69d626e4f3caa620f082bb15 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 -F src/select.c f0f8f7fd601aff50c303205c6ac6da789d02a6e420ccb25d9aaaeccc7fa314d7 +F src/select.c 04178566d0188be7de471064ced8cec1d407920726cb49b609486282d78faf56 F src/shell.c.in 0354ca51eee5fbf6af394a7ef9f5ef6823ef45b743db65431f6777e4d5be2199 F src/sqlite.h.in 32389e0d584551b300d0157881336162c14315a424cbf385c0d65eb7c2e31f7b F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 @@ -1662,7 +1662,7 @@ F test/stmtvtab1.test 6873dfb24f8e79cbb5b799b95c2e4349060eb7a3b811982749a84b3594 F test/strict1.test 4d2b492152b984fd7e8196d23eb88e2ccb0ef9e46ca2f96c2ce7147ceef9d168 F test/strict2.test b22c7a98b5000aef937f1990776497f0e979b1a23bc4f63e2d53b00e59b20070 F test/subjournal.test 8d4e2572c0ee9a15549f0d8e40863161295107e52f07a3e8012a2e1fdd093c49 -F test/subquery.test 312c5d26304b0e93a56ba2cb9d4480b8a1c8217e3b2b8f8be2bfb0b2458ac3a7 +F test/subquery.test 903abf41049f8404256f7be24b3151328304a5b25162e17ab0079460237382fc F test/subquery2.test 90cf944b9de8204569cf656028391e4af1ccc8c0cc02d4ef38ee3be8de1ffb12 F test/subselect.test 0966aa8e720224dbd6a5e769a3ec2a723e332303 F test/substr.test a673e3763e247e9b5e497a6cacbaf3da2bd8ec8921c0677145c109f2e633f36b @@ -2185,8 +2185,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 779723ad792ca24dd07b7a1425303c76b44bb173e718a33c26c9f7644e9912cb -R 365eec55f15f0f323e41980c307a2a9e +P b8ec8511b1968bbc1472b3e2e21f0fef1d5becebeb31f9d13ee3ca9e13abb1e5 +R a7fab6239835ca1909d168c0371f9e50 U drh -Z 924642415660e94bafdaa96d702ef424 +Z 0a86570527084dd8d6c773960419770f # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 208bda000a..392481f925 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b8ec8511b1968bbc1472b3e2e21f0fef1d5becebeb31f9d13ee3ca9e13abb1e5 \ No newline at end of file +bbdf22e3d989f42b963f1f2f219dfeac11db786f17ac27097ab72f72e7638a2a \ No newline at end of file diff --git a/src/select.c b/src/select.c index 785f9bc255..8ee59cf68a 100644 --- a/src/select.c +++ b/src/select.c @@ -2336,21 +2336,22 @@ void sqlite3SubqueryColumnTypes( for(i=0, pCol=pTab->aCol; inCol; i++, pCol++){ const char *zType; i64 n; + int m = 0; Select *pS2 = pSelect; pTab->tabFlags |= (pCol->colFlags & COLFLAG_NOINSERT); p = a[i].pExpr; /* pCol->szEst = ... // Column size est for SELECT tables never used */ pCol->affinity = sqlite3ExprAffinity(p); while( pCol->affinity<=SQLITE_AFF_NONE && pS2->pNext!=0 ){ + m |= sqlite3ExprDataType(pS2->pEList->a[i].pExpr); pS2 = pS2->pNext; pCol->affinity = sqlite3ExprAffinity(pS2->pEList->a[i].pExpr); } if( pCol->affinity<=SQLITE_AFF_NONE ){ pCol->affinity = aff; } - if( pCol->affinity>=SQLITE_AFF_TEXT && pS2->pNext ){ - int m = 0; - for(m=0, pS2=pS2->pNext; pS2; pS2=pS2->pNext){ + if( pCol->affinity>=SQLITE_AFF_TEXT && (pS2->pNext || pS2!=pSelect) ){ + for(pS2=pS2->pNext; pS2; pS2=pS2->pNext){ m |= sqlite3ExprDataType(pS2->pEList->a[i].pExpr); } if( pCol->affinity==SQLITE_AFF_TEXT && (m&0x01)!=0 ){ diff --git a/test/subquery.test b/test/subquery.test index c51edba040..17061d4b60 100644 --- a/test/subquery.test +++ b/test/subquery.test @@ -651,5 +651,64 @@ do_eqp_test subquery-10.2 { # `--SEARCH t1 USING INDEX x12 (aa=?) # +#----------------------------------------------------------------------------- +# 2024-04-25 Column affinities for columns of compound subqueries +# +reset_db +sqlite3_test_control SQLITE_TESTCTRL_INTERNAL_FUNCTIONS db +do_execsql_test subquery-11.1 { + CREATE TABLE t1(ix INT, rx REAL, bx BLOB, tx TEXT, ax); + INSERT INTO t1 VALUES(1,1.0,x'31','x',NULL); + WITH c(a) AS (SELECT 'y' UNION SELECT tx FROM t1) SELECT affinity(a) FROM c; + WITH c(a) AS (SELECT tx FROM t1 UNION SELECT 'y') SELECT affinity(a) FROM c; +} {text text text text} +do_execsql_test subquery-11.2 { + WITH c(a) AS (SELECT 2 UNION SELECT tx FROM t1) SELECT affinity(a) FROM c; + WITH c(a) AS (SELECT tx FROM t1 UNION SELECT 2) SELECT affinity(a) FROM c; +} {blob blob blob blob} +do_execsql_test subquery-11.3 { + WITH c(a) AS (SELECT 2.0 UNION SELECT tx FROM t1) SELECT affinity(a) FROM c; + WITH c(a) AS (SELECT tx FROM t1 UNION SELECT 2.0) SELECT affinity(a) FROM c; +} {blob blob blob blob} +do_execsql_test subquery-11.4 { + WITH c(a) AS (SELECT null UNION SELECT tx FROM t1) SELECT affinity(a) FROM c; + WITH c(a) AS (SELECT tx FROM t1 UNION SELECT null) SELECT affinity(a) FROM c; +} {text text text text} +do_execsql_test subquery-11.5 { + WITH c(a) AS (SELECT x'32' UNION SELECT tx FROM t1) SELECT affinity(a) FROM c; + WITH c(a) AS (SELECT tx FROM t1 UNION SELECT x'32') SELECT affinity(a) FROM c; +} {text text text text} +do_execsql_test subquery-11.6 { + WITH c(a) AS (SELECT 3 UNION SELECT ix FROM t1) SELECT affinity(a) FROM c; + WITH c(a) AS (SELECT ix FROM t1 UNION SELECT 3) SELECT affinity(a) FROM c; +} {integer integer integer integer} +do_execsql_test subquery-11.7 { + WITH c(a) AS (SELECT 3.0 UNION SELECT ix FROM t1) SELECT affinity(a) FROM c; + WITH c(a) AS (SELECT ix FROM t1 UNION SELECT 3.0) SELECT affinity(a) FROM c; +} {integer integer integer integer} +do_execsql_test subquery-11.8 { + WITH c(a) AS (SELECT '3' UNION SELECT ix FROM t1) SELECT affinity(a) FROM c; + WITH c(a) AS (SELECT ix FROM t1 UNION SELECT '3') SELECT affinity(a) FROM c; +} {blob blob blob blob} +do_execsql_test subquery-11.10 { + WITH c(a) AS (SELECT x'32' UNION SELECT ix FROM t1) SELECT affinity(a) FROM c; + WITH c(a) AS (SELECT ix FROM t1 UNION SELECT x'32') SELECT affinity(a) FROM c; +} {integer integer integer integer} +do_execsql_test subquery-11.11 { + WITH c(a) AS (SELECT 4 UNION SELECT rx FROM t1) SELECT affinity(a) FROM c; + WITH c(a) AS (SELECT rx FROM t1 UNION SELECT 4) SELECT affinity(a) FROM c; +} {real real real real} +do_execsql_test subquery-11.12 { + WITH c(a) AS (SELECT '4' UNION SELECT rx FROM t1) SELECT affinity(a) FROM c; + WITH c(a) AS (SELECT rx FROM t1 UNION SELECT '4') SELECT affinity(a) FROM c; +} {blob blob blob blob} +do_execsql_test subquery-11.13 { + WITH c(a) AS (SELECT null UNION SELECT rx FROM t1) SELECT affinity(a) FROM c; + WITH c(a) AS (SELECT rx FROM t1 UNION SELECT null) SELECT affinity(a) FROM c; +} {real real real real} +do_execsql_test subquery-11.14 { + WITH c(a) AS (SELECT x'b4' UNION SELECT rx FROM t1) SELECT affinity(a) FROM c; + WITH c(a) AS (SELECT rx FROM t1 UNION SELECT x'b4') SELECT affinity(a) FROM c; +} {real real real real} finish_test From fed13d50a98b1c173449e0626dd3bb19f791e495 Mon Sep 17 00:00:00 2001 From: drh <> Date: Fri, 26 Apr 2024 11:32:50 +0000 Subject: [PATCH 348/430] Fix the TreeView display of a LIMIT clause on a compound query. Debugging code only - not part of production builds. FossilOrigin-Name: 38f1e5ce4eedd59fbeb0a0d676d26dfe8a3313189ab9b9e4a5a1ed6721b73a14 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/treeview.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 0c6764a1bf..234d44e742 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improvement\sto\sthe\sway\sthat\saffinity\sis\sdetermined\sfor\scolumns\sof\sa\ncompound\ssubquery.\s\sThe\saffinity\sis\sthe\saffinity\sof\sthe\sleft-most\narm\sof\sthe\scompound\ssubquery\sthat\shas\san\saffinity\sother\sthan\sNONE,\sadjusted\nto\saccommodate\sthe\sdata\stypes\scoming\sout\sof\sthe\sother\sarms. -D 2024-04-25T23:26:11.710 +C Fix\sthe\sTreeView\sdisplay\sof\sa\sLIMIT\sclause\son\sa\scompound\squery.\s\sDebugging\ncode\sonly\s-\snot\spart\sof\sproduction\sbuilds. +D 2024-04-26T11:32:50.631 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -814,7 +814,7 @@ F src/test_window.c cdae419fdcea5bad6dcd9368c685abdad6deb59e9fc8b84b153de513d394 F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9 F src/threads.c 4ae07fa022a3dc7c5beb373cf744a85d3c5c6c3c F src/tokenize.c 3f703cacdab728d7741e5a6ac242006d74fe1c2754d4f03ed889d7253259bd68 -F src/treeview.c a8aa3086c886c6eb2ff2b6354b0f23d251f7219bf08fad52d4f2791e55324f1b +F src/treeview.c 4f9ba6c1c7c9893fc046fdb0bc1f6bdec7660122b1ae37e51fb9b64c286caafd F src/trigger.c 0858f75818ed1580332db274f1032bcc5effe567cb132df5c5be8b1d800ca97f F src/update.c 732404a04d1737ef14bb6ec6b84f74edf28b3c102a92ae46b4855438a710efe7 F src/upsert.c 2e60567a0e9e8520c18671b30712a88dc73534474304af94f32bb5f3ef65ac65 @@ -2185,8 +2185,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P d99a01a0f6e1f70f70c9a0625aeaa8a8015eba352bcfb3978eafca6df10ba5a8 bbdf22e3d989f42b963f1f2f219dfeac11db786f17ac27097ab72f72e7638a2a -R 654e0ae3f3741f82dda9d50fba2bb5a6 +P e6df846f36209bac3e420dd80ce2bbbd87ab7a20b8063fce05f78a3c7ab6027e +R cad28780e6b446bd6e2b3d9b26a145c6 U drh -Z cd9aa5444a2a196c931f4e6dcda6cddb +Z 00ad49f6765aaa2802fdc1e87b94bb22 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index d5803c8f68..17975a5072 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e6df846f36209bac3e420dd80ce2bbbd87ab7a20b8063fce05f78a3c7ab6027e \ No newline at end of file +38f1e5ce4eedd59fbeb0a0d676d26dfe8a3313189ab9b9e4a5a1ed6721b73a14 \ No newline at end of file diff --git a/src/treeview.c b/src/treeview.c index c223db29e0..d3346b4686 100644 --- a/src/treeview.c +++ b/src/treeview.c @@ -346,7 +346,7 @@ void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 moreToFollow){ sqlite3TreeViewItem(pView, "LIMIT", (n--)>0); sqlite3TreeViewExpr(pView, p->pLimit->pLeft, p->pLimit->pRight!=0); if( p->pLimit->pRight ){ - sqlite3TreeViewItem(pView, "OFFSET", (n--)>0); + sqlite3TreeViewItem(pView, "OFFSET", 0); sqlite3TreeViewExpr(pView, p->pLimit->pRight, 0); sqlite3TreeViewPop(&pView); } From d591a5b93d4f84c3e0a3080109936be22292607f Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 26 Apr 2024 12:01:17 +0000 Subject: [PATCH 349/430] Add test demonstrating the problem at [forum:/forumpost/c243b8f856|forum post c243b8f856]. No fix yet. FossilOrigin-Name: 1685495c0a00238c9c92cce01af8108204a2fad22433ed3e7bba3c9da9ee0766 --- manifest | 16 +++-- manifest.uuid | 2 +- test/bestindexC.test | 137 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 148 insertions(+), 7 deletions(-) create mode 100644 test/bestindexC.test diff --git a/manifest b/manifest index 0c6764a1bf..5aaf6f32cc 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improvement\sto\sthe\sway\sthat\saffinity\sis\sdetermined\sfor\scolumns\sof\sa\ncompound\ssubquery.\s\sThe\saffinity\sis\sthe\saffinity\sof\sthe\sleft-most\narm\sof\sthe\scompound\ssubquery\sthat\shas\san\saffinity\sother\sthan\sNONE,\sadjusted\nto\saccommodate\sthe\sdata\stypes\scoming\sout\sof\sthe\sother\sarms. -D 2024-04-25T23:26:11.710 +C Add\stest\sdemonstrating\sthe\sproblem\sat\s[forum:/forumpost/c243b8f856|forum\spost\sc243b8f856].\sNo\sfix\syet. +D 2024-04-26T12:01:17.532 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -936,6 +936,7 @@ F test/bestindex8.test 333ad8c6a554b885a49b68c019166eda92b05f493a92b36b0acdf7f76 F test/bestindex9.test 1a4b93db117fd8abe74ae9be982f86aa72f01e60cd4ac541e6ede39673a451a0 F test/bestindexA.test e1b5def6b190797cacf008e6815ffb78fb30261999030d60a728d572eef44c7f F test/bestindexB.test 328b97b69cd1a20928d5997f9ecb04d2e00f1d18e19ab27f9e9adb44d7bc51ce +F test/bestindexC.test cddef2bfebfce49f27d93de6db070e158842e9414ade05e2ddd9f869691bf698 F test/between.test b9a65fb065391980119e8a781a7409d3fcf059d89968279c750e190a9a1d5263 F test/bigfile.test aa74f4e5db51c8e54a1d9de9fa65d01d1eb20b59 F test/bigfile2.test 1b489a3a39ae90c7f027b79110d6b4e1dbc71bfc @@ -2185,8 +2186,11 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P d99a01a0f6e1f70f70c9a0625aeaa8a8015eba352bcfb3978eafca6df10ba5a8 bbdf22e3d989f42b963f1f2f219dfeac11db786f17ac27097ab72f72e7638a2a -R 654e0ae3f3741f82dda9d50fba2bb5a6 -U drh -Z cd9aa5444a2a196c931f4e6dcda6cddb +P e6df846f36209bac3e420dd80ce2bbbd87ab7a20b8063fce05f78a3c7ab6027e +R 86e9e2a691d55b415e3c7d753f120811 +T *branch * vtab-limit-fix +T *sym-vtab-limit-fix * +T -sym-trunk * +U dan +Z 98d2dacd3c5e1da28914a036142cb128 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index d5803c8f68..80649ce5f9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e6df846f36209bac3e420dd80ce2bbbd87ab7a20b8063fce05f78a3c7ab6027e \ No newline at end of file +1685495c0a00238c9c92cce01af8108204a2fad22433ed3e7bba3c9da9ee0766 \ No newline at end of file diff --git a/test/bestindexC.test b/test/bestindexC.test new file mode 100644 index 0000000000..91b8f027eb --- /dev/null +++ b/test/bestindexC.test @@ -0,0 +1,137 @@ +# 2023-10-26 +# +# 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. +# +#*********************************************************************** +# +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix bestindexB + +ifcapable !vtab { + finish_test + return +} + +register_tcl_module db + +proc vtab_command {lVal method args} { + switch -- $method { + xConnect { + return "CREATE TABLE t1(a)" + } + + xBestIndex { + set hdl [lindex $args 0] + set clist [$hdl constraints] + set orderby [$hdl orderby] + + set idxstr [list] + set res [list] + + set idx 0 + foreach c $clist { + array set a $c + if {$a(usable)==0} continue + if {$a(op)=="limit"} { + lappend idxstr limit + lappend res omit $idx + } + if {$a(op)=="offset"} { + lappend idxstr offset + lappend res omit $idx + } + incr idx + } + + return "cost 1000000 rows 1000000 idxnum 0 idxstr {$idxstr} $res" + } + + xFilter { + set idxstr [lindex $args 1] + set LIMIT "" + foreach a $idxstr b [lindex $args 2] { + append LIMIT " $a $b" + } + + set idx 1 + foreach v $lVal { + lappend lRow "($idx, '$v')" + incr idx + } + + return [list sql " + SELECT * FROM ( VALUES [join $lRow ,]) $LIMIT + "] + } + } + + return {} +} + +do_execsql_test 1.0 { + CREATE VIRTUAL TABLE x1 USING tcl(vtab_command "a b c d e f"); + CREATE VIRTUAL TABLE x2 USING tcl(vtab_command "A B C D E F a b"); +} {} + +do_execsql_test 1.1 { + CREATE TEMP TABLE t_unionall AS + SELECT * FROM x1 UNION ALL SELECT * FROM x2; + + CREATE TEMP TABLE t_intersect AS + SELECT * FROM x1 INTERSECT SELECT * FROM x2; + + CREATE TEMP TABLE t_union AS + SELECT * FROM x1 UNION SELECT * FROM x2; + + CREATE TEMP TABLE t_except AS + SELECT * FROM x1 EXCEPT SELECT * FROM x2; +} + +foreach {tn limit} { + 1 "LIMIT 8" + 2 "LIMIT 4" + 3 "LIMIT 4 OFFSET 2" + 4 "LIMIT 8 OFFSET 4" +} { + + foreach {op tbl} { + "UNION ALL" t_unionall + "UNION" t_union + "INTERSECT" t_intersect + "EXCEPT" t_except + } { + + set expect [execsql "SELECT * FROM $tbl $limit"] + do_execsql_test 1.2.$tbl.$tn "SELECT * FROM ( + SELECT * FROM x1 $op SELECT * FROM x2 + ) $limit" $expect + + } + +} + +#------------------------------------------------------------------------- +reset_db +register_tcl_module db + +do_execsql_test 2.0 { + CREATE VIRTUAL TABLE x1 USING tcl(vtab_command "a b c d e f"); + CREATE VIRTUAL TABLE x2 USING tcl(vtab_command "a b e f"); +} {} + +do_execsql_test 2.1 { + SELECT * FROM x1 + EXCEPT + SELECT * FROM x2 + LIMIT 3 +} {c d} + +finish_test From 317b7416a6e1a33446ee2fe3478ae4c13075c18b Mon Sep 17 00:00:00 2001 From: drh <> Date: Fri, 26 Apr 2024 13:30:48 +0000 Subject: [PATCH 350/430] Enhance the generated_series() table-valued-function to respond to LIMIT and OFFSET. Use this to add new test cases for LIMIT and OFFSET on virtual tables in a compound SELECT. FossilOrigin-Name: 408d47ecaa3b906d0886f76a22b76339ec5878270ffe8d1838c74de09c29a33e --- ext/misc/series.c | 80 +++++++++++++++++++++++++++++++++------------ manifest | 19 +++++------ manifest.uuid | 2 +- test/tabfunc01.test | 26 +++++++++++++++ 4 files changed, 94 insertions(+), 33 deletions(-) diff --git a/ext/misc/series.c b/ext/misc/series.c index 3e859a8f23..22968854ca 100644 --- a/ext/misc/series.c +++ b/ext/misc/series.c @@ -376,13 +376,13 @@ static int seriesEof(sqlite3_vtab_cursor *cur){ ** parameter. (idxStr is not used in this implementation.) idxNum ** is a bitmask showing which constraints are available: ** -** 1: start=VALUE -** 2: stop=VALUE -** 4: step=VALUE -** -** Also, if bit 8 is set, that means that the series should be output -** in descending order rather than in ascending order. If bit 16 is -** set, then output must appear in ascending order. +** 0x01: start=VALUE +** 0x02: stop=VALUE +** 0x04: step=VALUE +** 0x08: descending order +** 0x10: ascending order +** 0x20: LIMIT VALUE +** 0x40: OFFSET VALUE ** ** This routine should initialize the cursor and position it so that it ** is pointing at the first row, or pointing off the end of the table @@ -396,17 +396,17 @@ static int seriesFilter( series_cursor *pCur = (series_cursor *)pVtabCursor; int i = 0; (void)idxStrUnused; - if( idxNum & 1 ){ + if( idxNum & 0x01 ){ pCur->ss.iBase = sqlite3_value_int64(argv[i++]); }else{ pCur->ss.iBase = 0; } - if( idxNum & 2 ){ + if( idxNum & 0x02 ){ pCur->ss.iTerm = sqlite3_value_int64(argv[i++]); }else{ pCur->ss.iTerm = 0xffffffff; } - if( idxNum & 4 ){ + if( idxNum & 0x04 ){ pCur->ss.iStep = sqlite3_value_int64(argv[i++]); if( pCur->ss.iStep==0 ){ pCur->ss.iStep = 1; @@ -416,6 +416,24 @@ static int seriesFilter( }else{ pCur->ss.iStep = 1; } + if( idxNum & 0x20 ){ + sqlite3_int64 iLimit = sqlite3_value_int64(argv[i++]); + sqlite3_int64 iTerm; + if( idxNum & 0x40 ){ + sqlite3_int64 iOffset = sqlite3_value_int64(argv[i++]); + if( iOffset>0 ){ + pCur->ss.iBase += pCur->ss.iStep*iOffset; + } + } + if( iLimit>=0 ){ + iTerm = pCur->ss.iBase + (iLimit - 1)*pCur->ss.iStep; + if( pCur->ss.iStep<0 ){ + if( iTerm>pCur->ss.iTerm ) pCur->ss.iTerm = iTerm; + }else{ + if( iTermss.iTerm ) pCur->ss.iTerm = iTerm; + } + } + } for(i=0; iss.isReversing = pCur->ss.iStep > 0; }else{ pCur->ss.isReversing = pCur->ss.iStep < 0; @@ -446,10 +464,13 @@ static int seriesFilter( ** ** The query plan is represented by bits in idxNum: ** -** (1) start = $value -- constraint exists -** (2) stop = $value -- constraint exists -** (4) step = $value -- constraint exists -** (8) output in descending order +** 0x01 start = $value -- constraint exists +** 0x02 stop = $value -- constraint exists +** 0x04 step = $value -- constraint exists +** 0x08 output is in descending order +** 0x10 output is in ascending order +** 0x20 LIMIT $value -- constraint exists +** 0x40 OFFSET $value -- constraint exists */ static int seriesBestIndex( sqlite3_vtab *pVTab, @@ -460,7 +481,7 @@ static int seriesBestIndex( int bStartSeen = 0; /* EQ constraint seen on the START column */ int unusableMask = 0; /* Mask of unusable constraints */ int nArg = 0; /* Number of arguments that seriesFilter() expects */ - int aIdx[3]; /* Constraints on start, stop, and step */ + int aIdx[5]; /* Constraints on start, stop, step, LIMIT, OFFSET */ const struct sqlite3_index_constraint *pConstraint; /* This implementation assumes that the start, stop, and step columns @@ -468,11 +489,22 @@ static int seriesBestIndex( assert( SERIES_COLUMN_STOP == SERIES_COLUMN_START+1 ); assert( SERIES_COLUMN_STEP == SERIES_COLUMN_START+2 ); - aIdx[0] = aIdx[1] = aIdx[2] = -1; + aIdx[0] = aIdx[1] = aIdx[2] = aIdx[3] = aIdx[4] = -1; pConstraint = pIdxInfo->aConstraint; for(i=0; inConstraint; i++, pConstraint++){ int iCol; /* 0 for start, 1 for stop, 2 for step */ int iMask; /* bitmask for those column */ + int op = pConstraint->op; + if( op!=SQLITE_INDEX_CONSTRAINT_EQ ){ + if( op==SQLITE_INDEX_CONSTRAINT_LIMIT ){ + aIdx[3] = i; + idxNum |= 0x20; + }else if( op==SQLITE_INDEX_CONSTRAINT_OFFSET ){ + aIdx[4] = i; + idxNum |= 0x40; + } + continue; + } if( pConstraint->iColumniColumn - SERIES_COLUMN_START; assert( iCol>=0 && iCol<=2 ); @@ -486,10 +518,16 @@ static int seriesBestIndex( aIdx[iCol] = i; } } - for(i=0; i<3; i++){ + if( aIdx[3]==0 ){ + /* Ignore OFFSET if LIMIT is omitted */ + idxNum &= ~0x60; + aIdx[4] = 0; + } + for(i=0; i<5; i++){ if( (j = aIdx[i])>=0 ){ pIdxInfo->aConstraintUsage[j].argvIndex = ++nArg; - pIdxInfo->aConstraintUsage[j].omit = !SQLITE_SERIES_CONSTRAINT_VERIFY; + pIdxInfo->aConstraintUsage[j].omit = + !SQLITE_SERIES_CONSTRAINT_VERIFY || i>=3; } } /* The current generate_column() implementation requires at least one @@ -517,9 +555,9 @@ static int seriesBestIndex( pIdxInfo->estimatedRows = 1000; if( pIdxInfo->nOrderBy>=1 && pIdxInfo->aOrderBy[0].iColumn==0 ){ if( pIdxInfo->aOrderBy[0].desc ){ - idxNum |= 8; + idxNum |= 0x08; }else{ - idxNum |= 16; + idxNum |= 0x10; } pIdxInfo->orderByConsumed = 1; } diff --git a/manifest b/manifest index 5aaf6f32cc..df3495002e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\stest\sdemonstrating\sthe\sproblem\sat\s[forum:/forumpost/c243b8f856|forum\spost\sc243b8f856].\sNo\sfix\syet. -D 2024-04-26T12:01:17.532 +C Enhance\sthe\sgenerated_series()\stable-valued-function\sto\srespond\sto\nLIMIT\sand\sOFFSET.\s\sUse\sthis\sto\sadd\snew\stest\scases\sfor\sLIMIT\sand\sOFFSET\non\svirtual\stables\sin\sa\scompound\sSELECT. +D 2024-04-26T13:30:48.724 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -411,7 +411,7 @@ F ext/misc/regexp.c 4bdd0045912f81c84908bd535ec5ad3b1c8540b4287c70ab840709636240 F ext/misc/remember.c add730f0f7e7436cd15ea3fd6a90fd83c3f706ab44169f7f048438b7d6baa69c F ext/misc/rot13.c 51ac5f51e9d5fd811db58a9c23c628ad5f333c173f1fc53c8491a3603d38556c F ext/misc/scrub.c 2a44b0d44c69584c0580ad2553f6290a307a49df4668941d2812135bfb96a946 -F ext/misc/series.c 384f93a8a09cf45e1aa6575660cb580ed61d372c590aad05cdcd4a84fbd8f6ab +F ext/misc/series.c 69df6c989a37c58d831dcd4c6742ea7c98bc1517d45905290445f3bb277d2cbf F ext/misc/sha1.c 4011aef176616872b2a0d5bccf0ecfb1f7ce3fe5c3d107f3a8e949d8e1e3f08d F ext/misc/shathree.c 543af7ce71d391cd3a9ab6924a6a1124efc63211fd0f2e240dc4b56077ba88ac F ext/misc/showauth.c 732578f0fe4ce42d577e1c86dc89dd14a006ab52 @@ -1679,7 +1679,7 @@ F test/sync.test 89539f4973c010eda5638407e71ca7fddbcd8e0594f4c9980229f804d433309 F test/sync2.test 8f9f7d4f6d5be8ca8941a8dadcc4299e558cb6a1ff653a9469146c7a76ef2039 F test/syscall.test a39d9a36f852ae6e4800f861bc2f2e83f68bbc2112d9399931ecfadeabd2d69d F test/sysfault.test c9f2b0d8d677558f74de750c75e12a5454719d04 -F test/tabfunc01.test 54f27eacd054aa528a8b6e3331192c484104f30aaee351ad035f2b39a00f87c4 +F test/tabfunc01.test f150d206294471d20f50029e6b46b76b87a7a010b16dc57eb44245c76dd02802 F test/table.test 7862a00b58b5541511a26757ea9c5c7c3f8298766e98aa099deec703d9c0a8e0 F test/tableapi.test ecbcc29c4ab62c1912c3717c48ea5c5e59f7d64e4a91034e6148bd2b82f177f4 F test/tableopts.test dba698ba97251017b7c80d738c198d39ab747930 @@ -2186,11 +2186,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P e6df846f36209bac3e420dd80ce2bbbd87ab7a20b8063fce05f78a3c7ab6027e -R 86e9e2a691d55b415e3c7d753f120811 -T *branch * vtab-limit-fix -T *sym-vtab-limit-fix * -T -sym-trunk * -U dan -Z 98d2dacd3c5e1da28914a036142cb128 +P 1685495c0a00238c9c92cce01af8108204a2fad22433ed3e7bba3c9da9ee0766 +R 5bce82b446834e1e285fe6cb5599985f +U drh +Z 002d1fa139abb35e0569e061564589d9 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 80649ce5f9..9a585c8218 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1685495c0a00238c9c92cce01af8108204a2fad22433ed3e7bba3c9da9ee0766 \ No newline at end of file +408d47ecaa3b906d0886f76a22b76339ec5878270ffe8d1838c74de09c29a33e \ No newline at end of file diff --git a/test/tabfunc01.test b/test/tabfunc01.test index 8e90c549fa..3a62b81f99 100644 --- a/test/tabfunc01.test +++ b/test/tabfunc01.test @@ -322,6 +322,32 @@ ifcapable altertable { } {1 {table pragma_compile_options may not be altered}} } +#----------------------------------------------------------------------------- +# 2024-04-26 LIMIT and OFFSET passed into virtual tables +# https://sqlite.org/forum/forumpost/c243b8f856 +# +do_execsql_test tabfunc01-900 { + SELECT * FROM ( + SELECT * FROM generate_series(1,10) + UNION ALL + SELECT * FROM generate_series(101,104) + ) LIMIT 10 OFFSET 5; +} {6 7 8 9 10 101 102 103 104} +do_execsql_test tabfunc01-910 { + SELECT * FROM ( + SELECT * FROM generate_series(1,10) + UNION ALL + SELECT * FROM generate_series(101,104) + ) LIMIT -1 OFFSET 5; +} {6 7 8 9 10 101 102 103 104} +do_execsql_test tabfunc01-920 { + SELECT * FROM ( + SELECT * FROM generate_series(1,10) + UNION ALL + SELECT * FROM generate_series(101,104) + ) LIMIT -1 OFFSET 0; +} {1 2 3 4 5 6 7 8 9 10 101 102 103 104} + # Free up memory allocations intarray_addr From 99ac2324aa7f52713d4a14b29e0dde6f2c9479aa Mon Sep 17 00:00:00 2001 From: drh <> Date: Fri, 26 Apr 2024 13:38:43 +0000 Subject: [PATCH 351/430] Fix handling of LIMIT and OFFSET in virtual tables that are part of a compound SELECT. FossilOrigin-Name: 40421c1c4ed5bb1ed79ad7ee37cb5a4f0b7864c1eb94abd8ee357ab2202cad30 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/whereexpr.c | 8 +++++--- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index df3495002e..29cf2f4115 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Enhance\sthe\sgenerated_series()\stable-valued-function\sto\srespond\sto\nLIMIT\sand\sOFFSET.\s\sUse\sthis\sto\sadd\snew\stest\scases\sfor\sLIMIT\sand\sOFFSET\non\svirtual\stables\sin\sa\scompound\sSELECT. -D 2024-04-26T13:30:48.724 +C Fix\shandling\sof\sLIMIT\sand\sOFFSET\sin\svirtual\stables\sthat\sare\spart\sof\na\scompound\sSELECT. +D 2024-04-26T13:38:43.836 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -839,7 +839,7 @@ F src/walker.c 7c7ea0115345851c3da4e04e2e239a29983b61fb5b038b94eede6aba462640e2 F src/where.c 447d8761632fb0a18b03077161415d9713cbd0a81bf34a35cee63480e5c401c5 F src/whereInt.h 82a13766f13d1a53b05387c2e60726289ef26404bc7b9b1f7770204d97357fb8 F src/wherecode.c 1f6940349e92a6e056aecd70163b00f331554c815c362b4cc80906c48151d73d -F src/whereexpr.c 7b64295f1d82ad0928df435925dd7bbd5997b44a026153113eace0d9e71ff435 +F src/whereexpr.c f6c25f7c8c0301f983dbf2ca06dc0081728e3a6c104f6ffdfacd64d80c5c2e76 F src/window.c 5d95122dd330bfaebd732358c8ef067c5a9394a53ac249470d611d0ce2c52be2 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/affinity2.test ce1aafc86e110685b324e9a763eab4f2a73f737842ec3b687bd965867de90627 @@ -2186,8 +2186,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 1685495c0a00238c9c92cce01af8108204a2fad22433ed3e7bba3c9da9ee0766 -R 5bce82b446834e1e285fe6cb5599985f +P 408d47ecaa3b906d0886f76a22b76339ec5878270ffe8d1838c74de09c29a33e +R 6c52e220da37a777a1b67496ddeb5f65 U drh -Z 002d1fa139abb35e0569e061564589d9 +Z b21bac460d0c0d27bd69b9e1b44612bb # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 9a585c8218..e5ba1bb14a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -408d47ecaa3b906d0886f76a22b76339ec5878270ffe8d1838c74de09c29a33e \ No newline at end of file +40421c1c4ed5bb1ed79ad7ee37cb5a4f0b7864c1eb94abd8ee357ab2202cad30 \ No newline at end of file diff --git a/src/whereexpr.c b/src/whereexpr.c index 9d1f947a09..ff6f753b5a 100644 --- a/src/whereexpr.c +++ b/src/whereexpr.c @@ -1652,9 +1652,11 @@ void SQLITE_NOINLINE sqlite3WhereAddLimit(WhereClause *pWC, Select *p){ /* All conditions are met. Add the terms to the where-clause object. */ assert( p->pLimit->op==TK_LIMIT ); - whereAddLimitExpr(pWC, p->iLimit, p->pLimit->pLeft, - iCsr, SQLITE_INDEX_CONSTRAINT_LIMIT); - if( p->iOffset>0 ){ + if( p->iOffset==0 || (p->selFlags & SF_Compound)==0 ){ + whereAddLimitExpr(pWC, p->iLimit, p->pLimit->pLeft, + iCsr, SQLITE_INDEX_CONSTRAINT_LIMIT); + } + if( p->iOffset!=0 && (p->selFlags & SF_Compound)==0 ){ whereAddLimitExpr(pWC, p->iOffset, p->pLimit->pRight, iCsr, SQLITE_INDEX_CONSTRAINT_OFFSET); } From 3afd5b6d6565902271c09d6fa487e68fef3e92a4 Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 26 Apr 2024 14:32:58 +0000 Subject: [PATCH 352/430] Fix a problem allowing a LIMIT constraint to be passed to a virtual table in cases where there exist WHERE terms that cannot also be passed. FossilOrigin-Name: 72c8ed9698dd2aadee7b84fd293e8306233f0fe5b5b5731687482444fdf461c7 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/whereexpr.c | 1 + test/bestindexC.test | 20 ++++++++++++++++++++ 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 29cf2f4115..a2f90a673f 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\shandling\sof\sLIMIT\sand\sOFFSET\sin\svirtual\stables\sthat\sare\spart\sof\na\scompound\sSELECT. -D 2024-04-26T13:38:43.836 +C Fix\sa\sproblem\sallowing\sa\sLIMIT\sconstraint\sto\sbe\spassed\sto\sa\svirtual\stable\sin\scases\swhere\sthere\sexist\sWHERE\sterms\sthat\scannot\salso\sbe\spassed. +D 2024-04-26T14:32:58.805 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -839,7 +839,7 @@ F src/walker.c 7c7ea0115345851c3da4e04e2e239a29983b61fb5b038b94eede6aba462640e2 F src/where.c 447d8761632fb0a18b03077161415d9713cbd0a81bf34a35cee63480e5c401c5 F src/whereInt.h 82a13766f13d1a53b05387c2e60726289ef26404bc7b9b1f7770204d97357fb8 F src/wherecode.c 1f6940349e92a6e056aecd70163b00f331554c815c362b4cc80906c48151d73d -F src/whereexpr.c f6c25f7c8c0301f983dbf2ca06dc0081728e3a6c104f6ffdfacd64d80c5c2e76 +F src/whereexpr.c e8e26dbdefa3d89c726251c8b9690ad9766ad00b92cfd11c54402e7dd1350ce7 F src/window.c 5d95122dd330bfaebd732358c8ef067c5a9394a53ac249470d611d0ce2c52be2 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/affinity2.test ce1aafc86e110685b324e9a763eab4f2a73f737842ec3b687bd965867de90627 @@ -936,7 +936,7 @@ F test/bestindex8.test 333ad8c6a554b885a49b68c019166eda92b05f493a92b36b0acdf7f76 F test/bestindex9.test 1a4b93db117fd8abe74ae9be982f86aa72f01e60cd4ac541e6ede39673a451a0 F test/bestindexA.test e1b5def6b190797cacf008e6815ffb78fb30261999030d60a728d572eef44c7f F test/bestindexB.test 328b97b69cd1a20928d5997f9ecb04d2e00f1d18e19ab27f9e9adb44d7bc51ce -F test/bestindexC.test cddef2bfebfce49f27d93de6db070e158842e9414ade05e2ddd9f869691bf698 +F test/bestindexC.test c4957155d9bd21a3e5bdd7cf32e9753b721fff7a373fdc7a8769a2a072877b7f F test/between.test b9a65fb065391980119e8a781a7409d3fcf059d89968279c750e190a9a1d5263 F test/bigfile.test aa74f4e5db51c8e54a1d9de9fa65d01d1eb20b59 F test/bigfile2.test 1b489a3a39ae90c7f027b79110d6b4e1dbc71bfc @@ -2186,8 +2186,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 408d47ecaa3b906d0886f76a22b76339ec5878270ffe8d1838c74de09c29a33e -R 6c52e220da37a777a1b67496ddeb5f65 -U drh -Z b21bac460d0c0d27bd69b9e1b44612bb +P 40421c1c4ed5bb1ed79ad7ee37cb5a4f0b7864c1eb94abd8ee357ab2202cad30 +R 2db4adc3908600896b903e9d700f2b90 +U dan +Z 2050298cecb5ad6b15cc33d4bff9b8cd # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index e5ba1bb14a..ba5576360c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -40421c1c4ed5bb1ed79ad7ee37cb5a4f0b7864c1eb94abd8ee357ab2202cad30 \ No newline at end of file +72c8ed9698dd2aadee7b84fd293e8306233f0fe5b5b5731687482444fdf461c7 \ No newline at end of file diff --git a/src/whereexpr.c b/src/whereexpr.c index ff6f753b5a..d25bce5f08 100644 --- a/src/whereexpr.c +++ b/src/whereexpr.c @@ -1638,6 +1638,7 @@ void SQLITE_NOINLINE sqlite3WhereAddLimit(WhereClause *pWC, Select *p){ continue; } if( pWC->a[ii].leftCursor!=iCsr ) return; + if( pWC->a[ii].prereqRight!=0 ) return; } /* Check condition (5). Return early if it is not met. */ diff --git a/test/bestindexC.test b/test/bestindexC.test index 91b8f027eb..769f1601db 100644 --- a/test/bestindexC.test +++ b/test/bestindexC.test @@ -134,4 +134,24 @@ do_execsql_test 2.1 { LIMIT 3 } {c d} +#------------------------------------------------------------------------- +reset_db +register_tcl_module db +do_execsql_test 3.0 { + CREATE VIRTUAL TABLE y1 USING tcl(vtab_command "1 2 3 4 5 6 7 8 9 10"); +} {} + +do_execsql_test 3.1 { + SELECT * FROM y1 WHERE a = COALESCE('8', a) LIMIT 3 +} {8} + +do_execsql_test 3.2 { + SELECT * FROM y1 WHERE a = '2' LIMIT 3 +} {2} + +load_static_extension db series +do_execsql_test 3.3 { + SELECT * FROM generate_series(1, 5) WHERE value = (value & 14) LIMIT 3 +} {2 4} + finish_test From 84a231eb619f462ea183969eb29be23f5f4ecdda Mon Sep 17 00:00:00 2001 From: drh <> Date: Fri, 26 Apr 2024 14:36:28 +0000 Subject: [PATCH 353/430] Use hex flag masks rather than decimals in ext/misc/series.c. FossilOrigin-Name: a94e2cd02873c283d46bf6c21d0306ad454881d7882bb167d043cc79f79a2396 --- ext/misc/series.c | 2 +- manifest | 14 +++++++------- manifest.uuid | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/ext/misc/series.c b/ext/misc/series.c index 22968854ca..e355e5aab7 100644 --- a/ext/misc/series.c +++ b/ext/misc/series.c @@ -411,7 +411,7 @@ static int seriesFilter( if( pCur->ss.iStep==0 ){ pCur->ss.iStep = 1; }else if( pCur->ss.iStep<0 ){ - if( (idxNum & 16)==0 ) idxNum |= 8; + if( (idxNum & 0x10)==0 ) idxNum |= 0x08; } }else{ pCur->ss.iStep = 1; diff --git a/manifest b/manifest index a2f90a673f..6ebcff0402 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sproblem\sallowing\sa\sLIMIT\sconstraint\sto\sbe\spassed\sto\sa\svirtual\stable\sin\scases\swhere\sthere\sexist\sWHERE\sterms\sthat\scannot\salso\sbe\spassed. -D 2024-04-26T14:32:58.805 +C Use\shex\sflag\smasks\srather\sthan\sdecimals\sin\sext/misc/series.c. +D 2024-04-26T14:36:28.914 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -411,7 +411,7 @@ F ext/misc/regexp.c 4bdd0045912f81c84908bd535ec5ad3b1c8540b4287c70ab840709636240 F ext/misc/remember.c add730f0f7e7436cd15ea3fd6a90fd83c3f706ab44169f7f048438b7d6baa69c F ext/misc/rot13.c 51ac5f51e9d5fd811db58a9c23c628ad5f333c173f1fc53c8491a3603d38556c F ext/misc/scrub.c 2a44b0d44c69584c0580ad2553f6290a307a49df4668941d2812135bfb96a946 -F ext/misc/series.c 69df6c989a37c58d831dcd4c6742ea7c98bc1517d45905290445f3bb277d2cbf +F ext/misc/series.c ba7c22c607e24c42bd8e6f289e246abb997e6a11b76b1a385d6f4272eae1ac88 F ext/misc/sha1.c 4011aef176616872b2a0d5bccf0ecfb1f7ce3fe5c3d107f3a8e949d8e1e3f08d F ext/misc/shathree.c 543af7ce71d391cd3a9ab6924a6a1124efc63211fd0f2e240dc4b56077ba88ac F ext/misc/showauth.c 732578f0fe4ce42d577e1c86dc89dd14a006ab52 @@ -2186,8 +2186,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 40421c1c4ed5bb1ed79ad7ee37cb5a4f0b7864c1eb94abd8ee357ab2202cad30 -R 2db4adc3908600896b903e9d700f2b90 -U dan -Z 2050298cecb5ad6b15cc33d4bff9b8cd +P 72c8ed9698dd2aadee7b84fd293e8306233f0fe5b5b5731687482444fdf461c7 +R e853dfcde05ddfe7b4221b55af72f1df +U drh +Z 2da9867ae5f646560b353212baa0f0fb # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index ba5576360c..bc24868c16 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -72c8ed9698dd2aadee7b84fd293e8306233f0fe5b5b5731687482444fdf461c7 \ No newline at end of file +a94e2cd02873c283d46bf6c21d0306ad454881d7882bb167d043cc79f79a2396 \ No newline at end of file From d3a4dbe4b84732a57393a1966bae5ab56460478e Mon Sep 17 00:00:00 2001 From: drh <> Date: Fri, 26 Apr 2024 17:09:33 +0000 Subject: [PATCH 354/430] Further fixes and improvements to the generate_series() enhancements on this branch. FossilOrigin-Name: b7d9bd7ee2f4100608063fdf7648f290351465d393bc876a89704f643358853e --- ext/misc/series.c | 26 ++++++++++++++++++++------ manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/ext/misc/series.c b/ext/misc/series.c index e355e5aab7..0dfed181f6 100644 --- a/ext/misc/series.c +++ b/ext/misc/series.c @@ -478,7 +478,9 @@ static int seriesBestIndex( ){ int i, j; /* Loop over constraints */ int idxNum = 0; /* The query plan bitmask */ +#ifndef ZERO_ARGUMENT_GENERATE_SERIES int bStartSeen = 0; /* EQ constraint seen on the START column */ +#endif int unusableMask = 0; /* Mask of unusable constraints */ int nArg = 0; /* Number of arguments that seriesFilter() expects */ int aIdx[5]; /* Constraints on start, stop, step, LIMIT, OFFSET */ @@ -495,11 +497,16 @@ static int seriesBestIndex( int iCol; /* 0 for start, 1 for stop, 2 for step */ int iMask; /* bitmask for those column */ int op = pConstraint->op; - if( op!=SQLITE_INDEX_CONSTRAINT_EQ ){ - if( op==SQLITE_INDEX_CONSTRAINT_LIMIT ){ + if( op>=SQLITE_INDEX_CONSTRAINT_LIMIT + && op<=SQLITE_INDEX_CONSTRAINT_OFFSET + ){ + if( pConstraint->usable==0 ){ + /* do nothing */ + }else if( op==SQLITE_INDEX_CONSTRAINT_LIMIT ){ aIdx[3] = i; idxNum |= 0x20; - }else if( op==SQLITE_INDEX_CONSTRAINT_OFFSET ){ + }else{ + assert( op==SQLITE_INDEX_CONSTRAINT_OFFSET ); aIdx[4] = i; idxNum |= 0x40; } @@ -509,11 +516,15 @@ static int seriesBestIndex( iCol = pConstraint->iColumn - SERIES_COLUMN_START; assert( iCol>=0 && iCol<=2 ); iMask = 1 << iCol; - if( iCol==0 ) bStartSeen = 1; +#ifndef ZERO_ARGUMENT_GENERATE_SERIES + if( iCol==0 && op==SQLITE_INDEX_CONSTRAINT_EQ ){ + bStartSeen = 1; + } +#endif if( pConstraint->usable==0 ){ unusableMask |= iMask; continue; - }else if( pConstraint->op==SQLITE_INDEX_CONSTRAINT_EQ ){ + }else if( op==SQLITE_INDEX_CONSTRAINT_EQ ){ idxNum |= iMask; aIdx[iCol] = i; } @@ -548,7 +559,7 @@ static int seriesBestIndex( ** this plan is unusable */ return SQLITE_CONSTRAINT; } - if( (idxNum & 3)==3 ){ + if( (idxNum & 0x03)==0x03 ){ /* Both start= and stop= boundaries are available. This is the ** the preferred case */ pIdxInfo->estimatedCost = (double)(2 - ((idxNum&4)!=0)); @@ -561,6 +572,9 @@ static int seriesBestIndex( } pIdxInfo->orderByConsumed = 1; } + }else if( (idxNum & 0x21)==0x21 ){ + /* We have start= and LIMIT */ + pIdxInfo->estimatedRows = 2500; }else{ /* If either boundary is missing, we have to generate a huge span ** of numbers. Make this case very expensive so that the query diff --git a/manifest b/manifest index 6ebcff0402..8aa5658ec1 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Use\shex\sflag\smasks\srather\sthan\sdecimals\sin\sext/misc/series.c. -D 2024-04-26T14:36:28.914 +C Further\sfixes\sand\simprovements\sto\sthe\sgenerate_series()\senhancements\son\nthis\sbranch. +D 2024-04-26T17:09:33.571 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -411,7 +411,7 @@ F ext/misc/regexp.c 4bdd0045912f81c84908bd535ec5ad3b1c8540b4287c70ab840709636240 F ext/misc/remember.c add730f0f7e7436cd15ea3fd6a90fd83c3f706ab44169f7f048438b7d6baa69c F ext/misc/rot13.c 51ac5f51e9d5fd811db58a9c23c628ad5f333c173f1fc53c8491a3603d38556c F ext/misc/scrub.c 2a44b0d44c69584c0580ad2553f6290a307a49df4668941d2812135bfb96a946 -F ext/misc/series.c ba7c22c607e24c42bd8e6f289e246abb997e6a11b76b1a385d6f4272eae1ac88 +F ext/misc/series.c d96e5aac21658c6b5d54f918ac140460ec7197734c1a4fba806950831a7b1e7a F ext/misc/sha1.c 4011aef176616872b2a0d5bccf0ecfb1f7ce3fe5c3d107f3a8e949d8e1e3f08d F ext/misc/shathree.c 543af7ce71d391cd3a9ab6924a6a1124efc63211fd0f2e240dc4b56077ba88ac F ext/misc/showauth.c 732578f0fe4ce42d577e1c86dc89dd14a006ab52 @@ -2186,8 +2186,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 72c8ed9698dd2aadee7b84fd293e8306233f0fe5b5b5731687482444fdf461c7 -R e853dfcde05ddfe7b4221b55af72f1df +P a94e2cd02873c283d46bf6c21d0306ad454881d7882bb167d043cc79f79a2396 +R 321007e70e23799770941a10ae3004c2 U drh -Z 2da9867ae5f646560b353212baa0f0fb +Z 725229cc9017e5eea01f2ec07aa5dfdd # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index bc24868c16..269ea1f24e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a94e2cd02873c283d46bf6c21d0306ad454881d7882bb167d043cc79f79a2396 \ No newline at end of file +b7d9bd7ee2f4100608063fdf7648f290351465d393bc876a89704f643358853e \ No newline at end of file From 297472a2fcae79eb2e531d8c93fdb7f36725afdb Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 26 Apr 2024 17:19:59 +0000 Subject: [PATCH 355/430] Have where.c ignore any plan from a virtual table that tries to use LIMIT/OFFSET without also using all WHERE constraints. FossilOrigin-Name: 7d30596496c6a7a37b925f13d8d94d5de224ec31bb86594fa4cc07b10082e776 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/where.c | 30 ++++++++++++++++++++++++++---- test/bestindexC.test | 8 ++++++-- 4 files changed, 41 insertions(+), 15 deletions(-) diff --git a/manifest b/manifest index 8aa5658ec1..f0eb8e05e2 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Further\sfixes\sand\simprovements\sto\sthe\sgenerate_series()\senhancements\son\nthis\sbranch. -D 2024-04-26T17:09:33.571 +C Have\swhere.c\signore\sany\splan\sfrom\sa\svirtual\stable\sthat\stries\sto\suse\sLIMIT/OFFSET\swithout\salso\susing\sall\sWHERE\sconstraints. +D 2024-04-26T17:19:59.258 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -836,7 +836,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c 887fc4ca3f020ebb2e376f222069570834ac63bf50111ef0cbf3ae417048ed89 F src/wal.h ba252daaa94f889f4b2c17c027e823d9be47ce39da1d3799886bbd51f0490452 F src/walker.c 7c7ea0115345851c3da4e04e2e239a29983b61fb5b038b94eede6aba462640e2 -F src/where.c 447d8761632fb0a18b03077161415d9713cbd0a81bf34a35cee63480e5c401c5 +F src/where.c 0ef9638651b900d64d7e1e877af37cd7900159ff875547ec29b918a1497e5c9c F src/whereInt.h 82a13766f13d1a53b05387c2e60726289ef26404bc7b9b1f7770204d97357fb8 F src/wherecode.c 1f6940349e92a6e056aecd70163b00f331554c815c362b4cc80906c48151d73d F src/whereexpr.c e8e26dbdefa3d89c726251c8b9690ad9766ad00b92cfd11c54402e7dd1350ce7 @@ -936,7 +936,7 @@ F test/bestindex8.test 333ad8c6a554b885a49b68c019166eda92b05f493a92b36b0acdf7f76 F test/bestindex9.test 1a4b93db117fd8abe74ae9be982f86aa72f01e60cd4ac541e6ede39673a451a0 F test/bestindexA.test e1b5def6b190797cacf008e6815ffb78fb30261999030d60a728d572eef44c7f F test/bestindexB.test 328b97b69cd1a20928d5997f9ecb04d2e00f1d18e19ab27f9e9adb44d7bc51ce -F test/bestindexC.test c4957155d9bd21a3e5bdd7cf32e9753b721fff7a373fdc7a8769a2a072877b7f +F test/bestindexC.test 6a632d3b58ffce7b9d4492c93901384d5ede891b0db76c30f90805eaccacc3bc F test/between.test b9a65fb065391980119e8a781a7409d3fcf059d89968279c750e190a9a1d5263 F test/bigfile.test aa74f4e5db51c8e54a1d9de9fa65d01d1eb20b59 F test/bigfile2.test 1b489a3a39ae90c7f027b79110d6b4e1dbc71bfc @@ -2186,8 +2186,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P a94e2cd02873c283d46bf6c21d0306ad454881d7882bb167d043cc79f79a2396 -R 321007e70e23799770941a10ae3004c2 -U drh -Z 725229cc9017e5eea01f2ec07aa5dfdd +P b7d9bd7ee2f4100608063fdf7648f290351465d393bc876a89704f643358853e +R 730af36fce33d6528809ae8d9bef3e6c +U dan +Z 5c5972d6c199bce591c9d5b5a3c5a03a # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 269ea1f24e..a43f8e3abf 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b7d9bd7ee2f4100608063fdf7648f290351465d393bc876a89704f643358853e \ No newline at end of file +7d30596496c6a7a37b925f13d8d94d5de224ec31bb86594fa4cc07b10082e776 \ No newline at end of file diff --git a/src/where.c b/src/where.c index 39210ddb28..820e922490 100644 --- a/src/where.c +++ b/src/where.c @@ -4057,6 +4057,21 @@ static int isLimitTerm(WhereTerm *pTerm){ && pTerm->eMatchOp<=SQLITE_INDEX_CONSTRAINT_OFFSET; } +/* +** Return true if the first nCons constraints in the pUsage array are +** marked as in-use (have argvIndex>0). False otherwise. +*/ +static int allConstraintsUsed( + struct sqlite3_index_constraint_usage *aUsage, + int nCons +){ + int ii; + for(ii=0; iipNew->iTab. This @@ -4197,13 +4212,20 @@ static int whereLoopAddVirtualOne( *pbIn = 1; assert( (mExclude & WO_IN)==0 ); } + /* Unless pbRetryLimit is non-NULL, there should be no LIMIT/OFFSET + ** terms. And if there are any, they should follow all other terms. */ assert( pbRetryLimit || !isLimitTerm(pTerm) ); - if( isLimitTerm(pTerm) && *pbIn ){ + assert( !isLimitTerm(pTerm) || i>=nConstraint-2 ); + assert( !isLimitTerm(pTerm) || i==nConstraint-1 || isLimitTerm(pTerm+1) ); + + if( isLimitTerm(pTerm) && (*pbIn || !allConstraintsUsed(pUsage, i)) ){ /* If there is an IN(...) term handled as an == (separate call to ** xFilter for each value on the RHS of the IN) and a LIMIT or - ** OFFSET term handled as well, the plan is unusable. Set output - ** variable *pbRetryLimit to true to tell the caller to retry with - ** LIMIT and OFFSET disabled. */ + ** OFFSET term handled as well, the plan is unusable. Similarly, + ** if there is a LIMIT/OFFSET and there are other unused terms, + ** the plan cannot be used. In these cases set variable *pbRetryLimit + ** to true to tell the caller to retry with LIMIT and OFFSET + ** disabled. */ if( pIdxInfo->needToFreeIdxStr ){ sqlite3_free(pIdxInfo->idxStr); pIdxInfo->idxStr = 0; diff --git a/test/bestindexC.test b/test/bestindexC.test index 769f1601db..d854216008 100644 --- a/test/bestindexC.test +++ b/test/bestindexC.test @@ -1,4 +1,4 @@ -# 2023-10-26 +# 2024-04-26 # # The author disclaims copyright to this source code. In place of # a legal notice, here is a blessing: @@ -13,7 +13,7 @@ set testdir [file dirname $argv0] source $testdir/tester.tcl -set testprefix bestindexB +set testprefix bestindexC ifcapable !vtab { finish_test @@ -154,4 +154,8 @@ do_execsql_test 3.3 { SELECT * FROM generate_series(1, 5) WHERE value = (value & 14) LIMIT 3 } {2 4} +do_execsql_test 3.4 { + SELECT value FROM generate_series(1,10) WHERE value>2 LIMIT 4 OFFSET 1; +} {4 5 6 7} + finish_test From 4c3ab545a91d50fd13e711dc250cce6927407ca2 Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 26 Apr 2024 18:13:11 +0000 Subject: [PATCH 356/430] Allow virtual table implementations to handle OFFSET but not LIMIT, but not LIMIT but not OFFSET. FossilOrigin-Name: 90e5c8226a695e838e8c1703a9b8598e654d216799e8806c4d1a1f20c28c6486 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/whereexpr.c | 8 ++++---- test/bestindex8.test | 2 +- test/bestindexC.test | 23 ++++++++++++++++++++--- 5 files changed, 34 insertions(+), 17 deletions(-) diff --git a/manifest b/manifest index f0eb8e05e2..e044be16da 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Have\swhere.c\signore\sany\splan\sfrom\sa\svirtual\stable\sthat\stries\sto\suse\sLIMIT/OFFSET\swithout\salso\susing\sall\sWHERE\sconstraints. -D 2024-04-26T17:19:59.258 +C Allow\svirtual\stable\simplementations\sto\shandle\sOFFSET\sbut\snot\sLIMIT,\sbut\snot\sLIMIT\sbut\snot\sOFFSET. +D 2024-04-26T18:13:11.880 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -839,7 +839,7 @@ F src/walker.c 7c7ea0115345851c3da4e04e2e239a29983b61fb5b038b94eede6aba462640e2 F src/where.c 0ef9638651b900d64d7e1e877af37cd7900159ff875547ec29b918a1497e5c9c F src/whereInt.h 82a13766f13d1a53b05387c2e60726289ef26404bc7b9b1f7770204d97357fb8 F src/wherecode.c 1f6940349e92a6e056aecd70163b00f331554c815c362b4cc80906c48151d73d -F src/whereexpr.c e8e26dbdefa3d89c726251c8b9690ad9766ad00b92cfd11c54402e7dd1350ce7 +F src/whereexpr.c 67d15caf88a1a9528283d68ff578e024cf9fe810b517bb0343e5aaf695ad97dd F src/window.c 5d95122dd330bfaebd732358c8ef067c5a9394a53ac249470d611d0ce2c52be2 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/affinity2.test ce1aafc86e110685b324e9a763eab4f2a73f737842ec3b687bd965867de90627 @@ -932,11 +932,11 @@ F test/bestindex4.test 3039894f2dad50f3a68443dffad1b44c9b067ac03870102df1ce3d9a4 F test/bestindex5.test a0c90b2dad7836e80a01379e200e5f8ec9476d49b349af02c0dbff2fb75dc98d F test/bestindex6.test 16942535b551273f3ad9df8d7cc4b7f22b1fcd8882714358859eb049a6f99dd4 F test/bestindex7.test f094c669a6400777f4d2ddc3ed28e39169f1adb5be3d59b55f22ccf8c414b71e -F test/bestindex8.test 333ad8c6a554b885a49b68c019166eda92b05f493a92b36b0acdf7f766d04dad +F test/bestindex8.test b63a4f171a2c83d481bb14c431a8b72e85d27b2ffdaa0435a95d58ca941678f9 F test/bestindex9.test 1a4b93db117fd8abe74ae9be982f86aa72f01e60cd4ac541e6ede39673a451a0 F test/bestindexA.test e1b5def6b190797cacf008e6815ffb78fb30261999030d60a728d572eef44c7f F test/bestindexB.test 328b97b69cd1a20928d5997f9ecb04d2e00f1d18e19ab27f9e9adb44d7bc51ce -F test/bestindexC.test 6a632d3b58ffce7b9d4492c93901384d5ede891b0db76c30f90805eaccacc3bc +F test/bestindexC.test c14a8c8639b6825b0efa1ae693f34ec04f41a46e3056e7063d6e0f46bf4ff692 F test/between.test b9a65fb065391980119e8a781a7409d3fcf059d89968279c750e190a9a1d5263 F test/bigfile.test aa74f4e5db51c8e54a1d9de9fa65d01d1eb20b59 F test/bigfile2.test 1b489a3a39ae90c7f027b79110d6b4e1dbc71bfc @@ -2186,8 +2186,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P b7d9bd7ee2f4100608063fdf7648f290351465d393bc876a89704f643358853e -R 730af36fce33d6528809ae8d9bef3e6c +P 7d30596496c6a7a37b925f13d8d94d5de224ec31bb86594fa4cc07b10082e776 +R 9eed5aaa8e26bff88d62db6ed7adfa29 U dan -Z 5c5972d6c199bce591c9d5b5a3c5a03a +Z d168d9476b0b5c157ebfbc91beb1e6fe # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index a43f8e3abf..3d3eb37fa7 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7d30596496c6a7a37b925f13d8d94d5de224ec31bb86594fa4cc07b10082e776 \ No newline at end of file +90e5c8226a695e838e8c1703a9b8598e654d216799e8806c4d1a1f20c28c6486 \ No newline at end of file diff --git a/src/whereexpr.c b/src/whereexpr.c index d25bce5f08..5465dc953b 100644 --- a/src/whereexpr.c +++ b/src/whereexpr.c @@ -1653,14 +1653,14 @@ void SQLITE_NOINLINE sqlite3WhereAddLimit(WhereClause *pWC, Select *p){ /* All conditions are met. Add the terms to the where-clause object. */ assert( p->pLimit->op==TK_LIMIT ); - if( p->iOffset==0 || (p->selFlags & SF_Compound)==0 ){ - whereAddLimitExpr(pWC, p->iLimit, p->pLimit->pLeft, - iCsr, SQLITE_INDEX_CONSTRAINT_LIMIT); - } if( p->iOffset!=0 && (p->selFlags & SF_Compound)==0 ){ whereAddLimitExpr(pWC, p->iOffset, p->pLimit->pRight, iCsr, SQLITE_INDEX_CONSTRAINT_OFFSET); } + if( p->iOffset==0 || (p->selFlags & SF_Compound)==0 ){ + whereAddLimitExpr(pWC, p->iLimit, p->pLimit->pLeft, + iCsr, SQLITE_INDEX_CONSTRAINT_LIMIT); + } } } diff --git a/test/bestindex8.test b/test/bestindex8.test index e95c3c6dc2..3ed7f6703e 100644 --- a/test/bestindex8.test +++ b/test/bestindex8.test @@ -158,7 +158,7 @@ do_test 2.2 { set ::lFilterArgs [list] execsql { SELECT * FROM vt1 LIMIT 5 OFFSET 50 } set ::lFilterArgs -} {{5 50}} +} {{50 5}} do_test 2.3 { set ::lFilterArgs [list] diff --git a/test/bestindexC.test b/test/bestindexC.test index d854216008..476ea39faa 100644 --- a/test/bestindexC.test +++ b/test/bestindexC.test @@ -40,11 +40,11 @@ proc vtab_command {lVal method args} { foreach c $clist { array set a $c if {$a(usable)==0} continue - if {$a(op)=="limit"} { + if {$a(op)=="limit" && ![info exists ::do_not_use_limit]} { lappend idxstr limit lappend res omit $idx } - if {$a(op)=="offset"} { + if {$a(op)=="offset" && ![info exists ::do_not_use_offset]} { lappend idxstr offset lappend res omit $idx } @@ -58,9 +58,13 @@ proc vtab_command {lVal method args} { set idxstr [lindex $args 1] set LIMIT "" foreach a $idxstr b [lindex $args 2] { - append LIMIT " $a $b" + set x($a) $b } + if {![info exists x(limit)]} { set x(limit) -1 } + if {![info exists x(offset)]} { set x(offset) -1 } + set LIMIT " LIMIT $x(limit) OFFSET $x(offset)" + set idx 1 foreach v $lVal { lappend lRow "($idx, '$v')" @@ -158,4 +162,17 @@ do_execsql_test 3.4 { SELECT value FROM generate_series(1,10) WHERE value>2 LIMIT 4 OFFSET 1; } {4 5 6 7} +set ::do_not_use_limit 1 +do_execsql_test 3.5 { + SELECT * FROM y1 LIMIT 5 OFFSET 3 +} {4 5 6 7 8} +unset ::do_not_use_limit +set ::do_not_use_offset 1 +do_execsql_test 3.6 { + SELECT * FROM y1 LIMIT 5 OFFSET 3 +} {4 5 6 7 8} +unset ::do_not_use_offset + + + finish_test From 6c290ccd49248e6e53937172bea6598ed77eee69 Mon Sep 17 00:00:00 2001 From: stephan Date: Fri, 26 Apr 2024 18:24:23 +0000 Subject: [PATCH 357/430] Additional internal docs in the wasm utilities. FossilOrigin-Name: 5a2245a9ebae6d23cd343e46b9d730f66ec4d5ffc91b83ed11a0fbd2194ad807 --- ext/wasm/common/whwasmutil.js | 28 +++++++++++++++++++++++++--- manifest | 14 +++++++------- manifest.uuid | 2 +- 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/ext/wasm/common/whwasmutil.js b/ext/wasm/common/whwasmutil.js index 0437ef35d8..65421e3fac 100644 --- a/ext/wasm/common/whwasmutil.js +++ b/ext/wasm/common/whwasmutil.js @@ -1382,15 +1382,19 @@ globalThis.WhWasmUtilInstaller = function(target){ conversion of argument or return types, but see xWrap() and xCallWrapped() for variants which do. + If the first argument is a function is is assumed to be + a WASM-bound function and is used as-is instead of looking up + the function via xGet(). + As a special case, if passed only 1 argument after the name and that argument in an Array, that array's entries become the function arguments. (This is not an ambiguous case because it's not legal to pass an Array object to a WASM function.) */ target.xCall = function(fname, ...args){ - const f = target.xGet(fname); + const f = (fname instanceof Function) ? fname : target.xGet(fname); if(!(f instanceof Function)) toss("Exported symbol",fname,"is not a function."); - if(f.length!==args.length) __argcMismatch(fname,f.length) + if(f.length!==args.length) __argcMismatch(((f===fname) ? f.name : fname),f.length) /* This is arguably over-pedantic but we want to help clients keep from shooting themselves in the foot when calling C APIs. */; return (2===arguments.length && Array.isArray(arguments[1])) @@ -1537,7 +1541,7 @@ globalThis.WhWasmUtilInstaller = function(target){ jsFuncToWasm(). - bindScope (string): one of ('transient', 'context', - 'singleton'). Bind scopes are: + 'singleton', 'permanent'). Bind scopes are: - 'transient': it will convert JS functions to WASM only for the duration of the xWrap()'d function call, using @@ -1787,11 +1791,29 @@ globalThis.WhWasmUtilInstaller = function(target){ const __xResultAdapterCheck = (t)=>xResult.get(t) || toss("Result adapter not found:",t); + /** + Fetches the xWrap() argument adapter mapped to t, calls it, + passing in all remaining arguments, and returns the result. + Throws if t is not mapped to an argument converter. + */ cache.xWrap.convertArg = (t,...args)=>__xArgAdapterCheck(t)(...args); + /** + Identical to convertArg() except that it does not perform + an is-defined check on the mapping to t before invoking it. + */ cache.xWrap.convertArgNoCheck = (t,...args)=>xArg.get(t)(...args); + /** + Fetches the xWrap() result adapter mapped to t, calls it, passing + it v, and returns the result. Throws if t is not mapped to an + argument converter. + */ cache.xWrap.convertResult = (t,v)=>(null===t ? v : (t ? __xResultAdapterCheck(t)(v) : undefined)); + /** + Identical to convertResult() except that it does not perform an + is-defined check on the mapping to t before invoking it. + */ cache.xWrap.convertResultNoCheck = (t,v)=>(null===t ? v : (t ? xResult.get(t)(v) : undefined)); diff --git a/manifest b/manifest index 234d44e742..321eb88a47 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\sTreeView\sdisplay\sof\sa\sLIMIT\sclause\son\sa\scompound\squery.\s\sDebugging\ncode\sonly\s-\snot\spart\sof\sproduction\sbuilds. -D 2024-04-26T11:32:50.631 +C Additional\sinternal\sdocs\sin\sthe\swasm\sutilities. +D 2024-04-26T18:24:23.472 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -627,7 +627,7 @@ F ext/wasm/c-pp.c 6d80d8569d85713effe8b0818a3cf51dc779e3f0bf8dc88771b8998552ee25 F ext/wasm/common/SqliteTestUtil.js 7adaeffef757d8708418dc9190f72df22367b531831775804b31598b44f6aa51 F ext/wasm/common/emscripten.css 11bd104b6c0d597c67d40cc8ecc0a60dae2b965151e3b6a37fa5708bac3acd15 F ext/wasm/common/testing.css e97549bab24126c24e0daabfe2de9bb478fb0a69fdb2ddd0a73a992c091aad6f -F ext/wasm/common/whwasmutil.js 4c64594eecc7af4ae64259e95a71ba2a7edf118881aaff0bba86d0c7164e78e4 +F ext/wasm/common/whwasmutil.js fc923692f51b9a47cb6c3d0ab350db542cf6774c39d9e4ed9e894b55180d6989 F ext/wasm/demo-123-worker.html a0b58d9caef098a626a1a1db567076fca4245e8d60ba94557ede8684350a81ed F ext/wasm/demo-123.html 8c70a412ce386bd3796534257935eb1e3ea5c581e5d5aea0490b8232e570a508 F ext/wasm/demo-123.js c7b3cca50c55841c381a9ca4f9396e5bbdc6114273d0b10a43e378e32e7be5bf @@ -2185,8 +2185,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P e6df846f36209bac3e420dd80ce2bbbd87ab7a20b8063fce05f78a3c7ab6027e -R cad28780e6b446bd6e2b3d9b26a145c6 -U drh -Z 00ad49f6765aaa2802fdc1e87b94bb22 +P 38f1e5ce4eedd59fbeb0a0d676d26dfe8a3313189ab9b9e4a5a1ed6721b73a14 +R 42961bb992b575c9ac9834f429717116 +U stephan +Z e5e500cd82301a12835836646a3b6e08 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 17975a5072..8452508501 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -38f1e5ce4eedd59fbeb0a0d676d26dfe8a3313189ab9b9e4a5a1ed6721b73a14 \ No newline at end of file +5a2245a9ebae6d23cd343e46b9d730f66ec4d5ffc91b83ed11a0fbd2194ad807 \ No newline at end of file From b95c1d0ac9d020a9abd51c221194e188f25b69a9 Mon Sep 17 00:00:00 2001 From: stephan Date: Fri, 26 Apr 2024 18:42:50 +0000 Subject: [PATCH 358/430] Internal JS doc touchups. No functional changes. FossilOrigin-Name: 626b997b4e727554d7ec8b60fb37b2a94cb861a87325da4ae484bd9aa8961ca5 --- ext/wasm/common/whwasmutil.js | 18 +++++++++--------- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/ext/wasm/common/whwasmutil.js b/ext/wasm/common/whwasmutil.js index 65421e3fac..bbcf3d4930 100644 --- a/ext/wasm/common/whwasmutil.js +++ b/ext/wasm/common/whwasmutil.js @@ -1925,15 +1925,15 @@ globalThis.WhWasmUtilInstaller = function(target){ const C-string, encoded as UTF-8, copies it to a JS string, and returns that JS string. - - `string:dealloc` or `utf8:dealloc) (results): treats the result value - as a non-const UTF-8 C-string, ownership of which has just been - transfered to the caller. It copies the C-string to a JS - string, frees the C-string, and returns the JS string. If such - a result value is NULL, the JS result is `null`. Achtung: when - using an API which returns results from a specific allocator, - e.g. `my_malloc()`, this conversion _is not legal_. Instead, an - equivalent conversion which uses the appropriate deallocator is - required. For example: + - `string:dealloc` or `utf8:dealloc` (results): treats the result + value as a non-const UTF-8 C-string, ownership of which has + just been transfered to the caller. It copies the C-string to a + JS string, frees the C-string, and returns the JS string. If + such a result value is NULL, the JS result is `null`. Achtung: + when using an API which returns results from a specific + allocator, e.g. `my_malloc()`, this conversion _is not + legal_. Instead, an equivalent conversion which uses the + appropriate deallocator is required. For example: ```js target.xWrap.resultAdapter('string:my_free',(i)=>{ diff --git a/manifest b/manifest index 321eb88a47..bf1d462898 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Additional\sinternal\sdocs\sin\sthe\swasm\sutilities. -D 2024-04-26T18:24:23.472 +C Internal\sJS\sdoc\stouchups.\sNo\sfunctional\schanges. +D 2024-04-26T18:42:50.715 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -627,7 +627,7 @@ F ext/wasm/c-pp.c 6d80d8569d85713effe8b0818a3cf51dc779e3f0bf8dc88771b8998552ee25 F ext/wasm/common/SqliteTestUtil.js 7adaeffef757d8708418dc9190f72df22367b531831775804b31598b44f6aa51 F ext/wasm/common/emscripten.css 11bd104b6c0d597c67d40cc8ecc0a60dae2b965151e3b6a37fa5708bac3acd15 F ext/wasm/common/testing.css e97549bab24126c24e0daabfe2de9bb478fb0a69fdb2ddd0a73a992c091aad6f -F ext/wasm/common/whwasmutil.js fc923692f51b9a47cb6c3d0ab350db542cf6774c39d9e4ed9e894b55180d6989 +F ext/wasm/common/whwasmutil.js e474e0fac695abf88e5385581e26d53e5706cd268cab9d92a56eab2873c08daa F ext/wasm/demo-123-worker.html a0b58d9caef098a626a1a1db567076fca4245e8d60ba94557ede8684350a81ed F ext/wasm/demo-123.html 8c70a412ce386bd3796534257935eb1e3ea5c581e5d5aea0490b8232e570a508 F ext/wasm/demo-123.js c7b3cca50c55841c381a9ca4f9396e5bbdc6114273d0b10a43e378e32e7be5bf @@ -2185,8 +2185,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 38f1e5ce4eedd59fbeb0a0d676d26dfe8a3313189ab9b9e4a5a1ed6721b73a14 -R 42961bb992b575c9ac9834f429717116 +P 5a2245a9ebae6d23cd343e46b9d730f66ec4d5ffc91b83ed11a0fbd2194ad807 +R 2adc6cf9c9a2aba61ab0a2581495ddf7 U stephan -Z e5e500cd82301a12835836646a3b6e08 +Z fc84f35cfa574620d41dff4fcae199b4 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 8452508501..9a6a4621eb 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5a2245a9ebae6d23cd343e46b9d730f66ec4d5ffc91b83ed11a0fbd2194ad807 \ No newline at end of file +626b997b4e727554d7ec8b60fb37b2a94cb861a87325da4ae484bd9aa8961ca5 \ No newline at end of file From 8d5fe073d25b8bfd632d10d4875461316806481d Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 30 Apr 2024 19:34:15 +0000 Subject: [PATCH 359/430] Avoid 32-bit overflow when calculating ncycle for ".scanstats vm". FossilOrigin-Name: 2858efa06d4fc7b412b892f35f5e9a766b467b4a5b74d602a030d25443f9efb4 --- manifest | 15 +++++++-------- manifest.uuid | 2 +- src/vdbevtab.c | 4 ++-- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 137c5c9d3a..903dfbc746 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sissues\sin\s[/info/1e227ad9f413227f|LIMIT/OFFSET\ssupport\sfor\svirtual\stables].\nThe\sfirst\sproblem\swas\sreported\sby\n[forum:/forumpost/c243b8f856|forum\spost\sc243b8f856].\s\sThat\sreport\sprompted\nan\senhancement\sto\sthe\sgenerate_series()\s(also\sincluded\sin\sthis\smerge)\swhich\nin\sturn\sidentified\sother\ssimilar\sissues. -D 2024-04-26T19:10:15.851 +C Avoid\s32-bit\soverflow\swhen\scalculating\sncycle\sfor\s".scanstats\svm". +D 2024-04-30T19:34:15.474 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -830,7 +830,7 @@ F src/vdbeblob.c 13f9287b55b6356b4b1845410382d6bede203ceb29ef69388a4a3d007ffacbe F src/vdbemem.c 385c8b89da3b5ef9a468d77a466958aa72ee1212d5cb005f23ec63df1d413054 F src/vdbesort.c 237840ca1947511fa59bd4e18b9eeae93f2af2468c34d2427b059f896230a547 F src/vdbetrace.c fe0bc29ebd4e02c8bc5c1945f1d2e6be5927ec12c06d89b03ef2a4def34bf823 -F src/vdbevtab.c 2143db7db0ceed69b21422581f434baffc507a08d831565193a7a02882a1b6a7 +F src/vdbevtab.c fc46b9cbd759dc013f0b3724549cc0d71379183c667df3a5988f7e2f1bd485f3 F src/vtab.c 4c475fb672a6fe57830561e614dbee21a9a24a6f616d1cfcbe85f356a09f14ad F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c 887fc4ca3f020ebb2e376f222069570834ac63bf50111ef0cbf3ae417048ed89 @@ -2186,9 +2186,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 626b997b4e727554d7ec8b60fb37b2a94cb861a87325da4ae484bd9aa8961ca5 90e5c8226a695e838e8c1703a9b8598e654d216799e8806c4d1a1f20c28c6486 -R 2a7971e3914aa76c70593754ba02f5ed -T +closed 90e5c8226a695e838e8c1703a9b8598e654d216799e8806c4d1a1f20c28c6486 -U drh -Z e187ac779304121a02fd3106018bb12d +P 5f6c079d847e3664ec5acaf1b3e989efe0d548c211ae4a18936162b36df89065 +R 903fbc18fbeeda59fd5e86360c55f235 +U dan +Z 0ade4d9c1bbdd68ad336341e8aad91d0 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 58acb63008..07075e1cbb 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5f6c079d847e3664ec5acaf1b3e989efe0d548c211ae4a18936162b36df89065 \ No newline at end of file +2858efa06d4fc7b412b892f35f5e9a766b467b4a5b74d602a030d25443f9efb4 \ No newline at end of file diff --git a/src/vdbevtab.c b/src/vdbevtab.c index b295dff7b6..1c9909a1aa 100644 --- a/src/vdbevtab.c +++ b/src/vdbevtab.c @@ -286,10 +286,10 @@ static int bytecodevtabColumn( #ifdef SQLITE_ENABLE_STMT_SCANSTATUS case 9: /* nexec */ - sqlite3_result_int(ctx, pOp->nExec); + sqlite3_result_int64(ctx, pOp->nExec); break; case 10: /* ncycle */ - sqlite3_result_int(ctx, pOp->nCycle); + sqlite3_result_int64(ctx, pOp->nCycle); break; #else case 9: /* nexec */ From 19ca99eea479f2f1a4290e30ded7efee4c195769 Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 1 May 2024 14:42:20 +0000 Subject: [PATCH 360/430] Fix a problem causing the recovery extension to use excessive memory and CPU time in some cases. FossilOrigin-Name: 8de85170d53e1d2a2abe14508a222377b9493e25f3174b8f0f773427deb8df26 --- ext/recover/dbdata.c | 79 ++++++++++++++++++++++++++++++++------------ manifest | 12 +++---- manifest.uuid | 2 +- 3 files changed, 64 insertions(+), 29 deletions(-) diff --git a/ext/recover/dbdata.c b/ext/recover/dbdata.c index ca6371026e..3f3c3d71d5 100644 --- a/ext/recover/dbdata.c +++ b/ext/recover/dbdata.c @@ -88,6 +88,15 @@ typedef unsigned int u32; typedef struct DbdataTable DbdataTable; typedef struct DbdataCursor DbdataCursor; +typedef struct DbdataBuffer DbdataBuffer; + +/* +** Buffer type. +*/ +struct DbdataBuffer { + u8 *aBuf; + sqlite3_int64 nBuf; +}; /* Cursor object */ struct DbdataCursor { @@ -104,7 +113,7 @@ struct DbdataCursor { sqlite3_int64 iRowid; /* Only for the sqlite_dbdata table */ - u8 *pRec; /* Buffer containing current record */ + DbdataBuffer rec; sqlite3_int64 nRec; /* Size of pRec[] in bytes */ sqlite3_int64 nHdr; /* Size of header in bytes */ int iField; /* Current field number */ @@ -149,6 +158,31 @@ struct DbdataTable { " schema TEXT HIDDEN" \ ")" +/* +** Ensure the buffer passed as the first argument is at least nMin bytes +** in size. If an error occurs while attempting to resize the buffer, +** SQLITE_NOMEM is returned. Otherwise, SQLITE_OK. +*/ +static int dbdataBufferSize(DbdataBuffer *pBuf, sqlite3_int64 nMin){ + if( nMin>pBuf->nBuf ){ + sqlite3_int64 nNew = nMin+16384; + u8 *aNew = (u8*)sqlite3_realloc64(pBuf->aBuf, nNew); + + if( aNew==0 ) return SQLITE_NOMEM; + pBuf->aBuf = aNew; + pBuf->nBuf = nNew; + } + return SQLITE_OK; +} + +/* +** Release the allocation managed by buffer pBuf. +*/ +static void dbdataBufferFree(DbdataBuffer *pBuf){ + sqlite3_free(pBuf->aBuf); + memset(pBuf, 0, sizeof(*pBuf)); +} + /* ** Connect to an sqlite_dbdata (pAux==0) or sqlite_dbptr (pAux!=0) virtual ** table. @@ -289,8 +323,7 @@ static void dbdataResetCursor(DbdataCursor *pCsr){ pCsr->iField = 0; pCsr->bOnePage = 0; sqlite3_free(pCsr->aPage); - sqlite3_free(pCsr->pRec); - pCsr->pRec = 0; + dbdataBufferFree(&pCsr->rec); pCsr->aPage = 0; } @@ -551,7 +584,7 @@ static int dbdataNext(sqlite3_vtab_cursor *pCursor){ } }else{ /* If there is no record loaded, load it now. */ - if( pCsr->pRec==0 ){ + if( pCsr->nRec==0 ){ int bHasRowid = 0; int nPointer = 0; sqlite3_int64 nPayload = 0; @@ -595,6 +628,7 @@ static int dbdataNext(sqlite3_vtab_cursor *pCursor){ }else{ iOff += dbdataGetVarintU32(&pCsr->aPage[iOff], &nPayload); if( nPayload>0x7fffff00 ) nPayload &= 0x3fff; + if( nPayload==0 ) nPayload = 1; } /* If this is a leaf intkey cell, load the rowid */ @@ -629,13 +663,13 @@ static int dbdataNext(sqlite3_vtab_cursor *pCursor){ /* Allocate space for payload. And a bit more to catch small buffer ** overruns caused by attempting to read a varint or similar from ** near the end of a corrupt record. */ - pCsr->pRec = (u8*)sqlite3_malloc64(nPayload+DBDATA_PADDING_BYTES); - if( pCsr->pRec==0 ) return SQLITE_NOMEM; - memset(pCsr->pRec, 0, nPayload+DBDATA_PADDING_BYTES); + rc = dbdataBufferSize(&pCsr->rec, nPayload+DBDATA_PADDING_BYTES); + if( rc!=SQLITE_OK ) return rc; + assert( nPayload!=0 ); pCsr->nRec = nPayload; /* Load the nLocal bytes of payload */ - memcpy(pCsr->pRec, &pCsr->aPage[iOff], nLocal); + memcpy(pCsr->rec.aBuf, &pCsr->aPage[iOff], nLocal); iOff += nLocal; /* Load content from overflow pages */ @@ -653,19 +687,22 @@ static int dbdataNext(sqlite3_vtab_cursor *pCursor){ nCopy = U-4; if( nCopy>nRem ) nCopy = nRem; - memcpy(&pCsr->pRec[nPayload-nRem], &aOvfl[4], nCopy); + memcpy(&pCsr->rec.aBuf[nPayload-nRem], &aOvfl[4], nCopy); nRem -= nCopy; pgnoOvfl = get_uint32(aOvfl); sqlite3_free(aOvfl); } + memset(&pCsr->rec.aBuf[nPayload-nRem], 0, DBDATA_PADDING_BYTES); + }else{ + memset(&pCsr->rec.aBuf[nLocal], 0, DBDATA_PADDING_BYTES); } - iHdr = dbdataGetVarintU32(pCsr->pRec, &nHdr); + iHdr = dbdataGetVarintU32(pCsr->rec.aBuf, &nHdr); if( nHdr>nPayload ) nHdr = 0; pCsr->nHdr = nHdr; - pCsr->pHdrPtr = &pCsr->pRec[iHdr]; - pCsr->pPtr = &pCsr->pRec[pCsr->nHdr]; + pCsr->pHdrPtr = &pCsr->rec.aBuf[iHdr]; + pCsr->pPtr = &pCsr->rec.aBuf[pCsr->nHdr]; pCsr->iField = (bHasRowid ? -1 : 0); } } @@ -673,7 +710,7 @@ static int dbdataNext(sqlite3_vtab_cursor *pCursor){ pCsr->iField++; if( pCsr->iField>0 ){ sqlite3_int64 iType; - if( pCsr->pHdrPtr>=&pCsr->pRec[pCsr->nRec] + if( pCsr->pHdrPtr>=&pCsr->rec.aBuf[pCsr->nRec] || pCsr->iField>=DBDATA_MX_FIELD ){ bNextPage = 1; @@ -681,8 +718,8 @@ static int dbdataNext(sqlite3_vtab_cursor *pCursor){ int szField = 0; pCsr->pHdrPtr += dbdataGetVarintU32(pCsr->pHdrPtr, &iType); szField = dbdataValueBytes(iType); - if( (pCsr->nRec - (pCsr->pPtr - pCsr->pRec))pPtr = &pCsr->pRec[pCsr->nRec]; + if( (pCsr->nRec - (pCsr->pPtr - pCsr->rec.aBuf))pPtr = &pCsr->rec.aBuf[pCsr->nRec]; }else{ pCsr->pPtr += szField; } @@ -692,20 +729,18 @@ static int dbdataNext(sqlite3_vtab_cursor *pCursor){ if( bNextPage ){ sqlite3_free(pCsr->aPage); - sqlite3_free(pCsr->pRec); pCsr->aPage = 0; - pCsr->pRec = 0; + pCsr->nRec = 0; if( pCsr->bOnePage ) return SQLITE_OK; pCsr->iPgno++; }else{ - if( pCsr->iField<0 || pCsr->pHdrPtr<&pCsr->pRec[pCsr->nHdr] ){ + if( pCsr->iField<0 || pCsr->pHdrPtr<&pCsr->rec.aBuf[pCsr->nHdr] ){ return SQLITE_OK; } /* Advance to the next cell. The next iteration of the loop will load ** the record and so on. */ - sqlite3_free(pCsr->pRec); - pCsr->pRec = 0; + pCsr->nRec = 0; pCsr->iCell++; } } @@ -895,12 +930,12 @@ static int dbdataColumn( case DBDATA_COLUMN_VALUE: { if( pCsr->iField<0 ){ sqlite3_result_int64(ctx, pCsr->iIntkey); - }else if( &pCsr->pRec[pCsr->nRec] >= pCsr->pPtr ){ + }else if( &pCsr->rec.aBuf[pCsr->nRec] >= pCsr->pPtr ){ sqlite3_int64 iType; dbdataGetVarintU32(pCsr->pHdrPtr, &iType); dbdataValue( ctx, pCsr->enc, iType, pCsr->pPtr, - &pCsr->pRec[pCsr->nRec] - pCsr->pPtr + &pCsr->rec.aBuf[pCsr->nRec] - pCsr->pPtr ); } break; diff --git a/manifest b/manifest index 903dfbc746..dece840222 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Avoid\s32-bit\soverflow\swhen\scalculating\sncycle\sfor\s".scanstats\svm". -D 2024-04-30T19:34:15.474 +C Fix\sa\sproblem\scausing\sthe\srecovery\sextension\sto\suse\sexcessive\smemory\sand\sCPU\stime\sin\ssome\scases. +D 2024-05-01T14:42:20.390 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -478,7 +478,7 @@ F ext/rbu/rbuvacuum4.test ffccd22f67e2d0b380d2889685742159dfe0d19a3880ca3d2d1d69 F ext/rbu/sqlite3rbu.c 4a3376c0fb9a844a799ac529fb81260523f6b13c9f629bc270c632dbae5fc1f8 F ext/rbu/sqlite3rbu.h 9d923eb135c5d04aa6afd7c39ca47b0d1d0707c100e02f19fdde6a494e414304 F ext/rbu/test_rbu.c ee6ede75147bc081fe9bc3931e6b206277418d14d3fbceea6fdc6216d9b47055 -F ext/recover/dbdata.c d2e00d3cac74319c9c6def2e56ab2146b4f4ba5d820ab275e8da24e9766c247e +F ext/recover/dbdata.c bca5845064cf07b5583f4030d91906b1f147c52a80eff4adf591893d3a7c286c F ext/recover/recover1.test c484d01502239f11b61f23c1cee9f5dd19fa17617f8974e42e74d64639c524cf F ext/recover/recover_common.tcl a61306c1eb45c0c3fc45652c35b2d4ec19729e340bdf65a272ce4c229cefd85a F ext/recover/recoverbuild.test c74170e0f7b02456af41838afeb5353fdb985a48cc2331d661bbabbca7c6b8e3 @@ -2186,8 +2186,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 5f6c079d847e3664ec5acaf1b3e989efe0d548c211ae4a18936162b36df89065 -R 903fbc18fbeeda59fd5e86360c55f235 +P 2858efa06d4fc7b412b892f35f5e9a766b467b4a5b74d602a030d25443f9efb4 +R 3b77a71cd99d532953a23626b8d60d55 U dan -Z 0ade4d9c1bbdd68ad336341e8aad91d0 +Z d212fc82f6805723a5e49c9577f6a006 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 07075e1cbb..041e2c89a9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2858efa06d4fc7b412b892f35f5e9a766b467b4a5b74d602a030d25443f9efb4 \ No newline at end of file +8de85170d53e1d2a2abe14508a222377b9493e25f3174b8f0f773427deb8df26 \ No newline at end of file From 2ad1e92858e36399797263a2b7f7f2951c96e4a2 Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 1 May 2024 16:25:46 +0000 Subject: [PATCH 361/430] Fix another problem in the recovery extension where a corrupt sqlite_schema table could lead to excessive memory consumption. FossilOrigin-Name: 1c7e33a8aa0e6122b5ef606e4a7d95e8ecd9440216d4b099fe8f2a40653422be --- ext/recover/dbdata.c | 5 +- ext/recover/recovercorrupt3.test | 549 +++++++++++++++++++++++++++++++ manifest | 13 +- manifest.uuid | 2 +- 4 files changed, 559 insertions(+), 10 deletions(-) create mode 100644 ext/recover/recovercorrupt3.test diff --git a/ext/recover/dbdata.c b/ext/recover/dbdata.c index 3f3c3d71d5..b01e544885 100644 --- a/ext/recover/dbdata.c +++ b/ext/recover/dbdata.c @@ -693,10 +693,9 @@ static int dbdataNext(sqlite3_vtab_cursor *pCursor){ pgnoOvfl = get_uint32(aOvfl); sqlite3_free(aOvfl); } - memset(&pCsr->rec.aBuf[nPayload-nRem], 0, DBDATA_PADDING_BYTES); - }else{ - memset(&pCsr->rec.aBuf[nLocal], 0, DBDATA_PADDING_BYTES); + nPayload -= nRem; } + memset(&pCsr->rec.aBuf[nPayload], 0, DBDATA_PADDING_BYTES); iHdr = dbdataGetVarintU32(pCsr->rec.aBuf, &nHdr); if( nHdr>nPayload ) nHdr = 0; diff --git a/ext/recover/recovercorrupt3.test b/ext/recover/recovercorrupt3.test new file mode 100644 index 0000000000..9a7c2d0946 --- /dev/null +++ b/ext/recover/recovercorrupt3.test @@ -0,0 +1,549 @@ +# 2024 May 1 +# +# 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]] recover_common.tcl] +set testprefix recovercorrupt3 + +#| 0: d5 d5 9b d5 d5 d5 d5 d5 d5 d5 d5 d5 d5 d5 d5 d5 ................ +#| 16: 04 00 00 00 1d 00 00 00 00 00 00 00 5f 5f 5f 5f ............____ +#| 32: 5f 5f 5f 5f 5f 5f 5f 5f 71 5f 5f 5f 02 02 02 02 ________q___.... +#| 48: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +#| 64: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +#| 80: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +#| 96: 02 02 02 02 + +#------------------------------------------------------------------------- +reset_db +do_test 1.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +| size 3821 pagesize 1024 filename clusterfuzz-testcase-sql_recovery_fuzzer-5803962339885056 +| 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 01 00 00 00 02 .....@ ........ +| 32: 00 00 00 00 00 00 00 00 00 00 00 01 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 01 ................ +| 96: 00 2e 7a 70 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 112: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 128: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 144: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 160: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 176: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 192: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 208: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 224: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 240: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 256: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 272: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 288: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 304: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 320: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 336: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 352: 02 02 02 02 a0 02 02 02 02 02 02 02 02 02 02 02 ................ +| 368: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 384: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 400: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 416: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 432: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 448: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 29 29 ..............)) +| 464: 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 )))))))))))))))) +| 480: 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 )))))))))))))))) +| 496: 29 29 29 dd dd dd dd dd dd dd dd dd dd dd dd dd )))............. +| 512: dd dd dd dd dd dd dd dd dd 6e 69 d2 e9 e9 e9 d2 .........ni..... +| 528: d2 d2 d2 d2 dd dd dd dd dd dd dd dd dd dd dd dd ................ +| 544: dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd ................ +| 560: dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd ................ +| 576: dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd ................ +| 592: dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd ................ +| 608: dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd ................ +| 624: dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd ................ +| 640: dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd ................ +| 656: dd dd dd dd dd dd dd da dd dd dd dd dd dd dd dd ................ +| 672: dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd ................ +| 688: dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd ................ +| 704: dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd ................ +| 720: dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd ................ +| 736: dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd ................ +| 752: dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd ................ +| 768: dd dd dd dd dd dd dd dd dd dd dd dd dd 29 29 29 .............))) +| 784: 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 )))))))))))))))) +| 800: 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 )))))))))))))))) +| 816: 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 )))))))))))))))) +| 832: 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 )))))))))))))))) +| 848: 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 )))))))))))))))) +| 864: 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 )))))))))))))))) +| 880: 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 )))))))))))))))) +| 896: 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 )))))))))))))))) +| 912: 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 )))))))))))))))) +| 928: 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 )))))))))))))))) +| 944: 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 )))))))))))))))) +| 960: 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 )))))))))))))))) +| 976: 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 )))))))))))))))) +| 992: 29 29 29 29 29 29 29 29 29 29 dd dd dd dd dd dd ))))))))))...... +| 1008: dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd ................ +| page 2 offset 1024 +| 0: dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd ................ +| 16: dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd ................ +| 32: dd dd 6e 69 d2 e9 e9 e9 d2 d2 d2 d2 d2 dd dd dd ..ni............ +| 48: dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd ................ +| 64: dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd ................ +| 80: dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd ................ +| 96: dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd ................ +| 112: dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd ................ +| 128: dd dd dd dd dd dd 29 29 29 29 29 29 29 29 29 29 ......)))))))))) +| 144: 29 29 29 29 29 29 29 29 29 ad a5 29 29 29 29 00 )))))))))..)))). +| 160: 75 9c 11 00 5b e5 64 28 7c ca 09 69 28 2d 69 00 u...[.d(|..i(-i. +| 176: 85 88 6c 81 48 83 a0 93 c0 c0 82 8b 81 84 85 f9 ..l.H........... +| 192: 88 7a 00 7f 00 96 40 7b 12 4b 84 75 a0 00 99 a0 .z....@..K.u.... +| 208: df a0 7e 81 c6 90 8f 7f 84 85 cc 84 82 90 88 60 ..~............` +| 224: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................ +| 240: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................ +| 256: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................ +| 272: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................ +| 288: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 02 02 ................ +| 304: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 320: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 336: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 352: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 368: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 384: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 400: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 416: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 432: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 448: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 464: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 480: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 496: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 512: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 528: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 544: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 560: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 576: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 592: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 608: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 624: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 640: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 656: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 672: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 688: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 704: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 720: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 736: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 752: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 768: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 784: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 800: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 816: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 832: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 848: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 864: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 880: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 896: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 912: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 928: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 944: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 960: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 976: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 992: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 1008: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| page 3 offset 2048 +| 0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 16: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 32: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 48: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 64: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 80: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 96: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 112: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 128: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 144: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 160: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 176: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 192: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 208: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 224: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 240: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 256: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 272: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 288: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 304: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 320: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 336: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 352: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 368: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 384: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 400: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 416: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 432: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 448: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 464: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 480: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 496: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 512: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 528: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 544: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 560: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 576: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 592: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 608: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 624: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 640: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 656: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 672: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 688: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 704: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 720: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 736: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 752: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 768: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 784: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 800: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 816: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 832: 02 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................ +| 848: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................ +| 864: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................ +| 880: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................ +| 896: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................ +| 912: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................ +| 928: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................ +| 944: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................ +| 960: 80 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 976: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 992: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 1008: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| page 4 offset 3072 +| 0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 16: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 32: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 48: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 64: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 80: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 96: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 112: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 128: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 144: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 160: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 176: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 192: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 208: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 224: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 240: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 256: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 272: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 288: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 304: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 320: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 336: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 352: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 368: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 384: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 400: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 416: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 432: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 448: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 464: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 480: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 496: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 512: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 528: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 544: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 560: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 576: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 592: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 608: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 624: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 640: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 656: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 672: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 688: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 704: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 720: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 736: 5f 5f 5f 5f 5f 5f 5f 00 d5 fe fe fe 08 00 00 00 _______......... +| end clusterfuzz-testcase-sql_recovery_fuzzer-5803962339885056 +}]} {} + +sqlite3_dbdata_init db +do_execsql_test 1.1 { + PRAGMA writable_schema = 1; +} + +do_test 1.2 { + set R [sqlite3_recover_init db main test.db2] + $R run + $R finish +} {} + +#------------------------------------------------------------------------- +reset_db +do_test 2.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +| size 3821 pagesize 1024 filename clusterfuzz-testcase-sql_recovery_fuzzer-5803962339885056 +| 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: 04 00 01 01 00 40 20 20 00 00 00 01 00 00 00 02 .....@ ........ +| 32: 00 00 00 00 00 00 00 00 00 00 00 01 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 01 ................ +| 96: 00 2e 7a 70 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 112: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 128: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 144: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 160: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 176: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 192: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 208: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 224: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 240: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 256: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 272: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 288: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 304: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 320: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 336: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 352: 02 02 02 02 a0 02 02 02 02 02 02 02 02 02 02 02 ................ +| 368: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 384: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 400: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 416: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 432: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 448: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 29 29 ..............)) +| 464: 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 )))))))))))))))) +| 480: 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 )))))))))))))))) +| 496: 29 29 29 dd dd dd dd dd dd dd dd dd dd dd dd dd )))............. +| 512: dd dd dd dd dd dd dd dd dd 6e 69 d2 e9 e9 e9 d2 .........ni..... +| 528: d2 d2 d2 d2 dd dd dd dd dd dd dd dd dd dd dd dd ................ +| 544: dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd ................ +| 560: dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd ................ +| 576: dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd ................ +| 592: dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd ................ +| 608: dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd ................ +| 624: dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd ................ +| 640: dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd ................ +| 656: dd dd dd dd dd dd dd da dd dd dd dd dd dd dd dd ................ +| 672: dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd ................ +| 688: dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd ................ +| 704: dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd ................ +| 720: dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd ................ +| 736: dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd ................ +| 752: dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd ................ +| 768: dd dd dd dd dd dd dd dd dd dd dd dd dd 29 29 29 .............))) +| 784: 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 )))))))))))))))) +| 800: 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 )))))))))))))))) +| 816: 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 )))))))))))))))) +| 832: 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 )))))))))))))))) +| 848: 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 )))))))))))))))) +| 864: 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 )))))))))))))))) +| 880: 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 )))))))))))))))) +| 896: 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 )))))))))))))))) +| 912: 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 )))))))))))))))) +| 928: 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 )))))))))))))))) +| 944: 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 )))))))))))))))) +| 960: 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 )))))))))))))))) +| 976: 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 )))))))))))))))) +| 992: 29 29 29 29 29 29 29 29 29 29 dd dd dd dd dd dd ))))))))))...... +| 1008: dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd ................ +| page 2 offset 1024 +| 0: dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd ................ +| 16: dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd ................ +| 32: dd dd 6e 69 d2 e9 e9 e9 d2 d2 d2 d2 d2 dd dd dd ..ni............ +| 48: dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd ................ +| 64: dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd ................ +| 80: dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd ................ +| 96: dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd ................ +| 112: dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd ................ +| 128: dd dd dd dd dd dd 29 29 29 29 29 29 29 29 29 29 ......)))))))))) +| 144: 29 29 29 29 29 29 29 29 29 ad a5 29 29 29 29 00 )))))))))..)))). +| 160: 75 9c 11 00 5b e5 64 28 7c ca 09 69 28 2d 69 00 u...[.d(|..i(-i. +| 176: 85 88 6c 81 48 83 a0 93 c0 c0 82 8b 81 84 85 f9 ..l.H........... +| 192: 88 7a 00 7f 00 96 40 7b 12 4b 84 75 a0 00 99 a0 .z....@..K.u.... +| 208: df a0 7e 81 c6 90 8f 7f 84 85 cc 84 82 90 88 60 ..~............` +| 224: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................ +| 240: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................ +| 256: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................ +| 272: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................ +| 288: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 02 02 ................ +| 304: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 320: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 336: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 352: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 368: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 384: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 400: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 416: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 432: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 448: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 464: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 480: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 496: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 512: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 528: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 544: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 560: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 576: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 592: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 608: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 624: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 640: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 656: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 672: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 688: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 704: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 720: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 736: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 752: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 768: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 784: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 800: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 816: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 832: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 848: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 864: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 880: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 896: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 912: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 928: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 944: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 960: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 976: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 992: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 1008: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| page 3 offset 2048 +| 0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 16: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 32: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 48: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 64: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 80: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 96: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 112: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 128: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 144: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 160: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 176: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 192: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 208: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 224: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 240: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 256: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 272: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 288: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 304: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 320: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 336: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 352: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 368: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 384: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 400: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 416: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 432: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 448: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 464: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 480: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 496: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 512: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 528: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 544: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 560: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 576: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 592: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 608: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 624: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 640: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 656: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 672: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 688: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 704: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 720: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 736: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 752: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 768: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 784: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 800: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 816: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 832: 02 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................ +| 848: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................ +| 864: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................ +| 880: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................ +| 896: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................ +| 912: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................ +| 928: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................ +| 944: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ................ +| 960: 80 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 976: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 992: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 1008: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| page 4 offset 3072 +| 0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 16: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 32: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 48: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 64: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 80: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 96: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 112: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 128: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 144: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 160: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 176: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 192: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 208: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 224: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 240: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 256: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 272: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 288: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 304: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 320: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 336: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 352: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 368: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 384: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 400: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 416: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 432: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 448: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 464: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 480: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 496: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 512: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 528: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 544: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 560: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 576: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 592: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 608: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 624: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 640: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 656: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 672: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 688: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 704: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 720: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................ +| 736: 5f 5f 5f 5f 5f 5f 5f 00 d5 fe fe fe 08 00 00 00 _______......... +| end clusterfuzz-testcase-sql_recovery_fuzzer-5803962339885056 +}]} {} + +sqlite3_dbdata_init db +do_execsql_test 2.1 { + PRAGMA writable_schema = 1; +} + +do_test 2.2 { + set R [sqlite3_recover_init db main test.db2] + $R run + $R finish +} {} + +finish_test + diff --git a/manifest b/manifest index dece840222..86cb7fabac 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sproblem\scausing\sthe\srecovery\sextension\sto\suse\sexcessive\smemory\sand\sCPU\stime\sin\ssome\scases. -D 2024-05-01T14:42:20.390 +C Fix\sanother\sproblem\sin\sthe\srecovery\sextension\swhere\sa\scorrupt\ssqlite_schema\stable\scould\slead\sto\sexcessive\smemory\sconsumption. +D 2024-05-01T16:25:46.099 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -478,13 +478,14 @@ F ext/rbu/rbuvacuum4.test ffccd22f67e2d0b380d2889685742159dfe0d19a3880ca3d2d1d69 F ext/rbu/sqlite3rbu.c 4a3376c0fb9a844a799ac529fb81260523f6b13c9f629bc270c632dbae5fc1f8 F ext/rbu/sqlite3rbu.h 9d923eb135c5d04aa6afd7c39ca47b0d1d0707c100e02f19fdde6a494e414304 F ext/rbu/test_rbu.c ee6ede75147bc081fe9bc3931e6b206277418d14d3fbceea6fdc6216d9b47055 -F ext/recover/dbdata.c bca5845064cf07b5583f4030d91906b1f147c52a80eff4adf591893d3a7c286c +F ext/recover/dbdata.c 520636e61eddfa22fe13b0324c0e7b67b699464ff63aeaf4c26ff00b7ba0844c F ext/recover/recover1.test c484d01502239f11b61f23c1cee9f5dd19fa17617f8974e42e74d64639c524cf F ext/recover/recover_common.tcl a61306c1eb45c0c3fc45652c35b2d4ec19729e340bdf65a272ce4c229cefd85a F ext/recover/recoverbuild.test c74170e0f7b02456af41838afeb5353fdb985a48cc2331d661bbabbca7c6b8e3 F ext/recover/recoverclobber.test 3ba6c0c373c5c63d17e82eced64c05c57ccaf26c1abe1ca7141334022a79f32e F ext/recover/recovercorrupt.test 64c081ad1200ae77b447da99eb724785d6bf71715f394543dc7689642e92bf49 F ext/recover/recovercorrupt2.test 1418f1710debc24ff38276cedfcea234beb37a34205708e7e3e6d76cc4a979db +F ext/recover/recovercorrupt3.test 2e7b9a1b528ca23ed382cec6f64e3fcbbd0f8e852add7562397fd8df83f335d5 F ext/recover/recoverfault.test 9d9f88eeb222615a25e7514f234c950d46bee20d24cd8db49d8fff8d650dcfe1 F ext/recover/recoverfault2.test 730e7371bcda769554d15460cb23126abba1be8eca9539ccabf63623e7bb7e09 F ext/recover/recoverold.test 68db3d6f85dd2b98e785b6c4da4f5eea4bbe52ccf6674d9a94c7506dc92596aa @@ -2186,8 +2187,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 2858efa06d4fc7b412b892f35f5e9a766b467b4a5b74d602a030d25443f9efb4 -R 3b77a71cd99d532953a23626b8d60d55 +P 8de85170d53e1d2a2abe14508a222377b9493e25f3174b8f0f773427deb8df26 +R 2e43de06901a93042cb97fda0a6a1240 U dan -Z d212fc82f6805723a5e49c9577f6a006 +Z 503087664d848ee9e213d2cb778368c0 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 041e2c89a9..f2af8cbeb6 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8de85170d53e1d2a2abe14508a222377b9493e25f3174b8f0f773427deb8df26 \ No newline at end of file +1c7e33a8aa0e6122b5ef606e4a7d95e8ecd9440216d4b099fe8f2a40653422be \ No newline at end of file From f3ea92cceb577524c1d329aed2400127d7fd716a Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 1 May 2024 19:48:24 +0000 Subject: [PATCH 362/430] Avoid an OP_Next in cases where an IN(...) query against a UNIQUE index may return at most 1 row. FossilOrigin-Name: 560f64157d2fe40e107582eebb6526185c9c43305e364f4132e182dbec5b210a --- manifest | 16 +++++--- manifest.uuid | 2 +- src/wherecode.c | 25 ++++++++++- test/in7.test | 107 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 142 insertions(+), 8 deletions(-) create mode 100644 test/in7.test diff --git a/manifest b/manifest index 903dfbc746..fea7669dba 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Avoid\s32-bit\soverflow\swhen\scalculating\sncycle\sfor\s".scanstats\svm". -D 2024-04-30T19:34:15.474 +C Avoid\san\sOP_Next\sin\scases\swhere\san\sIN(...)\squery\sagainst\sa\sUNIQUE\sindex\smay\sreturn\sat\smost\s1\srow. +D 2024-05-01T19:48:24.190 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -838,7 +838,7 @@ F src/wal.h ba252daaa94f889f4b2c17c027e823d9be47ce39da1d3799886bbd51f0490452 F src/walker.c 7c7ea0115345851c3da4e04e2e239a29983b61fb5b038b94eede6aba462640e2 F src/where.c 0ef9638651b900d64d7e1e877af37cd7900159ff875547ec29b918a1497e5c9c F src/whereInt.h 82a13766f13d1a53b05387c2e60726289ef26404bc7b9b1f7770204d97357fb8 -F src/wherecode.c 1f6940349e92a6e056aecd70163b00f331554c815c362b4cc80906c48151d73d +F src/wherecode.c b73b5bcd0840491e8faa126fbf933e3bda0d9bf85222ddc7ff608154f0f86d1e F src/whereexpr.c 67d15caf88a1a9528283d68ff578e024cf9fe810b517bb0343e5aaf695ad97dd F src/window.c 5d95122dd330bfaebd732358c8ef067c5a9394a53ac249470d611d0ce2c52be2 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 @@ -1278,6 +1278,7 @@ F test/in3.test 3cbf58c87f4052cee3a58b37b6389777505aa0c0 F test/in4.test bb767ec1cfd1730256f0a83219f0acda36bc251b63f8b8bb7d8c7cff17875a4f F test/in5.test 4fd79c70dfa0681313e8cdca07f5ff0400bdc0e20f808a5c59eaef1e4b48082a F test/in6.test f5f40d6816a8bb7c784424b58a10ac38efb76ab29127a2c17399e0cbeeda0e4b +F test/in7.test e0b3bd735c13547f038f386440152ad2642a066e9f96366552763bb5455117d0 F test/incrblob.test c9b96afc292aeff43d6687bcb09b0280aa599822 F test/incrblob2.test a494c9e848560039a23974b9119cfc2cf3ad3bd15cc2694ee6367ae537ef8f1f F test/incrblob3.test 67621a04b3084113bf38ce03797d70eca012d9d8f948193b8f655df577b0da6f @@ -2186,8 +2187,11 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 5f6c079d847e3664ec5acaf1b3e989efe0d548c211ae4a18936162b36df89065 -R 903fbc18fbeeda59fd5e86360c55f235 +P 2858efa06d4fc7b412b892f35f5e9a766b467b4a5b74d602a030d25443f9efb4 +R 5dedafa0dd1df259fa093801bd417269 +T *branch * unique-in-opt +T *sym-unique-in-opt * +T -sym-trunk * U dan -Z 0ade4d9c1bbdd68ad336341e8aad91d0 +Z 057540a67356c4bc1a4b77adc8c49f86 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 07075e1cbb..cb59acdb7c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2858efa06d4fc7b412b892f35f5e9a766b467b4a5b74d602a030d25443f9efb4 \ No newline at end of file +560f64157d2fe40e107582eebb6526185c9c43305e364f4132e182dbec5b210a \ No newline at end of file diff --git a/src/wherecode.c b/src/wherecode.c index d95eae2797..a895d3935b 100644 --- a/src/wherecode.c +++ b/src/wherecode.c @@ -1337,6 +1337,27 @@ static SQLITE_NOINLINE void filterPullDown( } } +/* +** Loop pLoop is a WHERE_INDEXED level that uses at least one IN(...) +** operator. Return true if level pLoop is guaranteed to visit only one +** row for each key generated for the index. +*/ +static int whereLoopIsOneRow(WhereLoop *pLoop){ + if( pLoop->u.btree.pIndex->onError + && pLoop->nSkip==0 + && pLoop->u.btree.nEq==pLoop->u.btree.pIndex->nKeyCol + ){ + int ii; + for(ii=0; iiu.btree.nEq; ii++){ + if( pLoop->aLTerm[ii]->eOperator & (WO_IS|WO_ISNULL) ){ + return 0; + } + } + return 1; + } + return 0; +} + /* ** Generate code for the start of the iLevel-th loop in the WHERE clause ** implementation described by pWInfo. @@ -2084,7 +2105,9 @@ Bitmask sqlite3WhereCodeOneLoopStart( } /* Record the instruction used to terminate the loop. */ - if( pLoop->wsFlags & WHERE_ONEROW ){ + if( (pLoop->wsFlags & WHERE_ONEROW) + || (pLevel->u.in.nIn && whereLoopIsOneRow(pLoop)) + ){ pLevel->op = OP_Noop; }else if( bRev ){ pLevel->op = OP_Prev; diff --git a/test/in7.test b/test/in7.test new file mode 100644 index 0000000000..8917d4432f --- /dev/null +++ b/test/in7.test @@ -0,0 +1,107 @@ +# 2024-05-01 +# +# 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. +# +#*********************************************************************** +# +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix in7 + +do_execsql_test 1.0 { + CREATE TABLE t1(a, b, c PRIMARY KEY); + CREATE TABLE t2(x, y, z); +} + +foreach {tn nNext idx sql} { + 1 1 { + CREATE INDEX i1 ON t1(a, b); + } { + SELECT * FROM t1 WHERE (a, b) IN (SELECT x, y FROM t2) + } + + 2 0 { + CREATE UNIQUE INDEX i1 ON t1(a, b); + } { + SELECT * FROM t1 WHERE (a, b) IN (SELECT x, y FROM t2) + } + + 3 0 { + CREATE UNIQUE INDEX i1 ON t1(a, b); + } { + SELECT * FROM t1 WHERE a = ? AND b = ? + } + + 3 1 { + CREATE UNIQUE INDEX i1 ON t1(a, b); + } { + SELECT * FROM t1 WHERE a = ? AND b IS ? + } + + 4 0 { + CREATE UNIQUE INDEX i1 ON t1(a, b); + } { + SELECT * FROM t1 WHERE a = ? AND b IN (?, ?, ?); + } + + 5 1 { + CREATE UNIQUE INDEX i1 ON t1(a, b, c); + } { + SELECT * FROM t1 WHERE a = ? AND b = ? + } + + 6 0 { + } { + SELECT * FROM t1 WHERE c IN (SELECT z FROM t2) + } + + 7 0 { + } { + SELECT * FROM t1 WHERE (a, c) IN (SELECT z, x FROM t2) + } + + 8 1 { + } { + SELECT * FROM t1 WHERE a IN (SELECT z FROM t2) + } +} { + do_test 1.1.$tn { + execsql BEGIN + execsql $idx + + catch { array unset root_to_tbl } + catch { array unset csr_to_root } + + db eval {SELECT rootpage, tbl_name FROM sqlite_schema} { + set root_to_tbl($rootpage) $tbl_name + } + + set nSeen 0 + db eval "explain $sql" { + if {$opcode=="OpenRead"} { + set csr_to_root($p1) $p2 + } + if {$opcode=="Next"} { + catch { + set root $csr_to_root($p1) + set tbl $root_to_tbl($root) + if {$tbl=="t1"} {incr nSeen} + } + } + } + + execsql ROLLBACK + + set nSeen + } $nNext +} + + +finish_test From 2ae4531c89bbf9a3f01827e8019eddac0705765b Mon Sep 17 00:00:00 2001 From: drh <> Date: Thu, 2 May 2024 11:51:26 +0000 Subject: [PATCH 363/430] Omit the OP_SqlExec to "PRAGMA integrity_check" added by [348fa7aaf7958b3f] because it is a no-op. Even if the integrity_check failes, the CREATE TABLE is stull successful. The OP_SqlExec just burns CPU cycles for no reason. FossilOrigin-Name: 532795acd1c800751737fe70148f9ae691e9cf11b836577f8538421d24cab2fe --- manifest | 17 ++++++++++------- manifest.uuid | 2 +- src/build.c | 3 --- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 86cb7fabac..c00ad06360 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sanother\sproblem\sin\sthe\srecovery\sextension\swhere\sa\scorrupt\ssqlite_schema\stable\scould\slead\sto\sexcessive\smemory\sconsumption. -D 2024-05-01T16:25:46.099 +C Omit\sthe\sOP_SqlExec\sto\s"PRAGMA\sintegrity_check"\sadded\sby\s[348fa7aaf7958b3f]\nbecause\sit\sis\sa\sno-op.\s\sEven\sif\sthe\sintegrity_check\sfailes,\sthe\sCREATE\sTABLE\nis\sstull\ssuccessful.\s\sThe\sOP_SqlExec\sjust\sburns\sCPU\scycles\sfor\sno\sreason. +D 2024-05-02T11:51:26.866 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -694,7 +694,7 @@ F src/btmutex.c 79a43670447eacc651519a429f6ece9fd638563cf95b469d6891185ddae2b522 F src/btree.c 71b80e77b255144db47180fda8138740608e382a44231942464029b1a45fc036 F src/btree.h 55066f513eb095db935169dab1dc2f7c7a747ef223c533f5d4ad4dfed346cbd0 F src/btreeInt.h 98aadb6dcb77b012cab2574d6a728fad56b337fc946839b9898c4b4c969e30b6 -F src/build.c 02f5b25ca854c83b5015cb02b8c9ab236c60b1795528675aee8a5070e58da52a +F src/build.c 11ec7014a3c468e7b3ccc8dda8d9111cd5a29a358df18818788601e0600aaabd F src/callback.c db3a45e376deff6a16c0058163fe0ae2b73a2945f3f408ca32cf74960b28d490 F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e F src/ctime.c 64e4b1227b4ed123146f0aa2989131d1fbd9b927b11e80c9d58c6a68f9cd5ce3 @@ -2187,8 +2187,11 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 8de85170d53e1d2a2abe14508a222377b9493e25f3174b8f0f773427deb8df26 -R 2e43de06901a93042cb97fda0a6a1240 -U dan -Z 503087664d848ee9e213d2cb778368c0 +P 1c7e33a8aa0e6122b5ef606e4a7d95e8ecd9440216d4b099fe8f2a40653422be +R fa686d9a513ff74fa7b322c41469fcee +T *branch * faster-create +T *sym-faster-create * +T -sym-trunk * +U drh +Z 8e0fd4c6a3749c78cd7f96ba5b5be837 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index f2af8cbeb6..ab55c07118 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1c7e33a8aa0e6122b5ef606e4a7d95e8ecd9440216d4b099fe8f2a40653422be \ No newline at end of file +532795acd1c800751737fe70148f9ae691e9cf11b836577f8538421d24cab2fe \ No newline at end of file diff --git a/src/build.c b/src/build.c index 8279c0a89c..10aa342407 100644 --- a/src/build.c +++ b/src/build.c @@ -2927,9 +2927,6 @@ void sqlite3EndTable( sqlite3MPrintf(db, "SELECT*FROM\"%w\".\"%w\"", db->aDb[iDb].zDbSName, p->zName), P4_DYNAMIC); } - sqlite3VdbeAddOp4(v, OP_SqlExec, 0x0001, 0, 0, - sqlite3MPrintf(db, "PRAGMA \"%w\".integrity_check(%Q)", - db->aDb[iDb].zDbSName, p->zName), P4_DYNAMIC); } /* Add the table to the in-memory representation of the database. From 78bc1339ac9abe90927fdfcd71bf017595b80554 Mon Sep 17 00:00:00 2001 From: drh <> Date: Thu, 2 May 2024 11:52:31 +0000 Subject: [PATCH 364/430] Do not accept a string that looks like a number used as an argument to PRAGMA integrity_check as a number. Treat it as a table name that just happens to look like a number. FossilOrigin-Name: b04e7a23478f1012e501a810f3e09cca81a66e802f5f72cae80c81120174e2cb --- manifest | 15 ++++++--------- manifest.uuid | 2 +- src/pragma.c | 2 +- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index c00ad06360..d7bfebc567 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Omit\sthe\sOP_SqlExec\sto\s"PRAGMA\sintegrity_check"\sadded\sby\s[348fa7aaf7958b3f]\nbecause\sit\sis\sa\sno-op.\s\sEven\sif\sthe\sintegrity_check\sfailes,\sthe\sCREATE\sTABLE\nis\sstull\ssuccessful.\s\sThe\sOP_SqlExec\sjust\sburns\sCPU\scycles\sfor\sno\sreason. -D 2024-05-02T11:51:26.866 +C Do\snot\saccept\sa\sstring\sthat\slooks\slike\sa\snumber\sused\sas\san\sargument\sto\nPRAGMA\sintegrity_check\sas\sa\snumber.\s\sTreat\sit\sas\sa\stable\sname\sthat\sjust\nhappens\sto\slook\slike\sa\snumber. +D 2024-05-02T11:52:31.688 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -745,7 +745,7 @@ F src/parse.y 5bcef16094213efcc365a9d4dc4e3131f09251dc8838dce4a9e5f9764bff5b82 F src/pcache.c 040b165f30622a21b7a9a77c6f2e4877a32fb7f22d4c7f0d2a6fa6833a156a75 F src/pcache.h 1497ce1b823cf00094bb0cf3bac37b345937e6f910890c626b16512316d3abf5 F src/pcache1.c 602acb23c471bb8d557a6f0083cc2be641d6cafcafa19e481eba7ef4c9ca0f00 -F src/pragma.c f8f1845b42df684e9d31c5a1628c989a34939686049d7878bc5394ac1ae9cac4 +F src/pragma.c d357a25276d222adfd4637c48880409ec4539f30844b74001c6ba5c7d1a1f0f7 F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7 F src/prepare.c 371f6115cb69286ebc12c6f2d7511279c2e47d9f54f475d46a554d687a3b312c F src/printf.c 8b250972305e14b365561be5117ed0fd364e4fd58968776df1ce64c6280b90f9 @@ -2187,11 +2187,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 1c7e33a8aa0e6122b5ef606e4a7d95e8ecd9440216d4b099fe8f2a40653422be -R fa686d9a513ff74fa7b322c41469fcee -T *branch * faster-create -T *sym-faster-create * -T -sym-trunk * +P 532795acd1c800751737fe70148f9ae691e9cf11b836577f8538421d24cab2fe +R ac4ea06b7b0d066e4f57370f325b3bc3 U drh -Z 8e0fd4c6a3749c78cd7f96ba5b5be837 +Z fc28259a0336795cd85fcb803ce7457a # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index ab55c07118..ac399de21c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -532795acd1c800751737fe70148f9ae691e9cf11b836577f8538421d24cab2fe \ No newline at end of file +b04e7a23478f1012e501a810f3e09cca81a66e802f5f72cae80c81120174e2cb \ No newline at end of file diff --git a/src/pragma.c b/src/pragma.c index 8af18cbf20..80864da79f 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -1703,7 +1703,7 @@ void sqlite3Pragma( /* Set the maximum error count */ mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX; if( zRight ){ - if( sqlite3GetInt32(zRight, &mxErr) ){ + if( sqlite3GetInt32(pValue->z, &mxErr) ){ if( mxErr<=0 ){ mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX; } From 9b4e7898d754bc533be38908825d62a526bd6e75 Mon Sep 17 00:00:00 2001 From: drh <> Date: Thu, 2 May 2024 12:00:36 +0000 Subject: [PATCH 365/430] Add a test case to the fix to PRAGMA integrity_check in the previous check-in. FossilOrigin-Name: 39a57b596d309d9e2d4c59409fe5d36e0665781ce0307d157ff8b6e883161bbb --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/pragma.test | 3 +++ 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index d7bfebc567..0582d49a23 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Do\snot\saccept\sa\sstring\sthat\slooks\slike\sa\snumber\sused\sas\san\sargument\sto\nPRAGMA\sintegrity_check\sas\sa\snumber.\s\sTreat\sit\sas\sa\stable\sname\sthat\sjust\nhappens\sto\slook\slike\sa\snumber. -D 2024-05-02T11:52:31.688 +C Add\sa\stest\scase\sto\sthe\sfix\sto\sPRAGMA\sintegrity_check\sin\sthe\sprevious\scheck-in. +D 2024-05-02T12:00:36.739 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -1501,7 +1501,7 @@ F test/pendingrace.test 6aa33756b950c4529f79c4f3817a9a1e4025bd0d9961571a05c0279b F test/percentile.test 4243af26b8f3f4555abe166f723715a1f74c77ff F test/permutations.test 405542f1d659942994a6b38a9e024cf5cfd23eaa68c806aeb24a72d7c9186e80 F test/pg_common.tcl 3b27542224db1e713ae387459b5d117c836a5f6e328846922993b6d2b7640d9f -F test/pragma.test 8bb6d3992c1c31ff6d5553d1e0693d642f7e19015648c6ae7034cb497d26bbd4 +F test/pragma.test 11cb9310c42f921918f7f563e3c0b6e70f9f9c3a6a1cf12af8fccb6c574f3882 F test/pragma2.test e5d5c176360c321344249354c0c16aec46214c9f F test/pragma3.test 92a46bbea12322dd94a404f49edcfbfc913a2c98115f0d030a7459bb4712ef31 F test/pragma4.test 22834a228e59b80f5c15b519b710474859d91535002670ddb7cd13ac44b54e9a @@ -2187,8 +2187,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 532795acd1c800751737fe70148f9ae691e9cf11b836577f8538421d24cab2fe -R ac4ea06b7b0d066e4f57370f325b3bc3 +P b04e7a23478f1012e501a810f3e09cca81a66e802f5f72cae80c81120174e2cb +R 0ac28bb5468fe4b54198e9b7f938f439 U drh -Z fc28259a0336795cd85fcb803ce7457a +Z 39f04eb486031705b188423b1deb4083 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index ac399de21c..37970c7581 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b04e7a23478f1012e501a810f3e09cca81a66e802f5f72cae80c81120174e2cb \ No newline at end of file +39a57b596d309d9e2d4c59409fe5d36e0665781ce0307d157ff8b6e883161bbb \ No newline at end of file diff --git a/test/pragma.test b/test/pragma.test index 048dee8386..e823a67630 100644 --- a/test/pragma.test +++ b/test/pragma.test @@ -387,6 +387,9 @@ ifcapable attach { PRAGMA integrity_check=4 } } {{wrong # of entries in index i2} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}} + do_catchsql_test pragma-3.5.2 { + PRAGMA integrity_check='4' + } {1 {no such table: 4}} do_catchsql_test pragma-3.6 { PRAGMA integrity_check=xyz } {1 {no such table: xyz}} From 01508c814ccf21be880bfab14776a1015283e82a Mon Sep 17 00:00:00 2001 From: dan Date: Thu, 2 May 2024 17:46:52 +0000 Subject: [PATCH 366/430] Fix a case where the recovery extension might write uninitialized data to the recovered database. FossilOrigin-Name: 8519b4d0393ed17eed06bceffbc891fe8cae0bc1d466a79eba0602ef46b07c56 --- ext/recover/dbdata.c | 2 +- manifest | 13 ++++++------- manifest.uuid | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/ext/recover/dbdata.c b/ext/recover/dbdata.c index b01e544885..1905e68813 100644 --- a/ext/recover/dbdata.c +++ b/ext/recover/dbdata.c @@ -666,7 +666,6 @@ static int dbdataNext(sqlite3_vtab_cursor *pCursor){ rc = dbdataBufferSize(&pCsr->rec, nPayload+DBDATA_PADDING_BYTES); if( rc!=SQLITE_OK ) return rc; assert( nPayload!=0 ); - pCsr->nRec = nPayload; /* Load the nLocal bytes of payload */ memcpy(pCsr->rec.aBuf, &pCsr->aPage[iOff], nLocal); @@ -696,6 +695,7 @@ static int dbdataNext(sqlite3_vtab_cursor *pCursor){ nPayload -= nRem; } memset(&pCsr->rec.aBuf[nPayload], 0, DBDATA_PADDING_BYTES); + pCsr->nRec = nPayload; iHdr = dbdataGetVarintU32(pCsr->rec.aBuf, &nHdr); if( nHdr>nPayload ) nHdr = 0; diff --git a/manifest b/manifest index 7d77c4e1d2..d003fac95f 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Avoid\san\sOP_Next\sin\scases\swhere\san\sIN(...)\squery\sagainst\sa\sUNIQUE\sindex\smay\sreturn\sat\smost\s1\srow. -D 2024-05-02T14:48:58.295 +C Fix\sa\scase\swhere\sthe\srecovery\sextension\smight\swrite\suninitialized\sdata\sto\sthe\srecovered\sdatabase. +D 2024-05-02T17:46:52.967 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -478,7 +478,7 @@ F ext/rbu/rbuvacuum4.test ffccd22f67e2d0b380d2889685742159dfe0d19a3880ca3d2d1d69 F ext/rbu/sqlite3rbu.c 4a3376c0fb9a844a799ac529fb81260523f6b13c9f629bc270c632dbae5fc1f8 F ext/rbu/sqlite3rbu.h 9d923eb135c5d04aa6afd7c39ca47b0d1d0707c100e02f19fdde6a494e414304 F ext/rbu/test_rbu.c ee6ede75147bc081fe9bc3931e6b206277418d14d3fbceea6fdc6216d9b47055 -F ext/recover/dbdata.c 520636e61eddfa22fe13b0324c0e7b67b699464ff63aeaf4c26ff00b7ba0844c +F ext/recover/dbdata.c e518c1a221a259a1ea594d9db8fce356861bfa450e6f54eda999242b9bd5c50a F ext/recover/recover1.test c484d01502239f11b61f23c1cee9f5dd19fa17617f8974e42e74d64639c524cf F ext/recover/recover_common.tcl a61306c1eb45c0c3fc45652c35b2d4ec19729e340bdf65a272ce4c229cefd85a F ext/recover/recoverbuild.test c74170e0f7b02456af41838afeb5353fdb985a48cc2331d661bbabbca7c6b8e3 @@ -2188,9 +2188,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 71f08b912251c8a3ac1bd8e344903336648e4187f7493f8c126e60b3b51b9f09 560f64157d2fe40e107582eebb6526185c9c43305e364f4132e182dbec5b210a -R 86283dd1f6bad0a3523b1ba3ad89b434 -T +closed 560f64157d2fe40e107582eebb6526185c9c43305e364f4132e182dbec5b210a +P d7648e21605a0b381b1935a47e5a77bdfacc4cc96f03d6bb7956f8f4e6a40648 +R 91204a904de412874c1ad0642f190840 U dan -Z 136e857f8914132ecc08f9fc952c59a7 +Z c29162d93ac6c523dea45672137e5762 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index d6d09be1f3..1fad912567 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d7648e21605a0b381b1935a47e5a77bdfacc4cc96f03d6bb7956f8f4e6a40648 \ No newline at end of file +8519b4d0393ed17eed06bceffbc891fe8cae0bc1d466a79eba0602ef46b07c56 \ No newline at end of file From 72814933b9f072685788e49c6df409ba3f16668e Mon Sep 17 00:00:00 2001 From: dan Date: Thu, 2 May 2024 18:16:23 +0000 Subject: [PATCH 367/430] Avoid an assert failure accessible only when internal testing features are enabled. dbsqlfuzz crash-66abacda6bca6bd531e25595e8c8068e2c710326.txt. FossilOrigin-Name: fbc446daac761dd1b66a85c9b61e1d5af194a8fd665600c43a874da38cc6ec10 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/resolve.c | 3 ++- test/returning1.test | 11 +++++++++++ 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index d003fac95f..f3c1c280fd 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\scase\swhere\sthe\srecovery\sextension\smight\swrite\suninitialized\sdata\sto\sthe\srecovered\sdatabase. -D 2024-05-02T17:46:52.967 +C Avoid\san\sassert\sfailure\saccessible\sonly\swhen\sinternal\stesting\sfeatures\sare\senabled.\sdbsqlfuzz\scrash-66abacda6bca6bd531e25595e8c8068e2c710326.txt. +D 2024-05-02T18:16:23.502 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -750,7 +750,7 @@ F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7 F src/prepare.c 371f6115cb69286ebc12c6f2d7511279c2e47d9f54f475d46a554d687a3b312c F src/printf.c 8b250972305e14b365561be5117ed0fd364e4fd58968776df1ce64c6280b90f9 F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c -F src/resolve.c 647edf93729ba124c0a6048982af56c2fa4f841e69d626e4f3caa620f082bb15 +F src/resolve.c 8816212645e4e9bdf3cc2f2d298304f388d699f8fab47f3a5712ef5bbc5b6ccc F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c 04178566d0188be7de471064ced8cec1d407920726cb49b609486282d78faf56 F src/shell.c.in 0354ca51eee5fbf6af394a7ef9f5ef6823ef45b743db65431f6777e4d5be2199 @@ -1533,7 +1533,7 @@ F test/regexp2.test 55ed41da802b0e284ac7e2fe944be3948f93ff25abbca0361a609acfed13 F test/reindex.test cd9d6021729910ece82267b4f5e1b5ac2911a7566c43b43c176a6a4732e2118d F test/resetdb.test 54c06f18bc832ac6d6319e5ab23d5c8dd49fdbeec7c696d791682a8006bd5fc3 F test/resolver01.test f4022acafda7f4d40eca94dbf16bc5fc4ac30ceb -F test/returning1.test 2ebfe6e56f3de9b194295620f46a747c26cebdab937defb9afd84b96dd202ccb +F test/returning1.test 38eee9d07ac1dd4fbd4ce7373497f3783db86b9a76f13ea6a9f9afaf934f888b F test/returningfault.test ae4c4b5e8745813287a359d9ccdb9d5c883c2e68afb18fb0767937d5de5692a4 F test/rollback.test 06680159bc6746d0f26276e339e3ae2f951c64812468308838e0a3362d911eaa F test/rollback2.test 3f3a4e20401825017df7e7671e9f31b6de5fae5620c2b9b49917f52f8c160a8f @@ -2188,8 +2188,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P d7648e21605a0b381b1935a47e5a77bdfacc4cc96f03d6bb7956f8f4e6a40648 -R 91204a904de412874c1ad0642f190840 +P 8519b4d0393ed17eed06bceffbc891fe8cae0bc1d466a79eba0602ef46b07c56 +R 0a3b026a0a16d38bbb74d5089bed24b2 U dan -Z c29162d93ac6c523dea45672137e5762 +Z ae138bbd9a4a27c1543b292e5b8d0d96 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 1fad912567..9a2c0a20d2 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8519b4d0393ed17eed06bceffbc891fe8cae0bc1d466a79eba0602ef46b07c56 \ No newline at end of file +fbc446daac761dd1b66a85c9b61e1d5af194a8fd665600c43a874da38cc6ec10 \ No newline at end of file diff --git a/src/resolve.c b/src/resolve.c index 6a1d82606a..898c78654c 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -528,7 +528,8 @@ static int lookupName( if( pParse->bReturning ){ if( (pNC->ncFlags & NC_UBaseReg)!=0 && ALWAYS(zTab==0 - || sqlite3StrICmp(zTab,pParse->pTriggerTab->zName)==0) + || sqlite3StrICmp(zTab,pParse->pTriggerTab->zName)==0 + || isValidSchemaTableName(zTab, pParse->pTriggerTab, 0)) ){ pExpr->iTable = op!=TK_DELETE; pTab = pParse->pTriggerTab; diff --git a/test/returning1.test b/test/returning1.test index 8a2001de93..05bd445a2f 100644 --- a/test/returning1.test +++ b/test/returning1.test @@ -520,4 +520,15 @@ do_execsql_test 20.3 { 8 N N N } +#------------------------------------------------------------------------- +reset_db +do_execsql_test 21.0 { + PRAGMA writable_schema=ON; + INSERT INTO sqlite_schema DEFAULT VALUES RETURNING sqlite_schema.name; +} {{}} + +do_execsql_test 21.1 { + INSERT INTO sqlite_temp_schema DEFAULT VALUES RETURNING sqlite_temp_schema.name; +} {{}} + finish_test From 9c0d777a9f4a84f09b6145b74184a38a3abd7db0 Mon Sep 17 00:00:00 2001 From: dan Date: Thu, 2 May 2024 19:22:23 +0000 Subject: [PATCH 368/430] Fix a problem with queries that use "IN(...) ORDER BY ... NULLS LAST" or similar introduced by [d7648e21605a0b38]. FossilOrigin-Name: 26b2d9390f1273ee0e3f3c96f6bc5bf0e9c1dcfd0d9ecd993dba487ef5a07f7e --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/wherecode.c | 2 +- test/in7.test | 13 +++++++++++++ 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index f3c1c280fd..a0040a7b29 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Avoid\san\sassert\sfailure\saccessible\sonly\swhen\sinternal\stesting\sfeatures\sare\senabled.\sdbsqlfuzz\scrash-66abacda6bca6bd531e25595e8c8068e2c710326.txt. -D 2024-05-02T18:16:23.502 +C Fix\sa\sproblem\swith\squeries\sthat\suse\s"IN(...)\sORDER\sBY\s...\sNULLS\sLAST"\sor\ssimilar\sintroduced\sby\s[d7648e21605a0b38]. +D 2024-05-02T19:22:23.368 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -839,7 +839,7 @@ F src/wal.h ba252daaa94f889f4b2c17c027e823d9be47ce39da1d3799886bbd51f0490452 F src/walker.c 7c7ea0115345851c3da4e04e2e239a29983b61fb5b038b94eede6aba462640e2 F src/where.c 0ef9638651b900d64d7e1e877af37cd7900159ff875547ec29b918a1497e5c9c F src/whereInt.h 82a13766f13d1a53b05387c2e60726289ef26404bc7b9b1f7770204d97357fb8 -F src/wherecode.c b73b5bcd0840491e8faa126fbf933e3bda0d9bf85222ddc7ff608154f0f86d1e +F src/wherecode.c b9908c0a1aab095822a1e7032556bedc03b6d29641191e9ca535fb2307cd733d F src/whereexpr.c 67d15caf88a1a9528283d68ff578e024cf9fe810b517bb0343e5aaf695ad97dd F src/window.c 5d95122dd330bfaebd732358c8ef067c5a9394a53ac249470d611d0ce2c52be2 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 @@ -1279,7 +1279,7 @@ F test/in3.test 3cbf58c87f4052cee3a58b37b6389777505aa0c0 F test/in4.test bb767ec1cfd1730256f0a83219f0acda36bc251b63f8b8bb7d8c7cff17875a4f F test/in5.test 4fd79c70dfa0681313e8cdca07f5ff0400bdc0e20f808a5c59eaef1e4b48082a F test/in6.test f5f40d6816a8bb7c784424b58a10ac38efb76ab29127a2c17399e0cbeeda0e4b -F test/in7.test e0b3bd735c13547f038f386440152ad2642a066e9f96366552763bb5455117d0 +F test/in7.test b3a87d5e4f608ac9787e707fc4f8f2a0d89359489d109fdcac01470c3a6832f4 F test/incrblob.test c9b96afc292aeff43d6687bcb09b0280aa599822 F test/incrblob2.test a494c9e848560039a23974b9119cfc2cf3ad3bd15cc2694ee6367ae537ef8f1f F test/incrblob3.test 67621a04b3084113bf38ce03797d70eca012d9d8f948193b8f655df577b0da6f @@ -2188,8 +2188,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 8519b4d0393ed17eed06bceffbc891fe8cae0bc1d466a79eba0602ef46b07c56 -R 0a3b026a0a16d38bbb74d5089bed24b2 +P fbc446daac761dd1b66a85c9b61e1d5af194a8fd665600c43a874da38cc6ec10 +R 36f998b45a8aa5d9ecb00ca50d9b4f7d U dan -Z ae138bbd9a4a27c1543b292e5b8d0d96 +Z b095a9ec23cb25cb4e9e06b89cd38b3b # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 9a2c0a20d2..91bc583d15 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -fbc446daac761dd1b66a85c9b61e1d5af194a8fd665600c43a874da38cc6ec10 \ No newline at end of file +26b2d9390f1273ee0e3f3c96f6bc5bf0e9c1dcfd0d9ecd993dba487ef5a07f7e \ No newline at end of file diff --git a/src/wherecode.c b/src/wherecode.c index a895d3935b..4aca6eb624 100644 --- a/src/wherecode.c +++ b/src/wherecode.c @@ -2106,7 +2106,7 @@ Bitmask sqlite3WhereCodeOneLoopStart( /* Record the instruction used to terminate the loop. */ if( (pLoop->wsFlags & WHERE_ONEROW) - || (pLevel->u.in.nIn && whereLoopIsOneRow(pLoop)) + || (pLevel->u.in.nIn && regBignull==0 && whereLoopIsOneRow(pLoop)) ){ pLevel->op = OP_Noop; }else if( bRev ){ diff --git a/test/in7.test b/test/in7.test index 8917d4432f..cf17933a39 100644 --- a/test/in7.test +++ b/test/in7.test @@ -103,5 +103,18 @@ foreach {tn nNext idx sql} { } $nNext } +#------------------------------------------------------------------------- +reset_db +do_execsql_test 2.0 { + CREATE TABLE t1(a TEXT PRIMARY KEY, b TEXT) WITHOUT ROWID; + INSERT INTO t1 VALUES('1', 'one'); + INSERT INTO t1 VALUES('2', NULL); + INSERT INTO t1 VALUES('3', 'three'); +} + +do_execsql_test 2.1 { + SELECT b FROM t1 WHERE a IN (1,2,3) ORDER BY b ASC NULLS LAST; +} {one three {}} + finish_test From 0901571f0a66a2528c3fc6986b44d7a0323e36a1 Mon Sep 17 00:00:00 2001 From: drh <> Date: Fri, 3 May 2024 19:35:43 +0000 Subject: [PATCH 369/430] The coalesce(), ifnull(), and iif() functions pass through subtype values from their arguments, and hence need to have the SQLITE_RESULT_SUBTYPE flag set. This fixes an corner-case for the patch at [ba789a7804ab96d8]. FossilOrigin-Name: cdd1610c44876623e629bb8e5779ea689e6d23c545552b088eca63ad2d1cf8da --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/func.c | 6 +++--- test/indexexpr1.test | 28 ++++++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 12 deletions(-) diff --git a/manifest b/manifest index a0040a7b29..1ed79f3c89 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sproblem\swith\squeries\sthat\suse\s"IN(...)\sORDER\sBY\s...\sNULLS\sLAST"\sor\ssimilar\sintroduced\sby\s[d7648e21605a0b38]. -D 2024-05-02T19:22:23.368 +C The\scoalesce(),\sifnull(),\sand\siif()\sfunctions\spass\sthrough\ssubtype\svalues\nfrom\stheir\sarguments,\sand\shence\sneed\sto\shave\sthe\sSQLITE_RESULT_SUBTYPE\sflag\nset.\s\sThis\sfixes\san\scorner-case\sfor\sthe\spatch\sat\s[ba789a7804ab96d8]. +D 2024-05-03T19:35:43.156 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -705,7 +705,7 @@ F src/delete.c cb766727c78e715f9fb7ec8a7d03658ed2a3016343ca687acfcec9083cdca500 F src/expr.c 005bf7a088a2fb12a50752a2a1d40d423b8942e1920e93c3a1ba76da0bfbe52b F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c a47610f0a5c6cb0ad79f8fcef039c01833dec0c751bb695f28dc0ec6a4c3ba00 -F src/func.c 283d4f3b2751a1d9339fd93a8a013d1948fd5f4474a3cab0955eb4fafd445d0f +F src/func.c ac6e03e7f39feced49681a1a67c50a82b43e8573dd7a9278ca4ff291317f2b0d F src/global.c 61a419dd9e993b9be0f91de4c4ccf322b053eb829868e089f0321dd669be3b90 F src/hash.c 9ee4269fb1d6632a6fecfb9479c93a1f29271bddbbaf215dd60420bcb80c7220 F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 @@ -1302,7 +1302,7 @@ F test/index8.test caa097735c91dbc23d8a402f5e63a2a03c83840ba3928733ed7f9a03f8a91 F test/index9.test 2ac891806a4136ef3e91280477e23114e67575207dc331e6797fa0ed9379f997 F test/indexA.test 11d84f6995e6e5b9d8315953fb1b6d29772ee7c7803ee9112715e7e4dd3e4974 F test/indexedby.test f21eca4f7a6ffe14c8500a7ad6cd53166666c99e5ccd311842a28bc94a195fe0 -F test/indexexpr1.test 833f511213a5e26549186813f0566bd72f978177a7e6e98a2d2dd695de3c670d +F test/indexexpr1.test 870ffcf3911ef447e7714d49c4504a92580410ecb0d6d76499493f9a5591efb1 F test/indexexpr2.test 1c382e81ef996d8ae8b834a74f2a9013dddf59214c32201d7c8a656d739f999a F test/indexfault.test 98d78a8ff1f5335628b62f886a1cb7c7dac1ef6d48fa39c51ec871c87dce9811 F test/init.test 15c823093fdabbf7b531fe22cf037134d09587a7 @@ -2188,8 +2188,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P fbc446daac761dd1b66a85c9b61e1d5af194a8fd665600c43a874da38cc6ec10 -R 36f998b45a8aa5d9ecb00ca50d9b4f7d -U dan -Z b095a9ec23cb25cb4e9e06b89cd38b3b +P 26b2d9390f1273ee0e3f3c96f6bc5bf0e9c1dcfd0d9ecd993dba487ef5a07f7e +R 0268c566eccde5bd7b524cfab1a24524 +U drh +Z ad416147806e454b3211249b5d00a37b # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 91bc583d15..b99a890c23 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -26b2d9390f1273ee0e3f3c96f6bc5bf0e9c1dcfd0d9ecd993dba487ef5a07f7e \ No newline at end of file +cdd1610c44876623e629bb8e5779ea689e6d23c545552b088eca63ad2d1cf8da \ No newline at end of file diff --git a/src/func.c b/src/func.c index 18004984d9..472efa2110 100644 --- a/src/func.c +++ b/src/func.c @@ -2643,7 +2643,7 @@ void sqlite3RegisterBuiltinFunctions(void){ FUNCTION(concat_ws, -1, 0, 0, concatwsFunc ), FUNCTION(concat_ws, 0, 0, 0, 0 ), FUNCTION(concat_ws, 1, 0, 0, 0 ), - INLINE_FUNC(ifnull, 2, INLINEFUNC_coalesce, 0 ), + INLINE_FUNC(ifnull, 2, INLINEFUNC_coalesce, SQLITE_RESULT_SUBTYPE), VFUNCTION(random, 0, 0, 0, randomFunc ), VFUNCTION(randomblob, 1, 0, 0, randomBlob ), FUNCTION(nullif, 2, 0, 1, nullifFunc ), @@ -2725,8 +2725,8 @@ void sqlite3RegisterBuiltinFunctions(void){ FUNCTION(pi, 0, 0, 0, piFunc ), #endif /* SQLITE_ENABLE_MATH_FUNCTIONS */ FUNCTION(sign, 1, 0, 0, signFunc ), - INLINE_FUNC(coalesce, -1, INLINEFUNC_coalesce, 0 ), - INLINE_FUNC(iif, 3, INLINEFUNC_iif, 0 ), + INLINE_FUNC(coalesce, -1, INLINEFUNC_coalesce, SQLITE_RESULT_SUBTYPE), + INLINE_FUNC(iif, 3, INLINEFUNC_iif, SQLITE_RESULT_SUBTYPE), }; #ifndef SQLITE_OMIT_ALTERTABLE sqlite3AlterFunctions(); diff --git a/test/indexexpr1.test b/test/indexexpr1.test index 0316ee9d42..e6b3fb6333 100644 --- a/test/indexexpr1.test +++ b/test/indexexpr1.test @@ -615,6 +615,34 @@ do_execsql_test indexexpr1-2200 { GROUP BY t2.type, t1.tag ) v ON v.type = 0 AND v.tag = u.tag; } {7 100 8 101} +do_execsql_test indexexpr1-2210 { + DROP TABLE t1; + CREATE TABLE t1(x INT, y TEXT); + INSERT INTO t1(x,y) VALUES(1,'{b:5}'); + SELECT json_insert('{}', '$.a', coalesce(null,json(y)))->>'$.a.b' FROM t1; +} {5} +db null NULL +do_execsql_test indexexpr1-2211 { + CREATE INDEX t1j ON t1(coalesce(null,json(y))); + SELECT json_insert('{}', '$.a', coalesce(null,json(y)))->>'$.a.b' FROM t1; +} {5} +do_execsql_test indexexpr1-2220 { + DROP INDEX t1j; + SELECT json_insert('{}', '$.a', iif(1,json(y),123))->>'$.a.b' FROM t1; +} {5} +do_execsql_test indexexpr1-2221 { + CREATE INDEX t1j ON t1(iif(1,json(y),123)); + SELECT json_insert('{}', '$.a', iif(1,json(y),123))->>'$.a.b' FROM t1; +} {5} +do_execsql_test indexexpr1-2230 { + DROP INDEX t1j; + SELECT json_insert('{}', '$.a', ifnull(NULL,json(y)))->>'$.a.b' FROM t1; +} {5} +do_execsql_test indexexpr1-2231 { + CREATE INDEX t1j ON t1(ifnull(NULL,json(y))); + SELECT json_insert('{}', '$.a', ifnull(NULL,json(y)))->>'$.a.b' FROM t1; +} {5} + # 2023-11-08 Forum post https://sqlite.org/forum/forumpost/68d284c86b082c3e # From 5b9b7cba227ee0ec1532416637623103bbe43086 Mon Sep 17 00:00:00 2001 From: drh <> Date: Sat, 4 May 2024 11:31:34 +0000 Subject: [PATCH 370/430] Functions that pass through the sqlite3_value of one of their arguments must also be marked as SQLITE_RESULT_SUBTYPE, in case one of their arguments has a subtype. FossilOrigin-Name: 2f9fba931d9f80b3d5dffb175180098756bccc6a8f665d7aaf8826970ab60d72 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/func.c | 7 ++++--- test/indexexpr1.test | 24 ++++++++++++++++++++++++ 4 files changed, 36 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 1ed79f3c89..95c66ec418 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C The\scoalesce(),\sifnull(),\sand\siif()\sfunctions\spass\sthrough\ssubtype\svalues\nfrom\stheir\sarguments,\sand\shence\sneed\sto\shave\sthe\sSQLITE_RESULT_SUBTYPE\sflag\nset.\s\sThis\sfixes\san\scorner-case\sfor\sthe\spatch\sat\s[ba789a7804ab96d8]. -D 2024-05-03T19:35:43.156 +C Functions\sthat\spass\sthrough\sthe\ssqlite3_value\sof\sone\sof\stheir\sarguments\smust\nalso\sbe\smarked\sas\sSQLITE_RESULT_SUBTYPE,\sin\scase\sone\sof\stheir\sarguments\shas\na\ssubtype. +D 2024-05-04T11:31:34.734 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -705,7 +705,7 @@ F src/delete.c cb766727c78e715f9fb7ec8a7d03658ed2a3016343ca687acfcec9083cdca500 F src/expr.c 005bf7a088a2fb12a50752a2a1d40d423b8942e1920e93c3a1ba76da0bfbe52b F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c a47610f0a5c6cb0ad79f8fcef039c01833dec0c751bb695f28dc0ec6a4c3ba00 -F src/func.c ac6e03e7f39feced49681a1a67c50a82b43e8573dd7a9278ca4ff291317f2b0d +F src/func.c ee81e2fd91b93da5cee11f2abc1a197d32f037e00a8084d003a47e49b17a6c21 F src/global.c 61a419dd9e993b9be0f91de4c4ccf322b053eb829868e089f0321dd669be3b90 F src/hash.c 9ee4269fb1d6632a6fecfb9479c93a1f29271bddbbaf215dd60420bcb80c7220 F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 @@ -1302,7 +1302,7 @@ F test/index8.test caa097735c91dbc23d8a402f5e63a2a03c83840ba3928733ed7f9a03f8a91 F test/index9.test 2ac891806a4136ef3e91280477e23114e67575207dc331e6797fa0ed9379f997 F test/indexA.test 11d84f6995e6e5b9d8315953fb1b6d29772ee7c7803ee9112715e7e4dd3e4974 F test/indexedby.test f21eca4f7a6ffe14c8500a7ad6cd53166666c99e5ccd311842a28bc94a195fe0 -F test/indexexpr1.test 870ffcf3911ef447e7714d49c4504a92580410ecb0d6d76499493f9a5591efb1 +F test/indexexpr1.test 24fa85a12da384dd1d56f7b24e593c51a8a54b4c5e2e8bbb9e5fdf1099427faf F test/indexexpr2.test 1c382e81ef996d8ae8b834a74f2a9013dddf59214c32201d7c8a656d739f999a F test/indexfault.test 98d78a8ff1f5335628b62f886a1cb7c7dac1ef6d48fa39c51ec871c87dce9811 F test/init.test 15c823093fdabbf7b531fe22cf037134d09587a7 @@ -2188,8 +2188,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 26b2d9390f1273ee0e3f3c96f6bc5bf0e9c1dcfd0d9ecd993dba487ef5a07f7e -R 0268c566eccde5bd7b524cfab1a24524 +P cdd1610c44876623e629bb8e5779ea689e6d23c545552b088eca63ad2d1cf8da +R 33e55f0c34c1768cb20638651312a57f U drh -Z ad416147806e454b3211249b5d00a37b +Z 72ec691afb693a210c0cb7b3a98963ca # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index b99a890c23..34db1cbfb6 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -cdd1610c44876623e629bb8e5779ea689e6d23c545552b088eca63ad2d1cf8da \ No newline at end of file +2f9fba931d9f80b3d5dffb175180098756bccc6a8f665d7aaf8826970ab60d72 \ No newline at end of file diff --git a/src/func.c b/src/func.c index 472efa2110..3c98ba96f5 100644 --- a/src/func.c +++ b/src/func.c @@ -984,6 +984,7 @@ static void nullifFunc( UNUSED_PARAMETER(NotUsed); if( sqlite3MemCompare(argv[0], argv[1], pColl)!=0 ){ sqlite3_result_value(context, argv[0]); + sqlite3_result_subtype(context, sqlite3_value_subtype(argv[0])); } } @@ -2608,11 +2609,11 @@ void sqlite3RegisterBuiltinFunctions(void){ FUNCTION(rtrim, 2, 2, 0, trimFunc ), FUNCTION(trim, 1, 3, 0, trimFunc ), FUNCTION(trim, 2, 3, 0, trimFunc ), - FUNCTION(min, -1, 0, 1, minmaxFunc ), + FUNCTION2(min, -1, 0, 1, minmaxFunc, SQLITE_RESULT_SUBTYPE), FUNCTION(min, 0, 0, 1, 0 ), WAGGREGATE(min, 1, 0, 1, minmaxStep, minMaxFinalize, minMaxValue, 0, SQLITE_FUNC_MINMAX|SQLITE_FUNC_ANYORDER ), - FUNCTION(max, -1, 1, 1, minmaxFunc ), + FUNCTION2(max, -1, 1, 1, minmaxFunc, SQLITE_RESULT_SUBTYPE), FUNCTION(max, 0, 1, 1, 0 ), WAGGREGATE(max, 1, 1, 1, minmaxStep, minMaxFinalize, minMaxValue, 0, SQLITE_FUNC_MINMAX|SQLITE_FUNC_ANYORDER ), @@ -2646,7 +2647,7 @@ void sqlite3RegisterBuiltinFunctions(void){ INLINE_FUNC(ifnull, 2, INLINEFUNC_coalesce, SQLITE_RESULT_SUBTYPE), VFUNCTION(random, 0, 0, 0, randomFunc ), VFUNCTION(randomblob, 1, 0, 0, randomBlob ), - FUNCTION(nullif, 2, 0, 1, nullifFunc ), + FUNCTION2(nullif, 2, 0, 1, nullifFunc, SQLITE_RESULT_SUBTYPE), DFUNCTION(sqlite_version, 0, 0, 0, versionFunc ), DFUNCTION(sqlite_source_id, 0, 0, 0, sourceidFunc ), FUNCTION(sqlite_log, 2, 0, 0, errlogFunc ), diff --git a/test/indexexpr1.test b/test/indexexpr1.test index e6b3fb6333..3ba59449d5 100644 --- a/test/indexexpr1.test +++ b/test/indexexpr1.test @@ -642,6 +642,30 @@ do_execsql_test indexexpr1-2231 { CREATE INDEX t1j ON t1(ifnull(NULL,json(y))); SELECT json_insert('{}', '$.a', ifnull(NULL,json(y)))->>'$.a.b' FROM t1; } {5} +do_execsql_test indexexpr1-2240 { + DROP INDEX t1j; + SELECT json_insert('{}', '$.a', nullif(json(y),8))->>'$.a.b' FROM t1; +} {5} +do_execsql_test indexexpr1-2241 { + CREATE INDEX t1j ON t1(nullif(json(y),8)); + SELECT json_insert('{}', '$.a', nullif(json(y),8))->>'$.a.b' FROM t1; +} {5} +do_execsql_test indexexpr1-2250 { + DROP INDEX t1j; + SELECT json_insert('{}', '$.a', min('~',json(y)))->>'$.a.b' FROM t1; +} {5} +do_execsql_test indexexpr1-2251 { + CREATE INDEX t1j ON t1(min('~',json(y))); + SELECT json_insert('{}', '$.a', min('~',json(y)))->>'$.a.b' FROM t1; +} {5} +do_execsql_test indexexpr1-2260 { + DROP INDEX t1j; + SELECT json_insert('{}', '$.a', max('...',json(y)))->>'$.a.b' FROM t1; +} {5} +do_execsql_test indexexpr1-2261 { + CREATE INDEX t1j ON t1(max('...',json(y))); + SELECT json_insert('{}', '$.a', max('...',json(y)))->>'$.a.b' FROM t1; +} {5} # 2023-11-08 Forum post https://sqlite.org/forum/forumpost/68d284c86b082c3e From 2eb9adb564ee209e2f0ad38718d621ace1c55c72 Mon Sep 17 00:00:00 2001 From: drh <> Date: Sat, 4 May 2024 15:04:45 +0000 Subject: [PATCH 371/430] Assume that a function is able to return a subtype if either (1) it is itself marked with SQLITE_RESULT_SUBTYPE, or (2) one of its arguments is a function that is able to return a subtype. This check-in backs out the code changes from the previous two on this same branch, but keeps the test cases from the previous two. FossilOrigin-Name: f16b200f25a0ec59ad765d254d81c3ffdba21f79e6e82807a7b80d00627952e2 --- manifest | 14 +++++------ manifest.uuid | 2 +- src/func.c | 13 +++++------ src/where.c | 64 +++++++++++++++++++++++++++++++++++++++++++-------- 4 files changed, 68 insertions(+), 25 deletions(-) diff --git a/manifest b/manifest index 95c66ec418..0f9a114b45 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Functions\sthat\spass\sthrough\sthe\ssqlite3_value\sof\sone\sof\stheir\sarguments\smust\nalso\sbe\smarked\sas\sSQLITE_RESULT_SUBTYPE,\sin\scase\sone\sof\stheir\sarguments\shas\na\ssubtype. -D 2024-05-04T11:31:34.734 +C Assume\sthat\sa\sfunction\sis\sable\sto\sreturn\sa\ssubtype\sif\seither\s(1)\sit\sis\sitself\nmarked\swith\sSQLITE_RESULT_SUBTYPE,\sor\s(2)\sone\sof\sits\sarguments\sis\sa\sfunction\nthat\sis\sable\sto\sreturn\sa\ssubtype.\s\sThis\scheck-in\sbacks\sout\sthe\scode\schanges\nfrom\sthe\sprevious\stwo\son\sthis\ssame\sbranch,\sbut\skeeps\sthe\stest\scases\sfrom\nthe\sprevious\stwo. +D 2024-05-04T15:04:45.707 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -705,7 +705,7 @@ F src/delete.c cb766727c78e715f9fb7ec8a7d03658ed2a3016343ca687acfcec9083cdca500 F src/expr.c 005bf7a088a2fb12a50752a2a1d40d423b8942e1920e93c3a1ba76da0bfbe52b F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c a47610f0a5c6cb0ad79f8fcef039c01833dec0c751bb695f28dc0ec6a4c3ba00 -F src/func.c ee81e2fd91b93da5cee11f2abc1a197d32f037e00a8084d003a47e49b17a6c21 +F src/func.c 283d4f3b2751a1d9339fd93a8a013d1948fd5f4474a3cab0955eb4fafd445d0f F src/global.c 61a419dd9e993b9be0f91de4c4ccf322b053eb829868e089f0321dd669be3b90 F src/hash.c 9ee4269fb1d6632a6fecfb9479c93a1f29271bddbbaf215dd60420bcb80c7220 F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 @@ -837,7 +837,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c 887fc4ca3f020ebb2e376f222069570834ac63bf50111ef0cbf3ae417048ed89 F src/wal.h ba252daaa94f889f4b2c17c027e823d9be47ce39da1d3799886bbd51f0490452 F src/walker.c 7c7ea0115345851c3da4e04e2e239a29983b61fb5b038b94eede6aba462640e2 -F src/where.c 0ef9638651b900d64d7e1e877af37cd7900159ff875547ec29b918a1497e5c9c +F src/where.c d235ba520b0147f60732b3bd411e119b43be33d348251edaa6e304a8ad52c511 F src/whereInt.h 82a13766f13d1a53b05387c2e60726289ef26404bc7b9b1f7770204d97357fb8 F src/wherecode.c b9908c0a1aab095822a1e7032556bedc03b6d29641191e9ca535fb2307cd733d F src/whereexpr.c 67d15caf88a1a9528283d68ff578e024cf9fe810b517bb0343e5aaf695ad97dd @@ -2188,8 +2188,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P cdd1610c44876623e629bb8e5779ea689e6d23c545552b088eca63ad2d1cf8da -R 33e55f0c34c1768cb20638651312a57f +P 2f9fba931d9f80b3d5dffb175180098756bccc6a8f665d7aaf8826970ab60d72 +R 14886039188c50fb101aa25afbe73592 U drh -Z 72ec691afb693a210c0cb7b3a98963ca +Z 80e41ac2288666eefe08d1c7b25daa7c # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 34db1cbfb6..6c653e5a23 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2f9fba931d9f80b3d5dffb175180098756bccc6a8f665d7aaf8826970ab60d72 \ No newline at end of file +f16b200f25a0ec59ad765d254d81c3ffdba21f79e6e82807a7b80d00627952e2 \ No newline at end of file diff --git a/src/func.c b/src/func.c index 3c98ba96f5..18004984d9 100644 --- a/src/func.c +++ b/src/func.c @@ -984,7 +984,6 @@ static void nullifFunc( UNUSED_PARAMETER(NotUsed); if( sqlite3MemCompare(argv[0], argv[1], pColl)!=0 ){ sqlite3_result_value(context, argv[0]); - sqlite3_result_subtype(context, sqlite3_value_subtype(argv[0])); } } @@ -2609,11 +2608,11 @@ void sqlite3RegisterBuiltinFunctions(void){ FUNCTION(rtrim, 2, 2, 0, trimFunc ), FUNCTION(trim, 1, 3, 0, trimFunc ), FUNCTION(trim, 2, 3, 0, trimFunc ), - FUNCTION2(min, -1, 0, 1, minmaxFunc, SQLITE_RESULT_SUBTYPE), + FUNCTION(min, -1, 0, 1, minmaxFunc ), FUNCTION(min, 0, 0, 1, 0 ), WAGGREGATE(min, 1, 0, 1, minmaxStep, minMaxFinalize, minMaxValue, 0, SQLITE_FUNC_MINMAX|SQLITE_FUNC_ANYORDER ), - FUNCTION2(max, -1, 1, 1, minmaxFunc, SQLITE_RESULT_SUBTYPE), + FUNCTION(max, -1, 1, 1, minmaxFunc ), FUNCTION(max, 0, 1, 1, 0 ), WAGGREGATE(max, 1, 1, 1, minmaxStep, minMaxFinalize, minMaxValue, 0, SQLITE_FUNC_MINMAX|SQLITE_FUNC_ANYORDER ), @@ -2644,10 +2643,10 @@ void sqlite3RegisterBuiltinFunctions(void){ FUNCTION(concat_ws, -1, 0, 0, concatwsFunc ), FUNCTION(concat_ws, 0, 0, 0, 0 ), FUNCTION(concat_ws, 1, 0, 0, 0 ), - INLINE_FUNC(ifnull, 2, INLINEFUNC_coalesce, SQLITE_RESULT_SUBTYPE), + INLINE_FUNC(ifnull, 2, INLINEFUNC_coalesce, 0 ), VFUNCTION(random, 0, 0, 0, randomFunc ), VFUNCTION(randomblob, 1, 0, 0, randomBlob ), - FUNCTION2(nullif, 2, 0, 1, nullifFunc, SQLITE_RESULT_SUBTYPE), + FUNCTION(nullif, 2, 0, 1, nullifFunc ), DFUNCTION(sqlite_version, 0, 0, 0, versionFunc ), DFUNCTION(sqlite_source_id, 0, 0, 0, sourceidFunc ), FUNCTION(sqlite_log, 2, 0, 0, errlogFunc ), @@ -2726,8 +2725,8 @@ void sqlite3RegisterBuiltinFunctions(void){ FUNCTION(pi, 0, 0, 0, piFunc ), #endif /* SQLITE_ENABLE_MATH_FUNCTIONS */ FUNCTION(sign, 1, 0, 0, signFunc ), - INLINE_FUNC(coalesce, -1, INLINEFUNC_coalesce, SQLITE_RESULT_SUBTYPE), - INLINE_FUNC(iif, 3, INLINEFUNC_iif, SQLITE_RESULT_SUBTYPE), + INLINE_FUNC(coalesce, -1, INLINEFUNC_coalesce, 0 ), + INLINE_FUNC(iif, 3, INLINEFUNC_iif, 0 ), }; #ifndef SQLITE_OMIT_ALTERTABLE sqlite3AlterFunctions(); diff --git a/src/where.c b/src/where.c index 820e922490..13a362dcca 100644 --- a/src/where.c +++ b/src/where.c @@ -5989,6 +5989,58 @@ static SQLITE_NOINLINE void whereCheckIfBloomFilterIsUseful( } } +/* +** Expression Node callback for sqlite3ExprCanReturnSubtype(). +** +** Only a function call is able to return a subtype. So if the node +** is not a function call, return WRC_Prune immediately. +** +** A function call is able to return a subtype if it has the +** SQLITE_RESULT_SUBTYPE property. +** +** Assume that every function is able to pass-through a subtype from +** one of its argument (using sqlite3_result_value()). Most functions +** are not this way, but we don't have a mechanism to distinguish those +** that are from those that are not, so assume they all work this way. +** That means that if one of its arguments is another function and that +** other function is able to return a subtype, then this function is +** able to return a subtype. +*/ +static int exprNodeCanReturnSubtype(Walker *pWalker, Expr *pExpr){ + int n; + FuncDef *pDef; + sqlite3 *db; + if( pExpr->op!=TK_FUNCTION ){ + return WRC_Prune; + } + assert( ExprUseXList(pExpr) ); + db = pWalker->pParse->db; + n = pExpr->x.pList ? pExpr->x.pList->nExpr : 0; + pDef = sqlite3FindFunction(db, pExpr->u.zToken, n, ENC(db), 0); + if( pDef==0 || (pDef->funcFlags & SQLITE_RESULT_SUBTYPE)!=0 ){ + pWalker->eCode = 1; + return WRC_Prune; + } + return WRC_Continue; +} + +/* +** Return TRUE if expression pExpr is able to return a subtype. +** +** A TRUE return does not guarantee that a subtype will be returned. +** It only indicates that a subtype return is possible. False positives +** are acceptable as they only disable an optimization. False negatives, +** on the other hand, can lead to incorrect answers. +*/ +static int sqlite3ExprCanReturnSubtype(Parse *pParse, Expr *pExpr){ + Walker w; + memset(&w, 0, sizeof(w)); + w.pParse = pParse; + w.xExprCallback = exprNodeCanReturnSubtype; + sqlite3WalkExpr(&w, pExpr); + return w.eCode; +} + /* ** The index pIdx is used by a query and contains one or more expressions. ** In other words pIdx is an index on an expression. iIdxCur is the cursor @@ -6022,19 +6074,11 @@ static SQLITE_NOINLINE void whereAddIndexedExpr( continue; } if( sqlite3ExprIsConstant(0,pExpr) ) continue; - if( pExpr->op==TK_FUNCTION ){ + if( pExpr->op==TK_FUNCTION && sqlite3ExprCanReturnSubtype(pParse,pExpr) ){ /* Functions that might set a subtype should not be replaced by the ** value taken from an expression index since the index omits the ** subtype. https://sqlite.org/forum/forumpost/68d284c86b082c3e */ - int n; - FuncDef *pDef; - sqlite3 *db = pParse->db; - assert( ExprUseXList(pExpr) ); - n = pExpr->x.pList ? pExpr->x.pList->nExpr : 0; - pDef = sqlite3FindFunction(db, pExpr->u.zToken, n, ENC(db), 0); - if( pDef==0 || (pDef->funcFlags & SQLITE_RESULT_SUBTYPE)!=0 ){ - continue; - } + continue; } p = sqlite3DbMallocRaw(pParse->db, sizeof(IndexedExpr)); if( p==0 ) break; From c52c00f67095b4ca7c21b2215e607c5119cecb24 Mon Sep 17 00:00:00 2001 From: dan Date: Sat, 4 May 2024 16:50:47 +0000 Subject: [PATCH 372/430] Add test cases to test/in7.test. No code changes. FossilOrigin-Name: 8c3086f9fe502dfc4a1fa610a23794fb037721df29dc5d2126cfb749a9d44a50 --- manifest | 15 +++++++-------- manifest.uuid | 2 +- test/in7.test | 21 +++++++++++++++++++++ 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index edb0851ed9..6d144c0637 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Assume\sthat\san\sSQL\sfunction\sis\sable\sto\sreturn\sa\ssubtype\sif\sany\sof\sits\narguments\sare\sSQL\sfunctions\sthat\sare\sable\sto\sreturn\ssubtypes.\s\sThis\scloses\na\scorner-case\shole\sin\sthe\spatch\sat\s[ba789a7804ab96d8]. -D 2024-05-04T15:10:37.959 +C Add\stest\scases\sto\stest/in7.test.\sNo\scode\schanges. +D 2024-05-04T16:50:47.770 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -1279,7 +1279,7 @@ F test/in3.test 3cbf58c87f4052cee3a58b37b6389777505aa0c0 F test/in4.test bb767ec1cfd1730256f0a83219f0acda36bc251b63f8b8bb7d8c7cff17875a4f F test/in5.test 4fd79c70dfa0681313e8cdca07f5ff0400bdc0e20f808a5c59eaef1e4b48082a F test/in6.test f5f40d6816a8bb7c784424b58a10ac38efb76ab29127a2c17399e0cbeeda0e4b -F test/in7.test b3a87d5e4f608ac9787e707fc4f8f2a0d89359489d109fdcac01470c3a6832f4 +F test/in7.test 742b18c284cd9a9cd1347d3a8affeee44b8de11e875e91a1d40498c18ba16441 F test/incrblob.test c9b96afc292aeff43d6687bcb09b0280aa599822 F test/incrblob2.test a494c9e848560039a23974b9119cfc2cf3ad3bd15cc2694ee6367ae537ef8f1f F test/incrblob3.test 67621a04b3084113bf38ce03797d70eca012d9d8f948193b8f655df577b0da6f @@ -2188,9 +2188,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 26b2d9390f1273ee0e3f3c96f6bc5bf0e9c1dcfd0d9ecd993dba487ef5a07f7e f16b200f25a0ec59ad765d254d81c3ffdba21f79e6e82807a7b80d00627952e2 -R 14886039188c50fb101aa25afbe73592 -T +closed f16b200f25a0ec59ad765d254d81c3ffdba21f79e6e82807a7b80d00627952e2 -U drh -Z 1c69cc89e2338f86c36480d46824bedd +P b36d499e4cdb41a5d7e44a1c4347a059d7654f85ade9c5c04d18ac95ddc09fde +R 960c98e5734bcdd93c02bad4a02cdc67 +U dan +Z a883d658d4cc670b0c73f4c6321f0eb9 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 114badcf32..2b94ecb6ca 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b36d499e4cdb41a5d7e44a1c4347a059d7654f85ade9c5c04d18ac95ddc09fde \ No newline at end of file +8c3086f9fe502dfc4a1fa610a23794fb037721df29dc5d2126cfb749a9d44a50 \ No newline at end of file diff --git a/test/in7.test b/test/in7.test index cf17933a39..099f75c5f7 100644 --- a/test/in7.test +++ b/test/in7.test @@ -71,6 +71,27 @@ foreach {tn nNext idx sql} { } { SELECT * FROM t1 WHERE a IN (SELECT z FROM t2) } + + 9 1 { + CREATE UNIQUE INDEX i1 ON t1(a, b); + } { + SELECT * FROM t1 WHERE a IN (SELECT z FROM t2) AND b IS ? + } + 10 0 { + CREATE UNIQUE INDEX i1 ON t1(a, b); + } { + SELECT * FROM t1 WHERE a IN (SELECT z FROM t2) AND b = ? + } + 11 1 { + CREATE UNIQUE INDEX i1 ON t1(a, b); + } { + SELECT * FROM t1 WHERE a IS NULL AND b IN (SELECT z FROM t2) + } + 12 0 { + CREATE UNIQUE INDEX i1 ON t1(a, b); + } { + SELECT * FROM t1 WHERE a = ? AND b IN (SELECT z FROM t2) + } } { do_test 1.1.$tn { execsql BEGIN From 5b80dbe6b37fd246d6b29df6182d726655057dc1 Mon Sep 17 00:00:00 2001 From: dan Date: Sat, 4 May 2024 21:10:24 +0000 Subject: [PATCH 373/430] Add new sessions API sqlite3changegroup_add_change(). FossilOrigin-Name: 73647db1ddfdaf40cbf18f1e47c10b4a906489f6d34d7667f0f2ff532f1eb37c --- ext/session/sqlite3session.c | 251 +++++++++++++++++++++-------------- ext/session/sqlite3session.h | 19 +++ ext/session/test_session.c | 66 +++++++++ manifest | 19 +-- manifest.uuid | 2 +- 5 files changed, 252 insertions(+), 105 deletions(-) diff --git a/ext/session/sqlite3session.c b/ext/session/sqlite3session.c index acb945194d..e6081a6ce0 100644 --- a/ext/session/sqlite3session.c +++ b/ext/session/sqlite3session.c @@ -3685,14 +3685,14 @@ static int sessionChangesetNextOne( p->rc = sessionInputBuffer(&p->in, 2); if( p->rc!=SQLITE_OK ) return p->rc; + sessionDiscardData(&p->in); + p->in.iCurrent = p->in.iNext; + /* If the iterator is already at the end of the changeset, return DONE. */ if( p->in.iNext>=p->in.nData ){ return SQLITE_DONE; } - sessionDiscardData(&p->in); - p->in.iCurrent = p->in.iNext; - op = p->in.aData[p->in.iNext++]; while( op=='T' || op=='P' ){ if( pbNew ) *pbNew = 1; @@ -5427,6 +5427,7 @@ struct sqlite3_changegroup { int rc; /* Error code */ int bPatch; /* True to accumulate patchsets */ SessionTable *pList; /* List of tables in current patch */ + SessionBuffer rec; sqlite3 *db; /* Configured by changegroup_schema() */ char *zDb; /* Configured by changegroup_schema() */ @@ -5725,108 +5726,128 @@ static int sessionChangesetExtendRecord( } /* -** Add all changes in the changeset traversed by the iterator passed as -** the first argument to the changegroup hash tables. +** Locate or create a SessionTable object that may be used to add the +** change currently pointed to by iterator pIter to changegroup pGrp. +** If successful, set output variable (*ppTab) to point to the table +** object and return SQLITE_OK. Otherwise, if some error occurs, return +** an SQLite error code and leave (*ppTab) set to NULL. */ -static int sessionChangesetToHash( - sqlite3_changeset_iter *pIter, /* Iterator to read from */ - sqlite3_changegroup *pGrp, /* Changegroup object to add changeset to */ - int bRebase /* True if hash table is for rebasing */ +static int sessionChangesetFindTable( + sqlite3_changegroup *pGrp, + const char *zTab, + sqlite3_changeset_iter *pIter, + SessionTable **ppTab ){ - u8 *aRec; - int nRec; int rc = SQLITE_OK; SessionTable *pTab = 0; - SessionBuffer rec = {0, 0, 0}; + int nTab = (int)strlen(zTab); + u8 *abPK = 0; + int nCol = 0; - while( SQLITE_ROW==sessionChangesetNext(pIter, &aRec, &nRec, 0) ){ - const char *zNew; - int nCol; - int op; - int iHash; - int bIndirect; - SessionChange *pChange; - SessionChange *pExist = 0; - SessionChange **pp; - - /* Ensure that only changesets, or only patchsets, but not a mixture - ** of both, are being combined. It is an error to try to combine a - ** changeset and a patchset. */ - if( pGrp->pList==0 ){ - pGrp->bPatch = pIter->bPatchset; - }else if( pIter->bPatchset!=pGrp->bPatch ){ - rc = SQLITE_ERROR; - break; - } + *ppTab = 0; + sqlite3changeset_pk(pIter, &abPK, &nCol); - sqlite3changeset_op(pIter, &zNew, &nCol, &op, &bIndirect); - if( !pTab || sqlite3_stricmp(zNew, pTab->zName) ){ - /* Search the list for a matching table */ - int nNew = (int)strlen(zNew); - u8 *abPK; + /* Search the list for an existing table */ + for(pTab = pGrp->pList; pTab; pTab=pTab->pNext){ + if( 0==sqlite3_strnicmp(pTab->zName, zTab, nTab+1) ) break; + } - sqlite3changeset_pk(pIter, &abPK, 0); - for(pTab = pGrp->pList; pTab; pTab=pTab->pNext){ - if( 0==sqlite3_strnicmp(pTab->zName, zNew, nNew+1) ) break; + /* If one was not found above, create a new table now */ + if( !pTab ){ + SessionTable **ppNew; + + pTab = sqlite3_malloc64(sizeof(SessionTable) + nCol + nTab+1); + if( !pTab ){ + return SQLITE_NOMEM; + } + memset(pTab, 0, sizeof(SessionTable)); + pTab->nCol = nCol; + pTab->abPK = (u8*)&pTab[1]; + memcpy(pTab->abPK, abPK, nCol); + pTab->zName = (char*)&pTab->abPK[nCol]; + memcpy(pTab->zName, zTab, nTab+1); + + if( pGrp->db ){ + pTab->nCol = 0; + rc = sessionInitTable(0, pTab, pGrp->db, pGrp->zDb); + if( rc ){ + assert( pTab->azCol==0 ); + sqlite3_free(pTab); + return rc; } - if( !pTab ){ - SessionTable **ppTab; + } - pTab = sqlite3_malloc64(sizeof(SessionTable) + nCol + nNew+1); - if( !pTab ){ - rc = SQLITE_NOMEM; - break; - } - memset(pTab, 0, sizeof(SessionTable)); - pTab->nCol = nCol; - pTab->abPK = (u8*)&pTab[1]; - memcpy(pTab->abPK, abPK, nCol); - pTab->zName = (char*)&pTab->abPK[nCol]; - memcpy(pTab->zName, zNew, nNew+1); - - if( pGrp->db ){ - pTab->nCol = 0; - rc = sessionInitTable(0, pTab, pGrp->db, pGrp->zDb); - if( rc ){ - assert( pTab->azCol==0 ); - sqlite3_free(pTab); - break; - } - } + /* The new object must be linked on to the end of the list, not + ** simply added to the start of it. This is to ensure that the + ** tables within the output of sqlite3changegroup_output() are in + ** the right order. */ + for(ppNew=&pGrp->pList; *ppNew; ppNew=&(*ppNew)->pNext); + *ppNew = pTab; + } - /* The new object must be linked on to the end of the list, not - ** simply added to the start of it. This is to ensure that the - ** tables within the output of sqlite3changegroup_output() are in - ** the right order. */ - for(ppTab=&pGrp->pList; *ppTab; ppTab=&(*ppTab)->pNext); - *ppTab = pTab; - } + /* Check that the table is compatible. */ + if( !sessionChangesetCheckCompat(pTab, nCol, abPK) ){ + rc = SQLITE_SCHEMA; + } - if( !sessionChangesetCheckCompat(pTab, nCol, abPK) ){ - rc = SQLITE_SCHEMA; - break; - } - } + *ppTab = pTab; + return rc; +} - if( nColnCol ){ - assert( pGrp->db ); - rc = sessionChangesetExtendRecord(pGrp, pTab, nCol, op, aRec, nRec, &rec); - if( rc ) break; - aRec = rec.aBuf; - nRec = rec.nBuf; - } +/* +** Add the change currently indicated by iterator pIter to the hash table +** belonging to changegroup pGrp. +*/ +static int sessionOneChangeToHash( + sqlite3_changegroup *pGrp, + sqlite3_changeset_iter *pIter, + int bRebase +){ + int rc = SQLITE_OK; + int nCol = 0; + int op = 0; + int iHash = 0; + int bIndirect = 0; + SessionChange *pChange = 0; + SessionChange *pExist = 0; + SessionChange **pp = 0; + SessionTable *pTab = 0; + u8 *aRec = &pIter->in.aData[pIter->in.iCurrent + 2]; + int nRec = (pIter->in.iNext - pIter->in.iCurrent) - 2; - if( sessionGrowHash(0, pIter->bPatchset, pTab) ){ - rc = SQLITE_NOMEM; - break; - } + /* Ensure that only changesets, or only patchsets, but not a mixture + ** of both, are being combined. It is an error to try to combine a + ** changeset and a patchset. */ + if( pGrp->pList==0 ){ + pGrp->bPatch = pIter->bPatchset; + }else if( pIter->bPatchset!=pGrp->bPatch ){ + rc = SQLITE_ERROR; + } + + if( rc==SQLITE_OK ){ + const char *zTab = 0; + sqlite3changeset_op(pIter, &zTab, &nCol, &op, &bIndirect); + rc = sessionChangesetFindTable(pGrp, zTab, pIter, &pTab); + } + + if( rc==SQLITE_OK && nColnCol ){ + SessionBuffer *pBuf = &pGrp->rec; + rc = sessionChangesetExtendRecord(pGrp, pTab, nCol, op, aRec, nRec, pBuf); + aRec = pBuf->aBuf; + nRec = pBuf->nBuf; + assert( pGrp->db ); + } + + if( rc==SQLITE_OK && sessionGrowHash(0, pIter->bPatchset, pTab) ){ + rc = SQLITE_NOMEM; + } + + if( rc==SQLITE_OK ){ + /* Search for existing entry. If found, remove it from the hash table. + ** Code below may link it back in. */ iHash = sessionChangeHash( pTab, (pIter->bPatchset && op==SQLITE_DELETE), aRec, pTab->nChange ); - - /* Search for existing entry. If found, remove it from the hash table. - ** Code below may link it back in. - */ for(pp=&pTab->apChange[iHash]; *pp; pp=&(*pp)->pNext){ int bPkOnly1 = 0; int bPkOnly2 = 0; @@ -5841,19 +5862,41 @@ static int sessionChangesetToHash( break; } } + } + if( rc==SQLITE_OK ){ rc = sessionChangeMerge(pTab, bRebase, pIter->bPatchset, pExist, op, bIndirect, aRec, nRec, &pChange ); - if( rc ) break; - if( pChange ){ - pChange->pNext = pTab->apChange[iHash]; - pTab->apChange[iHash] = pChange; - pTab->nEntry++; - } + } + if( rc==SQLITE_OK && pChange ){ + pChange->pNext = pTab->apChange[iHash]; + pTab->apChange[iHash] = pChange; + pTab->nEntry++; + } + + if( rc==SQLITE_OK ) rc = pIter->rc; + return rc; +} + +/* +** Add all changes in the changeset traversed by the iterator passed as +** the first argument to the changegroup hash tables. +*/ +static int sessionChangesetToHash( + sqlite3_changeset_iter *pIter, /* Iterator to read from */ + sqlite3_changegroup *pGrp, /* Changegroup object to add changeset to */ + int bRebase /* True if hash table is for rebasing */ +){ + u8 *aRec; + int nRec; + int rc = SQLITE_OK; + + while( SQLITE_ROW==(sessionChangesetNext(pIter, &aRec, &nRec, 0)) ){ + rc = sessionOneChangeToHash(pGrp, pIter, bRebase); + if( rc!=SQLITE_OK ) break; } - sqlite3_free(rec.aBuf); if( rc==SQLITE_OK ) rc = pIter->rc; return rc; } @@ -5981,6 +6024,20 @@ int sqlite3changegroup_add(sqlite3_changegroup *pGrp, int nData, void *pData){ return rc; } +/* +** Add a single change to a changeset-group. +*/ +int sqlite3changegroup_add_change( + sqlite3_changegroup *pGrp, + sqlite3_changeset_iter *pIter +){ + if( pIter->in.iCurrent==pIter->in.iNext || pIter->rc!=SQLITE_OK ){ + /* Iterator does not point to any valid entry. */ + return SQLITE_ERROR; + } + return sessionChangesetToHash(pIter, pGrp, 0); +} + /* ** Obtain a buffer containing a changeset representing the concatenation ** of all changesets added to the group so far. @@ -6030,6 +6087,7 @@ void sqlite3changegroup_delete(sqlite3_changegroup *pGrp){ if( pGrp ){ sqlite3_free(pGrp->zDb); sessionDeleteTable(0, pGrp->pList); + sqlite3_free(pGrp->rec.aBuf); sqlite3_free(pGrp); } } @@ -6431,6 +6489,7 @@ int sqlite3rebaser_rebase_strm( void sqlite3rebaser_delete(sqlite3_rebaser *p){ if( p ){ sessionDeleteTable(0, p->grp.pList); + sqlite3_free(p->grp.rec.aBuf); sqlite3_free(p); } } diff --git a/ext/session/sqlite3session.h b/ext/session/sqlite3session.h index 160ea8786b..69c8ee588c 100644 --- a/ext/session/sqlite3session.h +++ b/ext/session/sqlite3session.h @@ -1057,6 +1057,25 @@ int sqlite3changegroup_schema(sqlite3_changegroup*, sqlite3*, const char *zDb); */ int sqlite3changegroup_add(sqlite3_changegroup*, int nData, void *pData); +/* +** CAPI3REF: Add A Single Change To A Changegroup +** METHOD: sqlite3_changegroup +** +** This function adds the single change currently indicated by the iterator +** passed as the second argument to the changegroup object. The rules for +** adding the change are just as described for [sqlite3_changegroup_add()]. +** +** The iterator must point to a valid entry when this function is called. +** If it does not, SQLITE_ERROR is returned and no change is added to the +** changegroup. +*/ +int sqlite3changegroup_add_change( + sqlite3_changegroup*, + sqlite3_changeset_iter* +); + + + /* ** CAPI3REF: Obtain A Composite Changeset From A Changegroup ** METHOD: sqlite3_changegroup diff --git a/ext/session/test_session.c b/ext/session/test_session.c index af42351ba7..f6db38c8a2 100644 --- a/ext/session/test_session.c +++ b/ext/session/test_session.c @@ -1585,6 +1585,71 @@ static int SQLITE_TCLAPI test_sqlite3changegroup( return TCL_OK; } +typedef struct TestChangeIter TestChangeIter; +struct TestChangeIter { + sqlite3_changeset_iter *pIter; +}; + +static int SQLITE_TCLAPI test_iter_cmd( + void * clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *CONST objv[] +){ + return TCL_OK; +} + +/* +** Tclcmd: sqlite3changeset_start ?-invert? CHANGESET +*/ +static int SQLITE_TCLAPI test_sqlite3changeset_start( + void * clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *CONST objv[] +){ + int isInvert = 0; + void *pChangeset = 0; /* Buffer containing changeset */ + int nChangeset = 0; /* Size of buffer aChangeset in bytes */ + TestChangeIter *pNew = 0; + sqlite3_changeset_iter *pIter = 0; + int flags = 0; + int rc = SQLITE_OK; + + static int iCmd = 1; + char zCmd[64]; + + if( objc==3 ){ + int n = 0; + const char *z = Tcl_GetStringFromObj(objv[1], &n); + isInvert = (n>=2 && sqlite3_strnicmp(z, "-invert", n)==0); + } + + if( objc!=2 && (objc!=3 || !isInvert) ){ + Tcl_WrongNumArgs(interp, 1, objv, "?-invert? CHANGESET"); + return TCL_ERROR; + } + + flags = isInvert ? SQLITE_CHANGESETSTART_INVERT : 0; + pChangeset = (void *)Tcl_GetByteArrayFromObj(objv[objc-1], &nChangeset); + rc = sqlite3changeset_start_v2(&pIter, nChangeset, pChangeset, flags); + if( rc!=SQLITE_OK ){ + char *zErr = sqlite3_mprintf( + "error in sqlite3changeset_start_v2() - %d", rc + ); + Tcl_AppendResult(interp, zErr, (char*)0); + return TCL_ERROR; + } + + pNew = (TestChangeIter*)ckalloc(sizeof(TestChangeIter)); + pNew->pIter = pIter; + + sprintf(zCmd, "csiter%d", iCmd++); + Tcl_CreateObjCommand(interp, zCmd, test_iter_cmd, (void*)pNew, 0); + Tcl_SetObjResult(interp, Tcl_NewStringObj(zCmd, -1)); + return TCL_OK; +} + int TestSession_Init(Tcl_Interp *interp){ struct Cmd { const char *zCmd; @@ -1592,6 +1657,7 @@ int TestSession_Init(Tcl_Interp *interp){ } aCmd[] = { { "sqlite3session", test_sqlite3session }, { "sqlite3changegroup", test_sqlite3changegroup }, + { "sqlite3changeset_start", test_sqlite3changeset_start }, { "sqlite3session_foreach", test_sqlite3session_foreach }, { "sqlite3changeset_invert", test_sqlite3changeset_invert }, { "sqlite3changeset_concat", test_sqlite3changeset_concat }, diff --git a/manifest b/manifest index 6d144c0637..e95fd9eb1b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\stest\scases\sto\stest/in7.test.\sNo\scode\schanges. -D 2024-05-04T16:50:47.770 +C Add\snew\ssessions\sAPI\ssqlite3changegroup_add_change(). +D 2024-05-04T21:10:24.120 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -582,9 +582,9 @@ F ext/session/sessionrowid.test 85187c2f1b38861a5844868126f69f9ec62223a03449a98a F ext/session/sessionsize.test 8fcf4685993c3dbaa46a24183940ab9f5aa9ed0d23e5fb63bfffbdb56134b795 F ext/session/sessionstat1.test 5e718d5888c0c49bbb33a7a4f816366db85f59f6a4f97544a806421b85dc2dec F ext/session/sessionwor.test 6fd9a2256442cebde5b2284936ae9e0d54bde692d0f5fd009ecef8511f4cf3fc -F ext/session/sqlite3session.c 829d468f0f3d2710aace56b0116a7ca3f414683ce78e3125ae5e21547a895078 -F ext/session/sqlite3session.h 4cf19a51975746d7cff2fdd74db8b769c570958e1c3639ac150d824ac1553b3e -F ext/session/test_session.c 7b94ad945cd4afe6c73ee935aeb3d44b4446186e1729362af616c7695a5283d9 +F ext/session/sqlite3session.c 0cdf052460fe11fd00a5c3f83b4a7152ed6c72ff7dacd4664c30ce16579748d7 +F ext/session/sqlite3session.h e36392d1087e42f4e691caff23cb99f4e9fc3b8b88ac7504dac3ea30883dc08b +F ext/session/test_session.c ba40d22840f3ed667448e34ab4eaa38e69f62f23af530c0f8f70a64ed92b039b F ext/userauth/sqlite3userauth.h 7f3ea8c4686db8e40b0a0e7a8e0b00fac13aa7a3 F ext/userauth/user-auth.txt ca7e9ee82ca4e1c1744295f8184dd70edfae1992865d26c64303f539eb6c084c F ext/userauth/userauth.c 7f00cded7dcaa5d47f54539b290a43d2e59f4b1eb5f447545fa865f002fc80cb @@ -2188,8 +2188,11 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P b36d499e4cdb41a5d7e44a1c4347a059d7654f85ade9c5c04d18ac95ddc09fde -R 960c98e5734bcdd93c02bad4a02cdc67 +P 8c3086f9fe502dfc4a1fa610a23794fb037721df29dc5d2126cfb749a9d44a50 +R 92b682ff0cdf49829f0c1fddda225a0c +T *branch * changegroup-add-change +T *sym-changegroup-add-change * +T -sym-trunk * U dan -Z a883d658d4cc670b0c73f4c6321f0eb9 +Z d18fc76401ae213ec8fe7cdec8b2f0ce # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 2b94ecb6ca..6e66176619 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8c3086f9fe502dfc4a1fa610a23794fb037721df29dc5d2126cfb749a9d44a50 \ No newline at end of file +73647db1ddfdaf40cbf18f1e47c10b4a906489f6d34d7667f0f2ff532f1eb37c \ No newline at end of file From 1aa94b58213bb39fc7252e04ba867c766460871c Mon Sep 17 00:00:00 2001 From: drh <> Date: Sun, 5 May 2024 10:00:02 +0000 Subject: [PATCH 374/430] Add comment to the test/lemon-test01.y file indicating that it does not work and is for historical reference only. FossilOrigin-Name: 9bdf73a8d4a3b4a72f2882252f9ed29a6f1a26d3f50c071f27455bcf10458c4b --- manifest | 14 +++++++------- manifest.uuid | 2 +- test/lemon-test01.y | 5 +++++ 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 6d144c0637..9cd03f667f 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\stest\scases\sto\stest/in7.test.\sNo\scode\schanges. -D 2024-05-04T16:50:47.770 +C Add\scomment\sto\sthe\stest/lemon-test01.y\sfile\sindicating\sthat\sit\sdoes\snot\swork\nand\sis\sfor\shistorical\sreference\sonly. +D 2024-05-05T10:00:02.569 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -1369,7 +1369,7 @@ F test/keyword1.test 37ef6bba5d2ed5b07ecdd6810571de2956599dff F test/kvtest.c 6e0228409ea7ca0497dad503fbd109badb5e59545d131014b6aaac68b56f484a F test/lastinsert.test 42e948fd6442f07d60acbd15d33fb86473e0ef63 F test/laststmtchanges.test ae613f53819206b3222771828d024154d51db200 -F test/lemon-test01.y 58b764610fd934e189ffbb0bbfa33d171b9cb06019b55bdc04d090d6767e11d7 +F test/lemon-test01.y f6280e3787ff9ab57b12527e814c205e1ba1f25fc7458dd6986e2d3351eee320 F test/like.test 242ee7f5d08a031144c0daf63bbd7e7710c847ccf387a83347e0b61b3aa69526 F test/like2.test d3be15fefee3e02fc88942a9b98f26c5339bbdef7783c90023c092c4955fe3d3 F test/like3.test a76e5938fadbe6d32807284c796bafd869974a961057bc5fc5a28e06de98745c @@ -2188,8 +2188,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P b36d499e4cdb41a5d7e44a1c4347a059d7654f85ade9c5c04d18ac95ddc09fde -R 960c98e5734bcdd93c02bad4a02cdc67 -U dan -Z a883d658d4cc670b0c73f4c6321f0eb9 +P 8c3086f9fe502dfc4a1fa610a23794fb037721df29dc5d2126cfb749a9d44a50 +R efcb64168ddc99770223ec8b44cbaf4e +U drh +Z 71bad1f699deb7358af8858b2f47ba10 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 2b94ecb6ca..066dbed864 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8c3086f9fe502dfc4a1fa610a23794fb037721df29dc5d2126cfb749a9d44a50 \ No newline at end of file +9bdf73a8d4a3b4a72f2882252f9ed29a6f1a26d3f50c071f27455bcf10458c4b \ No newline at end of file diff --git a/test/lemon-test01.y b/test/lemon-test01.y index 0fd514ff3a..929b00b62c 100644 --- a/test/lemon-test01.y +++ b/test/lemon-test01.y @@ -2,6 +2,11 @@ // // lemon lemon-test01.y && gcc -g lemon-test01.c && ./a.out // +// This testcase was made obsolete by check-in 7cca80808cef192f on +// 2021-08-17 (associated with Forum Thread +// https://sqlite.org/forum/forumpost/bd91fd965c9803c4) and no longer +// works. It is retained for historical reference only. +// %token_prefix TK_ %token_type int %default_type int From 1002bcff43697e6facff465d36d36ca822a8c5a1 Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 6 May 2024 11:27:47 +0000 Subject: [PATCH 375/430] Fix problem in sqlar_uncompress() when being used to extract symbolic links. FossilOrigin-Name: 4d90c3f179a3d7355b6b0202faf56f0be4be56986920576e528208cb84daa4af --- ext/misc/sqlar.c | 7 ++++--- manifest | 14 +++++++------- manifest.uuid | 2 +- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/ext/misc/sqlar.c b/ext/misc/sqlar.c index be079a546a..9f726f0b89 100644 --- a/ext/misc/sqlar.c +++ b/ext/misc/sqlar.c @@ -81,7 +81,7 @@ static void sqlarUncompressFunc( sqlite3_value **argv ){ uLong nData; - uLongf sz; + sqlite3_int64 sz; assert( argc==2 ); sz = sqlite3_value_int(argv[1]); @@ -89,14 +89,15 @@ static void sqlarUncompressFunc( 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); if( pOut==0 ){ sqlite3_result_error_nomem(context); - }else if( Z_OK!=uncompress(pOut, &sz, pData, nData) ){ + }else if( Z_OK!=uncompress(pOut, &szf, pData, nData) ){ sqlite3_result_error(context, "error in uncompress()", -1); }else{ - sqlite3_result_blob(context, pOut, sz, SQLITE_TRANSIENT); + sqlite3_result_blob(context, pOut, szf, SQLITE_TRANSIENT); } sqlite3_free(pOut); } diff --git a/manifest b/manifest index 9cd03f667f..1c056496d9 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\scomment\sto\sthe\stest/lemon-test01.y\sfile\sindicating\sthat\sit\sdoes\snot\swork\nand\sis\sfor\shistorical\sreference\sonly. -D 2024-05-05T10:00:02.569 +C Fix\sproblem\sin\ssqlar_uncompress()\swhen\sbeing\sused\sto\sextract\ssymbolic\slinks. +D 2024-05-06T11:27:47.649 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -416,7 +416,7 @@ F ext/misc/sha1.c 4011aef176616872b2a0d5bccf0ecfb1f7ce3fe5c3d107f3a8e949d8e1e3f0 F ext/misc/shathree.c 543af7ce71d391cd3a9ab6924a6a1124efc63211fd0f2e240dc4b56077ba88ac F ext/misc/showauth.c 732578f0fe4ce42d577e1c86dc89dd14a006ab52 F ext/misc/spellfix.c c0aa7b80d6df45f7da59d912b38752bcac1af53a5766966160e6c5cdd397dbea -F ext/misc/sqlar.c 53e7d48f68d699a24f1a92e68e71eca8b3a9ff991fe9588c2a05bde103c6e7b7 +F ext/misc/sqlar.c a6175790482328171da47095f87608b48a476d4fac78d8a9ff18b03a2454f634 F ext/misc/stmt.c b090086cd6bd6281c21271d38d576eeffe662f0e6b67536352ce32bbaa438321 F ext/misc/templatevtab.c 10f15b165b95423ddef593bc5dcb915ec4eb5e0f1066d585e5435a368b8bc22b F ext/misc/totype.c 75ed9827d19cc3b434fc2aeb60725d4d46e1534373615612a4d1cfdcc3d60922 @@ -2188,8 +2188,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 8c3086f9fe502dfc4a1fa610a23794fb037721df29dc5d2126cfb749a9d44a50 -R efcb64168ddc99770223ec8b44cbaf4e -U drh -Z 71bad1f699deb7358af8858b2f47ba10 +P 9bdf73a8d4a3b4a72f2882252f9ed29a6f1a26d3f50c071f27455bcf10458c4b +R c4e317266c51f659c5ce93f052688c23 +U dan +Z d759657d9ef1cadf5eb299f7ac2ab3b0 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 066dbed864..3cdac355c8 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9bdf73a8d4a3b4a72f2882252f9ed29a6f1a26d3f50c071f27455bcf10458c4b \ No newline at end of file +4d90c3f179a3d7355b6b0202faf56f0be4be56986920576e528208cb84daa4af \ No newline at end of file From 0f78aafec82d913c4d9b8337d77aad5b952df7b4 Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 6 May 2024 17:21:23 +0000 Subject: [PATCH 376/430] Add tests for sqlite3changegroup_add_change(). FossilOrigin-Name: 9d67bedc20c3a59e5488f0eaea6a6611940a9cb63f7cf5e687b061cb5d510943 --- ext/session/sqlite3session.c | 9 +- ext/session/sqlite3session.h | 4 +- ext/session/test_session.c | 200 +++++++++++++++++++++++------------ manifest | 19 ++-- manifest.uuid | 2 +- 5 files changed, 152 insertions(+), 82 deletions(-) diff --git a/ext/session/sqlite3session.c b/ext/session/sqlite3session.c index e6081a6ce0..7a8132bfa6 100644 --- a/ext/session/sqlite3session.c +++ b/ext/session/sqlite3session.c @@ -6031,11 +6031,14 @@ int sqlite3changegroup_add_change( sqlite3_changegroup *pGrp, sqlite3_changeset_iter *pIter ){ - if( pIter->in.iCurrent==pIter->in.iNext || pIter->rc!=SQLITE_OK ){ - /* Iterator does not point to any valid entry. */ + if( pIter->in.iCurrent==pIter->in.iNext + || pIter->rc!=SQLITE_OK + || pIter->bInvert + ){ + /* Iterator does not point to any valid entry or is an INVERT iterator. */ return SQLITE_ERROR; } - return sessionChangesetToHash(pIter, pGrp, 0); + return sessionOneChangeToHash(pGrp, pIter, 0); } /* diff --git a/ext/session/sqlite3session.h b/ext/session/sqlite3session.h index 69c8ee588c..ebd2cc5312 100644 --- a/ext/session/sqlite3session.h +++ b/ext/session/sqlite3session.h @@ -1067,7 +1067,9 @@ int sqlite3changegroup_add(sqlite3_changegroup*, int nData, void *pData); ** ** The iterator must point to a valid entry when this function is called. ** If it does not, SQLITE_ERROR is returned and no change is added to the -** changegroup. +** changegroup. Additionally, the iterator must not have been opened with +** the SQLITE_CHANGESETAPPLY_INVERT flag. In this case SQLITE_ERROR is also +** returned. */ int sqlite3changegroup_add_change( sqlite3_changegroup*, diff --git a/ext/session/test_session.c b/ext/session/test_session.c index f6db38c8a2..00c3c25068 100644 --- a/ext/session/test_session.c +++ b/ext/session/test_session.c @@ -1038,6 +1038,64 @@ static int SQLITE_TCLAPI test_sqlite3changeset_concat( return rc; } +static Tcl_Obj *testIterData(sqlite3_changeset_iter *pIter){ + Tcl_Obj *pVar = 0; + int nCol; /* Number of columns in table */ + int nCol2; /* Number of columns in table */ + int op; /* SQLITE_INSERT, UPDATE or DELETE */ + const char *zTab; /* Name of table change applies to */ + Tcl_Obj *pOld; /* Vector of old.* values */ + Tcl_Obj *pNew; /* Vector of new.* values */ + int bIndirect; + + char *zPK; + unsigned char *abPK; + int i; + + sqlite3changeset_op(pIter, &zTab, &nCol, &op, &bIndirect); + pVar = Tcl_NewObj(); + + Tcl_ListObjAppendElement(0, pVar, Tcl_NewStringObj( + op==SQLITE_INSERT ? "INSERT" : + op==SQLITE_UPDATE ? "UPDATE" : + "DELETE", -1 + )); + + Tcl_ListObjAppendElement(0, pVar, Tcl_NewStringObj(zTab, -1)); + Tcl_ListObjAppendElement(0, pVar, Tcl_NewBooleanObj(bIndirect)); + + zPK = ckalloc(nCol+1); + memset(zPK, 0, nCol+1); + sqlite3changeset_pk(pIter, &abPK, &nCol2); + assert( nCol==nCol2 ); + for(i=0; ipGrp, pIter->pIter); + if( rc!=SQLITE_OK ){ + rc = test_session_error(interp, rc, 0); + } + break; + }; + default: { /* delete */ assert( iSub==3 ); Tcl_DeleteCommand(interp, Tcl_GetString(objv[0])); @@ -1585,10 +1609,16 @@ static int SQLITE_TCLAPI test_sqlite3changegroup( return TCL_OK; } -typedef struct TestChangeIter TestChangeIter; -struct TestChangeIter { - sqlite3_changeset_iter *pIter; -}; +extern const char *sqlite3ErrName(int); + +/* +** Destructor for Tcl iterator command object. +*/ +static void test_iter_del(void *clientData){ + TestChangeIter *p = (TestChangeIter*)clientData; + sqlite3changeset_finalize(p->pIter); + ckfree(p); +} static int SQLITE_TCLAPI test_iter_cmd( void * clientData, @@ -1596,6 +1626,44 @@ static int SQLITE_TCLAPI test_iter_cmd( int objc, Tcl_Obj *CONST objv[] ){ + static const char *aSub[] = { + "next", /* 0 */ + "data", /* 1 */ + "finalize", /* 2 */ + 0 + }; + int iSub = 0; + + TestChangeIter *p = (TestChangeIter*)clientData; + int rc = SQLITE_OK; + + if( objc<2 ){ + Tcl_WrongNumArgs(interp, 1, objv, "CMD"); + return TCL_ERROR; + } + + if( Tcl_GetIndexFromObj(interp, objv[1], aSub, "sub-command", 0, &iSub) ){ + return TCL_ERROR; + } + switch( iSub ){ + case 0: + rc = sqlite3changeset_next(p->pIter); + Tcl_SetObjResult(interp, Tcl_NewStringObj(sqlite3ErrName(rc), -1)); + break; + case 1: + Tcl_SetObjResult(interp, testIterData(p->pIter)); + break; + case 2: + rc = sqlite3changeset_finalize(p->pIter); + p->pIter = 0; + Tcl_DeleteCommand(interp, Tcl_GetString(objv[0])); + Tcl_SetObjResult(interp, Tcl_NewStringObj(sqlite3ErrName(rc), -1)); + break; + default: + assert( 0 ); + break; + } + return TCL_OK; } @@ -1645,7 +1713,7 @@ static int SQLITE_TCLAPI test_sqlite3changeset_start( pNew->pIter = pIter; sprintf(zCmd, "csiter%d", iCmd++); - Tcl_CreateObjCommand(interp, zCmd, test_iter_cmd, (void*)pNew, 0); + Tcl_CreateObjCommand(interp, zCmd, test_iter_cmd, (void*)pNew, test_iter_del); Tcl_SetObjResult(interp, Tcl_NewStringObj(zCmd, -1)); return TCL_OK; } diff --git a/manifest b/manifest index e95fd9eb1b..d8069fa67e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\snew\ssessions\sAPI\ssqlite3changegroup_add_change(). -D 2024-05-04T21:10:24.120 +C Add\stests\sfor\ssqlite3changegroup_add_change(). +D 2024-05-06T17:21:23.939 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -582,9 +582,9 @@ F ext/session/sessionrowid.test 85187c2f1b38861a5844868126f69f9ec62223a03449a98a F ext/session/sessionsize.test 8fcf4685993c3dbaa46a24183940ab9f5aa9ed0d23e5fb63bfffbdb56134b795 F ext/session/sessionstat1.test 5e718d5888c0c49bbb33a7a4f816366db85f59f6a4f97544a806421b85dc2dec F ext/session/sessionwor.test 6fd9a2256442cebde5b2284936ae9e0d54bde692d0f5fd009ecef8511f4cf3fc -F ext/session/sqlite3session.c 0cdf052460fe11fd00a5c3f83b4a7152ed6c72ff7dacd4664c30ce16579748d7 -F ext/session/sqlite3session.h e36392d1087e42f4e691caff23cb99f4e9fc3b8b88ac7504dac3ea30883dc08b -F ext/session/test_session.c ba40d22840f3ed667448e34ab4eaa38e69f62f23af530c0f8f70a64ed92b039b +F ext/session/sqlite3session.c c7473aafbd88f796391a8c25aa90975a8f3729ab7f4f8cf74ab9d3b014e10abe +F ext/session/sqlite3session.h 1e9a1ab23701d85bb1a3794bae38a4c618c652ff84f744a7fd9b6339e9c8af2e +F ext/session/test_session.c 8bcc857125372e640f75ab63b4188080f9bbab92b65f86dfd160721c574b2044 F ext/userauth/sqlite3userauth.h 7f3ea8c4686db8e40b0a0e7a8e0b00fac13aa7a3 F ext/userauth/user-auth.txt ca7e9ee82ca4e1c1744295f8184dd70edfae1992865d26c64303f539eb6c084c F ext/userauth/userauth.c 7f00cded7dcaa5d47f54539b290a43d2e59f4b1eb5f447545fa865f002fc80cb @@ -2188,11 +2188,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 8c3086f9fe502dfc4a1fa610a23794fb037721df29dc5d2126cfb749a9d44a50 -R 92b682ff0cdf49829f0c1fddda225a0c -T *branch * changegroup-add-change -T *sym-changegroup-add-change * -T -sym-trunk * +P 73647db1ddfdaf40cbf18f1e47c10b4a906489f6d34d7667f0f2ff532f1eb37c +R 57bf39cdeb4ff65bb7bb7b027bf86eec U dan -Z d18fc76401ae213ec8fe7cdec8b2f0ce +Z 43c000dbcc9bde7f8ce3b6fbffdd9a33 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 6e66176619..18a3d1fa2a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -73647db1ddfdaf40cbf18f1e47c10b4a906489f6d34d7667f0f2ff532f1eb37c \ No newline at end of file +9d67bedc20c3a59e5488f0eaea6a6611940a9cb63f7cf5e687b061cb5d510943 \ No newline at end of file From cbea8d5c3fe95e8d3381102748846e7bc79949d9 Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 6 May 2024 17:32:26 +0000 Subject: [PATCH 377/430] Edit comments in sqlite3session.h. FossilOrigin-Name: 49f84878e21f85d44d8429cdc2908f87383e59737e1af3fdbccf0c276d883567 --- ext/session/sqlite3session.h | 3 +++ manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/ext/session/sqlite3session.h b/ext/session/sqlite3session.h index ebd2cc5312..aa4862eb2e 100644 --- a/ext/session/sqlite3session.h +++ b/ext/session/sqlite3session.h @@ -1065,6 +1065,9 @@ int sqlite3changegroup_add(sqlite3_changegroup*, int nData, void *pData); ** passed as the second argument to the changegroup object. The rules for ** adding the change are just as described for [sqlite3_changegroup_add()]. ** +** If the change is successfully added to the changegroup, SQLITE_OK is +** returned. Otherwise, an SQLite error code is returned. +** ** The iterator must point to a valid entry when this function is called. ** If it does not, SQLITE_ERROR is returned and no change is added to the ** changegroup. Additionally, the iterator must not have been opened with diff --git a/manifest b/manifest index d8069fa67e..0839ba753d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\stests\sfor\ssqlite3changegroup_add_change(). -D 2024-05-06T17:21:23.939 +C Edit\scomments\sin\ssqlite3session.h. +D 2024-05-06T17:32:26.518 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -583,7 +583,7 @@ F ext/session/sessionsize.test 8fcf4685993c3dbaa46a24183940ab9f5aa9ed0d23e5fb63b F ext/session/sessionstat1.test 5e718d5888c0c49bbb33a7a4f816366db85f59f6a4f97544a806421b85dc2dec F ext/session/sessionwor.test 6fd9a2256442cebde5b2284936ae9e0d54bde692d0f5fd009ecef8511f4cf3fc F ext/session/sqlite3session.c c7473aafbd88f796391a8c25aa90975a8f3729ab7f4f8cf74ab9d3b014e10abe -F ext/session/sqlite3session.h 1e9a1ab23701d85bb1a3794bae38a4c618c652ff84f744a7fd9b6339e9c8af2e +F ext/session/sqlite3session.h c02e7bbeb38647436fa7d6f364ffe90ac61b8ba5a28f0c04b22a23887baab6cb F ext/session/test_session.c 8bcc857125372e640f75ab63b4188080f9bbab92b65f86dfd160721c574b2044 F ext/userauth/sqlite3userauth.h 7f3ea8c4686db8e40b0a0e7a8e0b00fac13aa7a3 F ext/userauth/user-auth.txt ca7e9ee82ca4e1c1744295f8184dd70edfae1992865d26c64303f539eb6c084c @@ -2188,8 +2188,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 73647db1ddfdaf40cbf18f1e47c10b4a906489f6d34d7667f0f2ff532f1eb37c -R 57bf39cdeb4ff65bb7bb7b027bf86eec +P 9d67bedc20c3a59e5488f0eaea6a6611940a9cb63f7cf5e687b061cb5d510943 +R 296c227b21afb6ad42dfd04c5c56b363 U dan -Z 43c000dbcc9bde7f8ce3b6fbffdd9a33 +Z 10947964774872afcdccffdf87f6a27b # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 18a3d1fa2a..79b44f13a7 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9d67bedc20c3a59e5488f0eaea6a6611940a9cb63f7cf5e687b061cb5d510943 \ No newline at end of file +49f84878e21f85d44d8429cdc2908f87383e59737e1af3fdbccf0c276d883567 \ No newline at end of file From ebf9702b34ee0c4049e30df2f0382501125eb2ad Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 6 May 2024 19:04:46 +0000 Subject: [PATCH 378/430] Avoid unnecessary recursion in sqlite3ExprDeleteNN(). This complicates the code, but it is needed to prevent nuisance "stack overflow" reports from OSSFuzz while it is running the latest ASAN. FossilOrigin-Name: 70abc144ca90a58ea25dc2d90683545246c084d961215c20ec070b0abe640371 --- manifest | 15 +++++++-------- manifest.uuid | 2 +- src/expr.c | 15 ++++++++++++++- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index f7d7702ed9..66484c6c9a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\snew\ssessions\sAPI\ssqlite3changegroup_add_change(). -D 2024-05-06T17:55:19.315 +C Avoid\sunnecessary\srecursion\sin\ssqlite3ExprDeleteNN().\s\sThis\scomplicates\sthe\ncode,\sbut\sit\sis\sneeded\sto\sprevent\snuisance\s"stack\soverflow"\sreports\sfrom\nOSSFuzz\swhile\sit\sis\srunning\sthe\slatest\sASAN. +D 2024-05-06T19:04:46.744 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -703,7 +703,7 @@ F src/date.c 126ba2ab10aeb2e7ba6e089b5f07b747c0625b8287f78b60da346eda8d23c875 F src/dbpage.c 80e46e1df623ec40486da7a5086cb723b0275a6e2a7b01d9f9b5da0f04ba2782 F src/dbstat.c 3b677254d512fcafd4d0b341bf267b38b235ccfddbef24f9154e19360fa22e43 F src/delete.c cb766727c78e715f9fb7ec8a7d03658ed2a3016343ca687acfcec9083cdca500 -F src/expr.c 005bf7a088a2fb12a50752a2a1d40d423b8942e1920e93c3a1ba76da0bfbe52b +F src/expr.c 3428b046cb731be83770eaa34317d0ae5bdf8f5e7c3a0abd57528d0a03a8f9f9 F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c a47610f0a5c6cb0ad79f8fcef039c01833dec0c751bb695f28dc0ec6a4c3ba00 F src/func.c 283d4f3b2751a1d9339fd93a8a013d1948fd5f4474a3cab0955eb4fafd445d0f @@ -2189,9 +2189,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 4d90c3f179a3d7355b6b0202faf56f0be4be56986920576e528208cb84daa4af 49f84878e21f85d44d8429cdc2908f87383e59737e1af3fdbccf0c276d883567 -R 17b8f244002104b13ac86f24d06a1235 -T +closed 49f84878e21f85d44d8429cdc2908f87383e59737e1af3fdbccf0c276d883567 -U dan -Z ea504d9f33b8a329c60b503f8918f722 +P 5eaab43ce48bb8d710f784ecd6aa9a4b3e708b44b0f7e49daf66a3f8bc2b9873 +R ff7af78ebbbdb04b1ac8e2867e48ea3c +U drh +Z 931e0d906bc176d6db5edaecc3c54370 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 048c98751c..a2d92af012 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5eaab43ce48bb8d710f784ecd6aa9a4b3e708b44b0f7e49daf66a3f8bc2b9873 \ No newline at end of file +70abc144ca90a58ea25dc2d90683545246c084d961215c20ec070b0abe640371 \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index aeb04a37f2..a5272df7c9 100644 --- a/src/expr.c +++ b/src/expr.c @@ -1368,6 +1368,7 @@ void sqlite3ExprAssignVarNumber(Parse *pParse, Expr *pExpr, u32 n){ static SQLITE_NOINLINE void sqlite3ExprDeleteNN(sqlite3 *db, Expr *p){ assert( p!=0 ); assert( db!=0 ); +exprDeleteRestart: assert( !ExprUseUValue(p) || p->u.iValue>=0 ); assert( !ExprUseYWin(p) || !ExprUseYSub(p) ); assert( !ExprUseYWin(p) || p->y.pWin!=0 || db->mallocFailed ); @@ -1383,7 +1384,6 @@ static SQLITE_NOINLINE void sqlite3ExprDeleteNN(sqlite3 *db, Expr *p){ if( !ExprHasProperty(p, (EP_TokenOnly|EP_Leaf)) ){ /* The Expr.x union is never used at the same time as Expr.pRight */ assert( (ExprUseXList(p) && p->x.pList==0) || p->pRight==0 ); - if( p->pLeft && p->op!=TK_SELECT_COLUMN ) sqlite3ExprDeleteNN(db, p->pLeft); if( p->pRight ){ assert( !ExprHasProperty(p, EP_WinFunc) ); sqlite3ExprDeleteNN(db, p->pRight); @@ -1398,6 +1398,19 @@ static SQLITE_NOINLINE void sqlite3ExprDeleteNN(sqlite3 *db, Expr *p){ } #endif } + if( p->pLeft && p->op!=TK_SELECT_COLUMN ){ + Expr *pLeft = p->pLeft; + if( !ExprHasProperty(p, EP_Static) + && !ExprHasProperty(pLeft, EP_Static) + ){ + /* Avoid unnecessary recursion on unary operators */ + sqlite3DbNNFreeNN(db, p); + p = pLeft; + goto exprDeleteRestart; + }else{ + sqlite3ExprDeleteNN(db, pLeft); + } + } } if( !ExprHasProperty(p, EP_Static) ){ sqlite3DbNNFreeNN(db, p); From 07305e3a3ab5aaaa1062417f8176b95c13e73954 Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 6 May 2024 20:18:30 +0000 Subject: [PATCH 379/430] Omit redundant unary + operators from the AST. FossilOrigin-Name: f81cc149e5e308785502b36e83eaaf3d31c72520793e0596d5496abd70f9cda8 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/parse.y | 15 ++++++++++++--- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 66484c6c9a..adb660aa80 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Avoid\sunnecessary\srecursion\sin\ssqlite3ExprDeleteNN().\s\sThis\scomplicates\sthe\ncode,\sbut\sit\sis\sneeded\sto\sprevent\snuisance\s"stack\soverflow"\sreports\sfrom\nOSSFuzz\swhile\sit\sis\srunning\sthe\slatest\sASAN. -D 2024-05-06T19:04:46.744 +C Omit\sredundant\sunary\s+\soperators\sfrom\sthe\sAST. +D 2024-05-06T20:18:30.134 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -742,7 +742,7 @@ F src/os_win.c 6ff43bac175bd9ed79e7c0f96840b139f2f51d01689a638fd05128becf94908a F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a F src/pager.c 9beb80f6e330dd63c5d8ba0f7a7f3a55fff22067a68d424949c389bfc6fa0c56 F src/pager.h 4b1140d691860de0be1347474c51fee07d5420bd7f802d38cbab8ea4ab9f538a -F src/parse.y 5bcef16094213efcc365a9d4dc4e3131f09251dc8838dce4a9e5f9764bff5b82 +F src/parse.y 50516253433303673ff6b009983bb246d1527415e5a9af22acc51b0eedb9a10d F src/pcache.c 040b165f30622a21b7a9a77c6f2e4877a32fb7f22d4c7f0d2a6fa6833a156a75 F src/pcache.h 1497ce1b823cf00094bb0cf3bac37b345937e6f910890c626b16512316d3abf5 F src/pcache1.c 602acb23c471bb8d557a6f0083cc2be641d6cafcafa19e481eba7ef4c9ca0f00 @@ -2189,8 +2189,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 5eaab43ce48bb8d710f784ecd6aa9a4b3e708b44b0f7e49daf66a3f8bc2b9873 -R ff7af78ebbbdb04b1ac8e2867e48ea3c +P 70abc144ca90a58ea25dc2d90683545246c084d961215c20ec070b0abe640371 +R 6e7646721881518bcc2dce999a09299b U drh -Z 931e0d906bc176d6db5edaecc3c54370 +Z 6285aee0842c44c0bef4e5561a9995b3 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index a2d92af012..1eabb503c3 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -70abc144ca90a58ea25dc2d90683545246c084d961215c20ec070b0abe640371 \ No newline at end of file +f81cc149e5e308785502b36e83eaaf3d31c72520793e0596d5496abd70f9cda8 \ No newline at end of file diff --git a/src/parse.y b/src/parse.y index d22c8e6fc2..071e10abd4 100644 --- a/src/parse.y +++ b/src/parse.y @@ -1282,8 +1282,17 @@ expr(A) ::= NOT(B) expr(X). expr(A) ::= BITNOT(B) expr(X). {A = sqlite3PExpr(pParse, @B, X, 0);/*A-overwrites-B*/} expr(A) ::= PLUS|MINUS(B) expr(X). [BITNOT] { - A = sqlite3PExpr(pParse, @B==TK_PLUS ? TK_UPLUS : TK_UMINUS, X, 0); - /*A-overwrites-B*/ + Expr *p = X; + u8 op = @B + (TK_UPLUS-TK_PLUS); + assert( TK_UPLUS>TK_PLUS ); + assert( TK_UMINUS == TK_MINUS + (TK_UPLUS - TK_PLUS) ); + if( p && p->op==TK_UPLUS ){ + p->op = op; + A = p; + }else{ + A = sqlite3PExpr(pParse, op, p, 0); + /*A-overwrites-B*/ + } } expr(A) ::= expr(B) PTR(C) expr(D). { @@ -1929,8 +1938,8 @@ filter_clause(A) ::= FILTER LP WHERE expr(X) RP. { A = X; } TRUEFALSE /* True or false keyword */ ISNOT /* Combination of IS and NOT */ FUNCTION /* A function invocation */ - UMINUS /* Unary minus */ UPLUS /* Unary plus */ + UMINUS /* Unary minus */ TRUTH /* IS TRUE or IS FALSE or IS NOT TRUE or IS NOT FALSE */ REGISTER /* Reference to a VDBE register */ VECTOR /* Vector */ From 11a088b7eb9b563419253badf56fa50e897d5123 Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 6 May 2024 20:21:31 +0000 Subject: [PATCH 380/430] When extracting links from sqlar archives, clobber any existing file or link, and do not call utimes() to set the timestamp - it looks through the link and operates on the target. FossilOrigin-Name: 2bf8c3f99ad8b74f707d17272fa12b674bec66082d3e8349ebef3dac42ba0782 --- ext/misc/fileio.c | 24 ++++++++++++++++-------- manifest | 16 ++++++++-------- manifest.uuid | 2 +- test/shell8.test | 27 ++++++++++++++++++++++++++- 4 files changed, 51 insertions(+), 18 deletions(-) diff --git a/ext/misc/fileio.c b/ext/misc/fileio.c index 70546adfca..ca8090ed2e 100644 --- a/ext/misc/fileio.c +++ b/ext/misc/fileio.c @@ -372,7 +372,9 @@ static int writeFile( #if !defined(_WIN32) && !defined(WIN32) if( S_ISLNK(mode) ){ const char *zTo = (const char*)sqlite3_value_text(pData); - if( zTo==0 || symlink(zTo, zFile)<0 ) return 1; + if( zTo==0 ) return 1; + unlink(zFile); + if( symlink(zTo, zFile)<0 ) return 1; }else #endif { @@ -458,13 +460,19 @@ static int writeFile( return 1; } #else - /* Legacy unix */ - struct timeval times[2]; - times[0].tv_usec = times[1].tv_usec = 0; - times[0].tv_sec = time(0); - times[1].tv_sec = mtime; - if( utimes(zFile, times) ){ - return 1; + /* Legacy unix. + ** + ** Do not use utimes() on a symbolic link - it sees through the link and + ** modifies the timestamps on the target. Or fails if the target does + ** not exist. */ + if( 0==S_ISLNK(mode) ){ + struct timeval times[2]; + times[0].tv_usec = times[1].tv_usec = 0; + times[0].tv_sec = time(0); + times[1].tv_sec = mtime; + if( utimes(zFile, times) ){ + return 1; + } } #endif } diff --git a/manifest b/manifest index adb660aa80..1414eb9756 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Omit\sredundant\sunary\s+\soperators\sfrom\sthe\sAST. -D 2024-05-06T20:18:30.134 +C When\sextracting\slinks\sfrom\ssqlar\sarchives,\sclobber\sany\sexisting\sfile\sor\slink,\sand\sdo\snot\scall\sutimes()\sto\sset\sthe\stimestamp\s-\sit\slooks\sthrough\sthe\slink\sand\soperates\son\sthe\starget. +D 2024-05-06T20:21:31.369 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -391,7 +391,7 @@ F ext/misc/dbdump.c b8592f6f2da292c62991a13864a60d6c573c47a9cc58362131b9e6a64f82 F ext/misc/decimal.c 172cf81a8634e6a0f0bedaf71a8372fee63348cf5a3c4e1b78bb233c35889fdc F ext/misc/eval.c 04bc9aada78c888394204b4ed996ab834b99726fb59603b0ee3ed6e049755dc1 F ext/misc/explain.c 606100185fb90d6a1eade1ed0414d53503c86820d8956a06e3b0a56291894f2b -F ext/misc/fileio.c d88e60f63557d76d4e38acffda5556b2ab42e98f5d830897f22aba65930d975c +F ext/misc/fileio.c 916638042f318701460485032e33981056747d0f92e6757aa9499f2363ea7047 F ext/misc/fossildelta.c 8c026e086e406e2b69947f1856fa3b848fff5379962276430d10085b8756b05a F ext/misc/fuzzer.c 8b28acf1a7e95d50e332bdd47e792ff27054ad99d3f9bc2e91273814d4b31a5a F ext/misc/ieee754.c 62a90978204d2c956d5036eb89e548e736ca5fac0e965912867ddd7bb833256d @@ -1615,7 +1615,7 @@ F test/shell4.test 522fdc628c55eff697b061504fb0a9e4e6dfc5d9087a633ab0f3dd11bcc4f F test/shell5.test 5b2ab1c0540217773f939927c24163a56257446da3f564d4724042620bfea762 F test/shell6.test e3b883b61d4916b6906678a35f9d19054861123ad91b856461e0a456273bdbb8 F test/shell7.test 753c6ece5361df50025a50cadf378ea36db9cc05fb23d7a96cff7fa130626ef9 -F test/shell8.test 9b71d56a6f6fc62edd9163534ac21eaa328ad95f1b9026e7bd08d5b4621eacf6 +F test/shell8.test aea51ecbcd4494c746b096aeff51d841d04d5f0dc4b62eb42427f16109b87acd F test/shell9.test 8742a5b390cdcef6369f5aa223e415aa4255a4129ef249b177887dc635a87209 F test/shmlock.test 3dbf017d34ab0c60abe6a44e447d3552154bd0c87b41eaf5ceacd408dd13fda5 F test/shortread1.test bb591ef20f0fd9ed26d0d12e80eee6d7ac8897a3 @@ -2189,8 +2189,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 70abc144ca90a58ea25dc2d90683545246c084d961215c20ec070b0abe640371 -R 6e7646721881518bcc2dce999a09299b -U drh -Z 6285aee0842c44c0bef4e5561a9995b3 +P f81cc149e5e308785502b36e83eaaf3d31c72520793e0596d5496abd70f9cda8 +R 11a1bb72646a7cee54c6968ddd222fda +U dan +Z 139d76aa50084d40f26f43b610be1a4e # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 1eabb503c3..2c00a6909f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f81cc149e5e308785502b36e83eaaf3d31c72520793e0596d5496abd70f9cda8 \ No newline at end of file +2bf8c3f99ad8b74f707d17272fa12b674bec66082d3e8349ebef3dac42ba0782 \ No newline at end of file diff --git a/test/shell8.test b/test/shell8.test index 944173a2a1..ca37598e93 100644 --- a/test/shell8.test +++ b/test/shell8.test @@ -165,7 +165,7 @@ foreach {tn tcl} { # # Because it is slow, only do this for $tn==1. if {$tn==1} { - do_test 1.$tn.1 { + do_test 1.$tn.4 { catchcmd test_ar.db $c1 file delete -force ar1 after 2000 @@ -194,4 +194,29 @@ do_test 2.1.1 { regsub -all {ar4} [dir_content ar4] ar2 } {ar2/file1 ar2/file2 ar2/junk1} +# Test symbolic links. +# +if {$tcl_platform(platform)=="unix"} { + populate_dir ar2 { + file1 "1234" + file2 "3456" + } + file link ar2/link1 file1 + + forcedelete shell8.db + forcedelete link1 + + do_test 3.1 { + catchcmd shell8.db {.ar -C ar2 -c file2 link1 } + } {0 {}} + + do_test 3.2 { + catchcmd shell8.db {.ar -x} + } {0 {}} + + do_test 3.3 { + catchcmd shell8.db {.ar -x} + } {0 {}} +} + finish_test From e871779f7e48185c65954a41b0fb1d65768b8be4 Mon Sep 17 00:00:00 2001 From: stephan Date: Tue, 7 May 2024 13:20:24 +0000 Subject: [PATCH 381/430] Fix a compilation error in test/lemon-test01.y, reported in [forum:f0ad095705|forum post f0ad095705]. FossilOrigin-Name: 576b68c8b5132eb8901789b7fafb37e5ad7a00c1c7154090b42ddc5934ac0396 --- manifest | 14 +++++++------- manifest.uuid | 2 +- test/lemon-test01.y | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 1414eb9756..8d4e3858f7 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C When\sextracting\slinks\sfrom\ssqlar\sarchives,\sclobber\sany\sexisting\sfile\sor\slink,\sand\sdo\snot\scall\sutimes()\sto\sset\sthe\stimestamp\s-\sit\slooks\sthrough\sthe\slink\sand\soperates\son\sthe\starget. -D 2024-05-06T20:21:31.369 +C Fix\sa\scompilation\serror\sin\stest/lemon-test01.y,\sreported\sin\s[forum:f0ad095705|forum\spost\sf0ad095705]. +D 2024-05-07T13:20:24.512 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -1370,7 +1370,7 @@ F test/keyword1.test 37ef6bba5d2ed5b07ecdd6810571de2956599dff F test/kvtest.c 6e0228409ea7ca0497dad503fbd109badb5e59545d131014b6aaac68b56f484a F test/lastinsert.test 42e948fd6442f07d60acbd15d33fb86473e0ef63 F test/laststmtchanges.test ae613f53819206b3222771828d024154d51db200 -F test/lemon-test01.y f6280e3787ff9ab57b12527e814c205e1ba1f25fc7458dd6986e2d3351eee320 +F test/lemon-test01.y 70110eff607ab137ccc851edb2bc7e14a6d4f246b5d2d25f82a60b69d87a9ff2 F test/like.test 242ee7f5d08a031144c0daf63bbd7e7710c847ccf387a83347e0b61b3aa69526 F test/like2.test d3be15fefee3e02fc88942a9b98f26c5339bbdef7783c90023c092c4955fe3d3 F test/like3.test a76e5938fadbe6d32807284c796bafd869974a961057bc5fc5a28e06de98745c @@ -2189,8 +2189,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P f81cc149e5e308785502b36e83eaaf3d31c72520793e0596d5496abd70f9cda8 -R 11a1bb72646a7cee54c6968ddd222fda -U dan -Z 139d76aa50084d40f26f43b610be1a4e +P 2bf8c3f99ad8b74f707d17272fa12b674bec66082d3e8349ebef3dac42ba0782 +R cd6817873ffd9cbd41715e29850cbbb5 +U stephan +Z ea3f55e2a2ab2609bdac4d75c8a5f3af # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 2c00a6909f..2581198f30 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2bf8c3f99ad8b74f707d17272fa12b674bec66082d3e8349ebef3dac42ba0782 \ No newline at end of file +576b68c8b5132eb8901789b7fafb37e5ad7a00c1c7154090b42ddc5934ac0396 \ No newline at end of file diff --git a/test/lemon-test01.y b/test/lemon-test01.y index 929b00b62c..67890c6376 100644 --- a/test/lemon-test01.y +++ b/test/lemon-test01.y @@ -33,7 +33,7 @@ all ::= error B. #include "lemon-test01.h" static int nTest = 0; static int nErr = 0; - static int testCase(int testId, int shouldBe, int actual){ + static void testCase(int testId, int shouldBe, int actual){ nTest++; if( shouldBe==actual ){ printf("test %d: ok\n", testId); From a40cae78027eed3212b0207c478a5879ba49bea2 Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 7 May 2024 17:58:07 +0000 Subject: [PATCH 382/430] Ensure successive scans of pragma virtual tables return consistent rowids. FossilOrigin-Name: 6838bf3ac130c5862f5fbc718b3e49ece154fa840b6539af2616cffa31e73808 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/pragma.c | 1 + test/pragma4.test | 28 ++++++++++++++++++++++++++++ 4 files changed, 38 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 8d4e3858f7..6f4f8b70a4 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\scompilation\serror\sin\stest/lemon-test01.y,\sreported\sin\s[forum:f0ad095705|forum\spost\sf0ad095705]. -D 2024-05-07T13:20:24.512 +C Ensure\ssuccessive\sscans\sof\spragma\svirtual\stables\sreturn\sconsistent\srowids. +D 2024-05-07T17:58:07.671 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -746,7 +746,7 @@ F src/parse.y 50516253433303673ff6b009983bb246d1527415e5a9af22acc51b0eedb9a10d F src/pcache.c 040b165f30622a21b7a9a77c6f2e4877a32fb7f22d4c7f0d2a6fa6833a156a75 F src/pcache.h 1497ce1b823cf00094bb0cf3bac37b345937e6f910890c626b16512316d3abf5 F src/pcache1.c 602acb23c471bb8d557a6f0083cc2be641d6cafcafa19e481eba7ef4c9ca0f00 -F src/pragma.c d357a25276d222adfd4637c48880409ec4539f30844b74001c6ba5c7d1a1f0f7 +F src/pragma.c 52bfbf6dfd668b69b5eb9bd1186e3a67367c8453807150d6e75239229924f684 F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7 F src/prepare.c 371f6115cb69286ebc12c6f2d7511279c2e47d9f54f475d46a554d687a3b312c F src/printf.c 8b250972305e14b365561be5117ed0fd364e4fd58968776df1ce64c6280b90f9 @@ -1506,7 +1506,7 @@ F test/pg_common.tcl 3b27542224db1e713ae387459b5d117c836a5f6e328846922993b6d2b76 F test/pragma.test 11cb9310c42f921918f7f563e3c0b6e70f9f9c3a6a1cf12af8fccb6c574f3882 F test/pragma2.test e5d5c176360c321344249354c0c16aec46214c9f F test/pragma3.test 92a46bbea12322dd94a404f49edcfbfc913a2c98115f0d030a7459bb4712ef31 -F test/pragma4.test 22834a228e59b80f5c15b519b710474859d91535002670ddb7cd13ac44b54e9a +F test/pragma4.test f93f317693e90ece4ed0f5505d9035cae03f9fc684b718278433f2e48703f693 F test/pragma5.test 7b33fc43e2e41abf17f35fb73f71b49671a380ea92a6c94b6ce530a25f8d9102 F test/pragma6.test c5ec577ba087954b4dfa619a3cbe97b155b60a0af487527abe89b10fc17e6512 F test/pragmafault.test 275edaf3161771d37de60e5c2b412627ac94cef11739236bec12ed1258b240f8 @@ -2189,8 +2189,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 2bf8c3f99ad8b74f707d17272fa12b674bec66082d3e8349ebef3dac42ba0782 -R cd6817873ffd9cbd41715e29850cbbb5 -U stephan -Z ea3f55e2a2ab2609bdac4d75c8a5f3af +P 576b68c8b5132eb8901789b7fafb37e5ad7a00c1c7154090b42ddc5934ac0396 +R dd0146b65a6f2cce89315f9eb819a1ea +U dan +Z 7d535aaf3f019393b2ad327e44317dcb # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 2581198f30..f3000e5cae 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -576b68c8b5132eb8901789b7fafb37e5ad7a00c1c7154090b42ddc5934ac0396 \ No newline at end of file +6838bf3ac130c5862f5fbc718b3e49ece154fa840b6539af2616cffa31e73808 \ No newline at end of file diff --git a/src/pragma.c b/src/pragma.c index 80864da79f..a8045aab1e 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -2911,6 +2911,7 @@ static void pragmaVtabCursorClear(PragmaVtabCursor *pCsr){ int i; sqlite3_finalize(pCsr->pPragma); pCsr->pPragma = 0; + pCsr->iRowid = 0; for(i=0; iazArg); i++){ sqlite3_free(pCsr->azArg[i]); pCsr->azArg[i] = 0; diff --git a/test/pragma4.test b/test/pragma4.test index 6d59b4fff3..5360fbac40 100644 --- a/test/pragma4.test +++ b/test/pragma4.test @@ -283,4 +283,32 @@ ifcapable vtab { } {t2 t1 d a 1} } +# 2024-05-08 https://sqlite.org/forum/forumpost/cf29a33e94 +# +ifcapable vtab { + do_execsql_test 7.0 { + CREATE TABLE t3 ("a" TEXT, "b" TEXT); + CREATE TABLE t4 ("a" TEXT, "b" TEXT, "c" TEXT); + } + + do_execsql_test 7.1 { + CREATE TABLE pragma_t3 AS SELECT * FROM pragma_table_info('t3'); + CREATE TABLE pragma_t4 AS SELECT * FROM pragma_table_info('t4'); + } + + do_execsql_test 7.2 { + SELECT pragma_t4.name, pragma_t3.name + FROM pragma_t4 RIGHT JOIN pragma_t3 ON (pragma_t4.name=pragma_t3.name); + } {a a b b} + + do_execsql_test 7.3 { + SELECT t4.name, t3.name + FROM pragma_table_info('t4') t4 + RIGHT JOIN pragma_table_info('t3') t3 ON (t4.name=t3.name); + } {a a b b} +} + + + + finish_test From d1122a4c0f1aa72b5033a8ae03d293c0a1afb04a Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 7 May 2024 19:45:05 +0000 Subject: [PATCH 383/430] Fix bug in test script sessionconflict.test. FossilOrigin-Name: e29decb8b1991bb586f41fd74bbaa4d6c4bd63e22617145828b2500d697d7869 --- ext/session/sessionconflict.test | 1 + manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/ext/session/sessionconflict.test b/ext/session/sessionconflict.test index c842a8aacb..25b2602998 100644 --- a/ext/session/sessionconflict.test +++ b/ext/session/sessionconflict.test @@ -20,6 +20,7 @@ ifcapable !session {finish_test; return} set testprefix sessionconflict +db close sqlite3_shutdown test_sqlite3_log log proc log {code msg} { puts "LOG $code $msg" } diff --git a/manifest b/manifest index 6f4f8b70a4..e71dcac966 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Ensure\ssuccessive\sscans\sof\spragma\svirtual\stables\sreturn\sconsistent\srowids. -D 2024-05-07T17:58:07.671 +C Fix\sbug\sin\stest\sscript\ssessionconflict.test. +D 2024-05-07T19:45:05.255 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -568,7 +568,7 @@ F ext/session/sessionalter.test 460bdac2832a550519f6bc32e5db2c0cee94f335870aaf25 F ext/session/sessionat.test 00c8badb35e43a2f12a716d2734a44d614ff62361979b6b85419035bc04b45ee F ext/session/sessionbig.test 47c381e7acfabeef17d98519a3080d69151723354d220afa2053852182ca7adf F ext/session/sessionchange.test 77c4702050f24270b58070e2cf01c95c3d232a3ef164b70f31974b386ce69903 -F ext/session/sessionconflict.test 28890457bb90457be772d3067cdb5f78db9b51d997e4f3d09f22cddc9be80a38 +F ext/session/sessionconflict.test 8b8cbd98548e2e636ddc17d0986276f60e833fb865617dd4f88ea5bbe3a16b96 F ext/session/sessiondiff.test ad13dd65664bae26744e1f18eb3cbd5588349b7e9118851d8f9364248d67bcec F ext/session/sessionfault.test 573bf027fb870d57bd4e7cf50822a3e4b17b2b923407438747aaa918dec57a09 F ext/session/sessionfault2.test b0d6a7c1d7398a7e800d84657404909c7d385965ea8576dc79ed344c46fbf41c @@ -2189,8 +2189,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 576b68c8b5132eb8901789b7fafb37e5ad7a00c1c7154090b42ddc5934ac0396 -R dd0146b65a6f2cce89315f9eb819a1ea +P 6838bf3ac130c5862f5fbc718b3e49ece154fa840b6539af2616cffa31e73808 +R 7cad8658624c310fc9eec1405b0ca964 U dan -Z 7d535aaf3f019393b2ad327e44317dcb +Z 1d9426ac7036e4e699729b91e2ba47ed # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index f3000e5cae..eff0e01131 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6838bf3ac130c5862f5fbc718b3e49ece154fa840b6539af2616cffa31e73808 \ No newline at end of file +e29decb8b1991bb586f41fd74bbaa4d6c4bd63e22617145828b2500d697d7869 \ No newline at end of file From 538ad6ce58c47e48f2c85abfcb31c968e615fc40 Mon Sep 17 00:00:00 2001 From: drh <> Date: Wed, 8 May 2024 11:51:56 +0000 Subject: [PATCH 384/430] Fix a hyperlink typo in session documentation. FossilOrigin-Name: 42d67c6fed3a5f21d7b71515aca471ba61d387e620022735a2e7929fa3a237cf --- ext/session/sqlite3session.h | 2 +- manifest | 14 +++++++------- manifest.uuid | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/ext/session/sqlite3session.h b/ext/session/sqlite3session.h index aa4862eb2e..f950d419b5 100644 --- a/ext/session/sqlite3session.h +++ b/ext/session/sqlite3session.h @@ -1063,7 +1063,7 @@ int sqlite3changegroup_add(sqlite3_changegroup*, int nData, void *pData); ** ** This function adds the single change currently indicated by the iterator ** passed as the second argument to the changegroup object. The rules for -** adding the change are just as described for [sqlite3_changegroup_add()]. +** adding the change are just as described for [sqlite3changegroup_add()]. ** ** If the change is successfully added to the changegroup, SQLITE_OK is ** returned. Otherwise, an SQLite error code is returned. diff --git a/manifest b/manifest index e71dcac966..32bc04aaf5 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sbug\sin\stest\sscript\ssessionconflict.test. -D 2024-05-07T19:45:05.255 +C Fix\sa\shyperlink\stypo\sin\ssession\sdocumentation. +D 2024-05-08T11:51:56.927 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -584,7 +584,7 @@ F ext/session/sessionsize.test 8fcf4685993c3dbaa46a24183940ab9f5aa9ed0d23e5fb63b F ext/session/sessionstat1.test 5e718d5888c0c49bbb33a7a4f816366db85f59f6a4f97544a806421b85dc2dec F ext/session/sessionwor.test 6fd9a2256442cebde5b2284936ae9e0d54bde692d0f5fd009ecef8511f4cf3fc F ext/session/sqlite3session.c c7473aafbd88f796391a8c25aa90975a8f3729ab7f4f8cf74ab9d3b014e10abe -F ext/session/sqlite3session.h c02e7bbeb38647436fa7d6f364ffe90ac61b8ba5a28f0c04b22a23887baab6cb +F ext/session/sqlite3session.h 683ccbf16e2c2521661fc4c1cf918ce57002039efbcabcd8097fa4bca569104b F ext/session/test_session.c 8bcc857125372e640f75ab63b4188080f9bbab92b65f86dfd160721c574b2044 F ext/userauth/sqlite3userauth.h 7f3ea8c4686db8e40b0a0e7a8e0b00fac13aa7a3 F ext/userauth/user-auth.txt ca7e9ee82ca4e1c1744295f8184dd70edfae1992865d26c64303f539eb6c084c @@ -2189,8 +2189,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 6838bf3ac130c5862f5fbc718b3e49ece154fa840b6539af2616cffa31e73808 -R 7cad8658624c310fc9eec1405b0ca964 -U dan -Z 1d9426ac7036e4e699729b91e2ba47ed +P e29decb8b1991bb586f41fd74bbaa4d6c4bd63e22617145828b2500d697d7869 +R bd6c2a6994b109d4181b29475acc71ca +U drh +Z b1677682f99b4b1ca04906a7901df3be # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index eff0e01131..d0915126d9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e29decb8b1991bb586f41fd74bbaa4d6c4bd63e22617145828b2500d697d7869 \ No newline at end of file +42d67c6fed3a5f21d7b71515aca471ba61d387e620022735a2e7929fa3a237cf \ No newline at end of file From f0c9bc596ebd178fdab62634df88a03ae4da1d3e Mon Sep 17 00:00:00 2001 From: stephan Date: Wed, 8 May 2024 17:57:45 +0000 Subject: [PATCH 385/430] Rename a shadowed local var, as reported in [forum:2ba65af3148585cf|forum post 2ba65af31]. No functional changes. FossilOrigin-Name: d030c87c4d410e9ca2b90ec7cb63e752f4490c60e2feac84f233861593142c7d --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/select.c | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 32bc04aaf5..6387c6f73c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\shyperlink\stypo\sin\ssession\sdocumentation. -D 2024-05-08T11:51:56.927 +C Rename\sa\sshadowed\slocal\svar,\sas\sreported\sin\s[forum:2ba65af3148585cf|forum\spost\s2ba65af31].\sNo\sfunctional\schanges. +D 2024-05-08T17:57:45.450 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -753,7 +753,7 @@ F src/printf.c 8b250972305e14b365561be5117ed0fd364e4fd58968776df1ce64c6280b90f9 F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c 8816212645e4e9bdf3cc2f2d298304f388d699f8fab47f3a5712ef5bbc5b6ccc F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 -F src/select.c 04178566d0188be7de471064ced8cec1d407920726cb49b609486282d78faf56 +F src/select.c ce81687d769b174aa547b8216a34fabc9cafc05789b615494ab78dc2c1e799fa F src/shell.c.in 0354ca51eee5fbf6af394a7ef9f5ef6823ef45b743db65431f6777e4d5be2199 F src/sqlite.h.in 32389e0d584551b300d0157881336162c14315a424cbf385c0d65eb7c2e31f7b F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 @@ -2189,8 +2189,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P e29decb8b1991bb586f41fd74bbaa4d6c4bd63e22617145828b2500d697d7869 -R bd6c2a6994b109d4181b29475acc71ca -U drh -Z b1677682f99b4b1ca04906a7901df3be +P 42d67c6fed3a5f21d7b71515aca471ba61d387e620022735a2e7929fa3a237cf +R 720970f4b793c1274abaf8cd5acc207b +U stephan +Z ded7a2dedc55d6033e03441501e1782b # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index d0915126d9..1393352ef3 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -42d67c6fed3a5f21d7b71515aca471ba61d387e620022735a2e7929fa3a237cf \ No newline at end of file +d030c87c4d410e9ca2b90ec7cb63e752f4490c60e2feac84f233861593142c7d \ No newline at end of file diff --git a/src/select.c b/src/select.c index 8ee59cf68a..532fbd19e5 100644 --- a/src/select.c +++ b/src/select.c @@ -2381,12 +2381,12 @@ void sqlite3SubqueryColumnTypes( } } if( zType ){ - i64 m = sqlite3Strlen30(zType); + const i64 k = sqlite3Strlen30(zType); n = sqlite3Strlen30(pCol->zCnName); - pCol->zCnName = sqlite3DbReallocOrFree(db, pCol->zCnName, n+m+2); + pCol->zCnName = sqlite3DbReallocOrFree(db, pCol->zCnName, n+k+2); pCol->colFlags &= ~(COLFLAG_HASTYPE|COLFLAG_HASCOLL); if( pCol->zCnName ){ - memcpy(&pCol->zCnName[n+1], zType, m+1); + memcpy(&pCol->zCnName[n+1], zType, k+1); pCol->colFlags |= COLFLAG_HASTYPE; } } From 0e93237b17e652f92a4977abd4c8f8a98804fa4c Mon Sep 17 00:00:00 2001 From: stephan Date: Thu, 9 May 2024 18:00:14 +0000 Subject: [PATCH 386/430] Reformulate a for-in loop to a for loop in wasm.xWrap() to work around a downstream framework-level misbehavior, as reported in [forum:b549992634b55104|forum post b549992634b55104]. FossilOrigin-Name: dc58ed654928574ef254af289bd21c654c587aac80aea36ab96772c35d4ca754 --- ext/wasm/common/whwasmutil.js | 3 ++- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/ext/wasm/common/whwasmutil.js b/ext/wasm/common/whwasmutil.js index bbcf3d4930..326b28e22f 100644 --- a/ext/wasm/common/whwasmutil.js +++ b/ext/wasm/common/whwasmutil.js @@ -2035,7 +2035,8 @@ globalThis.WhWasmUtilInstaller = function(target){ arguments are, is _not_ part of the public interface and is _not_ stable. */ - for(const i in args) args[i] = cxw.convertArgNoCheck( + let i = 0; + for(; i < args.length; ++i) args[i] = cxw.convertArgNoCheck( argTypes[i], args[i], args, i ); return cxw.convertResultNoCheck(resultType, xf.apply(null,args)); diff --git a/manifest b/manifest index 6387c6f73c..03ae78d768 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Rename\sa\sshadowed\slocal\svar,\sas\sreported\sin\s[forum:2ba65af3148585cf|forum\spost\s2ba65af31].\sNo\sfunctional\schanges. -D 2024-05-08T17:57:45.450 +C Reformulate\sa\sfor-in\sloop\sto\sa\sfor\sloop\sin\swasm.xWrap()\sto\swork\saround\sa\sdownstream\sframework-level\smisbehavior,\sas\sreported\sin\s[forum:b549992634b55104|forum\spost\sb549992634b55104]. +D 2024-05-09T18:00:14.716 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -629,7 +629,7 @@ F ext/wasm/c-pp.c 6d80d8569d85713effe8b0818a3cf51dc779e3f0bf8dc88771b8998552ee25 F ext/wasm/common/SqliteTestUtil.js 7adaeffef757d8708418dc9190f72df22367b531831775804b31598b44f6aa51 F ext/wasm/common/emscripten.css 11bd104b6c0d597c67d40cc8ecc0a60dae2b965151e3b6a37fa5708bac3acd15 F ext/wasm/common/testing.css e97549bab24126c24e0daabfe2de9bb478fb0a69fdb2ddd0a73a992c091aad6f -F ext/wasm/common/whwasmutil.js e474e0fac695abf88e5385581e26d53e5706cd268cab9d92a56eab2873c08daa +F ext/wasm/common/whwasmutil.js 22a81c8ca81ceb2662db4a73ded2e8bef22300fd8894410fac0ffd45f32da8fd F ext/wasm/demo-123-worker.html a0b58d9caef098a626a1a1db567076fca4245e8d60ba94557ede8684350a81ed F ext/wasm/demo-123.html 8c70a412ce386bd3796534257935eb1e3ea5c581e5d5aea0490b8232e570a508 F ext/wasm/demo-123.js c7b3cca50c55841c381a9ca4f9396e5bbdc6114273d0b10a43e378e32e7be5bf @@ -2189,8 +2189,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 42d67c6fed3a5f21d7b71515aca471ba61d387e620022735a2e7929fa3a237cf -R 720970f4b793c1274abaf8cd5acc207b +P d030c87c4d410e9ca2b90ec7cb63e752f4490c60e2feac84f233861593142c7d +R 1ce3f637477b3f3b2a8d1fc27a6cb38f U stephan -Z ded7a2dedc55d6033e03441501e1782b +Z 6f5fe3e373ae24dc54ff89790b691517 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 1393352ef3..bc458de973 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d030c87c4d410e9ca2b90ec7cb63e752f4490c60e2feac84f233861593142c7d \ No newline at end of file +dc58ed654928574ef254af289bd21c654c587aac80aea36ab96772c35d4ca754 \ No newline at end of file From a8c43830f2bdfe7777350646040f70285a665e9f Mon Sep 17 00:00:00 2001 From: stephan Date: Thu, 9 May 2024 18:39:54 +0000 Subject: [PATCH 387/430] Add a maintenance-reminder comment explaining [dc58ed65492857]. FossilOrigin-Name: 857f5d7fadce1cfe30b3468826f403f736cfecacb1eb6d3b858b01ea3cfd6ffc --- ext/wasm/common/whwasmutil.js | 3 +++ manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/ext/wasm/common/whwasmutil.js b/ext/wasm/common/whwasmutil.js index 326b28e22f..b8a2a87742 100644 --- a/ext/wasm/common/whwasmutil.js +++ b/ext/wasm/common/whwasmutil.js @@ -2034,6 +2034,9 @@ globalThis.WhWasmUtilInstaller = function(target){ arguments may be passed in after that one, and what those arguments are, is _not_ part of the public interface and is _not_ stable. + + Maintenance reminder: the Ember framework modifies the core + Array type, breaking for-in loops. */ let i = 0; for(; i < args.length; ++i) args[i] = cxw.convertArgNoCheck( diff --git a/manifest b/manifest index 03ae78d768..583b3d98ac 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Reformulate\sa\sfor-in\sloop\sto\sa\sfor\sloop\sin\swasm.xWrap()\sto\swork\saround\sa\sdownstream\sframework-level\smisbehavior,\sas\sreported\sin\s[forum:b549992634b55104|forum\spost\sb549992634b55104]. -D 2024-05-09T18:00:14.716 +C Add\sa\smaintenance-reminder\scomment\sexplaining\s[dc58ed65492857]. +D 2024-05-09T18:39:54.271 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -629,7 +629,7 @@ F ext/wasm/c-pp.c 6d80d8569d85713effe8b0818a3cf51dc779e3f0bf8dc88771b8998552ee25 F ext/wasm/common/SqliteTestUtil.js 7adaeffef757d8708418dc9190f72df22367b531831775804b31598b44f6aa51 F ext/wasm/common/emscripten.css 11bd104b6c0d597c67d40cc8ecc0a60dae2b965151e3b6a37fa5708bac3acd15 F ext/wasm/common/testing.css e97549bab24126c24e0daabfe2de9bb478fb0a69fdb2ddd0a73a992c091aad6f -F ext/wasm/common/whwasmutil.js 22a81c8ca81ceb2662db4a73ded2e8bef22300fd8894410fac0ffd45f32da8fd +F ext/wasm/common/whwasmutil.js f7b3461028899b923fb554029a5c980396b02800b742aabb44346dd8704fd11b F ext/wasm/demo-123-worker.html a0b58d9caef098a626a1a1db567076fca4245e8d60ba94557ede8684350a81ed F ext/wasm/demo-123.html 8c70a412ce386bd3796534257935eb1e3ea5c581e5d5aea0490b8232e570a508 F ext/wasm/demo-123.js c7b3cca50c55841c381a9ca4f9396e5bbdc6114273d0b10a43e378e32e7be5bf @@ -2189,8 +2189,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P d030c87c4d410e9ca2b90ec7cb63e752f4490c60e2feac84f233861593142c7d -R 1ce3f637477b3f3b2a8d1fc27a6cb38f +P dc58ed654928574ef254af289bd21c654c587aac80aea36ab96772c35d4ca754 +R 1ed7609111b28491e4b1197daa094882 U stephan -Z 6f5fe3e373ae24dc54ff89790b691517 +Z e11e22686e88a9ceee16613611fcb507 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index bc458de973..ccb12330aa 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -dc58ed654928574ef254af289bd21c654c587aac80aea36ab96772c35d4ca754 \ No newline at end of file +857f5d7fadce1cfe30b3468826f403f736cfecacb1eb6d3b858b01ea3cfd6ffc \ No newline at end of file From 8292aa7a18da4d4f5b927bf396479f460ff6d041 Mon Sep 17 00:00:00 2001 From: stephan Date: Fri, 10 May 2024 09:26:53 +0000 Subject: [PATCH 388/430] Squelch two OMIT-flag-related warnings reported in [forum:388243d9882067a9|forum post 388243d9882067a9]. No functional changes. FossilOrigin-Name: 1d6716054d7fc50df237996c3db30e5fb8e32acbf48cb8b9af472360515945c4 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/sqliteInt.h | 2 ++ src/vdbeaux.c | 4 ++-- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 583b3d98ac..d73b846391 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sa\smaintenance-reminder\scomment\sexplaining\s[dc58ed65492857]. -D 2024-05-09T18:39:54.271 +C Squelch\stwo\sOMIT-flag-related\swarnings\sreported\sin\s[forum:388243d9882067a9|forum\spost\s388243d9882067a9].\sNo\sfunctional\schanges. +D 2024-05-10T09:26:53.619 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -758,7 +758,7 @@ F src/shell.c.in 0354ca51eee5fbf6af394a7ef9f5ef6823ef45b743db65431f6777e4d5be219 F src/sqlite.h.in 32389e0d584551b300d0157881336162c14315a424cbf385c0d65eb7c2e31f7b F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 -F src/sqliteInt.h 4ca38e206befb3738d8cca97b6c6ee56c10f1c5bdb379ac5442d0f1a71b9fefa +F src/sqliteInt.h 2eff008d787b12e76a906fd670dbe478dd1c7f2925fb59768e1f7d81c77a0600 F src/sqliteLimit.h 6878ab64bdeb8c24a1d762d45635e34b96da21132179023338c93f820eee6728 F src/status.c cb11f8589a6912af2da3bb1ec509a94dd8ef27df4d4c1a97e0bcf2309ece972b F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1 @@ -827,7 +827,7 @@ F src/vdbe.c 3b1793c5d2235ae89b01ef051a33d7d2ad3704c71799653b112686735ad401ff F src/vdbe.h c2d78d15112c3fc5ab87f5e8e0b75d2db1c624409de2e858c3d1aafb1650bb4f F src/vdbeInt.h 949669dfd8a41550d27dcb905b494f2ccde9a2e6c1b0b04daa1227e2e74c2b2c F src/vdbeapi.c 80235ac380e9467fec1cb0883354d841f2a771976e766995f7e0c77f845406df -F src/vdbeaux.c 6385727adf51a649e4993098870a62c3945fe21dbc0e0fd9013772aff930b8fb +F src/vdbeaux.c 3bcf13776c39bf660a52b4b97f6389a421c2756f9ffbf4c0d94f73e1935d8d9c F src/vdbeblob.c 13f9287b55b6356b4b1845410382d6bede203ceb29ef69388a4a3d007ffacbe5 F src/vdbemem.c 385c8b89da3b5ef9a468d77a466958aa72ee1212d5cb005f23ec63df1d413054 F src/vdbesort.c 237840ca1947511fa59bd4e18b9eeae93f2af2468c34d2427b059f896230a547 @@ -2189,8 +2189,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P dc58ed654928574ef254af289bd21c654c587aac80aea36ab96772c35d4ca754 -R 1ed7609111b28491e4b1197daa094882 +P 857f5d7fadce1cfe30b3468826f403f736cfecacb1eb6d3b858b01ea3cfd6ffc +R f270cbcd240352fa10729fed65c3c5a2 U stephan -Z e11e22686e88a9ceee16613611fcb507 +Z 06aaa7e94b8e9b6ffd39f925ee912fbc # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index ccb12330aa..a03c415635 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -857f5d7fadce1cfe30b3468826f403f736cfecacb1eb6d3b858b01ea3cfd6ffc \ No newline at end of file +1d6716054d7fc50df237996c3db30e5fb8e32acbf48cb8b9af472360515945c4 \ No newline at end of file diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 0d33f9ee2a..0da289d525 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -5267,7 +5267,9 @@ void sqlite3ErrorWithMsg(sqlite3*, int, const char*,...); void sqlite3Error(sqlite3*,int); void sqlite3ErrorClear(sqlite3*); void sqlite3SystemError(sqlite3*,int); +#if !defined(SQLITE_OMIT_BLOB_LITERAL) void *sqlite3HexToBlob(sqlite3*, const char *z, int n); +#endif u8 sqlite3HexToInt(int h); int sqlite3TwoPartName(Parse *, Token *, Token *, Token **); diff --git a/src/vdbeaux.c b/src/vdbeaux.c index e5c8303435..e4c174e3fb 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -3355,9 +3355,9 @@ int sqlite3VdbeHalt(Vdbe *p){ /* Check for immediate foreign key violations. */ if( p->rc==SQLITE_OK || (p->errorAction==OE_Fail && !isSpecialError) ){ - sqlite3VdbeCheckFk(p, 0); + (void)sqlite3VdbeCheckFk(p, 0); } - + /* If the auto-commit flag is set and this is the only active writer ** VM, then we do either a commit or rollback of the current transaction. ** From 7e60106d150571b8d8dd7f5d056add1d0383e2a0 Mon Sep 17 00:00:00 2001 From: drh <> Date: Fri, 10 May 2024 16:28:35 +0000 Subject: [PATCH 389/430] Add an sqlite3FaultSim(300) call to the sqlite3ParserAddCleanup() routine for more precise simulation of OOM errors in that routine. FossilOrigin-Name: 1e8863909ac369e5e62e82e53b6e5a7cc6794100cef281ede00b0bb9bbc28594 --- manifest | 17 ++++++++++------- manifest.uuid | 2 +- src/prepare.c | 7 ++++++- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index d73b846391..a3741d8008 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Squelch\stwo\sOMIT-flag-related\swarnings\sreported\sin\s[forum:388243d9882067a9|forum\spost\s388243d9882067a9].\sNo\sfunctional\schanges. -D 2024-05-10T09:26:53.619 +C Add\san\ssqlite3FaultSim(300)\scall\sto\sthe\ssqlite3ParserAddCleanup()\sroutine\nfor\smore\sprecise\ssimulation\sof\sOOM\serrors\sin\sthat\sroutine. +D 2024-05-10T16:28:35.966 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -748,7 +748,7 @@ F src/pcache.h 1497ce1b823cf00094bb0cf3bac37b345937e6f910890c626b16512316d3abf5 F src/pcache1.c 602acb23c471bb8d557a6f0083cc2be641d6cafcafa19e481eba7ef4c9ca0f00 F src/pragma.c 52bfbf6dfd668b69b5eb9bd1186e3a67367c8453807150d6e75239229924f684 F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7 -F src/prepare.c 371f6115cb69286ebc12c6f2d7511279c2e47d9f54f475d46a554d687a3b312c +F src/prepare.c 32a8ff049785282acb5fa5cbe5f16ff7b2bfb17e12105606d4371f6f8549640f F src/printf.c 8b250972305e14b365561be5117ed0fd364e4fd58968776df1ce64c6280b90f9 F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c 8816212645e4e9bdf3cc2f2d298304f388d699f8fab47f3a5712ef5bbc5b6ccc @@ -2189,8 +2189,11 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 857f5d7fadce1cfe30b3468826f403f736cfecacb1eb6d3b858b01ea3cfd6ffc -R f270cbcd240352fa10729fed65c3c5a2 -U stephan -Z 06aaa7e94b8e9b6ffd39f925ee912fbc +P 1d6716054d7fc50df237996c3db30e5fb8e32acbf48cb8b9af472360515945c4 +R dbff3b0072db6fdc65663e31e8141b09 +T *branch * cleanup-testing +T *sym-cleanup-testing * +T -sym-trunk * +U drh +Z 3a787a3d44ce577cad9fbd2868c41f20 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index a03c415635..d308dd1551 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1d6716054d7fc50df237996c3db30e5fb8e32acbf48cb8b9af472360515945c4 \ No newline at end of file +1e8863909ac369e5e62e82e53b6e5a7cc6794100cef281ede00b0bb9bbc28594 \ No newline at end of file diff --git a/src/prepare.c b/src/prepare.c index 87569ee91d..80c9fa71a3 100644 --- a/src/prepare.c +++ b/src/prepare.c @@ -633,7 +633,12 @@ void *sqlite3ParserAddCleanup( void (*xCleanup)(sqlite3*,void*), /* The cleanup routine */ void *pPtr /* Pointer to object to be cleaned up */ ){ - ParseCleanup *pCleanup = sqlite3DbMallocRaw(pParse->db, sizeof(*pCleanup)); + ParseCleanup *pCleanup; + if( sqlite3FaultSim(300) ){ + pCleanup = 0; + }else{ + pCleanup = sqlite3DbMallocRaw(pParse->db, sizeof(*pCleanup)); + } if( pCleanup ){ pCleanup->pNext = pParse->pCleanup; pParse->pCleanup = pCleanup; From 0e4afddadfb0843cc1d5acbab8b5affc9e14e106 Mon Sep 17 00:00:00 2001 From: drh <> Date: Fri, 10 May 2024 17:05:24 +0000 Subject: [PATCH 390/430] Improvements to the ".testctrl fault_install" command in the CLI. FossilOrigin-Name: 48b34ded82d0cec8a7dd67431f057b320b8c459b1b78c0fbf79bc2b355e85d4e --- manifest | 15 ++++++--------- manifest.uuid | 2 +- src/shell.c.in | 29 ++++++++++++++++++++++++----- 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/manifest b/manifest index a3741d8008..594fc55a50 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\san\ssqlite3FaultSim(300)\scall\sto\sthe\ssqlite3ParserAddCleanup()\sroutine\nfor\smore\sprecise\ssimulation\sof\sOOM\serrors\sin\sthat\sroutine. -D 2024-05-10T16:28:35.966 +C Improvements\sto\sthe\s".testctrl\sfault_install"\scommand\sin\sthe\sCLI. +D 2024-05-10T17:05:24.627 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -754,7 +754,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c 8816212645e4e9bdf3cc2f2d298304f388d699f8fab47f3a5712ef5bbc5b6ccc F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c ce81687d769b174aa547b8216a34fabc9cafc05789b615494ab78dc2c1e799fa -F src/shell.c.in 0354ca51eee5fbf6af394a7ef9f5ef6823ef45b743db65431f6777e4d5be2199 +F src/shell.c.in 8f2406e4e8d726452e48058d117f52e86b789f47435157b0418fb06c631349b6 F src/sqlite.h.in 32389e0d584551b300d0157881336162c14315a424cbf385c0d65eb7c2e31f7b F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 @@ -2189,11 +2189,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 1d6716054d7fc50df237996c3db30e5fb8e32acbf48cb8b9af472360515945c4 -R dbff3b0072db6fdc65663e31e8141b09 -T *branch * cleanup-testing -T *sym-cleanup-testing * -T -sym-trunk * +P 1e8863909ac369e5e62e82e53b6e5a7cc6794100cef281ede00b0bb9bbc28594 +R 8cf25f7e0890ed58515d4489ba665230 U drh -Z 3a787a3d44ce577cad9fbd2868c41f20 +Z ccce4523fbbf328d3eae15c83868f55f # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index d308dd1551..888c859d2c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1e8863909ac369e5e62e82e53b6e5a7cc6794100cef281ede00b0bb9bbc28594 \ No newline at end of file +48b34ded82d0cec8a7dd67431f057b320b8c459b1b78c0fbf79bc2b355e85d4e \ No newline at end of file diff --git a/src/shell.c.in b/src/shell.c.in index 2f91ac8ba1..2984853442 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -7940,7 +7940,10 @@ static struct { int iCnt; /* Trigger the fault only if iCnt is already zero */ int iInterval; /* Reset iCnt to this value after each fault */ int eVerbose; /* When to print output */ -} faultsim_state = {-1, 0, 0, 0, 0}; + int nHit; /* Number of hits seen so far */ + int nRepeat; /* Turn off after this many hits. 0 for never */ + int nSkip; /* Skip this many before first fault */ +} faultsim_state = {-1, 0, 0, 0, 0, 0, 0}; /* ** This is the fault-sim callback @@ -7949,8 +7952,8 @@ static int faultsim_callback(int iArg){ if( faultsim_state.iId>0 && faultsim_state.iId!=iArg ){ return SQLITE_OK; } - if( faultsim_state.iCnt>0 ){ - faultsim_state.iCnt--; + if( faultsim_state.iCnt ){ + if( faultsim_state.iCnt>0 ) faultsim_state.iCnt--; if( faultsim_state.eVerbose>=2 ){ oputf("FAULT-SIM id=%d no-fault (cnt=%d)\n", iArg, faultsim_state.iCnt); } @@ -7960,6 +7963,10 @@ static int faultsim_callback(int iArg){ oputf("FAULT-SIM id=%d returns %d\n", iArg, faultsim_state.iErr); } faultsim_state.iCnt = faultsim_state.iInterval; + faultsim_state.nHit++; + if( faultsim_state.nRepeat>0 && faultsim_state.nRepeat<=faultsim_state.nHit ){ + faultsim_state.iCnt = -1; + } return faultsim_state.iErr; } @@ -11121,17 +11128,23 @@ static int do_meta_command(char *zLine, ShellState *p){ if( cli_strcmp(z,"off")==0 ){ sqlite3_test_control(testctrl, 0); }else if( cli_strcmp(z,"on")==0 ){ - faultsim_state.iCnt = faultsim_state.iInterval; + faultsim_state.iCnt = faultsim_state.nSkip; if( faultsim_state.iErr==0 ) faultsim_state.iErr = 1; + faultsim_state.nHit = 0; sqlite3_test_control(testctrl, faultsim_callback); }else if( cli_strcmp(z,"reset")==0 ){ - faultsim_state.iCnt = faultsim_state.iInterval; + faultsim_state.iCnt = faultsim_state.nSkip; + faultsim_state.nHit = 0; + sqlite3_test_control(testctrl, faultsim_callback); }else if( cli_strcmp(z,"status")==0 ){ oputf("faultsim.iId: %d\n", faultsim_state.iId); oputf("faultsim.iErr: %d\n", faultsim_state.iErr); oputf("faultsim.iCnt: %d\n", faultsim_state.iCnt); + oputf("faultsim.nHit: %d\n", faultsim_state.nHit); oputf("faultsim.iInterval: %d\n", faultsim_state.iInterval); oputf("faultsim.eVerbose: %d\n", faultsim_state.eVerbose); + oputf("faultsim.nRepeat: %d\n", faultsim_state.nRepeat); + oputf("faultsim.nSkip: %d\n", faultsim_state.nSkip); }else if( cli_strcmp(z,"-v")==0 ){ if( faultsim_state.eVerbose<2 ) faultsim_state.eVerbose++; }else if( cli_strcmp(z,"-q")==0 ){ @@ -11142,6 +11155,10 @@ static int do_meta_command(char *zLine, ShellState *p){ faultsim_state.iErr = atoi(azArg[++kk]); }else if( cli_strcmp(z,"-interval")==0 && kk+1 Date: Fri, 10 May 2024 18:10:34 +0000 Subject: [PATCH 391/430] The sqlite3FaultSim(300) error from [1e8863909ac369e5] must be treated as an OOM, since it simulates an OOM. Also fix deferred deletion of Expr objects from [a53bdd311c4154fd] so that it does not corrupt the AST if an OOM occurs. FossilOrigin-Name: c623d9a51e0ae6b4a8e1186714d14e7aa3df55246e123323481f07f07749dea5 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/expr.c | 14 ++++++-------- src/prepare.c | 1 + src/sqliteInt.h | 2 +- 5 files changed, 17 insertions(+), 18 deletions(-) diff --git a/manifest b/manifest index 594fc55a50..7027d257c0 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improvements\sto\sthe\s".testctrl\sfault_install"\scommand\sin\sthe\sCLI. -D 2024-05-10T17:05:24.627 +C The\ssqlite3FaultSim(300)\serror\sfrom\s[1e8863909ac369e5]\smust\sbe\streated\sas\nan\sOOM,\ssince\sit\ssimulates\san\sOOM.\s\sAlso\sfix\sdeferred\sdeletion\sof\sExpr\sobjects\nfrom\s[a53bdd311c4154fd]\sso\sthat\sit\sdoes\snot\scorrupt\sthe\sAST\sif\san\sOOM\soccurs. +D 2024-05-10T18:10:34.762 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -703,7 +703,7 @@ F src/date.c 126ba2ab10aeb2e7ba6e089b5f07b747c0625b8287f78b60da346eda8d23c875 F src/dbpage.c 80e46e1df623ec40486da7a5086cb723b0275a6e2a7b01d9f9b5da0f04ba2782 F src/dbstat.c 3b677254d512fcafd4d0b341bf267b38b235ccfddbef24f9154e19360fa22e43 F src/delete.c cb766727c78e715f9fb7ec8a7d03658ed2a3016343ca687acfcec9083cdca500 -F src/expr.c 3428b046cb731be83770eaa34317d0ae5bdf8f5e7c3a0abd57528d0a03a8f9f9 +F src/expr.c f7bad20d2f74005f1f876e7fbb627222ea28250e44b296b047403720c5c21818 F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c a47610f0a5c6cb0ad79f8fcef039c01833dec0c751bb695f28dc0ec6a4c3ba00 F src/func.c 283d4f3b2751a1d9339fd93a8a013d1948fd5f4474a3cab0955eb4fafd445d0f @@ -748,7 +748,7 @@ F src/pcache.h 1497ce1b823cf00094bb0cf3bac37b345937e6f910890c626b16512316d3abf5 F src/pcache1.c 602acb23c471bb8d557a6f0083cc2be641d6cafcafa19e481eba7ef4c9ca0f00 F src/pragma.c 52bfbf6dfd668b69b5eb9bd1186e3a67367c8453807150d6e75239229924f684 F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7 -F src/prepare.c 32a8ff049785282acb5fa5cbe5f16ff7b2bfb17e12105606d4371f6f8549640f +F src/prepare.c d99931f45416652895e502328ca49fe782cfc4e1ebdcda13b3736d991ebf42ce F src/printf.c 8b250972305e14b365561be5117ed0fd364e4fd58968776df1ce64c6280b90f9 F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c 8816212645e4e9bdf3cc2f2d298304f388d699f8fab47f3a5712ef5bbc5b6ccc @@ -758,7 +758,7 @@ F src/shell.c.in 8f2406e4e8d726452e48058d117f52e86b789f47435157b0418fb06c631349b F src/sqlite.h.in 32389e0d584551b300d0157881336162c14315a424cbf385c0d65eb7c2e31f7b F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 -F src/sqliteInt.h 2eff008d787b12e76a906fd670dbe478dd1c7f2925fb59768e1f7d81c77a0600 +F src/sqliteInt.h adcf1cebb6fc00fc1f1329c00bb65ac36655736080acfd2071d84aa83a104afe F src/sqliteLimit.h 6878ab64bdeb8c24a1d762d45635e34b96da21132179023338c93f820eee6728 F src/status.c cb11f8589a6912af2da3bb1ec509a94dd8ef27df4d4c1a97e0bcf2309ece972b F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1 @@ -2189,8 +2189,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 1e8863909ac369e5e62e82e53b6e5a7cc6794100cef281ede00b0bb9bbc28594 -R 8cf25f7e0890ed58515d4489ba665230 +P 48b34ded82d0cec8a7dd67431f057b320b8c459b1b78c0fbf79bc2b355e85d4e +R cc5b938e964753c73fb58412e75a41dc U drh -Z ccce4523fbbf328d3eae15c83868f55f +Z 632961c30d31ace9e6d9239d4b43ad92 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 888c859d2c..e1839a2f8f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -48b34ded82d0cec8a7dd67431f057b320b8c459b1b78c0fbf79bc2b355e85d4e \ No newline at end of file +c623d9a51e0ae6b4a8e1186714d14e7aa3df55246e123323481f07f07749dea5 \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index a5272df7c9..27f89d659d 100644 --- a/src/expr.c +++ b/src/expr.c @@ -1443,11 +1443,11 @@ void sqlite3ClearOnOrUsing(sqlite3 *db, OnOrUsing *p){ ** ** The pExpr might be deleted immediately on an OOM error. ** -** The deferred delete is (currently) implemented by adding the -** pExpr to the pParse->pConstExpr list with a register number of 0. +** Return 0 if the delete was successfully deferred. Return non-zero +** if the delete happened immediately because of an OOM. */ -void sqlite3ExprDeferredDelete(Parse *pParse, Expr *pExpr){ - sqlite3ParserAddCleanup(pParse, sqlite3ExprDeleteGeneric, pExpr); +int sqlite3ExprDeferredDelete(Parse *pParse, Expr *pExpr){ + return 0==sqlite3ParserAddCleanup(pParse, sqlite3ExprDeleteGeneric, pExpr); } /* Invoke sqlite3RenameExprUnmap() and sqlite3ExprDelete() on the @@ -6681,9 +6681,8 @@ static int agginfoPersistExprCb(Walker *pWalker, Expr *pExpr){ && pAggInfo->aCol[iAgg].pCExpr==pExpr ){ pExpr = sqlite3ExprDup(db, pExpr, 0); - if( pExpr ){ + if( pExpr && !sqlite3ExprDeferredDelete(pParse, pExpr) ){ pAggInfo->aCol[iAgg].pCExpr = pExpr; - sqlite3ExprDeferredDelete(pParse, pExpr); } } }else{ @@ -6692,9 +6691,8 @@ static int agginfoPersistExprCb(Walker *pWalker, Expr *pExpr){ && pAggInfo->aFunc[iAgg].pFExpr==pExpr ){ pExpr = sqlite3ExprDup(db, pExpr, 0); - if( pExpr ){ + if( pExpr && !sqlite3ExprDeferredDelete(pParse, pExpr) ){ pAggInfo->aFunc[iAgg].pFExpr = pExpr; - sqlite3ExprDeferredDelete(pParse, pExpr); } } } diff --git a/src/prepare.c b/src/prepare.c index 80c9fa71a3..df9c98f743 100644 --- a/src/prepare.c +++ b/src/prepare.c @@ -636,6 +636,7 @@ void *sqlite3ParserAddCleanup( ParseCleanup *pCleanup; if( sqlite3FaultSim(300) ){ pCleanup = 0; + sqlite3OomFault(pParse->db); }else{ pCleanup = sqlite3DbMallocRaw(pParse->db, sizeof(*pCleanup)); } diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 0da289d525..aa8bfc4b7b 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -4856,7 +4856,7 @@ void sqlite3ExprFunctionUsable(Parse*,const Expr*,const FuncDef*); void sqlite3ExprAssignVarNumber(Parse*, Expr*, u32); void sqlite3ExprDelete(sqlite3*, Expr*); void sqlite3ExprDeleteGeneric(sqlite3*,void*); -void sqlite3ExprDeferredDelete(Parse*, Expr*); +int sqlite3ExprDeferredDelete(Parse*, Expr*); void sqlite3ExprUnmapAndDelete(Parse*, Expr*); ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*); ExprList *sqlite3ExprListAppendVector(Parse*,ExprList*,IdList*,Expr*); From e09e451a48f0e1ef74e15b3469f2dd78dee349a8 Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 10 May 2024 18:15:03 +0000 Subject: [PATCH 392/430] Add a test for the fixes on this branch. FossilOrigin-Name: 716088d673b80446ea5f9cb83f6aad8a9ea2ec769d4894e02ab916930e4cf169 --- manifest | 13 +++++++------ manifest.uuid | 2 +- test/exprfault2.test | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 7 deletions(-) create mode 100644 test/exprfault2.test diff --git a/manifest b/manifest index 7027d257c0..0baf00c3f8 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C The\ssqlite3FaultSim(300)\serror\sfrom\s[1e8863909ac369e5]\smust\sbe\streated\sas\nan\sOOM,\ssince\sit\ssimulates\san\sOOM.\s\sAlso\sfix\sdeferred\sdeletion\sof\sExpr\sobjects\nfrom\s[a53bdd311c4154fd]\sso\sthat\sit\sdoes\snot\scorrupt\sthe\sAST\sif\san\sOOM\soccurs. -D 2024-05-10T18:10:34.762 +C Add\sa\stest\sfor\sthe\sfixes\son\sthis\sbranch. +D 2024-05-10T18:15:03.688 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -1115,6 +1115,7 @@ F test/exists.test 79a75323c78f02bbe9c251ea502a092f9ef63dac F test/expr.test 5c06696478212e5a04e04b043f993373f6f8e5ce5a80f5548a84703b123b6caa F test/expr2.test c27327ae9c017a7ff6280123f67aff496f912da74d78c888926d68b46ec75fd8 F test/exprfault.test da33606d799718e2f8e34efd0e5858884a1ad87f608774c552a7f5517cc27181 +F test/exprfault2.test c49e84273898969af5dbc4fe6a3f4335f14639799f343590336c9ddf84425965 F test/extension01.test 00d13cec817f331a687a243e0e5a2d87b0e358c9 F test/external_reader.test c7d34694f1b25c32d866f56ac80c1e29edddc42b4ef90cad589263ffac2cde0c F test/extraquick.test cb254400bd42bfb777ff675356aabf3287978f79 @@ -2189,8 +2190,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 48b34ded82d0cec8a7dd67431f057b320b8c459b1b78c0fbf79bc2b355e85d4e -R cc5b938e964753c73fb58412e75a41dc -U drh -Z 632961c30d31ace9e6d9239d4b43ad92 +P c623d9a51e0ae6b4a8e1186714d14e7aa3df55246e123323481f07f07749dea5 +R 19835e40d33408ef0911b62a1ca97162 +U dan +Z 94556ae52ccd512ae4690e06866d27a0 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index e1839a2f8f..465515fa0d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c623d9a51e0ae6b4a8e1186714d14e7aa3df55246e123323481f07f07749dea5 \ No newline at end of file +716088d673b80446ea5f9cb83f6aad8a9ea2ec769d4894e02ab916930e4cf169 \ No newline at end of file diff --git a/test/exprfault2.test b/test/exprfault2.test new file mode 100644 index 0000000000..acbead59f6 --- /dev/null +++ b/test/exprfault2.test @@ -0,0 +1,35 @@ +# 2024-05-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. +# +#*********************************************************************** +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix exprfault2 + +do_execsql_test 1.0 { + CREATE TABLE t1(a,b,c,d,f,PRIMARY KEY(b,b)); + CREATE TABLE t2(x INT PRIMARY KEY, y, z); + CREATE TABLE t3(a,b,c,d,e,PRIMARY KEY(a,b))WITHOUT ROWID; +} +faultsim_save_and_close + + +do_faultsim_test 1 -faults oom-t* -prep { + faultsim_restore_and_reopen +} -body { + execsql { + UPDATE t3 SET (d,d,d,d, a )=(SELECT EXISTS(SELECT 1 NOT IN(SELECT EXISTS(SELECT 1 IN(SELECT max( 1 IN(SELECT x ORDER BY 1)) OVER(PARTITION BY sum((SELECT y FROM t2 UNION SELECT (SELECT max( 1 IN(SELECT x NOT IN(SELECT 1 NOT IN(SELECT EXISTS(SELECT 1 IN(SELECT max( 1 IN(SELECT x ORDER BY 1)) OVER(PARTITION BY sum((SELECT y FROM t2 UNION SELECT (SELECT max( (SELECT x NOT IN(SELECT 1 NOT IN(SELECT EXISTS(SELECT 1 IN(SELECT max( 1 IN(SELECT x ORDER BY 1)) OVER(PARTITION BY sum((SELECT y FROM t2 UNION SELECT (SELECT max( 1 IN(SELECT x ORDER BY 1)) OVER(PARTITION BY sum((SELECT y FROM t2 UNION SELECT x ORDER BY 1)))INTERSECT SELECT (SELECT 1 FROM t2 UNION SELECT d ORDER BY 1) ORDER BY 1) ORDERa)| (SELECT 1 x ORDER BY 1)))INTERSECT SELECT EXISTS(SELECT 1 FROM t2 UNION SELECT d ORDER BY 1) ORDER BY 1) a)| (SELECT 1 IN(SELECT max( 1 IN(SELECT x ORDER BY 1)) OVER(ORDER BY sum((SELECT DISTINCT y FROM t2 UNION SELECT x ORDER BY 1)))INTERSECT SELECT EXISTS(SELECT 1 FROM t2 UNION SELECT x ORDER BY 1) ORDER BY 1) z)|9 AS blob) IN(SELECT max( 1 IN(SELECT x ORDER BY 1)) OVER(PARTITION BY sum((SELECT DISTINCT y FROM t2 UNION SELECT x ORDER BY 1)))EXCEPT SELECT EXISTS(SELECT 1 FROM t2 UNION SELECT d ORDER BY 1) ORDER BY 1) z) ORDER BY 1) IN(SELECT x ORDER BY 1)) OVER(PARTITION BY sum((SELECT DISTINCT y FROM t2 UNION SELECT x ORDER BY 1)))INTERSECT SELECT (SELECT 1 FROM t2 UNION SELECT d ORDER BY 1) ORDER BY 1) ORDERa)| (SELECT 1 x ORDER BY 1)))EXCEPT SELECT EXISTS(SELECT 1 FROM t2 UNION SELECT d ORDER BY 1) ORDER BY 1) a)| (SELECT 1 IN(SELECT max( 1 IN(SELECT x ORDER BY 1)) OVER(PARTITION BY sum((SELECT DISTINCT y FROM t2 UNION SELECT x ORDER BY 1)))INTERSECT SELECT EXISTS(SELECT 1 FROM t2 UNION SELECT x ORDER BY 1) ORDER BY 1) z)|9 AS blob) IN(SELECT max( 1 IN(SELECT x ORDER BY 1)) OVER(PARTITION BY sum((SELECT DISTINCT y FROM t2 UNION SELECT x ORDER BY 1)))EXCEPT SELECT EXISTS(SELECT 1 FROM t2 UNION SELECT d ORDER BY 1) ORDER BY 1) z) ORDER BY 1)) OVER(PARTITION BY sum((SELECT y FROM t2 UNION SELECT x ORDER BY 1)))INTERSECT SELECT EXISTS(SELECT 1 FROM t2 UNION SELECT d ORDER BY 1) ORDER BY 1) ORDERa)| (SELECT 1 x ORDER BY 1)))INTERSECT SELECT EXISTS(SELECT 5 FROM t2 UNION SELECT d ORDER BY 1) ORDER BY 1) ORDERa)| (SELECT 1 IN(SELECT max( 1 IN(SELECT x ORDER BY 1)) OVER(ORDER BY sum((SELECT DISTINCT y FROM t2 UNION SELECT x ORDER BY 1)))INTERSECT SELECT EXISTS(SELECT 1 FROM t2 UNION SELECT x ORDER BY 1) ORDER BY 1) z)| 1 AS blob) IN(SELECT max( 1 IN(SELECT x ORDER BY 1)) OVER(PARTITION BY sum((SELECT DISTINCT y FROM t2 UNION SELECT x ORDER BY 1)))INTERSECT SELECT EXISTS(SELECT 1 FROM t2 UNION SELECT d ORDER BY 1) ORDER BY 1) z)| (SELECT 1 IN(SELECT max( 1 IN(SELECT c ORDER BY 1)) OVER(PARTITION BY sum((SELECT y FROM t2 UNION SELECT x ORDER BY 1)))INTERSECT SELECT (SELECT 1 FROM t2 UNION SELECT x ORDER BY 1) ORDER BY 1) e)|9 AS blob) FROM t2 WHERE a Date: Sat, 11 May 2024 16:44:56 +0000 Subject: [PATCH 393/430] Add tests to bestindexC.test. No changes to code. FossilOrigin-Name: 58d938c0e03c3c8d8796c537f89e69734ba6263d60ba37e345259cb6fdffbea5 --- manifest | 15 +++++++-------- manifest.uuid | 2 +- test/bestindexC.test | 19 +++++++++++++++++++ 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index eceb5d9184..1c2904f809 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\saggregate\sfunction\sprocessing\sto\scorrectly\sdeal\swith\sOOMs\sinside\sof\nsqlite3ParserAddCleanup().\s\n(dbsqlfuzz\sb2d11ca70e55ee8bde48ae0b53fa3e9355812f95).\nAlso\sadd\simproved\stesting\ssupport\sby\scausing\ssqlite3FaultSim(300)\sto\nsimulate\san\sOOM\sinside\sof\ssqlite3ParserAddCleanup()\sand\sby\sadding\nimproved\sfault-sim\ssupport\sto\sthe\sCLI. -D 2024-05-10T18:24:15.938 +C Add\stests\sto\sbestindexC.test.\sNo\schanges\sto\scode. +D 2024-05-11T16:44:56.528 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -938,7 +938,7 @@ F test/bestindex8.test b63a4f171a2c83d481bb14c431a8b72e85d27b2ffdaa0435a95d58ca9 F test/bestindex9.test 1a4b93db117fd8abe74ae9be982f86aa72f01e60cd4ac541e6ede39673a451a0 F test/bestindexA.test e1b5def6b190797cacf008e6815ffb78fb30261999030d60a728d572eef44c7f F test/bestindexB.test 328b97b69cd1a20928d5997f9ecb04d2e00f1d18e19ab27f9e9adb44d7bc51ce -F test/bestindexC.test c14a8c8639b6825b0efa1ae693f34ec04f41a46e3056e7063d6e0f46bf4ff692 +F test/bestindexC.test a2d4ab909e17bb58fe4d66a394460e713620c7b2964b450bc82216c171d264a2 F test/between.test b9a65fb065391980119e8a781a7409d3fcf059d89968279c750e190a9a1d5263 F test/bigfile.test aa74f4e5db51c8e54a1d9de9fa65d01d1eb20b59 F test/bigfile2.test 1b489a3a39ae90c7f027b79110d6b4e1dbc71bfc @@ -2190,9 +2190,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 1d6716054d7fc50df237996c3db30e5fb8e32acbf48cb8b9af472360515945c4 716088d673b80446ea5f9cb83f6aad8a9ea2ec769d4894e02ab916930e4cf169 -R 19835e40d33408ef0911b62a1ca97162 -T +closed 716088d673b80446ea5f9cb83f6aad8a9ea2ec769d4894e02ab916930e4cf169 -U drh -Z 7c60328ccced7c5397c63b972a68b6fa +P c6fd70b3c23fa00eaac9286d4a67e5c8ac76f926c11c220250c34032647bedc1 +R da518a0d510ea768080aa36a2357bedd +U dan +Z 00211d5eb53202476ca10f2c5f60b56e # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index b3549e902d..1e5e1fe061 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c6fd70b3c23fa00eaac9286d4a67e5c8ac76f926c11c220250c34032647bedc1 \ No newline at end of file +58d938c0e03c3c8d8796c537f89e69734ba6263d60ba37e345259cb6fdffbea5 \ No newline at end of file diff --git a/test/bestindexC.test b/test/bestindexC.test index 476ea39faa..708e56f774 100644 --- a/test/bestindexC.test +++ b/test/bestindexC.test @@ -173,6 +173,25 @@ do_execsql_test 3.6 { } {4 5 6 7 8} unset ::do_not_use_offset +#------------------------------------------------------------------------- +reset_db +proc vtab_command {lVal method args} { + switch -- $method { + xConnect { + error "not happy!" + } + } + + return {} +} + +register_tcl_module db +do_catchsql_test 4.0 { + CREATE VIRTUAL TABLE y1 USING tcl(vtab_command 1); +} {1 {not happy!}} +do_test 4.1 { + sqlite3_errcode db +} SQLITE_ERROR finish_test From 9a1a4822e8f7d7483d71733ecf13d0d1e3e2335f Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 15 May 2024 15:06:27 +0000 Subject: [PATCH 394/430] If there is no data available for a field in a corrupted record, but the type is available, have the recovery extension substitute 0, 0.0, '' or X'' instead of a NULL value. FossilOrigin-Name: 8eb326c24981647e2df90e4b9d75db52a552bd997bd821f5898c7ff3fb93a57d --- ext/recover/dbdata.c | 118 +++++++++++++++++-------------- ext/recover/recover1.test | 15 +++- ext/recover/recovercorrupt4.test | 58 +++++++++++++++ manifest | 15 ++-- manifest.uuid | 2 +- 5 files changed, 145 insertions(+), 63 deletions(-) create mode 100644 ext/recover/recovercorrupt4.test diff --git a/ext/recover/dbdata.c b/ext/recover/dbdata.c index 1905e68813..a999f1a853 100644 --- a/ext/recover/dbdata.c +++ b/ext/recover/dbdata.c @@ -466,63 +466,75 @@ static void dbdataValue( u8 *pData, sqlite3_int64 nData ){ - if( eType>=0 && dbdataValueBytes(eType)<=nData ){ - switch( eType ){ - case 0: - case 10: - case 11: - sqlite3_result_null(pCtx); - break; - - case 8: - sqlite3_result_int(pCtx, 0); - break; - case 9: - sqlite3_result_int(pCtx, 1); - break; - - case 1: case 2: case 3: case 4: case 5: case 6: case 7: { - sqlite3_uint64 v = (signed char)pData[0]; - pData++; - switch( eType ){ - case 7: - case 6: v = (v<<16) + (pData[0]<<8) + pData[1]; pData += 2; - case 5: v = (v<<16) + (pData[0]<<8) + pData[1]; pData += 2; - case 4: v = (v<<8) + pData[0]; pData++; - case 3: v = (v<<8) + pData[0]; pData++; - case 2: v = (v<<8) + pData[0]; pData++; - } - - if( eType==7 ){ - double r; - memcpy(&r, &v, sizeof(r)); - sqlite3_result_double(pCtx, r); - }else{ - sqlite3_result_int64(pCtx, (sqlite3_int64)v); + if( eType>=0 ){ + if( dbdataValueBytes(eType)<=nData ){ + switch( eType ){ + case 0: + case 10: + case 11: + sqlite3_result_null(pCtx); + break; + + case 8: + sqlite3_result_int(pCtx, 0); + break; + case 9: + sqlite3_result_int(pCtx, 1); + break; + + case 1: case 2: case 3: case 4: case 5: case 6: case 7: { + sqlite3_uint64 v = (signed char)pData[0]; + pData++; + switch( eType ){ + case 7: + case 6: v = (v<<16) + (pData[0]<<8) + pData[1]; pData += 2; + case 5: v = (v<<16) + (pData[0]<<8) + pData[1]; pData += 2; + case 4: v = (v<<8) + pData[0]; pData++; + case 3: v = (v<<8) + pData[0]; pData++; + case 2: v = (v<<8) + pData[0]; pData++; + } + + if( eType==7 ){ + double r; + memcpy(&r, &v, sizeof(r)); + sqlite3_result_double(pCtx, r); + }else{ + sqlite3_result_int64(pCtx, (sqlite3_int64)v); + } + break; } - break; - } - - default: { - int n = ((eType-12) / 2); - if( eType % 2 ){ - switch( enc ){ -#ifndef SQLITE_OMIT_UTF16 - case SQLITE_UTF16BE: - sqlite3_result_text16be(pCtx, (void*)pData, n, SQLITE_TRANSIENT); - break; - case SQLITE_UTF16LE: - sqlite3_result_text16le(pCtx, (void*)pData, n, SQLITE_TRANSIENT); - break; -#endif - default: - sqlite3_result_text(pCtx, (char*)pData, n, SQLITE_TRANSIENT); - break; + + default: { + int n = ((eType-12) / 2); + if( eType % 2 ){ + switch( enc ){ + #ifndef SQLITE_OMIT_UTF16 + case SQLITE_UTF16BE: + sqlite3_result_text16be(pCtx, (void*)pData, n, SQLITE_TRANSIENT); + break; + case SQLITE_UTF16LE: + sqlite3_result_text16le(pCtx, (void*)pData, n, SQLITE_TRANSIENT); + break; + #endif + default: + sqlite3_result_text(pCtx, (char*)pData, n, SQLITE_TRANSIENT); + break; + } + }else{ + sqlite3_result_blob(pCtx, pData, n, SQLITE_TRANSIENT); } - }else{ - sqlite3_result_blob(pCtx, pData, n, SQLITE_TRANSIENT); } } + }else{ + if( eType==7 ){ + sqlite3_result_double(pCtx, 0.0); + }else if( eType<7 ){ + sqlite3_result_int(pCtx, 0); + }else if( eType%2 ){ + sqlite3_result_text(pCtx, "", 0, SQLITE_STATIC); + }else{ + sqlite3_result_blob(pCtx, "", 0, SQLITE_STATIC); + } } } } diff --git a/ext/recover/recover1.test b/ext/recover/recover1.test index 070dd03d69..11a43780d9 100644 --- a/ext/recover/recover1.test +++ b/ext/recover/recover1.test @@ -342,7 +342,7 @@ foreach enc {utf8 utf16 utf16le utf16be} { DELETE FROM sqlite_schema WHERE name='t1'; } - proc my_sql_hook {sql} { + proc my_sql_hook2 {sql} { if {[string match "INSERT INTO lostandfound*" $sql]} { lappend ::script $sql } @@ -350,7 +350,7 @@ foreach enc {utf8 utf16 utf16le utf16be} { } do_test 18.$enc.2 { set ::script [list] - set R [sqlite3_recover_init_sql db main my_sql_hook] + set R [sqlite3_recover_init_sql db main my_sql_hook2] $R config lostandfound lostandfound $R run $R finish @@ -358,7 +358,18 @@ foreach enc {utf8 utf16 utf16le utf16be} { } {{INSERT INTO lostandfound VALUES(2, 2, 2, 1, 'abc', 'def')}} } +#------------------------------------------------------------------------- +reset_db +do_execsql_test 19.0 { + CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT); + INSERT INTO t1 VALUES(1, 'one'); + INSERT INTO t1 VALUES(2, 'two'); + + ALTER TABLE t1 ADD COLUMN c NOT NULL DEFAULT 13; + INSERT INTO t1 VALUES(3, 'three', 'hello world'); +} +do_recover_test 19.1 diff --git a/ext/recover/recovercorrupt4.test b/ext/recover/recovercorrupt4.test new file mode 100644 index 0000000000..53d691fbc4 --- /dev/null +++ b/ext/recover/recovercorrupt4.test @@ -0,0 +1,58 @@ +# 2024 May 15 +# +# 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]] recover_common.tcl] +set testprefix recovercorrupt4 + +database_may_be_corrupt + +do_execsql_test 1.0 { + CREATE TABLE rows(indexed INTEGER NOT NULL, unindexed INTEGER NOT NULL, filler BLOB NOT NULL DEFAULT 13); + -- CREATE UNIQUE INDEX rows_index ON rows(indexed); + INSERT INTO rows(indexed, unindexed, filler) VALUES(1, 1, x'31'); + INSERT INTO rows(indexed, unindexed, filler) VALUES(2, 2, x'32'); + INSERT INTO rows(indexed, unindexed, filler) VALUES(4, 4, x'34'); + INSERT INTO rows(indexed, unindexed, filler) VALUES(8, 8, randomblob(2048)); +} + +db close + +do_test 1.1 { + set sz [expr [file size test.db] - 1024] + set fd [open test.db] + fconfigure $fd -encoding binary -translation binary + + set data [read $fd $sz] + set fd2 [open test.db2 w] + fconfigure $fd2 -encoding binary -translation binary + puts -nonewline $fd2 $data + close $fd2 + set {} {} +} {} + +do_test 1.2 { + forcedelete test.db3 + sqlite3 db test.db2 + set R [sqlite3_recover_init db main test.db3] + $R run + $R finish +} {} + +do_test 1.3 { + sqlite3 db test.db3 + execsql { + SELECT indexed, unindexed FROM rows + } +} {1 1 2 2 4 4 8 8} + +finish_test + diff --git a/manifest b/manifest index 1c2904f809..78d7bf26c8 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\stests\sto\sbestindexC.test.\sNo\schanges\sto\scode. -D 2024-05-11T16:44:56.528 +C If\sthere\sis\sno\sdata\savailable\sfor\sa\sfield\sin\sa\scorrupted\srecord,\sbut\sthe\stype\sis\savailable,\shave\sthe\srecovery\sextension\ssubstitute\s0,\s0.0,\s''\sor\sX''\sinstead\sof\sa\sNULL\svalue. +D 2024-05-15T15:06:27.777 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -478,14 +478,15 @@ F ext/rbu/rbuvacuum4.test ffccd22f67e2d0b380d2889685742159dfe0d19a3880ca3d2d1d69 F ext/rbu/sqlite3rbu.c 4a3376c0fb9a844a799ac529fb81260523f6b13c9f629bc270c632dbae5fc1f8 F ext/rbu/sqlite3rbu.h 9d923eb135c5d04aa6afd7c39ca47b0d1d0707c100e02f19fdde6a494e414304 F ext/rbu/test_rbu.c ee6ede75147bc081fe9bc3931e6b206277418d14d3fbceea6fdc6216d9b47055 -F ext/recover/dbdata.c e518c1a221a259a1ea594d9db8fce356861bfa450e6f54eda999242b9bd5c50a -F ext/recover/recover1.test c484d01502239f11b61f23c1cee9f5dd19fa17617f8974e42e74d64639c524cf +F ext/recover/dbdata.c 0a943861ec096de375097e0aaff07b480a002eab9b01fecd3f9e828faf4ef624 +F ext/recover/recover1.test e16d78e94183562abff569967b18b7c77451d7044365516cd0fe14713a284851 F ext/recover/recover_common.tcl a61306c1eb45c0c3fc45652c35b2d4ec19729e340bdf65a272ce4c229cefd85a F ext/recover/recoverbuild.test c74170e0f7b02456af41838afeb5353fdb985a48cc2331d661bbabbca7c6b8e3 F ext/recover/recoverclobber.test 3ba6c0c373c5c63d17e82eced64c05c57ccaf26c1abe1ca7141334022a79f32e F ext/recover/recovercorrupt.test 64c081ad1200ae77b447da99eb724785d6bf71715f394543dc7689642e92bf49 F ext/recover/recovercorrupt2.test 1418f1710debc24ff38276cedfcea234beb37a34205708e7e3e6d76cc4a979db F ext/recover/recovercorrupt3.test 2e7b9a1b528ca23ed382cec6f64e3fcbbd0f8e852add7562397fd8df83f335d5 +F ext/recover/recovercorrupt4.test 8990c3a76da616b938e800cd2b40eb1f7adf9352624966ba0af0303c7a015f00 F ext/recover/recoverfault.test 9d9f88eeb222615a25e7514f234c950d46bee20d24cd8db49d8fff8d650dcfe1 F ext/recover/recoverfault2.test 730e7371bcda769554d15460cb23126abba1be8eca9539ccabf63623e7bb7e09 F ext/recover/recoverold.test 68db3d6f85dd2b98e785b6c4da4f5eea4bbe52ccf6674d9a94c7506dc92596aa @@ -2190,8 +2191,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P c6fd70b3c23fa00eaac9286d4a67e5c8ac76f926c11c220250c34032647bedc1 -R da518a0d510ea768080aa36a2357bedd +P 58d938c0e03c3c8d8796c537f89e69734ba6263d60ba37e345259cb6fdffbea5 +R cd015e2f2734629b19947eb11f0220ff U dan -Z 00211d5eb53202476ca10f2c5f60b56e +Z be5ac0bdafce0ff1c422be3037819109 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 1e5e1fe061..205cf17a54 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -58d938c0e03c3c8d8796c537f89e69734ba6263d60ba37e345259cb6fdffbea5 \ No newline at end of file +8eb326c24981647e2df90e4b9d75db52a552bd997bd821f5898c7ff3fb93a57d \ No newline at end of file From 1550771a6ad4b5a16ed5b2d2f3d8f6d57c0d70a7 Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 15 May 2024 21:38:04 +0000 Subject: [PATCH 395/430] Fix a case where an error in the ORDER BY clause of an aggregate function that is part of a trigger body might cause an assert() to fail in an ALTER TABLE command. FossilOrigin-Name: b79a8be37b44c1eff7d00f7af7cd9d0e13614ce5961bb88ddb9ec63f6a846c78 --- manifest | 17 ++++++++++------- manifest.uuid | 2 +- src/resolve.c | 4 +--- test/altertab2.test | 22 ++++++++++++++++++++++ 4 files changed, 34 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 78d7bf26c8..5ee97b85cd 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C If\sthere\sis\sno\sdata\savailable\sfor\sa\sfield\sin\sa\scorrupted\srecord,\sbut\sthe\stype\sis\savailable,\shave\sthe\srecovery\sextension\ssubstitute\s0,\s0.0,\s''\sor\sX''\sinstead\sof\sa\sNULL\svalue. -D 2024-05-15T15:06:27.777 +C Fix\sa\scase\swhere\san\serror\sin\sthe\sORDER\sBY\sclause\sof\san\saggregate\sfunction\sthat\sis\spart\sof\sa\strigger\sbody\smight\scause\san\sassert()\sto\sfail\sin\san\sALTER\sTABLE\scommand. +D 2024-05-15T21:38:04.100 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -752,7 +752,7 @@ F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7 F src/prepare.c d99931f45416652895e502328ca49fe782cfc4e1ebdcda13b3736d991ebf42ce F src/printf.c 8b250972305e14b365561be5117ed0fd364e4fd58968776df1ce64c6280b90f9 F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c -F src/resolve.c 8816212645e4e9bdf3cc2f2d298304f388d699f8fab47f3a5712ef5bbc5b6ccc +F src/resolve.c 6adf4bf10151bca046f3206ae8ff07dbf90b49de20bea49197f010276f5f494d F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c ce81687d769b174aa547b8216a34fabc9cafc05789b615494ab78dc2c1e799fa F src/shell.c.in 8f2406e4e8d726452e48058d117f52e86b789f47435157b0418fb06c631349b6 @@ -870,7 +870,7 @@ F test/altermalloc2.test 17fb3724c4b004c469c27dc4ef181608aa644555fbd3f3236767584 F test/altermalloc3.test 8040e486368403f2fdd6fc3998258b499bd4cc2f3ddbb5f8f874cd436f076e81 F test/alterqf.test 8ec03d776de9c391daa0078ea8f838903bdcfb11dfae4ba3576b48436834ccba F test/altertab.test 8a2712f9076da5012a002d0b5cc0a421398a5bf61c25bab41b77c427586a7a27 -F test/altertab2.test 62597b6fd08feaba1b6bfe7d31dac6117c67e06dc9ce9c478a3abe75b5926de0 +F test/altertab2.test fff90e3f01e8eb0e09282f538b8ec7cfeb035dbedbe570fe1983440f4613ad0e F test/altertab3.test b331ae34e69594e19605e3297805202d6156fcc8f75379dfd972a2e51cae8721 F test/altertrig.test aacc980b657354fe2d3d4d3a004f07d04ccc1a93e5ef82d68a79088c274ddc6b F test/amatch1.test b5ae7065f042b7f4c1c922933f4700add50cdb9f @@ -2191,8 +2191,11 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 58d938c0e03c3c8d8796c537f89e69734ba6263d60ba37e345259cb6fdffbea5 -R cd015e2f2734629b19947eb11f0220ff +P 8eb326c24981647e2df90e4b9d75db52a552bd997bd821f5898c7ff3fb93a57d +R 0bf8213edb19e5bc165e2308c6d79a06 +T *branch * alter-table-fix +T *sym-alter-table-fix * +T -sym-trunk * U dan -Z be5ac0bdafce0ff1c422be3037819109 +Z c2a36fdf7fb0d25294933bfa681979d4 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 205cf17a54..b79cfa76c6 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8eb326c24981647e2df90e4b9d75db52a552bd997bd821f5898c7ff3fb93a57d \ No newline at end of file +b79a8be37b44c1eff7d00f7af7cd9d0e13614ce5961bb88ddb9ec63f6a846c78 \ No newline at end of file diff --git a/src/resolve.c b/src/resolve.c index 898c78654c..546731afe5 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -1281,11 +1281,9 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){ #endif } } -#ifndef SQLITE_OMIT_WINDOWFUNC - else if( ExprHasProperty(pExpr, EP_WinFunc) ){ + else if( ExprHasProperty(pExpr, EP_WinFunc) || pExpr->pLeft ){ is_agg = 1; } -#endif sqlite3WalkExprList(pWalker, pList); if( is_agg ){ if( pExpr->pLeft ){ diff --git a/test/altertab2.test b/test/altertab2.test index def9e56686..576dc49670 100644 --- a/test/altertab2.test +++ b/test/altertab2.test @@ -360,4 +360,26 @@ do_catchsql_test 8.6 { SELECT sql FROM sqlite_master WHERE name='i0'; } {1 {error in index i0: second argument to likelihood() must be a constant between 0.0 and 1.0}} + +reset_db + +do_execsql_test 9.0 { + CREATE TABLE t1(a,b,c,d); + CREATE TABLE t2(a,b,c,d,x); + + CREATE TRIGGER AFTER INSERT ON t2 BEGIN + + SELECT group_conct( + 123 ORDER BY ( + SELECT 1 FROM ( VALUES(a, 'b'), ('c') ) + )) + FROM t1; + + END; +} + +do_catchsql_test 9.1 { + ALTER TABLE t2 RENAME TO newname; +} {1 {error in trigger AFTER: all VALUES must have the same number of terms}} + finish_test From 61f2ee6ab88dbc230b6c95af7d731327ddb727ce Mon Sep 17 00:00:00 2001 From: drh <> Date: Wed, 15 May 2024 23:36:24 +0000 Subject: [PATCH 396/430] Back out the assert() fixes from [a9443dbfbe25e588] and [3afaeac56dff58db] (but keep the corresponding test cases) because they are both made obsolete by the previous fix on this branch. FossilOrigin-Name: 3120c7c8a3565b8a3ca321129c09db96839c2f9af1777fc7a1668fef81973603 --- manifest | 17 +++++++---------- manifest.uuid | 2 +- src/select.c | 6 ++---- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/manifest b/manifest index 5ee97b85cd..9e0cc7c88b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\scase\swhere\san\serror\sin\sthe\sORDER\sBY\sclause\sof\san\saggregate\sfunction\sthat\sis\spart\sof\sa\strigger\sbody\smight\scause\san\sassert()\sto\sfail\sin\san\sALTER\sTABLE\scommand. -D 2024-05-15T21:38:04.100 +C Back\sout\sthe\sassert()\sfixes\sfrom\s[a9443dbfbe25e588]\sand\n[3afaeac56dff58db]\s(but\skeep\sthe\scorresponding\stest\scases)\sbecause\sthey\nare\sboth\smade\sobsolete\sby\sthe\sprevious\sfix\son\sthis\sbranch. +D 2024-05-15T23:36:24.437 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -754,7 +754,7 @@ F src/printf.c 8b250972305e14b365561be5117ed0fd364e4fd58968776df1ce64c6280b90f9 F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c 6adf4bf10151bca046f3206ae8ff07dbf90b49de20bea49197f010276f5f494d F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 -F src/select.c ce81687d769b174aa547b8216a34fabc9cafc05789b615494ab78dc2c1e799fa +F src/select.c 1a841c38974d45cf15a7611398479182b61ad4c187423c380741d8b1688fe607 F src/shell.c.in 8f2406e4e8d726452e48058d117f52e86b789f47435157b0418fb06c631349b6 F src/sqlite.h.in 32389e0d584551b300d0157881336162c14315a424cbf385c0d65eb7c2e31f7b F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 @@ -2191,11 +2191,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 8eb326c24981647e2df90e4b9d75db52a552bd997bd821f5898c7ff3fb93a57d -R 0bf8213edb19e5bc165e2308c6d79a06 -T *branch * alter-table-fix -T *sym-alter-table-fix * -T -sym-trunk * -U dan -Z c2a36fdf7fb0d25294933bfa681979d4 +P b79a8be37b44c1eff7d00f7af7cd9d0e13614ce5961bb88ddb9ec63f6a846c78 +R 91267a6a1982f21ea275bc49553555c1 +U drh +Z d62affd8eb7ffd4672ed09ea764a6e2a # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index b79cfa76c6..ffce3cc964 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b79a8be37b44c1eff7d00f7af7cd9d0e13614ce5961bb88ddb9ec63f6a846c78 \ No newline at end of file +3120c7c8a3565b8a3ca321129c09db96839c2f9af1777fc7a1668fef81973603 \ No newline at end of file diff --git a/src/select.c b/src/select.c index 532fbd19e5..9278ea18b8 100644 --- a/src/select.c +++ b/src/select.c @@ -2324,8 +2324,7 @@ void sqlite3SubqueryColumnTypes( NameContext sNC; assert( pSelect!=0 ); - testcase( (pSelect->selFlags & SF_Resolved)==0 ); - assert( (pSelect->selFlags & SF_Resolved)!=0 || IN_RENAME_OBJECT ); + assert( (pSelect->selFlags & SF_Resolved)!=0 ); assert( pTab->nCol==pSelect->pEList->nExpr || pParse->nErr>0 ); assert( aff==SQLITE_AFF_NONE || aff==SQLITE_AFF_BLOB ); if( db->mallocFailed || IN_RENAME_OBJECT ) return; @@ -6412,8 +6411,7 @@ static void selectAddSubqueryTypeInfo(Walker *pWalker, Select *p){ if( p->selFlags & SF_HasTypeInfo ) return; p->selFlags |= SF_HasTypeInfo; pParse = pWalker->pParse; - testcase( (p->selFlags & SF_Resolved)==0 ); - assert( (p->selFlags & SF_Resolved) || IN_RENAME_OBJECT ); + assert( (p->selFlags & SF_Resolved) ); pTabList = p->pSrc; for(i=0, pFrom=pTabList->a; inSrc; i++, pFrom++){ Table *pTab = pFrom->pTab; From c72953a4bc68c5716c224e714557d59fe3d91df4 Mon Sep 17 00:00:00 2001 From: drh <> Date: Thu, 16 May 2024 15:57:42 +0000 Subject: [PATCH 397/430] The sqlite3_declare_vtab() interface should return SQLITE_ERROR, not SQLITE_MISUSE when a nonsense SQL input is provided, for legacy compatibility. [forum:/forumpost/4b875d7b2a|Forum post 4b875d7b2a]. FossilOrigin-Name: 1ec2961a0341619ae88832942b52606b3246fc0de07ca6da0300e4bfc656ecf0 --- manifest | 13 ++++++------- manifest.uuid | 2 +- src/vtab.c | 5 ++++- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 8bc618777b..6365b053b1 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\scase\swhere\san\serror\sin\sthe\sORDER\sBY\sclause\sof\san\saggregate\sfunction\sthat\sis\spart\sof\sa\strigger\sbody\smight\scause\san\sassert()\sto\sfail\sin\san\sALTER\sTABLE\scommand.\s\sdbsqlfuzz\s899d9255555a07f1fe11a0bb51a2fe197b3150cd -D 2024-05-16T00:20:43.867 +C The\ssqlite3_declare_vtab()\sinterface\sshould\sreturn\sSQLITE_ERROR,\snot\nSQLITE_MISUSE\swhen\sa\snonsense\sSQL\sinput\sis\sprovided,\sfor\slegacy\scompatibility.\n[forum:/forumpost/4b875d7b2a|Forum\spost\s4b875d7b2a]. +D 2024-05-16T15:57:42.281 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -834,7 +834,7 @@ F src/vdbemem.c 385c8b89da3b5ef9a468d77a466958aa72ee1212d5cb005f23ec63df1d413054 F src/vdbesort.c 237840ca1947511fa59bd4e18b9eeae93f2af2468c34d2427b059f896230a547 F src/vdbetrace.c fe0bc29ebd4e02c8bc5c1945f1d2e6be5927ec12c06d89b03ef2a4def34bf823 F src/vdbevtab.c fc46b9cbd759dc013f0b3724549cc0d71379183c667df3a5988f7e2f1bd485f3 -F src/vtab.c 4c475fb672a6fe57830561e614dbee21a9a24a6f616d1cfcbe85f356a09f14ad +F src/vtab.c 5fb499d20494b7eecaadb7584634af9afcb374cb0524912b475fcb1712458a1b F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c 887fc4ca3f020ebb2e376f222069570834ac63bf50111ef0cbf3ae417048ed89 F src/wal.h ba252daaa94f889f4b2c17c027e823d9be47ce39da1d3799886bbd51f0490452 @@ -2191,9 +2191,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 8eb326c24981647e2df90e4b9d75db52a552bd997bd821f5898c7ff3fb93a57d 3120c7c8a3565b8a3ca321129c09db96839c2f9af1777fc7a1668fef81973603 -R 91267a6a1982f21ea275bc49553555c1 -T +closed 3120c7c8a3565b8a3ca321129c09db96839c2f9af1777fc7a1668fef81973603 +P 953271f29e7bd6ba9b85f73250b1c22b08eef317f9ac3c7c3d92cbaa57d7efd5 +R bd9b1f3e12a43e6ce15734622e6a391b U drh -Z 697456db2f591cb2a06b3f31c7640456 +Z b7a4080de77f5c75fed04a53319240a7 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index b10e4da54e..e169c99247 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -953271f29e7bd6ba9b85f73250b1c22b08eef317f9ac3c7c3d92cbaa57d7efd5 \ No newline at end of file +1ec2961a0341619ae88832942b52606b3246fc0de07ca6da0300e4bfc656ecf0 \ No newline at end of file diff --git a/src/vtab.c b/src/vtab.c index 61dafab711..1036eed445 100644 --- a/src/vtab.c +++ b/src/vtab.c @@ -831,7 +831,10 @@ int sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){ for(i=0; aKeyword[i]; i++){ int tokenType = 0; do{ z += sqlite3GetToken(z, &tokenType); }while( tokenType==TK_SPACE ); - if( tokenType!=aKeyword[i] ) return SQLITE_MISUSE_BKPT; + if( tokenType!=aKeyword[i] ){ + sqlite3ErrorWithMsg(db, SQLITE_ERROR, "syntax error"); + return SQLITE_ERROR; + } } sqlite3_mutex_enter(db->mutex); From fa0763eb3437cf0c16342e8e38a03014a557eb91 Mon Sep 17 00:00:00 2001 From: dan Date: Thu, 16 May 2024 16:22:51 +0000 Subject: [PATCH 398/430] Add extra tests for the error messages generated by sqlite3_declare_vtab() when passed something other than a well-formed CREATE TABLE statement. FossilOrigin-Name: 5fa0c2a026f0467af3a76ea80cee8168b7a49553c350f642d1dff02ff9e7aeed --- manifest | 18 +++++++++--------- manifest.uuid | 2 +- src/test_bestindex.c | 3 +++ test/bestindexC.test | 22 +++++++++++++++++++--- test/vtabL.test | 11 +++++++++-- 5 files changed, 41 insertions(+), 15 deletions(-) diff --git a/manifest b/manifest index 6365b053b1..ea1aa1987f 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C The\ssqlite3_declare_vtab()\sinterface\sshould\sreturn\sSQLITE_ERROR,\snot\nSQLITE_MISUSE\swhen\sa\snonsense\sSQL\sinput\sis\sprovided,\sfor\slegacy\scompatibility.\n[forum:/forumpost/4b875d7b2a|Forum\spost\s4b875d7b2a]. -D 2024-05-16T15:57:42.281 +C Add\sextra\stests\sfor\sthe\serror\smessages\sgenerated\sby\ssqlite3_declare_vtab()\swhen\spassed\ssomething\sother\sthan\sa\swell-formed\sCREATE\sTABLE\sstatement. +D 2024-05-16T16:22:51.903 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -775,7 +775,7 @@ F src/test9.c 12e5ba554d2d1cbe0158f6ab3f7ffcd7a86ee4e5 F src/test_async.c 195ab49da082053fdb0f949c114b806a49ca770a F src/test_autoext.c 915d245e736652a219a907909bb6710f0d587871 F src/test_backup.c bf5da90c9926df0a4b941f2d92825a01bbe090a0 -F src/test_bestindex.c 1ee3d64b49ca06a9cb8195fab04f1a0585cafc90d25a2a817caa14e7caab22e7 +F src/test_bestindex.c 770429c434221afe6216ec81fe4c00ad3bbdad1d5e64576aa613ffb7c5a984f0 F src/test_blob.c ae4a0620b478548afb67963095a7417cd06a4ec0a56adb453542203bfdcb31ce F src/test_btree.c 8b2dc8b8848cf3a4db93f11578f075e82252a274 F src/test_config.c 5fa77ee6064ba546e144c4fea870c5ede2c54314616f81485c6a9c4192100c75 @@ -939,7 +939,7 @@ F test/bestindex8.test b63a4f171a2c83d481bb14c431a8b72e85d27b2ffdaa0435a95d58ca9 F test/bestindex9.test 1a4b93db117fd8abe74ae9be982f86aa72f01e60cd4ac541e6ede39673a451a0 F test/bestindexA.test e1b5def6b190797cacf008e6815ffb78fb30261999030d60a728d572eef44c7f F test/bestindexB.test 328b97b69cd1a20928d5997f9ecb04d2e00f1d18e19ab27f9e9adb44d7bc51ce -F test/bestindexC.test a2d4ab909e17bb58fe4d66a394460e713620c7b2964b450bc82216c171d264a2 +F test/bestindexC.test 9e6f184be080fd9c4605a7e5c7097eed1a259372f9af78151c37b072a9086f86 F test/between.test b9a65fb065391980119e8a781a7409d3fcf059d89968279c750e190a9a1d5263 F test/bigfile.test aa74f4e5db51c8e54a1d9de9fa65d01d1eb20b59 F test/bigfile2.test 1b489a3a39ae90c7f027b79110d6b4e1dbc71bfc @@ -1958,7 +1958,7 @@ F test/vtabH.test 2efb5a24b0bb50796b21eca23032cfb77abfa4b0c03938e38ce5897abac404 F test/vtabI.test 751b07636700dbdea328e4265b6077ccd6811a3f F test/vtabJ.test a6aef49d558af90fae10565b29501f82a95781cb4f797f2d13e2d19f9b6bc77b F test/vtabK.test 13293177528fada1235c0112db0d187d754af1355c5a39371abd365104e3afbf -F test/vtabL.test 49ec7342e8bfcb0d6c3d2443c619f430c609c042d5d7e6ddf52def65d6d1812f +F test/vtabL.test c7b7f537978005d063fa2f53a3cd5a46ecf651ecd19970cb9ed4203698398deb F test/vtab_alter.test 736e66fb5ec7b4fee58229aa3ada2f27ec58bc58c00edae4836890c3784c6783 F test/vtab_err.test dcc8b7b9cb67522b3fe7a272c73856829dae4ab7fdb30399aea1b6981bda2b65 F test/vtab_shared.test 5253bff2355a9a3f014c15337da7e177ab0ef8ad @@ -2191,8 +2191,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 953271f29e7bd6ba9b85f73250b1c22b08eef317f9ac3c7c3d92cbaa57d7efd5 -R bd9b1f3e12a43e6ce15734622e6a391b -U drh -Z b7a4080de77f5c75fed04a53319240a7 +P 1ec2961a0341619ae88832942b52606b3246fc0de07ca6da0300e4bfc656ecf0 +R 3e80a1a8d16383b10a9edc0a3a535e00 +U dan +Z 4379dfd9de0672673743bdb6b799c4de # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index e169c99247..5851bda00f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1ec2961a0341619ae88832942b52606b3246fc0de07ca6da0300e4bfc656ecf0 \ No newline at end of file +5fa0c2a026f0467af3a76ea80cee8168b7a49553c350f642d1dff02ff9e7aeed \ No newline at end of file diff --git a/src/test_bestindex.c b/src/test_bestindex.c index 6b6b413950..0e1e86a81c 100644 --- a/src/test_bestindex.c +++ b/src/test_bestindex.c @@ -215,6 +215,9 @@ static int tclConnect( rc = SQLITE_ERROR; }else{ rc = sqlite3_declare_vtab(db, Tcl_GetStringResult(interp)); + if( rc!=SQLITE_OK ){ + *pzErr = sqlite3_mprintf("declare_vtab: %s", sqlite3_errmsg(db)); + } } if( rc!=SQLITE_OK ){ diff --git a/test/bestindexC.test b/test/bestindexC.test index 708e56f774..c6ddf30618 100644 --- a/test/bestindexC.test +++ b/test/bestindexC.test @@ -177,9 +177,7 @@ unset ::do_not_use_offset reset_db proc vtab_command {lVal method args} { switch -- $method { - xConnect { - error "not happy!" - } + xConnect { error "not happy!" } } return {} @@ -193,5 +191,23 @@ do_test 4.1 { sqlite3_errcode db } SQLITE_ERROR +proc vtab_command {lVal method args} { + switch -- $method { + xConnect { + return $lVal + } + } + return {} +} + +do_catchsql_test 4.2 { + CREATE VIRTUAL TABLE y1 USING tcl(vtab_command "PRAGMA page_size=1024"); +} {1 {declare_vtab: syntax error}} +do_catchsql_test 4.3 { + CREATE VIRTUAL TABLE y1 USING tcl(vtab_command "CREATE TABLE x1("); +} {1 {declare_vtab: incomplete input}} +do_catchsql_test 4.4 { + CREATE VIRTUAL TABLE y1 USING tcl(vtab_command "CREATE TABLE x1(insert)"); +} {1 {declare_vtab: near "insert": syntax error}} finish_test diff --git a/test/vtabL.test b/test/vtabL.test index 0834655ffd..45528edcbd 100644 --- a/test/vtabL.test +++ b/test/vtabL.test @@ -31,7 +31,6 @@ proc vtab_command {method args} { return {} } -breakpoint foreach {tn cts} { 1 {SELECT 123} 2 {SELECT 123, 456} @@ -41,13 +40,21 @@ foreach {tn cts} { 6 {DROP TABLE nosuchtable} 7 {DROP TABLE x1} 8 {DROP TABLE t1} +} { + set ::create_table_sql $cts + do_catchsql_test 1.$tn { + CREATE VIRTUAL TABLE x1 USING tcl(vtab_command); + } {1 {declare_vtab: syntax error}} +} + +foreach {tn cts} { 9 {CREATE TABLE xyz AS SELECT * FROM sqlite_schema} 10 {CREATE TABLE xyz AS SELECT 1 AS 'col'} } { set ::create_table_sql $cts do_catchsql_test 1.$tn { CREATE VIRTUAL TABLE x1 USING tcl(vtab_command); - } {1 {vtable constructor failed: x1}} + } {1 {declare_vtab: SQL logic error}} } foreach {tn cts} { From b834f629ccdea6452d92f9bfcf41c24a833a6dbd Mon Sep 17 00:00:00 2001 From: drh <> Date: Fri, 17 May 2024 22:51:03 +0000 Subject: [PATCH 399/430] Improvements to a VDBE comment. No changes to anything that affects queries. FossilOrigin-Name: c2188da860a1debd7c5d28b223deeef15035c33c2c5aefae9d9b620b6a2b4677 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/wherecode.c | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index ea1aa1987f..3b1d18c556 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sextra\stests\sfor\sthe\serror\smessages\sgenerated\sby\ssqlite3_declare_vtab()\swhen\spassed\ssomething\sother\sthan\sa\swell-formed\sCREATE\sTABLE\sstatement. -D 2024-05-16T16:22:51.903 +C Improvements\sto\sa\sVDBE\scomment.\s\sNo\schanges\sto\sanything\sthat\saffects\squeries. +D 2024-05-17T22:51:03.662 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -841,7 +841,7 @@ F src/wal.h ba252daaa94f889f4b2c17c027e823d9be47ce39da1d3799886bbd51f0490452 F src/walker.c 7c7ea0115345851c3da4e04e2e239a29983b61fb5b038b94eede6aba462640e2 F src/where.c d235ba520b0147f60732b3bd411e119b43be33d348251edaa6e304a8ad52c511 F src/whereInt.h 82a13766f13d1a53b05387c2e60726289ef26404bc7b9b1f7770204d97357fb8 -F src/wherecode.c b9908c0a1aab095822a1e7032556bedc03b6d29641191e9ca535fb2307cd733d +F src/wherecode.c f5255f49d1f42b6e7e6b0362ff3522fa88cbcaa7213e52f9374744027ecdebca F src/whereexpr.c 67d15caf88a1a9528283d68ff578e024cf9fe810b517bb0343e5aaf695ad97dd F src/window.c 5d95122dd330bfaebd732358c8ef067c5a9394a53ac249470d611d0ce2c52be2 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 @@ -2191,8 +2191,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 1ec2961a0341619ae88832942b52606b3246fc0de07ca6da0300e4bfc656ecf0 -R 3e80a1a8d16383b10a9edc0a3a535e00 -U dan -Z 4379dfd9de0672673743bdb6b799c4de +P 5fa0c2a026f0467af3a76ea80cee8168b7a49553c350f642d1dff02ff9e7aeed +R ff343800565c823ff5271a08e7be7456 +U drh +Z c91b300408dcad01064e8ec2c6e1dc4c # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 5851bda00f..781081e058 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5fa0c2a026f0467af3a76ea80cee8168b7a49553c350f642d1dff02ff9e7aeed \ No newline at end of file +c2188da860a1debd7c5d28b223deeef15035c33c2c5aefae9d9b620b6a2b4677 \ No newline at end of file diff --git a/src/wherecode.c b/src/wherecode.c index 4aca6eb624..a620a5ac06 100644 --- a/src/wherecode.c +++ b/src/wherecode.c @@ -1436,7 +1436,7 @@ Bitmask sqlite3WhereCodeOneLoopStart( if( pLevel->iFrom>0 && (pTabItem[0].fg.jointype & JT_LEFT)!=0 ){ pLevel->iLeftJoin = ++pParse->nMem; sqlite3VdbeAddOp2(v, OP_Integer, 0, pLevel->iLeftJoin); - VdbeComment((v, "init LEFT JOIN no-match flag")); + VdbeComment((v, "init LEFT JOIN match flag")); } /* Compute a safe address to jump to if we discover that the table for From 79dac84b315ced19266d55f769341782f429e6b4 Mon Sep 17 00:00:00 2001 From: stephan Date: Sat, 18 May 2024 15:21:45 +0000 Subject: [PATCH 400/430] JS error message and doc typos reported in the forum. No code changes. FossilOrigin-Name: 1a073f9acfb691eebf4a8cc78a72ff47ebbb6aba4acede6755fa3faefae48f2b --- ext/wasm/api/sqlite3-api-oo1.js | 2 +- ext/wasm/api/sqlite3-api-prologue.js | 2 +- ext/wasm/api/sqlite3-worker1-promiser.c-pp.js | 2 +- manifest | 18 +++++++++--------- manifest.uuid | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/ext/wasm/api/sqlite3-api-oo1.js b/ext/wasm/api/sqlite3-api-oo1.js index 8cd50a14bb..e557cbd578 100644 --- a/ext/wasm/api/sqlite3-api-oo1.js +++ b/ext/wasm/api/sqlite3-api-oo1.js @@ -1868,7 +1868,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ an exception is thrown. By default it will determine the data type of the result - automatically. If passed a second arugment, it must be one + automatically. If passed a second argument, it must be one of the enumeration values for sqlite3 types, which are defined as members of the sqlite3 module: SQLITE_INTEGER, SQLITE_FLOAT, SQLITE_TEXT, SQLITE_BLOB. Any other value, diff --git a/ext/wasm/api/sqlite3-api-prologue.js b/ext/wasm/api/sqlite3-api-prologue.js index 849dfe10f2..689c79ae34 100644 --- a/ext/wasm/api/sqlite3-api-prologue.js +++ b/ext/wasm/api/sqlite3-api-prologue.js @@ -1838,7 +1838,7 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap( /** Calls either sqlite3_result_error_nomem(), if e is-a WasmAllocError, or sqlite3_result_error(). In the latter case, - the second arugment is coerced to a string to create the error + the second argument is coerced to a string to create the error message. The first argument is a (sqlite3_context*). Returns void. diff --git a/ext/wasm/api/sqlite3-worker1-promiser.c-pp.js b/ext/wasm/api/sqlite3-worker1-promiser.c-pp.js index 8cfc709372..55e497ead5 100644 --- a/ext/wasm/api/sqlite3-worker1-promiser.c-pp.js +++ b/ext/wasm/api/sqlite3-worker1-promiser.c-pp.js @@ -207,7 +207,7 @@ globalThis.sqlite3Worker1Promiser = function callee(config = callee.defaultConfi msg.args = arguments[1]; msg.dbId = msg.args.dbId; }else{ - toss("Invalid arugments for sqlite3Worker1Promiser()-created factory."); + toss("Invalid arguments for sqlite3Worker1Promiser()-created factory."); } if(!msg.dbId && msg.type!=='open') msg.dbId = dbId; msg.messageId = genMsgId(msg); diff --git a/manifest b/manifest index 3b1d18c556..acf63d973b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improvements\sto\sa\sVDBE\scomment.\s\sNo\schanges\sto\sanything\sthat\saffects\squeries. -D 2024-05-17T22:51:03.662 +C JS\serror\smessage\sand\sdoc\stypos\sreported\sin\sthe\sforum.\sNo\scode\schanges. +D 2024-05-18T15:21:45.610 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -610,8 +610,8 @@ F ext/wasm/api/post-js-header.js 04dc12c3edd666b64a1b4ef3b6690c88dcc653f26451fd4 F ext/wasm/api/pre-js.c-pp.js ad906703f7429590f2fbf5e6498513bf727a1a4f0ebfa057afb08161d7511219 F ext/wasm/api/sqlite3-api-cleanup.js d235ad237df6954145404305040991c72ef8b1881715d2a650dda7b3c2576d0e F ext/wasm/api/sqlite3-api-glue.js 114085f4dceb28e06d20d3fb597b2501a4aa69f4b6cd29234f7cc1cf81d5b92d -F ext/wasm/api/sqlite3-api-oo1.js 40f6834314b60e636f0046a9c49b8566a992dcf04be9ea593e680c23f6984b2b -F ext/wasm/api/sqlite3-api-prologue.js 34457b25dcf0005c81d76f011f207026ec164f6ff0f69f024b608025ca808ea9 +F ext/wasm/api/sqlite3-api-oo1.js c373cc04625a96bd3f01ce8ebeac93a5d38dbda6215818c925570df5a945565e +F ext/wasm/api/sqlite3-api-prologue.js b347a0c5350247f90174a0ad9b9e72a99a5f837f31f78f60fcdb829b2ca30b63 F ext/wasm/api/sqlite3-api-worker1.js 9704b77b5eb9d0d498ceeaf3e7a837021b14c52ac15d6556c7f97e278ec725c3 F ext/wasm/api/sqlite3-license-version-header.js 0c807a421f0187e778dc1078f10d2994b915123c1223fe752b60afdcd1263f89 F ext/wasm/api/sqlite3-opfs-async-proxy.js 196ad83d36ca794e564044788c9d21b964679d63cad865f604da37c4afc9a285 @@ -620,7 +620,7 @@ F ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js 8433ee332d5f5e39fb19427fccb7bad7 F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js 3c72f1a0e6a7343c8c882d29d01bb440f10be12c844651605b486e76f3d6cc8c F ext/wasm/api/sqlite3-vtab-helper.c-pp.js a2fcbc3fecdd0eea229283584ebc122f29d98194083675dbe5cb2cf3a17fe309 F ext/wasm/api/sqlite3-wasm.c 9267174b9b0591b4f71193542ab57adf95bb9415f7d3453acf4a8ca8052f5e6c -F ext/wasm/api/sqlite3-worker1-promiser.c-pp.js 5bffc94b0ba45c658f7a70c683c536642cd95f4d6fc71d20785864111c396740 +F ext/wasm/api/sqlite3-worker1-promiser.c-pp.js 46f303ba8ddd1b2f0a391798837beddfa72e8c897038c8047eda49ce7d5ed46b F ext/wasm/api/sqlite3-worker1.c-pp.js 5e8706c2c4af2a57fbcdc02f4e7ef79869971bc21bb8ede777687786ce1c92d5 F ext/wasm/batch-runner-sahpool.html e9a38fdeb36a13eac7b50241dfe7ae066fe3f51f5c0b0151e7baee5fce0d07a7 F ext/wasm/batch-runner-sahpool.js 54a3ac228e6c4703fe72fb65c897e19156263a51fe9b7e21d2834a45e876aabd @@ -2191,8 +2191,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 5fa0c2a026f0467af3a76ea80cee8168b7a49553c350f642d1dff02ff9e7aeed -R ff343800565c823ff5271a08e7be7456 -U drh -Z c91b300408dcad01064e8ec2c6e1dc4c +P c2188da860a1debd7c5d28b223deeef15035c33c2c5aefae9d9b620b6a2b4677 +R 54dd93ee4a8dfed3331a7d693fe52477 +U stephan +Z f16374626a15dcefe372431613b7ed3c # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 781081e058..1518cbf1b1 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c2188da860a1debd7c5d28b223deeef15035c33c2c5aefae9d9b620b6a2b4677 \ No newline at end of file +1a073f9acfb691eebf4a8cc78a72ff47ebbb6aba4acede6755fa3faefae48f2b \ No newline at end of file From 04624990514ae7c593ad224dd87cd9037cec752f Mon Sep 17 00:00:00 2001 From: drh <> Date: Sat, 18 May 2024 20:00:08 +0000 Subject: [PATCH 401/430] Fix the definition of sqlite3_vtab_distinct() such that return codes 2 and 3 mean that all rows must be distinct over "colUsed" which is a superset of "aOrderBy". Also, disallow return codes 2 and 3 if the rowid of the virtual table is accessed. FossilOrigin-Name: 922731ce98c0ce7837784ff7966049e59fa73da2aa04abf3506503b6fc4aa048 --- manifest | 25 ++++++++++++++----------- manifest.uuid | 2 +- src/resolve.c | 8 ++++++-- src/sqlite.h.in | 16 +++++++++------- src/sqliteInt.h | 1 + src/treeview.c | 6 ++++-- src/where.c | 2 +- 7 files changed, 36 insertions(+), 24 deletions(-) diff --git a/manifest b/manifest index acf63d973b..401fc0177e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C JS\serror\smessage\sand\sdoc\stypos\sreported\sin\sthe\sforum.\sNo\scode\schanges. -D 2024-05-18T15:21:45.610 +C Fix\sthe\sdefinition\sof\ssqlite3_vtab_distinct()\ssuch\sthat\sreturn\scodes\s2\sand\n3\smean\sthat\sall\srows\smust\sbe\sdistinct\sover\s"colUsed"\swhich\sis\sa\ssuperset\sof\n"aOrderBy".\s\sAlso,\sdisallow\sreturn\scodes\s2\sand\s3\sif\sthe\srowid\sof\sthe\svirtual\ntable\sis\saccessed. +D 2024-05-18T20:00:08.988 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -752,14 +752,14 @@ F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7 F src/prepare.c d99931f45416652895e502328ca49fe782cfc4e1ebdcda13b3736d991ebf42ce F src/printf.c 8b250972305e14b365561be5117ed0fd364e4fd58968776df1ce64c6280b90f9 F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c -F src/resolve.c 6adf4bf10151bca046f3206ae8ff07dbf90b49de20bea49197f010276f5f494d +F src/resolve.c 22f1fa3423b377c02ae78d451cfeb1c2d96dcf0389c0642cbdcd19d3bfd7ae01 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c 1a841c38974d45cf15a7611398479182b61ad4c187423c380741d8b1688fe607 F src/shell.c.in 8f2406e4e8d726452e48058d117f52e86b789f47435157b0418fb06c631349b6 -F src/sqlite.h.in 32389e0d584551b300d0157881336162c14315a424cbf385c0d65eb7c2e31f7b +F src/sqlite.h.in 6d645f9c2da3b64ea44944024df0c733bba186ee200d849a72a25bf8ae9beac4 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 -F src/sqliteInt.h adcf1cebb6fc00fc1f1329c00bb65ac36655736080acfd2071d84aa83a104afe +F src/sqliteInt.h 6a9fa3902c9faca2b57060e822f2afadfbf96d64c4ede81e201f0e0c42d7e4aa F src/sqliteLimit.h 6878ab64bdeb8c24a1d762d45635e34b96da21132179023338c93f820eee6728 F src/status.c cb11f8589a6912af2da3bb1ec509a94dd8ef27df4d4c1a97e0bcf2309ece972b F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1 @@ -817,7 +817,7 @@ F src/test_window.c cdae419fdcea5bad6dcd9368c685abdad6deb59e9fc8b84b153de513d394 F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9 F src/threads.c 4ae07fa022a3dc7c5beb373cf744a85d3c5c6c3c F src/tokenize.c 3f703cacdab728d7741e5a6ac242006d74fe1c2754d4f03ed889d7253259bd68 -F src/treeview.c 4f9ba6c1c7c9893fc046fdb0bc1f6bdec7660122b1ae37e51fb9b64c286caafd +F src/treeview.c 38eefdc85d2793c4059ae651a611b30eb034389fb428f69e572bbea565da6c78 F src/trigger.c 0858f75818ed1580332db274f1032bcc5effe567cb132df5c5be8b1d800ca97f F src/update.c 732404a04d1737ef14bb6ec6b84f74edf28b3c102a92ae46b4855438a710efe7 F src/upsert.c 2e60567a0e9e8520c18671b30712a88dc73534474304af94f32bb5f3ef65ac65 @@ -839,7 +839,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c 887fc4ca3f020ebb2e376f222069570834ac63bf50111ef0cbf3ae417048ed89 F src/wal.h ba252daaa94f889f4b2c17c027e823d9be47ce39da1d3799886bbd51f0490452 F src/walker.c 7c7ea0115345851c3da4e04e2e239a29983b61fb5b038b94eede6aba462640e2 -F src/where.c d235ba520b0147f60732b3bd411e119b43be33d348251edaa6e304a8ad52c511 +F src/where.c 6f02c3936d1f9a637d8d7b5ad7362371af3e4434b0ec1eb950189a83de560d59 F src/whereInt.h 82a13766f13d1a53b05387c2e60726289ef26404bc7b9b1f7770204d97357fb8 F src/wherecode.c f5255f49d1f42b6e7e6b0362ff3522fa88cbcaa7213e52f9374744027ecdebca F src/whereexpr.c 67d15caf88a1a9528283d68ff578e024cf9fe810b517bb0343e5aaf695ad97dd @@ -2191,8 +2191,11 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P c2188da860a1debd7c5d28b223deeef15035c33c2c5aefae9d9b620b6a2b4677 -R 54dd93ee4a8dfed3331a7d693fe52477 -U stephan -Z f16374626a15dcefe372431613b7ed3c +P 1a073f9acfb691eebf4a8cc78a72ff47ebbb6aba4acede6755fa3faefae48f2b +R be7ef6a3dcb331720f0112bf3c3e9c8c +T *branch * vtab-distinct-fix +T *sym-vtab-distinct-fix * +T -sym-trunk * +U drh +Z 3a71e5f761d3443220a5a5a181b974f3 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 1518cbf1b1..6968f2e6b3 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1a073f9acfb691eebf4a8cc78a72ff47ebbb6aba4acede6755fa3faefae48f2b \ No newline at end of file +922731ce98c0ce7837784ff7966049e59fa73da2aa04abf3506503b6fc4aa048 \ No newline at end of file diff --git a/src/resolve.c b/src/resolve.c index 546731afe5..bf8326aa64 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -828,8 +828,12 @@ static int lookupName( ** If a generated column is referenced, set bits for every column ** of the table. */ - if( pExpr->iColumn>=0 && cnt==1 && pMatch!=0 ){ - pMatch->colUsed |= sqlite3ExprColUsed(pExpr); + if( pMatch ){ + if( pExpr->iColumn>=0 ){ + pMatch->colUsed |= sqlite3ExprColUsed(pExpr); + }else{ + pMatch->fg.rowidUsed = 1; + } } pExpr->op = eNewExprOp; diff --git a/src/sqlite.h.in b/src/sqlite.h.in index d553abb7bf..459af929b1 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -9942,20 +9942,22 @@ const char *sqlite3_vtab_collation(sqlite3_index_info*,int); **
  • ** ^(If the sqlite3_vtab_distinct() interface returns 2, that means ** that the query planner does not need the rows returned in any particular -** order, as long as rows with the same values in all "aOrderBy" columns +** order, as long as rows with the same values in all "colUsed" columns ** are adjacent.)^ ^(Furthermore, only a single row for each particular -** combination of values in the columns identified by the "aOrderBy" field +** combination of values in the columns identified by the "colUsed" field ** needs to be returned.)^ ^It is always ok for two or more rows with the same -** values in all "aOrderBy" columns to be returned, as long as all such rows +** values in all "colUsed" columns to be returned, as long as all such rows ** are adjacent. ^The virtual table may, if it chooses, omit extra rows -** that have the same value for all columns identified by "aOrderBy". +** that have the same value for all columns identified by "colUsed". ** ^However omitting the extra rows is optional. ** This mode is used for a DISTINCT query. **

  • ** ^(If the sqlite3_vtab_distinct() interface returns 3, that means -** that the query planner needs only distinct rows but it does need the -** rows to be sorted.)^ ^The virtual table implementation is free to omit -** rows that are identical in all aOrderBy columns, if it wants to, but +** that the query planner needs only rows that are distinct over the +** set of columns defined by "colUsed" but it does need the +** rows to be sorted according to the order defined by "aOrderBy".)^ +** ^The virtual table implementation is free to omit +** rows that are identical in all "colUsed" columns, if it wants to, but ** it is not required to omit any rows. This mode is used for queries ** that have both DISTINCT and ORDER BY clauses. ** diff --git a/src/sqliteInt.h b/src/sqliteInt.h index aa8bfc4b7b..d98a4f7f06 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -3312,6 +3312,7 @@ struct SrcItem { unsigned isOn :1; /* u3.pOn was once valid and non-NULL */ unsigned isSynthUsing :1; /* u3.pUsing is synthesized from NATURAL */ unsigned isNestedFrom :1; /* pSelect is a SF_NestedFrom subquery */ + unsigned rowidUsed :1; /* The ROWID of this table is referenced */ } fg; int iCursor; /* The VDBE cursor number used to access this table */ union { diff --git a/src/treeview.c b/src/treeview.c index d3346b4686..fa9eac6142 100644 --- a/src/treeview.c +++ b/src/treeview.c @@ -194,8 +194,10 @@ void sqlite3TreeViewSrcList(TreeView *pView, const SrcList *pSrc){ x.printfFlags |= SQLITE_PRINTF_INTERNAL; sqlite3_str_appendf(&x, "{%d:*} %!S", pItem->iCursor, pItem); if( pItem->pTab ){ - sqlite3_str_appendf(&x, " tab=%Q nCol=%d ptr=%p used=%llx", - pItem->pTab->zName, pItem->pTab->nCol, pItem->pTab, pItem->colUsed); + sqlite3_str_appendf(&x, " tab=%Q nCol=%d ptr=%p used=%llx%s", + pItem->pTab->zName, pItem->pTab->nCol, pItem->pTab, + pItem->colUsed, + pItem->fg.rowidUsed ? "+rowid" : ""); } if( (pItem->fg.jointype & (JT_LEFT|JT_RIGHT))==(JT_LEFT|JT_RIGHT) ){ sqlite3_str_appendf(&x, " FULL-OUTER-JOIN"); diff --git a/src/where.c b/src/where.c index 13a362dcca..fac0f6c5eb 100644 --- a/src/where.c +++ b/src/where.c @@ -1416,7 +1416,7 @@ static sqlite3_index_info *allocateIndexInfo( } if( i==n ){ nOrderBy = n; - if( (pWInfo->wctrlFlags & WHERE_DISTINCTBY) ){ + if( (pWInfo->wctrlFlags & WHERE_DISTINCTBY) && !pSrc->fg.rowidUsed ){ eDistinct = 2 + ((pWInfo->wctrlFlags & WHERE_SORTBYGROUP)!=0); }else if( pWInfo->wctrlFlags & WHERE_GROUPBY ){ eDistinct = 1; From df903fe0565e3793888bbd8f8a329245eec4d9ea Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 20 May 2024 16:00:27 +0000 Subject: [PATCH 402/430] Improvements to the sqlite3_vtab_distinct() documentation. FossilOrigin-Name: 6ee041d34f292b94701919f51bbb9e12bcb9e0c4f45e4c0b83f30ff328070637 --- manifest | 15 ++++++--------- manifest.uuid | 2 +- src/sqlite.h.in | 49 ++++++++++++++++++++++++++++++++++--------------- 3 files changed, 41 insertions(+), 25 deletions(-) diff --git a/manifest b/manifest index 401fc0177e..ce10a0198d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\sdefinition\sof\ssqlite3_vtab_distinct()\ssuch\sthat\sreturn\scodes\s2\sand\n3\smean\sthat\sall\srows\smust\sbe\sdistinct\sover\s"colUsed"\swhich\sis\sa\ssuperset\sof\n"aOrderBy".\s\sAlso,\sdisallow\sreturn\scodes\s2\sand\s3\sif\sthe\srowid\sof\sthe\svirtual\ntable\sis\saccessed. -D 2024-05-18T20:00:08.988 +C Improvements\sto\sthe\ssqlite3_vtab_distinct()\sdocumentation. +D 2024-05-20T16:00:27.117 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -756,7 +756,7 @@ F src/resolve.c 22f1fa3423b377c02ae78d451cfeb1c2d96dcf0389c0642cbdcd19d3bfd7ae01 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c 1a841c38974d45cf15a7611398479182b61ad4c187423c380741d8b1688fe607 F src/shell.c.in 8f2406e4e8d726452e48058d117f52e86b789f47435157b0418fb06c631349b6 -F src/sqlite.h.in 6d645f9c2da3b64ea44944024df0c733bba186ee200d849a72a25bf8ae9beac4 +F src/sqlite.h.in c71d9ef76a6d32dc7ff2d373f2e57ce09056af26c1457bcadae5358b7628c7c3 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 F src/sqliteInt.h 6a9fa3902c9faca2b57060e822f2afadfbf96d64c4ede81e201f0e0c42d7e4aa @@ -2191,11 +2191,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 1a073f9acfb691eebf4a8cc78a72ff47ebbb6aba4acede6755fa3faefae48f2b -R be7ef6a3dcb331720f0112bf3c3e9c8c -T *branch * vtab-distinct-fix -T *sym-vtab-distinct-fix * -T -sym-trunk * +P 922731ce98c0ce7837784ff7966049e59fa73da2aa04abf3506503b6fc4aa048 +R 65c04e4dfc1793594341c544753e5e70 U drh -Z 3a71e5f761d3443220a5a5a181b974f3 +Z 4b4899e535e10a58b98edaa878f294f3 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 6968f2e6b3..1200d1128c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -922731ce98c0ce7837784ff7966049e59fa73da2aa04abf3506503b6fc4aa048 \ No newline at end of file +6ee041d34f292b94701919f51bbb9e12bcb9e0c4f45e4c0b83f30ff328070637 \ No newline at end of file diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 459af929b1..549b52a153 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -9942,26 +9942,45 @@ const char *sqlite3_vtab_collation(sqlite3_index_info*,int); **

  • ** ^(If the sqlite3_vtab_distinct() interface returns 2, that means ** that the query planner does not need the rows returned in any particular -** order, as long as rows with the same values in all "colUsed" columns -** are adjacent.)^ ^(Furthermore, only a single row for each particular -** combination of values in the columns identified by the "colUsed" field -** needs to be returned.)^ ^It is always ok for two or more rows with the same -** values in all "colUsed" columns to be returned, as long as all such rows -** are adjacent. ^The virtual table may, if it chooses, omit extra rows -** that have the same value for all columns identified by "colUsed". -** ^However omitting the extra rows is optional. +** order, as long as rows with the same values in all columns identified +** by "aOrderBy" are adjacent.)^ ^(Furthermore, when two or more rows +** contain the same values for all columns identified by "colUsed", all but +** one such row may optionally be omitted from the result.)^ +** The virtual table is not required to omit rows that are duplicates +** over the "colUsed" columns, but if the virtual table can do that without +** too much extra effort, it could potentially help the query to run faster. ** This mode is used for a DISTINCT query. **

  • -** ^(If the sqlite3_vtab_distinct() interface returns 3, that means -** that the query planner needs only rows that are distinct over the -** set of columns defined by "colUsed" but it does need the -** rows to be sorted according to the order defined by "aOrderBy".)^ -** ^The virtual table implementation is free to omit -** rows that are identical in all "colUsed" columns, if it wants to, but -** it is not required to omit any rows. This mode is used for queries +** ^(If the sqlite3_vtab_distinct() interface returns 3, that means the +** virtual table must return rows in the order defined by "aOrderBy" as +** if the sqlite3_vtab_distinct() interface had returned 0. However if +** two or more rows in the result have the same values for all columns +** identified by "colUsed", then all but one such row may optionally be +** omitted.)^ Like when the return value is 2, the virtual table +** is not required to omit rows that are duplicates over the "colUsed" +** columns, but if the virtual table can do that without +** too much extra effort, it could potentially help the query to run faster. +** This mode is used for queries ** that have both DISTINCT and ORDER BY clauses. ** ** +**

    The following table summarizes the conditions under which the +** virtual table is allowed to set the "orderByConsumed" flag based on +** the value returned by sqlite3_vtab_distinct(). This table is a +** restatement of the previous four paragraphs: +** +** +** +**
    sqlite3_vtab_distinct() return value +** Rows are returned in aOrderBy order +** Rows with the same value in all aOrderBy columns are adjacent +** Duplicates over all colUsed columns may be omitted +**
    0yesyesno +**
    1noyesno +**
    2noyesyes +**
    3yesyesyes +**
    +** ** ^For the purposes of comparing virtual table output values to see if the ** values are same value for sorting purposes, two NULL values are considered ** to be the same. In other words, the comparison operator is "IS" From f765aec406c7cae212d579fa0fc1506f82d25812 Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 20 May 2024 19:51:06 +0000 Subject: [PATCH 403/430] Do not run the tests in recovercorrupt4.test with the inmemory_journal permutation. FossilOrigin-Name: c13205d66b8406cccfc937c88ac515fa758fe2ade8b3d30f0c1e79fe974e9600 --- ext/recover/recovercorrupt4.test | 80 +++++++++++++++++--------------- manifest | 15 +++--- manifest.uuid | 2 +- 3 files changed, 51 insertions(+), 46 deletions(-) diff --git a/ext/recover/recovercorrupt4.test b/ext/recover/recovercorrupt4.test index 53d691fbc4..0ff0b502df 100644 --- a/ext/recover/recovercorrupt4.test +++ b/ext/recover/recovercorrupt4.test @@ -15,44 +15,50 @@ set testprefix recovercorrupt4 database_may_be_corrupt -do_execsql_test 1.0 { - CREATE TABLE rows(indexed INTEGER NOT NULL, unindexed INTEGER NOT NULL, filler BLOB NOT NULL DEFAULT 13); - -- CREATE UNIQUE INDEX rows_index ON rows(indexed); - INSERT INTO rows(indexed, unindexed, filler) VALUES(1, 1, x'31'); - INSERT INTO rows(indexed, unindexed, filler) VALUES(2, 2, x'32'); - INSERT INTO rows(indexed, unindexed, filler) VALUES(4, 4, x'34'); - INSERT INTO rows(indexed, unindexed, filler) VALUES(8, 8, randomblob(2048)); -} - -db close - -do_test 1.1 { - set sz [expr [file size test.db] - 1024] - set fd [open test.db] - fconfigure $fd -encoding binary -translation binary - - set data [read $fd $sz] - set fd2 [open test.db2 w] - fconfigure $fd2 -encoding binary -translation binary - puts -nonewline $fd2 $data - close $fd2 - set {} {} -} {} - -do_test 1.2 { - forcedelete test.db3 - sqlite3 db test.db2 - set R [sqlite3_recover_init db main test.db3] - $R run - $R finish -} {} - -do_test 1.3 { - sqlite3 db test.db3 - execsql { - SELECT indexed, unindexed FROM rows +if {[permutation]!="inmemory_journal"} { + # This test cannot be run with the inmemory_journal permutation, as it + # must open a truncated, corrupt, database file. With the inmemory_journal + # permutation, this fails (SQLITE_CORRUPT error) when the [sqlite3] wrapper + # executes "PRAGMA journal_mode = memory". + do_execsql_test 1.0 { + CREATE TABLE rows(indexed INTEGER NOT NULL, unindexed INTEGER NOT NULL, filler BLOB NOT NULL DEFAULT 13); + -- CREATE UNIQUE INDEX rows_index ON rows(indexed); + INSERT INTO rows(indexed, unindexed, filler) VALUES(1, 1, x'31'); + INSERT INTO rows(indexed, unindexed, filler) VALUES(2, 2, x'32'); + INSERT INTO rows(indexed, unindexed, filler) VALUES(4, 4, x'34'); + INSERT INTO rows(indexed, unindexed, filler) VALUES(8, 8, randomblob(2048)); } -} {1 1 2 2 4 4 8 8} + + db close + + do_test 1.1 { + set sz [expr [file size test.db] - 1024] + set fd [open test.db] + fconfigure $fd -encoding binary -translation binary + + set data [read $fd $sz] + set fd2 [open test.db2 w] + fconfigure $fd2 -encoding binary -translation binary + puts -nonewline $fd2 $data + close $fd2 + set {} {} + } {} + + do_test 1.2 { + forcedelete test.db3 + sqlite3 db test.db2 + set R [sqlite3_recover_init db main test.db3] + $R run + $R finish + } {} + + do_test 1.3 { + sqlite3 db test.db3 + execsql { + SELECT indexed, unindexed FROM rows + } + } {1 1 2 2 4 4 8 8} +} finish_test diff --git a/manifest b/manifest index 29d10b5d87..8b165fad08 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improvements\sto\sthe\sdocumentation\sof\ssqlite3_vtab_distinct().\s\sDo\snot\sallow\nsqlite3_vtab_distinct()\sto\sreturn\s2\sor\s3\sif\sthe\srowid\scolumn\sof\sthe\svirtual\ntable\sis\sused,\sas\sdoing\sso\smight\slead\sto\san\sincorrect\sanswer. -D 2024-05-20T17:52:35.621 +C Do\snot\srun\sthe\stests\sin\srecovercorrupt4.test\swith\sthe\sinmemory_journal\spermutation. +D 2024-05-20T19:51:06.196 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -486,7 +486,7 @@ F ext/recover/recoverclobber.test 3ba6c0c373c5c63d17e82eced64c05c57ccaf26c1abe1c F ext/recover/recovercorrupt.test 64c081ad1200ae77b447da99eb724785d6bf71715f394543dc7689642e92bf49 F ext/recover/recovercorrupt2.test 1418f1710debc24ff38276cedfcea234beb37a34205708e7e3e6d76cc4a979db F ext/recover/recovercorrupt3.test 2e7b9a1b528ca23ed382cec6f64e3fcbbd0f8e852add7562397fd8df83f335d5 -F ext/recover/recovercorrupt4.test 8990c3a76da616b938e800cd2b40eb1f7adf9352624966ba0af0303c7a015f00 +F ext/recover/recovercorrupt4.test cc4a56086c50fba6a5b20db122a3f220195b3d4f11a86e0858c7f5f5d8ba58d1 F ext/recover/recoverfault.test 9d9f88eeb222615a25e7514f234c950d46bee20d24cd8db49d8fff8d650dcfe1 F ext/recover/recoverfault2.test 730e7371bcda769554d15460cb23126abba1be8eca9539ccabf63623e7bb7e09 F ext/recover/recoverold.test 68db3d6f85dd2b98e785b6c4da4f5eea4bbe52ccf6674d9a94c7506dc92596aa @@ -2191,9 +2191,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 1a073f9acfb691eebf4a8cc78a72ff47ebbb6aba4acede6755fa3faefae48f2b 6ee041d34f292b94701919f51bbb9e12bcb9e0c4f45e4c0b83f30ff328070637 -R 65c04e4dfc1793594341c544753e5e70 -T +closed 6ee041d34f292b94701919f51bbb9e12bcb9e0c4f45e4c0b83f30ff328070637 -U drh -Z fa3617d3b707c5d55775f8d830ee0281 +P 08058d66d1bde4fcf8324482ee4c6c030c681383470d5076b6f75b74aac2ae29 +R 01944e27726a0e53c62f6b779625a02f +U dan +Z f9b21623fcc9b31310e5e703021ca634 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 7aeea9e86c..4b60b06ff3 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -08058d66d1bde4fcf8324482ee4c6c030c681383470d5076b6f75b74aac2ae29 \ No newline at end of file +c13205d66b8406cccfc937c88ac515fa758fe2ade8b3d30f0c1e79fe974e9600 \ No newline at end of file From 00208479fd4c371eec868cadb6b9968fd9045fb8 Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 20 May 2024 19:59:32 +0000 Subject: [PATCH 404/430] Omit a capi3 test from 2007 that depends upon undefined behavior (UAF). FossilOrigin-Name: a60a0b75137c015e97b8dcd0070444fcb608f502ce88b2ee744dd6230dbdc120 --- manifest | 14 +++++++------- manifest.uuid | 2 +- test/capi3.test | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 8b165fad08..374394b147 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Do\snot\srun\sthe\stests\sin\srecovercorrupt4.test\swith\sthe\sinmemory_journal\spermutation. -D 2024-05-20T19:51:06.196 +C Omit\sa\scapi3\stest\sfrom\s2007\sthat\sdepends\supon\sundefined\sbehavior\s(UAF). +D 2024-05-20T19:59:32.762 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -969,7 +969,7 @@ F test/cache.test 13bc046b26210471ca6f2889aceb1ea52dc717de F test/cacheflush.test af25bb1509df04c1da10e38d8f322d66eceedf61 F test/cachespill.test 895997f84a25b323b166aecb69baab2d6380ea98f9e0bcc688c4493c535cfab9 F test/capi2.test 4ee545824adc3eb33bf57ef89f77440b28188ec3da72e5425ff0fcdba32e8d5a -F test/capi3.test 3910a73c38ac76d69778dd9eb481ab7cd6ed59117fc047b4f6056a5c72529de1 +F test/capi3.test 4892b5e53d2a6941edc9d204a0ab174dd66e8689282d9a15e4384561c3965945 F test/capi3b.test efb2b9cfd127efa84433cd7a2d72ce0454ae0dc4 F test/capi3c.test 31d3a6778f2d06f2d9222bd7660c41a516d1518a059b069e96ebbeadb5a490f7 F test/capi3d.test 8b778794af891b0dca3d900bd345fbc8ebd2aa2aae425a9dccdd10d5233dfbde @@ -2191,8 +2191,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 08058d66d1bde4fcf8324482ee4c6c030c681383470d5076b6f75b74aac2ae29 -R 01944e27726a0e53c62f6b779625a02f -U dan -Z f9b21623fcc9b31310e5e703021ca634 +P c13205d66b8406cccfc937c88ac515fa758fe2ade8b3d30f0c1e79fe974e9600 +R afa580b78e84297da9d918d4b239628f +U drh +Z dd88f180c52872ac43a520d8ec94266a # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 4b60b06ff3..58c5ec3196 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c13205d66b8406cccfc937c88ac515fa758fe2ade8b3d30f0c1e79fe974e9600 \ No newline at end of file +a60a0b75137c015e97b8dcd0070444fcb608f502ce88b2ee744dd6230dbdc120 \ No newline at end of file diff --git a/test/capi3.test b/test/capi3.test index 40d87ac8e3..e65f90e3aa 100644 --- a/test/capi3.test +++ b/test/capi3.test @@ -181,7 +181,7 @@ do_test capi3-3.4 { do_test capi3-3.5 { list [sqlite3_system_errno $db2] [sqlite3_close $db2] } [list $::capi3_errno SQLITE_OK] -if {[clang_sanitize_address]==0} { +if {[clang_sanitize_address]==0 && 0} { do_test capi3-3.6.1-misuse { sqlite3_close $db2 } {SQLITE_MISUSE} From b8337932b36e85b85f9fc8efc4b141371078c119 Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 21 May 2024 11:11:29 +0000 Subject: [PATCH 405/430] Fix the -> and ->> operators so that when the RHS is a string that looks like a number, it is still treated as a string, because that is what PG does. [forum:/forumpost/9e52cdfe15c3926e|Forum post 9e52cdfe15c3926e]. FossilOrigin-Name: de8182cf1773ac0d04268d896a613841cf6bf61f9f030342170657d5e06f2acb --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/json.c | 9 +-------- test/json102.test | 31 +++++++++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 16 deletions(-) diff --git a/manifest b/manifest index 374394b147..cccb4e7b93 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Omit\sa\scapi3\stest\sfrom\s2007\sthat\sdepends\supon\sundefined\sbehavior\s(UAF). -D 2024-05-20T19:59:32.762 +C Fix\sthe\s->\sand\s->>\soperators\sso\sthat\swhen\sthe\sRHS\sis\sa\sstring\sthat\slooks\slike\na\snumber,\sit\sis\sstill\streated\sas\sa\sstring,\sbecause\sthat\sis\swhat\sPG\sdoes.\n[forum:/forumpost/9e52cdfe15c3926e|Forum\spost\s9e52cdfe15c3926e]. +D 2024-05-21T11:11:29.610 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -714,7 +714,7 @@ F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 F src/insert.c 4bd7c7e54a1062dcd0214b7a6296f7194eb10fb14d3ddca1ed20b01c2a86a18c -F src/json.c e2e40760d6689134c3e2ece38c6a496b34ff5e2661a8f238444a119af666fdce +F src/json.c bf1b51e32158b3d01d96a878d3dba8d2e633a7e5bf2534d4617f89de8a6b9a91 F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 F src/main.c 8a59d297ec77e6b78550433bfccb95a1b26f2fb69aaaf233206e21579a1cfcc1 @@ -1358,7 +1358,7 @@ F test/json/json-q1.txt 65f9d1cdcc4cffa9823fb73ed936aae5658700cd001fde448f68bfb9 F test/json/json-speed-check.sh 912ee03e700a65c827ee0c7b4752c21ec5ef69cf7679d2f482ca817042bead52 x F test/json/jsonb-q1.txt 1e180fe6491efab307e318b22879e3a736ac9a96539bbde7911a13ee5b33abc7 F test/json101.test 30db5b055b103ccabc53a29cfe6cda3345d07e171aeb25403dafa04f19e98b19 -F test/json102.test 557a46e16df1aa9bdbc4076a71a45814ea0e7503d6621d87d42a8c04cbc2b0ef +F test/json102.test 4b3a0f94535f033239b67c13dbee8b47d2b5ee467e0f2fdab5eadf370bbe5fd3 F test/json103.test 53df87f83a4e5fa0c0a56eb29ff6c94055c6eb919f33316d62161a8880112dbe F test/json104.test 1b844a70cddcfa2e4cd81a5db0657b2e61e7f00868310f24f56a9ba0114348c1 F test/json105.test 043838b56e68f3252a0dcf5be1689016f6f3f05056f8dcfcdc9d074f4d932988 @@ -2191,8 +2191,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P c13205d66b8406cccfc937c88ac515fa758fe2ade8b3d30f0c1e79fe974e9600 -R afa580b78e84297da9d918d4b239628f +P a60a0b75137c015e97b8dcd0070444fcb608f502ce88b2ee744dd6230dbdc120 +R 83e05fc293c948e3f22eef5dc075f9b9 U drh -Z dd88f180c52872ac43a520d8ec94266a +Z 9111b0a4bac0297dbe95168c7eba24aa # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 58c5ec3196..2b76157e99 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a60a0b75137c015e97b8dcd0070444fcb608f502ce88b2ee744dd6230dbdc120 \ No newline at end of file +de8182cf1773ac0d04268d896a613841cf6bf61f9f030342170657d5e06f2acb \ No newline at end of file diff --git a/src/json.c b/src/json.c index 44ae846461..4db468c92d 100644 --- a/src/json.c +++ b/src/json.c @@ -3795,13 +3795,6 @@ static void jsonArrayLengthFunc( jsonParseFree(p); } -/* True if the string is all digits */ -static int jsonAllDigits(const char *z, int n){ - int i; - for(i=0; i $[NUMBER] // Not PG. Purely for convenience */ jsonStringInit(&jx, ctx); - if( jsonAllDigits(zPath, nPath) ){ + if( sqlite3_value_type(argv[i])==SQLITE_INTEGER ){ jsonAppendRawNZ(&jx, "[", 1); jsonAppendRaw(&jx, zPath, nPath); jsonAppendRawNZ(&jx, "]", 2); diff --git a/test/json102.test b/test/json102.test index 15a54b47c4..1a00cb67ae 100644 --- a/test/json102.test +++ b/test/json102.test @@ -764,4 +764,35 @@ do_execsql_test json102-1720 { SELECT * FROM t1; } {ok 2023-08-03 876 5 {{"x":77,"y":6}}} +# 2024-05-21 https://sqlite.org/forum/forumpost/9e52cdfe15c3926e +# What if the RHS of the -> or ->> operator is a string that looks +# like a number? PostgreSQL treats it as a string. +# +do_execsql_test json102-1800 { + SELECT '{"1":"one","2":"two","3":"three"}'->>'2'; +} two +db null NULL +do_execsql_test json102-1801 { + SELECT '{"1":"one","2":"two","3":"three"}'->>2; +} NULL +do_execsql_test json102-1810 { + SELECT '["zero","one","two"]'->>'1'; +} NULL +do_execsql_test json102-1811 { + SELECT '["zero","one","two"]'->>1; +} one +do_execsql_test json102-1820 { + SELECT '{"1":"one","2":"two","3":"three"}'->'2'; +} {{"two"}} +do_execsql_test json102-1821 { + SELECT '{"1":"one","2":"two","3":"three"}'->2; +} {NULL} +do_execsql_test json102-1830 { + SELECT '["zero","one","two"]'->'1'; +} {NULL} +do_execsql_test json102-1831 { + SELECT '["zero","one","two"]'->1; +} {{"one"}} + + finish_test From 33087dbf3059d29ffe0bd1ff495d886db0747dd4 Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 21 May 2024 13:34:26 +0000 Subject: [PATCH 406/430] Fix harmless compiler warnings. FossilOrigin-Name: aab59f9f7c1c4cfac4d29d7c7a381583295312baf3b9a75e30a617b1541e12e1 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/shell.c.in | 2 +- src/vdbemem.c | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index cccb4e7b93..09a9da69c2 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\s->\sand\s->>\soperators\sso\sthat\swhen\sthe\sRHS\sis\sa\sstring\sthat\slooks\slike\na\snumber,\sit\sis\sstill\streated\sas\sa\sstring,\sbecause\sthat\sis\swhat\sPG\sdoes.\n[forum:/forumpost/9e52cdfe15c3926e|Forum\spost\s9e52cdfe15c3926e]. -D 2024-05-21T11:11:29.610 +C Fix\sharmless\scompiler\swarnings. +D 2024-05-21T13:34:26.341 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -755,7 +755,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c 22f1fa3423b377c02ae78d451cfeb1c2d96dcf0389c0642cbdcd19d3bfd7ae01 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c 1a841c38974d45cf15a7611398479182b61ad4c187423c380741d8b1688fe607 -F src/shell.c.in 8f2406e4e8d726452e48058d117f52e86b789f47435157b0418fb06c631349b6 +F src/shell.c.in 885dafabb3f16d68bdb4576683afb0e39a1939f50985b162255bf656c470babf F src/sqlite.h.in c71d9ef76a6d32dc7ff2d373f2e57ce09056af26c1457bcadae5358b7628c7c3 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 @@ -830,7 +830,7 @@ F src/vdbeInt.h 949669dfd8a41550d27dcb905b494f2ccde9a2e6c1b0b04daa1227e2e74c2b2c F src/vdbeapi.c 80235ac380e9467fec1cb0883354d841f2a771976e766995f7e0c77f845406df F src/vdbeaux.c 3bcf13776c39bf660a52b4b97f6389a421c2756f9ffbf4c0d94f73e1935d8d9c F src/vdbeblob.c 13f9287b55b6356b4b1845410382d6bede203ceb29ef69388a4a3d007ffacbe5 -F src/vdbemem.c 385c8b89da3b5ef9a468d77a466958aa72ee1212d5cb005f23ec63df1d413054 +F src/vdbemem.c 831a244831eaa45335f9ae276b50a7a82ee10d8c46c2c72492d4eb8c98d94d89 F src/vdbesort.c 237840ca1947511fa59bd4e18b9eeae93f2af2468c34d2427b059f896230a547 F src/vdbetrace.c fe0bc29ebd4e02c8bc5c1945f1d2e6be5927ec12c06d89b03ef2a4def34bf823 F src/vdbevtab.c fc46b9cbd759dc013f0b3724549cc0d71379183c667df3a5988f7e2f1bd485f3 @@ -2191,8 +2191,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P a60a0b75137c015e97b8dcd0070444fcb608f502ce88b2ee744dd6230dbdc120 -R 83e05fc293c948e3f22eef5dc075f9b9 +P de8182cf1773ac0d04268d896a613841cf6bf61f9f030342170657d5e06f2acb +R 48a1dfe76e5f9714f60170e25f19a5ec U drh -Z 9111b0a4bac0297dbe95168c7eba24aa +Z 85ec8dacf40c6db93df32b415530df39 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 2b76157e99..0c3ade05c4 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -de8182cf1773ac0d04268d896a613841cf6bf61f9f030342170657d5e06f2acb \ No newline at end of file +aab59f9f7c1c4cfac4d29d7c7a381583295312baf3b9a75e30a617b1541e12e1 \ No newline at end of file diff --git a/src/shell.c.in b/src/shell.c.in index 2984853442..0029682f32 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -7943,7 +7943,7 @@ static struct { int nHit; /* Number of hits seen so far */ int nRepeat; /* Turn off after this many hits. 0 for never */ int nSkip; /* Skip this many before first fault */ -} faultsim_state = {-1, 0, 0, 0, 0, 0, 0}; +} faultsim_state = {-1, 0, 0, 0, 0, 0, 0, 0}; /* ** This is the fault-sim callback diff --git a/src/vdbemem.c b/src/vdbemem.c index 8a4011e10f..8e2aa4a6c9 100644 --- a/src/vdbemem.c +++ b/src/vdbemem.c @@ -1959,7 +1959,7 @@ int sqlite3Stat4Column( assert( iCol>0 ); iHdr = getVarint32(a, nHdr); - if( nHdr>nRec || iHdr>=nHdr ) return SQLITE_CORRUPT_BKPT; + if( nHdr>(u32)nRec || iHdr>=nHdr ) return SQLITE_CORRUPT_BKPT; iField = nHdr; for(i=0; i<=iCol; i++){ iHdr += getVarint32(&a[iHdr], t); From 25266685561fbe6db25dd72e3ae9b70a4a8da02f Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 21 May 2024 14:54:46 +0000 Subject: [PATCH 407/430] Do not attempt to run mmapcorrupt.test with builds that do not support mmap(). FossilOrigin-Name: 54a49f1847f95c377f0f611eb10f635b879bba8c2eb25e65e2f66a56f4f9a505 --- manifest | 14 +++++++------- manifest.uuid | 2 +- test/mmapcorrupt.test | 4 ++++ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 09a9da69c2..20bade802b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sharmless\scompiler\swarnings. -D 2024-05-21T13:34:26.341 +C Do\snot\sattempt\sto\srun\smmapcorrupt.test\swith\sbuilds\sthat\sdo\snot\ssupport\smmap(). +D 2024-05-21T14:54:46.724 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -1447,7 +1447,7 @@ F test/mmap1.test 18de3fd7b70a777af6004ca2feecfcdd3d0be17fa04058e808baf530c94b1a F test/mmap2.test 9d6dd9ddb4ad2379f29cc78f38ce1e63ed418022 F test/mmap3.test b3c297e78e6a8520aafcc1a8f140535594c9086e F test/mmap4.test 2e2b4e32555b58da15176e6fe750f17c9dcf7f93 -F test/mmapcorrupt.test 0d89724591f22a376019f3df60d075b838dd2ba6dae6effb0be465c49cf86d4a +F test/mmapcorrupt.test 470fb44fe92e99c1d23701d156f8c17865f5b027063c9119dcfdb842791f4465 F test/mmapfault.test d4c9eff9cd8c2dc14bc43e71e042f175b0a26fe3 F test/mmapwarm.test 2272005969cd17a910077bd5082f70bc1fefad9a875afec7fc9af483898ecaf3 F test/multiplex.test d74c034e52805f6de8cc5432cef8c9eb774bb64ec29b83a22effc8ca4dac1f08 @@ -2191,8 +2191,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P de8182cf1773ac0d04268d896a613841cf6bf61f9f030342170657d5e06f2acb -R 48a1dfe76e5f9714f60170e25f19a5ec -U drh -Z 85ec8dacf40c6db93df32b415530df39 +P aab59f9f7c1c4cfac4d29d7c7a381583295312baf3b9a75e30a617b1541e12e1 +R 818d4377176309545f29a9d7bd0669c5 +U dan +Z 22a050d68d008d1c3bd9c69172084f42 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 0c3ade05c4..4f0d499f6c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -aab59f9f7c1c4cfac4d29d7c7a381583295312baf3b9a75e30a617b1541e12e1 \ No newline at end of file +54a49f1847f95c377f0f611eb10f635b879bba8c2eb25e65e2f66a56f4f9a505 \ No newline at end of file diff --git a/test/mmapcorrupt.test b/test/mmapcorrupt.test index 70dbe84647..d434ec1836 100644 --- a/test/mmapcorrupt.test +++ b/test/mmapcorrupt.test @@ -16,6 +16,10 @@ set testdir [file dirname $argv0] source $testdir/tester.tcl set testprefix mmapcorrupt +ifcapable !mmap { + finish_test + return +} database_may_be_corrupt db close From 3731703dbb9dc9f88c8ed0da5bb88c35399478c0 Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 21 May 2024 17:37:50 +0000 Subject: [PATCH 408/430] Ensure an sqlite_dbdata cursor is properly reset before being used again, even if it has already encountered database corruption. FossilOrigin-Name: 3210e1ca4d0efedf9710c97abd050ba10d3af98cb1f029c26daa84daf42fbc7e --- ext/recover/dbdata.c | 2 ++ manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/ext/recover/dbdata.c b/ext/recover/dbdata.c index a999f1a853..109aeef2d6 100644 --- a/ext/recover/dbdata.c +++ b/ext/recover/dbdata.c @@ -325,6 +325,7 @@ static void dbdataResetCursor(DbdataCursor *pCsr){ sqlite3_free(pCsr->aPage); dbdataBufferFree(&pCsr->rec); pCsr->aPage = 0; + pCsr->nRec = 0; } /* @@ -596,6 +597,7 @@ static int dbdataNext(sqlite3_vtab_cursor *pCursor){ } }else{ /* If there is no record loaded, load it now. */ + assert( pCsr->rec.aBuf!=0 || pCsr->nRec==0 ); if( pCsr->nRec==0 ){ int bHasRowid = 0; int nPointer = 0; diff --git a/manifest b/manifest index 20bade802b..42c7c3296e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Do\snot\sattempt\sto\srun\smmapcorrupt.test\swith\sbuilds\sthat\sdo\snot\ssupport\smmap(). -D 2024-05-21T14:54:46.724 +C Ensure\san\ssqlite_dbdata\scursor\sis\sproperly\sreset\sbefore\sbeing\sused\sagain,\seven\sif\sit\shas\salready\sencountered\sdatabase\scorruption. +D 2024-05-21T17:37:50.943 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -478,7 +478,7 @@ F ext/rbu/rbuvacuum4.test ffccd22f67e2d0b380d2889685742159dfe0d19a3880ca3d2d1d69 F ext/rbu/sqlite3rbu.c 4a3376c0fb9a844a799ac529fb81260523f6b13c9f629bc270c632dbae5fc1f8 F ext/rbu/sqlite3rbu.h 9d923eb135c5d04aa6afd7c39ca47b0d1d0707c100e02f19fdde6a494e414304 F ext/rbu/test_rbu.c ee6ede75147bc081fe9bc3931e6b206277418d14d3fbceea6fdc6216d9b47055 -F ext/recover/dbdata.c 0a943861ec096de375097e0aaff07b480a002eab9b01fecd3f9e828faf4ef624 +F ext/recover/dbdata.c a22ecd689f00ff2ad33b5633c4ef84c8f088c65faeac18d4eb73c128395c7aec F ext/recover/recover1.test e16d78e94183562abff569967b18b7c77451d7044365516cd0fe14713a284851 F ext/recover/recover_common.tcl a61306c1eb45c0c3fc45652c35b2d4ec19729e340bdf65a272ce4c229cefd85a F ext/recover/recoverbuild.test c74170e0f7b02456af41838afeb5353fdb985a48cc2331d661bbabbca7c6b8e3 @@ -2191,8 +2191,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P aab59f9f7c1c4cfac4d29d7c7a381583295312baf3b9a75e30a617b1541e12e1 -R 818d4377176309545f29a9d7bd0669c5 +P 54a49f1847f95c377f0f611eb10f635b879bba8c2eb25e65e2f66a56f4f9a505 +R 03f38bbe86d08cc2accd8330faccbd25 U dan -Z 22a050d68d008d1c3bd9c69172084f42 +Z 9c29ad8747a8fddc9cb270f4ac86c97e # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 4f0d499f6c..b6db5e040b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -54a49f1847f95c377f0f611eb10f635b879bba8c2eb25e65e2f66a56f4f9a505 \ No newline at end of file +3210e1ca4d0efedf9710c97abd050ba10d3af98cb1f029c26daa84daf42fbc7e \ No newline at end of file From bebe2d8be8acfd02592c4972f4ba32c3b4e4a33f Mon Sep 17 00:00:00 2001 From: drh <> Date: Thu, 23 May 2024 13:25:27 +0000 Subject: [PATCH 409/430] Version 3.46.0 FossilOrigin-Name: 96c92aba00c8375bc32fafcdf12429c58bd8aabfcadab6683e35bbb9cdebf19e --- manifest | 13 ++++++++----- manifest.uuid | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/manifest b/manifest index 42c7c3296e..430e219336 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Ensure\san\ssqlite_dbdata\scursor\sis\sproperly\sreset\sbefore\sbeing\sused\sagain,\seven\sif\sit\shas\salready\sencountered\sdatabase\scorruption. -D 2024-05-21T17:37:50.943 +C Version\s3.46.0 +D 2024-05-23T13:25:27.566 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -2191,8 +2191,11 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 54a49f1847f95c377f0f611eb10f635b879bba8c2eb25e65e2f66a56f4f9a505 +P 3210e1ca4d0efedf9710c97abd050ba10d3af98cb1f029c26daa84daf42fbc7e R 03f38bbe86d08cc2accd8330faccbd25 -U dan -Z 9c29ad8747a8fddc9cb270f4ac86c97e +T +sym-major-release * +T +sym-release * +T +sym-version-3.46.0 * +U drh +Z 82f35d0822d1dfbb574e5dd2459b4a36 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index b6db5e040b..db75fc9bf9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -3210e1ca4d0efedf9710c97abd050ba10d3af98cb1f029c26daa84daf42fbc7e \ No newline at end of file +96c92aba00c8375bc32fafcdf12429c58bd8aabfcadab6683e35bbb9cdebf19e \ No newline at end of file From 936c8e42e151e95c5382995fba7e3f37eccf6c32 Mon Sep 17 00:00:00 2001 From: drh <> Date: Thu, 23 May 2024 23:30:27 +0000 Subject: [PATCH 410/430] Fix the window-function group_concat() so that it returns an empty string if it has one or more empty string inputs. FossilOrigin-Name: 7fe11274fc05a3773846ab1908fcaf4dc6a1b5a95d8b6abad253137aee097379 --- manifest | 21 +++++++++++---------- manifest.uuid | 2 +- src/func.c | 2 ++ test/window1.test | 18 ++++++++++++++++++ 4 files changed, 32 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 430e219336..281df7f8f0 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Version\s3.46.0 -D 2024-05-23T13:25:27.566 +C Fix\sthe\swindow-function\sgroup_concat()\sso\sthat\sit\sreturns\san\sempty\sstring\s\nif\sit\shas\sone\sor\smore\sempty\sstring\sinputs. +D 2024-05-23T23:30:27.098 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -707,7 +707,7 @@ F src/delete.c cb766727c78e715f9fb7ec8a7d03658ed2a3016343ca687acfcec9083cdca500 F src/expr.c f7bad20d2f74005f1f876e7fbb627222ea28250e44b296b047403720c5c21818 F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c a47610f0a5c6cb0ad79f8fcef039c01833dec0c751bb695f28dc0ec6a4c3ba00 -F src/func.c 283d4f3b2751a1d9339fd93a8a013d1948fd5f4474a3cab0955eb4fafd445d0f +F src/func.c f1f57c6863c1380f31ecf3d61732495bfff847a8e35a832c7e306e310db5a799 F src/global.c 61a419dd9e993b9be0f91de4c4ccf322b053eb829868e089f0321dd669be3b90 F src/hash.c 9ee4269fb1d6632a6fecfb9479c93a1f29271bddbbaf215dd60420bcb80c7220 F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 @@ -2034,7 +2034,7 @@ F test/win32heap.test 10fd891266bd00af68671e702317726375e5407561d859be1aa04696f2 F test/win32lock.test e0924eb8daac02bf80e9da88930747bd44dd9b230b7759fed927b1655b467c9c F test/win32longpath.test 4baffc3acb2e5188a5e3a895b2b543ed09e62f7c72d713c1feebf76222fe9976 F test/win32nolock.test ac4f08811a562e45a5755e661f45ca85892bdbbc -F test/window1.test 5e8abe56a7d667eeddbba6de180086dcf69ed528d046447a25464f945ece101f +F test/window1.test 79dc3b9a2226f622d7e104a1fc750d1c4c3c08d6147b59085bdbe05352947ffa F test/window2.tcl 492c125fa550cda1dd3555768a2303b3effbeceee215293adf8871efc25f1476 F test/window2.test e466a88bd626d66edc3d352d7d7e1d5531e0079b549ba44efb029d1fbff9fd3c F test/window3.tcl acea6e86a4324a210fd608d06741010ca83ded9fde438341cb978c49928faf03 @@ -2191,11 +2191,12 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 3210e1ca4d0efedf9710c97abd050ba10d3af98cb1f029c26daa84daf42fbc7e -R 03f38bbe86d08cc2accd8330faccbd25 -T +sym-major-release * -T +sym-release * -T +sym-version-3.46.0 * +P 96c92aba00c8375bc32fafcdf12429c58bd8aabfcadab6683e35bbb9cdebf19e +Q +cec6bb3fc9932ea78ec8e63d9c2d4e56a4d94b8973b9ea46033cc4baa87c0476 +R e46e2ca0b5c9c7bbd4a13f63dc50d414 +T *branch * branch-3.46 +T *sym-branch-3.46 * +T -sym-trunk * U drh -Z 82f35d0822d1dfbb574e5dd2459b4a36 +Z 889128282019d0caef715a8650aec8f9 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index db75fc9bf9..5570b63751 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -96c92aba00c8375bc32fafcdf12429c58bd8aabfcadab6683e35bbb9cdebf19e \ No newline at end of file +7fe11274fc05a3773846ab1908fcaf4dc6a1b5a95d8b6abad253137aee097379 \ No newline at end of file diff --git a/src/func.c b/src/func.c index 18004984d9..058f71cb64 100644 --- a/src/func.c +++ b/src/func.c @@ -2206,6 +2206,8 @@ static void groupConcatValue(sqlite3_context *context){ sqlite3_result_error_toobig(context); }else if( pAccum->accError==SQLITE_NOMEM ){ sqlite3_result_error_nomem(context); + }else if( pGCC->nAccum>0 && pAccum->nChar==0 ){ + sqlite3_result_text(context, "", 1, SQLITE_STATIC); }else{ const char *zText = sqlite3_str_value(pAccum); sqlite3_result_text(context, zText, pAccum->nChar, SQLITE_TRANSIENT); diff --git a/test/window1.test b/test/window1.test index d8348a8980..457852c145 100644 --- a/test/window1.test +++ b/test/window1.test @@ -2375,5 +2375,23 @@ do_execsql_test 77.2 { SELECT max(~likely(x)) FILTER (WHERE true) FROM t1 INDEXED BY t1x GROUP BY x; } {-2 -3 -5 -9} +# 2024-05-23 https://sqlite.org/forum/forumpost/bf8f43aa522c2299 +# +# A bug in group_concat() when used as a window function, reported +# just hours after the 3.46.0 release, though first appearing +# in 3.28.0. +# +# When used as a window function, a group_concat() was not +# correctly distinguishing between NULL and empty-string for +# its return value. +# +do_execsql_test 78.1 { + SELECT quote(group_concat(x) OVER ()) FROM (SELECT '' AS x); +} '' +do_execsql_test 78.2 { + SELECT quote(group_concat(x) OVER ( + ORDER BY y RANGE BETWEEN 1 FOLLOWING AND 2 FOLLOWING + )) FROM (SELECT 'abc' AS x, 1 AS y); +} NULL finish_test From 0ed22ad8476da9b41c350f5767ffefb4e48fdd9d Mon Sep 17 00:00:00 2001 From: drh <> Date: Thu, 23 May 2024 23:34:45 +0000 Subject: [PATCH 411/430] Increase the version number to 3.46.1 FossilOrigin-Name: 170e3a91d53ec28ae25e6b0d15ef3af65438f776097a0b8b538f66c37583eeb5 --- VERSION | 2 +- autoconf/tea/configure.ac | 2 +- configure | 18 +++++++++--------- manifest | 20 ++++++++------------ manifest.uuid | 2 +- 5 files changed, 20 insertions(+), 24 deletions(-) diff --git a/VERSION b/VERSION index 850ac8f28c..421931ea1e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.46.0 +3.46.1 diff --git a/autoconf/tea/configure.ac b/autoconf/tea/configure.ac index f188f22039..ea7eeda70f 100644 --- a/autoconf/tea/configure.ac +++ b/autoconf/tea/configure.ac @@ -19,7 +19,7 @@ dnl to configure the system for the local environment. # so that we create the export library with the dll. #----------------------------------------------------------------------- -AC_INIT([sqlite],[3.46.0]) +AC_INIT([sqlite],[3.46.1]) #-------------------------------------------------------------------- # Call TEA_INIT as the first TEA_ macro to set up initial vars. diff --git a/configure b/configure index f6717f96fb..5ad0ccad3c 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for sqlite 3.46.0. +# Generated by GNU Autoconf 2.69 for sqlite 3.46.1. # # # Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc. @@ -726,8 +726,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='sqlite' PACKAGE_TARNAME='sqlite' -PACKAGE_VERSION='3.46.0' -PACKAGE_STRING='sqlite 3.46.0' +PACKAGE_VERSION='3.46.1' +PACKAGE_STRING='sqlite 3.46.1' PACKAGE_BUGREPORT='' PACKAGE_URL='' @@ -1472,7 +1472,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures sqlite 3.46.0 to adapt to many kinds of systems. +\`configure' configures sqlite 3.46.1 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1537,7 +1537,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of sqlite 3.46.0:";; + short | recursive ) echo "Configuration of sqlite 3.46.1:";; esac cat <<\_ACEOF @@ -1668,7 +1668,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -sqlite configure 3.46.0 +sqlite configure 3.46.1 generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. @@ -2087,7 +2087,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by sqlite $as_me 3.46.0, which was +It was created by sqlite $as_me 3.46.1, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ @@ -12481,7 +12481,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by sqlite $as_me 3.46.0, which was +This file was extended by sqlite $as_me 3.46.1, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -12547,7 +12547,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -sqlite config.status 3.46.0 +sqlite config.status 3.46.1 configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" diff --git a/manifest b/manifest index 281df7f8f0..eb948a1fca 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\swindow-function\sgroup_concat()\sso\sthat\sit\sreturns\san\sempty\sstring\s\nif\sit\shas\sone\sor\smore\sempty\sstring\sinputs. -D 2024-05-23T23:30:27.098 +C Increase\sthe\sversion\snumber\sto\s3.46.1 +D 2024-05-23T23:34:45.406 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -7,7 +7,7 @@ F Makefile.in 993a7874e3d3721df61846f03dda4a9ef7490da11953ae36ba1bb0c0346eaf4a F Makefile.linux-gcc f3842a0b1efbfbb74ac0ef60e56b301836d05b4d867d014f714fa750048f1ab6 F Makefile.msc e64a52619310d3067f6c38f56eedd15918a82dade70954197d6da486ad99d7f4 F README.md 6358805260a03ebead84e168bbf3740ddf3f683b477e478567186aa7afb490d3 -F VERSION c84541c6a9e8426462176fbb1f9ecb5cfd7d1bb56228053ff7eeba8841673eb6 +F VERSION 01b0b94ee03b29c27cb72ef03c460cd9476dee97b0cf8cf74b17a201e199820a F aclocal.m4 a5c22d164aff7ed549d53a90fa56d56955281f50 F art/icon-243x273.gif 9750b734f82fdb3dc43127753d5e6fbf3b62c9f4e136c2fbf573b2f57ea87af5 F art/icon-80x90.gif 65509ce3e5f86a9cd64fe7fca2d23954199f31fe44c1e09e208c80fb83d87031 @@ -24,7 +24,7 @@ F autoconf/configure.ac ec7fa914c5e74ff212fe879f9bb6918e1234497e05facfb641f30c4d F autoconf/tea/Makefile.in 106a96f2f745d41a0f6193f1de98d7355830b65d45032c18cd7c90295ec24196 F autoconf/tea/README 3e9a3c060f29a44344ab50aec506f4db903fb873 F autoconf/tea/aclocal.m4 52c47aac44ce0ddb1f918b6993e8beb8eee88f43 -F autoconf/tea/configure.ac 9e74135563a901d9b1a019bad1c9d73a6659fa32325f6a565bef72bfb0ec7297 +F autoconf/tea/configure.ac 629148599fb2c29003b34e72dd161473b5fe23b6f26a2281200e9581daaede95 F autoconf/tea/doc/sqlite3.n e1fe45d4f5286ee3d0ccc877aca2a0def488e9bb F autoconf/tea/license.terms 13bd403c9610fd2b76ece0ab50c4c5eda933d523 F autoconf/tea/pkgIndex.tcl.in b9eb6dd37f64e08e637d576b3c83259814b9cddd78bec4af2e5abfc6c5c750ce @@ -35,7 +35,7 @@ F autoconf/tea/win/nmakehlp.c b01f822eabbe1ed2b64e70882d97d48402b42d2689a1ea0034 F autoconf/tea/win/rules.vc c511f222b80064096b705dbeb97060ee1d6b6d63 F config.guess 883205ddf25b46f10c181818bf42c09da9888884af96f79e1719264345053bd6 F config.sub c2d0260f17f3e4bc0b6808fccf1b291cb5e9126c14fc5890efc77b9fd0175559 -F configure 40f7af9ed5ca0d44a4b9bc7ad34f1ee4867bb4eeb19e75036be6bed66193a498 x +F configure 1728380292e4153caf04870b0734c771b9cdc73be655181618f7b8253f2d9d5c x F configure.ac f25bd7843120f2c2b8bc9db5a92b0502bbdd28e68907415c3d42fc8e57c657b9 F contrib/sqlitecon.tcl 210a913ad63f9f991070821e599d600bd913e0ad F doc/F2FS.txt c1d4a0ae9711cfe0e1d8b019d154f1c29e0d3abfe820787ba1e9ed7691160fcd @@ -2191,12 +2191,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 96c92aba00c8375bc32fafcdf12429c58bd8aabfcadab6683e35bbb9cdebf19e -Q +cec6bb3fc9932ea78ec8e63d9c2d4e56a4d94b8973b9ea46033cc4baa87c0476 -R e46e2ca0b5c9c7bbd4a13f63dc50d414 -T *branch * branch-3.46 -T *sym-branch-3.46 * -T -sym-trunk * +P 7fe11274fc05a3773846ab1908fcaf4dc6a1b5a95d8b6abad253137aee097379 +R bc976ec44d8e59a12d82f3a5926b8914 U drh -Z 889128282019d0caef715a8650aec8f9 +Z ac84877616e5695f3aaf49c4a152f507 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 5570b63751..26265acc5b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7fe11274fc05a3773846ab1908fcaf4dc6a1b5a95d8b6abad253137aee097379 \ No newline at end of file +170e3a91d53ec28ae25e6b0d15ef3af65438f776097a0b8b538f66c37583eeb5 \ No newline at end of file From ee8e00f53f42433de0b9f197cc5f4e7de07b247a Mon Sep 17 00:00:00 2001 From: drh <> Date: Sat, 25 May 2024 23:17:49 +0000 Subject: [PATCH 412/430] Ensure that sqlite3ViewGetColumnNames() returns non-zero on any error. FossilOrigin-Name: 01ead0a2d98cab8c58216387d76756419e20b827adba809596a2ad67382b9278 --- manifest | 13 +++++++------ manifest.uuid | 2 +- src/build.c | 7 ++++--- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index eb948a1fca..8db2343ec2 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Increase\sthe\sversion\snumber\sto\s3.46.1 -D 2024-05-23T23:34:45.406 +C Ensure\sthat\ssqlite3ViewGetColumnNames()\sreturns\snon-zero\son\sany\serror. +D 2024-05-25T23:17:49.594 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -696,7 +696,7 @@ F src/btmutex.c 79a43670447eacc651519a429f6ece9fd638563cf95b469d6891185ddae2b522 F src/btree.c 71b80e77b255144db47180fda8138740608e382a44231942464029b1a45fc036 F src/btree.h 55066f513eb095db935169dab1dc2f7c7a747ef223c533f5d4ad4dfed346cbd0 F src/btreeInt.h 98aadb6dcb77b012cab2574d6a728fad56b337fc946839b9898c4b4c969e30b6 -F src/build.c 11ec7014a3c468e7b3ccc8dda8d9111cd5a29a358df18818788601e0600aaabd +F src/build.c 237ccc0290d131d646be722f418e92ee0a38043aee25e7dfdc75f8ce5b3abe4e F src/callback.c db3a45e376deff6a16c0058163fe0ae2b73a2945f3f408ca32cf74960b28d490 F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e F src/ctime.c 64e4b1227b4ed123146f0aa2989131d1fbd9b927b11e80c9d58c6a68f9cd5ce3 @@ -2191,8 +2191,9 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 7fe11274fc05a3773846ab1908fcaf4dc6a1b5a95d8b6abad253137aee097379 -R bc976ec44d8e59a12d82f3a5926b8914 +P 170e3a91d53ec28ae25e6b0d15ef3af65438f776097a0b8b538f66c37583eeb5 +Q +57aeb3a287fc190bf8d438a7b03d6715c05fd3fd71559c6a14d7bd910d37b38d +R 68d938d6c76952afa664e25f6697241e U drh -Z ac84877616e5695f3aaf49c4a152f507 +Z ebcf7d570338e7449a5960dc5015d2c4 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 26265acc5b..26eb1b1620 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -170e3a91d53ec28ae25e6b0d15ef3af65438f776097a0b8b538f66c37583eeb5 \ No newline at end of file +01ead0a2d98cab8c58216387d76756419e20b827adba809596a2ad67382b9278 \ No newline at end of file diff --git a/src/build.c b/src/build.c index 10aa342407..9747810e82 100644 --- a/src/build.c +++ b/src/build.c @@ -3064,8 +3064,9 @@ void sqlite3CreateView( #if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE) /* ** The Table structure pTable is really a VIEW. Fill in the names of -** the columns of the view in the pTable structure. Return the number -** of errors. If an error is seen leave an error message in pParse->zErrMsg. +** the columns of the view in the pTable structure. Return non-zero if +** there are errors. If an error is seen an error message is left +** in pParse->zErrMsg. */ static SQLITE_NOINLINE int viewGetColumnNames(Parse *pParse, Table *pTable){ Table *pSelTab; /* A fake table from which we get the result set */ @@ -3188,7 +3189,7 @@ static SQLITE_NOINLINE int viewGetColumnNames(Parse *pParse, Table *pTable){ sqlite3DeleteColumnNames(db, pTable); } #endif /* SQLITE_OMIT_VIEW */ - return nErr; + return nErr + pParse->nErr; } int sqlite3ViewGetColumnNames(Parse *pParse, Table *pTable){ assert( pTable!=0 ); From 2eec675e6e307951d458768de71cf38916830e67 Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 27 May 2024 11:38:03 +0000 Subject: [PATCH 413/430] Fix a possible buffer overwrite in the ".import" command. FossilOrigin-Name: 55eee9f920e5dfdb88be5bb294707e743fa7ffe679fb0ff1e8f04b3a67ee271e --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/shell.c.in | 13 +++++++++---- test/shell5.test | 12 ++++++++++++ 4 files changed, 30 insertions(+), 13 deletions(-) diff --git a/manifest b/manifest index 8db2343ec2..ee447759aa 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Ensure\sthat\ssqlite3ViewGetColumnNames()\sreturns\snon-zero\son\sany\serror. -D 2024-05-25T23:17:49.594 +C Fix\sa\spossible\sbuffer\soverwrite\sin\sthe\s".import"\scommand. +D 2024-05-27T11:38:03.090 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -755,7 +755,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c 22f1fa3423b377c02ae78d451cfeb1c2d96dcf0389c0642cbdcd19d3bfd7ae01 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c 1a841c38974d45cf15a7611398479182b61ad4c187423c380741d8b1688fe607 -F src/shell.c.in 885dafabb3f16d68bdb4576683afb0e39a1939f50985b162255bf656c470babf +F src/shell.c.in ebb698028ec031e0b1595865500097d2005f977be0efd14bd8b0ddf634d5ed8d F src/sqlite.h.in c71d9ef76a6d32dc7ff2d373f2e57ce09056af26c1457bcadae5358b7628c7c3 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 @@ -1614,7 +1614,7 @@ F test/shell1.test 17a5ca9c6f24f807b2f505b4b38fcbce143d96cd8664c06c34bbbe0672bf7 F test/shell2.test 56da24128304c9ab67da2964cc80beff7b35761c446ec6e6e98bff2775b15026 F test/shell3.test 5ad4b2813717956414f2c0c8a2027895cd98ccf7dd54dbacbde4d4f5591ce5a1 F test/shell4.test 522fdc628c55eff697b061504fb0a9e4e6dfc5d9087a633ab0f3dd11bcc4f807 -F test/shell5.test 5b2ab1c0540217773f939927c24163a56257446da3f564d4724042620bfea762 +F test/shell5.test 6a49440bddc33a132f856fb189e71228f8132963655d12a2c8b8a161263b9632 F test/shell6.test e3b883b61d4916b6906678a35f9d19054861123ad91b856461e0a456273bdbb8 F test/shell7.test 753c6ece5361df50025a50cadf378ea36db9cc05fb23d7a96cff7fa130626ef9 F test/shell8.test aea51ecbcd4494c746b096aeff51d841d04d5f0dc4b62eb42427f16109b87acd @@ -2191,9 +2191,9 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 170e3a91d53ec28ae25e6b0d15ef3af65438f776097a0b8b538f66c37583eeb5 -Q +57aeb3a287fc190bf8d438a7b03d6715c05fd3fd71559c6a14d7bd910d37b38d -R 68d938d6c76952afa664e25f6697241e +P 01ead0a2d98cab8c58216387d76756419e20b827adba809596a2ad67382b9278 +Q +0fd958fa9b56a8ef254127e29800ca2a267590e86edf739bd339239b25a5da6e +R 697db273532868aed3d3530909b97d35 U drh -Z ebcf7d570338e7449a5960dc5015d2c4 +Z 8b9b061549db0b8a2214bdf7b4c184db # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 26eb1b1620..d485de85c2 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -01ead0a2d98cab8c58216387d76756419e20b827adba809596a2ad67382b9278 \ No newline at end of file +55eee9f920e5dfdb88be5bb294707e743fa7ffe679fb0ff1e8f04b3a67ee271e \ No newline at end of file diff --git a/src/shell.c.in b/src/shell.c.in index 0029682f32..7960acfab9 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -8977,7 +8977,6 @@ static int do_meta_command(char *zLine, ShellState *p){ import_cleanup(&sCtx); shell_out_of_memory(); } - nByte = strlen(zSql); rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0); sqlite3_free(zSql); zSql = 0; @@ -8996,16 +8995,21 @@ static int do_meta_command(char *zLine, ShellState *p){ sqlite3_finalize(pStmt); pStmt = 0; if( nCol==0 ) return 0; /* no columns, no error */ - zSql = sqlite3_malloc64( nByte*2 + 20 + nCol*2 ); + + nByte = 64 /* space for "INSERT INTO", "VALUES(", ")\0" */ + + (zSchema ? strlen(zSchema)*2 + 2: 0) /* Quoted schema name */ + + strlen(zTable)*2 + 2 /* Quoted table name */ + + nCol*2; /* Space for ",?" for each column */ + zSql = sqlite3_malloc64( nByte ); if( zSql==0 ){ import_cleanup(&sCtx); shell_out_of_memory(); } if( zSchema ){ - sqlite3_snprintf(nByte+20, zSql, "INSERT INTO \"%w\".\"%w\" VALUES(?", + sqlite3_snprintf(nByte, zSql, "INSERT INTO \"%w\".\"%w\" VALUES(?", zSchema, zTable); }else{ - sqlite3_snprintf(nByte+20, zSql, "INSERT INTO \"%w\" VALUES(?", zTable); + sqlite3_snprintf(nByte, zSql, "INSERT INTO \"%w\" VALUES(?", zTable); } j = strlen30(zSql); for(i=1; i=2 ){ oputf("Insert using: %s\n", zSql); } diff --git a/test/shell5.test b/test/shell5.test index 877676d726..8727edaafb 100644 --- a/test/shell5.test +++ b/test/shell5.test @@ -585,4 +585,16 @@ do_test shell5-7.1 { SELECT * FROM t1;} } {0 aaa|bbb|aaabbb} +#------------------------------------------------------------------------- + +do_test shell5-8.1 { + + set out [open shell5.csv w] + fconfigure $out -translation lf + puts $out x + close $out + + catchcmd :memory: {.import --csv shell5.csv '""""""""""""""""""""""""""""""""""""""""""""""'} +} {0 {}} + finish_test From ec79dfaf7ef311c960c6d440d6fa7eaff9f10c30 Mon Sep 17 00:00:00 2001 From: drh <> Date: Wed, 5 Jun 2024 16:50:34 +0000 Subject: [PATCH 414/430] Fix an fts5 problem with secure-delete mode causing integrity-check to erroneously report a corrupt index. FossilOrigin-Name: 0a7fa0a434bb84023bf9075463613857966ca579e18de903c0d9b1561acf42c6 --- ext/fts5/fts5_main.c | 1 + ext/fts5/test/fts5secure8.test | 16 ++++++++++++++++ manifest | 16 ++++++++-------- manifest.uuid | 2 +- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/ext/fts5/fts5_main.c b/ext/fts5/fts5_main.c index f609f7f34a..b3ca2f71bb 100644 --- a/ext/fts5/fts5_main.c +++ b/ext/fts5/fts5_main.c @@ -1700,6 +1700,7 @@ static int fts5UpdateMethod( rc = SQLITE_ERROR; }else{ rc = fts5SpecialDelete(pTab, apVal); + bUpdateOrDelete = 1; } }else{ rc = fts5SpecialInsert(pTab, z, apVal[2 + pConfig->nCol + 1]); diff --git a/ext/fts5/test/fts5secure8.test b/ext/fts5/test/fts5secure8.test index 8ceb9630aa..0216bb6ea1 100644 --- a/ext/fts5/test/fts5secure8.test +++ b/ext/fts5/test/fts5secure8.test @@ -42,6 +42,22 @@ do_execsql_test 1.2 { PRAGMA integrity_check; } {ok} +do_execsql_test 2.0 { + CREATE VIRTUAL TABLE xyz USING fts5 ( + name, + content='' + ); + + INSERT INTO xyz(xyz, rank) VALUES('secure-delete', 1); + INSERT INTO xyz (rowid, name) VALUES(1, 'A'); + INSERT INTO xyz (rowid, name) VALUES(2, 'A'); + INSERT INTO xyz(xyz, rowid, name) VALUES('delete', 2, 'A'); +} + +do_execsql_test 2.1 { + pragma quick_check; +} {ok} + diff --git a/manifest b/manifest index ee447759aa..fe24f4f7c0 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\spossible\sbuffer\soverwrite\sin\sthe\s".import"\scommand. -D 2024-05-27T11:38:03.090 +C Fix\san\sfts5\sproblem\swith\ssecure-delete\smode\scausing\sintegrity-check\sto\serroneously\sreport\sa\scorrupt\sindex. +D 2024-06-05T16:50:34.984 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -100,7 +100,7 @@ F ext/fts5/fts5_config.c 8072a207034b51ae9b7694121d1b5715c794e94b275e088f70ae532 F ext/fts5/fts5_expr.c e91156ebdcc08d837f4f324168f69f3c0d7fdef0e521fd561efb48ef3297b696 F ext/fts5/fts5_hash.c adda4272be401566a6e0ba1acbe70ee5cb97fce944bc2e04dc707152a0ec91b1 F ext/fts5/fts5_index.c ee0f4d50bc0c58a7c5ef7d645e7e38e1e59315b8ea9d722ae00c5f949ee65379 -F ext/fts5/fts5_main.c d68bd9533d5a638b7f6fae61c3cb0a15257dcdcccedaf3d0b3c9f55940c85048 +F ext/fts5/fts5_main.c 981551daf629445e37bef0280b888631503adeec37a1f9b5f7751a4430b70ac2 F ext/fts5/fts5_storage.c f9e31b0d155e9b2c92d5d3a09ad7a56b937fbf1c7f962e10f4ca6281349f3934 F ext/fts5/fts5_tcl.c fdf7e2bb9a9186cfcaf2d2ce11d338309342b7a7593c2812bc54455db53da5d2 F ext/fts5/fts5_test_mi.c 08c11ec968148d4cb4119d96d819f8c1f329812c568bac3684f5464be177d3ee @@ -218,7 +218,7 @@ F ext/fts5/test/fts5secure4.test 0d10a80590c07891478700af7793b232962042677432b98 F ext/fts5/test/fts5secure5.test c07a68ced5951567ac116c22f2d2aafae497e47fe9fcb6a335c22f9c7a4f2c3a F ext/fts5/test/fts5secure6.test 74bf04733cc523bccca519bb03d3b4e2ed6f6e3db7c59bf6be82c88a0ac857fd F ext/fts5/test/fts5secure7.test fd03d0868d64340a1db8615b02e5508fea409de13910114e4f19eaefc120777a -F ext/fts5/test/fts5secure8.test eb3579e9d58b0acad97e8082dee1f99b2d393198f03500b453c2b25761c0c298 +F ext/fts5/test/fts5secure8.test e68c0ac4447f415ff3e4e82531e99548289286f9f3a29c8cd53036113fe28602 F ext/fts5/test/fts5securefault.test dbca2b6a1c16700017f5051138991b705410889933f2a37c57ae8a23b296b10b F ext/fts5/test/fts5simple.test a298670508c1458b88ce6030440f26a30673931884eb5f4094ac1773b3ba217b F ext/fts5/test/fts5simple2.test 8dd2389ee75e21a1429fe87e5f8c7d9a97ad1470304a8a2d3ba4b8c3c345fecd @@ -2191,9 +2191,9 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 01ead0a2d98cab8c58216387d76756419e20b827adba809596a2ad67382b9278 -Q +0fd958fa9b56a8ef254127e29800ca2a267590e86edf739bd339239b25a5da6e -R 697db273532868aed3d3530909b97d35 +P 55eee9f920e5dfdb88be5bb294707e743fa7ffe679fb0ff1e8f04b3a67ee271e +Q +80bef4d60ba9e3679ea66655ca36fcfaa888775a3d1598d50e9649ad84a95b63 +R 2f54496332cca3ba9e6b24187c763a1f U drh -Z 8b9b061549db0b8a2214bdf7b4c184db +Z 2f13814fa7395f208fbd723618b40d57 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index d485de85c2..848b4b1eff 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -55eee9f920e5dfdb88be5bb294707e743fa7ffe679fb0ff1e8f04b3a67ee271e \ No newline at end of file +0a7fa0a434bb84023bf9075463613857966ca579e18de903c0d9b1561acf42c6 \ No newline at end of file From 2fdb32316daaeb3b4651fbb57a71732eb6d7b65b Mon Sep 17 00:00:00 2001 From: drh <> Date: Sun, 9 Jun 2024 17:58:09 +0000 Subject: [PATCH 415/430] Disable the omit-noop-join optimization when there are 64 or more terms in the ORDER BY clause. FossilOrigin-Name: a7fe90c1581e7e4ffbcb6fb9bcf1db7631cde612ad1d4a33b6b9a22640db5817 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/sqliteInt.h | 2 +- src/where.c | 13 +++++++++---- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/manifest b/manifest index fe24f4f7c0..b172a21cbf 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\san\sfts5\sproblem\swith\ssecure-delete\smode\scausing\sintegrity-check\sto\serroneously\sreport\sa\scorrupt\sindex. -D 2024-06-05T16:50:34.984 +C Disable\sthe\somit-noop-join\soptimization\swhen\sthere\sare\s64\sor\smore\sterms\sin\nthe\sORDER\sBY\sclause. +D 2024-06-09T17:58:09.994 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -759,7 +759,7 @@ F src/shell.c.in ebb698028ec031e0b1595865500097d2005f977be0efd14bd8b0ddf634d5ed8 F src/sqlite.h.in c71d9ef76a6d32dc7ff2d373f2e57ce09056af26c1457bcadae5358b7628c7c3 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 -F src/sqliteInt.h 6a9fa3902c9faca2b57060e822f2afadfbf96d64c4ede81e201f0e0c42d7e4aa +F src/sqliteInt.h 9d022fc8dc3fccd69e518c115101ab4c3d4cb45a79549c1a4c26fec492eb2cfb F src/sqliteLimit.h 6878ab64bdeb8c24a1d762d45635e34b96da21132179023338c93f820eee6728 F src/status.c cb11f8589a6912af2da3bb1ec509a94dd8ef27df4d4c1a97e0bcf2309ece972b F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1 @@ -839,7 +839,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c 887fc4ca3f020ebb2e376f222069570834ac63bf50111ef0cbf3ae417048ed89 F src/wal.h ba252daaa94f889f4b2c17c027e823d9be47ce39da1d3799886bbd51f0490452 F src/walker.c 7c7ea0115345851c3da4e04e2e239a29983b61fb5b038b94eede6aba462640e2 -F src/where.c 6f02c3936d1f9a637d8d7b5ad7362371af3e4434b0ec1eb950189a83de560d59 +F src/where.c 4df8b013fe5b56a6674af695fab8c738e59c9d21005abb11f53c42edf52b50bd F src/whereInt.h 82a13766f13d1a53b05387c2e60726289ef26404bc7b9b1f7770204d97357fb8 F src/wherecode.c f5255f49d1f42b6e7e6b0362ff3522fa88cbcaa7213e52f9374744027ecdebca F src/whereexpr.c 67d15caf88a1a9528283d68ff578e024cf9fe810b517bb0343e5aaf695ad97dd @@ -2191,9 +2191,9 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 55eee9f920e5dfdb88be5bb294707e743fa7ffe679fb0ff1e8f04b3a67ee271e -Q +80bef4d60ba9e3679ea66655ca36fcfaa888775a3d1598d50e9649ad84a95b63 -R 2f54496332cca3ba9e6b24187c763a1f +P 0a7fa0a434bb84023bf9075463613857966ca579e18de903c0d9b1561acf42c6 +Q +40de3939792e17df25598b3e60d1cebcecde2b00832acd55604f14b21398a9a7 +R 846daec7b0fe01d46a65b23c75ccc79e U drh -Z 2f13814fa7395f208fbd723618b40d57 +Z f18ab008f7a68095fb66c91171ab50b9 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 848b4b1eff..52294b7fb2 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0a7fa0a434bb84023bf9075463613857966ca579e18de903c0d9b1561acf42c6 \ No newline at end of file +a7fe90c1581e7e4ffbcb6fb9bcf1db7631cde612ad1d4a33b6b9a22640db5817 \ No newline at end of file diff --git a/src/sqliteInt.h b/src/sqliteInt.h index d98a4f7f06..ec126b0871 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -3388,7 +3388,7 @@ struct SrcList { #define WHERE_AGG_DISTINCT 0x0400 /* Query is "SELECT agg(DISTINCT ...)" */ #define WHERE_ORDERBY_LIMIT 0x0800 /* ORDERBY+LIMIT on the inner loop */ #define WHERE_RIGHT_JOIN 0x1000 /* Processing a RIGHT JOIN */ - /* 0x2000 not currently used */ +#define WHERE_KEEP_ALL_JOINS 0x2000 /* Do not do the omit-noop-join opt */ #define WHERE_USE_LIMIT 0x4000 /* Use the LIMIT in cost estimates */ /* 0x8000 not currently used */ diff --git a/src/where.c b/src/where.c index fac0f6c5eb..2e3679d5d5 100644 --- a/src/where.c +++ b/src/where.c @@ -5848,6 +5848,10 @@ static void showAllWhereLoops(WhereInfo *pWInfo, WhereClause *pWC){ ** the right-most table of a subquery that was flattened into the ** main query and that subquery was the right-hand operand of an ** inner join that held an ON or USING clause. +** 6) The ORDER BY clause has 63 or fewer terms +** 7) The omit-noop-join optimization is enabled. +** +** Items (1), (6), and (7) are checked by the caller. ** ** For example, given: ** @@ -6261,6 +6265,7 @@ WhereInfo *sqlite3WhereBegin( if( pOrderBy && pOrderBy->nExpr>=BMS ){ pOrderBy = 0; wctrlFlags &= ~WHERE_WANT_DISTINCT; + wctrlFlags |= WHERE_KEEP_ALL_JOINS; /* Disable omit-noop-join opt */ } /* The number of tables in the FROM clause is limited by the number of @@ -6561,10 +6566,10 @@ WhereInfo *sqlite3WhereBegin( ** in-line sqlite3WhereCodeOneLoopStart() for performance reasons. */ notReady = ~(Bitmask)0; - if( pWInfo->nLevel>=2 - && pResultSet!=0 /* these two combine to guarantee */ - && 0==(wctrlFlags & WHERE_AGG_DISTINCT) /* condition (1) above */ - && OptimizationEnabled(db, SQLITE_OmitNoopJoin) + if( pWInfo->nLevel>=2 /* Must be a join, or this opt8n is pointless */ + && pResultSet!=0 /* Condition (1) */ + && 0==(wctrlFlags & (WHERE_AGG_DISTINCT|WHERE_KEEP_ALL_JOINS)) /* (1),(6) */ + && OptimizationEnabled(db, SQLITE_OmitNoopJoin) /* (7) */ ){ notReady = whereOmitNoopJoin(pWInfo, notReady); nTabList = pWInfo->nLevel; From 94dbae0c8d3a6d8ae73c1facac7ad8f5c5609099 Mon Sep 17 00:00:00 2001 From: stephan Date: Wed, 12 Jun 2024 21:08:02 +0000 Subject: [PATCH 416/430] Fix a potential db corruption case triggered by the OPFS VFS's xCheckReservedLock() implementation. FossilOrigin-Name: a7cd07d96ef420bb1512e6d575bf756809561a536c627900d0eeac879f72e63b --- ext/wasm/api/sqlite3-vfs-opfs.c-pp.js | 14 +++++++++++--- manifest | 17 +++++++++-------- manifest.uuid | 2 +- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js b/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js index 4c654c3351..1c9a92a373 100644 --- a/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js +++ b/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js @@ -720,9 +720,18 @@ const installOpfsVfs = function callee(options){ involve an inherent race condition. For the time being, pending a better solution, we simply report whether the given pFile is open. + + Update 2024-06-12: based on forum discussions, this + function now always sets pOut to 0 (false): + + https://sqlite.org/forum/forumpost/a2f573b00cda1372 */ - const f = __openFiles[pFile]; - wasm.poke(pOut, f.lockType ? 1 : 0, 'i32'); + if(1){ + wasm.poke(pOut, 0, 'i32'); + }else{ + const f = __openFiles[pFile]; + wasm.poke(pOut, f.lockType ? 1 : 0, 'i32'); + } return 0; }, xClose: function(pFile){ @@ -738,7 +747,6 @@ const installOpfsVfs = function callee(options){ return rc; }, xDeviceCharacteristics: function(pFile){ - //debug("xDeviceCharacteristics(",pFile,")"); return capi.SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN; }, xFileControl: function(pFile, opId, pArg){ diff --git a/manifest b/manifest index b172a21cbf..84bb200162 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Disable\sthe\somit-noop-join\soptimization\swhen\sthere\sare\s64\sor\smore\sterms\sin\nthe\sORDER\sBY\sclause. -D 2024-06-09T17:58:09.994 +C Fix\sa\spotential\sdb\scorruption\scase\striggered\sby\sthe\sOPFS\sVFS's\sxCheckReservedLock()\simplementation. +D 2024-06-12T21:08:02.745 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -617,7 +617,7 @@ F ext/wasm/api/sqlite3-license-version-header.js 0c807a421f0187e778dc1078f10d299 F ext/wasm/api/sqlite3-opfs-async-proxy.js 196ad83d36ca794e564044788c9d21b964679d63cad865f604da37c4afc9a285 F ext/wasm/api/sqlite3-vfs-helper.c-pp.js 3f828cc66758acb40e9c5b4dcfd87fd478a14c8fb7f0630264e6c7fa0e57515d F ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js 8433ee332d5f5e39fb19427fccb7bad7f44aa99b5504daad3343fc128c311e78 -F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js 3c72f1a0e6a7343c8c882d29d01bb440f10be12c844651605b486e76f3d6cc8c +F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js 397bb234cf703c5de88a6f4abc154dfe6264989b1faac3797c4e053627043773 F ext/wasm/api/sqlite3-vtab-helper.c-pp.js a2fcbc3fecdd0eea229283584ebc122f29d98194083675dbe5cb2cf3a17fe309 F ext/wasm/api/sqlite3-wasm.c 9267174b9b0591b4f71193542ab57adf95bb9415f7d3453acf4a8ca8052f5e6c F ext/wasm/api/sqlite3-worker1-promiser.c-pp.js 46f303ba8ddd1b2f0a391798837beddfa72e8c897038c8047eda49ce7d5ed46b @@ -2191,9 +2191,10 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 0a7fa0a434bb84023bf9075463613857966ca579e18de903c0d9b1561acf42c6 -Q +40de3939792e17df25598b3e60d1cebcecde2b00832acd55604f14b21398a9a7 -R 846daec7b0fe01d46a65b23c75ccc79e -U drh -Z f18ab008f7a68095fb66c91171ab50b9 +P a7fe90c1581e7e4ffbcb6fb9bcf1db7631cde612ad1d4a33b6b9a22640db5817 +Q +c298b8ba2dcd01fa28b79a78bb4986fa0282755a0a36b7f38b93096ac31f521e +Q +f253cab3359270045a3ae9f5e9eadc1cfc8844181db127165bfdf49d5f99efb1 +R e3ade148f1be81568d1161f8f0ce574b +U stephan +Z 8c4365234cc05bb98b7150818b48ae1b # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 52294b7fb2..1bcc1424d4 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a7fe90c1581e7e4ffbcb6fb9bcf1db7631cde612ad1d4a33b6b9a22640db5817 \ No newline at end of file +a7cd07d96ef420bb1512e6d575bf756809561a536c627900d0eeac879f72e63b \ No newline at end of file From 17b83d28b881b99016899961f35001caef828d8c Mon Sep 17 00:00:00 2001 From: stephan Date: Mon, 17 Jun 2024 13:06:53 +0000 Subject: [PATCH 417/430] Improve the JS-exception-to-C-result-code conversion to account for the case of a file disappearing while the OPFS VFS is waiting to acquire a lock on it. FossilOrigin-Name: d34e788044eec3bf90d6d2db5a2ce20b0b8aea926f776d21c2cb58124773e544 --- ext/wasm/api/sqlite3-opfs-async-proxy.js | 54 ++++++++++++------------ ext/wasm/api/sqlite3-vfs-opfs.c-pp.js | 1 + manifest | 17 ++++---- manifest.uuid | 2 +- 4 files changed, 36 insertions(+), 38 deletions(-) diff --git a/ext/wasm/api/sqlite3-opfs-async-proxy.js b/ext/wasm/api/sqlite3-opfs-async-proxy.js index e671094f04..457b40603b 100644 --- a/ext/wasm/api/sqlite3-opfs-async-proxy.js +++ b/ext/wasm/api/sqlite3-opfs-async-proxy.js @@ -265,23 +265,34 @@ const installAsyncProxy = function(){ this.name = 'GetSyncHandleError'; } }; + + /** + Attempts to find a suitable SQLITE_xyz result code for Error + object e. Returns either such a translation or rc if if it does + not know how to translate the exception. + */ GetSyncHandleError.convertRc = (e,rc)=>{ - if(1){ - return ( - e instanceof GetSyncHandleError - && ((e.cause.name==='NoModificationAllowedError') - /* Inconsistent exception.name from Chrome/ium with the - same exception.message text: */ - || (e.cause.name==='DOMException' - && 0===e.cause.message.indexOf('Access Handles cannot'))) - ) ? ( - /*console.warn("SQLITE_BUSY",e),*/ - state.sq3Codes.SQLITE_BUSY - ) : rc; - }else{ - return rc; + if( e instanceof GetSyncHandleError ){ + if( e.cause.name==='NoModificationAllowedError' + /* Inconsistent exception.name from Chrome/ium with the + same exception.message text: */ + || (e.cause.name==='DOMException' + && 0===e.cause.message.indexOf('Access Handles cannot')) ){ + return state.sq3Codes.SQLITE_BUSY; + }else if( 'NotFoundError'===e.cause.name ){ + /** + Maintenance reminder: SQLITE_NOTFOUND, though it looks like + a good match, has different semantics than NotFoundError + and is not suitable here. + */ + return state.sq3Codes.SQLITE_CANTOPEN; + } + }else if( 'NotFoundError'===e?.name ){ + return state.sq3Codes.SQLITE_CANTOPEN; } - } + return rc; + }; + /** Returns the sync access handle associated with the given file handle object (which must be a valid handle object, as created by @@ -586,19 +597,6 @@ const installAsyncProxy = function(){ fh.releaseImplicitLocks = (opfsFlags & state.opfsFlags.OPFS_UNLOCK_ASAP) || state.opfsFlags.defaultUnlockAsap; - if(0 /* this block is modelled after something wa-sqlite - does but it leads to immediate contention on journal files. - Update: this approach reportedly only works for DELETE journal - mode. */ - && (0===(flags & state.sq3Codes.SQLITE_OPEN_MAIN_DB))){ - /* sqlite does not lock these files, so go ahead and grab an OPFS - lock. */ - fh.xLock = "xOpen"/* Truthy value to keep entry from getting - flagged as auto-locked. String value so - that we can easily distinguish is later - if needed. */; - await getSyncHandle(fh,'xOpen'); - } __openFiles[fid] = fh; storeAndNotify(opName, 0); }catch(e){ diff --git a/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js b/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js index 1c9a92a373..f5c59b4009 100644 --- a/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js +++ b/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js @@ -392,6 +392,7 @@ const installOpfsVfs = function callee(options){ 'SQLITE_ACCESS_EXISTS', 'SQLITE_ACCESS_READWRITE', 'SQLITE_BUSY', + 'SQLITE_CANTOPEN', 'SQLITE_ERROR', 'SQLITE_IOERR', 'SQLITE_IOERR_ACCESS', diff --git a/manifest b/manifest index 84bb200162..9c1ce72f76 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\spotential\sdb\scorruption\scase\striggered\sby\sthe\sOPFS\sVFS's\sxCheckReservedLock()\simplementation. -D 2024-06-12T21:08:02.745 +C Improve\sthe\sJS-exception-to-C-result-code\sconversion\sto\saccount\sfor\sthe\scase\sof\sa\sfile\sdisappearing\swhile\sthe\sOPFS\sVFS\sis\swaiting\sto\sacquire\sa\slock\son\sit. +D 2024-06-17T13:06:53.510 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -614,10 +614,10 @@ F ext/wasm/api/sqlite3-api-oo1.js c373cc04625a96bd3f01ce8ebeac93a5d38dbda6215818 F ext/wasm/api/sqlite3-api-prologue.js b347a0c5350247f90174a0ad9b9e72a99a5f837f31f78f60fcdb829b2ca30b63 F ext/wasm/api/sqlite3-api-worker1.js 9704b77b5eb9d0d498ceeaf3e7a837021b14c52ac15d6556c7f97e278ec725c3 F ext/wasm/api/sqlite3-license-version-header.js 0c807a421f0187e778dc1078f10d2994b915123c1223fe752b60afdcd1263f89 -F ext/wasm/api/sqlite3-opfs-async-proxy.js 196ad83d36ca794e564044788c9d21b964679d63cad865f604da37c4afc9a285 +F ext/wasm/api/sqlite3-opfs-async-proxy.js e0106685187ab649191cdc96377029b2517371286b6ddc1cf9b696f97cb9242c F ext/wasm/api/sqlite3-vfs-helper.c-pp.js 3f828cc66758acb40e9c5b4dcfd87fd478a14c8fb7f0630264e6c7fa0e57515d F ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js 8433ee332d5f5e39fb19427fccb7bad7f44aa99b5504daad3343fc128c311e78 -F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js 397bb234cf703c5de88a6f4abc154dfe6264989b1faac3797c4e053627043773 +F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js 6d3999f2dce2d50a7474e17b3e57f92c6e8ee8d228059aae1e5e0577f37f6a6c F ext/wasm/api/sqlite3-vtab-helper.c-pp.js a2fcbc3fecdd0eea229283584ebc122f29d98194083675dbe5cb2cf3a17fe309 F ext/wasm/api/sqlite3-wasm.c 9267174b9b0591b4f71193542ab57adf95bb9415f7d3453acf4a8ca8052f5e6c F ext/wasm/api/sqlite3-worker1-promiser.c-pp.js 46f303ba8ddd1b2f0a391798837beddfa72e8c897038c8047eda49ce7d5ed46b @@ -2191,10 +2191,9 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P a7fe90c1581e7e4ffbcb6fb9bcf1db7631cde612ad1d4a33b6b9a22640db5817 -Q +c298b8ba2dcd01fa28b79a78bb4986fa0282755a0a36b7f38b93096ac31f521e -Q +f253cab3359270045a3ae9f5e9eadc1cfc8844181db127165bfdf49d5f99efb1 -R e3ade148f1be81568d1161f8f0ce574b +P a7cd07d96ef420bb1512e6d575bf756809561a536c627900d0eeac879f72e63b +Q +5bd9fd5f61e7cd1ed3b44c5cabc759c154c98eb40ad10d29e61f142aaa062ddf +R 550207f6bca7a5ea068833719511be9d U stephan -Z 8c4365234cc05bb98b7150818b48ae1b +Z 56f6696bb5a6f7ff1003c5bbcec4bcd1 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 1bcc1424d4..a97d29c508 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a7cd07d96ef420bb1512e6d575bf756809561a536c627900d0eeac879f72e63b \ No newline at end of file +d34e788044eec3bf90d6d2db5a2ce20b0b8aea926f776d21c2cb58124773e544 \ No newline at end of file From a4ccda2979396b71a6b9057ed7bb4a707d4045d7 Mon Sep 17 00:00:00 2001 From: stephan Date: Fri, 12 Jul 2024 13:51:40 +0000 Subject: [PATCH 418/430] Work around a difficult-to-trigger Atomics API message-passing quirk in the OPFS VFS which appears in rare instances in some browsers when running high I/O loads. This resolves [https://github.com/sqlite/sqlite-wasm/issues/12 | issue #12 of the npm distribution]. FossilOrigin-Name: c7519d98ff09ed96c3c6f2cccf16f8efa19133e12cbb077fc86526f0e81f0470 --- ext/wasm/api/sqlite3-opfs-async-proxy.js | 133 +---------------------- ext/wasm/api/sqlite3-vfs-opfs.c-pp.js | 22 +++- manifest | 16 +-- manifest.uuid | 2 +- 4 files changed, 28 insertions(+), 145 deletions(-) diff --git a/ext/wasm/api/sqlite3-opfs-async-proxy.js b/ext/wasm/api/sqlite3-opfs-async-proxy.js index 457b40603b..3e2b20ffb3 100644 --- a/ext/wasm/api/sqlite3-opfs-async-proxy.js +++ b/ext/wasm/api/sqlite3-opfs-async-proxy.js @@ -87,35 +87,6 @@ const installAsyncProxy = function(){ const log = (...args)=>logImpl(2, ...args); const warn = (...args)=>logImpl(1, ...args); const error = (...args)=>logImpl(0, ...args); - const metrics = Object.create(null); - metrics.reset = ()=>{ - let k; - const r = (m)=>(m.count = m.time = m.wait = 0); - for(k in state.opIds){ - r(metrics[k] = Object.create(null)); - } - let s = metrics.s11n = Object.create(null); - s = s.serialize = Object.create(null); - s.count = s.time = 0; - s = metrics.s11n.deserialize = Object.create(null); - s.count = s.time = 0; - }; - metrics.dump = ()=>{ - let k, n = 0, t = 0, w = 0; - for(k in state.opIds){ - const m = metrics[k]; - n += m.count; - t += m.time; - w += m.wait; - m.avgTime = (m.count && m.time) ? (m.time / m.count) : 0; - } - console.log(globalThis?.location?.href, - "metrics for",globalThis?.location?.href,":\n", - metrics, - "\nTotal of",n,"op(s) for",t,"ms", - "approx",w,"ms spent waiting on OPFS APIs."); - console.log("Serialization metrics:",metrics.s11n); - }; /** __openFiles is a map of sqlite3_file pointers (integers) to @@ -358,37 +329,6 @@ const installAsyncProxy = function(){ if(fh.readOnly) toss(opName+"(): File is read-only: "+fh.filenameAbs); }; - /** - We track 2 different timers: the "metrics" timer records how much - time we spend performing work. The "wait" timer records how much - time we spend waiting on the underlying OPFS timer. See the calls - to mTimeStart(), mTimeEnd(), wTimeStart(), and wTimeEnd() - throughout this file to see how they're used. - */ - const __mTimer = Object.create(null); - __mTimer.op = undefined; - __mTimer.start = undefined; - const mTimeStart = (op)=>{ - __mTimer.start = performance.now(); - __mTimer.op = op; - //metrics[op] || toss("Maintenance required: missing metrics for",op); - ++metrics[op].count; - }; - const mTimeEnd = ()=>( - metrics[__mTimer.op].time += performance.now() - __mTimer.start - ); - const __wTimer = Object.create(null); - __wTimer.op = undefined; - __wTimer.start = undefined; - const wTimeStart = (op)=>{ - __wTimer.start = performance.now(); - __wTimer.op = op; - //metrics[op] || toss("Maintenance required: missing metrics for",op); - }; - const wTimeEnd = ()=>( - metrics[__wTimer.op].wait += performance.now() - __wTimer.start - ); - /** Gets set to true by the 'opfs-async-shutdown' command to quit the wait loop. This is only intended for debugging purposes: we cannot @@ -399,37 +339,24 @@ const installAsyncProxy = function(){ /** Asynchronous wrappers for sqlite3_vfs and sqlite3_io_methods - methods, as well as helpers like mkdir(). Maintenance reminder: - members are in alphabetical order to simplify finding them. + methods, as well as helpers like mkdir(). */ const vfsAsyncImpls = { - 'opfs-async-metrics': async ()=>{ - mTimeStart('opfs-async-metrics'); - metrics.dump(); - storeAndNotify('opfs-async-metrics', 0); - mTimeEnd(); - }, 'opfs-async-shutdown': async ()=>{ flagAsyncShutdown = true; storeAndNotify('opfs-async-shutdown', 0); }, mkdir: async (dirname)=>{ - mTimeStart('mkdir'); let rc = 0; - wTimeStart('mkdir'); try { await getDirForFilename(dirname+"/filepart", true); }catch(e){ state.s11n.storeException(2,e); rc = state.sq3Codes.SQLITE_IOERR; - }finally{ - wTimeEnd(); } storeAndNotify('mkdir', rc); - mTimeEnd(); }, xAccess: async (filename)=>{ - mTimeStart('xAccess'); /* OPFS cannot support the full range of xAccess() queries sqlite3 calls for. We can essentially just tell if the file is accessible, but if it is then it's automatically writable @@ -442,26 +369,20 @@ const installAsyncProxy = function(){ accessible, non-0 means not accessible. */ let rc = 0; - wTimeStart('xAccess'); try{ const [dh, fn] = await getDirForFilename(filename); await dh.getFileHandle(fn); }catch(e){ state.s11n.storeException(2,e); rc = state.sq3Codes.SQLITE_IOERR; - }finally{ - wTimeEnd(); } storeAndNotify('xAccess', rc); - mTimeEnd(); }, xClose: async function(fid/*sqlite3_file pointer*/){ const opName = 'xClose'; - mTimeStart(opName); __implicitLocks.delete(fid); const fh = __openFiles[fid]; let rc = 0; - wTimeStart(opName); if(fh){ delete __openFiles[fid]; await closeSyncHandle(fh); @@ -473,15 +394,11 @@ const installAsyncProxy = function(){ state.s11n.serialize(); rc = state.sq3Codes.SQLITE_NOTFOUND; } - wTimeEnd(); storeAndNotify(opName, rc); - mTimeEnd(); }, xDelete: async function(...args){ - mTimeStart('xDelete'); const rc = await vfsAsyncImpls.xDeleteNoWait(...args); storeAndNotify('xDelete', rc); - mTimeEnd(); }, xDeleteNoWait: async function(filename, syncDir = 0, recursive = false){ /* The syncDir flag is, for purposes of the VFS API's semantics, @@ -497,7 +414,6 @@ const installAsyncProxy = function(){ is false. */ let rc = 0; - wTimeStart('xDelete'); try { while(filename){ const [hDir, filenamePart] = await getDirForFilename(filename, false); @@ -513,14 +429,11 @@ const installAsyncProxy = function(){ state.s11n.storeException(2,e); rc = state.sq3Codes.SQLITE_IOERR_DELETE; } - wTimeEnd(); return rc; }, xFileSize: async function(fid/*sqlite3_file pointer*/){ - mTimeStart('xFileSize'); const fh = __openFiles[fid]; let rc = 0; - wTimeStart('xFileSize'); try{ const sz = await (await getSyncHandle(fh,'xFileSize')).getSize(); state.s11n.serialize(Number(sz)); @@ -529,19 +442,15 @@ const installAsyncProxy = function(){ rc = GetSyncHandleError.convertRc(e,state.sq3Codes.SQLITE_IOERR); } await releaseImplicitLock(fh); - wTimeEnd(); storeAndNotify('xFileSize', rc); - mTimeEnd(); }, xLock: async function(fid/*sqlite3_file pointer*/, lockType/*SQLITE_LOCK_...*/){ - mTimeStart('xLock'); const fh = __openFiles[fid]; let rc = 0; const oldLockType = fh.xLock; fh.xLock = lockType; if( !fh.syncHandle ){ - wTimeStart('xLock'); try { await getSyncHandle(fh,'xLock'); __implicitLocks.delete(fid); @@ -550,18 +459,14 @@ const installAsyncProxy = function(){ rc = GetSyncHandleError.convertRc(e,state.sq3Codes.SQLITE_IOERR_LOCK); fh.xLock = oldLockType; } - wTimeEnd(); } storeAndNotify('xLock',rc); - mTimeEnd(); }, xOpen: async function(fid/*sqlite3_file pointer*/, filename, flags/*SQLITE_OPEN_...*/, opfsFlags/*OPFS_...*/){ const opName = 'xOpen'; - mTimeStart(opName); const create = (state.sq3Codes.SQLITE_OPEN_CREATE & flags); - wTimeStart('xOpen'); try{ let hDir, filenamePart; try { @@ -569,8 +474,6 @@ const installAsyncProxy = function(){ }catch(e){ state.s11n.storeException(1,e); storeAndNotify(opName, state.sq3Codes.SQLITE_NOTFOUND); - mTimeEnd(); - wTimeEnd(); return; } if( state.opfsFlags.OPFS_UNLINK_BEFORE_OPEN & opfsFlags ){ @@ -582,7 +485,6 @@ const installAsyncProxy = function(){ } } const hFile = await hDir.getFileHandle(filenamePart, {create}); - wTimeEnd(); const fh = Object.assign(Object.create(null),{ fid: fid, filenameAbs: filename, @@ -600,60 +502,47 @@ const installAsyncProxy = function(){ __openFiles[fid] = fh; storeAndNotify(opName, 0); }catch(e){ - wTimeEnd(); error(opName,e); state.s11n.storeException(1,e); storeAndNotify(opName, state.sq3Codes.SQLITE_IOERR); } - mTimeEnd(); }, xRead: async function(fid/*sqlite3_file pointer*/,n,offset64){ - mTimeStart('xRead'); let rc = 0, nRead; const fh = __openFiles[fid]; try{ - wTimeStart('xRead'); nRead = (await getSyncHandle(fh,'xRead')).read( fh.sabView.subarray(0, n), {at: Number(offset64)} ); - wTimeEnd(); if(nRead < n){/* Zero-fill remaining bytes */ fh.sabView.fill(0, nRead, n); rc = state.sq3Codes.SQLITE_IOERR_SHORT_READ; } }catch(e){ - if(undefined===nRead) wTimeEnd(); error("xRead() failed",e,fh); state.s11n.storeException(1,e); rc = GetSyncHandleError.convertRc(e,state.sq3Codes.SQLITE_IOERR_READ); } await releaseImplicitLock(fh); storeAndNotify('xRead',rc); - mTimeEnd(); }, xSync: async function(fid/*sqlite3_file pointer*/,flags/*ignored*/){ - mTimeStart('xSync'); const fh = __openFiles[fid]; let rc = 0; if(!fh.readOnly && fh.syncHandle){ try { - wTimeStart('xSync'); await fh.syncHandle.flush(); }catch(e){ state.s11n.storeException(2,e); rc = state.sq3Codes.SQLITE_IOERR_FSYNC; } - wTimeEnd(); } storeAndNotify('xSync',rc); - mTimeEnd(); }, xTruncate: async function(fid/*sqlite3_file pointer*/,size){ - mTimeStart('xTruncate'); let rc = 0; const fh = __openFiles[fid]; - wTimeStart('xTruncate'); try{ affirmNotRO('xTruncate', fh); await (await getSyncHandle(fh,'xTruncate')).truncate(size); @@ -663,33 +552,25 @@ const installAsyncProxy = function(){ rc = GetSyncHandleError.convertRc(e,state.sq3Codes.SQLITE_IOERR_TRUNCATE); } await releaseImplicitLock(fh); - wTimeEnd(); storeAndNotify('xTruncate',rc); - mTimeEnd(); }, xUnlock: async function(fid/*sqlite3_file pointer*/, lockType/*SQLITE_LOCK_...*/){ - mTimeStart('xUnlock'); let rc = 0; const fh = __openFiles[fid]; if( state.sq3Codes.SQLITE_LOCK_NONE===lockType && fh.syncHandle ){ - wTimeStart('xUnlock'); try { await closeSyncHandle(fh) } catch(e){ state.s11n.storeException(1,e); rc = state.sq3Codes.SQLITE_IOERR_UNLOCK; } - wTimeEnd(); } storeAndNotify('xUnlock',rc); - mTimeEnd(); }, xWrite: async function(fid/*sqlite3_file pointer*/,n,offset64){ - mTimeStart('xWrite'); let rc; const fh = __openFiles[fid]; - wTimeStart('xWrite'); try{ affirmNotRO('xWrite', fh); rc = ( @@ -703,9 +584,7 @@ const installAsyncProxy = function(){ rc = GetSyncHandleError.convertRc(e,state.sq3Codes.SQLITE_IOERR_WRITE); } await releaseImplicitLock(fh); - wTimeEnd(); storeAndNotify('xWrite',rc); - mTimeEnd(); } }/*vfsAsyncImpls*/; @@ -739,8 +618,6 @@ const installAsyncProxy = function(){ } }; state.s11n.deserialize = function(clear=false){ - ++metrics.s11n.deserialize.count; - const t = performance.now(); const argc = viewU8[0]; const rc = argc ? [] : null; if(argc){ @@ -765,12 +642,9 @@ const installAsyncProxy = function(){ } if(clear) viewU8[0] = 0; //log("deserialize:",argc, rc); - metrics.s11n.deserialize.time += performance.now() - t; return rc; }; state.s11n.serialize = function(...args){ - const t = performance.now(); - ++metrics.s11n.serialize.count; if(args.length){ //log("serialize():",args); const typeIds = []; @@ -801,7 +675,6 @@ const installAsyncProxy = function(){ }else{ viewU8[0] = 0; } - metrics.s11n.serialize.time += performance.now() - t; }; state.s11n.storeException = state.asyncS11nExceptions @@ -883,7 +756,6 @@ const installAsyncProxy = function(){ } }); initS11n(); - metrics.reset(); log("init state",state); wPost('opfs-async-inited'); waitLoop(); @@ -896,9 +768,6 @@ const installAsyncProxy = function(){ waitLoop(); } break; - case 'opfs-async-metrics': - metrics.dump(); - break; } }; wPost('opfs-async-loaded'); diff --git a/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js b/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js index f5c59b4009..a0a456dc50 100644 --- a/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js +++ b/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js @@ -445,7 +445,7 @@ const installOpfsVfs = function callee(options){ OPFS_UNLINK_BEFORE_OPEN: 0x02, /** If true, any async routine which implicitly acquires a sync - access handle (i.e. an OPFS lock) will release that locks at + access handle (i.e. an OPFS lock) will release that lock at the end of the call which acquires it. If false, such "autolocks" are not released until the VFS is idle for some brief amount of time. @@ -472,9 +472,23 @@ const installOpfsVfs = function callee(options){ Atomics.notify(state.sabOPView, state.opIds.whichOp) /* async thread will take over here */; const t = performance.now(); - Atomics.wait(state.sabOPView, state.opIds.rc, -1) - /* When this wait() call returns, the async half will have - completed the operation and reported its results. */; + while('not-equal'!==Atomics.wait(state.sabOPView, state.opIds.rc, -1)){ + /* + The reason for this loop is burried in the details of + a long discussion at: + + https://github.com/sqlite/sqlite-wasm/issues/12 + + Summary: in at least one browser flavor, under high loads, + this wait() call can, on rare occasion, end up returning + 'ok', which indicates that it's returning _without_ the + other half of the proxy having called Atomics.notify(). When + this happens, we just wait() again. + */ + } + /* When the above wait() call returns 'not-equal', the async + half will have completed the operation and reported its results + in the state.opIds.rc slot of the SAB. */ const rc = Atomics.load(state.sabOPView, state.opIds.rc); metrics[op].wait += performance.now() - t; if(rc && state.asyncS11nExceptions){ diff --git a/manifest b/manifest index 9c1ce72f76..870819f0f1 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improve\sthe\sJS-exception-to-C-result-code\sconversion\sto\saccount\sfor\sthe\scase\sof\sa\sfile\sdisappearing\swhile\sthe\sOPFS\sVFS\sis\swaiting\sto\sacquire\sa\slock\son\sit. -D 2024-06-17T13:06:53.510 +C Work\saround\sa\sdifficult-to-trigger\sAtomics\sAPI\smessage-passing\squirk\sin\sthe\sOPFS\sVFS\swhich\sappears\sin\srare\sinstances\sin\ssome\sbrowsers\swhen\srunning\shigh\sI/O\sloads.\sThis\sresolves\s[https://github.com/sqlite/sqlite-wasm/issues/12\s|\sissue\s#12\sof\sthe\snpm\sdistribution]. +D 2024-07-12T13:51:40.137 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -614,10 +614,10 @@ F ext/wasm/api/sqlite3-api-oo1.js c373cc04625a96bd3f01ce8ebeac93a5d38dbda6215818 F ext/wasm/api/sqlite3-api-prologue.js b347a0c5350247f90174a0ad9b9e72a99a5f837f31f78f60fcdb829b2ca30b63 F ext/wasm/api/sqlite3-api-worker1.js 9704b77b5eb9d0d498ceeaf3e7a837021b14c52ac15d6556c7f97e278ec725c3 F ext/wasm/api/sqlite3-license-version-header.js 0c807a421f0187e778dc1078f10d2994b915123c1223fe752b60afdcd1263f89 -F ext/wasm/api/sqlite3-opfs-async-proxy.js e0106685187ab649191cdc96377029b2517371286b6ddc1cf9b696f97cb9242c +F ext/wasm/api/sqlite3-opfs-async-proxy.js dd4054e4f673027c330c96a04cf0a03b118156f01b076dc4e9d604dbdd7bfc51 F ext/wasm/api/sqlite3-vfs-helper.c-pp.js 3f828cc66758acb40e9c5b4dcfd87fd478a14c8fb7f0630264e6c7fa0e57515d F ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js 8433ee332d5f5e39fb19427fccb7bad7f44aa99b5504daad3343fc128c311e78 -F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js 6d3999f2dce2d50a7474e17b3e57f92c6e8ee8d228059aae1e5e0577f37f6a6c +F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js bde8097f84bc6ada8d2c6a5a18b97019e1346a390749902e83724cb1bba3da53 F ext/wasm/api/sqlite3-vtab-helper.c-pp.js a2fcbc3fecdd0eea229283584ebc122f29d98194083675dbe5cb2cf3a17fe309 F ext/wasm/api/sqlite3-wasm.c 9267174b9b0591b4f71193542ab57adf95bb9415f7d3453acf4a8ca8052f5e6c F ext/wasm/api/sqlite3-worker1-promiser.c-pp.js 46f303ba8ddd1b2f0a391798837beddfa72e8c897038c8047eda49ce7d5ed46b @@ -2191,9 +2191,9 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P a7cd07d96ef420bb1512e6d575bf756809561a536c627900d0eeac879f72e63b -Q +5bd9fd5f61e7cd1ed3b44c5cabc759c154c98eb40ad10d29e61f142aaa062ddf -R 550207f6bca7a5ea068833719511be9d +P d34e788044eec3bf90d6d2db5a2ce20b0b8aea926f776d21c2cb58124773e544 +Q +af41a1e6fc8b36e9bf65a5bb0154e1ce7eb99903cb5a3e4779322527c29d8780 +R 8e551aa869faf2023e5425f757cd3b4d U stephan -Z 56f6696bb5a6f7ff1003c5bbcec4bcd1 +Z da9f80bc86014305b702c29d9577ad17 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index a97d29c508..6e472ca685 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d34e788044eec3bf90d6d2db5a2ce20b0b8aea926f776d21c2cb58124773e544 \ No newline at end of file +c7519d98ff09ed96c3c6f2cccf16f8efa19133e12cbb077fc86526f0e81f0470 From 655219897abfff90fb71b1482641ea9e0edfa28f Mon Sep 17 00:00:00 2001 From: stephan Date: Mon, 15 Jul 2024 10:13:02 +0000 Subject: [PATCH 419/430] Slight doc touchup for [af41a1e6fc8b36e9bf65]/[c7519d98ff09e] based on feedback. No code changes. FossilOrigin-Name: a61997c315ce70d60f3722a2b3b3d06ba592ce1cafed1639a9d5f162f712ae03 --- ext/wasm/api/sqlite3-vfs-opfs.c-pp.js | 11 +++++------ manifest | 14 +++++++------- manifest.uuid | 2 +- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js b/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js index a0a456dc50..5b74e7863f 100644 --- a/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js +++ b/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js @@ -474,16 +474,15 @@ const installOpfsVfs = function callee(options){ const t = performance.now(); while('not-equal'!==Atomics.wait(state.sabOPView, state.opIds.rc, -1)){ /* - The reason for this loop is burried in the details of - a long discussion at: + The reason for this loop is buried in the details of a long + discussion at: https://github.com/sqlite/sqlite-wasm/issues/12 Summary: in at least one browser flavor, under high loads, - this wait() call can, on rare occasion, end up returning - 'ok', which indicates that it's returning _without_ the - other half of the proxy having called Atomics.notify(). When - this happens, we just wait() again. + the wait()/notify() pairings can get out of sync. Calling + wait() here until it returns 'not-equal' gets them back in + sync. */ } /* When the above wait() call returns 'not-equal', the async diff --git a/manifest b/manifest index 870819f0f1..f528de0301 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Work\saround\sa\sdifficult-to-trigger\sAtomics\sAPI\smessage-passing\squirk\sin\sthe\sOPFS\sVFS\swhich\sappears\sin\srare\sinstances\sin\ssome\sbrowsers\swhen\srunning\shigh\sI/O\sloads.\sThis\sresolves\s[https://github.com/sqlite/sqlite-wasm/issues/12\s|\sissue\s#12\sof\sthe\snpm\sdistribution]. -D 2024-07-12T13:51:40.137 +C Slight\sdoc\stouchup\sfor\s[af41a1e6fc8b36e9bf65]/[c7519d98ff09e]\sbased\son\sfeedback.\sNo\scode\schanges. +D 2024-07-15T10:13:02.516 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -617,7 +617,7 @@ F ext/wasm/api/sqlite3-license-version-header.js 0c807a421f0187e778dc1078f10d299 F ext/wasm/api/sqlite3-opfs-async-proxy.js dd4054e4f673027c330c96a04cf0a03b118156f01b076dc4e9d604dbdd7bfc51 F ext/wasm/api/sqlite3-vfs-helper.c-pp.js 3f828cc66758acb40e9c5b4dcfd87fd478a14c8fb7f0630264e6c7fa0e57515d F ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js 8433ee332d5f5e39fb19427fccb7bad7f44aa99b5504daad3343fc128c311e78 -F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js bde8097f84bc6ada8d2c6a5a18b97019e1346a390749902e83724cb1bba3da53 +F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js 834dcea56e27064ae8429780c85393c82b8f83fc23a1ebebb41849392bfe30bf F ext/wasm/api/sqlite3-vtab-helper.c-pp.js a2fcbc3fecdd0eea229283584ebc122f29d98194083675dbe5cb2cf3a17fe309 F ext/wasm/api/sqlite3-wasm.c 9267174b9b0591b4f71193542ab57adf95bb9415f7d3453acf4a8ca8052f5e6c F ext/wasm/api/sqlite3-worker1-promiser.c-pp.js 46f303ba8ddd1b2f0a391798837beddfa72e8c897038c8047eda49ce7d5ed46b @@ -2191,9 +2191,9 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P d34e788044eec3bf90d6d2db5a2ce20b0b8aea926f776d21c2cb58124773e544 -Q +af41a1e6fc8b36e9bf65a5bb0154e1ce7eb99903cb5a3e4779322527c29d8780 -R 8e551aa869faf2023e5425f757cd3b4d +P c7519d98ff09ed96c3c6f2cccf16f8efa19133e12cbb077fc86526f0e81f0470 +Q +be7b1fc0c5d8cda971b471dfcb4637212bfff4f42b1e074077a381cc493d877a +R 25d6454fe046cdba79f56994072c8204 U stephan -Z da9f80bc86014305b702c29d9577ad17 +Z a2c01e65c215b93339c9d803c0adca59 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 6e472ca685..2a99b57e42 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c7519d98ff09ed96c3c6f2cccf16f8efa19133e12cbb077fc86526f0e81f0470 +a61997c315ce70d60f3722a2b3b3d06ba592ce1cafed1639a9d5f162f712ae03 From 3903ad4497f3eb16d5fab344506edc3453e0162b Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 6 Aug 2024 22:54:56 +0000 Subject: [PATCH 420/430] Improved robustness of parsing of tokenize= arguments in FTS5. FossilOrigin-Name: 7a65ac42c2723b785786cf15f4b267ebfbd4f848f9fc6b37dcf9fac9abd0398c --- ext/fts5/fts5_tokenize.c | 12 +++++++----- ext/fts5/test/fts5tokenizer2.test | 20 ++++++++++++++++++++ ext/fts5/test/fts5trigram.test | 5 ++++- ext/fts5/test/fts5trigram2.test | 3 +++ manifest | 22 +++++++++++----------- manifest.uuid | 2 +- 6 files changed, 46 insertions(+), 18 deletions(-) diff --git a/ext/fts5/fts5_tokenize.c b/ext/fts5/fts5_tokenize.c index f12056170f..e5752efdd4 100644 --- a/ext/fts5/fts5_tokenize.c +++ b/ext/fts5/fts5_tokenize.c @@ -79,7 +79,7 @@ static int fts5AsciiCreate( int i; memset(p, 0, sizeof(AsciiTokenizer)); memcpy(p->aTokenChar, aAsciiTokenChar, sizeof(aAsciiTokenChar)); - for(i=0; rc==SQLITE_OK && ibFold = 1; pNew->iFoldParam = 0; - for(i=0; rc==SQLITE_OK && iiFoldParam!=0 && pNew->bFold==0 ){ rc = SQLITE_ERROR; diff --git a/ext/fts5/test/fts5tokenizer2.test b/ext/fts5/test/fts5tokenizer2.test index bdabd53127..52b30326ae 100644 --- a/ext/fts5/test/fts5tokenizer2.test +++ b/ext/fts5/test/fts5tokenizer2.test @@ -85,5 +85,25 @@ do_execsql_test 1.7 { SELECT highlight(t1, 0, '>', '<') FROM t1('BB mess'); } {AAdont>BBmess<} +# 2024-08-06 https://sqlite.org/forum/forumpost/171bcc2bcd +# Error handling of tokenize= arguments. +# +foreach {n tkz} { + 1 {ascii none} + 2 {unicode61 none} + 3 {porter none} + 4 {trigram none} + 5 {ascii none 0} + 6 {unicode61 none 0} + 7 {porter none 0} + 8 {trigram none 0} +} { + db eval {DROP TABLE IF EXISTS t2;} + do_catchsql_test 2.$n " + DROP TABLE IF EXISTS t2; + CREATE VIRTUAL TABLE t2 USING fts5(a,b,c,tokenize='$tkz'); + " {1 {error in tokenizer constructor}} +} + finish_test diff --git a/ext/fts5/test/fts5trigram.test b/ext/fts5/test/fts5trigram.test index 351c059bf5..752686620c 100644 --- a/ext/fts5/test/fts5trigram.test +++ b/ext/fts5/test/fts5trigram.test @@ -69,6 +69,9 @@ do_execsql_test 2.0 { INSERT INTO t1 VALUES('abcdefghijklm'); INSERT INTO t1 VALUES('กรุงเทพมหานคร'); } +do_catchsql_test 2.0.1 { + CREATE VIRTUAL TABLE t2 USING fts5(z, tokenize='trigram case_sensitive'); +} {1 {error in tokenizer constructor}} foreach {tn s res} { 1 abc "(abc)defghijklm" @@ -206,7 +209,7 @@ do_execsql_test 7.0 { (20, "жираф.png"), (30, "cat.png"), (40, "кот.png"), - (50, "misic-🎵-.mp3"); + (50, "misic-🎵-.mp3"); } do_execsql_test 7.1 { SELECT rowid FROM f WHERE +filename GLOB '*ир*'; diff --git a/ext/fts5/test/fts5trigram2.test b/ext/fts5/test/fts5trigram2.test index f5beae5b28..395d8994b2 100644 --- a/ext/fts5/test/fts5trigram2.test +++ b/ext/fts5/test/fts5trigram2.test @@ -21,6 +21,9 @@ do_execsql_test 1.0 " INSERT INTO t1 VALUES('abc\u0303defghijklm'); INSERT INTO t1 VALUES('a\u0303b\u0303c\u0303defghijklm'); " +do_catchsql_test 1.0.1 { + CREATE VIRTUAL TABLE t2 USING fts5(z, tokenize='trigram remove_diacritics'); +} {1 {error in tokenizer constructor}} do_execsql_test 1.1 { SELECT highlight(t1, 0, '(', ')') FROM t1('abc'); diff --git a/manifest b/manifest index f528de0301..f39f37f271 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Slight\sdoc\stouchup\sfor\s[af41a1e6fc8b36e9bf65]/[c7519d98ff09e]\sbased\son\sfeedback.\sNo\scode\schanges. -D 2024-07-15T10:13:02.516 +C Improved\srobustness\sof\sparsing\sof\stokenize=\sarguments\sin\sFTS5. +D 2024-08-06T22:54:56.766 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -105,7 +105,7 @@ F ext/fts5/fts5_storage.c f9e31b0d155e9b2c92d5d3a09ad7a56b937fbf1c7f962e10f4ca62 F ext/fts5/fts5_tcl.c fdf7e2bb9a9186cfcaf2d2ce11d338309342b7a7593c2812bc54455db53da5d2 F ext/fts5/fts5_test_mi.c 08c11ec968148d4cb4119d96d819f8c1f329812c568bac3684f5464be177d3ee F ext/fts5/fts5_test_tok.c 3cb0a9b508b30d17ef025ccddd26ae3dc8ddffbe76c057616e59a9aa85d36f3b -F ext/fts5/fts5_tokenize.c 83cfcede3898001cab84432a36ce1503e3080cf9b1c682b022ec82e267ea4c13 +F ext/fts5/fts5_tokenize.c b94826fc235e1937c4e93c266e0db4052dcab648ff87f4080376fc04b1fc93a4 F ext/fts5/fts5_unicode2.c eca63dbc797f8ff0572e97caf4631389c0ab900d6364861b915bdd4735973f00 F ext/fts5/fts5_varint.c e64d2113f6e1bfee0032972cffc1207b77af63319746951bf1d09885d1dadf80 F ext/fts5/fts5_vocab.c 209e0c151e108d5f3621fa24b91e9b02f3750ee6c3f9ccec312df39481b68a09 @@ -228,9 +228,9 @@ F ext/fts5/test/fts5synonym2.test e2f6ff68c4fbe12a866a3a87510f553d9dac99bcb74c10 F ext/fts5/test/fts5tok1.test 1f7817499f5971450d8c4a652114b3d833393c8134e32422d0af27884ffe9cef F ext/fts5/test/fts5tok2.test dcacb32d4a2a3f0dd3215d4a3987f78ae4be21a2 F ext/fts5/test/fts5tokenizer.test ac3c9112b263a639fb0508ae73a3ee886bf4866d2153771a8e8a20c721305a43 -F ext/fts5/test/fts5tokenizer2.test cb5428c7cfb3b6a74b7adfcde65506e329112003e8dffa7501d01c2d18d02569 -F ext/fts5/test/fts5trigram.test 6c4e37864f3e7d90673db5563d9736d7e40080ab94d10ebdffa94c1b77941da0 -F ext/fts5/test/fts5trigram2.test 9fe4207f8a4241747aff1005258b564958588d21bfd240d6cd4c2e955d31c156 +F ext/fts5/test/fts5tokenizer2.test b9d734c1b10bc317a377ffea3ecb5c2937313113a02e364f167d0c7f8c81c282 +F ext/fts5/test/fts5trigram.test be914555deb8504dde682bd5aa343d00c4da37dfad20709a5bac30d5f97f2ef5 +F ext/fts5/test/fts5trigram2.test 4043f8836bbbb0ce37b86dd1e741431c6c595c7e4ba4fc8e26f21dc3b540e228 F ext/fts5/test/fts5ubsan.test 783d5a8d13ebfa169e634940228db54540780e3ba7a87ad1e4510e61440bf64b F ext/fts5/test/fts5umlaut.test a42fe2fe6387c40c49ab27ccbd070e1ae38e07f38d05926482cc0bccac9ad602 F ext/fts5/test/fts5unicode.test 17056f4efe6b0a5d4f41fdf7a7dc9af2873004562eaa899d40633b93dc95f5a9 @@ -2191,9 +2191,9 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P c7519d98ff09ed96c3c6f2cccf16f8efa19133e12cbb077fc86526f0e81f0470 -Q +be7b1fc0c5d8cda971b471dfcb4637212bfff4f42b1e074077a381cc493d877a -R 25d6454fe046cdba79f56994072c8204 -U stephan -Z a2c01e65c215b93339c9d803c0adca59 +P a61997c315ce70d60f3722a2b3b3d06ba592ce1cafed1639a9d5f162f712ae03 +Q +d9f726ade6b258f8723f90d0b04a4682e885e30939eb29773913e4dfc8e85503 +R 5f343f5765d17f03385da2454716eb3e +U drh +Z 71e3aedaf58c5df6d18eb9c2aaa0e383 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 2a99b57e42..5283524042 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a61997c315ce70d60f3722a2b3b3d06ba592ce1cafed1639a9d5f162f712ae03 +7a65ac42c2723b785786cf15f4b267ebfbd4f848f9fc6b37dcf9fac9abd0398c From 9dc32eaa3369399a144dd2413def31d6df03efaa Mon Sep 17 00:00:00 2001 From: stephan Date: Thu, 8 Aug 2024 10:55:15 +0000 Subject: [PATCH 421/430] Move a misplaced va_end, as reported in [forum:702c79e9da|forum post 702c79e9da]. FossilOrigin-Name: 569824c7ff79ed1aadd2a6bce34bfcd8bf4f68db9565f56b803182adad526bc7 --- ext/recover/sqlite3recover.c | 2 +- manifest | 16 ++++++++-------- manifest.uuid | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ext/recover/sqlite3recover.c b/ext/recover/sqlite3recover.c index 1d858c0ab9..afa1ae8619 100644 --- a/ext/recover/sqlite3recover.c +++ b/ext/recover/sqlite3recover.c @@ -363,8 +363,8 @@ static int recoverError( va_start(ap, zFmt); if( zFmt ){ z = sqlite3_vmprintf(zFmt, ap); - va_end(ap); } + va_end(ap); sqlite3_free(p->zErrMsg); p->zErrMsg = z; p->errCode = errCode; diff --git a/manifest b/manifest index f39f37f271..3741effb97 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improved\srobustness\sof\sparsing\sof\stokenize=\sarguments\sin\sFTS5. -D 2024-08-06T22:54:56.766 +C Move\sa\smisplaced\sva_end,\sas\sreported\sin\s[forum:702c79e9da|forum\spost\s702c79e9da]. +D 2024-08-08T10:55:15.312 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -494,7 +494,7 @@ F ext/recover/recoverpgsz.test 3658ab8e68475b1bb87d6af88baa04551c84b73280a566a1b F ext/recover/recoverrowid.test f948bf4024a5f41b0e21b8af80c60564c5b5d78c05a8d64fc00787715ff9f45f F ext/recover/recoverslowidx.test 5205a9742dd9490ee99950dabb622307355ef1662dea6a3a21030057bfd81411 F ext/recover/recoversql.test e66d01f95302a223bcd3fd42b5ee58dc2b53d70afa90b0d00e41e4b8eab20486 -F ext/recover/sqlite3recover.c 65ef0f56301a16c0536c9839fb7e23540c9c4f75da0afe3b7b4d163c8f624404 +F ext/recover/sqlite3recover.c 2dcf6b56c5e0e2b43fc4c6115b689ab194c374ced7f7f8380ad9a24d8ef24ac9 F ext/recover/sqlite3recover.h 011c799f02deb70ab685916f6f538e6bb32c4e0025e79bfd0e24ff9c74820959 F ext/recover/test_recover.c fd871a40f2238022bedcbdf3cb493b91225edaa94d6ae8892af97a10e7ccc4ba F ext/repair/README.md 92f5e8aae749a4dae14f02eea8e1bb42d4db2b6ce5e83dbcdd6b1446997e0c15 @@ -2191,9 +2191,9 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P a61997c315ce70d60f3722a2b3b3d06ba592ce1cafed1639a9d5f162f712ae03 -Q +d9f726ade6b258f8723f90d0b04a4682e885e30939eb29773913e4dfc8e85503 -R 5f343f5765d17f03385da2454716eb3e -U drh -Z 71e3aedaf58c5df6d18eb9c2aaa0e383 +P 7a65ac42c2723b785786cf15f4b267ebfbd4f848f9fc6b37dcf9fac9abd0398c +Q +daa25fb35fd7bdd482d51214439f38b0b9a7df93f689a2b3d30a113daa9f2a1a +R 3ccb59e8ac6b0853bb8710d43043c061 +U stephan +Z 2fd891815cd1bc2fdd9840c2666785d4 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 5283524042..22db0758f1 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7a65ac42c2723b785786cf15f4b267ebfbd4f848f9fc6b37dcf9fac9abd0398c +569824c7ff79ed1aadd2a6bce34bfcd8bf4f68db9565f56b803182adad526bc7 From 3c44d50e47109db81b08aaddf884a3ca0c2c1ccf Mon Sep 17 00:00:00 2001 From: drh <> Date: Thu, 8 Aug 2024 14:49:54 +0000 Subject: [PATCH 422/430] Do not let the number of terms on a VALUES clause be limited by SQLITE_LIMIT_COMPOUND_SELECT, even if the VALUES clause contains elements that appear to be variables due to the use of double-quoted string literals. FossilOrigin-Name: 05dbfad70c3eb39f84b91503fc9b4c1cb96843e5e6599584077b1a630936ddc7 --- manifest | 20 ++++++++++---------- manifest.uuid | 2 +- src/insert.c | 1 + src/parse.y | 6 +++--- test/select7.test | 32 ++++++++++++++++++++++++++++++++ 5 files changed, 47 insertions(+), 14 deletions(-) diff --git a/manifest b/manifest index 3741effb97..e99bf37f1c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Move\sa\smisplaced\sva_end,\sas\sreported\sin\s[forum:702c79e9da|forum\spost\s702c79e9da]. -D 2024-08-08T10:55:15.312 +C Do\snot\slet\sthe\snumber\sof\sterms\son\sa\sVALUES\sclause\sbe\slimited\sby\nSQLITE_LIMIT_COMPOUND_SELECT,\seven\sif\sthe\sVALUES\sclause\scontains\selements\nthat\sappear\sto\sbe\svariables\sdue\sto\sthe\suse\sof\sdouble-quoted\sstring\sliterals. +D 2024-08-08T14:49:54.365 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -713,7 +713,7 @@ F src/hash.c 9ee4269fb1d6632a6fecfb9479c93a1f29271bddbbaf215dd60420bcb80c7220 F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 -F src/insert.c 4bd7c7e54a1062dcd0214b7a6296f7194eb10fb14d3ddca1ed20b01c2a86a18c +F src/insert.c 8ff11e9e54c5fc1fe89707b3d41cf44ad2822f712bd3b5da68338ea42518847e F src/json.c bf1b51e32158b3d01d96a878d3dba8d2e633a7e5bf2534d4617f89de8a6b9a91 F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 @@ -743,7 +743,7 @@ F src/os_win.c 6ff43bac175bd9ed79e7c0f96840b139f2f51d01689a638fd05128becf94908a F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a F src/pager.c 9beb80f6e330dd63c5d8ba0f7a7f3a55fff22067a68d424949c389bfc6fa0c56 F src/pager.h 4b1140d691860de0be1347474c51fee07d5420bd7f802d38cbab8ea4ab9f538a -F src/parse.y 50516253433303673ff6b009983bb246d1527415e5a9af22acc51b0eedb9a10d +F src/parse.y 1a526e56da1d8255196bd59d4ca3e26d912d3dc26d18663ade25dd328945062e F src/pcache.c 040b165f30622a21b7a9a77c6f2e4877a32fb7f22d4c7f0d2a6fa6833a156a75 F src/pcache.h 1497ce1b823cf00094bb0cf3bac37b345937e6f910890c626b16512316d3abf5 F src/pcache1.c 602acb23c471bb8d557a6f0083cc2be641d6cafcafa19e481eba7ef4c9ca0f00 @@ -1584,7 +1584,7 @@ F test/select3.test 180223af31e1ca5537dd395ef9708ae18e651a233777fd366fd0d75469fc F test/select4.test f0684d3da3bccacbe2a1ebadf6fb49d9df6f53acb4c6ebc228a88d0d6054cc7b F test/select5.test 8afc5e5dcdebc2be54472e73ebd9cd1adef1225fd15d37a1c62f969159f390ae F test/select6.test 9b2fb4ffedf52e1b5703cfcae1212e7a4a063f014c0458d78d29aca3db766d1f -F test/select7.test f659f231489349e8c5734e610803d7654207318f +F test/select7.test b825420da8a0b5722fdb77f3369f6396a3d198c46e8787eb26ff9425d4ac9d27 F test/select8.test 8c8f5ae43894c891efc5755ed905467d1d67ad5d F test/select9.test f7586b207ce2304ab80dc93d3146469a28fd4403621dd3a82d06644563d3c812 F test/selectA.test 1da8ce3884c326e11d2855baffb76436b0d7e044404af8a2a70d1399a4ff7e29 @@ -2191,9 +2191,9 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 7a65ac42c2723b785786cf15f4b267ebfbd4f848f9fc6b37dcf9fac9abd0398c -Q +daa25fb35fd7bdd482d51214439f38b0b9a7df93f689a2b3d30a113daa9f2a1a -R 3ccb59e8ac6b0853bb8710d43043c061 -U stephan -Z 2fd891815cd1bc2fdd9840c2666785d4 +P 569824c7ff79ed1aadd2a6bce34bfcd8bf4f68db9565f56b803182adad526bc7 +Q +670beb133eb203065a75022f0c6db7c605a4e0e22c8ef6d6b4724be2663ff3dc +R 5956e4906a5865a8a3cd97615eaa54c8 +U drh +Z ee8bf72416287bbd114ae3210307ccd4 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 22db0758f1..2c9a5db00b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -569824c7ff79ed1aadd2a6bce34bfcd8bf4f68db9565f56b803182adad526bc7 +05dbfad70c3eb39f84b91503fc9b4c1cb96843e5e6599584077b1a630936ddc7 diff --git a/src/insert.c b/src/insert.c index 072386e656..a7e94420bf 100644 --- a/src/insert.c +++ b/src/insert.c @@ -717,6 +717,7 @@ Select *sqlite3MultiValues(Parse *pParse, Select *pLeft, ExprList *pRow){ pRet->pSrc->nSrc = 1; pRet->pPrior = pLeft->pPrior; pRet->op = pLeft->op; + if( pRet->pPrior ) pRet->selFlags |= SF_Values; pLeft->pPrior = 0; pLeft->op = TK_SELECT; assert( pLeft->pNext==0 ); diff --git a/src/parse.y b/src/parse.y index 071e10abd4..2ada5eb24b 100644 --- a/src/parse.y +++ b/src/parse.y @@ -530,9 +530,9 @@ cmd ::= select(X). { break; } } - if( (p->selFlags & SF_MultiValue)==0 && - (mxSelect = pParse->db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT])>0 && - cnt>mxSelect + if( (p->selFlags & (SF_MultiValue|SF_Values))==0 + && (mxSelect = pParse->db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT])>0 + && cnt>mxSelect ){ sqlite3ErrorMsg(pParse, "too many terms in compound SELECT"); } diff --git a/test/select7.test b/test/select7.test index d705ebfaf4..0c4051006a 100644 --- a/test/select7.test +++ b/test/select7.test @@ -155,6 +155,38 @@ if {[clang_sanitize_address]==0} { } } +# https://issues.chromium.org/issues/358174302 +# Need to support an unlimited number of terms in a VALUES clause, even +# if some of those terms contain double-quoted string literals. +# +do_execsql_test select7-6.5 { + DROP TABLE IF EXISTS t1; + CREATE TABLE t1(a,b,c); +} +sqlite3_limit db SQLITE_LIMIT_COMPOUND_SELECT 10 +sqlite3_db_config db SQLITE_DBCONFIG_DQS_DML 0 +do_catchsql_test select7-6.6 { + INSERT INTO t1 VALUES + (NULL,0,""), (X'',0.0,0.0), (X'',X'',""), (0.0,0.0,""), (NULL,NULL,0.0), + (0,"",0), (0.0,X'',0), ("",X'',0.0), (0.0,X'',NULL), (0,NULL,""), + (0,"",NULL), (0.0,NULL,X''), ("",X'',NULL), (NULL,0,""), + (0,NULL,0), (X'',X'',0.0); +} {1 {no such column: "" - should this be a string literal in single-quotes?}} +do_execsql_test select7-6.7 { + SELECT count(*) FROM t1; +} {0} +sqlite3_db_config db SQLITE_DBCONFIG_DQS_DML 1 +do_catchsql_test select7-6.8 { + INSERT INTO t1 VALUES + (NULL,0,""), (X'',0.0,0.0), (X'',X'',""), (0.0,0.0,""), (NULL,NULL,0.0), + (0,"",0), (0.0,X'',0), ("",X'',0.0), (0.0,X'',NULL), (0,NULL,""), + (0,"",NULL), (0.0,NULL,X''), ("",X'',NULL), (NULL,0,""), + (0,NULL,0), (X'',X'',0.0); +} {0 {}} +do_execsql_test select7-6.9 { + SELECT count(*) FROM t1; +} {16} + # This block of tests verifies that bug aa92c76cd4 is fixed. # do_test select7-7.1 { From b11e7e6aa7f89d25b0546ea88caad48f7e5c8244 Mon Sep 17 00:00:00 2001 From: dan Date: Thu, 8 Aug 2024 15:42:46 +0000 Subject: [PATCH 423/430] Ensure sqlite3expert.c unregisters any SQL user-functions it registers with the database handle before returning. FossilOrigin-Name: 270831444812d77e2b3db9534753600f9aa5c88cbf29094feeba549e860a714b --- ext/expert/expert1.test | 7 +++++++ ext/expert/sqlite3expert.c | 20 ++++++++++++-------- manifest | 18 +++++++++--------- manifest.uuid | 2 +- 4 files changed, 29 insertions(+), 18 deletions(-) diff --git a/ext/expert/expert1.test b/ext/expert/expert1.test index c456c30c52..72c4fd72cd 100644 --- a/ext/expert/expert1.test +++ b/ext/expert/expert1.test @@ -465,6 +465,13 @@ do_execsql_test 5.3 { t2 t2_idx_0001295b {100 20 5} } +do_catchsql_test 5.4 { + SELECT sqlite_expert_rem(123, 123); +} {1 {no such function: sqlite_expert_rem}} +do_catchsql_test 5.5 { + SELECT sqlite_expert_sample(); +} {1 {no such function: sqlite_expert_sample}} + if 0 { do_test expert1-6.0 { catchcmd :memory: { diff --git a/ext/expert/sqlite3expert.c b/ext/expert/sqlite3expert.c index 276c2cc9fe..b59a59728d 100644 --- a/ext/expert/sqlite3expert.c +++ b/ext/expert/sqlite3expert.c @@ -626,7 +626,7 @@ static int expertFilter( pCsr->pData = 0; if( rc==SQLITE_OK ){ rc = idxPrintfPrepareStmt(pExpert->db, &pCsr->pData, &pVtab->base.zErrMsg, - "SELECT * FROM main.%Q WHERE sample()", pVtab->pTab->zName + "SELECT * FROM main.%Q WHERE sqlite_expert_sample()", pVtab->pTab->zName ); } @@ -1500,7 +1500,7 @@ struct IdxRemCtx { }; /* -** Implementation of scalar function rem(). +** Implementation of scalar function sqlite_expert_rem(). */ static void idxRemFunc( sqlite3_context *pCtx, @@ -1513,7 +1513,7 @@ static void idxRemFunc( assert( argc==2 ); iSlot = sqlite3_value_int(argv[0]); - assert( iSlot<=p->nSlot ); + assert( iSlotnSlot ); pSlot = &p->aSlot[iSlot]; switch( pSlot->eType ){ @@ -1624,7 +1624,8 @@ static int idxPopulateOneStat1( const char *zName = (const char*)sqlite3_column_text(pIndexXInfo, 0); const char *zColl = (const char*)sqlite3_column_text(pIndexXInfo, 1); zCols = idxAppendText(&rc, zCols, - "%sx.%Q IS rem(%d, x.%Q) COLLATE %s", zComma, zName, nCol, zName, zColl + "%sx.%Q IS sqlite_expert_rem(%d, x.%Q) COLLATE %s", + zComma, zName, nCol, zName, zColl ); zOrder = idxAppendText(&rc, zOrder, "%s%d", zComma, ++nCol); } @@ -1757,13 +1758,13 @@ static int idxPopulateStat1(sqlite3expert *p, char **pzErr){ if( rc==SQLITE_OK ){ sqlite3 *dbrem = (p->iSample==100 ? p->db : p->dbv); - rc = sqlite3_create_function( - dbrem, "rem", 2, SQLITE_UTF8, (void*)pCtx, idxRemFunc, 0, 0 + rc = sqlite3_create_function(dbrem, "sqlite_expert_rem", + 2, SQLITE_UTF8, (void*)pCtx, idxRemFunc, 0, 0 ); } if( rc==SQLITE_OK ){ - rc = sqlite3_create_function( - p->db, "sample", 0, SQLITE_UTF8, (void*)&samplectx, idxSampleFunc, 0, 0 + rc = sqlite3_create_function(p->db, "sqlite_expert_sample", + 0, SQLITE_UTF8, (void*)&samplectx, idxSampleFunc, 0, 0 ); } @@ -1815,6 +1816,9 @@ static int idxPopulateStat1(sqlite3expert *p, char **pzErr){ rc = sqlite3_exec(p->dbm, "ANALYZE sqlite_schema", 0, 0, 0); } + sqlite3_create_function(p->db, "sqlite_expert_rem", 2, SQLITE_UTF8, 0,0,0,0); + sqlite3_create_function(p->db, "sqlite_expert_sample", 0,SQLITE_UTF8,0,0,0,0); + sqlite3_exec(p->db, "DROP TABLE IF EXISTS temp."UNIQUE_TABLE_NAME,0,0,0); return rc; } diff --git a/manifest b/manifest index e99bf37f1c..4f523017cb 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Do\snot\slet\sthe\snumber\sof\sterms\son\sa\sVALUES\sclause\sbe\slimited\sby\nSQLITE_LIMIT_COMPOUND_SELECT,\seven\sif\sthe\sVALUES\sclause\scontains\selements\nthat\sappear\sto\sbe\svariables\sdue\sto\sthe\suse\sof\sdouble-quoted\sstring\sliterals. -D 2024-08-08T14:49:54.365 +C Ensure\ssqlite3expert.c\sunregisters\sany\sSQL\suser-functions\sit\sregisters\swith\sthe\sdatabase\shandle\sbefore\sreturning. +D 2024-08-08T15:42:46.324 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -57,8 +57,8 @@ F ext/consio/console_io.c f32b757c9ee7fdf68e7586bee306f8368759e7cd12febb2a683919 F ext/consio/console_io.h 0548b83d7c4b7270ad544a67f2bb90cebc519637fa39b1838df4744cf0d87646 F ext/expert/README.md b321c2762bb93c18ea102d5a5f7753a4b8bac646cb392b3b437f633caf2020c3 F ext/expert/expert.c d548d603a4cc9e61f446cc179c120c6713511c413f82a4a32b1e1e69d3f086a4 -F ext/expert/expert1.test 53a749de08939e3bc14f804e97410927d46fa772cbce0247d7e8fa6fc2523b0c -F ext/expert/sqlite3expert.c c8cea5ff15fbe792cccc4992a9b40b706411c41d32611f617897fecac6ff06a4 +F ext/expert/expert1.test 661f873fd451127edf822ef0d520088faa319135f6a15bd10be6801ac284ac9b +F ext/expert/sqlite3expert.c 8b09aeb2b95a9fca8b6628b522bf4d69aa746ff64c38eb1e99a9b5fad8cf03b9 F ext/expert/sqlite3expert.h ca81efc2679a92373a13a3e76a6138d0310e32be53d6c3bfaedabd158ea8969b F ext/expert/test_expert.c d56c194b769bdc90cf829a14c9ecbc1edca9c850b837a4d0b13be14095c32a72 F ext/fts3/README.content b9078d0843a094d86af0d48dffbff13c906702b4c3558012e67b9c7cc3bf59ee @@ -2191,9 +2191,9 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 569824c7ff79ed1aadd2a6bce34bfcd8bf4f68db9565f56b803182adad526bc7 -Q +670beb133eb203065a75022f0c6db7c605a4e0e22c8ef6d6b4724be2663ff3dc -R 5956e4906a5865a8a3cd97615eaa54c8 -U drh -Z ee8bf72416287bbd114ae3210307ccd4 +P 05dbfad70c3eb39f84b91503fc9b4c1cb96843e5e6599584077b1a630936ddc7 +Q +123b154ce3b6fee1bbf483704812bd6f8538966f9687520b4470d700f0270719 +R a8307329e7c28fd3c923f24b58fddfd1 +U dan +Z 6e3b831efc16724eb699f2665adc2c9d # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 2c9a5db00b..59163fb544 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -05dbfad70c3eb39f84b91503fc9b4c1cb96843e5e6599584077b1a630936ddc7 +270831444812d77e2b3db9534753600f9aa5c88cbf29094feeba549e860a714b From 4c6a1298f8863668d343574846b3e522de8f651b Mon Sep 17 00:00:00 2001 From: stephan Date: Fri, 9 Aug 2024 12:20:15 +0000 Subject: [PATCH 424/430] Remove unused static var cBadGroup from ext/consio/console_io.c to resolve a compiler warning reported in the fossil forum. This is a build fix, not a functional change. FossilOrigin-Name: be3de2e600037aa30a8c2cd7d6cfe8f2ba5a9c3e89ac99e87634e2c8c67c1846 --- ext/consio/console_io.c | 5 ----- manifest | 16 ++++++++-------- manifest.uuid | 2 +- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/ext/consio/console_io.c b/ext/consio/console_io.c index 3e2f556f52..3fa613ba9d 100755 --- a/ext/consio/console_io.c +++ b/ext/consio/console_io.c @@ -53,11 +53,6 @@ # define CIO_WIN_WC_XLATE 0 /* Not exposing translation routines at all */ #endif -#if CIO_WIN_WC_XLATE -/* Character used to represent a known-incomplete UTF-8 char group (�) */ -static WCHAR cBadGroup = 0xfffd; -#endif - #if CIO_WIN_WC_XLATE static HANDLE handleOfFile(FILE *pf){ int fileDesc = _fileno(pf); diff --git a/manifest b/manifest index 4f523017cb..4e7cf5c508 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Ensure\ssqlite3expert.c\sunregisters\sany\sSQL\suser-functions\sit\sregisters\swith\sthe\sdatabase\shandle\sbefore\sreturning. -D 2024-08-08T15:42:46.324 +C Remove\sunused\sstatic\svar\scBadGroup\sfrom\sext/consio/console_io.c\sto\sresolve\sa\scompiler\swarning\sreported\sin\sthe\sfossil\sforum.\sThis\sis\sa\sbuild\sfix,\snot\sa\sfunctional\schange. +D 2024-08-09T12:20:15.578 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -53,7 +53,7 @@ F ext/README.md fd5f78013b0a2bc6f0067afb19e6ad040e89a10179b4f6f03eee58fac5f169bd F ext/async/README.txt e12275968f6fde133a80e04387d0e839b0c51f91 F ext/async/sqlite3async.c 6f247666b495c477628dd19364d279c78ea48cd90c72d9f9b98ad1aff3294f94 F ext/async/sqlite3async.h 46b47c79357b97ad85d20d2795942c0020dc20c532114a49808287f04aa5309a -F ext/consio/console_io.c f32b757c9ee7fdf68e7586bee306f8368759e7cd12febb2a6839199b1c1af395 x +F ext/consio/console_io.c b4885dfea71ed583315de8f0792a29d5fc7c7460b4a26c0aebe5cda5da8b38f8 x F ext/consio/console_io.h 0548b83d7c4b7270ad544a67f2bb90cebc519637fa39b1838df4744cf0d87646 F ext/expert/README.md b321c2762bb93c18ea102d5a5f7753a4b8bac646cb392b3b437f633caf2020c3 F ext/expert/expert.c d548d603a4cc9e61f446cc179c120c6713511c413f82a4a32b1e1e69d3f086a4 @@ -2191,9 +2191,9 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 05dbfad70c3eb39f84b91503fc9b4c1cb96843e5e6599584077b1a630936ddc7 -Q +123b154ce3b6fee1bbf483704812bd6f8538966f9687520b4470d700f0270719 -R a8307329e7c28fd3c923f24b58fddfd1 -U dan -Z 6e3b831efc16724eb699f2665adc2c9d +P 270831444812d77e2b3db9534753600f9aa5c88cbf29094feeba549e860a714b +Q +fa047c3ea7a03d76afd6a11f58ef7b84c653f583ed795e0de5be2a6b986e558e +R a541bc144fee54c5941013bb3373ad5d +U stephan +Z 4c806094a0767e83b119a2a0b41e2595 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 59163fb544..367d688dff 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -270831444812d77e2b3db9534753600f9aa5c88cbf29094feeba549e860a714b +be3de2e600037aa30a8c2cd7d6cfe8f2ba5a9c3e89ac99e87634e2c8c67c1846 From 21219fe31314685d9c453d483ff763e85e122456 Mon Sep 17 00:00:00 2001 From: drh <> Date: Sat, 10 Aug 2024 10:14:47 +0000 Subject: [PATCH 425/430] Enhancements to covering-index prediction. Add early detection of over-prediction of covering-indexes so that sqlite3_prepare() will return an error rather than just generate bad bytecode. FossilOrigin-Name: 4afe3201f005bfd1aa66bbeebac659323d8a35dbee04d50fbf77ba96a94db91e --- manifest | 16 +++++++------- manifest.uuid | 2 +- src/where.c | 58 ++++++++++++++++----------------------------------- 3 files changed, 27 insertions(+), 49 deletions(-) diff --git a/manifest b/manifest index 4e7cf5c508..bd83d89783 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\sunused\sstatic\svar\scBadGroup\sfrom\sext/consio/console_io.c\sto\sresolve\sa\scompiler\swarning\sreported\sin\sthe\sfossil\sforum.\sThis\sis\sa\sbuild\sfix,\snot\sa\sfunctional\schange. -D 2024-08-09T12:20:15.578 +C Enhancements\sto\scovering-index\sprediction.\nAdd\searly\sdetection\sof\sover-prediction\sof\scovering-indexes\sso\sthat\nsqlite3_prepare()\swill\sreturn\san\serror\srather\sthan\sjust\sgenerate\sbad\nbytecode. +D 2024-08-10T10:14:47.173 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -839,7 +839,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c 887fc4ca3f020ebb2e376f222069570834ac63bf50111ef0cbf3ae417048ed89 F src/wal.h ba252daaa94f889f4b2c17c027e823d9be47ce39da1d3799886bbd51f0490452 F src/walker.c 7c7ea0115345851c3da4e04e2e239a29983b61fb5b038b94eede6aba462640e2 -F src/where.c 4df8b013fe5b56a6674af695fab8c738e59c9d21005abb11f53c42edf52b50bd +F src/where.c c015aba5f42fbb952029b693695ae2a75fd947aec6e43f94e6ab0ae6ed00cbf9 F src/whereInt.h 82a13766f13d1a53b05387c2e60726289ef26404bc7b9b1f7770204d97357fb8 F src/wherecode.c f5255f49d1f42b6e7e6b0362ff3522fa88cbcaa7213e52f9374744027ecdebca F src/whereexpr.c 67d15caf88a1a9528283d68ff578e024cf9fe810b517bb0343e5aaf695ad97dd @@ -2191,9 +2191,9 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 270831444812d77e2b3db9534753600f9aa5c88cbf29094feeba549e860a714b -Q +fa047c3ea7a03d76afd6a11f58ef7b84c653f583ed795e0de5be2a6b986e558e -R a541bc144fee54c5941013bb3373ad5d -U stephan -Z 4c806094a0767e83b119a2a0b41e2595 +P be3de2e600037aa30a8c2cd7d6cfe8f2ba5a9c3e89ac99e87634e2c8c67c1846 +Q +f0b671183f44d0ae294956e7651a1653f47bd6219f9636872d15993f30f28dfb +R 5dc9151f916d4136d39a91f2892712c3 +U drh +Z 020ac4aee91ddc9c1c230a230e0fc80c # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 367d688dff..855bc7b828 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -be3de2e600037aa30a8c2cd7d6cfe8f2ba5a9c3e89ac99e87634e2c8c67c1846 +4afe3201f005bfd1aa66bbeebac659323d8a35dbee04d50fbf77ba96a94db91e diff --git a/src/where.c b/src/where.c index 2e3679d5d5..684a37f54c 100644 --- a/src/where.c +++ b/src/where.c @@ -3959,7 +3959,9 @@ static int whereLoopAddBtree( " according to whereIsCoveringIndex()\n", pProbe->zName)); } } - }else if( m==0 ){ + }else if( m==0 + && (HasRowid(pTab) || pWInfo->pSelect!=0 || sqlite3FaultSim(700)) + ){ WHERETRACE(0x200, ("-> %s a covering index according to bitmasks\n", pProbe->zName, m==0 ? "is" : "is not")); @@ -6889,26 +6891,6 @@ WhereInfo *sqlite3WhereBegin( } #endif -#ifdef SQLITE_DEBUG -/* -** Return true if cursor iCur is opened by instruction k of the -** bytecode. Used inside of assert() only. -*/ -static int cursorIsOpen(Vdbe *v, int iCur, int k){ - while( k>=0 ){ - VdbeOp *pOp = sqlite3VdbeGetOp(v,k--); - if( pOp->p1!=iCur ) continue; - if( pOp->opcode==OP_Close ) return 0; - if( pOp->opcode==OP_OpenRead ) return 1; - if( pOp->opcode==OP_OpenWrite ) return 1; - if( pOp->opcode==OP_OpenDup ) return 1; - if( pOp->opcode==OP_OpenAutoindex ) return 1; - if( pOp->opcode==OP_OpenEphemeral ) return 1; - } - return 0; -} -#endif /* SQLITE_DEBUG */ - /* ** Generate the end of the WHERE loop. See comments on ** sqlite3WhereBegin() for additional information. @@ -7187,18 +7169,20 @@ void sqlite3WhereEnd(WhereInfo *pWInfo){ assert( pIdx->pTable==pTab ); #ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC if( pOp->opcode==OP_Offset ){ - /* Do not need to translate the column number */ + x = 0; }else #endif - if( !HasRowid(pTab) ){ - Index *pPk = sqlite3PrimaryKeyIndex(pTab); - x = pPk->aiColumn[x]; - assert( x>=0 ); - }else{ - testcase( x!=sqlite3StorageColumnToTable(pTab,x) ); - x = sqlite3StorageColumnToTable(pTab,x); + { + if( !HasRowid(pTab) ){ + Index *pPk = sqlite3PrimaryKeyIndex(pTab); + x = pPk->aiColumn[x]; + assert( x>=0 ); + }else{ + testcase( x!=sqlite3StorageColumnToTable(pTab,x) ); + x = sqlite3StorageColumnToTable(pTab,x); + } + x = sqlite3TableColumnToIndex(pIdx, x); } - x = sqlite3TableColumnToIndex(pIdx, x); if( x>=0 ){ pOp->p2 = x; pOp->p1 = pLevel->iIdxCur; @@ -7208,16 +7192,10 @@ void sqlite3WhereEnd(WhereInfo *pWInfo){ ** reference. Verify that this is harmless - that the ** table being referenced really is open. */ -#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC - assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 - || cursorIsOpen(v,pOp->p1,k) - || pOp->opcode==OP_Offset - ); -#else - assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 - || cursorIsOpen(v,pOp->p1,k) - ); -#endif + if( pLoop->wsFlags & WHERE_IDX_ONLY ){ + sqlite3ErrorMsg(pParse, "internal query planner error"); + pParse->rc = SQLITE_INTERNAL; + } } }else if( pOp->opcode==OP_Rowid ){ pOp->p1 = pLevel->iIdxCur; From 3b171836ec14ff3a25086f5f47a6f664976cd096 Mon Sep 17 00:00:00 2001 From: drh <> Date: Sat, 10 Aug 2024 11:02:23 +0000 Subject: [PATCH 426/430] Cherrypick various minor fixes from trunk into branch-3.46. FossilOrigin-Name: 6047b18ee3c4d8f2661386ef68c717f5892651c3d6f7e29a98a6b2795b3382d3 --- ext/fts5/fts5_expr.c | 7 ++++++- ext/fts5/fts5_main.c | 28 ++++++++++++++++++---------- ext/fts5/test/fts5aux.test | 24 ++++++++++++++++++++++++ ext/fts5/test/fts5integrity.test | 27 +++++++++++++++++++++++++++ manifest | 32 +++++++++++++++++++------------- manifest.uuid | 2 +- src/resolve.c | 6 +++--- src/vdbeaux.c | 6 ++++-- test/returning1.test | 13 +++++++++++++ 9 files changed, 115 insertions(+), 30 deletions(-) diff --git a/ext/fts5/fts5_expr.c b/ext/fts5/fts5_expr.c index 05c1b59c14..960a4d4687 100644 --- a/ext/fts5/fts5_expr.c +++ b/ext/fts5/fts5_expr.c @@ -324,7 +324,11 @@ int sqlite3Fts5ExprNew( } sqlite3_free(sParse.apPhrase); - *pzErr = sParse.zErr; + if( 0==*pzErr ){ + *pzErr = sParse.zErr; + }else{ + sqlite3_free(sParse.zErr); + } return sParse.rc; } @@ -2452,6 +2456,7 @@ Fts5ExprNode *sqlite3Fts5ParseImplicitAnd( assert( pRight->eType==FTS5_STRING || pRight->eType==FTS5_TERM || pRight->eType==FTS5_EOF + || (pRight->eType==FTS5_AND && pParse->bPhraseToAnd) ); if( pLeft->eType==FTS5_AND ){ diff --git a/ext/fts5/fts5_main.c b/ext/fts5/fts5_main.c index b3ca2f71bb..837ea4015d 100644 --- a/ext/fts5/fts5_main.c +++ b/ext/fts5/fts5_main.c @@ -2875,14 +2875,16 @@ int sqlite3Fts5GetTokenizer( if( pMod==0 ){ assert( nArg>0 ); rc = SQLITE_ERROR; - *pzErr = sqlite3_mprintf("no such tokenizer: %s", azArg[0]); + if( pzErr ) *pzErr = sqlite3_mprintf("no such tokenizer: %s", azArg[0]); }else{ rc = pMod->x.xCreate( pMod->pUserData, (azArg?&azArg[1]:0), (nArg?nArg-1:0), &pConfig->pTok ); pConfig->pTokApi = &pMod->x; if( rc!=SQLITE_OK ){ - if( pzErr ) *pzErr = sqlite3_mprintf("error in tokenizer constructor"); + if( pzErr && rc!=SQLITE_NOMEM ){ + *pzErr = sqlite3_mprintf("error in tokenizer constructor"); + } }else{ pConfig->ePattern = sqlite3Fts5TokenizerPattern( pMod->x.xCreate, pConfig->pTok @@ -2976,17 +2978,23 @@ static int fts5IntegrityMethod( assert( pzErr!=0 && *pzErr==0 ); UNUSED_PARAM(isQuick); + assert( pTab->p.pConfig->pzErrmsg==0 ); + pTab->p.pConfig->pzErrmsg = pzErr; rc = sqlite3Fts5StorageIntegrity(pTab->pStorage, 0); - if( (rc&0xff)==SQLITE_CORRUPT ){ - *pzErr = sqlite3_mprintf("malformed inverted index for FTS5 table %s.%s", - zSchema, zTabname); - rc = (*pzErr) ? SQLITE_OK : SQLITE_NOMEM; - }else if( rc!=SQLITE_OK ){ - *pzErr = sqlite3_mprintf("unable to validate the inverted index for" - " FTS5 table %s.%s: %s", - zSchema, zTabname, sqlite3_errstr(rc)); + if( *pzErr==0 && rc!=SQLITE_OK ){ + if( (rc&0xff)==SQLITE_CORRUPT ){ + *pzErr = sqlite3_mprintf("malformed inverted index for FTS5 table %s.%s", + zSchema, zTabname); + rc = (*pzErr) ? SQLITE_OK : SQLITE_NOMEM; + }else{ + *pzErr = sqlite3_mprintf("unable to validate the inverted index for" + " FTS5 table %s.%s: %s", + zSchema, zTabname, sqlite3_errstr(rc)); + } } + sqlite3Fts5IndexCloseReader(pTab->p.pIndex); + pTab->p.pConfig->pzErrmsg = 0; return rc; } diff --git a/ext/fts5/test/fts5aux.test b/ext/fts5/test/fts5aux.test index 5569f48cf3..7963006371 100644 --- a/ext/fts5/test/fts5aux.test +++ b/ext/fts5/test/fts5aux.test @@ -377,4 +377,28 @@ do_catchsql_test 12.3.3 { SELECT fts5_collist(t1, 1) FROM t1('one AND two'); } {0 1} +#------------------------------------------------------------------------- +reset_db +do_execsql_test 13.1 { + CREATE VIRTUAL TABLE t1 USING fts5(a, tokenize=ascii); + INSERT INTO t1 VALUES('a b c'), ('d e f'); + PRAGMA integrity_check; +} {ok} + +do_catchsql_test 13.2 { + SELECT highlight(t1, 0, '[', ']') FROM t1 +} {0 {{a b c} {d e f}}} + +do_execsql_test 13.3 { + PRAGMA writable_schema = 1; + UPDATE sqlite_schema SET sql = 'CREATE VIRTUAL TABLE t1 USING fts5(a, tokenize=blah)' + WHERE name = 't1'; +} + +db close +sqlite3 db test.db +do_catchsql_test 13.4 { + SELECT highlight(t1, 0, '[', ']') FROM t1 +} {1 {no such tokenizer: blah}} + finish_test diff --git a/ext/fts5/test/fts5integrity.test b/ext/fts5/test/fts5integrity.test index 1bb367538d..5ed659b1fd 100644 --- a/ext/fts5/test/fts5integrity.test +++ b/ext/fts5/test/fts5integrity.test @@ -380,5 +380,32 @@ do_execsql_test 12.3 { } {ok} +#------------------------------------------------------------------- +reset_db +do_execsql_test 13.1 { + CREATE VIRTUAL TABLE t1 USING fts5(a, tokenize=ascii); + INSERT INTO t1 VALUES('a b c'), ('d e f'); + PRAGMA integrity_check; +} {ok} + +db close +sqlite3 db test.db +do_catchsql_test 13.2 { + PRAGMA integrity_check; +} {0 ok} + +do_execsql_test 13.3 { + PRAGMA writable_schema = 1; + UPDATE sqlite_schema SET sql = 'CREATE VIRTUAL TABLE t1 USING fts5(a, tokenize=blah)' + WHERE name = 't1'; +} + +db close +sqlite3 db test.db +breakpoint +do_catchsql_test 13.4 { + PRAGMA integrity_check; +} {1 {no such tokenizer: blah}} + finish_test diff --git a/manifest b/manifest index bd83d89783..548a8f155e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Enhancements\sto\scovering-index\sprediction.\nAdd\searly\sdetection\sof\sover-prediction\sof\scovering-indexes\sso\sthat\nsqlite3_prepare()\swill\sreturn\san\serror\srather\sthan\sjust\sgenerate\sbad\nbytecode. -D 2024-08-10T10:14:47.173 +C Cherrypick\svarious\sminor\sfixes\sfrom\strunk\sinto\sbranch-3.46. +D 2024-08-10T11:02:23.976 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -97,10 +97,10 @@ F ext/fts5/fts5Int.h defa43c0932265138ee910ca416e6baccf8b774e0f3d610e74be1ab2880 F ext/fts5/fts5_aux.c 4584e88878e54828bf7d4d0d83deedd232ec60628b7731be02bad6adb62304b1 F ext/fts5/fts5_buffer.c 0eec58bff585f1a44ea9147eae5da2447292080ea435957f7488c70673cb6f09 F ext/fts5/fts5_config.c 8072a207034b51ae9b7694121d1b5715c794e94b275e088f70ae532378ca5cdf -F ext/fts5/fts5_expr.c e91156ebdcc08d837f4f324168f69f3c0d7fdef0e521fd561efb48ef3297b696 +F ext/fts5/fts5_expr.c d6a48d81aa96d68090187059f48dba2184e0cb0fd3b50a5a84a649a865cb31a5 F ext/fts5/fts5_hash.c adda4272be401566a6e0ba1acbe70ee5cb97fce944bc2e04dc707152a0ec91b1 F ext/fts5/fts5_index.c ee0f4d50bc0c58a7c5ef7d645e7e38e1e59315b8ea9d722ae00c5f949ee65379 -F ext/fts5/fts5_main.c 981551daf629445e37bef0280b888631503adeec37a1f9b5f7751a4430b70ac2 +F ext/fts5/fts5_main.c 0a8fc885851d76af6ea670090231ed23b9f8f349f44080e79a0f59b1d54511bb F ext/fts5/fts5_storage.c f9e31b0d155e9b2c92d5d3a09ad7a56b937fbf1c7f962e10f4ca6281349f3934 F ext/fts5/fts5_tcl.c fdf7e2bb9a9186cfcaf2d2ce11d338309342b7a7593c2812bc54455db53da5d2 F ext/fts5/fts5_test_mi.c 08c11ec968148d4cb4119d96d819f8c1f329812c568bac3684f5464be177d3ee @@ -126,7 +126,7 @@ F ext/fts5/test/fts5ak.test f459a64c9d38698af72a7c657ab6349bca96150241dd69fcce75 F ext/fts5/test/fts5al.test 00c4c1c6a1366b73aa48ce2068c634520867c3cf7f5d1676ebbb775ee1f35734 F ext/fts5/test/fts5alter.test 5565f7e4605512b69171ac18ca84398603f9f6456dbe377beeca97e83cc242cd F ext/fts5/test/fts5auto.test 78989e6527ce69c9eddbef7392fea5c10b0010cd2b2ae68eec7bc869c471e691 -F ext/fts5/test/fts5aux.test ed3596469f85a6cff5f6060e0cd9e3f9602051d8db2b497f5d12c85d39f20a62 +F ext/fts5/test/fts5aux.test e0866d924289423164c539576229ea589990e6dd38d05a0b6f8752ad51d70bb4 F ext/fts5/test/fts5auxdata.test eacc97ff04892f1a5f3d4df5a73f8bcbc3955ea1d12c9f24137eb1fc079e7611 F ext/fts5/test/fts5bigid.test 2860854c2561a57594192b00c33a29f91cb85e25f3d6c03b5c2b8f62708f39dd F ext/fts5/test/fts5bigpl.test 6466c89b38439f0aba26ac09e232a6b963f29b1cbe1304f6a664fe1e7a8f5fd3 @@ -178,7 +178,7 @@ F ext/fts5/test/fts5first.test 3fcf2365c00a15fc9704233674789a3b95131d12de18a9b99 F ext/fts5/test/fts5full.test e1701a112354e0ff9a1fdffb0c940c576530c33732ee20ac5e8361777070d717 F ext/fts5/test/fts5fuzz1.test 238d8c45f3b81342aa384de3e581ff2fa330bf922a7b69e484bbc06051a1080e F ext/fts5/test/fts5hash.test dc7bc7e0cdeb42cfce31294ad2f8fcf43192bfd0145bb7f3ecc5465d8c72696f -F ext/fts5/test/fts5integrity.test f1723fe9fb9381b26c946ab4d7505041434df2c449d1cd53f45c7bf8c098dfa2 +F ext/fts5/test/fts5integrity.test f7a9dc2c2b8db0db024eaa546ed56add97f869b67064e258c36dcdd0243f25f2 F ext/fts5/test/fts5interrupt.test 09613247b273a99889808ef852898177e671406fe71fdde7ea00e78ea283d227 F ext/fts5/test/fts5lastrowid.test be98fe3e03235296585b72daad7aed5717ba0062bae5e5c18dd6e04e194c6b28 F ext/fts5/test/fts5leftjoin.test c0b4cafb9661379e576dc4405c0891d8fcc2782680740513c4d1fc114b43d4ad @@ -752,7 +752,7 @@ F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7 F src/prepare.c d99931f45416652895e502328ca49fe782cfc4e1ebdcda13b3736d991ebf42ce F src/printf.c 8b250972305e14b365561be5117ed0fd364e4fd58968776df1ce64c6280b90f9 F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c -F src/resolve.c 22f1fa3423b377c02ae78d451cfeb1c2d96dcf0389c0642cbdcd19d3bfd7ae01 +F src/resolve.c ae341d04d39de308e024649d6777dd015b6a94ddbfbe74d7fca2ee122fb1aea9 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c 1a841c38974d45cf15a7611398479182b61ad4c187423c380741d8b1688fe607 F src/shell.c.in ebb698028ec031e0b1595865500097d2005f977be0efd14bd8b0ddf634d5ed8d @@ -828,7 +828,7 @@ F src/vdbe.c 3b1793c5d2235ae89b01ef051a33d7d2ad3704c71799653b112686735ad401ff F src/vdbe.h c2d78d15112c3fc5ab87f5e8e0b75d2db1c624409de2e858c3d1aafb1650bb4f F src/vdbeInt.h 949669dfd8a41550d27dcb905b494f2ccde9a2e6c1b0b04daa1227e2e74c2b2c F src/vdbeapi.c 80235ac380e9467fec1cb0883354d841f2a771976e766995f7e0c77f845406df -F src/vdbeaux.c 3bcf13776c39bf660a52b4b97f6389a421c2756f9ffbf4c0d94f73e1935d8d9c +F src/vdbeaux.c 6e37cb918506c28fe7657454fcbc2e01e66bfba4164f306c2f075fd5c5fef609 F src/vdbeblob.c 13f9287b55b6356b4b1845410382d6bede203ceb29ef69388a4a3d007ffacbe5 F src/vdbemem.c 831a244831eaa45335f9ae276b50a7a82ee10d8c46c2c72492d4eb8c98d94d89 F src/vdbesort.c 237840ca1947511fa59bd4e18b9eeae93f2af2468c34d2427b059f896230a547 @@ -1536,7 +1536,7 @@ F test/regexp2.test 55ed41da802b0e284ac7e2fe944be3948f93ff25abbca0361a609acfed13 F test/reindex.test cd9d6021729910ece82267b4f5e1b5ac2911a7566c43b43c176a6a4732e2118d F test/resetdb.test 54c06f18bc832ac6d6319e5ab23d5c8dd49fdbeec7c696d791682a8006bd5fc3 F test/resolver01.test f4022acafda7f4d40eca94dbf16bc5fc4ac30ceb -F test/returning1.test 38eee9d07ac1dd4fbd4ce7373497f3783db86b9a76f13ea6a9f9afaf934f888b +F test/returning1.test 212cd4111bb941a60abf608f20250db666c21eb1bc4d49217e96c87ff3ab9d1a F test/returningfault.test ae4c4b5e8745813287a359d9ccdb9d5c883c2e68afb18fb0767937d5de5692a4 F test/rollback.test 06680159bc6746d0f26276e339e3ae2f951c64812468308838e0a3362d911eaa F test/rollback2.test 3f3a4e20401825017df7e7671e9f31b6de5fae5620c2b9b49917f52f8c160a8f @@ -2191,9 +2191,15 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P be3de2e600037aa30a8c2cd7d6cfe8f2ba5a9c3e89ac99e87634e2c8c67c1846 -Q +f0b671183f44d0ae294956e7651a1653f47bd6219f9636872d15993f30f28dfb -R 5dc9151f916d4136d39a91f2892712c3 +P 4afe3201f005bfd1aa66bbeebac659323d8a35dbee04d50fbf77ba96a94db91e +Q +061d7b69e6a43474cd7123a69f4ee65b5649a0b5e51474343defef5ae5262657 +Q +08cc5488404d068e59378b82988460793710df43ec21b4a83a794b497abd035f +Q +273504b74cb9c3cfa2497a1339e706a1f2d2c3ce81b23a16beb47da9292535e0 +Q +a096eb7554952f8137c6e9330c328164719fb27e958787fbd503bcd1364e6ae4 +Q +a35c50eca907d0cf373b7962c359aebfce8ac7c34ce81edeb99122d4fb5804f7 +Q +c7aaa28f786567e29ebee3848283b5c740dd3b8144dc14372e56260ae1b76922 +Q +e78b7783040ef1ad34d4287af8a7a5998d360d50076e0de42a116d9a96fe74b4 +R 9db66ace3e0949b1bbff4f1693881c2f U drh -Z 020ac4aee91ddc9c1c230a230e0fc80c +Z 1aa2ed1f9203f8c31686df6bb8cab665 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 855bc7b828..581b9c84e3 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4afe3201f005bfd1aa66bbeebac659323d8a35dbee04d50fbf77ba96a94db91e +6047b18ee3c4d8f2661386ef68c717f5892651c3d6f7e29a98a6b2795b3382d3 diff --git a/src/resolve.c b/src/resolve.c index bf8326aa64..40044a2204 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -228,7 +228,7 @@ static void extendFJMatch( static SQLITE_NOINLINE int isValidSchemaTableName( const char *zTab, /* Name as it appears in the SQL */ Table *pTab, /* The schema table we are trying to match */ - Schema *pSchema /* non-NULL if a database qualifier is present */ + const char *zDb /* non-NULL if a database qualifier is present */ ){ const char *zLegacy; assert( pTab!=0 ); @@ -239,7 +239,7 @@ static SQLITE_NOINLINE int isValidSchemaTableName( if( sqlite3StrICmp(zTab+7, &PREFERRED_TEMP_SCHEMA_TABLE[7])==0 ){ return 1; } - if( pSchema==0 ) return 0; + if( zDb==0 ) return 0; if( sqlite3StrICmp(zTab+7, &LEGACY_SCHEMA_TABLE[7])==0 ) return 1; if( sqlite3StrICmp(zTab+7, &PREFERRED_SCHEMA_TABLE[7])==0 ) return 1; }else{ @@ -422,7 +422,7 @@ static int lookupName( } }else if( sqlite3StrICmp(zTab, pTab->zName)!=0 ){ if( pTab->tnum!=1 ) continue; - if( !isValidSchemaTableName(zTab, pTab, pSchema) ) continue; + if( !isValidSchemaTableName(zTab, pTab, zDb) ) continue; } assert( ExprUseYTab(pExpr) ); if( IN_RENAME_OBJECT && pItem->zAlias ){ diff --git a/src/vdbeaux.c b/src/vdbeaux.c index e4c174e3fb..665f6cd17a 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -5336,7 +5336,8 @@ sqlite3_value *sqlite3VdbeGetBoundValue(Vdbe *v, int iVar, u8 aff){ assert( iVar>0 ); if( v ){ Mem *pMem = &v->aVar[iVar-1]; - assert( (v->db->flags & SQLITE_EnableQPSG)==0 ); + assert( (v->db->flags & SQLITE_EnableQPSG)==0 + || (v->db->mDbFlags & DBFLAG_InternalFunc)!=0 ); if( 0==(pMem->flags & MEM_Null) ){ sqlite3_value *pRet = sqlite3ValueNew(v->db); if( pRet ){ @@ -5356,7 +5357,8 @@ sqlite3_value *sqlite3VdbeGetBoundValue(Vdbe *v, int iVar, u8 aff){ */ void sqlite3VdbeSetVarmask(Vdbe *v, int iVar){ assert( iVar>0 ); - assert( (v->db->flags & SQLITE_EnableQPSG)==0 ); + assert( (v->db->flags & SQLITE_EnableQPSG)==0 + || (v->db->mDbFlags & DBFLAG_InternalFunc)!=0 ); if( iVar>=32 ){ v->expmask |= 0x80000000; }else{ diff --git a/test/returning1.test b/test/returning1.test index 05bd445a2f..e7be7c65a3 100644 --- a/test/returning1.test +++ b/test/returning1.test @@ -531,4 +531,17 @@ do_execsql_test 21.1 { INSERT INTO sqlite_temp_schema DEFAULT VALUES RETURNING sqlite_temp_schema.name; } {{}} +#------------------------------------------------------------------------- +reset_db +do_execsql_test 22.0 { + PRAGMA writable_schema=ON; + CREATE TABLE xyz (a); +} +do_catchsql_test 22.1 { + INSERT INTO sqlite_temp_schema DEFAULT VALUES + RETURNING + (SELECT * FROM xyz AS sqlite_master WHERE a=sqlite_master.name); +} {1 {no such column: sqlite_master.name}} + + finish_test From 016214ddf777e7ce9b104787ab48cf8f69c4939f Mon Sep 17 00:00:00 2001 From: drh <> Date: Sat, 10 Aug 2024 13:45:25 +0000 Subject: [PATCH 427/430] Cherrypick ALTER TABLE fixes from trunk so that ALTER TABLE no longer returns SQLITE_INTERNAL instead of SQLITE_ERROR after malformed input. FossilOrigin-Name: 6decf00f7c56746fac31469ccc098a5be1344b2cafa8011bfcfbc7923e3cd97b --- manifest | 23 +++++++++-------------- manifest.uuid | 2 +- src/alter.c | 2 +- src/resolve.c | 11 +++++++---- 4 files changed, 18 insertions(+), 20 deletions(-) diff --git a/manifest b/manifest index 548a8f155e..fd8a3b324e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Cherrypick\svarious\sminor\sfixes\sfrom\strunk\sinto\sbranch-3.46. -D 2024-08-10T11:02:23.976 +C Cherrypick\sALTER\sTABLE\sfixes\sfrom\strunk\sso\sthat\sALTER\sTABLE\sno\slonger\nreturns\sSQLITE_INTERNAL\sinstead\sof\sSQLITE_ERROR\safter\smalformed\sinput. +D 2024-08-10T13:45:25.769 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -686,7 +686,7 @@ F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b F sqlite3.1 acdff36db796e2d00225b911d3047d580cd136547298435426ce9d40347973cc F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a F sqlite_cfg.h.in baf2e409c63d4e7a765e17769b6ff17c5a82bbd9cbf1e284fd2e4cefaff3fcf2 -F src/alter.c e1b6782b85dd758f89e5c588e4e3eb82638c2dafc0c857b79a43bb8ec1746fca +F src/alter.c bb663fddf1fe0e2e6d8758b2b7fb6374e7c057a6ca3955f37a48986806029765 F src/analyze.c a3df28274e2565ba5656577d7e3fd262169a213e6eb0bd47890e0f0729a4031c F src/attach.c cc9d00d30da916ff656038211410ccf04ed784b7564639b9b61d1839ed69fd39 F src/auth.c 19b7ccacae3dfba23fc6f1d0af68134fa216e9040e53b0681b4715445ea030b4 @@ -752,7 +752,7 @@ F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7 F src/prepare.c d99931f45416652895e502328ca49fe782cfc4e1ebdcda13b3736d991ebf42ce F src/printf.c 8b250972305e14b365561be5117ed0fd364e4fd58968776df1ce64c6280b90f9 F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c -F src/resolve.c ae341d04d39de308e024649d6777dd015b6a94ddbfbe74d7fca2ee122fb1aea9 +F src/resolve.c 4f4c99b8714fa04844a0f1f96ee69eefc8928e300af9247a46cfe80f78f8997c F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c 1a841c38974d45cf15a7611398479182b61ad4c187423c380741d8b1688fe607 F src/shell.c.in ebb698028ec031e0b1595865500097d2005f977be0efd14bd8b0ddf634d5ed8d @@ -2191,15 +2191,10 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 4afe3201f005bfd1aa66bbeebac659323d8a35dbee04d50fbf77ba96a94db91e -Q +061d7b69e6a43474cd7123a69f4ee65b5649a0b5e51474343defef5ae5262657 -Q +08cc5488404d068e59378b82988460793710df43ec21b4a83a794b497abd035f -Q +273504b74cb9c3cfa2497a1339e706a1f2d2c3ce81b23a16beb47da9292535e0 -Q +a096eb7554952f8137c6e9330c328164719fb27e958787fbd503bcd1364e6ae4 -Q +a35c50eca907d0cf373b7962c359aebfce8ac7c34ce81edeb99122d4fb5804f7 -Q +c7aaa28f786567e29ebee3848283b5c740dd3b8144dc14372e56260ae1b76922 -Q +e78b7783040ef1ad34d4287af8a7a5998d360d50076e0de42a116d9a96fe74b4 -R 9db66ace3e0949b1bbff4f1693881c2f +P 6047b18ee3c4d8f2661386ef68c717f5892651c3d6f7e29a98a6b2795b3382d3 +Q +9052187efd1f78abd9b285ac94269a3ba4d65b6aa74c9fa34002ee0628c83919 +Q +b416756320dfb46ad72b843a7fbf18807d3fd1966251c320de626280b5238a5c +R c3625207947b56085ff84e7a4b1c0404 U drh -Z 1aa2ed1f9203f8c31686df6bb8cab665 +Z 3b74f2bdac4bf6c3eef7ca7236fcd520 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 581b9c84e3..1d5e7b27da 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6047b18ee3c4d8f2661386ef68c717f5892651c3d6f7e29a98a6b2795b3382d3 +6decf00f7c56746fac31469ccc098a5be1344b2cafa8011bfcfbc7923e3cd97b diff --git a/src/alter.c b/src/alter.c index c1e0a295a4..a8556d115e 100644 --- a/src/alter.c +++ b/src/alter.c @@ -1320,7 +1320,7 @@ static int renameResolveTrigger(Parse *pParse){ /* ALWAYS() because if the table of the trigger does not exist, the ** error would have been hit before this point */ if( ALWAYS(pParse->pTriggerTab) ){ - rc = sqlite3ViewGetColumnNames(pParse, pParse->pTriggerTab); + rc = sqlite3ViewGetColumnNames(pParse, pParse->pTriggerTab)!=0; } /* Resolve symbols in WHEN clause */ diff --git a/src/resolve.c b/src/resolve.c index 40044a2204..590f8ae5e0 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -2154,6 +2154,9 @@ int sqlite3ResolveExprNames( ** Resolve all names for all expression in an expression list. This is ** just like sqlite3ResolveExprNames() except that it works for an expression ** list rather than a single expression. +** +** The return value is SQLITE_OK (0) for success or SQLITE_ERROR (1) for a +** failure. */ int sqlite3ResolveExprListNames( NameContext *pNC, /* Namespace to resolve expressions in. */ @@ -2162,7 +2165,7 @@ int sqlite3ResolveExprListNames( int i; int savedHasAgg = 0; Walker w; - if( pList==0 ) return WRC_Continue; + if( pList==0 ) return SQLITE_OK; w.pParse = pNC->pParse; w.xExprCallback = resolveExprStep; w.xSelectCallback = resolveSelectStep; @@ -2176,7 +2179,7 @@ int sqlite3ResolveExprListNames( #if SQLITE_MAX_EXPR_DEPTH>0 w.pParse->nHeight += pExpr->nHeight; if( sqlite3ExprCheckHeight(w.pParse, w.pParse->nHeight) ){ - return WRC_Abort; + return SQLITE_ERROR; } #endif sqlite3WalkExprNN(&w, pExpr); @@ -2193,10 +2196,10 @@ int sqlite3ResolveExprListNames( (NC_HasAgg|NC_MinMaxAgg|NC_HasWin|NC_OrderAgg); pNC->ncFlags &= ~(NC_HasAgg|NC_MinMaxAgg|NC_HasWin|NC_OrderAgg); } - if( w.pParse->nErr>0 ) return WRC_Abort; + if( w.pParse->nErr>0 ) return SQLITE_ERROR; } pNC->ncFlags |= savedHasAgg; - return WRC_Continue; + return SQLITE_OK; } /* From 8cec7ac64491497b1247d358249afc7da04ccb45 Mon Sep 17 00:00:00 2001 From: drh <> Date: Sat, 10 Aug 2024 14:56:06 +0000 Subject: [PATCH 428/430] Fix behavior change in the offset() SQL function introduced by check-in f0b671183f44d0ae. FossilOrigin-Name: d6fc6e5f0a68c5b34c0f93e14a38a7e1bc1b72a66f2bcc400c3d7e0f0bab5a92 --- manifest | 15 +++++++-------- manifest.uuid | 2 +- src/where.c | 20 +++++++++----------- 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/manifest b/manifest index fd8a3b324e..cd9cff97e5 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Cherrypick\sALTER\sTABLE\sfixes\sfrom\strunk\sso\sthat\sALTER\sTABLE\sno\slonger\nreturns\sSQLITE_INTERNAL\sinstead\sof\sSQLITE_ERROR\safter\smalformed\sinput. -D 2024-08-10T13:45:25.769 +C Fix\sbehavior\schange\sin\sthe\soffset()\sSQL\sfunction\sintroduced\sby\s\ncheck-in\sf0b671183f44d0ae. +D 2024-08-10T14:56:06.407 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -839,7 +839,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c 887fc4ca3f020ebb2e376f222069570834ac63bf50111ef0cbf3ae417048ed89 F src/wal.h ba252daaa94f889f4b2c17c027e823d9be47ce39da1d3799886bbd51f0490452 F src/walker.c 7c7ea0115345851c3da4e04e2e239a29983b61fb5b038b94eede6aba462640e2 -F src/where.c c015aba5f42fbb952029b693695ae2a75fd947aec6e43f94e6ab0ae6ed00cbf9 +F src/where.c 839956666ce9f6b5d4951fc1f27e976951aac66920c82f9cdc5036b61b54ef7b F src/whereInt.h 82a13766f13d1a53b05387c2e60726289ef26404bc7b9b1f7770204d97357fb8 F src/wherecode.c f5255f49d1f42b6e7e6b0362ff3522fa88cbcaa7213e52f9374744027ecdebca F src/whereexpr.c 67d15caf88a1a9528283d68ff578e024cf9fe810b517bb0343e5aaf695ad97dd @@ -2191,10 +2191,9 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 6047b18ee3c4d8f2661386ef68c717f5892651c3d6f7e29a98a6b2795b3382d3 -Q +9052187efd1f78abd9b285ac94269a3ba4d65b6aa74c9fa34002ee0628c83919 -Q +b416756320dfb46ad72b843a7fbf18807d3fd1966251c320de626280b5238a5c -R c3625207947b56085ff84e7a4b1c0404 +P 6decf00f7c56746fac31469ccc098a5be1344b2cafa8011bfcfbc7923e3cd97b +Q +c2ac17f183082d6388336338b8d5c0b334095e5f77a27bc08419431f37471d22 +R 395b437cb75d33acb7b81f314b91285a U drh -Z 3b74f2bdac4bf6c3eef7ca7236fcd520 +Z faa156c9fc79611223ead11bf7c61eee # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 1d5e7b27da..99f79a7f20 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6decf00f7c56746fac31469ccc098a5be1344b2cafa8011bfcfbc7923e3cd97b +d6fc6e5f0a68c5b34c0f93e14a38a7e1bc1b72a66f2bcc400c3d7e0f0bab5a92 diff --git a/src/where.c b/src/where.c index 684a37f54c..84deb5e9ea 100644 --- a/src/where.c +++ b/src/where.c @@ -7169,20 +7169,18 @@ void sqlite3WhereEnd(WhereInfo *pWInfo){ assert( pIdx->pTable==pTab ); #ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC if( pOp->opcode==OP_Offset ){ - x = 0; + /* Do not need to translate the column number */ }else #endif - { - if( !HasRowid(pTab) ){ - Index *pPk = sqlite3PrimaryKeyIndex(pTab); - x = pPk->aiColumn[x]; - assert( x>=0 ); - }else{ - testcase( x!=sqlite3StorageColumnToTable(pTab,x) ); - x = sqlite3StorageColumnToTable(pTab,x); - } - x = sqlite3TableColumnToIndex(pIdx, x); + if( !HasRowid(pTab) ){ + Index *pPk = sqlite3PrimaryKeyIndex(pTab); + x = pPk->aiColumn[x]; + assert( x>=0 ); + }else{ + testcase( x!=sqlite3StorageColumnToTable(pTab,x) ); + x = sqlite3StorageColumnToTable(pTab,x); } + x = sqlite3TableColumnToIndex(pIdx, x); if( x>=0 ){ pOp->p2 = x; pOp->p1 = pLevel->iIdxCur; From a751fddd0179d79f693c2788ccbb8ae368c628e3 Mon Sep 17 00:00:00 2001 From: drh <> Date: Sat, 10 Aug 2024 16:29:29 +0000 Subject: [PATCH 429/430] Revision to check-in d9f726ade6b258f8 so that OOM and other unrelated failures are not overridden by a syntax error in the tokenizer spec. FossilOrigin-Name: fc956353d3762d0e655b88f9d0c1a3840b40453a22e97160ccdf60485be56a92 --- ext/fts5/fts5_tokenize.c | 6 +++--- manifest | 14 +++++++------- manifest.uuid | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/ext/fts5/fts5_tokenize.c b/ext/fts5/fts5_tokenize.c index e5752efdd4..2200e78375 100644 --- a/ext/fts5/fts5_tokenize.c +++ b/ext/fts5/fts5_tokenize.c @@ -90,7 +90,7 @@ static int fts5AsciiCreate( rc = SQLITE_ERROR; } } - if( iiFoldParam!=0 && pNew->bFold==0 ){ rc = SQLITE_ERROR; diff --git a/manifest b/manifest index cd9cff97e5..9d3e9aea88 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sbehavior\schange\sin\sthe\soffset()\sSQL\sfunction\sintroduced\sby\s\ncheck-in\sf0b671183f44d0ae. -D 2024-08-10T14:56:06.407 +C Revision\sto\scheck-in\sd9f726ade6b258f8\sso\sthat\sOOM\sand\sother\sunrelated\sfailures\nare\snot\soverridden\sby\sa\ssyntax\serror\sin\sthe\stokenizer\sspec. +D 2024-08-10T16:29:29.304 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -105,7 +105,7 @@ F ext/fts5/fts5_storage.c f9e31b0d155e9b2c92d5d3a09ad7a56b937fbf1c7f962e10f4ca62 F ext/fts5/fts5_tcl.c fdf7e2bb9a9186cfcaf2d2ce11d338309342b7a7593c2812bc54455db53da5d2 F ext/fts5/fts5_test_mi.c 08c11ec968148d4cb4119d96d819f8c1f329812c568bac3684f5464be177d3ee F ext/fts5/fts5_test_tok.c 3cb0a9b508b30d17ef025ccddd26ae3dc8ddffbe76c057616e59a9aa85d36f3b -F ext/fts5/fts5_tokenize.c b94826fc235e1937c4e93c266e0db4052dcab648ff87f4080376fc04b1fc93a4 +F ext/fts5/fts5_tokenize.c 2321cbcef0bb99ed326d58f02cbd907e678c86572a72a434d08f6cb78e346dbd F ext/fts5/fts5_unicode2.c eca63dbc797f8ff0572e97caf4631389c0ab900d6364861b915bdd4735973f00 F ext/fts5/fts5_varint.c e64d2113f6e1bfee0032972cffc1207b77af63319746951bf1d09885d1dadf80 F ext/fts5/fts5_vocab.c 209e0c151e108d5f3621fa24b91e9b02f3750ee6c3f9ccec312df39481b68a09 @@ -2191,9 +2191,9 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 6decf00f7c56746fac31469ccc098a5be1344b2cafa8011bfcfbc7923e3cd97b -Q +c2ac17f183082d6388336338b8d5c0b334095e5f77a27bc08419431f37471d22 -R 395b437cb75d33acb7b81f314b91285a +P d6fc6e5f0a68c5b34c0f93e14a38a7e1bc1b72a66f2bcc400c3d7e0f0bab5a92 +Q +3778b2a9ca1cc12a88ef6c32a1ee7c58a0a829ed9715a3d32a225d377d7527ef +R 47b9d94ac84047bf00fd35221bcbfde9 U drh -Z faa156c9fc79611223ead11bf7c61eee +Z 26dcfcb42f2cbddea54751223061288b # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 99f79a7f20..86636887b4 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d6fc6e5f0a68c5b34c0f93e14a38a7e1bc1b72a66f2bcc400c3d7e0f0bab5a92 +fc956353d3762d0e655b88f9d0c1a3840b40453a22e97160ccdf60485be56a92 From f3d536d37825302e31ed0eddd811c689f38f85a3 Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 13 Aug 2024 09:16:08 +0000 Subject: [PATCH 430/430] Version 3.46.1 FossilOrigin-Name: c9c2ab54ba1f5f46360f1b4f35d849cd3f080e6fc2b6c60e91b16c63f69a1e33 --- manifest | 11 ++++++----- manifest.uuid | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/manifest b/manifest index 9d3e9aea88..a83c5c071a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Revision\sto\scheck-in\sd9f726ade6b258f8\sso\sthat\sOOM\sand\sother\sunrelated\sfailures\nare\snot\soverridden\sby\sa\ssyntax\serror\sin\sthe\stokenizer\sspec. -D 2024-08-10T16:29:29.304 +C Version\s3.46.1 +D 2024-08-13T09:16:08.704 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -2191,9 +2191,10 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P d6fc6e5f0a68c5b34c0f93e14a38a7e1bc1b72a66f2bcc400c3d7e0f0bab5a92 -Q +3778b2a9ca1cc12a88ef6c32a1ee7c58a0a829ed9715a3d32a225d377d7527ef +P fc956353d3762d0e655b88f9d0c1a3840b40453a22e97160ccdf60485be56a92 R 47b9d94ac84047bf00fd35221bcbfde9 +T +sym-release * +T +sym-version-3.46.1 * U drh -Z 26dcfcb42f2cbddea54751223061288b +Z 519cc14a63561bb4dfa17935ffe00a32 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 86636887b4..43d669ec29 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -fc956353d3762d0e655b88f9d0c1a3840b40453a22e97160ccdf60485be56a92 +c9c2ab54ba1f5f46360f1b4f35d849cd3f080e6fc2b6c60e91b16c63f69a1e33